Commit e9a3bec2e95a4b2b4641223c8ee4ebd8da76d7f9

Authored by Ye Li
1 parent f3d2fba818

MLK-18387 pmic: Add pmic driver for BD71837

The iMX8MM EVK board uses BD71837MWV pmic. Add its driver to u-boot.

Signed-off-by: Ye Li <ye.li@nxp.com>

Showing 5 changed files with 196 additions and 0 deletions Side-by-side Diff

drivers/power/pmic/Kconfig
... ... @@ -48,6 +48,13 @@
48 48 interface and is designs to cover most of the power managementment
49 49 required for a tablets or laptop.
50 50  
  51 +config DM_PMIC_BD71837
  52 + bool "Enable Driver Model for PMIC BD71837"
  53 + depends on DM_PMIC
  54 + help
  55 + This config enables implementation of driver-model pmic uclass features
  56 + for PMIC BD71837. The driver implements read/write operations.
  57 +
51 58 config DM_PMIC_PFUZE100
52 59 bool "Enable Driver Model for PMIC PFUZE100"
53 60 depends on DM_PMIC
drivers/power/pmic/Makefile
... ... @@ -9,6 +9,7 @@
9 9 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
10 10 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
11 11 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
  12 +obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
12 13 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
13 14 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
14 15 obj-$(CONFIG_PMIC_ACT8846) += act8846.o
... ... @@ -30,6 +31,7 @@
30 31 obj-$(CONFIG_POWER_MAX8997) += pmic_max8997.o
31 32 obj-$(CONFIG_POWER_MUIC_MAX8997) += muic_max8997.o
32 33 obj-$(CONFIG_POWER_MAX77686) += pmic_max77686.o
  34 +obj-$(CONFIG_POWER_BD71837) += pmic_bd71837.o
33 35 obj-$(CONFIG_POWER_PFUZE100) += pmic_pfuze100.o
34 36 obj-$(CONFIG_POWER_PFUZE3000) += pmic_pfuze3000.o
35 37 obj-$(CONFIG_POWER_TPS65217) += pmic_tps65217.o
drivers/power/pmic/bd71837.c
  1 +/*
  2 + * Copyright 2018 NXP *
  3 + * SPDX-License-Identifier: GPL-2.0+
  4 + */
  5 +
  6 +#include <common.h>
  7 +#include <fdtdec.h>
  8 +#include <errno.h>
  9 +#include <dm.h>
  10 +#include <i2c.h>
  11 +#include <power/pmic.h>
  12 +#include <power/regulator.h>
  13 +#include <power/bd71837.h>
  14 +
  15 +DECLARE_GLOBAL_DATA_PTR;
  16 +
  17 +static const struct pmic_child_info pmic_children_info[] = {
  18 + /* buck */
  19 + { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
  20 + /* ldo */
  21 + { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
  22 + { },
  23 +};
  24 +
  25 +static int bd71837_reg_count(struct udevice *dev)
  26 +{
  27 + return BD71837_REG_NUM;
  28 +}
  29 +
  30 +static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
  31 + int len)
  32 +{
  33 + if (dm_i2c_write(dev, reg, buff, len)) {
  34 + error("write error to device: %p register: %#x!", dev, reg);
  35 + return -EIO;
  36 + }
  37 +
  38 + return 0;
  39 +}
  40 +
  41 +static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  42 +{
  43 + if (dm_i2c_read(dev, reg, buff, len)) {
  44 + error("read error from device: %p register: %#x!", dev, reg);
  45 + return -EIO;
  46 + }
  47 +
  48 + return 0;
  49 +}
  50 +
  51 +static int bd71837_bind(struct udevice *dev)
  52 +{
  53 + int children;
  54 + int regulators_node;
  55 + const void *blob = gd->fdt_blob;
  56 +
  57 + regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
  58 + "regulators");
  59 + if (regulators_node <= 0) {
  60 + debug("%s: %s regulators subnode not found!", __func__,
  61 + dev->name);
  62 + return -ENXIO;
  63 + }
  64 +
  65 + debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  66 +
  67 + children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  68 + if (!children)
  69 + debug("%s: %s - no child found\n", __func__, dev->name);
  70 +
  71 + /* Always return success for this device */
  72 + return 0;
  73 +}
  74 +
  75 +static struct dm_pmic_ops bd71837_ops = {
  76 + .reg_count = bd71837_reg_count,
  77 + .read = bd71837_read,
  78 + .write = bd71837_write,
  79 +};
  80 +
  81 +static const struct udevice_id bd71837_ids[] = {
  82 + { .compatible = "rohm,bd71837", .data = 0x4b, },
  83 + { }
  84 +};
  85 +
  86 +U_BOOT_DRIVER(pmic_bd71837) = {
  87 + .name = "bd71837 pmic",
  88 + .id = UCLASS_PMIC,
  89 + .of_match = bd71837_ids,
  90 + .bind = bd71837_bind,
  91 + .ops = &bd71837_ops,
  92 +};
