Lines Matching +full:non +full:- +full:secure +full:- +full:otp

1 // SPDX-License-Identifier: GPL-2.0
3 * STM32 Factory-programmed memory read access driver
5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
9 #include <linux/arm-smccc.h>
12 #include <linux/nvmem-provider.h>
15 /* BSEC secure service access from non-secure */
25 /* 32 (x 32-bits) lower shadow registers */
45 *buf8++ = readb_relaxed(priv->base + i); in stm32_romem_read()
50 static int stm32_bsec_smc(u8 op, u32 otp, u32 data, u32 *result) in stm32_bsec_smc() argument
55 arm_smccc_smc(STM32_SMC_BSEC, op, otp, data, 0, 0, 0, 0, &res); in stm32_bsec_smc()
57 return -EIO; in stm32_bsec_smc()
64 return -ENXIO; in stm32_bsec_smc()
72 struct device *dev = priv->cfg.dev; in stm32_bsec_read()
77 /* Round unaligned access to 32-bits */ in stm32_bsec_read()
82 if (roffset + rbytes > priv->cfg.size) in stm32_bsec_read()
83 return -EINVAL; in stm32_bsec_read()
86 u32 otp = i >> 2; in stm32_bsec_read() local
88 if (otp < STM32MP15_BSEC_NUM_LOWER) { in stm32_bsec_read()
91 priv->base + STM32MP15_BSEC_DATA0 + i); in stm32_bsec_read()
93 ret = stm32_bsec_smc(STM32_SMC_READ_SHADOW, otp, 0, in stm32_bsec_read()
96 dev_err(dev, "Can't read data%d (%d)\n", otp, in stm32_bsec_read()
103 size = min(bytes, (size_t)(4 - skip_bytes)); in stm32_bsec_read()
107 bytes -= size; in stm32_bsec_read()
119 struct device *dev = priv->cfg.dev; in stm32_bsec_write()
123 /* Allow only writing complete 32-bits aligned words */ in stm32_bsec_write()
125 return -EINVAL; in stm32_bsec_write()
142 struct device *dev = &pdev->dev; in stm32_romem_probe()
148 return -ENOMEM; in stm32_romem_probe()
151 priv->base = devm_ioremap_resource(dev, res); in stm32_romem_probe()
152 if (IS_ERR(priv->base)) in stm32_romem_probe()
153 return PTR_ERR(priv->base); in stm32_romem_probe()
155 priv->cfg.name = "stm32-romem"; in stm32_romem_probe()
156 priv->cfg.word_size = 1; in stm32_romem_probe()
157 priv->cfg.stride = 1; in stm32_romem_probe()
158 priv->cfg.dev = dev; in stm32_romem_probe()
159 priv->cfg.priv = priv; in stm32_romem_probe()
160 priv->cfg.owner = THIS_MODULE; in stm32_romem_probe()
163 of_match_device(dev->driver->of_match_table, dev)->data; in stm32_romem_probe()
165 priv->cfg.read_only = true; in stm32_romem_probe()
166 priv->cfg.size = resource_size(res); in stm32_romem_probe()
167 priv->cfg.reg_read = stm32_romem_read; in stm32_romem_probe()
169 priv->cfg.size = cfg->size; in stm32_romem_probe()
170 priv->cfg.reg_read = stm32_bsec_read; in stm32_romem_probe()
171 priv->cfg.reg_write = stm32_bsec_write; in stm32_romem_probe()
174 return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &priv->cfg)); in stm32_romem_probe()
178 .size = 384, /* 96 x 32-bits data words */
182 { .compatible = "st,stm32f4-otp", }, {
183 .compatible = "st,stm32mp15-bsec",
193 .name = "stm32-romem",
200 MODULE_DESCRIPTION("STMicroelectronics STM32 RO-MEM");
201 MODULE_ALIAS("platform:nvmem-stm32-romem");