simpad.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * linux/arch/arm/mach-sa1100/simpad.c
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/kernel.h>
  7. #include <linux/tty.h>
  8. #include <linux/proc_fs.h>
  9. #include <linux/string.h>
  10. #include <linux/pm.h>
  11. #include <linux/platform_data/sa11x0-serial.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mfd/ucb1x00.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/partitions.h>
  16. #include <linux/io.h>
  17. #include <linux/gpio/driver.h>
  18. #include <mach/hardware.h>
  19. #include <asm/setup.h>
  20. #include <asm/irq.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/mach/arch.h>
  23. #include <asm/mach/flash.h>
  24. #include <asm/mach/map.h>
  25. #include <linux/platform_data/mfd-mcp-sa11x0.h>
  26. #include <mach/simpad.h>
  27. #include <mach/irqs.h>
  28. #include <linux/serial_core.h>
  29. #include <linux/ioport.h>
  30. #include <linux/input.h>
  31. #include <linux/gpio_keys.h>
  32. #include <linux/leds.h>
  33. #include <linux/i2c-gpio.h>
  34. #include "generic.h"
  35. /*
  36. * CS3 support
  37. */
  38. static long cs3_shadow;
  39. static spinlock_t cs3_lock;
  40. static struct gpio_chip cs3_gpio;
  41. long simpad_get_cs3_ro(void)
  42. {
  43. return readl(CS3_BASE);
  44. }
  45. EXPORT_SYMBOL(simpad_get_cs3_ro);
  46. long simpad_get_cs3_shadow(void)
  47. {
  48. return cs3_shadow;
  49. }
  50. EXPORT_SYMBOL(simpad_get_cs3_shadow);
  51. static void __simpad_write_cs3(void)
  52. {
  53. writel(cs3_shadow, CS3_BASE);
  54. }
  55. void simpad_set_cs3_bit(int value)
  56. {
  57. unsigned long flags;
  58. spin_lock_irqsave(&cs3_lock, flags);
  59. cs3_shadow |= value;
  60. __simpad_write_cs3();
  61. spin_unlock_irqrestore(&cs3_lock, flags);
  62. }
  63. EXPORT_SYMBOL(simpad_set_cs3_bit);
  64. void simpad_clear_cs3_bit(int value)
  65. {
  66. unsigned long flags;
  67. spin_lock_irqsave(&cs3_lock, flags);
  68. cs3_shadow &= ~value;
  69. __simpad_write_cs3();
  70. spin_unlock_irqrestore(&cs3_lock, flags);
  71. }
  72. EXPORT_SYMBOL(simpad_clear_cs3_bit);
  73. static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  74. {
  75. if (offset > 15)
  76. return;
  77. if (value)
  78. simpad_set_cs3_bit(1 << offset);
  79. else
  80. simpad_clear_cs3_bit(1 << offset);
  81. };
  82. static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset)
  83. {
  84. if (offset > 15)
  85. return !!(simpad_get_cs3_ro() & (1 << (offset - 16)));
  86. return !!(simpad_get_cs3_shadow() & (1 << offset));
  87. };
  88. static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  89. {
  90. if (offset > 15)
  91. return 0;
  92. return -EINVAL;
  93. };
  94. static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  95. int value)
  96. {
  97. if (offset > 15)
  98. return -EINVAL;
  99. cs3_gpio_set(chip, offset, value);
  100. return 0;
  101. };
  102. static struct map_desc simpad_io_desc[] __initdata = {
  103. { /* MQ200 */
  104. .virtual = 0xf2800000,
  105. .pfn = __phys_to_pfn(0x4b800000),
  106. .length = 0x00800000,
  107. .type = MT_DEVICE
  108. }, { /* Simpad CS3 */
  109. .virtual = (unsigned long)CS3_BASE,
  110. .pfn = __phys_to_pfn(SA1100_CS3_PHYS),
  111. .length = 0x00100000,
  112. .type = MT_DEVICE
  113. },
  114. };
  115. static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  116. {
  117. if (port->mapbase == (u_int)&Ser1UTCR0) {
  118. if (state)
  119. {
  120. simpad_clear_cs3_bit(RS232_ON);
  121. simpad_clear_cs3_bit(DECT_POWER_ON);
  122. }else
  123. {
  124. simpad_set_cs3_bit(RS232_ON);
  125. simpad_set_cs3_bit(DECT_POWER_ON);
  126. }
  127. }
  128. }
  129. static struct sa1100_port_fns simpad_port_fns __initdata = {
  130. .pm = simpad_uart_pm,
  131. };
  132. static struct mtd_partition simpad_partitions[] = {
  133. {
  134. .name = "SIMpad boot firmware",
  135. .size = 0x00080000,
  136. .offset = 0,
  137. .mask_flags = MTD_WRITEABLE,
  138. }, {
  139. .name = "SIMpad kernel",
  140. .size = 0x0010000,
  141. .offset = MTDPART_OFS_APPEND,
  142. }, {
  143. .name = "SIMpad root jffs2",
  144. .size = MTDPART_SIZ_FULL,
  145. .offset = MTDPART_OFS_APPEND,
  146. }
  147. };
  148. static struct flash_platform_data simpad_flash_data = {
  149. .map_name = "cfi_probe",
  150. .parts = simpad_partitions,
  151. .nr_parts = ARRAY_SIZE(simpad_partitions),
  152. };
  153. static struct resource simpad_flash_resources [] = {
  154. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_16M),
  155. DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M),
  156. };
  157. static struct ucb1x00_plat_data simpad_ucb1x00_data = {
  158. .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
  159. };
  160. static struct mcp_plat_data simpad_mcp_data = {
  161. .mccr0 = MCCR0_ADM,
  162. .sclk_rate = 11981000,
  163. .codec_pdata = &simpad_ucb1x00_data,
  164. };
  165. static void __init simpad_map_io(void)
  166. {
  167. sa1100_map_io();
  168. iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
  169. /* Initialize CS3 */
  170. cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
  171. RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
  172. __simpad_write_cs3(); /* Spinlocks not yet initialized */
  173. sa1100_register_uart_fns(&simpad_port_fns);
  174. sa1100_register_uart(0, 3); /* serial interface */
  175. sa1100_register_uart(1, 1); /* DECT */
  176. // Reassign UART 1 pins
  177. GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
  178. GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
  179. GPDR &= ~GPIO_UART_RXD;
  180. PPAR |= PPAR_UPR;
  181. /*
  182. * Set up registers for sleep mode.
  183. */
  184. PWER = PWER_GPIO0| PWER_RTC;
  185. PGSR = 0x818;
  186. PCFR = 0;
  187. PSDR = 0;
  188. }
  189. static void simpad_power_off(void)
  190. {
  191. local_irq_disable();
  192. cs3_shadow = SD_MEDIAQ;
  193. __simpad_write_cs3(); /* Bypass spinlock here */
  194. /* disable internal oscillator, float CS lines */
  195. PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
  196. /* enable wake-up on GPIO0 */
  197. PWER = GFER = GRER = PWER_GPIO0;
  198. /*
  199. * set scratchpad to zero, just in case it is used as a
  200. * restart address by the bootloader.
  201. */
  202. PSPR = 0;
  203. PGSR = 0;
  204. /* enter sleep mode */
  205. PMCR = PMCR_SF;
  206. while(1);
  207. local_irq_enable(); /* we won't ever call it */
  208. }
  209. /*
  210. * gpio_keys
  211. */
  212. static struct gpio_keys_button simpad_button_table[] = {
  213. { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
  214. };
  215. static struct gpio_keys_platform_data simpad_keys_data = {
  216. .buttons = simpad_button_table,
  217. .nbuttons = ARRAY_SIZE(simpad_button_table),
  218. };
  219. static struct platform_device simpad_keys = {
  220. .name = "gpio-keys",
  221. .dev = {
  222. .platform_data = &simpad_keys_data,
  223. },
  224. };
  225. static struct gpio_keys_button simpad_polled_button_table[] = {
  226. { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" },
  227. { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" },
  228. { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" },
  229. { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" },
  230. { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" },
  231. { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" },
  232. };
  233. static struct gpio_keys_platform_data simpad_polled_keys_data = {
  234. .buttons = simpad_polled_button_table,
  235. .nbuttons = ARRAY_SIZE(simpad_polled_button_table),
  236. .poll_interval = 50,
  237. };
  238. static struct platform_device simpad_polled_keys = {
  239. .name = "gpio-keys-polled",
  240. .dev = {
  241. .platform_data = &simpad_polled_keys_data,
  242. },
  243. };
  244. /*
  245. * GPIO LEDs
  246. */
  247. static struct gpio_led simpad_leds[] = {
  248. {
  249. .name = "simpad:power",
  250. .gpio = SIMPAD_CS3_LED2_ON,
  251. .active_low = 0,
  252. .default_trigger = "default-on",
  253. },
  254. };
  255. static struct gpio_led_platform_data simpad_led_data = {
  256. .num_leds = ARRAY_SIZE(simpad_leds),
  257. .leds = simpad_leds,
  258. };
  259. static struct platform_device simpad_gpio_leds = {
  260. .name = "leds-gpio",
  261. .id = 0,
  262. .dev = {
  263. .platform_data = &simpad_led_data,
  264. },
  265. };
  266. /*
  267. * i2c
  268. */
  269. static struct i2c_gpio_platform_data simpad_i2c_data = {
  270. .sda_pin = GPIO_GPIO21,
  271. .scl_pin = GPIO_GPIO25,
  272. .udelay = 10,
  273. .timeout = HZ,
  274. };
  275. static struct platform_device simpad_i2c = {
  276. .name = "i2c-gpio",
  277. .id = 0,
  278. .dev = {
  279. .platform_data = &simpad_i2c_data,
  280. },
  281. };
  282. /*
  283. * MediaQ Video Device
  284. */
  285. static struct platform_device simpad_mq200fb = {
  286. .name = "simpad-mq200",
  287. .id = 0,
  288. };
  289. static struct platform_device *devices[] __initdata = {
  290. &simpad_keys,
  291. &simpad_polled_keys,
  292. &simpad_mq200fb,
  293. &simpad_gpio_leds,
  294. &simpad_i2c,
  295. };
  296. static int __init simpad_init(void)
  297. {
  298. int ret;
  299. spin_lock_init(&cs3_lock);
  300. cs3_gpio.label = "simpad_cs3";
  301. cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
  302. cs3_gpio.ngpio = 24;
  303. cs3_gpio.set = cs3_gpio_set;
  304. cs3_gpio.get = cs3_gpio_get;
  305. cs3_gpio.direction_input = cs3_gpio_direction_input;
  306. cs3_gpio.direction_output = cs3_gpio_direction_output;
  307. ret = gpiochip_add_data(&cs3_gpio, NULL);
  308. if (ret)
  309. printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
  310. pm_power_off = simpad_power_off;
  311. sa11x0_ppc_configure_mcp();
  312. sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
  313. ARRAY_SIZE(simpad_flash_resources));
  314. sa11x0_register_mcp(&simpad_mcp_data);
  315. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  316. if(ret)
  317. printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
  318. return 0;
  319. }
  320. arch_initcall(simpad_init);
  321. MACHINE_START(SIMPAD, "Simpad")
  322. /* Maintainer: Holger Freyther */
  323. .atag_offset = 0x100,
  324. .map_io = simpad_map_io,
  325. .nr_irqs = SA1100_NR_IRQS,
  326. .init_irq = sa1100_init_irq,
  327. .init_late = sa11x0_init_late,
  328. .init_time = sa1100_timer_init,
  329. .restart = sa11x0_restart,
  330. MACHINE_END