simpad.c 8.4 KB

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