Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e8ebe2

Browse files
committed
drivers: soc: atmel: add attribute group for SoC attributes
Introduce a new attribute group (`at91_soc_attr_group`) to expose the SoC-specific attributes and add a new `exid_show` function to display the EXID value of the SoC. Signed-off-by: Dharma Balasubiramani <[email protected]> Reviewed-by: Balamanikandan Gunasundar <[email protected]>
1 parent c0f7fb7 commit 6e8ebe2

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

drivers/soc/atmel/soc.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@
2727
#define AT91_CIDR_MATCH_MASK GENMASK(30, 5)
2828
#define AT91_CIDR_MASK_SAMA7 GENMASK(27, 5)
2929

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+
3053
static const struct at91_soc socs[] __initconst = {
3154
#ifdef CONFIG_SOC_AT91RM9200
3255
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)
334357
struct soc_device_attribute *soc_dev_attr;
335358
const struct at91_soc *soc;
336359
struct soc_device *soc_dev;
337-
u32 cidr, exid;
360+
u32 cidr, *exid;
338361
int ret;
339362

363+
exid = kmalloc(sizeof(*exid), GFP_KERNEL);
364+
if (!exid)
365+
return NULL;
340366
/*
341367
* With SAMA5D2 and later SoCs, CIDR and EXID registers are no more
342368
* in the dbgu device but in the chipid device whose purpose is only
343369
* to expose these two registers.
344370
*/
345-
ret = at91_get_cidr_exid_from_dbgu(&cidr, &exid);
371+
ret = at91_get_cidr_exid_from_dbgu(&cidr, exid);
346372
if (ret)
347-
ret = at91_get_cidr_exid_from_chipid(&cidr, &exid);
373+
ret = at91_get_cidr_exid_from_chipid(&cidr, exid);
348374
if (ret) {
349375
if (ret == -ENODEV)
350376
pr_warn("Could not find identification node");
@@ -355,7 +381,7 @@ struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
355381
if (soc->cidr_match != (cidr & soc->cidr_mask))
356382
continue;
357383

358-
if (!(cidr & AT91_CIDR_EXT) || soc->exid_match == exid)
384+
if (!(cidr & AT91_CIDR_EXT) || soc->exid_match == *exid)
359385
break;
360386
}
361387

@@ -372,14 +398,19 @@ struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
372398
soc_dev_attr->soc_id = soc->name;
373399
soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%X",
374400
AT91_CIDR_VERSION(cidr, soc->version_mask));
401+
soc_dev_attr->custom_attr_group = soc->soc_attr_group;
375402
soc_dev = soc_device_register(soc_dev_attr);
376403
if (IS_ERR(soc_dev)) {
377404
kfree(soc_dev_attr->revision);
378405
kfree(soc_dev_attr);
406+
kfree(exid);
379407
pr_warn("Could not register SoC device\n");
380408
return NULL;
381409
}
382410

411+
soc_device_to_device(soc_dev)->release = at91_soc_release;
412+
dev_set_drvdata(soc_device_to_device(soc_dev), exid);
413+
383414
if (soc->family)
384415
pr_info("Detected SoC family: %s\n", soc->family);
385416
pr_info("Detected SoC: %s, revision %X\n", soc->name,

drivers/soc/atmel/soc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct at91_soc {
1717
u32 exid_match;
1818
const char *name;
1919
const char *family;
20+
const struct attribute_group *soc_attr_group;
2021
};
2122

2223
#define AT91_SOC(__cidr, __cidr_mask, __version_mask, __exid, \
@@ -28,6 +29,7 @@ struct at91_soc {
2829
.exid_match = (__exid), \
2930
.name = (__name), \
3031
.family = (__family), \
32+
.soc_attr_group = &at91_soc_attr_group \
3133
}
3234

3335
struct soc_device * __init

0 commit comments

Comments
 (0)