dss_features.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 <plat/display.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 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. [DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "N/A",
  154. [DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "N/A",
  155. [DSS_CLK_SRC_FCK] = "DSS_FCLK1",
  156. };
  157. static const char * const omap3_dss_clk_source_names[] = {
  158. [DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI1_PLL_FCLK",
  159. [DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI2_PLL_FCLK",
  160. [DSS_CLK_SRC_FCK] = "DSS1_ALWON_FCLK",
  161. };
  162. static const char * const omap4_dss_clk_source_names[] = {
  163. [DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "PLL1_CLK1",
  164. [DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "PLL1_CLK2",
  165. [DSS_CLK_SRC_FCK] = "DSS_FCLK",
  166. };
  167. static const struct dss_param_range omap2_dss_param_range[] = {
  168. [FEAT_PARAM_DSS_FCK] = { 0, 173000000 },
  169. [FEAT_PARAM_DSIPLL_REGN] = { 0, 0 },
  170. [FEAT_PARAM_DSIPLL_REGM] = { 0, 0 },
  171. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, 0 },
  172. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, 0 },
  173. [FEAT_PARAM_DSIPLL_FINT] = { 0, 0 },
  174. [FEAT_PARAM_DSIPLL_LPDIV] = { 0, 0 },
  175. };
  176. static const struct dss_param_range omap3_dss_param_range[] = {
  177. [FEAT_PARAM_DSS_FCK] = { 0, 173000000 },
  178. [FEAT_PARAM_DSIPLL_REGN] = { 0, (1 << 7) - 1 },
  179. [FEAT_PARAM_DSIPLL_REGM] = { 0, (1 << 11) - 1 },
  180. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, (1 << 4) - 1 },
  181. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, (1 << 4) - 1 },
  182. [FEAT_PARAM_DSIPLL_FINT] = { 750000, 2100000 },
  183. [FEAT_PARAM_DSIPLL_LPDIV] = { 1, (1 << 13) - 1},
  184. };
  185. static const struct dss_param_range omap4_dss_param_range[] = {
  186. [FEAT_PARAM_DSS_FCK] = { 0, 186000000 },
  187. [FEAT_PARAM_DSIPLL_REGN] = { 0, (1 << 8) - 1 },
  188. [FEAT_PARAM_DSIPLL_REGM] = { 0, (1 << 12) - 1 },
  189. [FEAT_PARAM_DSIPLL_REGM_DISPC] = { 0, (1 << 5) - 1 },
  190. [FEAT_PARAM_DSIPLL_REGM_DSI] = { 0, (1 << 5) - 1 },
  191. [FEAT_PARAM_DSIPLL_FINT] = { 500000, 2500000 },
  192. [FEAT_PARAM_DSIPLL_LPDIV] = { 0, (1 << 13) - 1 },
  193. };
  194. /* OMAP2 DSS Features */
  195. static struct omap_dss_features omap2_dss_features = {
  196. .reg_fields = omap2_dss_reg_fields,
  197. .num_reg_fields = ARRAY_SIZE(omap2_dss_reg_fields),
  198. .has_feature =
  199. FEAT_LCDENABLEPOL | FEAT_LCDENABLESIGNAL |
  200. FEAT_PCKFREEENABLE | FEAT_FUNCGATED |
  201. FEAT_ROWREPEATENABLE | FEAT_RESIZECONF,
  202. .num_mgrs = 2,
  203. .num_ovls = 3,
  204. .supported_displays = omap2_dss_supported_displays,
  205. .supported_color_modes = omap2_dss_supported_color_modes,
  206. .clksrc_names = omap2_dss_clk_source_names,
  207. .dss_params = omap2_dss_param_range,
  208. };
  209. /* OMAP3 DSS Features */
  210. static struct omap_dss_features omap3430_dss_features = {
  211. .reg_fields = omap3_dss_reg_fields,
  212. .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
  213. .has_feature =
  214. FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
  215. FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
  216. FEAT_FUNCGATED | FEAT_ROWREPEATENABLE |
  217. FEAT_LINEBUFFERSPLIT | FEAT_RESIZECONF,
  218. .num_mgrs = 2,
  219. .num_ovls = 3,
  220. .supported_displays = omap3430_dss_supported_displays,
  221. .supported_color_modes = omap3_dss_supported_color_modes,
  222. .clksrc_names = omap3_dss_clk_source_names,
  223. .dss_params = omap3_dss_param_range,
  224. };
  225. static struct omap_dss_features omap3630_dss_features = {
  226. .reg_fields = omap3_dss_reg_fields,
  227. .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
  228. .has_feature =
  229. FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
  230. FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
  231. FEAT_PRE_MULT_ALPHA | FEAT_FUNCGATED |
  232. FEAT_ROWREPEATENABLE | FEAT_LINEBUFFERSPLIT |
  233. FEAT_RESIZECONF,
  234. .num_mgrs = 2,
  235. .num_ovls = 3,
  236. .supported_displays = omap3630_dss_supported_displays,
  237. .supported_color_modes = omap3_dss_supported_color_modes,
  238. .clksrc_names = omap3_dss_clk_source_names,
  239. .dss_params = omap3_dss_param_range,
  240. };
  241. /* OMAP4 DSS Features */
  242. static struct omap_dss_features omap4_dss_features = {
  243. .reg_fields = omap4_dss_reg_fields,
  244. .num_reg_fields = ARRAY_SIZE(omap4_dss_reg_fields),
  245. .has_feature =
  246. FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
  247. FEAT_MGR_LCD2 | FEAT_GLOBAL_ALPHA_VID1 |
  248. FEAT_CORE_CLK_DIV | FEAT_LCD_CLK_SRC,
  249. .num_mgrs = 3,
  250. .num_ovls = 3,
  251. .supported_displays = omap4_dss_supported_displays,
  252. .supported_color_modes = omap3_dss_supported_color_modes,
  253. .clksrc_names = omap4_dss_clk_source_names,
  254. .dss_params = omap4_dss_param_range,
  255. };
  256. /* Functions returning values related to a DSS feature */
  257. int dss_feat_get_num_mgrs(void)
  258. {
  259. return omap_current_dss_features->num_mgrs;
  260. }
  261. int dss_feat_get_num_ovls(void)
  262. {
  263. return omap_current_dss_features->num_ovls;
  264. }
  265. unsigned long dss_feat_get_param_min(enum dss_range_param param)
  266. {
  267. return omap_current_dss_features->dss_params[param].min;
  268. }
  269. unsigned long dss_feat_get_param_max(enum dss_range_param param)
  270. {
  271. return omap_current_dss_features->dss_params[param].max;
  272. }
  273. enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel)
  274. {
  275. return omap_current_dss_features->supported_displays[channel];
  276. }
  277. enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane)
  278. {
  279. return omap_current_dss_features->supported_color_modes[plane];
  280. }
  281. bool dss_feat_color_mode_supported(enum omap_plane plane,
  282. enum omap_color_mode color_mode)
  283. {
  284. return omap_current_dss_features->supported_color_modes[plane] &
  285. color_mode;
  286. }
  287. const char *dss_feat_get_clk_source_name(enum dss_clk_source id)
  288. {
  289. return omap_current_dss_features->clksrc_names[id];
  290. }
  291. /* DSS has_feature check */
  292. bool dss_has_feature(enum dss_feat_id id)
  293. {
  294. return omap_current_dss_features->has_feature & id;
  295. }
  296. void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end)
  297. {
  298. if (id >= omap_current_dss_features->num_reg_fields)
  299. BUG();
  300. *start = omap_current_dss_features->reg_fields[id].start;
  301. *end = omap_current_dss_features->reg_fields[id].end;
  302. }
  303. void dss_features_init(void)
  304. {
  305. if (cpu_is_omap24xx())
  306. omap_current_dss_features = &omap2_dss_features;
  307. else if (cpu_is_omap3630())
  308. omap_current_dss_features = &omap3630_dss_features;
  309. else if (cpu_is_omap34xx())
  310. omap_current_dss_features = &omap3430_dss_features;
  311. else
  312. omap_current_dss_features = &omap4_dss_features;
  313. }