stmp378x_devb.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Freescale STMP378X development board support
  3. *
  4. * Embedded Alley Solutions, Inc <source@embeddedalley.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  7. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  8. */
  9. /*
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/io.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk.h>
  23. #include <linux/err.h>
  24. #include <linux/spi/spi.h>
  25. #include <asm/setup.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/mach/arch.h>
  28. #include <mach/pins.h>
  29. #include <mach/pinmux.h>
  30. #include <mach/platform.h>
  31. #include <mach/stmp3xxx.h>
  32. #include <mach/mmc.h>
  33. #include <mach/gpmi.h>
  34. #include "stmp378x.h"
  35. static struct platform_device *devices[] = {
  36. &stmp3xxx_dbguart,
  37. &stmp3xxx_appuart,
  38. &stmp3xxx_watchdog,
  39. &stmp3xxx_touchscreen,
  40. &stmp3xxx_rtc,
  41. &stmp3xxx_keyboard,
  42. &stmp3xxx_framebuffer,
  43. &stmp3xxx_backlight,
  44. &stmp3xxx_rotdec,
  45. &stmp3xxx_persistent,
  46. &stmp3xxx_dcp_bootstream,
  47. &stmp3xxx_dcp,
  48. &stmp3xxx_battery,
  49. &stmp378x_pxp,
  50. &stmp378x_i2c,
  51. };
  52. static struct pin_desc i2c_pins_desc[] = {
  53. { PINID_I2C_SCL, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  54. { PINID_I2C_SDA, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  55. };
  56. static struct pin_group i2c_pins = {
  57. .pins = i2c_pins_desc,
  58. .nr_pins = ARRAY_SIZE(i2c_pins_desc),
  59. };
  60. static struct pin_desc dbguart_pins_0[] = {
  61. { PINID_PWM0, PIN_FUN3, },
  62. { PINID_PWM1, PIN_FUN3, },
  63. };
  64. static struct pin_group dbguart_pins[] = {
  65. [0] = {
  66. .pins = dbguart_pins_0,
  67. .nr_pins = ARRAY_SIZE(dbguart_pins_0),
  68. },
  69. };
  70. static int dbguart_pins_control(int id, int request)
  71. {
  72. int r = 0;
  73. if (request)
  74. r = stmp3xxx_request_pin_group(&dbguart_pins[id], "debug uart");
  75. else
  76. stmp3xxx_release_pin_group(&dbguart_pins[id], "debug uart");
  77. return r;
  78. }
  79. static struct pin_desc appuart_pins_0[] = {
  80. { PINID_AUART1_CTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  81. { PINID_AUART1_RTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  82. { PINID_AUART1_RX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  83. { PINID_AUART1_TX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  84. };
  85. static struct pin_desc appuart_pins_1[] = {
  86. #if 0 /* enable these when second appuart will be connected */
  87. { PINID_AUART2_CTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  88. { PINID_AUART2_RTS, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  89. { PINID_AUART2_RX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  90. { PINID_AUART2_TX, PIN_FUN1, PIN_4MA, PIN_1_8V, 0, },
  91. #endif
  92. };
  93. static struct pin_desc mmc_pins_desc[] = {
  94. { PINID_SSP1_DATA0, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
  95. { PINID_SSP1_DATA1, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
  96. { PINID_SSP1_DATA2, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
  97. { PINID_SSP1_DATA3, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
  98. { PINID_SSP1_CMD, PIN_FUN1, PIN_8MA, PIN_3_3V, 1 },
  99. { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
  100. { PINID_SSP1_DETECT, PIN_FUN1, PIN_8MA, PIN_3_3V, 0 },
  101. };
  102. static struct pin_group mmc_pins = {
  103. .pins = mmc_pins_desc,
  104. .nr_pins = ARRAY_SIZE(mmc_pins_desc),
  105. };
  106. static int stmp3xxxmmc_get_wp(void)
  107. {
  108. return gpio_get_value(PINID_PWM4);
  109. }
  110. static int stmp3xxxmmc_hw_init_ssp1(void)
  111. {
  112. int ret;
  113. ret = stmp3xxx_request_pin_group(&mmc_pins, "mmc");
  114. if (ret)
  115. goto out;
  116. /* Configure write protect GPIO pin */
  117. ret = gpio_request(PINID_PWM4, "mmc wp");
  118. if (ret)
  119. goto out_wp;
  120. gpio_direction_input(PINID_PWM4);
  121. /* Configure POWER pin as gpio to drive power to MMC slot */
  122. ret = gpio_request(PINID_PWM3, "mmc power");
  123. if (ret)
  124. goto out_power;
  125. gpio_direction_output(PINID_PWM3, 0);
  126. mdelay(100);
  127. return 0;
  128. out_power:
  129. gpio_free(PINID_PWM4);
  130. out_wp:
  131. stmp3xxx_release_pin_group(&mmc_pins, "mmc");
  132. out:
  133. return ret;
  134. }
  135. static void stmp3xxxmmc_hw_release_ssp1(void)
  136. {
  137. gpio_free(PINID_PWM3);
  138. gpio_free(PINID_PWM4);
  139. stmp3xxx_release_pin_group(&mmc_pins, "mmc");
  140. }
  141. static void stmp3xxxmmc_cmd_pullup_ssp1(int enable)
  142. {
  143. stmp3xxx_pin_pullup(PINID_SSP1_CMD, enable, "mmc");
  144. }
  145. static unsigned long
  146. stmp3xxxmmc_setclock_ssp1(void __iomem *base, unsigned long hz)
  147. {
  148. struct clk *ssp, *parent;
  149. char *p;
  150. long r;
  151. ssp = clk_get(NULL, "ssp");
  152. /* using SSP1, no timeout, clock rate 1 */
  153. writel(BF(2, SSP_TIMING_CLOCK_DIVIDE) |
  154. BF(0xFFFF, SSP_TIMING_TIMEOUT),
  155. base + HW_SSP_TIMING);
  156. p = (hz > 1000000) ? "io" : "osc_24M";
  157. parent = clk_get(NULL, p);
  158. clk_set_parent(ssp, parent);
  159. r = clk_set_rate(ssp, 2 * hz / 1000);
  160. clk_put(parent);
  161. clk_put(ssp);
  162. return hz;
  163. }
  164. static struct stmp3xxxmmc_platform_data mmc_data = {
  165. .hw_init = stmp3xxxmmc_hw_init_ssp1,
  166. .hw_release = stmp3xxxmmc_hw_release_ssp1,
  167. .get_wp = stmp3xxxmmc_get_wp,
  168. .cmd_pullup = stmp3xxxmmc_cmd_pullup_ssp1,
  169. .setclock = stmp3xxxmmc_setclock_ssp1,
  170. };
  171. static struct pin_group appuart_pins[] = {
  172. [0] = {
  173. .pins = appuart_pins_0,
  174. .nr_pins = ARRAY_SIZE(appuart_pins_0),
  175. },
  176. [1] = {
  177. .pins = appuart_pins_1,
  178. .nr_pins = ARRAY_SIZE(appuart_pins_1),
  179. },
  180. };
  181. static struct pin_desc ssp1_pins_desc[] = {
  182. { PINID_SSP1_SCK, PIN_FUN1, PIN_8MA, PIN_3_3V, 0, },
  183. { PINID_SSP1_CMD, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
  184. { PINID_SSP1_DATA0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
  185. { PINID_SSP1_DATA3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0, },
  186. };
  187. static struct pin_desc ssp2_pins_desc[] = {
  188. { PINID_GPMI_WRN, PIN_FUN3, PIN_8MA, PIN_3_3V, 0, },
  189. { PINID_GPMI_RDY1, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
  190. { PINID_GPMI_D00, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
  191. { PINID_GPMI_D03, PIN_FUN3, PIN_4MA, PIN_3_3V, 0, },
  192. };
  193. static struct pin_group ssp1_pins = {
  194. .pins = ssp1_pins_desc,
  195. .nr_pins = ARRAY_SIZE(ssp1_pins_desc),
  196. };
  197. static struct pin_group ssp2_pins = {
  198. .pins = ssp1_pins_desc,
  199. .nr_pins = ARRAY_SIZE(ssp2_pins_desc),
  200. };
  201. static struct pin_desc gpmi_pins_desc[] = {
  202. { PINID_GPMI_CE0N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  203. { PINID_GPMI_CE1N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  204. { PINID_GMPI_CE2N, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  205. { PINID_GPMI_CLE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  206. { PINID_GPMI_ALE, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  207. { PINID_GPMI_WPN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
  208. { PINID_GPMI_RDY1, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  209. { PINID_GPMI_D00, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  210. { PINID_GPMI_D01, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  211. { PINID_GPMI_D02, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  212. { PINID_GPMI_D03, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  213. { PINID_GPMI_D04, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  214. { PINID_GPMI_D05, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  215. { PINID_GPMI_D06, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  216. { PINID_GPMI_D07, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  217. { PINID_GPMI_RDY0, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  218. { PINID_GPMI_RDY2, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  219. { PINID_GPMI_RDY3, PIN_FUN1, PIN_4MA, PIN_3_3V, 0 },
  220. { PINID_GPMI_WRN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
  221. { PINID_GPMI_RDN, PIN_FUN1, PIN_12MA, PIN_3_3V, 0 },
  222. };
  223. static struct pin_group gpmi_pins = {
  224. .pins = gpmi_pins_desc,
  225. .nr_pins = ARRAY_SIZE(gpmi_pins_desc),
  226. };
  227. static struct mtd_partition gpmi_partitions[] = {
  228. [0] = {
  229. .name = "boot",
  230. .size = 10 * SZ_1M,
  231. .offset = 0,
  232. },
  233. [1] = {
  234. .name = "data",
  235. .size = MTDPART_SIZ_FULL,
  236. .offset = MTDPART_OFS_APPEND,
  237. },
  238. };
  239. static struct gpmi_platform_data gpmi_data = {
  240. .pins = &gpmi_pins,
  241. .nr_parts = ARRAY_SIZE(gpmi_partitions),
  242. .parts = gpmi_partitions,
  243. .part_types = { "cmdline", NULL },
  244. };
  245. static struct spi_board_info spi_board_info[] __initdata = {
  246. #if defined(CONFIG_ENC28J60) || defined(CONFIG_ENC28J60_MODULE)
  247. {
  248. .modalias = "enc28j60",
  249. .max_speed_hz = 6 * 1000 * 1000,
  250. .bus_num = 1,
  251. .chip_select = 0,
  252. .platform_data = NULL,
  253. },
  254. #endif
  255. };
  256. static void __init stmp378x_devb_init(void)
  257. {
  258. stmp3xxx_pinmux_init(NR_REAL_IRQS);
  259. /* init stmp3xxx platform */
  260. stmp3xxx_init();
  261. stmp3xxx_dbguart.dev.platform_data = dbguart_pins_control;
  262. stmp3xxx_appuart.dev.platform_data = appuart_pins;
  263. stmp3xxx_mmc.dev.platform_data = &mmc_data;
  264. stmp3xxx_gpmi.dev.platform_data = &gpmi_data;
  265. stmp3xxx_spi1.dev.platform_data = &ssp1_pins;
  266. stmp3xxx_spi2.dev.platform_data = &ssp2_pins;
  267. stmp378x_i2c.dev.platform_data = &i2c_pins;
  268. /* register spi devices */
  269. spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
  270. /* add board's devices */
  271. platform_add_devices(devices, ARRAY_SIZE(devices));
  272. /* add devices selected by command line ssp1= and ssp2= options */
  273. stmp3xxx_ssp1_device_register();
  274. stmp3xxx_ssp2_device_register();
  275. }
  276. MACHINE_START(STMP378X, "STMP378X")
  277. .phys_io = 0x80000000,
  278. .io_pg_offst = ((0xf0000000) >> 18) & 0xfffc,
  279. .boot_params = 0x40000100,
  280. .map_io = stmp378x_map_io,
  281. .init_irq = stmp378x_init_irq,
  282. .timer = &stmp3xxx_timer,
  283. .init_machine = stmp378x_devb_init,
  284. MACHINE_END