malidp_hw.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. /* regmap features */
  54. #define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
  55. struct malidp_hw_regmap {
  56. /* address offset of the DE register bank */
  57. /* is always 0x0000 */
  58. /* address offset of the SE registers bank */
  59. const u16 se_base;
  60. /* address offset of the DC registers bank */
  61. const u16 dc_base;
  62. /* address offset for the output depth register */
  63. const u16 out_depth_base;
  64. /* bitmap with register map features */
  65. const u8 features;
  66. /* list of supported layers */
  67. const u8 n_layers;
  68. const struct malidp_layer *layers;
  69. const struct malidp_irq_map de_irq_map;
  70. const struct malidp_irq_map se_irq_map;
  71. const struct malidp_irq_map dc_irq_map;
  72. /* list of supported pixel formats for each layer */
  73. const struct malidp_format_id *pixel_formats;
  74. const u8 n_pixel_formats;
  75. /* pitch alignment requirement in bytes */
  76. const u8 bus_align_bytes;
  77. };
  78. /* device features */
  79. /* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
  80. #define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
  81. struct malidp_hw_device {
  82. const struct malidp_hw_regmap map;
  83. void __iomem *regs;
  84. /* APB clock */
  85. struct clk *pclk;
  86. /* AXI clock */
  87. struct clk *aclk;
  88. /* main clock for display core */
  89. struct clk *mclk;
  90. /* pixel clock for display core */
  91. struct clk *pxlclk;
  92. /*
  93. * Validate the driver instance against the hardware bits
  94. */
  95. int (*query_hw)(struct malidp_hw_device *hwdev);
  96. /*
  97. * Set the hardware into config mode, ready to accept mode changes
  98. */
  99. void (*enter_config_mode)(struct malidp_hw_device *hwdev);
  100. /*
  101. * Tell hardware to exit configuration mode
  102. */
  103. void (*leave_config_mode)(struct malidp_hw_device *hwdev);
  104. /*
  105. * Query if hardware is in configuration mode
  106. */
  107. bool (*in_config_mode)(struct malidp_hw_device *hwdev);
  108. /*
  109. * Set configuration valid flag for hardware parameters that can
  110. * be changed outside the configuration mode. Hardware will use
  111. * the new settings when config valid is set after the end of the
  112. * current buffer scanout
  113. */
  114. void (*set_config_valid)(struct malidp_hw_device *hwdev);
  115. /*
  116. * Set a new mode in hardware. Requires the hardware to be in
  117. * configuration mode before this function is called.
  118. */
  119. void (*modeset)(struct malidp_hw_device *hwdev, struct videomode *m);
  120. /*
  121. * Calculate the required rotation memory given the active area
  122. * and the buffer format.
  123. */
  124. int (*rotmem_required)(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt);
  125. u8 features;
  126. u8 min_line_size;
  127. u16 max_line_size;
  128. /* size of memory used for rotating layers, up to two banks available */
  129. u32 rotation_memory[2];
  130. };
  131. /* Supported variants of the hardware */
  132. enum {
  133. MALIDP_500 = 0,
  134. MALIDP_550,
  135. MALIDP_650,
  136. /* keep the next entry last */
  137. MALIDP_MAX_DEVICES
  138. };
  139. extern const struct malidp_hw_device malidp_device[MALIDP_MAX_DEVICES];
  140. static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
  141. {
  142. return readl(hwdev->regs + reg);
  143. }
  144. static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
  145. u32 value, u32 reg)
  146. {
  147. writel(value, hwdev->regs + reg);
  148. }
  149. static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
  150. u32 mask, u32 reg)
  151. {
  152. u32 data = malidp_hw_read(hwdev, reg);
  153. data |= mask;
  154. malidp_hw_write(hwdev, data, reg);
  155. }
  156. static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
  157. u32 mask, u32 reg)
  158. {
  159. u32 data = malidp_hw_read(hwdev, reg);
  160. data &= ~mask;
  161. malidp_hw_write(hwdev, data, reg);
  162. }
  163. static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
  164. u8 block)
  165. {
  166. switch (block) {
  167. case MALIDP_SE_BLOCK:
  168. return hwdev->map.se_base;
  169. case MALIDP_DC_BLOCK:
  170. return hwdev->map.dc_base;
  171. }
  172. return 0;
  173. }
  174. static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
  175. u8 block, u32 irq)
  176. {
  177. u32 base = malidp_get_block_base(hwdev, block);
  178. malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  179. }
  180. static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
  181. u8 block, u32 irq)
  182. {
  183. u32 base = malidp_get_block_base(hwdev, block);
  184. malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
  185. }
  186. int malidp_de_irq_init(struct drm_device *drm, int irq);
  187. void malidp_de_irq_fini(struct drm_device *drm);
  188. int malidp_se_irq_init(struct drm_device *drm, int irq);
  189. void malidp_se_irq_fini(struct drm_device *drm);
  190. u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
  191. u8 layer_id, u32 format);
  192. static inline bool malidp_hw_pitch_valid(struct malidp_hw_device *hwdev,
  193. unsigned int pitch)
  194. {
  195. return !(pitch & (hwdev->map.bus_align_bytes - 1));
  196. }
  197. /*
  198. * background color components are defined as 12bits values,
  199. * they will be shifted right when stored on hardware that
  200. * supports only 8bits per channel
  201. */
  202. #define MALIDP_BGND_COLOR_R 0x000
  203. #define MALIDP_BGND_COLOR_G 0x000
  204. #define MALIDP_BGND_COLOR_B 0x000
  205. #endif /* __MALIDP_HW_H__ */