blob: 136d3718a74a365d27156c70b4a9c7f7614646f2 [file] [log] [blame]
David S. Millerd979f172007-10-27 00:13:04 -07001/* central.c: Central FHC driver for Sunfire/Starfire/Wildfire.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Millerb69416b2008-08-31 20:56:15 -07003 * Copyright (C) 1997, 1999, 2008 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#include <linux/kernel.h>
7#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/init.h>
David S. Millerb69416b2008-08-31 20:56:15 -070011#include <linux/of_device.h>
12#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/fhc.h>
David S. Millerb69416b2008-08-31 20:56:15 -070015#include <asm/upa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
David S. Millerb69416b2008-08-31 20:56:15 -070017struct clock_board {
18 void __iomem *clock_freq_regs;
19 void __iomem *clock_regs;
20 void __iomem *clock_ver_reg;
21 int num_slots;
22 struct resource leds_resource;
23 struct platform_device leds_pdev;
24};
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
David S. Millerb69416b2008-08-31 20:56:15 -070026struct fhc {
27 void __iomem *pregs;
28 bool central;
29 bool jtag_master;
30 int board_num;
31 struct resource leds_resource;
32 struct platform_device leds_pdev;
33};
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
David S. Millerb69416b2008-08-31 20:56:15 -070035static int __devinit clock_board_calc_nslots(struct clock_board *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
David S. Millerb69416b2008-08-31 20:56:15 -070037 u8 reg = upa_readb(p->clock_regs + CLOCK_STAT1) & 0xc0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
David S. Millerb69416b2008-08-31 20:56:15 -070039 switch (reg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 case 0x40:
David S. Millerb69416b2008-08-31 20:56:15 -070041 return 16;
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 case 0xc0:
David S. Millerb69416b2008-08-31 20:56:15 -070044 return 8;
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 case 0x80:
David S. Millerb69416b2008-08-31 20:56:15 -070047 reg = 0;
48 if (p->clock_ver_reg)
49 reg = upa_readb(p->clock_ver_reg);
50 if (reg) {
51 if (reg & 0x80)
52 return 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 else
David S. Millerb69416b2008-08-31 20:56:15 -070054 return 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
David S. Millerb69416b2008-08-31 20:56:15 -070056 /* Fallthrough */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 default:
David S. Millerb69416b2008-08-31 20:56:15 -070058 return 4;
59 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Grant Likely4ebb24f2011-02-22 20:01:33 -070062static int __devinit clock_board_probe(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
David S. Millerb69416b2008-08-31 20:56:15 -070064 struct clock_board *p = kzalloc(sizeof(*p), GFP_KERNEL);
65 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
David S. Millerb69416b2008-08-31 20:56:15 -070067 if (!p) {
68 printk(KERN_ERR "clock_board: Cannot allocate struct clock_board\n");
69 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
71
David S. Millerb69416b2008-08-31 20:56:15 -070072 p->clock_freq_regs = of_ioremap(&op->resource[0], 0,
73 resource_size(&op->resource[0]),
74 "clock_board_freq");
75 if (!p->clock_freq_regs) {
76 printk(KERN_ERR "clock_board: Cannot map clock_freq_regs\n");
77 goto out_free;
David S. Millercecc4e92006-06-22 19:53:24 -070078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
David S. Millerb69416b2008-08-31 20:56:15 -070080 p->clock_regs = of_ioremap(&op->resource[1], 0,
81 resource_size(&op->resource[1]),
82 "clock_board_regs");
83 if (!p->clock_regs) {
84 printk(KERN_ERR "clock_board: Cannot map clock_regs\n");
85 goto out_unmap_clock_freq_regs;
86 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
David S. Millerb69416b2008-08-31 20:56:15 -070088 if (op->resource[2].flags) {
89 p->clock_ver_reg = of_ioremap(&op->resource[2], 0,
90 resource_size(&op->resource[2]),
91 "clock_ver_reg");
92 if (!p->clock_ver_reg) {
93 printk(KERN_ERR "clock_board: Cannot map clock_ver_reg\n");
94 goto out_unmap_clock_regs;
95 }
96 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
David S. Millerb69416b2008-08-31 20:56:15 -070098 p->num_slots = clock_board_calc_nslots(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
David S. Millerb69416b2008-08-31 20:56:15 -0700100 p->leds_resource.start = (unsigned long)
101 (p->clock_regs + CLOCK_CTRL);
Roel Kluin09317142010-01-15 01:27:49 -0800102 p->leds_resource.end = p->leds_resource.start;
David S. Millerb69416b2008-08-31 20:56:15 -0700103 p->leds_resource.name = "leds";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David S. Millerb69416b2008-08-31 20:56:15 -0700105 p->leds_pdev.name = "sunfire-clockboard-leds";
David S. Millerb7c18c12009-01-18 22:42:15 -0800106 p->leds_pdev.id = -1;
David S. Millerb69416b2008-08-31 20:56:15 -0700107 p->leds_pdev.resource = &p->leds_resource;
108 p->leds_pdev.num_resources = 1;
109 p->leds_pdev.dev.parent = &op->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David S. Millerb69416b2008-08-31 20:56:15 -0700111 err = platform_device_register(&p->leds_pdev);
112 if (err) {
113 printk(KERN_ERR "clock_board: Could not register LEDS "
114 "platform device\n");
115 goto out_unmap_clock_ver_reg;
116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
David S. Millerb69416b2008-08-31 20:56:15 -0700118 printk(KERN_INFO "clock_board: Detected %d slot Enterprise system.\n",
119 p->num_slots);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
David S. Millerb69416b2008-08-31 20:56:15 -0700121 err = 0;
122out:
123 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
David S. Millerb69416b2008-08-31 20:56:15 -0700125out_unmap_clock_ver_reg:
126 if (p->clock_ver_reg)
127 of_iounmap(&op->resource[2], p->clock_ver_reg,
128 resource_size(&op->resource[2]));
129
130out_unmap_clock_regs:
131 of_iounmap(&op->resource[1], p->clock_regs,
132 resource_size(&op->resource[1]));
133
134out_unmap_clock_freq_regs:
135 of_iounmap(&op->resource[0], p->clock_freq_regs,
136 resource_size(&op->resource[0]));
137
138out_free:
139 kfree(p);
140 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
David S. Millerb69416b2008-08-31 20:56:15 -0700143static struct of_device_id __initdata clock_board_match[] = {
144 {
145 .name = "clock-board",
146 },
147 {},
148};
149
Grant Likely4ebb24f2011-02-22 20:01:33 -0700150static struct platform_driver clock_board_driver = {
David S. Millerb69416b2008-08-31 20:56:15 -0700151 .probe = clock_board_probe,
Grant Likely40182942010-04-13 16:13:02 -0700152 .driver = {
153 .name = "clock_board",
154 .owner = THIS_MODULE,
155 .of_match_table = clock_board_match,
David S. Millerb69416b2008-08-31 20:56:15 -0700156 },
157};
158
Grant Likely4ebb24f2011-02-22 20:01:33 -0700159static int __devinit fhc_probe(struct platform_device *op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
David S. Millerb69416b2008-08-31 20:56:15 -0700161 struct fhc *p = kzalloc(sizeof(*p), GFP_KERNEL);
162 int err = -ENOMEM;
163 u32 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
David S. Millerb69416b2008-08-31 20:56:15 -0700165 if (!p) {
166 printk(KERN_ERR "fhc: Cannot allocate struct fhc\n");
167 goto out;
168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Grant Likely61c7a082010-04-13 16:12:29 -0700170 if (!strcmp(op->dev.of_node->parent->name, "central"))
David S. Millerb69416b2008-08-31 20:56:15 -0700171 p->central = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
David S. Millerb69416b2008-08-31 20:56:15 -0700173 p->pregs = of_ioremap(&op->resource[0], 0,
174 resource_size(&op->resource[0]),
175 "fhc_pregs");
176 if (!p->pregs) {
177 printk(KERN_ERR "fhc: Cannot map pregs\n");
178 goto out_free;
179 }
180
181 if (p->central) {
182 reg = upa_readl(p->pregs + FHC_PREGS_BSR);
183 p->board_num = ((reg >> 16) & 1) | ((reg >> 12) & 0x0e);
184 } else {
Grant Likely61c7a082010-04-13 16:12:29 -0700185 p->board_num = of_getintprop_default(op->dev.of_node, "board#", -1);
David S. Millerb69416b2008-08-31 20:56:15 -0700186 if (p->board_num == -1) {
187 printk(KERN_ERR "fhc: No board# property\n");
188 goto out_unmap_pregs;
189 }
190 if (upa_readl(p->pregs + FHC_PREGS_JCTRL) & FHC_JTAG_CTRL_MENAB)
191 p->jtag_master = true;
192 }
193
194 if (!p->central) {
195 p->leds_resource.start = (unsigned long)
196 (p->pregs + FHC_PREGS_CTRL);
Roel Kluin09317142010-01-15 01:27:49 -0800197 p->leds_resource.end = p->leds_resource.start;
David S. Millerb69416b2008-08-31 20:56:15 -0700198 p->leds_resource.name = "leds";
199
200 p->leds_pdev.name = "sunfire-fhc-leds";
David S. Millerb7c18c12009-01-18 22:42:15 -0800201 p->leds_pdev.id = p->board_num;
David S. Millerb69416b2008-08-31 20:56:15 -0700202 p->leds_pdev.resource = &p->leds_resource;
203 p->leds_pdev.num_resources = 1;
204 p->leds_pdev.dev.parent = &op->dev;
205
206 err = platform_device_register(&p->leds_pdev);
207 if (err) {
208 printk(KERN_ERR "fhc: Could not register LEDS "
209 "platform device\n");
210 goto out_unmap_pregs;
211 }
212 }
213 reg = upa_readl(p->pregs + FHC_PREGS_CTRL);
214
215 if (!p->central)
216 reg |= FHC_CONTROL_IXIST;
217
218 reg &= ~(FHC_CONTROL_AOFF |
219 FHC_CONTROL_BOFF |
220 FHC_CONTROL_SLINE);
221
222 upa_writel(reg, p->pregs + FHC_PREGS_CTRL);
223 upa_readl(p->pregs + FHC_PREGS_CTRL);
224
225 reg = upa_readl(p->pregs + FHC_PREGS_ID);
226 printk(KERN_INFO "fhc: Board #%d, Version[%x] PartID[%x] Manuf[%x] %s\n",
227 p->board_num,
228 (reg & FHC_ID_VERS) >> 28,
229 (reg & FHC_ID_PARTID) >> 12,
230 (reg & FHC_ID_MANUF) >> 1,
231 (p->jtag_master ?
232 "(JTAG Master)" :
233 (p->central ? "(Central)" : "")));
234
235 err = 0;
236
237out:
238 return err;
239
240out_unmap_pregs:
241 of_iounmap(&op->resource[0], p->pregs, resource_size(&op->resource[0]));
242
243out_free:
244 kfree(p);
245 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
David S. Millerb69416b2008-08-31 20:56:15 -0700248static struct of_device_id __initdata fhc_match[] = {
249 {
250 .name = "fhc",
251 },
252 {},
253};
254
Grant Likely4ebb24f2011-02-22 20:01:33 -0700255static struct platform_driver fhc_driver = {
David S. Millerb69416b2008-08-31 20:56:15 -0700256 .probe = fhc_probe,
Grant Likely40182942010-04-13 16:13:02 -0700257 .driver = {
258 .name = "fhc",
259 .owner = THIS_MODULE,
260 .of_match_table = fhc_match,
David S. Millerb69416b2008-08-31 20:56:15 -0700261 },
262};
263
264static int __init sunfire_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Grant Likely4ebb24f2011-02-22 20:01:33 -0700266 (void) platform_driver_register(&fhc_driver);
267 (void) platform_driver_register(&clock_board_driver);
David S. Millerb69416b2008-08-31 20:56:15 -0700268 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
David S. Millerb69416b2008-08-31 20:56:15 -0700271subsys_initcall(sunfire_init);