core.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * linux/arch/arm/mach-realview/core.c
  3. *
  4. * Copyright (C) 1999 - 2003 ARM Limited
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/sysdev.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/amba/bus.h>
  27. #include <linux/amba/clcd.h>
  28. #include <linux/io.h>
  29. #include <linux/smsc911x.h>
  30. #include <linux/ata_platform.h>
  31. #include <linux/amba/mmci.h>
  32. #include <linux/gfp.h>
  33. #include <linux/clkdev.h>
  34. #include <linux/mtd/physmap.h>
  35. #include <asm/system.h>
  36. #include <mach/hardware.h>
  37. #include <asm/irq.h>
  38. #include <asm/leds.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/hardware/arm_timer.h>
  41. #include <asm/hardware/icst.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/irq.h>
  44. #include <asm/mach/map.h>
  45. #include <asm/hardware/gic.h>
  46. #include <mach/platform.h>
  47. #include <mach/irqs.h>
  48. #include <asm/hardware/timer-sp.h>
  49. #include <plat/clcd.h>
  50. #include <plat/sched_clock.h>
  51. #include "core.h"
  52. #ifdef CONFIG_ZONE_DMA
  53. /*
  54. * Adjust the zones if there are restrictions for DMA access.
  55. */
  56. void __init realview_adjust_zones(unsigned long *size, unsigned long *hole)
  57. {
  58. unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
  59. if (!machine_is_realview_pbx() || size[0] <= dma_size)
  60. return;
  61. size[ZONE_NORMAL] = size[0] - dma_size;
  62. size[ZONE_DMA] = dma_size;
  63. hole[ZONE_NORMAL] = hole[0];
  64. hole[ZONE_DMA] = 0;
  65. }
  66. #endif
  67. #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
  68. static void realview_flash_set_vpp(struct platform_device *pdev, int on)
  69. {
  70. u32 val;
  71. val = __raw_readl(REALVIEW_FLASHCTRL);
  72. if (on)
  73. val |= REALVIEW_FLASHPROG_FLVPPEN;
  74. else
  75. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  76. __raw_writel(val, REALVIEW_FLASHCTRL);
  77. }
  78. static struct physmap_flash_data realview_flash_data = {
  79. .width = 4,
  80. .set_vpp = realview_flash_set_vpp,
  81. };
  82. struct platform_device realview_flash_device = {
  83. .name = "physmap-flash",
  84. .id = 0,
  85. .dev = {
  86. .platform_data = &realview_flash_data,
  87. },
  88. };
  89. int realview_flash_register(struct resource *res, u32 num)
  90. {
  91. realview_flash_device.resource = res;
  92. realview_flash_device.num_resources = num;
  93. return platform_device_register(&realview_flash_device);
  94. }
  95. static struct smsc911x_platform_config smsc911x_config = {
  96. .flags = SMSC911X_USE_32BIT,
  97. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
  98. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  99. .phy_interface = PHY_INTERFACE_MODE_MII,
  100. };
  101. static struct platform_device realview_eth_device = {
  102. .name = "smsc911x",
  103. .id = 0,
  104. .num_resources = 2,
  105. };
  106. int realview_eth_register(const char *name, struct resource *res)
  107. {
  108. if (name)
  109. realview_eth_device.name = name;
  110. realview_eth_device.resource = res;
  111. if (strcmp(realview_eth_device.name, "smsc911x") == 0)
  112. realview_eth_device.dev.platform_data = &smsc911x_config;
  113. return platform_device_register(&realview_eth_device);
  114. }
  115. struct platform_device realview_usb_device = {
  116. .name = "isp1760",
  117. .num_resources = 2,
  118. };
  119. int realview_usb_register(struct resource *res)
  120. {
  121. realview_usb_device.resource = res;
  122. return platform_device_register(&realview_usb_device);
  123. }
  124. static struct pata_platform_info pata_platform_data = {
  125. .ioport_shift = 1,
  126. };
  127. static struct resource pata_resources[] = {
  128. [0] = {
  129. .start = REALVIEW_CF_BASE,
  130. .end = REALVIEW_CF_BASE + 0xff,
  131. .flags = IORESOURCE_MEM,
  132. },
  133. [1] = {
  134. .start = REALVIEW_CF_BASE + 0x100,
  135. .end = REALVIEW_CF_BASE + SZ_4K - 1,
  136. .flags = IORESOURCE_MEM,
  137. },
  138. };
  139. struct platform_device realview_cf_device = {
  140. .name = "pata_platform",
  141. .id = -1,
  142. .num_resources = ARRAY_SIZE(pata_resources),
  143. .resource = pata_resources,
  144. .dev = {
  145. .platform_data = &pata_platform_data,
  146. },
  147. };
  148. static struct resource realview_i2c_resource = {
  149. .start = REALVIEW_I2C_BASE,
  150. .end = REALVIEW_I2C_BASE + SZ_4K - 1,
  151. .flags = IORESOURCE_MEM,
  152. };
  153. struct platform_device realview_i2c_device = {
  154. .name = "versatile-i2c",
  155. .id = 0,
  156. .num_resources = 1,
  157. .resource = &realview_i2c_resource,
  158. };
  159. static struct i2c_board_info realview_i2c_board_info[] = {
  160. {
  161. I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
  162. },
  163. };
  164. static int __init realview_i2c_init(void)
  165. {
  166. return i2c_register_board_info(0, realview_i2c_board_info,
  167. ARRAY_SIZE(realview_i2c_board_info));
  168. }
  169. arch_initcall(realview_i2c_init);
  170. #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
  171. /*
  172. * This is only used if GPIOLIB support is disabled
  173. */
  174. static unsigned int realview_mmc_status(struct device *dev)
  175. {
  176. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  177. u32 mask;
  178. if (machine_is_realview_pb1176()) {
  179. static bool inserted = false;
  180. /*
  181. * The PB1176 does not have the status register,
  182. * assume it is inserted at startup, then invert
  183. * for each call so card insertion/removal will
  184. * be detected anyway. This will not be called if
  185. * GPIO on PL061 is active, which is the proper
  186. * way to do this on the PB1176.
  187. */
  188. inserted = !inserted;
  189. return inserted ? 0 : 1;
  190. }
  191. if (adev->res.start == REALVIEW_MMCI0_BASE)
  192. mask = 1;
  193. else
  194. mask = 2;
  195. return readl(REALVIEW_SYSMCI) & mask;
  196. }
  197. struct mmci_platform_data realview_mmc0_plat_data = {
  198. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  199. .status = realview_mmc_status,
  200. .gpio_wp = 17,
  201. .gpio_cd = 16,
  202. .cd_invert = true,
  203. };
  204. struct mmci_platform_data realview_mmc1_plat_data = {
  205. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  206. .status = realview_mmc_status,
  207. .gpio_wp = 19,
  208. .gpio_cd = 18,
  209. .cd_invert = true,
  210. };
  211. /*
  212. * Clock handling
  213. */
  214. static const struct icst_params realview_oscvco_params = {
  215. .ref = 24000000,
  216. .vco_max = ICST307_VCO_MAX,
  217. .vco_min = ICST307_VCO_MIN,
  218. .vd_min = 4 + 8,
  219. .vd_max = 511 + 8,
  220. .rd_min = 1 + 2,
  221. .rd_max = 127 + 2,
  222. .s2div = icst307_s2div,
  223. .idx2s = icst307_idx2s,
  224. };
  225. static void realview_oscvco_set(struct clk *clk, struct icst_vco vco)
  226. {
  227. void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
  228. u32 val;
  229. val = readl(clk->vcoreg) & ~0x7ffff;
  230. val |= vco.v | (vco.r << 9) | (vco.s << 16);
  231. writel(0xa05f, sys_lock);
  232. writel(val, clk->vcoreg);
  233. writel(0, sys_lock);
  234. }
  235. static const struct clk_ops oscvco_clk_ops = {
  236. .round = icst_clk_round,
  237. .set = icst_clk_set,
  238. .setvco = realview_oscvco_set,
  239. };
  240. static struct clk oscvco_clk = {
  241. .ops = &oscvco_clk_ops,
  242. .params = &realview_oscvco_params,
  243. };
  244. /*
  245. * These are fixed clocks.
  246. */
  247. static struct clk ref24_clk = {
  248. .rate = 24000000,
  249. };
  250. static struct clk dummy_apb_pclk;
  251. static struct clk_lookup lookups[] = {
  252. { /* Bus clock */
  253. .con_id = "apb_pclk",
  254. .clk = &dummy_apb_pclk,
  255. }, { /* UART0 */
  256. .dev_id = "dev:uart0",
  257. .clk = &ref24_clk,
  258. }, { /* UART1 */
  259. .dev_id = "dev:uart1",
  260. .clk = &ref24_clk,
  261. }, { /* UART2 */
  262. .dev_id = "dev:uart2",
  263. .clk = &ref24_clk,
  264. }, { /* UART3 */
  265. .dev_id = "fpga:uart3",
  266. .clk = &ref24_clk,
  267. }, { /* UART3 is on the dev chip in PB1176 */
  268. .dev_id = "dev:uart3",
  269. .clk = &ref24_clk,
  270. }, { /* UART4 only exists in PB1176 */
  271. .dev_id = "fpga:uart4",
  272. .clk = &ref24_clk,
  273. }, { /* KMI0 */
  274. .dev_id = "fpga:kmi0",
  275. .clk = &ref24_clk,
  276. }, { /* KMI1 */
  277. .dev_id = "fpga:kmi1",
  278. .clk = &ref24_clk,
  279. }, { /* MMC0 */
  280. .dev_id = "fpga:mmc0",
  281. .clk = &ref24_clk,
  282. }, { /* CLCD is in the PB1176 and EB DevChip */
  283. .dev_id = "dev:clcd",
  284. .clk = &oscvco_clk,
  285. }, { /* PB:CLCD */
  286. .dev_id = "issp:clcd",
  287. .clk = &oscvco_clk,
  288. }, { /* SSP */
  289. .dev_id = "dev:ssp0",
  290. .clk = &ref24_clk,
  291. }
  292. };
  293. void __init realview_init_early(void)
  294. {
  295. void __iomem *sys = __io_address(REALVIEW_SYS_BASE);
  296. if (machine_is_realview_pb1176())
  297. oscvco_clk.vcoreg = sys + REALVIEW_SYS_OSC0_OFFSET;
  298. else
  299. oscvco_clk.vcoreg = sys + REALVIEW_SYS_OSC4_OFFSET;
  300. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  301. versatile_sched_clock_init(sys + REALVIEW_SYS_24MHz_OFFSET, 24000000);
  302. }
  303. /*
  304. * CLCD support.
  305. */
  306. #define SYS_CLCD_NLCDIOON (1 << 2)
  307. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  308. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  309. #define SYS_CLCD_ID_MASK (0x1f << 8)
  310. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  311. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  312. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  313. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  314. #define SYS_CLCD_ID_VGA (0x1f << 8)
  315. /*
  316. * Disable all display connectors on the interface module.
  317. */
  318. static void realview_clcd_disable(struct clcd_fb *fb)
  319. {
  320. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  321. u32 val;
  322. val = readl(sys_clcd);
  323. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  324. writel(val, sys_clcd);
  325. }
  326. /*
  327. * Enable the relevant connector on the interface module.
  328. */
  329. static void realview_clcd_enable(struct clcd_fb *fb)
  330. {
  331. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  332. u32 val;
  333. /*
  334. * Enable the PSUs
  335. */
  336. val = readl(sys_clcd);
  337. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  338. writel(val, sys_clcd);
  339. }
  340. /*
  341. * Detect which LCD panel is connected, and return the appropriate
  342. * clcd_panel structure. Note: we do not have any information on
  343. * the required timings for the 8.4in panel, so we presently assume
  344. * VGA timings.
  345. */
  346. static int realview_clcd_setup(struct clcd_fb *fb)
  347. {
  348. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  349. const char *panel_name, *vga_panel_name;
  350. unsigned long framesize;
  351. u32 val;
  352. if (machine_is_realview_eb()) {
  353. /* VGA, 16bpp */
  354. framesize = 640 * 480 * 2;
  355. vga_panel_name = "VGA";
  356. } else {
  357. /* XVGA, 16bpp */
  358. framesize = 1024 * 768 * 2;
  359. vga_panel_name = "XVGA";
  360. }
  361. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  362. if (val == SYS_CLCD_ID_SANYO_3_8)
  363. panel_name = "Sanyo TM38QV67A02A";
  364. else if (val == SYS_CLCD_ID_SANYO_2_5)
  365. panel_name = "Sanyo QVGA Portrait";
  366. else if (val == SYS_CLCD_ID_EPSON_2_2)
  367. panel_name = "Epson L2F50113T00";
  368. else if (val == SYS_CLCD_ID_VGA)
  369. panel_name = vga_panel_name;
  370. else {
  371. pr_err("CLCD: unknown LCD panel ID 0x%08x, using VGA\n", val);
  372. panel_name = vga_panel_name;
  373. }
  374. fb->panel = versatile_clcd_get_panel(panel_name);
  375. if (!fb->panel)
  376. return -EINVAL;
  377. return versatile_clcd_setup_dma(fb, framesize);
  378. }
  379. struct clcd_board clcd_plat_data = {
  380. .name = "RealView",
  381. .caps = CLCD_CAP_ALL,
  382. .check = clcdfb_check,
  383. .decode = clcdfb_decode,
  384. .disable = realview_clcd_disable,
  385. .enable = realview_clcd_enable,
  386. .setup = realview_clcd_setup,
  387. .mmap = versatile_clcd_mmap_dma,
  388. .remove = versatile_clcd_remove_dma,
  389. };
  390. #ifdef CONFIG_LEDS
  391. #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
  392. void realview_leds_event(led_event_t ledevt)
  393. {
  394. unsigned long flags;
  395. u32 val;
  396. u32 led = 1 << smp_processor_id();
  397. local_irq_save(flags);
  398. val = readl(VA_LEDS_BASE);
  399. switch (ledevt) {
  400. case led_idle_start:
  401. val = val & ~led;
  402. break;
  403. case led_idle_end:
  404. val = val | led;
  405. break;
  406. case led_timer:
  407. val = val ^ REALVIEW_SYS_LED7;
  408. break;
  409. case led_halted:
  410. val = 0;
  411. break;
  412. default:
  413. break;
  414. }
  415. writel(val, VA_LEDS_BASE);
  416. local_irq_restore(flags);
  417. }
  418. #endif /* CONFIG_LEDS */
  419. /*
  420. * Where is the timer (VA)?
  421. */
  422. void __iomem *timer0_va_base;
  423. void __iomem *timer1_va_base;
  424. void __iomem *timer2_va_base;
  425. void __iomem *timer3_va_base;
  426. /*
  427. * Set up the clock source and clock events devices
  428. */
  429. void __init realview_timer_init(unsigned int timer_irq)
  430. {
  431. u32 val;
  432. /*
  433. * set clock frequency:
  434. * REALVIEW_REFCLK is 32KHz
  435. * REALVIEW_TIMCLK is 1MHz
  436. */
  437. val = readl(__io_address(REALVIEW_SCTL_BASE));
  438. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  439. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  440. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  441. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  442. __io_address(REALVIEW_SCTL_BASE));
  443. /*
  444. * Initialise to a known state (all timers off)
  445. */
  446. writel(0, timer0_va_base + TIMER_CTRL);
  447. writel(0, timer1_va_base + TIMER_CTRL);
  448. writel(0, timer2_va_base + TIMER_CTRL);
  449. writel(0, timer3_va_base + TIMER_CTRL);
  450. sp804_clocksource_init(timer3_va_base);
  451. sp804_clockevents_init(timer0_va_base, timer_irq);
  452. }
  453. /*
  454. * Setup the memory banks.
  455. */
  456. void realview_fixup(struct machine_desc *mdesc, struct tag *tags, char **from,
  457. struct meminfo *meminfo)
  458. {
  459. /*
  460. * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
  461. * Half of this is mirrored at 0.
  462. */
  463. #ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
  464. meminfo->bank[0].start = 0x70000000;
  465. meminfo->bank[0].size = SZ_512M;
  466. meminfo->nr_banks = 1;
  467. #else
  468. meminfo->bank[0].start = 0;
  469. meminfo->bank[0].size = SZ_256M;
  470. meminfo->nr_banks = 1;
  471. #endif
  472. }