aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sbus
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2006-06-25 06:44:44 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-06-25 06:44:44 -0400
commit76a9f26c9e40e9c0ed5dc8f0cedd74e733f0088d (patch)
tree8e2db4ba9263e92d264ef469c7dac28078f63874 /drivers/sbus
parent9bf2aa129a107a0e9e2a5318d35aca731ae7e666 (diff)
parentdfd8317d3340f03bc06eba6b58f0ec0861da4a13 (diff)
Merge branch 'master' of /home/trondmy/kernel/linux-2.6/
Diffstat (limited to 'drivers/sbus')
-rw-r--r--drivers/sbus/char/bbc_envctrl.c4
-rw-r--r--drivers/sbus/char/bbc_i2c.c4
-rw-r--r--drivers/sbus/char/display7seg.c2
-rw-r--r--drivers/sbus/char/envctrl.c71
-rw-r--r--drivers/sbus/char/flash.c16
-rw-r--r--drivers/sbus/char/openprom.c4
-rw-r--r--drivers/sbus/sbus.c582
7 files changed, 202 insertions, 481 deletions
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index d89f83f769f5..1cc706e11119 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -575,9 +575,9 @@ int bbc_envctrl_init(void)
575 int devidx = 0; 575 int devidx = 0;
576 576
577 while ((echild = bbc_i2c_getdev(devidx++)) != NULL) { 577 while ((echild = bbc_i2c_getdev(devidx++)) != NULL) {
578 if (!strcmp(echild->prom_name, "temperature")) 578 if (!strcmp(echild->prom_node->name, "temperature"))
579 attach_one_temp(echild, temp_index++); 579 attach_one_temp(echild, temp_index++);
580 if (!strcmp(echild->prom_name, "fan-control")) 580 if (!strcmp(echild->prom_node->name, "fan-control"))
581 attach_one_fan(echild, fan_index++); 581 attach_one_fan(echild, fan_index++);
582 } 582 }
583 if (temp_index != 0 && fan_index != 0) { 583 if (temp_index != 0 && fan_index != 0) {
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 3e156e005f2e..73634371393b 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -423,7 +423,7 @@ static int __init bbc_present(void)
423 423
424 for_each_ebus(ebus) { 424 for_each_ebus(ebus) {
425 for_each_ebusdev(edev, ebus) { 425 for_each_ebusdev(edev, ebus) {
426 if (!strcmp(edev->prom_name, "bbc")) 426 if (!strcmp(edev->prom_node->name, "bbc"))
427 return 1; 427 return 1;
428 } 428 }
429 } 429 }
@@ -446,7 +446,7 @@ static int __init bbc_i2c_init(void)
446 446
447 for_each_ebus(ebus) { 447 for_each_ebus(ebus) {
448 for_each_ebusdev(edev, ebus) { 448 for_each_ebusdev(edev, ebus) {
449 if (!strcmp(edev->prom_name, "i2c")) { 449 if (!strcmp(edev->prom_node->name, "i2c")) {
450 if (!attach_one_i2c(edev, index)) 450 if (!attach_one_i2c(edev, index))
451 index++; 451 index++;
452 } 452 }
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index c3a51d1fae5d..d92bc8827a9e 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -184,7 +184,7 @@ static int __init d7s_init(void)
184 184
185 for_each_ebus(ebus) { 185 for_each_ebus(ebus) {
186 for_each_ebusdev(edev, ebus) { 186 for_each_ebusdev(edev, ebus) {
187 if (!strcmp(edev->prom_name, D7S_OBPNAME)) 187 if (!strcmp(edev->prom_node->name, D7S_OBPNAME))
188 goto ebus_done; 188 goto ebus_done;
189 } 189 }
190 } 190 }
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index 19e8eddf887a..cf97e9efe9b6 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -768,16 +768,14 @@ static void envctrl_set_mon(struct i2c_child_t *pchild,
768 * decoding tables, monitor type, optional properties. 768 * decoding tables, monitor type, optional properties.
769 * Return: None. 769 * Return: None.
770 */ 770 */
771static void envctrl_init_adc(struct i2c_child_t *pchild, int node) 771static void envctrl_init_adc(struct i2c_child_t *pchild, struct device_node *dp)
772{ 772{
773 char chnls_desc[CHANNEL_DESC_SZ];
774 int i = 0, len; 773 int i = 0, len;
775 char *pos = chnls_desc; 774 char *pos;
775 unsigned int *pval;
776 776
777 /* Firmware describe channels into a stream separated by a '\0'. */ 777 /* Firmware describe channels into a stream separated by a '\0'. */
778 len = prom_getproperty(node, "channels-description", chnls_desc, 778 pos = of_get_property(dp, "channels-description", &len);
779 CHANNEL_DESC_SZ);
780 chnls_desc[CHANNEL_DESC_SZ - 1] = '\0';
781 779
782 while (len > 0) { 780 while (len > 0) {
783 int l = strlen(pos) + 1; 781 int l = strlen(pos) + 1;
@@ -787,10 +785,13 @@ static void envctrl_init_adc(struct i2c_child_t *pchild, int node)
787 } 785 }
788 786
789 /* Get optional properties. */ 787 /* Get optional properties. */
790 len = prom_getproperty(node, "warning-temp", (char *)&warning_temperature, 788 pval = of_get_property(dp, "warning-temp", NULL);
791 sizeof(warning_temperature)); 789 if (pval)
792 len = prom_getproperty(node, "shutdown-temp", (char *)&shutdown_temperature, 790 warning_temperature = *pval;
793 sizeof(shutdown_temperature)); 791
792 pval = of_get_property(dp, "shutdown-temp", NULL);
793 if (pval)
794 shutdown_temperature = *pval;
794} 795}
795 796
796/* Function Description: Initialize child device monitoring fan status. 797/* Function Description: Initialize child device monitoring fan status.
@@ -864,21 +865,18 @@ static void envctrl_init_voltage_status(struct i2c_child_t *pchild)
864static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child, 865static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child,
865 struct i2c_child_t *pchild) 866 struct i2c_child_t *pchild)
866{ 867{
867 int node, len, i, tbls_size = 0; 868 int len, i, tbls_size = 0;
868 869 struct device_node *dp = edev_child->prom_node;
869 node = edev_child->prom_node; 870 void *pval;
870 871
871 /* Get device address. */ 872 /* Get device address. */
872 len = prom_getproperty(node, "reg", 873 pval = of_get_property(dp, "reg", &len);
873 (char *) &(pchild->addr), 874 memcpy(&pchild->addr, pval, len);
874 sizeof(pchild->addr));
875 875
876 /* Get tables property. Read firmware temperature tables. */ 876 /* Get tables property. Read firmware temperature tables. */
877 len = prom_getproperty(node, "translation", 877 pval = of_get_property(dp, "translation", &len);
878 (char *) pchild->tblprop_array, 878 if (pval && len > 0) {
879 (PCF8584_MAX_CHANNELS * 879 memcpy(pchild->tblprop_array, pval, len);
880 sizeof(struct pcf8584_tblprop)));
881 if (len > 0) {
882 pchild->total_tbls = len / sizeof(struct pcf8584_tblprop); 880 pchild->total_tbls = len / sizeof(struct pcf8584_tblprop);
883 for (i = 0; i < pchild->total_tbls; i++) { 881 for (i = 0; i < pchild->total_tbls; i++) {
884 if ((pchild->tblprop_array[i].size + pchild->tblprop_array[i].offset) > tbls_size) { 882 if ((pchild->tblprop_array[i].size + pchild->tblprop_array[i].offset) > tbls_size) {
@@ -891,12 +889,12 @@ static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child,
891 printk("envctrl: Failed to allocate table.\n"); 889 printk("envctrl: Failed to allocate table.\n");
892 return; 890 return;
893 } 891 }
894 len = prom_getproperty(node, "tables", 892 pval = of_get_property(dp, "tables", &len);
895 (char *) pchild->tables, tbls_size); 893 if (!pval || len <= 0) {
896 if (len <= 0) {
897 printk("envctrl: Failed to get table.\n"); 894 printk("envctrl: Failed to get table.\n");
898 return; 895 return;
899 } 896 }
897 memcpy(pchild->tables, pval, len);
900 } 898 }
901 899
902 /* SPARCengine ASM Reference Manual (ref. SMI doc 805-7581-04) 900 /* SPARCengine ASM Reference Manual (ref. SMI doc 805-7581-04)
@@ -907,12 +905,11 @@ static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child,
907 * 'NULL' monitor type. 905 * 'NULL' monitor type.
908 */ 906 */
909 if (ENVCTRL_CPCI_IGNORED_NODE == pchild->addr) { 907 if (ENVCTRL_CPCI_IGNORED_NODE == pchild->addr) {
908 struct device_node *root_node;
910 int len; 909 int len;
911 char prop[56];
912 910
913 len = prom_getproperty(prom_root_node, "name", prop, sizeof(prop)); 911 root_node = of_find_node_by_path("/");
914 if (0 < len && (0 == strncmp(prop, "SUNW,UltraSPARC-IIi-cEngine", len))) 912 if (!strcmp(root_node->name, "SUNW,UltraSPARC-IIi-cEngine")) {
915 {
916 for (len = 0; len < PCF8584_MAX_CHANNELS; ++len) { 913 for (len = 0; len < PCF8584_MAX_CHANNELS; ++len) {
917 pchild->mon_type[len] = ENVCTRL_NOMON; 914 pchild->mon_type[len] = ENVCTRL_NOMON;
918 } 915 }
@@ -921,16 +918,14 @@ static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child,
921 } 918 }
922 919
923 /* Get the monitor channels. */ 920 /* Get the monitor channels. */
924 len = prom_getproperty(node, "channels-in-use", 921 pval = of_get_property(dp, "channels-in-use", &len);
925 (char *) pchild->chnl_array, 922 memcpy(pchild->chnl_array, pval, len);
926 (PCF8584_MAX_CHANNELS *
927 sizeof(struct pcf8584_channel)));
928 pchild->total_chnls = len / sizeof(struct pcf8584_channel); 923 pchild->total_chnls = len / sizeof(struct pcf8584_channel);
929 924
930 for (i = 0; i < pchild->total_chnls; i++) { 925 for (i = 0; i < pchild->total_chnls; i++) {
931 switch (pchild->chnl_array[i].type) { 926 switch (pchild->chnl_array[i].type) {
932 case PCF8584_TEMP_TYPE: 927 case PCF8584_TEMP_TYPE:
933 envctrl_init_adc(pchild, node); 928 envctrl_init_adc(pchild, dp);
934 break; 929 break;
935 930
936 case PCF8584_GLOBALADDR_TYPE: 931 case PCF8584_GLOBALADDR_TYPE:
@@ -945,7 +940,7 @@ static void envctrl_init_i2c_child(struct linux_ebus_child *edev_child,
945 940
946 case PCF8584_VOLTAGE_TYPE: 941 case PCF8584_VOLTAGE_TYPE:
947 if (pchild->i2ctype == I2C_ADC) { 942 if (pchild->i2ctype == I2C_ADC) {
948 envctrl_init_adc(pchild,node); 943 envctrl_init_adc(pchild,dp);
949 } else { 944 } else {
950 envctrl_init_voltage_status(pchild); 945 envctrl_init_voltage_status(pchild);
951 } 946 }
@@ -1046,7 +1041,7 @@ static int __init envctrl_init(void)
1046 1041
1047 for_each_ebus(ebus) { 1042 for_each_ebus(ebus) {
1048 for_each_ebusdev(edev, ebus) { 1043 for_each_ebusdev(edev, ebus) {
1049 if (!strcmp(edev->prom_name, "bbc")) { 1044 if (!strcmp(edev->prom_node->name, "bbc")) {
1050 /* If we find a boot-bus controller node, 1045 /* If we find a boot-bus controller node,
1051 * then this envctrl driver is not for us. 1046 * then this envctrl driver is not for us.
1052 */ 1047 */
@@ -1060,14 +1055,14 @@ static int __init envctrl_init(void)
1060 */ 1055 */
1061 for_each_ebus(ebus) { 1056 for_each_ebus(ebus) {
1062 for_each_ebusdev(edev, ebus) { 1057 for_each_ebusdev(edev, ebus) {
1063 if (!strcmp(edev->prom_name, "i2c")) { 1058 if (!strcmp(edev->prom_node->name, "i2c")) {
1064 i2c = ioremap(edev->resource[0].start, 0x2); 1059 i2c = ioremap(edev->resource[0].start, 0x2);
1065 for_each_edevchild(edev, edev_child) { 1060 for_each_edevchild(edev, edev_child) {
1066 if (!strcmp("gpio", edev_child->prom_name)) { 1061 if (!strcmp("gpio", edev_child->prom_node->name)) {
1067 i2c_childlist[i].i2ctype = I2C_GPIO; 1062 i2c_childlist[i].i2ctype = I2C_GPIO;
1068 envctrl_init_i2c_child(edev_child, &(i2c_childlist[i++])); 1063 envctrl_init_i2c_child(edev_child, &(i2c_childlist[i++]));
1069 } 1064 }
1070 if (!strcmp("adc", edev_child->prom_name)) { 1065 if (!strcmp("adc", edev_child->prom_node->name)) {
1071 i2c_childlist[i].i2ctype = I2C_ADC; 1066 i2c_childlist[i].i2ctype = I2C_ADC;
1072 envctrl_init_i2c_child(edev_child, &(i2c_childlist[i++])); 1067 envctrl_init_i2c_child(edev_child, &(i2c_childlist[i++]));
1073 } 1068 }
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index 2beb3dded087..5ae684c011f8 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -192,9 +192,11 @@ static int __init flash_init(void)
192 } 192 }
193 if (!sdev) { 193 if (!sdev) {
194#ifdef CONFIG_PCI 194#ifdef CONFIG_PCI
195 struct linux_prom_registers *ebus_regs;
196
195 for_each_ebus(ebus) { 197 for_each_ebus(ebus) {
196 for_each_ebusdev(edev, ebus) { 198 for_each_ebusdev(edev, ebus) {
197 if (!strcmp(edev->prom_name, "flashprom")) 199 if (!strcmp(edev->prom_node->name, "flashprom"))
198 goto ebus_done; 200 goto ebus_done;
199 } 201 }
200 } 202 }
@@ -202,23 +204,23 @@ static int __init flash_init(void)
202 if (!edev) 204 if (!edev)
203 return -ENODEV; 205 return -ENODEV;
204 206
205 len = prom_getproperty(edev->prom_node, "reg", (void *)regs, sizeof(regs)); 207 ebus_regs = of_get_property(edev->prom_node, "reg", &len);
206 if ((len % sizeof(regs[0])) != 0) { 208 if (!ebus_regs || (len % sizeof(regs[0])) != 0) {
207 printk("flash: Strange reg property size %d\n", len); 209 printk("flash: Strange reg property size %d\n", len);
208 return -ENODEV; 210 return -ENODEV;
209 } 211 }
210 212
211 nregs = len / sizeof(regs[0]); 213 nregs = len / sizeof(ebus_regs[0]);
212 214
213 flash.read_base = edev->resource[0].start; 215 flash.read_base = edev->resource[0].start;
214 flash.read_size = regs[0].reg_size; 216 flash.read_size = ebus_regs[0].reg_size;
215 217
216 if (nregs == 1) { 218 if (nregs == 1) {
217 flash.write_base = edev->resource[0].start; 219 flash.write_base = edev->resource[0].start;
218 flash.write_size = regs[0].reg_size; 220 flash.write_size = ebus_regs[0].reg_size;
219 } else if (nregs == 2) { 221 } else if (nregs == 2) {
220 flash.write_base = edev->resource[1].start; 222 flash.write_base = edev->resource[1].start;
221 flash.write_size = regs[1].reg_size; 223 flash.write_size = ebus_regs[1].reg_size;
222 } else { 224 } else {
223 printk("flash: Strange number of regs %d\n", nregs); 225 printk("flash: Strange number of regs %d\n", nregs);
224 return -ENODEV; 226 return -ENODEV;
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 239e108b8ed1..cf5b476b5496 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -243,8 +243,8 @@ static int openprom_sunos_ioctl(struct inode * inode, struct file * file,
243 ((int *) opp->oprom_array)[1]); 243 ((int *) opp->oprom_array)[1]);
244 244
245 pcp = pdev->sysdata; 245 pcp = pdev->sysdata;
246 if (pcp != NULL && pcp->prom_node != -1 && pcp->prom_node) { 246 if (pcp != NULL) {
247 node = pcp->prom_node; 247 node = pcp->prom_node->node;
248 data->current_node = node; 248 data->current_node = node;
249 *((int *)opp->oprom_array) = node; 249 *((int *)opp->oprom_array) = node;
250 opp->oprom_size = sizeof(int); 250 opp->oprom_size = sizeof(int);
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index 5d30a3ebfccd..387a6aa8c020 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -1,7 +1,6 @@
1/* $Id: sbus.c,v 1.100 2002/01/24 15:36:24 davem Exp $ 1/* sbus.c: SBus support routines.
2 * sbus.c: SBus support routines.
3 * 2 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 3 * Copyright (C) 1995, 2006 David S. Miller (davem@davemloft.net)
5 */ 4 */
6 5
7#include <linux/kernel.h> 6#include <linux/kernel.h>
@@ -14,237 +13,76 @@
14#include <asm/sbus.h> 13#include <asm/sbus.h>
15#include <asm/dma.h> 14#include <asm/dma.h>
16#include <asm/oplib.h> 15#include <asm/oplib.h>
16#include <asm/prom.h>
17#include <asm/of_device.h>
17#include <asm/bpp.h> 18#include <asm/bpp.h>
18#include <asm/irq.h> 19#include <asm/irq.h>
19 20
20struct sbus_bus *sbus_root = NULL; 21struct sbus_bus *sbus_root;
21 22
22static struct linux_prom_irqs irqs[PROMINTR_MAX] __initdata = { { 0 } }; 23static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
23#ifdef CONFIG_SPARC32
24static int interrupts[PROMINTR_MAX] __initdata = { 0 };
25#endif
26
27#ifdef CONFIG_PCI
28extern int pcic_present(void);
29#endif
30
31/* Perhaps when I figure out more about the iommu we'll put a
32 * device registration routine here that probe_sbus() calls to
33 * setup the iommu for each Sbus.
34 */
35
36/* We call this for each SBus device, and fill the structure based
37 * upon the prom device tree. We return the start of memory after
38 * the things we have allocated.
39 */
40
41/* #define DEBUG_FILL */
42
43static void __init fill_sbus_device(int prom_node, struct sbus_dev *sdev)
44{ 24{
45 unsigned long address, base; 25 unsigned long base;
26 void *pval;
46 int len; 27 int len;
47 28
48 sdev->prom_node = prom_node; 29 sdev->prom_node = dp->node;
49 prom_getstring(prom_node, "name", 30 strcpy(sdev->prom_name, dp->name);
50 sdev->prom_name, sizeof(sdev->prom_name));
51 address = prom_getint(prom_node, "address");
52 len = prom_getproperty(prom_node, "reg",
53 (char *) sdev->reg_addrs,
54 sizeof(sdev->reg_addrs));
55 if (len == -1) {
56 sdev->num_registers = 0;
57 goto no_regs;
58 }
59 31
60 if (len % sizeof(struct linux_prom_registers)) { 32 pval = of_get_property(dp, "reg", &len);
61 prom_printf("fill_sbus_device: proplen for regs of %s " 33 sdev->num_registers = 0;
62 " was %d, need multiple of %d\n", 34 if (pval) {
63 sdev->prom_name, len, 35 memcpy(sdev->reg_addrs, pval, len);
64 (int) sizeof(struct linux_prom_registers));
65 prom_halt();
66 }
67 if (len > (sizeof(struct linux_prom_registers) * PROMREG_MAX)) {
68 prom_printf("fill_sbus_device: Too many register properties "
69 "for device %s, len=%d\n",
70 sdev->prom_name, len);
71 prom_halt();
72 }
73 sdev->num_registers = len / sizeof(struct linux_prom_registers);
74 sdev->ranges_applied = 0;
75 36
76 base = (unsigned long) sdev->reg_addrs[0].phys_addr; 37 sdev->num_registers =
38 len / sizeof(struct linux_prom_registers);
77 39
78 /* Compute the slot number. */ 40 base = (unsigned long) sdev->reg_addrs[0].phys_addr;
79 if (base >= SUN_SBUS_BVADDR && sparc_cpu_model == sun4m) {
80 sdev->slot = sbus_dev_slot(base);
81 } else {
82 sdev->slot = sdev->reg_addrs[0].which_io;
83 }
84 41
85no_regs: 42 /* Compute the slot number. */
86 len = prom_getproperty(prom_node, "ranges", 43 if (base >= SUN_SBUS_BVADDR && sparc_cpu_model == sun4m)
87 (char *)sdev->device_ranges, 44 sdev->slot = sbus_dev_slot(base);
88 sizeof(sdev->device_ranges)); 45 else
89 if (len == -1) { 46 sdev->slot = sdev->reg_addrs[0].which_io;
90 sdev->num_device_ranges = 0;
91 goto no_ranges;
92 }
93 if (len % sizeof(struct linux_prom_ranges)) {
94 prom_printf("fill_sbus_device: proplen for ranges of %s "
95 " was %d, need multiple of %d\n",
96 sdev->prom_name, len,
97 (int) sizeof(struct linux_prom_ranges));
98 prom_halt();
99 }
100 if (len > (sizeof(struct linux_prom_ranges) * PROMREG_MAX)) {
101 prom_printf("fill_sbus_device: Too many range properties "
102 "for device %s, len=%d\n",
103 sdev->prom_name, len);
104 prom_halt();
105 } 47 }
106 sdev->num_device_ranges = 48
107 len / sizeof(struct linux_prom_ranges); 49 pval = of_get_property(dp, "ranges", &len);
108 50 sdev->num_device_ranges = 0;
109no_ranges: 51 if (pval) {
110 /* XXX Unfortunately, IRQ issues are very arch specific. 52 memcpy(sdev->device_ranges, pval, len);
111 * XXX Pull this crud out into an arch specific area 53 sdev->num_device_ranges =
112 * XXX at some point. -DaveM 54 len / sizeof(struct linux_prom_ranges);
113 */
114#ifdef CONFIG_SPARC64
115 len = prom_getproperty(prom_node, "interrupts",
116 (char *) irqs, sizeof(irqs));
117 if (len == -1 || len == 0) {
118 sdev->irqs[0] = 0;
119 sdev->num_irqs = 0;
120 } else {
121 unsigned int pri = irqs[0].pri;
122
123 sdev->num_irqs = 1;
124 if (pri < 0x20)
125 pri += sdev->slot * 8;
126
127 sdev->irqs[0] = sbus_build_irq(sdev->bus, pri);
128 } 55 }
129#endif /* CONFIG_SPARC64 */
130
131#ifdef CONFIG_SPARC32
132 len = prom_getproperty(prom_node, "intr",
133 (char *)irqs, sizeof(irqs));
134 if (len != -1) {
135 sdev->num_irqs = len / 8;
136 if (sdev->num_irqs == 0) {
137 sdev->irqs[0] = 0;
138 } else if (sparc_cpu_model == sun4d) {
139 extern unsigned int sun4d_build_irq(struct sbus_dev *sdev, int irq);
140
141 for (len = 0; len < sdev->num_irqs; len++)
142 sdev->irqs[len] = sun4d_build_irq(sdev, irqs[len].pri);
143 } else {
144 for (len = 0; len < sdev->num_irqs; len++)
145 sdev->irqs[len] = irqs[len].pri;
146 }
147 } else {
148 /* No "intr" node found-- check for "interrupts" node.
149 * This node contains SBus interrupt levels, not IPLs
150 * as in "intr", and no vector values. We convert
151 * SBus interrupt levels to PILs (platform specific).
152 */
153 len = prom_getproperty(prom_node, "interrupts",
154 (char *)interrupts, sizeof(interrupts));
155 if (len == -1) {
156 sdev->irqs[0] = 0;
157 sdev->num_irqs = 0;
158 } else {
159 sdev->num_irqs = len / sizeof(int);
160 for (len = 0; len < sdev->num_irqs; len++) {
161 sdev->irqs[len] = sbint_to_irq(sdev, interrupts[len]);
162 }
163 }
164 }
165#endif /* CONFIG_SPARC32 */
166}
167 56
168/* This routine gets called from whoever needs the sbus first, to scan 57 sbus_fill_device_irq(sdev);
169 * the SBus device tree. Currently it just prints out the devices
170 * found on the bus and builds trees of SBUS structs and attached
171 * devices.
172 */
173 58
174extern void iommu_init(int iommu_node, struct sbus_bus *sbus); 59 sdev->ofdev.node = dp;
175extern void iounit_init(int sbi_node, int iounit_node, struct sbus_bus *sbus); 60 if (sdev->parent)
176void sun4_init(void); 61 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
177#ifdef CONFIG_SUN_AUXIO 62 else
178extern void auxio_probe(void); 63 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
179#endif 64 sdev->ofdev.dev.bus = &sbus_bus_type;
180 65 strcpy(sdev->ofdev.dev.bus_id, dp->path_component_name);
181static void __init sbus_do_child_siblings(int start_node,
182 struct sbus_dev *child,
183 struct sbus_dev *parent,
184 struct sbus_bus *sbus)
185{
186 struct sbus_dev *this_dev = child;
187 int this_node = start_node;
188
189 /* Child already filled in, just need to traverse siblings. */
190 child->child = NULL;
191 child->parent = parent;
192 while((this_node = prom_getsibling(this_node)) != 0) {
193 this_dev->next = kmalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
194 this_dev = this_dev->next;
195 this_dev->next = NULL;
196 this_dev->parent = parent;
197
198 this_dev->bus = sbus;
199 fill_sbus_device(this_node, this_dev);
200
201 if(prom_getchild(this_node)) {
202 this_dev->child = kmalloc(sizeof(struct sbus_dev),
203 GFP_ATOMIC);
204 this_dev->child->bus = sbus;
205 this_dev->child->next = NULL;
206 fill_sbus_device(prom_getchild(this_node), this_dev->child);
207 sbus_do_child_siblings(prom_getchild(this_node),
208 this_dev->child, this_dev, sbus);
209 } else {
210 this_dev->child = NULL;
211 }
212 }
213}
214 66
215/* 67 if (of_device_register(&sdev->ofdev) != 0)
216 * XXX This functions appears to be a distorted version of 68 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
217 * prom_sbus_ranges_init(), with all sun4d stuff cut away. 69 sdev->ofdev.dev.bus_id);
218 * Ask DaveM what is going on here, how is sun4d supposed to work... XXX 70}
219 */
220/* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */
221 71
222static void __init sbus_bus_ranges_init(int parent_node, struct sbus_bus *sbus) 72static void __init sbus_bus_ranges_init(struct device_node *dp, struct sbus_bus *sbus)
223{ 73{
74 void *pval;
224 int len; 75 int len;
225 76
226 len = prom_getproperty(sbus->prom_node, "ranges", 77 pval = of_get_property(dp, "ranges", &len);
227 (char *) sbus->sbus_ranges, 78 sbus->num_sbus_ranges = 0;
228 sizeof(sbus->sbus_ranges)); 79 if (pval) {
229 if (len == -1 || len == 0) { 80 memcpy(sbus->sbus_ranges, pval, len);
230 sbus->num_sbus_ranges = 0; 81 sbus->num_sbus_ranges =
231 return; 82 len / sizeof(struct linux_prom_ranges);
232 } 83
233 sbus->num_sbus_ranges = len / sizeof(struct linux_prom_ranges); 84 sbus_arch_bus_ranges_init(dp->parent, sbus);
234#ifdef CONFIG_SPARC32
235 if (sparc_cpu_model == sun4d) {
236 struct linux_prom_ranges iounit_ranges[PROMREG_MAX];
237 int num_iounit_ranges;
238
239 len = prom_getproperty(parent_node, "ranges",
240 (char *) iounit_ranges,
241 sizeof (iounit_ranges));
242 if (len != -1) {
243 num_iounit_ranges = (len/sizeof(struct linux_prom_ranges));
244 prom_adjust_ranges (sbus->sbus_ranges, sbus->num_sbus_ranges, iounit_ranges, num_iounit_ranges);
245 }
246 } 85 }
247#endif
248} 86}
249 87
250static void __init __apply_ranges_to_regs(struct linux_prom_ranges *ranges, 88static void __init __apply_ranges_to_regs(struct linux_prom_ranges *ranges,
@@ -322,241 +160,127 @@ static void __init sbus_fixup_all_regs(struct sbus_dev *first_sdev)
322 } 160 }
323} 161}
324 162
325extern void register_proc_sparc_ioport(void); 163/* We preserve the "probe order" of these bus and device lists to give
326extern void firetruck_init(void); 164 * the same ordering as the old code.
165 */
166static void __init sbus_insert(struct sbus_bus *sbus, struct sbus_bus **root)
167{
168 while (*root)
169 root = &(*root)->next;
170 *root = sbus;
171 sbus->next = NULL;
172}
327 173
328#ifdef CONFIG_SUN4 174static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
329extern void sun4_dvma_init(void); 175{
330#endif 176 while (*root)
177 root = &(*root)->next;
178 *root = sdev;
179 sdev->next = NULL;
180}
331 181
332static int __init sbus_init(void) 182static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
333{ 183{
334 int nd, this_sbus, sbus_devs, topnd, iommund; 184 dp = dp->child;
335 unsigned int sbus_clock; 185 while (dp) {
336 struct sbus_bus *sbus; 186 struct sbus_dev *sdev;
337 struct sbus_dev *this_dev;
338 int num_sbus = 0; /* How many did we find? */
339 187
340#ifdef CONFIG_SPARC32 188 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
341 register_proc_sparc_ioport(); 189 if (sdev) {
342#endif 190 sdev_insert(sdev, &parent->child);
343 191
344#ifdef CONFIG_SUN4 192 sdev->bus = sbus;
345 sun4_dvma_init(); 193 sdev->parent = parent;
346 return 0; 194
347#endif 195 fill_sbus_device(dp, sdev);
348 196
349 topnd = prom_getchild(prom_root_node); 197 walk_children(dp, sdev, sbus);
350
351 /* Finding the first sbus is a special case... */
352 iommund = 0;
353 if(sparc_cpu_model == sun4u) {
354 nd = prom_searchsiblings(topnd, "sbus");
355 if(nd == 0) {
356#ifdef CONFIG_PCI
357 if (!pcic_present()) {
358 prom_printf("Neither SBUS nor PCI found.\n");
359 prom_halt();
360 } else {
361#ifdef CONFIG_SPARC64
362 firetruck_init();
363#endif
364 }
365 return 0;
366#else
367 prom_printf("YEEE, UltraSparc sbus not found\n");
368 prom_halt();
369#endif
370 }
371 } else if(sparc_cpu_model == sun4d) {
372 if((iommund = prom_searchsiblings(topnd, "io-unit")) == 0 ||
373 (nd = prom_getchild(iommund)) == 0 ||
374 (nd = prom_searchsiblings(nd, "sbi")) == 0) {
375 panic("sbi not found");
376 }
377 } else if((nd = prom_searchsiblings(topnd, "sbus")) == 0) {
378 if((iommund = prom_searchsiblings(topnd, "iommu")) == 0 ||
379 (nd = prom_getchild(iommund)) == 0 ||
380 (nd = prom_searchsiblings(nd, "sbus")) == 0) {
381#ifdef CONFIG_PCI
382 if (!pcic_present()) {
383 prom_printf("Neither SBUS nor PCI found.\n");
384 prom_halt();
385 }
386 return 0;
387#else
388 /* No reason to run further - the data access trap will occur. */
389 panic("sbus not found");
390#endif
391 } 198 }
199 dp = dp->sibling;
392 } 200 }
201}
393 202
394 /* Ok, we've found the first one, allocate first SBus struct 203static void __init build_one_sbus(struct device_node *dp, int num_sbus)
395 * and place in chain. 204{
396 */ 205 struct sbus_bus *sbus;
397 sbus = sbus_root = kmalloc(sizeof(struct sbus_bus), GFP_ATOMIC); 206 unsigned int sbus_clock;
398 sbus->next = NULL; 207 struct device_node *dev_dp;
399 sbus->prom_node = nd;
400 this_sbus = nd;
401 208
402 if(iommund && sparc_cpu_model != sun4u && sparc_cpu_model != sun4d) 209 sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
403 iommu_init(iommund, sbus); 210 if (!sbus)
211 return;
404 212
405 /* Loop until we find no more SBUS's */ 213 sbus_insert(sbus, &sbus_root);
406 while(this_sbus) { 214 sbus->prom_node = dp->node;
407#ifdef CONFIG_SPARC64
408 /* IOMMU hides inside SBUS/SYSIO prom node on Ultra. */
409 if(sparc_cpu_model == sun4u) {
410 extern void sbus_iommu_init(int prom_node, struct sbus_bus *sbus);
411 215
412 sbus_iommu_init(this_sbus, sbus); 216 sbus_setup_iommu(sbus, dp);
413 }
414#endif /* CONFIG_SPARC64 */
415
416#ifdef CONFIG_SPARC32
417 if (sparc_cpu_model == sun4d)
418 iounit_init(this_sbus, iommund, sbus);
419#endif /* CONFIG_SPARC32 */
420 printk("sbus%d: ", num_sbus);
421 sbus_clock = prom_getint(this_sbus, "clock-frequency");
422 if(sbus_clock == -1)
423 sbus_clock = (25*1000*1000);
424 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
425 (int) (((sbus_clock/1000)%1000 != 0) ?
426 (((sbus_clock/1000)%1000) + 1000) : 0));
427
428 prom_getstring(this_sbus, "name",
429 sbus->prom_name, sizeof(sbus->prom_name));
430 sbus->clock_freq = sbus_clock;
431#ifdef CONFIG_SPARC32
432 if (sparc_cpu_model == sun4d) {
433 sbus->devid = prom_getint(iommund, "device-id");
434 sbus->board = prom_getint(iommund, "board#");
435 }
436#endif
437
438 sbus_bus_ranges_init(iommund, sbus);
439
440 sbus_devs = prom_getchild(this_sbus);
441 if (!sbus_devs) {
442 sbus->devices = NULL;
443 goto next_bus;
444 }
445 217
446 sbus->devices = kmalloc(sizeof(struct sbus_dev), GFP_ATOMIC); 218 printk("sbus%d: ", num_sbus);
447
448 this_dev = sbus->devices;
449 this_dev->next = NULL;
450
451 this_dev->bus = sbus;
452 this_dev->parent = NULL;
453 fill_sbus_device(sbus_devs, this_dev);
454
455 /* Should we traverse for children? */
456 if(prom_getchild(sbus_devs)) {
457 /* Allocate device node */
458 this_dev->child = kmalloc(sizeof(struct sbus_dev),
459 GFP_ATOMIC);
460 /* Fill it */
461 this_dev->child->bus = sbus;
462 this_dev->child->next = NULL;
463 fill_sbus_device(prom_getchild(sbus_devs),
464 this_dev->child);
465 sbus_do_child_siblings(prom_getchild(sbus_devs),
466 this_dev->child,
467 this_dev,
468 sbus);
469 } else {
470 this_dev->child = NULL;
471 }
472 219
473 while((sbus_devs = prom_getsibling(sbus_devs)) != 0) { 220 sbus_clock = of_getintprop_default(dp, "clock-frequency",
474 /* Allocate device node */ 221 (25*1000*1000));
475 this_dev->next = kmalloc(sizeof(struct sbus_dev), 222 sbus->clock_freq = sbus_clock;
476 GFP_ATOMIC); 223
477 this_dev = this_dev->next; 224 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
478 this_dev->next = NULL; 225 (int) (((sbus_clock/1000)%1000 != 0) ?
479 226 (((sbus_clock/1000)%1000) + 1000) : 0));
480 /* Fill it */ 227
481 this_dev->bus = sbus; 228 strcpy(sbus->prom_name, dp->name);
482 this_dev->parent = NULL; 229
483 fill_sbus_device(sbus_devs, this_dev); 230 sbus_setup_arch_props(sbus, dp);
484 231
485 /* Is there a child node hanging off of us? */ 232 sbus_bus_ranges_init(dp, sbus);
486 if(prom_getchild(sbus_devs)) { 233
487 /* Get new device struct */ 234 sbus->ofdev.node = dp;
488 this_dev->child = kmalloc(sizeof(struct sbus_dev), 235 sbus->ofdev.dev.parent = NULL;
489 GFP_ATOMIC); 236 sbus->ofdev.dev.bus = &sbus_bus_type;
490 /* Fill it */ 237 strcpy(sbus->ofdev.dev.bus_id, dp->path_component_name);
491 this_dev->child->bus = sbus; 238
492 this_dev->child->next = NULL; 239 if (of_device_register(&sbus->ofdev) != 0)
493 fill_sbus_device(prom_getchild(sbus_devs), 240 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
494 this_dev->child); 241 sbus->ofdev.dev.bus_id);
495 sbus_do_child_siblings(prom_getchild(sbus_devs), 242
496 this_dev->child, 243 dev_dp = dp->child;
497 this_dev, 244 while (dev_dp) {
498 sbus); 245 struct sbus_dev *sdev;
499 } else { 246
500 this_dev->child = NULL; 247 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
501 } 248 if (sdev) {
249 sdev_insert(sdev, &sbus->devices);
250
251 sdev->bus = sbus;
252 sdev->parent = NULL;
253 fill_sbus_device(dev_dp, sdev);
254
255 walk_children(dev_dp, sdev, sbus);
502 } 256 }
257 dev_dp = dev_dp->sibling;
258 }
503 259
504 /* Walk all devices and apply parent ranges. */ 260 sbus_fixup_all_regs(sbus->devices);
505 sbus_fixup_all_regs(sbus->devices);
506 261
507 dvma_init(sbus); 262 dvma_init(sbus);
508 next_bus: 263}
264
265static int __init sbus_init(void)
266{
267 struct device_node *dp;
268 const char *sbus_name = "sbus";
269 int num_sbus = 0;
270
271 if (sbus_arch_preinit())
272 return 0;
273
274 if (sparc_cpu_model == sun4d)
275 sbus_name = "sbi";
276
277 for_each_node_by_name(dp, sbus_name) {
278 build_one_sbus(dp, num_sbus);
509 num_sbus++; 279 num_sbus++;
510 if(sparc_cpu_model == sun4u) {
511 this_sbus = prom_getsibling(this_sbus);
512 if(!this_sbus)
513 break;
514 this_sbus = prom_searchsiblings(this_sbus, "sbus");
515 } else if(sparc_cpu_model == sun4d) {
516 iommund = prom_getsibling(iommund);
517 if(!iommund)
518 break;
519 iommund = prom_searchsiblings(iommund, "io-unit");
520 if(!iommund)
521 break;
522 this_sbus = prom_searchsiblings(prom_getchild(iommund), "sbi");
523 } else {
524 this_sbus = prom_getsibling(this_sbus);
525 if(!this_sbus)
526 break;
527 this_sbus = prom_searchsiblings(this_sbus, "sbus");
528 }
529 if(this_sbus) {
530 sbus->next = kmalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
531 sbus = sbus->next;
532 sbus->next = NULL;
533 sbus->prom_node = this_sbus;
534 } else {
535 break;
536 }
537 } /* while(this_sbus) */
538 280
539 if (sparc_cpu_model == sun4d) {
540 extern void sun4d_init_sbi_irq(void);
541 sun4d_init_sbi_irq();
542 }
543
544#ifdef CONFIG_SPARC64
545 if (sparc_cpu_model == sun4u) {
546 firetruck_init();
547 } 281 }
548#endif 282
549#ifdef CONFIG_SUN_AUXIO 283 sbus_arch_postinit();
550 if (sparc_cpu_model == sun4u)
551 auxio_probe ();
552#endif
553#ifdef CONFIG_SPARC64
554 if (sparc_cpu_model == sun4u) {
555 extern void clock_probe(void);
556
557 clock_probe();
558 }
559#endif
560 284
561 return 0; 285 return 0;
562} 286}