integrator_cp.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 irq_chip cic_chip = {
  143. .name = "CIC",
  144. .ack = cic_mask_irq,
  145. .mask = cic_mask_irq,
  146. .unmask = cic_unmask_irq,
  147. };
  148. static void pic_mask_irq(unsigned int irq)
  149. {
  150. irq -= IRQ_PIC_START;
  151. pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
  152. }
  153. static void pic_unmask_irq(unsigned int irq)
  154. {
  155. irq -= IRQ_PIC_START;
  156. pic_writel(1 << irq, INTCP_VA_PIC_BASE + IRQ_ENABLE_SET);
  157. }
  158. static struct irq_chip pic_chip = {
  159. .name = "PIC",
  160. .ack = pic_mask_irq,
  161. .mask = pic_mask_irq,
  162. .unmask = pic_unmask_irq,
  163. };
  164. static void sic_mask_irq(unsigned int irq)
  165. {
  166. irq -= IRQ_SIC_START;
  167. sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
  168. }
  169. static void sic_unmask_irq(unsigned int irq)
  170. {
  171. irq -= IRQ_SIC_START;
  172. sic_writel(1 << irq, INTCP_VA_SIC_BASE + IRQ_ENABLE_SET);
  173. }
  174. static struct irq_chip sic_chip = {
  175. .name = "SIC",
  176. .ack = sic_mask_irq,
  177. .mask = sic_mask_irq,
  178. .unmask = sic_unmask_irq,
  179. };
  180. static void
  181. sic_handle_irq(unsigned int irq, struct irq_desc *desc)
  182. {
  183. unsigned long status = sic_readl(INTCP_VA_SIC_BASE + IRQ_STATUS);
  184. if (status == 0) {
  185. do_bad_IRQ(irq, desc);
  186. return;
  187. }
  188. do {
  189. irq = ffs(status) - 1;
  190. status &= ~(1 << irq);
  191. irq += IRQ_SIC_START;
  192. desc = irq_desc + irq;
  193. desc_handle_irq(irq, desc);
  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_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
  233. #define CM_AUXOSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+0x1c)
  234. static const struct icst525_params cp_auxvco_params = {
  235. .ref = 24000,
  236. .vco_max = 320000,
  237. .vd_min = 8,
  238. .vd_max = 263,
  239. .rd_min = 3,
  240. .rd_max = 65,
  241. };
  242. static void cp_auxvco_set(struct clk *clk, struct icst525_vco vco)
  243. {
  244. u32 val;
  245. val = readl(CM_AUXOSC) & ~0x7ffff;
  246. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  247. writel(0xa05f, CM_LOCK);
  248. writel(val, CM_AUXOSC);
  249. writel(0, CM_LOCK);
  250. }
  251. static struct clk cp_clcd_clk = {
  252. .name = "CLCDCLK",
  253. .params = &cp_auxvco_params,
  254. .setvco = cp_auxvco_set,
  255. };
  256. static struct clk cp_mmci_clk = {
  257. .name = "MCLK",
  258. .rate = 14745600,
  259. };
  260. /*
  261. * Flash handling.
  262. */
  263. static int intcp_flash_init(void)
  264. {
  265. u32 val;
  266. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  267. val |= CINTEGRATOR_FLASHPROG_FLWREN;
  268. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  269. return 0;
  270. }
  271. static void intcp_flash_exit(void)
  272. {
  273. u32 val;
  274. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  275. val &= ~(CINTEGRATOR_FLASHPROG_FLVPPEN|CINTEGRATOR_FLASHPROG_FLWREN);
  276. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  277. }
  278. static void intcp_flash_set_vpp(int on)
  279. {
  280. u32 val;
  281. val = readl(INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  282. if (on)
  283. val |= CINTEGRATOR_FLASHPROG_FLVPPEN;
  284. else
  285. val &= ~CINTEGRATOR_FLASHPROG_FLVPPEN;
  286. writel(val, INTCP_VA_CTRL_BASE + INTCP_FLASHPROG);
  287. }
  288. static struct flash_platform_data intcp_flash_data = {
  289. .map_name = "cfi_probe",
  290. .width = 4,
  291. .init = intcp_flash_init,
  292. .exit = intcp_flash_exit,
  293. .set_vpp = intcp_flash_set_vpp,
  294. };
  295. static struct resource intcp_flash_resource = {
  296. .start = INTCP_PA_FLASH_BASE,
  297. .end = INTCP_PA_FLASH_BASE + INTCP_FLASH_SIZE - 1,
  298. .flags = IORESOURCE_MEM,
  299. };
  300. static struct platform_device intcp_flash_device = {
  301. .name = "armflash",
  302. .id = 0,
  303. .dev = {
  304. .platform_data = &intcp_flash_data,
  305. },
  306. .num_resources = 1,
  307. .resource = &intcp_flash_resource,
  308. };
  309. static struct resource smc91x_resources[] = {
  310. [0] = {
  311. .start = INTCP_PA_ETH_BASE,
  312. .end = INTCP_PA_ETH_BASE + INTCP_ETH_SIZE - 1,
  313. .flags = IORESOURCE_MEM,
  314. },
  315. [1] = {
  316. .start = IRQ_CP_ETHINT,
  317. .end = IRQ_CP_ETHINT,
  318. .flags = IORESOURCE_IRQ,
  319. },
  320. };
  321. static struct platform_device smc91x_device = {
  322. .name = "smc91x",
  323. .id = 0,
  324. .num_resources = ARRAY_SIZE(smc91x_resources),
  325. .resource = smc91x_resources,
  326. };
  327. static struct platform_device *intcp_devs[] __initdata = {
  328. &intcp_flash_device,
  329. &smc91x_device,
  330. };
  331. /*
  332. * It seems that the card insertion interrupt remains active after
  333. * we've acknowledged it. We therefore ignore the interrupt, and
  334. * rely on reading it from the SIC. This also means that we must
  335. * clear the latched interrupt.
  336. */
  337. static unsigned int mmc_status(struct device *dev)
  338. {
  339. unsigned int status = readl(0xfca00004);
  340. writel(8, 0xfcb00008);
  341. return status & 8;
  342. }
  343. static struct mmc_platform_data mmc_data = {
  344. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  345. .status = mmc_status,
  346. };
  347. static struct amba_device mmc_device = {
  348. .dev = {
  349. .bus_id = "mb:1c",
  350. .platform_data = &mmc_data,
  351. },
  352. .res = {
  353. .start = INTCP_PA_MMC_BASE,
  354. .end = INTCP_PA_MMC_BASE + SZ_4K - 1,
  355. .flags = IORESOURCE_MEM,
  356. },
  357. .irq = { IRQ_CP_MMCIINT0, IRQ_CP_MMCIINT1 },
  358. .periphid = 0,
  359. };
  360. static struct amba_device aaci_device = {
  361. .dev = {
  362. .bus_id = "mb:1d",
  363. },
  364. .res = {
  365. .start = INTCP_PA_AACI_BASE,
  366. .end = INTCP_PA_AACI_BASE + SZ_4K - 1,
  367. .flags = IORESOURCE_MEM,
  368. },
  369. .irq = { IRQ_CP_AACIINT, NO_IRQ },
  370. .periphid = 0,
  371. };
  372. /*
  373. * CLCD support
  374. */
  375. static struct clcd_panel vga = {
  376. .mode = {
  377. .name = "VGA",
  378. .refresh = 60,
  379. .xres = 640,
  380. .yres = 480,
  381. .pixclock = 39721,
  382. .left_margin = 40,
  383. .right_margin = 24,
  384. .upper_margin = 32,
  385. .lower_margin = 11,
  386. .hsync_len = 96,
  387. .vsync_len = 2,
  388. .sync = 0,
  389. .vmode = FB_VMODE_NONINTERLACED,
  390. },
  391. .width = -1,
  392. .height = -1,
  393. .tim2 = TIM2_BCD | TIM2_IPC,
  394. .cntl = CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  395. .bpp = 16,
  396. .grayscale = 0,
  397. };
  398. /*
  399. * Ensure VGA is selected.
  400. */
  401. static void cp_clcd_enable(struct clcd_fb *fb)
  402. {
  403. u32 val;
  404. if (fb->fb.var.bits_per_pixel <= 8)
  405. val = CM_CTRL_LCDMUXSEL_VGA_8421BPP;
  406. else if (fb->fb.var.bits_per_pixel <= 16)
  407. val = CM_CTRL_LCDMUXSEL_VGA_16BPP
  408. | CM_CTRL_LCDEN0 | CM_CTRL_LCDEN1
  409. | CM_CTRL_STATIC1 | CM_CTRL_STATIC2;
  410. else
  411. val = 0; /* no idea for this, don't trust the docs */
  412. cm_control(CM_CTRL_LCDMUXSEL_MASK|
  413. CM_CTRL_LCDEN0|
  414. CM_CTRL_LCDEN1|
  415. CM_CTRL_STATIC1|
  416. CM_CTRL_STATIC2|
  417. CM_CTRL_STATIC|
  418. CM_CTRL_n24BITEN, val);
  419. }
  420. static unsigned long framesize = SZ_1M;
  421. static int cp_clcd_setup(struct clcd_fb *fb)
  422. {
  423. dma_addr_t dma;
  424. fb->panel = &vga;
  425. fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
  426. &dma, GFP_KERNEL);
  427. if (!fb->fb.screen_base) {
  428. printk(KERN_ERR "CLCD: unable to map framebuffer\n");
  429. return -ENOMEM;
  430. }
  431. fb->fb.fix.smem_start = dma;
  432. fb->fb.fix.smem_len = framesize;
  433. return 0;
  434. }
  435. static int cp_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  436. {
  437. return dma_mmap_writecombine(&fb->dev->dev, vma,
  438. fb->fb.screen_base,
  439. fb->fb.fix.smem_start,
  440. fb->fb.fix.smem_len);
  441. }
  442. static void cp_clcd_remove(struct clcd_fb *fb)
  443. {
  444. dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
  445. fb->fb.screen_base, fb->fb.fix.smem_start);
  446. }
  447. static struct clcd_board clcd_data = {
  448. .name = "Integrator/CP",
  449. .check = clcdfb_check,
  450. .decode = clcdfb_decode,
  451. .enable = cp_clcd_enable,
  452. .setup = cp_clcd_setup,
  453. .mmap = cp_clcd_mmap,
  454. .remove = cp_clcd_remove,
  455. };
  456. static struct amba_device clcd_device = {
  457. .dev = {
  458. .bus_id = "mb:c0",
  459. .coherent_dma_mask = ~0,
  460. .platform_data = &clcd_data,
  461. },
  462. .res = {
  463. .start = INTCP_PA_CLCD_BASE,
  464. .end = INTCP_PA_CLCD_BASE + SZ_4K - 1,
  465. .flags = IORESOURCE_MEM,
  466. },
  467. .dma_mask = ~0,
  468. .irq = { IRQ_CP_CLCDCINT, NO_IRQ },
  469. .periphid = 0,
  470. };
  471. static struct amba_device *amba_devs[] __initdata = {
  472. &mmc_device,
  473. &aaci_device,
  474. &clcd_device,
  475. };
  476. static void __init intcp_init(void)
  477. {
  478. int i;
  479. clk_register(&cp_clcd_clk);
  480. clk_register(&cp_mmci_clk);
  481. platform_add_devices(intcp_devs, ARRAY_SIZE(intcp_devs));
  482. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  483. struct amba_device *d = amba_devs[i];
  484. amba_device_register(d, &iomem_resource);
  485. }
  486. }
  487. #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable */
  488. static void __init intcp_timer_init(void)
  489. {
  490. integrator_time_init(1000000 / HZ, TIMER_CTRL_IE);
  491. }
  492. static struct sys_timer cp_timer = {
  493. .init = intcp_timer_init,
  494. .offset = integrator_gettimeoffset,
  495. };
  496. MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
  497. /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
  498. .phys_io = 0x16000000,
  499. .io_pg_offst = ((0xf1600000) >> 18) & 0xfffc,
  500. .boot_params = 0x00000100,
  501. .map_io = intcp_map_io,
  502. .init_irq = intcp_init_irq,
  503. .timer = &cp_timer,
  504. .init_machine = intcp_init,
  505. MACHINE_END