malidp_hw.h 5.8 KB

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