Re: [U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
On Tue, 8 Jun 2010 15:20:57 -0400 Mike Frysinger vap...@gentoo.org wrote: speaking historically, the dataflash code absolutely has its place. it existed long before the SPI flash framework. but i'm looking forward only now. Yes, of course, understood. However, the Dataflash aren't normal SPI flash, they don't have the same opcodes. For example, drivers/mtd/spi/spi_flash.c assumes that it can probe the ID code of the SPI flash by sending the CMD_READ_ID (0x9F) command (in spi_flash_probe()). This works for SPI flashes, but not for Dataflashes. The identification of Dataflashes takes place with command GET_STATUS (0xD7) in drivers/mtd/at45.c, which has a different return value than the 0x9F command of SPI flashes. Am I missing something ? In terms of code infrastructure/organization, how do you suggest to handle this ? i think the first step would be to convert the boards we can and leave a #warning for the rest that the dataflash code is being killed off. then after some time, if no one has fixed the remainders, we do our best to convert them. -mike Ok. Thomas -- Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
On Wednesday, June 09, 2010 03:06:26 Thomas Petazzoni wrote: On Tue, 8 Jun 2010 15:20:57 -0400 Mike Frysinger wrote: speaking historically, the dataflash code absolutely has its place. it existed long before the SPI flash framework. but i'm looking forward only now. Yes, of course, understood. However, the Dataflash aren't normal SPI flash, they don't have the same opcodes. For example, drivers/mtd/spi/spi_flash.c assumes that it can probe the ID code of the SPI flash by sending the CMD_READ_ID (0x9F) command (in spi_flash_probe()). This works for SPI flashes, but not for Dataflashes. The identification of Dataflashes takes place with command GET_STATUS (0xD7) in drivers/mtd/at45.c, which has a different return value than the 0x9F command of SPI flashes. Am I missing something ? i see drivers/mtd/spi/atmel.c with all the same IDs as drivers/mtd/dataflash.c so presumably it works. i also vaguely recall having tested one or two myself with the SPI flash subsystem. according to the datasheet for the AT45DB642D, 0x9F is the get the ID code while 0xDF is the get flash status. i dont see how you can get the flash id info out of the flash status register. perhaps you're confusing the code bases ? -mike signature.asc Description: This is a digitally signed message part. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
On Mon, 7 Jun 2010 18:52:03 -0400 Mike Frysinger vap...@gentoo.org wrote: i have to ask ... what exactly is the advantage of the dataflash driver over the common spi flash drivers ? ive looked a bit and cant pick anything out. better to just scuttle the entire code base imo and unify consumers. I don't know the history of both drivers, but indeed it seems that the AT91-custom dataflash driver should be replaced by the corresponding SPI flash driver. I'll dig into this and see what I can do. However, I only have a Calao USB-A9263 board and an Atmel AT91SAM9261EK board here, so I won't be able to test on all Atmel evaluation boards. Thomas -- Thomas Petazzoni, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com signature.asc Description: PGP signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
On Tuesday, June 08, 2010 08:24:33 Thomas Petazzoni wrote: On Mon, 7 Jun 2010 18:52:03 -0400 Mike Frysinger wrote: i have to ask ... what exactly is the advantage of the dataflash driver over the common spi flash drivers ? ive looked a bit and cant pick anything out. better to just scuttle the entire code base imo and unify consumers. I don't know the history of both drivers, but indeed it seems that the AT91-custom dataflash driver should be replaced by the corresponding SPI flash driver. I'll dig into this and see what I can do. speaking historically, the dataflash code absolutely has its place. it existed long before the SPI flash framework. but i'm looking forward only now. However, I only have a Calao USB-A9263 board and an Atmel AT91SAM9261EK board here, so I won't be able to test on all Atmel evaluation boards. i think the first step would be to convert the boards we can and leave a #warning for the rest that the dataflash code is being killed off. then after some time, if no one has fixed the remainders, we do our best to convert them. -mike signature.asc Description: This is a digitally signed message part. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
Instead of using the old-style base + offset accessors, use the new at91 C struct accessors. The removal of #ifdef CONFIG_AT91_LEGACY allows to keep the definition of register values, needed to program the SPI. Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- arch/arm/include/asm/arch-at91/at91_spi.h |4 -- drivers/spi/atmel_dataflash_spi.c | 77 +++- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/arch/arm/include/asm/arch-at91/at91_spi.h b/arch/arm/include/asm/arch-at91/at91_spi.h index c520e89..73e23cf 100644 --- a/arch/arm/include/asm/arch-at91/at91_spi.h +++ b/arch/arm/include/asm/arch-at91/at91_spi.h @@ -33,8 +33,6 @@ typedef struct at91_spi { at91_pdc_t pdc; } at91_spi_t; -#ifdef CONFIG_AT91_LEGACY - #define AT91_SPI_CR0x00/* Control Register */ #defineAT91_SPI_SPIEN (1 0) /* SPI Enable */ #defineAT91_SPI_SPIDIS (1 1) /* SPI Disable */ @@ -121,6 +119,4 @@ typedef struct at91_spi { #define AT91_SPI_PTSR 0x0124 /* PDC Transfer Status Register */ -#endif /* CONFIG_AT91_LEGACY */ - #endif diff --git a/drivers/spi/atmel_dataflash_spi.c b/drivers/spi/atmel_dataflash_spi.c index 4a5c4aa..3693c93 100644 --- a/drivers/spi/atmel_dataflash_spi.c +++ b/drivers/spi/atmel_dataflash_spi.c @@ -2,6 +2,9 @@ * Driver for ATMEL DataFlash support * Author : Hamid Ikdoumi (Atmel) * + * Conversion to C struct SoC accessors by Thomas Petazzoni + * thomas.petazz...@free-electrons.com. + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of @@ -20,10 +23,6 @@ */ #include common.h -#ifndef CONFIG_AT91_LEGACY -#define CONFIG_AT91_LEGACY -#warning Please update to use C structur SoC access ! -#endif #include asm/arch/hardware.h #include asm/arch/clk.h #include asm/arch/gpio.h @@ -40,19 +39,21 @@ void AT91F_SpiInit(void) { + at91_spi_t *spi = (at91_spi_t *) AT91_SPI0_BASE; + /* Reset the SPI */ - writel(AT91_SPI_SWRST, AT91_BASE_SPI + AT91_SPI_CR); + writel(AT91_SPI_SWRST, spi-cr); /* Configure SPI in Master Mode with No CS selected !!! */ writel(AT91_SPI_MSTR | AT91_SPI_MODFDIS | AT91_SPI_PCS, - AT91_BASE_SPI + AT91_SPI_MR); + spi-mr); /* Configure CS0 */ writel(AT91_SPI_NCPHA | (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(0)); + spi-csr[0]); #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS1 /* Configure CS1 */ @@ -60,7 +61,7 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(1)); + spi-csr[1]); #endif #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS2 /* Configure CS2 */ @@ -68,7 +69,7 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(2)); + spi-csr[2]); #endif #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS3 /* Configure CS3 */ @@ -76,95 +77,99 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(3)); + spi-csr[3]); #endif /* SPI_Enable */ - writel(AT91_SPI_SPIEN, AT91_BASE_SPI + AT91_SPI_CR); + writel(AT91_SPI_SPIEN, spi-cr); - while (!(readl(AT91_BASE_SPI + AT91_SPI_SR) AT91_SPI_SPIENS)); + while (!(readl(spi-sr) AT91_SPI_SPIENS)) + ; /* * Add tempo to get SPI in a safe state. * Should not be needed for new silicon (Rev B) */ udelay(50); - readl(AT91_BASE_SPI + AT91_SPI_SR); - readl(AT91_BASE_SPI + AT91_SPI_RDR); + readl(spi-sr); + readl(spi-rdr); } void AT91F_SpiEnable(int cs) { + at91_spi_t *spi = (at91_spi_t *) AT91_SPI0_BASE; unsigned long mode; switch (cs) { case 0: /* Configure SPI CS0 for Serial DataFlash AT45DBxx */ - mode = readl(AT91_BASE_SPI + AT91_SPI_MR); + mode = readl(spi-mr); mode = 0xFFF0; writel(mode | ((AT91_SPI_PCS0_DATAFLASH_CARD16) AT91_SPI_PCS), - AT91_BASE_SPI + AT91_SPI_MR); + spi-mr);
Re: [U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
On Monday, June 07, 2010 17:56:21 Thomas Petazzoni wrote: Instead of using the old-style base + offset accessors, use the new at91 C struct accessors. The removal of #ifdef CONFIG_AT91_LEGACY allows to keep the definition of register values, needed to program the SPI. i have to ask ... what exactly is the advantage of the dataflash driver over the common spi flash drivers ? ive looked a bit and cant pick anything out. better to just scuttle the entire code base imo and unify consumers. -mike signature.asc Description: This is a digitally signed message part. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 1/4] Atmel Dataflash: convert to C struct accessors
Instead of using the old-style base + offset accessors, use the new at91 C struct accessors. The removal of #ifdef CONFIG_AT91_LEGACY allows to keep the definition of register values, needed to program the SPI. Signed-off-by: Thomas Petazzoni thomas.petazz...@free-electrons.com --- arch/arm/include/asm/arch-at91/at91_spi.h |4 -- drivers/spi/atmel_dataflash_spi.c | 73 +++-- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/arch/arm/include/asm/arch-at91/at91_spi.h b/arch/arm/include/asm/arch-at91/at91_spi.h index c520e89..73e23cf 100644 --- a/arch/arm/include/asm/arch-at91/at91_spi.h +++ b/arch/arm/include/asm/arch-at91/at91_spi.h @@ -33,8 +33,6 @@ typedef struct at91_spi { at91_pdc_t pdc; } at91_spi_t; -#ifdef CONFIG_AT91_LEGACY - #define AT91_SPI_CR0x00/* Control Register */ #defineAT91_SPI_SPIEN (1 0) /* SPI Enable */ #defineAT91_SPI_SPIDIS (1 1) /* SPI Disable */ @@ -121,6 +119,4 @@ typedef struct at91_spi { #define AT91_SPI_PTSR 0x0124 /* PDC Transfer Status Register */ -#endif /* CONFIG_AT91_LEGACY */ - #endif diff --git a/drivers/spi/atmel_dataflash_spi.c b/drivers/spi/atmel_dataflash_spi.c index 4a5c4aa..c6609a0 100644 --- a/drivers/spi/atmel_dataflash_spi.c +++ b/drivers/spi/atmel_dataflash_spi.c @@ -2,6 +2,9 @@ * Driver for ATMEL DataFlash support * Author : Hamid Ikdoumi (Atmel) * + * Conversion to C struct SoC accessors by Thomas Petazzoni + * thomas.petazz...@free-electrons.com. + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of @@ -20,10 +23,6 @@ */ #include common.h -#ifndef CONFIG_AT91_LEGACY -#define CONFIG_AT91_LEGACY -#warning Please update to use C structur SoC access ! -#endif #include asm/arch/hardware.h #include asm/arch/clk.h #include asm/arch/gpio.h @@ -40,19 +39,21 @@ void AT91F_SpiInit(void) { + at91_spi_t *spi = (at91_spi_t *) AT91_SPI0_BASE; + /* Reset the SPI */ - writel(AT91_SPI_SWRST, AT91_BASE_SPI + AT91_SPI_CR); + writel(AT91_SPI_SWRST, spi-cr); /* Configure SPI in Master Mode with No CS selected !!! */ writel(AT91_SPI_MSTR | AT91_SPI_MODFDIS | AT91_SPI_PCS, - AT91_BASE_SPI + AT91_SPI_MR); + spi-mr); /* Configure CS0 */ writel(AT91_SPI_NCPHA | (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(0)); + spi-csr[0]); #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS1 /* Configure CS1 */ @@ -60,7 +61,7 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(1)); + spi-csr[1]); #endif #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS2 /* Configure CS2 */ @@ -68,7 +69,7 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(2)); + spi-csr[2]); #endif #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS3 /* Configure CS3 */ @@ -76,95 +77,97 @@ void AT91F_SpiInit(void) (AT91_SPI_DLYBS DATAFLASH_TCSS) | (AT91_SPI_DLYBCT DATAFLASH_TCHS) | ((get_mck_clk_rate() / AT91_SPI_CLK) 8), - AT91_BASE_SPI + AT91_SPI_CSR(3)); + spi-csr[3]); #endif /* SPI_Enable */ - writel(AT91_SPI_SPIEN, AT91_BASE_SPI + AT91_SPI_CR); + writel(AT91_SPI_SPIEN, spi-cr); - while (!(readl(AT91_BASE_SPI + AT91_SPI_SR) AT91_SPI_SPIENS)); + while (!(readl(spi-sr) AT91_SPI_SPIENS)); /* * Add tempo to get SPI in a safe state. * Should not be needed for new silicon (Rev B) */ udelay(50); - readl(AT91_BASE_SPI + AT91_SPI_SR); - readl(AT91_BASE_SPI + AT91_SPI_RDR); + readl(spi-sr); + readl(spi-rdr); } void AT91F_SpiEnable(int cs) { + at91_spi_t *spi = (at91_spi_t *) AT91_SPI0_BASE; unsigned long mode; switch (cs) { case 0: /* Configure SPI CS0 for Serial DataFlash AT45DBxx */ - mode = readl(AT91_BASE_SPI + AT91_SPI_MR); + mode = readl(spi-mr); mode = 0xFFF0; writel(mode | ((AT91_SPI_PCS0_DATAFLASH_CARD16) AT91_SPI_PCS), - AT91_BASE_SPI + AT91_SPI_MR); + spi-mr); break;