simpad.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_16M),
  153. DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M),
  154. };
  155. static struct mcp_plat_data simpad_mcp_data = {
  156. .mccr0 = MCCR0_ADM,
  157. .sclk_rate = 11981000,
  158. .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
  159. };
  160. static void __init simpad_map_io(void)
  161. {
  162. sa1100_map_io();
  163. iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
  164. /* Initialize CS3 */
  165. cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
  166. RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
  167. __simpad_write_cs3(); /* Spinlocks not yet initialized */
  168. sa1100_register_uart_fns(&simpad_port_fns);
  169. sa1100_register_uart(0, 3); /* serial interface */
  170. sa1100_register_uart(1, 1); /* DECT */
  171. // Reassign UART 1 pins
  172. GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
  173. GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
  174. GPDR &= ~GPIO_UART_RXD;
  175. PPAR |= PPAR_UPR;
  176. /*
  177. * Set up registers for sleep mode.
  178. */
  179. PWER = PWER_GPIO0| PWER_RTC;
  180. PGSR = 0x818;
  181. PCFR = 0;
  182. PSDR = 0;
  183. }
  184. static void simpad_power_off(void)
  185. {
  186. local_irq_disable();
  187. cs3_shadow = SD_MEDIAQ;
  188. __simpad_write_cs3(); /* Bypass spinlock here */
  189. /* disable internal oscillator, float CS lines */
  190. PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
  191. /* enable wake-up on GPIO0 */
  192. PWER = GFER = GRER = PWER_GPIO0;
  193. /*
  194. * set scratchpad to zero, just in case it is used as a
  195. * restart address by the bootloader.
  196. */
  197. PSPR = 0;
  198. PGSR = 0;
  199. /* enter sleep mode */
  200. PMCR = PMCR_SF;
  201. while(1);
  202. local_irq_enable(); /* we won't ever call it */
  203. }
  204. /*
  205. * gpio_keys
  206. */
  207. static struct gpio_keys_button simpad_button_table[] = {
  208. { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" },
  209. };
  210. static struct gpio_keys_platform_data simpad_keys_data = {
  211. .buttons = simpad_button_table,
  212. .nbuttons = ARRAY_SIZE(simpad_button_table),
  213. };
  214. static struct platform_device simpad_keys = {
  215. .name = "gpio-keys",
  216. .dev = {
  217. .platform_data = &simpad_keys_data,
  218. },
  219. };
  220. static struct gpio_keys_button simpad_polled_button_table[] = {
  221. { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" },
  222. { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" },
  223. { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" },
  224. { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" },
  225. { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" },
  226. { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" },
  227. };
  228. static struct gpio_keys_platform_data simpad_polled_keys_data = {
  229. .buttons = simpad_polled_button_table,
  230. .nbuttons = ARRAY_SIZE(simpad_polled_button_table),
  231. .poll_interval = 50,
  232. };
  233. static struct platform_device simpad_polled_keys = {
  234. .name = "gpio-keys-polled",
  235. .dev = {
  236. .platform_data = &simpad_polled_keys_data,
  237. },
  238. };
  239. /*
  240. * GPIO LEDs
  241. */
  242. static struct gpio_led simpad_leds[] = {
  243. {
  244. .name = "simpad:power",
  245. .gpio = SIMPAD_CS3_LED2_ON,
  246. .active_low = 0,
  247. .default_trigger = "default-on",
  248. },
  249. };
  250. static struct gpio_led_platform_data simpad_led_data = {
  251. .num_leds = ARRAY_SIZE(simpad_leds),
  252. .leds = simpad_leds,
  253. };
  254. static struct platform_device simpad_gpio_leds = {
  255. .name = "leds-gpio",
  256. .id = 0,
  257. .dev = {
  258. .platform_data = &simpad_led_data,
  259. },
  260. };
  261. /*
  262. * i2c
  263. */
  264. static struct i2c_gpio_platform_data simpad_i2c_data = {
  265. .sda_pin = GPIO_GPIO21,
  266. .scl_pin = GPIO_GPIO25,
  267. .udelay = 10,
  268. .timeout = HZ,
  269. };
  270. static struct platform_device simpad_i2c = {
  271. .name = "i2c-gpio",
  272. .id = 0,
  273. .dev = {
  274. .platform_data = &simpad_i2c_data,
  275. },
  276. };
  277. /*
  278. * MediaQ Video Device
  279. */
  280. static struct platform_device simpad_mq200fb = {
  281. .name = "simpad-mq200",
  282. .id = 0,
  283. };
  284. static struct platform_device *devices[] __initdata = {
  285. &simpad_keys,
  286. &simpad_polled_keys,
  287. &simpad_mq200fb,
  288. &simpad_gpio_leds,
  289. &simpad_i2c,
  290. };
  291. static int __init simpad_init(void)
  292. {
  293. int ret;
  294. spin_lock_init(&cs3_lock);
  295. cs3_gpio.label = "simpad_cs3";
  296. cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
  297. cs3_gpio.ngpio = 24;
  298. cs3_gpio.set = cs3_gpio_set;
  299. cs3_gpio.get = cs3_gpio_get;
  300. cs3_gpio.direction_input = cs3_gpio_direction_input;
  301. cs3_gpio.direction_output = cs3_gpio_direction_output;
  302. ret = gpiochip_add(&cs3_gpio);
  303. if (ret)
  304. printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
  305. pm_power_off = simpad_power_off;
  306. sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
  307. ARRAY_SIZE(simpad_flash_resources));
  308. sa11x0_register_mcp(&simpad_mcp_data);
  309. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  310. if(ret)
  311. printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
  312. return 0;
  313. }
  314. arch_initcall(simpad_init);
  315. MACHINE_START(SIMPAD, "Simpad")
  316. /* Maintainer: Holger Freyther */
  317. .atag_offset = 0x100,
  318. .map_io = simpad_map_io,
  319. .init_irq = sa1100_init_irq,
  320. .timer = &sa1100_timer,
  321. .restart = sa11x0_restart,
  322. MACHINE_END