assabet.c 13 KB

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