--- arch/arm/mach-ep93xx/simone.c.old 2010-03-30 17:20:10.000000000 +0100 +++ arch/arm/mach-ep93xx/simone.c 2010-04-22 18:55:49.000000000 +0100 @@ -22,9 +22,12 @@ #include #include #include +#include +#include #include #include +#include #include #include @@ -59,6 +62,84 @@ .flags = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING, }; +/* + * MMC-on-SPI setup code + */ + +/* Which GPIO line is connected to the card-present detect line? */ +#define SIM_ONE_MMC_CARD_PRESENT_GPIO EP93XX_GPIO_LINE_EGPIO0 + +/* + * Initializes SPI system to communicate with MMC/SD card + */ +static int ep93xx_mmc_spi_init(struct device *pdev, irqreturn_t (*card_det_irq_handler)(int, void *), + void *mmc) +{ + int err, irq; + + err = gpio_request(SIM_ONE_MMC_CARD_PRESENT_GPIO, "ep93xx-mmc-spi"); + if (err) + return err; + + err = gpio_direction_input(SIM_ONE_MMC_CARD_PRESENT_GPIO); + if (err) + goto fail; + + irq = gpio_to_irq(SIM_ONE_MMC_CARD_PRESENT_GPIO); + err = request_irq(irq, card_det_irq_handler, + IRQF_DISABLED | IRQF_TRIGGER_FALLING, + "ep93xx-mmc-spi", mmc); + if (err == 0) { + printk(KERN_INFO "ep93xx-mmc-spi: assigned card detection IRQ %d\n", irq); + } else { + dev_err(pdev, "Cannot assign MMC/SD card detection IRQ (%i)!\n", irq); + goto fail; + } + + return 0; + +fail: + gpio_free(SIM_ONE_MMC_CARD_PRESENT_GPIO); + return err; +} + +static void ep93xx_mmc_spi_exit(struct device *pdev, void *mmc) +{ + free_irq(gpio_to_irq(SIM_ONE_MMC_CARD_PRESENT_GPIO), mmc); + gpio_free(SIM_ONE_MMC_CARD_PRESENT_GPIO); +} + +static struct mmc_spi_platform_data simone_spi_pdata = { + .init = &ep93xx_mmc_spi_init, /* set up card detect GPIO IRQ */ + .exit = &ep93xx_mmc_spi_exit, + .get_ro = NULL, /* no read-only detection here */ + .detect_delay = 500, /* card detection delay in msec */ + .ocr_mask = MMC_VDD_33_34, +}; + +/* + * Effective speeds are integer divisions of 7372800 with E1 silicon or + * 14745600 for E2 and the minimum usable divisor is 2, so we select the + * higher possible rate; E1 silicon will actually get 3686400. + * Modes 0 and 3 work with SD/MMC as they sample on the rising clock edge; + * Mode 0 deselects SFRMOUT between bytes while Mode 3 keeps it low. + * Since this is the SD chip select line on Sim.One, Mode 3 is suitable + * and gives 15% faster transfer speeds than Mode 0. + */ +static struct spi_board_info simone_spi_board_info[] = { + { + .modalias = "mmc_spi", + .platform_data = &simone_spi_pdata, + .max_speed_hz = 7372800, + .mode = SPI_MODE_3, + } +}; + +static struct ep93xx_spi_info simone_spi_info = { + .num_chipselect = 1, + .cs_control = NULL, +}; + static struct i2c_gpio_platform_data simone_i2c_gpio_data = { .sda_pin = EP93XX_GPIO_LINE_EEDAT, .sda_is_open_drain = 0, @@ -81,6 +162,8 @@ platform_device_register(&simone_flash); ep93xx_register_eth(&simone_eth_data, 1); ep93xx_register_fb(&simone_fb_info); + spi_register_board_info(simone_spi_board_info, ARRAY_SIZE(simone_spi_board_info)); + ep93xx_register_spi(&simone_spi_info); ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, ARRAY_SIZE(simone_i2c_board_info)); }