malidp_hw.h 11 KB

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