From: Boris Brezillon <boris.brezillon@bootlin.com>
To: <Tudor.Ambarus@microchip.com>
Cc: <marek.vasut@gmail.com>, <dwmw2@infradead.org>,
<computersforpeace@gmail.com>, <richard@nod.at>,
<linux-mtd@lists.infradead.org>
Subject: Re: [PATCH v2 2/6] mtd: spi-nor: Avoid forward declaration of internal functions
Date: Wed, 5 Dec 2018 09:09:26 +0100 [thread overview]
Message-ID: <20181205090926.7326eaff@bbrezillon> (raw)
In-Reply-To: <8ef2fdbf-35cd-bbe5-5fcf-d890546328da@microchip.com>
On Tue, 4 Dec 2018 19:09:04 +0000
<Tudor.Ambarus@microchip.com> wrote:
> Hi, Boris,
>
> On 11/29/2018 04:10 PM, Boris Brezillon wrote:
> > Reorganize the code to kill forward declarations of spi_nor_match_id()
> > macronix_quad_enable() and spi_nor_hwcaps_read2cmd().
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
> > ---
> > Changes in v2:
> > - None
> > ---
> > drivers/mtd/spi-nor/spi-nor.c | 202 +++++++++++++++++-----------------
> > 1 file changed, 98 insertions(+), 104 deletions(-)
> >
> > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> > index 0aa1b1035b4b..e1eaabf98d08 100644
> > --- a/drivers/mtd/spi-nor/spi-nor.c
> > +++ b/drivers/mtd/spi-nor/spi-nor.c
> > @@ -96,8 +96,6 @@ struct flash_info {
> >
> > #define JEDEC_MFR(info) ((info)->id[0])
> >
> > -static const struct flash_info *spi_nor_match_id(const char *name);
> > -
> > /*
> > * Read the status register, returning its value in the location
> > * Return the status register value.
> > @@ -1202,7 +1200,42 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> > return ret;
> > }
> >
> > -static int macronix_quad_enable(struct spi_nor *nor);
> > +/**
> > + * macronix_quad_enable() - set QE bit in Status Register.
> > + * @nor: pointer to a 'struct spi_nor'
> > + *
> > + * Set the Quad Enable (QE) bit in the Status Register.
> > + *
> > + * bit 6 of the Status Register is the QE bit for Macronix like QSPI memories.
> > + *
> > + * Return: 0 on success, -errno otherwise.
> > + */
> > +static int macronix_quad_enable(struct spi_nor *nor)
> > +{
> > + int ret, val;
> > +
> > + val = read_sr(nor);
> > + if (val < 0)
> > + return val;
> > + if (val & SR_QUAD_EN_MX)
> > + return 0;
> > +
> > + write_enable(nor);
> > +
> > + write_sr(nor, val | SR_QUAD_EN_MX);
> > +
> > + ret = spi_nor_wait_till_ready(nor);
> > + if (ret)
> > + return ret;
> > +
> > + ret = read_sr(nor);
> > + if (!(ret > 0 && (ret & SR_QUAD_EN_MX))) {
> > + dev_err(nor->dev, "Macronix Quad bit not set\n");
> > + return -EINVAL;
> > + }
> > +
> > + return 0;
> > +}
>
> The *_quad_enable() functions are now spread in the file. Would it make sense to
> move all the *_quad_enable() functions, to keep them together?
Yep, will do.
>
> >
> > /* Used when the "_ext_id" is two bytes at most */
> > #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
> > @@ -1778,43 +1811,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
> > return ret;
> > }
> >
> > -/**
> > - * macronix_quad_enable() - set QE bit in Status Register.
> > - * @nor: pointer to a 'struct spi_nor'
> > - *
> > - * Set the Quad Enable (QE) bit in the Status Register.
> > - *
> > - * bit 6 of the Status Register is the QE bit for Macronix like QSPI memories.
> > - *
> > - * Return: 0 on success, -errno otherwise.
> > - */
> > -static int macronix_quad_enable(struct spi_nor *nor)
> > -{
> > - int ret, val;
> > -
> > - val = read_sr(nor);
> > - if (val < 0)
> > - return val;
> > - if (val & SR_QUAD_EN_MX)
> > - return 0;
> > -
> > - write_enable(nor);
> > -
> > - write_sr(nor, val | SR_QUAD_EN_MX);
> > -
> > - ret = spi_nor_wait_till_ready(nor);
> > - if (ret)
> > - return ret;
> > -
> > - ret = read_sr(nor);
> > - if (!(ret > 0 && (ret & SR_QUAD_EN_MX))) {
> > - dev_err(nor->dev, "Macronix Quad bit not set\n");
> > - return -EINVAL;
> > - }
> > -
> > - return 0;
> > -}
> > -
> > /*
> > * Write status Register and configuration register with 2 bytes
> > * The first byte will be written to the status register, while the
> > @@ -2479,7 +2475,56 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {
> > {BFPT_DWORD(9), 16},
> > };
> >
> > -static int spi_nor_hwcaps_read2cmd(u32 hwcaps);
> > +static int spi_nor_hwcaps2cmd(u32 hwcaps, const int table[][2], size_t size)
> > +{
> > + size_t i;
> > +
> > + for (i = 0; i < size; i++)
> > + if (table[i][0] == (int)hwcaps)
> > + return table[i][1];
> > +
> > + return -EINVAL;
> > +}
> > +
> > +static int spi_nor_hwcaps_read2cmd(u32 hwcaps)
> > +{
> > + static const int hwcaps_read2cmd[][2] = {
> > + { SNOR_HWCAPS_READ, SNOR_CMD_READ },
> > + { SNOR_HWCAPS_READ_FAST, SNOR_CMD_READ_FAST },
> > + { SNOR_HWCAPS_READ_1_1_1_DTR, SNOR_CMD_READ_1_1_1_DTR },
> > + { SNOR_HWCAPS_READ_1_1_2, SNOR_CMD_READ_1_1_2 },
> > + { SNOR_HWCAPS_READ_1_2_2, SNOR_CMD_READ_1_2_2 },
> > + { SNOR_HWCAPS_READ_2_2_2, SNOR_CMD_READ_2_2_2 },
> > + { SNOR_HWCAPS_READ_1_2_2_DTR, SNOR_CMD_READ_1_2_2_DTR },
> > + { SNOR_HWCAPS_READ_1_1_4, SNOR_CMD_READ_1_1_4 },
> > + { SNOR_HWCAPS_READ_1_4_4, SNOR_CMD_READ_1_4_4 },
> > + { SNOR_HWCAPS_READ_4_4_4, SNOR_CMD_READ_4_4_4 },
> > + { SNOR_HWCAPS_READ_1_4_4_DTR, SNOR_CMD_READ_1_4_4_DTR },
> > + { SNOR_HWCAPS_READ_1_1_8, SNOR_CMD_READ_1_1_8 },
> > + { SNOR_HWCAPS_READ_1_8_8, SNOR_CMD_READ_1_8_8 },
> > + { SNOR_HWCAPS_READ_8_8_8, SNOR_CMD_READ_8_8_8 },
> > + { SNOR_HWCAPS_READ_1_8_8_DTR, SNOR_CMD_READ_1_8_8_DTR },
> > + };
> > +
> > + return spi_nor_hwcaps2cmd(hwcaps, hwcaps_read2cmd,
> > + ARRAY_SIZE(hwcaps_read2cmd));
> > +}
> > +
> > +static int spi_nor_hwcaps_pp2cmd(u32 hwcaps)
> > +{
> > + static const int hwcaps_pp2cmd[][2] = {
> > + { SNOR_HWCAPS_PP, SNOR_CMD_PP },
> > + { SNOR_HWCAPS_PP_1_1_4, SNOR_CMD_PP_1_1_4 },
> > + { SNOR_HWCAPS_PP_1_4_4, SNOR_CMD_PP_1_4_4 },
> > + { SNOR_HWCAPS_PP_4_4_4, SNOR_CMD_PP_4_4_4 },
> > + { SNOR_HWCAPS_PP_1_1_8, SNOR_CMD_PP_1_1_8 },
> > + { SNOR_HWCAPS_PP_1_8_8, SNOR_CMD_PP_1_8_8 },
> > + { SNOR_HWCAPS_PP_8_8_8, SNOR_CMD_PP_8_8_8 },
> > + };
> > +
> > + return spi_nor_hwcaps2cmd(hwcaps, hwcaps_pp2cmd,
> > + ARRAY_SIZE(hwcaps_pp2cmd));
> > +}
>
> Would it be a better place to put these immediately after
> spi_nor_set_pp_settings()? It would be consistent with how they were declared
> back in cfc5604c488ccd17936b69008af0c9ae050f4a08.
I thought it would be preferable to have the xx2cmd[] conversion tables
grouped together, but I can move this one next to
spi_nor_set_pp_settings() if you prefer.
next prev parent reply other threads:[~2018-12-05 8:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-29 14:10 [PATCH v2 0/6] mtd: spi-nor: Random cleanups Boris Brezillon
2018-11-29 14:10 ` [PATCH v2 1/6] mtd: spi-nor: Drop inline on all internal helpers Boris Brezillon
2018-11-29 16:16 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-04 17:01 ` Tudor.Ambarus
2018-11-29 14:10 ` [PATCH v2 2/6] mtd: spi-nor: Avoid forward declaration of internal functions Boris Brezillon
2018-12-04 19:09 ` Tudor.Ambarus
2018-12-05 8:09 ` Boris Brezillon [this message]
2018-12-05 8:40 ` Tudor.Ambarus
2018-11-29 14:10 ` [PATCH v2 3/6] mtd: spi-nor: Stop passing info to set_4byte() Boris Brezillon
2018-11-29 16:23 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-04 19:35 ` Tudor.Ambarus
2018-12-04 19:37 ` Boris Brezillon
2018-11-29 14:10 ` [PATCH v2 4/6] mtd: spi-nor: Make the enable argument passed to set_byte() a bool Boris Brezillon
2018-12-04 19:38 ` Tudor.Ambarus
2018-11-29 14:10 ` [PATCH v2 5/6] mtd: spi-nor: Add an SPDX tag to spi-nor.c Boris Brezillon
2018-11-29 16:29 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-04 19:45 ` Tudor.Ambarus
2018-12-05 8:09 ` Boris Brezillon
2018-11-29 14:10 ` [PATCH v2 6/6] mtd: spi-nor: Move the nor->info assignment earlier in the scan func Boris Brezillon
2018-11-29 16:35 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2018-12-04 20:24 ` Tudor.Ambarus
2018-12-04 20:21 ` Tudor.Ambarus
2018-12-05 8:11 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181205090926.7326eaff@bbrezillon \
--to=boris.brezillon@bootlin.com \
--cc=Tudor.Ambarus@microchip.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=richard@nod.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox