core.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /*
  2. * linux/arch/arm/mach-versatile/core.c
  3. *
  4. * Copyright (C) 1999 - 2003 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/config.h>
  22. #include <linux/init.h>
  23. #include <linux/device.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/interrupt.h>
  27. #include <asm/system.h>
  28. #include <asm/hardware.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/leds.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/hardware/amba.h>
  34. #include <asm/hardware/amba_clcd.h>
  35. #include <asm/hardware/icst307.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/flash.h>
  38. #include <asm/mach/irq.h>
  39. #include <asm/mach/time.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/mmc.h>
  42. #include "core.h"
  43. #include "clock.h"
  44. /*
  45. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  46. * is the (PA >> 12).
  47. *
  48. * Setup a VA for the Versatile Vectored Interrupt Controller.
  49. */
  50. #define VA_VIC_BASE IO_ADDRESS(VERSATILE_VIC_BASE)
  51. #define VA_SIC_BASE IO_ADDRESS(VERSATILE_SIC_BASE)
  52. static void vic_mask_irq(unsigned int irq)
  53. {
  54. irq -= IRQ_VIC_START;
  55. writel(1 << irq, VA_VIC_BASE + VIC_IRQ_ENABLE_CLEAR);
  56. }
  57. static void vic_unmask_irq(unsigned int irq)
  58. {
  59. irq -= IRQ_VIC_START;
  60. writel(1 << irq, VA_VIC_BASE + VIC_IRQ_ENABLE);
  61. }
  62. static struct irqchip vic_chip = {
  63. .ack = vic_mask_irq,
  64. .mask = vic_mask_irq,
  65. .unmask = vic_unmask_irq,
  66. };
  67. static void sic_mask_irq(unsigned int irq)
  68. {
  69. irq -= IRQ_SIC_START;
  70. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  71. }
  72. static void sic_unmask_irq(unsigned int irq)
  73. {
  74. irq -= IRQ_SIC_START;
  75. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_SET);
  76. }
  77. static struct irqchip sic_chip = {
  78. .ack = sic_mask_irq,
  79. .mask = sic_mask_irq,
  80. .unmask = sic_unmask_irq,
  81. };
  82. static void
  83. sic_handle_irq(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  84. {
  85. unsigned long status = readl(VA_SIC_BASE + SIC_IRQ_STATUS);
  86. if (status == 0) {
  87. do_bad_IRQ(irq, desc, regs);
  88. return;
  89. }
  90. do {
  91. irq = ffs(status) - 1;
  92. status &= ~(1 << irq);
  93. irq += IRQ_SIC_START;
  94. desc = irq_desc + irq;
  95. desc->handle(irq, desc, regs);
  96. } while (status);
  97. }
  98. #if 1
  99. #define IRQ_MMCI0A IRQ_VICSOURCE22
  100. #define IRQ_AACI IRQ_VICSOURCE24
  101. #define IRQ_ETH IRQ_VICSOURCE25
  102. #define PIC_MASK 0xFFD00000
  103. #else
  104. #define IRQ_MMCI0A IRQ_SIC_MMCI0A
  105. #define IRQ_AACI IRQ_SIC_AACI
  106. #define IRQ_ETH IRQ_SIC_ETH
  107. #define PIC_MASK 0
  108. #endif
  109. void __init versatile_init_irq(void)
  110. {
  111. unsigned int i, value;
  112. /* Disable all interrupts initially. */
  113. writel(0, VA_VIC_BASE + VIC_INT_SELECT);
  114. writel(0, VA_VIC_BASE + VIC_IRQ_ENABLE);
  115. writel(~0, VA_VIC_BASE + VIC_IRQ_ENABLE_CLEAR);
  116. writel(0, VA_VIC_BASE + VIC_IRQ_STATUS);
  117. writel(0, VA_VIC_BASE + VIC_ITCR);
  118. writel(~0, VA_VIC_BASE + VIC_IRQ_SOFT_CLEAR);
  119. /*
  120. * Make sure we clear all existing interrupts
  121. */
  122. writel(0, VA_VIC_BASE + VIC_VECT_ADDR);
  123. for (i = 0; i < 19; i++) {
  124. value = readl(VA_VIC_BASE + VIC_VECT_ADDR);
  125. writel(value, VA_VIC_BASE + VIC_VECT_ADDR);
  126. }
  127. for (i = 0; i < 16; i++) {
  128. value = readl(VA_VIC_BASE + VIC_VECT_CNTL0 + (i * 4));
  129. writel(value | VICVectCntl_Enable | i, VA_VIC_BASE + VIC_VECT_CNTL0 + (i * 4));
  130. }
  131. writel(32, VA_VIC_BASE + VIC_DEF_VECT_ADDR);
  132. for (i = IRQ_VIC_START; i <= IRQ_VIC_END; i++) {
  133. if (i != IRQ_VICSOURCE31) {
  134. set_irq_chip(i, &vic_chip);
  135. set_irq_handler(i, do_level_IRQ);
  136. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  137. }
  138. }
  139. set_irq_handler(IRQ_VICSOURCE31, sic_handle_irq);
  140. vic_unmask_irq(IRQ_VICSOURCE31);
  141. /* Do second interrupt controller */
  142. writel(~0, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  143. for (i = IRQ_SIC_START; i <= IRQ_SIC_END; i++) {
  144. if ((PIC_MASK & (1 << (i - IRQ_SIC_START))) == 0) {
  145. set_irq_chip(i, &sic_chip);
  146. set_irq_handler(i, do_level_IRQ);
  147. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  148. }
  149. }
  150. /*
  151. * Interrupts on secondary controller from 0 to 8 are routed to
  152. * source 31 on PIC.
  153. * Interrupts from 21 to 31 are routed directly to the VIC on
  154. * the corresponding number on primary controller. This is controlled
  155. * by setting PIC_ENABLEx.
  156. */
  157. writel(PIC_MASK, VA_SIC_BASE + SIC_INT_PIC_ENABLE);
  158. }
  159. static struct map_desc versatile_io_desc[] __initdata = {
  160. { IO_ADDRESS(VERSATILE_SYS_BASE), VERSATILE_SYS_BASE, SZ_4K, MT_DEVICE },
  161. { IO_ADDRESS(VERSATILE_SIC_BASE), VERSATILE_SIC_BASE, SZ_4K, MT_DEVICE },
  162. { IO_ADDRESS(VERSATILE_VIC_BASE), VERSATILE_VIC_BASE, SZ_4K, MT_DEVICE },
  163. { IO_ADDRESS(VERSATILE_SCTL_BASE), VERSATILE_SCTL_BASE, SZ_4K * 9, MT_DEVICE },
  164. #ifdef CONFIG_MACH_VERSATILE_AB
  165. { IO_ADDRESS(VERSATILE_GPIO0_BASE), VERSATILE_GPIO0_BASE, SZ_4K, MT_DEVICE },
  166. { IO_ADDRESS(VERSATILE_IB2_BASE), VERSATILE_IB2_BASE, SZ_64M, MT_DEVICE },
  167. #endif
  168. #ifdef CONFIG_DEBUG_LL
  169. { IO_ADDRESS(VERSATILE_UART0_BASE), VERSATILE_UART0_BASE, SZ_4K, MT_DEVICE },
  170. #endif
  171. #ifdef FIXME
  172. { PCI_MEMORY_VADDR, PHYS_PCI_MEM_BASE, SZ_16M, MT_DEVICE },
  173. { PCI_CONFIG_VADDR, PHYS_PCI_CONFIG_BASE, SZ_16M, MT_DEVICE },
  174. { PCI_V3_VADDR, PHYS_PCI_V3_BASE, SZ_512K, MT_DEVICE },
  175. { PCI_IO_VADDR, PHYS_PCI_IO_BASE, SZ_64K, MT_DEVICE },
  176. #endif
  177. };
  178. void __init versatile_map_io(void)
  179. {
  180. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  181. }
  182. #define VERSATILE_REFCOUNTER (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_24MHz_OFFSET)
  183. /*
  184. * This is the Versatile sched_clock implementation. This has
  185. * a resolution of 41.7ns, and a maximum value of about 179s.
  186. */
  187. unsigned long long sched_clock(void)
  188. {
  189. unsigned long long v;
  190. v = (unsigned long long)readl(VERSATILE_REFCOUNTER) * 125;
  191. do_div(v, 3);
  192. return v;
  193. }
  194. #define VERSATILE_FLASHCTRL (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
  195. static int versatile_flash_init(void)
  196. {
  197. u32 val;
  198. val = __raw_readl(VERSATILE_FLASHCTRL);
  199. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  200. __raw_writel(val, VERSATILE_FLASHCTRL);
  201. return 0;
  202. }
  203. static void versatile_flash_exit(void)
  204. {
  205. u32 val;
  206. val = __raw_readl(VERSATILE_FLASHCTRL);
  207. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  208. __raw_writel(val, VERSATILE_FLASHCTRL);
  209. }
  210. static void versatile_flash_set_vpp(int on)
  211. {
  212. u32 val;
  213. val = __raw_readl(VERSATILE_FLASHCTRL);
  214. if (on)
  215. val |= VERSATILE_FLASHPROG_FLVPPEN;
  216. else
  217. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  218. __raw_writel(val, VERSATILE_FLASHCTRL);
  219. }
  220. static struct flash_platform_data versatile_flash_data = {
  221. .map_name = "cfi_probe",
  222. .width = 4,
  223. .init = versatile_flash_init,
  224. .exit = versatile_flash_exit,
  225. .set_vpp = versatile_flash_set_vpp,
  226. };
  227. static struct resource versatile_flash_resource = {
  228. .start = VERSATILE_FLASH_BASE,
  229. .end = VERSATILE_FLASH_BASE + VERSATILE_FLASH_SIZE,
  230. .flags = IORESOURCE_MEM,
  231. };
  232. static struct platform_device versatile_flash_device = {
  233. .name = "armflash",
  234. .id = 0,
  235. .dev = {
  236. .platform_data = &versatile_flash_data,
  237. },
  238. .num_resources = 1,
  239. .resource = &versatile_flash_resource,
  240. };
  241. static struct resource smc91x_resources[] = {
  242. [0] = {
  243. .start = VERSATILE_ETH_BASE,
  244. .end = VERSATILE_ETH_BASE + SZ_64K - 1,
  245. .flags = IORESOURCE_MEM,
  246. },
  247. [1] = {
  248. .start = IRQ_ETH,
  249. .end = IRQ_ETH,
  250. .flags = IORESOURCE_IRQ,
  251. },
  252. };
  253. static struct platform_device smc91x_device = {
  254. .name = "smc91x",
  255. .id = 0,
  256. .num_resources = ARRAY_SIZE(smc91x_resources),
  257. .resource = smc91x_resources,
  258. };
  259. #define VERSATILE_SYSMCI (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
  260. unsigned int mmc_status(struct device *dev)
  261. {
  262. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  263. u32 mask;
  264. if (adev->res.start == VERSATILE_MMCI0_BASE)
  265. mask = 1;
  266. else
  267. mask = 2;
  268. return readl(VERSATILE_SYSMCI) & mask;
  269. }
  270. static struct mmc_platform_data mmc0_plat_data = {
  271. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  272. .status = mmc_status,
  273. };
  274. /*
  275. * Clock handling
  276. */
  277. static const struct icst307_params versatile_oscvco_params = {
  278. .ref = 24000,
  279. .vco_max = 200000,
  280. .vd_min = 4 + 8,
  281. .vd_max = 511 + 8,
  282. .rd_min = 1 + 2,
  283. .rd_max = 127 + 2,
  284. };
  285. static void versatile_oscvco_set(struct clk *clk, struct icst307_vco vco)
  286. {
  287. unsigned long sys_lock = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_LOCK_OFFSET;
  288. #if defined(CONFIG_ARCH_VERSATILE_PB)
  289. unsigned long sys_osc = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_OSC4_OFFSET;
  290. #elif defined(CONFIG_MACH_VERSATILE_AB)
  291. unsigned long sys_osc = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_OSC1_OFFSET;
  292. #endif
  293. u32 val;
  294. val = readl(sys_osc) & ~0x7ffff;
  295. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  296. writel(0xa05f, sys_lock);
  297. writel(val, sys_osc);
  298. writel(0, sys_lock);
  299. }
  300. static struct clk versatile_clcd_clk = {
  301. .name = "CLCDCLK",
  302. .params = &versatile_oscvco_params,
  303. .setvco = versatile_oscvco_set,
  304. };
  305. /*
  306. * CLCD support.
  307. */
  308. #define SYS_CLCD_MODE_MASK (3 << 0)
  309. #define SYS_CLCD_MODE_888 (0 << 0)
  310. #define SYS_CLCD_MODE_5551 (1 << 0)
  311. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  312. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  313. #define SYS_CLCD_NLCDIOON (1 << 2)
  314. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  315. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  316. #define SYS_CLCD_ID_MASK (0x1f << 8)
  317. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  318. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  319. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  320. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  321. #define SYS_CLCD_ID_VGA (0x1f << 8)
  322. static struct clcd_panel vga = {
  323. .mode = {
  324. .name = "VGA",
  325. .refresh = 60,
  326. .xres = 640,
  327. .yres = 480,
  328. .pixclock = 39721,
  329. .left_margin = 40,
  330. .right_margin = 24,
  331. .upper_margin = 32,
  332. .lower_margin = 11,
  333. .hsync_len = 96,
  334. .vsync_len = 2,
  335. .sync = 0,
  336. .vmode = FB_VMODE_NONINTERLACED,
  337. },
  338. .width = -1,
  339. .height = -1,
  340. .tim2 = TIM2_BCD | TIM2_IPC,
  341. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  342. .bpp = 16,
  343. };
  344. static struct clcd_panel sanyo_3_8_in = {
  345. .mode = {
  346. .name = "Sanyo QVGA",
  347. .refresh = 116,
  348. .xres = 320,
  349. .yres = 240,
  350. .pixclock = 100000,
  351. .left_margin = 6,
  352. .right_margin = 6,
  353. .upper_margin = 5,
  354. .lower_margin = 5,
  355. .hsync_len = 6,
  356. .vsync_len = 6,
  357. .sync = 0,
  358. .vmode = FB_VMODE_NONINTERLACED,
  359. },
  360. .width = -1,
  361. .height = -1,
  362. .tim2 = TIM2_BCD,
  363. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  364. .bpp = 16,
  365. };
  366. static struct clcd_panel sanyo_2_5_in = {
  367. .mode = {
  368. .name = "Sanyo QVGA Portrait",
  369. .refresh = 116,
  370. .xres = 240,
  371. .yres = 320,
  372. .pixclock = 100000,
  373. .left_margin = 20,
  374. .right_margin = 10,
  375. .upper_margin = 2,
  376. .lower_margin = 2,
  377. .hsync_len = 10,
  378. .vsync_len = 2,
  379. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  380. .vmode = FB_VMODE_NONINTERLACED,
  381. },
  382. .width = -1,
  383. .height = -1,
  384. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  385. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  386. .bpp = 16,
  387. };
  388. static struct clcd_panel epson_2_2_in = {
  389. .mode = {
  390. .name = "Epson QCIF",
  391. .refresh = 390,
  392. .xres = 176,
  393. .yres = 220,
  394. .pixclock = 62500,
  395. .left_margin = 3,
  396. .right_margin = 2,
  397. .upper_margin = 1,
  398. .lower_margin = 0,
  399. .hsync_len = 3,
  400. .vsync_len = 2,
  401. .sync = 0,
  402. .vmode = FB_VMODE_NONINTERLACED,
  403. },
  404. .width = -1,
  405. .height = -1,
  406. .tim2 = TIM2_BCD | TIM2_IPC,
  407. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  408. .bpp = 16,
  409. };
  410. /*
  411. * Detect which LCD panel is connected, and return the appropriate
  412. * clcd_panel structure. Note: we do not have any information on
  413. * the required timings for the 8.4in panel, so we presently assume
  414. * VGA timings.
  415. */
  416. static struct clcd_panel *versatile_clcd_panel(void)
  417. {
  418. unsigned long sys_clcd = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  419. struct clcd_panel *panel = &vga;
  420. u32 val;
  421. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  422. if (val == SYS_CLCD_ID_SANYO_3_8)
  423. panel = &sanyo_3_8_in;
  424. else if (val == SYS_CLCD_ID_SANYO_2_5)
  425. panel = &sanyo_2_5_in;
  426. else if (val == SYS_CLCD_ID_EPSON_2_2)
  427. panel = &epson_2_2_in;
  428. else if (val == SYS_CLCD_ID_VGA)
  429. panel = &vga;
  430. else {
  431. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  432. val);
  433. panel = &vga;
  434. }
  435. return panel;
  436. }
  437. /*
  438. * Disable all display connectors on the interface module.
  439. */
  440. static void versatile_clcd_disable(struct clcd_fb *fb)
  441. {
  442. unsigned long sys_clcd = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  443. u32 val;
  444. val = readl(sys_clcd);
  445. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  446. writel(val, sys_clcd);
  447. #ifdef CONFIG_MACH_VERSATILE_AB
  448. /*
  449. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light off
  450. */
  451. if (fb->panel == &sanyo_2_5_in) {
  452. unsigned long versatile_ib2_ctrl = IO_ADDRESS(VERSATILE_IB2_CTRL);
  453. unsigned long ctrl;
  454. ctrl = readl(versatile_ib2_ctrl);
  455. ctrl &= ~0x01;
  456. writel(ctrl, versatile_ib2_ctrl);
  457. }
  458. #endif
  459. }
  460. /*
  461. * Enable the relevant connector on the interface module.
  462. */
  463. static void versatile_clcd_enable(struct clcd_fb *fb)
  464. {
  465. unsigned long sys_clcd = IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  466. u32 val;
  467. val = readl(sys_clcd);
  468. val &= ~SYS_CLCD_MODE_MASK;
  469. switch (fb->fb.var.green.length) {
  470. case 5:
  471. val |= SYS_CLCD_MODE_5551;
  472. break;
  473. case 6:
  474. val |= SYS_CLCD_MODE_565_RLSB;
  475. break;
  476. case 8:
  477. val |= SYS_CLCD_MODE_888;
  478. break;
  479. }
  480. /*
  481. * Set the MUX
  482. */
  483. writel(val, sys_clcd);
  484. /*
  485. * And now enable the PSUs
  486. */
  487. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  488. writel(val, sys_clcd);
  489. #ifdef CONFIG_MACH_VERSATILE_AB
  490. /*
  491. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light on
  492. */
  493. if (fb->panel == &sanyo_2_5_in) {
  494. unsigned long versatile_ib2_ctrl = IO_ADDRESS(VERSATILE_IB2_CTRL);
  495. unsigned long ctrl;
  496. ctrl = readl(versatile_ib2_ctrl);
  497. ctrl |= 0x01;
  498. writel(ctrl, versatile_ib2_ctrl);
  499. }
  500. #endif
  501. }
  502. static unsigned long framesize = SZ_1M;
  503. static int versatile_clcd_setup(struct clcd_fb *fb)
  504. {
  505. dma_addr_t dma;
  506. fb->panel = versatile_clcd_panel();
  507. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  508. &dma, GFP_KERNEL);
  509. if (!fb->fb.screen_base) {
  510. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  511. return -ENOMEM;
  512. }
  513. fb->fb.fix.smem_start = dma;
  514. fb->fb.fix.smem_len = framesize;
  515. return 0;
  516. }
  517. static int versatile_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  518. {
  519. return dma_mmap_writecombine(&fb->dev->dev, vma,
  520. fb->fb.screen_base,
  521. fb->fb.fix.smem_start,
  522. fb->fb.fix.smem_len);
  523. }
  524. static void versatile_clcd_remove(struct clcd_fb *fb)
  525. {
  526. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  527. fb->fb.screen_base, fb->fb.fix.smem_start);
  528. }
  529. static struct clcd_board clcd_plat_data = {
  530. .name = "Versatile",
  531. .check = clcdfb_check,
  532. .decode = clcdfb_decode,
  533. .disable = versatile_clcd_disable,
  534. .enable = versatile_clcd_enable,
  535. .setup = versatile_clcd_setup,
  536. .mmap = versatile_clcd_mmap,
  537. .remove = versatile_clcd_remove,
  538. };
  539. #define AACI_IRQ { IRQ_AACI, NO_IRQ }
  540. #define AACI_DMA { 0x80, 0x81 }
  541. #define MMCI0_IRQ { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
  542. #define MMCI0_DMA { 0x84, 0 }
  543. #define KMI0_IRQ { IRQ_SIC_KMI0, NO_IRQ }
  544. #define KMI0_DMA { 0, 0 }
  545. #define KMI1_IRQ { IRQ_SIC_KMI1, NO_IRQ }
  546. #define KMI1_DMA { 0, 0 }
  547. /*
  548. * These devices are connected directly to the multi-layer AHB switch
  549. */
  550. #define SMC_IRQ { NO_IRQ, NO_IRQ }
  551. #define SMC_DMA { 0, 0 }
  552. #define MPMC_IRQ { NO_IRQ, NO_IRQ }
  553. #define MPMC_DMA { 0, 0 }
  554. #define CLCD_IRQ { IRQ_CLCDINT, NO_IRQ }
  555. #define CLCD_DMA { 0, 0 }
  556. #define DMAC_IRQ { IRQ_DMAINT, NO_IRQ }
  557. #define DMAC_DMA { 0, 0 }
  558. /*
  559. * These devices are connected via the core APB bridge
  560. */
  561. #define SCTL_IRQ { NO_IRQ, NO_IRQ }
  562. #define SCTL_DMA { 0, 0 }
  563. #define WATCHDOG_IRQ { IRQ_WDOGINT, NO_IRQ }
  564. #define WATCHDOG_DMA { 0, 0 }
  565. #define GPIO0_IRQ { IRQ_GPIOINT0, NO_IRQ }
  566. #define GPIO0_DMA { 0, 0 }
  567. #define GPIO1_IRQ { IRQ_GPIOINT1, NO_IRQ }
  568. #define GPIO1_DMA { 0, 0 }
  569. #define RTC_IRQ { IRQ_RTCINT, NO_IRQ }
  570. #define RTC_DMA { 0, 0 }
  571. /*
  572. * These devices are connected via the DMA APB bridge
  573. */
  574. #define SCI_IRQ { IRQ_SCIINT, NO_IRQ }
  575. #define SCI_DMA { 7, 6 }
  576. #define UART0_IRQ { IRQ_UARTINT0, NO_IRQ }
  577. #define UART0_DMA { 15, 14 }
  578. #define UART1_IRQ { IRQ_UARTINT1, NO_IRQ }
  579. #define UART1_DMA { 13, 12 }
  580. #define UART2_IRQ { IRQ_UARTINT2, NO_IRQ }
  581. #define UART2_DMA { 11, 10 }
  582. #define SSP_IRQ { IRQ_SSPINT, NO_IRQ }
  583. #define SSP_DMA { 9, 8 }
  584. /* FPGA Primecells */
  585. AMBA_DEVICE(aaci, "fpga:04", AACI, NULL);
  586. AMBA_DEVICE(mmc0, "fpga:05", MMCI0, &mmc0_plat_data);
  587. AMBA_DEVICE(kmi0, "fpga:06", KMI0, NULL);
  588. AMBA_DEVICE(kmi1, "fpga:07", KMI1, NULL);
  589. /* DevChip Primecells */
  590. AMBA_DEVICE(smc, "dev:00", SMC, NULL);
  591. AMBA_DEVICE(mpmc, "dev:10", MPMC, NULL);
  592. AMBA_DEVICE(clcd, "dev:20", CLCD, &clcd_plat_data);
  593. AMBA_DEVICE(dmac, "dev:30", DMAC, NULL);
  594. AMBA_DEVICE(sctl, "dev:e0", SCTL, NULL);
  595. AMBA_DEVICE(wdog, "dev:e1", WATCHDOG, NULL);
  596. AMBA_DEVICE(gpio0, "dev:e4", GPIO0, NULL);
  597. AMBA_DEVICE(gpio1, "dev:e5", GPIO1, NULL);
  598. AMBA_DEVICE(rtc, "dev:e8", RTC, NULL);
  599. AMBA_DEVICE(sci0, "dev:f0", SCI, NULL);
  600. AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  601. AMBA_DEVICE(uart1, "dev:f2", UART1, NULL);
  602. AMBA_DEVICE(uart2, "dev:f3", UART2, NULL);
  603. AMBA_DEVICE(ssp0, "dev:f4", SSP, NULL);
  604. static struct amba_device *amba_devs[] __initdata = {
  605. &dmac_device,
  606. &uart0_device,
  607. &uart1_device,
  608. &uart2_device,
  609. &smc_device,
  610. &mpmc_device,
  611. &clcd_device,
  612. &sctl_device,
  613. &wdog_device,
  614. &gpio0_device,
  615. &gpio1_device,
  616. &rtc_device,
  617. &sci0_device,
  618. &ssp0_device,
  619. &aaci_device,
  620. &mmc0_device,
  621. &kmi0_device,
  622. &kmi1_device,
  623. };
  624. #ifdef CONFIG_LEDS
  625. #define VA_LEDS_BASE (IO_ADDRESS(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
  626. static void versatile_leds_event(led_event_t ledevt)
  627. {
  628. unsigned long flags;
  629. u32 val;
  630. local_irq_save(flags);
  631. val = readl(VA_LEDS_BASE);
  632. switch (ledevt) {
  633. case led_idle_start:
  634. val = val & ~VERSATILE_SYS_LED0;
  635. break;
  636. case led_idle_end:
  637. val = val | VERSATILE_SYS_LED0;
  638. break;
  639. case led_timer:
  640. val = val ^ VERSATILE_SYS_LED1;
  641. break;
  642. case led_halted:
  643. val = 0;
  644. break;
  645. default:
  646. break;
  647. }
  648. writel(val, VA_LEDS_BASE);
  649. local_irq_restore(flags);
  650. }
  651. #endif /* CONFIG_LEDS */
  652. void __init versatile_init(void)
  653. {
  654. int i;
  655. clk_register(&versatile_clcd_clk);
  656. platform_device_register(&versatile_flash_device);
  657. platform_device_register(&smc91x_device);
  658. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  659. struct amba_device *d = amba_devs[i];
  660. amba_device_register(d, &iomem_resource);
  661. }
  662. #ifdef CONFIG_LEDS
  663. leds_event = versatile_leds_event;
  664. #endif
  665. }
  666. /*
  667. * Where is the timer (VA)?
  668. */
  669. #define TIMER0_VA_BASE IO_ADDRESS(VERSATILE_TIMER0_1_BASE)
  670. #define TIMER1_VA_BASE (IO_ADDRESS(VERSATILE_TIMER0_1_BASE) + 0x20)
  671. #define TIMER2_VA_BASE IO_ADDRESS(VERSATILE_TIMER2_3_BASE)
  672. #define TIMER3_VA_BASE (IO_ADDRESS(VERSATILE_TIMER2_3_BASE) + 0x20)
  673. #define VA_IC_BASE IO_ADDRESS(VERSATILE_VIC_BASE)
  674. /*
  675. * How long is the timer interval?
  676. */
  677. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  678. #if TIMER_INTERVAL >= 0x100000
  679. #define TIMER_RELOAD (TIMER_INTERVAL >> 8) /* Divide by 256 */
  680. #define TIMER_CTRL 0x88 /* Enable, Clock / 256 */
  681. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  682. #elif TIMER_INTERVAL >= 0x10000
  683. #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
  684. #define TIMER_CTRL 0x84 /* Enable, Clock / 16 */
  685. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  686. #else
  687. #define TIMER_RELOAD (TIMER_INTERVAL)
  688. #define TIMER_CTRL 0x80 /* Enable */
  689. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  690. #endif
  691. #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable */
  692. /*
  693. * What does it look like?
  694. */
  695. typedef struct TimerStruct {
  696. unsigned long TimerLoad;
  697. unsigned long TimerValue;
  698. unsigned long TimerControl;
  699. unsigned long TimerClear;
  700. } TimerStruct_t;
  701. /*
  702. * Returns number of ms since last clock interrupt. Note that interrupts
  703. * will have been disabled by do_gettimeoffset()
  704. */
  705. static unsigned long versatile_gettimeoffset(void)
  706. {
  707. volatile TimerStruct_t *timer0 = (TimerStruct_t *)TIMER0_VA_BASE;
  708. unsigned long ticks1, ticks2, status;
  709. /*
  710. * Get the current number of ticks. Note that there is a race
  711. * condition between us reading the timer and checking for
  712. * an interrupt. We get around this by ensuring that the
  713. * counter has not reloaded between our two reads.
  714. */
  715. ticks2 = timer0->TimerValue & 0xffff;
  716. do {
  717. ticks1 = ticks2;
  718. status = __raw_readl(VA_IC_BASE + VIC_IRQ_RAW_STATUS);
  719. ticks2 = timer0->TimerValue & 0xffff;
  720. } while (ticks2 > ticks1);
  721. /*
  722. * Number of ticks since last interrupt.
  723. */
  724. ticks1 = TIMER_RELOAD - ticks2;
  725. /*
  726. * Interrupt pending? If so, we've reloaded once already.
  727. *
  728. * FIXME: Need to check this is effectively timer 0 that expires
  729. */
  730. if (status & IRQMASK_TIMERINT0_1)
  731. ticks1 += TIMER_RELOAD;
  732. /*
  733. * Convert the ticks to usecs
  734. */
  735. return TICKS2USECS(ticks1);
  736. }
  737. /*
  738. * IRQ handler for the timer
  739. */
  740. static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  741. {
  742. volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE;
  743. write_seqlock(&xtime_lock);
  744. // ...clear the interrupt
  745. timer0->TimerClear = 1;
  746. timer_tick(regs);
  747. write_sequnlock(&xtime_lock);
  748. return IRQ_HANDLED;
  749. }
  750. static struct irqaction versatile_timer_irq = {
  751. .name = "Versatile Timer Tick",
  752. .flags = SA_INTERRUPT,
  753. .handler = versatile_timer_interrupt
  754. };
  755. /*
  756. * Set up timer interrupt, and return the current time in seconds.
  757. */
  758. static void __init versatile_timer_init(void)
  759. {
  760. volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE;
  761. volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
  762. volatile TimerStruct_t *timer2 = (volatile TimerStruct_t *)TIMER2_VA_BASE;
  763. volatile TimerStruct_t *timer3 = (volatile TimerStruct_t *)TIMER3_VA_BASE;
  764. /*
  765. * set clock frequency:
  766. * VERSATILE_REFCLK is 32KHz
  767. * VERSATILE_TIMCLK is 1MHz
  768. */
  769. *(volatile unsigned int *)IO_ADDRESS(VERSATILE_SCTL_BASE) |=
  770. ((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) | (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  771. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) | (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel));
  772. /*
  773. * Initialise to a known state (all timers off)
  774. */
  775. timer0->TimerControl = 0;
  776. timer1->TimerControl = 0;
  777. timer2->TimerControl = 0;
  778. timer3->TimerControl = 0;
  779. timer0->TimerLoad = TIMER_RELOAD;
  780. timer0->TimerValue = TIMER_RELOAD;
  781. timer0->TimerControl = TIMER_CTRL | 0x40 | TIMER_CTRL_IE; /* periodic + IE */
  782. /*
  783. * Make irqs happen for the system timer
  784. */
  785. setup_irq(IRQ_TIMERINT0_1, &versatile_timer_irq);
  786. }
  787. struct sys_timer versatile_timer = {
  788. .init = versatile_timer_init,
  789. .offset = versatile_gettimeoffset,
  790. };