Patchwork Add platform driver support to the CS890x driver

login
register
mail settings
Submitter Jaccon Bastiaansen
Date Sept. 11, 2011, 5:34 p.m.
Message ID <CAGzjT4f2agA30TGb8XFSRu57=--qyBt=bU5QWVTmU6LAGmwM8A@mail.gmail.com>
Download mbox | patch
Permalink /patch/114241/
State New
Headers show

Comments

Jaccon Bastiaansen - Sept. 11, 2011, 5:34 p.m.
Hello Uwe,

2011/9/10 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello Jaccon,
>
> On Sat, Sep 10, 2011 at 01:37:07PM +0200, Jaccon Bastiaansen wrote:
>> Hello Uwe,
>>
>> 2011/9/7 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
>> > Hello Jaccon,
>> >
>> > On Wed, Sep 07, 2011 at 12:22:47PM +0200, Jaccon Bastiaansen wrote:
>> >> The CS89x0 ethernet controller is used on a number of evaluation
>> >> boards, such as the MX31ADS. The current driver has memory address and
>> >> IRQ settings for each board on which this controller is used. Driver
>> >> updates are therefore required to support other boards that also use
>> >> the CS89x0. To avoid these driver updates, a better mechanism
>> >> (platform driver support) is added to communicate the board dependent
>> >> settings to the driver.
>> >>
>> >> Signed-off-by: Jaccon Bastiaansen <jaccon.bastiaansen@gmail.com>
>> >> ---
>> >>  drivers/net/Kconfig  |   18 +++++++++--
>> >>  drivers/net/Space.c  |    2 +-
>> >>  drivers/net/cs89x0.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++--
>> >>  3 files changed, 96 insertions(+), 7 deletions(-)
>> >>
>> >> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
>> >> index 93359fa..17be84f 100644
>> >> --- a/drivers/net/Kconfig
>> >> +++ b/drivers/net/Kconfig
>> >> @@ -1497,8 +1497,7 @@ config FORCEDETH
>> >>
>> >>  config CS89x0
>> >>       tristate "CS89x0 support"
>> >> -     depends on NET_ETHERNET && (ISA || EISA || MACH_IXDP2351 \
>> >> -             || ARCH_IXDP2X01 || MACH_MX31ADS || MACH_QQ2440)
>> >> +     depends on NET_ETHERNET
>> >>       ---help---
>> >>         Support for CS89x0 chipset based Ethernet cards. If you have a
>> >>         network (Ethernet) card of this type, say Y and read the
>> >> @@ -1509,10 +1508,23 @@ config CS89x0
>> >>         To compile this driver as a module, choose M here. The module
>> >>         will be called cs89x0.
>> >>
>> >> +config CS89x0_PLATFORM
>> >> +     bool "CS89x0 platform driver support"
>> >> +     depends on CS89x0
>> >> +     default n
>> > default n is implicit so you don't need (and should not) add it here.
>> >
>>
>> Ok, I will fix this in the next version of the patch.
>>
>> >> +     help
>> >> +       Say Y to compile the cs890x0 driver as a platform driver. This
>> >> +       makes this driver suitable for use on certain evaluation boards
>> >> +       such as the IMX21ADS.
>> >> +
>> >> +       If you are unsure, say N.
>> >> +
>> >>  config CS89x0_NONISA_IRQ
>> >>       def_bool y
>> >>       depends on CS89x0 != n
>> >> -     depends on MACH_IXDP2351 || ARCH_IXDP2X01 || MACH_MX31ADS || MACH_QQ2440
>> >> +     depends on MACH_IXDP2351 || ARCH_IXDP2X01 || MACH_MX31ADS || \
>> >> +                MACH_QQ2440 || CS89x0_PLATFORM
>> >> +
>> >>
>> >>  config TC35815
>> >>       tristate "TOSHIBA TC35815 Ethernet support"
>> >> diff --git a/drivers/net/Space.c b/drivers/net/Space.c
>> >> index 068c356..3c53ab1 100644
>> >> --- a/drivers/net/Space.c
>> >> +++ b/drivers/net/Space.c
>> >> @@ -189,7 +189,7 @@ static struct devprobe2 isa_probes[] __initdata = {
>> >>  #ifdef CONFIG_SEEQ8005
>> >>       {seeq8005_probe, 0},
>> >>  #endif
>> >> -#ifdef CONFIG_CS89x0
>> >> +#if defined(CONFIG_CS89x0) && !defined(CONFIG_CS89x0_PLATFORM)
>> >>       {cs89x0_probe, 0},
>> >>  #endif
>> >>  #ifdef CONFIG_AT1700
>> >> diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
>> >> index 537a4b2..604c828 100644
>> >> --- a/drivers/net/cs89x0.c
>> >> +++ b/drivers/net/cs89x0.c
>> >> @@ -98,6 +98,8 @@
>> >>    Domenico Andreoli : cavokz@gmail.com
>> >>                      : QQ2440 platform support
>> >>
>> >> +  Jaccon Bastiaansen: jaccon.bastiaansen@gmail.com
>> >> +                 : added platform driver support
>> >>  */
>> >>
>> >>  /* Always include 'config.h' first in case the user wants to turn on
>> >> @@ -154,7 +156,9 @@
>> >>  #if ALLOW_DMA
>> >>  #include <asm/dma.h>
>> >>  #endif
>> >> -
>> >> +#ifdef CONFIG_CS89x0_PLATFORM
>> >> +#include <linux/platform_device.h>
>> >> +#endif
>> > IMHO better include that unconditionally.
>> >
>>
>> I will also fix this in the next version of this patch.
>>
>> >>  #include "cs89x0.h"
>> >>
>> >>  static char version[] __initdata =
>> >> @@ -189,6 +193,9 @@ static unsigned int netcard_portlist[] __used __initdata = {
>> >>       PBC_BASE_ADDRESS + PBC_CS8900A_IOBASE + 0x300, 0
>> >>  };
>> >>  static unsigned cs8900_irq_map[] = {EXPIO_INT_ENET_INT, 0, 0, 0};
>> >> +#elif defined(CONFIG_CS89x0_PLATFORM)
>> >> +static unsigned int netcard_portlist[] __used __initdata = {0, 0};
>> >> +static unsigned int cs8900_irq_map[] = {0, 0, 0, 0};
>> >>  #else
>> >>  static unsigned int netcard_portlist[] __used __initdata =
>> >>     { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
>> >> @@ -1746,7 +1753,7 @@ static int set_mac_address(struct net_device *dev, void *p)
>> >>       return 0;
>> >>  }
>> >>
>> >> -#ifdef MODULE
>> >> +#if defined(MODULE) && !defined(CONFIG_CS89x0_PLATFORM)
>> >>
>> >>  static struct net_device *dev_cs89x0;
>> >>
>> >> @@ -1900,7 +1907,77 @@ cleanup_module(void)
>> >>       release_region(dev_cs89x0->base_addr, NETCARD_IO_EXTENT);
>> >>       free_netdev(dev_cs89x0);
>> >>  }
>> >> -#endif /* MODULE */
>> >> +#endif /* MODULE && !CONFIG_CS89x0_PLATFORM */
>> >> +
>> >> +#ifdef CONFIG_CS89x0_PLATFORM
>> >> +static int cs89x0_platform_probe(struct platform_device *pdev)
>> >> +{
>> >> +     struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
>> >> +     struct resource *mem_res;
>> >> +     struct resource *irq_res;
>> >> +     int err;
>> >> +
>> >> +     if (!dev)
>> >> +             return -ENODEV;
>> >> +
>> >> +     mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> >> +     irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>> >> +     if (mem_res == NULL || irq_res == NULL) {
>> >> +             printk(KERN_WARNING
>> >> +                    DRV_NAME
>> >> +                    ": memory and/or interrupt resource missing.\n");
>> > I'd prefer you do:
>> >
>> >        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>> >
>> > at the top of the driver and then just use:
>> >
>> >        pr_warning("memory and/or interrupt resource missing\m");
>> >
>>
>> I agree.
>>
>> >> +             err = -ENOENT;
>> >> +             goto out;
>> >> +     }
>> >> +
>> >> +     cs8900_irq_map[0] = irq_res->start;
>> >> +     err = cs89x0_probe1(dev, mem_res->start, 0);
>> > hmm, better switch the complete driver to be a platform driver and
>> > instead of the legacy probing let it create the corresponding device.
>> >
>>
>> What exactly do you mean with "switch the complete driver to be a
>> platform driver"? That I should remove all the legacy from the driver
>> (which would break the driver for users who don't use it as a platform
>> driver) or that I should add a new probe() function free of legacy
>> (which would duplicate code of the existing cs89x0_probe1() function)?
> Of course you should not break it for legacy users. Just instead of the
> legacy stuff just add a platform device with the respective values such
> that the platform driver is used in all cases.
>
> For extra points move the adding of the device to platform code.
>

The platform device you mention is added by another patch that I also
sent on the the 7th of September (not directly to you, but to Sascha
and kernel@pengutronix.de). This patch was called:

[PATCH] Add CS890x0 ethernet controller support to the i.MX21ADS

In this patch I add a platform device to the i.MX21ADS evaluation
board. All the required settings (memory address and IRQ) that the
CS890x platform driver needs to run on the i.MX21ADS board are set in
the i.MX21ADS specific code. You find the patch below. It this the
approach you mean?


--
1.7.1


> Best regards
> Uwe
>
> --
> Pengutronix e.K.                           | Uwe Kleine-König            |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
>

Regards,
  Jaccon
Uwe Kleine-König - Sept. 11, 2011, 6:53 p.m.
Hello Jaccon,

On Sun, Sep 11, 2011 at 07:34:25PM +0200, Jaccon Bastiaansen wrote:
> >> > hmm, better switch the complete driver to be a platform driver and
> >> > instead of the legacy probing let it create the corresponding device.
> >> >
> >>
> >> What exactly do you mean with "switch the complete driver to be a
> >> platform driver"? That I should remove all the legacy from the driver
> >> (which would break the driver for users who don't use it as a platform
> >> driver) or that I should add a new probe() function free of legacy
> >> (which would duplicate code of the existing cs89x0_probe1() function)?
> > Of course you should not break it for legacy users. Just instead of the
> > legacy stuff just add a platform device with the respective values such
> > that the platform driver is used in all cases.
> >
> > For extra points move the adding of the device to platform code.
> >
> 
> The platform device you mention is added by another patch that I also
> sent on the the 7th of September (not directly to you, but to Sascha
> and kernel@pengutronix.de). This patch was called:
> 
> [PATCH] Add CS890x0 ethernet controller support to the i.MX21ADS
> 
> In this patch I add a platform device to the i.MX21ADS evaluation
> board. All the required settings (memory address and IRQ) that the
> CS890x platform driver needs to run on the i.MX21ADS board are set in
> the i.MX21ADS specific code. You find the patch below. It this the
> approach you mean?
not really. On some machines (e.g arm/imx/mx31ads) some magic constants
are defined somewhere in arch/ to fill in netcard_portlist and
cs8900_irq_map. On these machines the cs8900 driver does drive some
hardware, but not via the platform bus. This is what i want to have
changed.

Best regards
Uwe
Jaccon Bastiaansen - Sept. 12, 2011, 10:52 a.m.
Hello Uwe,

2011/9/11 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello Jaccon,
>
> On Sun, Sep 11, 2011 at 07:34:25PM +0200, Jaccon Bastiaansen wrote:
>> >> > hmm, better switch the complete driver to be a platform driver and
>> >> > instead of the legacy probing let it create the corresponding device.
>> >> >
>> >>
>> >> What exactly do you mean with "switch the complete driver to be a
>> >> platform driver"? That I should remove all the legacy from the driver
>> >> (which would break the driver for users who don't use it as a platform
>> >> driver) or that I should add a new probe() function free of legacy
>> >> (which would duplicate code of the existing cs89x0_probe1() function)?
>> > Of course you should not break it for legacy users. Just instead of the
>> > legacy stuff just add a platform device with the respective values such
>> > that the platform driver is used in all cases.
>> >
>> > For extra points move the adding of the device to platform code.
>> >
>>
>> The platform device you mention is added by another patch that I also
>> sent on the the 7th of September (not directly to you, but to Sascha
>> and kernel@pengutronix.de). This patch was called:
>>
>> [PATCH] Add CS890x0 ethernet controller support to the i.MX21ADS
>>
>> In this patch I add a platform device to the i.MX21ADS evaluation
>> board. All the required settings (memory address and IRQ) that the
>> CS890x platform driver needs to run on the i.MX21ADS board are set in
>> the i.MX21ADS specific code. You find the patch below. It this the
>> approach you mean?
> not really. On some machines (e.g arm/imx/mx31ads) some magic constants
> are defined somewhere in arch/ to fill in netcard_portlist and
> cs8900_irq_map. On these machines the cs8900 driver does drive some
> hardware, but not via the platform bus. This is what i want to have
> changed.
>

Ok, so you would like to see the #ifdefs for the IXDP2351, IXDP2X01,
QQ2440 and MX31ADS in the cs890x driver replaced by platform_device
definitions in the platform specific code of those platforms (in the
same way as I have done for the i.MX21ADS platform)? Is this correct?

> Best regards
> Uwe
>
> --
> Pengutronix e.K.                           | Uwe Kleine-König            |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
>

Regards,
  Jaccon
Uwe Kleine-König - Sept. 12, 2011, 12:30 p.m.
Hello Jaccon,

On Mon, Sep 12, 2011 at 12:52:52PM +0200, Jaccon Bastiaansen wrote:
> 2011/9/11 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> >             On some machines (e.g arm/imx/mx31ads) some magic constants
> > are defined somewhere in arch/ to fill in netcard_portlist and
> > cs8900_irq_map. On these machines the cs8900 driver does drive some
> > hardware, but not via the platform bus. This is what i want to have
> > changed.
> >
> 
> Ok, so you would like to see the #ifdefs for the IXDP2351, IXDP2X01,
> QQ2440 and MX31ADS in the cs890x driver replaced by platform_device
> definitions in the platform specific code of those platforms (in the
> same way as I have done for the i.MX21ADS platform)? Is this correct?
More or less, yes. I would have started to keep the change local to
the cs8900 driver, but moving the devices to arch is the final goal.

The upside of first reworking the driver and only then move the devices
out is that it might be better/easier to bisect and review.

Best regards
Uwe
Jaccon Bastiaansen - Sept. 30, 2011, 9:01 a.m.
Hello Domenico,

2011/9/28 Domenico Andreoli <cavokz@gmail.com>:
> Hi Jaccon,
>
> On Mon, Sep 12, 2011 at 12:52:52PM +0200, Jaccon Bastiaansen wrote:
>>
>> Ok, so you would like to see the #ifdefs for the IXDP2351, IXDP2X01,
>> QQ2440 and MX31ADS in the cs890x driver replaced by platform_device
>> definitions in the platform specific code of those platforms (in the
>> same way as I have done for the i.MX21ADS platform)? Is this correct?
>
> Feel free to completely dump the QQ2440 thing, the QQ2440 board support
> is not in mainline and will not until it can be implemented mostly with
> DT, I guess.  At that time I will be happy to use your platform device
> conversion - with the OF initialization that sombody will write ;)
>
> I will test it.
>
> cheers,
> Domenico
>


This patch does what you describe and removes the QQ2440 board support.

Regards,
  Jaccon
Russell King - ARM Linux - Oct. 1, 2011, 5:13 p.m.
On Fri, Sep 30, 2011 at 11:01:10AM +0200, Jaccon Bastiaansen wrote:
> Hello Domenico,
> 
> 2011/9/28 Domenico Andreoli <cavokz@gmail.com>:
> > Hi Jaccon,
> >
> > On Mon, Sep 12, 2011 at 12:52:52PM +0200, Jaccon Bastiaansen wrote:
> >>
> >> Ok, so you would like to see the #ifdefs for the IXDP2351, IXDP2X01,
> >> QQ2440 and MX31ADS in the cs890x driver replaced by platform_device
> >> definitions in the platform specific code of those platforms (in the
> >> same way as I have done for the i.MX21ADS platform)? Is this correct?
> >
> > Feel free to completely dump the QQ2440 thing, the QQ2440 board support
> > is not in mainline and will not until it can be implemented mostly with
> > DT, I guess.  At that time I will be happy to use your platform device
> > conversion - with the OF initialization that sombody will write ;)

