diff mbox

[U-Boot,07/19] dm: pmic: add max77686 pmic driver

Message ID 1412801335-1591-8-git-send-email-p.marczak@samsung.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Przemyslaw Marczak Oct. 8, 2014, 8:48 p.m. UTC
This adds a simple implementation of driver model uclass pmic driver.
This implementation includes two funcitons:
- max77686_ofdata_to_platdada(...) - init I/O data from fdt
- max77686_probe(...) - looks for max77686 regulator driver and bind it

If there is no regulator driver, then pmic can still provide read/write
operations, and can be accessed by 'pmic' commands.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
---
 drivers/power/pmic/Makefile   |  1 +
 drivers/power/pmic/max77686.c | 89 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 drivers/power/pmic/max77686.c

Comments

Tom Rini Oct. 22, 2014, 3:31 p.m. UTC | #1
On Wed, Oct 08, 2014 at 10:48:43PM +0200, Przemyslaw Marczak wrote:

> This adds a simple implementation of driver model uclass pmic driver.
> This implementation includes two funcitons:
> - max77686_ofdata_to_platdada(...) - init I/O data from fdt
> - max77686_probe(...) - looks for max77686 regulator driver and bind it
> 
> If there is no regulator driver, then pmic can still provide read/write
> operations, and can be accessed by 'pmic' commands.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
[snip]
> +	parent = fdt_parent_offset(blob, node);
> +
> +	if (parent < 0) {
> +		error("%s: Cannot find node parent", __func__);
> +		return -EINVAL;
> +	}
> +
> +	pl->bus = i2c_get_bus_num_fdt(parent);
> +	if (pl->bus < 0) {
> +		debug("%s: Cannot find bus num\n", __func__);
> +		return -EINVAL;
> +	}

Both of those should be error() and please note (and fix globally!) that
error() already has __FILE__, __LINE__ and __func__ so you can drop
those duplications.

Otherwise:

Reviewed-by: Tom Rini <trini@ti.com>
diff mbox

Patch

diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index e7b07eb..49beffb 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -10,6 +10,7 @@  obj-$(CONFIG_POWER_MAX8998) += pmic_max8998.o
 obj-$(CONFIG_POWER_MAX8997) += pmic_max8997.o
 obj-$(CONFIG_POWER_MUIC_MAX8997) += muic_max8997.o
 obj-$(CONFIG_POWER_MAX77686) += pmic_max77686.o
+obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_POWER_PFUZE100) += pmic_pfuze100.o
 obj-$(CONFIG_POWER_TPS65090_I2C) += pmic_tps65090.o
 obj-$(CONFIG_POWER_TPS65090_EC) += pmic_tps65090_ec.o
diff --git a/drivers/power/pmic/max77686.c b/drivers/power/pmic/max77686.c
new file mode 100644
index 0000000..74b10da
--- /dev/null
+++ b/drivers/power/pmic/max77686.c
@@ -0,0 +1,89 @@ 
+/*
+ *  Copyright (C) 2012 Samsung Electronics
+ *  Rajeshwari Shinde <rajeshwari.s@samsung.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <i2c.h>
+#include <power/pmic.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <dm/root.h>
+#include <dm/lists.h>
+#include <power/max77686_pmic.h>
+#include <errno.h>
+#include <dm.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int max77686_ofdata_to_platdata(struct udevice *dev)
+{
+	struct pmic_platdata *pl = dev->platdata;
+	const void *blob = gd->fdt_blob;
+	int node = dev->of_offset;
+	int parent;
+
+	pl->interface = PMIC_I2C;
+	pl->regs_num = PMIC_NUM_OF_REGS;
+
+	parent = fdt_parent_offset(blob, node);
+
+	if (parent < 0) {
+		error("%s: Cannot find node parent", __func__);
+		return -EINVAL;
+	}
+
+	pl->bus = i2c_get_bus_num_fdt(parent);
+	if (pl->bus < 0) {
+		debug("%s: Cannot find bus num\n", __func__);
+		return -EINVAL;
+	}
+
+	pl->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", MAX77686_I2C_ADDR);
+	pl->hw.i2c.tx_num = 1;
+
+	return 0;
+}
+
+static int max77686_probe(struct udevice *parent)
+{
+	struct udevice *reg_dev;
+	struct driver *reg_drv;
+	int ret;
+
+	reg_drv = lists_driver_lookup_name("max77686 regulator");
+	if (!reg_drv) {
+		error("%s regulator driver not found!\n", parent->name);
+		return 0;
+	}
+
+	if (!parent->platdata) {
+		error("%s platdata not found!\n", parent->name);
+		return -EINVAL;
+	}
+
+	ret = device_bind(parent, reg_drv, parent->name, parent->platdata,
+			  parent->of_offset, &reg_dev);
+	if (ret)
+		error("%s regulator bind failed", parent->name);
+
+	/* Return error only if no parent platdata set */
+	return 0;
+}
+
+static const struct udevice_id max77686_ids[] = {
+	{ .compatible = "maxim,max77686_pmic"},
+	{ }
+};
+
+U_BOOT_DRIVER(pmic_max77686) = {
+	.name = "max77686 pmic",
+	.id = UCLASS_PMIC,
+	.of_match = max77686_ids,
+	.probe = max77686_probe,
+	.ofdata_to_platdata = max77686_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct pmic_platdata),
+};