summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPrzemyslaw Marczak <p.marczak@samsung.com>2015-04-20 20:07:41 +0200
committerSimon Glass <sjg@chromium.org>2015-05-14 18:49:37 -0600
commit4d9057e82be11a862db411c4867e859fe0d4ca2a (patch)
treecb1b6f70f1cbc80bc922dc2187241244c3e0a192 /drivers
parent6501ff6251d472177c68d628fe34ca03cb7f2287 (diff)
downloadtalos-obmc-uboot-4d9057e82be11a862db411c4867e859fe0d4ca2a.tar.gz
talos-obmc-uboot-4d9057e82be11a862db411c4867e859fe0d4ca2a.zip
dm: pmic: add implementation of driver model pmic uclass
This commit introduces the PMIC uclass implementation. It allows providing the basic I/O interface for PMIC devices. For the multi-function PMIC devices, this can be used as I/O parent device, for each IC's interface. Then, each PMIC particular function can be provided by the child device's operations, and the child devices will use its parent for read/write by the common API. Core files: - 'include/power/pmic.h' - 'drivers/power/pmic/pmic-uclass.c' The old pmic framework is still kept and is independent. For more detailed informations, please look into the header file. Changes: - new uclass-id: UCLASS_PMIC - new config: CONFIG_DM_PMIC Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/pmic/Kconfig11
-rw-r--r--drivers/power/pmic/Makefile1
-rw-r--r--drivers/power/pmic/pmic-uclass.c158
4 files changed, 176 insertions, 0 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f8f0239484..d03626e89c 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -1,3 +1,7 @@
+menu "Power"
+
+source "drivers/power/pmic/Kconfig"
+
config AXP221_POWER
boolean "axp221 / axp223 pmic support"
depends on MACH_SUN6I || MACH_SUN8I
@@ -73,3 +77,5 @@ config AXP221_ELDO3_VOLT
disable eldo3. On some A31(s) tablets it might be used to supply
1.2V for the SSD2828 chip (converter of parallel LCD interface
into MIPI DSI).
+
+endmenu
diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
new file mode 100644
index 0000000000..d06d632e89
--- /dev/null
+++ b/drivers/power/pmic/Kconfig
@@ -0,0 +1,11 @@
+config DM_PMIC
+ bool "Enable Driver Model for PMIC drivers (UCLASS_PMIC)"
+ depends on DM
+ ---help---
+ This config enables the driver-model PMIC support.
+ UCLASS_PMIC - designed to provide an I/O interface for PMIC devices.
+ For the multi-function PMIC devices, this can be used as parent I/O
+ device for each IC's interface. Then, each children uses its parent
+ for read/write. For detailed description, please refer to the files:
+ - 'drivers/power/pmic/pmic-uclass.c'
+ - 'include/power/pmic.h'
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 985cfdb901..594f620218 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_DM_PMIC) += pmic-uclass.o
obj-$(CONFIG_POWER_LTC3676) += pmic_ltc3676.o
obj-$(CONFIG_POWER_MAX8998) += pmic_max8998.o
obj-$(CONFIG_POWER_MAX8997) += pmic_max8997.o
diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c
new file mode 100644
index 0000000000..d82d3da51d
--- /dev/null
+++ b/drivers/power/pmic/pmic-uclass.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/ctype.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static ulong str_get_num(const char *ptr, const char *maxptr)
+{
+ if (!ptr || !maxptr)
+ return 0;
+
+ while (!isdigit(*ptr) && ptr++ < maxptr);
+
+ return simple_strtoul(ptr, NULL, 0);
+}
+
+int pmic_bind_childs(struct udevice *pmic, int offset,
+ const struct pmic_child_info *child_info)
+{
+ const struct pmic_child_info *info;
+ const void *blob = gd->fdt_blob;
+ struct driver *drv;
+ struct udevice *child;
+ const char *node_name;
+ int node_name_len;
+ int bind_count = 0;
+ int node;
+ int prefix_len;
+ int ret;
+
+ debug("%s for '%s' at node offset: %d\n", __func__, pmic->name,
+ pmic->of_offset);
+
+ for (node = fdt_first_subnode(blob, offset);
+ node > 0;
+ node = fdt_next_subnode(blob, node)) {
+ node_name = fdt_get_name(blob, node, &node_name_len);
+
+ debug("* Found child node: '%s' at offset:%d\n", node_name,
+ node);
+
+ child = NULL;
+ info = child_info;
+ while (info->prefix) {
+ prefix_len = strlen(info->prefix);
+ if (strncasecmp(info->prefix, node_name, prefix_len) ||
+ !info->driver) {
+ info++;
+ continue;
+ }
+
+ debug(" - compatible prefix: '%s'\n", info->prefix);
+
+ drv = lists_driver_lookup_name(info->driver);
+ if (!drv) {
+ debug(" - driver: '%s' not found!\n",
+ info->driver);
+ continue;
+ }
+
+ debug(" - found child driver: '%s'\n", drv->name);
+
+ ret = device_bind(pmic, drv, node_name, NULL,
+ node, &child);
+ if (ret) {
+ debug(" - child binding error: %d\n", ret);
+ continue;
+ }
+
+ debug(" - bound child device: '%s'\n", child->name);
+
+ child->driver_data = str_get_num(node_name +
+ prefix_len,
+ node_name +
+ node_name_len);
+
+ debug(" - set 'child->driver_data': %lu\n",
+ child->driver_data);
+ break;
+ }
+
+ if (child)
+ bind_count++;
+ else
+ debug(" - compatible prefix not found\n");
+ }
+
+ debug("Bound: %d childs for PMIC: '%s'\n", bind_count, pmic->name);
+ return bind_count;
+}
+
+int pmic_get(const char *name, struct udevice **devp)
+{
+ return uclass_get_device_by_name(UCLASS_PMIC, name, devp);
+}
+
+int pmic_reg_count(struct udevice *dev)
+{
+ const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
+ if (!ops)
+ return -ENOSYS;
+
+ return ops->reg_count;
+}
+
+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;
+
+ if (!ops || !ops->read)
+ return -ENOSYS;
+
+ ret = ops->read(dev, reg, buffer, len);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+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;
+
+ if (!ops || !ops->write)
+ return -ENOSYS;
+
+ ret = ops->write(dev, reg, buffer, len);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+UCLASS_DRIVER(pmic) = {
+ .id = UCLASS_PMIC,
+ .name = "pmic",
+};
OpenPOWER on IntegriCloud