drivers/power/pmic/pmic_bd71837.c
  1 +/*
  2 + * Copyright (C) 2014 Gateworks Corporation
  3 + * Tim Harvey <tharvey@gateworks.com>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <errno.h>
  10 +#include <i2c.h>
  11 +#include <power/pmic.h>
  12 +#include <power/bd71837.h>
  13 +
  14 +static const char bd71837_name[] = "BD71837";
  15 +int power_bd71837_init (unsigned char bus) {
  16 + struct pmic *p = pmic_alloc();
  17 +
  18 + if (!p) {
  19 + printf("%s: POWER allocation error!\n", __func__);
  20 + return -ENOMEM;
  21 + }
  22 +
  23 + p->name = bd71837_name;
  24 + p->interface = PMIC_I2C;
  25 + p->number_of_regs = BD71837_REG_NUM;
  26 + p->hw.i2c.addr = 0x4b;
  27 + p->hw.i2c.tx_num = 1;
  28 + p->bus = bus;
  29 +
  30 + printf("power_bd71837_init\n");
  31 +
  32 + return 0;
  33 +}
include/power/bd71837.h
  1 +
  2 +#ifndef BD71837_H_
  3 +#define BD71837_H_
  4 +
  5 +#define BD71837_REGULATOR_DRIVER "bd71837_regulator"
  6 +
  7 +enum {
  8 + BD71837_REV = 0x00,
  9 + BD71837_SWRESET = 0x01,
  10 + BD71837_I2C_DEV = 0x02,
  11 + BD71837_PWRCTRL0 = 0x03,
  12 + BD71837_PWRCTRL1 = 0x04,
  13 + BD71837_BUCK1_CTRL = 0x05,
  14 + BD71837_BUCK2_CTRL = 0x06,
  15 + BD71837_BUCK3_CTRL = 0x07,
  16 + BD71837_BUCK4_CTRL = 0x08,
  17 + BD71837_BUCK5_CTRL = 0x09,
  18 + BD71837_BUCK6_CTRL = 0x0A,
  19 + BD71837_BUCK7_CTRL = 0x0B,
  20 + BD71837_BUCK8_CTRL = 0x0C,
  21 + BD71837_BUCK1_VOLT_RUN = 0x0D,
  22 + BD71837_BUCK1_VOLT_IDLE = 0x0E,
  23 + BD71837_BUCK1_VOLT_SUSP = 0x0F,
  24 + BD71837_BUCK2_VOLT_RUN = 0x10,
  25 + BD71837_BUCK2_VOLT_IDLE = 0x11,
  26 + BD71837_BUCK3_VOLT_RUN = 0x12,
  27 + BD71837_BUCK4_VOLT_RUN = 0x13,
  28 + BD71837_BUCK5_VOLT = 0x14,
  29 + BD71837_BUCK6_VOLT = 0x15,
  30 + BD71837_BUCK7_VOLT = 0x16,
  31 + BD71837_BUCK8_VOLT = 0x17,
  32 + BD71837_LDO1_VOLT = 0x18,
  33 + BD71837_LDO2_VOLT = 0x19,
  34 + BD71837_LDO3_VOLT = 0x1A,
  35 + BD71837_LDO4_VOLT = 0x1B,
  36 + BD71837_LDO5_VOLT = 0x1C,
  37 + BD71837_LDO6_VOLT = 0x1D,
  38 + BD71837_LDO7_VOLT = 0x1E,
  39 + BD71837_TRANS_COND0 = 0x1F,
  40 + BD71837_TRANS_COND1 = 0x20,
  41 + BD71837_VRFAULTEN = 0x21,
  42 + BD71837_MVRFLTMASK0 = 0x22,
  43 + BD71837_MVRFLTMASK1 = 0x23,
  44 + BD71837_MVRFLTMASK2 = 0x24,
  45 + BD71837_RCVCFG = 0x25,
  46 + BD71837_RCVNUM = 0x26,
  47 + BD71837_PWRONCONFIG0 = 0x27,
  48 + BD71837_PWRONCONFIG1 = 0x28,
  49 + BD71837_RESETSRC = 0x29,
  50 + BD71837_MIRQ = 0x2A,
  51 + BD71837_IRQ = 0x2B,
  52 + BD71837_IN_MON = 0x2C,
  53 + BD71837_POW_STATE = 0x2D,
  54 + BD71837_OUT32K = 0x2E,
  55 + BD71837_REGLOCK = 0x2F,
  56 + BD71837_MUXSW_EN = 0x30,
  57 + BD71837_REG_NUM,
  58 +};
  59 +
  60 +int power_bd71837_init(unsigned char bus);
  61 +
  62 +#endif