From f415a3ec9dfafc887ddf34aee0c579fc948c5740 Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Wed, 13 May 2015 13:38:26 +0200 Subject: dm: pmic: code cleanup of PMIC uclass driver The cleanup includes: - pmic.h - fix mistakes in a few comments - pmic operations: value 'reg_count' - redefine as function call - fix function name: pmic_bind_childs() -> pmic_bind_children() - pmic_bind_children: change the 'while' loop with the 'for' - add implementation of pmic_reg_count() method - pmic_bind_children() - update function call name - Kconfig: add new line at the end of file - Update MAX77686 driver code Signed-off-by: Przemyslaw Marczak Acked-by: Simon Glass Tested on sandbox: Tested-by: Simon Glass --- drivers/power/pmic/Kconfig | 2 +- drivers/power/pmic/max77686.c | 15 ++++++++++----- drivers/power/pmic/pmic-uclass.c | 31 +++++++++---------------------- 3 files changed, 20 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index af68783987..d99d9e3a06 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -15,4 +15,4 @@ config DM_PMIC_MAX77686 depends on DM_PMIC ---help--- This config enables implementation of driver-model pmic uclass features - for PMIC MAX77686. The driver implements read/write operations. \ No newline at end of file + for PMIC MAX77686. The driver implements read/write operations. diff --git a/drivers/power/pmic/max77686.c b/drivers/power/pmic/max77686.c index e9503e24a4..3523b4a2de 100644 --- a/drivers/power/pmic/max77686.c +++ b/drivers/power/pmic/max77686.c @@ -16,12 +16,17 @@ DECLARE_GLOBAL_DATA_PTR; -static const struct pmic_child_info pmic_childs_info[] = { +static const struct pmic_child_info pmic_children_info[] = { { .prefix = "ldo", .driver = MAX77686_LDO_DRIVER }, { .prefix = "buck", .driver = MAX77686_BUCK_DRIVER }, { }, }; +static int max77686_reg_count(struct udevice *dev) +{ + return MAX77686_NUM_OF_REGS; +} + static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff, int len) { @@ -47,7 +52,7 @@ static int max77686_bind(struct udevice *dev) { int regulators_node; const void *blob = gd->fdt_blob; - int childs; + int children; regulators_node = fdt_subnode_offset(blob, dev->of_offset, "voltage-regulators"); @@ -59,8 +64,8 @@ static int max77686_bind(struct udevice *dev) debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); - childs = pmic_bind_childs(dev, regulators_node, pmic_childs_info); - if (!childs) + children = pmic_bind_children(dev, regulators_node, pmic_children_info); + if (!children) debug("%s: %s - no child found\n", __func__, dev->name); /* Always return success for this device */ @@ -68,7 +73,7 @@ static int max77686_bind(struct udevice *dev) } static struct dm_pmic_ops max77686_ops = { - .reg_count = MAX77686_NUM_OF_REGS, + .reg_count = max77686_reg_count, .read = max77686_read, .write = max77686_write, }; diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c index d82d3da51d..812ac13baa 100644 --- a/drivers/power/pmic/pmic-uclass.c +++ b/drivers/power/pmic/pmic-uclass.c @@ -27,8 +27,8 @@ static ulong str_get_num(const char *ptr, const char *maxptr) return simple_strtoul(ptr, NULL, 0); } -int pmic_bind_childs(struct udevice *pmic, int offset, - const struct pmic_child_info *child_info) +int pmic_bind_children(struct udevice *pmic, int offset, + const struct pmic_child_info *child_info) { const struct pmic_child_info *info; const void *blob = gd->fdt_blob; @@ -53,14 +53,10 @@ int pmic_bind_childs(struct udevice *pmic, int offset, node); child = NULL; - info = child_info; - while (info->prefix) { + for (info = child_info; info->prefix && info->driver; info++) { prefix_len = strlen(info->prefix); - if (strncasecmp(info->prefix, node_name, prefix_len) || - !info->driver) { - info++; + if (strncasecmp(info->prefix, node_name, prefix_len)) continue; - } debug(" - compatible prefix: '%s'\n", info->prefix); @@ -110,16 +106,16 @@ int pmic_get(const char *name, struct udevice **devp) int pmic_reg_count(struct udevice *dev) { const struct dm_pmic_ops *ops = dev_get_driver_ops(dev); - if (!ops) + + if (!ops || !ops->reg_count) return -ENOSYS; - return ops->reg_count; + return ops->reg_count(dev); } int pmic_read(struct udevice *dev, uint reg, uint8_t *buffer, int len) { const struct dm_pmic_ops *ops = dev_get_driver_ops(dev); - int ret; if (!buffer) return -EFAULT; @@ -127,17 +123,12 @@ int pmic_read(struct udevice *dev, uint reg, uint8_t *buffer, int len) if (!ops || !ops->read) return -ENOSYS; - ret = ops->read(dev, reg, buffer, len); - if (ret) - return ret; - - return 0; + return ops->read(dev, reg, buffer, len); } int pmic_write(struct udevice *dev, uint reg, const uint8_t *buffer, int len) { const struct dm_pmic_ops *ops = dev_get_driver_ops(dev); - int ret; if (!buffer) return -EFAULT; @@ -145,11 +136,7 @@ int pmic_write(struct udevice *dev, uint reg, const uint8_t *buffer, int len) if (!ops || !ops->write) return -ENOSYS; - ret = ops->write(dev, reg, buffer, len); - if (ret) - return ret; - - return 0; + return ops->write(dev, reg, buffer, len); } UCLASS_DRIVER(pmic) = { -- cgit v1.2.3