]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/stm32f7_i2c.c
cmd: Kconfig: Move CONFIG_MP to Kconfig
[u-boot] / drivers / i2c / stm32f7_i2c.c
index 196f2365ea5fad60140256b1dc89eed48ea4a5d2..36ec610c8ec696cdf01e2daf9ecf9afcacef6c3f 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2017 STMicroelectronics
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -244,8 +243,6 @@ static struct stm32_i2c_setup stm32f7_setup = {
        .analog_filter = STM32_I2C_ANALOG_FILTER_ENABLE,
 };
 
-DECLARE_GLOBAL_DATA_PTR;
-
 static int stm32_i2c_check_device_busy(struct stm32_i2c_priv *i2c_priv)
 {
        struct stm32_i2c_regs *regs = i2c_priv->regs;
@@ -533,7 +530,7 @@ static int stm32_i2c_compute_solutions(struct stm32_i2c_setup *setup,
                                if (((sdadel >= sdadel_min) &&
                                     (sdadel <= sdadel_max)) &&
                                    (p != p_prev)) {
-                                       v = kmalloc(sizeof(*v), GFP_KERNEL);
+                                       v = calloc(1, sizeof(*v));
                                        if (!v)
                                                return -ENOMEM;
 
@@ -571,6 +568,7 @@ static int stm32_i2c_choose_solution(struct stm32_i2c_setup *setup,
        u32 dnf_delay;
        u32 tsync;
        u16 l, h;
+       bool sol_found = false;
        int ret = 0;
 
        af_delay_min = setup->analog_filter ?
@@ -619,14 +617,15 @@ static int stm32_i2c_choose_solution(struct stm32_i2c_setup *setup,
                                                clk_error_prev = clk_error;
                                                v->scll = l;
                                                v->sclh = h;
-                                               s = v;
+                                               sol_found = true;
+                                               memcpy(s, v, sizeof(*s));
                                        }
                                }
                        }
                }
        }
 
-       if (!s) {
+       if (!sol_found) {
                pr_err("%s: no solution at all\n", __func__);
                ret = -EPERM;
        }
@@ -638,7 +637,7 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv,
                                      struct stm32_i2c_setup *setup,
                                      struct stm32_i2c_timings *output)
 {
-       struct stm32_i2c_timings *v, *_v, *s;
+       struct stm32_i2c_timings *v, *_v;
        struct list_head solutions;
        int ret;
 
@@ -669,22 +668,15 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv,
                return -EINVAL;
        }
 
-       s = NULL;
        INIT_LIST_HEAD(&solutions);
        ret = stm32_i2c_compute_solutions(setup, &solutions);
        if (ret)
                goto exit;
 
-       ret = stm32_i2c_choose_solution(setup, &solutions, s);
+       ret = stm32_i2c_choose_solution(setup, &solutions, output);
        if (ret)
                goto exit;
 
-       output->presc = s->presc;
-       output->scldel = s->scldel;
-       output->sdadel = s->sdadel;
-       output->scll = s->scll;
-       output->sclh = s->sclh;
-
        debug("%s: Presc: %i, scldel: %i, sdadel: %i, scll: %i, sclh: %i\n",
              __func__, output->presc,
              output->scldel, output->sdadel,
@@ -694,7 +686,7 @@ exit:
        /* Release list and memory */
        list_for_each_entry_safe(v, _v, &solutions, node) {
                list_del(&v->node);
-               kfree(v);
+               free(v);
        }
 
        return ret;