board-apollon.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * linux/arch/arm/mach-omap2/board-apollon.c
  3. *
  4. * Copyright (C) 2005,2006 Samsung Electronics
  5. * Author: Kyungmin Park <kyungmin.park@samsung.com>
  6. *
  7. * Modified from mach-omap/omap2/board-h4.c
  8. *
  9. * Code for apollon OMAP2 board. Should work on many OMAP2 systems where
  10. * the bootloader passes the board-specific data to the kernel.
  11. * Do not put any board specific code to this file; create a new machine
  12. * type if you need custom low-level initializations.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/partitions.h>
  23. #include <linux/mtd/onenand.h>
  24. #include <linux/irq.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/leds.h>
  28. #include <linux/err.h>
  29. #include <linux/clk.h>
  30. #include <mach/hardware.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/flash.h>
  34. #include <mach/gpio.h>
  35. #include <mach/led.h>
  36. #include <mach/mux.h>
  37. #include <mach/usb.h>
  38. #include <mach/board.h>
  39. #include <mach/common.h>
  40. #include <mach/gpmc.h>
  41. #include <mach/control.h>
  42. /* LED & Switch macros */
  43. #define LED0_GPIO13 13
  44. #define LED1_GPIO14 14
  45. #define LED2_GPIO15 15
  46. #define SW_ENTER_GPIO16 16
  47. #define SW_UP_GPIO17 17
  48. #define SW_DOWN_GPIO58 58
  49. #define APOLLON_FLASH_CS 0
  50. #define APOLLON_ETH_CS 1
  51. static struct mtd_partition apollon_partitions[] = {
  52. {
  53. .name = "X-Loader + U-Boot",
  54. .offset = 0,
  55. .size = SZ_128K,
  56. .mask_flags = MTD_WRITEABLE,
  57. },
  58. {
  59. .name = "params",
  60. .offset = MTDPART_OFS_APPEND,
  61. .size = SZ_128K,
  62. },
  63. {
  64. .name = "kernel",
  65. .offset = MTDPART_OFS_APPEND,
  66. .size = SZ_2M,
  67. },
  68. {
  69. .name = "rootfs",
  70. .offset = MTDPART_OFS_APPEND,
  71. .size = SZ_16M,
  72. },
  73. {
  74. .name = "filesystem00",
  75. .offset = MTDPART_OFS_APPEND,
  76. .size = SZ_32M,
  77. },
  78. {
  79. .name = "filesystem01",
  80. .offset = MTDPART_OFS_APPEND,
  81. .size = MTDPART_SIZ_FULL,
  82. },
  83. };
  84. static struct flash_platform_data apollon_flash_data = {
  85. .parts = apollon_partitions,
  86. .nr_parts = ARRAY_SIZE(apollon_partitions),
  87. };
  88. static struct resource apollon_flash_resource[] = {
  89. [0] = {
  90. .flags = IORESOURCE_MEM,
  91. },
  92. };
  93. static struct platform_device apollon_onenand_device = {
  94. .name = "onenand",
  95. .id = -1,
  96. .dev = {
  97. .platform_data = &apollon_flash_data,
  98. },
  99. .num_resources = ARRAY_SIZE(apollon_flash_resource),
  100. .resource = apollon_flash_resource,
  101. };
  102. static void __init apollon_flash_init(void)
  103. {
  104. unsigned long base;
  105. if (gpmc_cs_request(APOLLON_FLASH_CS, SZ_128K, &base) < 0) {
  106. printk(KERN_ERR "Cannot request OneNAND GPMC CS\n");
  107. return;
  108. }
  109. apollon_flash_resource[0].start = base;
  110. apollon_flash_resource[0].end = base + SZ_128K - 1;
  111. }
  112. static struct resource apollon_smc91x_resources[] = {
  113. [0] = {
  114. .flags = IORESOURCE_MEM,
  115. },
  116. [1] = {
  117. .start = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
  118. .end = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
  119. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  120. },
  121. };
  122. static struct platform_device apollon_smc91x_device = {
  123. .name = "smc91x",
  124. .id = -1,
  125. .num_resources = ARRAY_SIZE(apollon_smc91x_resources),
  126. .resource = apollon_smc91x_resources,
  127. };
  128. static struct platform_device apollon_lcd_device = {
  129. .name = "apollon_lcd",
  130. .id = -1,
  131. };
  132. static struct omap_led_config apollon_led_config[] = {
  133. {
  134. .cdev = {
  135. .name = "apollon:led0",
  136. },
  137. .gpio = LED0_GPIO13,
  138. },
  139. {
  140. .cdev = {
  141. .name = "apollon:led1",
  142. },
  143. .gpio = LED1_GPIO14,
  144. },
  145. {
  146. .cdev = {
  147. .name = "apollon:led2",
  148. },
  149. .gpio = LED2_GPIO15,
  150. },
  151. };
  152. static struct omap_led_platform_data apollon_led_data = {
  153. .nr_leds = ARRAY_SIZE(apollon_led_config),
  154. .leds = apollon_led_config,
  155. };
  156. static struct platform_device apollon_led_device = {
  157. .name = "omap-led",
  158. .id = -1,
  159. .dev = {
  160. .platform_data = &apollon_led_data,
  161. },
  162. };
  163. static struct platform_device *apollon_devices[] __initdata = {
  164. &apollon_onenand_device,
  165. &apollon_smc91x_device,
  166. &apollon_lcd_device,
  167. &apollon_led_device,
  168. };
  169. static inline void __init apollon_init_smc91x(void)
  170. {
  171. unsigned long base;
  172. unsigned int rate;
  173. struct clk *gpmc_fck;
  174. int eth_cs;
  175. gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
  176. if (IS_ERR(gpmc_fck)) {
  177. WARN_ON(1);
  178. return;
  179. }
  180. clk_enable(gpmc_fck);
  181. rate = clk_get_rate(gpmc_fck);
  182. eth_cs = APOLLON_ETH_CS;
  183. /* Make sure CS1 timings are correct */
  184. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);
  185. if (rate >= 160000000) {
  186. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
  187. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
  188. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
  189. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
  190. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
  191. } else if (rate >= 130000000) {
  192. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
  193. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
  194. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
  195. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
  196. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
  197. } else {/* rate = 100000000 */
  198. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
  199. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
  200. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
  201. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
  202. gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
  203. }
  204. if (gpmc_cs_request(APOLLON_ETH_CS, SZ_16M, &base) < 0) {
  205. printk(KERN_ERR "Failed to request GPMC CS for smc91x\n");
  206. goto out;
  207. }
  208. apollon_smc91x_resources[0].start = base + 0x300;
  209. apollon_smc91x_resources[0].end = base + 0x30f;
  210. udelay(100);
  211. omap_cfg_reg(W4__24XX_GPIO74);
  212. if (omap_request_gpio(APOLLON_ETHR_GPIO_IRQ) < 0) {
  213. printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
  214. APOLLON_ETHR_GPIO_IRQ);
  215. gpmc_cs_free(APOLLON_ETH_CS);
  216. goto out;
  217. }
  218. omap_set_gpio_direction(APOLLON_ETHR_GPIO_IRQ, 1);
  219. out:
  220. clk_disable(gpmc_fck);
  221. clk_put(gpmc_fck);
  222. }
  223. static void __init omap_apollon_init_irq(void)
  224. {
  225. omap2_init_common_hw();
  226. omap_init_irq();
  227. omap_gpio_init();
  228. apollon_init_smc91x();
  229. }
  230. static struct omap_uart_config apollon_uart_config __initdata = {
  231. .enabled_uarts = (1 << 0) | (0 << 1) | (0 << 2),
  232. };
  233. static struct omap_mmc_config apollon_mmc_config __initdata = {
  234. .mmc [0] = {
  235. .enabled = 1,
  236. .wire4 = 1,
  237. .wp_pin = -1,
  238. .power_pin = -1,
  239. .switch_pin = -1,
  240. },
  241. };
  242. static struct omap_usb_config apollon_usb_config __initdata = {
  243. .register_dev = 1,
  244. .hmc_mode = 0x14, /* 0:dev 1:host1 2:disable */
  245. .pins[0] = 6,
  246. };
  247. static struct omap_lcd_config apollon_lcd_config __initdata = {
  248. .ctrl_name = "internal",
  249. };
  250. static struct omap_board_config_kernel apollon_config[] = {
  251. { OMAP_TAG_UART, &apollon_uart_config },
  252. { OMAP_TAG_MMC, &apollon_mmc_config },
  253. { OMAP_TAG_USB, &apollon_usb_config },
  254. { OMAP_TAG_LCD, &apollon_lcd_config },
  255. };
  256. static void __init apollon_led_init(void)
  257. {
  258. /* LED0 - AA10 */
  259. omap_cfg_reg(AA10_242X_GPIO13);
  260. omap_request_gpio(LED0_GPIO13);
  261. omap_set_gpio_direction(LED0_GPIO13, 0);
  262. omap_set_gpio_dataout(LED0_GPIO13, 0);
  263. /* LED1 - AA6 */
  264. omap_cfg_reg(AA6_242X_GPIO14);
  265. omap_request_gpio(LED1_GPIO14);
  266. omap_set_gpio_direction(LED1_GPIO14, 0);
  267. omap_set_gpio_dataout(LED1_GPIO14, 0);
  268. /* LED2 - AA4 */
  269. omap_cfg_reg(AA4_242X_GPIO15);
  270. omap_request_gpio(LED2_GPIO15);
  271. omap_set_gpio_direction(LED2_GPIO15, 0);
  272. omap_set_gpio_dataout(LED2_GPIO15, 0);
  273. }
  274. static irqreturn_t apollon_sw_interrupt(int irq, void *ignored)
  275. {
  276. static unsigned int led0, led1, led2;
  277. if (irq == OMAP_GPIO_IRQ(SW_ENTER_GPIO16))
  278. omap_set_gpio_dataout(LED0_GPIO13, led0 ^= 1);
  279. else if (irq == OMAP_GPIO_IRQ(SW_UP_GPIO17))
  280. omap_set_gpio_dataout(LED1_GPIO14, led1 ^= 1);
  281. else if (irq == OMAP_GPIO_IRQ(SW_DOWN_GPIO58))
  282. omap_set_gpio_dataout(LED2_GPIO15, led2 ^= 1);
  283. return IRQ_HANDLED;
  284. }
  285. static void __init apollon_sw_init(void)
  286. {
  287. /* Enter SW - Y11 */
  288. omap_cfg_reg(Y11_242X_GPIO16);
  289. omap_request_gpio(SW_ENTER_GPIO16);
  290. omap_set_gpio_direction(SW_ENTER_GPIO16, 1);
  291. /* Up SW - AA12 */
  292. omap_cfg_reg(AA12_242X_GPIO17);
  293. omap_request_gpio(SW_UP_GPIO17);
  294. omap_set_gpio_direction(SW_UP_GPIO17, 1);
  295. /* Down SW - AA8 */
  296. omap_cfg_reg(AA8_242X_GPIO58);
  297. omap_request_gpio(SW_DOWN_GPIO58);
  298. omap_set_gpio_direction(SW_DOWN_GPIO58, 1);
  299. set_irq_type(OMAP_GPIO_IRQ(SW_ENTER_GPIO16), IRQ_TYPE_EDGE_RISING);
  300. if (request_irq(OMAP_GPIO_IRQ(SW_ENTER_GPIO16), &apollon_sw_interrupt,
  301. IRQF_SHARED, "enter sw",
  302. &apollon_sw_interrupt))
  303. return;
  304. set_irq_type(OMAP_GPIO_IRQ(SW_UP_GPIO17), IRQ_TYPE_EDGE_RISING);
  305. if (request_irq(OMAP_GPIO_IRQ(SW_UP_GPIO17), &apollon_sw_interrupt,
  306. IRQF_SHARED, "up sw",
  307. &apollon_sw_interrupt))
  308. return;
  309. set_irq_type(OMAP_GPIO_IRQ(SW_DOWN_GPIO58), IRQ_TYPE_EDGE_RISING);
  310. if (request_irq(OMAP_GPIO_IRQ(SW_DOWN_GPIO58), &apollon_sw_interrupt,
  311. IRQF_SHARED, "down sw",
  312. &apollon_sw_interrupt))
  313. return;
  314. }
  315. static void __init apollon_usb_init(void)
  316. {
  317. /* USB device */
  318. /* DEVICE_SUSPEND */
  319. omap_cfg_reg(P21_242X_GPIO12);
  320. omap_request_gpio(12);
  321. omap_set_gpio_direction(12, 0); /* OUT */
  322. omap_set_gpio_dataout(12, 0);
  323. }
  324. static void __init omap_apollon_init(void)
  325. {
  326. u32 v;
  327. apollon_led_init();
  328. apollon_sw_init();
  329. apollon_flash_init();
  330. apollon_usb_init();
  331. /* REVISIT: where's the correct place */
  332. omap_cfg_reg(W19_24XX_SYS_NIRQ);
  333. /* Use Interal loop-back in MMC/SDIO Module Input Clock selection */
  334. v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  335. v |= (1 << 24);
  336. omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
  337. /*
  338. * Make sure the serial ports are muxed on at this point.
  339. * You have to mux them off in device drivers later on
  340. * if not needed.
  341. */
  342. platform_add_devices(apollon_devices, ARRAY_SIZE(apollon_devices));
  343. omap_board_config = apollon_config;
  344. omap_board_config_size = ARRAY_SIZE(apollon_config);
  345. omap_serial_init();
  346. }
  347. static void __init omap_apollon_map_io(void)
  348. {
  349. omap2_set_globals_242x();
  350. omap2_map_common_io();
  351. }
  352. MACHINE_START(OMAP_APOLLON, "OMAP24xx Apollon")
  353. /* Maintainer: Kyungmin Park <kyungmin.park@samsung.com> */
  354. .phys_io = 0x48000000,
  355. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  356. .boot_params = 0x80000100,
  357. .map_io = omap_apollon_map_io,
  358. .init_irq = omap_apollon_init_irq,
  359. .init_machine = omap_apollon_init,
  360. .timer = &omap_timer,
  361. MACHINE_END