integrator_cp.c 13 KB

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