I don't have Domenico's original mail...

The QQ2440 thing got submitted into the patch system while the consolidation
push was going on earlier in the year, so I ignored it (along with the other
platforms which people submitted without regard to Linus' rant.)

It's now up to the SoC maintainers whether they want to accept this stuff,
and if so how to get it into mainline (probably via Arnd) - be that in
their current form or if they think that a DT based implementation is
better.

I'll be discarding the four 'new' platforms (of which QQ2440 is one) which
have been sitting in the patch system since March in the next few days.
Domenico Andreoli - Oct. 12, 2011, 2:28 p.m.
On Sat, Oct 01, 2011 at 06:13:40PM +0100, Russell King - ARM Linux wrote:
> On Fri, Sep 30, 2011 at 11:01:10AM +0200, Jaccon Bastiaansen wrote:
> > Hello Domenico,
> > 
> > 2011/9/28 Domenico Andreoli <cavokz@gmail.com>:
> > > Hi Jaccon,
> > >
> > > On Mon, Sep 12, 2011 at 12:52:52PM +0200, Jaccon Bastiaansen wrote:
> > >>
> > >> Ok, so you would like to see the #ifdefs for the IXDP2351, IXDP2X01,
> > >> QQ2440 and MX31ADS in the cs890x driver replaced by platform_device
> > >> definitions in the platform specific code of those platforms (in the
> > >> same way as I have done for the i.MX21ADS platform)? Is this correct?
> > >
> > > Feel free to completely dump the QQ2440 thing, the QQ2440 board support
> > > is not in mainline and will not until it can be implemented mostly with
> > > DT, I guess.  At that time I will be happy to use your platform device
> > > conversion - with the OF initialization that sombody will write ;)
> 
> I don't have Domenico's original mail...

