core.c 13 KB

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