assabet.c 13 KB

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