sh: add spi header and r2d platform data
PATCH 1/1 sh: add spi header and r2d platform data
sh: add spi header and r2d platform data
This patch adds the header file asm/spi.h and board specific code for the r2d board. The header file contains a structure that should be used to describe a single spi bus. The board specific code for r2d is updated with such a structure for the new spi_sh_sci driver. The structure contains a chip select callback plus information about the R9701 rtc chip which is attached to the spi bus.
---
arch/sh/boards/renesas/rts7751r2d/setup.c | 42 +++++++++++++++++++++++++++++ include/asm-sh/spi.h | 17 +++++++++++ 2 files changed, 59 insertions(+)
arch/sh/boards/renesas/rts7751r2d/setup.c +42 -0
@@ -16,9 +16,12 @@#include <linux/sm501-regs.h> #include <linux/pm.h> #include <linux/fb.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> #include <asm/machvec.h> #include <asm/rts7751r2d.h> #include <asm/io.h> +#include <asm/spi.h> static struct resource cf_ide_resources[] = { [0 ] = {
@@ -53,6 +56,44 @@ static struct platform_device cf_ide_dev }, }; +static void r2d_chip_select (struct sh_spi_info *spi,int cs,int state) +{ +BUG_ON (cs !=0 );/* Single Epson RTC-9701JE attached on CS0 */ +ctrl_outw (state =BITBANG_CS_ACTIVE ?1 :0 ,PA_RTCCE ); +} + +static struct resource spi_sh_sci_resources[] = { + { + .start =0xffe00000 , + .end =0xffe0001f , + .flags =IORESOURCE_MEM , + }, +}; + +static struct spi_board_info spi_board_info[] = { + { + .modalias ="rtc-r9701" , + .max_speed_hz =1000000 , + }, +}; + +static struct sh_spi_info spi_info = { + .num_chipselect =1 , + .chip_select = r2d_chip_select, + .board_info = spi_board_info, + .board_size =ARRAY_SIZE (spi_board_info), +}; + +static struct platform_device spi_sh_sci_device = { + .name ="spi_sh_sci" , + .id =-1 , + .num_resources =ARRAY_SIZE (spi_sh_sci_resources), + .resource = spi_sh_sci_resources, + .dev = { + .platform_data = &spi_info, + }, +}; +static struct resource heartbeat_resources[] = { [0 ] = { .start =PA_OUTPORT ,
@@ -176,6 +217,7 @@ static struct platform_device *rts7751r2#endif &cf_ide_device, &heartbeat_device, + &spi_sh_sci_device, };static int __init rts7751r2d_devices_setup (void )
include/asm-sh/spi.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __ASM_SPI_H__ +#define __ASM_SPI_H__ + +struct sh_spi_info ; +struct spi_board_info ; + +struct sh_spi_info { +int bus_num; +int num_chipselect; + +struct spi_board_info *board_info; +unsigned long board_size; + +void (*chip_select)(struct sh_spi_info *spi,int cs,int state); +}; + +#endif /* __ASM_SPI_H__ */
PATCH 1/1 sh: add spi header and r2d platform data V2
sh: add spi header and r2d platform data V2
This patch adds the header file asm/spi.h and board specific code for the r2d board. The header file contains a structure that should be used to point out a single spi bus. The board specific code for r2d is updated with such a structure for the new spi_sh_sci driver. The structure contains a chip select callback plus information about the R9701 rtc chip which is attached to the spi bus.
---
Changes since V1 include:
- Use spi_register_board_info() instead of struct sh_spi_info.
- Set mode for r9701 in struct spi_board_info.
arch/sh/boards/renesas/rts7751r2d/setup.c | 47 +++++++++++++++++++++++++++++ include/asm-sh/spi.h | 13 ++++++++ 2 files changed, 60 insertions(+)
arch/sh/boards/renesas/rts7751r2d/setup.c +47 -0
@@ -16,9 +16,12 @@#include <linux/sm501-regs.h> #include <linux/pm.h> #include <linux/fb.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> #include <asm/machvec.h> #include <asm/rts7751r2d.h> #include <asm/io.h> +#include <asm/spi.h> static struct resource cf_ide_resources[] = { [0 ] = {
@@ -53,6 +56,43 @@ static struct platform_device cf_ide_dev }, }; +static struct spi_board_info spi_bus[] = { + { + .modalias ="rtc-r9701" , + .max_speed_hz =1000000 , + .mode =SPI_MODE_3 , + }, +}; + +static void r2d_chip_select (struct sh_spi_info *spi,int cs,int state) +{ +BUG_ON (cs !=0 );/* Single Epson RTC-9701JE attached on CS0 */ +ctrl_outw (state =BITBANG_CS_ACTIVE ?1 :0 ,PA_RTCCE ); +} + +static struct sh_spi_info spi_info = { + .num_chipselect =1 , + .chip_select = r2d_chip_select, +}; + +static struct resource spi_sh_sci_resources[] = { + { + .start =0xffe00000 , + .end =0xffe0001f , + .flags =IORESOURCE_MEM , + }, +}; + +static struct platform_device spi_sh_sci_device = { + .name ="spi_sh_sci" , + .id =-1 , + .num_resources =ARRAY_SIZE (spi_sh_sci_resources), + .resource = spi_sh_sci_resources, + .dev = { + .platform_data = &spi_info, + }, +}; +static struct resource heartbeat_resources[] = { [0 ] = { .start =PA_OUTPORT ,
@@ -176,6 +216,7 @@ static struct platform_device *rts7751r2#endif &cf_ide_device, &heartbeat_device, + &spi_sh_sci_device, };static int __init rts7751r2d_devices_setup (void )
@@ -260,6 +301,12 @@ static void __init rts7751r2d_setup(charwritel (readl (sm501_reg) | (1 <<SM501_GATE_UART0 ), sm501_reg); } +static int __init r2d_register_spi (void ) +{ +return spi_register_board_info (spi_bus,ARRAY_SIZE (spi_bus)); +} +__initcall (r2d_register_spi); +/* * The Machine Vector */
include/asm-sh/spi.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __ASM_SPI_H__ +#define __ASM_SPI_H__ + +struct sh_spi_info ; + +struct sh_spi_info { +int bus_num; +int num_chipselect; + +void (*chip_select)(struct sh_spi_info *spi,int cs,int state); +}; + +#endif /* __ASM_SPI_H__ */
Re: [PATCH] sh: add spi header and r2d platform data V2
In reply to Magnus Dammarch/sh/boards/renesas/rts7751r2d/setup.c static struct platform_device cf_ide_dev · line 64
Quoted 6 lines · Magnus Damm
arch/sh/boards/renesas/rts7751r2d/setup.c +6
-0+static void r2d_chip_select (struct sh_spi_info *spi,int cs,int state) +{ +BUG_ON (cs !=0 );/* Single Epson RTC-9701JE attached on CS0 */ +ctrl_outw (state =BITBANG_CS_ACTIVE ?1 :0 ,PA_RTCCE ); +} +
The ? 1 : 0 thing is pointless here. = will already evaluate to this. ? 1 : 0 is almost always crap anyways. Either the result you want already exists in terms of evaluation, or you want a !! for the far off bits. If there's nothing in CodingStyle about this, there ought to be.
arch/sh/boards/renesas/rts7751r2d/setup.c static struct platform_device *rts7751r2 · line 222
Quoted 8 lines
arch/sh/boards/renesas/rts7751r2d/setup.c +1
-0@@ -176,6 +216,7 @@ static struct platform_device *rts7751r2#endif &cf_ide_device, &heartbeat_device, + &spi_sh_sci_device, };static int __init rts7751r2d_devices_setup (void )
You've just added the device to the platform device registration.
Review static void __init rts7751r2d_setup(char · line 309
Quoted 10 lines
(quoted diff) +6
-0@@ -260,6 +301,12 @@ static void __init rts7751r2d_setup(char writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg); } +static int __init r2d_register_spi(void) +{ + return spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); +} +__initcall(r2d_register_spi); +
And then added your own magical initcall for registering the bus. We already have rts7751r2d_devices_setup(), which as the name implies, is intended specifically for this sort of thing. Please use that instead of spreading around more initcall damage.
PATCH 1/1 sh: add spi header and r2d platform data V3
In reply to Magnus Dammsh: add spi header and r2d platform data V3
This patch adds the header file asm/spi.h and board specific code for the r2d board. The header file contains a structure that should be used to point out a single spi bus. The board specific code for r2d is updated with such a structure for the new spi_sh_sci driver. The structure contains a chip select callback plus information about the R9701 rtc chip which is attached to the spi bus.
---
Changes since V2 include:
- Moved spi_register_board_info() to rts7751r2d_devices_setup().
- Removed silly comparison in r2d_chip_select().
arch/sh/boards/renesas/rts7751r2d/setup.c | 42 +++++++++++++++++++++++++++++ include/asm-sh/spi.h | 13 ++++++++ 2 files changed, 55 insertions(+)
arch/sh/boards/renesas/rts7751r2d/setup.c +42 -0
@@ -16,9 +16,12 @@#include <linux/sm501-regs.h> #include <linux/pm.h> #include <linux/fb.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> #include <asm/machvec.h> #include <asm/rts7751r2d.h> #include <asm/io.h> +#include <asm/spi.h> static struct resource cf_ide_resources[] = { [0 ] = {
@@ -53,6 +56,43 @@ static struct platform_device cf_ide_dev }, }; +static struct spi_board_info spi_bus[] = { + { + .modalias ="rtc-r9701" , + .max_speed_hz =1000000 , + .mode =SPI_MODE_3 , + }, +}; + +static void r2d_chip_select (struct sh_spi_info *spi,int cs,int state) +{ +BUG_ON (cs !=0 );/* Single Epson RTC-9701JE attached on CS0 */ +ctrl_outw (state =BITBANG_CS_ACTIVE ,PA_RTCCE ); +} + +static struct sh_spi_info spi_info = { + .num_chipselect =1 , + .chip_select = r2d_chip_select, +}; + +static struct resource spi_sh_sci_resources[] = { + { + .start =0xffe00000 , + .end =0xffe0001f , + .flags =IORESOURCE_MEM , + }, +}; + +static struct platform_device spi_sh_sci_device = { + .name ="spi_sh_sci" , + .id =-1 , + .num_resources =ARRAY_SIZE (spi_sh_sci_resources), + .resource = spi_sh_sci_resources, + .dev = { + .platform_data = &spi_info, + }, +}; +static struct resource heartbeat_resources[] = { [0 ] = { .start =PA_OUTPORT ,
@@ -176,10 +216,12 @@ static struct platform_device *rts7751r2#endif &cf_ide_device, &heartbeat_device, + &spi_sh_sci_device, };static int __init rts7751r2d_devices_setup (void ) { +spi_register_board_info (spi_bus,ARRAY_SIZE (spi_bus));return platform_add_devices (rts7751r2d_devices,ARRAY_SIZE (rts7751r2d_devices)); }
include/asm-sh/spi.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __ASM_SPI_H__ +#define __ASM_SPI_H__ + +struct sh_spi_info ; + +struct sh_spi_info { +int bus_num; +int num_chipselect; + +void (*chip_select)(struct sh_spi_info *spi,int cs,int state); +}; + +#endif /* __ASM_SPI_H__ */
Re: [PATCH] sh: add spi header and r2d platform data V3
In reply to Magnus DammQuoted 12 lines · Magnus Damm
sh: add spi header and r2d platform data V3
This patch adds the header file
asm/spi.hand board specific code for the r2d board. The header file contains a structure that should be used to point out a single spi bus. The board specific code for r2d is updated with such a structure for the newspi_sh_scidriver. The structure contains a chip select callback plus information about the R9701 rtc chip which is attached to the spi bus.Signed-off-by Magnus Damm <[email protected]>---
Quoted 8 lines
Changes since V2 include:
- Movedspi_register_board_info()torts7751r2d_devices_setup().
- Removed silly comparison inr2d_chip_select().arch/sh/boards/renesas/rts7751r2d/setup.c | 42 +++++++++++++++++++++++++++++ include/asm-sh/spi.h | 13 ++++++++ 2 files changed, 55 insertions(+)
Looks fine. I'll queue it up once the other bits hit -mm.
Re: [PATCH] sh: add spi header and r2d platform data V3
In reply to Magnus DammQuoted 17 lines · Paul Mundt
Quoted 16 lines · Magnus Damm
sh: add spi header and r2d platform data V3
This patch adds the header file
asm/spi.hand board specific code for the r2d board. The header file contains a structure that should be used to point out a single spi bus. The board specific code for r2d is updated with such a structure for the newspi_sh_scidriver. The structure contains a chip select callback plus information about the R9701 rtc chip which is attached to the spi bus.Signed-off-by Magnus Damm <[email protected]>---
Changes since V2 include:
- Movedspi_register_board_info()torts7751r2d_devices_setup().
- Removed silly comparison inr2d_chip_select().
Quoted 5 lines
Quoted 4 lines
arch/sh/boards/renesas/rts7751r2d/setup.c | 42 +++++++++++++++++++++++++++++ include/asm-sh/spi.h | 13 ++++++++ 2 files changed, 55 insertions(+)Looks fine. I'll queue it up once the other bits hit -mm.
Excellent. Thank you!
/ magnus