malidp_hw.h 6.0 KB

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