static int imx_scu_ocotp_write()

in imx-ocotp-scu.c [180:219]


static int imx_scu_ocotp_write(void *context, unsigned int offset,
			       void *val, size_t bytes)
{
	struct ocotp_priv *priv = context;
	struct arm_smccc_res res;
	u32 *buf = val;
	u32 tmp;
	u32 index;
	int ret;

	/* allow only writing one complete OTP word at a time */
	if (bytes != 4)
		return -EINVAL;

	index = offset;

	if (in_hole(context, index))
		return -EINVAL;

	if (in_ecc(context, index)) {
		pr_warn("ECC region, only program once\n");
		mutex_lock(&scu_ocotp_mutex);
		ret = imx_sc_misc_otp_fuse_read(priv->nvmem_ipc, index, &tmp);
		mutex_unlock(&scu_ocotp_mutex);
		if (ret)
			return ret;
		if (tmp) {
			pr_warn("ECC region, already has value: %x\n", tmp);
			return -EIO;
		}
	}

	mutex_lock(&scu_ocotp_mutex);

	arm_smccc_smc(IMX_SIP_OTP_WRITE, index, *buf, 0, 0, 0, 0, 0, &res);

	mutex_unlock(&scu_ocotp_mutex);

	return res.a0;
}