pl111_versatile.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Versatile family (ARM reference designs) handling for the PL11x.
  4. * This is based on code and know-how in the previous frame buffer
  5. * driver in drivers/video/fbdev/amba-clcd.c:
  6. * Copyright (C) 2001 ARM Limited, by David A Rusling
  7. * Updated to 2.5 by Deep Blue Solutions Ltd.
  8. * Major contributions and discoveries by Russell King.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/device.h>
  12. #include <linux/mfd/syscon.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/regmap.h>
  17. #include <linux/vexpress.h>
  18. #include <drm/drm_fourcc.h>
  19. #include "pl111_versatile.h"
  20. #include "pl111_drm.h"
  21. static struct regmap *versatile_syscon_map;
  22. /*
  23. * We detect the different syscon types from the compatible strings.
  24. */
  25. enum versatile_clcd {
  26. INTEGRATOR_IMPD1,
  27. INTEGRATOR_CLCD_CM,
  28. VERSATILE_CLCD,
  29. REALVIEW_CLCD_EB,
  30. REALVIEW_CLCD_PB1176,
  31. REALVIEW_CLCD_PB11MP,
  32. REALVIEW_CLCD_PBA8,
  33. REALVIEW_CLCD_PBX,
  34. VEXPRESS_CLCD_V2M,
  35. };
  36. static const struct of_device_id versatile_clcd_of_match[] = {
  37. {
  38. .compatible = "arm,core-module-integrator",
  39. .data = (void *)INTEGRATOR_CLCD_CM,
  40. },
  41. {
  42. .compatible = "arm,versatile-sysreg",
  43. .data = (void *)VERSATILE_CLCD,
  44. },
  45. {
  46. .compatible = "arm,realview-eb-syscon",
  47. .data = (void *)REALVIEW_CLCD_EB,
  48. },
  49. {
  50. .compatible = "arm,realview-pb1176-syscon",
  51. .data = (void *)REALVIEW_CLCD_PB1176,
  52. },
  53. {
  54. .compatible = "arm,realview-pb11mp-syscon",
  55. .data = (void *)REALVIEW_CLCD_PB11MP,
  56. },
  57. {
  58. .compatible = "arm,realview-pba8-syscon",
  59. .data = (void *)REALVIEW_CLCD_PBA8,
  60. },
  61. {
  62. .compatible = "arm,realview-pbx-syscon",
  63. .data = (void *)REALVIEW_CLCD_PBX,
  64. },
  65. {
  66. .compatible = "arm,vexpress-muxfpga",
  67. .data = (void *)VEXPRESS_CLCD_V2M,
  68. },
  69. {},
  70. };
  71. static const struct of_device_id impd1_clcd_of_match[] = {
  72. {
  73. .compatible = "arm,im-pd1-syscon",
  74. .data = (void *)INTEGRATOR_IMPD1,
  75. },
  76. {},
  77. };
  78. /*
  79. * Core module CLCD control on the Integrator/CP, bits
  80. * 8 thru 19 of the CM_CONTROL register controls a bunch
  81. * of CLCD settings.
  82. */
  83. #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
  84. #define INTEGRATOR_CLCD_LCDBIASEN BIT(8)
  85. #define INTEGRATOR_CLCD_LCDBIASUP BIT(9)
  86. #define INTEGRATOR_CLCD_LCDBIASDN BIT(10)
  87. /* Bits 11,12,13 controls the LCD or VGA bridge type */
  88. #define INTEGRATOR_CLCD_LCDMUX_LCD24 BIT(11)
  89. #define INTEGRATOR_CLCD_LCDMUX_SHARP (BIT(11)|BIT(12))
  90. #define INTEGRATOR_CLCD_LCDMUX_VGA555 BIT(13)
  91. #define INTEGRATOR_CLCD_LCDMUX_VGA24 (BIT(11)|BIT(12)|BIT(13))
  92. #define INTEGRATOR_CLCD_LCD0_EN BIT(14)
  93. #define INTEGRATOR_CLCD_LCD1_EN BIT(15)
  94. /* R/L flip on Sharp */
  95. #define INTEGRATOR_CLCD_LCD_STATIC1 BIT(16)
  96. /* U/D flip on Sharp */
  97. #define INTEGRATOR_CLCD_LCD_STATIC2 BIT(17)
  98. /* No connection on Sharp */
  99. #define INTEGRATOR_CLCD_LCD_STATIC BIT(18)
  100. /* 0 = 24bit VGA, 1 = 18bit VGA */
  101. #define INTEGRATOR_CLCD_LCD_N24BITEN BIT(19)
  102. #define INTEGRATOR_CLCD_MASK GENMASK(19, 8)
  103. static void pl111_integrator_enable(struct drm_device *drm, u32 format)
  104. {
  105. u32 val;
  106. dev_info(drm->dev, "enable Integrator CLCD connectors\n");
  107. /* FIXME: really needed? */
  108. val = INTEGRATOR_CLCD_LCD_STATIC1 | INTEGRATOR_CLCD_LCD_STATIC2 |
  109. INTEGRATOR_CLCD_LCD0_EN | INTEGRATOR_CLCD_LCD1_EN;
  110. switch (format) {
  111. case DRM_FORMAT_XBGR8888:
  112. case DRM_FORMAT_XRGB8888:
  113. /* 24bit formats */
  114. val |= INTEGRATOR_CLCD_LCDMUX_VGA24;
  115. break;
  116. case DRM_FORMAT_XBGR1555:
  117. case DRM_FORMAT_XRGB1555:
  118. /* Pseudocolor, RGB555, BGR555 */
  119. val |= INTEGRATOR_CLCD_LCDMUX_VGA555;
  120. break;
  121. default:
  122. dev_err(drm->dev, "unhandled format on Integrator 0x%08x\n",
  123. format);
  124. break;
  125. }
  126. regmap_update_bits(versatile_syscon_map,
  127. INTEGRATOR_HDR_CTRL_OFFSET,
  128. INTEGRATOR_CLCD_MASK,
  129. val);
  130. }
  131. #define IMPD1_CTRL_OFFSET 0x18
  132. #define IMPD1_CTRL_DISP_LCD (0 << 0)
  133. #define IMPD1_CTRL_DISP_VGA (1 << 0)
  134. #define IMPD1_CTRL_DISP_LCD1 (2 << 0)
  135. #define IMPD1_CTRL_DISP_ENABLE (1 << 2)
  136. #define IMPD1_CTRL_DISP_MASK (7 << 0)
  137. static void pl111_impd1_enable(struct drm_device *drm, u32 format)
  138. {
  139. u32 val;
  140. dev_info(drm->dev, "enable IM-PD1 CLCD connectors\n");
  141. val = IMPD1_CTRL_DISP_VGA | IMPD1_CTRL_DISP_ENABLE;
  142. regmap_update_bits(versatile_syscon_map,
  143. IMPD1_CTRL_OFFSET,
  144. IMPD1_CTRL_DISP_MASK,
  145. val);
  146. }
  147. static void pl111_impd1_disable(struct drm_device *drm)
  148. {
  149. dev_info(drm->dev, "disable IM-PD1 CLCD connectors\n");
  150. regmap_update_bits(versatile_syscon_map,
  151. IMPD1_CTRL_OFFSET,
  152. IMPD1_CTRL_DISP_MASK,
  153. 0);
  154. }
  155. /*
  156. * This configuration register in the Versatile and RealView
  157. * family is uniformly present but appears more and more
  158. * unutilized starting with the RealView series.
  159. */
  160. #define SYS_CLCD 0x50
  161. #define SYS_CLCD_MODE_MASK (BIT(0)|BIT(1))
  162. #define SYS_CLCD_MODE_888 0
  163. #define SYS_CLCD_MODE_5551 BIT(0)
  164. #define SYS_CLCD_MODE_565_R_LSB BIT(1)
  165. #define SYS_CLCD_MODE_565_B_LSB (BIT(0)|BIT(1))
  166. #define SYS_CLCD_CONNECTOR_MASK (BIT(2)|BIT(3)|BIT(4)|BIT(5))
  167. #define SYS_CLCD_NLCDIOON BIT(2)
  168. #define SYS_CLCD_VDDPOSSWITCH BIT(3)
  169. #define SYS_CLCD_PWR3V5SWITCH BIT(4)
  170. #define SYS_CLCD_VDDNEGSWITCH BIT(5)
  171. static void pl111_versatile_disable(struct drm_device *drm)
  172. {
  173. dev_info(drm->dev, "disable Versatile CLCD connectors\n");
  174. regmap_update_bits(versatile_syscon_map,
  175. SYS_CLCD,
  176. SYS_CLCD_CONNECTOR_MASK,
  177. 0);
  178. }
  179. static void pl111_versatile_enable(struct drm_device *drm, u32 format)
  180. {
  181. u32 val = 0;
  182. dev_info(drm->dev, "enable Versatile CLCD connectors\n");
  183. switch (format) {
  184. case DRM_FORMAT_ABGR8888:
  185. case DRM_FORMAT_XBGR8888:
  186. case DRM_FORMAT_ARGB8888:
  187. case DRM_FORMAT_XRGB8888:
  188. val |= SYS_CLCD_MODE_888;
  189. break;
  190. case DRM_FORMAT_BGR565:
  191. val |= SYS_CLCD_MODE_565_R_LSB;
  192. break;
  193. case DRM_FORMAT_RGB565:
  194. val |= SYS_CLCD_MODE_565_B_LSB;
  195. break;
  196. case DRM_FORMAT_ABGR1555:
  197. case DRM_FORMAT_XBGR1555:
  198. case DRM_FORMAT_ARGB1555:
  199. case DRM_FORMAT_XRGB1555:
  200. val |= SYS_CLCD_MODE_5551;
  201. break;
  202. default:
  203. dev_err(drm->dev, "unhandled format on Versatile 0x%08x\n",
  204. format);
  205. break;
  206. }
  207. /* Set up the MUX */
  208. regmap_update_bits(versatile_syscon_map,
  209. SYS_CLCD,
  210. SYS_CLCD_MODE_MASK,
  211. val);
  212. /* Then enable the display */
  213. regmap_update_bits(versatile_syscon_map,
  214. SYS_CLCD,
  215. SYS_CLCD_CONNECTOR_MASK,
  216. SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
  217. }
  218. static void pl111_realview_clcd_disable(struct drm_device *drm)
  219. {
  220. dev_info(drm->dev, "disable RealView CLCD connectors\n");
  221. regmap_update_bits(versatile_syscon_map,
  222. SYS_CLCD,
  223. SYS_CLCD_CONNECTOR_MASK,
  224. 0);
  225. }
  226. static void pl111_realview_clcd_enable(struct drm_device *drm, u32 format)
  227. {
  228. dev_info(drm->dev, "enable RealView CLCD connectors\n");
  229. regmap_update_bits(versatile_syscon_map,
  230. SYS_CLCD,
  231. SYS_CLCD_CONNECTOR_MASK,
  232. SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
  233. }
  234. /* PL110 pixel formats for Integrator, vanilla PL110 */
  235. static const u32 pl110_integrator_pixel_formats[] = {
  236. DRM_FORMAT_ABGR8888,
  237. DRM_FORMAT_XBGR8888,
  238. DRM_FORMAT_ARGB8888,
  239. DRM_FORMAT_XRGB8888,
  240. DRM_FORMAT_ABGR1555,
  241. DRM_FORMAT_XBGR1555,
  242. DRM_FORMAT_ARGB1555,
  243. DRM_FORMAT_XRGB1555,
  244. };
  245. /* Extended PL110 pixel formats for Integrator and Versatile */
  246. static const u32 pl110_versatile_pixel_formats[] = {
  247. DRM_FORMAT_ABGR8888,
  248. DRM_FORMAT_XBGR8888,
  249. DRM_FORMAT_ARGB8888,
  250. DRM_FORMAT_XRGB8888,
  251. DRM_FORMAT_BGR565, /* Uses external PLD */
  252. DRM_FORMAT_RGB565, /* Uses external PLD */
  253. DRM_FORMAT_ABGR1555,
  254. DRM_FORMAT_XBGR1555,
  255. DRM_FORMAT_ARGB1555,
  256. DRM_FORMAT_XRGB1555,
  257. };
  258. static const u32 pl111_realview_pixel_formats[] = {
  259. DRM_FORMAT_ABGR8888,
  260. DRM_FORMAT_XBGR8888,
  261. DRM_FORMAT_ARGB8888,
  262. DRM_FORMAT_XRGB8888,
  263. DRM_FORMAT_BGR565,
  264. DRM_FORMAT_RGB565,
  265. DRM_FORMAT_ABGR1555,
  266. DRM_FORMAT_XBGR1555,
  267. DRM_FORMAT_ARGB1555,
  268. DRM_FORMAT_XRGB1555,
  269. DRM_FORMAT_ABGR4444,
  270. DRM_FORMAT_XBGR4444,
  271. DRM_FORMAT_ARGB4444,
  272. DRM_FORMAT_XRGB4444,
  273. };
  274. /*
  275. * The Integrator variant is a PL110 with a bunch of broken, or not
  276. * yet implemented features
  277. */
  278. static const struct pl111_variant_data pl110_integrator = {
  279. .name = "PL110 Integrator",
  280. .is_pl110 = true,
  281. .broken_clockdivider = true,
  282. .broken_vblank = true,
  283. .formats = pl110_integrator_pixel_formats,
  284. .nformats = ARRAY_SIZE(pl110_integrator_pixel_formats),
  285. .fb_bpp = 16,
  286. };
  287. /*
  288. * The IM-PD1 variant is a PL110 with a bunch of broken, or not
  289. * yet implemented features
  290. */
  291. static const struct pl111_variant_data pl110_impd1 = {
  292. .name = "PL110 IM-PD1",
  293. .is_pl110 = true,
  294. .broken_clockdivider = true,
  295. .broken_vblank = true,
  296. .formats = pl110_integrator_pixel_formats,
  297. .nformats = ARRAY_SIZE(pl110_integrator_pixel_formats),
  298. .fb_bpp = 16,
  299. };
  300. /*
  301. * This is the in-between PL110 variant found in the ARM Versatile,
  302. * supporting RGB565/BGR565
  303. */
  304. static const struct pl111_variant_data pl110_versatile = {
  305. .name = "PL110 Versatile",
  306. .is_pl110 = true,
  307. .external_bgr = true,
  308. .formats = pl110_versatile_pixel_formats,
  309. .nformats = ARRAY_SIZE(pl110_versatile_pixel_formats),
  310. .fb_bpp = 16,
  311. };
  312. /*
  313. * RealView PL111 variant, the only real difference from the vanilla
  314. * PL111 is that we select 16bpp framebuffer by default to be able
  315. * to get 1024x768 without saturating the memory bus.
  316. */
  317. static const struct pl111_variant_data pl111_realview = {
  318. .name = "PL111 RealView",
  319. .formats = pl111_realview_pixel_formats,
  320. .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
  321. .fb_bpp = 16,
  322. };
  323. /*
  324. * Versatile Express PL111 variant, again we just push the maximum
  325. * BPP to 16 to be able to get 1024x768 without saturating the memory
  326. * bus. The clockdivider also seems broken on the Versatile Express.
  327. */
  328. static const struct pl111_variant_data pl111_vexpress = {
  329. .name = "PL111 Versatile Express",
  330. .formats = pl111_realview_pixel_formats,
  331. .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
  332. .fb_bpp = 16,
  333. .broken_clockdivider = true,
  334. };
  335. #define VEXPRESS_FPGAMUX_MOTHERBOARD 0x00
  336. #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_1 0x01
  337. #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_2 0x02
  338. static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
  339. struct pl111_drm_dev_private *priv)
  340. {
  341. struct platform_device *pdev;
  342. struct device_node *root;
  343. struct device_node *child;
  344. struct device_node *ct_clcd = NULL;
  345. struct regmap *map;
  346. bool has_coretile_clcd = false;
  347. bool has_coretile_hdlcd = false;
  348. bool mux_motherboard = true;
  349. u32 val;
  350. int ret;
  351. if (!IS_ENABLED(CONFIG_VEXPRESS_CONFIG))
  352. return -ENODEV;
  353. /*
  354. * Check if we have a CLCD or HDLCD on the core tile by checking if a
  355. * CLCD or HDLCD is available in the root of the device tree.
  356. */
  357. root = of_find_node_by_path("/");
  358. if (!root)
  359. return -EINVAL;
  360. for_each_available_child_of_node(root, child) {
  361. if (of_device_is_compatible(child, "arm,pl111")) {
  362. has_coretile_clcd = true;
  363. ct_clcd = child;
  364. of_node_put(child);
  365. break;
  366. }
  367. if (of_device_is_compatible(child, "arm,hdlcd")) {
  368. has_coretile_hdlcd = true;
  369. of_node_put(child);
  370. break;
  371. }
  372. }
  373. of_node_put(root);
  374. /*
  375. * If there is a coretile HDLCD and it has a driver,
  376. * do not mux the CLCD on the motherboard to the DVI.
  377. */
  378. if (has_coretile_hdlcd && IS_ENABLED(CONFIG_DRM_HDLCD))
  379. mux_motherboard = false;
  380. /*
  381. * On the Vexpress CA9 we let the CLCD on the coretile
  382. * take precedence, so also in this case do not mux the
  383. * motherboard to the DVI.
  384. */
  385. if (has_coretile_clcd)
  386. mux_motherboard = false;
  387. if (mux_motherboard) {
  388. dev_info(dev, "DVI muxed to motherboard CLCD\n");
  389. val = VEXPRESS_FPGAMUX_MOTHERBOARD;
  390. } else if (ct_clcd == dev->of_node) {
  391. dev_info(dev,
  392. "DVI muxed to daughterboard 1 (core tile) CLCD\n");
  393. val = VEXPRESS_FPGAMUX_DAUGHTERBOARD_1;
  394. } else {
  395. dev_info(dev, "core tile graphics present\n");
  396. dev_info(dev, "this device will be deactivated\n");
  397. return -ENODEV;
  398. }
  399. /* Call into deep Vexpress configuration API */
  400. pdev = of_find_device_by_node(np);
  401. if (!pdev) {
  402. dev_err(dev, "can't find the sysreg device, deferring\n");
  403. return -EPROBE_DEFER;
  404. }
  405. map = devm_regmap_init_vexpress_config(&pdev->dev);
  406. if (IS_ERR(map)) {
  407. platform_device_put(pdev);
  408. return PTR_ERR(map);
  409. }
  410. ret = regmap_write(map, 0, val);
  411. platform_device_put(pdev);
  412. if (ret) {
  413. dev_err(dev, "error setting DVI muxmode\n");
  414. return -ENODEV;
  415. }
  416. priv->variant = &pl111_vexpress;
  417. dev_info(dev, "initializing Versatile Express PL111\n");
  418. return 0;
  419. }
  420. int pl111_versatile_init(struct device *dev, struct pl111_drm_dev_private *priv)
  421. {
  422. const struct of_device_id *clcd_id;
  423. enum versatile_clcd versatile_clcd_type;
  424. struct device_node *np;
  425. struct regmap *map;
  426. np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match,
  427. &clcd_id);
  428. if (!np) {
  429. /* Non-ARM reference designs, just bail out */
  430. return 0;
  431. }
  432. versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
  433. /* Versatile Express special handling */
  434. if (versatile_clcd_type == VEXPRESS_CLCD_V2M) {
  435. int ret = pl111_vexpress_clcd_init(dev, np, priv);
  436. of_node_put(np);
  437. if (ret)
  438. dev_err(dev, "Versatile Express init failed - %d", ret);
  439. return ret;
  440. }
  441. /*
  442. * On the Integrator, check if we should use the IM-PD1 instead,
  443. * if we find it, it will take precedence. This is on the Integrator/AP
  444. * which only has this option for PL110 graphics.
  445. */
  446. if (versatile_clcd_type == INTEGRATOR_CLCD_CM) {
  447. np = of_find_matching_node_and_match(NULL, impd1_clcd_of_match,
  448. &clcd_id);
  449. if (np)
  450. versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
  451. }
  452. map = syscon_node_to_regmap(np);
  453. of_node_put(np);
  454. if (IS_ERR(map)) {
  455. dev_err(dev, "no Versatile syscon regmap\n");
  456. return PTR_ERR(map);
  457. }
  458. switch (versatile_clcd_type) {
  459. case INTEGRATOR_CLCD_CM:
  460. versatile_syscon_map = map;
  461. priv->variant = &pl110_integrator;
  462. priv->variant_display_enable = pl111_integrator_enable;
  463. dev_info(dev, "set up callbacks for Integrator PL110\n");
  464. break;
  465. case INTEGRATOR_IMPD1:
  466. versatile_syscon_map = map;
  467. priv->variant = &pl110_impd1;
  468. priv->variant_display_enable = pl111_impd1_enable;
  469. priv->variant_display_disable = pl111_impd1_disable;
  470. dev_info(dev, "set up callbacks for IM-PD1 PL110\n");
  471. break;
  472. case VERSATILE_CLCD:
  473. versatile_syscon_map = map;
  474. /* This can do RGB565 with external PLD */
  475. priv->variant = &pl110_versatile;
  476. priv->variant_display_enable = pl111_versatile_enable;
  477. priv->variant_display_disable = pl111_versatile_disable;
  478. /*
  479. * The Versatile has a variant halfway between PL110
  480. * and PL111 where these two registers have already been
  481. * swapped.
  482. */
  483. priv->ienb = CLCD_PL111_IENB;
  484. priv->ctrl = CLCD_PL111_CNTL;
  485. dev_info(dev, "set up callbacks for Versatile PL110\n");
  486. break;
  487. case REALVIEW_CLCD_EB:
  488. case REALVIEW_CLCD_PB1176:
  489. case REALVIEW_CLCD_PB11MP:
  490. case REALVIEW_CLCD_PBA8:
  491. case REALVIEW_CLCD_PBX:
  492. versatile_syscon_map = map;
  493. priv->variant = &pl111_realview;
  494. priv->variant_display_enable = pl111_realview_clcd_enable;
  495. priv->variant_display_disable = pl111_realview_clcd_disable;
  496. dev_info(dev, "set up callbacks for RealView PL111\n");
  497. break;
  498. default:
  499. dev_info(dev, "unknown Versatile system controller\n");
  500. break;
  501. }
  502. return 0;
  503. }
  504. EXPORT_SYMBOL_GPL(pl111_versatile_init);