drivers/mtd: fix C89 compatibility of w25qxxxjv

Correct various style issues

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2023-05-17 22:59:55 +03:00 committed by Xiang Xiao
parent 1be4066b3c
commit 1e86682feb

View File

@ -51,7 +51,7 @@
/* QuadSPI Mode. Per data sheet, either Mode 0 or Mode 3 may be used. */
#ifndef CONFIG_W25QXXXJV_QSPIMODE
#define CONFIG_W25QXXXJV_QSPIMODE QSPIDEV_MODE0
# define CONFIG_W25QXXXJV_QSPIMODE QSPIDEV_MODE0
#endif
/* QuadSPI Frequency per data sheet:
@ -64,7 +64,7 @@
* with all commands. up to 133MHz.
*/
#define CONFIG_W25QXXXJV_QSPI_FREQUENCY 100000000
# define CONFIG_W25QXXXJV_QSPI_FREQUENCY 100000000
#endif
#ifndef CONFIG_W25QXXXJV_DUMMIES
@ -73,7 +73,7 @@
* clock and IO command dependent.(four to six times according to data sheet)
*/
#define CONFIG_W25QXXXJV_DUMMIES 6
# define CONFIG_W25QXXXJV_DUMMIES 6
#endif
/* W25QXXXJV Commands *******************************************************/
@ -129,8 +129,8 @@
* Data sequence *
*/
#define W25QXXXJV_JEDEC_ID 0x9f /* JEDEC ID: *
* 0x9f | Manufacturer | MemoryType | *
* Capacity */
* 0x9f | Manufacturer | *
* MemoryType | Capacity */
/* Multiple Die Commands ***************************************************
* Command Value Description: *
@ -401,10 +401,10 @@ static int w25qxxxjv_write_page(FAR struct w25qxxxjv_dev_s *priv,
off_t address,
size_t nbytes);
#ifdef CONFIG_W25QXXXJV_SECTOR512
static int w25qxxxjv_flush_cache(struct w25qxxxjv_dev_s *priv);
static FAR uint8_t *w25qxxxjv_read_cache(struct w25qxxxjv_dev_s *priv,
static int w25qxxxjv_flush_cache(FAR struct w25qxxxjv_dev_s *priv);
static FAR uint8_t *w25qxxxjv_read_cache(FAR struct w25qxxxjv_dev_s *priv,
off_t sector);
static void w25qxxxjv_erase_cache(struct w25qxxxjv_dev_s *priv,
static void w25qxxxjv_erase_cache(FAR struct w25qxxxjv_dev_s *priv,
off_t sector);
static int w25qxxxjv_write_cache(FAR struct w25qxxxjv_dev_s *priv,
FAR const uint8_t *buffer,
@ -505,10 +505,8 @@ static int w25qxxxjv_command_address(FAR struct qspi_dev_s *qspi,
{
struct qspi_cmdinfo_s cmdinfo;
finfo("CMD: %02x Address: %04lx addrlen=%d\n",
cmd,
(unsigned long)addr,
addrlen);
finfo("CMD: %02x Address: %04" PRIxOFF " addrlen=%d\n",
cmd, addr, addrlen);
cmdinfo.flags = QSPICMD_ADDRESS;
cmdinfo.addrlen = addrlen;
@ -586,7 +584,7 @@ static void w25qxxxjv_write_status(FAR struct w25qxxxjv_dev_s *priv)
priv->cmdbuf[0] &= ~STATUS_SRP_MASK;
w25qxxxjv_command_write(priv->qspi, W25QXXXJV_WRITE_STATUS_1,
(FAR const void *)priv->cmdbuf, 1);
(FAR const void *)priv->cmdbuf, 1);
w25qxxxjv_write_disable(priv);
}
@ -628,14 +626,9 @@ static void w25qxxxjv_write_disable(FAR struct w25qxxxjv_dev_s *priv)
static void w25qxxxjv_set_die(FAR struct w25qxxxjv_dev_s *priv, uint8_t die)
{
char buff[1] =
{
die,
};
w25qxxxjv_write_enable(priv);
w25qxxxjv_command_write(priv->qspi, W25QXXXJV_SW_DIE_SELECT,
(FAR const void *)buff, 1);
(FAR const void *)&die, 1);
w25qxxxjv_write_disable(priv);
priv->currentdie = die;
@ -671,13 +664,7 @@ static void w25qxxxjv_quad_enable(FAR struct w25qxxxjv_dev_s *priv)
static int w25qxxxjv_get_die_from_addr(FAR struct w25qxxxjv_dev_s *priv,
off_t addr)
{
uint8_t die;
die = W25QXXXJV_DIE0;
if (addr >= priv->diesize)
{
die = W25QXXXJV_DIE1;
}
uint8_t die = addr >= priv->diesize ? W25QXXXJV_DIE1 : W25QXXXJV_DIE0;
w25qxxxjv_set_die(priv, die);
@ -688,7 +675,7 @@ static int w25qxxxjv_get_die_from_addr(FAR struct w25qxxxjv_dev_s *priv,
* Name: w25qxxxjv_readid
****************************************************************************/
static inline int w25qxxxjv_readid(struct w25qxxxjv_dev_s *priv)
static inline int w25qxxxjv_readid(FAR struct w25qxxxjv_dev_s *priv)
{
/* Lock the QuadSPI bus and configure the bus. */
@ -804,12 +791,14 @@ static inline int w25qxxxjv_readid(struct w25qxxxjv_dev_s *priv)
static int w25qxxxjv_protect(FAR struct w25qxxxjv_dev_s *priv,
off_t startblock, size_t nblocks)
{
int i;
/* Get the status register value to check the current protection */
priv->cmdbuf[0] = w25qxxxjv_read_status(priv);
if ((priv->cmdbuf[0] & priv->protectmask) ==
(STATUS_BP_ALL & priv->protectmask))
(STATUS_BP_ALL & priv->protectmask))
{
/* Protection already enabled */
@ -823,12 +812,12 @@ static int w25qxxxjv_protect(FAR struct w25qxxxjv_dev_s *priv,
/* Check the new status */
for (int i = 0; i < priv->numofdies; i++)
for (i = 0; i < priv->numofdies; i++)
{
w25qxxxjv_set_die(priv, i);
priv->cmdbuf[0] = w25qxxxjv_read_status(priv);
if ((priv->cmdbuf[0] & priv->protectmask) !=
(STATUS_BP_ALL & priv->protectmask))
(STATUS_BP_ALL & priv->protectmask))
{
return -EACCES;
}
@ -851,6 +840,8 @@ static int w25qxxxjv_protect(FAR struct w25qxxxjv_dev_s *priv,
static int w25qxxxjv_unprotect(FAR struct w25qxxxjv_dev_s *priv,
off_t startblock, size_t nblocks)
{
int i;
/* Get the status register value to check the current protection */
priv->cmdbuf[0] = w25qxxxjv_read_status(priv);
@ -872,7 +863,7 @@ static int w25qxxxjv_unprotect(FAR struct w25qxxxjv_dev_s *priv,
/* Check the new status */
for (int i = 0; i < priv->numofdies; i++)
for (i = 0; i < priv->numofdies; i++)
{
w25qxxxjv_set_die(priv, i);
priv->cmdbuf[0] = w25qxxxjv_read_status(priv);
@ -897,8 +888,7 @@ static int w25qxxxjv_unprotect(FAR struct w25qxxxjv_dev_s *priv,
****************************************************************************/
static bool w25qxxxjv_isprotected(FAR struct w25qxxxjv_dev_s *priv,
uint8_t status,
off_t address)
uint8_t status, off_t address)
{
off_t protstart;
off_t protend;
@ -942,7 +932,7 @@ static bool w25qxxxjv_isprotected(FAR struct w25qxxxjv_dev_s *priv,
/* protend already computed above */
}
return (address >= protstart && address < protend);
return address >= protstart && address < protend;
}
/****************************************************************************
@ -955,11 +945,11 @@ static int w25qxxxjv_erase_sector(FAR struct w25qxxxjv_dev_s *priv,
off_t address;
uint8_t status;
finfo("sector: %08lx\n", (unsigned long)sector);
finfo("sector: %08" PRIxOFF "\n", sector);
/* Get the address associated with the sector */
address = (off_t)sector << priv->sectorshift;
address = sector << priv->sectorshift;
/* Check that the flash is ready and unprotected */
@ -976,7 +966,7 @@ static int w25qxxxjv_erase_sector(FAR struct w25qxxxjv_dev_s *priv,
}
if ((status & priv->protectmask) != 0 &&
w25qxxxjv_isprotected(priv, status, address))
w25qxxxjv_isprotected(priv, status, address))
{
ferr("ERROR: Flash protected: %02x", status);
return -EACCES;
@ -1023,7 +1013,7 @@ static int w25qxxxjv_erase_chip(FAR struct w25qxxxjv_dev_s *priv)
status = w25qxxxjv_read_status(priv);
while ((status & STATUS_BUSY_MASK) != 0)
{
nxsig_usleep(200 *1000);
nxsig_usleep(200 * 1000);
status = w25qxxxjv_read_status(priv);
}
@ -1035,12 +1025,12 @@ static int w25qxxxjv_erase_chip(FAR struct w25qxxxjv_dev_s *priv)
****************************************************************************/
static int w25qxxxjv_read_byte(FAR struct w25qxxxjv_dev_s *priv,
FAR uint8_t *buffer,
off_t address, size_t buflen)
FAR uint8_t *buffer, off_t address,
size_t buflen)
{
struct qspi_meminfo_s meminfo;
finfo("address: %08lx nbytes: %d\n", (long)address, (int)buflen);
finfo("address: %08" PRIxOFF " nbytes: %d\n", address, (int)buflen);
meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO;
meminfo.addrlen = priv->addresslen;
@ -1058,9 +1048,9 @@ static int w25qxxxjv_read_byte(FAR struct w25qxxxjv_dev_s *priv,
* Name: w25qxxxjv_write_page
****************************************************************************/
static int w25qxxxjv_write_page(struct w25qxxxjv_dev_s *priv,
FAR const uint8_t *buffer,
off_t address, size_t buflen)
static int w25qxxxjv_write_page(FAR struct w25qxxxjv_dev_s *priv,
FAR const uint8_t *buffer, off_t address,
size_t buflen)
{
struct qspi_meminfo_s meminfo;
unsigned int pagesize;
@ -1068,9 +1058,7 @@ static int w25qxxxjv_write_page(struct w25qxxxjv_dev_s *priv,
int ret;
int i;
finfo("address: %08lx buflen: %u\n",
(unsigned long)address,
(unsigned)buflen);
finfo("address: %08" PRIxOFF " buflen: %u\n", address, (unsigned)buflen);
npages = (buflen >> priv->pageshift);
pagesize = (1 << priv->pageshift);
@ -1100,7 +1088,7 @@ static int w25qxxxjv_write_page(struct w25qxxxjv_dev_s *priv,
if (ret < 0)
{
ferr("ERROR: QSPI_MEMORY failed writing address=%06"PRIxOFF"\n",
ferr("ERROR: QSPI_MEMORY failed writing address=%06" PRIxOFF "\n",
address);
return ret;
}
@ -1126,7 +1114,7 @@ static int w25qxxxjv_write_page(struct w25qxxxjv_dev_s *priv,
****************************************************************************/
#ifdef CONFIG_W25QXXXJV_SECTOR512
static int w25qxxxjv_flush_cache(struct w25qxxxjv_dev_s *priv)
static int w25qxxxjv_flush_cache(FAR struct w25qxxxjv_dev_s *priv)
{
int ret = OK;
@ -1169,7 +1157,7 @@ static int w25qxxxjv_flush_cache(struct w25qxxxjv_dev_s *priv)
****************************************************************************/
#ifdef CONFIG_W25QXXXJV_SECTOR512
static FAR uint8_t *w25qxxxjv_read_cache(struct w25qxxxjv_dev_s *priv,
static FAR uint8_t *w25qxxxjv_read_cache(FAR struct w25qxxxjv_dev_s *priv,
off_t sector)
{
off_t esectno;
@ -1185,7 +1173,8 @@ static FAR uint8_t *w25qxxxjv_read_cache(struct w25qxxxjv_dev_s *priv,
shift = priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT;
esectno = sector >> shift;
finfo("sector: %ld esectno: %d shift=%d\n", sector, esectno, shift);
finfo("sector: %" PRIdOFF " esectno: %" PRIdOFF " shift=%d\n",
sector, esectno, shift);
/* Check if the requested erase block is already in the cache */
@ -1237,7 +1226,8 @@ static FAR uint8_t *w25qxxxjv_read_cache(struct w25qxxxjv_dev_s *priv,
****************************************************************************/
#ifdef CONFIG_W25QXXXJV_SECTOR512
static void w25qxxxjv_erase_cache(struct w25qxxxjv_dev_s *priv, off_t sector)
static void w25qxxxjv_erase_cache(FAR struct w25qxxxjv_dev_s *priv,
off_t sector)
{
FAR uint8_t *dest;
@ -1254,9 +1244,9 @@ static void w25qxxxjv_erase_cache(struct w25qxxxjv_dev_s *priv, off_t sector)
if (!IS_ERASED(priv))
{
off_t esectno = sector >>
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
finfo("sector: %ld esectno: %d\n", sector, esectno);
off_t esectno = sector >>
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
finfo("sector: %" PRIdOFF " esectno: %" PRIdOFF "\n", sector, esectno);
DEBUGVERIFY(w25qxxxjv_erase_sector(priv, esectno));
SET_ERASED(priv);
@ -1299,9 +1289,10 @@ static int w25qxxxjv_write_cache(FAR struct w25qxxxjv_dev_s *priv,
if (!IS_ERASED(priv))
{
off_t esectno = sector >>
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
finfo("sector: %ld esectno: %d\n", sector, esectno);
off_t esectno = sector >>
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
finfo("sector: %" PRIdOFF " esectno: %" PRIdOFF "\n",
sector, esectno);
ret = w25qxxxjv_erase_sector(priv, esectno);
if (ret < 0)
@ -1343,7 +1334,8 @@ static int w25qxxxjv_erase(FAR struct mtd_dev_s *dev, off_t startblock,
int ret;
#endif
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
finfo("startblock: %08" PRIxOFF " nblocks: %d\n",
startblock, (int)nblocks);
/* Lock access to the SPI bus until we complete the erase */
@ -1388,7 +1380,8 @@ static ssize_t w25qxxxjv_bread(FAR struct mtd_dev_s *dev, off_t startblock,
#endif
ssize_t nbytes;
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
finfo("startblock: %08" PRIxOFF " nblocks: %d\n",
startblock, (int)nblocks);
/* On this device, we can handle the block read just like the byte-oriented
* read
@ -1402,14 +1395,14 @@ static ssize_t w25qxxxjv_bread(FAR struct mtd_dev_s *dev, off_t startblock,
#ifdef CONFIG_W25QXXXJV_SECTOR512
nbytes = w25qxxxjv_read(dev, startblock << W25QXXXJV_SECTOR512_SHIFT,
nblocks << W25QXXXJV_SECTOR512_SHIFT, buffer);
nblocks << W25QXXXJV_SECTOR512_SHIFT, buffer);
if (nbytes > 0)
{
nbytes >>= W25QXXXJV_SECTOR512_SHIFT;
}
#else
nbytes = w25qxxxjv_read(dev, startblock << priv->pageshift,
nblocks << priv->pageshift, buffer);
nblocks << priv->pageshift, buffer);
if (nbytes > 0)
{
nbytes >>= priv->pageshift;
@ -1429,7 +1422,8 @@ static ssize_t w25qxxxjv_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
FAR struct w25qxxxjv_dev_s *priv = (FAR struct w25qxxxjv_dev_s *)dev;
int ret = (int)nblocks;
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
finfo("startblock: %08" PRIxOFF " nblocks: %d\n",
startblock, (int)nblocks);
if (priv->numofdies != 0)
{
@ -1450,7 +1444,7 @@ static ssize_t w25qxxxjv_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
#else
ret = w25qxxxjv_write_page(priv, buffer, startblock << priv->pageshift,
nblocks << priv->pageshift);
nblocks << priv->pageshift);
if (ret < 0)
{
ferr("ERROR: w25qxxxjv_write_page failed: %d\n", ret);
@ -1466,15 +1460,13 @@ static ssize_t w25qxxxjv_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
* Name: w25qxxxjv_read
****************************************************************************/
static ssize_t w25qxxxjv_read(FAR struct mtd_dev_s *dev,
off_t offset,
size_t nbytes,
FAR uint8_t *buffer)
static ssize_t w25qxxxjv_read(FAR struct mtd_dev_s *dev, off_t offset,
size_t nbytes, FAR uint8_t *buffer)
{
FAR struct w25qxxxjv_dev_s *priv = (FAR struct w25qxxxjv_dev_s *)dev;
int ret;
finfo("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
finfo("offset: %08" PRIxOFF " nbytes: %d\n", offset, (int)nbytes);
/* Lock the QuadSPI bus and select this FLASH part */
@ -1497,8 +1489,7 @@ static ssize_t w25qxxxjv_read(FAR struct mtd_dev_s *dev,
* Name: w25qxxxjv_ioctl
****************************************************************************/
static int w25qxxxjv_ioctl(FAR struct mtd_dev_s *dev,
int cmd,
static int w25qxxxjv_ioctl(FAR struct mtd_dev_s *dev, int cmd,
unsigned long arg)
{
FAR struct w25qxxxjv_dev_s *priv = (FAR struct w25qxxxjv_dev_s *)dev;
@ -1540,7 +1531,8 @@ static int w25qxxxjv_ioctl(FAR struct mtd_dev_s *dev,
#endif
ret = OK;
finfo("blocksize: %lu erasesize: %lu neraseblocks: %lu\n",
finfo("blocksize: %" PRIu16 " erasesize: %" PRIu32
" neraseblocks: %" PRIu32 "\n",
geo->blocksize, geo->erasesize, geo->neraseblocks);
}
}
@ -1554,11 +1546,11 @@ static int w25qxxxjv_ioctl(FAR struct mtd_dev_s *dev,
{
#ifdef CONFIG_W25QXXXJV_SECTOR512
info->numsectors = priv->nsectors <<
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
(priv->sectorshift - W25QXXXJV_SECTOR512_SHIFT);
info->sectorsize = 1 << W25QXXXJV_SECTOR512_SHIFT;
#else
info->numsectors = priv->nsectors <<
(priv->sectorshift - priv->pageshift);
(priv->sectorshift - priv->pageshift);
info->sectorsize = 1 << priv->pageshift;
#endif
info->startsector = 0;