core.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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/platform_data/video-clcd-versatile.h>
  29. #include <linux/io.h>
  30. #include <linux/smsc911x.h>
  31. #include <linux/smc91x.h>
  32. #include <linux/ata_platform.h>
  33. #include <linux/amba/mmci.h>
  34. #include <linux/gfp.h>
  35. #include <linux/mtd/physmap.h>
  36. #include <linux/memblock.h>
  37. #include <clocksource/timer-sp804.h>
  38. #include "hardware.h"
  39. #include <asm/irq.h>
  40. #include <asm/mach-types.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 "platform.h"
  46. #include <plat/sched_clock.h>
  47. #include "core.h"
  48. #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
  49. static void realview_flash_set_vpp(struct platform_device *pdev, int on)
  50. {
  51. u32 val;
  52. val = __raw_readl(REALVIEW_FLASHCTRL);
  53. if (on)
  54. val |= REALVIEW_FLASHPROG_FLVPPEN;
  55. else
  56. val &= ~REALVIEW_FLASHPROG_FLVPPEN;
  57. __raw_writel(val, REALVIEW_FLASHCTRL);
  58. }
  59. static struct physmap_flash_data realview_flash_data = {
  60. .width = 4,
  61. .set_vpp = realview_flash_set_vpp,
  62. };
  63. struct platform_device realview_flash_device = {
  64. .name = "physmap-flash",
  65. .id = 0,
  66. .dev = {
  67. .platform_data = &realview_flash_data,
  68. },
  69. };
  70. int realview_flash_register(struct resource *res, u32 num)
  71. {
  72. realview_flash_device.resource = res;
  73. realview_flash_device.num_resources = num;
  74. return platform_device_register(&realview_flash_device);
  75. }
  76. static struct smsc911x_platform_config smsc911x_config = {
  77. .flags = SMSC911X_USE_32BIT,
  78. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
  79. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  80. .phy_interface = PHY_INTERFACE_MODE_MII,
  81. };
  82. static struct smc91x_platdata smc91x_platdata = {
  83. .flags = SMC91X_USE_8BIT | SMC91X_USE_16BIT | SMC91X_USE_32BIT |
  84. SMC91X_NOWAIT,
  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. else
  99. realview_eth_device.dev.platform_data = &smc91x_platdata;
  100. return platform_device_register(&realview_eth_device);
  101. }
  102. struct platform_device realview_usb_device = {
  103. .name = "isp1760",
  104. .num_resources = 2,
  105. };
  106. int realview_usb_register(struct resource *res)
  107. {
  108. realview_usb_device.resource = res;
  109. return platform_device_register(&realview_usb_device);
  110. }
  111. static struct pata_platform_info pata_platform_data = {
  112. .ioport_shift = 1,
  113. };
  114. static struct resource pata_resources[] = {
  115. [0] = {
  116. .start = REALVIEW_CF_BASE,
  117. .end = REALVIEW_CF_BASE + 0xff,
  118. .flags = IORESOURCE_MEM,
  119. },
  120. [1] = {
  121. .start = REALVIEW_CF_BASE + 0x100,
  122. .end = REALVIEW_CF_BASE + SZ_4K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. };
  126. struct platform_device realview_cf_device = {
  127. .name = "pata_platform",
  128. .id = -1,
  129. .num_resources = ARRAY_SIZE(pata_resources),
  130. .resource = pata_resources,
  131. .dev = {
  132. .platform_data = &pata_platform_data,
  133. },
  134. };
  135. static struct resource realview_leds_resources[] = {
  136. {
  137. .start = REALVIEW_SYS_BASE + REALVIEW_SYS_LED_OFFSET,
  138. .end = REALVIEW_SYS_BASE + REALVIEW_SYS_LED_OFFSET + 4,
  139. .flags = IORESOURCE_MEM,
  140. },
  141. };
  142. struct platform_device realview_leds_device = {
  143. .name = "versatile-leds",
  144. .id = -1,
  145. .num_resources = ARRAY_SIZE(realview_leds_resources),
  146. .resource = realview_leds_resources,
  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. void __init realview_init_early(void)
  212. {
  213. void __iomem *sys = __io_address(REALVIEW_SYS_BASE);
  214. versatile_sched_clock_init(sys + REALVIEW_SYS_24MHz_OFFSET, 24000000);
  215. }
  216. /*
  217. * CLCD support.
  218. */
  219. #define SYS_CLCD_NLCDIOON (1 << 2)
  220. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  221. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  222. #define SYS_CLCD_ID_MASK (0x1f << 8)
  223. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  224. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  225. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  226. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  227. #define SYS_CLCD_ID_VGA (0x1f << 8)
  228. /*
  229. * Disable all display connectors on the interface module.
  230. */
  231. static void realview_clcd_disable(struct clcd_fb *fb)
  232. {
  233. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  234. u32 val;
  235. val = readl(sys_clcd);
  236. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  237. writel(val, sys_clcd);
  238. }
  239. /*
  240. * Enable the relevant connector on the interface module.
  241. */
  242. static void realview_clcd_enable(struct clcd_fb *fb)
  243. {
  244. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  245. u32 val;
  246. /*
  247. * Enable the PSUs
  248. */
  249. val = readl(sys_clcd);
  250. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  251. writel(val, sys_clcd);
  252. }
  253. /*
  254. * Detect which LCD panel is connected, and return the appropriate
  255. * clcd_panel structure. Note: we do not have any information on
  256. * the required timings for the 8.4in panel, so we presently assume
  257. * VGA timings.
  258. */
  259. static int realview_clcd_setup(struct clcd_fb *fb)
  260. {
  261. void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
  262. const char *panel_name, *vga_panel_name;
  263. unsigned long framesize;
  264. u32 val;
  265. if (machine_is_realview_eb()) {
  266. /* VGA, 16bpp */
  267. framesize = 640 * 480 * 2;
  268. vga_panel_name = "VGA";
  269. } else {
  270. /* XVGA, 16bpp */
  271. framesize = 1024 * 768 * 2;
  272. vga_panel_name = "XVGA";
  273. }
  274. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  275. if (val == SYS_CLCD_ID_SANYO_3_8)
  276. panel_name = "Sanyo TM38QV67A02A";
  277. else if (val == SYS_CLCD_ID_SANYO_2_5)
  278. panel_name = "Sanyo QVGA Portrait";
  279. else if (val == SYS_CLCD_ID_EPSON_2_2)
  280. panel_name = "Epson L2F50113T00";
  281. else if (val == SYS_CLCD_ID_VGA)
  282. panel_name = vga_panel_name;
  283. else {
  284. pr_err("CLCD: unknown LCD panel ID 0x%08x, using VGA\n", val);
  285. panel_name = vga_panel_name;
  286. }
  287. fb->panel = versatile_clcd_get_panel(panel_name);
  288. if (!fb->panel)
  289. return -EINVAL;
  290. return versatile_clcd_setup_dma(fb, framesize);
  291. }
  292. struct clcd_board clcd_plat_data = {
  293. .name = "RealView",
  294. .caps = CLCD_CAP_ALL,
  295. .check = clcdfb_check,
  296. .decode = clcdfb_decode,
  297. .disable = realview_clcd_disable,
  298. .enable = realview_clcd_enable,
  299. .setup = realview_clcd_setup,
  300. .mmap = versatile_clcd_mmap_dma,
  301. .remove = versatile_clcd_remove_dma,
  302. };
  303. /*
  304. * Where is the timer (VA)?
  305. */
  306. void __iomem *timer0_va_base;
  307. void __iomem *timer1_va_base;
  308. void __iomem *timer2_va_base;
  309. void __iomem *timer3_va_base;
  310. /*
  311. * Set up the clock source and clock events devices
  312. */
  313. void __init realview_timer_init(unsigned int timer_irq)
  314. {
  315. u32 val;
  316. /*
  317. * set clock frequency:
  318. * REALVIEW_REFCLK is 32KHz
  319. * REALVIEW_TIMCLK is 1MHz
  320. */
  321. val = readl(__io_address(REALVIEW_SCTL_BASE));
  322. writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
  323. (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
  324. (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
  325. (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
  326. __io_address(REALVIEW_SCTL_BASE));
  327. /*
  328. * Initialise to a known state (all timers off)
  329. */
  330. sp804_timer_disable(timer0_va_base);
  331. sp804_timer_disable(timer1_va_base);
  332. sp804_timer_disable(timer2_va_base);
  333. sp804_timer_disable(timer3_va_base);
  334. sp804_clocksource_init(timer3_va_base, "timer3");
  335. sp804_clockevents_init(timer0_va_base, timer_irq, "timer0");
  336. }
  337. /*
  338. * Setup the memory banks.
  339. */
  340. void realview_fixup(struct tag *tags, char **from)
  341. {
  342. /*
  343. * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
  344. * Half of this is mirrored at 0.
  345. */
  346. #ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
  347. memblock_add(0x70000000, SZ_512M);
  348. #else
  349. memblock_add(0, SZ_256M);
  350. #endif
  351. }