simone.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * arch/arm/mach-ep93xx/simone.c
  3. * Simplemachines Sim.One support.
  4. *
  5. * Copyright (C) 2010 Ryan Mallon
  6. *
  7. * Based on the 2.6.24.7 support:
  8. * Copyright (C) 2009 Simplemachines
  9. * MMC support by Peter Ivanov <ivanovp@gmail.com>, 2007
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/i2c.h>
  21. #include <linux/i2c-gpio.h>
  22. #include <linux/mmc/host.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/mmc_spi.h>
  25. #include <linux/platform_data/video-ep93xx.h>
  26. #include <linux/platform_data/spi-ep93xx.h>
  27. #include <linux/gpio.h>
  28. #include <mach/hardware.h>
  29. #include <mach/gpio-ep93xx.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include "soc.h"
  33. static struct ep93xx_eth_data __initdata simone_eth_data = {
  34. .phy_id = 1,
  35. };
  36. static struct ep93xxfb_mach_info __initdata simone_fb_info = {
  37. .flags = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING,
  38. };
  39. /*
  40. * GPIO lines used for MMC card detection.
  41. */
  42. #define MMC_CARD_DETECT_GPIO EP93XX_GPIO_LINE_EGPIO0
  43. /*
  44. * Up to v1.3, the Sim.One used SFRMOUT as SD card chip select, but this goes
  45. * low between multi-message command blocks. From v1.4, it uses a GPIO instead.
  46. * v1.3 parts will still work, since the signal on SFRMOUT is automatic.
  47. */
  48. #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO1
  49. /*
  50. * MMC SPI chip select GPIO handling. If you are using SFRMOUT (SFRM1) signal,
  51. * you can leave these empty and pass NULL as .controller_data.
  52. */
  53. static int simone_mmc_spi_setup(struct spi_device *spi)
  54. {
  55. unsigned int gpio = MMC_CHIP_SELECT_GPIO;
  56. int err;
  57. err = gpio_request(gpio, spi->modalias);
  58. if (err)
  59. return err;
  60. err = gpio_direction_output(gpio, 1);
  61. if (err) {
  62. gpio_free(gpio);
  63. return err;
  64. }
  65. return 0;
  66. }
  67. static void simone_mmc_spi_cleanup(struct spi_device *spi)
  68. {
  69. unsigned int gpio = MMC_CHIP_SELECT_GPIO;
  70. gpio_set_value(gpio, 1);
  71. gpio_direction_input(gpio);
  72. gpio_free(gpio);
  73. }
  74. static void simone_mmc_spi_cs_control(struct spi_device *spi, int value)
  75. {
  76. gpio_set_value(MMC_CHIP_SELECT_GPIO, value);
  77. }
  78. static struct ep93xx_spi_chip_ops simone_mmc_spi_ops = {
  79. .setup = simone_mmc_spi_setup,
  80. .cleanup = simone_mmc_spi_cleanup,
  81. .cs_control = simone_mmc_spi_cs_control,
  82. };
  83. /*
  84. * MMC card detection GPIO setup.
  85. */
  86. static int simone_mmc_spi_init(struct device *dev,
  87. irqreturn_t (*irq_handler)(int, void *), void *mmc)
  88. {
  89. unsigned int gpio = MMC_CARD_DETECT_GPIO;
  90. int irq, err;
  91. err = gpio_request(gpio, dev_name(dev));
  92. if (err)
  93. return err;
  94. err = gpio_direction_input(gpio);
  95. if (err)
  96. goto fail;
  97. irq = gpio_to_irq(gpio);
  98. if (irq < 0)
  99. goto fail;
  100. err = request_irq(irq, irq_handler, IRQF_TRIGGER_FALLING,
  101. "MMC card detect", mmc);
  102. if (err)
  103. goto fail;
  104. printk(KERN_INFO "%s: using irq %d for MMC card detection\n",
  105. dev_name(dev), irq);
  106. return 0;
  107. fail:
  108. gpio_free(gpio);
  109. return err;
  110. }
  111. static void simone_mmc_spi_exit(struct device *dev, void *mmc)
  112. {
  113. unsigned int gpio = MMC_CARD_DETECT_GPIO;
  114. free_irq(gpio_to_irq(gpio), mmc);
  115. gpio_free(gpio);
  116. }
  117. static struct mmc_spi_platform_data simone_mmc_spi_data = {
  118. .init = simone_mmc_spi_init,
  119. .exit = simone_mmc_spi_exit,
  120. .detect_delay = 500,
  121. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  122. };
  123. static struct spi_board_info simone_spi_devices[] __initdata = {
  124. {
  125. .modalias = "mmc_spi",
  126. .controller_data = &simone_mmc_spi_ops,
  127. .platform_data = &simone_mmc_spi_data,
  128. /*
  129. * We use 10 MHz even though the maximum is 3.7 MHz. The driver
  130. * will limit it automatically to max. frequency.
  131. */
  132. .max_speed_hz = 10 * 1000 * 1000,
  133. .bus_num = 0,
  134. .chip_select = 0,
  135. .mode = SPI_MODE_3,
  136. },
  137. };
  138. static struct ep93xx_spi_info simone_spi_info __initdata = {
  139. .num_chipselect = ARRAY_SIZE(simone_spi_devices),
  140. .use_dma = 1,
  141. };
  142. static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
  143. .sda_pin = EP93XX_GPIO_LINE_EEDAT,
  144. .sda_is_open_drain = 0,
  145. .scl_pin = EP93XX_GPIO_LINE_EECLK,
  146. .scl_is_open_drain = 0,
  147. .udelay = 0,
  148. .timeout = 0,
  149. };
  150. static struct i2c_board_info __initdata simone_i2c_board_info[] = {
  151. {
  152. I2C_BOARD_INFO("ds1337", 0x68),
  153. },
  154. };
  155. static struct platform_device simone_audio_device = {
  156. .name = "simone-audio",
  157. .id = -1,
  158. };
  159. static void __init simone_register_audio(void)
  160. {
  161. ep93xx_register_ac97();
  162. platform_device_register(&simone_audio_device);
  163. }
  164. static void __init simone_init_machine(void)
  165. {
  166. ep93xx_init_devices();
  167. ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
  168. ep93xx_register_eth(&simone_eth_data, 1);
  169. ep93xx_register_fb(&simone_fb_info);
  170. ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
  171. ARRAY_SIZE(simone_i2c_board_info));
  172. ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
  173. ARRAY_SIZE(simone_spi_devices));
  174. simone_register_audio();
  175. }
  176. MACHINE_START(SIM_ONE, "Simplemachines Sim.One Board")
  177. /* Maintainer: Ryan Mallon */
  178. .atag_offset = 0x100,
  179. .map_io = ep93xx_map_io,
  180. .init_irq = ep93xx_init_irq,
  181. .init_time = ep93xx_timer_init,
  182. .init_machine = simone_init_machine,
  183. .init_late = ep93xx_init_late,
  184. .restart = ep93xx_restart,
  185. MACHINE_END