This source file includes following definitions.
- find_locked_reg
- dscr_write_locked1
- dscr_write_locked2
- dscr_write
- dscr_set_devstate
- dscr_rmii_reset
- dscr_parse_devstat
- dscr_parse_silicon_rev
- dscr_parse_mac_fuse
- dscr_parse_rmii_resets
- dscr_parse_privperm
- dscr_parse_locked_regs
- dscr_parse_kick_regs
- dscr_parse_devstate_ctl_regs
- dscr_parse_devstate_stat_regs
- dscr_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <linux/of.h>
27 #include <linux/of_address.h>
28 #include <linux/of_platform.h>
29 #include <linux/module.h>
30 #include <linux/io.h>
31 #include <linux/delay.h>
32 #include <asm/soc.h>
33 #include <asm/dscr.h>
34
35 #define MAX_DEVSTATE_IDS 32
36 #define MAX_DEVCTL_REGS 8
37 #define MAX_DEVSTAT_REGS 8
38 #define MAX_LOCKED_REGS 4
39 #define MAX_SOC_EMACS 2
40
41 struct rmii_reset_reg {
42 u32 reg;
43 u32 mask;
44 };
45
46
47
48
49
50 struct locked_reg {
51 u32 reg;
52 u32 lockreg;
53 u32 key;
54 };
55
56
57
58
59
60
61
62
63 struct devstate_ctl_reg {
64 u32 reg;
65 u8 start_id;
66 u8 num_ids;
67 u8 enable_only;
68 u8 enable;
69 u8 disable;
70 u8 shift;
71 u8 nbits;
72 };
73
74
75
76
77
78
79
80
81
82 struct devstate_stat_reg {
83 u32 reg;
84 u8 start_id;
85 u8 num_ids;
86 u8 enable;
87 u8 disable;
88 u8 shift;
89 u8 nbits;
90 };
91
92 struct devstate_info {
93 struct devstate_ctl_reg *ctl;
94 struct devstate_stat_reg *stat;
95 };
96
97
98 struct dscr_ops {
99 void (*init)(struct device_node *node);
100 };
101
102 struct dscr_regs {
103 spinlock_t lock;
104 void __iomem *base;
105 u32 kick_reg[2];
106 u32 kick_key[2];
107 struct locked_reg locked[MAX_LOCKED_REGS];
108 struct devstate_info devstate_info[MAX_DEVSTATE_IDS];
109 struct rmii_reset_reg rmii_resets[MAX_SOC_EMACS];
110 struct devstate_ctl_reg devctl[MAX_DEVCTL_REGS];
111 struct devstate_stat_reg devstat[MAX_DEVSTAT_REGS];
112 };
113
114 static struct dscr_regs dscr;
115
116 static struct locked_reg *find_locked_reg(u32 reg)
117 {
118 int i;
119
120 for (i = 0; i < MAX_LOCKED_REGS; i++)
121 if (dscr.locked[i].key && reg == dscr.locked[i].reg)
122 return &dscr.locked[i];
123 return NULL;
124 }
125
126
127
128
129 static void dscr_write_locked1(u32 reg, u32 val,
130 u32 lock, u32 key)
131 {
132 void __iomem *reg_addr = dscr.base + reg;
133 void __iomem *lock_addr = dscr.base + lock;
134
135
136
137
138
139
140
141 asm volatile ("b .s2 0f\n"
142 "nop 5\n"
143 " .align 5\n"
144 "0:\n"
145 "stw .D1T2 %3,*%2\n"
146 "stw .D1T2 %1,*%0\n"
147 :
148 : "a"(reg_addr), "b"(val), "a"(lock_addr), "b"(key)
149 );
150
151
152 soc_writel(0, lock_addr);
153 }
154
155
156
157
158 static void dscr_write_locked2(u32 reg, u32 val,
159 u32 lock0, u32 key0,
160 u32 lock1, u32 key1)
161 {
162 soc_writel(key0, dscr.base + lock0);
163 soc_writel(key1, dscr.base + lock1);
164 soc_writel(val, dscr.base + reg);
165 soc_writel(0, dscr.base + lock0);
166 soc_writel(0, dscr.base + lock1);
167 }
168
169 static void dscr_write(u32 reg, u32 val)
170 {
171 struct locked_reg *lock;
172
173 lock = find_locked_reg(reg);
174 if (lock)
175 dscr_write_locked1(reg, val, lock->lockreg, lock->key);
176 else if (dscr.kick_key[0])
177 dscr_write_locked2(reg, val, dscr.kick_reg[0], dscr.kick_key[0],
178 dscr.kick_reg[1], dscr.kick_key[1]);
179 else
180 soc_writel(val, dscr.base + reg);
181 }
182
183
184
185
186
187 void dscr_set_devstate(int id, enum dscr_devstate_t state)
188 {
189 struct devstate_ctl_reg *ctl;
190 struct devstate_stat_reg *stat;
191 struct devstate_info *info;
192 u32 ctl_val, val;
193 int ctl_shift, ctl_mask;
194 unsigned long flags;
195
196 if (!dscr.base)
197 return;
198
199 if (id < 0 || id >= MAX_DEVSTATE_IDS)
200 return;
201
202 info = &dscr.devstate_info[id];
203 ctl = info->ctl;
204 stat = info->stat;
205
206 if (ctl == NULL)
207 return;
208
209 ctl_shift = ctl->shift + ctl->nbits * (id - ctl->start_id);
210 ctl_mask = ((1 << ctl->nbits) - 1) << ctl_shift;
211
212 switch (state) {
213 case DSCR_DEVSTATE_ENABLED:
214 ctl_val = ctl->enable << ctl_shift;
215 break;
216 case DSCR_DEVSTATE_DISABLED:
217 if (ctl->enable_only)
218 return;
219 ctl_val = ctl->disable << ctl_shift;
220 break;
221 default:
222 return;
223 }
224
225 spin_lock_irqsave(&dscr.lock, flags);
226
227 val = soc_readl(dscr.base + ctl->reg);
228 val &= ~ctl_mask;
229 val |= ctl_val;
230
231 dscr_write(ctl->reg, val);
232
233 spin_unlock_irqrestore(&dscr.lock, flags);
234
235 if (!stat)
236 return;
237
238 ctl_shift = stat->shift + stat->nbits * (id - stat->start_id);
239
240 if (state == DSCR_DEVSTATE_ENABLED)
241 ctl_val = stat->enable;
242 else
243 ctl_val = stat->disable;
244
245 do {
246 val = soc_readl(dscr.base + stat->reg);
247 val >>= ctl_shift;
248 val &= ((1 << stat->nbits) - 1);
249 } while (val != ctl_val);
250 }
251 EXPORT_SYMBOL(dscr_set_devstate);
252
253
254
255
256 void dscr_rmii_reset(int id, int assert)
257 {
258 struct rmii_reset_reg *r;
259 unsigned long flags;
260 u32 val;
261
262 if (id < 0 || id >= MAX_SOC_EMACS)
263 return;
264
265 r = &dscr.rmii_resets[id];
266 if (r->mask == 0)
267 return;
268
269 spin_lock_irqsave(&dscr.lock, flags);
270
271 val = soc_readl(dscr.base + r->reg);
272 if (assert)
273 dscr_write(r->reg, val | r->mask);
274 else
275 dscr_write(r->reg, val & ~(r->mask));
276
277 spin_unlock_irqrestore(&dscr.lock, flags);
278 }
279 EXPORT_SYMBOL(dscr_rmii_reset);
280
281 static void __init dscr_parse_devstat(struct device_node *node,
282 void __iomem *base)
283 {
284 u32 val;
285 int err;
286
287 err = of_property_read_u32_array(node, "ti,dscr-devstat", &val, 1);
288 if (!err)
289 c6x_devstat = soc_readl(base + val);
290 printk(KERN_INFO "DEVSTAT: %08x\n", c6x_devstat);
291 }
292
293 static void __init dscr_parse_silicon_rev(struct device_node *node,
294 void __iomem *base)
295 {
296 u32 vals[3];
297 int err;
298
299 err = of_property_read_u32_array(node, "ti,dscr-silicon-rev", vals, 3);
300 if (!err) {
301 c6x_silicon_rev = soc_readl(base + vals[0]);
302 c6x_silicon_rev >>= vals[1];
303 c6x_silicon_rev &= vals[2];
304 }
305 }
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324 static void __init dscr_parse_mac_fuse(struct device_node *node,
325 void __iomem *base)
326 {
327 u32 vals[10], fuse;
328 int f, i, j, err;
329
330 err = of_property_read_u32_array(node, "ti,dscr-mac-fuse-regs",
331 vals, 10);
332 if (err)
333 return;
334
335 for (f = 0; f < 2; f++) {
336 fuse = soc_readl(base + vals[f * 5]);
337 for (j = (f * 5) + 1, i = 24; i >= 0; i -= 8, j++)
338 if (vals[j] && vals[j] <= 6)
339 c6x_fuse_mac[vals[j] - 1] = fuse >> i;
340 }
341 }
342
343 static void __init dscr_parse_rmii_resets(struct device_node *node,
344 void __iomem *base)
345 {
346 const __be32 *p;
347 int i, size;
348
349
350 p = of_get_property(node, "ti,dscr-rmii-resets", &size);
351 if (p) {
352
353 size /= (sizeof(*p) * 2);
354 if (size > MAX_SOC_EMACS)
355 size = MAX_SOC_EMACS;
356
357 for (i = 0; i < size; i++) {
358 dscr.rmii_resets[i].reg = be32_to_cpup(p++);
359 dscr.rmii_resets[i].mask = be32_to_cpup(p++);
360 }
361 }
362 }
363
364
365 static void __init dscr_parse_privperm(struct device_node *node,
366 void __iomem *base)
367 {
368 u32 vals[2];
369 int err;
370
371 err = of_property_read_u32_array(node, "ti,dscr-privperm", vals, 2);
372 if (err)
373 return;
374 dscr_write(vals[0], vals[1]);
375 }
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393 static void __init dscr_parse_locked_regs(struct device_node *node,
394 void __iomem *base)
395 {
396 struct locked_reg *r;
397 const __be32 *p;
398 int i, size;
399
400 p = of_get_property(node, "ti,dscr-locked-regs", &size);
401 if (p) {
402
403 size /= (sizeof(*p) * 3);
404 if (size > MAX_LOCKED_REGS)
405 size = MAX_LOCKED_REGS;
406
407 for (i = 0; i < size; i++) {
408 r = &dscr.locked[i];
409
410 r->reg = be32_to_cpup(p++);
411 r->lockreg = be32_to_cpup(p++);
412 r->key = be32_to_cpup(p++);
413 }
414 }
415 }
416
417
418
419
420
421
422
423
424
425
426
427
428 static void __init dscr_parse_kick_regs(struct device_node *node,
429 void __iomem *base)
430 {
431 u32 vals[4];
432 int err;
433
434 err = of_property_read_u32_array(node, "ti,dscr-kick-regs", vals, 4);
435 if (!err) {
436 dscr.kick_reg[0] = vals[0];
437 dscr.kick_key[0] = vals[1];
438 dscr.kick_reg[1] = vals[2];
439 dscr.kick_key[1] = vals[3];
440 }
441 }
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466 static void __init dscr_parse_devstate_ctl_regs(struct device_node *node,
467 void __iomem *base)
468 {
469 struct devstate_ctl_reg *r;
470 const __be32 *p;
471 int i, j, size;
472
473 p = of_get_property(node, "ti,dscr-devstate-ctl-regs", &size);
474 if (p) {
475
476 size /= (sizeof(*p) * 7);
477 if (size > MAX_DEVCTL_REGS)
478 size = MAX_DEVCTL_REGS;
479
480 for (i = 0; i < size; i++) {
481 r = &dscr.devctl[i];
482
483 r->start_id = be32_to_cpup(p++);
484 r->num_ids = be32_to_cpup(p++);
485 r->reg = be32_to_cpup(p++);
486 r->enable = be32_to_cpup(p++);
487 r->disable = be32_to_cpup(p++);
488 if (r->disable == 0xffffffff)
489 r->enable_only = 1;
490 r->shift = be32_to_cpup(p++);
491 r->nbits = be32_to_cpup(p++);
492
493 for (j = r->start_id;
494 j < (r->start_id + r->num_ids);
495 j++)
496 dscr.devstate_info[j].ctl = r;
497 }
498 }
499 }
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522 static void __init dscr_parse_devstate_stat_regs(struct device_node *node,
523 void __iomem *base)
524 {
525 struct devstate_stat_reg *r;
526 const __be32 *p;
527 int i, j, size;
528
529 p = of_get_property(node, "ti,dscr-devstate-stat-regs", &size);
530 if (p) {
531
532 size /= (sizeof(*p) * 7);
533 if (size > MAX_DEVSTAT_REGS)
534 size = MAX_DEVSTAT_REGS;
535
536 for (i = 0; i < size; i++) {
537 r = &dscr.devstat[i];
538
539 r->start_id = be32_to_cpup(p++);
540 r->num_ids = be32_to_cpup(p++);
541 r->reg = be32_to_cpup(p++);
542 r->enable = be32_to_cpup(p++);
543 r->disable = be32_to_cpup(p++);
544 r->shift = be32_to_cpup(p++);
545 r->nbits = be32_to_cpup(p++);
546
547 for (j = r->start_id;
548 j < (r->start_id + r->num_ids);
549 j++)
550 dscr.devstate_info[j].stat = r;
551 }
552 }
553 }
554
555 static struct of_device_id dscr_ids[] __initdata = {
556 { .compatible = "ti,c64x+dscr" },
557 {}
558 };
559
560
561
562
563
564
565
566
567 void __init dscr_probe(void)
568 {
569 struct device_node *node;
570 void __iomem *base;
571
572 spin_lock_init(&dscr.lock);
573
574 node = of_find_matching_node(NULL, dscr_ids);
575 if (!node)
576 return;
577
578 base = of_iomap(node, 0);
579 if (!base) {
580 of_node_put(node);
581 return;
582 }
583
584 dscr.base = base;
585
586 dscr_parse_devstat(node, base);
587 dscr_parse_silicon_rev(node, base);
588 dscr_parse_mac_fuse(node, base);
589 dscr_parse_rmii_resets(node, base);
590 dscr_parse_locked_regs(node, base);
591 dscr_parse_kick_regs(node, base);
592 dscr_parse_devstate_ctl_regs(node, base);
593 dscr_parse_devstate_stat_regs(node, base);
594 dscr_parse_privperm(node, base);
595 }