board-h4.c 12 KB

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