graphicsmaster.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/arm/mach-sa1100/graphicsmaster.c
  3.  *
  4.  * Pieces specific to the GraphicsMaster board
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  */
  10. #include <linux/init.h>
  11. #include <linux/sched.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/ptrace.h>
  14. #include <asm/hardware.h>
  15. #include <asm/setup.h>
  16. #include <asm/irq.h>
  17. #include <asm/mach/irq.h>
  18. #include <asm/mach/arch.h>
  19. #include <asm/mach/map.h>
  20. #include <asm/mach/serial_sa1100.h>
  21. #include <asm/arch/irq.h>
  22. #include "generic.h"
  23. #include "sa1111.h"
  24. static int __init graphicsmaster_init(void)
  25. {
  26. int ret;
  27. if (!machine_is_graphicsmaster())
  28. return -ENODEV;
  29. /*
  30.  * Ensure that the memory bus request/grant signals are setup,
  31.  * and the grant is held in its inactive state
  32.  */
  33. sa1110_mb_disable();
  34. /*
  35.  * Probe for SA1111.
  36.  */
  37. ret = sa1111_probe(ADS_SA1111_BASE);
  38. if (ret < 0)
  39. return ret;
  40. /*
  41.  * We found it.  Wake the chip up.
  42.  */
  43. sa1111_wake();
  44. /*
  45.  * The SDRAM configuration of the SA1110 and the SA1111 must
  46.  * match.  This is very important to ensure that SA1111 accesses
  47.  * don't corrupt the SDRAM.  Note that this ungates the SA1111's
  48.  * MBGNT signal, so we must have called sa1110_mb_disable()
  49.  * beforehand.
  50.  */
  51. sa1111_configure_smc(1,
  52.      FExtr(MDCNFG, MDCNFG_SA1110_DRAC0),
  53.      FExtr(MDCNFG, MDCNFG_SA1110_TDL0));
  54. /*
  55.  * Enable PWM control for LCD
  56.  */
  57. SKPCR |= SKPCR_PWMCLKEN;
  58. SKPWM0 = 0x7F; // VEE
  59. SKPEN0 = 1;
  60. SKPWM1 = 0x01; // Backlight
  61. SKPEN1 = 1;
  62. /*
  63.  * We only need to turn on DCLK whenever we want to use the
  64.  * DMA.  It can otherwise be held firmly in the off position.
  65.  */
  66. SKPCR |= SKPCR_DCLKEN;
  67. /*
  68.  * Enable the SA1110 memory bus request and grant signals.
  69.  */
  70. sa1110_mb_enable();
  71. sa1111_init_irq(ADS_EXT_IRQ(0));
  72. return 0;
  73. }
  74. __initcall(graphicsmaster_init);
  75. /*
  76.  * Handlers for GraphicsMaster's external IRQ logic
  77.  */
  78. static void ADS_IRQ_demux( int irq, void *dev_id, struct pt_regs *regs )
  79. {
  80. int i;
  81. while( (irq = ADS_INT_ST1 | (ADS_INT_ST2 << 8)) ){
  82. for( i = 0; i < 16; i++ )
  83. if( irq & (1<<i) ) {
  84. do_IRQ( ADS_EXT_IRQ(i), regs );
  85. }
  86. }
  87. }
  88. static struct irqaction ADS_ext_irq = {
  89. name: "ADS_ext_IRQ",
  90. handler: ADS_IRQ_demux,
  91. flags: SA_INTERRUPT
  92. };
  93. static void ADS_mask_and_ack_irq0(unsigned int irq)
  94. {
  95. int mask = (1 << (irq - ADS_EXT_IRQ(0)));
  96. ADS_INT_EN1 &= ~mask;
  97. ADS_INT_ST1 = mask;
  98. }
  99. static void ADS_mask_irq0(unsigned int irq)
  100. {
  101. ADS_INT_ST1 = (1 << (irq - ADS_EXT_IRQ(0)));
  102. }
  103. static void ADS_unmask_irq0(unsigned int irq)
  104. {
  105. ADS_INT_EN1 |= (1 << (irq - ADS_EXT_IRQ(0)));
  106. }
  107. static void ADS_mask_and_ack_irq1(unsigned int irq)
  108. {
  109. int mask = (1 << (irq - ADS_EXT_IRQ(8)));
  110. ADS_INT_EN2 &= ~mask;
  111. ADS_INT_ST2 = mask;
  112. }
  113. static void ADS_mask_irq1(unsigned int irq)
  114. {
  115. ADS_INT_ST2 = (1 << (irq - ADS_EXT_IRQ(8)));
  116. }
  117. static void ADS_unmask_irq1(unsigned int irq)
  118. {
  119. ADS_INT_EN2 |= (1 << (irq - ADS_EXT_IRQ(8)));
  120. }
  121. static void __init graphicsmaster_init_irq(void)
  122. {
  123. int irq;
  124. /* First the standard SA1100 IRQs */
  125. sa1100_init_irq();
  126. /* disable all IRQs */
  127. ADS_INT_EN1 = 0;
  128. ADS_INT_EN2 = 0;
  129. /* clear all IRQs */
  130. ADS_INT_ST1 = 0xff;
  131. ADS_INT_ST2 = 0xff;
  132. for (irq = ADS_EXT_IRQ(0); irq <= ADS_EXT_IRQ(7); irq++) {
  133. irq_desc[irq].valid = 1;
  134. irq_desc[irq].probe_ok = 1;
  135. irq_desc[irq].mask_ack = ADS_mask_and_ack_irq0;
  136. irq_desc[irq].mask = ADS_mask_irq0;
  137. irq_desc[irq].unmask = ADS_unmask_irq0;
  138. }
  139. for (irq = ADS_EXT_IRQ(8); irq <= ADS_EXT_IRQ(15); irq++) {
  140. irq_desc[irq].valid = 1;
  141. irq_desc[irq].probe_ok = 1;
  142. irq_desc[irq].mask_ack = ADS_mask_and_ack_irq1;
  143. irq_desc[irq].mask = ADS_mask_irq1;
  144. irq_desc[irq].unmask = ADS_unmask_irq1;
  145. }
  146. set_GPIO_IRQ_edge(GPIO_GPIO0, GPIO_FALLING_EDGE);
  147. setup_arm_irq( IRQ_GPIO0, &ADS_ext_irq );
  148. }
  149. /*
  150.  * Initialization fixup
  151.  */
  152. static void __init
  153. fixup_graphicsmaster(struct machine_desc *desc, struct param_struct *params,
  154.      char **cmdline, struct meminfo *mi)
  155. {
  156. SET_BANK( 0, 0xc0000000, 16*1024*1024 );
  157. mi->nr_banks = 1;
  158. SET_BANK( 1, 0xc8000000, 16*1024*1024 );
  159. mi->nr_banks = 2;
  160. ROOT_DEV = MKDEV(RAMDISK_MAJOR,0);
  161. setup_ramdisk( 1, 0, 0, 8192 );
  162. setup_initrd( __phys_to_virt(0xc0800000), 4*1024*1024 );
  163. }
  164. static struct map_desc graphicsmaster_io_desc[] __initdata = {
  165.  /* virtual     physical    length      domain     r  w  c  b */
  166.   { 0xe8000000, 0x08000000, 0x02000000, DOMAIN_IO, 0, 1, 0, 0 }, /* Flash bank 1 */
  167.   { 0xf0000000, 0x10000000, 0x00400000, DOMAIN_IO, 0, 1, 0, 0 }, /* CPLD */
  168.   { 0xf1000000, 0x40000000, 0x00400000, DOMAIN_IO, 0, 1, 0, 0 }, /* CAN */
  169.   { 0xf4000000, 0x18000000, 0x00800000, DOMAIN_IO, 0, 1, 0, 0 }, /* SA-1111 */
  170.   LAST_DESC
  171. };
  172. static int graphicsmaster_uart_open(struct uart_port *port, struct uart_info *info)
  173. {
  174. int ret = 0;
  175. if (port->mapbase == _Ser1UTCR0) {
  176. Ser1SDCR0 |= SDCR0_UART;
  177. /* Set RTS Output */
  178. GPSR = GPIO_GPIO15;
  179. }
  180. else if (port->mapbase == _Ser2UTCR0) {
  181. Ser2UTCR4 = Ser2HSCR0 = 0;
  182. /* Set RTS Output */
  183. GPSR = GPIO_GPIO17;
  184. }
  185. else if (port->mapbase == _Ser3UTCR0) {
  186.         /* Set RTS Output */
  187. GPSR = GPIO_GPIO19;
  188. }
  189. return ret;
  190. }
  191. static u_int graphicsmaster_get_mctrl(struct uart_port *port)
  192. {
  193. u_int result = TIOCM_CD | TIOCM_DSR;
  194. if (port->mapbase == _Ser1UTCR0) {
  195. if (!(GPLR & GPIO_GPIO14))
  196. result |= TIOCM_CTS;
  197. } else if (port->mapbase == _Ser2UTCR0) {
  198. if (!(GPLR & GPIO_GPIO16))
  199. result |= TIOCM_CTS;
  200. } else if (port->mapbase == _Ser3UTCR0) {
  201. if (!(GPLR & GPIO_GPIO17))
  202. result |= TIOCM_CTS;
  203. } else {
  204. result = TIOCM_CTS;
  205. }
  206. return result;
  207. }
  208. static void graphicsmaster_set_mctrl(struct uart_port *port, u_int mctrl)
  209. {
  210. if (port->mapbase == _Ser1UTCR0) {
  211. if (mctrl & TIOCM_RTS)
  212. GPCR = GPIO_GPIO15;
  213. else
  214. GPSR = GPIO_GPIO15;
  215. } else if (port->mapbase == _Ser2UTCR0) {
  216. if (mctrl & TIOCM_RTS)
  217. GPCR = GPIO_GPIO17;
  218. else
  219. GPSR = GPIO_GPIO17;
  220. } else if (port->mapbase == _Ser3UTCR0) {
  221. if (mctrl & TIOCM_RTS)
  222. GPCR = GPIO_GPIO19;
  223. else
  224. GPSR = GPIO_GPIO19;
  225. }
  226. }
  227. static void
  228. graphicsmaster_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  229. {
  230. if (!state) {
  231. /* make serial ports work ... */
  232. Ser2UTCR4 = 0;
  233. Ser2HSCR0 = 0; 
  234. Ser1SDCR0 |= SDCR0_UART;
  235. }
  236. }
  237. static struct sa1100_port_fns graphicsmaster_port_fns __initdata = {
  238. open: graphicsmaster_uart_open,
  239. get_mctrl: graphicsmaster_get_mctrl,
  240. set_mctrl: graphicsmaster_set_mctrl,
  241. pm: graphicsmaster_uart_pm,
  242. };
  243. static void __init graphicsmaster_map_io(void)
  244. {
  245. sa1100_map_io();
  246. iotable_init(graphicsmaster_io_desc);
  247. sa1100_register_uart_fns(&graphicsmaster_port_fns);
  248. sa1100_register_uart(0, 3);
  249. sa1100_register_uart(1, 1);
  250. sa1100_register_uart(2, 2);
  251. /* set GPDR now */
  252. GPDR |= GPIO_GPIO15 | GPIO_GPIO17 | GPIO_GPIO19;
  253.         GPDR &= ~(GPIO_GPIO14 | GPIO_GPIO16 | GPIO_GPIO18);
  254. }
  255. MACHINE_START(GRAPHICSMASTER, "ADS GraphicsMaster")
  256. BOOT_MEM(0xc0000000, 0x80000000, 0xf8000000)
  257. FIXUP(fixup_graphicsmaster)
  258. MAPIO(graphicsmaster_map_io)
  259. INITIRQ(graphicsmaster_init_irq)
  260. MACHINE_END