board-rx51-peripherals.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. * linux/arch/arm/mach-omap2/board-rx51-flash.c
  3. *
  4. * Copyright (C) 2008-2009 Nokia
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/input.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/i2c.h>
  16. #include <linux/i2c/twl4030.h>
  17. #include <linux/clk.h>
  18. #include <linux/delay.h>
  19. #include <linux/regulator/machine.h>
  20. #include <linux/gpio.h>
  21. #include <mach/mcspi.h>
  22. #include <mach/mux.h>
  23. #include <mach/board.h>
  24. #include <mach/common.h>
  25. #include <mach/dma.h>
  26. #include <mach/gpmc.h>
  27. #include <mach/keypad.h>
  28. #include "mmc-twl4030.h"
  29. #define SMC91X_CS 1
  30. #define SMC91X_GPIO_IRQ 54
  31. #define SMC91X_GPIO_RESET 164
  32. #define SMC91X_GPIO_PWRDWN 86
  33. static struct resource rx51_smc91x_resources[] = {
  34. [0] = {
  35. .flags = IORESOURCE_MEM,
  36. },
  37. [1] = {
  38. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  39. },
  40. };
  41. static struct platform_device rx51_smc91x_device = {
  42. .name = "smc91x",
  43. .id = -1,
  44. .num_resources = ARRAY_SIZE(rx51_smc91x_resources),
  45. .resource = rx51_smc91x_resources,
  46. };
  47. static int rx51_keymap[] = {
  48. KEY(0, 0, KEY_Q),
  49. KEY(0, 1, KEY_W),
  50. KEY(0, 2, KEY_E),
  51. KEY(0, 3, KEY_R),
  52. KEY(0, 4, KEY_T),
  53. KEY(0, 5, KEY_Y),
  54. KEY(0, 6, KEY_U),
  55. KEY(0, 7, KEY_I),
  56. KEY(1, 0, KEY_O),
  57. KEY(1, 1, KEY_D),
  58. KEY(1, 2, KEY_DOT),
  59. KEY(1, 3, KEY_V),
  60. KEY(1, 4, KEY_DOWN),
  61. KEY(2, 0, KEY_P),
  62. KEY(2, 1, KEY_F),
  63. KEY(2, 2, KEY_UP),
  64. KEY(2, 3, KEY_B),
  65. KEY(2, 4, KEY_RIGHT),
  66. KEY(3, 0, KEY_COMMA),
  67. KEY(3, 1, KEY_G),
  68. KEY(3, 2, KEY_ENTER),
  69. KEY(3, 3, KEY_N),
  70. KEY(4, 0, KEY_BACKSPACE),
  71. KEY(4, 1, KEY_H),
  72. KEY(4, 3, KEY_M),
  73. KEY(4, 4, KEY_LEFTCTRL),
  74. KEY(5, 1, KEY_J),
  75. KEY(5, 2, KEY_Z),
  76. KEY(5, 3, KEY_SPACE),
  77. KEY(5, 4, KEY_LEFTSHIFT),
  78. KEY(6, 0, KEY_A),
  79. KEY(6, 1, KEY_K),
  80. KEY(6, 2, KEY_X),
  81. KEY(6, 3, KEY_SPACE),
  82. KEY(6, 4, KEY_FN),
  83. KEY(7, 0, KEY_S),
  84. KEY(7, 1, KEY_L),
  85. KEY(7, 2, KEY_C),
  86. KEY(7, 3, KEY_LEFT),
  87. KEY(0xff, 0, KEY_F6),
  88. KEY(0xff, 1, KEY_F7),
  89. KEY(0xff, 2, KEY_F8),
  90. KEY(0xff, 4, KEY_F9),
  91. KEY(0xff, 5, KEY_F10),
  92. };
  93. static struct twl4030_keypad_data rx51_kp_data = {
  94. .rows = 8,
  95. .cols = 8,
  96. .keymap = rx51_keymap,
  97. .keymapsize = ARRAY_SIZE(rx51_keymap),
  98. .rep = 1,
  99. };
  100. static struct platform_device *rx51_peripherals_devices[] = {
  101. &rx51_smc91x_device,
  102. };
  103. /*
  104. * Timings are taken from smsc-lan91c96-ms.pdf
  105. */
  106. static int smc91x_init_gpmc(int cs)
  107. {
  108. struct gpmc_timings t;
  109. const int t2_r = 45; /* t2 in Figure 12.10 */
  110. const int t2_w = 30; /* t2 in Figure 12.11 */
  111. const int t3 = 15; /* t3 in Figure 12.10 */
  112. const int t5_r = 0; /* t5 in Figure 12.10 */
  113. const int t6_r = 45; /* t6 in Figure 12.10 */
  114. const int t6_w = 0; /* t6 in Figure 12.11 */
  115. const int t7_w = 15; /* t7 in Figure 12.11 */
  116. const int t15 = 12; /* t15 in Figure 12.2 */
  117. const int t20 = 185; /* t20 in Figure 12.2 */
  118. memset(&t, 0, sizeof(t));
  119. t.cs_on = t15;
  120. t.cs_rd_off = t3 + t2_r + t5_r; /* Figure 12.10 */
  121. t.cs_wr_off = t3 + t2_w + t6_w; /* Figure 12.11 */
  122. t.adv_on = t3; /* Figure 12.10 */
  123. t.adv_rd_off = t3 + t2_r; /* Figure 12.10 */
  124. t.adv_wr_off = t3 + t2_w; /* Figure 12.11 */
  125. t.oe_off = t3 + t2_r + t5_r; /* Figure 12.10 */
  126. t.oe_on = t.oe_off - t6_r; /* Figure 12.10 */
  127. t.we_off = t3 + t2_w + t6_w; /* Figure 12.11 */
  128. t.we_on = t.we_off - t7_w; /* Figure 12.11 */
  129. t.rd_cycle = t20; /* Figure 12.2 */
  130. t.wr_cycle = t20; /* Figure 12.4 */
  131. t.access = t3 + t2_r + t5_r; /* Figure 12.10 */
  132. t.wr_access = t3 + t2_w + t6_w; /* Figure 12.11 */
  133. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, GPMC_CONFIG1_DEVICESIZE_16);
  134. return gpmc_cs_set_timings(cs, &t);
  135. }
  136. static void __init rx51_init_smc91x(void)
  137. {
  138. unsigned long cs_mem_base;
  139. int ret;
  140. omap_cfg_reg(U8_34XX_GPIO54_DOWN);
  141. omap_cfg_reg(G25_34XX_GPIO86_OUT);
  142. omap_cfg_reg(H19_34XX_GPIO164_OUT);
  143. if (gpmc_cs_request(SMC91X_CS, SZ_16M, &cs_mem_base) < 0) {
  144. printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
  145. return;
  146. }
  147. rx51_smc91x_resources[0].start = cs_mem_base + 0x300;
  148. rx51_smc91x_resources[0].end = cs_mem_base + 0x30f;
  149. smc91x_init_gpmc(SMC91X_CS);
  150. if (gpio_request(SMC91X_GPIO_IRQ, "SMC91X irq") < 0)
  151. goto free1;
  152. gpio_direction_input(SMC91X_GPIO_IRQ);
  153. rx51_smc91x_resources[1].start = gpio_to_irq(SMC91X_GPIO_IRQ);
  154. ret = gpio_request(SMC91X_GPIO_PWRDWN, "SMC91X powerdown");
  155. if (ret)
  156. goto free2;
  157. gpio_direction_output(SMC91X_GPIO_PWRDWN, 0);
  158. ret = gpio_request(SMC91X_GPIO_RESET, "SMC91X reset");
  159. if (ret)
  160. goto free3;
  161. gpio_direction_output(SMC91X_GPIO_RESET, 0);
  162. gpio_set_value(SMC91X_GPIO_RESET, 1);
  163. msleep(100);
  164. gpio_set_value(SMC91X_GPIO_RESET, 0);
  165. return;
  166. free3:
  167. gpio_free(SMC91X_GPIO_PWRDWN);
  168. free2:
  169. gpio_free(SMC91X_GPIO_IRQ);
  170. free1:
  171. gpmc_cs_free(SMC91X_CS);
  172. printk(KERN_ERR "Could not initialize smc91x\n");
  173. }
  174. static struct twl4030_madc_platform_data rx51_madc_data = {
  175. .irq_line = 1,
  176. };
  177. static struct twl4030_hsmmc_info mmc[] = {
  178. {
  179. .name = "external",
  180. .mmc = 1,
  181. .wires = 4,
  182. .cover_only = true,
  183. .gpio_cd = 160,
  184. .gpio_wp = -EINVAL,
  185. },
  186. {
  187. .name = "internal",
  188. .mmc = 2,
  189. .wires = 8,
  190. .gpio_cd = -EINVAL,
  191. .gpio_wp = -EINVAL,
  192. },
  193. {} /* Terminator */
  194. };
  195. static struct regulator_consumer_supply rx51_vmmc1_supply = {
  196. .supply = "vmmc",
  197. };
  198. static struct regulator_consumer_supply rx51_vmmc2_supply = {
  199. .supply = "vmmc",
  200. };
  201. static struct regulator_consumer_supply rx51_vsim_supply = {
  202. .supply = "vmmc_aux",
  203. };
  204. static struct regulator_init_data rx51_vaux1 = {
  205. .constraints = {
  206. .name = "V28",
  207. .min_uV = 2800000,
  208. .max_uV = 2800000,
  209. .valid_modes_mask = REGULATOR_MODE_NORMAL
  210. | REGULATOR_MODE_STANDBY,
  211. .valid_ops_mask = REGULATOR_CHANGE_MODE
  212. | REGULATOR_CHANGE_STATUS,
  213. },
  214. };
  215. static struct regulator_init_data rx51_vaux2 = {
  216. .constraints = {
  217. .name = "VCSI",
  218. .min_uV = 1800000,
  219. .max_uV = 1800000,
  220. .valid_modes_mask = REGULATOR_MODE_NORMAL
  221. | REGULATOR_MODE_STANDBY,
  222. .valid_ops_mask = REGULATOR_CHANGE_MODE
  223. | REGULATOR_CHANGE_STATUS,
  224. },
  225. };
  226. /* VAUX3 - adds more power to VIO_18 rail */
  227. static struct regulator_init_data rx51_vaux3 = {
  228. .constraints = {
  229. .name = "VCAM_DIG_18",
  230. .min_uV = 1800000,
  231. .max_uV = 1800000,
  232. .apply_uV = true,
  233. .valid_modes_mask = REGULATOR_MODE_NORMAL
  234. | REGULATOR_MODE_STANDBY,
  235. .valid_ops_mask = REGULATOR_CHANGE_MODE
  236. | REGULATOR_CHANGE_STATUS,
  237. },
  238. };
  239. static struct regulator_init_data rx51_vaux4 = {
  240. .constraints = {
  241. .name = "VCAM_ANA_28",
  242. .min_uV = 2800000,
  243. .max_uV = 2800000,
  244. .apply_uV = true,
  245. .valid_modes_mask = REGULATOR_MODE_NORMAL
  246. | REGULATOR_MODE_STANDBY,
  247. .valid_ops_mask = REGULATOR_CHANGE_MODE
  248. | REGULATOR_CHANGE_STATUS,
  249. },
  250. };
  251. static struct regulator_init_data rx51_vmmc1 = {
  252. .constraints = {
  253. .min_uV = 1850000,
  254. .max_uV = 3150000,
  255. .valid_modes_mask = REGULATOR_MODE_NORMAL
  256. | REGULATOR_MODE_STANDBY,
  257. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  258. | REGULATOR_CHANGE_MODE
  259. | REGULATOR_CHANGE_STATUS,
  260. },
  261. .num_consumer_supplies = 1,
  262. .consumer_supplies = &rx51_vmmc1_supply,
  263. };
  264. static struct regulator_init_data rx51_vmmc2 = {
  265. .constraints = {
  266. .name = "VMMC2_30",
  267. .min_uV = 1850000,
  268. .max_uV = 3150000,
  269. .apply_uV = true,
  270. .valid_modes_mask = REGULATOR_MODE_NORMAL
  271. | REGULATOR_MODE_STANDBY,
  272. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  273. | REGULATOR_CHANGE_MODE
  274. | REGULATOR_CHANGE_STATUS,
  275. },
  276. .num_consumer_supplies = 1,
  277. .consumer_supplies = &rx51_vmmc2_supply,
  278. };
  279. static struct regulator_init_data rx51_vsim = {
  280. .constraints = {
  281. .name = "VMMC2_IO_18",
  282. .min_uV = 1800000,
  283. .max_uV = 1800000,
  284. .apply_uV = true,
  285. .valid_modes_mask = REGULATOR_MODE_NORMAL
  286. | REGULATOR_MODE_STANDBY,
  287. .valid_ops_mask = REGULATOR_CHANGE_MODE
  288. | REGULATOR_CHANGE_STATUS,
  289. },
  290. .num_consumer_supplies = 1,
  291. .consumer_supplies = &rx51_vsim_supply,
  292. };
  293. static struct regulator_init_data rx51_vdac = {
  294. .constraints = {
  295. .min_uV = 1800000,
  296. .max_uV = 1800000,
  297. .valid_modes_mask = REGULATOR_MODE_NORMAL
  298. | REGULATOR_MODE_STANDBY,
  299. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  300. | REGULATOR_CHANGE_MODE
  301. | REGULATOR_CHANGE_STATUS,
  302. },
  303. };
  304. static int rx51_twlgpio_setup(struct device *dev, unsigned gpio, unsigned n)
  305. {
  306. /* FIXME this gpio setup is just a placeholder for now */
  307. gpio_request(gpio + 6, "backlight_pwm");
  308. gpio_direction_output(gpio + 6, 0);
  309. gpio_request(gpio + 7, "speaker_en");
  310. gpio_direction_output(gpio + 7, 1);
  311. /* set up MMC adapters, linking their regulators to them */
  312. twl4030_mmc_init(mmc);
  313. rx51_vmmc1_supply.dev = mmc[0].dev;
  314. rx51_vmmc2_supply.dev = mmc[1].dev;
  315. rx51_vsim_supply.dev = mmc[1].dev;
  316. return 0;
  317. }
  318. static struct twl4030_gpio_platform_data rx51_gpio_data = {
  319. .gpio_base = OMAP_MAX_GPIO_LINES,
  320. .irq_base = TWL4030_GPIO_IRQ_BASE,
  321. .irq_end = TWL4030_GPIO_IRQ_END,
  322. .pulldowns = BIT(0) | BIT(1) | BIT(2) | BIT(3)
  323. | BIT(4) | BIT(5)
  324. | BIT(8) | BIT(9) | BIT(10) | BIT(11)
  325. | BIT(12) | BIT(13) | BIT(14) | BIT(15)
  326. | BIT(16) | BIT(17) ,
  327. .setup = rx51_twlgpio_setup,
  328. };
  329. static struct twl4030_platform_data rx51_twldata = {
  330. .irq_base = TWL4030_IRQ_BASE,
  331. .irq_end = TWL4030_IRQ_END,
  332. /* platform_data for children goes here */
  333. .gpio = &rx51_gpio_data,
  334. .keypad = &rx51_kp_data,
  335. .madc = &rx51_madc_data,
  336. .vaux1 = &rx51_vaux1,
  337. .vaux2 = &rx51_vaux2,
  338. .vaux3 = &rx51_vaux3,
  339. .vaux4 = &rx51_vaux4,
  340. .vmmc1 = &rx51_vmmc1,
  341. .vmmc2 = &rx51_vmmc2,
  342. .vsim = &rx51_vsim,
  343. .vdac = &rx51_vdac,
  344. };
  345. static struct i2c_board_info __initdata rx51_peripherals_i2c_board_info_1[] = {
  346. {
  347. I2C_BOARD_INFO("twl5030", 0x48),
  348. .flags = I2C_CLIENT_WAKE,
  349. .irq = INT_34XX_SYS_NIRQ,
  350. .platform_data = &rx51_twldata,
  351. },
  352. };
  353. static int __init rx51_i2c_init(void)
  354. {
  355. omap_register_i2c_bus(1, 2600, rx51_peripherals_i2c_board_info_1,
  356. ARRAY_SIZE(rx51_peripherals_i2c_board_info_1));
  357. omap_register_i2c_bus(2, 100, NULL, 0);
  358. omap_register_i2c_bus(3, 400, NULL, 0);
  359. return 0;
  360. }
  361. void __init rx51_peripherals_init(void)
  362. {
  363. platform_add_devices(rx51_peripherals_devices,
  364. ARRAY_SIZE(rx51_peripherals_devices));
  365. rx51_i2c_init();
  366. rx51_init_smc91x();
  367. }