core.c 21 KB

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