pl111_versatile.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #include <linux/device.h>
  2. #include <linux/of.h>
  3. #include <linux/regmap.h>
  4. #include <linux/mfd/syscon.h>
  5. #include <linux/bitops.h>
  6. #include <linux/module.h>
  7. #include <drm/drmP.h>
  8. #include "pl111_versatile.h"
  9. #include "pl111_drm.h"
  10. static struct regmap *versatile_syscon_map;
  11. /*
  12. * We detect the different syscon types from the compatible strings.
  13. */
  14. enum versatile_clcd {
  15. INTEGRATOR_CLCD_CM,
  16. VERSATILE_CLCD,
  17. REALVIEW_CLCD_EB,
  18. REALVIEW_CLCD_PB1176,
  19. REALVIEW_CLCD_PB11MP,
  20. REALVIEW_CLCD_PBA8,
  21. REALVIEW_CLCD_PBX,
  22. };
  23. static const struct of_device_id versatile_clcd_of_match[] = {
  24. {
  25. .compatible = "arm,core-module-integrator",
  26. .data = (void *)INTEGRATOR_CLCD_CM,
  27. },
  28. {
  29. .compatible = "arm,versatile-sysreg",
  30. .data = (void *)VERSATILE_CLCD,
  31. },
  32. {
  33. .compatible = "arm,realview-eb-syscon",
  34. .data = (void *)REALVIEW_CLCD_EB,
  35. },
  36. {
  37. .compatible = "arm,realview-pb1176-syscon",
  38. .data = (void *)REALVIEW_CLCD_PB1176,
  39. },
  40. {
  41. .compatible = "arm,realview-pb11mp-syscon",
  42. .data = (void *)REALVIEW_CLCD_PB11MP,
  43. },
  44. {
  45. .compatible = "arm,realview-pba8-syscon",
  46. .data = (void *)REALVIEW_CLCD_PBA8,
  47. },
  48. {
  49. .compatible = "arm,realview-pbx-syscon",
  50. .data = (void *)REALVIEW_CLCD_PBX,
  51. },
  52. {},
  53. };
  54. /*
  55. * Core module CLCD control on the Integrator/CP, bits
  56. * 8 thru 19 of the CM_CONTROL register controls a bunch
  57. * of CLCD settings.
  58. */
  59. #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
  60. #define INTEGRATOR_CLCD_LCDBIASEN BIT(8)
  61. #define INTEGRATOR_CLCD_LCDBIASUP BIT(9)
  62. #define INTEGRATOR_CLCD_LCDBIASDN BIT(10)
  63. /* Bits 11,12,13 controls the LCD type */
  64. #define INTEGRATOR_CLCD_LCDMUX_MASK (BIT(11)|BIT(12)|BIT(13))
  65. #define INTEGRATOR_CLCD_LCDMUX_LCD24 BIT(11)
  66. #define INTEGRATOR_CLCD_LCDMUX_VGA565 BIT(12)
  67. #define INTEGRATOR_CLCD_LCDMUX_SHARP (BIT(11)|BIT(12))
  68. #define INTEGRATOR_CLCD_LCDMUX_VGA555 BIT(13)
  69. #define INTEGRATOR_CLCD_LCDMUX_VGA24 (BIT(11)|BIT(12)|BIT(13))
  70. #define INTEGRATOR_CLCD_LCD0_EN BIT(14)
  71. #define INTEGRATOR_CLCD_LCD1_EN BIT(15)
  72. /* R/L flip on Sharp */
  73. #define INTEGRATOR_CLCD_LCD_STATIC1 BIT(16)
  74. /* U/D flip on Sharp */
  75. #define INTEGRATOR_CLCD_LCD_STATIC2 BIT(17)
  76. /* No connection on Sharp */
  77. #define INTEGRATOR_CLCD_LCD_STATIC BIT(18)
  78. /* 0 = 24bit VGA, 1 = 18bit VGA */
  79. #define INTEGRATOR_CLCD_LCD_N24BITEN BIT(19)
  80. #define INTEGRATOR_CLCD_MASK (INTEGRATOR_CLCD_LCDBIASEN | \
  81. INTEGRATOR_CLCD_LCDBIASUP | \
  82. INTEGRATOR_CLCD_LCDBIASDN | \
  83. INTEGRATOR_CLCD_LCDMUX_MASK | \
  84. INTEGRATOR_CLCD_LCD0_EN | \
  85. INTEGRATOR_CLCD_LCD1_EN | \
  86. INTEGRATOR_CLCD_LCD_STATIC1 | \
  87. INTEGRATOR_CLCD_LCD_STATIC2 | \
  88. INTEGRATOR_CLCD_LCD_STATIC | \
  89. INTEGRATOR_CLCD_LCD_N24BITEN)
  90. static void pl111_integrator_enable(struct drm_device *drm, u32 format)
  91. {
  92. u32 val;
  93. dev_info(drm->dev, "enable Integrator CLCD connectors\n");
  94. /* FIXME: really needed? */
  95. val = INTEGRATOR_CLCD_LCD_STATIC1 | INTEGRATOR_CLCD_LCD_STATIC2 |
  96. INTEGRATOR_CLCD_LCD0_EN | INTEGRATOR_CLCD_LCD1_EN;
  97. switch (format) {
  98. case DRM_FORMAT_XBGR8888:
  99. case DRM_FORMAT_XRGB8888:
  100. break;
  101. case DRM_FORMAT_BGR565:
  102. case DRM_FORMAT_RGB565:
  103. /* truecolor RGB565 */
  104. val |= INTEGRATOR_CLCD_LCDMUX_VGA565;
  105. break;
  106. case DRM_FORMAT_XBGR1555:
  107. case DRM_FORMAT_XRGB1555:
  108. /* Pseudocolor, RGB555, BGR555 */
  109. val |= INTEGRATOR_CLCD_LCDMUX_VGA555;
  110. break;
  111. default:
  112. dev_err(drm->dev, "unhandled format on Integrator 0x%08x\n",
  113. format);
  114. break;
  115. }
  116. regmap_update_bits(versatile_syscon_map,
  117. INTEGRATOR_HDR_CTRL_OFFSET,
  118. INTEGRATOR_CLCD_MASK,
  119. val);
  120. }
  121. /*
  122. * This configuration register in the Versatile and RealView
  123. * family is uniformly present but appears more and more
  124. * unutilized starting with the RealView series.
  125. */
  126. #define SYS_CLCD 0x50
  127. #define SYS_CLCD_MODE_MASK (BIT(0)|BIT(1))
  128. #define SYS_CLCD_MODE_888 0
  129. #define SYS_CLCD_MODE_5551 BIT(0)
  130. #define SYS_CLCD_MODE_565_R_LSB BIT(1)
  131. #define SYS_CLCD_MODE_565_B_LSB (BIT(0)|BIT(1))
  132. #define SYS_CLCD_CONNECTOR_MASK (BIT(2)|BIT(3)|BIT(4)|BIT(5))
  133. #define SYS_CLCD_NLCDIOON BIT(2)
  134. #define SYS_CLCD_VDDPOSSWITCH BIT(3)
  135. #define SYS_CLCD_PWR3V5SWITCH BIT(4)
  136. #define SYS_CLCD_VDDNEGSWITCH BIT(5)
  137. static void pl111_versatile_disable(struct drm_device *drm)
  138. {
  139. dev_info(drm->dev, "disable Versatile CLCD connectors\n");
  140. regmap_update_bits(versatile_syscon_map,
  141. SYS_CLCD,
  142. SYS_CLCD_CONNECTOR_MASK,
  143. 0);
  144. }
  145. static void pl111_versatile_enable(struct drm_device *drm, u32 format)
  146. {
  147. u32 val = 0;
  148. dev_info(drm->dev, "enable Versatile CLCD connectors\n");
  149. switch (format) {
  150. case DRM_FORMAT_ABGR8888:
  151. case DRM_FORMAT_XBGR8888:
  152. case DRM_FORMAT_ARGB8888:
  153. case DRM_FORMAT_XRGB8888:
  154. val |= SYS_CLCD_MODE_888;
  155. break;
  156. case DRM_FORMAT_BGR565:
  157. val |= SYS_CLCD_MODE_565_R_LSB;
  158. break;
  159. case DRM_FORMAT_RGB565:
  160. val |= SYS_CLCD_MODE_565_B_LSB;
  161. break;
  162. case DRM_FORMAT_ABGR1555:
  163. case DRM_FORMAT_XBGR1555:
  164. case DRM_FORMAT_ARGB1555:
  165. case DRM_FORMAT_XRGB1555:
  166. val |= SYS_CLCD_MODE_5551;
  167. break;
  168. default:
  169. dev_err(drm->dev, "unhandled format on Versatile 0x%08x\n",
  170. format);
  171. break;
  172. }
  173. /* Set up the MUX */
  174. regmap_update_bits(versatile_syscon_map,
  175. SYS_CLCD,
  176. SYS_CLCD_MODE_MASK,
  177. val);
  178. /* Then enable the display */
  179. regmap_update_bits(versatile_syscon_map,
  180. SYS_CLCD,
  181. SYS_CLCD_CONNECTOR_MASK,
  182. SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
  183. }
  184. static void pl111_realview_clcd_disable(struct drm_device *drm)
  185. {
  186. dev_info(drm->dev, "disable RealView CLCD connectors\n");
  187. regmap_update_bits(versatile_syscon_map,
  188. SYS_CLCD,
  189. SYS_CLCD_CONNECTOR_MASK,
  190. 0);
  191. }
  192. static void pl111_realview_clcd_enable(struct drm_device *drm, u32 format)
  193. {
  194. dev_info(drm->dev, "enable RealView CLCD connectors\n");
  195. regmap_update_bits(versatile_syscon_map,
  196. SYS_CLCD,
  197. SYS_CLCD_CONNECTOR_MASK,
  198. SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
  199. }
  200. int pl111_versatile_init(struct device *dev, struct pl111_drm_dev_private *priv)
  201. {
  202. const struct of_device_id *clcd_id;
  203. enum versatile_clcd versatile_clcd_type;
  204. struct device_node *np;
  205. struct regmap *map;
  206. np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match,
  207. &clcd_id);
  208. if (!np) {
  209. /* Non-ARM reference designs, just bail out */
  210. return 0;
  211. }
  212. versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
  213. map = syscon_node_to_regmap(np);
  214. if (IS_ERR(map)) {
  215. dev_err(dev, "no Versatile syscon regmap\n");
  216. return PTR_ERR(map);
  217. }
  218. switch (versatile_clcd_type) {
  219. case INTEGRATOR_CLCD_CM:
  220. versatile_syscon_map = map;
  221. priv->variant_display_enable = pl111_integrator_enable;
  222. dev_info(dev, "set up callbacks for Integrator PL110\n");
  223. break;
  224. case VERSATILE_CLCD:
  225. versatile_syscon_map = map;
  226. priv->variant_display_enable = pl111_versatile_enable;
  227. priv->variant_display_disable = pl111_versatile_disable;
  228. dev_info(dev, "set up callbacks for Versatile PL110+\n");
  229. break;
  230. case REALVIEW_CLCD_EB:
  231. case REALVIEW_CLCD_PB1176:
  232. case REALVIEW_CLCD_PB11MP:
  233. case REALVIEW_CLCD_PBA8:
  234. case REALVIEW_CLCD_PBX:
  235. versatile_syscon_map = map;
  236. priv->variant_display_enable = pl111_realview_clcd_enable;
  237. priv->variant_display_disable = pl111_realview_clcd_disable;
  238. dev_info(dev, "set up callbacks for RealView PL111\n");
  239. break;
  240. default:
  241. dev_info(dev, "unknown Versatile system controller\n");
  242. break;
  243. }
  244. return 0;
  245. }
  246. EXPORT_SYMBOL_GPL(pl111_versatile_init);