dss_features.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * linux/drivers/video/omap2/dss/dss_features.c
  3. *
  4. * Copyright (C) 2010 Texas Instruments
  5. * Author: Archit Taneja <archit@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/err.h>
  22. #include <linux/slab.h>
  23. #include <video/omapdss.h>
  24. #include <plat/cpu.h>
  25. #include "dss.h"
  26. #include "dss_features.h"
  27. /* Defines a generic omap register field */
  28. struct dss_reg_field {
  29. u8 start, end;
  30. };
  31. struct dss_param_range {
  32. int min, max;
  33. };
  34. struct omap_dss_features {
  35. const struct dss_reg_field *reg_fields;
  36. const int num_reg_fields;
  37. const u32 has_feature;
  38. const int num_mgrs;
  39. const int num_ovls;
  40. const enum omap_display_type *supported_displays;
  41. const enum omap_color_mode *supported_color_modes;
  42. const char * const *clksrc_names;
  43. const struct dss_param_range *dss_params;
  44. };
  45. /* This struct is assigned to one of the below during initialization */
  46. static const struct omap_dss_features *omap_current_dss_features;
  47. static const struct dss_reg_field omap2_dss_reg_fields[] = {
  48. [FEAT_REG_FIRHINC] = { 11, 0 },
  49. [FEAT_REG_FIRVINC] = { 27, 16 },
  50. [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
  51. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
  52. [FEAT_REG_FIFOSIZE] = { 8, 0 },
  53. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  54. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  55. [FEAT_REG_DISPC_CLK_SWITCH] = { 0, 0 },
  56. [FEAT_REG_DSIPLL_REGN] = { 0, 0 },
  57. [FEAT_REG_DSIPLL_REGM] = { 0, 0 },
  58. [FEAT_REG_DSIPLL_REGM_DISPC] = { 0, 0 },
  59. [FEAT_REG_DSIPLL_REGM_DSI] = { 0, 0 },
  60. };
  61. static const struct dss_reg_field omap3_dss_reg_fields[] = {
  62. [FEAT_REG_FIRHINC] = { 12, 0 },
  63. [FEAT_REG_FIRVINC] = { 28, 16 },
  64. [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
  65. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
  66. [FEAT_REG_FIFOSIZE] = { 10, 0 },
  67. [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
  68. [FEAT_REG_VERTICALACCU] = { 25, 16 },
  69. [FEAT_REG_DISPC_CLK_SWITCH] = { 0, 0 },
  70. [FEAT_REG_DSIPLL_REGN] = { 7, 1 },
  71. [FEAT_REG_DSIPLL_REGM] = { 18, 8 },
  72. [FEAT_REG_DSIPLL_REGM_DISPC] = { 22, 19 },
  73. [FEAT_REG_DSIPLL_REGM_DSI] = { 26, 23 },
  74. };
  75. static const struct dss_reg_field omap4_dss_reg_fields[] = {
  76. [FEAT_REG_FIRHINC] = { 12, 0 },
  77. [FEAT_REG_FIRVINC] = { 28, 16 },
  78. [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
  79. [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
  80. [FEAT_REG_FIFOSIZE] = { 15, 0 },
  81. [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
  82. [FEAT_REG_VERTICALACCU] = { 26, 16 },
  83. [FEAT_REG_DISPC_CLK_SWITCH] = { 9, 8 },
  84. [FEAT_REG_DSIPLL_REGN] = { 8, 1 },
  85. [FEAT_REG_DSIPLL_REGM] = { 20, 9 },
  86. [FEAT_REG_DSIPLL_REGM_DISPC] = { 25, 21 },
  87. [FEAT_REG_DSIPLL_REGM_DSI] = { 30, 26 },
  88. };
  89. static const enum omap_display_type omap2_dss_supported_displays[] = {
  90. /* OMAP_DSS_CHANNEL_LCD */
  91. OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI,
  92. /* OMAP_DSS_CHANNEL_DIGIT */
  93. OMAP_DISPLAY_TYPE_VENC,
  94. };
  95. static const enum omap_display_type omap3430_dss_supported_displays[] = {
  96. /* OMAP_DSS_CHANNEL_LCD */
  97. OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
  98. OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI,
  99. /* OMAP_DSS_CHANNEL_DIGIT */
  100. OMAP_DISPLAY_TYPE_VENC,
  101. };
  102. static const enum omap_display_type omap3630_dss_supported_displays[] = {
  103. /* OMAP_DSS_CHANNEL_LCD */
  104. OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
  105. OMAP_DISPLAY_TYPE_DSI,
  106. /* OMAP_DSS_CHANNEL_DIGIT */
  107. OMAP_DISPLAY_TYPE_VENC,
  108. };
  109. static const enum omap_display_type omap4_dss_supported_displays[] = {
  110. /* OMAP_DSS_CHANNEL_LCD */
  111. OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI,
  112. /* OMAP_DSS_CHANNEL_DIGIT */
  113. OMAP_DISPLAY_TYPE_VENC | OMAP_DISPLAY_TYPE_HDMI,
  114. /* OMAP_DSS_CHANNEL_LCD2 */
  115. OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
  116. OMAP_DISPLAY_TYPE_DSI,
  117. };
  118. static const enum omap_color_mode omap2_dss_supported_color_modes[] = {
  119. /* OMAP_DSS_GFX */
  120. OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 |
  121. OMAP_DSS_COLOR_CLUT4 | OMAP_DSS_COLOR_CLUT8 |
  122. OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_RGB16 |
  123. OMAP_DSS_COLOR_RGB24U | OMAP_DSS_COLOR_RGB24P,
  124. /* OMAP_DSS_VIDEO1 */
  125. OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
  126. OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
  127. OMAP_DSS_COLOR_UYVY,
  128. /* OMAP_DSS_VIDEO2 */
  129. OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
  130. OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
  131. OMAP_DSS_COLOR_UYVY,
  132. };
  133. static const enum omap_color_mode omap3_dss_supported_color_modes[] = {
  134. /* OMAP_DSS_GFX */
  135. OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 |
  136. OMAP_DSS_COLOR_CLUT4 | OMAP_DSS_COLOR_CLUT8 |
  137. OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_ARGB16 |
  138. OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
  139. OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_ARGB32 |
  140. OMAP_DSS_COLOR_RGBA32 | OMAP_DSS_COLOR_RGBX32,
  141. /* OMAP_DSS_VIDEO1 */
  142. OMAP_DSS_COLOR_RGB24U | OMAP_DSS_COLOR_RGB24P |
  143. OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_RGB16 |
  144. OMAP_DSS_COLOR_YUV2 | OMAP_DSS_COLOR_UYVY,
  145. /* OMAP_DSS_VIDEO2 */
  146. OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_ARGB16 |
  147. OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
  148. OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
  149. OMAP_DSS_COLOR_UYVY | OMAP_DSS_COLOR_ARGB32 |
  150. OMAP_DSS_COLOR_RGBA32 | OMAP_DSS_COLOR_RGBX32,
  151. };
  152. static const char * const omap2_dss_clk_source_names[] = {
  153. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "N/A",
  154. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "N/A",
  155. [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCLK1",
  156. };
  157. static const char * const omap3_dss_clk_source_names[] = {
  158. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI1_PLL_FCLK",
  159. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI2_PLL_FCLK",
  160. [OMAP_DSS_CLK_SRC_FCK] = "DSS1_ALWON_FCLK",
  161. };
  162. static const char * const omap4_dss_clk_source_names[] = {
  163. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "PLL1_CLK1",
  164. [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "PLL1_CLK2",
  165. [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCLK",
  166. [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC] = "PLL2_CLK1",
  167. [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI] = "PLL2_CLK2",
  168. };
  169. static const struct dss_param_range omap2_dss_param_range[] = {
  170. [FEAT_PARAM_DSS_FCK] = { 0, 173000000 },
  171. [FEAT_PARAM_DSIPLL_REGN] = { 0, 0 },
  172. [FEAT_PARAM_DSIPLL_REGM] = { 0, 0 },
  173. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, 0 },
  174. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, 0 },
  175. [FEAT_PARAM_DSIPLL_FINT] = { 0, 0 },
  176. [FEAT_PARAM_DSIPLL_LPDIV] = { 0, 0 },
  177. };
  178. static const struct dss_param_range omap3_dss_param_range[] = {
  179. [FEAT_PARAM_DSS_FCK] = { 0, 173000000 },
  180. [FEAT_PARAM_DSIPLL_REGN] = { 0, (1 << 7) - 1 },
  181. [FEAT_PARAM_DSIPLL_REGM] = { 0, (1 << 11) - 1 },
  182. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, (1 << 4) - 1 },
  183. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, (1 << 4) - 1 },
  184. [FEAT_PARAM_DSIPLL_FINT] = { 750000, 2100000 },
  185. [FEAT_PARAM_DSIPLL_LPDIV] = { 1, (1 << 13) - 1},
  186. };
  187. static const struct dss_param_range omap4_dss_param_range[] = {
  188. [FEAT_PARAM_DSS_FCK] = { 0, 186000000 },
  189. [FEAT_PARAM_DSIPLL_REGN] = { 0, (1 << 8) - 1 },
  190. [FEAT_PARAM_DSIPLL_REGM] = { 0, (1 << 12) - 1 },
  191. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, (1 << 5) - 1 },
  192. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, (1 << 5) - 1 },
  193. [FEAT_PARAM_DSIPLL_FINT] = { 500000, 2500000 },
  194. [FEAT_PARAM_DSIPLL_LPDIV] = { 0, (1 << 13) - 1 },
  195. };
  196. /* OMAP2 DSS Features */
  197. static const struct omap_dss_features omap2_dss_features = {
  198. .reg_fields = omap2_dss_reg_fields,
  199. .num_reg_fields = ARRAY_SIZE(omap2_dss_reg_fields),
  200. .has_feature =
  201. FEAT_LCDENABLEPOL | FEAT_LCDENABLESIGNAL |
  202. FEAT_PCKFREEENABLE | FEAT_FUNCGATED |
  203. FEAT_ROWREPEATENABLE | FEAT_RESIZECONF,
  204. .num_mgrs = 2,
  205. .num_ovls = 3,
  206. .supported_displays = omap2_dss_supported_displays,
  207. .supported_color_modes = omap2_dss_supported_color_modes,
  208. .clksrc_names = omap2_dss_clk_source_names,
  209. .dss_params = omap2_dss_param_range,
  210. };
  211. /* OMAP3 DSS Features */
  212. static const struct omap_dss_features omap3430_dss_features = {
  213. .reg_fields = omap3_dss_reg_fields,
  214. .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
  215. .has_feature =
  216. FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
  217. FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
  218. FEAT_FUNCGATED | FEAT_ROWREPEATENABLE |
  219. FEAT_LINEBUFFERSPLIT | FEAT_RESIZECONF |
  220. FEAT_DSI_PLL_FREQSEL | FEAT_DSI_REVERSE_TXCLKESC,
  221. .num_mgrs = 2,
  222. .num_ovls = 3,
  223. .supported_displays = omap3430_dss_supported_displays,
  224. .supported_color_modes = omap3_dss_supported_color_modes,
  225. .clksrc_names = omap3_dss_clk_source_names,
  226. .dss_params = omap3_dss_param_range,
  227. };
  228. static const struct omap_dss_features omap3630_dss_features = {
  229. .reg_fields = omap3_dss_reg_fields,
  230. .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
  231. .has_feature =
  232. FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
  233. FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
  234. FEAT_PRE_MULT_ALPHA | FEAT_FUNCGATED |
  235. FEAT_ROWREPEATENABLE | FEAT_LINEBUFFERSPLIT |
  236. FEAT_RESIZECONF | FEAT_DSI_PLL_PWR_BUG |
  237. FEAT_DSI_PLL_FREQSEL,
  238. .num_mgrs = 2,
  239. .num_ovls = 3,
  240. .supported_displays = omap3630_dss_supported_displays,
  241. .supported_color_modes = omap3_dss_supported_color_modes,
  242. .clksrc_names = omap3_dss_clk_source_names,
  243. .dss_params = omap3_dss_param_range,
  244. };
  245. /* OMAP4 DSS Features */
  246. static const struct omap_dss_features omap4_dss_features = {
  247. .reg_fields = omap4_dss_reg_fields,
  248. .num_reg_fields = ARRAY_SIZE(omap4_dss_reg_fields),
  249. .has_feature =
  250. FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
  251. FEAT_MGR_LCD2 | FEAT_GLOBAL_ALPHA_VID1 |
  252. FEAT_CORE_CLK_DIV | FEAT_LCD_CLK_SRC |
  253. FEAT_DSI_DCS_CMD_CONFIG_VC | FEAT_DSI_VC_OCP_WIDTH,
  254. .num_mgrs = 3,
  255. .num_ovls = 3,
  256. .supported_displays = omap4_dss_supported_displays,
  257. .supported_color_modes = omap3_dss_supported_color_modes,
  258. .clksrc_names = omap4_dss_clk_source_names,
  259. .dss_params = omap4_dss_param_range,
  260. };
  261. /* Functions returning values related to a DSS feature */
  262. int dss_feat_get_num_mgrs(void)
  263. {
  264. return omap_current_dss_features->num_mgrs;
  265. }
  266. int dss_feat_get_num_ovls(void)
  267. {
  268. return omap_current_dss_features->num_ovls;
  269. }
  270. unsigned long dss_feat_get_param_min(enum dss_range_param param)
  271. {
  272. return omap_current_dss_features->dss_params[param].min;
  273. }
  274. unsigned long dss_feat_get_param_max(enum dss_range_param param)
  275. {
  276. return omap_current_dss_features->dss_params[param].max;
  277. }
  278. enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel)
  279. {
  280. return omap_current_dss_features->supported_displays[channel];
  281. }
  282. enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane)
  283. {
  284. return omap_current_dss_features->supported_color_modes[plane];
  285. }
  286. bool dss_feat_color_mode_supported(enum omap_plane plane,
  287. enum omap_color_mode color_mode)
  288. {
  289. return omap_current_dss_features->supported_color_modes[plane] &
  290. color_mode;
  291. }
  292. const char *dss_feat_get_clk_source_name(enum omap_dss_clk_source id)
  293. {
  294. return omap_current_dss_features->clksrc_names[id];
  295. }
  296. /* DSS has_feature check */
  297. bool dss_has_feature(enum dss_feat_id id)
  298. {
  299. return omap_current_dss_features->has_feature & id;
  300. }
  301. void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end)
  302. {
  303. if (id >= omap_current_dss_features->num_reg_fields)
  304. BUG();
  305. *start = omap_current_dss_features->reg_fields[id].start;
  306. *end = omap_current_dss_features->reg_fields[id].end;
  307. }
  308. void dss_features_init(void)
  309. {
  310. if (cpu_is_omap24xx())
  311. omap_current_dss_features = &omap2_dss_features;
  312. else if (cpu_is_omap3630())
  313. omap_current_dss_features = &omap3630_dss_features;
  314. else if (cpu_is_omap34xx())
  315. omap_current_dss_features = &omap3430_dss_features;
  316. else
  317. omap_current_dss_features = &omap4_dss_features;
  318. }