All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Grinberg <grinberg@compulab.co.il>
To: Lei Wen <adrian.wenl@gmail.com>
Cc: Eric Miao <eric.y.miao@gmail.com>,
	David Woodhouse <David.Woodhouse@intel.com>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	Lei Wen <leiwen@marvell.com>,
	Haojian Zhuang <haojian.zhuang@gmail.com>,
	linux-mtd@lists.infradead.org,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] MTD: pxa3xx_nand: enable multiple chip select support
Date: Thu, 23 Jun 2011 13:44:16 +0300	[thread overview]
Message-ID: <4E031900.50108@compulab.co.il> (raw)
In-Reply-To: <BANLkTi=YFeVYfsp+68OA_vCF6LnJpqF-ag@mail.gmail.com>

Hi Lei,

On 06/23/11 09:35, Lei Wen wrote:
> Hi Igor,
>
> On Wed, Jun 22, 2011 at 9:45 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>> On 06/22/11 06:17, Lei Wen wrote:
>>> Current pxa3xx_nand controller has two chip select which
>>> both be workable. This patch enable this feature.
>>>
>>> Update platform driver to support this feature.
>>>
>>> Another notice should be taken that:
>>> When you want to use this feature, you should not enable the
>>> keep configuration feature, for two chip select could be
>>> attached with different nand chip. The different page size
>>> and timing requirement make the keep configuration impossible.
>> You should _also_ put this comment inside the pxa3xx_nand.h
>> may be even inside the pxa3xx_nand_platform_data structure,
>> so people would not have to search the git log to find this problem.
> How about just throw out a BUG() to force people cannot set keep_config
> when supported cs num more than 1? Also appended with the comments above?

I don't think BUG() is a good idea, instead what you can do
is force the user of the _new_ feature to _not_ use the keep_config
by overriding the keep_config to 0 and printing a warning
that keep_config is prohibited with multiple chip selects feature and
that it will be disabled.
Of course you will still need to put a comment inside the pxa3xx_nand.h.

>>> Signed-off-by: Lei Wen <leiwen@marvell.com>
>>> ---
>>>  arch/arm/mach-mmp/aspenite.c                 |    5 +-
>>>  arch/arm/mach-pxa/cm-x300.c                  |    5 +-
>>>  arch/arm/mach-pxa/colibri-pxa3xx.c           |    5 +-
>>>  arch/arm/mach-pxa/littleton.c                |    5 +-
>>>  arch/arm/mach-pxa/mxm8x10.c                  |    9 +-
>>>  arch/arm/mach-pxa/raumfeld.c                 |    5 +-
>>>  arch/arm/mach-pxa/zylonite.c                 |    5 +-
>>>  arch/arm/plat-pxa/include/plat/pxa3xx_nand.h |    8 +-
>>>  drivers/mtd/nand/pxa3xx_nand.c               |  735 +++++++++++++++-----------
>>>  9 files changed, 444 insertions(+), 338 deletions(-)

[...]

