Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * i.MX drm driver - Television Encoder (TVEv2) |
| 3 | * |
| 4 | * Copyright (C) 2013 Philipp Zabel, Pengutronix |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/clk.h> |
| 17 | #include <linux/clk-provider.h> |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 18 | #include <linux/component.h> |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 19 | #include <linux/module.h> |
Wolfram Sang | 687b81d | 2013-07-11 12:56:15 +0100 | [diff] [blame] | 20 | #include <linux/i2c.h> |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 21 | #include <linux/regmap.h> |
| 22 | #include <linux/regulator/consumer.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/videodev2.h> |
| 25 | #include <drm/drmP.h> |
Liu Ying | 255c35f | 2016-07-08 17:40:56 +0800 | [diff] [blame] | 26 | #include <drm/drm_atomic_helper.h> |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 27 | #include <drm/drm_fb_helper.h> |
| 28 | #include <drm/drm_crtc_helper.h> |
Philipp Zabel | 39b9004 | 2013-09-30 16:13:39 +0200 | [diff] [blame] | 29 | #include <video/imx-ipu-v3.h> |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 30 | |
| 31 | #include "imx-drm.h" |
| 32 | |
| 33 | #define TVE_COM_CONF_REG 0x00 |
| 34 | #define TVE_TVDAC0_CONT_REG 0x28 |
| 35 | #define TVE_TVDAC1_CONT_REG 0x2c |
| 36 | #define TVE_TVDAC2_CONT_REG 0x30 |
| 37 | #define TVE_CD_CONT_REG 0x34 |
| 38 | #define TVE_INT_CONT_REG 0x64 |
| 39 | #define TVE_STAT_REG 0x68 |
| 40 | #define TVE_TST_MODE_REG 0x6c |
| 41 | #define TVE_MV_CONT_REG 0xdc |
| 42 | |
| 43 | /* TVE_COM_CONF_REG */ |
| 44 | #define TVE_SYNC_CH_2_EN BIT(22) |
| 45 | #define TVE_SYNC_CH_1_EN BIT(21) |
| 46 | #define TVE_SYNC_CH_0_EN BIT(20) |
| 47 | #define TVE_TV_OUT_MODE_MASK (0x7 << 12) |
| 48 | #define TVE_TV_OUT_DISABLE (0x0 << 12) |
| 49 | #define TVE_TV_OUT_CVBS_0 (0x1 << 12) |
| 50 | #define TVE_TV_OUT_CVBS_2 (0x2 << 12) |
| 51 | #define TVE_TV_OUT_CVBS_0_2 (0x3 << 12) |
| 52 | #define TVE_TV_OUT_SVIDEO_0_1 (0x4 << 12) |
| 53 | #define TVE_TV_OUT_SVIDEO_0_1_CVBS2_2 (0x5 << 12) |
| 54 | #define TVE_TV_OUT_YPBPR (0x6 << 12) |
| 55 | #define TVE_TV_OUT_RGB (0x7 << 12) |
| 56 | #define TVE_TV_STAND_MASK (0xf << 8) |
| 57 | #define TVE_TV_STAND_HD_1080P30 (0xc << 8) |
| 58 | #define TVE_P2I_CONV_EN BIT(7) |
| 59 | #define TVE_INP_VIDEO_FORM BIT(6) |
| 60 | #define TVE_INP_YCBCR_422 (0x0 << 6) |
| 61 | #define TVE_INP_YCBCR_444 (0x1 << 6) |
| 62 | #define TVE_DATA_SOURCE_MASK (0x3 << 4) |
| 63 | #define TVE_DATA_SOURCE_BUS1 (0x0 << 4) |
| 64 | #define TVE_DATA_SOURCE_BUS2 (0x1 << 4) |
| 65 | #define TVE_DATA_SOURCE_EXT (0x2 << 4) |
| 66 | #define TVE_DATA_SOURCE_TESTGEN (0x3 << 4) |
| 67 | #define TVE_IPU_CLK_EN_OFS 3 |
| 68 | #define TVE_IPU_CLK_EN BIT(3) |
| 69 | #define TVE_DAC_SAMP_RATE_OFS 1 |
| 70 | #define TVE_DAC_SAMP_RATE_WIDTH 2 |
| 71 | #define TVE_DAC_SAMP_RATE_MASK (0x3 << 1) |
| 72 | #define TVE_DAC_FULL_RATE (0x0 << 1) |
| 73 | #define TVE_DAC_DIV2_RATE (0x1 << 1) |
| 74 | #define TVE_DAC_DIV4_RATE (0x2 << 1) |
| 75 | #define TVE_EN BIT(0) |
| 76 | |
| 77 | /* TVE_TVDACx_CONT_REG */ |
| 78 | #define TVE_TVDAC_GAIN_MASK (0x3f << 0) |
| 79 | |
| 80 | /* TVE_CD_CONT_REG */ |
| 81 | #define TVE_CD_CH_2_SM_EN BIT(22) |
| 82 | #define TVE_CD_CH_1_SM_EN BIT(21) |
| 83 | #define TVE_CD_CH_0_SM_EN BIT(20) |
| 84 | #define TVE_CD_CH_2_LM_EN BIT(18) |
| 85 | #define TVE_CD_CH_1_LM_EN BIT(17) |
| 86 | #define TVE_CD_CH_0_LM_EN BIT(16) |
| 87 | #define TVE_CD_CH_2_REF_LVL BIT(10) |
| 88 | #define TVE_CD_CH_1_REF_LVL BIT(9) |
| 89 | #define TVE_CD_CH_0_REF_LVL BIT(8) |
| 90 | #define TVE_CD_EN BIT(0) |
| 91 | |
| 92 | /* TVE_INT_CONT_REG */ |
| 93 | #define TVE_FRAME_END_IEN BIT(13) |
| 94 | #define TVE_CD_MON_END_IEN BIT(2) |
| 95 | #define TVE_CD_SM_IEN BIT(1) |
| 96 | #define TVE_CD_LM_IEN BIT(0) |
| 97 | |
| 98 | /* TVE_TST_MODE_REG */ |
| 99 | #define TVE_TVDAC_TEST_MODE_MASK (0x7 << 0) |
| 100 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 101 | enum { |
| 102 | TVE_MODE_TVOUT, |
| 103 | TVE_MODE_VGA, |
| 104 | }; |
| 105 | |
| 106 | struct imx_tve { |
| 107 | struct drm_connector connector; |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 108 | struct drm_encoder encoder; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 109 | struct device *dev; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 110 | spinlock_t lock; /* register lock */ |
| 111 | bool enabled; |
| 112 | int mode; |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 113 | int di_hsync_pin; |
| 114 | int di_vsync_pin; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 115 | |
| 116 | struct regmap *regmap; |
| 117 | struct regulator *dac_reg; |
| 118 | struct i2c_adapter *ddc; |
| 119 | struct clk *clk; |
| 120 | struct clk *di_sel_clk; |
| 121 | struct clk_hw clk_hw_di; |
| 122 | struct clk *di_clk; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
Philipp Zabel | 3df0739 | 2016-07-06 15:47:11 +0200 | [diff] [blame] | 125 | static inline struct imx_tve *con_to_tve(struct drm_connector *c) |
| 126 | { |
| 127 | return container_of(c, struct imx_tve, connector); |
| 128 | } |
| 129 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 130 | static inline struct imx_tve *enc_to_tve(struct drm_encoder *e) |
| 131 | { |
| 132 | return container_of(e, struct imx_tve, encoder); |
| 133 | } |
| 134 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 135 | static void tve_lock(void *__tve) |
Fabio Estevam | 5d78bf8 | 2013-07-16 02:16:14 -0300 | [diff] [blame] | 136 | __acquires(&tve->lock) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 137 | { |
| 138 | struct imx_tve *tve = __tve; |
Quentin Lambert | 63bc516 | 2014-08-04 21:07:07 +0200 | [diff] [blame] | 139 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 140 | spin_lock(&tve->lock); |
| 141 | } |
| 142 | |
| 143 | static void tve_unlock(void *__tve) |
Fabio Estevam | 5d78bf8 | 2013-07-16 02:16:14 -0300 | [diff] [blame] | 144 | __releases(&tve->lock) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 145 | { |
| 146 | struct imx_tve *tve = __tve; |
Quentin Lambert | 63bc516 | 2014-08-04 21:07:07 +0200 | [diff] [blame] | 147 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 148 | spin_unlock(&tve->lock); |
| 149 | } |
| 150 | |
| 151 | static void tve_enable(struct imx_tve *tve) |
| 152 | { |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 153 | int ret; |
| 154 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 155 | if (!tve->enabled) { |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 156 | tve->enabled = true; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 157 | clk_prepare_enable(tve->clk); |
| 158 | ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 159 | TVE_EN, TVE_EN); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /* clear interrupt status register */ |
| 163 | regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff); |
| 164 | |
| 165 | /* cable detection irq disabled in VGA mode, enabled in TVOUT mode */ |
| 166 | if (tve->mode == TVE_MODE_VGA) |
| 167 | regmap_write(tve->regmap, TVE_INT_CONT_REG, 0); |
| 168 | else |
| 169 | regmap_write(tve->regmap, TVE_INT_CONT_REG, |
Andreas Werner | 89911e5 | 2013-08-11 17:20:23 +0200 | [diff] [blame] | 170 | TVE_CD_SM_IEN | |
| 171 | TVE_CD_LM_IEN | |
| 172 | TVE_CD_MON_END_IEN); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static void tve_disable(struct imx_tve *tve) |
| 176 | { |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 177 | int ret; |
| 178 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 179 | if (tve->enabled) { |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 180 | tve->enabled = false; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 181 | ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 182 | TVE_EN, 0); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 183 | clk_disable_unprepare(tve->clk); |
| 184 | } |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int tve_setup_tvout(struct imx_tve *tve) |
| 188 | { |
| 189 | return -ENOTSUPP; |
| 190 | } |
| 191 | |
| 192 | static int tve_setup_vga(struct imx_tve *tve) |
| 193 | { |
| 194 | unsigned int mask; |
| 195 | unsigned int val; |
| 196 | int ret; |
| 197 | |
| 198 | /* set gain to (1 + 10/128) to provide 0.7V peak-to-peak amplitude */ |
| 199 | ret = regmap_update_bits(tve->regmap, TVE_TVDAC0_CONT_REG, |
| 200 | TVE_TVDAC_GAIN_MASK, 0x0a); |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 201 | if (ret) |
| 202 | return ret; |
| 203 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 204 | ret = regmap_update_bits(tve->regmap, TVE_TVDAC1_CONT_REG, |
| 205 | TVE_TVDAC_GAIN_MASK, 0x0a); |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 206 | if (ret) |
| 207 | return ret; |
| 208 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 209 | ret = regmap_update_bits(tve->regmap, TVE_TVDAC2_CONT_REG, |
| 210 | TVE_TVDAC_GAIN_MASK, 0x0a); |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 211 | if (ret) |
| 212 | return ret; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 213 | |
| 214 | /* set configuration register */ |
| 215 | mask = TVE_DATA_SOURCE_MASK | TVE_INP_VIDEO_FORM; |
| 216 | val = TVE_DATA_SOURCE_BUS2 | TVE_INP_YCBCR_444; |
| 217 | mask |= TVE_TV_STAND_MASK | TVE_P2I_CONV_EN; |
| 218 | val |= TVE_TV_STAND_HD_1080P30 | 0; |
| 219 | mask |= TVE_TV_OUT_MODE_MASK | TVE_SYNC_CH_0_EN; |
| 220 | val |= TVE_TV_OUT_RGB | TVE_SYNC_CH_0_EN; |
| 221 | ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, mask, val); |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 222 | if (ret) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 223 | return ret; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 224 | |
| 225 | /* set test mode (as documented) */ |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 226 | return regmap_update_bits(tve->regmap, TVE_TST_MODE_REG, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 227 | TVE_TVDAC_TEST_MODE_MASK, 1); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 230 | static int imx_tve_connector_get_modes(struct drm_connector *connector) |
| 231 | { |
| 232 | struct imx_tve *tve = con_to_tve(connector); |
| 233 | struct edid *edid; |
| 234 | int ret = 0; |
| 235 | |
| 236 | if (!tve->ddc) |
| 237 | return 0; |
| 238 | |
| 239 | edid = drm_get_edid(connector, tve->ddc); |
| 240 | if (edid) { |
| 241 | drm_mode_connector_update_edid_property(connector, edid); |
| 242 | ret = drm_add_edid_modes(connector, edid); |
| 243 | kfree(edid); |
| 244 | } |
| 245 | |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | static int imx_tve_connector_mode_valid(struct drm_connector *connector, |
| 250 | struct drm_display_mode *mode) |
| 251 | { |
| 252 | struct imx_tve *tve = con_to_tve(connector); |
| 253 | unsigned long rate; |
Russell King | baa68c4 | 2013-11-09 11:20:55 +0000 | [diff] [blame] | 254 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 255 | /* pixel clock with 2x oversampling */ |
| 256 | rate = clk_round_rate(tve->clk, 2000UL * mode->clock) / 2000; |
| 257 | if (rate == mode->clock) |
| 258 | return MODE_OK; |
| 259 | |
| 260 | /* pixel clock without oversampling */ |
| 261 | rate = clk_round_rate(tve->clk, 1000UL * mode->clock) / 1000; |
| 262 | if (rate == mode->clock) |
| 263 | return MODE_OK; |
| 264 | |
| 265 | dev_warn(tve->dev, "ignoring mode %dx%d\n", |
| 266 | mode->hdisplay, mode->vdisplay); |
| 267 | |
| 268 | return MODE_BAD; |
| 269 | } |
| 270 | |
| 271 | static struct drm_encoder *imx_tve_connector_best_encoder( |
| 272 | struct drm_connector *connector) |
| 273 | { |
| 274 | struct imx_tve *tve = con_to_tve(connector); |
| 275 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 276 | return &tve->encoder; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 279 | static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, |
Steve Longerbeam | eb10d63 | 2014-12-18 18:00:24 -0800 | [diff] [blame] | 280 | struct drm_display_mode *orig_mode, |
| 281 | struct drm_display_mode *mode) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 282 | { |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 283 | struct imx_tve *tve = enc_to_tve(encoder); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 284 | unsigned long rounded_rate; |
| 285 | unsigned long rate; |
| 286 | int div = 1; |
| 287 | int ret; |
| 288 | |
| 289 | /* |
| 290 | * FIXME |
| 291 | * we should try 4k * mode->clock first, |
| 292 | * and enable 4x oversampling for lower resolutions |
| 293 | */ |
| 294 | rate = 2000UL * mode->clock; |
| 295 | clk_set_rate(tve->clk, rate); |
| 296 | rounded_rate = clk_get_rate(tve->clk); |
| 297 | if (rounded_rate >= rate) |
| 298 | div = 2; |
| 299 | clk_set_rate(tve->di_clk, rounded_rate / div); |
| 300 | |
| 301 | ret = clk_set_parent(tve->di_sel_clk, tve->di_clk); |
| 302 | if (ret < 0) { |
| 303 | dev_err(tve->dev, "failed to set di_sel parent to tve_di: %d\n", |
| 304 | ret); |
| 305 | } |
| 306 | |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 307 | regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, |
| 308 | TVE_IPU_CLK_EN, TVE_IPU_CLK_EN); |
| 309 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 310 | if (tve->mode == TVE_MODE_VGA) |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 311 | ret = tve_setup_vga(tve); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 312 | else |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 313 | ret = tve_setup_tvout(tve); |
| 314 | if (ret) |
| 315 | dev_err(tve->dev, "failed to set configuration: %d\n", ret); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 318 | static void imx_tve_encoder_enable(struct drm_encoder *encoder) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 319 | { |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 320 | struct imx_tve *tve = enc_to_tve(encoder); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 321 | |
| 322 | tve_enable(tve); |
| 323 | } |
| 324 | |
| 325 | static void imx_tve_encoder_disable(struct drm_encoder *encoder) |
| 326 | { |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 327 | struct imx_tve *tve = enc_to_tve(encoder); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 328 | |
| 329 | tve_disable(tve); |
| 330 | } |
| 331 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 332 | static int imx_tve_atomic_check(struct drm_encoder *encoder, |
| 333 | struct drm_crtc_state *crtc_state, |
| 334 | struct drm_connector_state *conn_state) |
| 335 | { |
| 336 | struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state); |
| 337 | struct imx_tve *tve = enc_to_tve(encoder); |
| 338 | |
| 339 | imx_crtc_state->bus_format = MEDIA_BUS_FMT_GBR888_1X24; |
| 340 | imx_crtc_state->di_hsync_pin = tve->di_hsync_pin; |
| 341 | imx_crtc_state->di_vsync_pin = tve->di_vsync_pin; |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
Ville Syrjälä | 7ae847d | 2015-12-15 12:21:09 +0100 | [diff] [blame] | 346 | static const struct drm_connector_funcs imx_tve_connector_funcs = { |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 347 | .dpms = drm_atomic_helper_connector_dpms, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 348 | .fill_modes = drm_helper_probe_single_connector_modes, |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 349 | .destroy = imx_drm_connector_destroy, |
Liu Ying | 255c35f | 2016-07-08 17:40:56 +0800 | [diff] [blame] | 350 | .reset = drm_atomic_helper_connector_reset, |
| 351 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 352 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 353 | }; |
| 354 | |
Ville Syrjälä | 7ae847d | 2015-12-15 12:21:09 +0100 | [diff] [blame] | 355 | static const struct drm_connector_helper_funcs imx_tve_connector_helper_funcs = { |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 356 | .get_modes = imx_tve_connector_get_modes, |
| 357 | .best_encoder = imx_tve_connector_best_encoder, |
| 358 | .mode_valid = imx_tve_connector_mode_valid, |
| 359 | }; |
| 360 | |
Ville Syrjälä | 7ae847d | 2015-12-15 12:21:09 +0100 | [diff] [blame] | 361 | static const struct drm_encoder_funcs imx_tve_encoder_funcs = { |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 362 | .destroy = imx_drm_encoder_destroy, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 363 | }; |
| 364 | |
Ville Syrjälä | 7ae847d | 2015-12-15 12:21:09 +0100 | [diff] [blame] | 365 | static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = { |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 366 | .mode_set = imx_tve_encoder_mode_set, |
Liu Ying | f6e396e | 2016-07-08 17:41:01 +0800 | [diff] [blame] | 367 | .enable = imx_tve_encoder_enable, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 368 | .disable = imx_tve_encoder_disable, |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 369 | .atomic_check = imx_tve_atomic_check, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | static irqreturn_t imx_tve_irq_handler(int irq, void *data) |
| 373 | { |
| 374 | struct imx_tve *tve = data; |
| 375 | unsigned int val; |
| 376 | |
| 377 | regmap_read(tve->regmap, TVE_STAT_REG, &val); |
| 378 | |
| 379 | /* clear interrupt status register */ |
| 380 | regmap_write(tve->regmap, TVE_STAT_REG, 0xffffffff); |
| 381 | |
| 382 | return IRQ_HANDLED; |
| 383 | } |
| 384 | |
| 385 | static unsigned long clk_tve_di_recalc_rate(struct clk_hw *hw, |
| 386 | unsigned long parent_rate) |
| 387 | { |
| 388 | struct imx_tve *tve = container_of(hw, struct imx_tve, clk_hw_di); |
| 389 | unsigned int val; |
| 390 | int ret; |
| 391 | |
| 392 | ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); |
| 393 | if (ret < 0) |
| 394 | return 0; |
| 395 | |
| 396 | switch (val & TVE_DAC_SAMP_RATE_MASK) { |
| 397 | case TVE_DAC_DIV4_RATE: |
| 398 | return parent_rate / 4; |
| 399 | case TVE_DAC_DIV2_RATE: |
| 400 | return parent_rate / 2; |
| 401 | case TVE_DAC_FULL_RATE: |
| 402 | default: |
| 403 | return parent_rate; |
| 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static long clk_tve_di_round_rate(struct clk_hw *hw, unsigned long rate, |
| 410 | unsigned long *prate) |
| 411 | { |
| 412 | unsigned long div; |
| 413 | |
| 414 | div = *prate / rate; |
| 415 | if (div >= 4) |
| 416 | return *prate / 4; |
| 417 | else if (div >= 2) |
| 418 | return *prate / 2; |
Catalina Mocanu | 7557b6e | 2014-09-24 14:27:36 -0700 | [diff] [blame] | 419 | return *prate; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static int clk_tve_di_set_rate(struct clk_hw *hw, unsigned long rate, |
| 423 | unsigned long parent_rate) |
| 424 | { |
| 425 | struct imx_tve *tve = container_of(hw, struct imx_tve, clk_hw_di); |
| 426 | unsigned long div; |
| 427 | u32 val; |
| 428 | int ret; |
| 429 | |
| 430 | div = parent_rate / rate; |
| 431 | if (div >= 4) |
| 432 | val = TVE_DAC_DIV4_RATE; |
| 433 | else if (div >= 2) |
| 434 | val = TVE_DAC_DIV2_RATE; |
| 435 | else |
| 436 | val = TVE_DAC_FULL_RATE; |
| 437 | |
Andreas Werner | 89911e5 | 2013-08-11 17:20:23 +0200 | [diff] [blame] | 438 | ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, |
| 439 | TVE_DAC_SAMP_RATE_MASK, val); |
| 440 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 441 | if (ret < 0) { |
| 442 | dev_err(tve->dev, "failed to set divider: %d\n", ret); |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static struct clk_ops clk_tve_di_ops = { |
| 450 | .round_rate = clk_tve_di_round_rate, |
| 451 | .set_rate = clk_tve_di_set_rate, |
| 452 | .recalc_rate = clk_tve_di_recalc_rate, |
| 453 | }; |
| 454 | |
| 455 | static int tve_clk_init(struct imx_tve *tve, void __iomem *base) |
| 456 | { |
| 457 | const char *tve_di_parent[1]; |
| 458 | struct clk_init_data init = { |
| 459 | .name = "tve_di", |
| 460 | .ops = &clk_tve_di_ops, |
| 461 | .num_parents = 1, |
| 462 | .flags = 0, |
| 463 | }; |
| 464 | |
| 465 | tve_di_parent[0] = __clk_get_name(tve->clk); |
| 466 | init.parent_names = (const char **)&tve_di_parent; |
| 467 | |
| 468 | tve->clk_hw_di.init = &init; |
| 469 | tve->di_clk = clk_register(tve->dev, &tve->clk_hw_di); |
| 470 | if (IS_ERR(tve->di_clk)) { |
| 471 | dev_err(tve->dev, "failed to register TVE output clock: %ld\n", |
| 472 | PTR_ERR(tve->di_clk)); |
| 473 | return PTR_ERR(tve->di_clk); |
| 474 | } |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 479 | static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 480 | { |
Russell King | f2d66aa | 2013-11-03 15:52:16 +0000 | [diff] [blame] | 481 | int encoder_type; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 482 | int ret; |
| 483 | |
Russell King | f2d66aa | 2013-11-03 15:52:16 +0000 | [diff] [blame] | 484 | encoder_type = tve->mode == TVE_MODE_VGA ? |
| 485 | DRM_MODE_ENCODER_DAC : DRM_MODE_ENCODER_TVDAC; |
| 486 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 487 | ret = imx_drm_encoder_parse_of(drm, &tve->encoder, tve->dev->of_node); |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 488 | if (ret) |
| 489 | return ret; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 490 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 491 | drm_encoder_helper_add(&tve->encoder, &imx_tve_encoder_helper_funcs); |
| 492 | drm_encoder_init(drm, &tve->encoder, &imx_tve_encoder_funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 493 | encoder_type, NULL); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 494 | |
| 495 | drm_connector_helper_add(&tve->connector, |
| 496 | &imx_tve_connector_helper_funcs); |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 497 | drm_connector_init(drm, &tve->connector, &imx_tve_connector_funcs, |
| 498 | DRM_MODE_CONNECTOR_VGA); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 499 | |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 500 | drm_mode_connector_attach_encoder(&tve->connector, &tve->encoder); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | static bool imx_tve_readable_reg(struct device *dev, unsigned int reg) |
| 506 | { |
| 507 | return (reg % 4 == 0) && (reg <= 0xdc); |
| 508 | } |
| 509 | |
| 510 | static struct regmap_config tve_regmap_config = { |
| 511 | .reg_bits = 32, |
| 512 | .val_bits = 32, |
| 513 | .reg_stride = 4, |
| 514 | |
| 515 | .readable_reg = imx_tve_readable_reg, |
| 516 | |
| 517 | .lock = tve_lock, |
| 518 | .unlock = tve_unlock, |
| 519 | |
| 520 | .max_register = 0xdc, |
| 521 | }; |
| 522 | |
Aybuke Ozdemir | 8684ba7 | 2014-09-27 16:16:02 +0300 | [diff] [blame] | 523 | static const char * const imx_tve_modes[] = { |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 524 | [TVE_MODE_TVOUT] = "tvout", |
| 525 | [TVE_MODE_VGA] = "vga", |
| 526 | }; |
| 527 | |
Liu Ying | 7fc6cb2 | 2013-12-24 10:17:44 +0800 | [diff] [blame] | 528 | static const int of_get_tve_mode(struct device_node *np) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 529 | { |
| 530 | const char *bm; |
| 531 | int ret, i; |
| 532 | |
| 533 | ret = of_property_read_string(np, "fsl,tve-mode", &bm); |
| 534 | if (ret < 0) |
| 535 | return ret; |
| 536 | |
| 537 | for (i = 0; i < ARRAY_SIZE(imx_tve_modes); i++) |
| 538 | if (!strcasecmp(bm, imx_tve_modes[i])) |
| 539 | return i; |
| 540 | |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 544 | static int imx_tve_bind(struct device *dev, struct device *master, void *data) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 545 | { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 546 | struct platform_device *pdev = to_platform_device(dev); |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 547 | struct drm_device *drm = data; |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 548 | struct device_node *np = dev->of_node; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 549 | struct device_node *ddc_node; |
| 550 | struct imx_tve *tve; |
| 551 | struct resource *res; |
| 552 | void __iomem *base; |
| 553 | unsigned int val; |
| 554 | int irq; |
| 555 | int ret; |
| 556 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 557 | tve = devm_kzalloc(dev, sizeof(*tve), GFP_KERNEL); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 558 | if (!tve) |
| 559 | return -ENOMEM; |
| 560 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 561 | tve->dev = dev; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 562 | spin_lock_init(&tve->lock); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 563 | |
Shawn Guo | a3fe964 | 2014-04-10 14:19:05 +0800 | [diff] [blame] | 564 | ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 565 | if (ddc_node) { |
| 566 | tve->ddc = of_find_i2c_adapter_by_node(ddc_node); |
| 567 | of_node_put(ddc_node); |
| 568 | } |
| 569 | |
| 570 | tve->mode = of_get_tve_mode(np); |
| 571 | if (tve->mode != TVE_MODE_VGA) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 572 | dev_err(dev, "only VGA mode supported, currently\n"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 573 | return -EINVAL; |
| 574 | } |
| 575 | |
| 576 | if (tve->mode == TVE_MODE_VGA) { |
Andreas Werner | 89911e5 | 2013-08-11 17:20:23 +0200 | [diff] [blame] | 577 | ret = of_property_read_u32(np, "fsl,hsync-pin", |
Philipp Zabel | 49f98bc | 2016-07-06 14:49:24 +0200 | [diff] [blame] | 578 | &tve->di_hsync_pin); |
Andreas Werner | 89911e5 | 2013-08-11 17:20:23 +0200 | [diff] [blame] | 579 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 580 | if (ret < 0) { |
Fabio Estevam | ae8308b | 2016-07-09 18:57:44 -0300 | [diff] [blame] | 581 | dev_err(dev, "failed to get hsync pin\n"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 582 | return ret; |
| 583 | } |
| 584 | |
Fabio Estevam | 4f7a512 | 2016-07-09 18:57:43 -0300 | [diff] [blame] | 585 | ret = of_property_read_u32(np, "fsl,vsync-pin", |
| 586 | &tve->di_vsync_pin); |
Andreas Werner | 89911e5 | 2013-08-11 17:20:23 +0200 | [diff] [blame] | 587 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 588 | if (ret < 0) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 589 | dev_err(dev, "failed to get vsync pin\n"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 595 | base = devm_ioremap_resource(dev, res); |
Laurent Navet | 9b43b56 | 2013-05-02 13:41:41 +0200 | [diff] [blame] | 596 | if (IS_ERR(base)) |
| 597 | return PTR_ERR(base); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 598 | |
| 599 | tve_regmap_config.lock_arg = tve; |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 600 | tve->regmap = devm_regmap_init_mmio_clk(dev, "tve", base, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 601 | &tve_regmap_config); |
| 602 | if (IS_ERR(tve->regmap)) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 603 | dev_err(dev, "failed to init regmap: %ld\n", |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 604 | PTR_ERR(tve->regmap)); |
| 605 | return PTR_ERR(tve->regmap); |
| 606 | } |
| 607 | |
| 608 | irq = platform_get_irq(pdev, 0); |
| 609 | if (irq < 0) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 610 | dev_err(dev, "failed to get irq\n"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 611 | return irq; |
| 612 | } |
| 613 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 614 | ret = devm_request_threaded_irq(dev, irq, NULL, |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 615 | imx_tve_irq_handler, IRQF_ONESHOT, |
| 616 | "imx-tve", tve); |
| 617 | if (ret < 0) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 618 | dev_err(dev, "failed to request irq: %d\n", ret); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 619 | return ret; |
| 620 | } |
| 621 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 622 | tve->dac_reg = devm_regulator_get(dev, "dac"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 623 | if (!IS_ERR(tve->dac_reg)) { |
Fabio Estevam | deb6587 | 2016-07-09 18:57:42 -0300 | [diff] [blame] | 624 | ret = regulator_set_voltage(tve->dac_reg, 2750000, 2750000); |
| 625 | if (ret) |
| 626 | return ret; |
Fabio Estevam | c7b0cf3 | 2013-05-21 11:24:44 -0300 | [diff] [blame] | 627 | ret = regulator_enable(tve->dac_reg); |
| 628 | if (ret) |
| 629 | return ret; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 632 | tve->clk = devm_clk_get(dev, "tve"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 633 | if (IS_ERR(tve->clk)) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 634 | dev_err(dev, "failed to get high speed tve clock: %ld\n", |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 635 | PTR_ERR(tve->clk)); |
| 636 | return PTR_ERR(tve->clk); |
| 637 | } |
| 638 | |
| 639 | /* this is the IPU DI clock input selector, can be parented to tve_di */ |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 640 | tve->di_sel_clk = devm_clk_get(dev, "di_sel"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 641 | if (IS_ERR(tve->di_sel_clk)) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 642 | dev_err(dev, "failed to get ipu di mux clock: %ld\n", |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 643 | PTR_ERR(tve->di_sel_clk)); |
| 644 | return PTR_ERR(tve->di_sel_clk); |
| 645 | } |
| 646 | |
| 647 | ret = tve_clk_init(tve, base); |
| 648 | if (ret < 0) |
| 649 | return ret; |
| 650 | |
| 651 | ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); |
| 652 | if (ret < 0) { |
Rene Kolarik | f582d9a | 2014-10-09 20:29:32 +0200 | [diff] [blame] | 653 | dev_err(dev, "failed to read configuration register: %d\n", |
| 654 | ret); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 655 | return ret; |
| 656 | } |
| 657 | if (val != 0x00100000) { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 658 | dev_err(dev, "configuration register default value indicates this is not a TVEv2\n"); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 659 | return -ENODEV; |
Joe Perches | a22526e | 2013-10-10 16:07:59 -0700 | [diff] [blame] | 660 | } |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 661 | |
| 662 | /* disable cable detection for VGA mode */ |
| 663 | ret = regmap_write(tve->regmap, TVE_CD_CONT_REG, 0); |
Fabio Estevam | f555e7e | 2015-01-20 20:44:07 -0200 | [diff] [blame] | 664 | if (ret) |
| 665 | return ret; |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 666 | |
Russell King | 1b3f767 | 2013-11-03 13:30:48 +0000 | [diff] [blame] | 667 | ret = imx_tve_register(drm, tve); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 668 | if (ret) |
| 669 | return ret; |
| 670 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 671 | dev_set_drvdata(dev, tve); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 676 | static void imx_tve_unbind(struct device *dev, struct device *master, |
| 677 | void *data) |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 678 | { |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 679 | struct imx_tve *tve = dev_get_drvdata(dev); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 680 | |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 681 | if (!IS_ERR(tve->dac_reg)) |
| 682 | regulator_disable(tve->dac_reg); |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 683 | } |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 684 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 685 | static const struct component_ops imx_tve_ops = { |
| 686 | .bind = imx_tve_bind, |
| 687 | .unbind = imx_tve_unbind, |
| 688 | }; |
| 689 | |
| 690 | static int imx_tve_probe(struct platform_device *pdev) |
| 691 | { |
| 692 | return component_add(&pdev->dev, &imx_tve_ops); |
| 693 | } |
| 694 | |
| 695 | static int imx_tve_remove(struct platform_device *pdev) |
| 696 | { |
| 697 | component_del(&pdev->dev, &imx_tve_ops); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | static const struct of_device_id imx_tve_dt_ids[] = { |
| 702 | { .compatible = "fsl,imx53-tve", }, |
| 703 | { /* sentinel */ } |
| 704 | }; |
Luis de Bethencourt | 5e4789d | 2015-11-30 15:02:44 +0000 | [diff] [blame] | 705 | MODULE_DEVICE_TABLE(of, imx_tve_dt_ids); |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 706 | |
| 707 | static struct platform_driver imx_tve_driver = { |
| 708 | .probe = imx_tve_probe, |
| 709 | .remove = imx_tve_remove, |
| 710 | .driver = { |
| 711 | .of_match_table = imx_tve_dt_ids, |
| 712 | .name = "imx-tve", |
Philipp Zabel | fcbc51e | 2013-04-08 18:04:38 +0200 | [diff] [blame] | 713 | }, |
| 714 | }; |
| 715 | |
| 716 | module_platform_driver(imx_tve_driver); |
| 717 | |
| 718 | MODULE_DESCRIPTION("i.MX Television Encoder driver"); |
| 719 | MODULE_AUTHOR("Philipp Zabel, Pengutronix"); |
| 720 | MODULE_LICENSE("GPL"); |
Fabio Estevam | 52db752c | 2013-08-18 21:40:04 -0300 | [diff] [blame] | 721 | MODULE_ALIAS("platform:imx-tve"); |