Lines Matching +full:ddc +full:- +full:i2c +full:- +full:bus

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2006-2007 Intel Corporation
11 #include <linux/i2c.h>
25 * LVDS I2C backlight control macros
70 ret = dev_priv->regs.saveBLC_PWM_CTL; in psb_intel_lvds_get_max_backlight()
78 dev_err(dev->dev, "BL bug: Reg %08x save %08X\n", in psb_intel_lvds_get_max_backlight()
79 REG_READ(BLC_PWM_CTL), dev_priv->regs.saveBLC_PWM_CTL); in psb_intel_lvds_get_max_backlight()
84 * Set LVDS backlight level by I2C command
94 struct gma_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus; in psb_lvds_i2c_set_brightness()
100 .addr = lvds_i2c_bus->target_addr, in psb_lvds_i2c_set_brightness()
111 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) in psb_lvds_i2c_set_brightness()
112 blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness; in psb_lvds_i2c_set_brightness()
114 out_buf[0] = dev_priv->lvds_bl->brightnesscmd; in psb_lvds_i2c_set_brightness()
117 if (i2c_transfer(&lvds_i2c_bus->base, msgs, 1) == 1) { in psb_lvds_i2c_set_brightness()
118 dev_dbg(dev->dev, "I2C set brightness.(command, value) (%d, %d)\n", in psb_lvds_i2c_set_brightness()
119 dev_priv->lvds_bl->brightnesscmd, in psb_lvds_i2c_set_brightness()
124 dev_err(dev->dev, "I2C transfer error\n"); in psb_lvds_i2c_set_brightness()
125 return -1; in psb_lvds_i2c_set_brightness()
143 if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) in psb_lvds_pwm_set_brightness()
144 blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle; in psb_lvds_pwm_set_brightness()
151 dev_info(dev->dev, "Backlight lvds set brightness %08x\n", in psb_lvds_pwm_set_brightness()
159 * Set LVDS backlight level either by I2C or PWM
165 dev_dbg(dev->dev, "backlight level is %d\n", level); in psb_intel_lvds_set_brightness()
167 if (!dev_priv->lvds_bl) { in psb_intel_lvds_set_brightness()
168 dev_err(dev->dev, "NO LVDS backlight info\n"); in psb_intel_lvds_set_brightness()
172 if (dev_priv->lvds_bl->type == BLC_I2C_TYPE) in psb_intel_lvds_set_brightness()
194 dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl | in psb_intel_lvds_set_backlight()
198 blc_pwm_ctl = dev_priv->regs.saveBLC_PWM_CTL & in psb_intel_lvds_set_backlight()
200 dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl | in psb_intel_lvds_set_backlight()
211 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; in psb_intel_lvds_set_power()
215 dev_err(dev->dev, "set power, chip off!\n"); in psb_intel_lvds_set_power()
227 mode_dev->backlight_duty_cycle); in psb_intel_lvds_set_power()
243 struct drm_device *dev = encoder->dev; in psb_intel_lvds_encoder_dpms()
255 struct drm_device *dev = connector->dev; in psb_intel_lvds_save()
259 (struct psb_intel_lvds_priv *)gma_encoder->dev_priv; in psb_intel_lvds_save()
261 lvds_priv->savePP_ON = REG_READ(LVDSPP_ON); in psb_intel_lvds_save()
262 lvds_priv->savePP_OFF = REG_READ(LVDSPP_OFF); in psb_intel_lvds_save()
263 lvds_priv->saveLVDS = REG_READ(LVDS); in psb_intel_lvds_save()
264 lvds_priv->savePP_CONTROL = REG_READ(PP_CONTROL); in psb_intel_lvds_save()
265 lvds_priv->savePP_CYCLE = REG_READ(PP_CYCLE); in psb_intel_lvds_save()
266 /*lvds_priv->savePP_DIVISOR = REG_READ(PP_DIVISOR);*/ in psb_intel_lvds_save()
267 lvds_priv->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); in psb_intel_lvds_save()
268 lvds_priv->savePFIT_CONTROL = REG_READ(PFIT_CONTROL); in psb_intel_lvds_save()
269 lvds_priv->savePFIT_PGM_RATIOS = REG_READ(PFIT_PGM_RATIOS); in psb_intel_lvds_save()
272 dev_priv->backlight_duty_cycle = (dev_priv->regs.saveBLC_PWM_CTL & in psb_intel_lvds_save()
279 if (dev_priv->backlight_duty_cycle == 0) in psb_intel_lvds_save()
280 dev_priv->backlight_duty_cycle = in psb_intel_lvds_save()
283 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", in psb_intel_lvds_save()
284 lvds_priv->savePP_ON, in psb_intel_lvds_save()
285 lvds_priv->savePP_OFF, in psb_intel_lvds_save()
286 lvds_priv->saveLVDS, in psb_intel_lvds_save()
287 lvds_priv->savePP_CONTROL, in psb_intel_lvds_save()
288 lvds_priv->savePP_CYCLE, in psb_intel_lvds_save()
289 lvds_priv->saveBLC_PWM_CTL); in psb_intel_lvds_save()
294 struct drm_device *dev = connector->dev; in psb_intel_lvds_restore()
298 (struct psb_intel_lvds_priv *)gma_encoder->dev_priv; in psb_intel_lvds_restore()
300 dev_dbg(dev->dev, "(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n", in psb_intel_lvds_restore()
301 lvds_priv->savePP_ON, in psb_intel_lvds_restore()
302 lvds_priv->savePP_OFF, in psb_intel_lvds_restore()
303 lvds_priv->saveLVDS, in psb_intel_lvds_restore()
304 lvds_priv->savePP_CONTROL, in psb_intel_lvds_restore()
305 lvds_priv->savePP_CYCLE, in psb_intel_lvds_restore()
306 lvds_priv->saveBLC_PWM_CTL); in psb_intel_lvds_restore()
308 REG_WRITE(BLC_PWM_CTL, lvds_priv->saveBLC_PWM_CTL); in psb_intel_lvds_restore()
309 REG_WRITE(PFIT_CONTROL, lvds_priv->savePFIT_CONTROL); in psb_intel_lvds_restore()
310 REG_WRITE(PFIT_PGM_RATIOS, lvds_priv->savePFIT_PGM_RATIOS); in psb_intel_lvds_restore()
311 REG_WRITE(LVDSPP_ON, lvds_priv->savePP_ON); in psb_intel_lvds_restore()
312 REG_WRITE(LVDSPP_OFF, lvds_priv->savePP_OFF); in psb_intel_lvds_restore()
313 /*REG_WRITE(PP_DIVISOR, lvds_priv->savePP_DIVISOR);*/ in psb_intel_lvds_restore()
314 REG_WRITE(PP_CYCLE, lvds_priv->savePP_CYCLE); in psb_intel_lvds_restore()
315 REG_WRITE(PP_CONTROL, lvds_priv->savePP_CONTROL); in psb_intel_lvds_restore()
316 REG_WRITE(LVDS, lvds_priv->saveLVDS); in psb_intel_lvds_restore()
318 if (lvds_priv->savePP_CONTROL & POWER_TARGET_ON) { in psb_intel_lvds_restore()
336 struct drm_psb_private *dev_priv = to_drm_psb_private(connector->dev); in psb_intel_lvds_mode_valid()
339 dev_priv->mode_dev.panel_fixed_mode; in psb_intel_lvds_mode_valid()
341 if (gma_encoder->type == INTEL_OUTPUT_MIPI2) in psb_intel_lvds_mode_valid()
342 fixed_mode = dev_priv->mode_dev.panel_fixed_mode2; in psb_intel_lvds_mode_valid()
345 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) in psb_intel_lvds_mode_valid()
349 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in psb_intel_lvds_mode_valid()
353 if (mode->hdisplay > fixed_mode->hdisplay) in psb_intel_lvds_mode_valid()
355 if (mode->vdisplay > fixed_mode->vdisplay) in psb_intel_lvds_mode_valid()
365 struct drm_device *dev = encoder->dev; in psb_intel_lvds_mode_fixup()
367 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; in psb_intel_lvds_mode_fixup()
368 struct gma_crtc *gma_crtc = to_gma_crtc(encoder->crtc); in psb_intel_lvds_mode_fixup()
370 struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode; in psb_intel_lvds_mode_fixup()
373 if (gma_encoder->type == INTEL_OUTPUT_MIPI2) in psb_intel_lvds_mode_fixup()
374 panel_fixed_mode = mode_dev->panel_fixed_mode2; in psb_intel_lvds_mode_fixup()
377 if (!IS_MRST(dev) && gma_crtc->pipe == 0) { in psb_intel_lvds_mode_fixup()
381 if (IS_MRST(dev) && gma_crtc->pipe != 0) { in psb_intel_lvds_mode_fixup()
386 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, in psb_intel_lvds_mode_fixup()
389 && tmp_encoder->crtc == encoder->crtc) { in psb_intel_lvds_mode_fixup()
402 adjusted_mode->hdisplay = panel_fixed_mode->hdisplay; in psb_intel_lvds_mode_fixup()
403 adjusted_mode->hsync_start = panel_fixed_mode->hsync_start; in psb_intel_lvds_mode_fixup()
404 adjusted_mode->hsync_end = panel_fixed_mode->hsync_end; in psb_intel_lvds_mode_fixup()
405 adjusted_mode->htotal = panel_fixed_mode->htotal; in psb_intel_lvds_mode_fixup()
406 adjusted_mode->vdisplay = panel_fixed_mode->vdisplay; in psb_intel_lvds_mode_fixup()
407 adjusted_mode->vsync_start = panel_fixed_mode->vsync_start; in psb_intel_lvds_mode_fixup()
408 adjusted_mode->vsync_end = panel_fixed_mode->vsync_end; in psb_intel_lvds_mode_fixup()
409 adjusted_mode->vtotal = panel_fixed_mode->vtotal; in psb_intel_lvds_mode_fixup()
410 adjusted_mode->clock = panel_fixed_mode->clock; in psb_intel_lvds_mode_fixup()
426 struct drm_device *dev = encoder->dev; in psb_intel_lvds_prepare()
428 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; in psb_intel_lvds_prepare()
433 mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); in psb_intel_lvds_prepare()
434 mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL & in psb_intel_lvds_prepare()
444 struct drm_device *dev = encoder->dev; in psb_intel_lvds_commit()
446 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; in psb_intel_lvds_commit()
448 if (mode_dev->backlight_duty_cycle == 0) in psb_intel_lvds_commit()
449 mode_dev->backlight_duty_cycle = in psb_intel_lvds_commit()
459 struct drm_device *dev = encoder->dev; in psb_intel_lvds_mode_set()
470 * Enable automatic panel scaling so that non-native modes fill the in psb_intel_lvds_mode_set()
474 if (mode->hdisplay != adjusted_mode->hdisplay || in psb_intel_lvds_mode_set()
475 mode->vdisplay != adjusted_mode->vdisplay) in psb_intel_lvds_mode_set()
482 if (dev_priv->lvds_dither) in psb_intel_lvds_mode_set()
489 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
493 struct drm_device *dev = connector->dev; in psb_intel_lvds_get_modes()
495 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev; in psb_intel_lvds_get_modes()
499 ret = psb_intel_ddc_get_modes(connector, connector->ddc); in psb_intel_lvds_get_modes()
504 if (mode_dev->panel_fixed_mode != NULL) { in psb_intel_lvds_get_modes()
506 drm_mode_duplicate(dev, mode_dev->panel_fixed_mode); in psb_intel_lvds_get_modes()
520 struct gma_i2c_chan *ddc_bus = to_gma_i2c_chan(connector->ddc); in psb_intel_lvds_destroy()
531 struct drm_encoder *encoder = connector->encoder; in psb_intel_lvds_set_property()
534 return -1; in psb_intel_lvds_set_property()
536 if (!strcmp(property->name, "scaling mode")) { in psb_intel_lvds_set_property()
537 struct gma_crtc *crtc = to_gma_crtc(encoder->crtc); in psb_intel_lvds_set_property()
554 if (drm_object_property_get_value(&connector->base, in psb_intel_lvds_set_property()
562 if (drm_object_property_set_value(&connector->base, in psb_intel_lvds_set_property()
567 if (crtc->saved_mode.hdisplay != 0 && in psb_intel_lvds_set_property()
568 crtc->saved_mode.vdisplay != 0) { in psb_intel_lvds_set_property()
569 if (!drm_crtc_helper_set_mode(encoder->crtc, in psb_intel_lvds_set_property()
570 &crtc->saved_mode, in psb_intel_lvds_set_property()
571 encoder->crtc->x, in psb_intel_lvds_set_property()
572 encoder->crtc->y, in psb_intel_lvds_set_property()
573 encoder->crtc->primary->fb)) in psb_intel_lvds_set_property()
576 } else if (!strcmp(property->name, "backlight")) { in psb_intel_lvds_set_property()
577 if (drm_object_property_set_value(&connector->base, in psb_intel_lvds_set_property()
582 gma_backlight_set(encoder->dev, value); in psb_intel_lvds_set_property()
583 } else if (!strcmp(property->name, "DPMS")) { in psb_intel_lvds_set_property()
585 = encoder->helper_private; in psb_intel_lvds_set_property()
586 hfuncs->dpms(encoder, value); in psb_intel_lvds_set_property()
592 return -1; in psb_intel_lvds_set_property()
618 * psb_intel_lvds_init - setup LVDS connectors on this device
622 * Create the connector, register the LVDS DDC bus, and try to figure out what
643 dev_err(dev->dev, "gma_encoder allocation error\n"); in psb_intel_lvds_init()
646 encoder = &gma_encoder->base; in psb_intel_lvds_init()
650 dev_err(dev->dev, "gma_connector allocation error\n"); in psb_intel_lvds_init()
656 dev_err(dev->dev, "LVDS private allocation error\n"); in psb_intel_lvds_init()
660 gma_encoder->dev_priv = lvds_priv; in psb_intel_lvds_init()
662 connector = &gma_connector->base; in psb_intel_lvds_init()
663 gma_connector->save = psb_intel_lvds_save; in psb_intel_lvds_init()
664 gma_connector->restore = psb_intel_lvds_restore; in psb_intel_lvds_init()
666 /* Set up the DDC bus. */ in psb_intel_lvds_init()
669 dev_printk(KERN_ERR, dev->dev, in psb_intel_lvds_init()
670 "DDC bus registration " "failed.\n"); in psb_intel_lvds_init()
677 &ddc_bus->base); in psb_intel_lvds_init()
686 gma_encoder->type = INTEL_OUTPUT_LVDS; in psb_intel_lvds_init()
691 connector->display_info.subpixel_order = SubPixelHorizontalRGB; in psb_intel_lvds_init()
692 connector->interlace_allowed = false; in psb_intel_lvds_init()
693 connector->doublescan_allowed = false; in psb_intel_lvds_init()
696 drm_object_attach_property(&connector->base, in psb_intel_lvds_init()
697 dev->mode_config.scaling_mode_property, in psb_intel_lvds_init()
699 drm_object_attach_property(&connector->base, in psb_intel_lvds_init()
700 dev_priv->backlight_property, in psb_intel_lvds_init()
704 * Set up I2C bus in psb_intel_lvds_init()
707 lvds_priv->i2c_bus = gma_i2c_create(dev, GPIOB, "LVDSBLC_B"); in psb_intel_lvds_init()
708 if (!lvds_priv->i2c_bus) { in psb_intel_lvds_init()
710 dev->dev, "I2C bus registration failed.\n"); in psb_intel_lvds_init()
713 lvds_priv->i2c_bus->target_addr = 0x2C; in psb_intel_lvds_init()
714 dev_priv->lvds_i2c_bus = lvds_priv->i2c_bus; in psb_intel_lvds_init()
718 * 1) check for EDID on DDC in psb_intel_lvds_init()
727 * Attempt to get the fixed panel mode from DDC. Assume that the in psb_intel_lvds_init()
730 mutex_lock(&dev->mode_config.mutex); in psb_intel_lvds_init()
731 psb_intel_ddc_get_modes(connector, &ddc_bus->base); in psb_intel_lvds_init()
733 list_for_each_entry(scan, &connector->probed_modes, head) { in psb_intel_lvds_init()
734 if (scan->type & DRM_MODE_TYPE_PREFERRED) { in psb_intel_lvds_init()
735 mode_dev->panel_fixed_mode = in psb_intel_lvds_init()
737 DRM_DEBUG_KMS("Using mode from DDC\n"); in psb_intel_lvds_init()
743 if (dev_priv->lfp_lvds_vbt_mode) { in psb_intel_lvds_init()
744 mode_dev->panel_fixed_mode = in psb_intel_lvds_init()
745 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode); in psb_intel_lvds_init()
747 if (mode_dev->panel_fixed_mode) { in psb_intel_lvds_init()
748 mode_dev->panel_fixed_mode->type |= in psb_intel_lvds_init()
765 mode_dev->panel_fixed_mode = in psb_intel_lvds_init()
767 if (mode_dev->panel_fixed_mode) { in psb_intel_lvds_init()
768 mode_dev->panel_fixed_mode->type |= in psb_intel_lvds_init()
770 DRM_DEBUG_KMS("Using pre-programmed mode\n"); in psb_intel_lvds_init()
776 if (!mode_dev->panel_fixed_mode) { in psb_intel_lvds_init()
777 dev_err(dev->dev, "Found no modes on the lvds, ignoring the LVDS\n"); in psb_intel_lvds_init()
786 mutex_unlock(&dev->mode_config.mutex); in psb_intel_lvds_init()
790 mutex_unlock(&dev->mode_config.mutex); in psb_intel_lvds_init()
791 gma_i2c_destroy(lvds_priv->i2c_bus); in psb_intel_lvds_init()