[U-Boot] [PATCH v3 15/17] odroid: board: add support to dm pmic api

Simon Glass sjg at chromium.org
Sun Mar 29 15:08:46 CEST 2015


 Hi Przemyslaw,

On 24 March 2015 at 14:30, Przemyslaw Marczak <p.marczak at samsung.com> wrote:
> This commit change the old pmic framework calls with the new ones.
>
> Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
> ---
> Changes v2:
> - remove board_init_i2c() call
> - update regulator calls
> - update headers
> - samsung/misc.c: include required header
>
> Changes v3:
> - adjust regulator calls to new api
> ---
>  board/samsung/common/misc.c   |   1 +
>  board/samsung/odroid/odroid.c | 113 +++++++++++++++++++++++++++++++++---------
>  2 files changed, 91 insertions(+), 23 deletions(-)
>
> diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
> index 1a77c82..f0d69d4 100644
> --- a/board/samsung/common/misc.c
> +++ b/board/samsung/common/misc.c
> @@ -16,6 +16,7 @@
>  #include <asm/arch/cpu.h>
>  #include <asm/gpio.h>
>  #include <linux/input.h>
> +#include <dm.h>
>  #include <power/pmic.h>
>  #include <mmc.h>
>
> diff --git a/board/samsung/odroid/odroid.c b/board/samsung/odroid/odroid.c
> index ae41c29..aa3b0ff 100644
> --- a/board/samsung/odroid/odroid.c
> +++ b/board/samsung/odroid/odroid.c
> @@ -12,7 +12,9 @@
>  #include <asm/arch/gpio.h>
>  #include <asm/gpio.h>
>  #include <asm/arch/cpu.h>
> +#include <dm.h>
>  #include <power/pmic.h>
> +#include <power/regulator.h>
>  #include <power/max77686_pmic.h>
>  #include <errno.h>
>  #include <mmc.h>
> @@ -405,15 +407,62 @@ static void board_gpio_init(void)
>
>  static int pmic_init_max77686(void)
>  {
> -       struct pmic *p = pmic_get("MAX77686_PMIC");
> +       struct udevice *dev;
> +       int ret;
>
> -       if (pmic_probe(p))
> -               return -ENODEV;
> +       ret = regulator_get("VDDQ_EMMC_1.8V", &dev);
> +       if (ret) {
> +               error("Regulator get error: %d", ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_value(dev, 1800000);
> +       if (ret) {
> +               error("Regulator %s value setting error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_enable(dev, true);
> +       if (ret) {
> +               error("Regulator %s enable error: %d", dev->name, ret);
> +               return ret;
> +       }

How about adding a function that finds a regulator, sets its voltage
and enables it? Then you can avoid duplicating the same code 3 times.

> +
> +       ret = regulator_get("TFLASH_2.8V", &dev);
> +       if (ret) {
> +               error("Regulator get error: %d", ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_value(dev, 2800000);
> +       if (ret) {
> +               error("Regulator %s value setting error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_enable(dev, true);
> +       if (ret) {
> +               error("Regulator %s enable error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_get("VDDQ_EMMC_2.8V", &dev);
> +       if (ret) {
> +               error("Regulator get error: %d", ret);
> +               return ret;
> +       }
>
> -       /* Set LDO Voltage */
> -       max77686_set_ldo_voltage(p, 20, 1800000);       /* LDO20 eMMC */
> -       max77686_set_ldo_voltage(p, 21, 2800000);       /* LDO21 SD */
> -       max77686_set_ldo_voltage(p, 22, 2800000);       /* LDO22 eMMC */
> +       ret = regulator_set_value(dev, 2800000);
> +       if (ret) {
> +               error("Regulator %s value setting error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_enable(dev, true);
> +       if (ret) {
> +               error("Regulator %s enable error: %d", dev->name, ret);
> +               return ret;
> +       }
>
>         return 0;
>  }
> @@ -434,7 +483,6 @@ int exynos_init(void)
>
>  int exynos_power_init(void)
>  {
> -       pmic_init(0);
>         pmic_init_max77686();
>
>         return 0;
> @@ -443,19 +491,20 @@ int exynos_power_init(void)
>  #ifdef CONFIG_USB_GADGET
>  static int s5pc210_phy_control(int on)
>  {
> -       struct pmic *p_pmic;
> -
> -       p_pmic = pmic_get("MAX77686_PMIC");
> -       if (!p_pmic)
> -               return -ENODEV;
> +       struct udevice *dev;
> +       int ret;
>
> -       if (pmic_probe(p_pmic))
> -               return -1;
> +       ret = regulator_get("VDD_UOTG_3.0V", &dev);
> +       if (ret) {
> +               error("Regulator get error: %d", ret);
> +               return ret;
> +       }
>
>         if (on)
> -               return max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
> +               return regulator_set_mode(dev, OPMODE_ON);
>         else
> -               return max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
> +               return regulator_set_mode(dev, OPMODE_LPM);
> +
>  }
>
>  struct s3c_plat_otg_data s5pc210_otg_data = {
> @@ -472,7 +521,8 @@ struct s3c_plat_otg_data s5pc210_otg_data = {
>  int board_usb_init(int index, enum usb_init_type init)
>  {
>  #ifdef CONFIG_CMD_USB
> -       struct pmic *p_pmic;
> +       struct udevice *dev;
> +       int ret;
>
>         /* Set Ref freq 0 => 24MHz, 1 => 26MHz*/
>         /* Odroid Us have it at 24MHz, Odroid Xs at 26MHz */
> @@ -490,14 +540,31 @@ int board_usb_init(int index, enum usb_init_type init)
>         /* Power off and on BUCK8 for LAN9730 */
>         debug("LAN9730 - Turning power buck 8 OFF and ON.\n");
>
> -       p_pmic = pmic_get("MAX77686_PMIC");
> -       if (p_pmic && !pmic_probe(p_pmic)) {
> -               max77686_set_buck_voltage(p_pmic, 8, 750000);
> -               max77686_set_buck_voltage(p_pmic, 8, 3300000);
> +       ret = regulator_get("VCC_P3V3_2.85V", &dev);
> +       if (ret) {
> +               error("Regulator get error: %d", ret);
> +               return ret;
>         }
>
> -#endif
> +       ret = regulator_set_enable(dev, true);
> +       if (ret) {
> +               error("Regulator %s enable setting error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +       ret = regulator_set_value(dev, 750000);
> +       if (ret) {
> +               error("Regulator %s value setting error: %d", dev->name, ret);
> +               return ret;
> +       }
>
> +       ret = regulator_set_value(dev, 3300000);
> +       if (ret) {
> +               error("Regulator %s value setting error: %d", dev->name, ret);
> +               return ret;
> +       }
> +
> +#endif
>         debug("USB_udc_probe\n");
>         return s3c_udc_probe(&s5pc210_otg_data);
>  }
> --
> 1.9.1
>

Regards,
Simon


More information about the U-Boot mailing list