core.c 22 KB

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