[U-Boot] [PATCH v2 0/3] power: Add a driver to handle the PBIAS cell of the TI SOCs

In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. This bias voltage is either 1.8v or 3.0v.
The first patch adds 2 functions to the DM core: to count strings in a stringlist and get a string from a stringlist based on its position in the list. The second patch implements the support for this PBIAS cell as a regulator driver. The last patch is here to allow the binding of the driver. In the DTS of the dra7x and am57x platforms, the pbias entry is a child of a syscon.
changes since v1: - add new functions to get strings from a stringlist in DM core - use the dev_read_*() API to access the DT - automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set. - removed the patch touching the DRA7 and AM57 config files.
Jean-Jacques Hiblot (3): dm: core: Add functions to get strings and the string count from a stringlist regulator: pbias: Add PBIAS regulator for proper voltage switching on MMC1 dm: syscon: scan sub-nodes of the syscon node
drivers/core/read.c | 11 ++ drivers/core/syscon-uclass.c | 1 + drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ include/dm/read.h | 36 ++++ 7 files changed, 362 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c

dev_read_string_count() is used to get the number of strings in a stringlist. dev_read_string_index() is used to get a string in the stringlist based on its position in the list.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com ---
not present in the v1 of this series
drivers/core/read.c | 11 +++++++++++ include/dm/read.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
diff --git a/drivers/core/read.c b/drivers/core/read.c index eafe727..cb4c45e 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -74,6 +74,17 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, return ofnode_stringlist_search(dev_ofnode(dev), property, string); }
+int dev_read_string_index(struct udevice *dev, const char *propname, int index, + const char **outp) +{ + return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); +} + +int dev_read_string_count(struct udevice *dev, const char *propname) +{ + return ofnode_read_string_count(dev_ofnode(dev), propname); +} + int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, diff --git a/include/dm/read.h b/include/dm/read.h index b86a2f5..4ef99cb 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -166,6 +166,29 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, const char *string);
/** + * dev_read_string_index() - obtain an indexed string from a string list + * + * @dev: device to examine + * @propname: name of the property containing the string list + * @index: index of the string to return + * @out: return location for the string + * + * @return: + * length of string, if found or -ve error value if not found + */ +int dev_read_string_index(struct udevice *dev, const char *propname, int index, + const char **outp); + +/** + * dev_read_string_count() - find the number of strings in a string list + * + * @dev: device to examine + * @propname: name of the property containing the string list + * @return: + * number of strings in the list, or -ve error value if not found + */ +int dev_read_string_count(struct udevice *dev, const char *propname); +/** * dev_read_phandle_with_args() - Find a node pointed by phandle in a list * * This function is useful to parse lists of phandles and their arguments. @@ -407,6 +430,19 @@ static inline int dev_read_stringlist_search(struct udevice *dev, return ofnode_stringlist_search(dev_ofnode(dev), propname, string); }
+static inline int dev_read_string_index(struct udevice *dev, + const char *propname, int index, + const char **outp) +{ + return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); +} + +static inline int dev_read_string_count(struct udevice *dev, + const char *propname) +{ + return ofnode_read_string_count(dev_ofnode(dev), propname); +} + static inline int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args)

On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
dev_read_string_count() is used to get the number of strings in a stringlist. dev_read_string_index() is used to get a string in the stringlist based on its position in the list.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
Applied to u-boot-mmc. Thanks!
Best Regards, Jaehoon Chung
not present in the v1 of this series
drivers/core/read.c | 11 +++++++++++ include/dm/read.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
diff --git a/drivers/core/read.c b/drivers/core/read.c index eafe727..cb4c45e 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -74,6 +74,17 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, return ofnode_stringlist_search(dev_ofnode(dev), property, string); }
+int dev_read_string_index(struct udevice *dev, const char *propname, int index,
const char **outp)
+{
- return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
+}
+int dev_read_string_count(struct udevice *dev, const char *propname) +{
- return ofnode_read_string_count(dev_ofnode(dev), propname);
+}
int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, diff --git a/include/dm/read.h b/include/dm/read.h index b86a2f5..4ef99cb 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -166,6 +166,29 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, const char *string);
/**
- dev_read_string_index() - obtain an indexed string from a string list
- @dev: device to examine
- @propname: name of the property containing the string list
- @index: index of the string to return
- @out: return location for the string
- @return:
- length of string, if found or -ve error value if not found
- */
+int dev_read_string_index(struct udevice *dev, const char *propname, int index,
const char **outp);
+/**
- dev_read_string_count() - find the number of strings in a string list
- @dev: device to examine
- @propname: name of the property containing the string list
- @return:
- number of strings in the list, or -ve error value if not found
- */
+int dev_read_string_count(struct udevice *dev, const char *propname); +/**
- dev_read_phandle_with_args() - Find a node pointed by phandle in a list
- This function is useful to parse lists of phandles and their arguments.
@@ -407,6 +430,19 @@ static inline int dev_read_stringlist_search(struct udevice *dev, return ofnode_stringlist_search(dev_ofnode(dev), propname, string); }
+static inline int dev_read_string_index(struct udevice *dev,
const char *propname, int index,
const char **outp)
+{
- return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
+}
+static inline int dev_read_string_count(struct udevice *dev,
const char *propname)
+{
- return ofnode_read_string_count(dev_ofnode(dev), propname);
+}
static inline int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args)

In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. The PBIAS cell is controlled by software.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org ---
changes since v1: - automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set - use the dev_read_*() API to access the DT
drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 588e118..63e1122 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -158,6 +158,7 @@ config MMC_PCI config MMC_OMAP_HS bool "TI OMAP High Speed Multimedia Card Interface support" select DM_MMC_OPS if DM_MMC + select DM_REGULATOR_PBIAS if DM_MMC && DM_REGULATOR help This selects the TI OMAP High Speed Multimedia card Interface. If you have an omap2plus board with a Multimedia Card slot, diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index f213487..f4ed3cc 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -142,6 +142,16 @@ config DM_REGULATOR_PALMAS features for REGULATOR PALMAS and the family of PALMAS PMICs. The driver implements get/set api for: value and enable.
+config DM_REGULATOR_PBIAS + bool "Enable driver for PBIAS regulator" + ---help--- + This enables implementation of driver-model regulator uclass + features for pseudo-regulator PBIAS found in the OMAP SOCs. + This pseudo-regulator is used to provide a BIAS voltage to MMC1 + signal pads and must be configured properly during a voltage switch. + Voltage switching is required by some operating modes of SDcards and + eMMC. + config DM_REGULATOR_LP873X bool "Enable driver for LP873X PMIC regulators" depends on PMIC_LP873X diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index ce14d08..75d611a 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,5 +17,6 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PBIAS) += pbias_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c new file mode 100644 index 0000000..303eca9 --- /dev/null +++ b/drivers/power/regulator/pbias_regulator.c @@ -0,0 +1,302 @@ +/* + * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> + * Jean-Jacques Hiblot jjhiblot@ti.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <errno.h> +#include <dm.h> +#include <power/pmic.h> +#include <power/regulator.h> +#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/ioport.h> +#include <dm/read.h> + +DECLARE_GLOBAL_DATA_PTR; + +struct pbias_reg_info { + u32 enable; + u32 enable_mask; + u32 disable_val; + u32 vmode; + unsigned int enable_time; + char *name; +}; + +struct pbias_priv { + struct regmap *regmap; + int offset; +}; + +static const struct pmic_child_info pmic_children_info[] = { + { .prefix = "pbias", .driver = "pbias_regulator"}, + { }, +}; + +static int pbias_write(struct udevice *dev, uint reg, const uint8_t *buff, + int len) +{ + struct pbias_priv *priv = dev_get_priv(dev); + uint32_t val = *(uint32_t *)buff; + + if (len != 4) + return -EINVAL; + + return regmap_write(priv->regmap, priv->offset, val); +} + +static int pbias_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{ + struct pbias_priv *priv = dev_get_priv(dev); + + if (len != 4) + return -EINVAL; + + return regmap_read(priv->regmap, priv->offset, (uint32_t *)buff); +} + +static int pbias_ofdata_to_platdata(struct udevice *dev) +{ + struct pbias_priv *priv = dev_get_priv(dev); + struct udevice *syscon; + struct regmap *regmap; + struct resource res; + int err; + + err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, + "syscon", &syscon); + if (err) { + error("%s: unable to find syscon device (%d)\n", __func__, + err); + return err; + } + + regmap = syscon_get_regmap(syscon); + if (IS_ERR(regmap)) { + error("%s: unable to find regmap (%ld)\n", __func__, + PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + priv->regmap = regmap; + + err = dev_read_resource(dev, 0, &res); + if (err) { + error("%s: unable to find offset (%d)\n", __func__, err); + return err; + } + priv->offset = res.start; + + return 0; +} + +static int pbias_bind(struct udevice *dev) +{ + int children; + + children = pmic_bind_children(dev, dev->node, pmic_children_info); + if (!children) + debug("%s: %s - no child found\n", __func__, dev->name); + + return 0; +} + +static struct dm_pmic_ops pbias_ops = { + .read = pbias_read, + .write = pbias_write, +}; + +static const struct udevice_id pbias_ids[] = { + { .compatible = "ti,pbias-dra7" }, + { } +}; + +U_BOOT_DRIVER(pbias_pmic) = { + .name = "pbias_pmic", + .id = UCLASS_PMIC, + .of_match = pbias_ids, + .bind = pbias_bind, + .ops = &pbias_ops, + .ofdata_to_platdata = pbias_ofdata_to_platdata, + .priv_auto_alloc_size = sizeof(struct pbias_priv), +}; + +static const struct pbias_reg_info pbias_mmc_omap2430 = { + .enable = BIT(1), + .enable_mask = BIT(1), + .vmode = BIT(0), + .disable_val = 0, + .enable_time = 100, + .name = "pbias_mmc_omap2430" +}; + +static const struct pbias_reg_info pbias_sim_omap3 = { + .enable = BIT(9), + .enable_mask = BIT(9), + .vmode = BIT(8), + .enable_time = 100, + .name = "pbias_sim_omap3" +}; + +static const struct pbias_reg_info pbias_mmc_omap4 = { + .enable = BIT(26) | BIT(22), + .enable_mask = BIT(26) | BIT(25) | BIT(22), + .disable_val = BIT(25), + .vmode = BIT(21), + .enable_time = 100, + .name = "pbias_mmc_omap4" +}; + +static const struct pbias_reg_info pbias_mmc_omap5 = { + .enable = BIT(27) | BIT(26), + .enable_mask = BIT(27) | BIT(25) | BIT(26), + .disable_val = BIT(25), + .vmode = BIT(21), + .enable_time = 100, + .name = "pbias_mmc_omap5" +}; + +static const struct pbias_reg_info *pbias_reg_infos[] = { + &pbias_mmc_omap5, + &pbias_mmc_omap4, + &pbias_sim_omap3, + &pbias_mmc_omap2430, + NULL +}; + + +static int pbias_regulator_probe(struct udevice *dev) +{ + const struct pbias_reg_info **p = pbias_reg_infos; + struct dm_regulator_uclass_platdata *uc_pdata; + + uc_pdata = dev_get_uclass_platdata(dev); + + + while (*p) { + int rc; + rc = dev_read_stringlist_search(dev, "regulator-name", + (*p)->name); + if (rc >= 0) { + debug("found regulator %s\n", (*p)->name); + break; + } else if (rc != -ENODATA) { + return rc; + } + p++; + } + if (!*p) { + int i = 0; + const char *s; + + debug("regulator "); + while (dev_read_string_index(dev, "regulator-name", i++, &s) >= 0) + debug("%s'%s' ", (i > 1) ? ", " : "", s); + debug("%s not supported\n", (i > 2) ? "are" : "is"); + return -EINVAL; + } + + uc_pdata->type = REGULATOR_TYPE_OTHER; + dev->priv = (void *)*p; + + return 0; +} + +static int pbias_regulator_get_value(struct udevice *dev) +{ + const struct pbias_reg_info *p = dev_get_priv(dev); + int rc; + uint32_t reg; + + rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg)); + if (rc) + return rc; + + debug("%s voltage id %s\n", p->name, + (reg & p->vmode) ? "3.0v" : "1.8v"); + return (reg & p->vmode) ? 3000000 : 1800000; +} + +static int pbias_regulator_set_value(struct udevice *dev, int uV) +{ + const struct pbias_reg_info *p = dev_get_priv(dev); + int rc; + uint32_t reg; + + debug("Setting %s voltage to %s\n", p->name, + (reg & p->vmode) ? "3.0v" : "1.8v"); + + rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg)); + if (rc) + return rc; + + if (uV == 3000000) + reg |= p->vmode; + else if (uV == 1800000) + reg &= ~p->vmode; + else + return -EINVAL; + + return pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg)); +} + +static int pbias_regulator_get_enable(struct udevice *dev) +{ + const struct pbias_reg_info *p = dev_get_priv(dev); + int rc; + uint32_t reg; + + rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg)); + if (rc) + return rc; + + debug("%s id %s\n", p->name, + (reg & p->enable_mask) == (p->disable_val) ? "on" : "off"); + + return (reg & p->enable_mask) == (p->disable_val); +} + +static int pbias_regulator_set_enable(struct udevice *dev, bool enable) +{ + const struct pbias_reg_info *p = dev_get_priv(dev); + int rc; + uint32_t reg; + + debug("Turning %s %s\n", enable ? "on" : "off", p->name); + + rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg)); + if (rc) + return rc; + + reg &= ~p->enable_mask; + if (enable) + reg |= p->enable; + else + reg |= p->disable_val; + + rc = pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg)); + if (rc) + return rc; + + if (enable) + udelay(p->enable_time); + + return 0; +} + +static const struct dm_regulator_ops pbias_regulator_ops = { + .get_value = pbias_regulator_get_value, + .set_value = pbias_regulator_set_value, + .get_enable = pbias_regulator_get_enable, + .set_enable = pbias_regulator_set_enable, +}; + +U_BOOT_DRIVER(pbias_regulator) = { + .name = "pbias_regulator", + .id = UCLASS_REGULATOR, + .ops = &pbias_regulator_ops, + .probe = pbias_regulator_probe, +};

On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. The PBIAS cell is controlled by software.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-mmc. Thanks!
Best Regards, Jaehoon Chung
changes since v1:
- automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set
- use the dev_read_*() API to access the DT
drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 588e118..63e1122 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -158,6 +158,7 @@ config MMC_PCI config MMC_OMAP_HS bool "TI OMAP High Speed Multimedia Card Interface support" select DM_MMC_OPS if DM_MMC
- select DM_REGULATOR_PBIAS if DM_MMC && DM_REGULATOR help This selects the TI OMAP High Speed Multimedia card Interface. If you have an omap2plus board with a Multimedia Card slot,
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index f213487..f4ed3cc 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -142,6 +142,16 @@ config DM_REGULATOR_PALMAS features for REGULATOR PALMAS and the family of PALMAS PMICs. The driver implements get/set api for: value and enable.
+config DM_REGULATOR_PBIAS
- bool "Enable driver for PBIAS regulator"
- ---help---
- This enables implementation of driver-model regulator uclass
- features for pseudo-regulator PBIAS found in the OMAP SOCs.
- This pseudo-regulator is used to provide a BIAS voltage to MMC1
- signal pads and must be configured properly during a voltage switch.
- Voltage switching is required by some operating modes of SDcards and
- eMMC.
config DM_REGULATOR_LP873X bool "Enable driver for LP873X PMIC regulators" depends on PMIC_LP873X diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index ce14d08..75d611a 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,5 +17,6 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PBIAS) += pbias_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c new file mode 100644 index 0000000..303eca9 --- /dev/null +++ b/drivers/power/regulator/pbias_regulator.c @@ -0,0 +1,302 @@ +/*
- (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
- Jean-Jacques Hiblot jjhiblot@ti.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <errno.h> +#include <dm.h> +#include <power/pmic.h> +#include <power/regulator.h> +#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/ioport.h> +#include <dm/read.h>
+DECLARE_GLOBAL_DATA_PTR;
+struct pbias_reg_info {
- u32 enable;
- u32 enable_mask;
- u32 disable_val;
- u32 vmode;
- unsigned int enable_time;
- char *name;
+};
+struct pbias_priv {
- struct regmap *regmap;
- int offset;
+};
+static const struct pmic_child_info pmic_children_info[] = {
- { .prefix = "pbias", .driver = "pbias_regulator"},
- { },
+};
+static int pbias_write(struct udevice *dev, uint reg, const uint8_t *buff,
int len)
+{
- struct pbias_priv *priv = dev_get_priv(dev);
- uint32_t val = *(uint32_t *)buff;
- if (len != 4)
return -EINVAL;
- return regmap_write(priv->regmap, priv->offset, val);
+}
+static int pbias_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- if (len != 4)
return -EINVAL;
- return regmap_read(priv->regmap, priv->offset, (uint32_t *)buff);
+}
+static int pbias_ofdata_to_platdata(struct udevice *dev) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- struct udevice *syscon;
- struct regmap *regmap;
- struct resource res;
- int err;
- err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
"syscon", &syscon);
- if (err) {
error("%s: unable to find syscon device (%d)\n", __func__,
err);
return err;
- }
- regmap = syscon_get_regmap(syscon);
- if (IS_ERR(regmap)) {
error("%s: unable to find regmap (%ld)\n", __func__,
PTR_ERR(regmap));
return PTR_ERR(regmap);
- }
- priv->regmap = regmap;
- err = dev_read_resource(dev, 0, &res);
- if (err) {
error("%s: unable to find offset (%d)\n", __func__, err);
return err;
- }
- priv->offset = res.start;
- return 0;
+}
+static int pbias_bind(struct udevice *dev) +{
- int children;
- children = pmic_bind_children(dev, dev->node, pmic_children_info);
- if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
- return 0;
+}
+static struct dm_pmic_ops pbias_ops = {
- .read = pbias_read,
- .write = pbias_write,
+};
+static const struct udevice_id pbias_ids[] = {
- { .compatible = "ti,pbias-dra7" },
- { }
+};
+U_BOOT_DRIVER(pbias_pmic) = {
- .name = "pbias_pmic",
- .id = UCLASS_PMIC,
- .of_match = pbias_ids,
- .bind = pbias_bind,
- .ops = &pbias_ops,
- .ofdata_to_platdata = pbias_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct pbias_priv),
+};
+static const struct pbias_reg_info pbias_mmc_omap2430 = {
- .enable = BIT(1),
- .enable_mask = BIT(1),
- .vmode = BIT(0),
- .disable_val = 0,
- .enable_time = 100,
- .name = "pbias_mmc_omap2430"
+};
+static const struct pbias_reg_info pbias_sim_omap3 = {
- .enable = BIT(9),
- .enable_mask = BIT(9),
- .vmode = BIT(8),
- .enable_time = 100,
- .name = "pbias_sim_omap3"
+};
+static const struct pbias_reg_info pbias_mmc_omap4 = {
- .enable = BIT(26) | BIT(22),
- .enable_mask = BIT(26) | BIT(25) | BIT(22),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap4"
+};
+static const struct pbias_reg_info pbias_mmc_omap5 = {
- .enable = BIT(27) | BIT(26),
- .enable_mask = BIT(27) | BIT(25) | BIT(26),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap5"
+};
+static const struct pbias_reg_info *pbias_reg_infos[] = {
- &pbias_mmc_omap5,
- &pbias_mmc_omap4,
- &pbias_sim_omap3,
- &pbias_mmc_omap2430,
- NULL
+};
+static int pbias_regulator_probe(struct udevice *dev) +{
- const struct pbias_reg_info **p = pbias_reg_infos;
- struct dm_regulator_uclass_platdata *uc_pdata;
- uc_pdata = dev_get_uclass_platdata(dev);
- while (*p) {
int rc;
rc = dev_read_stringlist_search(dev, "regulator-name",
(*p)->name);
if (rc >= 0) {
debug("found regulator %s\n", (*p)->name);
break;
} else if (rc != -ENODATA) {
return rc;
}
p++;
- }
- if (!*p) {
int i = 0;
const char *s;
debug("regulator ");
while (dev_read_string_index(dev, "regulator-name", i++, &s) >= 0)
debug("%s'%s' ", (i > 1) ? ", " : "", s);
debug("%s not supported\n", (i > 2) ? "are" : "is");
return -EINVAL;
- }
- uc_pdata->type = REGULATOR_TYPE_OTHER;
- dev->priv = (void *)*p;
- return 0;
+}
+static int pbias_regulator_get_value(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s voltage id %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- return (reg & p->vmode) ? 3000000 : 1800000;
+}
+static int pbias_regulator_set_value(struct udevice *dev, int uV) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Setting %s voltage to %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (uV == 3000000)
reg |= p->vmode;
- else if (uV == 1800000)
reg &= ~p->vmode;
- else
return -EINVAL;
- return pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
+}
+static int pbias_regulator_get_enable(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s id %s\n", p->name,
(reg & p->enable_mask) == (p->disable_val) ? "on" : "off");
- return (reg & p->enable_mask) == (p->disable_val);
+}
+static int pbias_regulator_set_enable(struct udevice *dev, bool enable) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Turning %s %s\n", enable ? "on" : "off", p->name);
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- reg &= ~p->enable_mask;
- if (enable)
reg |= p->enable;
- else
reg |= p->disable_val;
- rc = pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (enable)
udelay(p->enable_time);
- return 0;
+}
+static const struct dm_regulator_ops pbias_regulator_ops = {
- .get_value = pbias_regulator_get_value,
- .set_value = pbias_regulator_set_value,
- .get_enable = pbias_regulator_get_enable,
- .set_enable = pbias_regulator_set_enable,
+};
+U_BOOT_DRIVER(pbias_regulator) = {
- .name = "pbias_regulator",
- .id = UCLASS_REGULATOR,
- .ops = &pbias_regulator_ops,
- .probe = pbias_regulator_probe,
+};

Dear JJ,
On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. The PBIAS cell is controlled by software.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
changes since v1:
- automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set
- use the dev_read_*() API to access the DT
drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 588e118..63e1122 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -158,6 +158,7 @@ config MMC_PCI config MMC_OMAP_HS bool "TI OMAP High Speed Multimedia Card Interface support" select DM_MMC_OPS if DM_MMC
- select DM_REGULATOR_PBIAS if DM_MMC && DM_REGULATOR help This selects the TI OMAP High Speed Multimedia card Interface. If you have an omap2plus board with a Multimedia Card slot,
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index f213487..f4ed3cc 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -142,6 +142,16 @@ config DM_REGULATOR_PALMAS features for REGULATOR PALMAS and the family of PALMAS PMICs. The driver implements get/set api for: value and enable.
+config DM_REGULATOR_PBIAS
- bool "Enable driver for PBIAS regulator"
pbias_regulator is using the regmap and syscon.. I think that i needs to select REGMAP and SYSCON at here.
So i dropped the your patch from my repository. Could you resend the patch? otherwise i will resend your patch after fixing. let me know what you want.
Best Regards, Jaehoon Chung
- ---help---
- This enables implementation of driver-model regulator uclass
- features for pseudo-regulator PBIAS found in the OMAP SOCs.
- This pseudo-regulator is used to provide a BIAS voltage to MMC1
- signal pads and must be configured properly during a voltage switch.
- Voltage switching is required by some operating modes of SDcards and
- eMMC.
config DM_REGULATOR_LP873X bool "Enable driver for LP873X PMIC regulators" depends on PMIC_LP873X diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index ce14d08..75d611a 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,5 +17,6 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PBIAS) += pbias_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c new file mode 100644 index 0000000..303eca9 --- /dev/null +++ b/drivers/power/regulator/pbias_regulator.c @@ -0,0 +1,302 @@ +/*
- (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
- Jean-Jacques Hiblot jjhiblot@ti.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <errno.h> +#include <dm.h> +#include <power/pmic.h> +#include <power/regulator.h> +#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/ioport.h> +#include <dm/read.h>
+DECLARE_GLOBAL_DATA_PTR;
+struct pbias_reg_info {
- u32 enable;
- u32 enable_mask;
- u32 disable_val;
- u32 vmode;
- unsigned int enable_time;
- char *name;
+};
+struct pbias_priv {
- struct regmap *regmap;
- int offset;
+};
+static const struct pmic_child_info pmic_children_info[] = {
- { .prefix = "pbias", .driver = "pbias_regulator"},
- { },
+};
+static int pbias_write(struct udevice *dev, uint reg, const uint8_t *buff,
int len)
+{
- struct pbias_priv *priv = dev_get_priv(dev);
- uint32_t val = *(uint32_t *)buff;
- if (len != 4)
return -EINVAL;
- return regmap_write(priv->regmap, priv->offset, val);
+}
+static int pbias_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- if (len != 4)
return -EINVAL;
- return regmap_read(priv->regmap, priv->offset, (uint32_t *)buff);
+}
+static int pbias_ofdata_to_platdata(struct udevice *dev) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- struct udevice *syscon;
- struct regmap *regmap;
- struct resource res;
- int err;
- err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
"syscon", &syscon);
- if (err) {
error("%s: unable to find syscon device (%d)\n", __func__,
err);
return err;
- }
- regmap = syscon_get_regmap(syscon);
- if (IS_ERR(regmap)) {
error("%s: unable to find regmap (%ld)\n", __func__,
PTR_ERR(regmap));
return PTR_ERR(regmap);
- }
- priv->regmap = regmap;
- err = dev_read_resource(dev, 0, &res);
- if (err) {
error("%s: unable to find offset (%d)\n", __func__, err);
return err;
- }
- priv->offset = res.start;
- return 0;
+}
+static int pbias_bind(struct udevice *dev) +{
- int children;
- children = pmic_bind_children(dev, dev->node, pmic_children_info);
- if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
- return 0;
+}
+static struct dm_pmic_ops pbias_ops = {
- .read = pbias_read,
- .write = pbias_write,
+};
+static const struct udevice_id pbias_ids[] = {
- { .compatible = "ti,pbias-dra7" },
- { }
+};
+U_BOOT_DRIVER(pbias_pmic) = {
- .name = "pbias_pmic",
- .id = UCLASS_PMIC,
- .of_match = pbias_ids,
- .bind = pbias_bind,
- .ops = &pbias_ops,
- .ofdata_to_platdata = pbias_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct pbias_priv),
+};
+static const struct pbias_reg_info pbias_mmc_omap2430 = {
- .enable = BIT(1),
- .enable_mask = BIT(1),
- .vmode = BIT(0),
- .disable_val = 0,
- .enable_time = 100,
- .name = "pbias_mmc_omap2430"
+};
+static const struct pbias_reg_info pbias_sim_omap3 = {
- .enable = BIT(9),
- .enable_mask = BIT(9),
- .vmode = BIT(8),
- .enable_time = 100,
- .name = "pbias_sim_omap3"
+};
+static const struct pbias_reg_info pbias_mmc_omap4 = {
- .enable = BIT(26) | BIT(22),
- .enable_mask = BIT(26) | BIT(25) | BIT(22),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap4"
+};
+static const struct pbias_reg_info pbias_mmc_omap5 = {
- .enable = BIT(27) | BIT(26),
- .enable_mask = BIT(27) | BIT(25) | BIT(26),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap5"
+};
+static const struct pbias_reg_info *pbias_reg_infos[] = {
- &pbias_mmc_omap5,
- &pbias_mmc_omap4,
- &pbias_sim_omap3,
- &pbias_mmc_omap2430,
- NULL
+};
+static int pbias_regulator_probe(struct udevice *dev) +{
- const struct pbias_reg_info **p = pbias_reg_infos;
- struct dm_regulator_uclass_platdata *uc_pdata;
- uc_pdata = dev_get_uclass_platdata(dev);
- while (*p) {
int rc;
rc = dev_read_stringlist_search(dev, "regulator-name",
(*p)->name);
if (rc >= 0) {
debug("found regulator %s\n", (*p)->name);
break;
} else if (rc != -ENODATA) {
return rc;
}
p++;
- }
- if (!*p) {
int i = 0;
const char *s;
debug("regulator ");
while (dev_read_string_index(dev, "regulator-name", i++, &s) >= 0)
debug("%s'%s' ", (i > 1) ? ", " : "", s);
debug("%s not supported\n", (i > 2) ? "are" : "is");
return -EINVAL;
- }
- uc_pdata->type = REGULATOR_TYPE_OTHER;
- dev->priv = (void *)*p;
- return 0;
+}
+static int pbias_regulator_get_value(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s voltage id %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- return (reg & p->vmode) ? 3000000 : 1800000;
+}
+static int pbias_regulator_set_value(struct udevice *dev, int uV) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Setting %s voltage to %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (uV == 3000000)
reg |= p->vmode;
- else if (uV == 1800000)
reg &= ~p->vmode;
- else
return -EINVAL;
- return pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
+}
+static int pbias_regulator_get_enable(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s id %s\n", p->name,
(reg & p->enable_mask) == (p->disable_val) ? "on" : "off");
- return (reg & p->enable_mask) == (p->disable_val);
+}
+static int pbias_regulator_set_enable(struct udevice *dev, bool enable) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Turning %s %s\n", enable ? "on" : "off", p->name);
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- reg &= ~p->enable_mask;
- if (enable)
reg |= p->enable;
- else
reg |= p->disable_val;
- rc = pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (enable)
udelay(p->enable_time);
- return 0;
+}
+static const struct dm_regulator_ops pbias_regulator_ops = {
- .get_value = pbias_regulator_get_value,
- .set_value = pbias_regulator_set_value,
- .get_enable = pbias_regulator_get_enable,
- .set_enable = pbias_regulator_set_enable,
+};
+U_BOOT_DRIVER(pbias_regulator) = {
- .name = "pbias_regulator",
- .id = UCLASS_REGULATOR,
- .ops = &pbias_regulator_ops,
- .probe = pbias_regulator_probe,
+};

Hi Jaehoon,
On 01/08/2017 06:23, Jaehoon Chung wrote:
Dear JJ,
On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. The PBIAS cell is controlled by software.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
changes since v1:
- automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set
- use the dev_read_*() API to access the DT
drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 588e118..63e1122 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -158,6 +158,7 @@ config MMC_PCI config MMC_OMAP_HS bool "TI OMAP High Speed Multimedia Card Interface support" select DM_MMC_OPS if DM_MMC
- select DM_REGULATOR_PBIAS if DM_MMC && DM_REGULATOR help This selects the TI OMAP High Speed Multimedia card Interface. If you have an omap2plus board with a Multimedia Card slot,
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index f213487..f4ed3cc 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -142,6 +142,16 @@ config DM_REGULATOR_PALMAS features for REGULATOR PALMAS and the family of PALMAS PMICs. The driver implements get/set api for: value and enable.
+config DM_REGULATOR_PBIAS
- bool "Enable driver for PBIAS regulator"
pbias_regulator is using the regmap and syscon.. I think that i needs to select REGMAP and SYSCON at here.
So i dropped the your patch from my repository. Could you resend the patch? otherwise i will resend your patch after fixing. let me know what you want.
I won't be able to work on it before September. So I guess, it's better if you can make the changes. Thank you,
jean-Jacques
Best Regards, Jaehoon Chung
- ---help---
- This enables implementation of driver-model regulator uclass
- features for pseudo-regulator PBIAS found in the OMAP SOCs.
- This pseudo-regulator is used to provide a BIAS voltage to MMC1
- signal pads and must be configured properly during a voltage switch.
- Voltage switching is required by some operating modes of SDcards and
- eMMC.
- config DM_REGULATOR_LP873X bool "Enable driver for LP873X PMIC regulators" depends on PMIC_LP873X
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index ce14d08..75d611a 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,5 +17,6 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PBIAS) += pbias_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c new file mode 100644 index 0000000..303eca9 --- /dev/null +++ b/drivers/power/regulator/pbias_regulator.c @@ -0,0 +1,302 @@ +/*
- (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
- Jean-Jacques Hiblot jjhiblot@ti.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <errno.h> +#include <dm.h> +#include <power/pmic.h> +#include <power/regulator.h> +#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/ioport.h> +#include <dm/read.h>
+DECLARE_GLOBAL_DATA_PTR;
+struct pbias_reg_info {
- u32 enable;
- u32 enable_mask;
- u32 disable_val;
- u32 vmode;
- unsigned int enable_time;
- char *name;
+};
+struct pbias_priv {
- struct regmap *regmap;
- int offset;
+};
+static const struct pmic_child_info pmic_children_info[] = {
- { .prefix = "pbias", .driver = "pbias_regulator"},
- { },
+};
+static int pbias_write(struct udevice *dev, uint reg, const uint8_t *buff,
int len)
+{
- struct pbias_priv *priv = dev_get_priv(dev);
- uint32_t val = *(uint32_t *)buff;
- if (len != 4)
return -EINVAL;
- return regmap_write(priv->regmap, priv->offset, val);
+}
+static int pbias_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- if (len != 4)
return -EINVAL;
- return regmap_read(priv->regmap, priv->offset, (uint32_t *)buff);
+}
+static int pbias_ofdata_to_platdata(struct udevice *dev) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- struct udevice *syscon;
- struct regmap *regmap;
- struct resource res;
- int err;
- err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
"syscon", &syscon);
- if (err) {
error("%s: unable to find syscon device (%d)\n", __func__,
err);
return err;
- }
- regmap = syscon_get_regmap(syscon);
- if (IS_ERR(regmap)) {
error("%s: unable to find regmap (%ld)\n", __func__,
PTR_ERR(regmap));
return PTR_ERR(regmap);
- }
- priv->regmap = regmap;
- err = dev_read_resource(dev, 0, &res);
- if (err) {
error("%s: unable to find offset (%d)\n", __func__, err);
return err;
- }
- priv->offset = res.start;
- return 0;
+}
+static int pbias_bind(struct udevice *dev) +{
- int children;
- children = pmic_bind_children(dev, dev->node, pmic_children_info);
- if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
- return 0;
+}
+static struct dm_pmic_ops pbias_ops = {
- .read = pbias_read,
- .write = pbias_write,
+};
+static const struct udevice_id pbias_ids[] = {
- { .compatible = "ti,pbias-dra7" },
- { }
+};
+U_BOOT_DRIVER(pbias_pmic) = {
- .name = "pbias_pmic",
- .id = UCLASS_PMIC,
- .of_match = pbias_ids,
- .bind = pbias_bind,
- .ops = &pbias_ops,
- .ofdata_to_platdata = pbias_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct pbias_priv),
+};
+static const struct pbias_reg_info pbias_mmc_omap2430 = {
- .enable = BIT(1),
- .enable_mask = BIT(1),
- .vmode = BIT(0),
- .disable_val = 0,
- .enable_time = 100,
- .name = "pbias_mmc_omap2430"
+};
+static const struct pbias_reg_info pbias_sim_omap3 = {
- .enable = BIT(9),
- .enable_mask = BIT(9),
- .vmode = BIT(8),
- .enable_time = 100,
- .name = "pbias_sim_omap3"
+};
+static const struct pbias_reg_info pbias_mmc_omap4 = {
- .enable = BIT(26) | BIT(22),
- .enable_mask = BIT(26) | BIT(25) | BIT(22),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap4"
+};
+static const struct pbias_reg_info pbias_mmc_omap5 = {
- .enable = BIT(27) | BIT(26),
- .enable_mask = BIT(27) | BIT(25) | BIT(26),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap5"
+};
+static const struct pbias_reg_info *pbias_reg_infos[] = {
- &pbias_mmc_omap5,
- &pbias_mmc_omap4,
- &pbias_sim_omap3,
- &pbias_mmc_omap2430,
- NULL
+};
+static int pbias_regulator_probe(struct udevice *dev) +{
- const struct pbias_reg_info **p = pbias_reg_infos;
- struct dm_regulator_uclass_platdata *uc_pdata;
- uc_pdata = dev_get_uclass_platdata(dev);
- while (*p) {
int rc;
rc = dev_read_stringlist_search(dev, "regulator-name",
(*p)->name);
if (rc >= 0) {
debug("found regulator %s\n", (*p)->name);
break;
} else if (rc != -ENODATA) {
return rc;
}
p++;
- }
- if (!*p) {
int i = 0;
const char *s;
debug("regulator ");
while (dev_read_string_index(dev, "regulator-name", i++, &s) >= 0)
debug("%s'%s' ", (i > 1) ? ", " : "", s);
debug("%s not supported\n", (i > 2) ? "are" : "is");
return -EINVAL;
- }
- uc_pdata->type = REGULATOR_TYPE_OTHER;
- dev->priv = (void *)*p;
- return 0;
+}
+static int pbias_regulator_get_value(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s voltage id %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- return (reg & p->vmode) ? 3000000 : 1800000;
+}
+static int pbias_regulator_set_value(struct udevice *dev, int uV) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Setting %s voltage to %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (uV == 3000000)
reg |= p->vmode;
- else if (uV == 1800000)
reg &= ~p->vmode;
- else
return -EINVAL;
- return pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
+}
+static int pbias_regulator_get_enable(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s id %s\n", p->name,
(reg & p->enable_mask) == (p->disable_val) ? "on" : "off");
- return (reg & p->enable_mask) == (p->disable_val);
+}
+static int pbias_regulator_set_enable(struct udevice *dev, bool enable) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Turning %s %s\n", enable ? "on" : "off", p->name);
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- reg &= ~p->enable_mask;
- if (enable)
reg |= p->enable;
- else
reg |= p->disable_val;
- rc = pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (enable)
udelay(p->enable_time);
- return 0;
+}
+static const struct dm_regulator_ops pbias_regulator_ops = {
- .get_value = pbias_regulator_get_value,
- .set_value = pbias_regulator_set_value,
- .get_enable = pbias_regulator_get_enable,
- .set_enable = pbias_regulator_set_enable,
+};
+U_BOOT_DRIVER(pbias_regulator) = {
- .name = "pbias_regulator",
- .id = UCLASS_REGULATOR,
- .ops = &pbias_regulator_ops,
- .probe = pbias_regulator_probe,
+};

Hi JJ,
On 08/04/2017 09:26 PM, Jean-Jacques Hiblot wrote:
Hi Jaehoon,
On 01/08/2017 06:23, Jaehoon Chung wrote:
Dear JJ,
On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
In the TI SOCs a PBIAS cell exists to provide a bias voltage to the MMC1 IO cells. Without this bias voltage these I/O cells can not function properly. The PBIAS cell is controlled by software.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Simon Glass sjg@chromium.org
changes since v1:
- automatically select the PBIAS driver if DM_REGULATOR, DM_MMC and MMC_OMAP_HS are set
- use the dev_read_*() API to access the DT
drivers/mmc/Kconfig | 1 + drivers/power/regulator/Kconfig | 10 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pbias_regulator.c | 302 ++++++++++++++++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/power/regulator/pbias_regulator.c
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index 588e118..63e1122 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -158,6 +158,7 @@ config MMC_PCI config MMC_OMAP_HS bool "TI OMAP High Speed Multimedia Card Interface support" select DM_MMC_OPS if DM_MMC
- select DM_REGULATOR_PBIAS if DM_MMC && DM_REGULATOR help This selects the TI OMAP High Speed Multimedia card Interface. If you have an omap2plus board with a Multimedia Card slot,
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index f213487..f4ed3cc 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -142,6 +142,16 @@ config DM_REGULATOR_PALMAS features for REGULATOR PALMAS and the family of PALMAS PMICs. The driver implements get/set api for: value and enable. +config DM_REGULATOR_PBIAS
- bool "Enable driver for PBIAS regulator"
pbias_regulator is using the regmap and syscon.. I think that i needs to select REGMAP and SYSCON at here.
So i dropped the your patch from my repository. Could you resend the patch? otherwise i will resend your patch after fixing. let me know what you want.
I won't be able to work on it before September. So I guess, it's better if you can make the changes.
Sorry for reviewing late. If you resend the patch, i will pick this immediately.
Best Regards, Jaehoon Chung
Thank you,
jean-Jacques
Best Regards, Jaehoon Chung
- ---help---
- This enables implementation of driver-model regulator uclass
- features for pseudo-regulator PBIAS found in the OMAP SOCs.
- This pseudo-regulator is used to provide a BIAS voltage to MMC1
- signal pads and must be configured properly during a voltage switch.
- Voltage switching is required by some operating modes of SDcards and
- eMMC.
- config DM_REGULATOR_LP873X bool "Enable driver for LP873X PMIC regulators" depends on PMIC_LP873X
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index ce14d08..75d611a 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,5 +17,6 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o obj-$(CONFIG_DM_REGULATOR_SANDBOX) += sandbox.o obj-$(CONFIG_REGULATOR_TPS65090) += tps65090_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PALMAS) += palmas_regulator.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PBIAS) += pbias_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c new file mode 100644 index 0000000..303eca9 --- /dev/null +++ b/drivers/power/regulator/pbias_regulator.c @@ -0,0 +1,302 @@ +/*
- (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
- Jean-Jacques Hiblot jjhiblot@ti.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <errno.h> +#include <dm.h> +#include <power/pmic.h> +#include <power/regulator.h> +#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/ioport.h> +#include <dm/read.h>
+DECLARE_GLOBAL_DATA_PTR;
+struct pbias_reg_info {
- u32 enable;
- u32 enable_mask;
- u32 disable_val;
- u32 vmode;
- unsigned int enable_time;
- char *name;
+};
+struct pbias_priv {
- struct regmap *regmap;
- int offset;
+};
+static const struct pmic_child_info pmic_children_info[] = {
- { .prefix = "pbias", .driver = "pbias_regulator"},
- { },
+};
+static int pbias_write(struct udevice *dev, uint reg, const uint8_t *buff,
int len)
+{
- struct pbias_priv *priv = dev_get_priv(dev);
- uint32_t val = *(uint32_t *)buff;
- if (len != 4)
return -EINVAL;
- return regmap_write(priv->regmap, priv->offset, val);
+}
+static int pbias_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- if (len != 4)
return -EINVAL;
- return regmap_read(priv->regmap, priv->offset, (uint32_t *)buff);
+}
+static int pbias_ofdata_to_platdata(struct udevice *dev) +{
- struct pbias_priv *priv = dev_get_priv(dev);
- struct udevice *syscon;
- struct regmap *regmap;
- struct resource res;
- int err;
- err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
"syscon", &syscon);
- if (err) {
error("%s: unable to find syscon device (%d)\n", __func__,
err);
return err;
- }
- regmap = syscon_get_regmap(syscon);
- if (IS_ERR(regmap)) {
error("%s: unable to find regmap (%ld)\n", __func__,
PTR_ERR(regmap));
return PTR_ERR(regmap);
- }
- priv->regmap = regmap;
- err = dev_read_resource(dev, 0, &res);
- if (err) {
error("%s: unable to find offset (%d)\n", __func__, err);
return err;
- }
- priv->offset = res.start;
- return 0;
+}
+static int pbias_bind(struct udevice *dev) +{
- int children;
- children = pmic_bind_children(dev, dev->node, pmic_children_info);
- if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
- return 0;
+}
+static struct dm_pmic_ops pbias_ops = {
- .read = pbias_read,
- .write = pbias_write,
+};
+static const struct udevice_id pbias_ids[] = {
- { .compatible = "ti,pbias-dra7" },
- { }
+};
+U_BOOT_DRIVER(pbias_pmic) = {
- .name = "pbias_pmic",
- .id = UCLASS_PMIC,
- .of_match = pbias_ids,
- .bind = pbias_bind,
- .ops = &pbias_ops,
- .ofdata_to_platdata = pbias_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct pbias_priv),
+};
+static const struct pbias_reg_info pbias_mmc_omap2430 = {
- .enable = BIT(1),
- .enable_mask = BIT(1),
- .vmode = BIT(0),
- .disable_val = 0,
- .enable_time = 100,
- .name = "pbias_mmc_omap2430"
+};
+static const struct pbias_reg_info pbias_sim_omap3 = {
- .enable = BIT(9),
- .enable_mask = BIT(9),
- .vmode = BIT(8),
- .enable_time = 100,
- .name = "pbias_sim_omap3"
+};
+static const struct pbias_reg_info pbias_mmc_omap4 = {
- .enable = BIT(26) | BIT(22),
- .enable_mask = BIT(26) | BIT(25) | BIT(22),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap4"
+};
+static const struct pbias_reg_info pbias_mmc_omap5 = {
- .enable = BIT(27) | BIT(26),
- .enable_mask = BIT(27) | BIT(25) | BIT(26),
- .disable_val = BIT(25),
- .vmode = BIT(21),
- .enable_time = 100,
- .name = "pbias_mmc_omap5"
+};
+static const struct pbias_reg_info *pbias_reg_infos[] = {
- &pbias_mmc_omap5,
- &pbias_mmc_omap4,
- &pbias_sim_omap3,
- &pbias_mmc_omap2430,
- NULL
+};
+static int pbias_regulator_probe(struct udevice *dev) +{
- const struct pbias_reg_info **p = pbias_reg_infos;
- struct dm_regulator_uclass_platdata *uc_pdata;
- uc_pdata = dev_get_uclass_platdata(dev);
- while (*p) {
int rc;
rc = dev_read_stringlist_search(dev, "regulator-name",
(*p)->name);
if (rc >= 0) {
debug("found regulator %s\n", (*p)->name);
break;
} else if (rc != -ENODATA) {
return rc;
}
p++;
- }
- if (!*p) {
int i = 0;
const char *s;
debug("regulator ");
while (dev_read_string_index(dev, "regulator-name", i++, &s) >= 0)
debug("%s'%s' ", (i > 1) ? ", " : "", s);
debug("%s not supported\n", (i > 2) ? "are" : "is");
return -EINVAL;
- }
- uc_pdata->type = REGULATOR_TYPE_OTHER;
- dev->priv = (void *)*p;
- return 0;
+}
+static int pbias_regulator_get_value(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s voltage id %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- return (reg & p->vmode) ? 3000000 : 1800000;
+}
+static int pbias_regulator_set_value(struct udevice *dev, int uV) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Setting %s voltage to %s\n", p->name,
(reg & p->vmode) ? "3.0v" : "1.8v");
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (uV == 3000000)
reg |= p->vmode;
- else if (uV == 1800000)
reg &= ~p->vmode;
- else
return -EINVAL;
- return pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
+}
+static int pbias_regulator_get_enable(struct udevice *dev) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- debug("%s id %s\n", p->name,
(reg & p->enable_mask) == (p->disable_val) ? "on" : "off");
- return (reg & p->enable_mask) == (p->disable_val);
+}
+static int pbias_regulator_set_enable(struct udevice *dev, bool enable) +{
- const struct pbias_reg_info *p = dev_get_priv(dev);
- int rc;
- uint32_t reg;
- debug("Turning %s %s\n", enable ? "on" : "off", p->name);
- rc = pmic_read(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- reg &= ~p->enable_mask;
- if (enable)
reg |= p->enable;
- else
reg |= p->disable_val;
- rc = pmic_write(dev->parent, 0, (uint8_t *)®, sizeof(reg));
- if (rc)
return rc;
- if (enable)
udelay(p->enable_time);
- return 0;
+}
+static const struct dm_regulator_ops pbias_regulator_ops = {
- .get_value = pbias_regulator_get_value,
- .set_value = pbias_regulator_set_value,
- .get_enable = pbias_regulator_get_enable,
- .set_enable = pbias_regulator_set_enable,
+};
+U_BOOT_DRIVER(pbias_regulator) = {
- .name = "pbias_regulator",
- .id = UCLASS_REGULATOR,
- .ops = &pbias_regulator_ops,
- .probe = pbias_regulator_probe,
+};

This allow to probe devices that are defined under a syscon node
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
no changes since v1
drivers/core/syscon-uclass.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c index 2148469..b06ca6a 100644 --- a/drivers/core/syscon-uclass.c +++ b/drivers/core/syscon-uclass.c @@ -104,5 +104,6 @@ static const struct udevice_id generic_syscon_ids[] = { U_BOOT_DRIVER(generic_syscon) = { .name = "syscon", .id = UCLASS_SYSCON, + .bind = dm_scan_fdt_dev, .of_match = generic_syscon_ids, };

On 07/19/2017 10:52 PM, Jean-Jacques Hiblot wrote:
This allow to probe devices that are defined under a syscon node
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
Applied to u-boot-mmc. Thanks!
Best Regards, Jaehoon Chung
Reviewed-by: Simon Glass sjg@chromium.org
no changes since v1
drivers/core/syscon-uclass.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c index 2148469..b06ca6a 100644 --- a/drivers/core/syscon-uclass.c +++ b/drivers/core/syscon-uclass.c @@ -104,5 +104,6 @@ static const struct udevice_id generic_syscon_ids[] = { U_BOOT_DRIVER(generic_syscon) = { .name = "syscon", .id = UCLASS_SYSCON,
- .bind = dm_scan_fdt_dev, .of_match = generic_syscon_ids,
};
participants (2)
-
Jaehoon Chung
-
Jean-Jacques Hiblot