simpad.c 8.3 KB

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