aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-08-05 18:57:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-05 18:57:35 -0400
commit03c0c29aff7e56b722eb6c47eace222b140d0377 (patch)
tree47267a19b523159cf36a050ef3c35f4dbdb33016 /drivers
parentc60c6a96b7bb0f1f8bb635fdfcf5b592aaf062b4 (diff)
parent7fb8f881c54beb05dd4d2c947dada1c636581d87 (diff)
Merge branch 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6
* 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6: (63 commits) of/platform: Register of_platform_drivers with an "of:" prefix of/address: Clean up function declarations of/spi: call of_register_spi_devices() from spi core code of: Provide default of_node_to_nid() implementation. of/device: Make of_device_make_bus_id() usable by other code. of/irq: Fix endian issues in parsing interrupt specifiers of: Fix phandle endian issues of/flattree: fix of_flat_dt_is_compatible() to match the full compatible string of: remove of_default_bus_ids of: make of_find_device_by_node generic microblaze: remove references to of_device and to_of_device sparc: remove references to of_device and to_of_device powerpc: remove references to of_device and to_of_device of/device: Replace of_device with platform_device in includes and core code of/device: Protect against binding of_platform_drivers to non-OF devices of: remove asm/of_device.h of: remove asm/of_platform.h of/platform: remove all of_bus_type and of_platform_bus_type references of: Merge of_platform_bus_type with platform_bus_type drivercore/of: Add OF style matching to platform bus ... Fix up trivial conflicts in arch/microblaze/kernel/Makefile due to just some obj-y removals by the devicetree branch, while the microblaze updates added a new file.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/atm/fore200e.c8
-rw-r--r--drivers/base/platform.c13
-rw-r--r--drivers/char/bsr.c1
-rw-r--r--drivers/char/hw_random/n2-drv.c4
-rw-r--r--drivers/crypto/n2_core.c10
-rw-r--r--drivers/gpio/gpiolib.c55
-rw-r--r--drivers/gpio/xilinx_gpio.c15
-rw-r--r--drivers/hwmon/ultra45_env.c4
-rw-r--r--drivers/i2c/busses/i2c-cpm.c6
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c4
-rw-r--r--drivers/i2c/busses/i2c-mpc.c2
-rw-r--r--drivers/i2c/i2c-core.c9
-rw-r--r--drivers/input/misc/sparcspkr.c12
-rw-r--r--drivers/input/serio/i8042-sparcio.h13
-rw-r--r--drivers/macintosh/macio_sysfs.c5
-rw-r--r--drivers/mmc/host/mmc_spi.c8
-rw-r--r--drivers/mtd/maps/sun_uflash.c4
-rw-r--r--drivers/net/fsl_pq_mdio.c1
-rw-r--r--drivers/net/ibm_newemac/core.c4
-rw-r--r--drivers/net/myri_sbus.c6
-rw-r--r--drivers/net/niu.c15
-rw-r--r--drivers/net/niu.h4
-rw-r--r--drivers/net/sunbmac.c6
-rw-r--r--drivers/net/sunhme.c10
-rw-r--r--drivers/net/sunlance.c6
-rw-r--r--drivers/net/sunqe.c10
-rw-r--r--drivers/net/xilinx_emaclite.c2
-rw-r--r--drivers/of/Kconfig40
-rw-r--r--drivers/of/Makefile2
-rw-r--r--drivers/of/address.c595
-rw-r--r--drivers/of/base.c76
-rw-r--r--drivers/of/device.c91
-rw-r--r--drivers/of/fdt.c26
-rw-r--r--drivers/of/gpio.c93
-rw-r--r--drivers/of/irq.c349
-rw-r--r--drivers/of/of_i2c.c50
-rw-r--r--drivers/of/of_mdio.c1
-rw-r--r--drivers/of/of_spi.c11
-rw-r--r--drivers/of/platform.c384
-rw-r--r--drivers/parport/parport_sunbpp.c6
-rw-r--r--drivers/sbus/char/bbc_i2c.c10
-rw-r--r--drivers/sbus/char/display7seg.c4
-rw-r--r--drivers/sbus/char/envctrl.c4
-rw-r--r--drivers/sbus/char/flash.c4
-rw-r--r--drivers/sbus/char/uctrl.c6
-rw-r--r--drivers/scsi/qlogicpti.c8
-rw-r--r--drivers/scsi/sun_esp.c6
-rw-r--r--drivers/serial/sunhv.c8
-rw-r--r--drivers/serial/sunsab.c6
-rw-r--r--drivers/serial/sunsu.c4
-rw-r--r--drivers/serial/sunzilog.c16
-rw-r--r--drivers/serial/uartlite.c1
-rw-r--r--drivers/spi/mpc512x_psc_spi.c2
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c11
-rw-r--r--drivers/spi/mpc52xx_spi.c3
-rw-r--r--drivers/spi/spi.c4
-rw-r--r--drivers/spi/spi_mpc8xxx.c4
-rw-r--r--drivers/spi/spi_ppc4xx.c2
-rw-r--r--drivers/spi/xilinx_spi.c3
-rw-r--r--drivers/spi/xilinx_spi_of.c4
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c1
-rw-r--r--drivers/video/bw2.c4
-rw-r--r--drivers/video/cg14.c4
-rw-r--r--drivers/video/cg3.c4
-rw-r--r--drivers/video/cg6.c4
-rw-r--r--drivers/video/controlfb.c2
-rw-r--r--drivers/video/ffb.c4
-rw-r--r--drivers/video/leo.c4
-rw-r--r--drivers/video/offb.c3
-rw-r--r--drivers/video/p9100.c4
-rw-r--r--drivers/video/sunxvr1000.c4
-rw-r--r--drivers/video/tcx.c4
-rw-r--r--drivers/watchdog/cpwd.c6
-rw-r--r--drivers/watchdog/riowd.c4
74 files changed, 1780 insertions, 343 deletions
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index da8f176c051e..b7385e077717 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -2657,7 +2657,7 @@ static int __devinit fore200e_sba_probe(struct of_device *op,
2657 2657
2658 fore200e->bus = bus; 2658 fore200e->bus = bus;
2659 fore200e->bus_dev = op; 2659 fore200e->bus_dev = op;
2660 fore200e->irq = op->irqs[0]; 2660 fore200e->irq = op->archdata.irqs[0];
2661 fore200e->phys_base = op->resource[0].start; 2661 fore200e->phys_base = op->resource[0].start;
2662 2662
2663 sprintf(fore200e->name, "%s-%d", bus->model_name, index); 2663 sprintf(fore200e->name, "%s-%d", bus->model_name, index);
@@ -2795,7 +2795,7 @@ static int __init fore200e_module_init(void)
2795 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n"); 2795 printk(FORE200E "FORE Systems 200E-series ATM driver - version " FORE200E_VERSION "\n");
2796 2796
2797#ifdef CONFIG_SBUS 2797#ifdef CONFIG_SBUS
2798 err = of_register_driver(&fore200e_sba_driver, &of_bus_type); 2798 err = of_register_platform_driver(&fore200e_sba_driver);
2799 if (err) 2799 if (err)
2800 return err; 2800 return err;
2801#endif 2801#endif
@@ -2806,7 +2806,7 @@ static int __init fore200e_module_init(void)
2806 2806
2807#ifdef CONFIG_SBUS 2807#ifdef CONFIG_SBUS
2808 if (err) 2808 if (err)
2809 of_unregister_driver(&fore200e_sba_driver); 2809 of_unregister_platform_driver(&fore200e_sba_driver);
2810#endif 2810#endif
2811 2811
2812 return err; 2812 return err;
@@ -2818,7 +2818,7 @@ static void __exit fore200e_module_cleanup(void)
2818 pci_unregister_driver(&fore200e_pca_driver); 2818 pci_unregister_driver(&fore200e_pca_driver);
2819#endif 2819#endif
2820#ifdef CONFIG_SBUS 2820#ifdef CONFIG_SBUS
2821 of_unregister_driver(&fore200e_sba_driver); 2821 of_unregister_platform_driver(&fore200e_sba_driver);
2822#endif 2822#endif
2823} 2823}
2824 2824
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 4d99c8bdfedc..f699fabf403b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/string.h> 13#include <linux/string.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/of_device.h>
15#include <linux/module.h> 16#include <linux/module.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
@@ -635,6 +636,12 @@ static struct device_attribute platform_dev_attrs[] = {
635static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) 636static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
636{ 637{
637 struct platform_device *pdev = to_platform_device(dev); 638 struct platform_device *pdev = to_platform_device(dev);
639 int rc;
640
641 /* Some devices have extra OF data and an OF-style MODALIAS */
642 rc = of_device_uevent(dev,env);
643 if (rc != -ENODEV)
644 return rc;
638 645
639 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX, 646 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
640 (pdev->id_entry) ? pdev->id_entry->name : pdev->name); 647 (pdev->id_entry) ? pdev->id_entry->name : pdev->name);
@@ -673,7 +680,11 @@ static int platform_match(struct device *dev, struct device_driver *drv)
673 struct platform_device *pdev = to_platform_device(dev); 680 struct platform_device *pdev = to_platform_device(dev);
674 struct platform_driver *pdrv = to_platform_driver(drv); 681 struct platform_driver *pdrv = to_platform_driver(drv);
675 682
676 /* match against the id table first */ 683 /* Attempt an OF style match first */
684 if (of_driver_match_device(dev, drv))
685 return 1;
686
687 /* Then try to match against the id table */
677 if (pdrv->id_table) 688 if (pdrv->id_table)
678 return platform_match_id(pdrv->id_table, pdev) != NULL; 689 return platform_match_id(pdrv->id_table, pdev) != NULL;
679 690
diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c
index 89d871ef8c2f..91917133ae0a 100644
--- a/drivers/char/bsr.c
+++ b/drivers/char/bsr.c
@@ -23,6 +23,7 @@
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/of_device.h> 24#include <linux/of_device.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/fs.h>
26#include <linux/module.h> 27#include <linux/module.h>
27#include <linux/cdev.h> 28#include <linux/cdev.h>
28#include <linux/list.h> 29#include <linux/list.h>
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 101d5f235547..7a4f080f8356 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -762,12 +762,12 @@ static struct of_platform_driver n2rng_driver = {
762 762
763static int __init n2rng_init(void) 763static int __init n2rng_init(void)
764{ 764{
765 return of_register_driver(&n2rng_driver, &of_bus_type); 765 return of_register_platform_driver(&n2rng_driver);
766} 766}
767 767
768static void __exit n2rng_exit(void) 768static void __exit n2rng_exit(void)
769{ 769{
770 of_unregister_driver(&n2rng_driver); 770 of_unregister_platform_driver(&n2rng_driver);
771} 771}
772 772
773module_init(n2rng_init); 773module_init(n2rng_init);
diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index b99c38f23d61..26af2dd5d831 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -2247,20 +2247,20 @@ static struct of_platform_driver n2_mau_driver = {
2247 2247
2248static int __init n2_init(void) 2248static int __init n2_init(void)
2249{ 2249{
2250 int err = of_register_driver(&n2_crypto_driver, &of_bus_type); 2250 int err = of_register_platform_driver(&n2_crypto_driver);
2251 2251
2252 if (!err) { 2252 if (!err) {
2253 err = of_register_driver(&n2_mau_driver, &of_bus_type); 2253 err = of_register_platform_driver(&n2_mau_driver);
2254 if (err) 2254 if (err)
2255 of_unregister_driver(&n2_crypto_driver); 2255 of_unregister_platform_driver(&n2_crypto_driver);
2256 } 2256 }
2257 return err; 2257 return err;
2258} 2258}
2259 2259
2260static void __exit n2_exit(void) 2260static void __exit n2_exit(void)
2261{ 2261{
2262 of_unregister_driver(&n2_mau_driver); 2262 of_unregister_platform_driver(&n2_mau_driver);
2263 of_unregister_driver(&n2_crypto_driver); 2263 of_unregister_platform_driver(&n2_crypto_driver);
2264} 2264}
2265 2265
2266module_init(n2_init); 2266module_init(n2_init);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4e51fe3c1fc4..6a6bd569e1f8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -8,6 +8,7 @@
8#include <linux/debugfs.h> 8#include <linux/debugfs.h>
9#include <linux/seq_file.h> 9#include <linux/seq_file.h>
10#include <linux/gpio.h> 10#include <linux/gpio.h>
11#include <linux/of_gpio.h>
11#include <linux/idr.h> 12#include <linux/idr.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13 14
@@ -1100,16 +1101,24 @@ int gpiochip_add(struct gpio_chip *chip)
1100 } 1101 }
1101 } 1102 }
1102 1103
1104 of_gpiochip_add(chip);
1105
1103unlock: 1106unlock:
1104 spin_unlock_irqrestore(&gpio_lock, flags); 1107 spin_unlock_irqrestore(&gpio_lock, flags);
1105 if (status == 0) 1108
1106 status = gpiochip_export(chip); 1109 if (status)
1110 goto fail;
1111
1112 status = gpiochip_export(chip);
1113 if (status)
1114 goto fail;
1115
1116 return 0;
1107fail: 1117fail:
1108 /* failures here can mean systems won't boot... */ 1118 /* failures here can mean systems won't boot... */
1109 if (status) 1119 pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n",
1110 pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n", 1120 chip->base, chip->base + chip->ngpio - 1,
1111 chip->base, chip->base + chip->ngpio - 1, 1121 chip->label ? : "generic");
1112 chip->label ? : "generic");
1113 return status; 1122 return status;
1114} 1123}
1115EXPORT_SYMBOL_GPL(gpiochip_add); 1124EXPORT_SYMBOL_GPL(gpiochip_add);
@@ -1128,6 +1137,8 @@ int gpiochip_remove(struct gpio_chip *chip)
1128 1137
1129 spin_lock_irqsave(&gpio_lock, flags); 1138 spin_lock_irqsave(&gpio_lock, flags);
1130 1139
1140 of_gpiochip_remove(chip);
1141
1131 for (id = chip->base; id < chip->base + chip->ngpio; id++) { 1142 for (id = chip->base; id < chip->base + chip->ngpio; id++) {
1132 if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) { 1143 if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) {
1133 status = -EBUSY; 1144 status = -EBUSY;
@@ -1148,6 +1159,38 @@ int gpiochip_remove(struct gpio_chip *chip)
1148} 1159}
1149EXPORT_SYMBOL_GPL(gpiochip_remove); 1160EXPORT_SYMBOL_GPL(gpiochip_remove);
1150 1161
1162/**
1163 * gpiochip_find() - iterator for locating a specific gpio_chip
1164 * @data: data to pass to match function
1165 * @callback: Callback function to check gpio_chip
1166 *
1167 * Similar to bus_find_device. It returns a reference to a gpio_chip as
1168 * determined by a user supplied @match callback. The callback should return
1169 * 0 if the device doesn't match and non-zero if it does. If the callback is
1170 * non-zero, this function will return to the caller and not iterate over any
1171 * more gpio_chips.
1172 */
1173struct gpio_chip *gpiochip_find(void *data,
1174 int (*match)(struct gpio_chip *chip, void *data))
1175{
1176 struct gpio_chip *chip = NULL;
1177 unsigned long flags;
1178 int i;
1179
1180 spin_lock_irqsave(&gpio_lock, flags);
1181 for (i = 0; i < ARCH_NR_GPIOS; i++) {
1182 if (!gpio_desc[i].chip)
1183 continue;
1184
1185 if (match(gpio_desc[i].chip, data)) {
1186 chip = gpio_desc[i].chip;
1187 break;
1188 }
1189 }
1190 spin_unlock_irqrestore(&gpio_lock, flags);
1191
1192 return chip;
1193}
1151 1194
1152/* These "optional" allocation calls help prevent drivers from stomping 1195/* These "optional" allocation calls help prevent drivers from stomping
1153 * on each other, and help provide better diagnostics in debugfs. 1196 * on each other, and help provide better diagnostics in debugfs.
diff --git a/drivers/gpio/xilinx_gpio.c b/drivers/gpio/xilinx_gpio.c
index b8fa65b5bfca..709690995d0d 100644
--- a/drivers/gpio/xilinx_gpio.c
+++ b/drivers/gpio/xilinx_gpio.c
@@ -161,14 +161,12 @@ static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)
161static int __devinit xgpio_of_probe(struct device_node *np) 161static int __devinit xgpio_of_probe(struct device_node *np)
162{ 162{
163 struct xgpio_instance *chip; 163 struct xgpio_instance *chip;
164 struct of_gpio_chip *ofchip;
165 int status = 0; 164 int status = 0;
166 const u32 *tree_info; 165 const u32 *tree_info;
167 166
168 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 167 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
169 if (!chip) 168 if (!chip)
170 return -ENOMEM; 169 return -ENOMEM;
171 ofchip = &chip->mmchip.of_gc;
172 170
173 /* Update GPIO state shadow register with default value */ 171 /* Update GPIO state shadow register with default value */
174 tree_info = of_get_property(np, "xlnx,dout-default", NULL); 172 tree_info = of_get_property(np, "xlnx,dout-default", NULL);
@@ -182,21 +180,20 @@ static int __devinit xgpio_of_probe(struct device_node *np)
182 chip->gpio_dir = *tree_info; 180 chip->gpio_dir = *tree_info;
183 181
184 /* Check device node and parent device node for device width */ 182 /* Check device node and parent device node for device width */
185 ofchip->gc.ngpio = 32; /* By default assume full GPIO controller */ 183 chip->mmchip.gc.ngpio = 32; /* By default assume full GPIO controller */
186 tree_info = of_get_property(np, "xlnx,gpio-width", NULL); 184 tree_info = of_get_property(np, "xlnx,gpio-width", NULL);
187 if (!tree_info) 185 if (!tree_info)
188 tree_info = of_get_property(np->parent, 186 tree_info = of_get_property(np->parent,
189 "xlnx,gpio-width", NULL); 187 "xlnx,gpio-width", NULL);
190 if (tree_info) 188 if (tree_info)
191 ofchip->gc.ngpio = *tree_info; 189 chip->mmchip.gc.ngpio = *tree_info;
192 190
193 spin_lock_init(&chip->gpio_lock); 191 spin_lock_init(&chip->gpio_lock);
194 192
195 ofchip->gpio_cells = 2; 193 chip->mmchip.gc.direction_input = xgpio_dir_in;
196 ofchip->gc.direction_input = xgpio_dir_in; 194 chip->mmchip.gc.direction_output = xgpio_dir_out;
197 ofchip->gc.direction_output = xgpio_dir_out; 195 chip->mmchip.gc.get = xgpio_get;
198 ofchip->gc.get = xgpio_get; 196 chip->mmchip.gc.set = xgpio_set;
199 ofchip->gc.set = xgpio_set;
200 197
201 chip->mmchip.save_regs = xgpio_save_regs; 198 chip->mmchip.save_regs = xgpio_save_regs;
202 199
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 5da5942cf970..89643261ccdb 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -311,12 +311,12 @@ static struct of_platform_driver env_driver = {
311 311
312static int __init env_init(void) 312static int __init env_init(void)
313{ 313{
314 return of_register_driver(&env_driver, &of_bus_type); 314 return of_register_platform_driver(&env_driver);
315} 315}
316 316
317static void __exit env_exit(void) 317static void __exit env_exit(void)
318{ 318{
319 of_unregister_driver(&env_driver); 319 of_unregister_platform_driver(&env_driver);
320} 320}
321 321
322module_init(env_init); 322module_init(env_init);
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index b02b4533651d..e591de1bc704 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -652,6 +652,7 @@ static int __devinit cpm_i2c_probe(struct of_device *ofdev,
652 cpm->adap = cpm_ops; 652 cpm->adap = cpm_ops;
653 i2c_set_adapdata(&cpm->adap, cpm); 653 i2c_set_adapdata(&cpm->adap, cpm);
654 cpm->adap.dev.parent = &ofdev->dev; 654 cpm->adap.dev.parent = &ofdev->dev;
655 cpm->adap.dev.of_node = of_node_get(ofdev->dev.of_node);
655 656
656 result = cpm_i2c_setup(cpm); 657 result = cpm_i2c_setup(cpm);
657 if (result) { 658 if (result) {
@@ -676,11 +677,6 @@ static int __devinit cpm_i2c_probe(struct of_device *ofdev,
676 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n", 677 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
677 cpm->adap.name); 678 cpm->adap.name);
678 679
679 /*
680 * register OF I2C devices
681 */
682 of_register_i2c_devices(&cpm->adap, ofdev->dev.of_node);
683
684 return 0; 680 return 0;
685out_shut: 681out_shut:
686 cpm_i2c_shutdown(cpm); 682 cpm_i2c_shutdown(cpm);
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index bf344135647a..1168d61418c9 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -745,6 +745,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
745 /* Register it with i2c layer */ 745 /* Register it with i2c layer */
746 adap = &dev->adap; 746 adap = &dev->adap;
747 adap->dev.parent = &ofdev->dev; 747 adap->dev.parent = &ofdev->dev;
748 adap->dev.of_node = of_node_get(np);
748 strlcpy(adap->name, "IBM IIC", sizeof(adap->name)); 749 strlcpy(adap->name, "IBM IIC", sizeof(adap->name));
749 i2c_set_adapdata(adap, dev); 750 i2c_set_adapdata(adap, dev);
750 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 751 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
@@ -760,9 +761,6 @@ static int __devinit iic_probe(struct of_device *ofdev,
760 dev_info(&ofdev->dev, "using %s mode\n", 761 dev_info(&ofdev->dev, "using %s mode\n",
761 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 762 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
762 763
763 /* Now register all the child nodes */
764 of_register_i2c_devices(adap, np);
765
766 return 0; 764 return 0;
767 765
768error_cleanup: 766error_cleanup:
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 54247d475fc3..6545d1c99b61 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -625,13 +625,13 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
625 i2c->adap = mpc_ops; 625 i2c->adap = mpc_ops;
626 i2c_set_adapdata(&i2c->adap, i2c); 626 i2c_set_adapdata(&i2c->adap, i2c);
627 i2c->adap.dev.parent = &op->dev; 627 i2c->adap.dev.parent = &op->dev;
628 i2c->adap.dev.of_node = of_node_get(op->dev.of_node);
628 629
629 result = i2c_add_adapter(&i2c->adap); 630 result = i2c_add_adapter(&i2c->adap);
630 if (result < 0) { 631 if (result < 0) {
631 dev_err(i2c->dev, "failed to add adapter\n"); 632 dev_err(i2c->dev, "failed to add adapter\n");
632 goto fail_add; 633 goto fail_add;
633 } 634 }
634 of_register_i2c_devices(&i2c->adap, op->dev.of_node);
635 635
636 return result; 636 return result;
637 637
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0815e10da7c6..df937df845eb 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -30,6 +30,8 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/of_i2c.h>
34#include <linux/of_device.h>
33#include <linux/completion.h> 35#include <linux/completion.h>
34#include <linux/hardirq.h> 36#include <linux/hardirq.h>
35#include <linux/irqflags.h> 37#include <linux/irqflags.h>
@@ -70,6 +72,10 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
70 if (!client) 72 if (!client)
71 return 0; 73 return 0;
72 74
75 /* Attempt an OF style match */
76 if (of_driver_match_device(dev, drv))
77 return 1;
78
73 driver = to_i2c_driver(drv); 79 driver = to_i2c_driver(drv);
74 /* match on an id table if there is one */ 80 /* match on an id table if there is one */
75 if (driver->id_table) 81 if (driver->id_table)
@@ -790,6 +796,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
790 if (adap->nr < __i2c_first_dynamic_bus_num) 796 if (adap->nr < __i2c_first_dynamic_bus_num)
791 i2c_scan_static_board_info(adap); 797 i2c_scan_static_board_info(adap);
792 798
799 /* Register devices from the device tree */
800 of_i2c_register_devices(adap);
801
793 /* Notify drivers */ 802 /* Notify drivers */
794 mutex_lock(&core_lock); 803 mutex_lock(&core_lock);
795 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 804 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap,
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index 1dacae4b43f0..f3bb92e9755f 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -353,14 +353,12 @@ static struct of_platform_driver grover_beep_driver = {
353 353
354static int __init sparcspkr_init(void) 354static int __init sparcspkr_init(void)
355{ 355{
356 int err = of_register_driver(&bbc_beep_driver, 356 int err = of_register_platform_driver(&bbc_beep_driver);
357 &of_platform_bus_type);
358 357
359 if (!err) { 358 if (!err) {
360 err = of_register_driver(&grover_beep_driver, 359 err = of_register_platform_driver(&grover_beep_driver);
361 &of_platform_bus_type);
362 if (err) 360 if (err)
363 of_unregister_driver(&bbc_beep_driver); 361 of_unregister_platform_driver(&bbc_beep_driver);
364 } 362 }
365 363
366 return err; 364 return err;
@@ -368,8 +366,8 @@ static int __init sparcspkr_init(void)
368 366
369static void __exit sparcspkr_exit(void) 367static void __exit sparcspkr_exit(void)
370{ 368{
371 of_unregister_driver(&bbc_beep_driver); 369 of_unregister_platform_driver(&bbc_beep_driver);
372 of_unregister_driver(&grover_beep_driver); 370 of_unregister_platform_driver(&grover_beep_driver);
373} 371}
374 372
375module_init(sparcspkr_init); 373module_init(sparcspkr_init);
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 04e32f2d1241..cb2a24b94746 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -58,9 +58,9 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || 58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) { 59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
60 struct of_device *kbd = of_find_device_by_node(dp); 60 struct of_device *kbd = of_find_device_by_node(dp);
61 unsigned int irq = kbd->irqs[0]; 61 unsigned int irq = kbd->archdata.irqs[0];
62 if (irq == 0xffffffff) 62 if (irq == 0xffffffff)
63 irq = op->irqs[0]; 63 irq = op->archdata.irqs[0];
64 i8042_kbd_irq = irq; 64 i8042_kbd_irq = irq;
65 kbd_iobase = of_ioremap(&kbd->resource[0], 65 kbd_iobase = of_ioremap(&kbd->resource[0],
66 0, 8, "kbd"); 66 0, 8, "kbd");
@@ -68,9 +68,9 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || 68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
69 !strcmp(dp->name, OBP_PS2MS_NAME2)) { 69 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
70 struct of_device *ms = of_find_device_by_node(dp); 70 struct of_device *ms = of_find_device_by_node(dp);
71 unsigned int irq = ms->irqs[0]; 71 unsigned int irq = ms->archdata.irqs[0];
72 if (irq == 0xffffffff) 72 if (irq == 0xffffffff)
73 irq = op->irqs[0]; 73 irq = op->archdata.irqs[0];
74 i8042_aux_irq = irq; 74 i8042_aux_irq = irq;
75 } 75 }
76 76
@@ -116,8 +116,7 @@ static int __init i8042_platform_init(void)
116 if (!kbd_iobase) 116 if (!kbd_iobase)
117 return -ENODEV; 117 return -ENODEV;
118 } else { 118 } else {
119 int err = of_register_driver(&sparc_i8042_driver, 119 int err = of_register_platform_driver(&sparc_i8042_driver);
120 &of_bus_type);
121 if (err) 120 if (err)
122 return err; 121 return err;
123 122
@@ -141,7 +140,7 @@ static inline void i8042_platform_exit(void)
141 struct device_node *root = of_find_node_by_path("/"); 140 struct device_node *root = of_find_node_by_path("/");
142 141
143 if (strcmp(root->name, "SUNW,JavaStation-1")) 142 if (strcmp(root->name, "SUNW,JavaStation-1"))
144 of_unregister_driver(&sparc_i8042_driver); 143 of_unregister_platform_driver(&sparc_i8042_driver);
145} 144}
146 145
147#else /* !CONFIG_PCI */ 146#else /* !CONFIG_PCI */
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
index 6999ce59fd10..6024038a5b9d 100644
--- a/drivers/macintosh/macio_sysfs.c
+++ b/drivers/macintosh/macio_sysfs.c
@@ -41,10 +41,7 @@ compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
41static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, 41static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
42 char *buf) 42 char *buf)
43{ 43{
44 struct of_device *ofdev = to_of_device(dev); 44 int len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
45 int len;
46
47 len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2);
48 45
49 buf[len] = '\n'; 46 buf[len] = '\n';
50 buf[len+1] = 0; 47 buf[len+1] = 0;
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index ad847a24a675..7b0f3ef50f96 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1533,12 +1533,20 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
1533 return 0; 1533 return 0;
1534} 1534}
1535 1535
1536#if defined(CONFIG_OF)
1537static struct of_device_id mmc_spi_of_match_table[] __devinitdata = {
1538 { .compatible = "mmc-spi-slot", },
1539};
1540#endif
1536 1541
1537static struct spi_driver mmc_spi_driver = { 1542static struct spi_driver mmc_spi_driver = {
1538 .driver = { 1543 .driver = {
1539 .name = "mmc_spi", 1544 .name = "mmc_spi",
1540 .bus = &spi_bus_type, 1545 .bus = &spi_bus_type,
1541 .owner = THIS_MODULE, 1546 .owner = THIS_MODULE,
1547#if defined(CONFIG_OF)
1548 .of_match_table = mmc_spi_of_match_table,
1549#endif
1542 }, 1550 },
1543 .probe = mmc_spi_probe, 1551 .probe = mmc_spi_probe,
1544 .remove = __devexit_p(mmc_spi_remove), 1552 .remove = __devexit_p(mmc_spi_remove),
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index 0391c2527bd7..8984236a8d0a 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -160,12 +160,12 @@ static struct of_platform_driver uflash_driver = {
160 160
161static int __init uflash_init(void) 161static int __init uflash_init(void)
162{ 162{
163 return of_register_driver(&uflash_driver, &of_bus_type); 163 return of_register_platform_driver(&uflash_driver);
164} 164}
165 165
166static void __exit uflash_exit(void) 166static void __exit uflash_exit(void)
167{ 167{
168 of_unregister_driver(&uflash_driver); 168 of_unregister_platform_driver(&uflash_driver);
169} 169}
170 170
171module_init(uflash_init); 171module_init(uflash_init);
diff --git a/drivers/net/fsl_pq_mdio.c b/drivers/net/fsl_pq_mdio.c
index b4c41d72c423..f53f850b6418 100644
--- a/drivers/net/fsl_pq_mdio.c
+++ b/drivers/net/fsl_pq_mdio.c
@@ -35,6 +35,7 @@
35#include <linux/mii.h> 35#include <linux/mii.h>
36#include <linux/phy.h> 36#include <linux/phy.h>
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/of_address.h>
38#include <linux/of_mdio.h> 39#include <linux/of_mdio.h>
39#include <linux/of_platform.h> 40#include <linux/of_platform.h>
40 41
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 0f1d4e96cf89..eeec7bc2ce74 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -2339,11 +2339,11 @@ static int __devinit emac_wait_deps(struct emac_instance *dev)
2339 deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph; 2339 deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph;
2340 if (dev->blist && dev->blist > emac_boot_list) 2340 if (dev->blist && dev->blist > emac_boot_list)
2341 deps[EMAC_DEP_PREV_IDX].phandle = 0xffffffffu; 2341 deps[EMAC_DEP_PREV_IDX].phandle = 0xffffffffu;
2342 bus_register_notifier(&of_platform_bus_type, &emac_of_bus_notifier); 2342 bus_register_notifier(&platform_bus_type, &emac_of_bus_notifier);
2343 wait_event_timeout(emac_probe_wait, 2343 wait_event_timeout(emac_probe_wait,
2344 emac_check_deps(dev, deps), 2344 emac_check_deps(dev, deps),
2345 EMAC_PROBE_DEP_TIMEOUT); 2345 EMAC_PROBE_DEP_TIMEOUT);
2346 bus_unregister_notifier(&of_platform_bus_type, &emac_of_bus_notifier); 2346 bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier);
2347 err = emac_check_deps(dev, deps) ? 0 : -ENODEV; 2347 err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
2348 for (i = 0; i < EMAC_DEP_COUNT; i++) { 2348 for (i = 0; i < EMAC_DEP_COUNT; i++) {
2349 if (deps[i].node) 2349 if (deps[i].node)
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index 1a57c3da1f49..04e552aa14ec 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -1079,7 +1079,7 @@ static int __devinit myri_sbus_probe(struct of_device *op, const struct of_devic
1079 1079
1080 mp->dev = dev; 1080 mp->dev = dev;
1081 dev->watchdog_timeo = 5*HZ; 1081 dev->watchdog_timeo = 5*HZ;
1082 dev->irq = op->irqs[0]; 1082 dev->irq = op->archdata.irqs[0];
1083 dev->netdev_ops = &myri_ops; 1083 dev->netdev_ops = &myri_ops;
1084 1084
1085 /* Register interrupt handler now. */ 1085 /* Register interrupt handler now. */
@@ -1172,12 +1172,12 @@ static struct of_platform_driver myri_sbus_driver = {
1172 1172
1173static int __init myri_sbus_init(void) 1173static int __init myri_sbus_init(void)
1174{ 1174{
1175 return of_register_driver(&myri_sbus_driver, &of_bus_type); 1175 return of_register_platform_driver(&myri_sbus_driver);
1176} 1176}
1177 1177
1178static void __exit myri_sbus_exit(void) 1178static void __exit myri_sbus_exit(void)
1179{ 1179{
1180 of_unregister_driver(&myri_sbus_driver); 1180 of_unregister_platform_driver(&myri_sbus_driver);
1181} 1181}
1182 1182
1183module_init(myri_sbus_init); 1183module_init(myri_sbus_init);
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index b9b950845b0e..404f2d552888 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -28,10 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29 29
30#include <linux/io.h> 30#include <linux/io.h>
31
32#ifdef CONFIG_SPARC64
33#include <linux/of_device.h> 31#include <linux/of_device.h>
34#endif
35 32
36#include "niu.h" 33#include "niu.h"
37 34
@@ -9114,12 +9111,12 @@ static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map)
9114 if (!int_prop) 9111 if (!int_prop)
9115 return -ENODEV; 9112 return -ENODEV;
9116 9113
9117 for (i = 0; i < op->num_irqs; i++) { 9114 for (i = 0; i < op->archdata.num_irqs; i++) {
9118 ldg_num_map[i] = int_prop[i]; 9115 ldg_num_map[i] = int_prop[i];
9119 np->ldg[i].irq = op->irqs[i]; 9116 np->ldg[i].irq = op->archdata.irqs[i];
9120 } 9117 }
9121 9118
9122 np->num_ldg = op->num_irqs; 9119 np->num_ldg = op->archdata.num_irqs;
9123 9120
9124 return 0; 9121 return 0;
9125#else 9122#else
@@ -10249,14 +10246,14 @@ static int __init niu_init(void)
10249 niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT); 10246 niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT);
10250 10247
10251#ifdef CONFIG_SPARC64 10248#ifdef CONFIG_SPARC64
10252 err = of_register_driver(&niu_of_driver, &of_bus_type); 10249 err = of_register_platform_driver(&niu_of_driver);
10253#endif 10250#endif
10254 10251
10255 if (!err) { 10252 if (!err) {
10256 err = pci_register_driver(&niu_pci_driver); 10253 err = pci_register_driver(&niu_pci_driver);
10257#ifdef CONFIG_SPARC64 10254#ifdef CONFIG_SPARC64
10258 if (err) 10255 if (err)
10259 of_unregister_driver(&niu_of_driver); 10256 of_unregister_platform_driver(&niu_of_driver);
10260#endif 10257#endif
10261 } 10258 }
10262 10259
@@ -10267,7 +10264,7 @@ static void __exit niu_exit(void)
10267{ 10264{
10268 pci_unregister_driver(&niu_pci_driver); 10265 pci_unregister_driver(&niu_pci_driver);
10269#ifdef CONFIG_SPARC64 10266#ifdef CONFIG_SPARC64
10270 of_unregister_driver(&niu_of_driver); 10267 of_unregister_platform_driver(&niu_of_driver);
10271#endif 10268#endif
10272} 10269}
10273 10270
diff --git a/drivers/net/niu.h b/drivers/net/niu.h
index d6715465f35d..a41fa8ebe05f 100644
--- a/drivers/net/niu.h
+++ b/drivers/net/niu.h
@@ -3236,7 +3236,7 @@ struct niu_phy_ops {
3236 int (*link_status)(struct niu *np, int *); 3236 int (*link_status)(struct niu *np, int *);
3237}; 3237};
3238 3238
3239struct of_device; 3239struct platform_device;
3240struct niu { 3240struct niu {
3241 void __iomem *regs; 3241 void __iomem *regs;
3242 struct net_device *dev; 3242 struct net_device *dev;
@@ -3297,7 +3297,7 @@ struct niu {
3297 struct niu_vpd vpd; 3297 struct niu_vpd vpd;
3298 u32 eeprom_len; 3298 u32 eeprom_len;
3299 3299
3300 struct of_device *op; 3300 struct platform_device *op;
3301 void __iomem *vir_regs_1; 3301 void __iomem *vir_regs_1;
3302 void __iomem *vir_regs_2; 3302 void __iomem *vir_regs_2;
3303}; 3303};
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 367e96f317d4..09c071bd6ad4 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -1201,7 +1201,7 @@ static int __devinit bigmac_ether_init(struct of_device *op,
1201 dev->watchdog_timeo = 5*HZ; 1201 dev->watchdog_timeo = 5*HZ;
1202 1202
1203 /* Finish net device registration. */ 1203 /* Finish net device registration. */
1204 dev->irq = bp->bigmac_op->irqs[0]; 1204 dev->irq = bp->bigmac_op->archdata.irqs[0];
1205 dev->dma = 0; 1205 dev->dma = 0;
1206 1206
1207 if (register_netdev(dev)) { 1207 if (register_netdev(dev)) {
@@ -1301,12 +1301,12 @@ static struct of_platform_driver bigmac_sbus_driver = {
1301 1301
1302static int __init bigmac_init(void) 1302static int __init bigmac_init(void)
1303{ 1303{
1304 return of_register_driver(&bigmac_sbus_driver, &of_bus_type); 1304 return of_register_platform_driver(&bigmac_sbus_driver);
1305} 1305}
1306 1306
1307static void __exit bigmac_exit(void) 1307static void __exit bigmac_exit(void)
1308{ 1308{
1309 of_unregister_driver(&bigmac_sbus_driver); 1309 of_unregister_platform_driver(&bigmac_sbus_driver);
1310} 1310}
1311 1311
1312module_init(bigmac_init); 1312module_init(bigmac_init);
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index 3d9650b8d38f..eec443f64079 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -2561,7 +2561,7 @@ static int __init quattro_sbus_register_irqs(void)
2561 if (skip) 2561 if (skip)
2562 continue; 2562 continue;
2563 2563
2564 err = request_irq(op->irqs[0], 2564 err = request_irq(op->archdata.irqs[0],
2565 quattro_sbus_interrupt, 2565 quattro_sbus_interrupt,
2566 IRQF_SHARED, "Quattro", 2566 IRQF_SHARED, "Quattro",
2567 qp); 2567 qp);
@@ -2590,7 +2590,7 @@ static void quattro_sbus_free_irqs(void)
2590 if (skip) 2590 if (skip)
2591 continue; 2591 continue;
2592 2592
2593 free_irq(op->irqs[0], qp); 2593 free_irq(op->archdata.irqs[0], qp);
2594 } 2594 }
2595} 2595}
2596#endif /* CONFIG_SBUS */ 2596#endif /* CONFIG_SBUS */
@@ -2790,7 +2790,7 @@ static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe)
2790 /* Happy Meal can do it all... */ 2790 /* Happy Meal can do it all... */
2791 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; 2791 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2792 2792
2793 dev->irq = op->irqs[0]; 2793 dev->irq = op->archdata.irqs[0];
2794 2794
2795#if defined(CONFIG_SBUS) && defined(CONFIG_PCI) 2795#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
2796 /* Hook up SBUS register/descriptor accessors. */ 2796 /* Hook up SBUS register/descriptor accessors. */
@@ -3304,7 +3304,7 @@ static int __init happy_meal_sbus_init(void)
3304{ 3304{
3305 int err; 3305 int err;
3306 3306
3307 err = of_register_driver(&hme_sbus_driver, &of_bus_type); 3307 err = of_register_platform_driver(&hme_sbus_driver);
3308 if (!err) 3308 if (!err)
3309 err = quattro_sbus_register_irqs(); 3309 err = quattro_sbus_register_irqs();
3310 3310
@@ -3313,7 +3313,7 @@ static int __init happy_meal_sbus_init(void)
3313 3313
3314static void happy_meal_sbus_exit(void) 3314static void happy_meal_sbus_exit(void)
3315{ 3315{
3316 of_unregister_driver(&hme_sbus_driver); 3316 of_unregister_platform_driver(&hme_sbus_driver);
3317 quattro_sbus_free_irqs(); 3317 quattro_sbus_free_irqs();
3318 3318
3319 while (qfe_sbus_list) { 3319 while (qfe_sbus_list) {
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index 7d9c33dd9d1a..ee364fa75634 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -1474,7 +1474,7 @@ no_link_test:
1474 dev->ethtool_ops = &sparc_lance_ethtool_ops; 1474 dev->ethtool_ops = &sparc_lance_ethtool_ops;
1475 dev->netdev_ops = &sparc_lance_ops; 1475 dev->netdev_ops = &sparc_lance_ops;
1476 1476
1477 dev->irq = op->irqs[0]; 1477 dev->irq = op->archdata.irqs[0];
1478 1478
1479 /* We cannot sleep if the chip is busy during a 1479 /* We cannot sleep if the chip is busy during a
1480 * multicast list update event, because such events 1480 * multicast list update event, because such events
@@ -1558,12 +1558,12 @@ static struct of_platform_driver sunlance_sbus_driver = {
1558/* Find all the lance cards on the system and initialize them */ 1558/* Find all the lance cards on the system and initialize them */
1559static int __init sparc_lance_init(void) 1559static int __init sparc_lance_init(void)
1560{ 1560{
1561 return of_register_driver(&sunlance_sbus_driver, &of_bus_type); 1561 return of_register_platform_driver(&sunlance_sbus_driver);
1562} 1562}
1563 1563
1564static void __exit sparc_lance_exit(void) 1564static void __exit sparc_lance_exit(void)
1565{ 1565{
1566 of_unregister_driver(&sunlance_sbus_driver); 1566 of_unregister_platform_driver(&sunlance_sbus_driver);
1567} 1567}
1568 1568
1569module_init(sparc_lance_init); 1569module_init(sparc_lance_init);
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index 72b579c8d812..5f84a5dadedd 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -803,7 +803,7 @@ static struct sunqec * __devinit get_qec(struct of_device *child)
803 803
804 qec_init_once(qecp, op); 804 qec_init_once(qecp, op);
805 805
806 if (request_irq(op->irqs[0], qec_interrupt, 806 if (request_irq(op->archdata.irqs[0], qec_interrupt,
807 IRQF_SHARED, "qec", (void *) qecp)) { 807 IRQF_SHARED, "qec", (void *) qecp)) {
808 printk(KERN_ERR "qec: Can't register irq.\n"); 808 printk(KERN_ERR "qec: Can't register irq.\n");
809 goto fail; 809 goto fail;
@@ -901,7 +901,7 @@ static int __devinit qec_ether_init(struct of_device *op)
901 SET_NETDEV_DEV(dev, &op->dev); 901 SET_NETDEV_DEV(dev, &op->dev);
902 902
903 dev->watchdog_timeo = 5*HZ; 903 dev->watchdog_timeo = 5*HZ;
904 dev->irq = op->irqs[0]; 904 dev->irq = op->archdata.irqs[0];
905 dev->dma = 0; 905 dev->dma = 0;
906 dev->ethtool_ops = &qe_ethtool_ops; 906 dev->ethtool_ops = &qe_ethtool_ops;
907 dev->netdev_ops = &qec_ops; 907 dev->netdev_ops = &qec_ops;
@@ -988,18 +988,18 @@ static struct of_platform_driver qec_sbus_driver = {
988 988
989static int __init qec_init(void) 989static int __init qec_init(void)
990{ 990{
991 return of_register_driver(&qec_sbus_driver, &of_bus_type); 991 return of_register_platform_driver(&qec_sbus_driver);
992} 992}
993 993
994static void __exit qec_exit(void) 994static void __exit qec_exit(void)
995{ 995{
996 of_unregister_driver(&qec_sbus_driver); 996 of_unregister_platform_driver(&qec_sbus_driver);
997 997
998 while (root_qec_dev) { 998 while (root_qec_dev) {
999 struct sunqec *next = root_qec_dev->next_module; 999 struct sunqec *next = root_qec_dev->next_module;
1000 struct of_device *op = root_qec_dev->op; 1000 struct of_device *op = root_qec_dev->op;
1001 1001
1002 free_irq(op->irqs[0], (void *) root_qec_dev); 1002 free_irq(op->archdata.irqs[0], (void *) root_qec_dev);
1003 of_iounmap(&op->resource[0], root_qec_dev->gregs, 1003 of_iounmap(&op->resource[0], root_qec_dev->gregs,
1004 GLOB_REG_SIZE); 1004 GLOB_REG_SIZE);
1005 kfree(root_qec_dev); 1005 kfree(root_qec_dev);
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index d04c5b262050..b2c2f391b29d 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -20,7 +20,7 @@
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23 23#include <linux/of_address.h>
24#include <linux/of_device.h> 24#include <linux/of_device.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/of_mdio.h> 26#include <linux/of_mdio.h>
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 7cecc8fea9bd..6acbff389ab6 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -1,35 +1,61 @@
1config OF_FLATTREE 1config DTC
2 bool
3
4config OF
2 bool 5 bool
6
7menu "Flattened Device Tree and Open Firmware support"
3 depends on OF 8 depends on OF
4 9
10config PROC_DEVICETREE
11 bool "Support for device tree in /proc"
12 depends on PROC_FS && !SPARC
13 help
14 This option adds a device-tree directory under /proc which contains
15 an image of the device tree that the kernel copies from Open
16 Firmware or other boot firmware. If unsure, say Y here.
17
18config OF_FLATTREE
19 bool
20 select DTC
21
5config OF_DYNAMIC 22config OF_DYNAMIC
6 def_bool y 23 def_bool y
7 depends on OF && PPC_OF 24 depends on PPC_OF
25
26config OF_ADDRESS
27 def_bool y
28 depends on !SPARC
29
30config OF_IRQ
31 def_bool y
32 depends on !SPARC
8 33
9config OF_DEVICE 34config OF_DEVICE
10 def_bool y 35 def_bool y
11 depends on OF && (SPARC || PPC_OF || MICROBLAZE)
12 36
13config OF_GPIO 37config OF_GPIO
14 def_bool y 38 def_bool y
15 depends on OF && (PPC_OF || MICROBLAZE) && GPIOLIB 39 depends on GPIOLIB && !SPARC
16 help 40 help
17 OpenFirmware GPIO accessors 41 OpenFirmware GPIO accessors
18 42
19config OF_I2C 43config OF_I2C
20 def_tristate I2C 44 def_tristate I2C
21 depends on (PPC_OF || MICROBLAZE) && I2C 45 depends on I2C && !SPARC
22 help 46 help
23 OpenFirmware I2C accessors 47 OpenFirmware I2C accessors
24 48
25config OF_SPI 49config OF_SPI
26 def_tristate SPI 50 def_tristate SPI
27 depends on OF && (PPC_OF || MICROBLAZE) && SPI 51 depends on SPI && !SPARC
28 help 52 help
29 OpenFirmware SPI accessors 53 OpenFirmware SPI accessors
30 54
31config OF_MDIO 55config OF_MDIO
32 def_tristate PHYLIB 56 def_tristate PHYLIB
33 depends on OF && PHYLIB 57 depends on PHYLIB
34 help 58 help
35 OpenFirmware MDIO bus (Ethernet PHY) accessors 59 OpenFirmware MDIO bus (Ethernet PHY) accessors
60
61endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index f232cc98ce00..0052c405463a 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,7 @@
1obj-y = base.o 1obj-y = base.o
2obj-$(CONFIG_OF_FLATTREE) += fdt.o 2obj-$(CONFIG_OF_FLATTREE) += fdt.o
3obj-$(CONFIG_OF_ADDRESS) += address.o
4obj-$(CONFIG_OF_IRQ) += irq.o
3obj-$(CONFIG_OF_DEVICE) += device.o platform.o 5obj-$(CONFIG_OF_DEVICE) += device.o platform.o
4obj-$(CONFIG_OF_GPIO) += gpio.o 6obj-$(CONFIG_OF_GPIO) += gpio.o
5obj-$(CONFIG_OF_I2C) += of_i2c.o 7obj-$(CONFIG_OF_I2C) += of_i2c.o
diff --git a/drivers/of/address.c b/drivers/of/address.c
new file mode 100644
index 000000000000..fcadb726d4f9
--- /dev/null
+++ b/drivers/of/address.c
@@ -0,0 +1,595 @@
1
2#include <linux/io.h>
3#include <linux/ioport.h>
4#include <linux/module.h>
5#include <linux/of_address.h>
6#include <linux/pci_regs.h>
7#include <linux/string.h>
8
9/* Max address size we deal with */
10#define OF_MAX_ADDR_CELLS 4
11#define OF_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
12 (ns) > 0)
13
14static struct of_bus *of_match_bus(struct device_node *np);
15static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
16 u64 size, unsigned int flags,
17 struct resource *r);
18
19/* Debug utility */
20#ifdef DEBUG
21static void of_dump_addr(const char *s, const u32 *addr, int na)
22{
23 printk(KERN_DEBUG "%s", s);
24 while (na--)
25 printk(" %08x", be32_to_cpu(*(addr++)));
26 printk("\n");
27}
28#else
29static void of_dump_addr(const char *s, const u32 *addr, int na) { }
30#endif
31
32/* Callbacks for bus specific translators */
33struct of_bus {
34 const char *name;
35 const char *addresses;
36 int (*match)(struct device_node *parent);
37 void (*count_cells)(struct device_node *child,
38 int *addrc, int *sizec);
39 u64 (*map)(u32 *addr, const u32 *range,
40 int na, int ns, int pna);
41 int (*translate)(u32 *addr, u64 offset, int na);
42 unsigned int (*get_flags)(const u32 *addr);
43};
44
45/*
46 * Default translator (generic bus)
47 */
48
49static void of_bus_default_count_cells(struct device_node *dev,
50 int *addrc, int *sizec)
51{
52 if (addrc)
53 *addrc = of_n_addr_cells(dev);
54 if (sizec)
55 *sizec = of_n_size_cells(dev);
56}
57
58static u64 of_bus_default_map(u32 *addr, const u32 *range,
59 int na, int ns, int pna)
60{
61 u64 cp, s, da;
62
63 cp = of_read_number(range, na);
64 s = of_read_number(range + na + pna, ns);
65 da = of_read_number(addr, na);
66
67 pr_debug("OF: default map, cp=%llx, s=%llx, da=%llx\n",
68 (unsigned long long)cp, (unsigned long long)s,
69 (unsigned long long)da);
70
71 if (da < cp || da >= (cp + s))
72 return OF_BAD_ADDR;
73 return da - cp;
74}
75
76static int of_bus_default_translate(u32 *addr, u64 offset, int na)
77{
78 u64 a = of_read_number(addr, na);
79 memset(addr, 0, na * 4);
80 a += offset;
81 if (na > 1)
82 addr[na - 2] = cpu_to_be32(a >> 32);
83 addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
84
85 return 0;
86}
87
88static unsigned int of_bus_default_get_flags(const u32 *addr)
89{
90 return IORESOURCE_MEM;
91}
92
93#ifdef CONFIG_PCI
94/*
95 * PCI bus specific translator
96 */
97
98static int of_bus_pci_match(struct device_node *np)
99{
100 /* "vci" is for the /chaos bridge on 1st-gen PCI powermacs */
101 return !strcmp(np->type, "pci") || !strcmp(np->type, "vci");
102}
103
104static void of_bus_pci_count_cells(struct device_node *np,
105 int *addrc, int *sizec)
106{
107 if (addrc)
108 *addrc = 3;
109 if (sizec)
110 *sizec = 2;
111}
112
113static unsigned int of_bus_pci_get_flags(const u32 *addr)
114{
115 unsigned int flags = 0;
116 u32 w = addr[0];
117
118 switch((w >> 24) & 0x03) {
119 case 0x01:
120 flags |= IORESOURCE_IO;
121 break;
122 case 0x02: /* 32 bits */
123 case 0x03: /* 64 bits */
124 flags |= IORESOURCE_MEM;
125 break;
126 }
127 if (w & 0x40000000)
128 flags |= IORESOURCE_PREFETCH;
129 return flags;
130}
131
132static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna)
133{
134 u64 cp, s, da;
135 unsigned int af, rf;
136
137 af = of_bus_pci_get_flags(addr);
138 rf = of_bus_pci_get_flags(range);
139
140 /* Check address type match */
141 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
142 return OF_BAD_ADDR;
143
144 /* Read address values, skipping high cell */
145 cp = of_read_number(range + 1, na - 1);
146 s = of_read_number(range + na + pna, ns);
147 da = of_read_number(addr + 1, na - 1);
148
149 pr_debug("OF: PCI map, cp=%llx, s=%llx, da=%llx\n",
150 (unsigned long long)cp, (unsigned long long)s,
151 (unsigned long long)da);
152
153 if (da < cp || da >= (cp + s))
154 return OF_BAD_ADDR;
155 return da - cp;
156}
157
158static int of_bus_pci_translate(u32 *addr, u64 offset, int na)
159{
160 return of_bus_default_translate(addr + 1, offset, na - 1);
161}
162
163const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
164 unsigned int *flags)
165{
166 const u32 *prop;
167 unsigned int psize;
168 struct device_node *parent;
169 struct of_bus *bus;
170 int onesize, i, na, ns;
171
172 /* Get parent & match bus type */
173 parent = of_get_parent(dev);
174 if (parent == NULL)
175 return NULL;
176 bus = of_match_bus(parent);
177 if (strcmp(bus->name, "pci")) {
178 of_node_put(parent);
179 return NULL;
180 }
181 bus->count_cells(dev, &na, &ns);
182 of_node_put(parent);
183 if (!OF_CHECK_COUNTS(na, ns))
184 return NULL;
185
186 /* Get "reg" or "assigned-addresses" property */
187 prop = of_get_property(dev, bus->addresses, &psize);
188 if (prop == NULL)
189 return NULL;
190 psize /= 4;
191
192 onesize = na + ns;
193 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
194 u32 val = be32_to_cpu(prop[0]);
195 if ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
196 if (size)
197 *size = of_read_number(prop + na, ns);
198 if (flags)
199 *flags = bus->get_flags(prop);
200 return prop;
201 }
202 }
203 return NULL;
204}
205EXPORT_SYMBOL(of_get_pci_address);
206
207int of_pci_address_to_resource(struct device_node *dev, int bar,
208 struct resource *r)
209{
210 const u32 *addrp;
211 u64 size;
212 unsigned int flags;
213
214 addrp = of_get_pci_address(dev, bar, &size, &flags);
215 if (addrp == NULL)
216 return -EINVAL;
217 return __of_address_to_resource(dev, addrp, size, flags, r);
218}
219EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
220#endif /* CONFIG_PCI */
221
222/*
223 * ISA bus specific translator
224 */
225
226static int of_bus_isa_match(struct device_node *np)
227{
228 return !strcmp(np->name, "isa");
229}
230
231static void of_bus_isa_count_cells(struct device_node *child,
232 int *addrc, int *sizec)
233{
234 if (addrc)
235 *addrc = 2;
236 if (sizec)
237 *sizec = 1;
238}
239
240static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna)
241{
242 u64 cp, s, da;
243
244 /* Check address type match */
245 if ((addr[0] ^ range[0]) & 0x00000001)
246 return OF_BAD_ADDR;
247
248 /* Read address values, skipping high cell */
249 cp = of_read_number(range + 1, na - 1);
250 s = of_read_number(range + na + pna, ns);
251 da = of_read_number(addr + 1, na - 1);
252
253 pr_debug("OF: ISA map, cp=%llx, s=%llx, da=%llx\n",
254 (unsigned long long)cp, (unsigned long long)s,
255 (unsigned long long)da);
256
257 if (da < cp || da >= (cp + s))
258 return OF_BAD_ADDR;
259 return da - cp;
260}
261
262static int of_bus_isa_translate(u32 *addr, u64 offset, int na)
263{
264 return of_bus_default_translate(addr + 1, offset, na - 1);
265}
266
267static unsigned int of_bus_isa_get_flags(const u32 *addr)
268{
269 unsigned int flags = 0;
270 u32 w = addr[0];
271
272 if (w & 1)
273 flags |= IORESOURCE_IO;
274 else
275 flags |= IORESOURCE_MEM;
276 return flags;
277}
278
279/*
280 * Array of bus specific translators
281 */
282
283static struct of_bus of_busses[] = {
284#ifdef CONFIG_PCI
285 /* PCI */
286 {
287 .name = "pci",
288 .addresses = "assigned-addresses",
289 .match = of_bus_pci_match,
290 .count_cells = of_bus_pci_count_cells,
291 .map = of_bus_pci_map,
292 .translate = of_bus_pci_translate,
293 .get_flags = of_bus_pci_get_flags,
294 },
295#endif /* CONFIG_PCI */
296 /* ISA */
297 {
298 .name = "isa",
299 .addresses = "reg",
300 .match = of_bus_isa_match,
301 .count_cells = of_bus_isa_count_cells,
302 .map = of_bus_isa_map,
303 .translate = of_bus_isa_translate,
304 .get_flags = of_bus_isa_get_flags,
305 },
306 /* Default */
307 {
308 .name = "default",
309 .addresses = "reg",
310 .match = NULL,
311 .count_cells = of_bus_default_count_cells,
312 .map = of_bus_default_map,
313 .translate = of_bus_default_translate,
314 .get_flags = of_bus_default_get_flags,
315 },
316};
317
318static struct of_bus *of_match_bus(struct device_node *np)
319{
320 int i;
321
322 for (i = 0; i < ARRAY_SIZE(of_busses); i++)
323 if (!of_busses[i].match || of_busses[i].match(np))
324 return &of_busses[i];
325 BUG();
326 return NULL;
327}
328
329static int of_translate_one(struct device_node *parent, struct of_bus *bus,
330 struct of_bus *pbus, u32 *addr,
331 int na, int ns, int pna, const char *rprop)
332{
333 const u32 *ranges;
334 unsigned int rlen;
335 int rone;
336 u64 offset = OF_BAD_ADDR;
337
338 /* Normally, an absence of a "ranges" property means we are
339 * crossing a non-translatable boundary, and thus the addresses
340 * below the current not cannot be converted to CPU physical ones.
341 * Unfortunately, while this is very clear in the spec, it's not
342 * what Apple understood, and they do have things like /uni-n or
343 * /ht nodes with no "ranges" property and a lot of perfectly
344 * useable mapped devices below them. Thus we treat the absence of
345 * "ranges" as equivalent to an empty "ranges" property which means
346 * a 1:1 translation at that level. It's up to the caller not to try
347 * to translate addresses that aren't supposed to be translated in
348 * the first place. --BenH.
349 *
350 * As far as we know, this damage only exists on Apple machines, so
351 * This code is only enabled on powerpc. --gcl
352 */
353 ranges = of_get_property(parent, rprop, &rlen);
354#if !defined(CONFIG_PPC)
355 if (ranges == NULL) {
356 pr_err("OF: no ranges; cannot translate\n");
357 return 1;
358 }
359#endif /* !defined(CONFIG_PPC) */
360 if (ranges == NULL || rlen == 0) {
361 offset = of_read_number(addr, na);
362 memset(addr, 0, pna * 4);
363 pr_debug("OF: empty ranges; 1:1 translation\n");
364 goto finish;
365 }
366
367 pr_debug("OF: walking ranges...\n");
368
369 /* Now walk through the ranges */
370 rlen /= 4;
371 rone = na + pna + ns;
372 for (; rlen >= rone; rlen -= rone, ranges += rone) {
373 offset = bus->map(addr, ranges, na, ns, pna);
374 if (offset != OF_BAD_ADDR)
375 break;
376 }
377 if (offset == OF_BAD_ADDR) {
378 pr_debug("OF: not found !\n");
379 return 1;
380 }
381 memcpy(addr, ranges + na, 4 * pna);
382
383 finish:
384 of_dump_addr("OF: parent translation for:", addr, pna);
385 pr_debug("OF: with offset: %llx\n", (unsigned long long)offset);
386
387 /* Translate it into parent bus space */
388 return pbus->translate(addr, offset, pna);
389}
390
391/*
392 * Translate an address from the device-tree into a CPU physical address,
393 * this walks up the tree and applies the various bus mappings on the
394 * way.
395 *
396 * Note: We consider that crossing any level with #size-cells == 0 to mean
397 * that translation is impossible (that is we are not dealing with a value
398 * that can be mapped to a cpu physical address). This is not really specified
399 * that way, but this is traditionally the way IBM at least do things
400 */
401u64 __of_translate_address(struct device_node *dev, const u32 *in_addr,
402 const char *rprop)
403{
404 struct device_node *parent = NULL;
405 struct of_bus *bus, *pbus;
406 u32 addr[OF_MAX_ADDR_CELLS];
407 int na, ns, pna, pns;
408 u64 result = OF_BAD_ADDR;
409
410 pr_debug("OF: ** translation for device %s **\n", dev->full_name);
411
412 /* Increase refcount at current level */
413 of_node_get(dev);
414
415 /* Get parent & match bus type */
416 parent = of_get_parent(dev);
417 if (parent == NULL)
418 goto bail;
419 bus = of_match_bus(parent);
420
421 /* Cound address cells & copy address locally */
422 bus->count_cells(dev, &na, &ns);
423 if (!OF_CHECK_COUNTS(na, ns)) {
424 printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
425 dev->full_name);
426 goto bail;
427 }
428 memcpy(addr, in_addr, na * 4);
429
430 pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
431 bus->name, na, ns, parent->full_name);
432 of_dump_addr("OF: translating address:", addr, na);
433
434 /* Translate */
435 for (;;) {
436 /* Switch to parent bus */
437 of_node_put(dev);
438 dev = parent;
439 parent = of_get_parent(dev);
440
441 /* If root, we have finished */
442 if (parent == NULL) {
443 pr_debug("OF: reached root node\n");
444 result = of_read_number(addr, na);
445 break;
446 }
447
448 /* Get new parent bus and counts */
449 pbus = of_match_bus(parent);
450 pbus->count_cells(dev, &pna, &pns);
451 if (!OF_CHECK_COUNTS(pna, pns)) {
452 printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
453 dev->full_name);
454 break;
455 }
456
457 pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
458 pbus->name, pna, pns, parent->full_name);
459
460 /* Apply bus translation */
461 if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
462 break;
463
464 /* Complete the move up one level */
465 na = pna;
466 ns = pns;
467 bus = pbus;
468
469 of_dump_addr("OF: one level translation:", addr, na);
470 }
471 bail:
472 of_node_put(parent);
473 of_node_put(dev);
474
475 return result;
476}
477
478u64 of_translate_address(struct device_node *dev, const u32 *in_addr)
479{
480 return __of_translate_address(dev, in_addr, "ranges");
481}
482EXPORT_SYMBOL(of_translate_address);
483
484u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr)
485{
486 return __of_translate_address(dev, in_addr, "dma-ranges");
487}
488EXPORT_SYMBOL(of_translate_dma_address);
489
490const u32 *of_get_address(struct device_node *dev, int index, u64 *size,
491 unsigned int *flags)
492{
493 const u32 *prop;
494 unsigned int psize;
495 struct device_node *parent;
496 struct of_bus *bus;
497 int onesize, i, na, ns;
498
499 /* Get parent & match bus type */
500 parent = of_get_parent(dev);
501 if (parent == NULL)
502 return NULL;
503 bus = of_match_bus(parent);
504 bus->count_cells(dev, &na, &ns);
505 of_node_put(parent);
506 if (!OF_CHECK_COUNTS(na, ns))
507 return NULL;
508
509 /* Get "reg" or "assigned-addresses" property */
510 prop = of_get_property(dev, bus->addresses, &psize);
511 if (prop == NULL)
512 return NULL;
513 psize /= 4;
514
515 onesize = na + ns;
516 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
517 if (i == index) {
518 if (size)
519 *size = of_read_number(prop + na, ns);
520 if (flags)
521 *flags = bus->get_flags(prop);
522 return prop;
523 }
524 return NULL;
525}
526EXPORT_SYMBOL(of_get_address);
527
528static int __of_address_to_resource(struct device_node *dev, const u32 *addrp,
529 u64 size, unsigned int flags,
530 struct resource *r)
531{
532 u64 taddr;
533
534 if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
535 return -EINVAL;
536 taddr = of_translate_address(dev, addrp);
537 if (taddr == OF_BAD_ADDR)
538 return -EINVAL;
539 memset(r, 0, sizeof(struct resource));
540 if (flags & IORESOURCE_IO) {
541 unsigned long port;
542 port = pci_address_to_pio(taddr);
543 if (port == (unsigned long)-1)
544 return -EINVAL;
545 r->start = port;
546 r->end = port + size - 1;
547 } else {
548 r->start = taddr;
549 r->end = taddr + size - 1;
550 }
551 r->flags = flags;
552 r->name = dev->full_name;
553 return 0;
554}
555
556/**
557 * of_address_to_resource - Translate device tree address and return as resource
558 *
559 * Note that if your address is a PIO address, the conversion will fail if
560 * the physical address can't be internally converted to an IO token with
561 * pci_address_to_pio(), that is because it's either called to early or it
562 * can't be matched to any host bridge IO space
563 */
564int of_address_to_resource(struct device_node *dev, int index,
565 struct resource *r)
566{
567 const u32 *addrp;
568 u64 size;
569 unsigned int flags;
570
571 addrp = of_get_address(dev, index, &size, &flags);
572 if (addrp == NULL)
573 return -EINVAL;
574 return __of_address_to_resource(dev, addrp, size, flags, r);
575}
576EXPORT_SYMBOL_GPL(of_address_to_resource);
577
578
579/**
580 * of_iomap - Maps the memory mapped IO for a given device_node
581 * @device: the device whose io range will be mapped
582 * @index: index of the io range
583 *
584 * Returns a pointer to the mapped memory
585 */
586void __iomem *of_iomap(struct device_node *np, int index)
587{
588 struct resource res;
589
590 if (of_address_to_resource(np, index, &res))
591 return NULL;
592
593 return ioremap(res.start, 1 + res.end - res.start);
594}
595EXPORT_SYMBOL(of_iomap);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b5ad9740d8b2..aa805250de76 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -545,74 +545,28 @@ struct device_node *of_find_matching_node(struct device_node *from,
545EXPORT_SYMBOL(of_find_matching_node); 545EXPORT_SYMBOL(of_find_matching_node);
546 546
547/** 547/**
548 * of_modalias_table: Table of explicit compatible ==> modalias mappings
549 *
550 * This table allows particulare compatible property values to be mapped
551 * to modalias strings. This is useful for busses which do not directly
552 * understand the OF device tree but are populated based on data contained
553 * within the device tree. SPI and I2C are the two current users of this
554 * table.
555 *
556 * In most cases, devices do not need to be listed in this table because
557 * the modalias value can be derived directly from the compatible table.
558 * However, if for any reason a value cannot be derived, then this table
559 * provides a method to override the implicit derivation.
560 *
561 * At the moment, a single table is used for all bus types because it is
562 * assumed that the data size is small and that the compatible values
563 * should already be distinct enough to differentiate between SPI, I2C
564 * and other devices.
565 */
566struct of_modalias_table {
567 char *of_device;
568 char *modalias;
569};
570static struct of_modalias_table of_modalias_table[] = {
571 { "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
572 { "mmc-spi-slot", "mmc_spi" },
573};
574
575/**
576 * of_modalias_node - Lookup appropriate modalias for a device node 548 * of_modalias_node - Lookup appropriate modalias for a device node
577 * @node: pointer to a device tree node 549 * @node: pointer to a device tree node
578 * @modalias: Pointer to buffer that modalias value will be copied into 550 * @modalias: Pointer to buffer that modalias value will be copied into
579 * @len: Length of modalias value 551 * @len: Length of modalias value
580 * 552 *
581 * Based on the value of the compatible property, this routine will determine 553 * Based on the value of the compatible property, this routine will attempt
582 * an appropriate modalias value for a particular device tree node. Two 554 * to choose an appropriate modalias value for a particular device tree node.
583 * separate methods are attempted to derive a modalias value. 555 * It does this by stripping the manufacturer prefix (as delimited by a ',')
556 * from the first entry in the compatible list property.
584 * 557 *
585 * First method is to lookup the compatible value in of_modalias_table. 558 * This routine returns 0 on success, <0 on failure.
586 * Second is to strip off the manufacturer prefix from the first
587 * compatible entry and use the remainder as modalias
588 *
589 * This routine returns 0 on success
590 */ 559 */
591int of_modalias_node(struct device_node *node, char *modalias, int len) 560int of_modalias_node(struct device_node *node, char *modalias, int len)
592{ 561{
593 int i, cplen; 562 const char *compatible, *p;
594 const char *compatible; 563 int cplen;
595 const char *p;
596
597 /* 1. search for exception list entry */
598 for (i = 0; i < ARRAY_SIZE(of_modalias_table); i++) {
599 compatible = of_modalias_table[i].of_device;
600 if (!of_device_is_compatible(node, compatible))
601 continue;
602 strlcpy(modalias, of_modalias_table[i].modalias, len);
603 return 0;
604 }
605 564
606 compatible = of_get_property(node, "compatible", &cplen); 565 compatible = of_get_property(node, "compatible", &cplen);
607 if (!compatible) 566 if (!compatible || strlen(compatible) > cplen)
608 return -ENODEV; 567 return -ENODEV;
609
610 /* 2. take first compatible entry and strip manufacturer */
611 p = strchr(compatible, ','); 568 p = strchr(compatible, ',');
612 if (!p) 569 strlcpy(modalias, p ? p + 1 : compatible, len);
613 return -ENODEV;
614 p++;
615 strlcpy(modalias, p, len);
616 return 0; 570 return 0;
617} 571}
618EXPORT_SYMBOL_GPL(of_modalias_node); 572EXPORT_SYMBOL_GPL(of_modalias_node);
@@ -651,14 +605,14 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
651struct device_node * 605struct device_node *
652of_parse_phandle(struct device_node *np, const char *phandle_name, int index) 606of_parse_phandle(struct device_node *np, const char *phandle_name, int index)
653{ 607{
654 const phandle *phandle; 608 const __be32 *phandle;
655 int size; 609 int size;
656 610
657 phandle = of_get_property(np, phandle_name, &size); 611 phandle = of_get_property(np, phandle_name, &size);
658 if ((!phandle) || (size < sizeof(*phandle) * (index + 1))) 612 if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
659 return NULL; 613 return NULL;
660 614
661 return of_find_node_by_phandle(phandle[index]); 615 return of_find_node_by_phandle(be32_to_cpup(phandle + index));
662} 616}
663EXPORT_SYMBOL(of_parse_phandle); 617EXPORT_SYMBOL(of_parse_phandle);
664 618
@@ -714,16 +668,16 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
714 668
715 while (list < list_end) { 669 while (list < list_end) {
716 const __be32 *cells; 670 const __be32 *cells;
717 const phandle *phandle; 671 phandle phandle;
718 672
719 phandle = list++; 673 phandle = be32_to_cpup(list++);
720 args = list; 674 args = list;
721 675
722 /* one cell hole in the list = <>; */ 676 /* one cell hole in the list = <>; */
723 if (!*phandle) 677 if (!phandle)
724 goto next; 678 goto next;
725 679
726 node = of_find_node_by_phandle(*phandle); 680 node = of_find_node_by_phandle(phandle);
727 if (!node) { 681 if (!node) {
728 pr_debug("%s: could not find phandle\n", 682 pr_debug("%s: could not find phandle\n",
729 np->full_name); 683 np->full_name);
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 7d18f8e0b013..0d8a0644f540 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -20,13 +20,13 @@
20const struct of_device_id *of_match_device(const struct of_device_id *matches, 20const struct of_device_id *of_match_device(const struct of_device_id *matches,
21 const struct device *dev) 21 const struct device *dev)
22{ 22{
23 if (!dev->of_node) 23 if ((!matches) || (!dev->of_node))
24 return NULL; 24 return NULL;
25 return of_match_node(matches, dev->of_node); 25 return of_match_node(matches, dev->of_node);
26} 26}
27EXPORT_SYMBOL(of_match_device); 27EXPORT_SYMBOL(of_match_device);
28 28
29struct of_device *of_dev_get(struct of_device *dev) 29struct platform_device *of_dev_get(struct platform_device *dev)
30{ 30{
31 struct device *tmp; 31 struct device *tmp;
32 32
@@ -34,13 +34,13 @@ struct of_device *of_dev_get(struct of_device *dev)
34 return NULL; 34 return NULL;
35 tmp = get_device(&dev->dev); 35 tmp = get_device(&dev->dev);
36 if (tmp) 36 if (tmp)
37 return to_of_device(tmp); 37 return to_platform_device(tmp);
38 else 38 else
39 return NULL; 39 return NULL;
40} 40}
41EXPORT_SYMBOL(of_dev_get); 41EXPORT_SYMBOL(of_dev_get);
42 42
43void of_dev_put(struct of_device *dev) 43void of_dev_put(struct platform_device *dev)
44{ 44{
45 if (dev) 45 if (dev)
46 put_device(&dev->dev); 46 put_device(&dev->dev);
@@ -50,28 +50,25 @@ EXPORT_SYMBOL(of_dev_put);
50static ssize_t devspec_show(struct device *dev, 50static ssize_t devspec_show(struct device *dev,
51 struct device_attribute *attr, char *buf) 51 struct device_attribute *attr, char *buf)
52{ 52{
53 struct of_device *ofdev; 53 struct platform_device *ofdev;
54 54
55 ofdev = to_of_device(dev); 55 ofdev = to_platform_device(dev);
56 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name); 56 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
57} 57}
58 58
59static ssize_t name_show(struct device *dev, 59static ssize_t name_show(struct device *dev,
60 struct device_attribute *attr, char *buf) 60 struct device_attribute *attr, char *buf)
61{ 61{
62 struct of_device *ofdev; 62 struct platform_device *ofdev;
63 63
64 ofdev = to_of_device(dev); 64 ofdev = to_platform_device(dev);
65 return sprintf(buf, "%s\n", ofdev->dev.of_node->name); 65 return sprintf(buf, "%s\n", ofdev->dev.of_node->name);
66} 66}
67 67
68static ssize_t modalias_show(struct device *dev, 68static ssize_t modalias_show(struct device *dev,
69 struct device_attribute *attr, char *buf) 69 struct device_attribute *attr, char *buf)
70{ 70{
71 struct of_device *ofdev = to_of_device(dev); 71 ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
72 ssize_t len = 0;
73
74 len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2);
75 buf[len] = '\n'; 72 buf[len] = '\n';
76 buf[len+1] = 0; 73 buf[len+1] = 0;
77 return len+1; 74 return len+1;
@@ -93,20 +90,25 @@ struct device_attribute of_platform_device_attrs[] = {
93 */ 90 */
94void of_release_dev(struct device *dev) 91void of_release_dev(struct device *dev)
95{ 92{
96 struct of_device *ofdev; 93 struct platform_device *ofdev;
97 94
98 ofdev = to_of_device(dev); 95 ofdev = to_platform_device(dev);
99 of_node_put(ofdev->dev.of_node); 96 of_node_put(ofdev->dev.of_node);
100 kfree(ofdev); 97 kfree(ofdev);
101} 98}
102EXPORT_SYMBOL(of_release_dev); 99EXPORT_SYMBOL(of_release_dev);
103 100
104int of_device_register(struct of_device *ofdev) 101int of_device_register(struct platform_device *ofdev)
105{ 102{
106 BUG_ON(ofdev->dev.of_node == NULL); 103 BUG_ON(ofdev->dev.of_node == NULL);
107 104
108 device_initialize(&ofdev->dev); 105 device_initialize(&ofdev->dev);
109 106
107 /* name and id have to be set so that the platform bus doesn't get
108 * confused on matching */
109 ofdev->name = dev_name(&ofdev->dev);
110 ofdev->id = -1;
111
110 /* device_add will assume that this device is on the same node as 112 /* device_add will assume that this device is on the same node as
111 * the parent. If there is no parent defined, set the node 113 * the parent. If there is no parent defined, set the node
112 * explicitly */ 114 * explicitly */
@@ -117,25 +119,24 @@ int of_device_register(struct of_device *ofdev)
117} 119}
118EXPORT_SYMBOL(of_device_register); 120EXPORT_SYMBOL(of_device_register);
119 121
120void of_device_unregister(struct of_device *ofdev) 122void of_device_unregister(struct platform_device *ofdev)
121{ 123{
122 device_unregister(&ofdev->dev); 124 device_unregister(&ofdev->dev);
123} 125}
124EXPORT_SYMBOL(of_device_unregister); 126EXPORT_SYMBOL(of_device_unregister);
125 127
126ssize_t of_device_get_modalias(struct of_device *ofdev, 128ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
127 char *str, ssize_t len)
128{ 129{
129 const char *compat; 130 const char *compat;
130 int cplen, i; 131 int cplen, i;
131 ssize_t tsize, csize, repend; 132 ssize_t tsize, csize, repend;
132 133
133 /* Name & Type */ 134 /* Name & Type */
134 csize = snprintf(str, len, "of:N%sT%s", ofdev->dev.of_node->name, 135 csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
135 ofdev->dev.of_node->type); 136 dev->of_node->type);
136 137
137 /* Get compatible property if any */ 138 /* Get compatible property if any */
138 compat = of_get_property(ofdev->dev.of_node, "compatible", &cplen); 139 compat = of_get_property(dev->of_node, "compatible", &cplen);
139 if (!compat) 140 if (!compat)
140 return csize; 141 return csize;
141 142
@@ -170,3 +171,51 @@ ssize_t of_device_get_modalias(struct of_device *ofdev,
170 171
171 return tsize; 172 return tsize;
172} 173}
174
175/**
176 * of_device_uevent - Display OF related uevent information
177 */
178int of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
179{
180 const char *compat;
181 int seen = 0, cplen, sl;
182
183 if ((!dev) || (!dev->of_node))
184 return -ENODEV;
185
186 if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name))
187 return -ENOMEM;
188
189 if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type))
190 return -ENOMEM;
191
192 /* Since the compatible field can contain pretty much anything
193 * it's not really legal to split it out with commas. We split it
194 * up using a number of environment variables instead. */
195
196 compat = of_get_property(dev->of_node, "compatible", &cplen);
197 while (compat && *compat && cplen > 0) {
198 if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat))
199 return -ENOMEM;
200
201 sl = strlen(compat) + 1;
202 compat += sl;
203 cplen -= sl;
204 seen++;
205 }
206
207 if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen))
208 return -ENOMEM;
209
210 /* modalias is trickier, we add it in 2 steps */
211 if (add_uevent_var(env, "MODALIAS="))
212 return -ENOMEM;
213
214 sl = of_device_get_modalias(dev, &env->buf[env->buflen-1],
215 sizeof(env->buf) - env->buflen);
216 if (sl >= (sizeof(env->buf) - env->buflen))
217 return -ENOMEM;
218 env->buflen += sl;
219
220 return 0;
221}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index b6987bba8556..65da5aec7552 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -69,9 +69,9 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
69 u32 sz = be32_to_cpup((__be32 *)p); 69 u32 sz = be32_to_cpup((__be32 *)p);
70 p += 8; 70 p += 8;
71 if (be32_to_cpu(initial_boot_params->version) < 0x10) 71 if (be32_to_cpu(initial_boot_params->version) < 0x10)
72 p = _ALIGN(p, sz >= 8 ? 8 : 4); 72 p = ALIGN(p, sz >= 8 ? 8 : 4);
73 p += sz; 73 p += sz;
74 p = _ALIGN(p, 4); 74 p = ALIGN(p, 4);
75 continue; 75 continue;
76 } 76 }
77 if (tag != OF_DT_BEGIN_NODE) { 77 if (tag != OF_DT_BEGIN_NODE) {
@@ -80,7 +80,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node,
80 } 80 }
81 depth++; 81 depth++;
82 pathp = (char *)p; 82 pathp = (char *)p;
83 p = _ALIGN(p + strlen(pathp) + 1, 4); 83 p = ALIGN(p + strlen(pathp) + 1, 4);
84 if ((*pathp) == '/') { 84 if ((*pathp) == '/') {
85 char *lp, *np; 85 char *lp, *np;
86 for (lp = NULL, np = pathp; *np; np++) 86 for (lp = NULL, np = pathp; *np; np++)
@@ -109,7 +109,7 @@ unsigned long __init of_get_flat_dt_root(void)
109 p += 4; 109 p += 4;
110 BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE); 110 BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE);
111 p += 4; 111 p += 4;
112 return _ALIGN(p + strlen((char *)p) + 1, 4); 112 return ALIGN(p + strlen((char *)p) + 1, 4);
113} 113}
114 114
115/** 115/**
@@ -138,7 +138,7 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
138 noff = be32_to_cpup((__be32 *)(p + 4)); 138 noff = be32_to_cpup((__be32 *)(p + 4));
139 p += 8; 139 p += 8;
140 if (be32_to_cpu(initial_boot_params->version) < 0x10) 140 if (be32_to_cpu(initial_boot_params->version) < 0x10)
141 p = _ALIGN(p, sz >= 8 ? 8 : 4); 141 p = ALIGN(p, sz >= 8 ? 8 : 4);
142 142
143 nstr = find_flat_dt_string(noff); 143 nstr = find_flat_dt_string(noff);
144 if (nstr == NULL) { 144 if (nstr == NULL) {
@@ -151,7 +151,7 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
151 return (void *)p; 151 return (void *)p;
152 } 152 }
153 p += sz; 153 p += sz;
154 p = _ALIGN(p, 4); 154 p = ALIGN(p, 4);
155 } while (1); 155 } while (1);
156} 156}
157 157
@@ -169,7 +169,7 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
169 if (cp == NULL) 169 if (cp == NULL)
170 return 0; 170 return 0;
171 while (cplen > 0) { 171 while (cplen > 0) {
172 if (strncasecmp(cp, compat, strlen(compat)) == 0) 172 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
173 return 1; 173 return 1;
174 l = strlen(cp) + 1; 174 l = strlen(cp) + 1;
175 cp += l; 175 cp += l;
@@ -184,7 +184,7 @@ static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
184{ 184{
185 void *res; 185 void *res;
186 186
187 *mem = _ALIGN(*mem, align); 187 *mem = ALIGN(*mem, align);
188 res = (void *)*mem; 188 res = (void *)*mem;
189 *mem += size; 189 *mem += size;
190 190
@@ -220,7 +220,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
220 *p += 4; 220 *p += 4;
221 pathp = (char *)*p; 221 pathp = (char *)*p;
222 l = allocl = strlen(pathp) + 1; 222 l = allocl = strlen(pathp) + 1;
223 *p = _ALIGN(*p + l, 4); 223 *p = ALIGN(*p + l, 4);
224 224
225 /* version 0x10 has a more compact unit name here instead of the full 225 /* version 0x10 has a more compact unit name here instead of the full
226 * path. we accumulate the full path size using "fpsize", we'll rebuild 226 * path. we accumulate the full path size using "fpsize", we'll rebuild
@@ -299,7 +299,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
299 noff = be32_to_cpup((__be32 *)((*p) + 4)); 299 noff = be32_to_cpup((__be32 *)((*p) + 4));
300 *p += 8; 300 *p += 8;
301 if (be32_to_cpu(initial_boot_params->version) < 0x10) 301 if (be32_to_cpu(initial_boot_params->version) < 0x10)
302 *p = _ALIGN(*p, sz >= 8 ? 8 : 4); 302 *p = ALIGN(*p, sz >= 8 ? 8 : 4);
303 303
304 pname = find_flat_dt_string(noff); 304 pname = find_flat_dt_string(noff);
305 if (pname == NULL) { 305 if (pname == NULL) {
@@ -320,20 +320,20 @@ unsigned long __init unflatten_dt_node(unsigned long mem,
320 if ((strcmp(pname, "phandle") == 0) || 320 if ((strcmp(pname, "phandle") == 0) ||
321 (strcmp(pname, "linux,phandle") == 0)) { 321 (strcmp(pname, "linux,phandle") == 0)) {
322 if (np->phandle == 0) 322 if (np->phandle == 0)
323 np->phandle = *((u32 *)*p); 323 np->phandle = be32_to_cpup((__be32*)*p);
324 } 324 }
325 /* And we process the "ibm,phandle" property 325 /* And we process the "ibm,phandle" property
326 * used in pSeries dynamic device tree 326 * used in pSeries dynamic device tree
327 * stuff */ 327 * stuff */
328 if (strcmp(pname, "ibm,phandle") == 0) 328 if (strcmp(pname, "ibm,phandle") == 0)
329 np->phandle = *((u32 *)*p); 329 np->phandle = be32_to_cpup((__be32 *)*p);
330 pp->name = pname; 330 pp->name = pname;
331 pp->length = sz; 331 pp->length = sz;
332 pp->value = (void *)*p; 332 pp->value = (void *)*p;
333 *prev_pp = pp; 333 *prev_pp = pp;
334 prev_pp = &pp->next; 334 prev_pp = &pp->next;
335 } 335 }
336 *p = _ALIGN((*p) + sz, 4); 336 *p = ALIGN((*p) + sz, 4);
337 } 337 }
338 /* with version 0x10 we may not have the name property, recreate 338 /* with version 0x10 we may not have the name property, recreate
339 * it here from the unit name if absent 339 * it here from the unit name if absent
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index a1b31a4abae4..905960338fb2 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -11,13 +11,14 @@
11 * (at your option) any later version. 11 * (at your option) any later version.
12 */ 12 */
13 13
14#include <linux/kernel.h> 14#include <linux/device.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/module.h>
16#include <linux/io.h> 17#include <linux/io.h>
17#include <linux/of.h> 18#include <linux/of.h>
18#include <linux/slab.h> 19#include <linux/of_address.h>
19#include <linux/of_gpio.h> 20#include <linux/of_gpio.h>
20#include <asm/prom.h> 21#include <linux/slab.h>
21 22
22/** 23/**
23 * of_get_gpio_flags - Get a GPIO number and flags to use with GPIO API 24 * of_get_gpio_flags - Get a GPIO number and flags to use with GPIO API
@@ -33,32 +34,32 @@ int of_get_gpio_flags(struct device_node *np, int index,
33 enum of_gpio_flags *flags) 34 enum of_gpio_flags *flags)
34{ 35{
35 int ret; 36 int ret;
36 struct device_node *gc; 37 struct device_node *gpio_np;
37 struct of_gpio_chip *of_gc = NULL; 38 struct gpio_chip *gc;
38 int size; 39 int size;
39 const void *gpio_spec; 40 const void *gpio_spec;
40 const __be32 *gpio_cells; 41 const __be32 *gpio_cells;
41 42
42 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, 43 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
43 &gc, &gpio_spec); 44 &gpio_np, &gpio_spec);
44 if (ret) { 45 if (ret) {
45 pr_debug("%s: can't parse gpios property\n", __func__); 46 pr_debug("%s: can't parse gpios property\n", __func__);
46 goto err0; 47 goto err0;
47 } 48 }
48 49
49 of_gc = gc->data; 50 gc = of_node_to_gpiochip(gpio_np);
50 if (!of_gc) { 51 if (!gc) {
51 pr_debug("%s: gpio controller %s isn't registered\n", 52 pr_debug("%s: gpio controller %s isn't registered\n",
52 np->full_name, gc->full_name); 53 np->full_name, gpio_np->full_name);
53 ret = -ENODEV; 54 ret = -ENODEV;
54 goto err1; 55 goto err1;
55 } 56 }
56 57
57 gpio_cells = of_get_property(gc, "#gpio-cells", &size); 58 gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size);
58 if (!gpio_cells || size != sizeof(*gpio_cells) || 59 if (!gpio_cells || size != sizeof(*gpio_cells) ||
59 be32_to_cpup(gpio_cells) != of_gc->gpio_cells) { 60 be32_to_cpup(gpio_cells) != gc->of_gpio_n_cells) {
60 pr_debug("%s: wrong #gpio-cells for %s\n", 61 pr_debug("%s: wrong #gpio-cells for %s\n",
61 np->full_name, gc->full_name); 62 np->full_name, gpio_np->full_name);
62 ret = -EINVAL; 63 ret = -EINVAL;
63 goto err1; 64 goto err1;
64 } 65 }
@@ -67,13 +68,13 @@ int of_get_gpio_flags(struct device_node *np, int index,
67 if (flags) 68 if (flags)
68 *flags = 0; 69 *flags = 0;
69 70
70 ret = of_gc->xlate(of_gc, np, gpio_spec, flags); 71 ret = gc->of_xlate(gc, np, gpio_spec, flags);
71 if (ret < 0) 72 if (ret < 0)
72 goto err1; 73 goto err1;
73 74
74 ret += of_gc->gc.base; 75 ret += gc->base;
75err1: 76err1:
76 of_node_put(gc); 77 of_node_put(gpio_np);
77err0: 78err0:
78 pr_debug("%s exited with status %d\n", __func__, ret); 79 pr_debug("%s exited with status %d\n", __func__, ret);
79 return ret; 80 return ret;
@@ -116,7 +117,7 @@ EXPORT_SYMBOL(of_gpio_count);
116 117
117/** 118/**
118 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 119 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
119 * @of_gc: pointer to the of_gpio_chip structure 120 * @gc: pointer to the gpio_chip structure
120 * @np: device node of the GPIO chip 121 * @np: device node of the GPIO chip
121 * @gpio_spec: gpio specifier as found in the device tree 122 * @gpio_spec: gpio specifier as found in the device tree
122 * @flags: a flags pointer to fill in 123 * @flags: a flags pointer to fill in
@@ -125,8 +126,8 @@ EXPORT_SYMBOL(of_gpio_count);
125 * gpio chips. This function performs only one sanity check: whether gpio 126 * gpio chips. This function performs only one sanity check: whether gpio
126 * is less than ngpios (that is specified in the gpio_chip). 127 * is less than ngpios (that is specified in the gpio_chip).
127 */ 128 */
128int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, 129static int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
129 const void *gpio_spec, enum of_gpio_flags *flags) 130 const void *gpio_spec, u32 *flags)
130{ 131{
131 const __be32 *gpio = gpio_spec; 132 const __be32 *gpio = gpio_spec;
132 const u32 n = be32_to_cpup(gpio); 133 const u32 n = be32_to_cpup(gpio);
@@ -137,12 +138,12 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
137 * number and the flags from a single gpio cell -- this is possible, 138 * number and the flags from a single gpio cell -- this is possible,
138 * but not recommended). 139 * but not recommended).
139 */ 140 */
140 if (of_gc->gpio_cells < 2) { 141 if (gc->of_gpio_n_cells < 2) {
141 WARN_ON(1); 142 WARN_ON(1);
142 return -EINVAL; 143 return -EINVAL;
143 } 144 }
144 145
145 if (n > of_gc->gc.ngpio) 146 if (n > gc->ngpio)
146 return -EINVAL; 147 return -EINVAL;
147 148
148 if (flags) 149 if (flags)
@@ -150,7 +151,6 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
150 151
151 return n; 152 return n;
152} 153}
153EXPORT_SYMBOL(of_gpio_simple_xlate);
154 154
155/** 155/**
156 * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank) 156 * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank)
@@ -161,10 +161,8 @@ EXPORT_SYMBOL(of_gpio_simple_xlate);
161 * 161 *
162 * 1) In the gpio_chip structure: 162 * 1) In the gpio_chip structure:
163 * - all the callbacks 163 * - all the callbacks
164 * 164 * - of_gpio_n_cells
165 * 2) In the of_gpio_chip structure: 165 * - of_xlate callback (optional)
166 * - gpio_cells
167 * - xlate callback (optional)
168 * 166 *
169 * 3) In the of_mm_gpio_chip structure: 167 * 3) In the of_mm_gpio_chip structure:
170 * - save_regs callback (optional) 168 * - save_regs callback (optional)
@@ -177,8 +175,7 @@ int of_mm_gpiochip_add(struct device_node *np,
177 struct of_mm_gpio_chip *mm_gc) 175 struct of_mm_gpio_chip *mm_gc)
178{ 176{
179 int ret = -ENOMEM; 177 int ret = -ENOMEM;
180 struct of_gpio_chip *of_gc = &mm_gc->of_gc; 178 struct gpio_chip *gc = &mm_gc->gc;
181 struct gpio_chip *gc = &of_gc->gc;
182 179
183 gc->label = kstrdup(np->full_name, GFP_KERNEL); 180 gc->label = kstrdup(np->full_name, GFP_KERNEL);
184 if (!gc->label) 181 if (!gc->label)
@@ -190,26 +187,19 @@ int of_mm_gpiochip_add(struct device_node *np,
190 187
191 gc->base = -1; 188 gc->base = -1;
192 189
193 if (!of_gc->xlate)
194 of_gc->xlate = of_gpio_simple_xlate;
195
196 if (mm_gc->save_regs) 190 if (mm_gc->save_regs)
197 mm_gc->save_regs(mm_gc); 191 mm_gc->save_regs(mm_gc);
198 192
199 np->data = of_gc; 193 mm_gc->gc.of_node = np;
200 194
201 ret = gpiochip_add(gc); 195 ret = gpiochip_add(gc);
202 if (ret) 196 if (ret)
203 goto err2; 197 goto err2;
204 198
205 /* We don't want to lose the node and its ->data */
206 of_node_get(np);
207
208 pr_debug("%s: registered as generic GPIO chip, base is %d\n", 199 pr_debug("%s: registered as generic GPIO chip, base is %d\n",
209 np->full_name, gc->base); 200 np->full_name, gc->base);
210 return 0; 201 return 0;
211err2: 202err2:
212 np->data = NULL;
213 iounmap(mm_gc->regs); 203 iounmap(mm_gc->regs);
214err1: 204err1:
215 kfree(gc->label); 205 kfree(gc->label);
@@ -219,3 +209,36 @@ err0:
219 return ret; 209 return ret;
220} 210}
221EXPORT_SYMBOL(of_mm_gpiochip_add); 211EXPORT_SYMBOL(of_mm_gpiochip_add);
212
213void of_gpiochip_add(struct gpio_chip *chip)
214{
215 if ((!chip->of_node) && (chip->dev))
216 chip->of_node = chip->dev->of_node;
217
218 if (!chip->of_node)
219 return;
220
221 if (!chip->of_xlate) {
222 chip->of_gpio_n_cells = 2;
223 chip->of_xlate = of_gpio_simple_xlate;
224 }
225
226 of_node_get(chip->of_node);
227}
228
229void of_gpiochip_remove(struct gpio_chip *chip)
230{
231 if (chip->of_node)
232 of_node_put(chip->of_node);
233}
234
235/* Private function for resolving node pointer to gpio_chip */
236static int of_gpiochip_is_match(struct gpio_chip *chip, void *data)
237{
238 return chip->of_node == data;
239}
240
241struct gpio_chip *of_node_to_gpiochip(struct device_node *np)
242{
243 return gpiochip_find(np, of_gpiochip_is_match);
244}
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
new file mode 100644
index 000000000000..6e595e5a3977
--- /dev/null
+++ b/drivers/of/irq.c
@@ -0,0 +1,349 @@
1/*
2 * Derived from arch/i386/kernel/irq.c
3 * Copyright (C) 1992 Linus Torvalds
4 * Adapted from arch/i386 by Gary Thomas
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Updated and modified by Cort Dougan <cort@fsmlabs.com>
7 * Copyright (C) 1996-2001 Cort Dougan
8 * Adapted for Power Macintosh by Paul Mackerras
9 * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * This file contains the code used to make IRQ descriptions in the
17 * device tree to actual irq numbers on an interrupt controller
18 * driver.
19 */
20
21#include <linux/errno.h>
22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/of_irq.h>
25#include <linux/string.h>
26
27/**
28 * irq_of_parse_and_map - Parse and map an interrupt into linux virq space
29 * @device: Device node of the device whose interrupt is to be mapped
30 * @index: Index of the interrupt to map
31 *
32 * This function is a wrapper that chains of_irq_map_one() and
33 * irq_create_of_mapping() to make things easier to callers
34 */
35unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
36{
37 struct of_irq oirq;
38
39 if (of_irq_map_one(dev, index, &oirq))
40 return NO_IRQ;
41
42 return irq_create_of_mapping(oirq.controller, oirq.specifier,
43 oirq.size);
44}
45EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
46
47/**
48 * of_irq_find_parent - Given a device node, find its interrupt parent node
49 * @child: pointer to device node
50 *
51 * Returns a pointer to the interrupt parent node, or NULL if the interrupt
52 * parent could not be determined.
53 */
54static struct device_node *of_irq_find_parent(struct device_node *child)
55{
56 struct device_node *p;
57 const __be32 *parp;
58
59 if (!of_node_get(child))
60 return NULL;
61
62 do {
63 parp = of_get_property(child, "interrupt-parent", NULL);
64 if (parp == NULL)
65 p = of_get_parent(child);
66 else {
67 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
68 p = of_node_get(of_irq_dflt_pic);
69 else
70 p = of_find_node_by_phandle(be32_to_cpup(parp));
71 }
72 of_node_put(child);
73 child = p;
74 } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
75
76 return p;
77}
78
79/**
80 * of_irq_map_raw - Low level interrupt tree parsing
81 * @parent: the device interrupt parent
82 * @intspec: interrupt specifier ("interrupts" property of the device)
83 * @ointsize: size of the passed in interrupt specifier
84 * @addr: address specifier (start of "reg" property of the device)
85 * @out_irq: structure of_irq filled by this function
86 *
87 * Returns 0 on success and a negative number on error
88 *
89 * This function is a low-level interrupt tree walking function. It
90 * can be used to do a partial walk with synthetized reg and interrupts
91 * properties, for example when resolving PCI interrupts when no device
92 * node exist for the parent.
93 */
94int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,
95 u32 ointsize, const __be32 *addr, struct of_irq *out_irq)
96{
97 struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL;
98 const __be32 *tmp, *imap, *imask;
99 u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0;
100 int imaplen, match, i;
101
102 pr_debug("of_irq_map_raw: par=%s,intspec=[0x%08x 0x%08x...],ointsize=%d\n",
103 parent->full_name, be32_to_cpup(intspec),
104 be32_to_cpup(intspec + 1), ointsize);
105
106 ipar = of_node_get(parent);
107
108 /* First get the #interrupt-cells property of the current cursor
109 * that tells us how to interpret the passed-in intspec. If there
110 * is none, we are nice and just walk up the tree
111 */
112 do {
113 tmp = of_get_property(ipar, "#interrupt-cells", NULL);
114 if (tmp != NULL) {
115 intsize = be32_to_cpu(*tmp);
116 break;
117 }
118 tnode = ipar;
119 ipar = of_irq_find_parent(ipar);
120 of_node_put(tnode);
121 } while (ipar);
122 if (ipar == NULL) {
123 pr_debug(" -> no parent found !\n");
124 goto fail;
125 }
126
127 pr_debug("of_irq_map_raw: ipar=%s, size=%d\n", ipar->full_name, intsize);
128
129 if (ointsize != intsize)
130 return -EINVAL;
131
132 /* Look for this #address-cells. We have to implement the old linux
133 * trick of looking for the parent here as some device-trees rely on it
134 */
135 old = of_node_get(ipar);
136 do {
137 tmp = of_get_property(old, "#address-cells", NULL);
138 tnode = of_get_parent(old);
139 of_node_put(old);
140 old = tnode;
141 } while (old && tmp == NULL);
142 of_node_put(old);
143 old = NULL;
144 addrsize = (tmp == NULL) ? 2 : be32_to_cpu(*tmp);
145
146 pr_debug(" -> addrsize=%d\n", addrsize);
147
148 /* Now start the actual "proper" walk of the interrupt tree */
149 while (ipar != NULL) {
150 /* Now check if cursor is an interrupt-controller and if it is
151 * then we are done
152 */
153 if (of_get_property(ipar, "interrupt-controller", NULL) !=
154 NULL) {
155 pr_debug(" -> got it !\n");
156 for (i = 0; i < intsize; i++)
157 out_irq->specifier[i] =
158 of_read_number(intspec +i, 1);
159 out_irq->size = intsize;
160 out_irq->controller = ipar;
161 of_node_put(old);
162 return 0;
163 }
164
165 /* Now look for an interrupt-map */
166 imap = of_get_property(ipar, "interrupt-map", &imaplen);
167 /* No interrupt map, check for an interrupt parent */
168 if (imap == NULL) {
169 pr_debug(" -> no map, getting parent\n");
170 newpar = of_irq_find_parent(ipar);
171 goto skiplevel;
172 }
173 imaplen /= sizeof(u32);
174
175 /* Look for a mask */
176 imask = of_get_property(ipar, "interrupt-map-mask", NULL);
177
178 /* If we were passed no "reg" property and we attempt to parse
179 * an interrupt-map, then #address-cells must be 0.
180 * Fail if it's not.
181 */
182 if (addr == NULL && addrsize != 0) {
183 pr_debug(" -> no reg passed in when needed !\n");
184 goto fail;
185 }
186
187 /* Parse interrupt-map */
188 match = 0;
189 while (imaplen > (addrsize + intsize + 1) && !match) {
190 /* Compare specifiers */
191 match = 1;
192 for (i = 0; i < addrsize && match; ++i) {
193 u32 mask = imask ? imask[i] : 0xffffffffu;
194 match = ((addr[i] ^ imap[i]) & mask) == 0;
195 }
196 for (; i < (addrsize + intsize) && match; ++i) {
197 u32 mask = imask ? imask[i] : 0xffffffffu;
198 match =
199 ((intspec[i-addrsize] ^ imap[i]) & mask) == 0;
200 }
201 imap += addrsize + intsize;
202 imaplen -= addrsize + intsize;
203
204 pr_debug(" -> match=%d (imaplen=%d)\n", match, imaplen);
205
206 /* Get the interrupt parent */
207 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
208 newpar = of_node_get(of_irq_dflt_pic);
209 else
210 newpar = of_find_node_by_phandle(be32_to_cpup(imap));
211 imap++;
212 --imaplen;
213
214 /* Check if not found */
215 if (newpar == NULL) {
216 pr_debug(" -> imap parent not found !\n");
217 goto fail;
218 }
219
220 /* Get #interrupt-cells and #address-cells of new
221 * parent
222 */
223 tmp = of_get_property(newpar, "#interrupt-cells", NULL);
224 if (tmp == NULL) {
225 pr_debug(" -> parent lacks #interrupt-cells!\n");
226 goto fail;
227 }
228 newintsize = be32_to_cpu(*tmp);
229 tmp = of_get_property(newpar, "#address-cells", NULL);
230 newaddrsize = (tmp == NULL) ? 0 : be32_to_cpu(*tmp);
231
232 pr_debug(" -> newintsize=%d, newaddrsize=%d\n",
233 newintsize, newaddrsize);
234
235 /* Check for malformed properties */
236 if (imaplen < (newaddrsize + newintsize))
237 goto fail;
238
239 imap += newaddrsize + newintsize;
240 imaplen -= newaddrsize + newintsize;
241
242 pr_debug(" -> imaplen=%d\n", imaplen);
243 }
244 if (!match)
245 goto fail;
246
247 of_node_put(old);
248 old = of_node_get(newpar);
249 addrsize = newaddrsize;
250 intsize = newintsize;
251 intspec = imap - intsize;
252 addr = intspec - addrsize;
253
254 skiplevel:
255 /* Iterate again with new parent */
256 pr_debug(" -> new parent: %s\n", newpar ? newpar->full_name : "<>");
257 of_node_put(ipar);
258 ipar = newpar;
259 newpar = NULL;
260 }
261 fail:
262 of_node_put(ipar);
263 of_node_put(old);
264 of_node_put(newpar);
265
266 return -EINVAL;
267}
268EXPORT_SYMBOL_GPL(of_irq_map_raw);
269
270/**
271 * of_irq_map_one - Resolve an interrupt for a device
272 * @device: the device whose interrupt is to be resolved
273 * @index: index of the interrupt to resolve
274 * @out_irq: structure of_irq filled by this function
275 *
276 * This function resolves an interrupt, walking the tree, for a given
277 * device-tree node. It's the high level pendant to of_irq_map_raw().
278 */
279int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq)
280{
281 struct device_node *p;
282 const __be32 *intspec, *tmp, *addr;
283 u32 intsize, intlen;
284 int res = -EINVAL;
285
286 pr_debug("of_irq_map_one: dev=%s, index=%d\n", device->full_name, index);
287
288 /* OldWorld mac stuff is "special", handle out of line */
289 if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
290 return of_irq_map_oldworld(device, index, out_irq);
291
292 /* Get the interrupts property */
293 intspec = of_get_property(device, "interrupts", &intlen);
294 if (intspec == NULL)
295 return -EINVAL;
296 intlen /= sizeof(*intspec);
297
298 pr_debug(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen);
299
300 /* Get the reg property (if any) */
301 addr = of_get_property(device, "reg", NULL);
302
303 /* Look for the interrupt parent. */
304 p = of_irq_find_parent(device);
305 if (p == NULL)
306 return -EINVAL;
307
308 /* Get size of interrupt specifier */
309 tmp = of_get_property(p, "#interrupt-cells", NULL);
310 if (tmp == NULL)
311 goto out;
312 intsize = be32_to_cpu(*tmp);
313
314 pr_debug(" intsize=%d intlen=%d\n", intsize, intlen);
315
316 /* Check index */
317 if ((index + 1) * intsize > intlen)
318 goto out;
319
320 /* Get new specifier and map it */
321 res = of_irq_map_raw(p, intspec + index * intsize, intsize,
322 addr, out_irq);
323 out:
324 of_node_put(p);
325 return res;
326}
327EXPORT_SYMBOL_GPL(of_irq_map_one);
328
329/**
330 * of_irq_to_resource - Decode a node's IRQ and return it as a resource
331 * @dev: pointer to device tree node
332 * @index: zero-based index of the irq
333 * @r: pointer to resource structure to return result into.
334 */
335int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
336{
337 int irq = irq_of_parse_and_map(dev, index);
338
339 /* Only dereference the resource if both the
340 * resource and the irq are valid. */
341 if (r && irq != NO_IRQ) {
342 r->start = r->end = irq;
343 r->flags = IORESOURCE_IRQ;
344 r->name = dev->full_name;
345 }
346
347 return irq;
348}
349EXPORT_SYMBOL_GPL(of_irq_to_resource);
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index ab6522c8e4fe..0a694debd226 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -14,57 +14,65 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/of_i2c.h> 16#include <linux/of_i2c.h>
17#include <linux/of_irq.h>
17#include <linux/module.h> 18#include <linux/module.h>
18 19
19void of_register_i2c_devices(struct i2c_adapter *adap, 20void of_i2c_register_devices(struct i2c_adapter *adap)
20 struct device_node *adap_node)
21{ 21{
22 void *result; 22 void *result;
23 struct device_node *node; 23 struct device_node *node;
24 24
25 for_each_child_of_node(adap_node, node) { 25 /* Only register child devices if the adapter has a node pointer set */
26 if (!adap->dev.of_node)
27 return;
28
29 dev_dbg(&adap->dev, "of_i2c: walking child nodes\n");
30
31 for_each_child_of_node(adap->dev.of_node, node) {
26 struct i2c_board_info info = {}; 32 struct i2c_board_info info = {};
27 struct dev_archdata dev_ad = {}; 33 struct dev_archdata dev_ad = {};
28 const __be32 *addr; 34 const __be32 *addr;
29 int len; 35 int len;
30 36
31 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) 37 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
38
39 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
40 dev_err(&adap->dev, "of_i2c: modalias failure on %s\n",
41 node->full_name);
32 continue; 42 continue;
43 }
33 44
34 addr = of_get_property(node, "reg", &len); 45 addr = of_get_property(node, "reg", &len);
35 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) { 46 if (!addr || (len < sizeof(int))) {
36 printk(KERN_ERR 47 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
37 "of-i2c: invalid i2c device entry\n"); 48 node->full_name);
38 continue; 49 continue;
39 } 50 }
40 51
41 info.irq = irq_of_parse_and_map(node, 0);
42
43 info.addr = be32_to_cpup(addr); 52 info.addr = be32_to_cpup(addr);
53 if (info.addr > (1 << 10) - 1) {
54 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
55 info.addr, node->full_name);
56 continue;
57 }
44 58
45 info.of_node = node; 59 info.irq = irq_of_parse_and_map(node, 0);
60 info.of_node = of_node_get(node);
46 info.archdata = &dev_ad; 61 info.archdata = &dev_ad;
47 62
48 request_module("%s", info.type); 63 request_module("%s", info.type);
49 64
50 result = i2c_new_device(adap, &info); 65 result = i2c_new_device(adap, &info);
51 if (result == NULL) { 66 if (result == NULL) {
52 printk(KERN_ERR 67 dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
53 "of-i2c: Failed to load driver for %s\n", 68 node->full_name);
54 info.type); 69 of_node_put(node);
55 irq_dispose_mapping(info.irq); 70 irq_dispose_mapping(info.irq);
56 continue; 71 continue;
57 } 72 }
58
59 /*
60 * Get the node to not lose the dev_archdata->of_node.
61 * Currently there is no way to put it back, as well as no
62 * of_unregister_i2c_devices() call.
63 */
64 of_node_get(node);
65 } 73 }
66} 74}
67EXPORT_SYMBOL(of_register_i2c_devices); 75EXPORT_SYMBOL(of_i2c_register_devices);
68 76
69static int of_dev_node_match(struct device *dev, void *data) 77static int of_dev_node_match(struct device *dev, void *data)
70{ 78{
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 42a6715f8e84..1fce00eb421b 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/phy.h> 16#include <linux/phy.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_irq.h>
18#include <linux/of_mdio.h> 19#include <linux/of_mdio.h>
19#include <linux/module.h> 20#include <linux/module.h>
20 21
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
index 5fed7e3c7da3..1dbce58a58b0 100644
--- a/drivers/of/of_spi.c
+++ b/drivers/of/of_spi.c
@@ -9,17 +9,17 @@
9#include <linux/of.h> 9#include <linux/of.h>
10#include <linux/device.h> 10#include <linux/device.h>
11#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
12#include <linux/of_irq.h>
12#include <linux/of_spi.h> 13#include <linux/of_spi.h>
13 14
14/** 15/**
15 * of_register_spi_devices - Register child devices onto the SPI bus 16 * of_register_spi_devices - Register child devices onto the SPI bus
16 * @master: Pointer to spi_master device 17 * @master: Pointer to spi_master device
17 * @np: parent node of SPI device nodes
18 * 18 *
19 * Registers an spi_device for each child node of 'np' which has a 'reg' 19 * Registers an spi_device for each child node of master node which has a 'reg'
20 * property. 20 * property.
21 */ 21 */
22void of_register_spi_devices(struct spi_master *master, struct device_node *np) 22void of_register_spi_devices(struct spi_master *master)
23{ 23{
24 struct spi_device *spi; 24 struct spi_device *spi;
25 struct device_node *nc; 25 struct device_node *nc;
@@ -27,7 +27,10 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
27 int rc; 27 int rc;
28 int len; 28 int len;
29 29
30 for_each_child_of_node(np, nc) { 30 if (!master->dev.of_node)
31 return;
32
33 for_each_child_of_node(master->dev.of_node, nc) {
31 /* Alloc an spi_device */ 34 /* Alloc an spi_device */
32 spi = spi_alloc_device(master); 35 spi = spi_alloc_device(master);
33 if (!spi) { 36 if (!spi) {
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 7dacc1ebe91e..bb72223c22ae 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -14,8 +14,105 @@
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/dma-mapping.h>
18#include <linux/slab.h>
19#include <linux/of_address.h>
17#include <linux/of_device.h> 20#include <linux/of_device.h>
21#include <linux/of_irq.h>
18#include <linux/of_platform.h> 22#include <linux/of_platform.h>
23#include <linux/platform_device.h>
24
25static int of_dev_node_match(struct device *dev, void *data)
26{
27 return dev->of_node == data;
28}
29
30/**
31 * of_find_device_by_node - Find the platform_device associated with a node
32 * @np: Pointer to device tree node
33 *
34 * Returns platform_device pointer, or NULL if not found
35 */
36struct platform_device *of_find_device_by_node(struct device_node *np)
37{
38 struct device *dev;
39
40 dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
41 return dev ? to_platform_device(dev) : NULL;
42}
43EXPORT_SYMBOL(of_find_device_by_node);
44
45static int platform_driver_probe_shim(struct platform_device *pdev)
46{
47 struct platform_driver *pdrv;
48 struct of_platform_driver *ofpdrv;
49 const struct of_device_id *match;
50
51 pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
52 ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
53
54 /* There is an unlikely chance that an of_platform driver might match
55 * on a non-OF platform device. If so, then of_match_device() will
56 * come up empty. Return -EINVAL in this case so other drivers get
57 * the chance to bind. */
58 match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
59 return match ? ofpdrv->probe(pdev, match) : -EINVAL;
60}
61
62static void platform_driver_shutdown_shim(struct platform_device *pdev)
63{
64 struct platform_driver *pdrv;
65 struct of_platform_driver *ofpdrv;
66
67 pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
68 ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
69 ofpdrv->shutdown(pdev);
70}
71
72/**
73 * of_register_platform_driver
74 */
75int of_register_platform_driver(struct of_platform_driver *drv)
76{
77 char *of_name;
78
79 /* setup of_platform_driver to platform_driver adaptors */
80 drv->platform_driver.driver = drv->driver;
81
82 /* Prefix the driver name with 'of:' to avoid namespace collisions
83 * and bogus matches. There are some drivers in the tree that
84 * register both an of_platform_driver and a platform_driver with
85 * the same name. This is a temporary measure until they are all
86 * cleaned up --gcl July 29, 2010 */
87 of_name = kmalloc(strlen(drv->driver.name) + 5, GFP_KERNEL);
88 if (!of_name)
89 return -ENOMEM;
90 sprintf(of_name, "of:%s", drv->driver.name);
91 drv->platform_driver.driver.name = of_name;
92
93 if (drv->probe)
94 drv->platform_driver.probe = platform_driver_probe_shim;
95 drv->platform_driver.remove = drv->remove;
96 if (drv->shutdown)
97 drv->platform_driver.shutdown = platform_driver_shutdown_shim;
98 drv->platform_driver.suspend = drv->suspend;
99 drv->platform_driver.resume = drv->resume;
100
101 return platform_driver_register(&drv->platform_driver);
102}
103EXPORT_SYMBOL(of_register_platform_driver);
104
105void of_unregister_platform_driver(struct of_platform_driver *drv)
106{
107 platform_driver_unregister(&drv->platform_driver);
108 kfree(drv->platform_driver.driver.name);
109 drv->platform_driver.driver.name = NULL;
110}
111EXPORT_SYMBOL(of_unregister_platform_driver);
112
113#if defined(CONFIG_PPC_DCR)
114#include <asm/dcr.h>
115#endif
19 116
20extern struct device_attribute of_platform_device_attrs[]; 117extern struct device_attribute of_platform_device_attrs[];
21 118
@@ -33,11 +130,11 @@ static int of_platform_device_probe(struct device *dev)
33{ 130{
34 int error = -ENODEV; 131 int error = -ENODEV;
35 struct of_platform_driver *drv; 132 struct of_platform_driver *drv;
36 struct of_device *of_dev; 133 struct platform_device *of_dev;
37 const struct of_device_id *match; 134 const struct of_device_id *match;
38 135
39 drv = to_of_platform_driver(dev->driver); 136 drv = to_of_platform_driver(dev->driver);
40 of_dev = to_of_device(dev); 137 of_dev = to_platform_device(dev);
41 138
42 if (!drv->probe) 139 if (!drv->probe)
43 return error; 140 return error;
@@ -55,7 +152,7 @@ static int of_platform_device_probe(struct device *dev)
55 152
56static int of_platform_device_remove(struct device *dev) 153static int of_platform_device_remove(struct device *dev)
57{ 154{
58 struct of_device *of_dev = to_of_device(dev); 155 struct platform_device *of_dev = to_platform_device(dev);
59 struct of_platform_driver *drv = to_of_platform_driver(dev->driver); 156 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
60 157
61 if (dev->driver && drv->remove) 158 if (dev->driver && drv->remove)
@@ -65,7 +162,7 @@ static int of_platform_device_remove(struct device *dev)
65 162
66static void of_platform_device_shutdown(struct device *dev) 163static void of_platform_device_shutdown(struct device *dev)
67{ 164{
68 struct of_device *of_dev = to_of_device(dev); 165 struct platform_device *of_dev = to_platform_device(dev);
69 struct of_platform_driver *drv = to_of_platform_driver(dev->driver); 166 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
70 167
71 if (dev->driver && drv->shutdown) 168 if (dev->driver && drv->shutdown)
@@ -76,7 +173,7 @@ static void of_platform_device_shutdown(struct device *dev)
76 173
77static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg) 174static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg)
78{ 175{
79 struct of_device *of_dev = to_of_device(dev); 176 struct platform_device *of_dev = to_platform_device(dev);
80 struct of_platform_driver *drv = to_of_platform_driver(dev->driver); 177 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
81 int ret = 0; 178 int ret = 0;
82 179
@@ -87,7 +184,7 @@ static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg)
87 184
88static int of_platform_legacy_resume(struct device *dev) 185static int of_platform_legacy_resume(struct device *dev)
89{ 186{
90 struct of_device *of_dev = to_of_device(dev); 187 struct platform_device *of_dev = to_platform_device(dev);
91 struct of_platform_driver *drv = to_of_platform_driver(dev->driver); 188 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
92 int ret = 0; 189 int ret = 0;
93 190
@@ -384,15 +481,286 @@ int of_bus_type_init(struct bus_type *bus, const char *name)
384 481
385int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus) 482int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
386{ 483{
387 drv->driver.bus = bus; 484 /*
485 * Temporary: of_platform_bus used to be distinct from the platform
486 * bus. It isn't anymore, and so drivers on the platform bus need
487 * to be registered in a special way.
488 *
489 * After all of_platform_bus_type drivers are converted to
490 * platform_drivers, this exception can be removed.
491 */
492 if (bus == &platform_bus_type)
493 return of_register_platform_driver(drv);
388 494
389 /* register with core */ 495 /* register with core */
496 drv->driver.bus = bus;
390 return driver_register(&drv->driver); 497 return driver_register(&drv->driver);
391} 498}
392EXPORT_SYMBOL(of_register_driver); 499EXPORT_SYMBOL(of_register_driver);
393 500
394void of_unregister_driver(struct of_platform_driver *drv) 501void of_unregister_driver(struct of_platform_driver *drv)
395{ 502{
396 driver_unregister(&drv->driver); 503 if (drv->driver.bus == &platform_bus_type)
504 of_unregister_platform_driver(drv);
505 else
506 driver_unregister(&drv->driver);
397} 507}
398EXPORT_SYMBOL(of_unregister_driver); 508EXPORT_SYMBOL(of_unregister_driver);
509
510#if !defined(CONFIG_SPARC)
511/*
512 * The following routines scan a subtree and registers a device for
513 * each applicable node.
514 *
515 * Note: sparc doesn't use these routines because it has a different
516 * mechanism for creating devices from device tree nodes.
517 */
518
519/**
520 * of_device_make_bus_id - Use the device node data to assign a unique name
521 * @dev: pointer to device structure that is linked to a device tree node
522 *
523 * This routine will first try using either the dcr-reg or the reg property
524 * value to derive a unique name. As a last resort it will use the node
525 * name followed by a unique number.
526 */
527void of_device_make_bus_id(struct device *dev)
528{
529 static atomic_t bus_no_reg_magic;
530 struct device_node *node = dev->of_node;
531 const u32 *reg;
532 u64 addr;
533 int magic;
534
535#ifdef CONFIG_PPC_DCR
536 /*
537 * If it's a DCR based device, use 'd' for native DCRs
538 * and 'D' for MMIO DCRs.
539 */
540 reg = of_get_property(node, "dcr-reg", NULL);
541 if (reg) {
542#ifdef CONFIG_PPC_DCR_NATIVE
543 dev_set_name(dev, "d%x.%s", *reg, node->name);
544#else /* CONFIG_PPC_DCR_NATIVE */
545 u64 addr = of_translate_dcr_address(node, *reg, NULL);
546 if (addr != OF_BAD_ADDR) {
547 dev_set_name(dev, "D%llx.%s",
548 (unsigned long long)addr, node->name);
549 return;
550 }
551#endif /* !CONFIG_PPC_DCR_NATIVE */
552 }
553#endif /* CONFIG_PPC_DCR */
554
555 /*
556 * For MMIO, get the physical address
557 */
558 reg = of_get_property(node, "reg", NULL);
559 if (reg) {
560 addr = of_translate_address(node, reg);
561 if (addr != OF_BAD_ADDR) {
562 dev_set_name(dev, "%llx.%s",
563 (unsigned long long)addr, node->name);
564 return;
565 }
566 }
567
568 /*
569 * No BusID, use the node name and add a globally incremented
570 * counter (and pray...)
571 */
572 magic = atomic_add_return(1, &bus_no_reg_magic);
573 dev_set_name(dev, "%s.%d", node->name, magic - 1);
574}
575
576/**
577 * of_device_alloc - Allocate and initialize an of_device
578 * @np: device node to assign to device
579 * @bus_id: Name to assign to the device. May be null to use default name.
580 * @parent: Parent device.
581 */
582struct platform_device *of_device_alloc(struct device_node *np,
583 const char *bus_id,
584 struct device *parent)
585{
586 struct platform_device *dev;
587 int rc, i, num_reg = 0, num_irq = 0;
588 struct resource *res, temp_res;
589
590 /* First count how many resources are needed */
591 while (of_address_to_resource(np, num_reg, &temp_res) == 0)
592 num_reg++;
593 while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ)
594 num_irq++;
595
596 /* Allocate memory for both the struct device and the resource table */
597 dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)),
598 GFP_KERNEL);
599 if (!dev)
600 return NULL;
601 res = (struct resource *) &dev[1];
602
603 /* Populate the resource table */
604 if (num_irq || num_reg) {
605 dev->num_resources = num_reg + num_irq;
606 dev->resource = res;
607 for (i = 0; i < num_reg; i++, res++) {
608 rc = of_address_to_resource(np, i, res);
609 WARN_ON(rc);
610 }
611 for (i = 0; i < num_irq; i++, res++) {
612 rc = of_irq_to_resource(np, i, res);
613 WARN_ON(rc == NO_IRQ);
614 }
615 }
616
617 dev->dev.of_node = of_node_get(np);
618#if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE)
619 dev->dev.dma_mask = &dev->archdata.dma_mask;
620#endif
621 dev->dev.parent = parent;
622 dev->dev.release = of_release_dev;
623
624 if (bus_id)
625 dev_set_name(&dev->dev, "%s", bus_id);
626 else
627 of_device_make_bus_id(&dev->dev);
628
629 return dev;
630}
631EXPORT_SYMBOL(of_device_alloc);
632
633/**
634 * of_platform_device_create - Alloc, initialize and register an of_device
635 * @np: pointer to node to create device for
636 * @bus_id: name to assign device
637 * @parent: Linux device model parent device.
638 */
639struct platform_device *of_platform_device_create(struct device_node *np,
640 const char *bus_id,
641 struct device *parent)
642{
643 struct platform_device *dev;
644
645 dev = of_device_alloc(np, bus_id, parent);
646 if (!dev)
647 return NULL;
648
649#if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE)
650 dev->archdata.dma_mask = 0xffffffffUL;
651#endif
652 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
653 dev->dev.bus = &platform_bus_type;
654
655 /* We do not fill the DMA ops for platform devices by default.
656 * This is currently the responsibility of the platform code
657 * to do such, possibly using a device notifier
658 */
659
660 if (of_device_register(dev) != 0) {
661 of_device_free(dev);
662 return NULL;
663 }
664
665 return dev;
666}
667EXPORT_SYMBOL(of_platform_device_create);
668
669/**
670 * of_platform_bus_create - Create an OF device for a bus node and all its
671 * children. Optionally recursively instantiate matching busses.
672 * @bus: device node of the bus to instantiate
673 * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
674 * disallow recursive creation of child busses
675 */
676static int of_platform_bus_create(const struct device_node *bus,
677 const struct of_device_id *matches,
678 struct device *parent)
679{
680 struct device_node *child;
681 struct platform_device *dev;
682 int rc = 0;
683
684 for_each_child_of_node(bus, child) {
685 pr_debug(" create child: %s\n", child->full_name);
686 dev = of_platform_device_create(child, NULL, parent);
687 if (dev == NULL)
688 rc = -ENOMEM;
689 else if (!of_match_node(matches, child))
690 continue;
691 if (rc == 0) {
692 pr_debug(" and sub busses\n");
693 rc = of_platform_bus_create(child, matches, &dev->dev);
694 }
695 if (rc) {
696 of_node_put(child);
697 break;
698 }
699 }
700 return rc;
701}
702
703/**
704 * of_platform_bus_probe - Probe the device-tree for platform busses
705 * @root: parent of the first level to probe or NULL for the root of the tree
706 * @matches: match table, NULL to use the default
707 * @parent: parent to hook devices from, NULL for toplevel
708 *
709 * Note that children of the provided root are not instantiated as devices
710 * unless the specified root itself matches the bus list and is not NULL.
711 */
712int of_platform_bus_probe(struct device_node *root,
713 const struct of_device_id *matches,
714 struct device *parent)
715{
716 struct device_node *child;
717 struct platform_device *dev;
718 int rc = 0;
719
720 if (WARN_ON(!matches || matches == OF_NO_DEEP_PROBE))
721 return -EINVAL;
722 if (root == NULL)
723 root = of_find_node_by_path("/");
724 else
725 of_node_get(root);
726 if (root == NULL)
727 return -EINVAL;
728
729 pr_debug("of_platform_bus_probe()\n");
730 pr_debug(" starting at: %s\n", root->full_name);
731
732 /* Do a self check of bus type, if there's a match, create
733 * children
734 */
735 if (of_match_node(matches, root)) {
736 pr_debug(" root match, create all sub devices\n");
737 dev = of_platform_device_create(root, NULL, parent);
738 if (dev == NULL) {
739 rc = -ENOMEM;
740 goto bail;
741 }
742 pr_debug(" create all sub busses\n");
743 rc = of_platform_bus_create(root, matches, &dev->dev);
744 goto bail;
745 }
746 for_each_child_of_node(root, child) {
747 if (!of_match_node(matches, child))
748 continue;
749
750 pr_debug(" match: %s\n", child->full_name);
751 dev = of_platform_device_create(child, NULL, parent);
752 if (dev == NULL)
753 rc = -ENOMEM;
754 else
755 rc = of_platform_bus_create(child, matches, &dev->dev);
756 if (rc) {
757 of_node_put(child);
758 break;
759 }
760 }
761 bail:
762 of_node_put(root);
763 return rc;
764}
765EXPORT_SYMBOL(of_platform_bus_probe);
766#endif /* !CONFIG_SPARC */
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c
index 9a5b4b894161..210a6441a066 100644
--- a/drivers/parport/parport_sunbpp.c
+++ b/drivers/parport/parport_sunbpp.c
@@ -295,7 +295,7 @@ static int __devinit bpp_probe(struct of_device *op, const struct of_device_id *
295 void __iomem *base; 295 void __iomem *base;
296 struct parport *p; 296 struct parport *p;
297 297
298 irq = op->irqs[0]; 298 irq = op->archdata.irqs[0];
299 base = of_ioremap(&op->resource[0], 0, 299 base = of_ioremap(&op->resource[0], 0,
300 resource_size(&op->resource[0]), 300 resource_size(&op->resource[0]),
301 "sunbpp"); 301 "sunbpp");
@@ -393,12 +393,12 @@ static struct of_platform_driver bpp_sbus_driver = {
393 393
394static int __init parport_sunbpp_init(void) 394static int __init parport_sunbpp_init(void)
395{ 395{
396 return of_register_driver(&bpp_sbus_driver, &of_bus_type); 396 return of_register_platform_driver(&bpp_sbus_driver);
397} 397}
398 398
399static void __exit parport_sunbpp_exit(void) 399static void __exit parport_sunbpp_exit(void)
400{ 400{
401 of_unregister_driver(&bpp_sbus_driver); 401 of_unregister_platform_driver(&bpp_sbus_driver);
402} 402}
403 403
404MODULE_AUTHOR("Derrick J Brashear"); 404MODULE_AUTHOR("Derrick J Brashear");
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 8bfdd63a1fcb..3e89c313e98d 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -317,7 +317,7 @@ static struct bbc_i2c_bus * __init attach_one_i2c(struct of_device *op, int inde
317 317
318 bp->waiting = 0; 318 bp->waiting = 0;
319 init_waitqueue_head(&bp->wq); 319 init_waitqueue_head(&bp->wq);
320 if (request_irq(op->irqs[0], bbc_i2c_interrupt, 320 if (request_irq(op->archdata.irqs[0], bbc_i2c_interrupt,
321 IRQF_SHARED, "bbc_i2c", bp)) 321 IRQF_SHARED, "bbc_i2c", bp))
322 goto fail; 322 goto fail;
323 323
@@ -373,7 +373,7 @@ static int __devinit bbc_i2c_probe(struct of_device *op,
373 373
374 err = bbc_envctrl_init(bp); 374 err = bbc_envctrl_init(bp);
375 if (err) { 375 if (err) {
376 free_irq(op->irqs[0], bp); 376 free_irq(op->archdata.irqs[0], bp);
377 if (bp->i2c_bussel_reg) 377 if (bp->i2c_bussel_reg)
378 of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1); 378 of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1);
379 if (bp->i2c_control_regs) 379 if (bp->i2c_control_regs)
@@ -392,7 +392,7 @@ static int __devexit bbc_i2c_remove(struct of_device *op)
392 392
393 bbc_envctrl_cleanup(bp); 393 bbc_envctrl_cleanup(bp);
394 394
395 free_irq(op->irqs[0], bp); 395 free_irq(op->archdata.irqs[0], bp);
396 396
397 if (bp->i2c_bussel_reg) 397 if (bp->i2c_bussel_reg)
398 of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1); 398 of_iounmap(&op->resource[0], bp->i2c_bussel_reg, 1);
@@ -425,12 +425,12 @@ static struct of_platform_driver bbc_i2c_driver = {
425 425
426static int __init bbc_i2c_init(void) 426static int __init bbc_i2c_init(void)
427{ 427{
428 return of_register_driver(&bbc_i2c_driver, &of_bus_type); 428 return of_register_platform_driver(&bbc_i2c_driver);
429} 429}
430 430
431static void __exit bbc_i2c_exit(void) 431static void __exit bbc_i2c_exit(void)
432{ 432{
433 of_unregister_driver(&bbc_i2c_driver); 433 of_unregister_platform_driver(&bbc_i2c_driver);
434} 434}
435 435
436module_init(bbc_i2c_init); 436module_init(bbc_i2c_init);
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 4ad4d2c91075..47db97583ea7 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -277,12 +277,12 @@ static struct of_platform_driver d7s_driver = {
277 277
278static int __init d7s_init(void) 278static int __init d7s_init(void)
279{ 279{
280 return of_register_driver(&d7s_driver, &of_bus_type); 280 return of_register_platform_driver(&d7s_driver);
281} 281}
282 282
283static void __exit d7s_exit(void) 283static void __exit d7s_exit(void)
284{ 284{
285 of_unregister_driver(&d7s_driver); 285 of_unregister_platform_driver(&d7s_driver);
286} 286}
287 287
288module_init(d7s_init); 288module_init(d7s_init);
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index bd0bbc621351..3c27f45e2b6d 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -1140,12 +1140,12 @@ static struct of_platform_driver envctrl_driver = {
1140 1140
1141static int __init envctrl_init(void) 1141static int __init envctrl_init(void)
1142{ 1142{
1143 return of_register_driver(&envctrl_driver, &of_bus_type); 1143 return of_register_platform_driver(&envctrl_driver);
1144} 1144}
1145 1145
1146static void __exit envctrl_exit(void) 1146static void __exit envctrl_exit(void)
1147{ 1147{
1148 of_unregister_driver(&envctrl_driver); 1148 of_unregister_platform_driver(&envctrl_driver);
1149} 1149}
1150 1150
1151module_init(envctrl_init); 1151module_init(envctrl_init);
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index ed9494e18859..8bb31c584b64 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -219,12 +219,12 @@ static struct of_platform_driver flash_driver = {
219 219
220static int __init flash_init(void) 220static int __init flash_init(void)
221{ 221{
222 return of_register_driver(&flash_driver, &of_bus_type); 222 return of_register_platform_driver(&flash_driver);
223} 223}
224 224
225static void __exit flash_cleanup(void) 225static void __exit flash_cleanup(void)
226{ 226{
227 of_unregister_driver(&flash_driver); 227 of_unregister_platform_driver(&flash_driver);
228} 228}
229 229
230module_init(flash_init); 230module_init(flash_init);
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 079da4cb45a5..41eb6725ff5f 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -368,7 +368,7 @@ static int __devinit uctrl_probe(struct of_device *op,
368 goto out_free; 368 goto out_free;
369 } 369 }
370 370
371 p->irq = op->irqs[0]; 371 p->irq = op->archdata.irqs[0];
372 err = request_irq(p->irq, uctrl_interrupt, 0, "uctrl", p); 372 err = request_irq(p->irq, uctrl_interrupt, 0, "uctrl", p);
373 if (err) { 373 if (err) {
374 printk(KERN_ERR "uctrl: Unable to register irq.\n"); 374 printk(KERN_ERR "uctrl: Unable to register irq.\n");
@@ -438,12 +438,12 @@ static struct of_platform_driver uctrl_driver = {
438 438
439static int __init uctrl_init(void) 439static int __init uctrl_init(void)
440{ 440{
441 return of_register_driver(&uctrl_driver, &of_bus_type); 441 return of_register_platform_driver(&uctrl_driver);
442} 442}
443 443
444static void __exit uctrl_exit(void) 444static void __exit uctrl_exit(void)
445{ 445{
446 of_unregister_driver(&uctrl_driver); 446 of_unregister_platform_driver(&uctrl_driver);
447} 447}
448 448
449module_init(uctrl_init); 449module_init(uctrl_init);
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index ca5c15c779cf..53d7ed0dc169 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -729,7 +729,7 @@ static int __devinit qpti_register_irq(struct qlogicpti *qpti)
729{ 729{
730 struct of_device *op = qpti->op; 730 struct of_device *op = qpti->op;
731 731
732 qpti->qhost->irq = qpti->irq = op->irqs[0]; 732 qpti->qhost->irq = qpti->irq = op->archdata.irqs[0];
733 733
734 /* We used to try various overly-clever things to 734 /* We used to try various overly-clever things to
735 * reduce the interrupt processing overhead on 735 * reduce the interrupt processing overhead on
@@ -1302,7 +1302,7 @@ static int __devinit qpti_sbus_probe(struct of_device *op, const struct of_devic
1302 /* Sometimes Antares cards come up not completely 1302 /* Sometimes Antares cards come up not completely
1303 * setup, and we get a report of a zero IRQ. 1303 * setup, and we get a report of a zero IRQ.
1304 */ 1304 */
1305 if (op->irqs[0] == 0) 1305 if (op->archdata.irqs[0] == 0)
1306 return -ENODEV; 1306 return -ENODEV;
1307 1307
1308 host = scsi_host_alloc(tpnt, sizeof(struct qlogicpti)); 1308 host = scsi_host_alloc(tpnt, sizeof(struct qlogicpti));
@@ -1467,12 +1467,12 @@ static struct of_platform_driver qpti_sbus_driver = {
1467 1467
1468static int __init qpti_init(void) 1468static int __init qpti_init(void)
1469{ 1469{
1470 return of_register_driver(&qpti_sbus_driver, &of_bus_type); 1470 return of_register_platform_driver(&qpti_sbus_driver);
1471} 1471}
1472 1472
1473static void __exit qpti_exit(void) 1473static void __exit qpti_exit(void)
1474{ 1474{
1475 of_unregister_driver(&qpti_sbus_driver); 1475 of_unregister_platform_driver(&qpti_sbus_driver);
1476} 1476}
1477 1477
1478MODULE_DESCRIPTION("QlogicISP SBUS driver"); 1478MODULE_DESCRIPTION("QlogicISP SBUS driver");
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index 386dd9d602b6..89ba6fe02f80 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -116,7 +116,7 @@ static int __devinit esp_sbus_register_irq(struct esp *esp)
116 struct Scsi_Host *host = esp->host; 116 struct Scsi_Host *host = esp->host;
117 struct of_device *op = esp->dev; 117 struct of_device *op = esp->dev;
118 118
119 host->irq = op->irqs[0]; 119 host->irq = op->archdata.irqs[0];
120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp); 120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
121} 121}
122 122
@@ -644,12 +644,12 @@ static struct of_platform_driver esp_sbus_driver = {
644 644
645static int __init sunesp_init(void) 645static int __init sunesp_init(void)
646{ 646{
647 return of_register_driver(&esp_sbus_driver, &of_bus_type); 647 return of_register_platform_driver(&esp_sbus_driver);
648} 648}
649 649
650static void __exit sunesp_exit(void) 650static void __exit sunesp_exit(void)
651{ 651{
652 of_unregister_driver(&esp_sbus_driver); 652 of_unregister_platform_driver(&esp_sbus_driver);
653} 653}
654 654
655MODULE_DESCRIPTION("Sun ESP SCSI driver"); 655MODULE_DESCRIPTION("Sun ESP SCSI driver");
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index 890f91742962..a779e22d213e 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -525,7 +525,7 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
525 unsigned long minor; 525 unsigned long minor;
526 int err; 526 int err;
527 527
528 if (op->irqs[0] == 0xffffffff) 528 if (op->archdata.irqs[0] == 0xffffffff)
529 return -ENODEV; 529 return -ENODEV;
530 530
531 port = kzalloc(sizeof(struct uart_port), GFP_KERNEL); 531 port = kzalloc(sizeof(struct uart_port), GFP_KERNEL);
@@ -557,7 +557,7 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
557 557
558 port->membase = (unsigned char __iomem *) __pa(port); 558 port->membase = (unsigned char __iomem *) __pa(port);
559 559
560 port->irq = op->irqs[0]; 560 port->irq = op->archdata.irqs[0];
561 561
562 port->dev = &op->dev; 562 port->dev = &op->dev;
563 563
@@ -644,12 +644,12 @@ static int __init sunhv_init(void)
644 if (tlb_type != hypervisor) 644 if (tlb_type != hypervisor)
645 return -ENODEV; 645 return -ENODEV;
646 646
647 return of_register_driver(&hv_driver, &of_bus_type); 647 return of_register_platform_driver(&hv_driver);
648} 648}
649 649
650static void __exit sunhv_exit(void) 650static void __exit sunhv_exit(void)
651{ 651{
652 of_unregister_driver(&hv_driver); 652 of_unregister_platform_driver(&hv_driver);
653} 653}
654 654
655module_init(sunhv_init); 655module_init(sunhv_init);
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 5e81bc6b48b0..9845fb1cfb1f 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -969,7 +969,7 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
969 return -ENOMEM; 969 return -ENOMEM;
970 up->regs = (union sab82532_async_regs __iomem *) up->port.membase; 970 up->regs = (union sab82532_async_regs __iomem *) up->port.membase;
971 971
972 up->port.irq = op->irqs[0]; 972 up->port.irq = op->archdata.irqs[0];
973 973
974 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; 974 up->port.fifosize = SAB82532_XMIT_FIFO_SIZE;
975 up->port.iotype = UPIO_MEM; 975 up->port.iotype = UPIO_MEM;
@@ -1130,12 +1130,12 @@ static int __init sunsab_init(void)
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 return of_register_driver(&sab_driver, &of_bus_type); 1133 return of_register_platform_driver(&sab_driver);
1134} 1134}
1135 1135
1136static void __exit sunsab_exit(void) 1136static void __exit sunsab_exit(void)
1137{ 1137{
1138 of_unregister_driver(&sab_driver); 1138 of_unregister_platform_driver(&sab_driver);
1139 if (sunsab_reg.nr) { 1139 if (sunsab_reg.nr) {
1140 sunserial_unregister_minors(&sunsab_reg, sunsab_reg.nr); 1140 sunserial_unregister_minors(&sunsab_reg, sunsab_reg.nr);
1141 } 1141 }
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index ffbf4553f665..3cdf74822db5 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1443,7 +1443,7 @@ static int __devinit su_probe(struct of_device *op, const struct of_device_id *m
1443 return -ENOMEM; 1443 return -ENOMEM;
1444 } 1444 }
1445 1445
1446 up->port.irq = op->irqs[0]; 1446 up->port.irq = op->archdata.irqs[0];
1447 1447
1448 up->port.dev = &op->dev; 1448 up->port.dev = &op->dev;
1449 1449
@@ -1586,7 +1586,7 @@ static int __init sunsu_init(void)
1586 return err; 1586 return err;
1587 } 1587 }
1588 1588
1589 err = of_register_driver(&su_driver, &of_bus_type); 1589 err = of_register_platform_driver(&su_driver);
1590 if (err && num_uart) 1590 if (err && num_uart)
1591 sunserial_unregister_minors(&sunsu_reg, num_uart); 1591 sunserial_unregister_minors(&sunsu_reg, num_uart);
1592 1592
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index f9a24f4ebb34..d1e6bcb59546 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1426,7 +1426,7 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1426 rp = sunzilog_chip_regs[inst]; 1426 rp = sunzilog_chip_regs[inst];
1427 1427
1428 if (zilog_irq == -1) 1428 if (zilog_irq == -1)
1429 zilog_irq = op->irqs[0]; 1429 zilog_irq = op->archdata.irqs[0];
1430 1430
1431 up = &sunzilog_port_table[inst * 2]; 1431 up = &sunzilog_port_table[inst * 2];
1432 1432
@@ -1434,7 +1434,7 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1434 up[0].port.mapbase = op->resource[0].start + 0x00; 1434 up[0].port.mapbase = op->resource[0].start + 0x00;
1435 up[0].port.membase = (void __iomem *) &rp->channelA; 1435 up[0].port.membase = (void __iomem *) &rp->channelA;
1436 up[0].port.iotype = UPIO_MEM; 1436 up[0].port.iotype = UPIO_MEM;
1437 up[0].port.irq = op->irqs[0]; 1437 up[0].port.irq = op->archdata.irqs[0];
1438 up[0].port.uartclk = ZS_CLOCK; 1438 up[0].port.uartclk = ZS_CLOCK;
1439 up[0].port.fifosize = 1; 1439 up[0].port.fifosize = 1;
1440 up[0].port.ops = &sunzilog_pops; 1440 up[0].port.ops = &sunzilog_pops;
@@ -1451,7 +1451,7 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1451 up[1].port.mapbase = op->resource[0].start + 0x04; 1451 up[1].port.mapbase = op->resource[0].start + 0x04;
1452 up[1].port.membase = (void __iomem *) &rp->channelB; 1452 up[1].port.membase = (void __iomem *) &rp->channelB;
1453 up[1].port.iotype = UPIO_MEM; 1453 up[1].port.iotype = UPIO_MEM;
1454 up[1].port.irq = op->irqs[0]; 1454 up[1].port.irq = op->archdata.irqs[0];
1455 up[1].port.uartclk = ZS_CLOCK; 1455 up[1].port.uartclk = ZS_CLOCK;
1456 up[1].port.fifosize = 1; 1456 up[1].port.fifosize = 1;
1457 up[1].port.ops = &sunzilog_pops; 1457 up[1].port.ops = &sunzilog_pops;
@@ -1492,12 +1492,12 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1492 "is a %s\n", 1492 "is a %s\n",
1493 dev_name(&op->dev), 1493 dev_name(&op->dev),
1494 (unsigned long long) up[0].port.mapbase, 1494 (unsigned long long) up[0].port.mapbase,
1495 op->irqs[0], sunzilog_type(&up[0].port)); 1495 op->archdata.irqs[0], sunzilog_type(&up[0].port));
1496 printk(KERN_INFO "%s: Mouse at MMIO 0x%llx (irq = %d) " 1496 printk(KERN_INFO "%s: Mouse at MMIO 0x%llx (irq = %d) "
1497 "is a %s\n", 1497 "is a %s\n",
1498 dev_name(&op->dev), 1498 dev_name(&op->dev),
1499 (unsigned long long) up[1].port.mapbase, 1499 (unsigned long long) up[1].port.mapbase,
1500 op->irqs[0], sunzilog_type(&up[1].port)); 1500 op->archdata.irqs[0], sunzilog_type(&up[1].port));
1501 kbm_inst++; 1501 kbm_inst++;
1502 } 1502 }
1503 1503
@@ -1576,7 +1576,7 @@ static int __init sunzilog_init(void)
1576 goto out_free_tables; 1576 goto out_free_tables;
1577 } 1577 }
1578 1578
1579 err = of_register_driver(&zs_driver, &of_bus_type); 1579 err = of_register_platform_driver(&zs_driver);
1580 if (err) 1580 if (err)
1581 goto out_unregister_uart; 1581 goto out_unregister_uart;
1582 1582
@@ -1604,7 +1604,7 @@ out:
1604 return err; 1604 return err;
1605 1605
1606out_unregister_driver: 1606out_unregister_driver:
1607 of_unregister_driver(&zs_driver); 1607 of_unregister_platform_driver(&zs_driver);
1608 1608
1609out_unregister_uart: 1609out_unregister_uart:
1610 if (num_sunzilog) { 1610 if (num_sunzilog) {
@@ -1619,7 +1619,7 @@ out_free_tables:
1619 1619
1620static void __exit sunzilog_exit(void) 1620static void __exit sunzilog_exit(void)
1621{ 1621{
1622 of_unregister_driver(&zs_driver); 1622 of_unregister_platform_driver(&zs_driver);
1623 1623
1624 if (zilog_irq != -1) { 1624 if (zilog_irq != -1) {
1625 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1625 struct uart_sunzilog_port *up = sunzilog_irq_chain;
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 8acccd564378..caf085d3a76a 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -21,6 +21,7 @@
21#include <asm/io.h> 21#include <asm/io.h>
22#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE)) 22#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE))
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/of_address.h>
24#include <linux/of_device.h> 25#include <linux/of_device.h>
25#include <linux/of_platform.h> 26#include <linux/of_platform.h>
26 27
diff --git a/drivers/spi/mpc512x_psc_spi.c b/drivers/spi/mpc512x_psc_spi.c
index 2534b1ec3edd..10baac3f8ea5 100644
--- a/drivers/spi/mpc512x_psc_spi.c
+++ b/drivers/spi/mpc512x_psc_spi.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/of_address.h>
22#include <linux/of_platform.h> 23#include <linux/of_platform.h>
23#include <linux/workqueue.h> 24#include <linux/workqueue.h>
24#include <linux/completion.h> 25#include <linux/completion.h>
@@ -440,6 +441,7 @@ static int __init mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
440 master->setup = mpc512x_psc_spi_setup; 441 master->setup = mpc512x_psc_spi_setup;
441 master->transfer = mpc512x_psc_spi_transfer; 442 master->transfer = mpc512x_psc_spi_transfer;
442 master->cleanup = mpc512x_psc_spi_cleanup; 443 master->cleanup = mpc512x_psc_spi_cleanup;
444 master->dev.of_node = dev->of_node;
443 445
444 tempp = ioremap(regaddr, size); 446 tempp = ioremap(regaddr, size);
445 if (!tempp) { 447 if (!tempp) {
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 7104cb739da7..66d170147dcc 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -16,8 +16,8 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/of_address.h>
19#include <linux/of_platform.h> 20#include <linux/of_platform.h>
20#include <linux/of_spi.h>
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22#include <linux/completion.h> 22#include <linux/completion.h>
23#include <linux/io.h> 23#include <linux/io.h>
@@ -398,6 +398,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
398 master->setup = mpc52xx_psc_spi_setup; 398 master->setup = mpc52xx_psc_spi_setup;
399 master->transfer = mpc52xx_psc_spi_transfer; 399 master->transfer = mpc52xx_psc_spi_transfer;
400 master->cleanup = mpc52xx_psc_spi_cleanup; 400 master->cleanup = mpc52xx_psc_spi_cleanup;
401 master->dev.of_node = dev->of_node;
401 402
402 mps->psc = ioremap(regaddr, size); 403 mps->psc = ioremap(regaddr, size);
403 if (!mps->psc) { 404 if (!mps->psc) {
@@ -470,7 +471,6 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
470 const u32 *regaddr_p; 471 const u32 *regaddr_p;
471 u64 regaddr64, size64; 472 u64 regaddr64, size64;
472 s16 id = -1; 473 s16 id = -1;
473 int rc;
474 474
475 regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL); 475 regaddr_p = of_get_address(op->dev.of_node, 0, &size64, NULL);
476 if (!regaddr_p) { 476 if (!regaddr_p) {
@@ -491,13 +491,8 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
491 id = *psc_nump + 1; 491 id = *psc_nump + 1;
492 } 492 }
493 493
494 rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64, 494 return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
495 irq_of_parse_and_map(op->dev.of_node, 0), id); 495 irq_of_parse_and_map(op->dev.of_node, 0), id);
496 if (rc == 0)
497 of_register_spi_devices(dev_get_drvdata(&op->dev),
498 op->dev.of_node);
499
500 return rc;
501} 496}
502 497
503static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op) 498static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
index b1a76bff775f..56136ff00e01 100644
--- a/drivers/spi/mpc52xx_spi.c
+++ b/drivers/spi/mpc52xx_spi.c
@@ -18,7 +18,6 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
21#include <linux/of_spi.h>
22#include <linux/io.h> 21#include <linux/io.h>
23#include <linux/of_gpio.h> 22#include <linux/of_gpio.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
@@ -439,6 +438,7 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
439 master->setup = mpc52xx_spi_setup; 438 master->setup = mpc52xx_spi_setup;
440 master->transfer = mpc52xx_spi_transfer; 439 master->transfer = mpc52xx_spi_transfer;
441 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; 440 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
441 master->dev.of_node = op->dev.of_node;
442 442
443 dev_set_drvdata(&op->dev, master); 443 dev_set_drvdata(&op->dev, master);
444 444
@@ -512,7 +512,6 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
512 if (rc) 512 if (rc)
513 goto err_register; 513 goto err_register;
514 514
515 of_register_spi_devices(master, op->dev.of_node);
516 dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n"); 515 dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
517 516
518 return rc; 517 return rc;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b3a1f9259b62..1bb1b88780ce 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -26,6 +26,7 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/mod_devicetable.h> 27#include <linux/mod_devicetable.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/of_spi.h>
29 30
30 31
31/* SPI bustype and spi_master class are registered after board init code 32/* SPI bustype and spi_master class are registered after board init code
@@ -540,6 +541,9 @@ int spi_register_master(struct spi_master *master)
540 /* populate children from any spi device tables */ 541 /* populate children from any spi device tables */
541 scan_boardinfo(master); 542 scan_boardinfo(master);
542 status = 0; 543 status = 0;
544
545 /* Register devices from the device tree */
546 of_register_spi_devices(master);
543done: 547done:
544 return status; 548 return status;
545} 549}
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index 97ab0a81338a..aad9ae1b9c69 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -38,7 +38,6 @@
38#include <linux/of_platform.h> 38#include <linux/of_platform.h>
39#include <linux/gpio.h> 39#include <linux/gpio.h>
40#include <linux/of_gpio.h> 40#include <linux/of_gpio.h>
41#include <linux/of_spi.h>
42#include <linux/slab.h> 41#include <linux/slab.h>
43 42
44#include <sysdev/fsl_soc.h> 43#include <sysdev/fsl_soc.h>
@@ -1009,6 +1008,7 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
1009 master->setup = mpc8xxx_spi_setup; 1008 master->setup = mpc8xxx_spi_setup;
1010 master->transfer = mpc8xxx_spi_transfer; 1009 master->transfer = mpc8xxx_spi_transfer;
1011 master->cleanup = mpc8xxx_spi_cleanup; 1010 master->cleanup = mpc8xxx_spi_cleanup;
1011 master->dev.of_node = dev->of_node;
1012 1012
1013 mpc8xxx_spi = spi_master_get_devdata(master); 1013 mpc8xxx_spi = spi_master_get_devdata(master);
1014 mpc8xxx_spi->dev = dev; 1014 mpc8xxx_spi->dev = dev;
@@ -1299,8 +1299,6 @@ static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev,
1299 goto err; 1299 goto err;
1300 } 1300 }
1301 1301
1302 of_register_spi_devices(master, np);
1303
1304 return 0; 1302 return 0;
1305 1303
1306err: 1304err:
diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c
index d53466a249d9..0f5fa7e2a550 100644
--- a/drivers/spi/spi_ppc4xx.c
+++ b/drivers/spi/spi_ppc4xx.c
@@ -407,6 +407,7 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
407 master = spi_alloc_master(dev, sizeof *hw); 407 master = spi_alloc_master(dev, sizeof *hw);
408 if (master == NULL) 408 if (master == NULL)
409 return -ENOMEM; 409 return -ENOMEM;
410 master->dev.of_node = np;
410 dev_set_drvdata(dev, master); 411 dev_set_drvdata(dev, master);
411 hw = spi_master_get_devdata(master); 412 hw = spi_master_get_devdata(master);
412 hw->master = spi_master_get(master); 413 hw->master = spi_master_get(master);
@@ -545,7 +546,6 @@ static int __init spi_ppc4xx_of_probe(struct of_device *op,
545 } 546 }
546 547
547 dev_info(dev, "driver initialized\n"); 548 dev_info(dev, "driver initialized\n");
548 of_register_spi_devices(master, np);
549 549
550 return 0; 550 return 0;
551 551
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 1b47363cb73f..80f2db5bcfd6 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -390,6 +390,9 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
390 390
391 master->bus_num = bus_num; 391 master->bus_num = bus_num;
392 master->num_chipselect = pdata->num_chipselect; 392 master->num_chipselect = pdata->num_chipselect;
393#ifdef CONFIG_OF
394 master->dev.of_node = dev->of_node;
395#endif
393 396
394 xspi->mem = *mem; 397 xspi->mem = *mem;
395 xspi->irq = irq; 398 xspi->irq = irq;
diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c
index 4654805b08d8..f53d3f6b9f61 100644
--- a/drivers/spi/xilinx_spi_of.c
+++ b/drivers/spi/xilinx_spi_of.c
@@ -29,6 +29,7 @@
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31 31
32#include <linux/of_address.h>
32#include <linux/of_platform.h> 33#include <linux/of_platform.h>
33#include <linux/of_device.h> 34#include <linux/of_device.h>
34#include <linux/of_spi.h> 35#include <linux/of_spi.h>
@@ -80,9 +81,6 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
80 81
81 dev_set_drvdata(&ofdev->dev, master); 82 dev_set_drvdata(&ofdev->dev, master);
82 83
83 /* Add any subnodes on the SPI bus */
84 of_register_spi_devices(master, ofdev->dev.of_node);
85
86 return 0; 84 return 0;
87} 85}
88 86
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 82506ca297d5..9648b75f0283 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -32,6 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
35#include <linux/of_address.h>
35#include <linux/of_platform.h> 36#include <linux/of_platform.h>
36#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
37#include <linux/usb/ch9.h> 38#include <linux/usb/ch9.h>
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index 09f1b9b462f4..c7796637bafd 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -390,12 +390,12 @@ static int __init bw2_init(void)
390 if (fb_get_options("bw2fb", NULL)) 390 if (fb_get_options("bw2fb", NULL))
391 return -ENODEV; 391 return -ENODEV;
392 392
393 return of_register_driver(&bw2_driver, &of_bus_type); 393 return of_register_platform_driver(&bw2_driver);
394} 394}
395 395
396static void __exit bw2_exit(void) 396static void __exit bw2_exit(void)
397{ 397{
398 of_unregister_driver(&bw2_driver); 398 of_unregister_platform_driver(&bw2_driver);
399} 399}
400 400
401module_init(bw2_init); 401module_init(bw2_init);
diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c
index e5dc2241194f..d09fde8beb69 100644
--- a/drivers/video/cg14.c
+++ b/drivers/video/cg14.c
@@ -610,12 +610,12 @@ static int __init cg14_init(void)
610 if (fb_get_options("cg14fb", NULL)) 610 if (fb_get_options("cg14fb", NULL))
611 return -ENODEV; 611 return -ENODEV;
612 612
613 return of_register_driver(&cg14_driver, &of_bus_type); 613 return of_register_platform_driver(&cg14_driver);
614} 614}
615 615
616static void __exit cg14_exit(void) 616static void __exit cg14_exit(void)
617{ 617{
618 of_unregister_driver(&cg14_driver); 618 of_unregister_platform_driver(&cg14_driver);
619} 619}
620 620
621module_init(cg14_init); 621module_init(cg14_init);
diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c
index 558d73a948a0..64aa29809fb9 100644
--- a/drivers/video/cg3.c
+++ b/drivers/video/cg3.c
@@ -477,12 +477,12 @@ static int __init cg3_init(void)
477 if (fb_get_options("cg3fb", NULL)) 477 if (fb_get_options("cg3fb", NULL))
478 return -ENODEV; 478 return -ENODEV;
479 479
480 return of_register_driver(&cg3_driver, &of_bus_type); 480 return of_register_platform_driver(&cg3_driver);
481} 481}
482 482
483static void __exit cg3_exit(void) 483static void __exit cg3_exit(void)
484{ 484{
485 of_unregister_driver(&cg3_driver); 485 of_unregister_platform_driver(&cg3_driver);
486} 486}
487 487
488module_init(cg3_init); 488module_init(cg3_init);
diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c
index 480d761a27a8..2389a719dcc7 100644
--- a/drivers/video/cg6.c
+++ b/drivers/video/cg6.c
@@ -870,12 +870,12 @@ static int __init cg6_init(void)
870 if (fb_get_options("cg6fb", NULL)) 870 if (fb_get_options("cg6fb", NULL))
871 return -ENODEV; 871 return -ENODEV;
872 872
873 return of_register_driver(&cg6_driver, &of_bus_type); 873 return of_register_platform_driver(&cg6_driver);
874} 874}
875 875
876static void __exit cg6_exit(void) 876static void __exit cg6_exit(void)
877{ 877{
878 of_unregister_driver(&cg6_driver); 878 of_unregister_platform_driver(&cg6_driver);
879} 879}
880 880
881module_init(cg6_init); 881module_init(cg6_init);
diff --git a/drivers/video/controlfb.c b/drivers/video/controlfb.c
index 49fcbe8f18ac..c225dcce89e7 100644
--- a/drivers/video/controlfb.c
+++ b/drivers/video/controlfb.c
@@ -40,6 +40,8 @@
40#include <linux/vmalloc.h> 40#include <linux/vmalloc.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/interrupt.h> 42#include <linux/interrupt.h>
43#include <linux/of.h>
44#include <linux/of_address.h>
43#include <linux/fb.h> 45#include <linux/fb.h>
44#include <linux/init.h> 46#include <linux/init.h>
45#include <linux/pci.h> 47#include <linux/pci.h>
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index 95c0227f47fc..f6ecfab296d3 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -1067,12 +1067,12 @@ static int __init ffb_init(void)
1067 if (fb_get_options("ffb", NULL)) 1067 if (fb_get_options("ffb", NULL))
1068 return -ENODEV; 1068 return -ENODEV;
1069 1069
1070 return of_register_driver(&ffb_driver, &of_bus_type); 1070 return of_register_platform_driver(&ffb_driver);
1071} 1071}
1072 1072
1073static void __exit ffb_exit(void) 1073static void __exit ffb_exit(void)
1074{ 1074{
1075 of_unregister_driver(&ffb_driver); 1075 of_unregister_platform_driver(&ffb_driver);
1076} 1076}
1077 1077
1078module_init(ffb_init); 1078module_init(ffb_init);
diff --git a/drivers/video/leo.c b/drivers/video/leo.c
index 9e8bf7d5e249..ad677637ffbb 100644
--- a/drivers/video/leo.c
+++ b/drivers/video/leo.c
@@ -677,12 +677,12 @@ static int __init leo_init(void)
677 if (fb_get_options("leofb", NULL)) 677 if (fb_get_options("leofb", NULL))
678 return -ENODEV; 678 return -ENODEV;
679 679
680 return of_register_driver(&leo_driver, &of_bus_type); 680 return of_register_platform_driver(&leo_driver);
681} 681}
682 682
683static void __exit leo_exit(void) 683static void __exit leo_exit(void)
684{ 684{
685 of_unregister_driver(&leo_driver); 685 of_unregister_platform_driver(&leo_driver);
686} 686}
687 687
688module_init(leo_init); 688module_init(leo_init);
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 46dda7d8aaee..cb163a5397be 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -19,13 +19,14 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/of.h>
23#include <linux/of_address.h>
22#include <linux/interrupt.h> 24#include <linux/interrupt.h>
23#include <linux/fb.h> 25#include <linux/fb.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/ioport.h> 27#include <linux/ioport.h>
26#include <linux/pci.h> 28#include <linux/pci.h>
27#include <asm/io.h> 29#include <asm/io.h>
28#include <asm/prom.h>
29 30
30#ifdef CONFIG_PPC64 31#ifdef CONFIG_PPC64
31#include <asm/pci-bridge.h> 32#include <asm/pci-bridge.h>
diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c
index 6552751e81aa..688b055abab2 100644
--- a/drivers/video/p9100.c
+++ b/drivers/video/p9100.c
@@ -367,12 +367,12 @@ static int __init p9100_init(void)
367 if (fb_get_options("p9100fb", NULL)) 367 if (fb_get_options("p9100fb", NULL))
368 return -ENODEV; 368 return -ENODEV;
369 369
370 return of_register_driver(&p9100_driver, &of_bus_type); 370 return of_register_platform_driver(&p9100_driver);
371} 371}
372 372
373static void __exit p9100_exit(void) 373static void __exit p9100_exit(void)
374{ 374{
375 of_unregister_driver(&p9100_driver); 375 of_unregister_platform_driver(&p9100_driver);
376} 376}
377 377
378module_init(p9100_init); 378module_init(p9100_init);
diff --git a/drivers/video/sunxvr1000.c b/drivers/video/sunxvr1000.c
index 489b44e8db81..7288934c0d49 100644
--- a/drivers/video/sunxvr1000.c
+++ b/drivers/video/sunxvr1000.c
@@ -213,12 +213,12 @@ static int __init gfb_init(void)
213 if (fb_get_options("gfb", NULL)) 213 if (fb_get_options("gfb", NULL))
214 return -ENODEV; 214 return -ENODEV;
215 215
216 return of_register_driver(&gfb_driver, &of_bus_type); 216 return of_register_platform_driver(&gfb_driver);
217} 217}
218 218
219static void __exit gfb_exit(void) 219static void __exit gfb_exit(void)
220{ 220{
221 of_unregister_driver(&gfb_driver); 221 of_unregister_platform_driver(&gfb_driver);
222} 222}
223 223
224module_init(gfb_init); 224module_init(gfb_init);
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c
index cc039b33d2d8..f375e0db6776 100644
--- a/drivers/video/tcx.c
+++ b/drivers/video/tcx.c
@@ -526,12 +526,12 @@ static int __init tcx_init(void)
526 if (fb_get_options("tcxfb", NULL)) 526 if (fb_get_options("tcxfb", NULL))
527 return -ENODEV; 527 return -ENODEV;
528 528
529 return of_register_driver(&tcx_driver, &of_bus_type); 529 return of_register_platform_driver(&tcx_driver);
530} 530}
531 531
532static void __exit tcx_exit(void) 532static void __exit tcx_exit(void)
533{ 533{
534 of_unregister_driver(&tcx_driver); 534 of_unregister_platform_driver(&tcx_driver);
535} 535}
536 536
537module_init(tcx_init); 537module_init(tcx_init);
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index d62b9ce8f773..30a2512fd52e 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -545,7 +545,7 @@ static int __devinit cpwd_probe(struct of_device *op,
545 goto out; 545 goto out;
546 } 546 }
547 547
548 p->irq = op->irqs[0]; 548 p->irq = op->archdata.irqs[0];
549 549
550 spin_lock_init(&p->lock); 550 spin_lock_init(&p->lock);
551 551
@@ -688,12 +688,12 @@ static struct of_platform_driver cpwd_driver = {
688 688
689static int __init cpwd_init(void) 689static int __init cpwd_init(void)
690{ 690{
691 return of_register_driver(&cpwd_driver, &of_bus_type); 691 return of_register_platform_driver(&cpwd_driver);
692} 692}
693 693
694static void __exit cpwd_exit(void) 694static void __exit cpwd_exit(void)
695{ 695{
696 of_unregister_driver(&cpwd_driver); 696 of_unregister_platform_driver(&cpwd_driver);
697} 697}
698 698
699module_init(cpwd_init); 699module_init(cpwd_init);
diff --git a/drivers/watchdog/riowd.c b/drivers/watchdog/riowd.c
index 5dceeddc8859..4082b4ace1fc 100644
--- a/drivers/watchdog/riowd.c
+++ b/drivers/watchdog/riowd.c
@@ -250,12 +250,12 @@ static struct of_platform_driver riowd_driver = {
250 250
251static int __init riowd_init(void) 251static int __init riowd_init(void)
252{ 252{
253 return of_register_driver(&riowd_driver, &of_bus_type); 253 return of_register_platform_driver(&riowd_driver);
254} 254}
255 255
256static void __exit riowd_exit(void) 256static void __exit riowd_exit(void)
257{ 257{
258 of_unregister_driver(&riowd_driver); 258 of_unregister_platform_driver(&riowd_driver);
259} 259}
260 260
261module_init(riowd_init); 261module_init(riowd_init);