malidp_hw.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. SE_MEMWRITE = BIT(5),
  32. };
  33. struct malidp_format_id {
  34. u32 format; /* DRM fourcc */
  35. u8 layer; /* bitmask of layers supporting it */
  36. u8 id; /* used internally */
  37. };
  38. #define MALIDP_INVALID_FORMAT_ID 0xff
  39. /*
  40. * hide the differences between register maps
  41. * by using a common structure to hold the
  42. * base register offsets
  43. */
  44. struct malidp_irq_map {
  45. u32 irq_mask; /* mask of IRQs that can be enabled in the block */
  46. u32 vsync_irq; /* IRQ bit used for signaling during VSYNC */
  47. u32 err_mask; /* mask of bits that represent errors */
  48. };
  49. struct malidp_layer {
  50. u16 id; /* layer ID */
  51. u16 base; /* address offset for the register bank */
  52. u16 ptr; /* address offset for the pointer register */
  53. u16 stride_offset; /* offset to the first stride register. */
  54. s16 yuv2rgb_offset; /* offset to the YUV->RGB matrix entries */
  55. };
  56. enum malidp_scaling_coeff_set {
  57. MALIDP_UPSCALING_COEFFS = 1,
  58. MALIDP_DOWNSCALING_1_5_COEFFS = 2,
  59. MALIDP_DOWNSCALING_2_COEFFS = 3,
  60. MALIDP_DOWNSCALING_2_75_COEFFS = 4,
  61. MALIDP_DOWNSCALING_4_COEFFS = 5,
  62. };
  63. struct malidp_se_config {
  64. u8 scale_enable : 1;
  65. u8 enhancer_enable : 1;
  66. u8 hcoeff : 3;
  67. u8 vcoeff : 3;
  68. u8 plane_src_id;
  69. u16 input_w, input_h;
  70. u16 output_w, output_h;
  71. u32 h_init_phase, h_delta_phase;
  72. u32 v_init_phase, v_delta_phase;
  73. };
  74. /* regmap features */
  75. #define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
  76. struct malidp_hw_regmap {
  77. /* address offset of the DE register bank */
  78. /* is always 0x0000 */
  79. /* address offset of the DE coefficients registers */
  80. const u16 coeffs_base;
  81. /* address offset of the SE registers bank */
  82. const u16 se_base;
  83. /* address offset of the DC registers bank */
  84. const u16 dc_base;
  85. /* address offset for the output depth register */
  86. const u16 out_depth_base;
  87. /* bitmap with register map features */
  88. const u8 features;
  89. /* list of supported layers */
  90. const u8 n_layers;
  91. const struct malidp_layer *layers;
  92. const struct malidp_irq_map de_irq_map;
  93. const struct malidp_irq_map se_irq_map;
  94. const struct malidp_irq_map dc_irq_map;
  95. /* list of supported pixel formats for each layer */
  96. const struct malidp_format_id *pixel_formats;
  97. const u8 n_pixel_formats;
  98. /* pitch alignment requirement in bytes */
  99. const u8 bus_align_bytes;
  100. };
  101. /* device features */
  102. /* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
  103. #define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
  104. struct malidp_hw_device;
  105. /*
  106. * Static structure containing hardware specific data and pointers to
  107. * functions that behave differently between various versions of the IP.
  108. */
  109. struct malidp_hw {
  110. const struct malidp_hw_regmap map;
  111. /*
  112. * Validate the driver instance against the hardware bits
  113. */
  114. int (*query_hw)(struct malidp_hw_device *hwdev);
  115. /*
  116. * Set the hardware into config mode, ready to accept mode changes
  117. */
  118. void (*enter_config_mode)(struct malidp_hw_device *hwdev);
  119. /*
  120. * Tell hardware to exit configuration mode
  121. */
  122. void (*leave_config_mode)(struct malidp_hw_device *hwdev);
  123. /*
  124. * Query if hardware is in configuration mode
  125. */
  126. bool (*in_config_mode)(struct malidp_hw_device *hwdev);
  127. /*
  128. * Set/clear configuration valid flag for hardware parameters that can
  129. * be changed outside the configuration mode to the given value.
  130. * Hardware will use the new settings when config valid is set,
  131. * after the end of the current buffer scanout, and will ignore
  132. * any new values for those parameters if config valid flag is cleared
  133. */
  134. void (*set_config_valid)(struct malidp_hw_device *hwdev, u8 value);
  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. /*
  152. * Enable writing to memory the content of the next frame
  153. * @param hwdev - malidp_hw_device structure containing the HW description
  154. * @param addrs - array of addresses for each plane
  155. * @param pitches - array of pitches for each plane
  156. * @param num_planes - number of planes to be written
  157. * @param w - width of the output frame
  158. * @param h - height of the output frame
  159. * @param fmt_id - internal format ID of output buffer
  160. */
  161. int (*enable_memwrite)(struct malidp_hw_device *hwdev, dma_addr_t *addrs,
  162. s32 *pitches, int num_planes, u16 w, u16 h, u32 fmt_id,
  163. const s16 *rgb2yuv_coeffs);
  164. /*
  165. * Disable the writing to memory of the next frame's content.
  166. */
  167. void (*disable_memwrite)(struct malidp_hw_device *hwdev);
  168. u8 features;
  169. };
  170. /* Supported variants of the hardware */
  171. enum {
  172. MALIDP_500 = 0,
  173. MALIDP_550,
  174. MALIDP_650,
  175. /* keep the next entry last */
  176. MALIDP_MAX_DEVICES
  177. };
  178. extern const struct malidp_hw malidp_device[MALIDP_MAX_DEVICES];
  179. /*
  180. * Structure used by the driver during runtime operation.
  181. */
  182. struct malidp_hw_device {
  183. struct malidp_hw *hw;
  184. void __iomem *regs;
  185. /* APB clock */
  186. struct clk *pclk;
  187. /* AXI clock */
  188. struct clk *aclk;
  189. /* main clock for display core */
  190. struct clk *mclk;
  191. /* pixel clock for display core */
  192. struct clk *pxlclk;
  193. u8 min_line_size;
  194. u16 max_line_size;
  195. u32 output_color_depth;
  196. /* track the device PM state */
  197. bool pm_suspended;
  198. /* track the SE memory writeback state */
  199. u8 mw_state;
  200. /* size of memory used for rotating layers, up to two banks available */
  201. u32 rotation_memory[2];
  202. };
  203. static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
  204. {
  205. WARN_ON(hwdev->pm_suspended);
  206. return readl(hwdev->regs + reg);
  207. }
  208. static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
  209. u32 value, u32 reg)
  210. {
  211. WARN_ON(hwdev->pm_suspended);
  212. writel(value, hwdev->regs + reg);
  213. }
  214. static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
  215. u32 mask, u32 reg)
  216. {
  217. u32 data = malidp_hw_read(hwdev, reg);
  218. data |= mask;
  219. malidp_hw_write(hwdev, data, reg);
  220. }
  221. static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
  222. u32 mask, u32 reg)
  223. {
  224. u32 data = malidp_hw_read(hwdev, reg);
  225. data &= ~mask;
  226. malidp_hw_write(hwdev, data, reg);
  227. }
  228. static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
  229. u8 block)
  230. {
  231. switch (block) {
  232. case MALIDP_SE_BLOCK:
  233. return hwdev->hw->map.se_base;
  234. case MALIDP_DC_BLOCK:
  235. return hwdev->hw->map.dc_base;
  236. }
  237. return 0;
  238. }
  239. static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
  240. u8 block, u32 irq)
  241. {
  242. u32 base = malidp_get_block_base(hwdev, block);
  243. malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  244. }
  245. static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
  246. u8 block, u32 irq)
  247. {
  248. u32 base = malidp_get_block_base(hwdev, block);
  249. malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  250. }
  251. int malidp_de_irq_init(struct drm_device *drm, int irq);
  252. void malidp_se_irq_hw_init(struct malidp_hw_device *hwdev);
  253. void malidp_de_irq_hw_init(struct malidp_hw_device *hwdev);
  254. void malidp_de_irq_fini(struct malidp_hw_device *hwdev);
  255. int malidp_se_irq_init(struct drm_device *drm, int irq);
  256. void malidp_se_irq_fini(struct malidp_hw_device *hwdev);
  257. u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
  258. u8 layer_id, u32 format);
  259. static inline u8 malidp_hw_get_pitch_align(struct malidp_hw_device *hwdev, bool rotated)
  260. {
  261. /*
  262. * only hardware that cannot do 8 bytes bus alignments have further
  263. * constraints on rotated planes
  264. */
  265. if (hwdev->hw->map.bus_align_bytes == 8)
  266. return 8;
  267. else
  268. return hwdev->hw->map.bus_align_bytes << (rotated ? 2 : 0);
  269. }
  270. /* U16.16 */
  271. #define FP_1_00000 0x00010000 /* 1.0 */
  272. #define FP_0_66667 0x0000AAAA /* 0.6667 = 1/1.5 */
  273. #define FP_0_50000 0x00008000 /* 0.5 = 1/2 */
  274. #define FP_0_36363 0x00005D17 /* 0.36363 = 1/2.75 */
  275. #define FP_0_25000 0x00004000 /* 0.25 = 1/4 */
  276. static inline enum malidp_scaling_coeff_set
  277. malidp_se_select_coeffs(u32 upscale_factor)
  278. {
  279. return (upscale_factor >= FP_1_00000) ? MALIDP_UPSCALING_COEFFS :
  280. (upscale_factor >= FP_0_66667) ? MALIDP_DOWNSCALING_1_5_COEFFS :
  281. (upscale_factor >= FP_0_50000) ? MALIDP_DOWNSCALING_2_COEFFS :
  282. (upscale_factor >= FP_0_36363) ? MALIDP_DOWNSCALING_2_75_COEFFS :
  283. MALIDP_DOWNSCALING_4_COEFFS;
  284. }
  285. #undef FP_0_25000
  286. #undef FP_0_36363
  287. #undef FP_0_50000
  288. #undef FP_0_66667
  289. #undef FP_1_00000
  290. static inline void malidp_se_set_enh_coeffs(struct malidp_hw_device *hwdev)
  291. {
  292. static const s32 enhancer_coeffs[] = {
  293. -8, -8, -8, -8, 128, -8, -8, -8, -8
  294. };
  295. u32 val = MALIDP_SE_SET_ENH_LIMIT_LOW(MALIDP_SE_ENH_LOW_LEVEL) |
  296. MALIDP_SE_SET_ENH_LIMIT_HIGH(MALIDP_SE_ENH_HIGH_LEVEL);
  297. u32 image_enh = hwdev->hw->map.se_base +
  298. ((hwdev->hw->map.features & MALIDP_REGMAP_HAS_CLEARIRQ) ?
  299. 0x10 : 0xC) + MALIDP_SE_IMAGE_ENH;
  300. u32 enh_coeffs = image_enh + MALIDP_SE_ENH_COEFF0;
  301. int i;
  302. malidp_hw_write(hwdev, val, image_enh);
  303. for (i = 0; i < ARRAY_SIZE(enhancer_coeffs); ++i)
  304. malidp_hw_write(hwdev, enhancer_coeffs[i], enh_coeffs + i * 4);
  305. }
  306. /*
  307. * background color components are defined as 12bits values,
  308. * they will be shifted right when stored on hardware that
  309. * supports only 8bits per channel
  310. */
  311. #define MALIDP_BGND_COLOR_R 0x000
  312. #define MALIDP_BGND_COLOR_G 0x000
  313. #define MALIDP_BGND_COLOR_B 0x000
  314. #define MALIDP_COLORADJ_NUM_COEFFS 12
  315. #define MALIDP_COEFFTAB_NUM_COEFFS 64
  316. #define MALIDP_GAMMA_LUT_SIZE 4096
  317. #endif /* __MALIDP_HW_H__ */