integrator_cp.c 13 KB

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