assabet.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 <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 ucb1x00_plat_data assabet_ucb1x00_data = {
  180. .gpio_base = -1,
  181. };
  182. static struct mcp_plat_data assabet_mcp_data = {
  183. .mccr0 = MCCR0_ADM,
  184. .sclk_rate = 11981000,
  185. .codec_pdata = &assabet_ucb1x00_data,
  186. };
  187. static void __init assabet_init(void)
  188. {
  189. /*
  190. * Ensure that the power supply is in "high power" mode.
  191. */
  192. GPDR |= GPIO_GPIO16;
  193. GPSR = GPIO_GPIO16;
  194. /*
  195. * Ensure that these pins are set as outputs and are driving
  196. * logic 0. This ensures that we won't inadvertently toggle
  197. * the WS latch in the CPLD, and we don't float causing
  198. * excessive power drain. --rmk
  199. */
  200. GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
  201. GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
  202. /*
  203. * Set up registers for sleep mode.
  204. */
  205. PWER = PWER_GPIO0;
  206. PGSR = 0;
  207. PCFR = 0;
  208. PSDR = 0;
  209. PPDR |= PPC_TXD3 | PPC_TXD1;
  210. PPSR |= PPC_TXD3 | PPC_TXD1;
  211. sa11x0_ppc_configure_mcp();
  212. sa1100fb_lcd_power = assabet_lcd_power;
  213. sa1100fb_backlight_power = assabet_backlight_power;
  214. if (machine_has_neponset()) {
  215. /*
  216. * Angel sets this, but other bootloaders may not.
  217. *
  218. * This must precede any driver calls to BCR_set()
  219. * or BCR_clear().
  220. */
  221. ASSABET_BCR = BCR_value = ASSABET_BCR_DB1111;
  222. #ifndef CONFIG_ASSABET_NEPONSET
  223. printk( "Warning: Neponset detected but full support "
  224. "hasn't been configured in the kernel\n" );
  225. #endif
  226. }
  227. sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
  228. ARRAY_SIZE(assabet_flash_resources));
  229. sa11x0_register_irda(&assabet_irda_data);
  230. sa11x0_register_mcp(&assabet_mcp_data);
  231. }
  232. /*
  233. * On Assabet, we must probe for the Neponset board _before_
  234. * paging_init() has occurred to actually determine the amount
  235. * of RAM available. To do so, we map the appropriate IO section
  236. * in the page table here in order to access GPIO registers.
  237. */
  238. static void __init map_sa1100_gpio_regs( void )
  239. {
  240. unsigned long phys = __PREG(GPLR) & PMD_MASK;
  241. unsigned long virt = io_p2v(phys);
  242. int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
  243. pmd_t *pmd;
  244. pmd = pmd_offset(pud_offset(pgd_offset_k(virt), virt), virt);
  245. *pmd = __pmd(phys | prot);
  246. flush_pmd_entry(pmd);
  247. }
  248. /*
  249. * Read System Configuration "Register"
  250. * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
  251. * User's Guide", section 4.4.1)
  252. *
  253. * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
  254. * to set up the serial port for decompression status messages. We
  255. * repeat it here because the kernel may not be loaded as a zImage, and
  256. * also because it's a hassle to communicate the SCR value to the kernel
  257. * from the decompressor.
  258. *
  259. * Note that IRQs are guaranteed to be disabled.
  260. */
  261. static void __init get_assabet_scr(void)
  262. {
  263. unsigned long scr, i;
  264. GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
  265. GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
  266. GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
  267. for(i = 100; i--; ) /* Read GPIO 9:2 */
  268. scr = GPLR;
  269. GPDR |= 0x3fc; /* restore correct pin direction */
  270. scr &= 0x3fc; /* save as system configuration byte. */
  271. SCR_value = scr;
  272. }
  273. static void __init
  274. fixup_assabet(struct tag *tags, char **cmdline, struct meminfo *mi)
  275. {
  276. /* This must be done before any call to machine_has_neponset() */
  277. map_sa1100_gpio_regs();
  278. get_assabet_scr();
  279. if (machine_has_neponset())
  280. printk("Neponset expansion board detected\n");
  281. }
  282. static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  283. {
  284. if (port->mapbase == _Ser1UTCR0) {
  285. if (state)
  286. ASSABET_BCR_clear(ASSABET_BCR_RS232EN |
  287. ASSABET_BCR_COM_RTS |
  288. ASSABET_BCR_COM_DTR);
  289. else
  290. ASSABET_BCR_set(ASSABET_BCR_RS232EN |
  291. ASSABET_BCR_COM_RTS |
  292. ASSABET_BCR_COM_DTR);
  293. }
  294. }
  295. /*
  296. * Assabet uses COM_RTS and COM_DTR for both UART1 (com port)
  297. * and UART3 (radio module). We only handle them for UART1 here.
  298. */
  299. static void assabet_set_mctrl(struct uart_port *port, u_int mctrl)
  300. {
  301. if (port->mapbase == _Ser1UTCR0) {
  302. u_int set = 0, clear = 0;
  303. if (mctrl & TIOCM_RTS)
  304. clear |= ASSABET_BCR_COM_RTS;
  305. else
  306. set |= ASSABET_BCR_COM_RTS;
  307. if (mctrl & TIOCM_DTR)
  308. clear |= ASSABET_BCR_COM_DTR;
  309. else
  310. set |= ASSABET_BCR_COM_DTR;
  311. ASSABET_BCR_clear(clear);
  312. ASSABET_BCR_set(set);
  313. }
  314. }
  315. static u_int assabet_get_mctrl(struct uart_port *port)
  316. {
  317. u_int ret = 0;
  318. u_int bsr = ASSABET_BSR;
  319. /* need 2 reads to read current value */
  320. bsr = ASSABET_BSR;
  321. if (port->mapbase == _Ser1UTCR0) {
  322. if (bsr & ASSABET_BSR_COM_DCD)
  323. ret |= TIOCM_CD;
  324. if (bsr & ASSABET_BSR_COM_CTS)
  325. ret |= TIOCM_CTS;
  326. if (bsr & ASSABET_BSR_COM_DSR)
  327. ret |= TIOCM_DSR;
  328. } else if (port->mapbase == _Ser3UTCR0) {
  329. if (bsr & ASSABET_BSR_RAD_DCD)
  330. ret |= TIOCM_CD;
  331. if (bsr & ASSABET_BSR_RAD_CTS)
  332. ret |= TIOCM_CTS;
  333. if (bsr & ASSABET_BSR_RAD_DSR)
  334. ret |= TIOCM_DSR;
  335. if (bsr & ASSABET_BSR_RAD_RI)
  336. ret |= TIOCM_RI;
  337. } else {
  338. ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  339. }
  340. return ret;
  341. }
  342. static struct sa1100_port_fns assabet_port_fns __initdata = {
  343. .set_mctrl = assabet_set_mctrl,
  344. .get_mctrl = assabet_get_mctrl,
  345. .pm = assabet_uart_pm,
  346. };
  347. static struct map_desc assabet_io_desc[] __initdata = {
  348. { /* Board Control Register */
  349. .virtual = 0xf1000000,
  350. .pfn = __phys_to_pfn(0x12000000),
  351. .length = 0x00100000,
  352. .type = MT_DEVICE
  353. }, { /* MQ200 */
  354. .virtual = 0xf2800000,
  355. .pfn = __phys_to_pfn(0x4b800000),
  356. .length = 0x00800000,
  357. .type = MT_DEVICE
  358. }
  359. };
  360. static void __init assabet_map_io(void)
  361. {
  362. sa1100_map_io();
  363. iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
  364. /*
  365. * Set SUS bit in SDCR0 so serial port 1 functions.
  366. * Its called GPCLKR0 in my SA1110 manual.
  367. */
  368. Ser1SDCR0 |= SDCR0_SUS;
  369. if (machine_has_neponset()) {
  370. #ifdef CONFIG_ASSABET_NEPONSET
  371. extern void neponset_map_io(void);
  372. /*
  373. * We map Neponset registers even if it isn't present since
  374. * many drivers will try to probe their stuff (and fail).
  375. * This is still more friendly than a kernel paging request
  376. * crash.
  377. */
  378. neponset_map_io();
  379. #endif
  380. } else {
  381. sa1100_register_uart_fns(&assabet_port_fns);
  382. }
  383. /*
  384. * When Neponset is attached, the first UART should be
  385. * UART3. That's what Angel is doing and many documents
  386. * are stating this.
  387. *
  388. * We do the Neponset mapping even if Neponset support
  389. * isn't compiled in so the user will still get something on
  390. * the expected physical serial port.
  391. *
  392. * We no longer do this; not all boot loaders support it,
  393. * and UART3 appears to be somewhat unreliable with blob.
  394. */
  395. sa1100_register_uart(0, 1);
  396. sa1100_register_uart(2, 3);
  397. }
  398. MACHINE_START(ASSABET, "Intel-Assabet")
  399. .atag_offset = 0x100,
  400. .fixup = fixup_assabet,
  401. .map_io = assabet_map_io,
  402. .init_irq = sa1100_init_irq,
  403. .timer = &sa1100_timer,
  404. .init_machine = assabet_init,
  405. #ifdef CONFIG_SA1111
  406. .dma_zone_size = SZ_1M,
  407. #endif
  408. .restart = sa11x0_restart,
  409. MACHINE_END