core.c 13 KB

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