simpad.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 "generic.h"
  29. /*
  30. * CS3 support
  31. */
  32. static long cs3_shadow;
  33. static spinlock_t cs3_lock;
  34. static struct gpio_chip cs3_gpio;
  35. long simpad_get_cs3_ro(void)
  36. {
  37. return readl(CS3_BASE);
  38. }
  39. EXPORT_SYMBOL(simpad_get_cs3_ro);
  40. long simpad_get_cs3_shadow(void)
  41. {
  42. return cs3_shadow;
  43. }
  44. EXPORT_SYMBOL(simpad_get_cs3_shadow);
  45. static void __simpad_write_cs3(void)
  46. {
  47. writel(cs3_shadow, CS3_BASE);
  48. }
  49. void simpad_set_cs3_bit(int value)
  50. {
  51. unsigned long flags;
  52. spin_lock_irqsave(&cs3_lock, flags);
  53. cs3_shadow |= value;
  54. __simpad_write_cs3();
  55. spin_unlock_irqrestore(&cs3_lock, flags);
  56. }
  57. EXPORT_SYMBOL(simpad_set_cs3_bit);
  58. void simpad_clear_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_clear_cs3_bit);
  67. static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  68. {
  69. if (offset > 15)
  70. return;
  71. if (value)
  72. simpad_set_cs3_bit(1 << offset);
  73. else
  74. simpad_clear_cs3_bit(1 << offset);
  75. };
  76. static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset)
  77. {
  78. if (offset > 15)
  79. return simpad_get_cs3_ro() & (1 << (offset - 16));
  80. return simpad_get_cs3_shadow() & (1 << offset);
  81. };
  82. static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  83. {
  84. if (offset > 15)
  85. return 0;
  86. return -EINVAL;
  87. };
  88. static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  89. int value)
  90. {
  91. if (offset > 15)
  92. return -EINVAL;
  93. cs3_gpio_set(chip, offset, value);
  94. return 0;
  95. };
  96. static struct map_desc simpad_io_desc[] __initdata = {
  97. { /* MQ200 */
  98. .virtual = 0xf2800000,
  99. .pfn = __phys_to_pfn(0x4b800000),
  100. .length = 0x00800000,
  101. .type = MT_DEVICE
  102. }, { /* Simpad CS3 */
  103. .virtual = CS3_BASE,
  104. .pfn = __phys_to_pfn(SA1100_CS3_PHYS),
  105. .length = 0x00100000,
  106. .type = MT_DEVICE
  107. },
  108. };
  109. static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  110. {
  111. if (port->mapbase == (u_int)&Ser1UTCR0) {
  112. if (state)
  113. {
  114. simpad_clear_cs3_bit(RS232_ON);
  115. simpad_clear_cs3_bit(DECT_POWER_ON);
  116. }else
  117. {
  118. simpad_set_cs3_bit(RS232_ON);
  119. simpad_set_cs3_bit(DECT_POWER_ON);
  120. }
  121. }
  122. }
  123. static struct sa1100_port_fns simpad_port_fns __initdata = {
  124. .pm = simpad_uart_pm,
  125. };
  126. static struct mtd_partition simpad_partitions[] = {
  127. {
  128. .name = "SIMpad boot firmware",
  129. .size = 0x00080000,
  130. .offset = 0,
  131. .mask_flags = MTD_WRITEABLE,
  132. }, {
  133. .name = "SIMpad kernel",
  134. .size = 0x0010000,
  135. .offset = MTDPART_OFS_APPEND,
  136. }, {
  137. .name = "SIMpad root jffs2",
  138. .size = MTDPART_SIZ_FULL,
  139. .offset = MTDPART_OFS_APPEND,
  140. }
  141. };
  142. static struct flash_platform_data simpad_flash_data = {
  143. .map_name = "cfi_probe",
  144. .parts = simpad_partitions,
  145. .nr_parts = ARRAY_SIZE(simpad_partitions),
  146. };
  147. static struct resource simpad_flash_resources [] = {
  148. {
  149. .start = SA1100_CS0_PHYS,
  150. .end = SA1100_CS0_PHYS + SZ_16M -1,
  151. .flags = IORESOURCE_MEM,
  152. }, {
  153. .start = SA1100_CS1_PHYS,
  154. .end = SA1100_CS1_PHYS + SZ_16M -1,
  155. .flags = IORESOURCE_MEM,
  156. }
  157. };
  158. static struct mcp_plat_data simpad_mcp_data = {
  159. .mccr0 = MCCR0_ADM,
  160. .sclk_rate = 11981000,
  161. .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
  162. };
  163. static void __init simpad_map_io(void)
  164. {
  165. sa1100_map_io();
  166. iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc));
  167. /* Initialize CS3 */
  168. cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON |
  169. RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON);
  170. __simpad_write_cs3(); /* Spinlocks not yet initialized */
  171. sa1100_register_uart_fns(&simpad_port_fns);
  172. sa1100_register_uart(0, 3); /* serial interface */
  173. sa1100_register_uart(1, 1); /* DECT */
  174. // Reassign UART 1 pins
  175. GAFR |= GPIO_UART_TXD | GPIO_UART_RXD;
  176. GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15;
  177. GPDR &= ~GPIO_UART_RXD;
  178. PPAR |= PPAR_UPR;
  179. /*
  180. * Set up registers for sleep mode.
  181. */
  182. PWER = PWER_GPIO0| PWER_RTC;
  183. PGSR = 0x818;
  184. PCFR = 0;
  185. PSDR = 0;
  186. }
  187. static void simpad_power_off(void)
  188. {
  189. local_irq_disable();
  190. cs3_shadow = SD_MEDIAQ;
  191. __simpad_write_cs3(); /* Bypass spinlock here */
  192. /* disable internal oscillator, float CS lines */
  193. PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
  194. /* enable wake-up on GPIO0 */
  195. PWER = GFER = GRER = PWER_GPIO0;
  196. /*
  197. * set scratchpad to zero, just in case it is used as a
  198. * restart address by the bootloader.
  199. */
  200. PSPR = 0;
  201. PGSR = 0;
  202. /* enter sleep mode */
  203. PMCR = PMCR_SF;
  204. while(1);
  205. local_irq_enable(); /* we won't ever call it */
  206. }
  207. /*
  208. * MediaQ Video Device
  209. */
  210. static struct platform_device simpad_mq200fb = {
  211. .name = "simpad-mq200",
  212. .id = 0,
  213. };
  214. static struct platform_device *devices[] __initdata = {
  215. &simpad_mq200fb
  216. };
  217. static int __init simpad_init(void)
  218. {
  219. int ret;
  220. spin_lock_init(&cs3_lock);
  221. cs3_gpio.label = "simpad_cs3";
  222. cs3_gpio.base = SIMPAD_CS3_GPIO_BASE;
  223. cs3_gpio.ngpio = 24;
  224. cs3_gpio.set = cs3_gpio_set;
  225. cs3_gpio.get = cs3_gpio_get;
  226. cs3_gpio.direction_input = cs3_gpio_direction_input;
  227. cs3_gpio.direction_output = cs3_gpio_direction_output;
  228. ret = gpiochip_add(&cs3_gpio);
  229. if (ret)
  230. printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
  231. pm_power_off = simpad_power_off;
  232. sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
  233. ARRAY_SIZE(simpad_flash_resources));
  234. sa11x0_register_mcp(&simpad_mcp_data);
  235. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  236. if(ret)
  237. printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
  238. return 0;
  239. }
  240. arch_initcall(simpad_init);
  241. MACHINE_START(SIMPAD, "Simpad")
  242. /* Maintainer: Holger Freyther */
  243. .boot_params = 0xc0000100,
  244. .map_io = simpad_map_io,
  245. .init_irq = sa1100_init_irq,
  246. .timer = &sa1100_timer,
  247. MACHINE_END