dm: pmic: Convert uclass to livetree

Update the pmic uclass and all pmics to support a live device tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2017-05-18 20:09:32 -06:00
parent f6e76202d4
commit 7a869e6cd1
11 changed files with 42 additions and 59 deletions

View File

@ -48,13 +48,11 @@ static int act8846_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int act8846_bind(struct udevice *dev) static int act8846_bind(struct udevice *dev)
{ {
const void *blob = gd->fdt_blob; ofnode regulators_node;
int regulators_node;
int children; int children;
regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev), regulators_node = dev_read_subnode(dev, "regulators");
"regulators"); if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -46,15 +46,13 @@ static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int lp873x_bind(struct udevice *dev) static int lp873x_bind(struct udevice *dev)
{ {
int regulators_node; ofnode regulators_node;
const void *blob = gd->fdt_blob;
int children; int children;
int node = dev_of_offset(dev);
regulators_node = fdt_subnode_offset(blob, node, "regulators"); regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) { debug("%s: %s regulators subnode not found!", __func__,
printf("%s: %s reg subnode not found!", __func__, dev->name); dev->name);
return -ENXIO; return -ENXIO;
} }

View File

@ -50,13 +50,11 @@ static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int max77686_bind(struct udevice *dev) static int max77686_bind(struct udevice *dev)
{ {
int regulators_node; ofnode regulators_node;
const void *blob = gd->fdt_blob;
int children; int children;
regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev), regulators_node = dev_read_subnode(dev, "voltage-regulators");
"voltage-regulators"); if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -46,17 +46,15 @@ static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int palmas_bind(struct udevice *dev) static int palmas_bind(struct udevice *dev)
{ {
int pmic_node = -1, regulators_node; ofnode pmic_node = ofnode_null(), regulators_node;
const void *blob = gd->fdt_blob; ofnode subnode;
int children; int children;
int node = dev_of_offset(dev);
int subnode, len;
fdt_for_each_subnode(subnode, blob, node) { dev_for_each_subnode(subnode, dev) {
const char *name; const char *name;
char *temp; char *temp;
name = fdt_get_name(blob, subnode, &len); name = ofnode_get_name(subnode);
temp = strstr(name, "pmic"); temp = strstr(name, "pmic");
if (temp) { if (temp) {
pmic_node = subnode; pmic_node = subnode;
@ -64,14 +62,14 @@ static int palmas_bind(struct udevice *dev)
} }
} }
if (pmic_node <= 0) { if (!ofnode_valid(pmic_node)) {
debug("%s: %s pmic subnode not found!", __func__, dev->name); debug("%s: %s pmic subnode not found!", __func__, dev->name);
return -ENXIO; return -ENXIO;
} }
regulators_node = fdt_subnode_offset(blob, pmic_node, "regulators"); regulators_node = ofnode_find_subnode(pmic_node, "regulators");
if (regulators_node <= 0) { if (!ofnode_valid(regulators_node)) {
debug("%s: %s reg subnode not found!", __func__, dev->name); debug("%s: %s reg subnode not found!", __func__, dev->name);
return -ENXIO; return -ENXIO;
} }

View File

@ -52,13 +52,11 @@ static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int pfuze100_bind(struct udevice *dev) static int pfuze100_bind(struct udevice *dev)
{ {
ofnode regulators_node;
int children; int children;
int regulators_node;
const void *blob = gd->fdt_blob;
regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev), regulators_node = dev_read_subnode(dev, "regulators");
"regulators"); if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -19,29 +19,27 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
#if CONFIG_IS_ENABLED(PMIC_CHILDREN) #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
int pmic_bind_children(struct udevice *pmic, int offset, int pmic_bind_children(struct udevice *pmic, ofnode parent,
const struct pmic_child_info *child_info) const struct pmic_child_info *child_info)
{ {
const struct pmic_child_info *info; const struct pmic_child_info *info;
const void *blob = gd->fdt_blob;
struct driver *drv; struct driver *drv;
struct udevice *child; struct udevice *child;
const char *node_name; const char *node_name;
int bind_count = 0; int bind_count = 0;
int node; ofnode node;
int prefix_len; int prefix_len;
int ret; int ret;
debug("%s for '%s' at node offset: %d\n", __func__, pmic->name, debug("%s for '%s' at node offset: %d\n", __func__, pmic->name,
dev_of_offset(pmic)); dev_of_offset(pmic));
for (node = fdt_first_subnode(blob, offset); for (node = ofnode_first_subnode(parent);
node > 0; ofnode_valid(node);
node = fdt_next_subnode(blob, node)) { node = ofnode_next_subnode(node)) {
node_name = fdt_get_name(blob, node, NULL); node_name = ofnode_get_name(node);
debug("* Found child node: '%s' at offset:%d\n", node_name, debug("* Found child node: '%s'\n", node_name);
node);
child = NULL; child = NULL;
for (info = child_info; info->prefix && info->driver; info++) { for (info = child_info; info->prefix && info->driver; info++) {
@ -60,8 +58,8 @@ int pmic_bind_children(struct udevice *pmic, int offset,
debug(" - found child driver: '%s'\n", drv->name); debug(" - found child driver: '%s'\n", drv->name);
ret = device_bind(pmic, drv, node_name, NULL, ret = device_bind_with_driver_data(pmic, drv, node_name,
node, &child); 0, node, &child);
if (ret) { if (ret) {
debug(" - child binding error: %d\n", ret); debug(" - child binding error: %d\n", ret);
continue; continue;
@ -82,7 +80,7 @@ int pmic_bind_children(struct udevice *pmic, int offset,
debug(" - compatible prefix not found\n"); debug(" - compatible prefix not found\n");
} }
debug("Bound: %d childs for PMIC: '%s'\n", bind_count, pmic->name); debug("Bound: %d children for PMIC: '%s'\n", bind_count, pmic->name);
return bind_count; return bind_count;
} }
#endif #endif

View File

@ -57,13 +57,11 @@ static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
#if CONFIG_IS_ENABLED(PMIC_CHILDREN) #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
static int rk8xx_bind(struct udevice *dev) static int rk8xx_bind(struct udevice *dev)
{ {
const void *blob = gd->fdt_blob; ofnode regulators_node;
int regulators_node;
int children; int children;
regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev), regulators_node = dev_read_subnode(dev, "regulators");
"regulators"); if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -54,12 +54,11 @@ int s5m8767_enable_32khz_cp(struct udevice *dev)
static int s5m8767_bind(struct udevice *dev) static int s5m8767_bind(struct udevice *dev)
{ {
int node;
const void *blob = gd->fdt_blob;
int children; int children;
ofnode node;
node = fdt_subnode_offset(blob, dev_of_offset(dev), "regulators"); node = dev_read_subnode(dev, "regulators");
if (node <= 0) { if (!ofnode_valid(node)) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -51,7 +51,7 @@ static int sandbox_pmic_read(struct udevice *dev, uint reg,
static int sandbox_pmic_bind(struct udevice *dev) static int sandbox_pmic_bind(struct udevice *dev)
{ {
if (!pmic_bind_children(dev, dev_of_offset(dev), pmic_children_info)) if (!pmic_bind_children(dev, dev_ofnode(dev), pmic_children_info))
error("%s:%d PMIC: %s - no child found!", __func__, __LINE__, error("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
dev->name); dev->name);

View File

@ -52,13 +52,11 @@ static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
static int tps65090_bind(struct udevice *dev) static int tps65090_bind(struct udevice *dev)
{ {
int regulators_node; ofnode regulators_node;
const void *blob = gd->fdt_blob;
int children; int children;
regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev), regulators_node = dev_read_subnode(dev, "regulators");
"regulators"); if (!ofnode_valid(regulators_node)) {
if (regulators_node <= 0) {
debug("%s: %s regulators subnode not found!", __func__, debug("%s: %s regulators subnode not found!", __func__,
dev->name); dev->name);
return -ENXIO; return -ENXIO;

View File

@ -226,7 +226,7 @@ struct pmic_child_info {
* buck2 { ... }; * buck2 { ... };
* }; * };
*/ */
int pmic_bind_children(struct udevice *pmic, int offset, int pmic_bind_children(struct udevice *pmic, ofnode parent,
const struct pmic_child_info *child_info); const struct pmic_child_info *child_info);
/** /**