core.c 13 KB

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