assabet.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*
  2. * linux/arch/arm/mach-sa1100/assabet.c
  3. *
  4. * Author: Nicolas Pitre
  5. *
  6. * This file contains all Assabet-specific tweaks.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/errno.h>
  17. #include <linux/ioport.h>
  18. #include <linux/serial_core.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <linux/delay.h>
  22. #include <linux/mm.h>
  23. #include <asm/hardware.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/irq.h>
  26. #include <asm/setup.h>
  27. #include <asm/page.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/tlbflush.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/flash.h>
  32. #include <asm/mach/irda.h>
  33. #include <asm/mach/map.h>
  34. #include <asm/mach/serial_sa1100.h>
  35. #include <asm/arch/assabet.h>
  36. #include "generic.h"
  37. #define ASSABET_BCR_DB1110 \
  38. (ASSABET_BCR_SPK_OFF | ASSABET_BCR_QMUTE | \
  39. ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
  40. ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
  41. ASSABET_BCR_IRDA_MD0)
  42. #define ASSABET_BCR_DB1111 \
  43. (ASSABET_BCR_SPK_OFF | ASSABET_BCR_QMUTE | \
  44. ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
  45. ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
  46. ASSABET_BCR_CF_BUS_OFF | ASSABET_BCR_STEREO_LB | \
  47. ASSABET_BCR_IRDA_MD0 | ASSABET_BCR_CF_RST)
  48. unsigned long SCR_value = ASSABET_SCR_INIT;
  49. EXPORT_SYMBOL(SCR_value);
  50. static unsigned long BCR_value = ASSABET_BCR_DB1110;
  51. void ASSABET_BCR_frob(unsigned int mask, unsigned int val)
  52. {
  53. unsigned long flags;
  54. local_irq_save(flags);
  55. BCR_value = (BCR_value & ~mask) | val;
  56. ASSABET_BCR = BCR_value;
  57. local_irq_restore(flags);
  58. }
  59. EXPORT_SYMBOL(ASSABET_BCR_frob);
  60. static void assabet_backlight_power(int on)
  61. {
  62. #ifndef ASSABET_PAL_VIDEO
  63. if (on)
  64. ASSABET_BCR_set(ASSABET_BCR_LIGHT_ON);
  65. else
  66. #endif
  67. ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
  68. }
  69. /*
  70. * Turn on/off the backlight. When turning the backlight on,
  71. * we wait 500us after turning it on so we don't cause the
  72. * supplies to droop when we enable the LCD controller (and
  73. * cause a hard reset.)
  74. */
  75. static void assabet_lcd_power(int on)
  76. {
  77. #ifndef ASSABET_PAL_VIDEO
  78. if (on) {
  79. ASSABET_BCR_set(ASSABET_BCR_LCD_ON);
  80. udelay(500);
  81. } else
  82. #endif
  83. ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
  84. }
  85. /*
  86. * Assabet flash support code.
  87. */
  88. #ifdef ASSABET_REV_4
  89. /*
  90. * Phase 4 Assabet has two 28F160B3 flash parts in bank 0:
  91. */
  92. static struct mtd_partition assabet_partitions[] = {
  93. {
  94. .name = "bootloader",
  95. .size = 0x00020000,
  96. .offset = 0,
  97. .mask_flags = MTD_WRITEABLE,
  98. }, {
  99. .name = "bootloader params",
  100. .size = 0x00020000,
  101. .offset = MTDPART_OFS_APPEND,
  102. .mask_flags = MTD_WRITEABLE,
  103. }, {
  104. .name = "jffs",
  105. .size = MTDPART_SIZ_FULL,
  106. .offset = MTDPART_OFS_APPEND,
  107. }
  108. };
  109. #else
  110. /*
  111. * Phase 5 Assabet has two 28F128J3A flash parts in bank 0:
  112. */
  113. static struct mtd_partition assabet_partitions[] = {
  114. {
  115. .name = "bootloader",
  116. .size = 0x00040000,
  117. .offset = 0,
  118. .mask_flags = MTD_WRITEABLE,
  119. }, {
  120. .name = "bootloader params",
  121. .size = 0x00040000,
  122. .offset = MTDPART_OFS_APPEND,
  123. .mask_flags = MTD_WRITEABLE,
  124. }, {
  125. .name = "jffs",
  126. .size = MTDPART_SIZ_FULL,
  127. .offset = MTDPART_OFS_APPEND,
  128. }
  129. };
  130. #endif
  131. static struct flash_platform_data assabet_flash_data = {
  132. .map_name = "cfi_probe",
  133. .parts = assabet_partitions,
  134. .nr_parts = ARRAY_SIZE(assabet_partitions),
  135. };
  136. static struct resource assabet_flash_resources[] = {
  137. {
  138. .start = SA1100_CS0_PHYS,
  139. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  140. .flags = IORESOURCE_MEM,
  141. }, {
  142. .start = SA1100_CS1_PHYS,
  143. .end = SA1100_CS1_PHYS + SZ_32M - 1,
  144. .flags = IORESOURCE_MEM,
  145. }
  146. };
  147. /*
  148. * Assabet IrDA support code.
  149. */
  150. static int assabet_irda_set_power(struct device *dev, unsigned int state)
  151. {
  152. static unsigned int bcr_state[4] = {
  153. ASSABET_BCR_IRDA_MD0,
  154. ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0,
  155. ASSABET_BCR_IRDA_MD1,
  156. 0
  157. };
  158. if (state < 4) {
  159. state = bcr_state[state];
  160. ASSABET_BCR_clear(state ^ (ASSABET_BCR_IRDA_MD1|
  161. ASSABET_BCR_IRDA_MD0));
  162. ASSABET_BCR_set(state);
  163. }
  164. return 0;
  165. }
  166. static void assabet_irda_set_speed(struct device *dev, unsigned int speed)
  167. {
  168. if (speed < 4000000)
  169. ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL);
  170. else
  171. ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL);
  172. }
  173. static struct irda_platform_data assabet_irda_data = {
  174. .set_power = assabet_irda_set_power,
  175. .set_speed = assabet_irda_set_speed,
  176. };
  177. static void __init assabet_init(void)
  178. {
  179. /*
  180. * Ensure that the power supply is in "high power" mode.
  181. */
  182. GPDR |= GPIO_GPIO16;
  183. GPSR = GPIO_GPIO16;
  184. /*
  185. * Ensure that these pins are set as outputs and are driving
  186. * logic 0. This ensures that we won't inadvertently toggle
  187. * the WS latch in the CPLD, and we don't float causing
  188. * excessive power drain. --rmk
  189. */
  190. GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
  191. GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
  192. /*
  193. * Set up registers for sleep mode.
  194. */
  195. PWER = PWER_GPIO0;
  196. PGSR = 0;
  197. PCFR = 0;
  198. PSDR = 0;
  199. PPDR |= PPC_TXD3 | PPC_TXD1;
  200. PPSR |= PPC_TXD3 | PPC_TXD1;
  201. sa1100fb_lcd_power = assabet_lcd_power;
  202. sa1100fb_backlight_power = assabet_backlight_power;
  203. if (machine_has_neponset()) {
  204. /*
  205. * Angel sets this, but other bootloaders may not.
  206. *
  207. * This must precede any driver calls to BCR_set()
  208. * or BCR_clear().
  209. */
  210. ASSABET_BCR = BCR_value = ASSABET_BCR_DB1111;
  211. #ifndef CONFIG_ASSABET_NEPONSET
  212. printk( "Warning: Neponset detected but full support "
  213. "hasn't been configured in the kernel\n" );
  214. #endif
  215. }
  216. sa11x0_set_flash_data(&assabet_flash_data, assabet_flash_resources,
  217. ARRAY_SIZE(assabet_flash_resources));
  218. sa11x0_set_irda_data(&assabet_irda_data);
  219. }
  220. /*
  221. * On Assabet, we must probe for the Neponset board _before_
  222. * paging_init() has occurred to actually determine the amount
  223. * of RAM available. To do so, we map the appropriate IO section
  224. * in the page table here in order to access GPIO registers.
  225. */
  226. static void __init map_sa1100_gpio_regs( void )
  227. {
  228. unsigned long phys = __PREG(GPLR) & PMD_MASK;
  229. unsigned long virt = io_p2v(phys);
  230. int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
  231. pmd_t *pmd;
  232. pmd = pmd_offset(pgd_offset_k(virt), virt);
  233. *pmd = __pmd(phys | prot);
  234. flush_pmd_entry(pmd);
  235. }
  236. /*
  237. * Read System Configuration "Register"
  238. * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
  239. * User's Guide", section 4.4.1)
  240. *
  241. * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
  242. * to set up the serial port for decompression status messages. We
  243. * repeat it here because the kernel may not be loaded as a zImage, and
  244. * also because it's a hassle to communicate the SCR value to the kernel
  245. * from the decompressor.
  246. *
  247. * Note that IRQs are guaranteed to be disabled.
  248. */
  249. static void __init get_assabet_scr(void)
  250. {
  251. unsigned long scr, i;
  252. GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
  253. GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
  254. GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
  255. for(i = 100; i--; scr = GPLR); /* Read GPIO 9:2 */
  256. GPDR |= 0x3fc; /* restore correct pin direction */
  257. scr &= 0x3fc; /* save as system configuration byte. */
  258. SCR_value = scr;
  259. }
  260. static void __init
  261. fixup_assabet(struct machine_desc *desc, struct tag *tags,
  262. char **cmdline, struct meminfo *mi)
  263. {
  264. /* This must be done before any call to machine_has_neponset() */
  265. map_sa1100_gpio_regs();
  266. get_assabet_scr();
  267. if (machine_has_neponset())
  268. printk("Neponset expansion board detected\n");
  269. }
  270. static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  271. {
  272. if (port->mapbase == _Ser1UTCR0) {
  273. if (state)
  274. ASSABET_BCR_clear(ASSABET_BCR_RS232EN |
  275. ASSABET_BCR_COM_RTS |
  276. ASSABET_BCR_COM_DTR);
  277. else
  278. ASSABET_BCR_set(ASSABET_BCR_RS232EN |
  279. ASSABET_BCR_COM_RTS |
  280. ASSABET_BCR_COM_DTR);
  281. }
  282. }
  283. /*
  284. * Assabet uses COM_RTS and COM_DTR for both UART1 (com port)
  285. * and UART3 (radio module). We only handle them for UART1 here.
  286. */
  287. static void assabet_set_mctrl(struct uart_port *port, u_int mctrl)
  288. {
  289. if (port->mapbase == _Ser1UTCR0) {
  290. u_int set = 0, clear = 0;
  291. if (mctrl & TIOCM_RTS)
  292. clear |= ASSABET_BCR_COM_RTS;
  293. else
  294. set |= ASSABET_BCR_COM_RTS;
  295. if (mctrl & TIOCM_DTR)
  296. clear |= ASSABET_BCR_COM_DTR;
  297. else
  298. set |= ASSABET_BCR_COM_DTR;
  299. ASSABET_BCR_clear(clear);
  300. ASSABET_BCR_set(set);
  301. }
  302. }
  303. static u_int assabet_get_mctrl(struct uart_port *port)
  304. {
  305. u_int ret = 0;
  306. u_int bsr = ASSABET_BSR;
  307. /* need 2 reads to read current value */
  308. bsr = ASSABET_BSR;
  309. if (port->mapbase == _Ser1UTCR0) {
  310. if (bsr & ASSABET_BSR_COM_DCD)
  311. ret |= TIOCM_CD;
  312. if (bsr & ASSABET_BSR_COM_CTS)
  313. ret |= TIOCM_CTS;
  314. if (bsr & ASSABET_BSR_COM_DSR)
  315. ret |= TIOCM_DSR;
  316. } else if (port->mapbase == _Ser3UTCR0) {
  317. if (bsr & ASSABET_BSR_RAD_DCD)
  318. ret |= TIOCM_CD;
  319. if (bsr & ASSABET_BSR_RAD_CTS)
  320. ret |= TIOCM_CTS;
  321. if (bsr & ASSABET_BSR_RAD_DSR)
  322. ret |= TIOCM_DSR;
  323. if (bsr & ASSABET_BSR_RAD_RI)
  324. ret |= TIOCM_RI;
  325. } else {
  326. ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  327. }
  328. return ret;
  329. }
  330. static struct sa1100_port_fns assabet_port_fns __initdata = {
  331. .set_mctrl = assabet_set_mctrl,
  332. .get_mctrl = assabet_get_mctrl,
  333. .pm = assabet_uart_pm,
  334. };
  335. static struct map_desc assabet_io_desc[] __initdata = {
  336. /* virtual physical length type */
  337. { 0xf1000000, 0x12000000, 0x00100000, MT_DEVICE }, /* Board Control Register */
  338. { 0xf2800000, 0x4b800000, 0x00800000, MT_DEVICE } /* MQ200 */
  339. };
  340. static void __init assabet_map_io(void)
  341. {
  342. sa1100_map_io();
  343. iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
  344. /*
  345. * Set SUS bit in SDCR0 so serial port 1 functions.
  346. * Its called GPCLKR0 in my SA1110 manual.
  347. */
  348. Ser1SDCR0 |= SDCR0_SUS;
  349. if (machine_has_neponset()) {
  350. #ifdef CONFIG_ASSABET_NEPONSET
  351. extern void neponset_map_io(void);
  352. /*
  353. * We map Neponset registers even if it isn't present since
  354. * many drivers will try to probe their stuff (and fail).
  355. * This is still more friendly than a kernel paging request
  356. * crash.
  357. */
  358. neponset_map_io();
  359. #endif
  360. } else {
  361. sa1100_register_uart_fns(&assabet_port_fns);
  362. }
  363. /*
  364. * When Neponset is attached, the first UART should be
  365. * UART3. That's what Angel is doing and many documents
  366. * are stating this.
  367. *
  368. * We do the Neponset mapping even if Neponset support
  369. * isn't compiled in so the user will still get something on
  370. * the expected physical serial port.
  371. *
  372. * We no longer do this; not all boot loaders support it,
  373. * and UART3 appears to be somewhat unreliable with blob.
  374. */
  375. sa1100_register_uart(0, 1);
  376. sa1100_register_uart(2, 3);
  377. }
  378. MACHINE_START(ASSABET, "Intel-Assabet")
  379. .phys_ram = 0xc0000000,
  380. .phys_io = 0x80000000,
  381. .io_pg_offst = ((0xf8000000) >> 18) & 0xfffc,
  382. .boot_params = 0xc0000100,
  383. .fixup = fixup_assabet,
  384. .map_io = assabet_map_io,
  385. .init_irq = sa1100_init_irq,
  386. .timer = &sa1100_timer,
  387. .init_machine = assabet_init,
  388. MACHINE_END