versatile_dt.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Versatile board support using the device tree
  3. *
  4. * Copyright (C) 2010 Secret Lab Technologies Ltd.
  5. * Copyright (C) 2009 Jeremy Kerr <jeremy.kerr@canonical.com>
  6. * Copyright (C) 2004 ARM Limited
  7. * Copyright (C) 2000 Deep Blue Solutions Ltd
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include <linux/of.h>
  26. #include <linux/of_address.h>
  27. #include <linux/of_irq.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/slab.h>
  30. #include <linux/amba/bus.h>
  31. #include <linux/amba/clcd.h>
  32. #include <linux/platform_data/video-clcd-versatile.h>
  33. #include <linux/amba/mmci.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/map.h>
  37. /* macro to get at MMIO space when running virtually */
  38. #define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  39. #define __io_address(n) ((void __iomem __force *)IO_ADDRESS(n))
  40. /*
  41. * ------------------------------------------------------------------------
  42. * Versatile Registers
  43. * ------------------------------------------------------------------------
  44. */
  45. #define VERSATILE_SYS_PCICTL_OFFSET 0x44
  46. #define VERSATILE_SYS_MCI_OFFSET 0x48
  47. #define VERSATILE_SYS_CLCD_OFFSET 0x50
  48. /*
  49. * VERSATILE peripheral addresses
  50. */
  51. #define VERSATILE_MMCI0_BASE 0x10005000 /* MMC interface */
  52. #define VERSATILE_MMCI1_BASE 0x1000B000 /* MMC Interface */
  53. #define VERSATILE_CLCD_BASE 0x10120000 /* CLCD */
  54. #define VERSATILE_SCTL_BASE 0x101E0000 /* System controller */
  55. #define VERSATILE_IB2_BASE 0x24000000 /* IB2 module */
  56. #define VERSATILE_IB2_CTL_BASE (VERSATILE_IB2_BASE + 0x03000000)
  57. /*
  58. * System controller bit assignment
  59. */
  60. #define VERSATILE_REFCLK 0
  61. #define VERSATILE_TIMCLK 1
  62. #define VERSATILE_TIMER1_EnSel 15
  63. #define VERSATILE_TIMER2_EnSel 17
  64. #define VERSATILE_TIMER3_EnSel 19
  65. #define VERSATILE_TIMER4_EnSel 21
  66. static void __iomem *versatile_sys_base;
  67. static void __iomem *versatile_ib2_ctrl;
  68. unsigned int mmc_status(struct device *dev)
  69. {
  70. struct amba_device *adev = container_of(dev, struct amba_device, dev);
  71. u32 mask;
  72. if (adev->res.start == VERSATILE_MMCI0_BASE)
  73. mask = 1;
  74. else
  75. mask = 2;
  76. return readl(versatile_sys_base + VERSATILE_SYS_MCI_OFFSET) & mask;
  77. }
  78. static struct mmci_platform_data mmc0_plat_data = {
  79. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  80. .status = mmc_status,
  81. .gpio_wp = -1,
  82. .gpio_cd = -1,
  83. };
  84. static struct mmci_platform_data mmc1_plat_data = {
  85. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  86. .status = mmc_status,
  87. .gpio_wp = -1,
  88. .gpio_cd = -1,
  89. };
  90. /*
  91. * CLCD support.
  92. */
  93. #define SYS_CLCD_MODE_MASK (3 << 0)
  94. #define SYS_CLCD_MODE_888 (0 << 0)
  95. #define SYS_CLCD_MODE_5551 (1 << 0)
  96. #define SYS_CLCD_MODE_565_RLSB (2 << 0)
  97. #define SYS_CLCD_MODE_565_BLSB (3 << 0)
  98. #define SYS_CLCD_NLCDIOON (1 << 2)
  99. #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
  100. #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
  101. #define SYS_CLCD_ID_MASK (0x1f << 8)
  102. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  103. #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
  104. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  105. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  106. #define SYS_CLCD_ID_VGA (0x1f << 8)
  107. static bool is_sanyo_2_5_lcd;
  108. /*
  109. * Disable all display connectors on the interface module.
  110. */
  111. static void versatile_clcd_disable(struct clcd_fb *fb)
  112. {
  113. void __iomem *sys_clcd = versatile_sys_base + VERSATILE_SYS_CLCD_OFFSET;
  114. u32 val;
  115. val = readl(sys_clcd);
  116. val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  117. writel(val, sys_clcd);
  118. /*
  119. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light off
  120. */
  121. if (of_machine_is_compatible("arm,versatile-ab") && is_sanyo_2_5_lcd) {
  122. unsigned long ctrl;
  123. ctrl = readl(versatile_ib2_ctrl);
  124. ctrl &= ~0x01;
  125. writel(ctrl, versatile_ib2_ctrl);
  126. }
  127. }
  128. /*
  129. * Enable the relevant connector on the interface module.
  130. */
  131. static void versatile_clcd_enable(struct clcd_fb *fb)
  132. {
  133. struct fb_var_screeninfo *var = &fb->fb.var;
  134. void __iomem *sys_clcd = versatile_sys_base + VERSATILE_SYS_CLCD_OFFSET;
  135. u32 val;
  136. val = readl(sys_clcd);
  137. val &= ~SYS_CLCD_MODE_MASK;
  138. switch (var->green.length) {
  139. case 5:
  140. val |= SYS_CLCD_MODE_5551;
  141. break;
  142. case 6:
  143. if (var->red.offset == 0)
  144. val |= SYS_CLCD_MODE_565_RLSB;
  145. else
  146. val |= SYS_CLCD_MODE_565_BLSB;
  147. break;
  148. case 8:
  149. val |= SYS_CLCD_MODE_888;
  150. break;
  151. }
  152. /*
  153. * Set the MUX
  154. */
  155. writel(val, sys_clcd);
  156. /*
  157. * And now enable the PSUs
  158. */
  159. val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
  160. writel(val, sys_clcd);
  161. /*
  162. * If the LCD is Sanyo 2x5 in on the IB2 board, turn the back-light on
  163. */
  164. if (of_machine_is_compatible("arm,versatile-ab") && is_sanyo_2_5_lcd) {
  165. unsigned long ctrl;
  166. ctrl = readl(versatile_ib2_ctrl);
  167. ctrl |= 0x01;
  168. writel(ctrl, versatile_ib2_ctrl);
  169. }
  170. }
  171. /*
  172. * Detect which LCD panel is connected, and return the appropriate
  173. * clcd_panel structure. Note: we do not have any information on
  174. * the required timings for the 8.4in panel, so we presently assume
  175. * VGA timings.
  176. */
  177. static int versatile_clcd_setup(struct clcd_fb *fb)
  178. {
  179. void __iomem *sys_clcd = versatile_sys_base + VERSATILE_SYS_CLCD_OFFSET;
  180. const char *panel_name;
  181. u32 val;
  182. is_sanyo_2_5_lcd = false;
  183. val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
  184. if (val == SYS_CLCD_ID_SANYO_3_8)
  185. panel_name = "Sanyo TM38QV67A02A";
  186. else if (val == SYS_CLCD_ID_SANYO_2_5) {
  187. panel_name = "Sanyo QVGA Portrait";
  188. is_sanyo_2_5_lcd = true;
  189. } else if (val == SYS_CLCD_ID_EPSON_2_2)
  190. panel_name = "Epson L2F50113T00";
  191. else if (val == SYS_CLCD_ID_VGA)
  192. panel_name = "VGA";
  193. else {
  194. printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
  195. val);
  196. panel_name = "VGA";
  197. }
  198. fb->panel = versatile_clcd_get_panel(panel_name);
  199. if (!fb->panel)
  200. return -EINVAL;
  201. return versatile_clcd_setup_dma(fb, SZ_1M);
  202. }
  203. static void versatile_clcd_decode(struct clcd_fb *fb, struct clcd_regs *regs)
  204. {
  205. clcdfb_decode(fb, regs);
  206. /* Always clear BGR for RGB565: we do the routing externally */
  207. if (fb->fb.var.green.length == 6)
  208. regs->cntl &= ~CNTL_BGR;
  209. }
  210. static struct clcd_board clcd_plat_data = {
  211. .name = "Versatile",
  212. .caps = CLCD_CAP_5551 | CLCD_CAP_565 | CLCD_CAP_888,
  213. .check = clcdfb_check,
  214. .decode = versatile_clcd_decode,
  215. .disable = versatile_clcd_disable,
  216. .enable = versatile_clcd_enable,
  217. .setup = versatile_clcd_setup,
  218. .mmap = versatile_clcd_mmap_dma,
  219. .remove = versatile_clcd_remove_dma,
  220. };
  221. /*
  222. * Lookup table for attaching a specific name and platform_data pointer to
  223. * devices as they get created by of_platform_populate(). Ideally this table
  224. * would not exist, but the current clock implementation depends on some devices
  225. * having a specific name.
  226. */
  227. struct of_dev_auxdata versatile_auxdata_lookup[] __initdata = {
  228. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI0_BASE, "fpga:05", &mmc0_plat_data),
  229. OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI1_BASE, "fpga:0b", &mmc1_plat_data),
  230. OF_DEV_AUXDATA("arm,primecell", VERSATILE_CLCD_BASE, "dev:20", &clcd_plat_data),
  231. {}
  232. };
  233. static struct map_desc versatile_io_desc[] __initdata __maybe_unused = {
  234. {
  235. .virtual = IO_ADDRESS(VERSATILE_SCTL_BASE),
  236. .pfn = __phys_to_pfn(VERSATILE_SCTL_BASE),
  237. .length = SZ_4K * 9,
  238. .type = MT_DEVICE
  239. }
  240. };
  241. static void __init versatile_map_io(void)
  242. {
  243. debug_ll_io_init();
  244. iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
  245. }
  246. static void __init versatile_init_early(void)
  247. {
  248. u32 val;
  249. /*
  250. * set clock frequency:
  251. * VERSATILE_REFCLK is 32KHz
  252. * VERSATILE_TIMCLK is 1MHz
  253. */
  254. val = readl(__io_address(VERSATILE_SCTL_BASE));
  255. writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
  256. (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
  257. (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
  258. (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
  259. __io_address(VERSATILE_SCTL_BASE));
  260. }
  261. static void __init versatile_dt_pci_init(void)
  262. {
  263. u32 val;
  264. struct device_node *np;
  265. struct property *newprop;
  266. np = of_find_compatible_node(NULL, NULL, "arm,versatile-pci");
  267. if (!np)
  268. return;
  269. /* Check if PCI backplane is detected */
  270. val = readl(versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
  271. if (val & 1) {
  272. /*
  273. * Enable PCI accesses. Note that the documentaton is
  274. * inconsistent whether or not this is needed, but the old
  275. * driver had it so we will keep it.
  276. */
  277. writel(1, versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
  278. return;
  279. }
  280. newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
  281. if (!newprop)
  282. return;
  283. newprop->name = kstrdup("status", GFP_KERNEL);
  284. newprop->value = kstrdup("disabled", GFP_KERNEL);
  285. newprop->length = sizeof("disabled");
  286. of_update_property(np, newprop);
  287. pr_info("Not plugged into PCI backplane!\n");
  288. }
  289. static void __init versatile_dt_init(void)
  290. {
  291. struct device_node *np;
  292. np = of_find_compatible_node(NULL, NULL, "arm,core-module-versatile");
  293. if (np)
  294. versatile_sys_base = of_iomap(np, 0);
  295. WARN_ON(!versatile_sys_base);
  296. versatile_ib2_ctrl = ioremap(VERSATILE_IB2_CTL_BASE, SZ_4K);
  297. versatile_dt_pci_init();
  298. of_platform_default_populate(NULL, versatile_auxdata_lookup, NULL);
  299. }
  300. static const char *const versatile_dt_match[] __initconst = {
  301. "arm,versatile-ab",
  302. "arm,versatile-pb",
  303. NULL,
  304. };
  305. DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
  306. .map_io = versatile_map_io,
  307. .init_early = versatile_init_early,
  308. .init_machine = versatile_dt_init,
  309. .dt_compat = versatile_dt_match,
  310. MACHINE_END