Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Eric Anholt <eric@anholt.net> |
| 19 | * Dave Airlie <airlied@linux.ie> |
| 20 | * Jesse Barnes <jesse.barnes@intel.com> |
| 21 | */ |
| 22 | |
| 23 | #include <linux/i2c.h> |
| 24 | #include <drm/drmP.h> |
| 25 | |
| 26 | #include "intel_bios.h" |
| 27 | #include "psb_drv.h" |
| 28 | #include "psb_intel_drv.h" |
| 29 | #include "psb_intel_reg.h" |
| 30 | #include "power.h" |
| 31 | #include <linux/pm_runtime.h> |
| 32 | |
| 33 | /* |
| 34 | * LVDS I2C backlight control macros |
| 35 | */ |
| 36 | #define BRIGHTNESS_MAX_LEVEL 100 |
| 37 | #define BRIGHTNESS_MASK 0xFF |
| 38 | #define BLC_I2C_TYPE 0x01 |
| 39 | #define BLC_PWM_TYPT 0x02 |
| 40 | |
| 41 | #define BLC_POLARITY_NORMAL 0 |
| 42 | #define BLC_POLARITY_INVERSE 1 |
| 43 | |
| 44 | #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE) |
| 45 | #define PSB_BLC_MIN_PWM_REG_FREQ (0x2) |
| 46 | #define PSB_BLC_PWM_PRECISION_FACTOR (10) |
| 47 | #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16) |
| 48 | #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE) |
| 49 | |
| 50 | struct psb_intel_lvds_priv { |
| 51 | /* |
| 52 | * Saved LVDO output states |
| 53 | */ |
| 54 | uint32_t savePP_ON; |
| 55 | uint32_t savePP_OFF; |
| 56 | uint32_t saveLVDS; |
| 57 | uint32_t savePP_CONTROL; |
| 58 | uint32_t savePP_CYCLE; |
| 59 | uint32_t savePFIT_CONTROL; |
| 60 | uint32_t savePFIT_PGM_RATIOS; |
| 61 | uint32_t saveBLC_PWM_CTL; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 62 | |
| 63 | struct psb_intel_i2c_chan *i2c_bus; |
| 64 | struct psb_intel_i2c_chan *ddc_bus; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | |
| 68 | /* |
| 69 | * Returns the maximum level of the backlight duty cycle field. |
| 70 | */ |
| 71 | static u32 psb_intel_lvds_get_max_backlight(struct drm_device *dev) |
| 72 | { |
| 73 | struct drm_psb_private *dev_priv = dev->dev_private; |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 74 | u32 ret; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 75 | |
| 76 | if (gma_power_begin(dev, false)) { |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 77 | ret = REG_READ(BLC_PWM_CTL); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 78 | gma_power_end(dev); |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 79 | } else /* Powered off, use the saved value */ |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 80 | ret = dev_priv->regs.saveBLC_PWM_CTL; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 81 | |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 82 | /* Top 15bits hold the frequency mask */ |
| 83 | ret = (ret & BACKLIGHT_MODULATION_FREQ_MASK) >> |
| 84 | BACKLIGHT_MODULATION_FREQ_SHIFT; |
| 85 | |
| 86 | ret *= 2; /* Return a 16bit range as needed for setting */ |
| 87 | if (ret == 0) |
| 88 | dev_err(dev->dev, "BL bug: Reg %08x save %08X\n", |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 89 | REG_READ(BLC_PWM_CTL), dev_priv->regs.saveBLC_PWM_CTL); |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 90 | return ret; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Set LVDS backlight level by I2C command |
| 95 | * |
| 96 | * FIXME: at some point we need to both track this for PM and also |
| 97 | * disable runtime pm on MRST if the brightness is nil (ie blanked) |
| 98 | */ |
| 99 | static int psb_lvds_i2c_set_brightness(struct drm_device *dev, |
| 100 | unsigned int level) |
| 101 | { |
| 102 | struct drm_psb_private *dev_priv = |
| 103 | (struct drm_psb_private *)dev->dev_private; |
| 104 | |
| 105 | struct psb_intel_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus; |
| 106 | u8 out_buf[2]; |
| 107 | unsigned int blc_i2c_brightness; |
| 108 | |
| 109 | struct i2c_msg msgs[] = { |
| 110 | { |
| 111 | .addr = lvds_i2c_bus->slave_addr, |
| 112 | .flags = 0, |
| 113 | .len = 2, |
| 114 | .buf = out_buf, |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | blc_i2c_brightness = BRIGHTNESS_MASK & ((unsigned int)level * |
| 119 | BRIGHTNESS_MASK / |
| 120 | BRIGHTNESS_MAX_LEVEL); |
| 121 | |
| 122 | if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) |
| 123 | blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness; |
| 124 | |
| 125 | out_buf[0] = dev_priv->lvds_bl->brightnesscmd; |
| 126 | out_buf[1] = (u8)blc_i2c_brightness; |
| 127 | |
| 128 | if (i2c_transfer(&lvds_i2c_bus->adapter, msgs, 1) == 1) { |
| 129 | dev_dbg(dev->dev, "I2C set brightness.(command, value) (%d, %d)\n", |
| 130 | dev_priv->lvds_bl->brightnesscmd, |
| 131 | blc_i2c_brightness); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | dev_err(dev->dev, "I2C transfer error\n"); |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | static int psb_lvds_pwm_set_brightness(struct drm_device *dev, int level) |
| 141 | { |
| 142 | struct drm_psb_private *dev_priv = |
| 143 | (struct drm_psb_private *)dev->dev_private; |
| 144 | |
| 145 | u32 max_pwm_blc; |
| 146 | u32 blc_pwm_duty_cycle; |
| 147 | |
| 148 | max_pwm_blc = psb_intel_lvds_get_max_backlight(dev); |
| 149 | |
| 150 | /*BLC_PWM_CTL Should be initiated while backlight device init*/ |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 151 | BUG_ON(max_pwm_blc == 0); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 152 | |
| 153 | blc_pwm_duty_cycle = level * max_pwm_blc / BRIGHTNESS_MAX_LEVEL; |
| 154 | |
| 155 | if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) |
| 156 | blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle; |
| 157 | |
| 158 | blc_pwm_duty_cycle &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR; |
| 159 | REG_WRITE(BLC_PWM_CTL, |
| 160 | (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) | |
| 161 | (blc_pwm_duty_cycle)); |
| 162 | |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 163 | dev_info(dev->dev, "Backlight lvds set brightness %08x\n", |
| 164 | (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) | |
| 165 | (blc_pwm_duty_cycle)); |
| 166 | |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Set LVDS backlight level either by I2C or PWM |
| 172 | */ |
| 173 | void psb_intel_lvds_set_brightness(struct drm_device *dev, int level) |
| 174 | { |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 175 | struct drm_psb_private *dev_priv = dev->dev_private; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 176 | |
| 177 | dev_dbg(dev->dev, "backlight level is %d\n", level); |
| 178 | |
| 179 | if (!dev_priv->lvds_bl) { |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 180 | dev_err(dev->dev, "NO LVDS backlight info\n"); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | if (dev_priv->lvds_bl->type == BLC_I2C_TYPE) |
| 185 | psb_lvds_i2c_set_brightness(dev, level); |
| 186 | else |
| 187 | psb_lvds_pwm_set_brightness(dev, level); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Sets the backlight level. |
| 192 | * |
| 193 | * level: backlight level, from 0 to psb_intel_lvds_get_max_backlight(). |
| 194 | */ |
| 195 | static void psb_intel_lvds_set_backlight(struct drm_device *dev, int level) |
| 196 | { |
| 197 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 198 | u32 blc_pwm_ctl; |
| 199 | |
| 200 | if (gma_power_begin(dev, false)) { |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 201 | blc_pwm_ctl = REG_READ(BLC_PWM_CTL); |
| 202 | blc_pwm_ctl &= ~BACKLIGHT_DUTY_CYCLE_MASK; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 203 | REG_WRITE(BLC_PWM_CTL, |
| 204 | (blc_pwm_ctl | |
| 205 | (level << BACKLIGHT_DUTY_CYCLE_SHIFT))); |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 206 | dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl | |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 207 | (level << BACKLIGHT_DUTY_CYCLE_SHIFT)); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 208 | gma_power_end(dev); |
| 209 | } else { |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 210 | blc_pwm_ctl = dev_priv->regs.saveBLC_PWM_CTL & |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 211 | ~BACKLIGHT_DUTY_CYCLE_MASK; |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 212 | dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl | |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 213 | (level << BACKLIGHT_DUTY_CYCLE_SHIFT)); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Sets the power state for the panel. |
| 219 | */ |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 220 | static void psb_intel_lvds_set_power(struct drm_device *dev, bool on) |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 221 | { |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 222 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 223 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 224 | u32 pp_status; |
| 225 | |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 226 | if (!gma_power_begin(dev, true)) { |
| 227 | dev_err(dev->dev, "set power, chip off!\n"); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 228 | return; |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 231 | if (on) { |
| 232 | REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | |
| 233 | POWER_TARGET_ON); |
| 234 | do { |
| 235 | pp_status = REG_READ(PP_STATUS); |
| 236 | } while ((pp_status & PP_ON) == 0); |
| 237 | |
| 238 | psb_intel_lvds_set_backlight(dev, |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 239 | mode_dev->backlight_duty_cycle); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 240 | } else { |
| 241 | psb_intel_lvds_set_backlight(dev, 0); |
| 242 | |
| 243 | REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & |
| 244 | ~POWER_TARGET_ON); |
| 245 | do { |
| 246 | pp_status = REG_READ(PP_STATUS); |
| 247 | } while (pp_status & PP_ON); |
| 248 | } |
| 249 | |
| 250 | gma_power_end(dev); |
| 251 | } |
| 252 | |
| 253 | static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 254 | { |
| 255 | struct drm_device *dev = encoder->dev; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 256 | |
| 257 | if (mode == DRM_MODE_DPMS_ON) |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 258 | psb_intel_lvds_set_power(dev, true); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 259 | else |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 260 | psb_intel_lvds_set_power(dev, false); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 261 | |
| 262 | /* XXX: We never power down the LVDS pairs. */ |
| 263 | } |
| 264 | |
| 265 | static void psb_intel_lvds_save(struct drm_connector *connector) |
| 266 | { |
| 267 | struct drm_device *dev = connector->dev; |
| 268 | struct drm_psb_private *dev_priv = |
| 269 | (struct drm_psb_private *)dev->dev_private; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 270 | struct psb_intel_encoder *psb_intel_encoder = |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 271 | gma_attached_encoder(connector); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 272 | struct psb_intel_lvds_priv *lvds_priv = |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 273 | (struct psb_intel_lvds_priv *)psb_intel_encoder->dev_priv; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 274 | |
| 275 | lvds_priv->savePP_ON = REG_READ(LVDSPP_ON); |
| 276 | lvds_priv->savePP_OFF = REG_READ(LVDSPP_OFF); |
| 277 | lvds_priv->saveLVDS = REG_READ(LVDS); |
| 278 | lvds_priv->savePP_CONTROL = REG_READ(PP_CONTROL); |
| 279 | lvds_priv->savePP_CYCLE = REG_READ(PP_CYCLE); |
| 280 | /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/ |
| 281 | lvds_priv->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); |
| 282 | lvds_priv->savePFIT_CONTROL = REG_READ(PFIT_CONTROL); |
| 283 | lvds_priv->savePFIT_PGM_RATIOS = REG_READ(PFIT_PGM_RATIOS); |
| 284 | |
| 285 | /*TODO: move backlight_duty_cycle to psb_intel_lvds_priv*/ |
Alan Cox | 648a8e3 | 2012-03-08 16:00:31 +0000 | [diff] [blame] | 286 | dev_priv->backlight_duty_cycle = (dev_priv->regs.saveBLC_PWM_CTL & |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 287 | BACKLIGHT_DUTY_CYCLE_MASK); |
| 288 | |
| 289 | /* |
| 290 | * If the light is off at server startup, |
| 291 | * just make it full brightness |
| 292 | */ |
| 293 | if (dev_priv->backlight_duty_cycle == 0) |
| 294 | dev_priv->backlight_duty_cycle = |
| 295 | psb_intel_lvds_get_max_backlight(dev); |
| 296 | |
| 297 | dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", |
| 298 | lvds_priv->savePP_ON, |
| 299 | lvds_priv->savePP_OFF, |
| 300 | lvds_priv->saveLVDS, |
| 301 | lvds_priv->savePP_CONTROL, |
| 302 | lvds_priv->savePP_CYCLE, |
| 303 | lvds_priv->saveBLC_PWM_CTL); |
| 304 | } |
| 305 | |
| 306 | static void psb_intel_lvds_restore(struct drm_connector *connector) |
| 307 | { |
| 308 | struct drm_device *dev = connector->dev; |
| 309 | u32 pp_status; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 310 | struct psb_intel_encoder *psb_intel_encoder = |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 311 | gma_attached_encoder(connector); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 312 | struct psb_intel_lvds_priv *lvds_priv = |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 313 | (struct psb_intel_lvds_priv *)psb_intel_encoder->dev_priv; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 314 | |
| 315 | dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", |
| 316 | lvds_priv->savePP_ON, |
| 317 | lvds_priv->savePP_OFF, |
| 318 | lvds_priv->saveLVDS, |
| 319 | lvds_priv->savePP_CONTROL, |
| 320 | lvds_priv->savePP_CYCLE, |
| 321 | lvds_priv->saveBLC_PWM_CTL); |
| 322 | |
| 323 | REG_WRITE(BLC_PWM_CTL, lvds_priv->saveBLC_PWM_CTL); |
| 324 | REG_WRITE(PFIT_CONTROL, lvds_priv->savePFIT_CONTROL); |
| 325 | REG_WRITE(PFIT_PGM_RATIOS, lvds_priv->savePFIT_PGM_RATIOS); |
| 326 | REG_WRITE(LVDSPP_ON, lvds_priv->savePP_ON); |
| 327 | REG_WRITE(LVDSPP_OFF, lvds_priv->savePP_OFF); |
| 328 | /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/ |
| 329 | REG_WRITE(PP_CYCLE, lvds_priv->savePP_CYCLE); |
| 330 | REG_WRITE(PP_CONTROL, lvds_priv->savePP_CONTROL); |
| 331 | REG_WRITE(LVDS, lvds_priv->saveLVDS); |
| 332 | |
| 333 | if (lvds_priv->savePP_CONTROL & POWER_TARGET_ON) { |
| 334 | REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | |
| 335 | POWER_TARGET_ON); |
| 336 | do { |
| 337 | pp_status = REG_READ(PP_STATUS); |
| 338 | } while ((pp_status & PP_ON) == 0); |
| 339 | } else { |
| 340 | REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & |
| 341 | ~POWER_TARGET_ON); |
| 342 | do { |
| 343 | pp_status = REG_READ(PP_STATUS); |
| 344 | } while (pp_status & PP_ON); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | int psb_intel_lvds_mode_valid(struct drm_connector *connector, |
| 349 | struct drm_display_mode *mode) |
| 350 | { |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 351 | struct drm_psb_private *dev_priv = connector->dev->dev_private; |
| 352 | struct psb_intel_encoder *psb_intel_encoder = |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 353 | gma_attached_encoder(connector); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 354 | struct drm_display_mode *fixed_mode = |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 355 | dev_priv->mode_dev.panel_fixed_mode; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 356 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 357 | if (psb_intel_encoder->type == INTEL_OUTPUT_MIPI2) |
| 358 | fixed_mode = dev_priv->mode_dev.panel_fixed_mode2; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 359 | |
| 360 | /* just in case */ |
| 361 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 362 | return MODE_NO_DBLESCAN; |
| 363 | |
| 364 | /* just in case */ |
| 365 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 366 | return MODE_NO_INTERLACE; |
| 367 | |
| 368 | if (fixed_mode) { |
| 369 | if (mode->hdisplay > fixed_mode->hdisplay) |
| 370 | return MODE_PANEL; |
| 371 | if (mode->vdisplay > fixed_mode->vdisplay) |
| 372 | return MODE_PANEL; |
| 373 | } |
| 374 | return MODE_OK; |
| 375 | } |
| 376 | |
| 377 | bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 378 | const struct drm_display_mode *mode, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 379 | struct drm_display_mode *adjusted_mode) |
| 380 | { |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 381 | struct drm_device *dev = encoder->dev; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 382 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 383 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame^] | 384 | struct gma_crtc *gma_crtc = to_gma_crtc(encoder->crtc); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 385 | struct drm_encoder *tmp_encoder; |
| 386 | struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 387 | struct psb_intel_encoder *psb_intel_encoder = |
| 388 | to_psb_intel_encoder(encoder); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 389 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 390 | if (psb_intel_encoder->type == INTEL_OUTPUT_MIPI2) |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 391 | panel_fixed_mode = mode_dev->panel_fixed_mode2; |
| 392 | |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 393 | /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */ |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame^] | 394 | if (!IS_MRST(dev) && gma_crtc->pipe == 0) { |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 395 | printk(KERN_ERR "Can't support LVDS on pipe A\n"); |
| 396 | return false; |
| 397 | } |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame^] | 398 | if (IS_MRST(dev) && gma_crtc->pipe != 0) { |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 399 | printk(KERN_ERR "Must use PIPE A\n"); |
| 400 | return false; |
| 401 | } |
| 402 | /* Should never happen!! */ |
| 403 | list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, |
| 404 | head) { |
| 405 | if (tmp_encoder != encoder |
| 406 | && tmp_encoder->crtc == encoder->crtc) { |
| 407 | printk(KERN_ERR "Can't enable LVDS and another " |
| 408 | "encoder on the same pipe\n"); |
| 409 | return false; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * If we have timings from the BIOS for the panel, put them in |
| 415 | * to the adjusted mode. The CRTC will be set up for this mode, |
| 416 | * with the panel scaling set up to source from the H/VDisplay |
| 417 | * of the original mode. |
| 418 | */ |
| 419 | if (panel_fixed_mode != NULL) { |
| 420 | adjusted_mode->hdisplay = panel_fixed_mode->hdisplay; |
| 421 | adjusted_mode->hsync_start = panel_fixed_mode->hsync_start; |
| 422 | adjusted_mode->hsync_end = panel_fixed_mode->hsync_end; |
| 423 | adjusted_mode->htotal = panel_fixed_mode->htotal; |
| 424 | adjusted_mode->vdisplay = panel_fixed_mode->vdisplay; |
| 425 | adjusted_mode->vsync_start = panel_fixed_mode->vsync_start; |
| 426 | adjusted_mode->vsync_end = panel_fixed_mode->vsync_end; |
| 427 | adjusted_mode->vtotal = panel_fixed_mode->vtotal; |
| 428 | adjusted_mode->clock = panel_fixed_mode->clock; |
| 429 | drm_mode_set_crtcinfo(adjusted_mode, |
| 430 | CRTC_INTERLACE_HALVE_V); |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * XXX: It would be nice to support lower refresh rates on the |
| 435 | * panels to reduce power consumption, and perhaps match the |
| 436 | * user's requested refresh rate. |
| 437 | */ |
| 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | static void psb_intel_lvds_prepare(struct drm_encoder *encoder) |
| 443 | { |
| 444 | struct drm_device *dev = encoder->dev; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 445 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 446 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 447 | |
| 448 | if (!gma_power_begin(dev, true)) |
| 449 | return; |
| 450 | |
| 451 | mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); |
| 452 | mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL & |
| 453 | BACKLIGHT_DUTY_CYCLE_MASK); |
| 454 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 455 | psb_intel_lvds_set_power(dev, false); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 456 | |
| 457 | gma_power_end(dev); |
| 458 | } |
| 459 | |
| 460 | static void psb_intel_lvds_commit(struct drm_encoder *encoder) |
| 461 | { |
| 462 | struct drm_device *dev = encoder->dev; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 463 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 464 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 465 | |
| 466 | if (mode_dev->backlight_duty_cycle == 0) |
| 467 | mode_dev->backlight_duty_cycle = |
| 468 | psb_intel_lvds_get_max_backlight(dev); |
| 469 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 470 | psb_intel_lvds_set_power(dev, true); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void psb_intel_lvds_mode_set(struct drm_encoder *encoder, |
| 474 | struct drm_display_mode *mode, |
| 475 | struct drm_display_mode *adjusted_mode) |
| 476 | { |
| 477 | struct drm_device *dev = encoder->dev; |
| 478 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 479 | u32 pfit_control; |
| 480 | |
| 481 | /* |
| 482 | * The LVDS pin pair will already have been turned on in the |
| 483 | * psb_intel_crtc_mode_set since it has a large impact on the DPLL |
| 484 | * settings. |
| 485 | */ |
| 486 | |
| 487 | /* |
| 488 | * Enable automatic panel scaling so that non-native modes fill the |
| 489 | * screen. Should be enabled before the pipe is enabled, according to |
| 490 | * register description and PRM. |
| 491 | */ |
| 492 | if (mode->hdisplay != adjusted_mode->hdisplay || |
| 493 | mode->vdisplay != adjusted_mode->vdisplay) |
| 494 | pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE | |
| 495 | HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR | |
| 496 | HORIZ_INTERP_BILINEAR); |
| 497 | else |
| 498 | pfit_control = 0; |
| 499 | |
| 500 | if (dev_priv->lvds_dither) |
| 501 | pfit_control |= PANEL_8TO6_DITHER_ENABLE; |
| 502 | |
| 503 | REG_WRITE(PFIT_CONTROL, pfit_control); |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Detect the LVDS connection. |
| 508 | * |
| 509 | * This always returns CONNECTOR_STATUS_CONNECTED. |
| 510 | * This connector should only have |
| 511 | * been set up if the LVDS was actually connected anyway. |
| 512 | */ |
| 513 | static enum drm_connector_status psb_intel_lvds_detect(struct drm_connector |
| 514 | *connector, bool force) |
| 515 | { |
| 516 | return connector_status_connected; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Return the list of DDC modes if available, or the BIOS fixed mode otherwise. |
| 521 | */ |
| 522 | static int psb_intel_lvds_get_modes(struct drm_connector *connector) |
| 523 | { |
| 524 | struct drm_device *dev = connector->dev; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 525 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 526 | struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; |
| 527 | struct psb_intel_encoder *psb_intel_encoder = |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 528 | gma_attached_encoder(connector); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 529 | struct psb_intel_lvds_priv *lvds_priv = psb_intel_encoder->dev_priv; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 530 | int ret = 0; |
| 531 | |
| 532 | if (!IS_MRST(dev)) |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 533 | ret = psb_intel_ddc_get_modes(connector, &lvds_priv->i2c_bus->adapter); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 534 | |
| 535 | if (ret) |
| 536 | return ret; |
| 537 | |
| 538 | /* Didn't get an EDID, so |
| 539 | * Set wide sync ranges so we get all modes |
| 540 | * handed to valid_mode for checking |
| 541 | */ |
| 542 | connector->display_info.min_vfreq = 0; |
| 543 | connector->display_info.max_vfreq = 200; |
| 544 | connector->display_info.min_hfreq = 0; |
| 545 | connector->display_info.max_hfreq = 200; |
| 546 | |
| 547 | if (mode_dev->panel_fixed_mode != NULL) { |
| 548 | struct drm_display_mode *mode = |
| 549 | drm_mode_duplicate(dev, mode_dev->panel_fixed_mode); |
| 550 | drm_mode_probed_add(connector, mode); |
| 551 | return 1; |
| 552 | } |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * psb_intel_lvds_destroy - unregister and free LVDS structures |
| 559 | * @connector: connector to free |
| 560 | * |
| 561 | * Unregister the DDC bus for this connector then free the driver private |
| 562 | * structure. |
| 563 | */ |
| 564 | void psb_intel_lvds_destroy(struct drm_connector *connector) |
| 565 | { |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 566 | struct psb_intel_encoder *psb_intel_encoder = |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 567 | gma_attached_encoder(connector); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 568 | struct psb_intel_lvds_priv *lvds_priv = psb_intel_encoder->dev_priv; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 569 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 570 | if (lvds_priv->ddc_bus) |
| 571 | psb_intel_i2c_destroy(lvds_priv->ddc_bus); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 572 | drm_sysfs_connector_remove(connector); |
| 573 | drm_connector_cleanup(connector); |
| 574 | kfree(connector); |
| 575 | } |
| 576 | |
| 577 | int psb_intel_lvds_set_property(struct drm_connector *connector, |
| 578 | struct drm_property *property, |
| 579 | uint64_t value) |
| 580 | { |
| 581 | struct drm_encoder *encoder = connector->encoder; |
| 582 | |
| 583 | if (!encoder) |
| 584 | return -1; |
| 585 | |
| 586 | if (!strcmp(property->name, "scaling mode")) { |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame^] | 587 | struct gma_crtc *crtc = to_gma_crtc(encoder->crtc); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 588 | uint64_t curval; |
| 589 | |
| 590 | if (!crtc) |
| 591 | goto set_prop_error; |
| 592 | |
| 593 | switch (value) { |
| 594 | case DRM_MODE_SCALE_FULLSCREEN: |
| 595 | break; |
| 596 | case DRM_MODE_SCALE_NO_SCALE: |
| 597 | break; |
| 598 | case DRM_MODE_SCALE_ASPECT: |
| 599 | break; |
| 600 | default: |
| 601 | goto set_prop_error; |
| 602 | } |
| 603 | |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 604 | if (drm_object_property_get_value(&connector->base, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 605 | property, |
| 606 | &curval)) |
| 607 | goto set_prop_error; |
| 608 | |
| 609 | if (curval == value) |
| 610 | goto set_prop_done; |
| 611 | |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 612 | if (drm_object_property_set_value(&connector->base, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 613 | property, |
| 614 | value)) |
| 615 | goto set_prop_error; |
| 616 | |
| 617 | if (crtc->saved_mode.hdisplay != 0 && |
| 618 | crtc->saved_mode.vdisplay != 0) { |
| 619 | if (!drm_crtc_helper_set_mode(encoder->crtc, |
| 620 | &crtc->saved_mode, |
| 621 | encoder->crtc->x, |
| 622 | encoder->crtc->y, |
| 623 | encoder->crtc->fb)) |
| 624 | goto set_prop_error; |
| 625 | } |
| 626 | } else if (!strcmp(property->name, "backlight")) { |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 627 | if (drm_object_property_set_value(&connector->base, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 628 | property, |
| 629 | value)) |
| 630 | goto set_prop_error; |
Zhao Yakui | d112a81 | 2012-08-08 13:55:55 +0000 | [diff] [blame] | 631 | else |
| 632 | gma_backlight_set(encoder->dev, value); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 633 | } else if (!strcmp(property->name, "DPMS")) { |
| 634 | struct drm_encoder_helper_funcs *hfuncs |
| 635 | = encoder->helper_private; |
| 636 | hfuncs->dpms(encoder, value); |
| 637 | } |
| 638 | |
| 639 | set_prop_done: |
| 640 | return 0; |
| 641 | set_prop_error: |
| 642 | return -1; |
| 643 | } |
| 644 | |
| 645 | static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs = { |
| 646 | .dpms = psb_intel_lvds_encoder_dpms, |
| 647 | .mode_fixup = psb_intel_lvds_mode_fixup, |
| 648 | .prepare = psb_intel_lvds_prepare, |
| 649 | .mode_set = psb_intel_lvds_mode_set, |
| 650 | .commit = psb_intel_lvds_commit, |
| 651 | }; |
| 652 | |
| 653 | const struct drm_connector_helper_funcs |
| 654 | psb_intel_lvds_connector_helper_funcs = { |
| 655 | .get_modes = psb_intel_lvds_get_modes, |
| 656 | .mode_valid = psb_intel_lvds_mode_valid, |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 657 | .best_encoder = gma_best_encoder, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | const struct drm_connector_funcs psb_intel_lvds_connector_funcs = { |
| 661 | .dpms = drm_helper_connector_dpms, |
| 662 | .save = psb_intel_lvds_save, |
| 663 | .restore = psb_intel_lvds_restore, |
| 664 | .detect = psb_intel_lvds_detect, |
| 665 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 666 | .set_property = psb_intel_lvds_set_property, |
| 667 | .destroy = psb_intel_lvds_destroy, |
| 668 | }; |
| 669 | |
| 670 | |
| 671 | static void psb_intel_lvds_enc_destroy(struct drm_encoder *encoder) |
| 672 | { |
| 673 | drm_encoder_cleanup(encoder); |
| 674 | } |
| 675 | |
| 676 | const struct drm_encoder_funcs psb_intel_lvds_enc_funcs = { |
| 677 | .destroy = psb_intel_lvds_enc_destroy, |
| 678 | }; |
| 679 | |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * psb_intel_lvds_init - setup LVDS connectors on this device |
| 684 | * @dev: drm device |
| 685 | * |
| 686 | * Create the connector, register the LVDS DDC bus, and try to figure out what |
| 687 | * modes we can display on the LVDS panel (if present). |
| 688 | */ |
| 689 | void psb_intel_lvds_init(struct drm_device *dev, |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 690 | struct psb_intel_mode_device *mode_dev) |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 691 | { |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 692 | struct psb_intel_encoder *psb_intel_encoder; |
| 693 | struct psb_intel_connector *psb_intel_connector; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 694 | struct psb_intel_lvds_priv *lvds_priv; |
| 695 | struct drm_connector *connector; |
| 696 | struct drm_encoder *encoder; |
| 697 | struct drm_display_mode *scan; /* *modes, *bios_mode; */ |
| 698 | struct drm_crtc *crtc; |
Alan Cox | 1f0d0b5 | 2011-11-29 22:26:58 +0000 | [diff] [blame] | 699 | struct drm_psb_private *dev_priv = dev->dev_private; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 700 | u32 lvds; |
| 701 | int pipe; |
| 702 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 703 | psb_intel_encoder = |
| 704 | kzalloc(sizeof(struct psb_intel_encoder), GFP_KERNEL); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 705 | if (!psb_intel_encoder) { |
| 706 | dev_err(dev->dev, "psb_intel_encoder allocation error\n"); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 707 | return; |
| 708 | } |
| 709 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 710 | psb_intel_connector = |
| 711 | kzalloc(sizeof(struct psb_intel_connector), GFP_KERNEL); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 712 | if (!psb_intel_connector) { |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 713 | dev_err(dev->dev, "psb_intel_connector allocation error\n"); |
Jesper Juhl | aa7c62a | 2012-03-08 16:00:58 +0000 | [diff] [blame] | 714 | goto failed_encoder; |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | lvds_priv = kzalloc(sizeof(struct psb_intel_lvds_priv), GFP_KERNEL); |
| 718 | if (!lvds_priv) { |
| 719 | dev_err(dev->dev, "LVDS private allocation error\n"); |
| 720 | goto failed_connector; |
| 721 | } |
| 722 | |
| 723 | psb_intel_encoder->dev_priv = lvds_priv; |
| 724 | |
| 725 | connector = &psb_intel_connector->base; |
| 726 | encoder = &psb_intel_encoder->base; |
| 727 | drm_connector_init(dev, connector, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 728 | &psb_intel_lvds_connector_funcs, |
| 729 | DRM_MODE_CONNECTOR_LVDS); |
| 730 | |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 731 | drm_encoder_init(dev, encoder, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 732 | &psb_intel_lvds_enc_funcs, |
| 733 | DRM_MODE_ENCODER_LVDS); |
| 734 | |
Patrik Jakobsson | c9d4959 | 2013-07-11 01:02:01 +0200 | [diff] [blame] | 735 | gma_connector_attach_encoder(psb_intel_connector, psb_intel_encoder); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 736 | psb_intel_encoder->type = INTEL_OUTPUT_LVDS; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 737 | |
| 738 | drm_encoder_helper_add(encoder, &psb_intel_lvds_helper_funcs); |
| 739 | drm_connector_helper_add(connector, |
| 740 | &psb_intel_lvds_connector_helper_funcs); |
| 741 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; |
| 742 | connector->interlace_allowed = false; |
| 743 | connector->doublescan_allowed = false; |
| 744 | |
| 745 | /*Attach connector properties*/ |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 746 | drm_object_attach_property(&connector->base, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 747 | dev->mode_config.scaling_mode_property, |
| 748 | DRM_MODE_SCALE_FULLSCREEN); |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 749 | drm_object_attach_property(&connector->base, |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 750 | dev_priv->backlight_property, |
| 751 | BRIGHTNESS_MAX_LEVEL); |
| 752 | |
| 753 | /* |
| 754 | * Set up I2C bus |
| 755 | * FIXME: distroy i2c_bus when exit |
| 756 | */ |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 757 | lvds_priv->i2c_bus = psb_intel_i2c_create(dev, GPIOB, "LVDSBLC_B"); |
| 758 | if (!lvds_priv->i2c_bus) { |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 759 | dev_printk(KERN_ERR, |
| 760 | &dev->pdev->dev, "I2C bus registration failed.\n"); |
| 761 | goto failed_blc_i2c; |
| 762 | } |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 763 | lvds_priv->i2c_bus->slave_addr = 0x2C; |
| 764 | dev_priv->lvds_i2c_bus = lvds_priv->i2c_bus; |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 765 | |
| 766 | /* |
| 767 | * LVDS discovery: |
| 768 | * 1) check for EDID on DDC |
| 769 | * 2) check for VBT data |
| 770 | * 3) check to see if LVDS is already on |
| 771 | * if none of the above, no panel |
| 772 | * 4) make sure lid is open |
| 773 | * if closed, act like it's not there for now |
| 774 | */ |
| 775 | |
| 776 | /* Set up the DDC bus. */ |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 777 | lvds_priv->ddc_bus = psb_intel_i2c_create(dev, GPIOC, "LVDSDDC_C"); |
| 778 | if (!lvds_priv->ddc_bus) { |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 779 | dev_printk(KERN_ERR, &dev->pdev->dev, |
| 780 | "DDC bus registration " "failed.\n"); |
| 781 | goto failed_ddc; |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * Attempt to get the fixed panel mode from DDC. Assume that the |
| 786 | * preferred mode is the right one. |
| 787 | */ |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 788 | psb_intel_ddc_get_modes(connector, &lvds_priv->ddc_bus->adapter); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 789 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 790 | if (scan->type & DRM_MODE_TYPE_PREFERRED) { |
| 791 | mode_dev->panel_fixed_mode = |
| 792 | drm_mode_duplicate(dev, scan); |
| 793 | goto out; /* FIXME: check for quirks */ |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | /* Failed to get EDID, what about VBT? do we need this? */ |
| 798 | if (mode_dev->vbt_mode) |
| 799 | mode_dev->panel_fixed_mode = |
| 800 | drm_mode_duplicate(dev, mode_dev->vbt_mode); |
| 801 | |
| 802 | if (!mode_dev->panel_fixed_mode) |
| 803 | if (dev_priv->lfp_lvds_vbt_mode) |
| 804 | mode_dev->panel_fixed_mode = |
| 805 | drm_mode_duplicate(dev, |
| 806 | dev_priv->lfp_lvds_vbt_mode); |
| 807 | |
| 808 | /* |
| 809 | * If we didn't get EDID, try checking if the panel is already turned |
| 810 | * on. If so, assume that whatever is currently programmed is the |
| 811 | * correct mode. |
| 812 | */ |
| 813 | lvds = REG_READ(LVDS); |
| 814 | pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0; |
| 815 | crtc = psb_intel_get_crtc_from_pipe(dev, pipe); |
| 816 | |
| 817 | if (crtc && (lvds & LVDS_PORT_EN)) { |
| 818 | mode_dev->panel_fixed_mode = |
| 819 | psb_intel_crtc_mode_get(dev, crtc); |
| 820 | if (mode_dev->panel_fixed_mode) { |
| 821 | mode_dev->panel_fixed_mode->type |= |
| 822 | DRM_MODE_TYPE_PREFERRED; |
| 823 | goto out; /* FIXME: check for quirks */ |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | /* If we still don't have a mode after all that, give up. */ |
| 828 | if (!mode_dev->panel_fixed_mode) { |
| 829 | dev_err(dev->dev, "Found no modes on the lvds, ignoring the LVDS\n"); |
| 830 | goto failed_find; |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Blacklist machines with BIOSes that list an LVDS panel without |
| 835 | * actually having one. |
| 836 | */ |
| 837 | out: |
| 838 | drm_sysfs_connector_add(connector); |
| 839 | return; |
| 840 | |
| 841 | failed_find: |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 842 | if (lvds_priv->ddc_bus) |
| 843 | psb_intel_i2c_destroy(lvds_priv->ddc_bus); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 844 | failed_ddc: |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 845 | if (lvds_priv->i2c_bus) |
| 846 | psb_intel_i2c_destroy(lvds_priv->i2c_bus); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 847 | failed_blc_i2c: |
| 848 | drm_encoder_cleanup(encoder); |
| 849 | drm_connector_cleanup(connector); |
Patrik Jakobsson | 9c8cee4 | 2011-12-19 21:40:45 +0000 | [diff] [blame] | 850 | failed_connector: |
Jesper Juhl | aa7c62a | 2012-03-08 16:00:58 +0000 | [diff] [blame] | 851 | kfree(psb_intel_connector); |
| 852 | failed_encoder: |
| 853 | kfree(psb_intel_encoder); |
Alan Cox | 89c7813 | 2011-11-03 18:22:15 +0000 | [diff] [blame] | 854 | } |
| 855 | |