SPI support for fsl_soc and mpc832x_rdb
v2 cover SPI support for fsl_soc and mpc832x_rdb
Hi all,
Thanks for the previous review! Here is updated version, also needs your comments.
Changelog:
o Device tree:
- cosmetic cleanups (@01 -> @1);
- device-id renamed to fsl,device-id;
- removed max-chipselect and sysclk properties from spi node;
- removed chipselect property from mmc node, now reg property used for this purpose, thereby address-cells and size-cells added to the spi node;
- other non-mandatory (device-id, device_type, compatible, ...) properties removed from mmc node, today board file is using of_find_node_by_name(), instead of of_find_compatible_node();
- "qe" mode renamed to "cpu-qe".
o board file <-> fsl_soc interaction
- fsl_soc no longer scans for SPI nodes in the arch initcall. Also it's no longer exports any global variables. Instead, it's export fsl_spi_init function now, which accepts pointer to the fsl_spi_board_info structure;
- board file fills fsl_spi_board_info structure and issues fsl_spi_init(), which register SPI devices and SPI board infos. Various sanity checks also perfromed.
I'd want to note that if spi_mpc83xx will be converted to of_platform_driver then the scheme described above will not work anymore, and I'll have to revert back ugly hacks:
global variables for activate/deactivate_cs functions. I see no other options.
Thanks!
Signature · 4 lines
Anton Vorontsov email: [email protected] backup email: [email protected] irc://irc.freenode.net/bd2
RFC PATCH v2 1/2 MPC832x_RDB: update dts to use spi, register mmc_spi stub
mmc_spi already tested to work. When it will hit mainline the only change that will be needed is replacing "spidev" by "mmc_spi".
--- arch/powerpc/boot/dts/mpc832x_rdb.dts | 27 +++++++++++++- arch/powerpc/platforms/83xx/mpc832x_rdb.c | 55 +++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletions(-)
arch/powerpc/boot/dts/mpc832x_rdb.dts +26 -1
@@ -183,6 +183,21 @@ 1 c 1 0 1 0 /* TX_EN */ 1 d 2 0 1 0>; /* CRS */ }; + spi1pio: spi_pin@1 { + pio-map = < + /* port pin dir open_drain assignment has_irq */ + 3 0 3 0 1 0 /* SPI1 MOSI, I/O */ + 3 1 3 0 1 0 /* SPI1 MISO, I/O */ + 3 2 3 0 1 0 /* SPI1 CLK, I/O */ + 3 3 2 0 1 0>; /* SPI1 SEL, I */ + }; + mmc0pio: mmc_pin@0 { + pio-map = < + /* port pin dir open_drain assignment has_irq */ + 3 d 1 0 0 0 /* !SD_CS */ + 3 e 2 0 0 0 /* SD_INSERT */ + 3 f 2 0 0 0>; /* SD_PROTECT */ + }; }; };
@@ -206,16 +221,26 @@ }; spi@4c0 { + #address-cells = <1>; + #size-cells = <0>; device_type = "spi"; + fsl,device-id = <1>; compatible = "fsl_spi"; reg = <4c0 40>; interrupts = <2>; interrupt-parent = <&qeic>; - mode = "cpu"; + mode = "cpu-qe"; + pio-handle = <&spi1pio>; + + mmc@0 { + reg = <0>; + pio-handle = <&mmc0pio>; + }; }; spi@500 { device_type = "spi"; + fsl,device-id = <2>; compatible = "fsl_spi"; reg = <500 40>; interrupts = <1>;
arch/powerpc/platforms/83xx/mpc832x_rdb.c +55 -0
79 lines not on this page · raw message
Signature · 1 line
1.5.0.6
Re: [PATCH v2 1/2] [RFC][POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub
Quoted 16 lines · Anton Vorontsov
mmc_spialready tested to work. When it will hit mainline the only change that will be needed is replacing "spidev" by "mmc_spi".Signed-off-by Anton Vorontsov <[email protected]>--- arch/powerpc/boot/dts/mpc832x_rdb.dts | 27 +++++++++++++- arch/powerpc/platforms/83xx/mpc832x_rdb.c | 55 ++++++++++++++++++ +++++++++++ 2 files changed, 81 insertions(+), 1 deletions(-)arch/powerpc/boot/dts/mpc832x_rdb.dts +0
-0@@ -183,6 +183,21 @@
[snip]
Quoted 11 lines
arch/powerpc/boot/dts/mpc832x_rdb.dts +3
-0@@ -206,16 +221,26 @@ }; spi@4c0 { + #address-cells = <1>; + #size-cells = <0>; device_type = "spi"; + fsl,device-id = <1>; compatible = "fsl_spi"; reg = <4c0 40>; interrupts = <2>;
arch/powerpc/boot/dts/mpc832x_rdb.dts line 239
Quoted 10 lines
arch/powerpc/boot/dts/mpc832x_rdb.dts +7
-1interrupt-parent = <&qeic>; - mode = "cpu"; + mode = "cpu-qe"; + pio-handle = <&spi1pio>; + + mmc@0 { + reg = <0>; + pio-handle = <&mmc0pio>; + }; };
I'm still against this. Why don't we just do this in 83xx/mpc832x_rdb.c
- k
Re: [PATCH v2 1/2] [RFC][POWERPC] MPC832x_RDB: update dts to use spi, register mmc_spi stub
Quoted 7 lines
arch/powerpc/boot/dts/mpc832x_rdb.dts line 239
Quoted 5 lines
arch/powerpc/boot/dts/mpc832x_rdb.dts +4
-0+ mmc@0 { + reg = <0>; + pio-handle = <&mmc0pio>; + }; };I'm still against this. Why don't we just do this in
83xx/mpc832x_rdb.c
Seconded.
Segher
RFC PATCH v2 2/2 fsl_soc: add support for fsl_spi
In reply to Anton Vorontsov--- arch/powerpc/sysdev/fsl_soc.c | 109 +++++++++++++++++++++++++++++++++++++++++ arch/powerpc/sysdev/fsl_soc.h | 12 +++++ 2 files changed, 121 insertions(+), 0 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +109 -0
@@ -23,6 +23,7 @@#include <linux/device.h> #include <linux/platform_device.h> #include <linux/phy.h> +#include <linux/spi/spi.h> #include <linux/fsl_devices.h> #include <linux/fs_enet_pd.h> #include <linux/fs_uart_pd.h>
@@ -1186,3 +1187,111 @@ err:arch_initcall (cpm_smc_uart_of_init);#endif /* CONFIG_8xx */ + +static int fsl_spi_get_max_chipselect (struct device_node *spi_node, +struct fsl_spi_board_info *binfo, +s16 bus_num) +{ +struct device_node *child =NULL ; +unsigned int i =0 ; +unsigned int dt_num_children =0 ; +unsigned int bi_num_children =0 ; + +while ((child =of_get_next_child (spi_node, child))) + dt_num_children++; + +for (; i < binfo->num_board_infos; i++) { +if (binfo->board_infos[i].bus_num == bus_num) + bi_num_children++; + } + +if (dt_num_children != bi_num_children) { +printk (KERN_WARNING "%s: board file and device tree are " +"disagreeing about max chipselects: %d vs %d\n" , + __func__, bi_num_children, dt_num_children); + } + +return max (dt_num_children, bi_num_children); +} + +int fsl_spi_init (struct fsl_spi_board_info *binfo) +{ +struct device_node *np; +unsigned int i; +u32 sysclk; + + np =of_find_node_by_type (NULL ,"qe" ); +if (!np) +return -ENODEV ; + + sysclk = *(u32 *)of_get_property (np,"bus-frequency" ,NULL ); + +for (np =NULL , i =1 ; + (np =of_find_compatible_node (np,"spi" ,"fsl_spi" )) !=NULL ; + i++) { +int ret =0 ; +const char *devid; +const char *mode; +struct resource res[2 ]; +struct platform_device *pdev =NULL ; +struct fsl_spi_platform_data pdata = { + .activate_cs = binfo->activate_cs, + .deactivate_cs = binfo->deactivate_cs, + }; + +memset (res,0 ,sizeof (res)); + + devid =of_get_property (np,"fsl,device-id" ,NULL ); + mode =of_get_property (np,"mode" ,NULL ); +if (!devid || !mode) + goto err; + + pdata.sysclk = sysclk; + pdata.bus_num = *(u32 *)devid; + pdata.max_chipselect =fsl_spi_get_max_chipselect (np, binfo, + pdata.bus_num); +if (!pdata.max_chipselect) + goto err; + +if (!strcmp (mode,"cpu-qe" )) + pdata.qe_mode =1 ; + + ret =of_address_to_resource (np,0 , &res[0 ]); +if (ret) + goto err; + + res[1 ].start = res[2 ].end =irq_of_parse_and_map (np,0 ); +if (res[1 ].start ==NO_IRQ ) + goto err; + + res[1 ].name ="mpc83xx_spi" ; + res[1 ].flags =IORESOURCE_IRQ ;; + + pdev =platform_device_alloc ("mpc83xx_spi" , i); +if (!pdev) + goto err; + + ret =platform_device_add_data (pdev, &pdata,sizeof (pdata)); +if (ret) + goto unreg; + + ret =platform_device_add_resources (pdev, res, +ARRAY_SIZE (res)); +if (ret) + goto unreg; + + ret =platform_device_register (pdev); +if (ret) + goto unreg; + +continue ; +unreg: +platform_device_del (pdev); +err: +continue ; + } + +return spi_register_board_info (binfo->board_infos, + binfo->num_board_infos); +} +EXPORT_SYMBOL (fsl_spi_init);
arch/powerpc/sysdev/fsl_soc.h +12 -0
@@ -8,5 +8,17 @@ extern phys_addr_t get_immrbase(void);extern u32 get_brgfreq (void );extern u32 get_baudrate (void ); +struct spi_board_info ; + +struct fsl_spi_board_info { +struct spi_board_info *board_infos; +unsigned int num_board_infos; + +void (*activate_cs)(u8 cs,u8 polarity); +void (*deactivate_cs)(u8 cs,u8 polarity); +}; + +extern int fsl_spi_init (struct fsl_spi_board_info *info); +#endif #endif
Signature · 1 line
1.5.0.6