1 /* central.c: Central FHC driver for Sunfire/Starfire/Wildfire.
3 * Copyright (C) 1997, 1999, 2008 David S. Miller (davem@davemloft.net)
6 #include <linux/kernel.h>
7 #include <linux/types.h>
8 #include <linux/slab.h>
9 #include <linux/string.h>
10 #include <linux/init.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
18 void __iomem
*clock_freq_regs
;
19 void __iomem
*clock_regs
;
20 void __iomem
*clock_ver_reg
;
22 struct resource leds_resource
;
23 struct platform_device leds_pdev
;
31 struct resource leds_resource
;
32 struct platform_device leds_pdev
;
35 static int __devinit
clock_board_calc_nslots(struct clock_board
*p
)
37 u8 reg
= upa_readb(p
->clock_regs
+ CLOCK_STAT1
) & 0xc0;
49 reg
= upa_readb(p
->clock_ver_reg
);
62 static int __devinit
clock_board_probe(struct of_device
*op
,
63 const struct of_device_id
*match
)
65 struct clock_board
*p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
69 printk(KERN_ERR
"clock_board: Cannot allocate struct clock_board\n");
73 p
->clock_freq_regs
= of_ioremap(&op
->resource
[0], 0,
74 resource_size(&op
->resource
[0]),
76 if (!p
->clock_freq_regs
) {
77 printk(KERN_ERR
"clock_board: Cannot map clock_freq_regs\n");
81 p
->clock_regs
= of_ioremap(&op
->resource
[1], 0,
82 resource_size(&op
->resource
[1]),
85 printk(KERN_ERR
"clock_board: Cannot map clock_regs\n");
86 goto out_unmap_clock_freq_regs
;
89 if (op
->resource
[2].flags
) {
90 p
->clock_ver_reg
= of_ioremap(&op
->resource
[2], 0,
91 resource_size(&op
->resource
[2]),
93 if (!p
->clock_ver_reg
) {
94 printk(KERN_ERR
"clock_board: Cannot map clock_ver_reg\n");
95 goto out_unmap_clock_regs
;
99 p
->num_slots
= clock_board_calc_nslots(p
);
101 p
->leds_resource
.start
= (unsigned long)
102 (p
->clock_regs
+ CLOCK_CTRL
);
103 p
->leds_resource
.end
= p
->leds_resource
.start
;
104 p
->leds_resource
.name
= "leds";
106 p
->leds_pdev
.name
= "sunfire-clockboard-leds";
107 p
->leds_pdev
.id
= -1;
108 p
->leds_pdev
.resource
= &p
->leds_resource
;
109 p
->leds_pdev
.num_resources
= 1;
110 p
->leds_pdev
.dev
.parent
= &op
->dev
;
112 err
= platform_device_register(&p
->leds_pdev
);
114 printk(KERN_ERR
"clock_board: Could not register LEDS "
115 "platform device\n");
116 goto out_unmap_clock_ver_reg
;
119 printk(KERN_INFO
"clock_board: Detected %d slot Enterprise system.\n",
126 out_unmap_clock_ver_reg
:
127 if (p
->clock_ver_reg
)
128 of_iounmap(&op
->resource
[2], p
->clock_ver_reg
,
129 resource_size(&op
->resource
[2]));
131 out_unmap_clock_regs
:
132 of_iounmap(&op
->resource
[1], p
->clock_regs
,
133 resource_size(&op
->resource
[1]));
135 out_unmap_clock_freq_regs
:
136 of_iounmap(&op
->resource
[0], p
->clock_freq_regs
,
137 resource_size(&op
->resource
[0]));
144 static struct of_device_id __initdata clock_board_match
[] = {
146 .name
= "clock-board",
151 static struct of_platform_driver clock_board_driver
= {
152 .probe
= clock_board_probe
,
154 .name
= "clock_board",
155 .owner
= THIS_MODULE
,
156 .of_match_table
= clock_board_match
,
160 static int __devinit
fhc_probe(struct of_device
*op
,
161 const struct of_device_id
*match
)
163 struct fhc
*p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
168 printk(KERN_ERR
"fhc: Cannot allocate struct fhc\n");
172 if (!strcmp(op
->dev
.of_node
->parent
->name
, "central"))
175 p
->pregs
= of_ioremap(&op
->resource
[0], 0,
176 resource_size(&op
->resource
[0]),
179 printk(KERN_ERR
"fhc: Cannot map pregs\n");
184 reg
= upa_readl(p
->pregs
+ FHC_PREGS_BSR
);
185 p
->board_num
= ((reg
>> 16) & 1) | ((reg
>> 12) & 0x0e);
187 p
->board_num
= of_getintprop_default(op
->dev
.of_node
, "board#", -1);
188 if (p
->board_num
== -1) {
189 printk(KERN_ERR
"fhc: No board# property\n");
190 goto out_unmap_pregs
;
192 if (upa_readl(p
->pregs
+ FHC_PREGS_JCTRL
) & FHC_JTAG_CTRL_MENAB
)
193 p
->jtag_master
= true;
197 p
->leds_resource
.start
= (unsigned long)
198 (p
->pregs
+ FHC_PREGS_CTRL
);
199 p
->leds_resource
.end
= p
->leds_resource
.start
;
200 p
->leds_resource
.name
= "leds";
202 p
->leds_pdev
.name
= "sunfire-fhc-leds";
203 p
->leds_pdev
.id
= p
->board_num
;
204 p
->leds_pdev
.resource
= &p
->leds_resource
;
205 p
->leds_pdev
.num_resources
= 1;
206 p
->leds_pdev
.dev
.parent
= &op
->dev
;
208 err
= platform_device_register(&p
->leds_pdev
);
210 printk(KERN_ERR
"fhc: Could not register LEDS "
211 "platform device\n");
212 goto out_unmap_pregs
;
215 reg
= upa_readl(p
->pregs
+ FHC_PREGS_CTRL
);
218 reg
|= FHC_CONTROL_IXIST
;
220 reg
&= ~(FHC_CONTROL_AOFF
|
224 upa_writel(reg
, p
->pregs
+ FHC_PREGS_CTRL
);
225 upa_readl(p
->pregs
+ FHC_PREGS_CTRL
);
227 reg
= upa_readl(p
->pregs
+ FHC_PREGS_ID
);
228 printk(KERN_INFO
"fhc: Board #%d, Version[%x] PartID[%x] Manuf[%x] %s\n",
230 (reg
& FHC_ID_VERS
) >> 28,
231 (reg
& FHC_ID_PARTID
) >> 12,
232 (reg
& FHC_ID_MANUF
) >> 1,
235 (p
->central
? "(Central)" : "")));
243 of_iounmap(&op
->resource
[0], p
->pregs
, resource_size(&op
->resource
[0]));
250 static struct of_device_id __initdata fhc_match
[] = {
257 static struct of_platform_driver fhc_driver
= {
261 .owner
= THIS_MODULE
,
262 .of_match_table
= fhc_match
,
266 static int __init
sunfire_init(void)
268 (void) of_register_driver(&fhc_driver
, &of_platform_bus_type
);
269 (void) of_register_driver(&clock_board_driver
, &of_platform_bus_type
);
273 subsys_initcall(sunfire_init
);