core.c 22 KB

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