integrator_cp.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * linux/arch/arm/mach-integrator/integrator_cp.c
  3. *
  4. * Copyright (C) 2003 Deep Blue Solutions Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/list.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/string.h>
  17. #include <linux/sysdev.h>
  18. #include <linux/amba/bus.h>
  19. #include <linux/amba/kmi.h>
  20. #include <linux/amba/clcd.h>
  21. #include <linux/amba/mmci.h>
  22. #include <linux/io.h>
  23. #include <linux/gfp.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/hardware.h>
  26. #include <mach/platform.h>
  27. #include <asm/irq.h>
  28. #include <asm/setup.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/hardware/arm_timer.h>
  31. #include <asm/hardware/icst.h>
  32. #include <mach/cm.h>
  33. #include <mach/lm.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/mach/flash.h>
  36. #include <asm/mach/irq.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/time.h>
  39. #include <asm/hardware/timer-sp.h>
  40. #include <plat/clcd.h>
  41. #include "common.h"
  42. #define INTCP_PA_FLASH_BASE 0x24000000
  43. #define INTCP_FLASH_SIZE SZ_32M
  44. #define INTCP_PA_CLCD_BASE 0xc0000000
  45. #define INTCP_VA_CIC_BASE IO_ADDRESS(INTEGRATOR_HDR_BASE + 0x40)
  46. #define INTCP_VA_PIC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
  47. #define INTCP_VA_SIC_BASE IO_ADDRESS(INTEGRATOR_CP_SIC_BASE)
  48. #define INTCP_ETH_SIZE 0x10
  49. #define INTCP_VA_CTRL_BASE IO_ADDRESS(INTEGRATOR_CP_CTL_BASE)
  50. #define INTCP_FLASHPROG 0x04
  51. #define CINTEGRATOR_FLASHPROG_FLVPPEN (1 << 0)
  52. #define CINTEGRATOR_FLASHPROG_FLWREN (1 << 1)
  53. /*
  54. * Logical Physical
  55. * f1000000 10000000 Core module registers
  56. * f1100000 11000000 System controller registers
  57. * f1200000 12000000 EBI registers
  58. * f1300000 13000000 Counter/Timer
  59. * f1400000 14000000 Interrupt controller
  60. * f1600000 16000000 UART 0
  61. * f1700000 17000000 UART 1
  62. * f1a00000 1a000000 Debug LEDs
  63. * fc900000 c9000000 GPIO
  64. * fca00000 ca000000 SIC
  65. * fcb00000 cb000000 CP system control
  66. */
  67. static struct map_desc intcp_io_desc[] __initdata = {
  68. {
  69. .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE),
  70. .pfn = __phys_to_pfn(INTEGRATOR_HDR_BASE),
  71. .length = SZ_4K,
  72. .type = MT_DEVICE
  73. }, {
  74. .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE),
  75. .pfn = __phys_to_pfn(INTEGRATOR_SC_BASE),
  76. .length = SZ_4K,
  77. .type = MT_DEVICE
  78. }, {
  79. .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE),
  80. .pfn = __phys_to_pfn(INTEGRATOR_EBI_BASE),
  81. .length = SZ_4K,
  82. .type = MT_DEVICE
  83. }, {
  84. .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE),
  85. .pfn = __phys_to_pfn(INTEGRATOR_CT_BASE),
  86. .length = SZ_4K,
  87. .type = MT_DEVICE
  88. }, {
  89. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  90. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  91. .length = SZ_4K,
  92. .type = MT_DEVICE
  93. }, {
  94. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  95. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  96. .length = SZ_4K,
  97. .type = MT_DEVICE
  98. }, {
  99. .virtual = IO_ADDRESS(INTEGRATOR_UART1_BASE),
  100. .pfn = __phys_to_pfn(INTEGRATOR_UART1_BASE),
  101. .length = SZ_4K,
  102. .type = MT_DEVICE
  103. }, {
  104. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  105. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  106. .length = SZ_4K,
  107. .type = MT_DEVICE
  108. }, {
  109. .virtual = IO_ADDRESS(INTEGRATOR_CP_GPIO_BASE),
  110. .pfn = __phys_to_pfn(INTEGRATOR_CP_GPIO_BASE),
  111. .length = SZ_4K,
  112. .type = MT_DEVICE
  113. }, {
  114. .virtual = IO_ADDRESS(INTEGRATOR_CP_SIC_BASE),
  115. .pfn = __phys_to_pfn(INTEGRATOR_CP_SIC_BASE),
  116. .length = SZ_4K,
  117. .type = MT_DEVICE
  118. }, {
  119. .virtual = IO_ADDRESS(INTEGRATOR_CP_CTL_BASE),
  120. .pfn = __phys_to_pfn(INTEGRATOR_CP_CTL_BASE),
  121. .length = SZ_4K,
  122. .type = MT_DEVICE
  123. }
  124. };
  125. static void __init intcp_map_io(void)
  126. {
  127. iotable_init(intcp_io_desc, ARRAY_SIZE(intcp_io_desc));
  128. }
  129. #define cic_writel __raw_writel
  130. #define cic_readl __raw_readl
  131. #define pic_writel __raw_writel
  132. #define pic_readl __raw_readl
  133. #define sic_writel __raw_writel
  134. #define sic_readl __raw_readl
  135. static void cic_mask_irq(struct irq_data *d)
  136. {
  137. unsigned int irq = d->irq - IRQ_CIC_START;
  138. cic_writel(1 << irq, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
  139. }
  140. static void cic_unmask_irq(struct irq_data *d)
  141. {
  142. unsigned int irq = d->irq - IRQ_CIC_START;
  143. cic_writel(1 << irq, INTCP_VA_CIC_BASE + IRQ_ENABLE_SET);
  144. }
  145. static struct irq_chip cic_chip = {
  146. .name = "CIC",
  147. .irq_ack = cic_mask_irq,
  148. .irq_mask = cic_mask_irq,
  149. .irq_unmask = cic_unmask_irq,
  150. };
  151. static void pic_mask_irq(struct irq_data *d)
  152. {
  153. unsigned int irq = d->irq - IRQ_PIC_START;
  154. pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
  155. }
  156. static void pic_unmask_irq(struct irq_data *d)
  157. {
  158. unsigned int irq = d->irq - IRQ_PIC_START;
  159. pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_SET);
  160. }
  161. static struct irq_chip pic_chip = {
  162. .name = "PIC",
  163. .irq_ack = pic_mask_irq,
  164. .irq_mask = pic_mask_irq,
  165. .irq_unmask = pic_unmask_irq,
  166. };
  167. static void sic_mask_irq(struct irq_data *d)
  168. {
  169. unsigned int irq = d->irq - IRQ_SIC_START;
  170. sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
  171. }
  172. static void sic_unmask_irq(struct irq_data *d)
  173. {
  174. unsigned int irq = d->irq - IRQ_SIC_START;
  175. sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_SET);
  176. }
  177. static struct irq_chip sic_chip = {
  178. .name = "SIC",
  179. .irq_ack = sic_mask_irq,
  180. .irq_mask = sic_mask_irq,
  181. .irq_unmask = sic_unmask_irq,
  182. };
  183. static void
  184. sic_handle_irq(unsigned int irq, struct irq_desc *desc)
  185. {
  186. unsigned long status = sic_readl(INTCP_VA_SIC_BASE + IRQ_STATUS);
  187. if (status == 0) {
  188. do_bad_IRQ(irq, desc);
  189. return;
  190. }
  191. do {
  192. irq = ffs(status) - 1;
  193. status &= ~(1 << irq);
  194. irq += IRQ_SIC_START;
  195. generic_handle_irq(irq);
  196. } while (status);
  197. }
  198. static void __init intcp_init_irq(void)
  199. {
  200. unsigned int i;
  201. /*
  202. * Disable all interrupt sources
  203. */
  204. pic_writel(0xffffffff, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
  205. pic_writel(0xffffffff, INTCP_VA_PIC_BASE + FIQ_ENABLE_CLEAR);
  206. for (i = IRQ_PIC_START; i <= IRQ_PIC_END; i++) {
  207. if (i == 11)
  208. i = 22;
  209. if (i == 29)
  210. break;
  211. set_irq_chip(i, &pic_chip);
  212. set_irq_handler(i, handle_level_irq);
  213. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  214. }
  215. cic_writel(0xffffffff, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
  216. cic_writel(0xffffffff, INTCP_VA_CIC_BASE + FIQ_ENABLE_CLEAR);
  217. for (i = IRQ_CIC_START; i <= IRQ_CIC_END; i++) {
  218. set_irq_chip(i, &cic_chip);
  219. set_irq_handler(i, handle_level_irq);
  220. set_irq_flags(i, IRQF_VALID);
  221. }
  222. sic_writel(0x00000fff, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
  223. sic_writel(0x00000fff, INTCP_VA_SIC_BASE + FIQ_ENABLE_CLEAR);
  224. for (i = IRQ_SIC_START; i <= IRQ_SIC_END; i++) {
  225. set_irq_chip(i, &sic_chip);
  226. set_irq_handler(i, handle_level_irq);
  227. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  228. }
  229. set_irq_chained_handler(IRQ_CP_CPPLDINT, sic_handle_irq);
  230. }
  231. /*
  232. * Clock handling
  233. */
  234. #define CM_LOCK (__io_address(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
  235. #define CM_AUXOSC (__io_address(INTEGRATOR_HDR_BASE)+0x1c)
  236. static const struct icst_params cp_auxvco_params = {
  237. .ref = 24000000,
  238. .vco_max = ICST525_VCO_MAX_5V,
  239. .vco_min = ICST525_VCO_MIN,
  240. .vd_min = 8,
  241. .vd_max = 263,
  242. .rd_min = 3,
  243. .rd_max = 65,
  244. .s2div = icst525_s2div,
  245. .idx2s = icst525_idx2s,
  246. };
  247. static void cp_auxvco_set(struct clk *clk, struct icst_vco vco)
  248. {
  249. u32 val;
  250. val = readl(clk->vcoreg) & ~0x7ffff;
  251. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  252. writel(0xa05f, CM_LOCK);
  253. writel(val, clk->vcoreg);
  254. writel(0, CM_LOCK);
  255. }
  256. static const struct clk_ops cp_auxclk_ops = {
  257. .round = icst_clk_round,
  258. .set = icst_clk_set,
  259. .setvco = cp_auxvco_set,
  260. };
  261. static struct clk cp_auxclk = {
  262. .ops = &cp_auxclk_ops,
  263. .params = &cp_auxvco_params,
  264. .vcoreg = CM_AUXOSC,
  265. };
  266. static struct clk_lookup cp_lookups[] = {
  267. { /* CLCD */
  268. .dev_id = "mb:c0",
  269. .clk = &cp_auxclk,
  270. },
  271. };
  272. /*
  273. * Flash handling.
  274. */
  275. static int intcp_flash_init(void)
  276. {
  277. u32 val;
  278. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  279. val |= CINTEGRATOR_FLASHPROG_FLWREN;
  280. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  281. return 0;
  282. }
  283. static void intcp_flash_exit(void)
  284. {
  285. u32 val;
  286. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  287. val &= ~(CINTEGRATOR_FLASHPROG_FLVPPEN|CINTEGRATOR_FLASHPROG_FLWREN);
  288. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  289. }
  290. static void intcp_flash_set_vpp(int on)
  291. {
  292. u32 val;
  293. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  294. if (on)
  295. val |= CINTEGRATOR_FLASHPROG_FLVPPEN;
  296. else
  297. val &= ~CINTEGRATOR_FLASHPROG_FLVPPEN;
  298. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  299. }
  300. static struct flash_platform_data intcp_flash_data = {
  301. .map_name = "cfi_probe",
  302. .width = 4,
  303. .init = intcp_flash_init,
  304. .exit = intcp_flash_exit,
  305. .set_vpp = intcp_flash_set_vpp,
  306. };
  307. static struct resource intcp_flash_resource = {
  308. .start = INTCP_PA_FLASH_BASE,
  309. .end = INTCP_PA_FLASH_BASE + INTCP_FLASH_SIZE - 1,
  310. .flags = IORESOURCE_MEM,
  311. };
  312. static struct platform_device intcp_flash_device = {
  313. .name = "armflash",
  314. .id = 0,
  315. .dev = {
  316. .platform_data = &intcp_flash_data,
  317. },
  318. .num_resources = 1,
  319. .resource = &intcp_flash_resource,
  320. };
  321. static struct resource smc91x_resources[] = {
  322. [0] = {
  323. .start = INTEGRATOR_CP_ETH_BASE,
  324. .end = INTEGRATOR_CP_ETH_BASE + INTCP_ETH_SIZE - 1,
  325. .flags = IORESOURCE_MEM,
  326. },
  327. [1] = {
  328. .start = IRQ_CP_ETHINT,
  329. .end = IRQ_CP_ETHINT,
  330. .flags = IORESOURCE_IRQ,
  331. },
  332. };
  333. static struct platform_device smc91x_device = {
  334. .name = "smc91x",
  335. .id = 0,
  336. .num_resources = ARRAY_SIZE(smc91x_resources),
  337. .resource = smc91x_resources,
  338. };
  339. static struct platform_device *intcp_devs[] __initdata = {
  340. &intcp_flash_device,
  341. &smc91x_device,
  342. };
  343. /*
  344. * It seems that the card insertion interrupt remains active after
  345. * we've acknowledged it. We therefore ignore the interrupt, and
  346. * rely on reading it from the SIC. This also means that we must
  347. * clear the latched interrupt.
  348. */
  349. static unsigned int mmc_status(struct device *dev)
  350. {
  351. unsigned int status = readl(IO_ADDRESS(0xca000000 + 4));
  352. writel(8, IO_ADDRESS(INTEGRATOR_CP_CTL_BASE + 8));
  353. return status & 8;
  354. }
  355. static struct mmci_platform_data mmc_data = {
  356. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  357. .status = mmc_status,
  358. .gpio_wp = -1,
  359. .gpio_cd = -1,
  360. };
  361. static struct amba_device mmc_device = {
  362. .dev = {
  363. .init_name = "mb:1c",
  364. .platform_data = &mmc_data,
  365. },
  366. .res = {
  367. .start = INTEGRATOR_CP_MMC_BASE,
  368. .end = INTEGRATOR_CP_MMC_BASE + SZ_4K - 1,
  369. .flags = IORESOURCE_MEM,
  370. },
  371. .irq = { IRQ_CP_MMCIINT0, IRQ_CP_MMCIINT1 },
  372. .periphid = 0,
  373. };
  374. static struct amba_device aaci_device = {
  375. .dev = {
  376. .init_name = "mb:1d",
  377. },
  378. .res = {
  379. .start = INTEGRATOR_CP_AACI_BASE,
  380. .end = INTEGRATOR_CP_AACI_BASE + SZ_4K - 1,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. .irq = { IRQ_CP_AACIINT, NO_IRQ },
  384. .periphid = 0,
  385. };
  386. /*
  387. * CLCD support
  388. */
  389. /*
  390. * Ensure VGA is selected.
  391. */
  392. static void cp_clcd_enable(struct clcd_fb *fb)
  393. {
  394. struct fb_var_screeninfo *var = &fb->fb.var;
  395. u32 val = CM_CTRL_STATIC1 | CM_CTRL_STATIC2;
  396. if (var->bits_per_pixel <= 8 ||
  397. (var->bits_per_pixel == 16 && var->green.length == 5))
  398. /* Pseudocolor, RGB555, BGR555 */
  399. val |= CM_CTRL_LCDMUXSEL_VGA555_TFT555;
  400. else if (fb->fb.var.bits_per_pixel <= 16)
  401. /* truecolor RGB565 */
  402. val |= CM_CTRL_LCDMUXSEL_VGA565_TFT555;
  403. else
  404. val = 0; /* no idea for this, don't trust the docs */
  405. cm_control(CM_CTRL_LCDMUXSEL_MASK|
  406. CM_CTRL_LCDEN0|
  407. CM_CTRL_LCDEN1|
  408. CM_CTRL_STATIC1|
  409. CM_CTRL_STATIC2|
  410. CM_CTRL_STATIC|
  411. CM_CTRL_n24BITEN, val);
  412. }
  413. static int cp_clcd_setup(struct clcd_fb *fb)
  414. {
  415. fb->panel = versatile_clcd_get_panel("VGA");
  416. if (!fb->panel)
  417. return -EINVAL;
  418. return versatile_clcd_setup_dma(fb, SZ_1M);
  419. }
  420. static struct clcd_board clcd_data = {
  421. .name = "Integrator/CP",
  422. .caps = CLCD_CAP_5551 | CLCD_CAP_RGB565 | CLCD_CAP_888,
  423. .check = clcdfb_check,
  424. .decode = clcdfb_decode,
  425. .enable = cp_clcd_enable,
  426. .setup = cp_clcd_setup,
  427. .mmap = versatile_clcd_mmap_dma,
  428. .remove = versatile_clcd_remove_dma,
  429. };
  430. static struct amba_device clcd_device = {
  431. .dev = {
  432. .init_name = "mb:c0",
  433. .coherent_dma_mask = ~0,
  434. .platform_data = &clcd_data,
  435. },
  436. .res = {
  437. .start = INTCP_PA_CLCD_BASE,
  438. .end = INTCP_PA_CLCD_BASE + SZ_4K - 1,
  439. .flags = IORESOURCE_MEM,
  440. },
  441. .dma_mask = ~0,
  442. .irq = { IRQ_CP_CLCDCINT, NO_IRQ },
  443. .periphid = 0,
  444. };
  445. static struct amba_device *amba_devs[] __initdata = {
  446. &mmc_device,
  447. &aaci_device,
  448. &clcd_device,
  449. };
  450. static void __init intcp_init(void)
  451. {
  452. int i;
  453. clkdev_add_table(cp_lookups, ARRAY_SIZE(cp_lookups));
  454. platform_add_devices(intcp_devs, ARRAY_SIZE(intcp_devs));
  455. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  456. struct amba_device *d = amba_devs[i];
  457. amba_device_register(d, &iomem_resource);
  458. }
  459. }
  460. #define TIMER0_VA_BASE __io_address(INTEGRATOR_TIMER0_BASE)
  461. #define TIMER1_VA_BASE __io_address(INTEGRATOR_TIMER1_BASE)
  462. #define TIMER2_VA_BASE __io_address(INTEGRATOR_TIMER2_BASE)
  463. static void __init intcp_timer_init(void)
  464. {
  465. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  466. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  467. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  468. sp804_clocksource_init(TIMER2_VA_BASE);
  469. sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1);
  470. }
  471. static struct sys_timer cp_timer = {
  472. .init = intcp_timer_init,
  473. };
  474. MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
  475. /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
  476. .boot_params = 0x00000100,
  477. .map_io = intcp_map_io,
  478. .reserve = integrator_reserve,
  479. .init_irq = intcp_init_irq,
  480. .timer = &cp_timer,
  481. .init_machine = intcp_init,
  482. MACHINE_END