yes, there was a problem on my side that I hope is now fixed.

> It's now up to the SoC maintainers whether they want to accept this stuff,
> and if so how to get it into mainline (probably via Arnd) - be that in
> their current form or if they think that a DT based implementation is
> better.
> 
> I'll be discarding the four 'new' platforms (of which QQ2440 is one) which
> have been sitting in the patch system since March in the next few days.

thank you.

Regards,
Domenico

Patch

===================================
[PATCH] Add CS890x0 ethernet controller support to the i.MX21ADS

Signed-off-by: Jaccon Bastiaansen <jaccon.bastiaansen@gmail.com>
---
 arch/arm/mach-imx/mach-mx21ads.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-imx/mach-mx21ads.c b/arch/arm/mach-imx/mach-mx21ads.c
index 74ac889..62b4717 100644
--- a/arch/arm/mach-imx/mach-mx21ads.c
+++ b/arch/arm/mach-imx/mach-mx21ads.c
@@ -159,6 +159,26 @@  static struct platform_device mx21ads_nor_mtd_device = {
       .resource = &mx21ads_flash_resource,
 };

+static struct resource mx21ads_cs8900_resources[] = {
+       {
+               .start  = (u32)MX21ADS_CS8900A_IOBASE_REG,
+               .end    = (u32)MX21ADS_CS8900A_IOBASE_REG + 0x200000 - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = MX21ADS_CS8900A_IRQ,
+               .end    = MX21ADS_CS8900A_IRQ,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mx21ads_cs8900_device = {
+       .name           = "cs89x0",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(mx21ads_cs8900_resources),
+       .resource       = mx21ads_cs8900_resources,
+};
+
 static const struct imxuart_platform_data uart_pdata_rts __initconst = {
       .flags = IMXUART_HAVE_RTSCTS,
 };
@@ -275,6 +295,7 @@  static void __init mx21ads_map_io(void)

 static struct platform_device *platform_devices[] __initdata = {
       &mx21ads_nor_mtd_device,
+       &mx21ads_cs8900_device
 };

 static void __init mx21ads_board_init(void)