SPI patches for 1.3.4
v4 cover SPI patches for 1.3.4
Hi,
The latest incarnation of the SPI API changes didn't get any complaints, while it got a couple of ACKs. So I'm resending the parts of the series that I consider complete for inclusion in U-Boot 1.3.4.
I'm holding back the SPI flash stuff for now since it currently lacks support for most flash chips, and it probably needs more review and testing.
These patches still need testing on NIOS. I'd appreciate some help with that.
Please let me know if I should merge this via the avr32 tree.
Haavard Skinnemoen (2):
Move definition of container_of() to common.h SPI API improvements
Hans-Christian Egtvedt (1):
atmel_spi: Driver for the Atmel SPI controller
board/amcc/taihu/taihu.c | 16 +- board/freescale/mpc8349emds/mpc8349emds.c | 25 ++-- board/sacsng/sacsng.c | 35 ++-- board/ssv/adnpesc1/adnpesc1.c | 27 ++-- common/cmd_spi.c | 42 +++-- common/soft_spi.c | 124 +++++++++--- cpu/at32ap/at32ap700x/gpio.c | 43 +++++ cpu/nios/spi.c | 79 ++++++-- drivers/rtc/ds1306.c | 67 +++++-- drivers/rtc/mc13783-rtc.c | 43 ++++- drivers/spi/Makefile | 1 + drivers/spi/atmel_spi.c | 210 +++++++++++++++++++++ drivers/spi/atmel_spi.h | 95 +++++++++ drivers/spi/mpc8xxx_spi.c | 54 +++++- drivers/spi/mxc_spi.c | 88 ++++++--- include/asm-arm/arch-at91sam9/hardware.h | 11 - include/asm-avr32/arch-at32ap700x/chip-features.h | 1 + include/asm-avr32/arch-at32ap700x/clk.h | 6 + include/asm-avr32/arch-at32ap700x/gpio.h | 4 + include/asm-avr32/u-boot.h | 11 - include/common.h | 11 + include/configs/imx31_litekit.h | 3 +- include/configs/mx31ads.h | 3 +- include/spi.h | 150 +++++++++++++--- 24 files changed, 918 insertions(+), 231 deletions(-) create mode 100644 drivers/spi/atmel_spi.c create mode 100644 drivers/spi/atmel_spi.h
PATCH v4 1/3 Move definition of container_of() to common.h
AVR32 and AT91SAM9 both have their own identical definitions of container_of() taken from the Linux kernel. Move it to common.h so that all architectures can use it.
container_of() is already used by some drivers, and will be used extensively by the new and improved SPI API.
--- include/asm-arm/arch-at91sam9/hardware.h | 11 ----------- include/asm-avr32/u-boot.h | 11 ----------- include/common.h | 11 +++++++++++ 3 files changed, 11 insertions(+), 22 deletions(-)
include/asm-arm/arch-at91sam9/hardware.h +0 -11
@@ -42,15 +42,4 @@#error "Unsupported AT91 processor"#endif -/* -* container_of - cast a member of a structure out to the containing structure -* -* @ptr: the pointer to the member. -* @type: the type of the container struct this is embedded in. -* @member: the name of the member within the struct. -*/ -#define container_of (ptr, type, member) ({ \ - const typeof(((type *)0)->member) *__mptr = (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); }) -#endif
include/asm-avr32/u-boot.h +0 -11
@@ -42,15 +42,4 @@ typedef struct bd_info {#define bi_memstart bi_dram[0].start#define bi_memsize bi_dram[0].size -/** -* container_of - cast a member of a structure out to the containing structure -* -* @ptr: the pointer to the member. -* @type: the type of the container struct this is embedded in. -* @member: the name of the member within the struct. -*/ -#define container_of (ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) -#endif /* __ASM_U_BOOT_H__ */
include/common.h +11 -0
@@ -176,6 +176,17 @@ typedef void (interrupt_handler_t)(void *); (__x > __y) ? __x : __y; }) +/** +* container_of - cast a member of a structure out to the containing structure +* @ptr: the pointer to the member. +* @type: the type of the container struct this is embedded in. +* @member: the name of the member within the struct. +* +*/ +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +/* * Function Prototypes */
Signature · 1 line
1.5.5.1
PATCH v4 2/3 SPI API improvements
From: Haavard Skinnemoen <[email protected]>
This patch gets rid of the spi_chipsel table and adds a handful of new functions that makes the SPI layer cleaner and more flexible.
Instead of the spi_chipsel table, each board that wants to use SPI gets to implement three hooks:
* spi_cs_activate(): Activates the chipselect for a given slave
* spi_cs_deactivate(): Deactivates the chipselect for a given slave
* spi_cs_is_valid(): Determines if the given bus/chipselect combination can be activated.
Not all drivers may need those extra functions however. If that's the case, the board code may just leave them out (assuming they know what the driver needs) or rely on the linker to strip them out (assuming --gc-sections is being used.)
To set up communication parameters for a given slave, the driver needs to call spi_setup_slave(). This returns a pointer to an opaque spi_slave struct which must be passed as a parameter to subsequent SPI calls. This struct can be freed by calling spi_free_slave(), but most driver probably don't want to do this.
Before starting one or more SPI transfers, the driver must call spi_claim_bus() to gain exclusive access to the SPI bus and initialize the hardware. When all transfers are done, the driver must call spi_release_bus() to make the bus available to others, and possibly shut down the SPI controller hardware.
spi_xfer() behaves mostly the same as before, but it now takes a spi_slave parameter instead of a spi_chipsel function pointer. It also got a new parameter, flags, which is used to specify chip select behaviour. This may be extended with other flags in the future.
---
Changed in v4:
- Build fixes for various boards, drivers and commands
- Provide common struct spi_slave definition that can be extended by drivers
- Pass a struct spi_slave * to spi_cs_activate and spi_cs_deactivate
- Make default bus and mode build-time configurable
- Override default SPI bus ID and mode on mx32ads and imx31_litekit.
Changed in v3:
- Add opaque struct spi_slave for controller-specific data associated with a slave.
- Add spi_claim_bus() and spi_release_bus()
- Add spi_free_slave()
- spi_setup() is now called spi_setup_slave() and returns a struct spi_slave
- soft_spi now supports four SPI modes (CPOL|CPHA)
- Add bus parameter to spi_setup_slave()
- Convert the new i.MX32 SPI driver
- Convert the new MC13783 RTC driver
Changed in v2:
- Convert the mpc8xxx_spi driver and the mpc8349emds board to the new API.
board/amcc/taihu/taihu.c | 16 ++- board/freescale/mpc8349emds/mpc8349emds.c | 25 +++--- board/sacsng/sacsng.c | 35 +++---- board/ssv/adnpesc1/adnpesc1.c | 27 +++--- common/cmd_spi.c | 42 +++++---- common/soft_spi.c | 124 ++++++++++++++++++------ cpu/nios/spi.c | 79 +++++++++++---- drivers/rtc/ds1306.c | 67 ++++++++++---- drivers/rtc/mc13783-rtc.c | 43 +++++++- drivers/spi/mpc8xxx_spi.c | 54 +++++++++-- drivers/spi/mxc_spi.c | 88 +++++++++++------ include/configs/imx31_litekit.h | 3 +- include/configs/mx31ads.h | 3 +- include/spi.h | 150 ++++++++++++++++++++++++----- 14 files changed, 547 insertions(+), 209 deletions(-)
board/amcc/taihu/taihu.c +10 -6
@@ -165,16 +165,20 @@ unsigned char spi_read(void)return (unsigned char )gpio_read_in_bit (SPI_DIN_GPIO15 ); } -void taihu_spi_chipsel (int cs) +int spi_cs_is_valid (unsigned int bus,unsigned int cs) { -gpio_write_bit (SPI_CS_GPIO0 , cs); +return bus ==0 && cs ==0 ; } -spi_chipsel_type spi_chipsel[]= { - taihu_spi_chipsel -}; +void spi_cs_activate (struct spi_slave *slave) +{ +gpio_write_bit (SPI_CS_GPIO0 ,1 ); +} -int spi_chipsel_cnt =sizeof (spi_chipsel) /sizeof (spi_chipsel[0 ]); +void spi_cs_deactivate (struct spi_slave *slave) +{ +gpio_write_bit (SPI_CS_GPIO0 ,0 ); +}#ifdef CONFIG_PCI static unsigned char int_lines[32] = {
board/freescale/mpc8349emds/mpc8349emds.c +12 -13
@@ -257,25 +257,24 @@ void sdram_init(void)#define SPI_CS_MASK 0x80000000 -void spi_eeprom_chipsel (int cs) +int spi_cs_is_valid (unsigned int bus,unsigned int cs) +{ +return bus ==0 && cs ==0 ; +} + +void spi_cs_activate (struct spi_slave *slave) {volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR )->gpio[0 ]; -if (cs) - iopd->dat &= ~SPI_CS_MASK ; -else - iopd->dat |=SPI_CS_MASK ; + iopd->dat &= ~SPI_CS_MASK ; } -/* -* The SPI command uses this table of functions for controlling the SPI -* chip selects. -*/ -spi_chipsel_type spi_chipsel[] = { - spi_eeprom_chipsel, -}; -int spi_chipsel_cnt =sizeof (spi_chipsel) /sizeof (spi_chipsel[0 ]); +void spi_cs_deactivate (struct spi_slave *slave) +{ +volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR )->gpio[0 ]; + iopd->dat |=SPI_CS_MASK ; +}#endif /* CONFIG_HARD_SPI */ #if defined(CONFIG_OF_BOARD_SETUP )
board/sacsng/sacsng.c +14 -21
@@ -842,37 +842,30 @@ void show_boot_progress (int status)#define SPI_ADC_CS_MASK 0x00000800#define SPI_DAC_CS_MASK 0x00001000 -void spi_adc_chipsel (int cs) +static const u32 cs_mask[] = { +SPI_ADC_CS_MASK , +SPI_DAC_CS_MASK , +}; + +int spi_cs_is_valid (unsigned int bus,unsigned int cs) +{ +return bus ==0 && cs <sizeof (cs_mask) /sizeof (cs_mask[0 ]); +} + +void spi_cs_activate (struct spi_slave *slave) {volatile ioport_t *iopd =ioport_addr ((immap_t *)CFG_IMMR ,3 /* port D */ ); -if (cs) - iopd->pdat &= ~SPI_ADC_CS_MASK ;/* activate the chip select */ -else - iopd->pdat |=SPI_ADC_CS_MASK ;/* deactivate the chip select */ + iopd->pdat &= ~cs_mask[slave->cs]; } -void spi_dac_chipsel (int cs) +void spi_cs_deactivate (struct spi_slave *slave) {volatile ioport_t *iopd =ioport_addr ((immap_t *)CFG_IMMR ,3 /* port D */ ); -if (cs) - iopd->pdat &= ~SPI_DAC_CS_MASK ;/* activate the chip select */ -else - iopd->pdat |=SPI_DAC_CS_MASK ;/* deactivate the chip select */ + iopd->pdat |= cs_mask[slave->cs]; } -/* -* The SPI command uses this table of functions for controlling the SPI -* chip selects: it calls the appropriate function to control the SPI -* chip selects. -*/ -spi_chipsel_type spi_chipsel[] = { - spi_adc_chipsel, - spi_dac_chipsel -}; -int spi_chipsel_cnt =sizeof (spi_chipsel) /sizeof (spi_chipsel[0 ]); -#endif #endif /* CONFIG_MISC_INIT_R */
board/ssv/adnpesc1/adnpesc1.c +13 -14
@@ -69,25 +69,24 @@ long int initdram (int board_type)#define SPI_RTC_CS_MASK 0x00000001 -void spi_rtc_chipsel (int cs) +int spi_cs_is_valid (unsigned int bus,unsigned int cs) +{ +return bus ==0 && cs ==0 ; +} + +void spi_cs_activate (struct spi_slave *slave) {nios_spi_t *spi = (nios_spi_t *)CFG_NIOS_SPIBASE ; -if (cs) - spi->slaveselect =SPI_RTC_CS_MASK ;/* activate (1) */ -else - spi->slaveselect =0 ;/* deactivate (0) */ + spi->slaveselect =SPI_RTC_CS_MASK ;/* activate (1) */ } -/* -* The SPI command uses this table of functions for controlling the SPI -* chip selects: it calls the appropriate function to control the SPI -* chip selects. -*/ -spi_chipsel_type spi_chipsel[] = { - spi_rtc_chipsel -}; -int spi_chipsel_cnt =sizeof (spi_chipsel) /sizeof (spi_chipsel[0 ]); +void spi_cs_deactivate (struct spi_slave *slave) +{ +nios_spi_t *spi = (nios_spi_t *)CFG_NIOS_SPIBASE ; + + spi->slaveselect =0 ;/* deactivate (0) */ +}#endif
common/cmd_spi.c +25 -17
76 lines not on this page · raw message
common/soft_spi.c +93 -31
175 lines not on this page · raw message
cpu/nios/spi.c +58 -21
135 lines not on this page · raw message
drivers/rtc/ds1306.c +50 -17
127 lines not on this page · raw message
drivers/rtc/mc13783-rtc.c +37 -6
87 lines not on this page · raw message
drivers/spi/mpc8xxx_spi.c +47 -7
85 lines not on this page · raw message
drivers/spi/mxc_spi.c +57 -31
152 lines not on this page · raw message
include/configs/imx31_litekit.h +2 -1
@@ -65,7 +65,8 @@#define CONFIG_HARD_SPI 1#define CONFIG_MXC_SPI 1 -#define CONFIG_MXC_SPI_IFACE 1 +#define CONFIG_DEFAULT_SPI_BUS 1 +#define CONFIG_DEFAULT_SPI_MODE (SPI_MODE_2 | SPI_CS_HIGH)#define CONFIG_RTC_MC13783 1
include/configs/mx31ads.h +2 -1
@@ -62,7 +62,8 @@#define CONFIG_HARD_SPI 1#define CONFIG_MXC_SPI 1 -#define CONFIG_MXC_SPI_IFACE 1/* Default SPI interface number */ +#define CONFIG_DEFAULT_SPI_BUS 1 +#define CONFIG_DEFAULT_SPI_MODE (SPI_MODE_2 | SPI_CS_HIGH)#define CONFIG_RTC_MC13783 1
include/spi.h +127 -23
177 lines not on this page · raw message
Signature · 1 line
1.5.5.1
PATCH v4 3/3 atmel_spi: Driver for the Atmel SPI controller
From: Hans-Christian Egtvedt <[email protected]>
This adds a driver for the SPI controller found on most AT91 and AVR32 chips, implementing the new SPI API.
---
Changed in v4:
- Update to new API
- Handle zero-length transfers appropriately. The user may send a zero-length SPI transfer with SPI_XFER_END set in order to deactivate the chip select after a series of transfers with chip select active. This is useful e.g. when polling the status register of DataFlash.
cpu/at32ap/at32ap700x/gpio.c | 43 +++++ drivers/spi/Makefile | 1 + drivers/spi/atmel_spi.c | 210 +++++++++++++++++++++ drivers/spi/atmel_spi.h | 95 +++++++++ include/asm-avr32/arch-at32ap700x/chip-features.h | 1 + include/asm-avr32/arch-at32ap700x/clk.h | 6 + include/asm-avr32/arch-at32ap700x/gpio.h | 4 + 7 files changed, 360 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/atmel_spi.c create mode 100644 drivers/spi/atmel_spi.h
cpu/at32ap/at32ap700x/gpio.c +43 -0
@@ -21,8 +21,11 @@*/ #include <common.h> +#include <asm/io.h> +#include <asm/arch/chip-features.h> #include <asm/arch/gpio.h> +#include <asm/arch/memory-map.h> /* * Lots of small functions here. We depend on --gc-sections getting
@@ -142,3 +145,43 @@ void gpio_enable_mmci(void)gpio_select_periph_A (GPIO_PIN_PA15 ,0 );/* DATA3 */ }#endif + +#ifdef AT32AP700x_CHIP_HAS_SPI +void gpio_enable_spi0 (unsigned long cs_mask) +{ +u32 pa_mask =0 ; + +gpio_select_periph_A (GPIO_PIN_PA0 ,0 );/* MISO */ +gpio_select_periph_A (GPIO_PIN_PA1 ,0 );/* MOSI */ +gpio_select_periph_A (GPIO_PIN_PA2 ,0 );/* SCK */ + +if (cs_mask & (1 <<0 )) + pa_mask |=1 <<3 ;/* NPCS0 */ +if (cs_mask & (1 <<1 )) + pa_mask |=1 <<4 ;/* NPCS1 */ +if (cs_mask & (1 <<2 )) + pa_mask |=1 <<5 ;/* NPCS2 */ +if (cs_mask & (1 <<3 )) + pa_mask |=1 <<20 ;/* NPCS3 */ + +__raw_writel (pa_mask,PIOA_BASE +0x00 ); +__raw_writel (pa_mask,PIOA_BASE +0x30 ); +__raw_writel (pa_mask,PIOA_BASE +0x10 ); +} + +void gpio_enable_spi1 (unsigned long cs_mask) +{ +gpio_select_periph_B (GPIO_PIN_PA0 ,0 );/* MISO */ +gpio_select_periph_B (GPIO_PIN_PB1 ,0 );/* MOSI */ +gpio_select_periph_B (GPIO_PIN_PB5 ,0 );/* SCK */ + +if (cs_mask & (1 <<0 )) +gpio_select_periph_B (GPIO_PIN_PB2 ,0 );/* NPCS0 */ +if (cs_mask & (1 <<1 )) +gpio_select_periph_B (GPIO_PIN_PB3 ,0 );/* NPCS1 */ +if (cs_mask & (1 <<2 )) +gpio_select_periph_B (GPIO_PIN_PB4 ,0 );/* NPCS2 */ +if (cs_mask & (1 <<3 )) +gpio_select_periph_A (GPIO_PIN_PA27 ,0 );/* NPCS3 */ +} +#endif
drivers/spi/Makefile +1 -0
@@ -26,6 +26,7 @@ include $(TOPDIR)/config.mk LIB := $(obj)libspi.a COBJS-y += mpc8xxx_spi.o +COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o COBJS := $(COBJS-y)
drivers/spi/atmel_spi.c new file +210 -0
210 lines not on this page · raw message
drivers/spi/atmel_spi.h new file +95 -0
95 lines not on this page · raw message
include/asm-avr32/arch-at32ap700x/chip-features.h +1 -0
@@ -25,6 +25,7 @@/* Currently, all the AP700x chips have these */ #define AT32AP700x_CHIP_HAS_USART#define AT32AP700x_CHIP_HAS_MMCI +#define AT32AP700x_CHIP_HAS_SPI/* Only AP7000 has ethernet interface */ #ifdef CONFIG_AT32AP7000
include/asm-avr32/arch-at32ap700x/clk.h +6 -0
@@ -74,6 +74,12 @@ static inline unsigned long get_mci_clk_rate(void) return get_pbb_clk_rate(); }#endif +#ifdef AT32AP700x_CHIP_HAS_SPI +static inline unsigned long get_spi_clk_rate (unsigned int dev_id) +{ +return get_pba_clk_rate (); +} +#endif /* Board code may need the SDRAM base clock as a compile-time constant */ #define SDRAMC_BUS_HZ (MAIN_CLK_RATE >> CFG_CLKDIV_HSB)
include/asm-avr32/arch-at32ap700x/gpio.h +4 -0
@@ -216,5 +216,9 @@ void gpio_enable_macb1(void);#ifdef AT32AP700x_CHIP_HAS_MMCIvoid gpio_enable_mmci (void );#endif +#ifdef AT32AP700x_CHIP_HAS_SPI +void gpio_enable_spi0 (unsigned long cs_mask); +void gpio_enable_spi1 (unsigned long cs_mask); +#endif #endif /* __ASM_AVR32_ARCH_GPIO_H__ */
Signature · 1 line
1.5.5.1
v4 cover SPI patches for 1.3.4
In reply to Haavard SkinnemoenAm Montag 26 Mai 2008 12:55:09 schrieb Haavard Skinnemoen:
Quoted 1 line
Hi,
Hi Haavard,
first of all, sorry for my late response. I'm busy with other projects. In the near future I will not test the patch on NIOS, because I'm lacking of test equipment.
Please contact Scott McNutt. I think he can help, or not?
Best regards,
Stephan Linz
Quoted 49 lines
The latest incarnation of the SPI API changes didn't get any complaints, while it got a couple of ACKs. So I'm resending the parts of the series that I consider complete for inclusion in U-Boot 1.3.4.
I'm holding back the SPI flash stuff for now since it currently lacks support for most flash chips, and it probably needs more review and testing.
These patches still need testing on NIOS. I'd appreciate some help with that.
Please let me know if I should merge this via the avr32 tree.
Haavard Skinnemoen (2):
Move definition ofcontainer_of()tocommon.hSPI API improvementsHans-Christian Egtvedt (1):
atmel_spi: Driver for the Atmel SPI controllerboard/amcc/taihu/taihu.c | 16 +- board/freescale/mpc8349emds/mpc8349emds.c | 25 ++-- board/sacsng/sacsng.c | 35 ++-- board/ssv/adnpesc1/adnpesc1.c | 27 ++-- common/cmd_spi.c | 42 +++-- common/soft_spi.c | 124 +++++++++--- cpu/at32ap/at32ap700x/gpio.c | 43 +++++ cpu/nios/spi.c | 79 ++++++-- drivers/rtc/ds1306.c | 67 +++++-- drivers/rtc/mc13783-rtc.c | 43 ++++- drivers/spi/Makefile | 1 + drivers/spi/atmel_spi.c | 210 +++++++++++++++++++++ drivers/spi/atmel_spi.h | 95 +++++++++ drivers/spi/mpc8xxx_spi.c | 54 +++++- drivers/spi/mxc_spi.c | 88 ++++++--- include/asm-arm/arch-at91sam9/hardware.h | 11 - include/asm-avr32/arch-at32ap700x/chip-features.h | 1 + include/asm-avr32/arch-at32ap700x/clk.h | 6 + include/asm-avr32/arch-at32ap700x/gpio.h | 4 + include/asm-avr32/u-boot.h | 11 - include/common.h | 11 + include/configs/imx31_litekit.h | 3 +- include/configs/mx31ads.h | 3 +- include/spi.h | 150 +++++++++++++--- 24 files changed, 918 insertions(+), 231 deletions(-) create mode 100644 drivers/spi/atmel_spi.c create mode 100644 drivers/spi/atmel_spi.h