Commit 6c56a82d authored by Michael Walle's avatar Michael Walle Committed by Greg Kroah-Hartman
Browse files

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: default avatarMichael Walle <michael@walle.cc>
Tested-by: Michael Walle <michael@walle.cc> # on kontron-pitx-imx8m
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-19-srinivas.kandagatla@linaro.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent de12c969
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -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;

	/* 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;

	/* Deal with some post processing of nvmem cell data */
	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);