Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 1 | How to use SD/MMC cards with Atmel SoCs having MCI hardware |
| 2 | ----------------------------------------------------------- |
| 3 | 2010-08-16 Reinhard Meyer <reinhard.meyer@emk-elektronik.de> |
| 4 | |
| 5 | This is a new approach to use Atmel MCI hardware with the |
| 6 | general MMC framework. Therefore it benefits from that |
| 7 | framework's abilities to handle SDHC Cards and the ability |
| 8 | to write blocks. |
| 9 | |
| 10 | - AT91SAM9XE512 (tested, will definitely work with XE128 and XE256) |
| 11 | - AT91SAM9260 (not tested, but MCI is to AT91SAM9XE) |
| 12 | - AT91SAM9G20 (not tested, should work) |
| 13 | |
Andy Shevchenko | 8cb5cdd | 2017-07-05 16:25:22 +0300 | [diff] [blame] | 14 | It should work with all other ATMEL devices that have MCI. |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 15 | |
| 16 | The generic driver does NOT assign port pins to the MCI block |
| 17 | nor does it start the MCI clock. This has to be handled in a |
| 18 | board/SoC specific manner before the driver is initialized: |
| 19 | |
| 20 | example: this is added to at91sam9260_devices.c: |
| 21 | |
Sven Schnelle | 69df6de | 2011-10-21 14:49:26 +0200 | [diff] [blame] | 22 | #if defined(CONFIG_GENERIC_ATMEL_MCI) |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 23 | void at91_mci_hw_init(void) |
| 24 | { |
| 25 | at91_set_a_periph(AT91_PIO_PORTA, 8, PUP); /* MCCK */ |
| 26 | #if defined(CONFIG_ATMEL_MCI_PORTB) |
| 27 | at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* MCCDB */ |
| 28 | at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* MCDB0 */ |
| 29 | at91_set_b_periph(AT91_PIO_PORTA, 5, PUP); /* MCDB1 */ |
| 30 | at91_set_b_periph(AT91_PIO_PORTA, 4, PUP); /* MCDB2 */ |
| 31 | at91_set_b_periph(AT91_PIO_PORTA, 3, PUP); /* MCDB3 */ |
| 32 | #else |
| 33 | at91_set_a_periph(AT91_PIO_PORTA, 7, PUP); /* MCCDA */ |
| 34 | at91_set_a_periph(AT91_PIO_PORTA, 6, PUP); /* MCDA0 */ |
| 35 | at91_set_a_periph(AT91_PIO_PORTA, 9, PUP); /* MCDA1 */ |
| 36 | at91_set_a_periph(AT91_PIO_PORTA, 10, PUP); /* MCDA2 */ |
| 37 | at91_set_a_periph(AT91_PIO_PORTA, 11, PUP); /* MCDA3 */ |
| 38 | #endif |
| 39 | } |
| 40 | #endif |
| 41 | |
| 42 | the board specific file need added: |
| 43 | ... |
| 44 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 45 | # include <mmc.h> |
| 46 | #endif |
| 47 | ... |
| 48 | #ifdef CONFIG_GENERIC_ATMEL_MCI |
| 49 | /* this is a weak define that we are overriding */ |
Masahiro Yamada | 940a922 | 2020-06-26 15:13:34 +0900 | [diff] [blame] | 50 | int board_mmc_init(struct bd_info *bd) |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 51 | { |
| 52 | /* Enable clock */ |
| 53 | at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_MCI); |
| 54 | at91_mci_hw_init(); |
| 55 | |
| 56 | /* This calls the atmel_mci_init in gen_atmel_mci.c */ |
| 57 | return atmel_mci_init((void *)AT91_BASE_MCI); |
| 58 | } |
| 59 | |
| 60 | /* this is a weak define that we are overriding */ |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 61 | int board_mmc_getcd(struct mmc *mmc) |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 62 | { |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 63 | return !at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN); |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | #endif |
| 67 | |
| 68 | and the board definition files needs: |
| 69 | |
| 70 | /* SD/MMC card */ |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 71 | #define CONFIG_GENERIC_ATMEL_MCI 1 |
| 72 | #define CONFIG_ATMEL_MCI_PORTB 1 /* Atmel XE-EK uses port B */ |
| 73 | #define CONFIG_SYS_MMC_CD_PIN AT91_PIN_PC9 |
| 74 | #define CONFIG_CMD_MMC 1 |