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
= {
50 .add_legacy_fixed_of_cells
= true,
53 .id
= NVMEM_DEVID_AUTO
,
54 .reg_read
= sec_qfprom_reg_read
,
56 struct device
*dev
= &pdev
->dev
;
57 struct nvmem_device
*nvmem
;
58 struct sec_qfprom
*priv
;
61 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
65 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
69 priv
->base
= res
->start
;
71 econfig
.size
= resource_size(res
);
77 nvmem
= devm_nvmem_register(dev
, &econfig
);
79 return PTR_ERR_OR_ZERO(nvmem
);
82 static const struct of_device_id sec_qfprom_of_match
[] = {
83 { .compatible
= "qcom,sec-qfprom" },
86 MODULE_DEVICE_TABLE(of
, sec_qfprom_of_match
);
88 static struct platform_driver qfprom_driver
= {
89 .probe
= sec_qfprom_probe
,
91 .name
= "qcom_sec_qfprom",
92 .of_match_table
= sec_qfprom_of_match
,
95 module_platform_driver(qfprom_driver
);
96 MODULE_DESCRIPTION("Qualcomm Secure QFPROM driver");
97 MODULE_LICENSE("GPL");