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"
28 #include <asm/intel_scu_ipc.h>
31 static const struct psb_ops oaktrail_chip_ops
;
33 /* IPC message and command defines used to enable/disable mipi panel voltages */
34 #define IPC_MSG_PANEL_ON_OFF 0xE9
35 #define IPC_CMD_PANEL_ON 1
36 #define IPC_CMD_PANEL_OFF 0
38 static int mrst_output_init(struct drm_device
*dev
)
40 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
41 if (dev_priv
->iLVDS_enable
) {
42 mrst_lvds_init(dev
, &dev_priv
->mode_dev
);
45 dev_err(dev
->dev
, "DSI is not supported\n");
50 * Provide the low level interfaces for the Moorestown backlight
53 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
55 #define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF
56 #define BLC_PWM_PRECISION_FACTOR 100 /* 10000000 */
57 #define BLC_PWM_FREQ_CALC_CONSTANT 32
59 #define BLC_ADJUSTMENT_MAX 100
61 static struct backlight_device
*mrst_backlight_device
;
62 static int mrst_brightness
;
64 static int mrst_set_brightness(struct backlight_device
*bd
)
66 struct drm_device
*dev
= bl_get_data(mrst_backlight_device
);
67 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
68 int level
= bd
->props
.brightness
;
72 /* Percentage 1-100% being valid */
76 if (gma_power_begin(dev
, 0)) {
77 /* Calculate and set the brightness value */
78 max_pwm_blc
= REG_READ(BLC_PWM_CTL
) >> 16;
79 blc_pwm_ctl
= level
* max_pwm_blc
/ 100;
81 /* Adjust the backlight level with the percent in
84 blc_pwm_ctl
= blc_pwm_ctl
* dev_priv
->blc_adj1
;
85 blc_pwm_ctl
= blc_pwm_ctl
/ 100;
87 /* Adjust the backlight level with the percent in
90 blc_pwm_ctl
= blc_pwm_ctl
* dev_priv
->blc_adj2
;
91 blc_pwm_ctl
= blc_pwm_ctl
/ 100;
93 /* force PWM bit on */
94 REG_WRITE(BLC_PWM_CTL2
, (0x80000000 | REG_READ(BLC_PWM_CTL2
)));
95 REG_WRITE(BLC_PWM_CTL
, (max_pwm_blc
<< 16) | blc_pwm_ctl
);
98 mrst_brightness
= level
;
102 static int mrst_get_brightness(struct backlight_device
*bd
)
104 /* return locally cached var instead of HW read (due to DPST etc.) */
105 /* FIXME: ideally return actual value in case firmware fiddled with
107 return mrst_brightness
;
110 static int device_backlight_init(struct drm_device
*dev
)
112 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
113 unsigned long core_clock
;
116 uint32_t blc_pwm_precision_factor
;
118 dev_priv
->blc_adj1
= BLC_ADJUSTMENT_MAX
;
119 dev_priv
->blc_adj2
= BLC_ADJUSTMENT_MAX
;
121 /* this needs to be set elsewhere */
122 blc_pwm_precision_factor
= BLC_PWM_PRECISION_FACTOR
;
124 core_clock
= dev_priv
->core_freq
;
126 value
= (core_clock
* MHz
) / BLC_PWM_FREQ_CALC_CONSTANT
;
127 value
*= blc_pwm_precision_factor
;
128 value
/= bl_max_freq
;
129 value
/= blc_pwm_precision_factor
;
131 if (gma_power_begin(dev
, false)) {
132 if (value
> (unsigned long long)MRST_BLC_MAX_PWM_REG_FREQ
)
135 REG_WRITE(BLC_PWM_CTL2
,
136 (0x80000000 | REG_READ(BLC_PWM_CTL2
)));
137 REG_WRITE(BLC_PWM_CTL
, value
| (value
<< 16));
144 static const struct backlight_ops mrst_ops
= {
145 .get_brightness
= mrst_get_brightness
,
146 .update_status
= mrst_set_brightness
,
149 int mrst_backlight_init(struct drm_device
*dev
)
151 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
153 struct backlight_properties props
;
155 memset(&props
, 0, sizeof(struct backlight_properties
));
156 props
.max_brightness
= 100;
157 props
.type
= BACKLIGHT_PLATFORM
;
159 mrst_backlight_device
= backlight_device_register("mrst-bl",
160 NULL
, (void *)dev
, &mrst_ops
, &props
);
162 if (IS_ERR(mrst_backlight_device
))
163 return PTR_ERR(mrst_backlight_device
);
165 ret
= device_backlight_init(dev
);
167 backlight_device_unregister(mrst_backlight_device
);
170 mrst_backlight_device
->props
.brightness
= 100;
171 mrst_backlight_device
->props
.max_brightness
= 100;
172 backlight_update_status(mrst_backlight_device
);
173 dev_priv
->backlight_device
= mrst_backlight_device
;
180 * Provide the Moorestown specific chip logic and low level methods
181 * for power management
184 static void mrst_init_pm(struct drm_device
*dev
)
189 * mrst_save_display_registers - save registers lost on suspend
190 * @dev: our DRM device
192 * Save the state we need in order to be able to restore the interface
193 * upon resume from suspend
195 static int mrst_save_display_registers(struct drm_device
*dev
)
197 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
198 struct drm_crtc
*crtc
;
199 struct drm_connector
*connector
;
201 /* Display arbitration control + watermarks */
202 dev_priv
->saveDSPARB
= PSB_RVDC32(DSPARB
);
203 dev_priv
->saveDSPFW1
= PSB_RVDC32(DSPFW1
);
204 dev_priv
->saveDSPFW2
= PSB_RVDC32(DSPFW2
);
205 dev_priv
->saveDSPFW3
= PSB_RVDC32(DSPFW3
);
206 dev_priv
->saveDSPFW4
= PSB_RVDC32(DSPFW4
);
207 dev_priv
->saveDSPFW5
= PSB_RVDC32(DSPFW5
);
208 dev_priv
->saveDSPFW6
= PSB_RVDC32(DSPFW6
);
209 dev_priv
->saveCHICKENBIT
= PSB_RVDC32(DSPCHICKENBIT
);
211 /* Save crtc and output state */
212 mutex_lock(&dev
->mode_config
.mutex
);
213 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
214 if (drm_helper_crtc_in_use(crtc
))
215 crtc
->funcs
->save(crtc
);
218 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
219 connector
->funcs
->save(connector
);
221 mutex_unlock(&dev
->mode_config
.mutex
);
226 * mrst_restore_display_registers - restore lost register state
227 * @dev: our DRM device
229 * Restore register state that was lost during suspend and resume.
231 static int mrst_restore_display_registers(struct drm_device
*dev
)
233 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
234 struct drm_crtc
*crtc
;
235 struct drm_connector
*connector
;
238 if (!dev_priv
->iLVDS_enable
) {
239 #ifdef CONFIG_X86_MRST
240 intel_scu_ipc_simple_command(IPC_MSG_PANEL_ON_OFF
,
242 /* FIXME: can we avoid this delay ? */
243 msleep(2000); /* wait 2 seconds */
247 /* Display arbitration + watermarks */
248 PSB_WVDC32(dev_priv
->saveDSPARB
, DSPARB
);
249 PSB_WVDC32(dev_priv
->saveDSPFW1
, DSPFW1
);
250 PSB_WVDC32(dev_priv
->saveDSPFW2
, DSPFW2
);
251 PSB_WVDC32(dev_priv
->saveDSPFW3
, DSPFW3
);
252 PSB_WVDC32(dev_priv
->saveDSPFW4
, DSPFW4
);
253 PSB_WVDC32(dev_priv
->saveDSPFW5
, DSPFW5
);
254 PSB_WVDC32(dev_priv
->saveDSPFW6
, DSPFW6
);
255 PSB_WVDC32(dev_priv
->saveCHICKENBIT
, DSPCHICKENBIT
);
257 /*make sure VGA plane is off. it initializes to on after reset!*/
258 PSB_WVDC32(0x80000000, VGACNTRL
);
260 mutex_lock(&dev
->mode_config
.mutex
);
261 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
262 if (drm_helper_crtc_in_use(crtc
))
263 crtc
->funcs
->restore(crtc
);
265 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
266 connector
->funcs
->restore(connector
);
268 mutex_unlock(&dev
->mode_config
.mutex
);
270 if (dev_priv
->iLVDS_enable
) {
271 /*shutdown the panel*/
272 PSB_WVDC32(0, PP_CONTROL
);
274 pp_stat
= PSB_RVDC32(PP_STATUS
);
275 } while (pp_stat
& 0x80000000);
277 /* Turn off the plane */
278 PSB_WVDC32(0x58000000, DSPACNTR
);
279 PSB_WVDC32(0, DSPASURF
);/*trigger the plane disable*/
283 PSB_WVDC32(0x0, PIPEACONF
);
288 PSB_WVDC32(0, MRST_DPLL_A
);
290 PSB_WVDC32(DPI_SHUT_DOWN
, DPI_CONTROL_REG
);
291 PSB_WVDC32(0x0, PIPEACONF
);
292 PSB_WVDC32(0x2faf0000, BLC_PWM_CTL
);
293 while (REG_READ(0x70008) & 0x40000000)
295 while ((PSB_RVDC32(GEN_FIFO_STAT_REG
) & DPI_FIFO_EMPTY
)
298 PSB_WVDC32(0, DEVICE_READY_REG
);
299 /* Turn off panel power */
300 #ifdef CONFIG_X86_MRST /* FIXME: kill define once modular */
301 intel_scu_ipc_simple_command(IPC_MSG_PANEL_ON_OFF
,
309 * mrst_power_down - power down the display island
310 * @dev: our DRM device
312 * Power down the display interface of our device
314 static int mrst_power_down(struct drm_device
*dev
)
316 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
320 pwr_mask
= PSB_PWRGT_DISPLAY_MASK
;
321 outl(pwr_mask
, dev_priv
->ospm_base
+ PSB_PM_SSC
);
324 pwr_sts
= inl(dev_priv
->ospm_base
+ PSB_PM_SSS
);
325 if ((pwr_sts
& pwr_mask
) == pwr_mask
)
336 * Restore power to the specified island(s) (powergating)
338 static int mrst_power_up(struct drm_device
*dev
)
340 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
341 u32 pwr_mask
= PSB_PWRGT_DISPLAY_MASK
;
342 u32 pwr_sts
, pwr_cnt
;
344 pwr_cnt
= inl(dev_priv
->ospm_base
+ PSB_PM_SSC
);
345 pwr_cnt
&= ~pwr_mask
;
346 outl(pwr_cnt
, (dev_priv
->ospm_base
+ PSB_PM_SSC
));
349 pwr_sts
= inl(dev_priv
->ospm_base
+ PSB_PM_SSS
);
350 if ((pwr_sts
& pwr_mask
) == 0)
358 static int mrst_chip_setup(struct drm_device
*dev
)
360 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
362 #if defined(CONFIG_X86_MRST)
363 if (mrst_identify_cpu())
364 return mid_chip_setup(dev
);
366 dev_priv
->ops
= &oaktrail_chip_ops
;
367 /* Check - may be better to go via BIOS paths ? */
368 return mid_chip_setup(dev
);
371 const struct psb_ops mrst_chip_ops
= {
372 .name
= "Moorestown",
376 .sgx_offset
= MRST_SGX_OFFSET
,
378 .chip_setup
= mrst_chip_setup
,
379 .crtc_helper
= &mrst_helper_funcs
,
380 .crtc_funcs
= &psb_intel_crtc_funcs
,
382 .output_init
= mrst_output_init
,
384 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
385 .backlight_init
= mrst_backlight_init
,
388 .init_pm
= mrst_init_pm
,
389 .save_regs
= mrst_save_display_registers
,
390 .restore_regs
= mrst_restore_display_registers
,
391 .power_down
= mrst_power_down
,
392 .power_up
= mrst_power_up
,
395 static const struct psb_ops oaktrail_chip_ops
= {
400 .sgx_offset
= MRST_SGX_OFFSET
,
402 .chip_setup
= mid_chip_setup
,
403 .crtc_helper
= &mrst_helper_funcs
,
404 .crtc_funcs
= &psb_intel_crtc_funcs
,
406 .output_init
= mrst_output_init
,
408 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
409 .backlight_init
= mrst_backlight_init
,
412 .init_pm
= mrst_init_pm
,
413 .save_regs
= mrst_save_display_registers
,
414 .restore_regs
= mrst_restore_display_registers
,
415 .power_down
= mrst_power_down
,
416 .power_up
= mrst_power_up
,