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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Freescale QorIQ Platforms GUTS Driver
*
* Copyright (C) 2016 Freescale Semiconductor, Inc.
*/
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/of_fdt.h>
#include <linux/sys_soc.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/fsl/guts.h>
#define DCFG_CCSR 0
#define DCFG_DCSR 1
#define RCW_TIMEOUT_US 1
#define LS1046A_RCWSR5_SRDS_PRTCL_S1(lane) \
GENMASK(19 + 4 * (lane), 16 + 4 * (lane))
#define LS1046A_SRDS_PRTCL_XFI 1
#define LS1046A_SRDS_PRTCL_100BASEX_SGMII 3
#define LS1088A_RCWSR29_SRDS_PRTCL_S1_LNn(lane) \
GENMASK(19 + 4 * (3 - (lane)), 16 + 4 * (3 - (lane)))
#define LS1088A_RCWSR30_SRDS_PRTCL_S2_LNn(lane) \
GENMASK(3 + 4 * (3 - (lane)), 4 * (3 - (lane)))
#define LS1088A_SRDS_PRTCL_XFI 1
#define LS1088A_SRDS_PRTCL_100BASEX_SGMII 3
#define LS2088A_RCWSR29_SRDS_PRTCL_S1 GENMASK(23, 16)
#define LS2088A_RCWSR30_SRDS_CLK_EN_SEL_XGMII_S1 BIT(14)
#define LS2088A_RCWSR30_SRDS_CLK_SEL_XGMII_Ln_S1(lane) BIT(6 + (7 - (lane)))
#define LS2088A_RCWSR30_SRDS_CLK_SEL_MSK GENMASK(13, 6)
#define LS2088A_SRDS_CLK_SEL_XGMII 1
#define LS2088A_SRDS_CLK_SEL_GMII 0
struct fsl_soc_die_attr {
char *die;
u32 svr;
u32 mask;
};
struct fsl_soc_serdes_rcw_override {
int offset;
int mask;
int val;
};
struct fsl_soc_data {
const char *sfp_compat;
u32 uid_offset;
int num_serdes_blocks;
int num_serdes_lanes;
int (*serdes_init_rcwcr)(int index);
int (*serdes_get_rcw_override)(int index, int lane,
enum lynx_lane_mode lane_mode,
struct fsl_soc_serdes_rcw_override *override);
};
enum qoriq_die {
DIE_T4240,
DIE_T1040,
DIE_T2080,
DIE_T1024,
DIE_LS1043A,
DIE_LS2080A,
DIE_LS1088A,
DIE_LS1012A,
DIE_LS1046A,
DIE_LS2088A,
DIE_LS1021A,
DIE_LX2160A,
DIE_LS1028A,
DIE_MAX,
};
struct rcw_full_srds_proto {
int srds_proto_val;
unsigned long xgmii_lanes;
};
static const struct rcw_full_srds_proto ls2088a_rcw_full_srds1_protos[] = {
{ 0x05, 0 },
{ 0x07, 0 },
{ 0x09, 0 },
{ 0x0a, 0 },
{ 0x0c, 0 },
{ 0x0e, 0 },
{ 0x10, 0 },
{ 0x12, 0 },
{ 0x14, 0 },
{ 0x16, 0 },
{ 0x18, 0 },
{ 0x1a, 0 },
{ 0x1c, 0 },
{ 0x1e, 0 },
{ 0x20, 0 },
{ 0x22, 0 },
{ 0x24, 0 },
{ 0x26, GENMASK(7, 6) },
{ 0x28, GENMASK(7, 4) },
{ 0x2a, GENMASK(7, 0) },
/* 0x2b: unimplemented because of XAUI1 (lanes E-H) */
/* 0x2d: unimplemented because of XAUI1 (lanes E-H) */
/* 0x2e: unimplemented because of XAUI1 (lanes E-H) */
/* 0x30: unimplemented because of XAUI1 (lanes E-H) */
/* 0x32: unimplemented because of XAUI1 (lanes E-H) and XAUI2 (A-D) */
/* 0x33: unimplemented because of QSGMII (lanes E-H) */
/* 0x35: unimplemented because of QSGMII (lanes A-C) */
/* 0x37: unimplemented because of QSGMII (lanes E-F) */
{ 0x39, 0 },
{ 0x3b, GENMASK(6, 4) | GENMASK(2, 0) },
{ 0x4b, GENMASK(7, 4) },
{ 0x4c, GENMASK(3, 0) },
{ 0x4d, 0 },
{ 0x58, 0 },
};
/* SoC die attribute definition for QorIQ platform */
static const struct fsl_soc_die_attr fsl_soc_die[] = {
/*
* Power Architecture-based SoCs T Series
*/
/* Die: T4240, SoC: T4240/T4160/T4080 */
[DIE_T4240] =
{ .die = "T4240",
.svr = 0x82400000,
.mask = 0xfff00000,
},
/* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
[DIE_T1040] =
{ .die = "T1040",
.svr = 0x85200000,
.mask = 0xfff00000,
},
/* Die: T2080, SoC: T2080/T2081 */
[DIE_T2080] =
{ .die = "T2080",
.svr = 0x85300000,
.mask = 0xfff00000,
},
/* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
[DIE_T1024] =
{ .die = "T1024",
.svr = 0x85400000,
.mask = 0xfff00000,
},
/*
* ARM-based SoCs LS Series
*/
/* Die: LS1043A, SoC: LS1043A/LS1023A */
[DIE_LS1043A] =
{ .die = "LS1043A",
.svr = 0x87920000,
.mask = 0xffff0000,
},
/* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
[DIE_LS2080A] =
{ .die = "LS2080A",
.svr = 0x87010000,
.mask = 0xff3f0000,
},
/* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
[DIE_LS1088A] =
{ .die = "LS1088A",
.svr = 0x87030000,
.mask = 0xff3f0000,
},
/* Die: LS1012A, SoC: LS1012A */
[DIE_LS1012A] =
{ .die = "LS1012A",
.svr = 0x87040000,
.mask = 0xffff0000,
},
/* Die: LS1046A, SoC: LS1046A/LS1026A */
[DIE_LS1046A] =
{ .die = "LS1046A",
.svr = 0x87070000,
.mask = 0xffff0000,
},
/* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
[DIE_LS2088A] =
{ .die = "LS2088A",
.svr = 0x87090000,
.mask = 0xff3f0000,
},
/* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
[DIE_LS1021A] =
{ .die = "LS1021A",
.svr = 0x87000000,
.mask = 0xfff70000,
},
/* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */
[DIE_LX2160A] =
{ .die = "LX2160A",
.svr = 0x87360000,
.mask = 0xff3f0000,
},
/* Die: LS1028A, SoC: LS1028A */
[DIE_LS1028A] =
{ .die = "LS1028A",
.svr = 0x870b0000,
.mask = 0xff3f0000,
},
{ },
};
static struct fsl_soc_guts {
struct ccsr_guts __iomem *dcfg_ccsr;
struct ccsr_guts __iomem *dcfg_dcsr;
const struct fsl_soc_data *data;
bool little_endian;
u32 svr;
spinlock_t rcwcr_lock; /* serializes concurrent writes to the RCWCR */
} soc;
static unsigned int fsl_guts_read(const void __iomem *reg)
{
if (soc.little_endian)
return ioread32(reg);
return ioread32be(reg);
}
static void fsl_guts_write(void __iomem *reg, u32 val)
{
if (soc.little_endian)
iowrite32(val, reg);
else
iowrite32be(val, reg);
}
/* Some fields of the Reset Configuration Word (RCW) can be overridden at
* runtime by writing to the RCWCRn registers contained within the DCSR space
* of the Device Configuration (DCFG) block. The layout of the RCWCRn registers
* is identical with the read-only RCWSRn from the CCSR space.
*/
static int fsl_guts_rcw_rmw(int offset, u32 val, u32 mask)
{
u32 rcwcr, rcwsr = fsl_guts_read(&soc.dcfg_ccsr->rcwsr[offset]);
rcwcr = rcwsr & ~mask;
rcwcr |= val;
fsl_guts_write(&soc.dcfg_dcsr->rcwcr[offset], rcwcr);
pr_debug("RCW override: RCWSR%d 0x%x -> RCWCR%d 0x%x\n",
offset + 1, rcwsr, offset + 1, rcwcr);
/* Updates to RCWCR should be visible back in RCWSR immediately */
return read_poll_timeout_atomic(fsl_guts_read, rcwsr, rcwsr == rcwcr,
0, RCW_TIMEOUT_US, false,
&soc.dcfg_ccsr->rcwsr[offset]);
}
static bool fsl_soc_die_match_one(u32 svr, const struct fsl_soc_die_attr *match)
{
return match->svr == (svr & match->mask);
}
static const struct fsl_soc_die_attr *fsl_soc_die_match(
u32 svr, const struct fsl_soc_die_attr *matches)
{
while (matches->svr) {
if (fsl_soc_die_match_one(svr, matches))
return matches;
matches++;
}
return NULL;
}
static int
fsl_guts_serdes_get_rcw_override(int serdes_idx, int lane,
enum lynx_lane_mode lane_mode,
struct fsl_soc_serdes_rcw_override *override)
{
const struct fsl_soc_data *soc_data = soc.data;
if (!soc_data)
return -ENODEV;
/* serdes_idx is one-based */
if (serdes_idx > soc_data->num_serdes_blocks || serdes_idx <= 0)
return -ERANGE;
if (lane >= soc_data->num_serdes_lanes || lane < 0)
return -ERANGE;
if (!soc_data->serdes_get_rcw_override) {
pr_debug("RCW override not implemented for SoC\n");
return -EINVAL;
}
if (!soc.dcfg_dcsr) {
pr_debug("Device tree does not define DCFG_DCSR region necessary for RCW override\n");
return -EINVAL;
}
return soc_data->serdes_get_rcw_override(serdes_idx, lane, lane_mode,
override);
}
/**
* fsl_guts_lane_validate() - Validate that SerDes protocol is implemented and
* supported on current SoC
* @serdes_idx: one-based SerDes block index
* @lane: zero-based lane index within SerDes
* @lane_mode: requested SerDes protocol
*
* Should be called before actually requesting the RCW override procedure to be
* applied using %fsl_guts_lane_set_mode()
*
* Return: 0 if RCW override to protocol is possible, negative error otherwise
*/
int fsl_guts_lane_validate(int serdes_idx, int lane, enum lynx_lane_mode lane_mode)
{
struct fsl_soc_serdes_rcw_override override;
return fsl_guts_serdes_get_rcw_override(serdes_idx, lane, lane_mode,
&override);
}
EXPORT_SYMBOL_NS_GPL(fsl_guts_lane_validate, "FSL_GUTS");
/**
* fsl_guts_lane_set_mode() - apply RCW override procedure for SerDes lane
* @serdes_idx: one-based SerDes block index
* @lane: zero-based lane index within SerDes
* @lane_mode: requested SerDes protocol
*
* Return: 0 on success, negative error otherwise
*/
int fsl_guts_lane_set_mode(int serdes_idx, int lane, enum lynx_lane_mode lane_mode)
{
struct fsl_soc_serdes_rcw_override override;
int err;
err = fsl_guts_serdes_get_rcw_override(serdes_idx, lane, lane_mode,
&override);
if (err)
return err;
spin_lock(&soc.rcwcr_lock);
if (soc.data->serdes_init_rcwcr) {
err = soc.data->serdes_init_rcwcr(serdes_idx);
if (err)
goto out_unlock;
}
err = fsl_guts_rcw_rmw(override.offset,
override.val << __ffs(override.mask),
override.mask);
if (err)
pr_err("RCW override failed: %pe\n", ERR_PTR(err));
out_unlock:
spin_unlock(&soc.rcwcr_lock);
return err;
}
EXPORT_SYMBOL_NS_GPL(fsl_guts_lane_set_mode, "FSL_GUTS");
static u64 fsl_guts_get_soc_uid(const char *compat, unsigned int offset)
{
struct device_node *np;
void __iomem *sfp_base;
u64 uid;
np = of_find_compatible_node(NULL, NULL, compat);
if (!np)
return 0;
sfp_base = of_iomap(np, 0);
if (!sfp_base) {
of_node_put(np);
return 0;
}
uid = ioread32(sfp_base + offset);
uid <<= 32;
uid |= ioread32(sfp_base + offset + 4);
iounmap(sfp_base);
of_node_put(np);
return uid;
}
static int ls1046a_serdes_get_rcw_override(int index, int lane,
enum lynx_lane_mode lane_mode,
struct fsl_soc_serdes_rcw_override *override)
{
/* The RCW override procedure has to write to different registers
* depending on the SerDes block index.
*/
switch (index) {
case 1:
override->offset = 4;
override->mask = LS1046A_RCWSR5_SRDS_PRTCL_S1(lane);
break;
default:
return -EINVAL;
}
if (lynx_lane_mode_uses_xgmii_mac(lane_mode))
override->val = LS1046A_SRDS_PRTCL_XFI;
else if (lynx_lane_mode_uses_gmii_mac(lane_mode))
override->val = LS1046A_SRDS_PRTCL_100BASEX_SGMII;
else
return -EINVAL;
return 0;
}
static int ls1088a_serdes_get_rcw_override(int index, int lane,
enum lynx_lane_mode lane_mode,
struct fsl_soc_serdes_rcw_override *override)
{
/* The RCW override procedure has to write to different registers
* depending on the SerDes block index.
*/
switch (index) {
case 1:
override->offset = 28;
override->mask = LS1088A_RCWSR29_SRDS_PRTCL_S1_LNn(lane);
break;
case 2:
override->offset = 29;
override->mask = LS1088A_RCWSR30_SRDS_PRTCL_S2_LNn(lane);
break;
default:
return -EINVAL;
}
if (lynx_lane_mode_uses_xgmii_mac(lane_mode))
override->val = LS1088A_SRDS_PRTCL_XFI;
else if (lynx_lane_mode_uses_gmii_mac(lane_mode))
override->val = LS1088A_SRDS_PRTCL_100BASEX_SGMII;
else
return -EINVAL;
return 0;
}
static const struct rcw_full_srds_proto *ls2088a_get_full_serdes1_proto(void)
{
u32 rcwsr29 = fsl_guts_read(&soc.dcfg_ccsr->rcwsr[28]);
u32 srds_prtcl_s1 = FIELD_GET(LS2088A_RCWSR29_SRDS_PRTCL_S1, rcwsr29);
for (int i = 0; i < ARRAY_SIZE(ls2088a_rcw_full_srds1_protos); i++) {
const struct rcw_full_srds_proto *proto;
proto = &ls2088a_rcw_full_srds1_protos[i];
if (proto->srds_proto_val == srds_prtcl_s1)
return proto;
}
return NULL;
}
static int ls2088a_serdes_get_rcw_override(int index, int lane,
enum lynx_lane_mode lane_mode,
struct fsl_soc_serdes_rcw_override *override)
{
switch (index) {
case 1:
override->offset = 29;
override->mask = LS2088A_RCWSR30_SRDS_CLK_SEL_XGMII_Ln_S1(lane);
break;
default:
return -EINVAL;
}
/* RCW override only supported if we know how to handle the initial
* RCWSR29[SRDS_PRTCL_S1] value and turn it into an override.
*/
if (!ls2088a_get_full_serdes1_proto()) {
u32 rcwsr30 = fsl_guts_read(&soc.dcfg_ccsr->rcwsr[29]);
/* If a SerDes-level override is already in place (probably
* left there by a previous boot stage), use it.
*/
if (!(rcwsr30 & LS2088A_RCWSR30_SRDS_CLK_EN_SEL_XGMII_S1))
return -EINVAL;
}
if (lynx_lane_mode_uses_xgmii_mac(lane_mode))
override->val = LS2088A_SRDS_CLK_SEL_XGMII;
else if (lynx_lane_mode_uses_gmii_mac(lane_mode))
override->val = LS2088A_SRDS_CLK_SEL_GMII;
else
return -EINVAL;
return 0;
}
static int ls2088a_serdes_init_rcwcr(int serdes_idx)
{
const struct rcw_full_srds_proto *srds_prtcl_s1;
const struct fsl_soc_data *soc_data = soc.data;
u32 rcwsr30;
int i, err;
/* SerDes 2 supports only SGMII for networking. There should be
* no need for RCW override
*/
if (serdes_idx != 1)
return -EINVAL;
/* SRDS_CLK_EN_SEL_XGMII_S1: SerDes Clock Enable Select XGMII Serdes 1:
* Enables to select GMII/XGMII clock according to
* SRDS_CLK_SEL_XGMII_Ln_S1.
* If the GMII/XGMII select override has already been set, use it.
* Otherwise, derive an initial override for all lanes based on the
* full SerDes protocol table.
*/
rcwsr30 = fsl_guts_read(&soc.dcfg_ccsr->rcwsr[29]);
if (rcwsr30 & LS2088A_RCWSR30_SRDS_CLK_EN_SEL_XGMII_S1) {
pr_debug("RCWSR30 = 0x%x, using this.\n", rcwsr30);
return 0;
}
srds_prtcl_s1 = ls2088a_get_full_serdes1_proto();
rcwsr30 = LS2088A_RCWSR30_SRDS_CLK_EN_SEL_XGMII_S1;
/* We need to configure the initial state of all lanes for
* the SerDes block #1
*/
for_each_set_bit(i, &srds_prtcl_s1->xgmii_lanes, soc_data->num_serdes_lanes)
rcwsr30 |= LS2088A_RCWSR30_SRDS_CLK_SEL_XGMII_Ln_S1(i);
pr_debug("Setting initial RCWSR30 = 0x%x based on SRDS_PRTCL_S1 = 0x%x\n",
rcwsr30, srds_prtcl_s1->srds_proto_val);
err = fsl_guts_rcw_rmw(29, rcwsr30,
LS2088A_RCWSR30_SRDS_CLK_EN_SEL_XGMII_S1 |
LS2088A_RCWSR30_SRDS_CLK_SEL_MSK);
if (err) {
pr_err("Setting up initial RCWCR failed: %pe\n", ERR_PTR(err));
return err;
}
return 0;
}
static const struct fsl_soc_data ls1088a_data = {
.serdes_get_rcw_override = ls1088a_serdes_get_rcw_override,
.num_serdes_blocks = 2,
.num_serdes_lanes = 4,
};
static const struct fsl_soc_data ls1046a_data = {
.serdes_get_rcw_override = ls1046a_serdes_get_rcw_override,
.num_serdes_blocks = 2,
.num_serdes_lanes = 4,
};
static const struct fsl_soc_data ls2088a_data = {
.serdes_get_rcw_override = ls2088a_serdes_get_rcw_override,
.serdes_init_rcwcr = ls2088a_serdes_init_rcwcr,
.num_serdes_blocks = 2,
.num_serdes_lanes = 8,
};
static const struct fsl_soc_data ls1028a_data = {
.sfp_compat = "fsl,ls1028a-sfp",
.uid_offset = 0x21c,
.num_serdes_blocks = 1,
.num_serdes_lanes = 4,
};
/*
* Table for matching compatible strings, for device tree
* guts node, for Freescale QorIQ SOCs.
*/
static const struct of_device_id fsl_guts_of_match[] = {
{ .compatible = "fsl,qoriq-device-config-1.0", },
{ .compatible = "fsl,qoriq-device-config-2.0", },
{ .compatible = "fsl,p1010-guts", },
{ .compatible = "fsl,p1020-guts", },
{ .compatible = "fsl,p1021-guts", },
{ .compatible = "fsl,p1022-guts", },
{ .compatible = "fsl,p1023-guts", },
{ .compatible = "fsl,p2020-guts", },
{ .compatible = "fsl,bsc9131-guts", },
{ .compatible = "fsl,bsc9132-guts", },
{ .compatible = "fsl,mpc8536-guts", },
{ .compatible = "fsl,mpc8544-guts", },
{ .compatible = "fsl,mpc8548-guts", },
{ .compatible = "fsl,mpc8568-guts", },
{ .compatible = "fsl,mpc8569-guts", },
{ .compatible = "fsl,mpc8572-guts", },
{ .compatible = "fsl,ls1021a-dcfg", },
{ .compatible = "fsl,ls1043a-dcfg", },
{ .compatible = "fsl,ls2080a-dcfg", .data = &ls2088a_data},
{ .compatible = "fsl,ls1088a-dcfg", .data = &ls1088a_data},
{ .compatible = "fsl,ls1012a-dcfg", },
{ .compatible = "fsl,ls1046a-dcfg", .data = &ls1046a_data},
{ .compatible = "fsl,lx2160a-dcfg", },
{ .compatible = "fsl,ls1028a-dcfg", .data = &ls1028a_data},
{}
};
static int __init fsl_guts_init(void)
{
struct soc_device_attribute *soc_dev_attr = NULL;
static struct soc_device *soc_dev;
const struct fsl_soc_die_attr *soc_die;
const struct of_device_id *match;
struct device_node *np;
u64 soc_uid = 0;
int ret;
spin_lock_init(&soc.rcwcr_lock);
np = of_find_matching_node_and_match(NULL, fsl_guts_of_match, &match);
if (!np)
return 0;
soc.data = match->data;
soc.dcfg_ccsr = of_iomap(np, DCFG_CCSR);
if (!soc.dcfg_ccsr) {
of_node_put(np);
ret = -ENOMEM;
goto err_clear_soc_data;
}
/* DCFG_DCSR is optional */
soc.dcfg_dcsr = of_iomap(np, DCFG_DCSR);
soc.little_endian = of_property_read_bool(np, "little-endian");
soc.svr = fsl_guts_read(&soc.dcfg_ccsr->svr);
of_node_put(np);
/* Register soc device */
soc_dev_attr = kzalloc_obj(*soc_dev_attr);
if (!soc_dev_attr) {
ret = -ENOMEM;
goto err_unmap_dcfg_ccsr_dcsr;
}
ret = soc_attr_read_machine(soc_dev_attr);
if (ret)
of_machine_read_compatible(&soc_dev_attr->machine, 0);
soc_die = fsl_soc_die_match(soc.svr, fsl_soc_die);
if (soc_die) {
soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ %s",
soc_die->die);
} else {
soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ");
}
if (!soc_dev_attr->family) {
ret = -ENOMEM;
goto err_free_soc_dev_attr;
}
soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "svr:0x%08x", soc.svr);
if (!soc_dev_attr->soc_id) {
ret = -ENOMEM;
goto err_free_family;
}
soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
(soc.svr >> 4) & 0xf, soc.svr & 0xf);
if (!soc_dev_attr->revision) {
ret = -ENOMEM;
goto err_free_soc_id;
}
if (soc.data)
soc_uid = fsl_guts_get_soc_uid(soc.data->sfp_compat,
soc.data->uid_offset);
if (soc_uid)
soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX",
soc_uid);
soc_dev = soc_device_register(soc_dev_attr);
if (IS_ERR(soc_dev)) {
ret = PTR_ERR(soc_dev);
goto err_free_serial_number;
}
pr_info("Machine: %s\n", soc_dev_attr->machine);
pr_info("SoC family: %s\n", soc_dev_attr->family);
pr_info("SoC ID: %s, Revision: %s\n",
soc_dev_attr->soc_id, soc_dev_attr->revision);
return 0;
err_free_serial_number:
kfree(soc_dev_attr->serial_number);
kfree(soc_dev_attr->revision);
err_free_soc_id:
kfree(soc_dev_attr->soc_id);
err_free_family:
kfree(soc_dev_attr->family);
err_free_soc_dev_attr:
kfree(soc_dev_attr);
err_unmap_dcfg_ccsr_dcsr:
if (soc.dcfg_dcsr) {
iounmap(soc.dcfg_dcsr);
soc.dcfg_dcsr = NULL;
}
iounmap(soc.dcfg_ccsr);
soc.dcfg_ccsr = NULL;
err_clear_soc_data:
soc.data = NULL;
return ret;
}
core_initcall(fsl_guts_init);
|