diff options
Diffstat (limited to 'drivers')
39 files changed, 1521 insertions, 206 deletions
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c index da8f176c051e..38df87b198d5 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); |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 3ca36542e338..83cbc34e3a76 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 | ||
@@ -1099,16 +1100,24 @@ int gpiochip_add(struct gpio_chip *chip) | |||
1099 | } | 1100 | } |
1100 | } | 1101 | } |
1101 | 1102 | ||
1103 | of_gpiochip_add(chip); | ||
1104 | |||
1102 | unlock: | 1105 | unlock: |
1103 | spin_unlock_irqrestore(&gpio_lock, flags); | 1106 | spin_unlock_irqrestore(&gpio_lock, flags); |
1104 | if (status == 0) | 1107 | |
1105 | status = gpiochip_export(chip); | 1108 | if (status) |
1109 | goto fail; | ||
1110 | |||
1111 | status = gpiochip_export(chip); | ||
1112 | if (status) | ||
1113 | goto fail; | ||
1114 | |||
1115 | return 0; | ||
1106 | fail: | 1116 | fail: |
1107 | /* failures here can mean systems won't boot... */ | 1117 | /* failures here can mean systems won't boot... */ |
1108 | if (status) | 1118 | pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n", |
1109 | pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n", | 1119 | chip->base, chip->base + chip->ngpio - 1, |
1110 | chip->base, chip->base + chip->ngpio - 1, | 1120 | chip->label ? : "generic"); |
1111 | chip->label ? : "generic"); | ||
1112 | return status; | 1121 | return status; |
1113 | } | 1122 | } |
1114 | EXPORT_SYMBOL_GPL(gpiochip_add); | 1123 | EXPORT_SYMBOL_GPL(gpiochip_add); |
@@ -1127,6 +1136,8 @@ int gpiochip_remove(struct gpio_chip *chip) | |||
1127 | 1136 | ||
1128 | spin_lock_irqsave(&gpio_lock, flags); | 1137 | spin_lock_irqsave(&gpio_lock, flags); |
1129 | 1138 | ||
1139 | of_gpiochip_remove(chip); | ||
1140 | |||
1130 | for (id = chip->base; id < chip->base + chip->ngpio; id++) { | 1141 | for (id = chip->base; id < chip->base + chip->ngpio; id++) { |
1131 | if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) { | 1142 | if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) { |
1132 | status = -EBUSY; | 1143 | status = -EBUSY; |
@@ -1147,6 +1158,38 @@ int gpiochip_remove(struct gpio_chip *chip) | |||
1147 | } | 1158 | } |
1148 | EXPORT_SYMBOL_GPL(gpiochip_remove); | 1159 | EXPORT_SYMBOL_GPL(gpiochip_remove); |
1149 | 1160 | ||
1161 | /** | ||
1162 | * gpiochip_find() - iterator for locating a specific gpio_chip | ||
1163 | * @data: data to pass to match function | ||
1164 | * @callback: Callback function to check gpio_chip | ||
1165 | * | ||
1166 | * Similar to bus_find_device. It returns a reference to a gpio_chip as | ||
1167 | * determined by a user supplied @match callback. The callback should return | ||
1168 | * 0 if the device doesn't match and non-zero if it does. If the callback is | ||
1169 | * non-zero, this function will return to the caller and not iterate over any | ||
1170 | * more gpio_chips. | ||
1171 | */ | ||
1172 | struct gpio_chip *gpiochip_find(void *data, | ||
1173 | int (*match)(struct gpio_chip *chip, void *data)) | ||
1174 | { | ||
1175 | struct gpio_chip *chip = NULL; | ||
1176 | unsigned long flags; | ||
1177 | int i; | ||
1178 | |||
1179 | spin_lock_irqsave(&gpio_lock, flags); | ||
1180 | for (i = 0; i < ARCH_NR_GPIOS; i++) { | ||
1181 | if (!gpio_desc[i].chip) | ||
1182 | continue; | ||
1183 | |||
1184 | if (match(gpio_desc[i].chip, data)) { | ||
1185 | chip = gpio_desc[i].chip; | ||
1186 | break; | ||
1187 | } | ||
1188 | } | ||
1189 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
1190 | |||
1191 | return chip; | ||
1192 | } | ||
1150 | 1193 | ||
1151 | /* These "optional" allocation calls help prevent drivers from stomping | 1194 | /* These "optional" allocation calls help prevent drivers from stomping |
1152 | * on each other, and help provide better diagnostics in debugfs. | 1195 | * 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) | |||
161 | static int __devinit xgpio_of_probe(struct device_node *np) | 161 | static 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/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; |
685 | out_shut: | 681 | out_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 | ||
768 | error_cleanup: | 766 | error_cleanup: |
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index df00eb1f11f9..9f7fef8c4639 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
@@ -600,13 +600,13 @@ static int __devinit fsl_i2c_probe(struct of_device *op, | |||
600 | i2c->adap = mpc_ops; | 600 | i2c->adap = mpc_ops; |
601 | i2c_set_adapdata(&i2c->adap, i2c); | 601 | i2c_set_adapdata(&i2c->adap, i2c); |
602 | i2c->adap.dev.parent = &op->dev; | 602 | i2c->adap.dev.parent = &op->dev; |
603 | i2c->adap.dev.of_node = of_node_get(op->dev.of_node); | ||
603 | 604 | ||
604 | result = i2c_add_adapter(&i2c->adap); | 605 | result = i2c_add_adapter(&i2c->adap); |
605 | if (result < 0) { | 606 | if (result < 0) { |
606 | dev_err(i2c->dev, "failed to add adapter\n"); | 607 | dev_err(i2c->dev, "failed to add adapter\n"); |
607 | goto fail_add; | 608 | goto fail_add; |
608 | } | 609 | } |
609 | of_register_i2c_devices(&i2c->adap, op->dev.of_node); | ||
610 | 610 | ||
611 | return result; | 611 | return result; |
612 | 612 | ||
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/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h index 04e32f2d1241..c7d50ff43fca 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 | ||
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) | |||
41 | static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, | 41 | static 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) | ||
1537 | static struct of_device_id mmc_spi_of_match_table[] __devinitdata = { | ||
1538 | { .compatible = "mmc-spi-slot", }, | ||
1539 | }; | ||
1540 | #endif | ||
1536 | 1541 | ||
1537 | static struct spi_driver mmc_spi_driver = { | 1542 | static 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/net/myri_sbus.c b/drivers/net/myri_sbus.c index 1a57c3da1f49..370d3c17f24c 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. */ |
diff --git a/drivers/net/niu.c b/drivers/net/niu.c index 63e8e3893bd6..f6ecf6180f72 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 | ||
@@ -9119,12 +9116,12 @@ static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map) | |||
9119 | if (!int_prop) | 9116 | if (!int_prop) |
9120 | return -ENODEV; | 9117 | return -ENODEV; |
9121 | 9118 | ||
9122 | for (i = 0; i < op->num_irqs; i++) { | 9119 | for (i = 0; i < op->archdata.num_irqs; i++) { |
9123 | ldg_num_map[i] = int_prop[i]; | 9120 | ldg_num_map[i] = int_prop[i]; |
9124 | np->ldg[i].irq = op->irqs[i]; | 9121 | np->ldg[i].irq = op->archdata.irqs[i]; |
9125 | } | 9122 | } |
9126 | 9123 | ||
9127 | np->num_ldg = op->num_irqs; | 9124 | np->num_ldg = op->archdata.num_irqs; |
9128 | 9125 | ||
9129 | return 0; | 9126 | return 0; |
9130 | #else | 9127 | #else |
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 | ||
3239 | struct of_device; | 3239 | struct platform_device; |
3240 | struct niu { | 3240 | struct 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..0b10d24de051 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)) { |
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c index 3d9650b8d38f..0a63ebef86a0 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. */ |
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c index 7d9c33dd9d1a..c6bfdad6c0c8 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 |
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c index 72b579c8d812..446517487084 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; |
@@ -999,7 +999,7 @@ static void __exit qec_exit(void) | |||
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/of/Kconfig b/drivers/of/Kconfig index 7cecc8fea9bd..6acbff389ab6 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
@@ -1,35 +1,61 @@ | |||
1 | config OF_FLATTREE | 1 | config DTC |
2 | bool | ||
3 | |||
4 | config OF | ||
2 | bool | 5 | bool |
6 | |||
7 | menu "Flattened Device Tree and Open Firmware support" | ||
3 | depends on OF | 8 | depends on OF |
4 | 9 | ||
10 | config 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 | |||
18 | config OF_FLATTREE | ||
19 | bool | ||
20 | select DTC | ||
21 | |||
5 | config OF_DYNAMIC | 22 | config OF_DYNAMIC |
6 | def_bool y | 23 | def_bool y |
7 | depends on OF && PPC_OF | 24 | depends on PPC_OF |
25 | |||
26 | config OF_ADDRESS | ||
27 | def_bool y | ||
28 | depends on !SPARC | ||
29 | |||
30 | config OF_IRQ | ||
31 | def_bool y | ||
32 | depends on !SPARC | ||
8 | 33 | ||
9 | config OF_DEVICE | 34 | config OF_DEVICE |
10 | def_bool y | 35 | def_bool y |
11 | depends on OF && (SPARC || PPC_OF || MICROBLAZE) | ||
12 | 36 | ||
13 | config OF_GPIO | 37 | config 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 | ||
19 | config OF_I2C | 43 | config 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 | ||
25 | config OF_SPI | 49 | config 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 | ||
31 | config OF_MDIO | 55 | config 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 | |||
61 | endmenu # 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 @@ | |||
1 | obj-y = base.o | 1 | obj-y = base.o |
2 | obj-$(CONFIG_OF_FLATTREE) += fdt.o | 2 | obj-$(CONFIG_OF_FLATTREE) += fdt.o |
3 | obj-$(CONFIG_OF_ADDRESS) += address.o | ||
4 | obj-$(CONFIG_OF_IRQ) += irq.o | ||
3 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o | 5 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o |
4 | obj-$(CONFIG_OF_GPIO) += gpio.o | 6 | obj-$(CONFIG_OF_GPIO) += gpio.o |
5 | obj-$(CONFIG_OF_I2C) += of_i2c.o | 7 | obj-$(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 | |||
14 | static struct of_bus *of_match_bus(struct device_node *np); | ||
15 | static 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 | ||
21 | static 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 | ||
29 | static void of_dump_addr(const char *s, const u32 *addr, int na) { } | ||
30 | #endif | ||
31 | |||
32 | /* Callbacks for bus specific translators */ | ||
33 | struct 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 | |||
49 | static 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 | |||
58 | static 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 | |||
76 | static 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 | |||
88 | static 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 | |||
98 | static 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 | |||
104 | static 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 | |||
113 | static 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 | |||
132 | static 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 | |||
158 | static 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 | |||
163 | const 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 | } | ||
205 | EXPORT_SYMBOL(of_get_pci_address); | ||
206 | |||
207 | int 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 | } | ||
219 | EXPORT_SYMBOL_GPL(of_pci_address_to_resource); | ||
220 | #endif /* CONFIG_PCI */ | ||
221 | |||
222 | /* | ||
223 | * ISA bus specific translator | ||
224 | */ | ||
225 | |||
226 | static int of_bus_isa_match(struct device_node *np) | ||
227 | { | ||
228 | return !strcmp(np->name, "isa"); | ||
229 | } | ||
230 | |||
231 | static 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 | |||
240 | static 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 | |||
262 | static 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 | |||
267 | static 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 | |||
283 | static 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 | |||
318 | static 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 | |||
329 | static 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 | */ | ||
401 | u64 __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 | |||
478 | u64 of_translate_address(struct device_node *dev, const u32 *in_addr) | ||
479 | { | ||
480 | return __of_translate_address(dev, in_addr, "ranges"); | ||
481 | } | ||
482 | EXPORT_SYMBOL(of_translate_address); | ||
483 | |||
484 | u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr) | ||
485 | { | ||
486 | return __of_translate_address(dev, in_addr, "dma-ranges"); | ||
487 | } | ||
488 | EXPORT_SYMBOL(of_translate_dma_address); | ||
489 | |||
490 | const 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 | } | ||
526 | EXPORT_SYMBOL(of_get_address); | ||
527 | |||
528 | static 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 | */ | ||
564 | int 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 | } | ||
576 | EXPORT_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 | */ | ||
586 | void __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 | } | ||
595 | EXPORT_SYMBOL(of_iomap); | ||
diff --git a/drivers/of/base.c b/drivers/of/base.c index b5ad9740d8b2..e3f7af882e45 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, | |||
545 | EXPORT_SYMBOL(of_find_matching_node); | 545 | EXPORT_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 | */ | ||
566 | struct of_modalias_table { | ||
567 | char *of_device; | ||
568 | char *modalias; | ||
569 | }; | ||
570 | static 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 | */ |
591 | int of_modalias_node(struct device_node *node, char *modalias, int len) | 560 | int 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 | } |
618 | EXPORT_SYMBOL_GPL(of_modalias_node); | 572 | EXPORT_SYMBOL_GPL(of_modalias_node); |
diff --git a/drivers/of/device.c b/drivers/of/device.c index 7d18f8e0b013..5282a202f5a9 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c | |||
@@ -20,7 +20,7 @@ | |||
20 | const struct of_device_id *of_match_device(const struct of_device_id *matches, | 20 | const 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 | } |
@@ -68,10 +68,7 @@ static ssize_t name_show(struct device *dev, | |||
68 | static ssize_t modalias_show(struct device *dev, | 68 | static 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; |
@@ -123,19 +120,18 @@ void of_device_unregister(struct of_device *ofdev) | |||
123 | } | 120 | } |
124 | EXPORT_SYMBOL(of_device_unregister); | 121 | EXPORT_SYMBOL(of_device_unregister); |
125 | 122 | ||
126 | ssize_t of_device_get_modalias(struct of_device *ofdev, | 123 | ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) |
127 | char *str, ssize_t len) | ||
128 | { | 124 | { |
129 | const char *compat; | 125 | const char *compat; |
130 | int cplen, i; | 126 | int cplen, i; |
131 | ssize_t tsize, csize, repend; | 127 | ssize_t tsize, csize, repend; |
132 | 128 | ||
133 | /* Name & Type */ | 129 | /* Name & Type */ |
134 | csize = snprintf(str, len, "of:N%sT%s", ofdev->dev.of_node->name, | 130 | csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name, |
135 | ofdev->dev.of_node->type); | 131 | dev->of_node->type); |
136 | 132 | ||
137 | /* Get compatible property if any */ | 133 | /* Get compatible property if any */ |
138 | compat = of_get_property(ofdev->dev.of_node, "compatible", &cplen); | 134 | compat = of_get_property(dev->of_node, "compatible", &cplen); |
139 | if (!compat) | 135 | if (!compat) |
140 | return csize; | 136 | return csize; |
141 | 137 | ||
@@ -170,3 +166,51 @@ ssize_t of_device_get_modalias(struct of_device *ofdev, | |||
170 | 166 | ||
171 | return tsize; | 167 | return tsize; |
172 | } | 168 | } |
169 | |||
170 | /** | ||
171 | * of_device_uevent - Display OF related uevent information | ||
172 | */ | ||
173 | int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
174 | { | ||
175 | const char *compat; | ||
176 | int seen = 0, cplen, sl; | ||
177 | |||
178 | if ((!dev) || (!dev->of_node)) | ||
179 | return -ENODEV; | ||
180 | |||
181 | if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name)) | ||
182 | return -ENOMEM; | ||
183 | |||
184 | if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type)) | ||
185 | return -ENOMEM; | ||
186 | |||
187 | /* Since the compatible field can contain pretty much anything | ||
188 | * it's not really legal to split it out with commas. We split it | ||
189 | * up using a number of environment variables instead. */ | ||
190 | |||
191 | compat = of_get_property(dev->of_node, "compatible", &cplen); | ||
192 | while (compat && *compat && cplen > 0) { | ||
193 | if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat)) | ||
194 | return -ENOMEM; | ||
195 | |||
196 | sl = strlen(compat) + 1; | ||
197 | compat += sl; | ||
198 | cplen -= sl; | ||
199 | seen++; | ||
200 | } | ||
201 | |||
202 | if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen)) | ||
203 | return -ENOMEM; | ||
204 | |||
205 | /* modalias is trickier, we add it in 2 steps */ | ||
206 | if (add_uevent_var(env, "MODALIAS=")) | ||
207 | return -ENOMEM; | ||
208 | |||
209 | sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], | ||
210 | sizeof(env->buf) - env->buflen); | ||
211 | if (sl >= (sizeof(env->buf) - env->buflen)) | ||
212 | return -ENOMEM; | ||
213 | env->buflen += sl; | ||
214 | |||
215 | return 0; | ||
216 | } | ||
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index b6987bba8556..d61fda836e03 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 | ||
@@ -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) { |
@@ -333,7 +333,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
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; |
75 | err1: | 76 | err1: |
76 | of_node_put(gc); | 77 | of_node_put(gpio_np); |
77 | err0: | 78 | err0: |
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 | */ |
128 | int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, | 129 | static 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 | } |
153 | EXPORT_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; |
211 | err2: | 202 | err2: |
212 | np->data = NULL; | ||
213 | iounmap(mm_gc->regs); | 203 | iounmap(mm_gc->regs); |
214 | err1: | 204 | err1: |
215 | kfree(gc->label); | 205 | kfree(gc->label); |
@@ -219,3 +209,36 @@ err0: | |||
219 | return ret; | 209 | return ret; |
220 | } | 210 | } |
221 | EXPORT_SYMBOL(of_mm_gpiochip_add); | 211 | EXPORT_SYMBOL(of_mm_gpiochip_add); |
212 | |||
213 | void 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 | |||
229 | void 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 */ | ||
236 | static int of_gpiochip_is_match(struct gpio_chip *chip, void *data) | ||
237 | { | ||
238 | return chip->of_node == data; | ||
239 | } | ||
240 | |||
241 | struct 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..6cfb307204c3 --- /dev/null +++ b/drivers/of/irq.c | |||
@@ -0,0 +1,348 @@ | |||
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 | */ | ||
35 | unsigned 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 | } | ||
45 | EXPORT_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 | */ | ||
54 | static struct device_node *of_irq_find_parent(struct device_node *child) | ||
55 | { | ||
56 | struct device_node *p; | ||
57 | const phandle *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(*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 | */ | ||
94 | int of_irq_map_raw(struct device_node *parent, const u32 *intspec, u32 ointsize, | ||
95 | const u32 *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, intspec[0], intspec[1], ointsize); | ||
104 | |||
105 | ipar = of_node_get(parent); | ||
106 | |||
107 | /* First get the #interrupt-cells property of the current cursor | ||
108 | * that tells us how to interpret the passed-in intspec. If there | ||
109 | * is none, we are nice and just walk up the tree | ||
110 | */ | ||
111 | do { | ||
112 | tmp = of_get_property(ipar, "#interrupt-cells", NULL); | ||
113 | if (tmp != NULL) { | ||
114 | intsize = be32_to_cpu(*tmp); | ||
115 | break; | ||
116 | } | ||
117 | tnode = ipar; | ||
118 | ipar = of_irq_find_parent(ipar); | ||
119 | of_node_put(tnode); | ||
120 | } while (ipar); | ||
121 | if (ipar == NULL) { | ||
122 | pr_debug(" -> no parent found !\n"); | ||
123 | goto fail; | ||
124 | } | ||
125 | |||
126 | pr_debug("of_irq_map_raw: ipar=%s, size=%d\n", ipar->full_name, intsize); | ||
127 | |||
128 | if (ointsize != intsize) | ||
129 | return -EINVAL; | ||
130 | |||
131 | /* Look for this #address-cells. We have to implement the old linux | ||
132 | * trick of looking for the parent here as some device-trees rely on it | ||
133 | */ | ||
134 | old = of_node_get(ipar); | ||
135 | do { | ||
136 | tmp = of_get_property(old, "#address-cells", NULL); | ||
137 | tnode = of_get_parent(old); | ||
138 | of_node_put(old); | ||
139 | old = tnode; | ||
140 | } while (old && tmp == NULL); | ||
141 | of_node_put(old); | ||
142 | old = NULL; | ||
143 | addrsize = (tmp == NULL) ? 2 : be32_to_cpu(*tmp); | ||
144 | |||
145 | pr_debug(" -> addrsize=%d\n", addrsize); | ||
146 | |||
147 | /* Now start the actual "proper" walk of the interrupt tree */ | ||
148 | while (ipar != NULL) { | ||
149 | /* Now check if cursor is an interrupt-controller and if it is | ||
150 | * then we are done | ||
151 | */ | ||
152 | if (of_get_property(ipar, "interrupt-controller", NULL) != | ||
153 | NULL) { | ||
154 | pr_debug(" -> got it !\n"); | ||
155 | for (i = 0; i < intsize; i++) | ||
156 | out_irq->specifier[i] = | ||
157 | of_read_number(intspec +i, 1); | ||
158 | out_irq->size = intsize; | ||
159 | out_irq->controller = ipar; | ||
160 | of_node_put(old); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | /* Now look for an interrupt-map */ | ||
165 | imap = of_get_property(ipar, "interrupt-map", &imaplen); | ||
166 | /* No interrupt map, check for an interrupt parent */ | ||
167 | if (imap == NULL) { | ||
168 | pr_debug(" -> no map, getting parent\n"); | ||
169 | newpar = of_irq_find_parent(ipar); | ||
170 | goto skiplevel; | ||
171 | } | ||
172 | imaplen /= sizeof(u32); | ||
173 | |||
174 | /* Look for a mask */ | ||
175 | imask = of_get_property(ipar, "interrupt-map-mask", NULL); | ||
176 | |||
177 | /* If we were passed no "reg" property and we attempt to parse | ||
178 | * an interrupt-map, then #address-cells must be 0. | ||
179 | * Fail if it's not. | ||
180 | */ | ||
181 | if (addr == NULL && addrsize != 0) { | ||
182 | pr_debug(" -> no reg passed in when needed !\n"); | ||
183 | goto fail; | ||
184 | } | ||
185 | |||
186 | /* Parse interrupt-map */ | ||
187 | match = 0; | ||
188 | while (imaplen > (addrsize + intsize + 1) && !match) { | ||
189 | /* Compare specifiers */ | ||
190 | match = 1; | ||
191 | for (i = 0; i < addrsize && match; ++i) { | ||
192 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
193 | match = ((addr[i] ^ imap[i]) & mask) == 0; | ||
194 | } | ||
195 | for (; i < (addrsize + intsize) && match; ++i) { | ||
196 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
197 | match = | ||
198 | ((intspec[i-addrsize] ^ imap[i]) & mask) == 0; | ||
199 | } | ||
200 | imap += addrsize + intsize; | ||
201 | imaplen -= addrsize + intsize; | ||
202 | |||
203 | pr_debug(" -> match=%d (imaplen=%d)\n", match, imaplen); | ||
204 | |||
205 | /* Get the interrupt parent */ | ||
206 | if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) | ||
207 | newpar = of_node_get(of_irq_dflt_pic); | ||
208 | else | ||
209 | newpar = of_find_node_by_phandle((phandle)*imap); | ||
210 | imap++; | ||
211 | --imaplen; | ||
212 | |||
213 | /* Check if not found */ | ||
214 | if (newpar == NULL) { | ||
215 | pr_debug(" -> imap parent not found !\n"); | ||
216 | goto fail; | ||
217 | } | ||
218 | |||
219 | /* Get #interrupt-cells and #address-cells of new | ||
220 | * parent | ||
221 | */ | ||
222 | tmp = of_get_property(newpar, "#interrupt-cells", NULL); | ||
223 | if (tmp == NULL) { | ||
224 | pr_debug(" -> parent lacks #interrupt-cells!\n"); | ||
225 | goto fail; | ||
226 | } | ||
227 | newintsize = be32_to_cpu(*tmp); | ||
228 | tmp = of_get_property(newpar, "#address-cells", NULL); | ||
229 | newaddrsize = (tmp == NULL) ? 0 : be32_to_cpu(*tmp); | ||
230 | |||
231 | pr_debug(" -> newintsize=%d, newaddrsize=%d\n", | ||
232 | newintsize, newaddrsize); | ||
233 | |||
234 | /* Check for malformed properties */ | ||
235 | if (imaplen < (newaddrsize + newintsize)) | ||
236 | goto fail; | ||
237 | |||
238 | imap += newaddrsize + newintsize; | ||
239 | imaplen -= newaddrsize + newintsize; | ||
240 | |||
241 | pr_debug(" -> imaplen=%d\n", imaplen); | ||
242 | } | ||
243 | if (!match) | ||
244 | goto fail; | ||
245 | |||
246 | of_node_put(old); | ||
247 | old = of_node_get(newpar); | ||
248 | addrsize = newaddrsize; | ||
249 | intsize = newintsize; | ||
250 | intspec = imap - intsize; | ||
251 | addr = intspec - addrsize; | ||
252 | |||
253 | skiplevel: | ||
254 | /* Iterate again with new parent */ | ||
255 | pr_debug(" -> new parent: %s\n", newpar ? newpar->full_name : "<>"); | ||
256 | of_node_put(ipar); | ||
257 | ipar = newpar; | ||
258 | newpar = NULL; | ||
259 | } | ||
260 | fail: | ||
261 | of_node_put(ipar); | ||
262 | of_node_put(old); | ||
263 | of_node_put(newpar); | ||
264 | |||
265 | return -EINVAL; | ||
266 | } | ||
267 | EXPORT_SYMBOL_GPL(of_irq_map_raw); | ||
268 | |||
269 | /** | ||
270 | * of_irq_map_one - Resolve an interrupt for a device | ||
271 | * @device: the device whose interrupt is to be resolved | ||
272 | * @index: index of the interrupt to resolve | ||
273 | * @out_irq: structure of_irq filled by this function | ||
274 | * | ||
275 | * This function resolves an interrupt, walking the tree, for a given | ||
276 | * device-tree node. It's the high level pendant to of_irq_map_raw(). | ||
277 | */ | ||
278 | int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq) | ||
279 | { | ||
280 | struct device_node *p; | ||
281 | const u32 *intspec, *tmp, *addr; | ||
282 | u32 intsize, intlen; | ||
283 | int res = -EINVAL; | ||
284 | |||
285 | pr_debug("of_irq_map_one: dev=%s, index=%d\n", device->full_name, index); | ||
286 | |||
287 | /* OldWorld mac stuff is "special", handle out of line */ | ||
288 | if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC) | ||
289 | return of_irq_map_oldworld(device, index, out_irq); | ||
290 | |||
291 | /* Get the interrupts property */ | ||
292 | intspec = of_get_property(device, "interrupts", &intlen); | ||
293 | if (intspec == NULL) | ||
294 | return -EINVAL; | ||
295 | intlen /= sizeof(u32); | ||
296 | |||
297 | pr_debug(" intspec=%d intlen=%d\n", *intspec, intlen); | ||
298 | |||
299 | /* Get the reg property (if any) */ | ||
300 | addr = of_get_property(device, "reg", NULL); | ||
301 | |||
302 | /* Look for the interrupt parent. */ | ||
303 | p = of_irq_find_parent(device); | ||
304 | if (p == NULL) | ||
305 | return -EINVAL; | ||
306 | |||
307 | /* Get size of interrupt specifier */ | ||
308 | tmp = of_get_property(p, "#interrupt-cells", NULL); | ||
309 | if (tmp == NULL) | ||
310 | goto out; | ||
311 | intsize = be32_to_cpu(*tmp); | ||
312 | |||
313 | pr_debug(" intsize=%d intlen=%d\n", intsize, intlen); | ||
314 | |||
315 | /* Check index */ | ||
316 | if ((index + 1) * intsize > intlen) | ||
317 | goto out; | ||
318 | |||
319 | /* Get new specifier and map it */ | ||
320 | res = of_irq_map_raw(p, intspec + index * intsize, intsize, | ||
321 | addr, out_irq); | ||
322 | out: | ||
323 | of_node_put(p); | ||
324 | return res; | ||
325 | } | ||
326 | EXPORT_SYMBOL_GPL(of_irq_map_one); | ||
327 | |||
328 | /** | ||
329 | * of_irq_to_resource - Decode a node's IRQ and return it as a resource | ||
330 | * @dev: pointer to device tree node | ||
331 | * @index: zero-based index of the irq | ||
332 | * @r: pointer to resource structure to return result into. | ||
333 | */ | ||
334 | int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) | ||
335 | { | ||
336 | int irq = irq_of_parse_and_map(dev, index); | ||
337 | |||
338 | /* Only dereference the resource if both the | ||
339 | * resource and the irq are valid. */ | ||
340 | if (r && irq != NO_IRQ) { | ||
341 | r->start = r->end = irq; | ||
342 | r->flags = IORESOURCE_IRQ; | ||
343 | r->name = dev->full_name; | ||
344 | } | ||
345 | |||
346 | return irq; | ||
347 | } | ||
348 | EXPORT_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 | ||
19 | void of_register_i2c_devices(struct i2c_adapter *adap, | 20 | void 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 | } |
67 | EXPORT_SYMBOL(of_register_i2c_devices); | 75 | EXPORT_SYMBOL(of_i2c_register_devices); |
68 | 76 | ||
69 | static int of_dev_node_match(struct device *dev, void *data) | 77 | static 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..d504f1d1324b 100644 --- a/drivers/of/of_spi.c +++ b/drivers/of/of_spi.c | |||
@@ -9,6 +9,7 @@ | |||
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 | /** |
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 7dacc1ebe91e..9d3d932bcb6f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -14,9 +14,17 @@ | |||
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> |
19 | 23 | ||
24 | #if defined(CONFIG_PPC_DCR) | ||
25 | #include <asm/dcr.h> | ||
26 | #endif | ||
27 | |||
20 | extern struct device_attribute of_platform_device_attrs[]; | 28 | extern struct device_attribute of_platform_device_attrs[]; |
21 | 29 | ||
22 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) | 30 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) |
@@ -396,3 +404,263 @@ void of_unregister_driver(struct of_platform_driver *drv) | |||
396 | driver_unregister(&drv->driver); | 404 | driver_unregister(&drv->driver); |
397 | } | 405 | } |
398 | EXPORT_SYMBOL(of_unregister_driver); | 406 | EXPORT_SYMBOL(of_unregister_driver); |
407 | |||
408 | #if !defined(CONFIG_SPARC) | ||
409 | /* | ||
410 | * The following routines scan a subtree and registers a device for | ||
411 | * each applicable node. | ||
412 | * | ||
413 | * Note: sparc doesn't use these routines because it has a different | ||
414 | * mechanism for creating devices from device tree nodes. | ||
415 | */ | ||
416 | |||
417 | /** | ||
418 | * of_device_make_bus_id - Use the device node data to assign a unique name | ||
419 | * @dev: pointer to device structure that is linked to a device tree node | ||
420 | * | ||
421 | * This routine will first try using either the dcr-reg or the reg property | ||
422 | * value to derive a unique name. As a last resort it will use the node | ||
423 | * name followed by a unique number. | ||
424 | */ | ||
425 | static void of_device_make_bus_id(struct device *dev) | ||
426 | { | ||
427 | static atomic_t bus_no_reg_magic; | ||
428 | struct device_node *node = dev->of_node; | ||
429 | const u32 *reg; | ||
430 | u64 addr; | ||
431 | int magic; | ||
432 | |||
433 | #ifdef CONFIG_PPC_DCR | ||
434 | /* | ||
435 | * If it's a DCR based device, use 'd' for native DCRs | ||
436 | * and 'D' for MMIO DCRs. | ||
437 | */ | ||
438 | reg = of_get_property(node, "dcr-reg", NULL); | ||
439 | if (reg) { | ||
440 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
441 | dev_set_name(dev, "d%x.%s", *reg, node->name); | ||
442 | #else /* CONFIG_PPC_DCR_NATIVE */ | ||
443 | u64 addr = of_translate_dcr_address(node, *reg, NULL); | ||
444 | if (addr != OF_BAD_ADDR) { | ||
445 | dev_set_name(dev, "D%llx.%s", | ||
446 | (unsigned long long)addr, node->name); | ||
447 | return; | ||
448 | } | ||
449 | #endif /* !CONFIG_PPC_DCR_NATIVE */ | ||
450 | } | ||
451 | #endif /* CONFIG_PPC_DCR */ | ||
452 | |||
453 | /* | ||
454 | * For MMIO, get the physical address | ||
455 | */ | ||
456 | reg = of_get_property(node, "reg", NULL); | ||
457 | if (reg) { | ||
458 | addr = of_translate_address(node, reg); | ||
459 | if (addr != OF_BAD_ADDR) { | ||
460 | dev_set_name(dev, "%llx.%s", | ||
461 | (unsigned long long)addr, node->name); | ||
462 | return; | ||
463 | } | ||
464 | } | ||
465 | |||
466 | /* | ||
467 | * No BusID, use the node name and add a globally incremented | ||
468 | * counter (and pray...) | ||
469 | */ | ||
470 | magic = atomic_add_return(1, &bus_no_reg_magic); | ||
471 | dev_set_name(dev, "%s.%d", node->name, magic - 1); | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * of_device_alloc - Allocate and initialize an of_device | ||
476 | * @np: device node to assign to device | ||
477 | * @bus_id: Name to assign to the device. May be null to use default name. | ||
478 | * @parent: Parent device. | ||
479 | */ | ||
480 | struct of_device *of_device_alloc(struct device_node *np, | ||
481 | const char *bus_id, | ||
482 | struct device *parent) | ||
483 | { | ||
484 | struct of_device *dev; | ||
485 | int rc, i, num_reg = 0, num_irq = 0; | ||
486 | struct resource *res, temp_res; | ||
487 | |||
488 | /* First count how many resources are needed */ | ||
489 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
490 | num_reg++; | ||
491 | while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ) | ||
492 | num_irq++; | ||
493 | |||
494 | /* Allocate memory for both the struct device and the resource table */ | ||
495 | dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), | ||
496 | GFP_KERNEL); | ||
497 | if (!dev) | ||
498 | return NULL; | ||
499 | res = (struct resource *) &dev[1]; | ||
500 | |||
501 | /* Populate the resource table */ | ||
502 | if (num_irq || num_reg) { | ||
503 | dev->num_resources = num_reg + num_irq; | ||
504 | dev->resource = res; | ||
505 | for (i = 0; i < num_reg; i++, res++) { | ||
506 | rc = of_address_to_resource(np, i, res); | ||
507 | WARN_ON(rc); | ||
508 | } | ||
509 | for (i = 0; i < num_irq; i++, res++) { | ||
510 | rc = of_irq_to_resource(np, i, res); | ||
511 | WARN_ON(rc == NO_IRQ); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | dev->dev.of_node = of_node_get(np); | ||
516 | #if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE) | ||
517 | dev->dev.dma_mask = &dev->archdata.dma_mask; | ||
518 | #endif | ||
519 | dev->dev.parent = parent; | ||
520 | dev->dev.release = of_release_dev; | ||
521 | |||
522 | if (bus_id) | ||
523 | dev_set_name(&dev->dev, "%s", bus_id); | ||
524 | else | ||
525 | of_device_make_bus_id(&dev->dev); | ||
526 | |||
527 | return dev; | ||
528 | } | ||
529 | EXPORT_SYMBOL(of_device_alloc); | ||
530 | |||
531 | /** | ||
532 | * of_platform_device_create - Alloc, initialize and register an of_device | ||
533 | * @np: pointer to node to create device for | ||
534 | * @bus_id: name to assign device | ||
535 | * @parent: Linux device model parent device. | ||
536 | */ | ||
537 | struct of_device *of_platform_device_create(struct device_node *np, | ||
538 | const char *bus_id, | ||
539 | struct device *parent) | ||
540 | { | ||
541 | struct of_device *dev; | ||
542 | |||
543 | dev = of_device_alloc(np, bus_id, parent); | ||
544 | if (!dev) | ||
545 | return NULL; | ||
546 | |||
547 | #if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE) | ||
548 | dev->archdata.dma_mask = 0xffffffffUL; | ||
549 | #endif | ||
550 | dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | ||
551 | dev->dev.bus = &of_platform_bus_type; | ||
552 | |||
553 | /* We do not fill the DMA ops for platform devices by default. | ||
554 | * This is currently the responsibility of the platform code | ||
555 | * to do such, possibly using a device notifier | ||
556 | */ | ||
557 | |||
558 | if (of_device_register(dev) != 0) { | ||
559 | of_device_free(dev); | ||
560 | return NULL; | ||
561 | } | ||
562 | |||
563 | return dev; | ||
564 | } | ||
565 | EXPORT_SYMBOL(of_platform_device_create); | ||
566 | |||
567 | /** | ||
568 | * of_platform_bus_create - Create an OF device for a bus node and all its | ||
569 | * children. Optionally recursively instantiate matching busses. | ||
570 | * @bus: device node of the bus to instantiate | ||
571 | * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to | ||
572 | * disallow recursive creation of child busses | ||
573 | */ | ||
574 | static int of_platform_bus_create(const struct device_node *bus, | ||
575 | const struct of_device_id *matches, | ||
576 | struct device *parent) | ||
577 | { | ||
578 | struct device_node *child; | ||
579 | struct of_device *dev; | ||
580 | int rc = 0; | ||
581 | |||
582 | for_each_child_of_node(bus, child) { | ||
583 | pr_debug(" create child: %s\n", child->full_name); | ||
584 | dev = of_platform_device_create(child, NULL, parent); | ||
585 | if (dev == NULL) | ||
586 | rc = -ENOMEM; | ||
587 | else if (!of_match_node(matches, child)) | ||
588 | continue; | ||
589 | if (rc == 0) { | ||
590 | pr_debug(" and sub busses\n"); | ||
591 | rc = of_platform_bus_create(child, matches, &dev->dev); | ||
592 | } | ||
593 | if (rc) { | ||
594 | of_node_put(child); | ||
595 | break; | ||
596 | } | ||
597 | } | ||
598 | return rc; | ||
599 | } | ||
600 | |||
601 | /** | ||
602 | * of_platform_bus_probe - Probe the device-tree for platform busses | ||
603 | * @root: parent of the first level to probe or NULL for the root of the tree | ||
604 | * @matches: match table, NULL to use the default | ||
605 | * @parent: parent to hook devices from, NULL for toplevel | ||
606 | * | ||
607 | * Note that children of the provided root are not instantiated as devices | ||
608 | * unless the specified root itself matches the bus list and is not NULL. | ||
609 | */ | ||
610 | int of_platform_bus_probe(struct device_node *root, | ||
611 | const struct of_device_id *matches, | ||
612 | struct device *parent) | ||
613 | { | ||
614 | struct device_node *child; | ||
615 | struct of_device *dev; | ||
616 | int rc = 0; | ||
617 | |||
618 | if (matches == NULL) | ||
619 | matches = of_default_bus_ids; | ||
620 | if (matches == OF_NO_DEEP_PROBE) | ||
621 | return -EINVAL; | ||
622 | if (root == NULL) | ||
623 | root = of_find_node_by_path("/"); | ||
624 | else | ||
625 | of_node_get(root); | ||
626 | if (root == NULL) | ||
627 | return -EINVAL; | ||
628 | |||
629 | pr_debug("of_platform_bus_probe()\n"); | ||
630 | pr_debug(" starting at: %s\n", root->full_name); | ||
631 | |||
632 | /* Do a self check of bus type, if there's a match, create | ||
633 | * children | ||
634 | */ | ||
635 | if (of_match_node(matches, root)) { | ||
636 | pr_debug(" root match, create all sub devices\n"); | ||
637 | dev = of_platform_device_create(root, NULL, parent); | ||
638 | if (dev == NULL) { | ||
639 | rc = -ENOMEM; | ||
640 | goto bail; | ||
641 | } | ||
642 | pr_debug(" create all sub busses\n"); | ||
643 | rc = of_platform_bus_create(root, matches, &dev->dev); | ||
644 | goto bail; | ||
645 | } | ||
646 | for_each_child_of_node(root, child) { | ||
647 | if (!of_match_node(matches, child)) | ||
648 | continue; | ||
649 | |||
650 | pr_debug(" match: %s\n", child->full_name); | ||
651 | dev = of_platform_device_create(child, NULL, parent); | ||
652 | if (dev == NULL) | ||
653 | rc = -ENOMEM; | ||
654 | else | ||
655 | rc = of_platform_bus_create(child, matches, &dev->dev); | ||
656 | if (rc) { | ||
657 | of_node_put(child); | ||
658 | break; | ||
659 | } | ||
660 | } | ||
661 | bail: | ||
662 | of_node_put(root); | ||
663 | return rc; | ||
664 | } | ||
665 | EXPORT_SYMBOL(of_platform_bus_probe); | ||
666 | #endif /* !CONFIG_SPARC */ | ||
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c index 9a5b4b894161..3cdfe96e8999 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"); |
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c index 8bfdd63a1fcb..40d7a1fc69af 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); |
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c index 5f253665a1da..b8b40e9eca79 100644 --- a/drivers/sbus/char/uctrl.c +++ b/drivers/sbus/char/uctrl.c | |||
@@ -367,7 +367,7 @@ static int __devinit uctrl_probe(struct of_device *op, | |||
367 | goto out_free; | 367 | goto out_free; |
368 | } | 368 | } |
369 | 369 | ||
370 | p->irq = op->irqs[0]; | 370 | p->irq = op->archdata.irqs[0]; |
371 | err = request_irq(p->irq, uctrl_interrupt, 0, "uctrl", p); | 371 | err = request_irq(p->irq, uctrl_interrupt, 0, "uctrl", p); |
372 | if (err) { | 372 | if (err) { |
373 | printk(KERN_ERR "uctrl: Unable to register irq.\n"); | 373 | printk(KERN_ERR "uctrl: Unable to register irq.\n"); |
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c index ca5c15c779cf..3f5b5411e6bc 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)); |
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c index 386dd9d602b6..ddc221acd14c 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 | ||
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c index 890f91742962..36e244867dd8 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 | ||
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c index 5e81bc6b48b0..0a7dd6841ff8 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; |
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c index ffbf4553f665..5deafc8180b5 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 | ||
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c index f9a24f4ebb34..fcbe20d48039 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 | ||
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c index d62b9ce8f773..8c03fd71693e 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 | ||