simpad.c 9.2 KB

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