board-h4.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * linux/arch/arm/mach-omap2/board-h4.c
  3. *
  4. * Copyright (C) 2005 Nokia Corporation
  5. * Author: Paul Mundt <paul.mundt@nokia.com>
  6. *
  7. * Modified from mach-omap/omap1/board-generic.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/delay.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/input.h>
  21. #include <linux/err.h>
  22. #include <linux/clk.h>
  23. #include <linux/io.h>
  24. #include <mach/hardware.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include <asm/mach/flash.h>
  29. #include <mach/control.h>
  30. #include <mach/gpio.h>
  31. #include <mach/gpioexpander.h>
  32. #include <mach/mux.h>
  33. #include <mach/usb.h>
  34. #include <mach/irda.h>
  35. #include <mach/board.h>
  36. #include <mach/common.h>
  37. #include <mach/keypad.h>
  38. #include <mach/menelaus.h>
  39. #include <mach/dma.h>
  40. #include <mach/gpmc.h>
  41. #define H4_FLASH_CS 0
  42. #define H4_SMC91X_CS 1
  43. static unsigned int row_gpios[6] = { 88, 89, 124, 11, 6, 96 };
  44. static unsigned int col_gpios[7] = { 90, 91, 100, 36, 12, 97, 98 };
  45. static int h4_keymap[] = {
  46. KEY(0, 0, KEY_LEFT),
  47. KEY(0, 1, KEY_RIGHT),
  48. KEY(0, 2, KEY_A),
  49. KEY(0, 3, KEY_B),
  50. KEY(0, 4, KEY_C),
  51. KEY(1, 0, KEY_DOWN),
  52. KEY(1, 1, KEY_UP),
  53. KEY(1, 2, KEY_E),
  54. KEY(1, 3, KEY_F),
  55. KEY(1, 4, KEY_G),
  56. KEY(2, 0, KEY_ENTER),
  57. KEY(2, 1, KEY_I),
  58. KEY(2, 2, KEY_J),
  59. KEY(2, 3, KEY_K),
  60. KEY(2, 4, KEY_3),
  61. KEY(3, 0, KEY_M),
  62. KEY(3, 1, KEY_N),
  63. KEY(3, 2, KEY_O),
  64. KEY(3, 3, KEY_P),
  65. KEY(3, 4, KEY_Q),
  66. KEY(4, 0, KEY_R),
  67. KEY(4, 1, KEY_4),
  68. KEY(4, 2, KEY_T),
  69. KEY(4, 3, KEY_U),
  70. KEY(4, 4, KEY_ENTER),
  71. KEY(5, 0, KEY_V),
  72. KEY(5, 1, KEY_W),
  73. KEY(5, 2, KEY_L),
  74. KEY(5, 3, KEY_S),
  75. KEY(5, 4, KEY_ENTER),
  76. 0
  77. };
  78. static struct mtd_partition h4_partitions[] = {
  79. /* bootloader (U-Boot, etc) in first sector */
  80. {
  81. .name = "bootloader",
  82. .offset = 0,
  83. .size = SZ_128K,
  84. .mask_flags = MTD_WRITEABLE, /* force read-only */
  85. },
  86. /* bootloader params in the next sector */
  87. {
  88. .name = "params",
  89. .offset = MTDPART_OFS_APPEND,
  90. .size = SZ_128K,
  91. .mask_flags = 0,
  92. },
  93. /* kernel */
  94. {
  95. .name = "kernel",
  96. .offset = MTDPART_OFS_APPEND,
  97. .size = SZ_2M,
  98. .mask_flags = 0
  99. },
  100. /* file system */
  101. {
  102. .name = "filesystem",
  103. .offset = MTDPART_OFS_APPEND,
  104. .size = MTDPART_SIZ_FULL,
  105. .mask_flags = 0
  106. }
  107. };
  108. static struct flash_platform_data h4_flash_data = {
  109. .map_name = "cfi_probe",
  110. .width = 2,
  111. .parts = h4_partitions,
  112. .nr_parts = ARRAY_SIZE(h4_partitions),
  113. };
  114. static struct resource h4_flash_resource = {
  115. .flags = IORESOURCE_MEM,
  116. };
  117. static struct platform_device h4_flash_device = {
  118. .name = "omapflash",
  119. .id = 0,
  120. .dev = {
  121. .platform_data = &h4_flash_data,
  122. },
  123. .num_resources = 1,
  124. .resource = &h4_flash_resource,
  125. };
  126. /* Select between the IrDA and aGPS module
  127. */
  128. static int h4_select_irda(struct device *dev, int state)
  129. {
  130. unsigned char expa;
  131. int err = 0;
  132. if ((err = read_gpio_expa(&expa, 0x21))) {
  133. printk(KERN_ERR "Error reading from I/O expander\n");
  134. return err;
  135. }
  136. /* 'P6' enable/disable IRDA_TX and IRDA_RX */
  137. if (state & IR_SEL) { /* IrDa */
  138. if ((err = write_gpio_expa(expa | 0x01, 0x21))) {
  139. printk(KERN_ERR "Error writing to I/O expander\n");
  140. return err;
  141. }
  142. } else {
  143. if ((err = write_gpio_expa(expa & ~0x01, 0x21))) {
  144. printk(KERN_ERR "Error writing to I/O expander\n");
  145. return err;
  146. }
  147. }
  148. return err;
  149. }
  150. static void set_trans_mode(struct work_struct *work)
  151. {
  152. struct omap_irda_config *irda_config =
  153. container_of(work, struct omap_irda_config, gpio_expa.work);
  154. int mode = irda_config->mode;
  155. unsigned char expa;
  156. int err = 0;
  157. if ((err = read_gpio_expa(&expa, 0x20)) != 0) {
  158. printk(KERN_ERR "Error reading from I/O expander\n");
  159. }
  160. expa &= ~0x01;
  161. if (!(mode & IR_SIRMODE)) { /* MIR/FIR */
  162. expa |= 0x01;
  163. }
  164. if ((err = write_gpio_expa(expa, 0x20)) != 0) {
  165. printk(KERN_ERR "Error writing to I/O expander\n");
  166. }
  167. }
  168. static int h4_transceiver_mode(struct device *dev, int mode)
  169. {
  170. struct omap_irda_config *irda_config = dev->platform_data;
  171. irda_config->mode = mode;
  172. cancel_delayed_work(&irda_config->gpio_expa);
  173. PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode);
  174. schedule_delayed_work(&irda_config->gpio_expa, 0);
  175. return 0;
  176. }
  177. static struct omap_irda_config h4_irda_data = {
  178. .transceiver_cap = IR_SIRMODE | IR_MIRMODE | IR_FIRMODE,
  179. .transceiver_mode = h4_transceiver_mode,
  180. .select_irda = h4_select_irda,
  181. .rx_channel = OMAP24XX_DMA_UART3_RX,
  182. .tx_channel = OMAP24XX_DMA_UART3_TX,
  183. .dest_start = OMAP_UART3_BASE,
  184. .src_start = OMAP_UART3_BASE,
  185. .tx_trigger = OMAP24XX_DMA_UART3_TX,
  186. .rx_trigger = OMAP24XX_DMA_UART3_RX,
  187. };
  188. static struct resource h4_irda_resources[] = {
  189. [0] = {
  190. .start = INT_24XX_UART3_IRQ,
  191. .end = INT_24XX_UART3_IRQ,
  192. .flags = IORESOURCE_IRQ,
  193. },
  194. };
  195. static struct platform_device h4_irda_device = {
  196. .name = "omapirda",
  197. .id = -1,
  198. .dev = {
  199. .platform_data = &h4_irda_data,
  200. },
  201. .num_resources = 1,
  202. .resource = h4_irda_resources,
  203. };
  204. static struct omap_kp_platform_data h4_kp_data = {
  205. .rows = 6,
  206. .cols = 7,
  207. .keymap = h4_keymap,
  208. .keymapsize = ARRAY_SIZE(h4_keymap),
  209. .rep = 1,
  210. .row_gpios = row_gpios,
  211. .col_gpios = col_gpios,
  212. };
  213. static struct platform_device h4_kp_device = {
  214. .name = "omap-keypad",
  215. .id = -1,
  216. .dev = {
  217. .platform_data = &h4_kp_data,
  218. },
  219. };
  220. static struct platform_device h4_lcd_device = {
  221. .name = "lcd_h4",
  222. .id = -1,
  223. };
  224. static struct platform_device *h4_devices[] __initdata = {
  225. &h4_flash_device,
  226. &h4_irda_device,
  227. &h4_kp_device,
  228. &h4_lcd_device,
  229. };
  230. /* 2420 Sysboot setup (2430 is different) */
  231. static u32 get_sysboot_value(void)
  232. {
  233. return (omap_ctrl_readl(OMAP24XX_CONTROL_STATUS) &
  234. (OMAP2_SYSBOOT_5_MASK | OMAP2_SYSBOOT_4_MASK |
  235. OMAP2_SYSBOOT_3_MASK | OMAP2_SYSBOOT_2_MASK |
  236. OMAP2_SYSBOOT_1_MASK | OMAP2_SYSBOOT_0_MASK));
  237. }
  238. /* H4-2420's always used muxed mode, H4-2422's always use non-muxed
  239. *
  240. * Note: OMAP-GIT doesn't correctly do is_cpu_omap2422 and is_cpu_omap2423
  241. * correctly. The macro needs to look at production_id not just hawkeye.
  242. */
  243. static u32 is_gpmc_muxed(void)
  244. {
  245. u32 mux;
  246. mux = get_sysboot_value();
  247. if ((mux & 0xF) == 0xd)
  248. return 1; /* NAND config (could be either) */
  249. if (mux & 0x2) /* if mux'ed */
  250. return 1;
  251. else
  252. return 0;
  253. }
  254. static inline void __init h4_init_debug(void)
  255. {
  256. int eth_cs;
  257. unsigned long cs_mem_base;
  258. unsigned int muxed, rate;
  259. struct clk *gpmc_fck;
  260. eth_cs = H4_SMC91X_CS;
  261. gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
  262. if (IS_ERR(gpmc_fck)) {
  263. WARN_ON(1);
  264. return;
  265. }
  266. clk_enable(gpmc_fck);
  267. rate = clk_get_rate(gpmc_fck);
  268. clk_disable(gpmc_fck);
  269. clk_put(gpmc_fck);
  270. if (is_gpmc_muxed())
  271. muxed = 0x200;
  272. else
  273. muxed = 0;
  274. /* Make sure CS1 timings are correct */
  275. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1,
  276. 0x00011000 | muxed);
  277. if (rate >= 160000000) {
  278. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
  279. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
  280. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
  281. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
  282. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
  283. } else if (rate >= 130000000) {
  284. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
  285. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
  286. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
  287. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
  288. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
  289. } else {/* rate = 100000000 */
  290. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
  291. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
  292. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
  293. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
  294. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
  295. }
  296. if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
  297. printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
  298. goto out;
  299. }
  300. udelay(100);
  301. omap_cfg_reg(M15_24XX_GPIO92);
  302. if (debug_card_init(cs_mem_base, OMAP24XX_ETHR_GPIO_IRQ) < 0)
  303. gpmc_cs_free(eth_cs);
  304. out:
  305. clk_disable(gpmc_fck);
  306. clk_put(gpmc_fck);
  307. }
  308. static void __init h4_init_flash(void)
  309. {
  310. unsigned long base;
  311. if (gpmc_cs_request(H4_FLASH_CS, SZ_64M, &base) < 0) {
  312. printk("Can't request GPMC CS for flash\n");
  313. return;
  314. }
  315. h4_flash_resource.start = base;
  316. h4_flash_resource.end = base + SZ_64M - 1;
  317. }
  318. static void __init omap_h4_init_irq(void)
  319. {
  320. omap2_init_common_hw();
  321. omap_init_irq();
  322. omap_gpio_init();
  323. h4_init_flash();
  324. }
  325. static struct omap_uart_config h4_uart_config __initdata = {
  326. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  327. };
  328. static struct omap_mmc_config h4_mmc_config __initdata = {
  329. .mmc [0] = {
  330. .enabled = 1,
  331. .wire4 = 1,
  332. .wp_pin = -1,
  333. .power_pin = -1,
  334. .switch_pin = -1,
  335. },
  336. };
  337. static struct omap_lcd_config h4_lcd_config __initdata = {
  338. .ctrl_name = "internal",
  339. };
  340. static struct omap_board_config_kernel h4_config[] = {
  341. { OMAP_TAG_UART, &h4_uart_config },
  342. { OMAP_TAG_MMC, &h4_mmc_config },
  343. { OMAP_TAG_LCD, &h4_lcd_config },
  344. };
  345. static void __init omap_h4_init(void)
  346. {
  347. /*
  348. * Make sure the serial ports are muxed on at this point.
  349. * You have to mux them off in device drivers later on
  350. * if not needed.
  351. */
  352. #if defined(CONFIG_OMAP_IR) || defined(CONFIG_OMAP_IR_MODULE)
  353. omap_cfg_reg(K15_24XX_UART3_TX);
  354. omap_cfg_reg(K14_24XX_UART3_RX);
  355. #endif
  356. #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
  357. if (omap_has_menelaus()) {
  358. row_gpios[5] = 0;
  359. col_gpios[2] = 15;
  360. col_gpios[6] = 18;
  361. }
  362. #endif
  363. platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices));
  364. omap_board_config = h4_config;
  365. omap_board_config_size = ARRAY_SIZE(h4_config);
  366. omap_serial_init();
  367. }
  368. static void __init omap_h4_map_io(void)
  369. {
  370. omap2_set_globals_242x();
  371. omap2_map_common_io();
  372. }
  373. MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
  374. /* Maintainer: Paul Mundt <paul.mundt@nokia.com> */
  375. .phys_io = 0x48000000,
  376. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  377. .boot_params = 0x80000100,
  378. .map_io = omap_h4_map_io,
  379. .init_irq = omap_h4_init_irq,
  380. .init_machine = omap_h4_init,
  381. .timer = &omap_timer,
  382. MACHINE_END