27
27
#define AT91_CIDR_MATCH_MASK GENMASK(30, 5)
28
28
#define AT91_CIDR_MASK_SAMA7 GENMASK(27, 5)
29
29
30
+ static ssize_t exid_show (struct device * dev , struct device_attribute * attr ,
31
+ char * buf )
32
+ {
33
+ u32 * exid = dev_get_drvdata (dev );
34
+
35
+ return sysfs_emit (buf , "0x%08x\n" , * exid );
36
+ }
37
+ static DEVICE_ATTR_RO (exid );
38
+
39
+ static struct attribute * at91_soc_attr [] = {
40
+ & dev_attr_exid .attr ,
41
+ NULL ,
42
+ };
43
+
44
+ const struct attribute_group at91_soc_attr_group = {
45
+ .attrs = at91_soc_attr ,
46
+ };
47
+
48
+ static void at91_soc_release (struct device * dev )
49
+ {
50
+ kfree (dev_get_drvdata (dev ));
51
+ }
52
+
30
53
static const struct at91_soc socs [] __initconst = {
31
54
#ifdef CONFIG_SOC_AT91RM9200
32
55
AT91_SOC (AT91RM9200_CIDR_MATCH , AT91_CIDR_MATCH_MASK ,
@@ -334,17 +357,20 @@ struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
334
357
struct soc_device_attribute * soc_dev_attr ;
335
358
const struct at91_soc * soc ;
336
359
struct soc_device * soc_dev ;
337
- u32 cidr , exid ;
360
+ u32 cidr , * exid ;
338
361
int ret ;
339
362
363
+ exid = kmalloc (sizeof (* exid ), GFP_KERNEL );
364
+ if (!exid )
365
+ return NULL ;
340
366
/*
341
367
* With SAMA5D2 and later SoCs, CIDR and EXID registers are no more
342
368
* in the dbgu device but in the chipid device whose purpose is only
343
369
* to expose these two registers.
344
370
*/
345
- ret = at91_get_cidr_exid_from_dbgu (& cidr , & exid );
371
+ ret = at91_get_cidr_exid_from_dbgu (& cidr , exid );
346
372
if (ret )
347
- ret = at91_get_cidr_exid_from_chipid (& cidr , & exid );
373
+ ret = at91_get_cidr_exid_from_chipid (& cidr , exid );
348
374
if (ret ) {
349
375
if (ret == - ENODEV )
350
376
pr_warn ("Could not find identification node" );
@@ -355,7 +381,7 @@ struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
355
381
if (soc -> cidr_match != (cidr & soc -> cidr_mask ))
356
382
continue ;
357
383
358
- if (!(cidr & AT91_CIDR_EXT ) || soc -> exid_match == exid )
384
+ if (!(cidr & AT91_CIDR_EXT ) || soc -> exid_match == * exid )
359
385
break ;
360
386
}
361
387
@@ -372,14 +398,19 @@ struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
372
398
soc_dev_attr -> soc_id = soc -> name ;
373
399
soc_dev_attr -> revision = kasprintf (GFP_KERNEL , "%X" ,
374
400
AT91_CIDR_VERSION (cidr , soc -> version_mask ));
401
+ soc_dev_attr -> custom_attr_group = soc -> soc_attr_group ;
375
402
soc_dev = soc_device_register (soc_dev_attr );
376
403
if (IS_ERR (soc_dev )) {
377
404
kfree (soc_dev_attr -> revision );
378
405
kfree (soc_dev_attr );
406
+ kfree (exid );
379
407
pr_warn ("Could not register SoC device\n" );
380
408
return NULL ;
381
409
}
382
410
411
+ soc_device_to_device (soc_dev )-> release = at91_soc_release ;
412
+ dev_set_drvdata (soc_device_to_device (soc_dev ), exid );
413
+
383
414
if (soc -> family )
384
415
pr_info ("Detected SoC family: %s\n" , soc -> family );
385
416
pr_info ("Detected SoC: %s, revision %X\n" , soc -> name ,
0 commit comments