Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) STMicroelectronics SA 2014 |
| 3 | * Authors: Benjamin Gaignard <benjamin.gaignard@st.com> |
| 4 | * Vincent Abriou <vincent.abriou@st.com> |
| 5 | * for STMicroelectronics. |
| 6 | * License terms: GNU General Public License (GPL), version 2 |
| 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| 10 | #include <linux/component.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/of_platform.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/reset.h> |
| 15 | |
| 16 | #include <drm/drmP.h> |
| 17 | #include <drm/drm_crtc_helper.h> |
| 18 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 19 | #include "sti_crtc.h" |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 20 | #include "sti_vtg.h" |
Benjamin Gaignard | 5e03abc | 2014-12-08 17:32:36 +0100 | [diff] [blame] | 21 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 22 | /* glue registers */ |
| 23 | #define TVO_CSC_MAIN_M0 0x000 |
| 24 | #define TVO_CSC_MAIN_M1 0x004 |
| 25 | #define TVO_CSC_MAIN_M2 0x008 |
| 26 | #define TVO_CSC_MAIN_M3 0x00c |
| 27 | #define TVO_CSC_MAIN_M4 0x010 |
| 28 | #define TVO_CSC_MAIN_M5 0x014 |
| 29 | #define TVO_CSC_MAIN_M6 0x018 |
| 30 | #define TVO_CSC_MAIN_M7 0x01c |
| 31 | #define TVO_MAIN_IN_VID_FORMAT 0x030 |
| 32 | #define TVO_CSC_AUX_M0 0x100 |
| 33 | #define TVO_CSC_AUX_M1 0x104 |
| 34 | #define TVO_CSC_AUX_M2 0x108 |
| 35 | #define TVO_CSC_AUX_M3 0x10c |
| 36 | #define TVO_CSC_AUX_M4 0x110 |
| 37 | #define TVO_CSC_AUX_M5 0x114 |
| 38 | #define TVO_CSC_AUX_M6 0x118 |
| 39 | #define TVO_CSC_AUX_M7 0x11c |
| 40 | #define TVO_AUX_IN_VID_FORMAT 0x130 |
| 41 | #define TVO_VIP_HDF 0x400 |
| 42 | #define TVO_HD_SYNC_SEL 0x418 |
| 43 | #define TVO_HD_DAC_CFG_OFF 0x420 |
| 44 | #define TVO_VIP_HDMI 0x500 |
| 45 | #define TVO_HDMI_FORCE_COLOR_0 0x504 |
| 46 | #define TVO_HDMI_FORCE_COLOR_1 0x508 |
| 47 | #define TVO_HDMI_CLIP_VALUE_B_CB 0x50c |
| 48 | #define TVO_HDMI_CLIP_VALUE_Y_G 0x510 |
| 49 | #define TVO_HDMI_CLIP_VALUE_R_CR 0x514 |
| 50 | #define TVO_HDMI_SYNC_SEL 0x518 |
| 51 | #define TVO_HDMI_DFV_OBS 0x540 |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 52 | #define TVO_VIP_DVO 0x600 |
| 53 | #define TVO_DVO_SYNC_SEL 0x618 |
| 54 | #define TVO_DVO_CONFIG 0x620 |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 55 | |
| 56 | #define TVO_IN_FMT_SIGNED BIT(0) |
| 57 | #define TVO_SYNC_EXT BIT(4) |
| 58 | |
| 59 | #define TVO_VIP_REORDER_R_SHIFT 24 |
| 60 | #define TVO_VIP_REORDER_G_SHIFT 20 |
| 61 | #define TVO_VIP_REORDER_B_SHIFT 16 |
| 62 | #define TVO_VIP_REORDER_MASK 0x3 |
| 63 | #define TVO_VIP_REORDER_Y_G_SEL 0 |
| 64 | #define TVO_VIP_REORDER_CB_B_SEL 1 |
| 65 | #define TVO_VIP_REORDER_CR_R_SEL 2 |
| 66 | |
| 67 | #define TVO_VIP_CLIP_SHIFT 8 |
| 68 | #define TVO_VIP_CLIP_MASK 0x7 |
| 69 | #define TVO_VIP_CLIP_DISABLED 0 |
| 70 | #define TVO_VIP_CLIP_EAV_SAV 1 |
| 71 | #define TVO_VIP_CLIP_LIMITED_RANGE_RGB_Y 2 |
| 72 | #define TVO_VIP_CLIP_LIMITED_RANGE_CB_CR 3 |
| 73 | #define TVO_VIP_CLIP_PROG_RANGE 4 |
| 74 | |
| 75 | #define TVO_VIP_RND_SHIFT 4 |
| 76 | #define TVO_VIP_RND_MASK 0x3 |
| 77 | #define TVO_VIP_RND_8BIT_ROUNDED 0 |
| 78 | #define TVO_VIP_RND_10BIT_ROUNDED 1 |
| 79 | #define TVO_VIP_RND_12BIT_ROUNDED 2 |
| 80 | |
| 81 | #define TVO_VIP_SEL_INPUT_MASK 0xf |
| 82 | #define TVO_VIP_SEL_INPUT_MAIN 0x0 |
| 83 | #define TVO_VIP_SEL_INPUT_AUX 0x8 |
| 84 | #define TVO_VIP_SEL_INPUT_FORCE_COLOR 0xf |
| 85 | #define TVO_VIP_SEL_INPUT_BYPASS_MASK 0x1 |
| 86 | #define TVO_VIP_SEL_INPUT_BYPASSED 1 |
| 87 | |
| 88 | #define TVO_SYNC_MAIN_VTG_SET_REF 0x00 |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 89 | #define TVO_SYNC_AUX_VTG_SET_REF 0x10 |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 90 | |
| 91 | #define TVO_SYNC_HD_DCS_SHIFT 8 |
| 92 | |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 93 | #define TVO_SYNC_DVO_PAD_HSYNC_SHIFT 8 |
| 94 | #define TVO_SYNC_DVO_PAD_VSYNC_SHIFT 16 |
| 95 | |
Benjamin Gaignard | 5e03abc | 2014-12-08 17:32:36 +0100 | [diff] [blame] | 96 | #define ENCODER_CRTC_MASK (BIT(0) | BIT(1)) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 97 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 98 | #define TVO_MIN_HD_HEIGHT 720 |
| 99 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 100 | /* enum listing the supported output data format */ |
| 101 | enum sti_tvout_video_out_type { |
| 102 | STI_TVOUT_VIDEO_OUT_RGB, |
| 103 | STI_TVOUT_VIDEO_OUT_YUV, |
| 104 | }; |
| 105 | |
| 106 | struct sti_tvout { |
| 107 | struct device *dev; |
| 108 | struct drm_device *drm_dev; |
| 109 | void __iomem *regs; |
| 110 | struct reset_control *reset; |
| 111 | struct drm_encoder *hdmi; |
| 112 | struct drm_encoder *hda; |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 113 | struct drm_encoder *dvo; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | struct sti_tvout_encoder { |
| 117 | struct drm_encoder encoder; |
| 118 | struct sti_tvout *tvout; |
| 119 | }; |
| 120 | |
| 121 | #define to_sti_tvout_encoder(x) \ |
| 122 | container_of(x, struct sti_tvout_encoder, encoder) |
| 123 | |
| 124 | #define to_sti_tvout(x) to_sti_tvout_encoder(x)->tvout |
| 125 | |
| 126 | /* preformatter conversion matrix */ |
| 127 | static const u32 rgb_to_ycbcr_601[8] = { |
| 128 | 0xF927082E, 0x04C9FEAB, 0x01D30964, 0xFA95FD3D, |
| 129 | 0x0000082E, 0x00002000, 0x00002000, 0x00000000 |
| 130 | }; |
| 131 | |
| 132 | /* 709 RGB to YCbCr */ |
| 133 | static const u32 rgb_to_ycbcr_709[8] = { |
| 134 | 0xF891082F, 0x0367FF40, 0x01280B71, 0xF9B1FE20, |
| 135 | 0x0000082F, 0x00002000, 0x00002000, 0x00000000 |
| 136 | }; |
| 137 | |
| 138 | static u32 tvout_read(struct sti_tvout *tvout, int offset) |
| 139 | { |
| 140 | return readl(tvout->regs + offset); |
| 141 | } |
| 142 | |
| 143 | static void tvout_write(struct sti_tvout *tvout, u32 val, int offset) |
| 144 | { |
| 145 | writel(val, tvout->regs + offset); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Set the clipping mode of a VIP |
| 150 | * |
| 151 | * @tvout: tvout structure |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 152 | * @reg: register to set |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 153 | * @cr_r: |
| 154 | * @y_g: |
| 155 | * @cb_b: |
| 156 | */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 157 | static void tvout_vip_set_color_order(struct sti_tvout *tvout, int reg, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 158 | u32 cr_r, u32 y_g, u32 cb_b) |
| 159 | { |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 160 | u32 val = tvout_read(tvout, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 161 | |
| 162 | val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT); |
| 163 | val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT); |
| 164 | val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT); |
| 165 | val |= cr_r << TVO_VIP_REORDER_R_SHIFT; |
| 166 | val |= y_g << TVO_VIP_REORDER_G_SHIFT; |
| 167 | val |= cb_b << TVO_VIP_REORDER_B_SHIFT; |
| 168 | |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 169 | tvout_write(tvout, val, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Set the clipping mode of a VIP |
| 174 | * |
| 175 | * @tvout: tvout structure |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 176 | * @reg: register to set |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 177 | * @range: clipping range |
| 178 | */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 179 | static void tvout_vip_set_clip_mode(struct sti_tvout *tvout, int reg, u32 range) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 180 | { |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 181 | u32 val = tvout_read(tvout, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 182 | |
| 183 | val &= ~(TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT); |
| 184 | val |= range << TVO_VIP_CLIP_SHIFT; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 185 | tvout_write(tvout, val, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Set the rounded value of a VIP |
| 190 | * |
| 191 | * @tvout: tvout structure |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 192 | * @reg: register to set |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 193 | * @rnd: rounded val per component |
| 194 | */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 195 | static void tvout_vip_set_rnd(struct sti_tvout *tvout, int reg, u32 rnd) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 196 | { |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 197 | u32 val = tvout_read(tvout, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 198 | |
| 199 | val &= ~(TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT); |
| 200 | val |= rnd << TVO_VIP_RND_SHIFT; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 201 | tvout_write(tvout, val, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Select the VIP input |
| 206 | * |
| 207 | * @tvout: tvout structure |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 208 | * @reg: register to set |
| 209 | * @main_path: main or auxiliary path |
| 210 | * @sel_input_logic_inverted: need to invert the logic |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 211 | * @sel_input: selected_input (main/aux + conv) |
| 212 | */ |
| 213 | static void tvout_vip_set_sel_input(struct sti_tvout *tvout, |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 214 | int reg, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 215 | bool main_path, |
| 216 | bool sel_input_logic_inverted, |
| 217 | enum sti_tvout_video_out_type video_out) |
| 218 | { |
| 219 | u32 sel_input; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 220 | u32 val = tvout_read(tvout, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 221 | |
| 222 | if (main_path) |
| 223 | sel_input = TVO_VIP_SEL_INPUT_MAIN; |
| 224 | else |
| 225 | sel_input = TVO_VIP_SEL_INPUT_AUX; |
| 226 | |
| 227 | switch (video_out) { |
| 228 | case STI_TVOUT_VIDEO_OUT_RGB: |
| 229 | sel_input |= TVO_VIP_SEL_INPUT_BYPASSED; |
| 230 | break; |
| 231 | case STI_TVOUT_VIDEO_OUT_YUV: |
| 232 | sel_input &= ~TVO_VIP_SEL_INPUT_BYPASSED; |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | /* on stih407 chip the sel_input bypass mode logic is inverted */ |
| 237 | if (sel_input_logic_inverted) |
| 238 | sel_input = sel_input ^ TVO_VIP_SEL_INPUT_BYPASS_MASK; |
| 239 | |
| 240 | val &= ~TVO_VIP_SEL_INPUT_MASK; |
| 241 | val |= sel_input; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 242 | tvout_write(tvout, val, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Select the input video signed or unsigned |
| 247 | * |
| 248 | * @tvout: tvout structure |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 249 | * @reg: register to set |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 250 | * @in_vid_signed: used video input format |
| 251 | */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 252 | static void tvout_vip_set_in_vid_fmt(struct sti_tvout *tvout, |
| 253 | int reg, u32 in_vid_fmt) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 254 | { |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 255 | u32 val = tvout_read(tvout, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 256 | |
| 257 | val &= ~TVO_IN_FMT_SIGNED; |
| 258 | val |= in_vid_fmt; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 259 | tvout_write(tvout, val, reg); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 263 | * Set preformatter matrix |
| 264 | * |
| 265 | * @tvout: tvout structure |
| 266 | * @mode: display mode structure |
| 267 | */ |
| 268 | static void tvout_preformatter_set_matrix(struct sti_tvout *tvout, |
| 269 | struct drm_display_mode *mode) |
| 270 | { |
| 271 | unsigned int i; |
| 272 | const u32 *pf_matrix; |
| 273 | |
| 274 | if (mode->vdisplay >= TVO_MIN_HD_HEIGHT) |
| 275 | pf_matrix = rgb_to_ycbcr_709; |
| 276 | else |
| 277 | pf_matrix = rgb_to_ycbcr_601; |
| 278 | |
| 279 | for (i = 0; i < 8; i++) { |
| 280 | tvout_write(tvout, *(pf_matrix + i), |
| 281 | TVO_CSC_MAIN_M0 + (i * 4)); |
| 282 | tvout_write(tvout, *(pf_matrix + i), |
| 283 | TVO_CSC_AUX_M0 + (i * 4)); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 288 | * Start VIP block for DVO output |
| 289 | * |
| 290 | * @tvout: pointer on tvout structure |
| 291 | * @main_path: true if main path has to be used in the vip configuration |
| 292 | * else aux path is used. |
| 293 | */ |
| 294 | static void tvout_dvo_start(struct sti_tvout *tvout, bool main_path) |
| 295 | { |
| 296 | struct device_node *node = tvout->dev->of_node; |
| 297 | bool sel_input_logic_inverted = false; |
| 298 | u32 tvo_in_vid_format; |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 299 | int val, tmp; |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 300 | |
| 301 | dev_dbg(tvout->dev, "%s\n", __func__); |
| 302 | |
| 303 | if (main_path) { |
| 304 | DRM_DEBUG_DRIVER("main vip for DVO\n"); |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 305 | /* Select the input sync for dvo */ |
| 306 | tmp = TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_DVO; |
| 307 | val = tmp << TVO_SYNC_DVO_PAD_VSYNC_SHIFT; |
| 308 | val |= tmp << TVO_SYNC_DVO_PAD_HSYNC_SHIFT; |
| 309 | val |= tmp; |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 310 | tvout_write(tvout, val, TVO_DVO_SYNC_SEL); |
| 311 | tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT; |
| 312 | } else { |
| 313 | DRM_DEBUG_DRIVER("aux vip for DVO\n"); |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 314 | /* Select the input sync for dvo */ |
| 315 | tmp = TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_DVO; |
| 316 | val = tmp << TVO_SYNC_DVO_PAD_VSYNC_SHIFT; |
| 317 | val |= tmp << TVO_SYNC_DVO_PAD_HSYNC_SHIFT; |
| 318 | val |= tmp; |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 319 | tvout_write(tvout, val, TVO_DVO_SYNC_SEL); |
| 320 | tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT; |
| 321 | } |
| 322 | |
| 323 | /* Set color channel order */ |
| 324 | tvout_vip_set_color_order(tvout, TVO_VIP_DVO, |
| 325 | TVO_VIP_REORDER_CR_R_SEL, |
| 326 | TVO_VIP_REORDER_Y_G_SEL, |
| 327 | TVO_VIP_REORDER_CB_B_SEL); |
| 328 | |
Vincent Abriou | 1834b84 | 2016-02-01 17:51:33 +0100 | [diff] [blame] | 329 | /* Set clipping mode */ |
| 330 | tvout_vip_set_clip_mode(tvout, TVO_VIP_DVO, TVO_VIP_CLIP_DISABLED); |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 331 | |
| 332 | /* Set round mode (rounded to 8-bit per component) */ |
| 333 | tvout_vip_set_rnd(tvout, TVO_VIP_DVO, TVO_VIP_RND_8BIT_ROUNDED); |
| 334 | |
| 335 | if (of_device_is_compatible(node, "st,stih407-tvout")) { |
| 336 | /* Set input video format */ |
| 337 | tvout_vip_set_in_vid_fmt(tvout, tvo_in_vid_format, |
| 338 | TVO_IN_FMT_SIGNED); |
| 339 | sel_input_logic_inverted = true; |
| 340 | } |
| 341 | |
| 342 | /* Input selection */ |
| 343 | tvout_vip_set_sel_input(tvout, TVO_VIP_DVO, main_path, |
| 344 | sel_input_logic_inverted, |
| 345 | STI_TVOUT_VIDEO_OUT_RGB); |
| 346 | } |
| 347 | |
| 348 | /** |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 349 | * Start VIP block for HDMI output |
| 350 | * |
| 351 | * @tvout: pointer on tvout structure |
| 352 | * @main_path: true if main path has to be used in the vip configuration |
| 353 | * else aux path is used. |
| 354 | */ |
| 355 | static void tvout_hdmi_start(struct sti_tvout *tvout, bool main_path) |
| 356 | { |
| 357 | struct device_node *node = tvout->dev->of_node; |
| 358 | bool sel_input_logic_inverted = false; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 359 | u32 tvo_in_vid_format; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 360 | |
| 361 | dev_dbg(tvout->dev, "%s\n", __func__); |
| 362 | |
| 363 | if (main_path) { |
| 364 | DRM_DEBUG_DRIVER("main vip for hdmi\n"); |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 365 | /* select the input sync for hdmi */ |
| 366 | tvout_write(tvout, |
| 367 | TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDMI, |
| 368 | TVO_HDMI_SYNC_SEL); |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 369 | tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 370 | } else { |
| 371 | DRM_DEBUG_DRIVER("aux vip for hdmi\n"); |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 372 | /* select the input sync for hdmi */ |
| 373 | tvout_write(tvout, |
| 374 | TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDMI, |
| 375 | TVO_HDMI_SYNC_SEL); |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 376 | tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* set color channel order */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 380 | tvout_vip_set_color_order(tvout, TVO_VIP_HDMI, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 381 | TVO_VIP_REORDER_CR_R_SEL, |
| 382 | TVO_VIP_REORDER_Y_G_SEL, |
| 383 | TVO_VIP_REORDER_CB_B_SEL); |
| 384 | |
Vincent Abriou | 1834b84 | 2016-02-01 17:51:33 +0100 | [diff] [blame] | 385 | /* set clipping mode */ |
| 386 | tvout_vip_set_clip_mode(tvout, TVO_VIP_HDMI, TVO_VIP_CLIP_DISABLED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 387 | |
| 388 | /* set round mode (rounded to 8-bit per component) */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 389 | tvout_vip_set_rnd(tvout, TVO_VIP_HDMI, TVO_VIP_RND_8BIT_ROUNDED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 390 | |
| 391 | if (of_device_is_compatible(node, "st,stih407-tvout")) { |
| 392 | /* set input video format */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 393 | tvout_vip_set_in_vid_fmt(tvout, tvo_in_vid_format, |
| 394 | TVO_IN_FMT_SIGNED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 395 | sel_input_logic_inverted = true; |
| 396 | } |
| 397 | |
| 398 | /* input selection */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 399 | tvout_vip_set_sel_input(tvout, TVO_VIP_HDMI, main_path, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 400 | sel_input_logic_inverted, STI_TVOUT_VIDEO_OUT_RGB); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Start HDF VIP and HD DAC |
| 405 | * |
| 406 | * @tvout: pointer on tvout structure |
| 407 | * @main_path: true if main path has to be used in the vip configuration |
| 408 | * else aux path is used. |
| 409 | */ |
| 410 | static void tvout_hda_start(struct sti_tvout *tvout, bool main_path) |
| 411 | { |
| 412 | struct device_node *node = tvout->dev->of_node; |
| 413 | bool sel_input_logic_inverted = false; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 414 | u32 tvo_in_vid_format; |
| 415 | int val; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 416 | |
| 417 | dev_dbg(tvout->dev, "%s\n", __func__); |
| 418 | |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 419 | if (main_path) { |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 420 | DRM_DEBUG_DRIVER("main vip for HDF\n"); |
| 421 | /* Select the input sync for HD analog and HD DCS */ |
| 422 | val = TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDDCS; |
| 423 | val = val << TVO_SYNC_HD_DCS_SHIFT; |
| 424 | val |= TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDF; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 425 | tvout_write(tvout, val, TVO_HD_SYNC_SEL); |
| 426 | tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT; |
| 427 | } else { |
Vincent Abriou | 503290c | 2016-01-28 13:08:48 +0100 | [diff] [blame] | 428 | DRM_DEBUG_DRIVER("aux vip for HDF\n"); |
| 429 | /* Select the input sync for HD analog and HD DCS */ |
| 430 | val = TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDDCS; |
| 431 | val = val << TVO_SYNC_HD_DCS_SHIFT; |
| 432 | val |= TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDF; |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 433 | tvout_write(tvout, val, TVO_HD_SYNC_SEL); |
| 434 | tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 435 | } |
| 436 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 437 | /* set color channel order */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 438 | tvout_vip_set_color_order(tvout, TVO_VIP_HDF, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 439 | TVO_VIP_REORDER_CR_R_SEL, |
| 440 | TVO_VIP_REORDER_Y_G_SEL, |
| 441 | TVO_VIP_REORDER_CB_B_SEL); |
| 442 | |
Vincent Abriou | 1834b84 | 2016-02-01 17:51:33 +0100 | [diff] [blame] | 443 | /* set clipping mode */ |
| 444 | tvout_vip_set_clip_mode(tvout, TVO_VIP_HDF, TVO_VIP_CLIP_DISABLED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 445 | |
| 446 | /* set round mode (rounded to 10-bit per component) */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 447 | tvout_vip_set_rnd(tvout, TVO_VIP_HDF, TVO_VIP_RND_10BIT_ROUNDED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 448 | |
| 449 | if (of_device_is_compatible(node, "st,stih407-tvout")) { |
| 450 | /* set input video format */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 451 | tvout_vip_set_in_vid_fmt(tvout, |
| 452 | tvo_in_vid_format, TVO_IN_FMT_SIGNED); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 453 | sel_input_logic_inverted = true; |
| 454 | } |
| 455 | |
| 456 | /* Input selection */ |
Benjamin Gaignard | ca27960 | 2014-12-04 11:31:37 +0100 | [diff] [blame] | 457 | tvout_vip_set_sel_input(tvout, TVO_VIP_HDF, main_path, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 458 | sel_input_logic_inverted, |
| 459 | STI_TVOUT_VIDEO_OUT_YUV); |
| 460 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 461 | /* power up HD DAC */ |
| 462 | tvout_write(tvout, 0, TVO_HD_DAC_CFG_OFF); |
| 463 | } |
| 464 | |
Vincent Abriou | b514bee | 2016-02-05 11:14:48 +0100 | [diff] [blame] | 465 | #define DBGFS_DUMP(reg) seq_printf(s, "\n %-25s 0x%08X", #reg, \ |
| 466 | readl(tvout->regs + reg)) |
| 467 | |
| 468 | static void tvout_dbg_vip(struct seq_file *s, int val) |
| 469 | { |
| 470 | int r, g, b, tmp, mask; |
| 471 | char *const reorder[] = {"Y_G", "Cb_B", "Cr_R"}; |
| 472 | char *const clipping[] = {"No", "EAV/SAV", "Limited range RGB/Y", |
| 473 | "Limited range Cb/Cr", "decided by register"}; |
| 474 | char *const round[] = {"8-bit", "10-bit", "12-bit"}; |
| 475 | char *const input_sel[] = {"Main (color matrix enabled)", |
| 476 | "Main (color matrix by-passed)", |
| 477 | "", "", "", "", "", "", |
| 478 | "Aux (color matrix enabled)", |
| 479 | "Aux (color matrix by-passed)", |
| 480 | "", "", "", "", "", "Force value"}; |
| 481 | |
| 482 | seq_puts(s, "\t"); |
| 483 | mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT; |
| 484 | r = (val & mask) >> TVO_VIP_REORDER_R_SHIFT; |
| 485 | mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT; |
| 486 | g = (val & mask) >> TVO_VIP_REORDER_G_SHIFT; |
| 487 | mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT; |
| 488 | b = (val & mask) >> TVO_VIP_REORDER_B_SHIFT; |
| 489 | seq_printf(s, "%-24s %s->%s %s->%s %s->%s\n", "Reorder:", |
| 490 | reorder[r], reorder[TVO_VIP_REORDER_CR_R_SEL], |
| 491 | reorder[g], reorder[TVO_VIP_REORDER_Y_G_SEL], |
| 492 | reorder[b], reorder[TVO_VIP_REORDER_CB_B_SEL]); |
| 493 | seq_puts(s, "\t\t\t\t\t"); |
| 494 | mask = TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT; |
| 495 | tmp = (val & mask) >> TVO_VIP_CLIP_SHIFT; |
| 496 | seq_printf(s, "%-24s %s\n", "Clipping:", clipping[tmp]); |
| 497 | seq_puts(s, "\t\t\t\t\t"); |
| 498 | mask = TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT; |
| 499 | tmp = (val & mask) >> TVO_VIP_RND_SHIFT; |
| 500 | seq_printf(s, "%-24s input data rounded to %s per component\n", |
| 501 | "Round:", round[tmp]); |
| 502 | seq_puts(s, "\t\t\t\t\t"); |
| 503 | tmp = (val & TVO_VIP_SEL_INPUT_MASK); |
| 504 | seq_printf(s, "%-24s %s", "Input selection:", input_sel[tmp]); |
| 505 | } |
| 506 | |
| 507 | static void tvout_dbg_hd_dac_cfg(struct seq_file *s, int val) |
| 508 | { |
| 509 | seq_printf(s, "\t%-24s %s", "HD DAC:", |
| 510 | val & 1 ? "disabled" : "enabled"); |
| 511 | } |
| 512 | |
| 513 | static int tvout_dbg_show(struct seq_file *s, void *data) |
| 514 | { |
| 515 | struct drm_info_node *node = s->private; |
| 516 | struct sti_tvout *tvout = (struct sti_tvout *)node->info_ent->data; |
| 517 | struct drm_device *dev = node->minor->dev; |
| 518 | struct drm_crtc *crtc; |
| 519 | int ret; |
| 520 | |
| 521 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 522 | if (ret) |
| 523 | return ret; |
| 524 | |
| 525 | seq_printf(s, "TVOUT: (vaddr = 0x%p)", tvout->regs); |
| 526 | |
| 527 | seq_puts(s, "\n\n HDMI encoder: "); |
| 528 | crtc = tvout->hdmi->crtc; |
| 529 | if (crtc) { |
| 530 | seq_printf(s, "connected to %s path", |
| 531 | sti_crtc_is_main(crtc) ? "main" : "aux"); |
| 532 | DBGFS_DUMP(TVO_HDMI_SYNC_SEL); |
| 533 | DBGFS_DUMP(TVO_VIP_HDMI); |
| 534 | tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_HDMI)); |
| 535 | } else { |
| 536 | seq_puts(s, "disabled"); |
| 537 | } |
| 538 | |
| 539 | seq_puts(s, "\n\n DVO encoder: "); |
| 540 | crtc = tvout->dvo->crtc; |
| 541 | if (crtc) { |
| 542 | seq_printf(s, "connected to %s path", |
| 543 | sti_crtc_is_main(crtc) ? "main" : "aux"); |
| 544 | DBGFS_DUMP(TVO_DVO_SYNC_SEL); |
| 545 | DBGFS_DUMP(TVO_DVO_CONFIG); |
| 546 | DBGFS_DUMP(TVO_VIP_DVO); |
| 547 | tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_DVO)); |
| 548 | } else { |
| 549 | seq_puts(s, "disabled"); |
| 550 | } |
| 551 | |
| 552 | seq_puts(s, "\n\n HDA encoder: "); |
| 553 | crtc = tvout->hda->crtc; |
| 554 | if (crtc) { |
| 555 | seq_printf(s, "connected to %s path", |
| 556 | sti_crtc_is_main(crtc) ? "main" : "aux"); |
| 557 | DBGFS_DUMP(TVO_HD_SYNC_SEL); |
| 558 | DBGFS_DUMP(TVO_HD_DAC_CFG_OFF); |
| 559 | tvout_dbg_hd_dac_cfg(s, |
| 560 | readl(tvout->regs + TVO_HD_DAC_CFG_OFF)); |
| 561 | DBGFS_DUMP(TVO_VIP_HDF); |
| 562 | tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_HDF)); |
| 563 | } else { |
| 564 | seq_puts(s, "disabled"); |
| 565 | } |
| 566 | |
| 567 | seq_puts(s, "\n\n main path configuration"); |
| 568 | DBGFS_DUMP(TVO_CSC_MAIN_M0); |
| 569 | DBGFS_DUMP(TVO_CSC_MAIN_M1); |
| 570 | DBGFS_DUMP(TVO_CSC_MAIN_M2); |
| 571 | DBGFS_DUMP(TVO_CSC_MAIN_M3); |
| 572 | DBGFS_DUMP(TVO_CSC_MAIN_M4); |
| 573 | DBGFS_DUMP(TVO_CSC_MAIN_M5); |
| 574 | DBGFS_DUMP(TVO_CSC_MAIN_M6); |
| 575 | DBGFS_DUMP(TVO_CSC_MAIN_M7); |
| 576 | DBGFS_DUMP(TVO_MAIN_IN_VID_FORMAT); |
| 577 | |
| 578 | seq_puts(s, "\n\n auxiliary path configuration"); |
| 579 | DBGFS_DUMP(TVO_CSC_AUX_M0); |
| 580 | DBGFS_DUMP(TVO_CSC_AUX_M2); |
| 581 | DBGFS_DUMP(TVO_CSC_AUX_M3); |
| 582 | DBGFS_DUMP(TVO_CSC_AUX_M4); |
| 583 | DBGFS_DUMP(TVO_CSC_AUX_M5); |
| 584 | DBGFS_DUMP(TVO_CSC_AUX_M6); |
| 585 | DBGFS_DUMP(TVO_CSC_AUX_M7); |
| 586 | DBGFS_DUMP(TVO_AUX_IN_VID_FORMAT); |
| 587 | seq_puts(s, "\n"); |
| 588 | |
| 589 | mutex_unlock(&dev->struct_mutex); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static struct drm_info_list tvout_debugfs_files[] = { |
| 594 | { "tvout", tvout_dbg_show, 0, NULL }, |
| 595 | }; |
| 596 | |
| 597 | static void tvout_debugfs_exit(struct sti_tvout *tvout, struct drm_minor *minor) |
| 598 | { |
| 599 | drm_debugfs_remove_files(tvout_debugfs_files, |
| 600 | ARRAY_SIZE(tvout_debugfs_files), |
| 601 | minor); |
| 602 | } |
| 603 | |
| 604 | static int tvout_debugfs_init(struct sti_tvout *tvout, struct drm_minor *minor) |
| 605 | { |
| 606 | unsigned int i; |
| 607 | |
| 608 | for (i = 0; i < ARRAY_SIZE(tvout_debugfs_files); i++) |
| 609 | tvout_debugfs_files[i].data = tvout; |
| 610 | |
| 611 | return drm_debugfs_create_files(tvout_debugfs_files, |
| 612 | ARRAY_SIZE(tvout_debugfs_files), |
| 613 | minor->debugfs_root, minor); |
| 614 | } |
| 615 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 616 | static void sti_tvout_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 617 | { |
| 618 | } |
| 619 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 620 | static void sti_tvout_encoder_mode_set(struct drm_encoder *encoder, |
| 621 | struct drm_display_mode *mode, |
| 622 | struct drm_display_mode *adjusted_mode) |
| 623 | { |
| 624 | } |
| 625 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 626 | static void sti_tvout_encoder_destroy(struct drm_encoder *encoder) |
| 627 | { |
| 628 | struct sti_tvout_encoder *sti_encoder = to_sti_tvout_encoder(encoder); |
| 629 | |
| 630 | drm_encoder_cleanup(encoder); |
| 631 | kfree(sti_encoder); |
| 632 | } |
| 633 | |
| 634 | static const struct drm_encoder_funcs sti_tvout_encoder_funcs = { |
| 635 | .destroy = sti_tvout_encoder_destroy, |
| 636 | }; |
| 637 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 638 | static void sti_dvo_encoder_enable(struct drm_encoder *encoder) |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 639 | { |
| 640 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 641 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 642 | tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode); |
| 643 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 644 | tvout_dvo_start(tvout, sti_crtc_is_main(encoder->crtc)); |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void sti_dvo_encoder_disable(struct drm_encoder *encoder) |
| 648 | { |
| 649 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 650 | |
| 651 | /* Reset VIP register */ |
| 652 | tvout_write(tvout, 0x0, TVO_VIP_DVO); |
| 653 | } |
| 654 | |
| 655 | static const struct drm_encoder_helper_funcs sti_dvo_encoder_helper_funcs = { |
| 656 | .dpms = sti_tvout_encoder_dpms, |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 657 | .mode_set = sti_tvout_encoder_mode_set, |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 658 | .enable = sti_dvo_encoder_enable, |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 659 | .disable = sti_dvo_encoder_disable, |
| 660 | }; |
| 661 | |
| 662 | static struct drm_encoder * |
| 663 | sti_tvout_create_dvo_encoder(struct drm_device *dev, |
| 664 | struct sti_tvout *tvout) |
| 665 | { |
| 666 | struct sti_tvout_encoder *encoder; |
| 667 | struct drm_encoder *drm_encoder; |
| 668 | |
| 669 | encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); |
| 670 | if (!encoder) |
| 671 | return NULL; |
| 672 | |
| 673 | encoder->tvout = tvout; |
| 674 | |
| 675 | drm_encoder = (struct drm_encoder *)encoder; |
| 676 | |
| 677 | drm_encoder->possible_crtcs = ENCODER_CRTC_MASK; |
| 678 | drm_encoder->possible_clones = 1 << 0; |
| 679 | |
| 680 | drm_encoder_init(dev, drm_encoder, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 681 | &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_LVDS, |
| 682 | NULL); |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 683 | |
| 684 | drm_encoder_helper_add(drm_encoder, &sti_dvo_encoder_helper_funcs); |
| 685 | |
| 686 | return drm_encoder; |
| 687 | } |
| 688 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 689 | static void sti_hda_encoder_enable(struct drm_encoder *encoder) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 690 | { |
| 691 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 692 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 693 | tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode); |
| 694 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 695 | tvout_hda_start(tvout, sti_crtc_is_main(encoder->crtc)); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | static void sti_hda_encoder_disable(struct drm_encoder *encoder) |
| 699 | { |
| 700 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 701 | |
| 702 | /* reset VIP register */ |
| 703 | tvout_write(tvout, 0x0, TVO_VIP_HDF); |
| 704 | |
| 705 | /* power down HD DAC */ |
| 706 | tvout_write(tvout, 1, TVO_HD_DAC_CFG_OFF); |
| 707 | } |
| 708 | |
| 709 | static const struct drm_encoder_helper_funcs sti_hda_encoder_helper_funcs = { |
| 710 | .dpms = sti_tvout_encoder_dpms, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 711 | .mode_set = sti_tvout_encoder_mode_set, |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 712 | .commit = sti_hda_encoder_enable, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 713 | .disable = sti_hda_encoder_disable, |
| 714 | }; |
| 715 | |
| 716 | static struct drm_encoder *sti_tvout_create_hda_encoder(struct drm_device *dev, |
| 717 | struct sti_tvout *tvout) |
| 718 | { |
| 719 | struct sti_tvout_encoder *encoder; |
| 720 | struct drm_encoder *drm_encoder; |
| 721 | |
| 722 | encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); |
| 723 | if (!encoder) |
| 724 | return NULL; |
| 725 | |
| 726 | encoder->tvout = tvout; |
| 727 | |
| 728 | drm_encoder = (struct drm_encoder *) encoder; |
| 729 | |
Benjamin Gaignard | 5e03abc | 2014-12-08 17:32:36 +0100 | [diff] [blame] | 730 | drm_encoder->possible_crtcs = ENCODER_CRTC_MASK; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 731 | drm_encoder->possible_clones = 1 << 0; |
| 732 | |
| 733 | drm_encoder_init(dev, drm_encoder, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 734 | &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_DAC, NULL); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 735 | |
| 736 | drm_encoder_helper_add(drm_encoder, &sti_hda_encoder_helper_funcs); |
| 737 | |
| 738 | return drm_encoder; |
| 739 | } |
| 740 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 741 | static void sti_hdmi_encoder_enable(struct drm_encoder *encoder) |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 742 | { |
| 743 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 744 | |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 745 | tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode); |
| 746 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 747 | tvout_hdmi_start(tvout, sti_crtc_is_main(encoder->crtc)); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | static void sti_hdmi_encoder_disable(struct drm_encoder *encoder) |
| 751 | { |
| 752 | struct sti_tvout *tvout = to_sti_tvout(encoder); |
| 753 | |
| 754 | /* reset VIP register */ |
| 755 | tvout_write(tvout, 0x0, TVO_VIP_HDMI); |
| 756 | } |
| 757 | |
| 758 | static const struct drm_encoder_helper_funcs sti_hdmi_encoder_helper_funcs = { |
| 759 | .dpms = sti_tvout_encoder_dpms, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 760 | .mode_set = sti_tvout_encoder_mode_set, |
Bich Hemon | 05a142c | 2016-02-10 10:39:23 +0100 | [diff] [blame] | 761 | .commit = sti_hdmi_encoder_enable, |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 762 | .disable = sti_hdmi_encoder_disable, |
| 763 | }; |
| 764 | |
| 765 | static struct drm_encoder *sti_tvout_create_hdmi_encoder(struct drm_device *dev, |
| 766 | struct sti_tvout *tvout) |
| 767 | { |
| 768 | struct sti_tvout_encoder *encoder; |
| 769 | struct drm_encoder *drm_encoder; |
| 770 | |
| 771 | encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL); |
| 772 | if (!encoder) |
| 773 | return NULL; |
| 774 | |
| 775 | encoder->tvout = tvout; |
| 776 | |
| 777 | drm_encoder = (struct drm_encoder *) encoder; |
| 778 | |
Benjamin Gaignard | 5e03abc | 2014-12-08 17:32:36 +0100 | [diff] [blame] | 779 | drm_encoder->possible_crtcs = ENCODER_CRTC_MASK; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 780 | drm_encoder->possible_clones = 1 << 1; |
| 781 | |
| 782 | drm_encoder_init(dev, drm_encoder, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 783 | &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_TMDS, NULL); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 784 | |
| 785 | drm_encoder_helper_add(drm_encoder, &sti_hdmi_encoder_helper_funcs); |
| 786 | |
| 787 | return drm_encoder; |
| 788 | } |
| 789 | |
| 790 | static void sti_tvout_create_encoders(struct drm_device *dev, |
| 791 | struct sti_tvout *tvout) |
| 792 | { |
| 793 | tvout->hdmi = sti_tvout_create_hdmi_encoder(dev, tvout); |
| 794 | tvout->hda = sti_tvout_create_hda_encoder(dev, tvout); |
Benjamin Gaignard | f32c4c5 | 2014-12-30 15:08:16 +0100 | [diff] [blame] | 795 | tvout->dvo = sti_tvout_create_dvo_encoder(dev, tvout); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static void sti_tvout_destroy_encoders(struct sti_tvout *tvout) |
| 799 | { |
| 800 | if (tvout->hdmi) |
| 801 | drm_encoder_cleanup(tvout->hdmi); |
| 802 | tvout->hdmi = NULL; |
| 803 | |
| 804 | if (tvout->hda) |
| 805 | drm_encoder_cleanup(tvout->hda); |
| 806 | tvout->hda = NULL; |
Vincent Abriou | 0a1dc29 | 2016-02-05 09:31:18 +0100 | [diff] [blame] | 807 | |
| 808 | if (tvout->dvo) |
| 809 | drm_encoder_cleanup(tvout->dvo); |
| 810 | tvout->dvo = NULL; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static int sti_tvout_bind(struct device *dev, struct device *master, void *data) |
| 814 | { |
| 815 | struct sti_tvout *tvout = dev_get_drvdata(dev); |
| 816 | struct drm_device *drm_dev = data; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 817 | |
| 818 | tvout->drm_dev = drm_dev; |
| 819 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 820 | sti_tvout_create_encoders(drm_dev, tvout); |
| 821 | |
Vincent Abriou | b514bee | 2016-02-05 11:14:48 +0100 | [diff] [blame] | 822 | if (tvout_debugfs_init(tvout, drm_dev->primary)) |
| 823 | DRM_ERROR("TVOUT debugfs setup failed\n"); |
| 824 | |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 825 | return 0; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static void sti_tvout_unbind(struct device *dev, struct device *master, |
| 829 | void *data) |
| 830 | { |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 831 | struct sti_tvout *tvout = dev_get_drvdata(dev); |
Vincent Abriou | b514bee | 2016-02-05 11:14:48 +0100 | [diff] [blame] | 832 | struct drm_device *drm_dev = data; |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 833 | |
| 834 | sti_tvout_destroy_encoders(tvout); |
Vincent Abriou | b514bee | 2016-02-05 11:14:48 +0100 | [diff] [blame] | 835 | |
| 836 | tvout_debugfs_exit(tvout, drm_dev->primary); |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | static const struct component_ops sti_tvout_ops = { |
| 840 | .bind = sti_tvout_bind, |
| 841 | .unbind = sti_tvout_unbind, |
| 842 | }; |
| 843 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 844 | static int sti_tvout_probe(struct platform_device *pdev) |
| 845 | { |
| 846 | struct device *dev = &pdev->dev; |
| 847 | struct device_node *node = dev->of_node; |
| 848 | struct sti_tvout *tvout; |
| 849 | struct resource *res; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 850 | |
| 851 | DRM_INFO("%s\n", __func__); |
| 852 | |
| 853 | if (!node) |
| 854 | return -ENODEV; |
| 855 | |
| 856 | tvout = devm_kzalloc(dev, sizeof(*tvout), GFP_KERNEL); |
| 857 | if (!tvout) |
| 858 | return -ENOMEM; |
| 859 | |
| 860 | tvout->dev = dev; |
| 861 | |
| 862 | /* get Memory ressources */ |
| 863 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tvout-reg"); |
| 864 | if (!res) { |
| 865 | DRM_ERROR("Invalid glue resource\n"); |
| 866 | return -ENOMEM; |
| 867 | } |
| 868 | tvout->regs = devm_ioremap_nocache(dev, res->start, resource_size(res)); |
Wei Yongjun | 31f32a2 | 2014-08-26 12:17:36 +0200 | [diff] [blame] | 869 | if (!tvout->regs) |
| 870 | return -ENOMEM; |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 871 | |
| 872 | /* get reset resources */ |
| 873 | tvout->reset = devm_reset_control_get(dev, "tvout"); |
| 874 | /* take tvout out of reset */ |
| 875 | if (!IS_ERR(tvout->reset)) |
| 876 | reset_control_deassert(tvout->reset); |
| 877 | |
| 878 | platform_set_drvdata(pdev, tvout); |
| 879 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 880 | return component_add(dev, &sti_tvout_ops); |
| 881 | } |
| 882 | |
| 883 | static int sti_tvout_remove(struct platform_device *pdev) |
| 884 | { |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 885 | component_del(&pdev->dev, &sti_tvout_ops); |
| 886 | return 0; |
| 887 | } |
| 888 | |
Kiran Padwal | 8e932cf | 2014-08-26 12:25:24 +0200 | [diff] [blame] | 889 | static const struct of_device_id tvout_of_match[] = { |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 890 | { .compatible = "st,stih416-tvout", }, |
| 891 | { .compatible = "st,stih407-tvout", }, |
| 892 | { /* end node */ } |
| 893 | }; |
| 894 | MODULE_DEVICE_TABLE(of, tvout_of_match); |
| 895 | |
| 896 | struct platform_driver sti_tvout_driver = { |
| 897 | .driver = { |
| 898 | .name = "sti-tvout", |
| 899 | .owner = THIS_MODULE, |
| 900 | .of_match_table = tvout_of_match, |
| 901 | }, |
| 902 | .probe = sti_tvout_probe, |
| 903 | .remove = sti_tvout_remove, |
| 904 | }; |
| 905 | |
Benjamin Gaignard | cdfbff7 | 2014-07-30 19:26:17 +0200 | [diff] [blame] | 906 | MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>"); |
| 907 | MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver"); |
| 908 | MODULE_LICENSE("GPL"); |