Commit e5480bdc authored by Rob Herring's avatar Rob Herring Committed by Michael Ellerman

powerpc: Use device_type helpers to access the node type

Remove directly accessing device_node.type pointer and use the
accessors instead. This will eventually allow removing the type
pointer.

Replace the open coded iterating over child nodes with
for_each_child_of_node() while we're here.
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 5b8d6be7
...@@ -428,7 +428,7 @@ static void link_cache_lists(struct cache *smaller, struct cache *bigger) ...@@ -428,7 +428,7 @@ static void link_cache_lists(struct cache *smaller, struct cache *bigger)
static void do_subsidiary_caches_debugcheck(struct cache *cache) static void do_subsidiary_caches_debugcheck(struct cache *cache)
{ {
WARN_ON_ONCE(cache->level != 1); WARN_ON_ONCE(cache->level != 1);
WARN_ON_ONCE(strcmp(cache->ofnode->type, "cpu")); WARN_ON_ONCE(!of_node_is_type(cache->ofnode, "cpu"));
} }
static void do_subsidiary_caches(struct cache *cache) static void do_subsidiary_caches(struct cache *cache)
......
...@@ -327,8 +327,7 @@ static int isa_bridge_notify(struct notifier_block *nb, unsigned long action, ...@@ -327,8 +327,7 @@ static int isa_bridge_notify(struct notifier_block *nb, unsigned long action,
/* Check if we have no ISA device, and this happens to be one, /* Check if we have no ISA device, and this happens to be one,
* register it as such if it has an OF device * register it as such if it has an OF device
*/ */
if (!isa_bridge_devnode && devnode && devnode->type && if (!isa_bridge_devnode && of_node_is_type(devnode, "isa"))
!strcmp(devnode->type, "isa"))
isa_bridge_find_late(pdev, devnode); isa_bridge_find_late(pdev, devnode);
return 0; return 0;
......
...@@ -192,7 +192,7 @@ static int __init add_legacy_soc_port(struct device_node *np, ...@@ -192,7 +192,7 @@ static int __init add_legacy_soc_port(struct device_node *np,
/* Add port, irq will be dealt with later. We passed a translated /* Add port, irq will be dealt with later. We passed a translated
* IO port value. It will be fixed up later along with the irq * IO port value. It will be fixed up later along with the irq
*/ */
if (tsi && !strcmp(tsi->type, "tsi-bridge")) if (of_node_is_type(tsi, "tsi-bridge"))
return add_legacy_port(np, -1, UPIO_TSI, addr, addr, return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
0, legacy_port_flags, 0); 0, legacy_port_flags, 0);
else else
...@@ -417,7 +417,8 @@ void __init find_legacy_serial_ports(void) ...@@ -417,7 +417,8 @@ void __init find_legacy_serial_ports(void)
of_node_put(parent); of_node_put(parent);
continue; continue;
} }
if (strcmp(np->name, "serial") && strcmp(np->type, "serial")) { if (strcmp(np->name, "serial") &&
!of_node_is_type(np, "serial")) {
of_node_put(parent); of_node_put(parent);
continue; continue;
} }
......
...@@ -125,16 +125,13 @@ struct pci_dev *of_create_pci_dev(struct device_node *node, ...@@ -125,16 +125,13 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
struct pci_bus *bus, int devfn) struct pci_bus *bus, int devfn)
{ {
struct pci_dev *dev; struct pci_dev *dev;
const char *type;
dev = pci_alloc_dev(bus); dev = pci_alloc_dev(bus);
if (!dev) if (!dev)
return NULL; return NULL;
type = of_get_property(node, "device_type", NULL);
if (type == NULL)
type = "";
pr_debug(" create device, devfn: %x, type: %s\n", devfn, type); pr_debug(" create device, devfn: %x, type: %s\n", devfn,
of_node_get_device_type(node));
dev->dev.of_node = of_node_get(node); dev->dev.of_node = of_node_get(node);
dev->dev.parent = bus->bridge; dev->dev.parent = bus->bridge;
...@@ -167,12 +164,12 @@ struct pci_dev *of_create_pci_dev(struct device_node *node, ...@@ -167,12 +164,12 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
/* Early fixups, before probing the BARs */ /* Early fixups, before probing the BARs */
pci_fixup_device(pci_fixup_early, dev); pci_fixup_device(pci_fixup_early, dev);
if (!strcmp(type, "pci") || !strcmp(type, "pciex")) { if (of_node_is_type(node, "pci") || of_node_is_type(node, "pciex")) {
/* a PCI-PCI bridge */ /* a PCI-PCI bridge */
dev->hdr_type = PCI_HEADER_TYPE_BRIDGE; dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
dev->rom_base_reg = PCI_ROM_ADDRESS1; dev->rom_base_reg = PCI_ROM_ADDRESS1;
set_pcie_hotplug_bridge(dev); set_pcie_hotplug_bridge(dev);
} else if (!strcmp(type, "cardbus")) { } else if (of_node_is_type(node, "cardbus")) {
dev->hdr_type = PCI_HEADER_TYPE_CARDBUS; dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
} else { } else {
dev->hdr_type = PCI_HEADER_TYPE_NORMAL; dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
......
...@@ -687,7 +687,7 @@ int check_legacy_ioport(unsigned long base_port) ...@@ -687,7 +687,7 @@ int check_legacy_ioport(unsigned long base_port)
return ret; return ret;
parent = of_get_parent(np); parent = of_get_parent(np);
if (parent) { if (parent) {
if (strcmp(parent->type, "isa") == 0) if (of_node_is_type(parent, "isa"))
ret = 0; ret = 0;
of_node_put(parent); of_node_put(parent);
} }
......
...@@ -1475,7 +1475,7 @@ static int dt_update_callback(struct notifier_block *nb, ...@@ -1475,7 +1475,7 @@ static int dt_update_callback(struct notifier_block *nb,
switch (action) { switch (action) {
case OF_RECONFIG_UPDATE_PROPERTY: case OF_RECONFIG_UPDATE_PROPERTY:
if (!of_prop_cmp(update->dn->type, "cpu") && if (of_node_is_type(update->dn, "cpu") &&
!of_prop_cmp(update->prop->name, "ibm,associativity")) { !of_prop_cmp(update->prop->name, "ibm,associativity")) {
u32 core_id; u32 core_id;
of_property_read_u32(update->dn, "reg", &core_id); of_property_read_u32(update->dn, "reg", &core_id);
......
...@@ -2081,7 +2081,6 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np) ...@@ -2081,7 +2081,6 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
const u32 *pval; const u32 *pval;
int portno; int portno;
unsigned int dcrs; unsigned int dcrs;
const char *val;
/* First, proceed to core initialization as we assume there's /* First, proceed to core initialization as we assume there's
* only one PCIe core in the system * only one PCIe core in the system
...@@ -2127,10 +2126,9 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np) ...@@ -2127,10 +2126,9 @@ static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
* Resulting from this setup this PCIe port will be configured * Resulting from this setup this PCIe port will be configured
* as root-complex or as endpoint. * as root-complex or as endpoint.
*/ */
val = of_get_property(port->node, "device_type", NULL); if (of_node_is_type(port->node, "pci-endpoint")) {
if (!strcmp(val, "pci-endpoint")) {
port->endpoint = 1; port->endpoint = 1;
} else if (!strcmp(val, "pci")) { } else if (of_node_is_type(port->node, "pci")) {
port->endpoint = 0; port->endpoint = 0;
} else { } else {
printk(KERN_ERR "PCIE: missing or incorrect device_type for %pOF\n", printk(KERN_ERR "PCIE: missing or incorrect device_type for %pOF\n",
......
...@@ -53,7 +53,7 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np) ...@@ -53,7 +53,7 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np)
int i; int i;
struct device_node *tmp_np; struct device_node *tmp_np;
if (strcasecmp(np->type, "spe")) { if (!of_node_is_type(np, "spe")) {
for (i = 0; i < cbe_regs_map_count; i++) for (i = 0; i < cbe_regs_map_count; i++)
if (cbe_regs_maps[i].cpu_node == np || if (cbe_regs_maps[i].cpu_node == np ||
cbe_regs_maps[i].be_node == np) cbe_regs_maps[i].be_node == np)
...@@ -70,8 +70,8 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np) ...@@ -70,8 +70,8 @@ static struct cbe_regs_map *cbe_find_map(struct device_node *np)
tmp_np = tmp_np->parent; tmp_np = tmp_np->parent;
/* on a correct devicetree we wont get up to root */ /* on a correct devicetree we wont get up to root */
BUG_ON(!tmp_np); BUG_ON(!tmp_np);
} while (strcasecmp(tmp_np->type, "cpu") && } while (!of_node_is_type(tmp_np, "cpu") ||
strcasecmp(tmp_np->type, "be")); !of_node_is_type(tmp_np, "be"));
np->data = cbe_find_map(tmp_np); np->data = cbe_find_map(tmp_np);
......
...@@ -168,8 +168,7 @@ static int __init cell_publish_devices(void) ...@@ -168,8 +168,7 @@ static int __init cell_publish_devices(void)
* platform devices for the PCI host bridges * platform devices for the PCI host bridges
*/ */
for_each_child_of_node(root, np) { for_each_child_of_node(root, np) {
if (np->type == NULL || (strcmp(np->type, "pci") != 0 && if (!of_node_is_type(np, "pci") && !of_node_is_type(np, "pciex"))
strcmp(np->type, "pciex") != 0))
continue; continue;
of_platform_device_create(np, NULL, NULL); of_platform_device_create(np, NULL, NULL);
} }
......
...@@ -230,8 +230,8 @@ chrp_find_bridges(void) ...@@ -230,8 +230,8 @@ chrp_find_bridges(void)
else if (strncmp(machine, "Pegasos", 7) == 0) else if (strncmp(machine, "Pegasos", 7) == 0)
is_pegasos = 1; is_pegasos = 1;
} }
for (dev = root->child; dev != NULL; dev = dev->sibling) { for_each_child_of_node(root, dev) {
if (dev->type == NULL || strcmp(dev->type, "pci") != 0) if (!of_node_is_type(dev, "pci"))
continue; continue;
++index; ++index;
/* The GG2 bridge on the LongTrail doesn't have an address */ /* The GG2 bridge on the LongTrail doesn't have an address */
......
...@@ -280,10 +280,7 @@ static __init void chrp_init(void) ...@@ -280,10 +280,7 @@ static __init void chrp_init(void)
node = of_find_node_by_path(property); node = of_find_node_by_path(property);
if (!node) if (!node)
return; return;
property = of_get_property(node, "device_type", NULL); if (!of_node_is_type(node, "serial"))
if (!property)
goto out_put;
if (strcmp(property, "serial"))
goto out_put; goto out_put;
/* /*
* The 9pin connector is either /failsafe * The 9pin connector is either /failsafe
......
...@@ -604,10 +604,8 @@ void __init maple_pci_init(void) ...@@ -604,10 +604,8 @@ void __init maple_pci_init(void)
printk(KERN_CRIT "maple_find_bridges: can't find root of device tree\n"); printk(KERN_CRIT "maple_find_bridges: can't find root of device tree\n");
return; return;
} }
for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) { for_each_child_of_node(root, np) {
if (!np->type) if (!of_node_is_type(np, "pci") && !of_node_is_type(np, "ht"))
continue;
if (strcmp(np->type, "pci") && strcmp(np->type, "ht"))
continue; continue;
if ((of_device_is_compatible(np, "u4-pcie") || if ((of_device_is_compatible(np, "u4-pcie") ||
of_device_is_compatible(np, "u3-agp")) && of_device_is_compatible(np, "u3-agp")) &&
......
...@@ -917,10 +917,9 @@ static void __init smu_i2c_probe(void) ...@@ -917,10 +917,9 @@ static void __init smu_i2c_probe(void)
* type as older device trees mix i2c busses and other things * type as older device trees mix i2c busses and other things
* at the same level * at the same level
*/ */
for (busnode = NULL; for_each_child_of_node(controller, busnode) {
(busnode = of_get_next_child(controller, busnode)) != NULL;) { if (!of_node_is_type(busnode, "i2c") &&
if (strcmp(busnode->type, "i2c") && !of_node_is_type(busnode, "i2c-bus"))
strcmp(busnode->type, "i2c-bus"))
continue; continue;
reg = of_get_property(busnode, "reg", NULL); reg = of_get_property(busnode, "reg", NULL);
if (reg == NULL) if (reg == NULL)
......
...@@ -417,7 +417,7 @@ int of_irq_parse_oldworld(struct device_node *device, int index, ...@@ -417,7 +417,7 @@ int of_irq_parse_oldworld(struct device_node *device, int index,
if (ints != NULL) if (ints != NULL)
break; break;
device = device->parent; device = device->parent;
if (device && strcmp(device->type, "pci") != 0) if (!of_node_is_type(device, "pci"))
break; break;
} }
if (ints == NULL) if (ints == NULL)
......
...@@ -194,7 +194,7 @@ int __init udbg_adb_init(int force_btext) ...@@ -194,7 +194,7 @@ int __init udbg_adb_init(int force_btext)
*/ */
for_each_node_by_name(np, "keyboard") { for_each_node_by_name(np, "keyboard") {
struct device_node *parent = of_get_parent(np); struct device_node *parent = of_get_parent(np);
int found = (parent && strcmp(parent->type, "adb") == 0); int found = of_node_is_type(parent, "adb");
of_node_put(parent); of_node_put(parent);
if (found) if (found)
break; break;
......
...@@ -313,7 +313,6 @@ static int pseries_remove_memblock(unsigned long base, unsigned int memblock_siz ...@@ -313,7 +313,6 @@ static int pseries_remove_memblock(unsigned long base, unsigned int memblock_siz
static int pseries_remove_mem_node(struct device_node *np) static int pseries_remove_mem_node(struct device_node *np)
{ {
const char *type;
const __be32 *regs; const __be32 *regs;
unsigned long base; unsigned long base;
unsigned int lmb_size; unsigned int lmb_size;
...@@ -322,8 +321,7 @@ static int pseries_remove_mem_node(struct device_node *np) ...@@ -322,8 +321,7 @@ static int pseries_remove_mem_node(struct device_node *np)
/* /*
* Check to see if we are actually removing memory * Check to see if we are actually removing memory
*/ */
type = of_get_property(np, "device_type", NULL); if (!of_node_is_type(np, "memory"))
if (type == NULL || strcmp(type, "memory") != 0)
return 0; return 0;
/* /*
...@@ -936,7 +934,6 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog) ...@@ -936,7 +934,6 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
static int pseries_add_mem_node(struct device_node *np) static int pseries_add_mem_node(struct device_node *np)
{ {
const char *type;
const __be32 *regs; const __be32 *regs;
unsigned long base; unsigned long base;
unsigned int lmb_size; unsigned int lmb_size;
...@@ -945,8 +942,7 @@ static int pseries_add_mem_node(struct device_node *np) ...@@ -945,8 +942,7 @@ static int pseries_add_mem_node(struct device_node *np)
/* /*
* Check to see if we are actually adding memory * Check to see if we are actually adding memory
*/ */
type = of_get_property(np, "device_type", NULL); if (!of_node_is_type(np, "memory"))
if (type == NULL || strcmp(type, "memory") != 0)
return 0; return 0;
/* /*
......
...@@ -469,8 +469,8 @@ static void __init find_and_init_phbs(void) ...@@ -469,8 +469,8 @@ static void __init find_and_init_phbs(void)
struct device_node *root = of_find_node_by_path("/"); struct device_node *root = of_find_node_by_path("/");
for_each_child_of_node(root, node) { for_each_child_of_node(root, node) {
if (node->type == NULL || (strcmp(node->type, "pci") != 0 && if (!of_node_is_type(node, "pci") &&
strcmp(node->type, "pciex") != 0)) !of_node_is_type(node, "pciex"))
continue; continue;
phb = pcibios_alloc_controller(node); phb = pcibios_alloc_controller(node);
...@@ -978,11 +978,7 @@ static void pseries_power_off(void) ...@@ -978,11 +978,7 @@ static void pseries_power_off(void)
static int __init pSeries_probe(void) static int __init pSeries_probe(void)
{ {
const char *dtype = of_get_property(of_root, "device_type", NULL); if (!of_node_is_type(of_root, "chrp"))
if (dtype == NULL)
return 0;
if (strcmp(dtype, "chrp"))
return 0; return 0;
/* Cell blades firmware claims to be chrp while it's not. Until this /* Cell blades firmware claims to be chrp while it's not. Until this
......
...@@ -1356,9 +1356,9 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node) ...@@ -1356,9 +1356,9 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
*/ */
parent_node = of_get_parent(of_node); parent_node = of_get_parent(of_node);
if (parent_node) { if (parent_node) {
if (!strcmp(parent_node->type, "ibm,platform-facilities")) if (of_node_is_type(parent_node, "ibm,platform-facilities"))
family = PFO; family = PFO;
else if (!strcmp(parent_node->type, "vdevice")) else if (of_node_is_type(parent_node, "vdevice"))
family = VDEVICE; family = VDEVICE;
else { else {
pr_warn("%s: parent(%pOF) of %pOFn not recognized.\n", pr_warn("%s: parent(%pOF) of %pOFn not recognized.\n",
...@@ -1395,9 +1395,8 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node) ...@@ -1395,9 +1395,8 @@ struct vio_dev *vio_register_device_node(struct device_node *of_node)
if (viodev->family == VDEVICE) { if (viodev->family == VDEVICE) {
unsigned int unit_address; unsigned int unit_address;
if (of_node->type != NULL) viodev->type = of_node_get_device_type(of_node);
viodev->type = of_node->type; if (!viodev->type) {
else {
pr_warn("%s: node %pOFn is missing the 'device_type' " pr_warn("%s: node %pOFn is missing the 'device_type' "
"property.\n", __func__, of_node); "property.\n", __func__, of_node);
goto out; goto out;
...@@ -1672,32 +1671,30 @@ struct vio_dev *vio_find_node(struct device_node *vnode) ...@@ -1672,32 +1671,30 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
{ {
char kobj_name[20]; char kobj_name[20];
struct device_node *vnode_parent; struct device_node *vnode_parent;
const char *dev_type;
vnode_parent = of_get_parent(vnode); vnode_parent = of_get_parent(vnode);
if (!vnode_parent) if (!vnode_parent)
return NULL; return NULL;
dev_type = of_get_property(vnode_parent, "device_type", NULL);
of_node_put(vnode_parent);
if (!dev_type)
return NULL;
/* construct the kobject name from the device node */ /* construct the kobject name from the device node */
if (!strcmp(dev_type, "vdevice")) { if (of_node_is_type(vnode_parent, "vdevice")) {
const __be32 *prop; const __be32 *prop;
prop = of_get_property(vnode, "reg", NULL); prop = of_get_property(vnode, "reg", NULL);
if (!prop) if (!prop)
return NULL; goto out;
snprintf(kobj_name, sizeof(kobj_name), "%x", snprintf(kobj_name, sizeof(kobj_name), "%x",
(uint32_t)of_read_number(prop, 1)); (uint32_t)of_read_number(prop, 1));
} else if (!strcmp(dev_type, "ibm,platform-facilities")) } else if (of_node_is_type(vnode_parent, "ibm,platform-facilities"))
snprintf(kobj_name, sizeof(kobj_name), "%pOFn", vnode); snprintf(kobj_name, sizeof(kobj_name), "%pOFn", vnode);
else else
return NULL; goto out;
of_node_put(vnode_parent);
return vio_find_name(kobj_name); return vio_find_name(kobj_name);
out:
of_node_put(vnode_parent);
return NULL;
} }
EXPORT_SYMBOL(vio_find_node); EXPORT_SYMBOL(vio_find_node);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment