malidp_hw.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. *
  3. * (C) COPYRIGHT 2013-2016 ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * ARM Mali DP hardware manipulation routines.
  11. */
  12. #ifndef __MALIDP_HW_H__
  13. #define __MALIDP_HW_H__
  14. #include <linux/bitops.h>
  15. #include "malidp_regs.h"
  16. struct videomode;
  17. struct clk;
  18. /* Mali DP IP blocks */
  19. enum {
  20. MALIDP_DE_BLOCK = 0,
  21. MALIDP_SE_BLOCK,
  22. MALIDP_DC_BLOCK
  23. };
  24. /* Mali DP layer IDs */
  25. enum {
  26. DE_VIDEO1 = BIT(0),
  27. DE_GRAPHICS1 = BIT(1),
  28. DE_GRAPHICS2 = BIT(2), /* used only in DP500 */
  29. DE_VIDEO2 = BIT(3),
  30. DE_SMART = BIT(4),
  31. };
  32. struct malidp_format_id {
  33. u32 format; /* DRM fourcc */
  34. u8 layer; /* bitmask of layers supporting it */
  35. u8 id; /* used internally */
  36. };
  37. #define MALIDP_INVALID_FORMAT_ID 0xff
  38. /*
  39. * hide the differences between register maps
  40. * by using a common structure to hold the
  41. * base register offsets
  42. */
  43. struct malidp_irq_map {
  44. u32 irq_mask; /* mask of IRQs that can be enabled in the block */
  45. u32 vsync_irq; /* IRQ bit used for signaling during VSYNC */
  46. };
  47. struct malidp_layer {
  48. u16 id; /* layer ID */
  49. u16 base; /* address offset for the register bank */
  50. u16 ptr; /* address offset for the pointer register */
  51. u16 stride_offset; /* Offset to the first stride register. */
  52. };
  53. enum malidp_scaling_coeff_set {
  54. MALIDP_UPSCALING_COEFFS = 1,
  55. MALIDP_DOWNSCALING_1_5_COEFFS = 2,
  56. MALIDP_DOWNSCALING_2_COEFFS = 3,
  57. MALIDP_DOWNSCALING_2_75_COEFFS = 4,
  58. MALIDP_DOWNSCALING_4_COEFFS = 5,
  59. };
  60. struct malidp_se_config {
  61. u8 scale_enable : 1;
  62. u8 enhancer_enable : 1;
  63. u8 hcoeff : 3;
  64. u8 vcoeff : 3;
  65. u8 plane_src_id;
  66. u16 input_w, input_h;
  67. u16 output_w, output_h;
  68. u32 h_init_phase, h_delta_phase;
  69. u32 v_init_phase, v_delta_phase;
  70. };
  71. /* regmap features */
  72. #define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
  73. struct malidp_hw_regmap {
  74. /* address offset of the DE register bank */
  75. /* is always 0x0000 */
  76. /* address offset of the DE coefficients registers */
  77. const u16 coeffs_base;
  78. /* address offset of the SE registers bank */
  79. const u16 se_base;
  80. /* address offset of the DC registers bank */
  81. const u16 dc_base;
  82. /* address offset for the output depth register */
  83. const u16 out_depth_base;
  84. /* bitmap with register map features */
  85. const u8 features;
  86. /* list of supported layers */
  87. const u8 n_layers;
  88. const struct malidp_layer *layers;
  89. const struct malidp_irq_map de_irq_map;
  90. const struct malidp_irq_map se_irq_map;
  91. const struct malidp_irq_map dc_irq_map;
  92. /* list of supported pixel formats for each layer */
  93. const struct malidp_format_id *pixel_formats;
  94. const u8 n_pixel_formats;
  95. /* pitch alignment requirement in bytes */
  96. const u8 bus_align_bytes;
  97. };
  98. /* device features */
  99. /* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
  100. #define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
  101. struct malidp_hw_device {
  102. const struct malidp_hw_regmap map;
  103. void __iomem *regs;
  104. /* APB clock */
  105. struct clk *pclk;
  106. /* AXI clock */
  107. struct clk *aclk;
  108. /* main clock for display core */
  109. struct clk *mclk;
  110. /* pixel clock for display core */
  111. struct clk *pxlclk;
  112. /*
  113. * Validate the driver instance against the hardware bits
  114. */
  115. int (*query_hw)(struct malidp_hw_device *hwdev);
  116. /*
  117. * Set the hardware into config mode, ready to accept mode changes
  118. */
  119. void (*enter_config_mode)(struct malidp_hw_device *hwdev);
  120. /*
  121. * Tell hardware to exit configuration mode
  122. */
  123. void (*leave_config_mode)(struct malidp_hw_device *hwdev);
  124. /*
  125. * Query if hardware is in configuration mode
  126. */
  127. bool (*in_config_mode)(struct malidp_hw_device *hwdev);
  128. /*
  129. * Set configuration valid flag for hardware parameters that can
  130. * be changed outside the configuration mode. Hardware will use
  131. * the new settings when config valid is set after the end of the
  132. * current buffer scanout
  133. */
  134. void (*set_config_valid)(struct malidp_hw_device *hwdev);
  135. /*
  136. * Set a new mode in hardware. Requires the hardware to be in
  137. * configuration mode before this function is called.
  138. */
  139. void (*modeset)(struct malidp_hw_device *hwdev, struct videomode *m);
  140. /*
  141. * Calculate the required rotation memory given the active area
  142. * and the buffer format.
  143. */
  144. int (*rotmem_required)(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt);
  145. int (*se_set_scaling_coeffs)(struct malidp_hw_device *hwdev,
  146. struct malidp_se_config *se_config,
  147. struct malidp_se_config *old_config);
  148. long (*se_calc_mclk)(struct malidp_hw_device *hwdev,
  149. struct malidp_se_config *se_config,
  150. struct videomode *vm);
  151. u8 features;
  152. u8 min_line_size;
  153. u16 max_line_size;
  154. /* track the device PM state */
  155. bool pm_suspended;
  156. /* size of memory used for rotating layers, up to two banks available */
  157. u32 rotation_memory[2];
  158. };
  159. /* Supported variants of the hardware */
  160. enum {
  161. MALIDP_500 = 0,
  162. MALIDP_550,
  163. MALIDP_650,
  164. /* keep the next entry last */
  165. MALIDP_MAX_DEVICES
  166. };
  167. extern const struct malidp_hw_device malidp_device[MALIDP_MAX_DEVICES];
  168. static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
  169. {
  170. WARN_ON(hwdev->pm_suspended);
  171. return readl(hwdev->regs + reg);
  172. }
  173. static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
  174. u32 value, u32 reg)
  175. {
  176. WARN_ON(hwdev->pm_suspended);
  177. writel(value, hwdev->regs + reg);
  178. }
  179. static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
  180. u32 mask, u32 reg)
  181. {
  182. u32 data = malidp_hw_read(hwdev, reg);
  183. data |= mask;
  184. malidp_hw_write(hwdev, data, reg);
  185. }
  186. static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
  187. u32 mask, u32 reg)
  188. {
  189. u32 data = malidp_hw_read(hwdev, reg);
  190. data &= ~mask;
  191. malidp_hw_write(hwdev, data, reg);
  192. }
  193. static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
  194. u8 block)
  195. {
  196. switch (block) {
  197. case MALIDP_SE_BLOCK:
  198. return hwdev->map.se_base;
  199. case MALIDP_DC_BLOCK:
  200. return hwdev->map.dc_base;
  201. }
  202. return 0;
  203. }
  204. static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
  205. u8 block, u32 irq)
  206. {
  207. u32 base = malidp_get_block_base(hwdev, block);
  208. malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  209. }
  210. static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
  211. u8 block, u32 irq)
  212. {
  213. u32 base = malidp_get_block_base(hwdev, block);
  214. malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  215. }
  216. int malidp_de_irq_init(struct drm_device *drm, int irq);
  217. void malidp_de_irq_fini(struct drm_device *drm);
  218. int malidp_se_irq_init(struct drm_device *drm, int irq);
  219. void malidp_se_irq_fini(struct drm_device *drm);
  220. u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
  221. u8 layer_id, u32 format);
  222. static inline bool malidp_hw_pitch_valid(struct malidp_hw_device *hwdev,
  223. unsigned int pitch)
  224. {
  225. return !(pitch & (hwdev->map.bus_align_bytes - 1));
  226. }
  227. /* U16.16 */
  228. #define FP_1_00000 0x00010000 /* 1.0 */
  229. #define FP_0_66667 0x0000AAAA /* 0.6667 = 1/1.5 */
  230. #define FP_0_50000 0x00008000 /* 0.5 = 1/2 */
  231. #define FP_0_36363 0x00005D17 /* 0.36363 = 1/2.75 */
  232. #define FP_0_25000 0x00004000 /* 0.25 = 1/4 */
  233. static inline enum malidp_scaling_coeff_set
  234. malidp_se_select_coeffs(u32 upscale_factor)
  235. {
  236. return (upscale_factor >= FP_1_00000) ? MALIDP_UPSCALING_COEFFS :
  237. (upscale_factor >= FP_0_66667) ? MALIDP_DOWNSCALING_1_5_COEFFS :
  238. (upscale_factor >= FP_0_50000) ? MALIDP_DOWNSCALING_2_COEFFS :
  239. (upscale_factor >= FP_0_36363) ? MALIDP_DOWNSCALING_2_75_COEFFS :
  240. MALIDP_DOWNSCALING_4_COEFFS;
  241. }
  242. #undef FP_0_25000
  243. #undef FP_0_36363
  244. #undef FP_0_50000
  245. #undef FP_0_66667
  246. #undef FP_1_00000
  247. static inline void malidp_se_set_enh_coeffs(struct malidp_hw_device *hwdev)
  248. {
  249. static const s32 enhancer_coeffs[] = {
  250. -8, -8, -8, -8, 128, -8, -8, -8, -8
  251. };
  252. u32 val = MALIDP_SE_SET_ENH_LIMIT_LOW(MALIDP_SE_ENH_LOW_LEVEL) |
  253. MALIDP_SE_SET_ENH_LIMIT_HIGH(MALIDP_SE_ENH_HIGH_LEVEL);
  254. u32 image_enh = hwdev->map.se_base +
  255. ((hwdev->map.features & MALIDP_REGMAP_HAS_CLEARIRQ) ?
  256. 0x10 : 0xC) + MALIDP_SE_IMAGE_ENH;
  257. u32 enh_coeffs = image_enh + MALIDP_SE_ENH_COEFF0;
  258. int i;
  259. malidp_hw_write(hwdev, val, image_enh);
  260. for (i = 0; i < ARRAY_SIZE(enhancer_coeffs); ++i)
  261. malidp_hw_write(hwdev, enhancer_coeffs[i], enh_coeffs + i * 4);
  262. }
  263. /*
  264. * background color components are defined as 12bits values,
  265. * they will be shifted right when stored on hardware that
  266. * supports only 8bits per channel
  267. */
  268. #define MALIDP_BGND_COLOR_R 0x000
  269. #define MALIDP_BGND_COLOR_G 0x000
  270. #define MALIDP_BGND_COLOR_B 0x000
  271. #define MALIDP_COLORADJ_NUM_COEFFS 12
  272. #define MALIDP_COEFFTAB_NUM_COEFFS 64
  273. #define MALIDP_GAMMA_LUT_SIZE 4096
  274. #endif /* __MALIDP_HW_H__ */