>>> diff --git a/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h b/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> index 442301f..34a3f52 100644
>>> --- a/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> +++ b/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> @@ -41,6 +41,8 @@ struct pxa3xx_nand_flash {
>>>       struct pxa3xx_nand_timing *timing;      /* NAND Flash timing */
>>>  };
>>>
>>> +/* The max num of chip select current support */
>> /* The maximum number of chip selects currently supported */
>>
>>> +#define NUM_CHIP_SELECT              (2)
>>>  struct pxa3xx_nand_platform_data {
>>>
>>>       /* the data flash bus is shared between the Static Memory
>>> @@ -52,8 +54,10 @@ struct pxa3xx_nand_platform_data {
>>>       /* allow platform code to keep OBM/bootloader defined NFC config */
>>>       int     keep_config;
>>>
>>> -     const struct mtd_partition              *parts;
>>> -     unsigned int                            nr_parts;
>>> +     /* indicate how many chip select would be used for this platform */
>> /* indicate how many chip selects will be used */
>>
>>> +     int     cs_num;
>> This name is too confusing, I think even num_cs is better or cs_count?
>> Also, may be align it with the others?
>  I prefer the num_cs.

Good.

>>> +     const struct mtd_partition              *parts[NUM_CHIP_SELECT];
>>> +     unsigned int                            nr_parts[NUM_CHIP_SELECT];
>>>
>>>       const struct pxa3xx_nand_flash *        flash;
>>>       size_t                                  num_flash;
>>> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
>>> index 30689cc..259b8d5 100644
>>> --- a/drivers/mtd/nand/pxa3xx_nand.c
>>> +++ b/drivers/mtd/nand/pxa3xx_nand.c

[...]

>>> @@ -123,63 +126,63 @@ enum {
>>>  struct pxa3xx_nand_info {
>>>       struct nand_chip        nand_chip;
>>>
>>> -     struct nand_hw_control  controller;
>>> -     struct platform_device   *pdev;
>>>       struct pxa3xx_nand_cmdset *cmdset;
>>> +     /* page size of attached chip */
>>> +     uint16_t                page_size;
>>> +     uint8_t                 chip_select;
>>> +     uint8_t                 use_ecc;
>>> +
>>> +     /* calculated from pxa3xx_nand_flash data */
>>> +     uint8_t                 col_addr_cycles;
>>> +     uint8_t                 row_addr_cycles;
>>> +     uint8_t                 read_id_bytes;
>>> +
>>> +     /* cached register value */
>>> +     uint32_t                reg_ndcr;
>>> +     uint32_t                ndtr0cs0;
>>> +     uint32_t                ndtr1cs0;
>>>
>>> +     void                    *nand_data;
>>> +};
>>> +
>>> +struct pxa3xx_nand {
>>>       struct clk              *clk;
>>>       void __iomem            *mmio_base;
>>>       unsigned long           mmio_phys;
>>> +     struct nand_hw_control  controller;
>>> +     struct completion       cmd_complete;
>>> +     struct platform_device   *pdev;
>> please, align
> Do you still mean cs_num? What this comment refer to?

No, I mean the white space before *pdev - it is not aligned with all others

>>> -     unsigned int            buf_start;
>>> -     unsigned int            buf_count;
>>> -
>>> -     struct mtd_info         *mtd;
>>>       /* DMA information */
>>>       int                     drcmr_dat;
>>>       int                     drcmr_cmd;
>>> -
>>> -     unsigned char           *data_buff;
>>> -     unsigned char           *oob_buff;
>>> -     dma_addr_t              data_buff_phys;
>>> -     size_t                  data_buff_size;
>>>       int                     data_dma_ch;
>>> -     struct pxa_dma_desc     *data_desc;
>>> +     dma_addr_t              data_buff_phys;
>>>       dma_addr_t              data_desc_addr;
>>> +     struct pxa_dma_desc     *data_desc;
>>>
>>> -     uint32_t                reg_ndcr;
>>> -
>>> -     /* saved column/page_addr during CMD_SEQIN */
>>> -     int                     seqin_column;
>>> -     int                     seqin_page_addr;
>>> +     struct pxa3xx_nand_info *info[NUM_CHIP_SELECT];
>>> +     uint32_t                command;
>>> +     uint16_t                data_size;      /* data size in FIFO */
>>> +     uint16_t                oob_size;
>>> +     unsigned char           *data_buff;
>>> +     unsigned char           *oob_buff;
>>> +     uint32_t                buf_start;
>>> +     uint32_t                buf_count;
>>>
>>>       /* relate to the command */
>>>       unsigned int            state;
>>> -
>>> +     uint8_t                 chip_select;
>>>       int                     use_ecc;        /* use HW ECC ? */
>>>       int                     use_dma;        /* use DMA ? */
>>>       int                     is_ready;
>>> -
>>> -     unsigned int            page_size;      /* page size of attached chip */
>>> -     unsigned int            data_size;      /* data size in FIFO */
>>>       int                     retcode;
>>> -     struct completion       cmd_complete;
>>>
>>>       /* generated NDCBx register values */
>>> +     uint8_t                 total_cmds;
>>>       uint32_t                ndcb0;
>>>       uint32_t                ndcb1;
>>>       uint32_t                ndcb2;
>>> -
>>> -     /* timing calcuted from setting */
>>> -     uint32_t                ndtr0cs0;
>>> -     uint32_t                ndtr1cs0;
>>> -
>>> -     /* calculated from pxa3xx_nand_flash data */
>>> -     size_t          oob_size;
>>> -     size_t          read_id_bytes;
>>> -
>>> -     unsigned int    col_addr_cycles;
>>> -     unsigned int    row_addr_cycles;
>>>  };
>> It looks like if you switch the names of the structures above,
>> then the patch will be much shorter and cleaner,
>> but will it make structures meaning confusion?
> Could you elaborate more about this? Do you means no need to create a seperated
> structure?

No, if you have 2 chips, then certainly you'd better have a separate
structure for the chip description.

What I was wondering, is that there are many places in the patch where
you change the "info" to "nand", may be this can be avoided if you keep
the structure that describes the controller ("pxa3xx_nand" in the patch)
named "pxa3xx_nand_info" and the new structure that describes the chip
will be named something else like pxa3xx_nand_chip or anything like this.
This way, your patch will not have to change the "info" to "nand" in many
places (or maybe even all places) and will be much shorter and will include
only functional changes.



[...]

>>>  static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
>>>  {
>>> -     struct pxa3xx_nand_info *info = devid;
>>> -     unsigned int status, is_completed = 0;
>>> +     struct pxa3xx_nand *nand = devid;
>>> +     struct pxa3xx_nand_info *info;
>>> +     unsigned int status, is_completed = 0, cs;
>>> +     unsigned int ready, cmd_done, page_done, badblock_detect;
>>>
>>> -     status = nand_readl(info, NDSR);
>>> +     cs              = nand->chip_select;
>>> +     ready           = (cs) ? NDSR_RDY : NDSR_FLASH_RDY;
>>> +     cmd_done        = (cs) ? NDSR_CS1_CMDD : NDSR_CS0_CMDD;
>>> +     page_done       = (cs) ? NDSR_CS1_PAGED : NDSR_CS0_PAGED;
>>> +     badblock_detect = (cs) ? NDSR_CS1_BBD : NDSR_CS0_BBD;
>> This is confusing... do you use to ?: operator for differentiating between
>> cs = 0 and cs = 1?
>> I think this is a bad idea.
>> Moreover, the use of ?: is discouraged among the kernel.
> I could use if/else to replace this statement.

or switch, what ever you like, but please, don't leave it like
if (cs) ..., because this is confusing it has a meaning of "cs is good or bad?",
while actually, you want to know if it is 0 or 1 (both values are good).


[...]

>>> -static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
>>> +static int prepare_command_pool(struct pxa3xx_nand *nand, int command,
>>>               uint16_t column, int page_addr)
>>>  {
>>>       uint16_t cmd;
>>>       int addr_cycle, exec_cmd, ndcb0;
>>> -     struct mtd_info *mtd = info->mtd;
>>> +     struct mtd_info *mtd;
>>> +     struct pxa3xx_nand_info *info = nand->info[nand->chip_select];
>>>
>>> -     ndcb0 = 0;
>>> +     mtd = get_mtd_by_info(info);
>>> +     ndcb0 = (nand->chip_select) ? NDCB0_CSEL : 0;
>> This one is confusing too...
>> Besides, you don't need the parenthesis.
> Got that. I would fix it.

Good, my previous explanation also applies here.
Thanks


[...]

>>>  static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
>>>  {
>>> -     struct mtd_info *mtd = info->mtd;
>>> +     struct pxa3xx_nand *nand = info->nand_data;
>>> +     struct mtd_info *mtd = get_mtd_by_info(info);
>>>       struct nand_chip *chip = mtd->priv;
>>>
>>>       /* use the common timing to make a try */
>>> -     pxa3xx_nand_config_flash(info, &builtin_flash_types[0]);
>>> +     if (pxa3xx_nand_config_flash(info, &builtin_flash_types[0]))
>>> +             return 0;
>>>       chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0);
>>> -     if (info->is_ready)
>>> +     if (nand->is_ready)
>>>               return 1;
>>>       else
>>>               return 0;
>> I think it is time to change this function return convention to propagate
>> errors and not just 0 or 1, (may be in separate patch) what do you think?
> How about return 0 when sensing the READY signal, or return -ENODEV?

Yes, this should be fine, but also don't forget about
pxa3xx_nand_config_flash() function call - it can return 0 or -EINVAL
and it should also propagate instead of being squashed.

>>> @@ -882,7 +908,8 @@ static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
>>>  static int pxa3xx_nand_scan(struct mtd_info *mtd)
>>>  {
>>>       struct pxa3xx_nand_info *info = mtd->priv;
>>> -     struct platform_device *pdev = info->pdev;
>>> +     struct pxa3xx_nand *nand = info->nand_data;
>>> +     struct platform_device *pdev = nand->pdev;
>>>       struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
>>>       struct nand_flash_dev pxa3xx_flash_ids[2], *def = NULL;
>>>       const struct pxa3xx_nand_flash *f = NULL;
>>> @@ -891,27 +918,25 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
>>>       uint64_t chipsize;
>>>       int i, ret, num;
>>>
>>> +     nand->chip_select = info->chip_select;
>>>       if (pdata->keep_config && !pxa3xx_nand_detect_config(info))
>>>               goto KEEP_CONFIG;
>>>
>>>       ret = pxa3xx_nand_sensing(info);
>>>       if (!ret) {
>>> -             kfree(mtd);
>>> -             info->mtd = NULL;
>>> -             printk(KERN_INFO "There is no nand chip on cs 0!\n");
>>> +             free_cs_resource(info, nand->chip_select);
>>> +             printk(KERN_INFO "There is no nand chip on cs %d!\n",
>>> +                             nand->chip_select);
>>>
>>>               return -EINVAL;

after the change of pxa3xx_nand_sensing() function,
you should change the above "return -EINVAL;" into "return ret;"



[...]


-- 
Regards,
Igor.

WARNING: multiple messages have this Message-ID (diff)
From: grinberg@compulab.co.il (Igor Grinberg)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] MTD: pxa3xx_nand: enable multiple chip select support
Date: Thu, 23 Jun 2011 13:44:16 +0300	[thread overview]
Message-ID: <4E031900.50108@compulab.co.il> (raw)
In-Reply-To: <BANLkTi=YFeVYfsp+68OA_vCF6LnJpqF-ag@mail.gmail.com>

Hi Lei,

On 06/23/11 09:35, Lei Wen wrote:
> Hi Igor,
>
> On Wed, Jun 22, 2011 at 9:45 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>> On 06/22/11 06:17, Lei Wen wrote:
>>> Current pxa3xx_nand controller has two chip select which
>>> both be workable. This patch enable this feature.
>>>
>>> Update platform driver to support this feature.
>>>
>>> Another notice should be taken that:
>>> When you want to use this feature, you should not enable the
>>> keep configuration feature, for two chip select could be
>>> attached with different nand chip. The different page size
>>> and timing requirement make the keep configuration impossible.
>> You should _also_ put this comment inside the pxa3xx_nand.h
>> may be even inside the pxa3xx_nand_platform_data structure,
>> so people would not have to search the git log to find this problem.
> How about just throw out a BUG() to force people cannot set keep_config
> when supported cs num more than 1? Also appended with the comments above?

I don't think BUG() is a good idea, instead what you can do
is force the user of the _new_ feature to _not_ use the keep_config
by overriding the keep_config to 0 and printing a warning
that keep_config is prohibited with multiple chip selects feature and
that it will be disabled.
Of course you will still need to put a comment inside the pxa3xx_nand.h.

>>> Signed-off-by: Lei Wen <leiwen@marvell.com>
>>> ---
>>>  arch/arm/mach-mmp/aspenite.c                 |    5 +-
>>>  arch/arm/mach-pxa/cm-x300.c                  |    5 +-
>>>  arch/arm/mach-pxa/colibri-pxa3xx.c           |    5 +-
>>>  arch/arm/mach-pxa/littleton.c                |    5 +-
>>>  arch/arm/mach-pxa/mxm8x10.c                  |    9 +-
>>>  arch/arm/mach-pxa/raumfeld.c                 |    5 +-
>>>  arch/arm/mach-pxa/zylonite.c                 |    5 +-
>>>  arch/arm/plat-pxa/include/plat/pxa3xx_nand.h |    8 +-
>>>  drivers/mtd/nand/pxa3xx_nand.c               |  735 +++++++++++++++-----------
>>>  9 files changed, 444 insertions(+), 338 deletions(-)

[...]

>>> diff --git a/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h b/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> index 442301f..34a3f52 100644
>>> --- a/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> +++ b/arch/arm/plat-pxa/include/plat/pxa3xx_nand.h
>>> @@ -41,6 +41,8 @@ struct pxa3xx_nand_flash {
>>>       struct pxa3xx_nand_timing *timing;      /* NAND Flash timing */
>>>  };
>>>
>>> +/* The max num of chip select current support */
>> /* The maximum number of chip selects currently supported */
>>
>>> +#define NUM_CHIP_SELECT              (2)
>>>  struct pxa3xx_nand_platform_data {
>>>
>>>       /* the data flash bus is shared between the Static Memory
>>> @@ -52,8 +54,10 @@ struct pxa3xx_nand_platform_data {
>>>       /* allow platform code to keep OBM/bootloader defined NFC config */
>>>       int     keep_config;
>>>
>>> -     const struct mtd_partition              *parts;
>>> -     unsigned int                            nr_parts;
>>> +     /* indicate how many chip select would be used for this platform */
>> /* indicate how many chip selects will be used */
>>
>>> +     int     cs_num;
>> This name is too confusing, I think even num_cs is better or cs_count?
>> Also, may be align it with the others?
>  I prefer the num_cs.

Good.

>>> +     const struct mtd_partition              *parts[NUM_CHIP_SELECT];
>>> +     unsigned int                            nr_parts[NUM_CHIP_SELECT];
>>>
>>>       const struct pxa3xx_nand_flash *        flash;
>>>       size_t                                  num_flash;
>>> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
>>> index 30689cc..259b8d5 100644
>>> --- a/drivers/mtd/nand/pxa3xx_nand.c
>>> +++ b/drivers/mtd/nand/pxa3xx_nand.c

[...]

>>> @@ -123,63 +126,63 @@ enum {
>>>  struct pxa3xx_nand_info {
>>>       struct nand_chip        nand_chip;
>>>
>>> -     struct nand_hw_control  controller;
>>> -     struct platform_device   *pdev;
>>>       struct pxa3xx_nand_cmdset *cmdset;
>>> +     /* page size of attached chip */
>>> +     uint16_t                page_size;
>>> +     uint8_t                 chip_select;
>>> +     uint8_t                 use_ecc;
>>> +
>>> +     /* calculated from pxa3xx_nand_flash data */
>>> +     uint8_t                 col_addr_cycles;
>>> +     uint8_t                 row_addr_cycles;
>>> +     uint8_t                 read_id_bytes;
>>> +
>>> +     /* cached register value */
>>> +     uint32_t                reg_ndcr;
>>> +     uint32_t                ndtr0cs0;
>>> +     uint32_t                ndtr1cs0;
>>>
>>> +     void                    *nand_data;
>>> +};
>>> +
>>> +struct pxa3xx_nand {
>>>       struct clk              *clk;
>>>       void __iomem            *mmio_base;
>>>       unsigned long           mmio_phys;
>>> +     struct nand_hw_control  controller;
>>> +     struct completion       cmd_complete;
>>> +     struct platform_device   *pdev;
>> please, align
> Do you still mean cs_num? What this comment refer to?

No, I mean the white space before *pdev - it is not aligned with all others

>>> -     unsigned int            buf_start;
>>> -     unsigned int            buf_count;
>>> -
>>> -     struct mtd_info         *mtd;
>>>       /* DMA information */
>>>       int                     drcmr_dat;
>>>       int                     drcmr_cmd;
>>> -
>>> -     unsigned char           *data_buff;
>>> -     unsigned char           *oob_buff;
>>> -     dma_addr_t              data_buff_phys;
>>> -     size_t                  data_buff_size;
>>>       int                     data_dma_ch;
>>> -     struct pxa_dma_desc     *data_desc;
>>> +     dma_addr_t              data_buff_phys;
>>>       dma_addr_t              data_desc_addr;
>>> +     struct pxa_dma_desc     *data_desc;
>>>
>>> -     uint32_t                reg_ndcr;
>>> -
>>> -     /* saved column/page_addr during CMD_SEQIN */
>>> -     int                     seqin_column;
>>> -     int                     seqin_page_addr;
>>> +     struct pxa3xx_nand_info *info[NUM_CHIP_SELECT];
>>> +     uint32_t                command;
>>> +     uint16_t                data_size;      /* data size in FIFO */
>>> +     uint16_t                oob_size;
>>> +     unsigned char           *data_buff;
>>> +     unsigned char           *oob_buff;
>>> +     uint32_t                buf_start;
>>> +     uint32_t                buf_count;
>>>
>>>       /* relate to the command */
>>>       unsigned int            state;
>>> -
>>> +     uint8_t                 chip_select;
>>>       int                     use_ecc;        /* use HW ECC ? */
>>>       int                     use_dma;        /* use DMA ? */
>>>       int                     is_ready;
>>> -
>>> -     unsigned int            page_size;      /* page size of attached chip */
>>> -     unsigned int            data_size;      /* data size in FIFO */
>>>       int                     retcode;
>>> -     struct completion       cmd_complete;
>>>
>>>       /* generated NDCBx register values */
>>> +     uint8_t                 total_cmds;
>>>       uint32_t                ndcb0;
>>>       uint32_t                ndcb1;
>>>       uint32_t                ndcb2;
>>> -
>>> -     /* timing calcuted from setting */
>>> -     uint32_t                ndtr0cs0;
>>> -     uint32_t                ndtr1cs0;
>>> -
>>> -     /* calculated from pxa3xx_nand_flash data */
>>> -     size_t          oob_size;
>>> -     size_t          read_id_bytes;
>>> -
>>> -     unsigned int    col_addr_cycles;
>>> -     unsigned int    row_addr_cycles;
>>>  };
>> It looks like if you switch the names of the structures above,
>> then the patch will be much shorter and cleaner,
>> but will it make structures meaning confusion?
> Could you elaborate more about this? Do you means no need to create a seperated
> structure?

No, if you have 2 chips, then certainly you'd better have a separate
structure for the chip description.

What I was wondering, is that there are many places in the patch where
you change the "info" to "nand", may be this can be avoided if you keep
the structure that describes the controller ("pxa3xx_nand" in the patch)
named "pxa3xx_nand_info" and the new structure that describes the chip
will be named something else like pxa3xx_nand_chip or anything like this.
This way, your patch will not have to change the "info" to "nand" in many
places (or maybe even all places) and will be much shorter and will include
only functional changes.



[...]

>>>  static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
>>>  {
>>> -     struct pxa3xx_nand_info *info = devid;
>>> -     unsigned int status, is_completed = 0;
>>> +     struct pxa3xx_nand *nand = devid;
>>> +     struct pxa3xx_nand_info *info;
>>> +     unsigned int status, is_completed = 0, cs;
>>> +     unsigned int ready, cmd_done, page_done, badblock_detect;
>>>
>>> -     status = nand_readl(info, NDSR);
>>> +     cs              = nand->chip_select;
>>> +     ready           = (cs) ? NDSR_RDY : NDSR_FLASH_RDY;
>>> +     cmd_done        = (cs) ? NDSR_CS1_CMDD : NDSR_CS0_CMDD;
>>> +     page_done       = (cs) ? NDSR_CS1_PAGED : NDSR_CS0_PAGED;
>>> +     badblock_detect = (cs) ? NDSR_CS1_BBD : NDSR_CS0_BBD;
>> This is confusing... do you use to ?: operator for differentiating between
>> cs = 0 and cs = 1?
>> I think this is a bad idea.
>> Moreover, the use of ?: is discouraged among the kernel.
> I could use if/else to replace this statement.

or switch, what ever you like, but please, don't leave it like
if (cs) ..., because this is confusing it has a meaning of "cs is good or bad?",
while actually, you want to know if it is 0 or 1 (both values are good).


[...]

>>> -static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
>>> +static int prepare_command_pool(struct pxa3xx_nand *nand, int command,
>>>               uint16_t column, int page_addr)
>>>  {
>>>       uint16_t cmd;
>>>       int addr_cycle, exec_cmd, ndcb0;
>>> -     struct mtd_info *mtd = info->mtd;
>>> +     struct mtd_info *mtd;
>>> +     struct pxa3xx_nand_info *info = nand->info[nand->chip_select];
>>>
>>> -     ndcb0 = 0;
>>> +     mtd = get_mtd_by_info(info);
>>> +     ndcb0 = (nand->chip_select) ? NDCB0_CSEL : 0;
>> This one is confusing too...
>> Besides, you don't need the parenthesis.
> Got that. I would fix it.

Good, my previous explanation also applies here.
Thanks


[...]

>>>  static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
>>>  {
>>> -     struct mtd_info *mtd = info->mtd;
>>> +     struct pxa3xx_nand *nand = info->nand_data;
>>> +     struct mtd_info *mtd = get_mtd_by_info(info);
>>>       struct nand_chip *chip = mtd->priv;
>>>
>>>       /* use the common timing to make a try */
>>> -     pxa3xx_nand_config_flash(info, &builtin_flash_types[0]);
>>> +     if (pxa3xx_nand_config_flash(info, &builtin_flash_types[0]))
>>> +             return 0;
>>>       chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0);
>>> -     if (info->is_ready)
>>> +     if (nand->is_ready)
>>>               return 1;
>>>       else
>>>               return 0;
>> I think it is time to change this function return convention to propagate
>> errors and not just 0 or 1, (may be in separate patch) what do you think?
> How about return 0 when sensing the READY signal, or return -ENODEV?

Yes, this should be fine, but also don't forget about
pxa3xx_nand_config_flash() function call - it can return 0 or -EINVAL
and it should also propagate instead of being squashed.

>>> @@ -882,7 +908,8 @@ static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
>>>  static int pxa3xx_nand_scan(struct mtd_info *mtd)
>>>  {
>>>       struct pxa3xx_nand_info *info = mtd->priv;
>>> -     struct platform_device *pdev = info->pdev;
>>> +     struct pxa3xx_nand *nand = info->nand_data;
>>> +     struct platform_device *pdev = nand->pdev;
>>>       struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
>>>       struct nand_flash_dev pxa3xx_flash_ids[2], *def = NULL;
>>>       const struct pxa3xx_nand_flash *f = NULL;
>>> @@ -891,27 +918,25 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
>>>       uint64_t chipsize;
>>>       int i, ret, num;
>>>
>>> +     nand->chip_select = info->chip_select;
>>>       if (pdata->keep_config && !pxa3xx_nand_detect_config(info))
>>>               goto KEEP_CONFIG;
>>>
>>>       ret = pxa3xx_nand_sensing(info);
>>>       if (!ret) {
>>> -             kfree(mtd);
>>> -             info->mtd = NULL;
>>> -             printk(KERN_INFO "There is no nand chip on cs 0!\n");
>>> +             free_cs_resource(info, nand->chip_select);
>>> +             printk(KERN_INFO "There is no nand chip on cs %d!\n",
>>> +                             nand->chip_select);
>>>
>>>               return -EINVAL;

after the change of pxa3xx_nand_sensing() function,
you should change the above "return -EINVAL;" into "return ret;"



[...]


-- 
Regards,
Igor.

  reply	other threads:[~2011-06-23 10:44 UTC|newest]

Thread overview: 162+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-22  3:17 [PATCH] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-08 16:00 ` Lei Wen
2011-06-22 11:39 ` Daniel Mack
2011-06-22 11:39   ` Daniel Mack
2011-06-22 12:21   ` Lei Wen
2011-07-08 17:38     ` Lei Wen
2011-06-22 13:06     ` Daniel Mack
2011-06-22 13:06       ` Daniel Mack
2011-06-23  6:22       ` Lei Wen
2011-06-23  6:22         ` Lei Wen
2011-06-22 13:45 ` Igor Grinberg
2011-07-08 16:09   ` Igor Grinberg
2011-06-23  6:35   ` Lei Wen
2011-07-08 15:26     ` Lei Wen
2011-06-23 10:44     ` Igor Grinberg [this message]
2011-06-23 10:44       ` Igor Grinberg
2011-06-25 11:17       ` Lei Wen
2011-06-25 11:17         ` Lei Wen
2011-06-25 12:32         ` Daniel Mack
2011-06-25 12:32           ` Daniel Mack
2011-06-25 12:51           ` Lei Wen
2011-06-25 12:51             ` Lei Wen
2011-06-27 13:22         ` Igor Grinberg
2011-06-27 13:22           ` Igor Grinberg
2011-06-28  7:32         ` Artem Bityutskiy
2011-06-28  7:32           ` Artem Bityutskiy
2011-06-28 15:12           ` Lei Wen
2011-06-28 15:12             ` Lei Wen
2011-06-29  3:51           ` [PATCH V3 0/9] pxa3xx_nand: add two " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  9:00             ` Igor Grinberg
2011-06-29  9:00               ` Igor Grinberg
2011-06-29 10:20               ` Artem Bityutskiy
2011-06-29 10:20                 ` Artem Bityutskiy
2011-07-04  9:27                 ` Lei Wen
2011-07-04  9:27                   ` Lei Wen
2011-07-04  9:25             ` [PATCH V4 0/4] " Lei Wen
2011-07-04  9:25               ` Lei Wen
2011-07-08  3:34               ` [PATCH V5 0/3] " Lei Wen
2011-07-08  3:34                 ` Lei Wen
2011-07-12 10:28                 ` [PATCH V6 0/4] " Lei Wen
2011-07-12 10:28                   ` Lei Wen
2011-07-12 14:35                   ` [PATCH V7 " Lei Wen
2011-07-12 14:35                     ` Lei Wen
2011-07-15  3:44                     ` [PATCH V8 " Lei Wen
2011-07-15  3:44                       ` Lei Wen
2011-07-20  4:51                       ` Artem Bityutskiy
2011-07-20  4:51                         ` Artem Bityutskiy
2011-07-15  3:44                     ` [PATCH V8 1/4] MTD: pxa3xx_nand: enhance suspend and resume routine Lei Wen
2011-07-15  3:44                       ` Lei Wen
2011-07-15  3:44                     ` [PATCH V8 2/4] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-07-15  3:44                       ` Lei Wen
2011-07-15  3:44                     ` [PATCH V8 3/4] MTD: pxa3xx_nand: sperate each chip individual info Lei Wen
2011-07-15  3:44                       ` Lei Wen
2011-07-15  3:44                     ` [PATCH V8 4/4] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-15  3:44                       ` Lei Wen
2011-07-12 14:35                   ` [PATCH V7 1/4] MTD: pxa3xx_nand: enhance suspend and resume routine Lei Wen
2011-07-12 14:35                     ` Lei Wen
2011-07-13 10:53                     ` Sergei Shtylyov
2011-07-13 10:53                       ` Sergei Shtylyov
2011-07-12 14:35                   ` [PATCH V7 2/4] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-07-12 14:35                     ` Lei Wen
2011-07-13 10:57                     ` Sergei Shtylyov
2011-07-13 10:57                       ` Sergei Shtylyov
2011-07-13 12:41                       ` Lei Wen
2011-07-13 12:41                         ` Lei Wen
2011-07-13 14:35                         ` Sergei Shtylyov
2011-07-13 14:35                           ` Sergei Shtylyov
2011-07-12 14:35                   ` [PATCH V7 3/4] MTD: pxa3xx_nand: sperate each chip individual info Lei Wen
2011-07-12 14:35                     ` Lei Wen
2011-07-12 14:35                   ` [PATCH V7 4/4] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-12 14:35                     ` Lei Wen
2011-07-12 10:28                 ` [PATCH V6 1/4] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-07-12 10:28                   ` Lei Wen
2011-07-12 10:28                 ` [PATCH V6 2/4] MTD: pxa3xx_nand: sperate each chip individual info Lei Wen
2011-07-12 10:28                   ` Lei Wen
2011-07-12 10:28                 ` [PATCH V6 3/4] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-12 10:28                   ` Lei Wen
2011-07-12 10:28                 ` [PATCH V6 4/4] MTD: pxa3xx_nand: enhance suspend and resume routine Lei Wen
2011-07-12 10:28                   ` Lei Wen
2011-07-12 11:39                   ` Daniel Mack
2011-07-12 11:39                     ` Daniel Mack
2011-07-12 12:02                     ` Daniel Mack
2011-07-12 12:02                       ` Daniel Mack
2011-07-12 15:56                       ` Igor Grinberg
2011-07-12 15:56                         ` Igor Grinberg
2011-07-12 17:35                         ` Daniel Mack
2011-07-12 17:35                           ` Daniel Mack
2011-07-08  3:34               ` [PATCH 1/3] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-07-08  3:34                 ` Lei Wen
2011-07-08  3:34               ` [PATCH 2/3] MTD: pxa3xx_nand: sperate each chip individual info Lei Wen
2011-07-08  3:34                 ` Lei Wen
2011-07-08  3:34               ` [PATCH 3/3] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-08  3:34                 ` Lei Wen
2011-07-04  9:25             ` [PATCH 1/4] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-07-04  9:25               ` Lei Wen
2011-07-04  9:25             ` [PATCH 2/4] MTD: pxa3xx_nand: sperate each chip individual info Lei Wen
2011-07-04  9:25               ` Lei Wen
2011-07-06  7:29               ` Igor Grinberg
2011-07-06  7:29                 ` Igor Grinberg
2011-07-04  9:25             ` [PATCH 3/4] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-07-04  9:25               ` Lei Wen
2011-07-06  6:53               ` Artem Bityutskiy
2011-07-06  6:53                 ` Artem Bityutskiy
2011-07-06  6:54                 ` Lei Wen
2011-07-06  6:54                   ` Lei Wen
2011-07-06  7:07                   ` Artem Bityutskiy
2011-07-06  7:07                     ` Artem Bityutskiy
2011-07-06  7:41               ` Igor Grinberg
2011-07-06  7:41                 ` Igor Grinberg
2011-07-07  6:26                 ` Lei Wen
2011-07-07  6:26                   ` Lei Wen
2011-07-07  8:59                   ` Igor Grinberg
2011-07-07  8:59                     ` Igor Grinberg
2011-07-07  9:06                     ` Lei Wen
2011-07-07  9:06                       ` Lei Wen
2011-07-07 11:23                       ` Igor Grinberg
2011-07-07 11:23                         ` Igor Grinberg
2011-07-11 14:49                 ` Daniel Mack
2011-07-11 14:49                   ` Daniel Mack
2011-07-11 18:19                   ` Igor Grinberg
2011-07-11 18:19                     ` Igor Grinberg
2011-07-11 18:53                     ` Daniel Mack
2011-07-11 18:53                       ` Daniel Mack
2011-07-11 19:25                       ` Igor Grinberg
2011-07-11 19:25                         ` Igor Grinberg
2011-07-12  9:40                         ` Lei Wen
2011-07-12  9:40                           ` Lei Wen
2011-07-12  9:57                           ` Daniel Mack
2011-07-12  9:57                             ` Daniel Mack
2011-07-12 10:29                             ` Lei Wen
2011-07-12 10:29                               ` Lei Wen
2011-07-12 12:05                               ` Daniel Mack
2011-07-12 12:05                                 ` Daniel Mack
2011-07-12 12:48                         ` Daniel Mack
2011-07-12 12:48                           ` Daniel Mack
2011-07-12 15:49                           ` Igor Grinberg
2011-07-12 15:49                             ` Igor Grinberg
2011-07-04  9:25             ` [PATCH 4/4] ARM: mmp/pxa: fix nand platform data Lei Wen
2011-07-04  9:25               ` Lei Wen
2011-06-29  3:51           ` [PATCH 1/9] MTD: pxa3xx_nand: convert all printk into dev_* Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 2/9] MTD: pxa3xx_nand: enable multiple chip select support Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  7:11             ` Artem Bityutskiy
2011-06-29  7:11               ` Artem Bityutskiy
2011-06-29  7:16               ` Lei Wen
2011-06-29  7:16                 ` Lei Wen
2011-06-29  3:51           ` [PATCH 3/9] ARM: aspenite: fix nand platform data Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 4/9] ARM: cm-x300: " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 5/9] ARM: colibri-pxa3xx: " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 6/9] ARM: littleton: " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 7/9] ARM: mxm8x10: " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 8/9] ARM: raumfeld: " Lei Wen
2011-06-29  3:51             ` Lei Wen
2011-06-29  3:51           ` [PATCH 9/9] ARM: zylonite: " Lei Wen
2011-06-29  3:51             ` Lei Wen

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=4E031900.50108@compulab.co.il \
    --to=grinberg@compulab.co.il \
    --cc=David.Woodhouse@intel.com \
    --cc=adrian.wenl@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=eric.y.miao@gmail.com \
    --cc=haojian.zhuang@gmail.com \
    --cc=leiwen@marvell.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.