spi: Add PXA2xx SSP SPI Driver
Subsystems (4)
PATCH 1/1 spi: Add PXA2xx SSP SPI Driver
From: Stephen Street <[email protected]>
The driver turns a PXA2xx synchronous serial port (SSP) into a SPI master controller (see Documentation/spi/spi_summary). The driver has the following features:
- Support for any PXA2xx SSP
- SSP PIO and SSP DMA data transfers.
- External and Internal (SSPFRM) chip selects.
- Per slave device (chip) configuration.
- Full suspend, freeze, resume support.
---
Documentation/spi/pxa2xx | 234 +++++ drivers/spi/Kconfig | 8 drivers/spi/Makefile | 1 drivers/spi/pxa2xx_spi.c | 1512 ++++++++++++++++++++++++++++++++++ include/asm-arm/arch-pxa/pxa2xx_spi.h | 75 + 5 files changed, 1830 insertions(+)
drivers/spi/Kconfig +8 -0
@@ -85,6 +85,14 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_PXA2XX + tristate "PXA2xx SSP SPI master" + depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL + help + This enables using a PXA2xx SSP port as a SPI master controller. + The driver can be configured to use any SSP port and additional + documentation can be found a Documentation/spi/pxa2xx. + # # Add new SPI master controllers in alphabetical order above this line #
drivers/spi/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_SPI_MASTER) += spi.o # SPI master controller drivers (bus) obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o +obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o # ... add above this line ... # SPI protocol drivers (device/link on bus)
drivers/spi/pxa2xx_spi.c +1512 -0
1,512 lines not on this page · raw message
include/asm-arm/arch-pxa/pxa2xx_spi.h +75 -0
75 lines not on this page · raw message
Documentation/spi/pxa2xx +234 -0
234 lines not on this page · raw message
PATCH 1/1 pxa2xx_spi, board support for Lubbock
Building on Stephen's patch, here is board support for one of the reference pxa25x development platforms. To use this you will want some ads7846 patches ... I think they're now in Dmitry's input queue (or ask me).
This is against 2.6.16-rc2 ... now I get some tabletop space back! :)
- Dave
Lubbock update for SPI support: declare the SSP controller and ADS7846 device. This is only lightly tested, since my board doesn't populate J5 ... this seems to behave for access to the temperature sensors, but there's no way to hook up the touchscreen and use that.
arch/arm/mach-pxa/lubbock.c +77 -0
@@ -22,6 +22,10 @@#include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> +#include <linux/spi/spi.h> +#include <linux/spi/ads7846.h> +#include <asm/arch/pxa2xx_spi.h> +#include <asm/setup.h> #include <asm/memory.h> #include <asm/mach-types.h>
@@ -196,6 +200,71 @@ static struct resource smc91x_resources[ }, }; +/* ADS7846 is connected through SSP ... and if your board has J5 populated, +* you can select it to replace the ucb1400 by switching the touchscreen cable +* (to J5) and poking board registers (as done below). Else it's only usable +* for the temperature sensors. +*/ +static struct resource pxa_ssp_resources[] = { + [0 ] = { + .start =__PREG (SSCR0_P (1 )), + .end =__PREG (SSCR0_P (1 )) +0x14 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =IRQ_SSP , + .end =IRQ_SSP , + .flags =IORESOURCE_IRQ , + }, +}; + +static struct pxa2xx_spi_master pxa_ssp_master_info = { + .ssp_type = PXA25x_SSP, + .clock_enable =CKEN3_SSP , + .num_chipselect =0 , +}; + +static struct platform_device pxa_ssp = { + .name ="pxa2xx-spi" , + .id =1 , + .resource = pxa_ssp_resources, + .num_resources =ARRAY_SIZE (pxa_ssp_resources), + .dev = { + .platform_data = &pxa_ssp_master_info, + }, +}; + +static struct ads7846_platform_data ads_info = { + .model =7846 , + .vref_delay_usecs =100 ,/* internal, no cap */ + + .x_plate_ohms =500 ,/* GUESS! */ + .y_plate_ohms =500 ,/* GUESS! */ +}; + +static void ads7846_cs (u32 command) +{ +static const unsigned TS_nCS =1 <<11 ; +lubbock_set_misc_wr (TS_nCS, (command ==PXA2XX_CS_ASSERT ) ?0 : TS_nCS); +} + +static struct pxa2xx_spi_chip ads_hw = { + .tx_threshold =1 , + .rx_threshold =2 , + .cs_control = ads7846_cs, +}; + +static struct spi_board_info spi_board_info[]__initdata = { { + .modalias ="ads7846" , + .platform_data = &ads_info, + .controller_data = &ads_hw, + .irq =LUBBOCK_BB_IRQ , + .max_speed_hz =120000 /* max sample rate at 3V */ *16 , + .bus_num =1 , + .chip_select =0 , +}, +}; +static struct platform_device smc91x_device = { .name ="smc91x" , .id =-1 ,
@@ -272,6 +341,7 @@ static struct platform_device *devices[] &smc91x_device, &lubbock_flash_device[0 ], &lubbock_flash_device[1 ], + &pxa_ssp, }; static struct pxafb_mach_info sharp_lm8v31 __initdata = {
@@ -400,6 +470,8 @@ static void __init lubbock_init(void) lubbock_flash_data[flashboot^1 ].name ="application-flash" ; lubbock_flash_data[flashboot].name ="boot-rom" ; (void )platform_add_devices (devices,ARRAY_SIZE (devices)); + +spi_register_board_info (spi_board_info,ARRAY_SIZE (spi_board_info)); }static struct map_desc lubbock_io_desc[]__initdata = {
@@ -416,6 +488,11 @@ static void __init lubbock_map_io(void)pxa_map_io ();iotable_init (lubbock_io_desc,ARRAY_SIZE (lubbock_io_desc)); +/* SSP data pins */ +pxa_gpio_mode (GPIO23_SCLK_MD ); +pxa_gpio_mode (GPIO25_STXD_MD ); +pxa_gpio_mode (GPIO26_SRXD_MD ); +/* This enables the BTUART */ pxa_gpio_mode (GPIO42_BTRXD_MD );pxa_gpio_mode (GPIO43_BTTXD_MD );
Quoted 5 lines · [email protected] wrote:
From: Stephen Street <[email protected]>
The driver turns a PXA2xx synchronous serial port (SSP) into a SPI master controller (see
Documentation/spi/spi_summary). The driver has the following features:
I've not tested this on my PXA27x platform yet (I'll try and get this done this tomorrow) but a few comments.
drivers/spi/pxa2xx_spi.c
Quoted 5 lines
drivers/spi/pxa2xx_spi.c +1
-0+#define CLOCK_SPEED_HZ 3686400
PXA27x has a clock speed of 13000000 Hz.
drivers/spi/pxa2xx_spi.c line 1017
Quoted 1 line
drivers/spi/pxa2xx_spi.c +1
-0+ chip->cr0 =SSCR0_SerClkDiv ((CLOCK_SPEED_HZ / spi->max_speed_hz) +2 )
Consider spi->max_speed_hz == CLOCK_SPEED_HZ which gives a divisor of 3 (when it should be 1).
You need SSCR0_SerClkDiv(CLOCK_SPEED_HZ / (spi->max_speed_hz + 1) + 1) for the correct divisor and for proper rounding.
drivers/spi/pxa2xx_spi.c line 1225
Quoted 7 lines
drivers/spi/pxa2xx_spi.c +7
-0+/* Attach to IRQ */ + irq =platform_get_irq (pdev,0 ); +if (irq ==0 ) { +dev_err (&pdev->dev,"irq resource not defined\n" ); + status = -ENODEV ; + goto out_error_master_alloc; + }
Greg K-H has a patch pending that makes platform_get_irq() return -ENXIO instead of 0 on error. This is required for SSP3 on the PXA27x which uses IRQ 0.
drivers/spi/pxa2xx_spi.c line 1382
Quoted 4 lines
drivers/spi/pxa2xx_spi.c +4
-0+/* Release IRQ */ + irq =platform_get_irq (pdev,0 ); +if (irq !=0 ) +free_irq (irq, drv_data);
Similarly.
David Vrabel
Signature · 4 lines
David Vrabel, Design Engineer Arcom, Clifton Road Tel: +44 (0)1223 411200 ext. 3233 Cambridge CB1 7EA, UK Web: http://www.arcom.com/
Quoted 11 lines · David Vrabel
Quoted 5 lines · [email protected] wrote:
From: Stephen Street <[email protected]>
The driver turns a PXA2xx synchronous serial port (SSP) into a SPI master controller (see
Documentation/spi/spi_summary). The driver has the following features:I've not tested this on my PXA27x platform yet (I'll try and get this done this tomorrow) but a few comments.
Found time to test it today.
I needed to use DMA for all transfers (not just ones >= dma_burst_size) since at high clock rates (> ~5 MHz) PIO just can't keep up.
David Vrabel
Signature · 4 lines
David Vrabel, Design Engineer Arcom, Clifton Road Tel: +44 (0)1223 411200 ext. 3233 Cambridge CB1 7EA, UK Web: http://www.arcom.com/
drivers/spi/pxa2xx_spi.c +8 -7
@@ -43,7 +43,11 @@MODULE_DESCRIPTION ("PXA2xx SSP SPI Contoller" );MODULE_LICENSE ("GPL" ); -#define CLOCK_SPEED_HZ 3686400 +#if defined(CONFIG_PXA25x) +# define CLOCK_SPEED_HZ 3686400 +#elif defined(CONFIG_PXA27x) +# define CLOCK_SPEED_HZ 13000000 +#endif #define MAX_BUSES 3#define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)
@@ -429,9 +433,6 @@if (!IS_DMA_ALIGNED (drv_data->rx) || !IS_DMA_ALIGNED (drv_data->tx))return 0 ; -if (drv_data->len < drv_data->cur_chip->dma_burst_size) -return 0 ; -/* Modify setup if rx buffer is null */ if (drv_data->rx ==NULL ) { *(u32 *)(drv_data->null_dma_buf) =0 ;
@@ -1014,7 +1015,7 @@ chip->cr1 =SSCR1_LBM ; } - chip->cr0 =SSCR0_SerClkDiv ((CLOCK_SPEED_HZ / spi->max_speed_hz) +2 ) + chip->cr0 =SSCR0_SerClkDiv (CLOCK_SPEED_HZ / (spi->max_speed_hz +1 ) +1 ) | SSCR0_Motorola |SSCR0_DataSize (spi->bits_per_word &0x0f ) |SSCR0_SSE
@@ -1218,7 +1219,7 @@/* Attach to IRQ */ irq =platform_get_irq (pdev,0 ); -if (irq ==0 ) { +if (irq <0 ) {dev_err (&pdev->dev,"irq resource not defined\n" ); status = -ENODEV ; goto out_error_master_alloc;
@@ -1378,7 +1379,7 @@/* Release IRQ */ irq =platform_get_irq (pdev,0 ); -if (irq !=0 ) +if (irq >=0 )free_irq (irq, drv_data);/* Disconnect from the SPI framework */
drivers/spi/pxa2xx_spi.c line 434
Quoted 7 lines · David Vrabel
drivers/spi/pxa2xx_spi.c +0
-3@@ -429,9 +433,6 @@if (!IS_DMA_ALIGNED (drv_data->rx) || !IS_DMA_ALIGNED (drv_data->tx))return 0 ; -if (drv_data->len < drv_data->cur_chip->dma_burst_size) -return 0 ; -
Will do. This was a last minute crappy idea.
-Stephen
Quoted 2 lines · David Vrabel
PXA27x has a clock speed of 13000000 Hz.
Yea... And this affects the divisor calculation depending on type of CPU and when the CPU is a PXA260 or PXA25x which SSP port. And worse, the SSP controller (as opposed to the NSSP/ASSP) on the PXA25x and PXA260 use a different divisor calculation:
Serial Bit Rate = SSP Port Clock / 2 / (SCR + 1)
The pxa_regs.h file is misleading and potentially inaccurate in this respect.
Quoted 5 lines
Consider
spi->max_speed_hz==CLOCK_SPEED_HZwhich gives a divisor of 3 (when it should be 1).You need
SSCR0_SerClkDiv(CLOCK_SPEED_HZ / (spi->max_speed_hz + 1) + 1)for the correct divisor and for proper rounding.
Yes, but see qualification above. I will fix this as you suggest, with some modifications. FYI The CPU differences also exposed a similar problem with the DMA setup. Thanks!
Quoted 13 lines
drivers/spi/pxa2xx_spi.c line 1225
Quoted 8 lines
drivers/spi/pxa2xx_spi.c +7
-0+/* Attach to IRQ */ + irq =platform_get_irq (pdev,0 ); +if (irq ==0 ) { +dev_err (&pdev->dev,"irq resource not defined\n" ); + status = -ENODEV ; + goto out_error_master_alloc; + }Greg K-H has a patch pending that makes
platform_get_irq()return-ENXIOinstead of 0 on error. This is required for SSP3 on the PXA27x which uses IRQ 0.
Quoted 6 lines
drivers/spi/pxa2xx_spi.c line 1382
Quoted 4 lines
drivers/spi/pxa2xx_spi.c +4
-0+/* Release IRQ */ + irq =platform_get_irq (pdev,0 ); +if (irq !=0 ) +free_irq (irq, drv_data);Similarly.
Will do.
I will re-post the patch again to today. Thanks for the help.
-Stephen
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
In reply to [email protected]Sorry for the delay in posting this. My workstation crashed on Tuesday and I'm still recovering.
Attached is an updated patch to add SPI master controller for PXA2xx boards. This update includes fixes for the PXA27x CPU to correctly handle the differences peripheral clock speeds with in the PXA2xx family.
I have tested the driver extensively on the PXA255 NSSP port. My application includes a 3 slave chip SPI bus configuration which I have driven under load (44850+ bytes per second). Everything appears to work great. I also implemented a sample loopback driver (please e-mail me directly if you are interested the loopback driver) for testing purposes and used it to test the driver on the PXA255 SSP port.
It would be nice is additional eyes review my implementation as I only have access to a custom PXA255 board. Any feedback or word of success would be greatly appreciated!
Stephen
The driver turns a PXA2xx synchronous serial port (SSP) into a SPI master controller (see Documentation/spi/spi_summary). The driver has the following features:
- Support for any PXA2xx SSP
- SSP PIO and SSP DMA data transfers.
- External and Internal (SSPFRM) chip selects.
- Per slave device (chip) configuration.
- Full suspend, freeze, resume support.
---
Documentation/spi/pxa2xx | 234 +++++ drivers/spi/Kconfig | 8 drivers/spi/Makefile | 1 drivers/spi/pxa2xx_spi.c | 1523 ++++++++++++++++++++++++++++++++++ include/asm-arm/arch-pxa/pxa2xx_spi.h | 91 ++ 5 files changed, 1857 insertions(+)
drivers/spi/Kconfig +8 -0
@@ -85,6 +85,14 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_PXA2XX + tristate "PXA2xx SSP SPI master" + depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL + help + This enables using a PXA2xx SSP port as a SPI master controller. + The driver can be configured to use any SSP port and additional + documentation can be found a Documentation/spi/pxa2xx. + # # Add new SPI master controllers in alphabetical order above this line #
drivers/spi/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_SPI_MASTER) += spi.o # SPI master controller drivers (bus) obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o +obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o # ... add above this line ... # SPI protocol drivers (device/link on bus)
drivers/spi/pxa2xx_spi.c +1523 -0
1,523 lines not on this page · raw message
include/asm-arm/arch-pxa/pxa2xx_spi.h +91 -0
91 lines not on this page · raw message
Documentation/spi/pxa2xx +234 -0
234 lines not on this page · raw message
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 6 lines · Stephen Street
Attached is an updated patch to add SPI master controller for PXA2xx boards. This update includes fixes for the PXA27x CPU to correctly handle the differences peripheral clock speeds with in the PXA2xx family.
Driver looks pretty clean. It's refreshingly deviod of comments ;)
Random minor observations:
drivers/spi/pxa2xx_spi.c line 159
Quoted 12 lines
drivers/spi/pxa2xx_spi.c +12
-0+static inline void flush (struct driver_data *drv_data) +{ +u32 sssr = drv_data->sssr; +u32 ssdr = drv_data->ssdr; + +do { +while (SSP_REG (sssr) &SSSR_RNE ) { + (void )SSP_REG (ssdr); + } + }while (SSP_REG (sssr) &SSSR_BSY ); +SSP_REG (sssr) =SSSR_ROR ; +}
Suggest this be uninlined.
drivers/spi/pxa2xx_spi.c line 281
Quoted 9 lines
drivers/spi/pxa2xx_spi.c +9
-0+static inline void save_state(struct driver_data *drv_data) +static inline void restore_state(struct driver_data *drv_data) +static inline void dump_dma_state(struct driver_data *drv_data) +static inline void dump_ssp_state(struct driver_data *drv_data) +static inline void dump_message(char *header, struct spi_message *msg) +static inline void dump_transfer_state(char* header, struct driver_data *drv_data) +static inline void dump_chip_state(struct device *dev, + char * header, + struct chip_data *chip)
These appear to not have any callers?
Suggest they be uninlined, but that'd generate defined-but-not-used warnings.
drivers/spi/pxa2xx_spi.c line 315
Quoted 12 lines
drivers/spi/pxa2xx_spi.c +12
-0+static void null_writer (struct driver_data *drv_data) +{ +u32 sssr = drv_data->sssr; +u32 ssdr = drv_data->ssdr; +u8 n_bytes = drv_data->cur_chip->n_bytes; + +while ((SSP_REG (sssr) &SSSR_TNF ) + && (drv_data->tx < drv_data->tx_end)) { +SSP_REG (ssdr) =0 ; + drv_data->tx += n_bytes; + } +}
hm.
#define SSP_REG(x) (*((volatile unsigned long *)x))
what's this doing? Accessing a device register? Cannot we use readl/writel?
Quoted 1 line
+static inline void*
next_transfer(struct driver_data *drv_data)
^^ swap these chars!
Quoted 4 lines
drivers/spi/pxa2xx_spi.c +4
-0+{ +struct spi_message *msg = drv_data->cur_msg; +struct spi_transfer *trans = drv_data->cur_transfer; +
drivers/spi/pxa2xx_spi.c line 415
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+/* Move to next transfer */ +if (trans->transfer_list.next != &msg->transfers) { + drv_data->cur_transfer = +list_entry (trans->transfer_list.next, + struct spi_transfer, + transfer_list); +return RUNNING_STATE ; + }else +return DONE_STATE ; +}
Suggest this be uninlined.
Review
Quoted 1 line
(quoted diff) +1
-0+ *(u32 *)(drv_data->null_dma_buf) = 0;
null_dma_buf gets typecast a lot. Maybe make it a u32*?
Quoted 5 lines
drivers/spi/pxa2xx_spi.c +5
-0+static void giveback (struct spi_message *message,struct driver_data *drv_data) +{ +struct spi_transfer * last_transfer; + + last_transfer = list_entry(message->transfers.prev,
drivers/spi/pxa2xx_spi.c line 502
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+ struct spi_transfer, + transfer_list); + +if (!last_transfer->cs_change) + drv_data->cs_control (PXA2XX_CS_DEASSERT ); + + message->state =NULL ; +if (message->complete) { + message->complete (message->context); + }
Unneeded braces.
drivers/spi/pxa2xx_spi.c line 512
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+static void dma_handler (int channel,void *data,struct pt_regs *regs) +{ +struct driver_data *drv_data = (struct driver_data *)data;
Unneeded typecast.
drivers/spi/pxa2xx_spi.c line 555
Quoted 8 lines
drivers/spi/pxa2xx_spi.c +8
-0+/* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */ +if ((drv_data->ssp_type == PXA25x_SSP) + && (channel == drv_data->tx_channel) + && (irq_status &DCSR_ENDINTR )) { + +/* Wait for rx to stall */ +while (SSP_REG (sssr) &SSSR_BSY ) +cpu_relax ();
A timeout here, perhaps?
drivers/spi/pxa2xx_spi.c line 563
Quoted 2 lines
drivers/spi/pxa2xx_spi.c +2
-0+while (!(DCSR (drv_data->rx_channel) &DCSR_STOPSTATE )) +cpu_relax ();
And here.
Quoted 34 lines
drivers/spi/pxa2xx_spi.c +34
-0+static irqreturn_t dma_transfer (struct driver_data *drv_data) +{ +u32 sssr = drv_data->sssr; +u32 sscr1 = drv_data->sscr1; +u32 ssto = drv_data->ssto; +u32 irq_status =SSP_REG (sssr) & drv_data->mask_sr; +u32 trailing_sssr =0 ; +struct spi_message *msg = drv_data->cur_msg; + +if (irq_status &SSSR_ROR ) { +/* Clear and disable interrupts on SSP and DMA channels*/ +SSP_REG (ssto) =0 ; +SSP_REG (sssr) = drv_data->clear_sr; +SSP_REG (sscr1) &= ~(drv_data->dma_cr1); +DCSR (drv_data->tx_channel) =RESET_DMA_CHANNEL ; +DCSR (drv_data->rx_channel) =RESET_DMA_CHANNEL ; +unmap_dma_buffers (drv_data); +flush (drv_data); + +dev_warn (&drv_data->pdev->dev,"dma_transfer: fifo overun\n" ); + + drv_data->cur_msg->state =ERROR_STATE ; +tasklet_schedule (&drv_data->pump_transfers); + +return IRQ_HANDLED ; + } + +/* Check for false positive timeout */ +if ((irq_status &SSSR_TINT ) &&DCSR (drv_data->tx_channel) &DCSR_RUN ) { +SSP_REG (sssr) =SSSR_TINT ; +return IRQ_HANDLED ; + } + +if (irq_status &SSSR_TINT || drv_data->rx == drv_data->rx_end) {
drivers/spi/pxa2xx_spi.c line 633
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+ +/* Clear and disable interrupts on SSP and DMA channels*/ +SSP_REG (ssto) =0 ; +SSP_REG (sssr) = drv_data->clear_sr; +SSP_REG (sscr1) &= ~(drv_data->dma_cr1); +DCSR (drv_data->tx_channel) =RESET_DMA_CHANNEL ; +DCSR (drv_data->rx_channel) =RESET_DMA_CHANNEL ; +while (!(DCSR (drv_data->rx_channel) &DCSR_STOPSTATE ) + || (SSP_REG (sssr) &SSSR_BSY )) +cpu_relax ();
And here.
Quoted 16 lines
drivers/spi/pxa2xx_spi.c +16
-0+unmap_dma_buffers (drv_data); + +/* Calculate number of trailing bytes, read them */ + trailing_sssr =SSP_REG (sssr); +if ((trailing_sssr &0xf008 ) !=0xf000 ) { + drv_data->rx = drv_data->rx_end - + (((trailing_sssr >>12 ) &0x0f ) +1 ); + drv_data->read (drv_data); + } + msg->actual_length += drv_data->len; + +/* Release chip select if requested, transfer delays are +* handled in pump_transfers */ +if (drv_data->cs_change) + drv_data->cs_control (PXA2XX_CS_DEASSERT ); +
drivers/spi/pxa2xx_spi.c line 660
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+/* Move to next transfer */ + msg->state =next_transfer (drv_data); + +/* Schedule transfer tasklet */ +tasklet_schedule (&drv_data->pump_transfers); + +return IRQ_HANDLED ; + } + +/* Never Fail */
WARN_ON(1)?
Why not return IRQ_NONE here? That way, the IRQ system will save the machine if the IRQ gets stuck.
drivers/spi/pxa2xx_spi.c line 689
Quoted 8 lines
drivers/spi/pxa2xx_spi.c +7
-0+return IRQ_HANDLED ; +} + +static irqreturn_t interrupt_transfer (struct driver_data *drv_data) +{ +return IRQ_HANDLED ; +}
Ditto.
drivers/spi/pxa2xx_spi.c line 851
Quoted 7 lines
drivers/spi/pxa2xx_spi.c +6
-0+static void pump_transfers (unsigned long data) +{ +/* Enable dma end irqs on SSP to detect end of transfer */ +if (drv_data->ssp_type == PXA25x_SSP) { +DCMD (drv_data->tx_channel) |=DCMD_ENDIRQEN ; + }
Braces.
Quoted 21 lines
drivers/spi/pxa2xx_spi.c +21
-0+static int setup (struct spi_device *spi) +{ +struct pxa2xx_spi_chip *chip_info =NULL ; +struct chip_data *chip; +struct driver_data *drv_data =spi_master_get_devdata (spi->master); +unsigned int clk_div; + +if (!spi->bits_per_word) + spi->bits_per_word =8 ; + +if (drv_data->ssp_type != PXA25x_SSP + && (spi->bits_per_word <4 || spi->bits_per_word >32 )) +return -EINVAL ; +else if (spi->bits_per_word <4 || spi->bits_per_word >16 ) +return -EINVAL ; + +/* Only alloc (or use chip_info) on first setup */ + chip =spi_get_ctldata (spi); +if (chip ==NULL ) { + chip =kzalloc (sizeof (struct chip_data ),GFP_KERNEL ); +if (!chip)
drivers/spi/pxa2xx_spi.c line 976
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+return -ENOMEM ; + + chip->cs_control = null_cs_control; + chip->enable_dma =0 ; + chip->timeout =5 ; + chip->threshold =SSCR1_RxTresh (1 ) |SSCR1_TxTresh (1 ); + chip->dma_burst_size = drv_data->master_info->enable_dma ? +DCMD_BURST8 :0 ; + + chip_info = (struct pxa2xx_spi_chip *)spi->controller_data;
Unneeded cast.
drivers/spi/pxa2xx_spi.c line 1026
Quoted 13 lines
drivers/spi/pxa2xx_spi.c +13
-0+switch (drv_data->sscr0) { +case SSP1_VIRT : + clk_div =SSP1_SerClkDiv (spi->max_speed_hz); +break ; +case SSP2_VIRT : + clk_div =SSP2_SerClkDiv (spi->max_speed_hz); +break ; +case SSP3_VIRT : + clk_div =SSP3_SerClkDiv (spi->max_speed_hz); +break ; +default : +return -ENODEV ; + }
We normally lay out switch statements one tabstop less than this.
drivers/spi/pxa2xx_spi.c line 1079
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+static void cleanup (const struct spi_device *spi) +{ +struct chip_data *chip =spi_get_ctldata ((struct spi_device *)spi);
Remove the typecast, change spi_get_ctldata() to take a const struct spi_device *? I guess that might cause warnings too - the compiler might want spi_get_ctldata() to return a const thing.
Might be simpler to not have a const arg here.
drivers/spi/pxa2xx_spi.c line 1082
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+if (chip) +kfree (chip); +}
kfree(NULL) is legal.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + queue_work(drv_data->workqueue, &drv_data->pump_messages);
I see a queue_work(), but I see no flush_workqueue(). Basically a flush is always needed to push through any pending work in the shutdown/close/rmmod paths.
drivers/spi/pxa2xx_spi.c line 1157
Quoted 9 lines
drivers/spi/pxa2xx_spi.c +9
-0+static int destroy_queue (struct driver_data *drv_data) +{ +int status; + + status =stop_queue (drv_data); +if (status !=0 ) +return status; + +destroy_workqueue (drv_data->workqueue);
hm, OK, destroy_workqueue() does flush_workqueue.
drivers/spi/pxa2xx_spi.c line 1172
Quoted 11 lines
drivers/spi/pxa2xx_spi.c +11
-0+static int pxa2xx_spi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct pxa2xx_spi_master *platform_info; +struct spi_master *master; +struct driver_data *drv_data =0 ; +struct resource *memory_resource; +int irq; +int status =0 ; + + platform_info = (struct pxa2xx_spi_master *)dev->platform_data;
Unneeded cast.
drivers/spi/pxa2xx_spi.c line 1199
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+ drv_data->null_dma_buf = drv_data +sizeof (struct driver_data ); + drv_data->null_dma_buf = (void *)(((u32)(drv_data->null_dma_buf) + &0xfffffff8 ) |8 );
Consider using the ALIGN() macro here.
This all looks very non-64-bit-capable.
drivers/spi/pxa2xx_spi.c line 1346
Quoted 2 lines
drivers/spi/pxa2xx_spi.c +2
-0+out_error_master_alloc: + (void )spi_master_put (master);
Remove the (void). Unless it does something??
drivers/spi/pxa2xx_spi.c line 1410
Quoted 7 lines
drivers/spi/pxa2xx_spi.c +7
-0+static void pxa2xx_spi_shutdown (struct platform_device *pdev) +{ +int status =0 ; + +if ((status =pxa2xx_spi_remove (pdev)) !=0 ) { +dev_err (&pdev->dev,"shutdown failed with %d\n" , status); + }
Braces.
Quoted 5 lines
drivers/spi/pxa2xx_spi.c +5
-0+#ifdef CONFIG_PM +static int stall_queue (struct driver_data *drv_data) +{ +unsigned long flags; +unsigned limit =500 ;
drivers/spi/pxa2xx_spi.c line 1427
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+ +spin_lock_irqsave (&drv_data->lock, flags); + + drv_data->run =QUEUE_STALLED ; + +while (drv_data->busy && limit--) { +spin_unlock_irqrestore (&drv_data->lock, flags); +msleep (10 ); +spin_lock_irqsave (&drv_data->lock, flags); + }
That looks a bit lame. What's happening here?
drivers/spi/pxa2xx_spi.c line 1144
Quoted 4 lines
drivers/spi/pxa2xx_spi.c +4
-0+spin_unlock_irqrestore (&drv_data->lock, flags); + +if (!list_empty (&drv_data->queue) || drv_data->busy) +return -EBUSY ;
Does the list_empty() make sense outside the lock?
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 1 line · Andrew Morton
Driver looks pretty clean. It's refreshingly deviod of comments ;)
Thanks. Add more comments? I got scared of over commenting as a result of reading the kernel code style document.
Quoted 15 lines
drivers/spi/pxa2xx_spi.c line 315
Quoted 12 lines
drivers/spi/pxa2xx_spi.c +12
-0+static void null_writer (struct driver_data *drv_data) +{ +u32 sssr = drv_data->sssr; +u32 ssdr = drv_data->ssdr; +u8 n_bytes = drv_data->cur_chip->n_bytes; + +while ((SSP_REG (sssr) &SSSR_TNF ) + && (drv_data->tx < drv_data->tx_end)) { +SSP_REG (ssdr) =0 ; + drv_data->tx += n_bytes; + } +}hm.
Quoted 4 lines
#define SSP_REG(x) (*((volatile unsigned long *)x))what's this doing? Accessing a device register? Cannot we use readl/writel?
Just following the pattern in include/asm-arm/arch-pxa/pxa_regs.h Nicolas made a similar comment. I'm changing it now.
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ *(u32 *)(drv_data->null_dma_buf) = 0;
null_dma_bufgets typecast a lot. Maybe make it a u32*?
Yes.
Quoted 11 lines
drivers/spi/pxa2xx_spi.c line 555
Quoted 8 lines
drivers/spi/pxa2xx_spi.c +8
-0+/* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */ +if ((drv_data->ssp_type == PXA25x_SSP) + && (channel == drv_data->tx_channel) + && (irq_status &DCSR_ENDINTR )) { + +/* Wait for rx to stall */ +while (SSP_REG (sssr) &SSSR_BSY ) +cpu_relax ();A timeout here, perhaps?
Quoted 3 lines
drivers/spi/pxa2xx_spi.c line 563
Quoted 2 lines
drivers/spi/pxa2xx_spi.c +2
-0+while (!(DCSR (drv_data->rx_channel) &DCSR_STOPSTATE )) +cpu_relax ();
Ok, but if a SSP or the DMA channel never stops then the CPU is probably toast anywise.
Quoted 29 lines
Quoted 16 lines
drivers/spi/pxa2xx_spi.c +16
-0+unmap_dma_buffers (drv_data); + +/* Calculate number of trailing bytes, read them */ + trailing_sssr =SSP_REG (sssr); +if ((trailing_sssr &0xf008 ) !=0xf000 ) { + drv_data->rx = drv_data->rx_end - + (((trailing_sssr >>12 ) &0x0f ) +1 ); + drv_data->read (drv_data); + } + msg->actual_length += drv_data->len; + +/* Release chip select if requested, transfer delays are +* handled in pump_transfers */ +if (drv_data->cs_change) + drv_data->cs_control (PXA2XX_CS_DEASSERT ); +drivers/spi/pxa2xx_spi.c line 660
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+/* Move to next transfer */ + msg->state =next_transfer (drv_data); + +/* Schedule transfer tasklet */ +tasklet_schedule (&drv_data->pump_transfers); + +return IRQ_HANDLED ; + } + +/* Never Fail */
WARN_ON(1)?
Quoted 3 lines
Why not return
IRQ_NONEhere? That way, the IRQ system will save the machine if the IRQ gets stuck.
In my generally confused state I decided that if the IRQ handler ran then by definition I handled the interrupt. But thats probably not right. Will change.
Quoted 8 lines
drivers/spi/pxa2xx_spi.c line 1079
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+static void cleanup (const struct spi_device *spi) +{ +struct chip_data *chip =spi_get_ctldata ((struct spi_device *)spi);Remove the typecast, change
spi_get_ctldata()to take a const structspi_device*? I guess that might cause warnings too - the compiler might wantspi_get_ctldata()to return a const thing.
I will talk with David about this. Maybe the right answer is changing the cleanup function signiture.
Quoted 6 lines
drivers/spi/pxa2xx_spi.c line 1199
Quoted 3 lines
drivers/spi/pxa2xx_spi.c +3
-0+ drv_data->null_dma_buf = drv_data +sizeof (struct driver_data ); + drv_data->null_dma_buf = (void *)(((u32)(drv_data->null_dma_buf) + &0xfffffff8 ) |8 );Consider using the
ALIGN()macro here.
I been looking for someway to due this for weeks and now I found it. THANKS!
Quoted 1 line
This all looks very non-64-bit-capable.
Just the null_dma_buf issue or something more?
Quoted 9 lines
Quoted 9 lines
drivers/spi/pxa2xx_spi.c +9
-0+#ifdef CONFIG_PM +static int stall_queue (struct driver_data *drv_data) +{ +unsigned long flags; +unsigned limit =500 ; + +spin_lock_irqsave (&drv_data->lock, flags); + + drv_data->run =QUEUE_STALLED ;
Quoted 8 lines
drivers/spi/pxa2xx_spi.c line 1427
Quoted 6 lines
drivers/spi/pxa2xx_spi.c +6
-0+ +while (drv_data->busy && limit--) { +spin_unlock_irqrestore (&drv_data->lock, flags); +msleep (10 ); +spin_lock_irqsave (&drv_data->lock, flags); + }That looks a bit lame. What's happening here?
Sort of dumb, I agree. I interpreted PM_EVENT_FREEZE to mean that I should stop processing the internal message queue but leave the queue intact so that it can be restarted. "stall_queue" does this by setting the run flag to QUEUE_STALLED (checked in pump_messages) and waiting for the busy to indicate the idle state. I considered using an wait_queue but this seemed to much for to little. Would you prefer a wait_queue?
Quoted 6 lines
drivers/spi/pxa2xx_spi.c line 1144
Quoted 4 lines
drivers/spi/pxa2xx_spi.c +4
-0+spin_unlock_irqrestore (&drv_data->lock, flags); + +if (!list_empty (&drv_data->queue) || drv_data->busy) +return -EBUSY ;Does the
list_empty()make sense outside the lock?
Badness
Thanks for the through review!
Stephen
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 31 lines · Stephen Street
...
Quoted 29 lines
Quoted 16 lines
drivers/spi/pxa2xx_spi.c +16
-0+unmap_dma_buffers (drv_data); + +/* Calculate number of trailing bytes, read them */ + trailing_sssr =SSP_REG (sssr); +if ((trailing_sssr &0xf008 ) !=0xf000 ) { + drv_data->rx = drv_data->rx_end - + (((trailing_sssr >>12 ) &0x0f ) +1 ); + drv_data->read (drv_data); + } + msg->actual_length += drv_data->len; + +/* Release chip select if requested, transfer delays are +* handled in pump_transfers */ +if (drv_data->cs_change) + drv_data->cs_control (PXA2XX_CS_DEASSERT ); +drivers/spi/pxa2xx_spi.c line 660
Quoted 10 lines
drivers/spi/pxa2xx_spi.c +10
-0+/* Move to next transfer */ + msg->state =next_transfer (drv_data); + +/* Schedule transfer tasklet */ +tasklet_schedule (&drv_data->pump_transfers); + +return IRQ_HANDLED ; + } + +/* Never Fail */
WARN_ON(1)?
Quoted 6 lines
Quoted 3 lines
Why not return
IRQ_NONEhere? That way, the IRQ system will save the machine if the IRQ gets stuck.In my generally confused state I decided that if the IRQ handler ran then by definition I handled the interrupt. But thats probably not right. Will change.
Yes, IRQ_NONE means "I don't have a clue why this IRQ handler was called - none of my device registers indicate that anything needs servicing".
The core kernel IRQ handling will see that as a signal that perhaps the hardware is busted and ultimately it will disable the entire IRQ line so the machine can continue to struggle along.
Quoted 2 lines
Quoted 1 line
This all looks very non-64-bit-capable.
Just the
null_dma_bufissue or something more?
Well, yes, that expression. Generally if you get all the types right and avoid typecasting, the compiler will shout at you about 64-bit-brokenness.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
drivers/spi/pxa2xx_spi.c +9
-0+#ifdef CONFIG_PM +static int stall_queue (struct driver_data *drv_data) +{ +unsigned long flags; +unsigned limit =500 ; + +spin_lock_irqsave (&drv_data->lock, flags); + + drv_data->run =QUEUE_STALLED ;Quoted 8 lines
drivers/spi/pxa2xx_spi.c line 1427
Quoted 6 lines
drivers/spi/pxa2xx_spi.c +6
-0+ +while (drv_data->busy && limit--) { +spin_unlock_irqrestore (&drv_data->lock, flags); +msleep (10 ); +spin_lock_irqsave (&drv_data->lock, flags); + }That looks a bit lame. What's happening here?
Quoted 7 lines
Sort of dumb, I agree. I interpreted
PM_EVENT_FREEZEto mean that I should stop processing the internal message queue but leave the queue intact so that it can be restarted. "stall_queue" does this by setting the run flag toQUEUE_STALLED(checked inpump_messages) and waiting for the busy to indicate the idle state. I considered using anwait_queuebut this seemed to much for to little. Would you prefer await_queue?
I guess a waitqueue would be nicer. I don't recall seeing drivers doing anything really fancy like this in response to a suspend request though.
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
In reply to Stephen StreetQuoted 15 lines · Stephen Street
Sorry for the delay in posting this. My workstation crashed on Tuesday and I'm still recovering.
Attached is an updated patch to add SPI master controller for PXA2xx boards. This update includes fixes for the PXA27x CPU to correctly handle the differences peripheral clock speeds with in the PXA2xx family.
I have tested the driver extensively on the PXA255 NSSP port. My application includes a 3 slave chip SPI bus configuration which I have driven under load (44850+ bytes per second). Everything appears to work great. I also implemented a sample loopback driver (please e-mail me directly if you are interested the loopback driver) for testing purposes and used it to test the driver on the PXA255 SSP port.
Quoted 3 lines
It would be nice is additional eyes review my implementation as I only have access to a custom PXA255 board. Any feedback or word of success would be greatly appreciated!
[...]
+#define SSP_REG(x) (*((volatile unsigned long *)x))
Don't do that. Instead, please use:
#define DEFINE_SSP_REG(reg, off) \
static inline u32 read_##reg(void *p) { return __raw_readl(p + (off)); \
static inline void write_##reg(u32 v, void *p) { __raw_writel(v, p + (off)); }
DEFINE_SSP_REG(SSCR0, 0x00)DEFINE_SSP_REG(SSCR1, 0x04)DEFINE_SSP_REG(SSSR, 0x08)DEFINE_SSP_REG(SSITR, 0x0c)DEFINE_SSP_REG(SSDR, 0x10)DEFINE_SSP_REG(SSTO, 0x28)DEFINE_SSP_REG(SSPSP, 0x2c)
[...]
+ /* SSP register addresses */
+ u32 sscr0;
+ u32 sscr1;
+ u32 sssr;
+ u32 ssitr;
+ u32 ssdr;
+ u32 ssdr_physical;
+ u32 ssto;
+ u32 Bsspsp;
And then you'll only need to store the base address for each port:
void *ioaddr;
[...]
+static inline void flush(struct driver_data *drv_data) +{
+ u32 sssr = drv_data->sssr;
+ u32 ssdr = drv_data->ssdr;
+
+ do {
+ while (SSP_REG(sssr) & SSSR_RNE) {
+ (void)SSP_REG(ssdr);
+ }
+ } while (SSP_REG(sssr) & SSSR_BSY);
+ SSP_REG(sssr) = SSSR_ROR ;
+}
Then it would become:
static inline void flush(struct driver_data *drv_data)
{
void *reg = drv_data->ioaddr;
do {
while (read_SSSR(reg) & SSSR_RNE)
read_SSDR(reg);
} while (read_SSSR(reg) & SSSR_BSY);
write_SSSR(SSSR_ROR, reg);
}This will make your structure smaller, and gcc will be able to produce much smaller and better code due to less register pressure and constant base offsets. It also make the source a bit more readable with fewer possibilities for errors like:
+static void dma_handler(int channel, void *data, struct pt_regs *regs) +{
+ struct driver_data *drv_data = (struct driver_data *)data;
+ struct spi_message *msg = drv_data->cur_msg;
+ u32 sssr = drv_data->sssr;
+ u32 sscr1 = drv_data->sscr1;
+ u32 ssto = drv_data->sscr1;
^^^^^^^^^^^^^^^^^^^^^^^^^^Nicolas
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 10 lines · Nicolas Pitre
[...]
+#define
SSP_REG(x)(*((volatile unsigned long *)x))Don't do that. Instead, please use:
#define
DEFINE_SSP_REG(reg, off)\
static inline u32 read_##reg(void *p) { return__raw_readl(p + (off)); \
static inline void write_##reg(u32 v, void *p) {__raw_writel(v, p + (off)); }
Quoted 8 lines
DEFINE_SSP_REG(SSCR0, 0x00)DEFINE_SSP_REG(SSCR1, 0x04)DEFINE_SSP_REG(SSSR, 0x08)DEFINE_SSP_REG(SSITR, 0x0c)DEFINE_SSP_REG(SSDR, 0x10)DEFINE_SSP_REG(SSTO, 0x28)DEFINE_SSP_REG(SSPSP, 0x2c)
Ok, I'll do this (Andrew made a similar comment). But...
I modeled my SSP_REG on the contents of include/asm- arm/arch_pxa/pxa_reg.h which makes extensive use of __REG defined in include/asm-arm/arch_pxa/hardware.h as
#define __REG(x) (*((volatile u32 *)io_p2v(x)))
which is effectively my SSP_REG without the io_p2v because I preloaded the virtual SSP register addresses in the pxa2xx_spi_probe function.
For my education:
Why are __raw_readl and friends better than exploiting the memory map I/O nature of the PXA2xx and other SOCs?
Especially since something like
SSP_REG(sscr1) &= ~SSCR1_TIE;
becomes
write_SSCR1(read_SSCR1(reg) & ~SSCR_TIE, reg);
Further what should I do with the DMA register accesses (i.e. DCSR, DCMD, etc)?
drivers/spi/pxa2xx_spi.c
Quoted 9 lines
drivers/spi/pxa2xx_spi.c +7
-0+static void dma_handler (int channel,void *data,struct pt_regs *regs) +{ +struct driver_data *drv_data = (struct driver_data *)data; +struct spi_message *msg = drv_data->cur_msg; +u32 sssr = drv_data->sssr; +u32 sscr1 = drv_data->sscr1; +u32 ssto = drv_data->sscr1; ^^^^^^^^^^^^^^^^^^^^^^^^^^
Definitely wrong, harmless in this case but bad none the less. Thanks great eyes!
Stephen
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 21 lines · Stephen Street
Quoted 10 lines · Nicolas Pitre
[...]
+#define
SSP_REG(x)(*((volatile unsigned long *)x))Don't do that. Instead, please use:
#define
DEFINE_SSP_REG(reg, off)\
static inline u32 read_##reg(void *p) { return__raw_readl(p + (off)); \
static inline void write_##reg(u32 v, void *p) {__raw_writel(v, p + (off)); }Quoted 8 lines
DEFINE_SSP_REG(SSCR0, 0x00)DEFINE_SSP_REG(SSCR1, 0x04)DEFINE_SSP_REG(SSSR, 0x08)DEFINE_SSP_REG(SSITR, 0x0c)DEFINE_SSP_REG(SSDR, 0x10)DEFINE_SSP_REG(SSTO, 0x28)DEFINE_SSP_REG(SSPSP, 0x2c)Ok, I'll do this (Andrew made a similar comment). But...
Quoted 8 lines
I modeled my
SSP_REGon the contents ofinclude/asm-arm/arch_pxa/pxa_reg.hwhich makes extensive use of__REGdefined ininclude/asm-arm/arch_pxa/hardware.has#define
__REG(x)(*((volatile u32 *)io_p2v(x)))which is effectively my
SSP_REGwithout theio_p2vbecause I preloaded the virtual SSP register addresses in thepxa2xx_spi_probefunction.
True. But you should pretend to never have seen that. This macro is low level stuff and if it changes for whatever reason it is better if driver code didn't reimplement it. Furthermore the argument to __REG() is always a constant not a variable making it a simple absolute address that the compiler can use and optimize for pretty effectively.
Quoted 4 lines
For my education:
Why are
__raw_readland friends better than exploiting the memory map I/O nature of the PXA2xx and other SOCs?
Actually, it will do almost the same as you originally did if you look at its definition. However, because a solution needs to be implemented to support multiple ports then using __raw_readl() at the driver level is more familiar to other kernel people.
Quoted 10 lines
Especially since something like
SSP_REG(sscr1)&= ~SSCR1_TIE;becomes
write_SSCR1(read_SSCR1(reg) & ~SSCR_TIE, reg);Further what should I do with the DMA register accesses (i.e. DCSR, DCMD, etc)?
They are fine already.
In fact, if there was only one SSP port, I'd have asked you to use SSPCR0, SSPDR, etc. directly. But the fact that the driver can handle multiple ports makes it rather messy (and the SSP*_P() macros in pxa-regs.h are an abomination IMHO).
Nicolas
Re: [PATCH] spi: Updated PXA2xx SSP SPI Driver
Quoted 6 lines · Nicolas Pitre
Actually, it will do almost the same as you originally did if you look at its definition. However, because a solution needs to be implemented to support multiple ports then using
__raw_readl()at the driver level is more familiar to other kernel people.
Yea, I did notice that also. I just wanted to make sure I understood what is going on so that I do not make the same mistake for the third time.
Quoted 5 lines
In fact, if there was only one SSP port, I'd have asked you to use SSPCR0, SSPDR, etc. directly. But the fact that the driver can handle multiple ports makes it rather messy (and the SSP*_P() macros in
pxa-regs.hare an abomination IMHO).
I did not use the SSP*_P functions because of the mess. Actually at one point the driver implemented register accesses in similar manner as SSP*_P but David Brownell got me straightened out. Thus the original question.
Stephen
PATCH 1/1 spi: Code Review Updated PXA2xx SSP SPI Driver
In reply to Stephen StreetAttached is an updated patch to add a SPI master controller for PXA2xx boards. This update includes changes suggested by Andrew Morton and Nicolas Pitre. Thank you for the through review:)
Any additional feedback or word of success would be greatly appreciated!
Stephen
This driver turns a PXA2xx synchronous serial port (SSP) into a SPI master controller (see Documentation/spi/spi_summary). The driver has the following features:
- Support for any PXA2xx SSP
- SSP PIO and SSP DMA data transfers.
- External and Internal (SSPFRM) chip selects.
- Per slave device (chip) configuration.
- Full suspend, freeze, resume support.
---
Documentation/spi/pxa2xx | 234 +++++ drivers/spi/Kconfig | 8 drivers/spi/Makefile | 1 drivers/spi/pxa2xx_spi.c | 1399 ++++++++++++++++++++++++++++++++++ include/asm-arm/arch-pxa/pxa2xx_spi.h | 68 + 5 files changed, 1710 insertions(+)
drivers/spi/Kconfig +8 -0
@@ -85,6 +85,14 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_PXA2XX + tristate "PXA2xx SSP SPI master" + depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL + help + This enables using a PXA2xx SSP port as a SPI master controller. + The driver can be configured to use any SSP port and additional + documentation can be found a Documentation/spi/pxa2xx. + # # Add new SPI master controllers in alphabetical order above this line #
drivers/spi/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_SPI_MASTER) += spi.o # SPI master controller drivers (bus) obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o +obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o # ... add above this line ... # SPI protocol drivers (device/link on bus)
drivers/spi/pxa2xx_spi.c +1399 -0
1,399 lines not on this page · raw message
include/asm-arm/arch-pxa/pxa2xx_spi.h +68 -0
68 lines not on this page · raw message
Documentation/spi/pxa2xx +234 -0
234 lines not on this page · raw message