panel-arm-versatile.c 9.6 KB

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