nvmem: imx-ocotp: replace global post processing with layouts

In preparation of retiring the global post processing hook change this
driver to use layouts. The layout will be supplied during registration
and will be used to add the post processing hook to all added cells.

Signed-off-by: Michael Walle <michael@walle.cc>
Tested-by: Michael Walle <michael@walle.cc> # on kontron-pitx-imx8m
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-19-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Michael Walle 2023-04-04 18:21:26 +01:00 committed by Greg Kroah-Hartman
parent de12c96915
commit 6c56a82d78

View file

@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset,
static int imx_ocotp_cell_pp(void *context, const char *id, int index,
unsigned int offset, void *data, size_t bytes)
{
struct ocotp_priv *priv = context;
u8 *buf = data;
int i;
/* Deal with some post processing of nvmem cell data */
if (id && !strcmp(id, "mac-address")) {
if (priv->params->reverse_mac_address) {
u8 *buf = data;
int i;
for (i = 0; i < bytes/2; i++)
swap(buf[i], buf[bytes - i - 1]);
}
}
if (id && !strcmp(id, "mac-address"))
for (i = 0; i < bytes / 2; i++)
swap(buf[i], buf[bytes - i - 1]);
return 0;
}
@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = {
.stride = 1,
.reg_read = imx_ocotp_read,
.reg_write = imx_ocotp_write,
.cell_post_process = imx_ocotp_cell_pp,
};
static const struct ocotp_params imx6q_params = {
@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem,
struct nvmem_layout *layout,
struct nvmem_cell_info *cell)
{
cell->read_post_process = imx_ocotp_cell_pp;
}
struct nvmem_layout imx_ocotp_layout = {
.fixup_cell_info = imx_ocotp_fixup_cell_info,
};
static int imx_ocotp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev)
imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
imx_ocotp_nvmem_config.dev = dev;
imx_ocotp_nvmem_config.priv = priv;
if (priv->params->reverse_mac_address)
imx_ocotp_nvmem_config.layout = &imx_ocotp_layout;
priv->config = &imx_ocotp_nvmem_config;
clk_prepare_enable(priv->clk);