[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <2265a7467850190ec99ac9ab0aaa7905@walle.cc>
Date: Tue, 25 Apr 2023 09:33:40 +0200
From: Michael Walle <michael@...le.cc>
To: "Vaibhaav Ram T.L" <vaibhaavram.tl@...rochip.com>
Cc: gregkh@...uxfoundation.org, arnd@...db.de,
kumaravel.thiagarajan@...rochip.com,
tharunkumar.pasumarthi@...rochip.com, linux-kernel@...r.kernel.org,
linux-gpio@...r.kernel.org, UNGLinuxDriver@...rochip.com
Subject: Re: [PATCH v10 char-misc-next 1/2] misc: microchip: pci1xxxx: Add
support to read and write into PCI1XXXX OTP via NVMEM sysfs
Hi,
> +static int pci1xxxx_otp_read(void *priv_t, unsigned int off,
> + void *buf_t, size_t count)
> +{
> + struct pci1xxxx_otp_eeprom_device *priv = priv_t;
> + void __iomem *rb = priv->reg_base;
> + char *buf = buf_t;
> + u32 regval;
> + u32 byte;
> + int ret;
> + u8 data;
> +
> + if (off >= priv->nvmem_config_otp.size)
> + return -EFAULT;
> +
> + if ((off + count) > priv->nvmem_config_otp.size)
> + count = priv->nvmem_config_otp.size - off;
> +
> + ret = set_sys_lock(priv);
> + if (ret)
> + return ret;
> +
> + for (byte = 0; byte < count; byte++) {
> + otp_device_set_address(priv, (u16)(off + byte));
> + data = readl(rb + MMAP_OTP_OFFSET(OTP_FUNC_CMD_OFFSET));
> + writel(data | OTP_FUNC_RD_BIT,
> + rb + MMAP_OTP_OFFSET(OTP_FUNC_CMD_OFFSET));
> + data = readl(rb + MMAP_OTP_OFFSET(OTP_CMD_GO_OFFSET));
> + writel(data | OTP_CMD_GO_BIT,
> + rb + MMAP_OTP_OFFSET(OTP_CMD_GO_OFFSET));
> +
> + ret = read_poll_timeout(readl, regval,
> + !(regval & OTP_STATUS_BUSY_BIT),
> + STATUS_READ_DELAY_US,
> + STATUS_READ_TIMEOUT_US, true,
> + rb + MMAP_OTP_OFFSET(OTP_STATUS_OFFSET));
> +
> + data = readl(rb + MMAP_OTP_OFFSET(OTP_PASS_FAIL_OFFSET));
> + if (ret < 0 || data & OTP_FAIL_BIT)
> + return -EIO;
Don't you need to release the lock?
> +
> + buf[byte] = readl(rb + MMAP_OTP_OFFSET(OTP_RD_DATA_OFFSET));
> + }
> + release_sys_lock(priv);
> +
> + return byte;
> +}
Powered by blists - more mailing lists