integrator_cp.c 12 KB

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