core.c 21 KB

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