Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Apple SoC eFuse driver
0004  *
0005  * Copyright (C) The Asahi Linux Contributors
0006  */
0007 
0008 #include <linux/io.h>
0009 #include <linux/mod_devicetable.h>
0010 #include <linux/module.h>
0011 #include <linux/nvmem-provider.h>
0012 #include <linux/platform_device.h>
0013 
0014 struct apple_efuses_priv {
0015     void __iomem *fuses;
0016 };
0017 
0018 static int apple_efuses_read(void *context, unsigned int offset, void *val,
0019                  size_t bytes)
0020 {
0021     struct apple_efuses_priv *priv = context;
0022     u32 *dst = val;
0023 
0024     while (bytes >= sizeof(u32)) {
0025         *dst++ = readl_relaxed(priv->fuses + offset);
0026         bytes -= sizeof(u32);
0027         offset += sizeof(u32);
0028     }
0029 
0030     return 0;
0031 }
0032 
0033 static int apple_efuses_probe(struct platform_device *pdev)
0034 {
0035     struct apple_efuses_priv *priv;
0036     struct resource *res;
0037     struct nvmem_config config = {
0038         .dev = &pdev->dev,
0039         .read_only = true,
0040         .reg_read = apple_efuses_read,
0041         .stride = sizeof(u32),
0042         .word_size = sizeof(u32),
0043         .name = "apple_efuses_nvmem",
0044         .id = NVMEM_DEVID_AUTO,
0045         .root_only = true,
0046     };
0047 
0048     priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL);
0049     if (!priv)
0050         return -ENOMEM;
0051 
0052     priv->fuses = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
0053     if (IS_ERR(priv->fuses))
0054         return PTR_ERR(priv->fuses);
0055 
0056     config.priv = priv;
0057     config.size = resource_size(res);
0058 
0059     return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config));
0060 }
0061 
0062 static const struct of_device_id apple_efuses_of_match[] = {
0063     { .compatible = "apple,efuses", },
0064     {}
0065 };
0066 
0067 MODULE_DEVICE_TABLE(of, apple_efuses_of_match);
0068 
0069 static struct platform_driver apple_efuses_driver = {
0070     .driver = {
0071         .name = "apple_efuses",
0072         .of_match_table = apple_efuses_of_match,
0073     },
0074     .probe = apple_efuses_probe,
0075 };
0076 
0077 module_platform_driver(apple_efuses_driver);
0078 
0079 MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
0080 MODULE_LICENSE("GPL");