panel-arm-versatile.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Panel driver for the ARM Versatile family reference designs from
  4. * ARM Limited.
  5. *
  6. * Author:
  7. * Linus Walleij <linus.wallei@linaro.org>
  8. *
  9. * On the Versatile AB, these panels come mounted on daughterboards
  10. * named "IB1" or "IB2" (Interface Board 1 & 2 respectively.) They
  11. * are documented in ARM DUI 0225D Appendix C and D. These daughter
  12. * boards support TFT display panels.
  13. *
  14. * - The IB1 is a passive board where the display connector defines a
  15. * few wires for encoding the display type for autodetection,
  16. * suitable display settings can then be looked up from this setting.
  17. * The magic bits can be read out from the system controller.
  18. *
  19. * - The IB2 is a more complex board intended for GSM phone development
  20. * with some logic and a control register, which needs to be accessed
  21. * and the board display needs to be turned on explicitly.
  22. *
  23. * On the Versatile PB, a special CLCD adaptor board is available
  24. * supporting the same displays as the Versatile AB, plus one more
  25. * Epson QCIF display.
  26. *
  27. */
  28. #include <linux/bitops.h>
  29. #include <linux/init.h>
  30. #include <linux/kernel.h>
  31. #include <linux/mfd/syscon.h>
  32. #include <linux/mod_devicetable.h>
  33. #include <linux/module.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/regmap.h>
  36. #include <video/of_videomode.h>
  37. #include <video/videomode.h>
  38. #include <drm/drm_modes.h>
  39. #include <drm/drm_panel.h>
  40. /*
  41. * This configuration register in the Versatile and RealView
  42. * family is uniformly present but appears more and more
  43. * unutilized starting with the RealView series.
  44. */
  45. #define SYS_CLCD 0x50
  46. /* The Versatile can detect the connected panel type */
  47. #define SYS_CLCD_CLCDID_MASK (BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12))
  48. #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
  49. #define SYS_CLCD_ID_SHARP_8_4 (0x01 << 8)
  50. #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
  51. #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
  52. #define SYS_CLCD_ID_VGA (0x1f << 8)
  53. /* IB2 control register for the Versatile daughterboard */
  54. #define IB2_CTRL 0x00
  55. #define IB2_CTRL_LCD_SD BIT(1) /* 1 = shut down LCD */
  56. #define IB2_CTRL_LCD_BL_ON BIT(0)
  57. #define IB2_CTRL_LCD_MASK (BIT(0)|BIT(1))
  58. /**
  59. * struct versatile_panel_type - lookup struct for the supported panels
  60. */
  61. struct versatile_panel_type {
  62. /**
  63. * @name: the name of this panel
  64. */
  65. const char *name;
  66. /**
  67. * @magic: the magic value from the detection register
  68. */
  69. u32 magic;
  70. /**
  71. * @mode: the DRM display mode for this panel
  72. */
  73. struct drm_display_mode mode;
  74. /**
  75. * @bus_flags: the DRM bus flags for this panel e.g. inverted clock
  76. */
  77. u32 bus_flags;
  78. /**
  79. * @width_mm: the panel width in mm
  80. */
  81. u32 width_mm;
  82. /**
  83. * @height_mm: the panel height in mm
  84. */
  85. u32 height_mm;
  86. /**
  87. * @ib2: the panel may be connected on an IB2 daughterboard
  88. */
  89. bool ib2;
  90. };
  91. /**
  92. * struct versatile_panel - state container for the Versatile panels
  93. */
  94. struct versatile_panel {
  95. /**
  96. * @dev: the container device
  97. */
  98. struct device *dev;
  99. /**
  100. * @panel: the DRM panel instance for this device
  101. */
  102. struct drm_panel panel;
  103. /**
  104. * @panel_type: the Versatile panel type as detected
  105. */
  106. const struct versatile_panel_type *panel_type;
  107. /**
  108. * @map: map to the parent syscon where the main register reside
  109. */
  110. struct regmap *map;
  111. /**
  112. * @ib2_map: map to the IB2 syscon, if applicable
  113. */
  114. struct regmap *ib2_map;
  115. };
  116. static const struct versatile_panel_type versatile_panels[] = {
  117. /*
  118. * Sanyo TM38QV67A02A - 3.8 inch QVGA (320x240) Color TFT
  119. * found on the Versatile AB IB1 connector or the Versatile
  120. * PB adaptor board connector.
  121. */
  122. {
  123. .name = "Sanyo TM38QV67A02A",
  124. .magic = SYS_CLCD_ID_SANYO_3_8,
  125. .width_mm = 79,
  126. .height_mm = 54,
  127. .mode = {
  128. .clock = 10000,
  129. .hdisplay = 320,
  130. .hsync_start = 320 + 6,
  131. .hsync_end = 320 + 6 + 6,
  132. .htotal = 320 + 6 + 6 + 6,
  133. .vdisplay = 240,
  134. .vsync_start = 240 + 5,
  135. .vsync_end = 240 + 5 + 6,
  136. .vtotal = 240 + 5 + 6 + 5,
  137. .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
  138. },
  139. },
  140. /*
  141. * Sharp LQ084V1DG21 640x480 VGA Color TFT module
  142. * found on the Versatile AB IB1 connector or the Versatile
  143. * PB adaptor board connector.
  144. */
  145. {
  146. .name = "Sharp LQ084V1DG21",
  147. .magic = SYS_CLCD_ID_SHARP_8_4,
  148. .width_mm = 171,
  149. .height_mm = 130,
  150. .mode = {
  151. .clock = 25000,
  152. .hdisplay = 640,
  153. .hsync_start = 640 + 24,
  154. .hsync_end = 640 + 24 + 96,
  155. .htotal = 640 + 24 + 96 + 24,
  156. .vdisplay = 480,
  157. .vsync_start = 480 + 11,
  158. .vsync_end = 480 + 11 + 2,
  159. .vtotal = 480 + 11 + 2 + 32,
  160. .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
  161. },
  162. },
  163. /*
  164. * Epson L2F50113T00 - 2.2 inch QCIF 176x220 Color TFT
  165. * found on the Versatile PB adaptor board connector.
  166. */
  167. {
  168. .name = "Epson L2F50113T00",
  169. .magic = SYS_CLCD_ID_EPSON_2_2,
  170. .width_mm = 34,
  171. .height_mm = 45,
  172. .mode = {
  173. .clock = 62500,
  174. .hdisplay = 176,
  175. .hsync_start = 176 + 2,
  176. .hsync_end = 176 + 2 + 3,
  177. .htotal = 176 + 2 + 3 + 3,
  178. .vdisplay = 220,
  179. .vsync_start = 220 + 0,
  180. .vsync_end = 220 + 0 + 2,
  181. .vtotal = 220 + 0 + 2 + 1,
  182. .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
  183. },
  184. .bus_flags = DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE,
  185. },
  186. /*
  187. * Sanyo ALR252RGT 240x320 portrait display found on the
  188. * Versatile AB IB2 daughterboard for GSM prototyping.
  189. */
  190. {
  191. .name = "Sanyo ALR252RGT",
  192. .magic = SYS_CLCD_ID_SANYO_2_5,
  193. .width_mm = 37,
  194. .height_mm = 50,
  195. .mode = {
  196. .clock = 5400,
  197. .hdisplay = 240,
  198. .hsync_start = 240 + 10,
  199. .hsync_end = 240 + 10 + 10,
  200. .htotal = 240 + 10 + 10 + 20,
  201. .vdisplay = 320,
  202. .vsync_start = 320 + 2,
  203. .vsync_end = 320 + 2 + 2,
  204. .vtotal = 320 + 2 + 2 + 2,
  205. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  206. },
  207. .bus_flags = DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE,
  208. .ib2 = true,
  209. },
  210. };
  211. static inline struct versatile_panel *
  212. to_versatile_panel(struct drm_panel *panel)
  213. {
  214. return container_of(panel, struct versatile_panel, panel);
  215. }
  216. static int versatile_panel_disable(struct drm_panel *panel)
  217. {
  218. struct versatile_panel *vpanel = to_versatile_panel(panel);
  219. /* If we're on an IB2 daughterboard, turn off display */
  220. if (vpanel->ib2_map) {
  221. dev_dbg(vpanel->dev, "disable IB2 display\n");
  222. regmap_update_bits(vpanel->ib2_map,
  223. IB2_CTRL,
  224. IB2_CTRL_LCD_MASK,
  225. IB2_CTRL_LCD_SD);
  226. }
  227. return 0;
  228. }
  229. static int versatile_panel_enable(struct drm_panel *panel)
  230. {
  231. struct versatile_panel *vpanel = to_versatile_panel(panel);
  232. /* If we're on an IB2 daughterboard, turn on display */
  233. if (vpanel->ib2_map) {
  234. dev_dbg(vpanel->dev, "enable IB2 display\n");
  235. regmap_update_bits(vpanel->ib2_map,
  236. IB2_CTRL,
  237. IB2_CTRL_LCD_MASK,
  238. IB2_CTRL_LCD_BL_ON);
  239. }
  240. return 0;
  241. }
  242. static int versatile_panel_get_modes(struct drm_panel *panel,
  243. struct drm_connector *connector)
  244. {
  245. struct versatile_panel *vpanel = to_versatile_panel(panel);
  246. struct drm_display_mode *mode;
  247. connector->display_info.width_mm = vpanel->panel_type->width_mm;
  248. connector->display_info.height_mm = vpanel->panel_type->height_mm;
  249. connector->display_info.bus_flags = vpanel->panel_type->bus_flags;
  250. mode = drm_mode_duplicate(connector->dev, &vpanel->panel_type->mode);
  251. drm_mode_set_name(mode);
  252. mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  253. mode->width_mm = vpanel->panel_type->width_mm;
  254. mode->height_mm = vpanel->panel_type->height_mm;
  255. drm_mode_probed_add(connector, mode);
  256. return 1;
  257. }
  258. static const struct drm_panel_funcs versatile_panel_drm_funcs = {
  259. .disable = versatile_panel_disable,
  260. .enable = versatile_panel_enable,
  261. .get_modes = versatile_panel_get_modes,
  262. };
  263. static int versatile_panel_probe(struct platform_device *pdev)
  264. {
  265. struct device *dev = &pdev->dev;
  266. struct versatile_panel *vpanel;
  267. struct device *parent;
  268. struct regmap *map;
  269. int ret;
  270. u32 val;
  271. int i;
  272. parent = dev->parent;
  273. if (!parent) {
  274. dev_err(dev, "no parent for versatile panel\n");
  275. return -ENODEV;
  276. }
  277. map = syscon_node_to_regmap(parent->of_node);
  278. if (IS_ERR(map)) {
  279. dev_err(dev, "no regmap for versatile panel parent\n");
  280. return PTR_ERR(map);
  281. }
  282. vpanel = devm_kzalloc(dev, sizeof(*vpanel), GFP_KERNEL);
  283. if (!vpanel)
  284. return -ENOMEM;
  285. ret = regmap_read(map, SYS_CLCD, &val);
  286. if (ret) {
  287. dev_err(dev, "cannot access syscon regs\n");
  288. return ret;
  289. }
  290. val &= SYS_CLCD_CLCDID_MASK;
  291. for (i = 0; i < ARRAY_SIZE(versatile_panels); i++) {
  292. const struct versatile_panel_type *pt;
  293. pt = &versatile_panels[i];
  294. if (pt->magic == val) {
  295. vpanel->panel_type = pt;
  296. break;
  297. }
  298. }
  299. /* No panel detected or VGA, let's leave this show */
  300. if (i == ARRAY_SIZE(versatile_panels)) {
  301. dev_info(dev, "no panel detected\n");
  302. return -ENODEV;
  303. }
  304. dev_info(dev, "detected: %s\n", vpanel->panel_type->name);
  305. vpanel->dev = dev;
  306. vpanel->map = map;
  307. /* Check if the panel is mounted on an IB2 daughterboard */
  308. if (vpanel->panel_type->ib2) {
  309. vpanel->ib2_map = syscon_regmap_lookup_by_compatible(
  310. "arm,versatile-ib2-syscon");
  311. if (IS_ERR(vpanel->ib2_map))
  312. vpanel->ib2_map = NULL;
  313. else
  314. dev_info(dev, "panel mounted on IB2 daughterboard\n");
  315. }
  316. drm_panel_init(&vpanel->panel, dev, &versatile_panel_drm_funcs,
  317. DRM_MODE_CONNECTOR_DPI);
  318. drm_panel_add(&vpanel->panel);
  319. return 0;
  320. }
  321. static const struct of_device_id versatile_panel_match[] = {
  322. { .compatible = "arm,versatile-tft-panel", },
  323. {},
  324. };
  325. MODULE_DEVICE_TABLE(of, versatile_panel_match);
  326. static struct platform_driver versatile_panel_driver = {
  327. .probe = versatile_panel_probe,
  328. .driver = {
  329. .name = "versatile-tft-panel",
  330. .of_match_table = versatile_panel_match,
  331. },
  332. };
  333. module_platform_driver(versatile_panel_driver);
  334. MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
  335. MODULE_DESCRIPTION("ARM Versatile panel driver");
  336. MODULE_LICENSE("GPL v2");