core.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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/interrupt.h>
  26. #include <linux/irqdomain.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/amba/bus.h>
  30. #include <linux/amba/clcd.h>
  31. #include <linux/amba/pl061.h>
  32. #include <linux/amba/mmci.h>
  33. #include <linux/amba/pl022.h>
  34. #include <linux/io.h>
  35. #include <linux/gfp.h>
  36. #include <linux/clkdev.h>
  37. #include <linux/mtd/physmap.h>
  38. #include <asm/irq.h>
  39. #include <asm/leds.h>
  40. #include <asm/hardware/arm_timer.h>
  41. #include <asm/hardware/icst.h>
  42. #include <asm/hardware/vic.h>
  43. #include <asm/mach-types.h>
  44. #include <asm/mach/arch.h>
  45. #include <asm/mach/irq.h>
  46. #include <asm/mach/time.h>
  47. #include <asm/mach/map.h>
  48. #include <mach/hardware.h>
  49. #include <mach/platform.h>
  50. #include <asm/hardware/timer-sp.h>
  51. #include <plat/clcd.h>
  52. #include <plat/fpga-irq.h>
  53. #include <plat/sched_clock.h>
  54. #include "core.h"
  55. /*
  56. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  57. * is the (PA >> 12).
  58. *
  59. * Setup a VA for the Versatile Vectored Interrupt Controller.
  60. */
  61. #define VA_VIC_BASE __io_address(VERSATILE_VIC_BASE)
  62. #define VA_SIC_BASE __io_address(VERSATILE_SIC_BASE)
  63. #if 1
  64. #define IRQ_MMCI0A IRQ_VICSOURCE22
  65. #define IRQ_AACI IRQ_VICSOURCE24
  66. #define IRQ_ETH IRQ_VICSOURCE25
  67. #define PIC_MASK 0xFFD00000
  68. #else
  69. #define IRQ_MMCI0A IRQ_SIC_MMCI0A
  70. #define IRQ_AACI IRQ_SIC_AACI
  71. #define IRQ_ETH IRQ_SIC_ETH
  72. #define PIC_MASK 0
  73. #endif
  74. /* Lookup table for finding a DT node that represents the vic instance */
  75. static const struct of_device_id vic_of_match[] __initconst = {
  76. { .compatible = "arm,versatile-vic", },
  77. {}
  78. };
  79. static const struct of_device_id sic_of_match[] __initconst = {
  80. { .compatible = "arm,versatile-sic", },
  81. {}
  82. };
  83. void __init versatile_init_irq(void)
  84. {
  85. struct device_node *np;
  86. np = of_find_matching_node_by_address(NULL, vic_of_match,
  87. VERSATILE_VIC_BASE);
  88. __vic_init(VA_VIC_BASE, IRQ_VIC_START, ~0, 0, np);
  89. writel(~0, VA_SIC_BASE + SIC_IRQ_ENABLE_CLEAR);
  90. np = of_find_matching_node_by_address(NULL, sic_of_match,
  91. VERSATILE_SIC_BASE);
  92. fpga_irq_init(VA_SIC_BASE, "SIC", IRQ_SIC_START,
  93. IRQ_VICSOURCE31, ~PIC_MASK, np);
  94. /*
  95. * Interrupts on secondary controller from 0 to 8 are routed to
  96. * source 31 on PIC.
  97. * Interrupts from 21 to 31 are routed directly to the VIC on
  98. * the corresponding number on primary controller. This is controlled
  99. * by setting PIC_ENABLEx.
  100. */
  101. writel(PIC_MASK, VA_SIC_BASE + SIC_INT_PIC_ENABLE);
  102. }
  103. static struct map_desc versatile_io_desc[] __initdata = {
  104. {
  105. .virtual = IO_ADDRESS(VERSATILE_SYS_BASE),
  106. .pfn = __phys_to_pfn(VERSATILE_SYS_BASE),
  107. .length = SZ_4K,
  108. .type = MT_DEVICE
  109. }, {
  110. .virtual = IO_ADDRESS(VERSATILE_SIC_BASE),
  111. .pfn = __phys_to_pfn(VERSATILE_SIC_BASE),
  112. .length = SZ_4K,
  113. .type = MT_DEVICE
  114. }, {
  115. .virtual = IO_ADDRESS(VERSATILE_VIC_BASE),
  116. .pfn = __phys_to_pfn(VERSATILE_VIC_BASE),
  117. .length = SZ_4K,
  118. .type = MT_DEVICE
  119. }, {
  120. .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
  121. .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
  122. .length = SZ_4K * 9,
  123. .type = MT_DEVICE
  124. },
  125. #ifdef CONFIG_MACH_VERSATILE_AB
  126. {
  127. .virtual = IO_ADDRESS(VERSATILE_IB2_BASE),
  128. .pfn = __phys_to_pfn(VERSATILE_IB2_BASE),
  129. .length = SZ_64M,
  130. .type = MT_DEVICE
  131. },
  132. #endif
  133. #ifdef CONFIG_DEBUG_LL
  134. {
  135. .virtual = IO_ADDRESS(VERSATILE_UART0_BASE),
  136. .pfn = __phys_to_pfn(VERSATILE_UART0_BASE),
  137. .length = SZ_4K,
  138. .type = MT_DEVICE
  139. },
  140. #endif
  141. #ifdef CONFIG_PCI
  142. {
  143. .virtual = IO_ADDRESS(VERSATILE_PCI_CORE_BASE),
  144. .pfn = __phys_to_pfn(VERSATILE_PCI_CORE_BASE),
  145. .length = SZ_4K,
  146. .type = MT_DEVICE
  147. }, {
  148. .virtual = (unsigned long)VERSATILE_PCI_VIRT_BASE,
  149. .pfn = __phys_to_pfn(VERSATILE_PCI_BASE),
  150. .length = VERSATILE_PCI_BASE_SIZE,
  151. .type = MT_DEVICE
  152. }, {
  153. .virtual = (unsigned long)VERSATILE_PCI_CFG_VIRT_BASE,
  154. .pfn = __phys_to_pfn(VERSATILE_PCI_CFG_BASE),
  155. .length = VERSATILE_PCI_CFG_BASE_SIZE,
  156. .type = MT_DEVICE
  157. },
  158. #endif
  159. };
  160. void __init versatile_map_io(void)
  161. {
  162. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  163. }
  164. #define VERSATILE_FLASHCTRL (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
  165. static void versatile_flash_set_vpp(struct platform_device *pdev, int on)
  166. {
  167. u32 val;
  168. val = __raw_readl(VERSATILE_FLASHCTRL);
  169. if (on)
  170. val |= VERSATILE_FLASHPROG_FLVPPEN;
  171. else
  172. val &= ~VERSATILE_FLASHPROG_FLVPPEN;
  173. __raw_writel(val, VERSATILE_FLASHCTRL);
  174. }
  175. static struct physmap_flash_data versatile_flash_data = {
  176. .width = 4,
  177. .set_vpp = versatile_flash_set_vpp,
  178. };
  179. static struct resource versatile_flash_resource = {
  180. .start = VERSATILE_FLASH_BASE,
  181. .end = VERSATILE_FLASH_BASE + VERSATILE_FLASH_SIZE - 1,
  182. .flags = IORESOURCE_MEM,
  183. };
  184. static struct platform_device versatile_flash_device = {
  185. .name = "physmap-flash",
  186. .id = 0,
  187. .dev = {
  188. .platform_data = &versatile_flash_data,
  189. },
  190. .num_resources = 1,
  191. .resource = &versatile_flash_resource,
  192. };
  193. static struct resource smc91x_resources[] = {
  194. [0] = {
  195. .start = VERSATILE_ETH_BASE,
  196. .end = VERSATILE_ETH_BASE + SZ_64K - 1,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .start = IRQ_ETH,
  201. .end = IRQ_ETH,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static struct platform_device smc91x_device = {
  206. .name = "smc91x",
  207. .id = 0,
  208. .num_resources = ARRAY_SIZE(smc91x_resources),
  209. .resource = smc91x_resources,
  210. };
  211. static struct resource versatile_i2c_resource = {
  212. .start = VERSATILE_I2C_BASE,
  213. .end = VERSATILE_I2C_BASE + SZ_4K - 1,
  214. .flags = IORESOURCE_MEM,
  215. };
  216. static struct platform_device versatile_i2c_device = {
  217. .name = "versatile-i2c",
  218. .id = 0,
  219. .num_resources = 1,
  220. .resource = &versatile_i2c_resource,
  221. };
  222. static struct i2c_board_info versatile_i2c_board_info[] = {
  223. {
  224. I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
  225. },
  226. };
  227. static int __init versatile_i2c_init(void)
  228. {
  229. return i2c_register_board_info(0, versatile_i2c_board_info,
  230. ARRAY_SIZE(versatile_i2c_board_info));
  231. }
  232. arch_initcall(versatile_i2c_init);
  233. #define VERSATILE_SYSMCI (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
  234. unsigned int mmc_status(struct device *dev)
  235. {
  236. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  237. u32 mask;
  238. if (adev->res.start == VERSATILE_MMCI0_BASE)
  239. mask = 1;
  240. else
  241. mask = 2;
  242. return readl(VERSATILE_SYSMCI) & mask;
  243. }
  244. static struct mmci_platform_data mmc0_plat_data = {
  245. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  246. .status = mmc_status,
  247. .gpio_wp = -1,
  248. .gpio_cd = -1,
  249. };
  250. static struct resource char_lcd_resources[] = {
  251. {
  252. .start = VERSATILE_CHAR_LCD_BASE,
  253. .end = (VERSATILE_CHAR_LCD_BASE + SZ_4K - 1),
  254. .flags = IORESOURCE_MEM,
  255. },
  256. };
  257. static struct platform_device char_lcd_device = {
  258. .name = "arm-charlcd",
  259. .id = -1,
  260. .num_resources = ARRAY_SIZE(char_lcd_resources),
  261. .resource = char_lcd_resources,
  262. };
  263. /*
  264. * Clock handling
  265. */
  266. static const struct icst_params versatile_oscvco_params = {
  267. .ref = 24000000,
  268. .vco_max = ICST307_VCO_MAX,
  269. .vco_min = ICST307_VCO_MIN,
  270. .vd_min = 4 + 8,
  271. .vd_max = 511 + 8,
  272. .rd_min = 1 + 2,
  273. .rd_max = 127 + 2,
  274. .s2div = icst307_s2div,
  275. .idx2s = icst307_idx2s,
  276. };
  277. static void versatile_oscvco_set(struct clk *clk, struct icst_vco vco)
  278. {
  279. void __iomem *sys_lock = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LOCK_OFFSET;
  280. u32 val;
  281. val = readl(clk->vcoreg) & ~0x7ffff;
  282. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  283. writel(0xa05f, sys_lock);
  284. writel(val, clk->vcoreg);
  285. writel(0, sys_lock);
  286. }
  287. static const struct clk_ops osc4_clk_ops = {
  288. .round = icst_clk_round,
  289. .set = icst_clk_set,
  290. .setvco = versatile_oscvco_set,
  291. };
  292. static struct clk osc4_clk = {
  293. .ops = &osc4_clk_ops,
  294. .params = &versatile_oscvco_params,
  295. };
  296. /*
  297. * These are fixed clocks.
  298. */
  299. static struct clk ref24_clk = {
  300. .rate = 24000000,
  301. };
  302. static struct clk sp804_clk = {
  303. .rate = 1000000,
  304. };
  305. static struct clk dummy_apb_pclk;
  306. static struct clk_lookup lookups[] = {
  307. { /* AMBA bus clock */
  308. .con_id = "apb_pclk",
  309. .clk = &dummy_apb_pclk,
  310. }, { /* UART0 */
  311. .dev_id = "dev:f1",
  312. .clk = &ref24_clk,
  313. }, { /* UART1 */
  314. .dev_id = "dev:f2",
  315. .clk = &ref24_clk,
  316. }, { /* UART2 */
  317. .dev_id = "dev:f3",
  318. .clk = &ref24_clk,
  319. }, { /* UART3 */
  320. .dev_id = "fpga:09",
  321. .clk = &ref24_clk,
  322. }, { /* KMI0 */
  323. .dev_id = "fpga:06",
  324. .clk = &ref24_clk,
  325. }, { /* KMI1 */
  326. .dev_id = "fpga:07",
  327. .clk = &ref24_clk,
  328. }, { /* MMC0 */
  329. .dev_id = "fpga:05",
  330. .clk = &ref24_clk,
  331. }, { /* MMC1 */
  332. .dev_id = "fpga:0b",
  333. .clk = &ref24_clk,
  334. }, { /* SSP */
  335. .dev_id = "dev:f4",
  336. .clk = &ref24_clk,
  337. }, { /* CLCD */
  338. .dev_id = "dev:20",
  339. .clk = &osc4_clk,
  340. }, { /* SP804 timers */
  341. .dev_id = "sp804",
  342. .clk = &sp804_clk,
  343. },
  344. };
  345. /*
  346. * CLCD support.
  347. */
  348. #define SYS_CLCD_MODE_MASK (3 << 0)
  349. #define SYS_CLCD_MODE_888 (0 << 0)
  350. #define SYS_CLCD_MODE_5551 (1 << 0)
  351. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  352. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  353. #define SYS_CLCD_NLCDIOON (1 << 2)
  354. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  355. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  356. #define SYS_CLCD_ID_MASK (0x1f << 8)
  357. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  358. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  359. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  360. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  361. #define SYS_CLCD_ID_VGA (0x1f << 8)
  362. static bool is_sanyo_2_5_lcd;
  363. /*
  364. * Disable all display connectors on the interface module.
  365. */
  366. static void versatile_clcd_disable(struct clcd_fb *fb)
  367. {
  368. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  369. u32 val;
  370. val = readl(sys_clcd);
  371. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  372. writel(val, sys_clcd);
  373. #ifdef CONFIG_MACH_VERSATILE_AB
  374. /*
  375. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light off
  376. */
  377. if (machine_is_versatile_ab() && is_sanyo_2_5_lcd) {
  378. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  379. unsigned long ctrl;
  380. ctrl = readl(versatile_ib2_ctrl);
  381. ctrl &= ~0x01;
  382. writel(ctrl, versatile_ib2_ctrl);
  383. }
  384. #endif
  385. }
  386. /*
  387. * Enable the relevant connector on the interface module.
  388. */
  389. static void versatile_clcd_enable(struct clcd_fb *fb)
  390. {
  391. struct fb_var_screeninfo *var = &fb->fb.var;
  392. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  393. u32 val;
  394. val = readl(sys_clcd);
  395. val &= ~SYS_CLCD_MODE_MASK;
  396. switch (var->green.length) {
  397. case 5:
  398. val |= SYS_CLCD_MODE_5551;
  399. break;
  400. case 6:
  401. if (var->red.offset == 0)
  402. val |= SYS_CLCD_MODE_565_RLSB;
  403. else
  404. val |= SYS_CLCD_MODE_565_BLSB;
  405. break;
  406. case 8:
  407. val |= SYS_CLCD_MODE_888;
  408. break;
  409. }
  410. /*
  411. * Set the MUX
  412. */
  413. writel(val, sys_clcd);
  414. /*
  415. * And now enable the PSUs
  416. */
  417. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  418. writel(val, sys_clcd);
  419. #ifdef CONFIG_MACH_VERSATILE_AB
  420. /*
  421. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light on
  422. */
  423. if (machine_is_versatile_ab() && is_sanyo_2_5_lcd) {
  424. void __iomem *versatile_ib2_ctrl = __io_address(VERSATILE_IB2_CTRL);
  425. unsigned long ctrl;
  426. ctrl = readl(versatile_ib2_ctrl);
  427. ctrl |= 0x01;
  428. writel(ctrl, versatile_ib2_ctrl);
  429. }
  430. #endif
  431. }
  432. /*
  433. * Detect which LCD panel is connected, and return the appropriate
  434. * clcd_panel structure. Note: we do not have any information on
  435. * the required timings for the 8.4in panel, so we presently assume
  436. * VGA timings.
  437. */
  438. static int versatile_clcd_setup(struct clcd_fb *fb)
  439. {
  440. void __iomem *sys_clcd = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_CLCD_OFFSET;
  441. const char *panel_name;
  442. u32 val;
  443. is_sanyo_2_5_lcd = false;
  444. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  445. if (val == SYS_CLCD_ID_SANYO_3_8)
  446. panel_name = "Sanyo TM38QV67A02A";
  447. else if (val == SYS_CLCD_ID_SANYO_2_5) {
  448. panel_name = "Sanyo QVGA Portrait";
  449. is_sanyo_2_5_lcd = true;
  450. } else if (val == SYS_CLCD_ID_EPSON_2_2)
  451. panel_name = "Epson L2F50113T00";
  452. else if (val == SYS_CLCD_ID_VGA)
  453. panel_name = "VGA";
  454. else {
  455. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  456. val);
  457. panel_name = "VGA";
  458. }
  459. fb->panel = versatile_clcd_get_panel(panel_name);
  460. if (!fb->panel)
  461. return -EINVAL;
  462. return versatile_clcd_setup_dma(fb, SZ_1M);
  463. }
  464. static void versatile_clcd_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  465. {
  466. clcdfb_decode(fb, regs);
  467. /* Always clear BGR for RGB565: we do the routing externally */
  468. if (fb->fb.var.green.length == 6)
  469. regs->cntl &= ~CNTL_BGR;
  470. }
  471. static struct clcd_board clcd_plat_data = {
  472. .name = "Versatile",
  473. .caps = CLCD_CAP_5551 | CLCD_CAP_565 | CLCD_CAP_888,
  474. .check = clcdfb_check,
  475. .decode = versatile_clcd_decode,
  476. .disable = versatile_clcd_disable,
  477. .enable = versatile_clcd_enable,
  478. .setup = versatile_clcd_setup,
  479. .mmap = versatile_clcd_mmap_dma,
  480. .remove = versatile_clcd_remove_dma,
  481. };
  482. static struct pl061_platform_data gpio0_plat_data = {
  483. .gpio_base = 0,
  484. .irq_base = IRQ_GPIO0_START,
  485. };
  486. static struct pl061_platform_data gpio1_plat_data = {
  487. .gpio_base = 8,
  488. .irq_base = IRQ_GPIO1_START,
  489. };
  490. static struct pl022_ssp_controller ssp0_plat_data = {
  491. .bus_id = 0,
  492. .enable_dma = 0,
  493. .num_chipselect = 1,
  494. };
  495. #define AACI_IRQ { IRQ_AACI }
  496. #define MMCI0_IRQ { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
  497. #define KMI0_IRQ { IRQ_SIC_KMI0 }
  498. #define KMI1_IRQ { IRQ_SIC_KMI1 }
  499. /*
  500. * These devices are connected directly to the multi-layer AHB switch
  501. */
  502. #define SMC_IRQ { }
  503. #define MPMC_IRQ { }
  504. #define CLCD_IRQ { IRQ_CLCDINT }
  505. #define DMAC_IRQ { IRQ_DMAINT }
  506. /*
  507. * These devices are connected via the core APB bridge
  508. */
  509. #define SCTL_IRQ { }
  510. #define WATCHDOG_IRQ { IRQ_WDOGINT }
  511. #define GPIO0_IRQ { IRQ_GPIOINT0 }
  512. #define GPIO1_IRQ { IRQ_GPIOINT1 }
  513. #define RTC_IRQ { IRQ_RTCINT }
  514. /*
  515. * These devices are connected via the DMA APB bridge
  516. */
  517. #define SCI_IRQ { IRQ_SCIINT }
  518. #define UART0_IRQ { IRQ_UARTINT0 }
  519. #define UART1_IRQ { IRQ_UARTINT1 }
  520. #define UART2_IRQ { IRQ_UARTINT2 }
  521. #define SSP_IRQ { IRQ_SSPINT }
  522. /* FPGA Primecells */
  523. APB_DEVICE(aaci, "fpga:04", AACI, NULL);
  524. APB_DEVICE(mmc0, "fpga:05", MMCI0, &mmc0_plat_data);
  525. APB_DEVICE(kmi0, "fpga:06", KMI0, NULL);
  526. APB_DEVICE(kmi1, "fpga:07", KMI1, NULL);
  527. /* DevChip Primecells */
  528. AHB_DEVICE(smc, "dev:00", SMC, NULL);
  529. AHB_DEVICE(mpmc, "dev:10", MPMC, NULL);
  530. AHB_DEVICE(clcd, "dev:20", CLCD, &clcd_plat_data);
  531. AHB_DEVICE(dmac, "dev:30", DMAC, NULL);
  532. APB_DEVICE(sctl, "dev:e0", SCTL, NULL);
  533. APB_DEVICE(wdog, "dev:e1", WATCHDOG, NULL);
  534. APB_DEVICE(gpio0, "dev:e4", GPIO0, &gpio0_plat_data);
  535. APB_DEVICE(gpio1, "dev:e5", GPIO1, &gpio1_plat_data);
  536. APB_DEVICE(rtc, "dev:e8", RTC, NULL);
  537. APB_DEVICE(sci0, "dev:f0", SCI, NULL);
  538. APB_DEVICE(uart0, "dev:f1", UART0, NULL);
  539. APB_DEVICE(uart1, "dev:f2", UART1, NULL);
  540. APB_DEVICE(uart2, "dev:f3", UART2, NULL);
  541. APB_DEVICE(ssp0, "dev:f4", SSP, &ssp0_plat_data);
  542. static struct amba_device *amba_devs[] __initdata = {
  543. &dmac_device,
  544. &uart0_device,
  545. &uart1_device,
  546. &uart2_device,
  547. &smc_device,
  548. &mpmc_device,
  549. &clcd_device,
  550. &sctl_device,
  551. &wdog_device,
  552. &gpio0_device,
  553. &gpio1_device,
  554. &rtc_device,
  555. &sci0_device,
  556. &ssp0_device,
  557. &aaci_device,
  558. &mmc0_device,
  559. &kmi0_device,
  560. &kmi1_device,
  561. };
  562. #ifdef CONFIG_OF
  563. /*
  564. * Lookup table for attaching a specific name and platform_data pointer to
  565. * devices as they get created by of_platform_populate(). Ideally this table
  566. * would not exist, but the current clock implementation depends on some devices
  567. * having a specific name.
  568. */
  569. struct of_dev_auxdata versatile_auxdata_lookup[] __initdata = {
  570. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI0_BASE, "fpga:05", &mmc0_plat_data),
  571. OF_DEV_AUXDATA("arm,primecell", VERSATILE_KMI0_BASE, "fpga:06", NULL),
  572. OF_DEV_AUXDATA("arm,primecell", VERSATILE_KMI1_BASE, "fpga:07", NULL),
  573. OF_DEV_AUXDATA("arm,primecell", VERSATILE_UART3_BASE, "fpga:09", NULL),
  574. /* FIXME: this is buggy, the platform data is needed for this MMC instance too */
  575. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI1_BASE, "fpga:0b", NULL),
  576. OF_DEV_AUXDATA("arm,primecell", VERSATILE_CLCD_BASE, "dev:20", &clcd_plat_data),
  577. OF_DEV_AUXDATA("arm,primecell", VERSATILE_UART0_BASE, "dev:f1", NULL),
  578. OF_DEV_AUXDATA("arm,primecell", VERSATILE_UART1_BASE, "dev:f2", NULL),
  579. OF_DEV_AUXDATA("arm,primecell", VERSATILE_UART2_BASE, "dev:f3", NULL),
  580. OF_DEV_AUXDATA("arm,primecell", VERSATILE_SSP_BASE, "dev:f4", &ssp0_plat_data),
  581. #if 0
  582. /*
  583. * These entries are unnecessary because no clocks referencing
  584. * them. I've left them in for now as place holders in case
  585. * any of them need to be added back, but they should be
  586. * removed before actually committing this patch. --gcl
  587. */
  588. OF_DEV_AUXDATA("arm,primecell", VERSATILE_AACI_BASE, "fpga:04", NULL),
  589. OF_DEV_AUXDATA("arm,primecell", VERSATILE_SCI1_BASE, "fpga:0a", NULL),
  590. OF_DEV_AUXDATA("arm,primecell", VERSATILE_SMC_BASE, "dev:00", NULL),
  591. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MPMC_BASE, "dev:10", NULL),
  592. OF_DEV_AUXDATA("arm,primecell", VERSATILE_DMAC_BASE, "dev:30", NULL),
  593. OF_DEV_AUXDATA("arm,primecell", VERSATILE_SCTL_BASE, "dev:e0", NULL),
  594. OF_DEV_AUXDATA("arm,primecell", VERSATILE_WATCHDOG_BASE, "dev:e1", NULL),
  595. OF_DEV_AUXDATA("arm,primecell", VERSATILE_GPIO0_BASE, "dev:e4", NULL),
  596. OF_DEV_AUXDATA("arm,primecell", VERSATILE_GPIO1_BASE, "dev:e5", NULL),
  597. OF_DEV_AUXDATA("arm,primecell", VERSATILE_GPIO2_BASE, "dev:e6", NULL),
  598. OF_DEV_AUXDATA("arm,primecell", VERSATILE_GPIO3_BASE, "dev:e7", NULL),
  599. OF_DEV_AUXDATA("arm,primecell", VERSATILE_RTC_BASE, "dev:e8", NULL),
  600. OF_DEV_AUXDATA("arm,primecell", VERSATILE_SCI_BASE, "dev:f0", NULL),
  601. #endif
  602. {}
  603. };
  604. #endif
  605. #ifdef CONFIG_LEDS
  606. #define VA_LEDS_BASE (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
  607. static void versatile_leds_event(led_event_t ledevt)
  608. {
  609. unsigned long flags;
  610. u32 val;
  611. local_irq_save(flags);
  612. val = readl(VA_LEDS_BASE);
  613. switch (ledevt) {
  614. case led_idle_start:
  615. val = val & ~VERSATILE_SYS_LED0;
  616. break;
  617. case led_idle_end:
  618. val = val | VERSATILE_SYS_LED0;
  619. break;
  620. case led_timer:
  621. val = val ^ VERSATILE_SYS_LED1;
  622. break;
  623. case led_halted:
  624. val = 0;
  625. break;
  626. default:
  627. break;
  628. }
  629. writel(val, VA_LEDS_BASE);
  630. local_irq_restore(flags);
  631. }
  632. #endif /* CONFIG_LEDS */
  633. void versatile_restart(char mode, const char *cmd)
  634. {
  635. void __iomem *sys = __io_address(VERSATILE_SYS_BASE);
  636. u32 val;
  637. val = __raw_readl(sys + VERSATILE_SYS_RESETCTL_OFFSET);
  638. val |= 0x105;
  639. __raw_writel(0xa05f, sys + VERSATILE_SYS_LOCK_OFFSET);
  640. __raw_writel(val, sys + VERSATILE_SYS_RESETCTL_OFFSET);
  641. __raw_writel(0, sys + VERSATILE_SYS_LOCK_OFFSET);
  642. }
  643. /* Early initializations */
  644. void __init versatile_init_early(void)
  645. {
  646. void __iomem *sys = __io_address(VERSATILE_SYS_BASE);
  647. osc4_clk.vcoreg = sys + VERSATILE_SYS_OSCCLCD_OFFSET;
  648. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  649. versatile_sched_clock_init(sys + VERSATILE_SYS_24MHz_OFFSET, 24000000);
  650. }
  651. void __init versatile_init(void)
  652. {
  653. int i;
  654. platform_device_register(&versatile_flash_device);
  655. platform_device_register(&versatile_i2c_device);
  656. platform_device_register(&smc91x_device);
  657. platform_device_register(&char_lcd_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. /*
  674. * Set up timer interrupt, and return the current time in seconds.
  675. */
  676. static void __init versatile_timer_init(void)
  677. {
  678. u32 val;
  679. /*
  680. * set clock frequency:
  681. * VERSATILE_REFCLK is 32KHz
  682. * VERSATILE_TIMCLK is 1MHz
  683. */
  684. val = readl(__io_address(VERSATILE_SCTL_BASE));
  685. writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
  686. (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  687. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
  688. (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
  689. __io_address(VERSATILE_SCTL_BASE));
  690. /*
  691. * Initialise to a known state (all timers off)
  692. */
  693. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  694. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  695. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  696. writel(0, TIMER3_VA_BASE + TIMER_CTRL);
  697. sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
  698. sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1, "timer0");
  699. }
  700. struct sys_timer versatile_timer = {
  701. .init = versatile_timer_init,
  702. };