core.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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/init.h>
  22. #include <linux/device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/amba/bus.h>
  28. #include <linux/amba/clcd.h>
  29. #include <linux/amba/pl061.h>
  30. #include <linux/amba/mmci.h>
  31. #include <linux/amba/pl022.h>
  32. #include <linux/io.h>
  33. #include <linux/gfp.h>
  34. #include <asm/clkdev.h>
  35. #include <asm/system.h>
  36. #include <asm/irq.h>
  37. #include <asm/leds.h>
  38. #include <asm/hardware/arm_timer.h>
  39. #include <asm/hardware/icst.h>
  40. #include <asm/hardware/vic.h>
  41. #include <asm/mach-types.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/flash.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/time.h>
  46. #include <asm/mach/map.h>
  47. #include <mach/clkdev.h>
  48. #include <mach/hardware.h>
  49. #include <mach/platform.h>
  50. #include <plat/timer-sp.h>
  51. #include "core.h"
  52. /*
  53. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  54. * is the (PA >> 12).
  55. *
  56. * Setup a VA for the Versatile Vectored Interrupt Controller.
  57. */
  58. #define VA_VIC_BASE __io_address(VERSATILE_VIC_BASE)
  59. #define VA_SIC_BASE __io_address(VERSATILE_SIC_BASE)
  60. static void sic_mask_irq(unsigned int irq)
  61. {
  62. irq -= IRQ_SIC_START;
  63. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  64. }
  65. static void sic_unmask_irq(unsigned int irq)
  66. {
  67. irq -= IRQ_SIC_START;
  68. writel(1 << irq, VA_SIC_BASE + SIC_IRQ_ENABLE_SET);
  69. }
  70. static struct irq_chip sic_chip = {
  71. .name = "SIC",
  72. .ack = sic_mask_irq,
  73. .mask = sic_mask_irq,
  74. .unmask = sic_unmask_irq,
  75. };
  76. static void
  77. sic_handle_irq(unsigned int irq, struct irq_desc *desc)
  78. {
  79. unsigned long status = readl(VA_SIC_BASE + SIC_IRQ_STATUS);
  80. if (status == 0) {
  81. do_bad_IRQ(irq, desc);
  82. return;
  83. }
  84. do {
  85. irq = ffs(status) - 1;
  86. status &= ~(1 << irq);
  87. irq += IRQ_SIC_START;
  88. generic_handle_irq(irq);
  89. } while (status);
  90. }
  91. #if 1
  92. #define IRQ_MMCI0A IRQ_VICSOURCE22
  93. #define IRQ_AACI IRQ_VICSOURCE24
  94. #define IRQ_ETH IRQ_VICSOURCE25
  95. #define PIC_MASK 0xFFD00000
  96. #else
  97. #define IRQ_MMCI0A IRQ_SIC_MMCI0A
  98. #define IRQ_AACI IRQ_SIC_AACI
  99. #define IRQ_ETH IRQ_SIC_ETH
  100. #define PIC_MASK 0
  101. #endif
  102. void __init versatile_init_irq(void)
  103. {
  104. unsigned int i;
  105. vic_init(VA_VIC_BASE, IRQ_VIC_START, ~0, 0);
  106. set_irq_chained_handler(IRQ_VICSOURCE31, sic_handle_irq);
  107. /* Do second interrupt controller */
  108. writel(~0, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  109. for (i = IRQ_SIC_START; i <= IRQ_SIC_END; i++) {
  110. if ((PIC_MASK & (1 << (i - IRQ_SIC_START))) == 0) {
  111. set_irq_chip(i, &sic_chip);
  112. set_irq_handler(i, handle_level_irq);
  113. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  114. }
  115. }
  116. /*
  117. * Interrupts on secondary controller from 0 to 8 are routed to
  118. * source 31 on PIC.
  119. * Interrupts from 21 to 31 are routed directly to the VIC on
  120. * the corresponding number on primary controller. This is controlled
  121. * by setting PIC_ENABLEx.
  122. */
  123. writel(PIC_MASK, VA_SIC_BASE + SIC_INT_PIC_ENABLE);
  124. }
  125. static struct map_desc versatile_io_desc[] __initdata = {
  126. {
  127. .virtual = IO_ADDRESS(VERSATILE_SYS_BASE),
  128. .pfn = __phys_to_pfn(VERSATILE_SYS_BASE),
  129. .length = SZ_4K,
  130. .type = MT_DEVICE
  131. }, {
  132. .virtual = IO_ADDRESS(VERSATILE_SIC_BASE),
  133. .pfn = __phys_to_pfn(VERSATILE_SIC_BASE),
  134. .length = SZ_4K,
  135. .type = MT_DEVICE
  136. }, {
  137. .virtual = IO_ADDRESS(VERSATILE_VIC_BASE),
  138. .pfn = __phys_to_pfn(VERSATILE_VIC_BASE),
  139. .length = SZ_4K,
  140. .type = MT_DEVICE
  141. }, {
  142. .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
  143. .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
  144. .length = SZ_4K * 9,
  145. .type = MT_DEVICE
  146. },
  147. #ifdef CONFIG_MACH_VERSATILE_AB
  148. {
  149. .virtual = IO_ADDRESS(VERSATILE_GPIO0_BASE),
  150. .pfn = __phys_to_pfn(VERSATILE_GPIO0_BASE),
  151. .length = SZ_4K,
  152. .type = MT_DEVICE
  153. }, {
  154. .virtual = IO_ADDRESS(VERSATILE_IB2_BASE),
  155. .pfn = __phys_to_pfn(VERSATILE_IB2_BASE),
  156. .length = SZ_64M,
  157. .type = MT_DEVICE
  158. },
  159. #endif
  160. #ifdef CONFIG_DEBUG_LL
  161. {
  162. .virtual = IO_ADDRESS(VERSATILE_UART0_BASE),
  163. .pfn = __phys_to_pfn(VERSATILE_UART0_BASE),
  164. .length = SZ_4K,
  165. .type = MT_DEVICE
  166. },
  167. #endif
  168. #ifdef CONFIG_PCI
  169. {
  170. .virtual = IO_ADDRESS(VERSATILE_PCI_CORE_BASE),
  171. .pfn = __phys_to_pfn(VERSATILE_PCI_CORE_BASE),
  172. .length = SZ_4K,
  173. .type = MT_DEVICE
  174. }, {
  175. .virtual = (unsigned long)VERSATILE_PCI_VIRT_BASE,
  176. .pfn = __phys_to_pfn(VERSATILE_PCI_BASE),
  177. .length = VERSATILE_PCI_BASE_SIZE,
  178. .type = MT_DEVICE
  179. }, {
  180. .virtual = (unsigned long)VERSATILE_PCI_CFG_VIRT_BASE,
  181. .pfn = __phys_to_pfn(VERSATILE_PCI_CFG_BASE),
  182. .length = VERSATILE_PCI_CFG_BASE_SIZE,
  183. .type = MT_DEVICE
  184. },
  185. #if 0
  186. {
  187. .virtual = VERSATILE_PCI_VIRT_MEM_BASE0,
  188. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE0),
  189. .length = SZ_16M,
  190. .type = MT_DEVICE
  191. }, {
  192. .virtual = VERSATILE_PCI_VIRT_MEM_BASE1,
  193. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE1),
  194. .length = SZ_16M,
  195. .type = MT_DEVICE
  196. }, {
  197. .virtual = VERSATILE_PCI_VIRT_MEM_BASE2,
  198. .pfn = __phys_to_pfn(VERSATILE_PCI_MEM_BASE2),
  199. .length = SZ_16M,
  200. .type = MT_DEVICE
  201. },
  202. #endif
  203. #endif
  204. };
  205. void __init versatile_map_io(void)
  206. {
  207. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  208. }
  209. #define VERSATILE_FLASHCTRL (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
  210. static int versatile_flash_init(void)
  211. {
  212. u32 val;
  213. val = __raw_readl(VERSATILE_FLASHCTRL);
  214. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  215. __raw_writel(val, VERSATILE_FLASHCTRL);
  216. return 0;
  217. }
  218. static void versatile_flash_exit(void)
  219. {
  220. u32 val;
  221. val = __raw_readl(VERSATILE_FLASHCTRL);
  222. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  223. __raw_writel(val, VERSATILE_FLASHCTRL);
  224. }
  225. static void versatile_flash_set_vpp(int on)
  226. {
  227. u32 val;
  228. val = __raw_readl(VERSATILE_FLASHCTRL);
  229. if (on)
  230. val |= VERSATILE_FLASHPROG_FLVPPEN;
  231. else
  232. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  233. __raw_writel(val, VERSATILE_FLASHCTRL);
  234. }
  235. static struct flash_platform_data versatile_flash_data = {
  236. .map_name = "cfi_probe",
  237. .width = 4,
  238. .init = versatile_flash_init,
  239. .exit = versatile_flash_exit,
  240. .set_vpp = versatile_flash_set_vpp,
  241. };
  242. static struct resource versatile_flash_resource = {
  243. .start = VERSATILE_FLASH_BASE,
  244. .end = VERSATILE_FLASH_BASE + VERSATILE_FLASH_SIZE - 1,
  245. .flags = IORESOURCE_MEM,
  246. };
  247. static struct platform_device versatile_flash_device = {
  248. .name = "armflash",
  249. .id = 0,
  250. .dev = {
  251. .platform_data = &versatile_flash_data,
  252. },
  253. .num_resources = 1,
  254. .resource = &versatile_flash_resource,
  255. };
  256. static struct resource smc91x_resources[] = {
  257. [0] = {
  258. .start = VERSATILE_ETH_BASE,
  259. .end = VERSATILE_ETH_BASE + SZ_64K - 1,
  260. .flags = IORESOURCE_MEM,
  261. },
  262. [1] = {
  263. .start = IRQ_ETH,
  264. .end = IRQ_ETH,
  265. .flags = IORESOURCE_IRQ,
  266. },
  267. };
  268. static struct platform_device smc91x_device = {
  269. .name = "smc91x",
  270. .id = 0,
  271. .num_resources = ARRAY_SIZE(smc91x_resources),
  272. .resource = smc91x_resources,
  273. };
  274. static struct resource versatile_i2c_resource = {
  275. .start = VERSATILE_I2C_BASE,
  276. .end = VERSATILE_I2C_BASE + SZ_4K - 1,
  277. .flags = IORESOURCE_MEM,
  278. };
  279. static struct platform_device versatile_i2c_device = {
  280. .name = "versatile-i2c",
  281. .id = 0,
  282. .num_resources = 1,
  283. .resource = &versatile_i2c_resource,
  284. };
  285. static struct i2c_board_info versatile_i2c_board_info[] = {
  286. {
  287. I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
  288. },
  289. };
  290. static int __init versatile_i2c_init(void)
  291. {
  292. return i2c_register_board_info(0, versatile_i2c_board_info,
  293. ARRAY_SIZE(versatile_i2c_board_info));
  294. }
  295. arch_initcall(versatile_i2c_init);
  296. #define VERSATILE_SYSMCI (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
  297. unsigned int mmc_status(struct device *dev)
  298. {
  299. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  300. u32 mask;
  301. if (adev->res.start == VERSATILE_MMCI0_BASE)
  302. mask = 1;
  303. else
  304. mask = 2;
  305. return readl(VERSATILE_SYSMCI) & mask;
  306. }
  307. static struct mmci_platform_data mmc0_plat_data = {
  308. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  309. .status = mmc_status,
  310. .gpio_wp = -1,
  311. .gpio_cd = -1,
  312. };
  313. static struct resource char_lcd_resources[] = {
  314. {
  315. .start = VERSATILE_CHAR_LCD_BASE,
  316. .end = (VERSATILE_CHAR_LCD_BASE + SZ_4K - 1),
  317. .flags = IORESOURCE_MEM,
  318. },
  319. };
  320. static struct platform_device char_lcd_device = {
  321. .name = "arm-charlcd",
  322. .id = -1,
  323. .num_resources = ARRAY_SIZE(char_lcd_resources),
  324. .resource = char_lcd_resources,
  325. };
  326. /*
  327. * Clock handling
  328. */
  329. static const struct icst_params versatile_oscvco_params = {
  330. .ref = 24000000,
  331. .vco_max = ICST307_VCO_MAX,
  332. .vco_min = ICST307_VCO_MIN,
  333. .vd_min = 4 + 8,
  334. .vd_max = 511 + 8,
  335. .rd_min = 1 + 2,
  336. .rd_max = 127 + 2,
  337. .s2div = icst307_s2div,
  338. .idx2s = icst307_idx2s,
  339. };
  340. static void versatile_oscvco_set(struct clk *clk, struct icst_vco vco)
  341. {
  342. void __iomem *sys_lock = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LOCK_OFFSET;
  343. u32 val;
  344. val = readl(clk->vcoreg) & ~0x7ffff;
  345. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  346. writel(0xa05f, sys_lock);
  347. writel(val, clk->vcoreg);
  348. writel(0, sys_lock);
  349. }
  350. static const struct clk_ops osc4_clk_ops = {
  351. .round = icst_clk_round,
  352. .set = icst_clk_set,
  353. .setvco = versatile_oscvco_set,
  354. };
  355. static struct clk osc4_clk = {
  356. .ops = &osc4_clk_ops,
  357. .params = &versatile_oscvco_params,
  358. };
  359. /*
  360. * These are fixed clocks.
  361. */
  362. static struct clk ref24_clk = {
  363. .rate = 24000000,
  364. };
  365. static struct clk_lookup lookups[] = {
  366. { /* UART0 */
  367. .dev_id = "dev:f1",
  368. .clk = &ref24_clk,
  369. }, { /* UART1 */
  370. .dev_id = "dev:f2",
  371. .clk = &ref24_clk,
  372. }, { /* UART2 */
  373. .dev_id = "dev:f3",
  374. .clk = &ref24_clk,
  375. }, { /* UART3 */
  376. .dev_id = "fpga:09",
  377. .clk = &ref24_clk,
  378. }, { /* KMI0 */
  379. .dev_id = "fpga:06",
  380. .clk = &ref24_clk,
  381. }, { /* KMI1 */
  382. .dev_id = "fpga:07",
  383. .clk = &ref24_clk,
  384. }, { /* MMC0 */
  385. .dev_id = "fpga:05",
  386. .clk = &ref24_clk,
  387. }, { /* MMC1 */
  388. .dev_id = "fpga:0b",
  389. .clk = &ref24_clk,
  390. }, { /* SSP */
  391. .dev_id = "dev:f4",
  392. .clk = &ref24_clk,
  393. }, { /* CLCD */
  394. .dev_id = "dev:20",
  395. .clk = &osc4_clk,
  396. }
  397. };
  398. /*
  399. * CLCD support.
  400. */
  401. #define SYS_CLCD_MODE_MASK (3 << 0)
  402. #define SYS_CLCD_MODE_888 (0 << 0)
  403. #define SYS_CLCD_MODE_5551 (1 << 0)
  404. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  405. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  406. #define SYS_CLCD_NLCDIOON (1 << 2)
  407. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  408. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  409. #define SYS_CLCD_ID_MASK (0x1f << 8)
  410. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  411. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  412. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  413. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  414. #define SYS_CLCD_ID_VGA (0x1f << 8)
  415. static struct clcd_panel vga = {
  416. .mode = {
  417. .name = "VGA",
  418. .refresh = 60,
  419. .xres = 640,
  420. .yres = 480,
  421. .pixclock = 39721,
  422. .left_margin = 40,
  423. .right_margin = 24,
  424. .upper_margin = 32,
  425. .lower_margin = 11,
  426. .hsync_len = 96,
  427. .vsync_len = 2,
  428. .sync = 0,
  429. .vmode = FB_VMODE_NONINTERLACED,
  430. },
  431. .width = -1,
  432. .height = -1,
  433. .tim2 = TIM2_BCD | TIM2_IPC,
  434. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  435. .bpp = 16,
  436. };
  437. static struct clcd_panel sanyo_3_8_in = {
  438. .mode = {
  439. .name = "Sanyo QVGA",
  440. .refresh = 116,
  441. .xres = 320,
  442. .yres = 240,
  443. .pixclock = 100000,
  444. .left_margin = 6,
  445. .right_margin = 6,
  446. .upper_margin = 5,
  447. .lower_margin = 5,
  448. .hsync_len = 6,
  449. .vsync_len = 6,
  450. .sync = 0,
  451. .vmode = FB_VMODE_NONINTERLACED,
  452. },
  453. .width = -1,
  454. .height = -1,
  455. .tim2 = TIM2_BCD,
  456. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  457. .bpp = 16,
  458. };
  459. static struct clcd_panel sanyo_2_5_in = {
  460. .mode = {
  461. .name = "Sanyo QVGA Portrait",
  462. .refresh = 116,
  463. .xres = 240,
  464. .yres = 320,
  465. .pixclock = 100000,
  466. .left_margin = 20,
  467. .right_margin = 10,
  468. .upper_margin = 2,
  469. .lower_margin = 2,
  470. .hsync_len = 10,
  471. .vsync_len = 2,
  472. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  473. .vmode = FB_VMODE_NONINTERLACED,
  474. },
  475. .width = -1,
  476. .height = -1,
  477. .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
  478. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  479. .bpp = 16,
  480. };
  481. static struct clcd_panel epson_2_2_in = {
  482. .mode = {
  483. .name = "Epson QCIF",
  484. .refresh = 390,
  485. .xres = 176,
  486. .yres = 220,
  487. .pixclock = 62500,
  488. .left_margin = 3,
  489. .right_margin = 2,
  490. .upper_margin = 1,
  491. .lower_margin = 0,
  492. .hsync_len = 3,
  493. .vsync_len = 2,
  494. .sync = 0,
  495. .vmode = FB_VMODE_NONINTERLACED,
  496. },
  497. .width = -1,
  498. .height = -1,
  499. .tim2 = TIM2_BCD | TIM2_IPC,
  500. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  501. .bpp = 16,
  502. };
  503. /*
  504. * Detect which LCD panel is connected, and return the appropriate
  505. * clcd_panel structure. Note: we do not have any information on
  506. * the required timings for the 8.4in panel, so we presently assume
  507. * VGA timings.
  508. */
  509. static struct clcd_panel *versatile_clcd_panel(void)
  510. {
  511. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  512. struct clcd_panel *panel = &vga;
  513. u32 val;
  514. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  515. if (val == SYS_CLCD_ID_SANYO_3_8)
  516. panel = &sanyo_3_8_in;
  517. else if (val == SYS_CLCD_ID_SANYO_2_5)
  518. panel = &sanyo_2_5_in;
  519. else if (val == SYS_CLCD_ID_EPSON_2_2)
  520. panel = &epson_2_2_in;
  521. else if (val == SYS_CLCD_ID_VGA)
  522. panel = &vga;
  523. else {
  524. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  525. val);
  526. panel = &vga;
  527. }
  528. return panel;
  529. }
  530. /*
  531. * Disable all display connectors on the interface module.
  532. */
  533. static void versatile_clcd_disable(struct clcd_fb *fb)
  534. {
  535. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  536. u32 val;
  537. val = readl(sys_clcd);
  538. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  539. writel(val, sys_clcd);
  540. #ifdef CONFIG_MACH_VERSATILE_AB
  541. /*
  542. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light off
  543. */
  544. if (machine_is_versatile_ab() && fb->panel == &sanyo_2_5_in) {
  545. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  546. unsigned long ctrl;
  547. ctrl = readl(versatile_ib2_ctrl);
  548. ctrl &= ~0x01;
  549. writel(ctrl, versatile_ib2_ctrl);
  550. }
  551. #endif
  552. }
  553. /*
  554. * Enable the relevant connector on the interface module.
  555. */
  556. static void versatile_clcd_enable(struct clcd_fb *fb)
  557. {
  558. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  559. u32 val;
  560. val = readl(sys_clcd);
  561. val &= ~SYS_CLCD_MODE_MASK;
  562. switch (fb->fb.var.green.length) {
  563. case 5:
  564. val |= SYS_CLCD_MODE_5551;
  565. break;
  566. case 6:
  567. val |= SYS_CLCD_MODE_565_RLSB;
  568. break;
  569. case 8:
  570. val |= SYS_CLCD_MODE_888;
  571. break;
  572. }
  573. /*
  574. * Set the MUX
  575. */
  576. writel(val, sys_clcd);
  577. /*
  578. * And now enable the PSUs
  579. */
  580. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  581. writel(val, sys_clcd);
  582. #ifdef CONFIG_MACH_VERSATILE_AB
  583. /*
  584. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light on
  585. */
  586. if (machine_is_versatile_ab() && fb->panel == &sanyo_2_5_in) {
  587. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  588. unsigned long ctrl;
  589. ctrl = readl(versatile_ib2_ctrl);
  590. ctrl |= 0x01;
  591. writel(ctrl, versatile_ib2_ctrl);
  592. }
  593. #endif
  594. }
  595. static unsigned long framesize = SZ_1M;
  596. static int versatile_clcd_setup(struct clcd_fb *fb)
  597. {
  598. dma_addr_t dma;
  599. fb->panel = versatile_clcd_panel();
  600. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  601. &dma, GFP_KERNEL);
  602. if (!fb->fb.screen_base) {
  603. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  604. return -ENOMEM;
  605. }
  606. fb->fb.fix.smem_start = dma;
  607. fb->fb.fix.smem_len = framesize;
  608. return 0;
  609. }
  610. static int versatile_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  611. {
  612. return dma_mmap_writecombine(&fb->dev->dev, vma,
  613. fb->fb.screen_base,
  614. fb->fb.fix.smem_start,
  615. fb->fb.fix.smem_len);
  616. }
  617. static void versatile_clcd_remove(struct clcd_fb *fb)
  618. {
  619. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  620. fb->fb.screen_base, fb->fb.fix.smem_start);
  621. }
  622. static struct clcd_board clcd_plat_data = {
  623. .name = "Versatile",
  624. .check = clcdfb_check,
  625. .decode = clcdfb_decode,
  626. .disable = versatile_clcd_disable,
  627. .enable = versatile_clcd_enable,
  628. .setup = versatile_clcd_setup,
  629. .mmap = versatile_clcd_mmap,
  630. .remove = versatile_clcd_remove,
  631. };
  632. static struct pl061_platform_data gpio0_plat_data = {
  633. .gpio_base = 0,
  634. .irq_base = IRQ_GPIO0_START,
  635. };
  636. static struct pl061_platform_data gpio1_plat_data = {
  637. .gpio_base = 8,
  638. .irq_base = IRQ_GPIO1_START,
  639. };
  640. static struct pl022_ssp_controller ssp0_plat_data = {
  641. .bus_id = 0,
  642. .enable_dma = 0,
  643. .num_chipselect = 1,
  644. };
  645. #define AACI_IRQ { IRQ_AACI, NO_IRQ }
  646. #define AACI_DMA { 0x80, 0x81 }
  647. #define MMCI0_IRQ { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
  648. #define MMCI0_DMA { 0x84, 0 }
  649. #define KMI0_IRQ { IRQ_SIC_KMI0, NO_IRQ }
  650. #define KMI0_DMA { 0, 0 }
  651. #define KMI1_IRQ { IRQ_SIC_KMI1, NO_IRQ }
  652. #define KMI1_DMA { 0, 0 }
  653. /*
  654. * These devices are connected directly to the multi-layer AHB switch
  655. */
  656. #define SMC_IRQ { NO_IRQ, NO_IRQ }
  657. #define SMC_DMA { 0, 0 }
  658. #define MPMC_IRQ { NO_IRQ, NO_IRQ }
  659. #define MPMC_DMA { 0, 0 }
  660. #define CLCD_IRQ { IRQ_CLCDINT, NO_IRQ }
  661. #define CLCD_DMA { 0, 0 }
  662. #define DMAC_IRQ { IRQ_DMAINT, NO_IRQ }
  663. #define DMAC_DMA { 0, 0 }
  664. /*
  665. * These devices are connected via the core APB bridge
  666. */
  667. #define SCTL_IRQ { NO_IRQ, NO_IRQ }
  668. #define SCTL_DMA { 0, 0 }
  669. #define WATCHDOG_IRQ { IRQ_WDOGINT, NO_IRQ }
  670. #define WATCHDOG_DMA { 0, 0 }
  671. #define GPIO0_IRQ { IRQ_GPIOINT0, NO_IRQ }
  672. #define GPIO0_DMA { 0, 0 }
  673. #define GPIO1_IRQ { IRQ_GPIOINT1, NO_IRQ }
  674. #define GPIO1_DMA { 0, 0 }
  675. #define RTC_IRQ { IRQ_RTCINT, NO_IRQ }
  676. #define RTC_DMA { 0, 0 }
  677. /*
  678. * These devices are connected via the DMA APB bridge
  679. */
  680. #define SCI_IRQ { IRQ_SCIINT, NO_IRQ }
  681. #define SCI_DMA { 7, 6 }
  682. #define UART0_IRQ { IRQ_UARTINT0, NO_IRQ }
  683. #define UART0_DMA { 15, 14 }
  684. #define UART1_IRQ { IRQ_UARTINT1, NO_IRQ }
  685. #define UART1_DMA { 13, 12 }
  686. #define UART2_IRQ { IRQ_UARTINT2, NO_IRQ }
  687. #define UART2_DMA { 11, 10 }
  688. #define SSP_IRQ { IRQ_SSPINT, NO_IRQ }
  689. #define SSP_DMA { 9, 8 }
  690. /* FPGA Primecells */
  691. AMBA_DEVICE(aaci, "fpga:04", AACI, NULL);
  692. AMBA_DEVICE(mmc0, "fpga:05", MMCI0, &mmc0_plat_data);
  693. AMBA_DEVICE(kmi0, "fpga:06", KMI0, NULL);
  694. AMBA_DEVICE(kmi1, "fpga:07", KMI1, NULL);
  695. /* DevChip Primecells */
  696. AMBA_DEVICE(smc, "dev:00", SMC, NULL);
  697. AMBA_DEVICE(mpmc, "dev:10", MPMC, NULL);
  698. AMBA_DEVICE(clcd, "dev:20", CLCD, &clcd_plat_data);
  699. AMBA_DEVICE(dmac, "dev:30", DMAC, NULL);
  700. AMBA_DEVICE(sctl, "dev:e0", SCTL, NULL);
  701. AMBA_DEVICE(wdog, "dev:e1", WATCHDOG, NULL);
  702. AMBA_DEVICE(gpio0, "dev:e4", GPIO0, &gpio0_plat_data);
  703. AMBA_DEVICE(gpio1, "dev:e5", GPIO1, &gpio1_plat_data);
  704. AMBA_DEVICE(rtc, "dev:e8", RTC, NULL);
  705. AMBA_DEVICE(sci0, "dev:f0", SCI, NULL);
  706. AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  707. AMBA_DEVICE(uart1, "dev:f2", UART1, NULL);
  708. AMBA_DEVICE(uart2, "dev:f3", UART2, NULL);
  709. AMBA_DEVICE(ssp0, "dev:f4", SSP, &ssp0_plat_data);
  710. static struct amba_device *amba_devs[] __initdata = {
  711. &dmac_device,
  712. &uart0_device,
  713. &uart1_device,
  714. &uart2_device,
  715. &smc_device,
  716. &mpmc_device,
  717. &clcd_device,
  718. &sctl_device,
  719. &wdog_device,
  720. &gpio0_device,
  721. &gpio1_device,
  722. &rtc_device,
  723. &sci0_device,
  724. &ssp0_device,
  725. &aaci_device,
  726. &mmc0_device,
  727. &kmi0_device,
  728. &kmi1_device,
  729. };
  730. #ifdef CONFIG_LEDS
  731. #define VA_LEDS_BASE (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
  732. static void versatile_leds_event(led_event_t ledevt)
  733. {
  734. unsigned long flags;
  735. u32 val;
  736. local_irq_save(flags);
  737. val = readl(VA_LEDS_BASE);
  738. switch (ledevt) {
  739. case led_idle_start:
  740. val = val & ~VERSATILE_SYS_LED0;
  741. break;
  742. case led_idle_end:
  743. val = val | VERSATILE_SYS_LED0;
  744. break;
  745. case led_timer:
  746. val = val ^ VERSATILE_SYS_LED1;
  747. break;
  748. case led_halted:
  749. val = 0;
  750. break;
  751. default:
  752. break;
  753. }
  754. writel(val, VA_LEDS_BASE);
  755. local_irq_restore(flags);
  756. }
  757. #endif /* CONFIG_LEDS */
  758. void __init versatile_init(void)
  759. {
  760. int i;
  761. osc4_clk.vcoreg = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_OSCCLCD_OFFSET;
  762. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  763. platform_device_register(&versatile_flash_device);
  764. platform_device_register(&versatile_i2c_device);
  765. platform_device_register(&smc91x_device);
  766. platform_device_register(&char_lcd_device);
  767. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  768. struct amba_device *d = amba_devs[i];
  769. amba_device_register(d, &iomem_resource);
  770. }
  771. #ifdef CONFIG_LEDS
  772. leds_event = versatile_leds_event;
  773. #endif
  774. }
  775. /*
  776. * Where is the timer (VA)?
  777. */
  778. #define TIMER0_VA_BASE __io_address(VERSATILE_TIMER0_1_BASE)
  779. #define TIMER1_VA_BASE (__io_address(VERSATILE_TIMER0_1_BASE) + 0x20)
  780. #define TIMER2_VA_BASE __io_address(VERSATILE_TIMER2_3_BASE)
  781. #define TIMER3_VA_BASE (__io_address(VERSATILE_TIMER2_3_BASE) + 0x20)
  782. /*
  783. * Set up timer interrupt, and return the current time in seconds.
  784. */
  785. static void __init versatile_timer_init(void)
  786. {
  787. u32 val;
  788. /*
  789. * set clock frequency:
  790. * VERSATILE_REFCLK is 32KHz
  791. * VERSATILE_TIMCLK is 1MHz
  792. */
  793. val = readl(__io_address(VERSATILE_SCTL_BASE));
  794. writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
  795. (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  796. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
  797. (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
  798. __io_address(VERSATILE_SCTL_BASE));
  799. /*
  800. * Initialise to a known state (all timers off)
  801. */
  802. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  803. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  804. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  805. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  806. sp804_clocksource_init(TIMER3_VA_BASE);
  807. sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1);
  808. }
  809. struct sys_timer versatile_timer = {
  810. .init = versatile_timer_init,
  811. };