assabet.c 12 KB

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