public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mugunthan V N <mugunthanvnm@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/9] drivers: nand: implement a NAND uclass
Date: Fri, 22 Apr 2016 10:36:04 +0530	[thread overview]
Message-ID: <5719B13C.4030200@ti.com> (raw)
In-Reply-To: <CAPnjgZ1jG+g0t+LTH=mzhtoTofBTfjO_GVik6GPWa7xjQ7z=fg@mail.gmail.com>

On Thursday 21 April 2016 07:41 PM, Simon Glass wrote:
> Hi Mugunthan,
> 
> On 20 April 2016 at 23:55, Mugunthan V N <mugunthanvnm@ti.com> wrote:
>> On Wednesday 20 April 2016 08:09 PM, Simon Glass wrote:
>>> Hi Mugunthan,
>>>
>>> On 1 April 2016 at 05:29, Mugunthan V N <mugunthanvnm@ti.com> wrote:
>>>> Implement a NAND uclass so that the NAND devices can be
>>>> accessed via the DM framework.
>>>>
>>>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>>>> ---
>>>>  drivers/mtd/nand/Kconfig       | 10 +++++++
>>>>  drivers/mtd/nand/Makefile      |  2 ++
>>>>  drivers/mtd/nand/nand-uclass.c | 62 ++++++++++++++++++++++++++++++++++++++++++
>>>>  drivers/mtd/nand/nand.c        |  6 +++-
>>>>  include/dm/uclass-id.h         |  1 +
>>>>  include/nand.h                 |  5 ++++
>>>>  6 files changed, 85 insertions(+), 1 deletion(-)
>>>>  create mode 100644 drivers/mtd/nand/nand-uclass.c
>>>>
>>>> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
>>>> index 7787505..53b57b8 100644
>>>> --- a/drivers/mtd/nand/Kconfig
>>>> +++ b/drivers/mtd/nand/Kconfig
>>>> @@ -8,6 +8,16 @@ menuconfig NAND
>>>>
>>>>  if NAND
>>>>
>>>> +config DM_NAND
>>>> +       bool "Enable driver model for NAND"
>>>> +       depends on NAND && DM
>>>> +       help
>>>> +         Enable driver model for NAND. The NAND interface is then
>>>> +         implemented by the NAND uclass. Multiple NAND devices can
>>>> +         be attached and used. The 'nand' command works as normal.
>>>> +
>>>> +         If the NAND drivers doesn't support DM, say N.
>>>> +
>>>>  config SYS_NAND_SELF_INIT
>>>>         bool
>>>>         help
>>>> diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
>>>> index 6fb3718..7745705 100644
>>>> --- a/drivers/mtd/nand/Makefile
>>>> +++ b/drivers/mtd/nand/Makefile
>>>> @@ -39,6 +39,8 @@ endif # not spl
>>>>
>>>>  ifdef NORMAL_DRIVERS
>>>>
>>>> +obj-$(CONFIG_DM_NAND) += nand-uclass.o
>>>> +
>>>>  obj-$(CONFIG_NAND_ECC_BCH) += nand_bch.o
>>>>
>>>>  obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o
>>>> diff --git a/drivers/mtd/nand/nand-uclass.c b/drivers/mtd/nand/nand-uclass.c
>>>> new file mode 100644
>>>> index 0000000..d68d357
>>>> --- /dev/null
>>>> +++ b/drivers/mtd/nand/nand-uclass.c
>>>> @@ -0,0 +1,62 @@
>>>> +/*
>>>> + * NAND uclass driver for NAND bus.
>>>> + *
>>>> + * (C) Copyright 2012-2016
>>>> + *     Texas Instruments Incorporated, <www.ti.com>
>>>> + *
>>>> + * SPDX-License-Identifier:     GPL-2.0+
>>>> + */
>>>> +
>>>> +#include <common.h>
>>>> +#include <dm.h>
>>>> +#include <errno.h>
>>>> +#include <nand.h>
>>>> +
>>>> +DECLARE_GLOBAL_DATA_PTR;
>>>> +
>>>> +#ifdef CONFIG_DM_NAND
>>>> +
>>>> +nand_info_t *get_nand_dev_by_index(int idx)
>>>> +{
>>>> +       nand_info_t *nand;
>>>> +       struct udevice *dev;
>>>> +       int ret;
>>>> +
>>>> +       ret = uclass_get_device(UCLASS_NAND, idx, &dev);
>>>> +       if (ret) {
>>>> +               error("NAND device (%d) not found\n", idx);
>>>
>>> This should return -ENODEV. Also please avoid printf() in drivers. The
>>> caller can report the error.
>>>
>>
>> Return type is pointer so returned NULL and NULL denotes no dev.
>> Will change this error to debug in v2.
> 
> OK, I see that this is the existing API.
> 
>>
>>>> +               return NULL;
>>>> +       }
>>>> +
>>>> +       nand = (nand_info_t *)dev_get_uclass_priv(dev);
>>>> +       if (!nand) {
>>>> +               error("Nand device not ready\n");
>>>> +               return NULL;
>>>> +       }
>>>
>>> But if the device has been probed ((with uclass_get_device()) then
>>> this cannot be NULL.
>>
>> This check is just a failsafe. ideally it should not fail here.
> 
> I cannot get to probe the device without this data, since this would
> be a bug in DM. So the check has no value.
> 

Okay then I will remove this check as it doesn't add value.

Regards
Mugunthan V N

  reply	other threads:[~2016-04-22  5:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01 11:29 [U-Boot] [PATCH 0/9] device model bringup of nand on am335x gp evm and am437x gp evm Mugunthan V N
2016-04-01 11:29 ` [U-Boot] [PATCH 1/9] include: nand: move endif to end of file Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-20 14:39   ` Simon Glass
2016-04-01 11:29 ` [U-Boot] [PATCH 2/9] cmd: nand: abstract global variable usage for dm conversion Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-01 22:57   ` Scott Wood
2016-04-13 11:01     ` Mugunthan V N
2016-04-14 11:50   ` Mugunthan V N
2016-04-01 11:29 ` [U-Boot] [PATCH 3/9] drivers: nand: Kconfig: add NAND as Kconfig option Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-01 14:57     ` Mugunthan V N
2016-04-01 23:07     ` Scott Wood
2016-04-01 23:41       ` Tom Rini
2016-04-01 23:45         ` Scott Wood
2016-04-02  0:25           ` Tom Rini
2016-04-05  8:37             ` Mugunthan V N
2016-04-08 19:45               ` Tom Rini
2016-04-17  1:38                 ` Scott Wood
2016-04-01 11:29 ` [U-Boot] [PATCH 4/9] drivers: nand: implement a NAND uclass Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-01 14:59     ` Mugunthan V N
2016-04-01 23:25   ` Scott Wood
2016-04-01 23:31     ` Scott Wood
2016-04-05  8:27       ` Mugunthan V N
2016-04-20 14:39   ` Simon Glass
2016-04-21  5:55     ` Mugunthan V N
2016-04-21 14:11       ` Simon Glass
2016-04-22  5:06         ` Mugunthan V N [this message]
2016-04-01 11:29 ` [U-Boot] [PATCH 5/9] drivers: nand: omap_gpmc: convert driver to adopt driver model Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-04 17:22   ` Scott Wood
2016-04-05  8:41     ` Mugunthan V N
2016-04-01 11:29 ` [U-Boot] [PATCH 6/9] am43xx_evm: nand: do not define DM_NAND for spl Mugunthan V N
2016-04-01 12:51   ` Tom Rini
2016-04-20 14:39   ` Simon Glass
2016-04-01 11:29 ` [U-Boot] [PATCH 7/9] defconfig: am437x_gp_evm: enable NAND driver model Mugunthan V N
2016-04-01 12:52   ` Tom Rini
2016-04-20 14:39     ` Simon Glass
2016-04-01 11:29 ` [U-Boot] [PATCH 8/9] am335x_evm: nand: do not define DM_NAND for spl Mugunthan V N
2016-04-01 12:52   ` Tom Rini
2016-04-20 14:39     ` Simon Glass
2016-04-01 11:29 ` [U-Boot] [PATCH 9/9] defconfig: am335x_gp_evm: enable NAND driver model Mugunthan V N
2016-04-20 14:39   ` Simon Glass

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=5719B13C.4030200@ti.com \
    --to=mugunthanvnm@ti.com \
    --cc=u-boot@lists.denx.de \
    /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