1*4882a593SmuzhiyunHow to use SD/MMC cards with Atmel SoCs having MCI hardware 2*4882a593Smuzhiyun----------------------------------------------------------- 3*4882a593Smuzhiyun2010-08-16 Reinhard Meyer <reinhard.meyer@emk-elektronik.de> 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunThis is a new approach to use Atmel MCI hardware with the 6*4882a593Smuzhiyungeneral MMC framework. Therefore it benefits from that 7*4882a593Smuzhiyunframework's abilities to handle SDHC Cards and the ability 8*4882a593Smuzhiyunto write blocks. 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun- AT91SAM9XE512 (tested, will definitely work with XE128 and XE256) 11*4882a593Smuzhiyun- AT91SAM9260 (not tested, but MCI is to AT91SAM9XE) 12*4882a593Smuzhiyun- AT91SAM9G20 (not tested, should work) 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunIt should work with all other ATMEL devices that have MCI. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe generic driver does NOT assign port pins to the MCI block 17*4882a593Smuzhiyunnor does it start the MCI clock. This has to be handled in a 18*4882a593Smuzhiyunboard/SoC specific manner before the driver is initialized: 19*4882a593Smuzhiyun 20*4882a593Smuzhiyunexample: this is added to at91sam9260_devices.c: 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun#if defined(CONFIG_GENERIC_ATMEL_MCI) 23*4882a593Smuzhiyunvoid at91_mci_hw_init(void) 24*4882a593Smuzhiyun{ 25*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 8, PUP); /* MCCK */ 26*4882a593Smuzhiyun#if defined(CONFIG_ATMEL_MCI_PORTB) 27*4882a593Smuzhiyun at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* MCCDB */ 28*4882a593Smuzhiyun at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* MCDB0 */ 29*4882a593Smuzhiyun at91_set_b_periph(AT91_PIO_PORTA, 5, PUP); /* MCDB1 */ 30*4882a593Smuzhiyun at91_set_b_periph(AT91_PIO_PORTA, 4, PUP); /* MCDB2 */ 31*4882a593Smuzhiyun at91_set_b_periph(AT91_PIO_PORTA, 3, PUP); /* MCDB3 */ 32*4882a593Smuzhiyun#else 33*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 7, PUP); /* MCCDA */ 34*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 6, PUP); /* MCDA0 */ 35*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 9, PUP); /* MCDA1 */ 36*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 10, PUP); /* MCDA2 */ 37*4882a593Smuzhiyun at91_set_a_periph(AT91_PIO_PORTA, 11, PUP); /* MCDA3 */ 38*4882a593Smuzhiyun#endif 39*4882a593Smuzhiyun} 40*4882a593Smuzhiyun#endif 41*4882a593Smuzhiyun 42*4882a593Smuzhiyunthe board specific file need added: 43*4882a593Smuzhiyun... 44*4882a593Smuzhiyun#ifdef CONFIG_GENERIC_ATMEL_MCI 45*4882a593Smuzhiyun# include <mmc.h> 46*4882a593Smuzhiyun#endif 47*4882a593Smuzhiyun... 48*4882a593Smuzhiyun#ifdef CONFIG_GENERIC_ATMEL_MCI 49*4882a593Smuzhiyun/* this is a weak define that we are overriding */ 50*4882a593Smuzhiyunint board_mmc_init(bd_t *bd) 51*4882a593Smuzhiyun{ 52*4882a593Smuzhiyun /* Enable clock */ 53*4882a593Smuzhiyun at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_MCI); 54*4882a593Smuzhiyun at91_mci_hw_init(); 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun /* This calls the atmel_mci_init in gen_atmel_mci.c */ 57*4882a593Smuzhiyun return atmel_mci_init((void *)AT91_BASE_MCI); 58*4882a593Smuzhiyun} 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun/* this is a weak define that we are overriding */ 61*4882a593Smuzhiyunint board_mmc_getcd(struct mmc *mmc) 62*4882a593Smuzhiyun{ 63*4882a593Smuzhiyun return !at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN); 64*4882a593Smuzhiyun} 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun#endif 67*4882a593Smuzhiyun 68*4882a593Smuzhiyunand the board definition files needs: 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun/* SD/MMC card */ 71*4882a593Smuzhiyun#define CONFIG_GENERIC_ATMEL_MCI 1 72*4882a593Smuzhiyun#define CONFIG_ATMEL_MCI_PORTB 1 /* Atmel XE-EK uses port B */ 73*4882a593Smuzhiyun#define CONFIG_SYS_MMC_CD_PIN AT91_PIN_PC9 74*4882a593Smuzhiyun#define CONFIG_CMD_MMC 1 75