1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
6 #include <linux/firmware/qcom/qcom_scm.h>
7 #include <linux/mod_devicetable.h>
8 #include <linux/nvmem-provider.h>
9 #include <linux/platform_device.h>
10 #include <linux/pm_runtime.h>
13 * struct sec_qfprom - structure holding secure qfprom attributes
15 * @base: starting physical address for secure qfprom corrected address space.
16 * @dev: qfprom device structure.
23 static int sec_qfprom_reg_read(void *context, unsigned int reg, void *_val, size_t bytes)
25 struct sec_qfprom *priv = context;
31 for (i = 0; i < bytes; i++, reg++) {
32 if (i == 0 || reg % 4 == 0) {
33 if (qcom_scm_io_readl(priv->base + (reg & ~3), &read_val)) {
34 dev_err(priv->dev, "Couldn't access fuse register\n");
37 tmp = (u8 *)&read_val;
40 val[i] = tmp[reg & 3];
46 static int sec_qfprom_probe(struct platform_device *pdev)
48 struct nvmem_config econfig = {
52 .id = NVMEM_DEVID_AUTO,
53 .reg_read = sec_qfprom_reg_read,
55 struct device *dev = &pdev->dev;
56 struct nvmem_device *nvmem;
57 struct sec_qfprom *priv;
60 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
64 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
68 priv->base = res->start;
70 econfig.size = resource_size(res);
76 nvmem = devm_nvmem_register(dev, &econfig);
78 return PTR_ERR_OR_ZERO(nvmem);
81 static const struct of_device_id sec_qfprom_of_match[] = {
82 { .compatible = "qcom,sec-qfprom" },
85 MODULE_DEVICE_TABLE(of, sec_qfprom_of_match);
87 static struct platform_driver qfprom_driver = {
88 .probe = sec_qfprom_probe,
90 .name = "qcom_sec_qfprom",
91 .of_match_table = sec_qfprom_of_match,
94 module_platform_driver(qfprom_driver);
95 MODULE_DESCRIPTION("Qualcomm Secure QFPROM driver");
96 MODULE_LICENSE("GPL");