mci: add Atmel AT91 MCI driver
PATCH 1/1 mci: add Atmel AT91 MCI driver
The driver supports push and pull transfers.
Tested on at91sam9m10 SoC.
--- arch/arm/mach-at91/at91sam9g45_devices.c | 92 +++++ arch/arm/mach-at91/include/mach/at91_mci.h | 121 +++++++ arch/arm/mach-at91/include/mach/board.h | 10 + drivers/mci/Kconfig | 7 + drivers/mci/Makefile | 1 + drivers/mci/atmel_mci.c | 519 ++++++++++++++++++++++++++++ 6 files changed, 750 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-at91/include/mach/at91_mci.h create mode 100644 drivers/mci/atmel_mci.c
arch/arm/mach-at91/at91sam9g45_devices.c +92 -0
@@ -10,6 +10,7 @@* */ #include <common.h> +#include <sizes.h> #include <asm/armlinux.h> #include <asm/hardware.h> #include <mach/at91_pmc.h>
@@ -240,3 +241,94 @@ void at91_register_uart(unsigned id, unsigned pins) } } + +#if defined(CONFIG_MCI_ATMEL ) +static struct device_d mci0_device = { + .id =0 , + .name ="atmel_mci" , + .map_base =AT91SAM9G45_BASE_MCI0 , + .size =SZ_16K , +}; + +static struct device_d mci1_device = { + .id =1 , + .name ="atmel_mci" , + .map_base =AT91SAM9G45_BASE_MCI1 , + .size =SZ_16K , +}; + +/* Consider only one slot : slot 0 */ +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) +{ + +if (!data) +return ; + +/* Must have at least one usable slot */ +if (!data->bus_width) +return ; + +/* input/irq */ +if (data->detect_pin) { +at91_set_gpio_input (data->detect_pin,1 ); +at91_set_deglitch (data->detect_pin,1 ); + } +if (data->wp_pin) +at91_set_gpio_input (data->wp_pin,1 ); + +if (mmc_id ==0 ) {/* MCI0 */ + +/* CLK */ +at91_set_A_periph (AT91_PIN_PA0 ,0 ); + +/* CMD */ +at91_set_A_periph (AT91_PIN_PA1 ,1 ); + +/* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */ +at91_set_A_periph (AT91_PIN_PA2 ,1 ); +if (data->bus_width ==4 ) { +at91_set_A_periph (AT91_PIN_PA3 ,1 ); +at91_set_A_periph (AT91_PIN_PA4 ,1 ); +at91_set_A_periph (AT91_PIN_PA5 ,1 ); +if (data->bus_width ==8 ) { +at91_set_A_periph (AT91_PIN_PA6 ,1 ); +at91_set_A_periph (AT91_PIN_PA7 ,1 ); +at91_set_A_periph (AT91_PIN_PA8 ,1 ); +at91_set_A_periph (AT91_PIN_PA9 ,1 ); + } + } + + mci0_device.platform_data = data; +at91_clock_associate ("mci0_clk" , &mci0_device,"mci_clk" ); +register_device (&mci0_device); + + }else {/* MCI1 */ +/* CLK */ +at91_set_A_periph (AT91_PIN_PA31 ,0 ); + +/* CMD */ +at91_set_A_periph (AT91_PIN_PA22 ,1 ); + +/* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */ +at91_set_A_periph (AT91_PIN_PA23 ,1 ); +if (data->bus_width ==4 ) { +at91_set_A_periph (AT91_PIN_PA24 ,1 ); +at91_set_A_periph (AT91_PIN_PA25 ,1 ); +at91_set_A_periph (AT91_PIN_PA26 ,1 ); +if (data->bus_width ==8 ) { +at91_set_A_periph (AT91_PIN_PA27 ,1 ); +at91_set_A_periph (AT91_PIN_PA28 ,1 ); +at91_set_A_periph (AT91_PIN_PA29 ,1 ); +at91_set_A_periph (AT91_PIN_PA30 ,1 ); + } + } + + mci1_device.platform_data = data; +at91_clock_associate ("mci1_clk" , &mci1_device,"mci_clk" ); +register_device (&mci1_device); + } +} +#else +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) {} +#endif +
arch/arm/mach-at91/include/mach/at91_mci.h new file +121 -0
121 lines not on this page · raw message
arch/arm/mach-at91/include/mach/board.h +10 -0
@@ -63,4 +63,14 @@ void at91_add_device_sdram(u32 size);#define ATMEL_UART_RI 0x20void at91_register_uart (unsigned id,unsigned pins); + +/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +}; + +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data);#endif
drivers/mci/Kconfig +7 -0
@@ -73,4 +73,11 @@ config MCI_OMAP_HSMMC Enable this entry to add support to read and write SD cards on a OMAP4 based system. +config MCI_ATMEL + bool "ATMEL (AT91)" + depends on ARCH_AT91 + help + Enable this entry to add support to read and write SD cards on a + Atmel AT91. + endif
drivers/mci/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_MCI_S3C) += s3c.o obj-$(CONFIG_MCI_IMX) += imx.o obj-$(CONFIG_MCI_IMX_ESDHC) += imx-esdhc.o obj-$(CONFIG_MCI_OMAP_HSMMC) += omap_hsmmc.o +obj-$(CONFIG_MCI_ATMEL) += atmel_mci.o
drivers/mci/atmel_mci.c new file +519 -0
519 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 9 lines · Hubert Feurstein
The driver supports push and pull transfers.
Tested on at91sam9m10 SoC.Signed-off-by Hubert Feurstein <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>Cc Nicolas Ferre <[email protected]>Cc Patrice Vilchez <[email protected]>--- arch/arm/mach-at91/at91sam9g45_devices.c | 92 +++++
I was working on similar patch too
please add other chips too
I'll test it this week
please check the patch with checkpatch
I see some whitespace issue
Quoted 22 lines
arch/arm/mach-at91/include/mach/at91_mci.h | 121 +++++++ arch/arm/mach-at91/include/mach/board.h | 10 + drivers/mci/Kconfig | 7 + drivers/mci/Makefile | 1 + drivers/mci/atmel_mci.c | 519 ++++++++++++++++++++++++++++ 6 files changed, 750 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-at91/include/mach/at91_mci.h create mode 100644 drivers/mci/atmel_mci.carch/arm/mach-at91/at91sam9g45_devices.c +1
-0@@ -10,6 +10,7 @@* */ #include <common.h> +#include <sizes.h> #include <asm/armlinux.h> #include <asm/hardware.h> #include <mach/at91_pmc.h>
arch/arm/mach-at91/at91sam9g45_devices.c void at91_register_uart(unsigned id, unsigned pins) · line 247
Quoted 7 lines
arch/arm/mach-at91/at91sam9g45_devices.c +4
-0@@ -240,3 +241,94 @@ void at91_register_uart(unsigned id, unsigned pins) } } + +#if defined(CONFIG_MCI_ATMEL ) +static struct device_d mci0_device = { + .id = 0,
please use tab for indent
Quoted 12 lines
arch/arm/mach-at91/at91sam9g45_devices.c +12
-0+ .name = "atmel_mci", + .map_base = AT91SAM9G45_BASE_MCI0, + .size = SZ_16K, +}; + +static struct device_d mci1_device = { + .id =1 , + .name ="atmel_mci" , + .map_base =AT91SAM9G45_BASE_MCI1 , + .size =SZ_16K , +}; +
....
arch/arm/mach-at91/include/mach/at91_mci.h line 2
Quoted 9 lines
arch/arm/mach-at91/at91sam9g45_devices.c +1
-0+arch/arm/mach-at91/include/mach/at91_mci.h new file +2
-0@@ -0,0 +1,121 @@ +/* +* [origin: Linux kernel arch/arm/mach-at91/include/mach/at91_mci.h]
please move this with the driver I'm going to the same in the kernel
Quoted 16 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +16
-0+* +* Copyright (C) 2005 Ivan Kokshaysky +* Copyright (C) SAN People +* +* MultiMedia Card Interface (MCI) registers. +* Based on AT91RM9200 datasheet revision F. +* +* 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 the License, or +* (at your option) any later version. +*/ + +#ifndef AT91_MCI_H +#define AT91_MCI_H +
...
arch/arm/mach-at91/include/mach/at91_mci.h
Quoted 3 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +3
-0+ +pr_debug ("atmel_set_clk_rate: clkIn=%d clkIos=%d divider=%d\n" , + clk_in, clk_ios, divider);
dev_dbg here?
Quoted 36 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +36
-0+ +writel (((AT91_MCI_CLKDIV & divider) + |AT91_MCI_RDPROOF + |AT91_MCI_WRPROOF ), &host->base->mr); +} + +static int atmel_poll_status (struct atmel_mci_host *host,u32 mask) +{ +u32 stat; +uint64_t start =get_time_ns (); + +do { + stat =readl (&host->base->sr); +if (stat &STATUS_ERROR_MASK ) +return stat; +if (is_timeout (start,SECOND )) +return AT91_MCI_RTOE | stat; +if (stat & mask) +return 0 ; + }while (1 ); +} + +static int atmel_pull (struct atmel_mci_host *host,void *_buf,int bytes) +{ +unsigned int stat; +u32 *buf = _buf; + +while (bytes >3 ) { + stat =atmel_poll_status (host,AT91_MCI_RXRDY ); +if (stat) +return stat; + + *buf++ =readl (&host->base->rdr); + bytes -=4 ; + } +
arch/arm/mach-at91/include/mach/at91_mci.h
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +10
-0+if (bytes) { +u8 *b = (u8 *)buf; +u32 tmp; + + stat =atmel_poll_status (host,AT91_MCI_RXRDY ); +if (stat) +return stat; + + tmp =readl (&host->base->rdr); +memcpy (b, &tmp, bytes);
we could use __iowrite32 here to speed up the copy I'll send a patch to add it to barebox
Quoted 19 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +19
-0+ } + +return 0 ; +} + +#ifdef CONFIG_MCI_WRITE +static int atmel_push (struct atmel_mci_host *host,const void *_buf,int bytes) +{ +unsigned int stat; +const u32 *buf = _buf; + +while (bytes >3 ) { + stat =atmel_poll_status (host,AT91_MCI_TXRDY ); +if (stat) +return stat; + +writel (*buf++, &host->base->tdr); + bytes -=4 ; + }
arch/arm/mach-at91/include/mach/at91_mci.h
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +10
-0+ +if (bytes) { +const u8 *b = (u8 *)buf; +u32 tmp; + + stat =atmel_poll_status (host,AT91_MCI_TXRDY ); +if (stat) +return stat; + +memcpy (&tmp, b, bytes);
ditto
Quoted 27 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +27
-0+ writel(tmp, &host->base->tdr); + } + + stat =atmel_poll_status (host,AT91_MCI_TXRDY ); +if (stat) +return stat; + +return 0 ; +} +#endif /* CONFIG_MCI_WRITE */ + +static int atmel_transfer_data (struct atmel_mci_host *host) +{ +struct mci_data *data = host->data; +int stat; +unsigned long length; + + length = data->blocks * data->blocksize; + host->datasize =0 ; + +if (data->flags &MMC_DATA_READ ) { + stat =atmel_pull (host, data->dest, length); +if (stat) +return stat; + + stat =atmel_poll_status (host,AT91_MCI_NOTBUSY ); +if (stat)
arch/arm/mach-at91/include/mach/at91_mci.h
Quoted 10 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +10
-0+return stat; + + host->datasize += length; + }else { +BUG_ON (data->blocksize &3 ); +BUG_ON (nob ==0 ); + + host->data = data; + +pr_debug ("atmel_setup_data: nob=%d blksz=%d\n" , nob, blksz);
deb_dbg?
arch/arm/mach-at91/include/mach/at91_mci.h
Quoted 7 lines
arch/arm/mach-at91/include/mach/at91_mci.h new file +7
-0+ +writel (AT91_MCI_BLKR_BCNT (nob) + |AT91_MCI_BLKR_BLKLEN (blksz), &host->base->blkr); + + host->datasize = datasize; +} +
otherwise look good
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/1 mci: add Atmel AT91 MCI driver
The driver supports push and pull transfers.
Tested on at91sam9m10 SoC.
---
Changes against v1:
- Code cleanup according to checkpatch.pl.
- Add support for devices: 9260, 9261 and 9263 (but not tested!)
- Use dev_* function instead of pr_*
arch/arm/mach-at91/at91sam9260_devices.c | 50 +++ arch/arm/mach-at91/at91sam9261_devices.c | 50 +++ arch/arm/mach-at91/at91sam9263_devices.c | 78 +++++ arch/arm/mach-at91/at91sam9g45_devices.c | 91 +++++ arch/arm/mach-at91/include/mach/board.h | 10 + drivers/mci/Kconfig | 7 + drivers/mci/Makefile | 1 + drivers/mci/at91_mci.h | 121 +++++++ drivers/mci/atmel_mci.c | 526 ++++++++++++++++++++++++++++++ 9 files changed, 934 insertions(+), 0 deletions(-) create mode 100644 drivers/mci/at91_mci.h create mode 100644 drivers/mci/atmel_mci.c
arch/arm/mach-at91/at91sam9260_devices.c +50 -0
@@ -10,6 +10,7 @@* */ #include <common.h> +#include <sizes.h> #include <asm/armlinux.h> #include <asm/hardware.h> #include <mach/board.h>
@@ -280,3 +281,52 @@ void at91_register_uart(unsigned id, unsigned pins)return ; } } + +#if defined(CONFIG_MCI_ATMEL ) +static struct device_d mci_device = { + .id =-1 , + .name ="atmel_mci" , + .map_base =AT91SAM9260_BASE_MCI , + .size =SZ_16K , +}; + +/* Consider only one slot : slot 0 */ +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) +{ +if (!data) +return ; + +/* need bus_width */ +if (!data->bus_width) +return ; + +/* input/irq */ +if (data->detect_pin) { +at91_set_gpio_input (data->detect_pin,1 ); +at91_set_deglitch (data->detect_pin,1 ); + } + +if (data->wp_pin) +at91_set_gpio_input (data->wp_pin,1 ); + +/* CLK */ +at91_set_A_periph (AT91_PIN_PA8 ,0 ); + +/* CMD */ +at91_set_A_periph (AT91_PIN_PA7 ,1 ); + +/* DAT0, maybe DAT1..DAT3 */ +at91_set_A_periph (AT91_PIN_PA6 ,1 ); +if (data->bus_width ==4 ) { +at91_set_A_periph (AT91_PIN_PA9 ,1 ); +at91_set_A_periph (AT91_PIN_PA10 ,1 ); +at91_set_A_periph (AT91_PIN_PA11 ,1 ); + } + + mci_device.platform_data = data; +at91_clock_associate ("mci_clk" , &mci_device,"mci_clk" ); +register_device (&mci_device); +} +#else +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) {} +#endif
arch/arm/mach-at91/at91sam9261_devices.c +50 -0
59 lines not on this page · raw message
arch/arm/mach-at91/at91sam9263_devices.c +78 -0
87 lines not on this page · raw message
arch/arm/mach-at91/at91sam9g45_devices.c +91 -0
100 lines not on this page · raw message
arch/arm/mach-at91/include/mach/board.h +10 -0
@@ -63,4 +63,14 @@ void at91_add_device_sdram(u32 size);#define ATMEL_UART_RI 0x20void at91_register_uart (unsigned id,unsigned pins); + +/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +}; + +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data);#endif
drivers/mci/Kconfig +7 -0
@@ -73,4 +73,11 @@ config MCI_OMAP_HSMMC Enable this entry to add support to read and write SD cards on a OMAP4 based system. +config MCI_ATMEL + bool "ATMEL (AT91)" + depends on ARCH_AT91 + help + Enable this entry to add support to read and write SD cards on a + Atmel AT91. + endif
drivers/mci/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_MCI_S3C) += s3c.o obj-$(CONFIG_MCI_IMX) += imx.o obj-$(CONFIG_MCI_IMX_ESDHC) += imx-esdhc.o obj-$(CONFIG_MCI_OMAP_HSMMC) += omap_hsmmc.o +obj-$(CONFIG_MCI_ATMEL) += atmel_mci.o
drivers/mci/at91_mci.h new file +121 -0
121 lines not on this page · raw message
drivers/mci/atmel_mci.c new file +526 -0
526 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 7 lines · Hubert Feurstein
The driver supports push and pull transfers.
Tested on at91sam9m10 SoC.Signed-off-by Hubert Feurstein <[email protected]>Cc Jean-Christophe PLAGNIOL-VILLARD <[email protected]>Cc Nicolas Ferre <[email protected]>Cc Patrice Vilchez <[email protected]>
Quoted 6 lines
---
Changes against v1:
- Code cleanup according to checkpatch.pl.
- Add support for devices: 9260, 9261 and 9263 (but not tested!)
- Use dev_* function instead of pr_*
I've test it on at91sam9263ek and work fine
please fix the following comments
Quoted 6 lines
arch/arm/mach-at91/include/mach/board.h +0
-0@@ -63,4 +63,14 @@ void at91_add_device_sdram(u32 size);#define ATMEL_UART_RI 0x20
arch/arm/mach-at91/include/mach/board.h void at91_add_device_sdram(u32 size); · line 73
Quoted 10 lines
arch/arm/mach-at91/include/mach/board.h +8
-0void at91_register_uart (unsigned id,unsigned pins); + +/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +};
we can have 2 slot but you allow only one
Quoted 17 lines
arch/arm/mach-at91/include/mach/board.h +2
-0+ +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data);#endif drivers/mci/Kconfig +6
-0@@ -73,4 +73,11 @@ config MCI_OMAP_HSMMC Enable this entry to add support to read and write SD cards on a OMAP4 based system. +config MCI_ATMEL + bool "ATMEL (AT91)" + depends on ARCH_AT91 + help + Enable this entry to add support to read and write SD cards on a + Atmel AT91.
drivers/mci/Kconfig config MCI_OMAP_HSMMC
Quoted 10 lines
drivers/mci/Kconfig +8
-0+ endif + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +/* #define DEBUG */
no need please remove
Quoted 30 lines
drivers/mci/Kconfig +30
-0+ +#include <common.h> +#include <init.h> +#include <mci.h> +#include <errno.h> +#include <clock.h> +#include <gpio.h> +#include <asm/io.h> +#include <mach/board.h> +#include <linux/clk.h> + +#include "at91_mci.h" + +/* + * Structure for struct SoC access. + * Names starting with '_' are fillers. + */ +struct atmel_mci_regs { + /* reg Offset */ + u32 cr; /* 0x00 */ + u32 mr; /* 0x04 */ + u32 dtor; /* 0x08 */ + u32 sdcr; /* 0x0c */ + u32 argr; /* 0x10 */ + u32 cmdr; /* 0x14 */ + u32 blkr; /* 0x18 */ + u32 _1c; /* 0x1c */ + u32 rspr; /* 0x20 */ + u32 rspr1; /* 0x24 */ + u32 rspr2; /* 0x28 */
drivers/mci/Kconfig
Quoted 10 lines
drivers/mci/Kconfig +10
-0+ u32 rspr3; /* 0x2c */ + u32 rdr; /* 0x30 */ + u32 tdr; /* 0x34 */ + u32 _38; /* 0x38 */ + u32 _3c; /* 0x3c */ + u32 sr; /* 0x40 */ + u32 ier; /* 0x44 */ + u32 idr; /* 0x48 */ + u32 imr; /* 0x4c */ +};
please use the same as the kernel here
offset not a struct
Quoted 27 lines
drivers/mci/Kconfig +26
-0+ +struct atmel_mci_host { + struct mci_host mci; + struct atmel_mci_regs volatile __iomem *base; + struct device_d *hw_dev; + struct clk *clk; + + u32 datasize; + struct mci_cmd *cmd; + struct mci_data *data; +}; + +static int atmel_pull(struct atmel_mci_host *host, void *_buf, int bytes) +{ + unsigned int stat; + u32 *buf = _buf; + + while (bytes > 3) { + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + *buf++ = readl(&host->base->rdr); + bytes -= 4; + } +
drivers/mci/Kconfig
Quoted 10 lines
drivers/mci/Kconfig +10
-0+ if (bytes) { + u8 *b = (u8 *)buf; + u32 tmp; + + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + tmp = readl(&host->base->rdr); + memcpy(b, &tmp, bytes);
please use __iowrite32 to speedup the copy
Quoted 19 lines
drivers/mci/Kconfig +19
-0+ } + + return 0; +} + +#ifdef CONFIG_MCI_WRITE +static int atmel_push(struct atmel_mci_host *host, const void *_buf, int bytes) +{ + unsigned int stat; + const u32 *buf = _buf; + + while (bytes > 3) { + stat = atmel_poll_status(host, AT91_MCI_TXRDY); + if (stat) + return stat; + + writel(*buf++, &host->base->tdr); + bytes -= 4; + }
drivers/mci/Kconfig
Quoted 10 lines
drivers/mci/Kconfig +10
-0+ + if (bytes) { + const u8 *b = (u8 *)buf; + u32 tmp; + + stat = atmel_poll_status(host, AT91_MCI_TXRDY); + if (stat) + return stat; + + memcpy(&tmp, b, bytes);
ditto
Quoted 30 lines
drivers/mci/Kconfig +30
-0+ writel(tmp, &host->base->tdr); + } + + stat = atmel_poll_status(host, AT91_MCI_TXRDY); + if (stat) + return stat; + + return 0; +} +#endif /* CONFIG_MCI_WRITE */ + +static int atmel_transfer_data(struct atmel_mci_host *host) +{ + struct mci_data *data = host->data; + int stat; + unsigned long length; + + length = data->blocks * data->blocksize; + host->datasize = 0; + + if (data->flags & MMC_DATA_READ) { + stat = atmel_pull(host, data->dest, length); + if (stat) + return stat; + +/** change host interface settings */ +static void mci_set_ios(struct mci_host *mci, struct device_d *mci_dev, + unsigned bus_width, unsigned clock) +{ + struct atmel_mci_host *host = to_mci_host(mci);
drivers/mci/Kconfig
Quoted 10 lines
drivers/mci/Kconfig +10
-0+ + dev_dbg(host->hw_dev, "atmel_mci_set_ios: bus_width=%d clk=%d\n", + bus_width, clock); + + if (bus_width == 8) + writel(AT91_MCI_SDCBUS_8BIT, &host->base->sdcr); + if (bus_width == 4) + writel(AT91_MCI_SDCBUS_4BIT, &host->base->sdcr); + else + writel(AT91_MCI_SDCBUS_1BIT, &host->base->sdcr);
switch here
Quoted 62 lines
drivers/mci/Kconfig +62
-0+ + if (clock) { + atmel_set_clk_rate(host, clock); + writel(AT91_MCI_MCIEN, &host->base->cr); + } else { + writel(AT91_MCI_MCIDIS, &host->base->cr); + } + + return; +} + +/** handle a command */ +static int mci_request(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data) +{ + struct atmel_mci_host *host = to_mci_host(mci); + u32 stat, cmdat = 0; + int ret; + + if (cmd->resp_type != MMC_RSP_NONE) + cmdat |= AT91_MCI_MAXLAT; + + if (data) { + atmel_setup_data(host, data); + + cmdat |= AT91_MCI_TRCMD_START | AT91_MCI_TRTYP_MULTIPLE; + + if (data->flags & MMC_DATA_READ) + cmdat |= AT91_MCI_TRDIR_RX; + } + + ret = atmel_start_cmd(host, cmd, cmdat); + if (ret) { + atmel_finish_request(host); + return ret; + } + + stat = atmel_poll_status(host, AT91_MCI_CMDRDY); + return atmel_cmd_done(host, stat); +} + +#ifdef CONFIG_MCI_INFO +static void mci_info(struct device_d *mci_dev) +{ + struct atmel_mci_host *host = mci_dev->priv; + struct atmel_mci_platform_data *pd = host->hw_dev->platform_data; + + printf(" Bus data width: %d bit\n", host->mci.bus_width); + + printf(" Bus frequency: %u Hz\n", host->mci.clock); + printf(" Frequency limits: "); + if (host->mci.f_min == 0) + printf("no lower limit "); + else + printf("%u Hz lower limit ", host->mci.f_min); + if (host->mci.f_max == 0) + printf("- no upper limit"); + else + printf("- %u Hz upper limit", host->mci.f_max); + + printf("\n Card detection support: %s\n", + pd->detect_pin != 0 ? "yes" : "no"); +
drivers/mci/Kconfig
Quoted 10 lines
drivers/mci/Kconfig +10
-0+} +#endif /* CONFIG_MCI_INFO */ + +static int mci_probe(struct device_d *hw_dev) +{ + unsigned long clk_rate; + struct atmel_mci_host *host; + struct atmel_mci_platform_data *pd = hw_dev->platform_data; + + if (pd == NULL) {
if (!pd)
drivers/mci/Kconfig
Quoted 9 lines
drivers/mci/Kconfig +9
-0+ dev_err(hw_dev, "missing platform data\n"); + return -EINVAL; + } + + host = xzalloc(sizeof(*host)); + host->mci.send_cmd = mci_request; + host->mci.set_ios = mci_set_ios; + host->mci.init = mci_reset; +
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/1 at91sam9263ek: add mci1 support
In reply to Hubert Feursteinenable fat support
--- arch/arm/boards/at91sam9263ek/init.c | 16 ++++++++++++++++ arch/arm/configs/at91sam9263ek_defconfig | 5 +++++ 2 files changed, 21 insertions(+), 0 deletions(-)
arch/arm/boards/at91sam9263ek/init.c +16 -0
@@ -99,6 +99,21 @@ static struct at91_ether_platform_data macb_pdata = { .phy_addr = 0, }; +#if defined(CONFIG_MCI_ATMEL ) +static struct atmel_mci_platform_data __initdata ek_mci_data = { + .bus_width =4 , + .detect_pin =AT91_PIN_PE18 , + .wp_pin =AT91_PIN_PE19 , +}; + +static void ek_add_device_mci (void ) +{ +at91_add_device_mci (1 , &ek_mci_data); +} +#else +static void ek_add_device_mci (void ) {} +#endif +static int at91sam9263ek_devices_init (void ) {/*
@@ -113,6 +128,7 @@ static int at91sam9263ek_devices_init(void)ek_add_device_nand ();at91_add_device_eth (&macb_pdata);register_device (&cfi_dev); +ek_add_device_mci ();#if defined(CONFIG_DRIVER_CFI ) || defined(CONFIG_DRIVER_CFI_OLD )devfs_add_partition ("nor0" ,0x00000 ,0x40000 ,PARTITION_FIXED ,"self" );
arch/arm/configs/at91sam9263ek_defconfig +5 -0
@@ -40,3 +40,8 @@ CONFIG_MTD=y CONFIG_NAND=y CONFIG_NAND_ATMEL=y CONFIG_UBI=y +CONFIG_MCI=y +CONFIG_MCI_ATMEL=y +CONFIG_FS_FAT=y +CONFIG_FS_FAT_WRITE=y +CONFIG_FS_FAT_LFN=y
Signature · 7 lines
1.7.4.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
2011/6/2 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:
Quoted 1 line · Hubert Feurstein
[snip]
Quoted 1 line
I've test it on at91sam9263ek and work fine
Great, good to hear ;) I'll add also support for at91sam9m10g45ek later in an extra commit.
Quoted 4 lines
please fix the following comments
[snip]
Quoted 8 lines
arch/arm/mach-at91/include/mach/board.h void at91_add_device_sdram(u32 size); · line 73
Quoted 7 lines
arch/arm/mach-at91/include/mach/board.h +7
-0+/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +};we can have 2 slot but you allow only one
Would it be ok to add the second slot in an extra commit?
[snip]
Quoted 21 lines
Quoted 21 lines
drivers/mci/atmel_mci.c new file +21
-0+/* +* Structure for struct SoC access. +* Names starting with '_' are fillers. +*/ +struct atmel_mci_regs { + /* reg Offset */ + u32 cr; /* 0x00 */ + u32 mr; /* 0x04 */ + u32 dtor; /* 0x08 */ + u32 sdcr; /* 0x0c */ + u32 argr; /* 0x10 */ + u32 cmdr; /* 0x14 */ + u32 blkr; /* 0x18 */ + u32 _1c; /* 0x1c */ + u32 rspr; /* 0x20 */ + u32 rspr1; /* 0x24 */ + u32 rspr2; /* 0x28 */ + u32 rspr3; /* 0x2c */ + u32 rdr; /* 0x30 */ + u32 tdr; /* 0x34 */ + u32 _38; /* 0x38 */
Quoted 8 lines
Quoted 6 lines
+ u32
_3c; /*0x3c*/
+ u32 sr; /*0x40*/
+ u32 ier; /*0x44*/
+ u32 idr; /*0x48*/
+ u32 imr; /*0x4c*/
+};please use the same as the kernel here
offset not a struct
Of course I could change it to offset, but I thought this is the way how it is done in barebox.
What is Sascha's opinion on that?
Quoted 30 lines
Quoted 30 lines
drivers/mci/atmel_mci.c new file +29
-0+ +struct atmel_mci_host { + struct mci_host mci; + struct atmel_mci_regs volatile __iomem *base; + struct device_d *hw_dev; + struct clk *clk; + + u32 datasize; + struct mci_cmd *cmd; + struct mci_data *data; +}; + +static int atmel_pull (struct atmel_mci_host *host,void *_buf,int bytes) +{ + unsigned int stat; + u32 *buf = _buf; + + while (bytes > 3) { + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + *buf++ = readl(&host->base->rdr); + bytes -= 4; + } + + if (bytes) { + u8 *b = (u8 *)buf; + u32 tmp;
Quoted 8 lines
drivers/mci/atmel_mci.c line 153
Quoted 7 lines
drivers/mci/atmel_mci.c new file +7
-0+ + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + tmp = readl(&host->base->rdr); + memcpy(b, &tmp, bytes);please use
__iowrite32to speedup the copy
I think memcpy is alright here. Usually this code-path shouldn't be executed anyway, because the mci-core always
requests multiples of 512 bytes, and here we copy only the last remaining _three_ bytes.
Quoted 5 lines
Quoted 5 lines
+ }
drivers/mci/atmel_mci.c new file +4
-0+ + return 0; +} +
[snip]
Quoted 8 lines
Quoted 7 lines
+
+ if (bus_width== 8)
+writel(AT91_MCI_SDCBUS_8BIT, &host->base->sdcr);
+ if (bus_width== 4)
+writel(AT91_MCI_SDCBUS_4BIT, &host->base->sdcr);
+ else
+writel(AT91_MCI_SDCBUS_1BIT, &host->base->sdcr);switch here
OK
[snip]
Quoted 9 lines
drivers/mci/atmel_mci.c line 475
Quoted 8 lines
drivers/mci/atmel_mci.c new file +8
-0+ +static int mci_probe (struct device_d *hw_dev) +{ + unsigned long clk_rate; + struct atmel_mci_host *host; + struct atmel_mci_platform_data *pd = hw_dev->platform_data; + + if (pd == NULL) {if (!pd)
OK
Quoted 4 lines
Quoted 4 lines
+
dev_err(hw_dev, "missing platform data\n");
+ return-EINVAL;
+ }
+
Quoted 9 lines
Quoted 5 lines
+ host = xzalloc(sizeof(*host));
+host->mci.send_cmd=mci_request;
+host->mci.set_ios=mci_set_ios;
+host->mci.init=mci_reset;
+Best Regards,
J.
Best Regards and thank you for the support.
Hubert
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 51 lines · Hubert Feurstein
2011/6/2 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:
Quoted 1 line · Hubert Feurstein
[snip]
Quoted 1 line
I've test it on at91sam9263ek and work fine
Great, good to hear ;) I'll add also support for at91sam9m10g45ek later in an extra commit.
Quoted 4 lines
please fix the following comments
[snip]
Quoted 8 lines
arch/arm/mach-at91/include/mach/board.h void at91_add_device_sdram(u32 size); · line 73
Quoted 7 lines
arch/arm/mach-at91/include/mach/board.h +7
-0+/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +};we can have 2 slot but you allow only one
Would it be ok to add the second slot in an extra commit?
[snip]
Quoted 21 lines
Quoted 21 lines
drivers/mci/atmel_mci.c new file +21
-0+/* +* Structure for struct SoC access. +* Names starting with '_' are fillers. +*/ +struct atmel_mci_regs { + /* reg Offset */ + u32 cr; /* 0x00 */ + u32 mr; /* 0x04 */ + u32 dtor; /* 0x08 */ + u32 sdcr; /* 0x0c */ + u32 argr; /* 0x10 */ + u32 cmdr; /* 0x14 */ + u32 blkr; /* 0x18 */ + u32 _1c; /* 0x1c */ + u32 rspr; /* 0x20 */ + u32 rspr1; /* 0x24 */ + u32 rspr2; /* 0x28 */ + u32 rspr3; /* 0x2c */ + u32 rdr; /* 0x30 */ + u32 tdr; /* 0x34 */ + u32 _38; /* 0x38 */Quoted 8 lines
Quoted 6 lines
+ u32
_3c; /*0x3c*/
+ u32 sr; /*0x40*/
+ u32 ier; /*0x44*/
+ u32 idr; /*0x48*/
+ u32 imr; /*0x4c*/
+};please use the same as the kernel here
offset not a struct
Quoted 2 lines
Of course I could change it to offset, but I thought this is the way how it is done in barebox.
Nope, it's prefered in U-Boot but not barebox.
Quoted 1 line
What is Sascha's opinion on that?
Personally I prefer having defines instead of struct types for variables. Reasons for this are:
- defines make the actual register offset clear without having to put comments after them. Also, you can't make mistakes while numbering the registers.
- Type safety is often an argument for using struct types, but 16 bit registers with 32bit alignment are just too ugly to describe in struct types. Also, if used in another SoC the registers might have a different alignment which is also quite ugly to describe in structs.
I know there are other opinions and I won't nack patches just because of this. It's probably best to just use the way the drivers does you copied this one from.
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
drivers/mci/atmel_mci.c new file +29
-0+ +struct atmel_mci_host { + struct mci_host mci; + struct atmel_mci_regs volatile __iomem *base; + struct device_d *hw_dev; + struct clk *clk; + + u32 datasize; + struct mci_cmd *cmd; + struct mci_data *data; +}; + +static int atmel_pull (struct atmel_mci_host *host,void *_buf,int bytes) +{ + unsigned int stat; + u32 *buf = _buf; + + while (bytes > 3) { + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + *buf++ = readl(&host->base->rdr); + bytes -= 4; + } + + if (bytes) { + u8 *b = (u8 *)buf; + u32 tmp;
Quoted 8 lines
Quoted 8 lines
drivers/mci/atmel_mci.c line 153
Quoted 7 lines
drivers/mci/atmel_mci.c new file +7
-0+ + stat = atmel_poll_status(host, AT91_MCI_RXRDY); + if (stat) + return stat; + + tmp = readl(&host->base->rdr); + memcpy(b, &tmp, bytes);please use
__iowrite32to speedup the copy
Ah, here is the potential __iowrite32 user ;)
Quoted 4 lines
I think memcpy is alright here. Usually this code-path shouldn't be executed anyway, because the mci-core always
requests multiples of 512 bytes, and here we copy only the last remaining _three_ bytes.
One thing to consider when using memcpy for io accesses is that it is not specified which type of accesses are used. For example on arm, when assembler optimized string functions are used, the code will use 32 bit accesses when possible. If not, memcpy will be a simple byte copy loop.
I really doubt this code works as expected. Does your hardware support byte accesses? Might be better to just add a WARN_ON(bytes) instead of introducing this kind of untested code.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 19 lines · Hubert Feurstein
2011/6/2 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>:
Quoted 1 line · Hubert Feurstein
[snip]
Quoted 1 line
I've test it on at91sam9263ek and work fine
Great, good to hear ;) I'll add also support for at91sam9m10g45ek later in an extra commit.
Quoted 4 lines
please fix the following comments
[snip]
Quoted 8 lines
arch/arm/mach-at91/include/mach/board.h void at91_add_device_sdram(u32 size); · line 73
Quoted 7 lines
arch/arm/mach-at91/include/mach/board.h +7
-0+/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +};we can have 2 slot but you allow only one
Quoted 1 line
Would it be ok to add the second slot in an extra commit?
ok
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 1/1 mci: add Atmel AT91 MCI driver
The driver supports push and pull transfers.
Tested on at91sam9m10 SoC.
---
Changes according to v2:
- removed struct based register access
- use WARN_ON when transfer size is not multiple of 4 bytes
arch/arm/mach-at91/at91sam9260_devices.c | 50 +++ arch/arm/mach-at91/at91sam9261_devices.c | 50 +++ arch/arm/mach-at91/at91sam9263_devices.c | 78 +++++ arch/arm/mach-at91/at91sam9g45_devices.c | 91 ++++++ arch/arm/mach-at91/include/mach/board.h | 10 + drivers/mci/Kconfig | 7 + drivers/mci/Makefile | 1 + drivers/mci/at91_mci.h | 121 ++++++++ drivers/mci/atmel_mci.c | 494 ++++++++++++++++++++++++++++++ 9 files changed, 902 insertions(+), 0 deletions(-) create mode 100644 drivers/mci/at91_mci.h create mode 100644 drivers/mci/atmel_mci.c
arch/arm/mach-at91/at91sam9260_devices.c +50 -0
@@ -10,6 +10,7 @@* */ #include <common.h> +#include <sizes.h> #include <asm/armlinux.h> #include <asm/hardware.h> #include <mach/board.h>
@@ -280,3 +281,52 @@ void at91_register_uart(unsigned id, unsigned pins)return ; } } + +#if defined(CONFIG_MCI_ATMEL ) +static struct device_d mci_device = { + .id =-1 , + .name ="atmel_mci" , + .map_base =AT91SAM9260_BASE_MCI , + .size =SZ_16K , +}; + +/* Consider only one slot : slot 0 */ +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) +{ +if (!data) +return ; + +/* need bus_width */ +if (!data->bus_width) +return ; + +/* input/irq */ +if (data->detect_pin) { +at91_set_gpio_input (data->detect_pin,1 ); +at91_set_deglitch (data->detect_pin,1 ); + } + +if (data->wp_pin) +at91_set_gpio_input (data->wp_pin,1 ); + +/* CLK */ +at91_set_A_periph (AT91_PIN_PA8 ,0 ); + +/* CMD */ +at91_set_A_periph (AT91_PIN_PA7 ,1 ); + +/* DAT0, maybe DAT1..DAT3 */ +at91_set_A_periph (AT91_PIN_PA6 ,1 ); +if (data->bus_width ==4 ) { +at91_set_A_periph (AT91_PIN_PA9 ,1 ); +at91_set_A_periph (AT91_PIN_PA10 ,1 ); +at91_set_A_periph (AT91_PIN_PA11 ,1 ); + } + + mci_device.platform_data = data; +at91_clock_associate ("mci_clk" , &mci_device,"mci_clk" ); +register_device (&mci_device); +} +#else +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data) {} +#endif
arch/arm/mach-at91/at91sam9261_devices.c +50 -0
59 lines not on this page · raw message
arch/arm/mach-at91/at91sam9263_devices.c +78 -0
87 lines not on this page · raw message
arch/arm/mach-at91/at91sam9g45_devices.c +91 -0
100 lines not on this page · raw message
arch/arm/mach-at91/include/mach/board.h +10 -0
@@ -63,4 +63,14 @@ void at91_add_device_sdram(u32 size);#define ATMEL_UART_RI 0x20void at91_register_uart (unsigned id,unsigned pins); + +/* Multimedia Card Interface */ +struct atmel_mci_platform_data { +unsigned bus_width; +unsigned host_caps;/* MCI_MODE_* from mci.h */ +unsigned detect_pin; +unsigned wp_pin; +}; + +void at91_add_device_mci (short mmc_id,struct atmel_mci_platform_data *data);#endif
drivers/mci/Kconfig +7 -0
@@ -73,4 +73,11 @@ config MCI_OMAP_HSMMC Enable this entry to add support to read and write SD cards on a OMAP4 based system. +config MCI_ATMEL + bool "ATMEL (AT91)" + depends on ARCH_AT91 + help + Enable this entry to add support to read and write SD cards on a + Atmel AT91. + endif
drivers/mci/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_MCI_S3C) += s3c.o obj-$(CONFIG_MCI_IMX) += imx.o obj-$(CONFIG_MCI_IMX_ESDHC) += imx-esdhc.o obj-$(CONFIG_MCI_OMAP_HSMMC) += omap_hsmmc.o +obj-$(CONFIG_MCI_ATMEL) += atmel_mci.o
drivers/mci/at91_mci.h new file +121 -0
121 lines not on this page · raw message
drivers/mci/atmel_mci.c new file +494 -0
494 lines not on this page · raw message
--
1.7.1
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox