| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright © 2006-2011 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 | 4 | * |
|---|
| 17 | 5 | * Authors: |
|---|
| 18 | 6 | * Eric Anholt <eric@anholt.net> |
|---|
| .. | .. |
|---|
| 20 | 8 | * Jesse Barnes <jesse.barnes@intel.com> |
|---|
| 21 | 9 | */ |
|---|
| 22 | 10 | |
|---|
| 23 | | -#include <linux/i2c.h> |
|---|
| 24 | 11 | #include <linux/dmi.h> |
|---|
| 25 | | -#include <drm/drmP.h> |
|---|
| 12 | +#include <linux/i2c.h> |
|---|
| 13 | +#include <linux/pm_runtime.h> |
|---|
| 26 | 14 | |
|---|
| 15 | +#include <drm/drm_simple_kms_helper.h> |
|---|
| 16 | + |
|---|
| 17 | +#include "cdv_device.h" |
|---|
| 27 | 18 | #include "intel_bios.h" |
|---|
| 19 | +#include "power.h" |
|---|
| 28 | 20 | #include "psb_drv.h" |
|---|
| 29 | 21 | #include "psb_intel_drv.h" |
|---|
| 30 | 22 | #include "psb_intel_reg.h" |
|---|
| 31 | | -#include "power.h" |
|---|
| 32 | | -#include <linux/pm_runtime.h> |
|---|
| 33 | | -#include "cdv_device.h" |
|---|
| 34 | 23 | |
|---|
| 35 | 24 | /** |
|---|
| 36 | 25 | * LVDS I2C backlight control macros |
|---|
| .. | .. |
|---|
| 84 | 73 | |
|---|
| 85 | 74 | return retval; |
|---|
| 86 | 75 | } |
|---|
| 87 | | - |
|---|
| 88 | | -#if 0 |
|---|
| 89 | | -/* |
|---|
| 90 | | - * Set LVDS backlight level by I2C command |
|---|
| 91 | | - */ |
|---|
| 92 | | -static int cdv_lvds_i2c_set_brightness(struct drm_device *dev, |
|---|
| 93 | | - unsigned int level) |
|---|
| 94 | | -{ |
|---|
| 95 | | - struct drm_psb_private *dev_priv = dev->dev_private; |
|---|
| 96 | | - struct psb_intel_i2c_chan *lvds_i2c_bus = dev_priv->lvds_i2c_bus; |
|---|
| 97 | | - u8 out_buf[2]; |
|---|
| 98 | | - unsigned int blc_i2c_brightness; |
|---|
| 99 | | - |
|---|
| 100 | | - struct i2c_msg msgs[] = { |
|---|
| 101 | | - { |
|---|
| 102 | | - .addr = lvds_i2c_bus->slave_addr, |
|---|
| 103 | | - .flags = 0, |
|---|
| 104 | | - .len = 2, |
|---|
| 105 | | - .buf = out_buf, |
|---|
| 106 | | - } |
|---|
| 107 | | - }; |
|---|
| 108 | | - |
|---|
| 109 | | - blc_i2c_brightness = BRIGHTNESS_MASK & ((unsigned int)level * |
|---|
| 110 | | - BRIGHTNESS_MASK / |
|---|
| 111 | | - BRIGHTNESS_MAX_LEVEL); |
|---|
| 112 | | - |
|---|
| 113 | | - if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) |
|---|
| 114 | | - blc_i2c_brightness = BRIGHTNESS_MASK - blc_i2c_brightness; |
|---|
| 115 | | - |
|---|
| 116 | | - out_buf[0] = dev_priv->lvds_bl->brightnesscmd; |
|---|
| 117 | | - out_buf[1] = (u8)blc_i2c_brightness; |
|---|
| 118 | | - |
|---|
| 119 | | - if (i2c_transfer(&lvds_i2c_bus->adapter, msgs, 1) == 1) |
|---|
| 120 | | - return 0; |
|---|
| 121 | | - |
|---|
| 122 | | - DRM_ERROR("I2C transfer error\n"); |
|---|
| 123 | | - return -1; |
|---|
| 124 | | -} |
|---|
| 125 | | - |
|---|
| 126 | | - |
|---|
| 127 | | -static int cdv_lvds_pwm_set_brightness(struct drm_device *dev, int level) |
|---|
| 128 | | -{ |
|---|
| 129 | | - struct drm_psb_private *dev_priv = dev->dev_private; |
|---|
| 130 | | - |
|---|
| 131 | | - u32 max_pwm_blc; |
|---|
| 132 | | - u32 blc_pwm_duty_cycle; |
|---|
| 133 | | - |
|---|
| 134 | | - max_pwm_blc = cdv_intel_lvds_get_max_backlight(dev); |
|---|
| 135 | | - |
|---|
| 136 | | - /*BLC_PWM_CTL Should be initiated while backlight device init*/ |
|---|
| 137 | | - BUG_ON((max_pwm_blc & PSB_BLC_MAX_PWM_REG_FREQ) == 0); |
|---|
| 138 | | - |
|---|
| 139 | | - blc_pwm_duty_cycle = level * max_pwm_blc / BRIGHTNESS_MAX_LEVEL; |
|---|
| 140 | | - |
|---|
| 141 | | - if (dev_priv->lvds_bl->pol == BLC_POLARITY_INVERSE) |
|---|
| 142 | | - blc_pwm_duty_cycle = max_pwm_blc - blc_pwm_duty_cycle; |
|---|
| 143 | | - |
|---|
| 144 | | - blc_pwm_duty_cycle &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR; |
|---|
| 145 | | - REG_WRITE(BLC_PWM_CTL, |
|---|
| 146 | | - (max_pwm_blc << PSB_BACKLIGHT_PWM_CTL_SHIFT) | |
|---|
| 147 | | - (blc_pwm_duty_cycle)); |
|---|
| 148 | | - |
|---|
| 149 | | - return 0; |
|---|
| 150 | | -} |
|---|
| 151 | | - |
|---|
| 152 | | -/* |
|---|
| 153 | | - * Set LVDS backlight level either by I2C or PWM |
|---|
| 154 | | - */ |
|---|
| 155 | | -void cdv_intel_lvds_set_brightness(struct drm_device *dev, int level) |
|---|
| 156 | | -{ |
|---|
| 157 | | - struct drm_psb_private *dev_priv = dev->dev_private; |
|---|
| 158 | | - |
|---|
| 159 | | - if (!dev_priv->lvds_bl) { |
|---|
| 160 | | - DRM_ERROR("NO LVDS Backlight Info\n"); |
|---|
| 161 | | - return; |
|---|
| 162 | | - } |
|---|
| 163 | | - |
|---|
| 164 | | - if (dev_priv->lvds_bl->type == BLC_I2C_TYPE) |
|---|
| 165 | | - cdv_lvds_i2c_set_brightness(dev, level); |
|---|
| 166 | | - else |
|---|
| 167 | | - cdv_lvds_pwm_set_brightness(dev, level); |
|---|
| 168 | | -} |
|---|
| 169 | | -#endif |
|---|
| 170 | 76 | |
|---|
| 171 | 77 | /** |
|---|
| 172 | 78 | * Sets the backlight level. |
|---|
| .. | .. |
|---|
| 512 | 418 | .destroy = cdv_intel_lvds_destroy, |
|---|
| 513 | 419 | }; |
|---|
| 514 | 420 | |
|---|
| 515 | | - |
|---|
| 516 | | -static void cdv_intel_lvds_enc_destroy(struct drm_encoder *encoder) |
|---|
| 517 | | -{ |
|---|
| 518 | | - drm_encoder_cleanup(encoder); |
|---|
| 519 | | -} |
|---|
| 520 | | - |
|---|
| 521 | | -static const struct drm_encoder_funcs cdv_intel_lvds_enc_funcs = { |
|---|
| 522 | | - .destroy = cdv_intel_lvds_enc_destroy, |
|---|
| 523 | | -}; |
|---|
| 524 | | - |
|---|
| 525 | 421 | /* |
|---|
| 526 | 422 | * Enumerate the child dev array parsed from VBT to check whether |
|---|
| 527 | 423 | * the LVDS is present. |
|---|
| .. | .. |
|---|
| 629 | 525 | &cdv_intel_lvds_connector_funcs, |
|---|
| 630 | 526 | DRM_MODE_CONNECTOR_LVDS); |
|---|
| 631 | 527 | |
|---|
| 632 | | - drm_encoder_init(dev, encoder, |
|---|
| 633 | | - &cdv_intel_lvds_enc_funcs, |
|---|
| 634 | | - DRM_MODE_ENCODER_LVDS, NULL); |
|---|
| 635 | | - |
|---|
| 528 | + drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS); |
|---|
| 636 | 529 | |
|---|
| 637 | 530 | gma_connector_attach_encoder(gma_connector, gma_encoder); |
|---|
| 638 | 531 | gma_encoder->type = INTEL_OUTPUT_LVDS; |
|---|