forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/soc/ux500/ux500-soc-id.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) ST-Ericsson SA 2010
34 *
45 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5
- * License terms: GNU General Public License (GPL) version 2
66 */
77
88 #include <linux/kernel.h>
....@@ -146,9 +146,8 @@
146146 return kasprintf(GFP_KERNEL, "%s", "Unknown");
147147 }
148148
149
-static ssize_t ux500_get_process(struct device *dev,
150
- struct device_attribute *attr,
151
- char *buf)
149
+static ssize_t
150
+process_show(struct device *dev, struct device_attribute *attr, char *buf)
152151 {
153152 if (dbx500_id.process == 0x00)
154153 return sprintf(buf, "Standard\n");
....@@ -156,23 +155,30 @@
156155 return sprintf(buf, "%02xnm\n", dbx500_id.process);
157156 }
158157
158
+static DEVICE_ATTR_RO(process);
159
+
160
+static struct attribute *ux500_soc_attrs[] = {
161
+ &dev_attr_process.attr,
162
+ NULL
163
+};
164
+
165
+ATTRIBUTE_GROUPS(ux500_soc);
166
+
159167 static const char *db8500_read_soc_id(struct device_node *backupram)
160168 {
161169 void __iomem *base;
162
- void __iomem *uid;
163170 const char *retstr;
171
+ u32 uid[5];
164172
165173 base = of_iomap(backupram, 0);
166174 if (!base)
167175 return NULL;
168
- uid = base + 0x1fc0;
176
+ memcpy_fromio(uid, base + 0x1fc0, sizeof(uid));
169177
170178 /* Throw these device-specific numbers into the entropy pool */
171
- add_device_randomness(uid, 0x14);
179
+ add_device_randomness(uid, sizeof(uid));
172180 retstr = kasprintf(GFP_KERNEL, "%08x%08x%08x%08x%08x",
173
- readl((u32 *)uid+0),
174
- readl((u32 *)uid+1), readl((u32 *)uid+2),
175
- readl((u32 *)uid+3), readl((u32 *)uid+4));
181
+ uid[0], uid[1], uid[2], uid[3], uid[4]);
176182 iounmap(base);
177183 return retstr;
178184 }
....@@ -184,14 +190,11 @@
184190 soc_dev_attr->machine = ux500_get_machine();
185191 soc_dev_attr->family = ux500_get_family();
186192 soc_dev_attr->revision = ux500_get_revision();
193
+ soc_dev_attr->custom_attr_group = ux500_soc_groups[0];
187194 }
188
-
189
-static const struct device_attribute ux500_soc_attr =
190
- __ATTR(process, S_IRUGO, ux500_get_process, NULL);
191195
192196 static int __init ux500_soc_device_init(void)
193197 {
194
- struct device *parent;
195198 struct soc_device *soc_dev;
196199 struct soc_device_attribute *soc_dev_attr;
197200 struct device_node *backupram;
....@@ -203,19 +206,19 @@
203206 ux500_setup_id();
204207
205208 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
206
- if (!soc_dev_attr)
209
+ if (!soc_dev_attr) {
210
+ of_node_put(backupram);
207211 return -ENOMEM;
212
+ }
208213
209214 soc_info_populate(soc_dev_attr, backupram);
215
+ of_node_put(backupram);
210216
211217 soc_dev = soc_device_register(soc_dev_attr);
212218 if (IS_ERR(soc_dev)) {
213219 kfree(soc_dev_attr);
214220 return PTR_ERR(soc_dev);
215221 }
216
-
217
- parent = soc_device_to_device(soc_dev);
218
- device_create_file(parent, &ux500_soc_attr);
219222
220223 return 0;
221224 }