hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/nvmem/bcm-ocotp.c
....@@ -11,13 +11,14 @@
1111 * GNU General Public License for more details.
1212 */
1313
14
+#include <linux/acpi.h>
1415 #include <linux/delay.h>
1516 #include <linux/device.h>
1617 #include <linux/io.h>
1718 #include <linux/module.h>
1819 #include <linux/nvmem-provider.h>
1920 #include <linux/of.h>
20
-#include <linux/of_address.h>
21
+#include <linux/of_device.h>
2122 #include <linux/platform_device.h>
2223
2324 /*
....@@ -78,9 +79,9 @@
7879 };
7980
8081 struct otpc_priv {
81
- struct device *dev;
82
- void __iomem *base;
83
- struct otpc_map *map;
82
+ struct device *dev;
83
+ void __iomem *base;
84
+ const struct otpc_map *map;
8485 struct nvmem_config *config;
8586 };
8687
....@@ -237,16 +238,22 @@
237238 };
238239
239240 static const struct of_device_id bcm_otpc_dt_ids[] = {
240
- { .compatible = "brcm,ocotp" },
241
- { .compatible = "brcm,ocotp-v2" },
241
+ { .compatible = "brcm,ocotp", .data = &otp_map },
242
+ { .compatible = "brcm,ocotp-v2", .data = &otp_map_v2 },
242243 { },
243244 };
244245 MODULE_DEVICE_TABLE(of, bcm_otpc_dt_ids);
245246
247
+static const struct acpi_device_id bcm_otpc_acpi_ids[] = {
248
+ { .id = "BRCM0700", .driver_data = (kernel_ulong_t)&otp_map },
249
+ { .id = "BRCM0701", .driver_data = (kernel_ulong_t)&otp_map_v2 },
250
+ { /* sentinel */ }
251
+};
252
+MODULE_DEVICE_TABLE(acpi, bcm_otpc_acpi_ids);
253
+
246254 static int bcm_otpc_probe(struct platform_device *pdev)
247255 {
248256 struct device *dev = &pdev->dev;
249
- struct device_node *dn = dev->of_node;
250257 struct resource *res;
251258 struct otpc_priv *priv;
252259 struct nvmem_device *nvmem;
....@@ -257,14 +264,9 @@
257264 if (!priv)
258265 return -ENOMEM;
259266
260
- if (of_device_is_compatible(dev->of_node, "brcm,ocotp"))
261
- priv->map = &otp_map;
262
- else if (of_device_is_compatible(dev->of_node, "brcm,ocotp-v2"))
263
- priv->map = &otp_map_v2;
264
- else {
265
- dev_err(dev, "%s otpc config map not defined\n", __func__);
266
- return -EINVAL;
267
- }
267
+ priv->map = device_get_match_data(dev);
268
+ if (!priv->map)
269
+ return -ENODEV;
268270
269271 /* Get OTP base address register. */
270272 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
....@@ -281,7 +283,7 @@
281283 reset_start_bit(priv->base);
282284
283285 /* Read size of memory in words. */
284
- err = of_property_read_u32(dn, "brcm,ocotp-size", &num_words);
286
+ err = device_property_read_u32(dev, "brcm,ocotp-size", &num_words);
285287 if (err) {
286288 dev_err(dev, "size parameter not specified\n");
287289 return -EINVAL;
....@@ -294,7 +296,7 @@
294296 bcm_otpc_nvmem_config.dev = dev;
295297 bcm_otpc_nvmem_config.priv = priv;
296298
297
- if (of_device_is_compatible(dev->of_node, "brcm,ocotp-v2")) {
299
+ if (priv->map == &otp_map_v2) {
298300 bcm_otpc_nvmem_config.word_size = 8;
299301 bcm_otpc_nvmem_config.stride = 8;
300302 }
....@@ -315,6 +317,7 @@
315317 .driver = {
316318 .name = "brcm-otpc",
317319 .of_match_table = bcm_otpc_dt_ids,
320
+ .acpi_match_table = ACPI_PTR(bcm_otpc_acpi_ids),
318321 },
319322 };
320323 module_platform_driver(bcm_otpc_driver);