1 /**************************************************************************
2 * Copyright (c) 2011, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 **************************************************************************/
20 #include <linux/backlight.h>
26 #include "psb_intel_reg.h"
27 #include <asm/intel_scu_ipc.h>
30 /* IPC message and command defines used to enable/disable mipi panel voltages */
31 #define IPC_MSG_PANEL_ON_OFF 0xE9
32 #define IPC_CMD_PANEL_ON 1
33 #define IPC_CMD_PANEL_OFF 0
35 static int mrst_output_init(struct drm_device
*dev
)
37 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
38 if (dev_priv
->iLVDS_enable
) {
39 mrst_lvds_init(dev
, &dev_priv
->mode_dev
);
42 dev_err(dev
->dev
, "DSI is not supported\n");
47 * Provide the low level interfaces for the Moorestown backlight
50 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
52 #define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF
53 #define BLC_PWM_PRECISION_FACTOR 100 /* 10000000 */
54 #define BLC_PWM_FREQ_CALC_CONSTANT 32
56 #define BLC_ADJUSTMENT_MAX 100
58 static struct backlight_device
*mrst_backlight_device
;
59 static int mrst_brightness
;
61 static int mrst_set_brightness(struct backlight_device
*bd
)
63 struct drm_device
*dev
= bl_get_data(mrst_backlight_device
);
64 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
65 int level
= bd
->props
.brightness
;
69 /* Percentage 1-100% being valid */
73 if (gma_power_begin(dev
, 0)) {
74 /* Calculate and set the brightness value */
75 max_pwm_blc
= REG_READ(BLC_PWM_CTL
) >> 16;
76 blc_pwm_ctl
= level
* max_pwm_blc
/ 100;
78 /* Adjust the backlight level with the percent in
81 blc_pwm_ctl
= blc_pwm_ctl
* dev_priv
->blc_adj1
;
82 blc_pwm_ctl
= blc_pwm_ctl
/ 100;
84 /* Adjust the backlight level with the percent in
87 blc_pwm_ctl
= blc_pwm_ctl
* dev_priv
->blc_adj2
;
88 blc_pwm_ctl
= blc_pwm_ctl
/ 100;
90 /* force PWM bit on */
91 REG_WRITE(BLC_PWM_CTL2
, (0x80000000 | REG_READ(BLC_PWM_CTL2
)));
92 REG_WRITE(BLC_PWM_CTL
, (max_pwm_blc
<< 16) | blc_pwm_ctl
);
95 mrst_brightness
= level
;
99 static int mrst_get_brightness(struct backlight_device
*bd
)
101 /* return locally cached var instead of HW read (due to DPST etc.) */
102 /* FIXME: ideally return actual value in case firmware fiddled with
104 return mrst_brightness
;
107 static int device_backlight_init(struct drm_device
*dev
)
109 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
110 unsigned long core_clock
;
113 uint32_t blc_pwm_precision_factor
;
115 dev_priv
->blc_adj1
= BLC_ADJUSTMENT_MAX
;
116 dev_priv
->blc_adj2
= BLC_ADJUSTMENT_MAX
;
118 /* this needs to be set elsewhere */
119 blc_pwm_precision_factor
= BLC_PWM_PRECISION_FACTOR
;
121 core_clock
= dev_priv
->core_freq
;
123 value
= (core_clock
* MHz
) / BLC_PWM_FREQ_CALC_CONSTANT
;
124 value
*= blc_pwm_precision_factor
;
125 value
/= bl_max_freq
;
126 value
/= blc_pwm_precision_factor
;
128 if (gma_power_begin(dev
, false)) {
129 if (value
> (unsigned long long)MRST_BLC_MAX_PWM_REG_FREQ
)
132 REG_WRITE(BLC_PWM_CTL2
,
133 (0x80000000 | REG_READ(BLC_PWM_CTL2
)));
134 REG_WRITE(BLC_PWM_CTL
, value
| (value
<< 16));
141 static const struct backlight_ops mrst_ops
= {
142 .get_brightness
= mrst_get_brightness
,
143 .update_status
= mrst_set_brightness
,
146 int mrst_backlight_init(struct drm_device
*dev
)
148 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
150 struct backlight_properties props
;
152 memset(&props
, 0, sizeof(struct backlight_properties
));
153 props
.max_brightness
= 100;
154 props
.type
= BACKLIGHT_PLATFORM
;
156 mrst_backlight_device
= backlight_device_register("mrst-bl",
157 NULL
, (void *)dev
, &mrst_ops
, &props
);
159 if (IS_ERR(mrst_backlight_device
))
160 return PTR_ERR(mrst_backlight_device
);
162 ret
= device_backlight_init(dev
);
164 backlight_device_unregister(mrst_backlight_device
);
167 mrst_backlight_device
->props
.brightness
= 100;
168 mrst_backlight_device
->props
.max_brightness
= 100;
169 backlight_update_status(mrst_backlight_device
);
170 dev_priv
->backlight_device
= mrst_backlight_device
;
177 * Provide the Moorestown specific chip logic and low level methods
178 * for power management
181 static void mrst_init_pm(struct drm_device
*dev
)
186 * mrst_save_display_registers - save registers lost on suspend
187 * @dev: our DRM device
189 * Save the state we need in order to be able to restore the interface
190 * upon resume from suspend
192 static int mrst_save_display_registers(struct drm_device
*dev
)
194 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
195 struct drm_crtc
*crtc
;
196 struct drm_connector
*connector
;
198 /* Display arbitration control + watermarks */
199 dev_priv
->saveDSPARB
= PSB_RVDC32(DSPARB
);
200 dev_priv
->saveDSPFW1
= PSB_RVDC32(DSPFW1
);
201 dev_priv
->saveDSPFW2
= PSB_RVDC32(DSPFW2
);
202 dev_priv
->saveDSPFW3
= PSB_RVDC32(DSPFW3
);
203 dev_priv
->saveDSPFW4
= PSB_RVDC32(DSPFW4
);
204 dev_priv
->saveDSPFW5
= PSB_RVDC32(DSPFW5
);
205 dev_priv
->saveDSPFW6
= PSB_RVDC32(DSPFW6
);
206 dev_priv
->saveCHICKENBIT
= PSB_RVDC32(DSPCHICKENBIT
);
208 /* Save crtc and output state */
209 mutex_lock(&dev
->mode_config
.mutex
);
210 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
211 if (drm_helper_crtc_in_use(crtc
))
212 crtc
->funcs
->save(crtc
);
215 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
216 connector
->funcs
->save(connector
);
218 mutex_unlock(&dev
->mode_config
.mutex
);
223 * mrst_restore_display_registers - restore lost register state
224 * @dev: our DRM device
226 * Restore register state that was lost during suspend and resume.
228 static int mrst_restore_display_registers(struct drm_device
*dev
)
230 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
231 struct drm_crtc
*crtc
;
232 struct drm_connector
*connector
;
235 if (!dev_priv
->iLVDS_enable
) {
236 #ifdef CONFIG_X86_MRST
237 intel_scu_ipc_simple_command(IPC_MSG_PANEL_ON_OFF
,
239 /* FIXME: can we avoid this delay ? */
240 msleep(2000); /* wait 2 seconds */
244 /* Display arbitration + watermarks */
245 PSB_WVDC32(dev_priv
->saveDSPARB
, DSPARB
);
246 PSB_WVDC32(dev_priv
->saveDSPFW1
, DSPFW1
);
247 PSB_WVDC32(dev_priv
->saveDSPFW2
, DSPFW2
);
248 PSB_WVDC32(dev_priv
->saveDSPFW3
, DSPFW3
);
249 PSB_WVDC32(dev_priv
->saveDSPFW4
, DSPFW4
);
250 PSB_WVDC32(dev_priv
->saveDSPFW5
, DSPFW5
);
251 PSB_WVDC32(dev_priv
->saveDSPFW6
, DSPFW6
);
252 PSB_WVDC32(dev_priv
->saveCHICKENBIT
, DSPCHICKENBIT
);
254 /*make sure VGA plane is off. it initializes to on after reset!*/
255 PSB_WVDC32(0x80000000, VGACNTRL
);
257 mutex_lock(&dev
->mode_config
.mutex
);
258 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
259 if (drm_helper_crtc_in_use(crtc
))
260 crtc
->funcs
->restore(crtc
);
262 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
263 connector
->funcs
->restore(connector
);
265 mutex_unlock(&dev
->mode_config
.mutex
);
267 if (dev_priv
->iLVDS_enable
) {
268 /*shutdown the panel*/
269 PSB_WVDC32(0, PP_CONTROL
);
271 pp_stat
= PSB_RVDC32(PP_STATUS
);
272 } while (pp_stat
& 0x80000000);
274 /* Turn off the plane */
275 PSB_WVDC32(0x58000000, DSPACNTR
);
276 PSB_WVDC32(0, DSPASURF
);/*trigger the plane disable*/
280 PSB_WVDC32(0x0, PIPEACONF
);
285 PSB_WVDC32(0, MRST_DPLL_A
);
287 PSB_WVDC32(DPI_SHUT_DOWN
, DPI_CONTROL_REG
);
288 PSB_WVDC32(0x0, PIPEACONF
);
289 PSB_WVDC32(0x2faf0000, BLC_PWM_CTL
);
290 while (REG_READ(0x70008) & 0x40000000)
292 while ((PSB_RVDC32(GEN_FIFO_STAT_REG
) & DPI_FIFO_EMPTY
)
295 PSB_WVDC32(0, DEVICE_READY_REG
);
296 /* Turn off panel power */
297 #ifdef CONFIG_X86_MRST /* FIXME: kill define once modular */
298 intel_scu_ipc_simple_command(IPC_MSG_PANEL_ON_OFF
,
306 * mrst_power_down - power down the display island
307 * @dev: our DRM device
309 * Power down the display interface of our device
311 static int mrst_power_down(struct drm_device
*dev
)
313 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
317 pwr_mask
= PSB_PWRGT_DISPLAY_MASK
;
318 outl(pwr_mask
, dev_priv
->ospm_base
+ PSB_PM_SSC
);
321 pwr_sts
= inl(dev_priv
->ospm_base
+ PSB_PM_SSS
);
322 if ((pwr_sts
& pwr_mask
) == pwr_mask
)
333 * Restore power to the specified island(s) (powergating)
335 static int mrst_power_up(struct drm_device
*dev
)
337 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
338 u32 pwr_mask
= PSB_PWRGT_DISPLAY_MASK
;
339 u32 pwr_sts
, pwr_cnt
;
341 pwr_cnt
= inl(dev_priv
->ospm_base
+ PSB_PM_SSC
);
342 pwr_cnt
&= ~pwr_mask
;
343 outl(pwr_cnt
, (dev_priv
->ospm_base
+ PSB_PM_SSC
));
346 pwr_sts
= inl(dev_priv
->ospm_base
+ PSB_PM_SSS
);
347 if ((pwr_sts
& pwr_mask
) == 0)
355 const struct psb_ops mrst_chip_ops
= {
356 .name
= "Moorestown",
359 .sgx_offset
= MRST_SGX_OFFSET
,
361 .chip_setup
= mid_chip_setup
,
362 .crtc_helper
= &mrst_helper_funcs
,
363 .crtc_funcs
= &psb_intel_crtc_funcs
,
365 .output_init
= mrst_output_init
,
367 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
368 .backlight_init
= mrst_backlight_init
,
371 .init_pm
= mrst_init_pm
,
372 .save_regs
= mrst_save_display_registers
,
373 .restore_regs
= mrst_restore_display_registers
,
374 .power_down
= mrst_power_down
,
375 .power_up
= mrst_power_up
,