blob: 6f99be47b4f55056db219c3af2b7516c59ba8067 [file] [log] [blame]
Alan Cox5c49fd32011-11-03 18:22:04 +00001/**************************************************************************
2 * Copyright (c) 2007-2011, Intel Corporation.
3 * All Rights Reserved.
4 *
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.
8 *
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
12 * more details.
13 *
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.
17 *
18 **************************************************************************/
19
20#ifndef _PSB_DRV_H_
21#define _PSB_DRV_H_
22
23#include <linux/kref.h>
24
25#include <drm/drmP.h>
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drm_global.h>
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/gma_drm.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000028#include "psb_reg.h"
29#include "psb_intel_drv.h"
Patrik Jakobsson5ea75e02013-06-30 21:39:00 +020030#include "gma_display.h"
Zhao Yakuid112a812012-08-08 13:55:55 +000031#include "intel_bios.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000032#include "gtt.h"
33#include "power.h"
Alan Coxd839ede2012-05-03 15:06:18 +010034#include "opregion.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000035#include "oaktrail.h"
Patrik Jakobssonac1b01b2014-01-04 19:35:20 +010036#include "mmu.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000037
Arthur Borsboomf90cd812014-03-15 22:12:17 +010038#define DRIVER_AUTHOR "Alan Cox <alan@linux.intel.com> and others"
39#define DRIVER_LICENSE "GPL"
40
41#define DRIVER_NAME "gma500"
42#define DRIVER_DESC "DRM driver for the Intel GMA500, GMA600, GMA3600, GMA3650"
43#define DRIVER_DATE "20140314"
44
45#define DRIVER_MAJOR 1
46#define DRIVER_MINOR 0
47#define DRIVER_PATCHLEVEL 0
48
Alan Cox5c49fd32011-11-03 18:22:04 +000049/* Append new drm mode definition here, align with libdrm definition */
50#define DRM_MODE_SCALE_NO_SCALE 2
51
52enum {
53 CHIP_PSB_8108 = 0, /* Poulsbo */
54 CHIP_PSB_8109 = 1, /* Poulsbo */
55 CHIP_MRST_4100 = 2, /* Moorestown/Oaktrail */
56 CHIP_MFLD_0130 = 3, /* Medfield */
57};
58
Ville Syrjäläffbab09b2013-10-04 14:53:40 +030059#define IS_PSB(dev) (((dev)->pdev->device & 0xfffe) == 0x8108)
Patrik Jakobsson9d3e2f52013-09-16 17:46:17 +020060#define IS_MRST(dev) (((dev)->pdev->device & 0xfff0) == 0x4100)
Ville Syrjäläffbab09b2013-10-04 14:53:40 +030061#define IS_MFLD(dev) (((dev)->pdev->device & 0xfff8) == 0x0130)
62#define IS_CDV(dev) (((dev)->pdev->device & 0xfff0) == 0x0be0)
Alan Cox5c49fd32011-11-03 18:22:04 +000063
Alan Cox5c49fd32011-11-03 18:22:04 +000064
65/*
66 * Hardware offsets
67 */
68#define PSB_VDC_OFFSET 0x00000000
69#define PSB_VDC_SIZE 0x000080000
70#define MRST_MMIO_SIZE 0x0000C0000
71#define MDFLD_MMIO_SIZE 0x000100000
72#define PSB_SGX_SIZE 0x8000
73#define PSB_SGX_OFFSET 0x00040000
74#define MRST_SGX_OFFSET 0x00080000
75/*
76 * PCI resource identifiers
77 */
78#define PSB_MMIO_RESOURCE 0
Patrik Jakobsson26579292013-09-16 18:02:40 +020079#define PSB_AUX_RESOURCE 0
Alan Cox5c49fd32011-11-03 18:22:04 +000080#define PSB_GATT_RESOURCE 2
81#define PSB_GTT_RESOURCE 3
82/*
83 * PCI configuration
84 */
85#define PSB_GMCH_CTRL 0x52
86#define PSB_BSM 0x5C
87#define _PSB_GMCH_ENABLED 0x4
88#define PSB_PGETBL_CTL 0x2020
89#define _PSB_PGETBL_ENABLED 0x00000001
90#define PSB_SGX_2D_SLAVE_PORT 0x4000
91
92/* To get rid of */
93#define PSB_TT_PRIV0_LIMIT (256*1024*1024)
94#define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT)
95
96/*
97 * SGX side MMU definitions (these can probably go)
98 */
99
100/*
101 * Flags for external memory type field.
102 */
103#define PSB_MMU_CACHED_MEMORY 0x0001 /* Bind to MMU only */
104#define PSB_MMU_RO_MEMORY 0x0002 /* MMU RO memory */
105#define PSB_MMU_WO_MEMORY 0x0004 /* MMU WO memory */
106/*
107 * PTE's and PDE's
108 */
109#define PSB_PDE_MASK 0x003FFFFF
110#define PSB_PDE_SHIFT 22
111#define PSB_PTE_SHIFT 12
112/*
113 * Cache control
114 */
115#define PSB_PTE_VALID 0x0001 /* PTE / PDE valid */
116#define PSB_PTE_WO 0x0002 /* Write only */
117#define PSB_PTE_RO 0x0004 /* Read only */
118#define PSB_PTE_CACHED 0x0008 /* CPU cache coherent */
119
120/*
121 * VDC registers and bits
122 */
123#define PSB_MSVDX_CLOCKGATING 0x2064
124#define PSB_TOPAZ_CLOCKGATING 0x2068
125#define PSB_HWSTAM 0x2098
126#define PSB_INSTPM 0x20C0
127#define PSB_INT_IDENTITY_R 0x20A4
Alan Coxd839ede2012-05-03 15:06:18 +0100128#define _PSB_IRQ_ASLE (1<<0)
Alan Cox5c49fd32011-11-03 18:22:04 +0000129#define _MDFLD_PIPEC_EVENT_FLAG (1<<2)
130#define _MDFLD_PIPEC_VBLANK_FLAG (1<<3)
131#define _PSB_DPST_PIPEB_FLAG (1<<4)
132#define _MDFLD_PIPEB_EVENT_FLAG (1<<4)
133#define _PSB_VSYNC_PIPEB_FLAG (1<<5)
134#define _PSB_DPST_PIPEA_FLAG (1<<6)
135#define _PSB_PIPEA_EVENT_FLAG (1<<6)
136#define _PSB_VSYNC_PIPEA_FLAG (1<<7)
137#define _MDFLD_MIPIA_FLAG (1<<16)
138#define _MDFLD_MIPIC_FLAG (1<<17)
Alan Cox68cb6382012-04-25 14:38:20 +0100139#define _PSB_IRQ_DISP_HOTSYNC (1<<17)
Alan Cox5c49fd32011-11-03 18:22:04 +0000140#define _PSB_IRQ_SGX_FLAG (1<<18)
141#define _PSB_IRQ_MSVDX_FLAG (1<<19)
142#define _LNC_IRQ_TOPAZ_FLAG (1<<20)
143
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000144#define _PSB_PIPE_EVENT_FLAG (_PSB_VSYNC_PIPEA_FLAG | \
145 _PSB_VSYNC_PIPEB_FLAG)
146
Alan Cox5c49fd32011-11-03 18:22:04 +0000147/* This flag includes all the display IRQ bits excepts the vblank irqs. */
148#define _MDFLD_DISP_ALL_IRQ_FLAG (_MDFLD_PIPEC_EVENT_FLAG | \
149 _MDFLD_PIPEB_EVENT_FLAG | \
150 _PSB_PIPEA_EVENT_FLAG | \
151 _PSB_VSYNC_PIPEA_FLAG | \
152 _MDFLD_MIPIA_FLAG | \
153 _MDFLD_MIPIC_FLAG)
154#define PSB_INT_IDENTITY_R 0x20A4
155#define PSB_INT_MASK_R 0x20A8
156#define PSB_INT_ENABLE_R 0x20A0
157
158#define _PSB_MMU_ER_MASK 0x0001FF00
159#define _PSB_MMU_ER_HOST (1 << 16)
160#define GPIOA 0x5010
161#define GPIOB 0x5014
162#define GPIOC 0x5018
163#define GPIOD 0x501c
164#define GPIOE 0x5020
165#define GPIOF 0x5024
166#define GPIOG 0x5028
167#define GPIOH 0x502c
168#define GPIO_CLOCK_DIR_MASK (1 << 0)
169#define GPIO_CLOCK_DIR_IN (0 << 1)
170#define GPIO_CLOCK_DIR_OUT (1 << 1)
171#define GPIO_CLOCK_VAL_MASK (1 << 2)
172#define GPIO_CLOCK_VAL_OUT (1 << 3)
173#define GPIO_CLOCK_VAL_IN (1 << 4)
174#define GPIO_CLOCK_PULLUP_DISABLE (1 << 5)
175#define GPIO_DATA_DIR_MASK (1 << 8)
176#define GPIO_DATA_DIR_IN (0 << 9)
177#define GPIO_DATA_DIR_OUT (1 << 9)
178#define GPIO_DATA_VAL_MASK (1 << 10)
179#define GPIO_DATA_VAL_OUT (1 << 11)
180#define GPIO_DATA_VAL_IN (1 << 12)
181#define GPIO_DATA_PULLUP_DISABLE (1 << 13)
182
183#define VCLK_DIVISOR_VGA0 0x6000
184#define VCLK_DIVISOR_VGA1 0x6004
185#define VCLK_POST_DIV 0x6010
186
187#define PSB_COMM_2D (PSB_ENGINE_2D << 4)
188#define PSB_COMM_3D (PSB_ENGINE_3D << 4)
189#define PSB_COMM_TA (PSB_ENGINE_TA << 4)
190#define PSB_COMM_HP (PSB_ENGINE_HP << 4)
191#define PSB_COMM_USER_IRQ (1024 >> 2)
192#define PSB_COMM_USER_IRQ_LOST (PSB_COMM_USER_IRQ + 1)
193#define PSB_COMM_FW (2048 >> 2)
194
195#define PSB_UIRQ_VISTEST 1
196#define PSB_UIRQ_OOM_REPLY 2
197#define PSB_UIRQ_FIRE_TA_REPLY 3
198#define PSB_UIRQ_FIRE_RASTER_REPLY 4
199
200#define PSB_2D_SIZE (256*1024*1024)
201#define PSB_MAX_RELOC_PAGES 1024
202
203#define PSB_LOW_REG_OFFS 0x0204
204#define PSB_HIGH_REG_OFFS 0x0600
205
206#define PSB_NUM_VBLANKS 2
207
208
209#define PSB_2D_SIZE (256*1024*1024)
210#define PSB_MAX_RELOC_PAGES 1024
211
212#define PSB_LOW_REG_OFFS 0x0204
213#define PSB_HIGH_REG_OFFS 0x0600
214
215#define PSB_NUM_VBLANKS 2
Daniel Vetterbfd83032013-12-11 11:34:41 +0100216#define PSB_WATCHDOG_DELAY (HZ * 2)
217#define PSB_LID_DELAY (HZ / 10)
Alan Cox5c49fd32011-11-03 18:22:04 +0000218
219#define MDFLD_PNW_B0 0x04
220#define MDFLD_PNW_C0 0x08
221
222#define MDFLD_DSR_2D_3D_0 (1 << 0)
223#define MDFLD_DSR_2D_3D_2 (1 << 1)
224#define MDFLD_DSR_CURSOR_0 (1 << 2)
225#define MDFLD_DSR_CURSOR_2 (1 << 3)
226#define MDFLD_DSR_OVERLAY_0 (1 << 4)
227#define MDFLD_DSR_OVERLAY_2 (1 << 5)
228#define MDFLD_DSR_MIPI_CONTROL (1 << 6)
229#define MDFLD_DSR_DAMAGE_MASK_0 ((1 << 0) | (1 << 2) | (1 << 4))
230#define MDFLD_DSR_DAMAGE_MASK_2 ((1 << 1) | (1 << 3) | (1 << 5))
231#define MDFLD_DSR_2D_3D (MDFLD_DSR_2D_3D_0 | MDFLD_DSR_2D_3D_2)
232
233#define MDFLD_DSR_RR 45
234#define MDFLD_DPU_ENABLE (1 << 31)
235#define MDFLD_DSR_FULLSCREEN (1 << 30)
Daniel Vetterbfd83032013-12-11 11:34:41 +0100236#define MDFLD_DSR_DELAY (HZ / MDFLD_DSR_RR)
Alan Cox5c49fd32011-11-03 18:22:04 +0000237
238#define PSB_PWR_STATE_ON 1
239#define PSB_PWR_STATE_OFF 2
240
241#define PSB_PMPOLICY_NOPM 0
242#define PSB_PMPOLICY_CLOCKGATING 1
243#define PSB_PMPOLICY_POWERDOWN 2
244
245#define PSB_PMSTATE_POWERUP 0
246#define PSB_PMSTATE_CLOCKGATED 1
247#define PSB_PMSTATE_POWERDOWN 2
248#define PSB_PCIx_MSI_ADDR_LOC 0x94
249#define PSB_PCIx_MSI_DATA_LOC 0x98
250
251/* Medfield crystal settings */
252#define KSEL_CRYSTAL_19 1
253#define KSEL_BYPASS_19 5
254#define KSEL_BYPASS_25 6
255#define KSEL_BYPASS_83_100 7
256
257struct opregion_header;
258struct opregion_acpi;
259struct opregion_swsci;
260struct opregion_asle;
261
262struct psb_intel_opregion {
263 struct opregion_header *header;
264 struct opregion_acpi *acpi;
265 struct opregion_swsci *swsci;
266 struct opregion_asle *asle;
Alan Cox1fb28e92012-04-25 14:37:14 +0100267 void *vbt;
Alan Coxd839ede2012-05-03 15:06:18 +0100268 u32 __iomem *lid_state;
Patrik Jakobsson778e26d2014-03-11 18:51:20 +0100269 struct work_struct asle_work;
Alan Cox5c49fd32011-11-03 18:22:04 +0000270};
271
Patrik Jakobsson57369952011-12-19 21:41:10 +0000272struct sdvo_device_mapping {
273 u8 initialized;
274 u8 dvo_port;
275 u8 slave_addr;
276 u8 dvo_wiring;
277 u8 i2c_pin;
278 u8 i2c_speed;
279 u8 ddc_pin;
280};
281
Patrik Jakobsson5c0c1d52011-12-19 21:40:58 +0000282struct intel_gmbus {
283 struct i2c_adapter adapter;
284 struct i2c_adapter *force_bit;
285 u32 reg0;
286};
287
Alan Cox648a8e32012-03-08 16:00:31 +0000288/*
Alan Cox8512e072012-05-11 11:30:53 +0100289 * Register offset maps
290 */
291
292struct psb_offset {
293 u32 fp0;
294 u32 fp1;
295 u32 cntr;
296 u32 conf;
297 u32 src;
298 u32 dpll;
299 u32 dpll_md;
300 u32 htotal;
301 u32 hblank;
302 u32 hsync;
303 u32 vtotal;
304 u32 vblank;
305 u32 vsync;
306 u32 stride;
307 u32 size;
308 u32 pos;
309 u32 surf;
310 u32 addr;
311 u32 base;
312 u32 status;
313 u32 linoff;
314 u32 tileoff;
315 u32 palette;
316};
317
318/*
Alan Cox648a8e32012-03-08 16:00:31 +0000319 * Register save state. This is used to hold the context when the
320 * device is powered off. In the case of Oaktrail this can (but does not
321 * yet) include screen blank. Operations occuring during the save
322 * update the register cache instead.
323 */
Alan Cox62563042012-05-11 11:30:16 +0100324
325/*
326 * Common status for pipes.
327 */
328struct psb_pipe {
329 u32 fp0;
330 u32 fp1;
331 u32 cntr;
332 u32 conf;
333 u32 src;
334 u32 dpll;
335 u32 dpll_md;
336 u32 htotal;
337 u32 hblank;
338 u32 hsync;
339 u32 vtotal;
340 u32 vblank;
341 u32 vsync;
342 u32 stride;
343 u32 size;
344 u32 pos;
345 u32 base;
346 u32 surf;
347 u32 addr;
348 u32 status;
349 u32 linoff;
350 u32 tileoff;
351 u32 palette[256];
352};
353
Alan Cox648a8e32012-03-08 16:00:31 +0000354struct psb_state {
Alan Cox648a8e32012-03-08 16:00:31 +0000355 uint32_t saveVCLK_DIVISOR_VGA0;
356 uint32_t saveVCLK_DIVISOR_VGA1;
357 uint32_t saveVCLK_POST_DIV;
358 uint32_t saveVGACNTRL;
359 uint32_t saveADPA;
360 uint32_t saveLVDS;
361 uint32_t saveDVOA;
362 uint32_t saveDVOB;
363 uint32_t saveDVOC;
364 uint32_t savePP_ON;
365 uint32_t savePP_OFF;
366 uint32_t savePP_CONTROL;
367 uint32_t savePP_CYCLE;
368 uint32_t savePFIT_CONTROL;
Alan Cox648a8e32012-03-08 16:00:31 +0000369 uint32_t saveCLOCKGATING;
370 uint32_t saveDSPARB;
Alan Cox648a8e32012-03-08 16:00:31 +0000371 uint32_t savePFIT_AUTO_RATIOS;
372 uint32_t savePFIT_PGM_RATIOS;
373 uint32_t savePP_ON_DELAYS;
374 uint32_t savePP_OFF_DELAYS;
375 uint32_t savePP_DIVISOR;
Alan Cox648a8e32012-03-08 16:00:31 +0000376 uint32_t saveBCLRPAT_A;
377 uint32_t saveBCLRPAT_B;
Alan Cox648a8e32012-03-08 16:00:31 +0000378 uint32_t savePERF_MODE;
379 uint32_t saveDSPFW1;
380 uint32_t saveDSPFW2;
381 uint32_t saveDSPFW3;
382 uint32_t saveDSPFW4;
383 uint32_t saveDSPFW5;
384 uint32_t saveDSPFW6;
385 uint32_t saveCHICKENBIT;
386 uint32_t saveDSPACURSOR_CTRL;
387 uint32_t saveDSPBCURSOR_CTRL;
388 uint32_t saveDSPACURSOR_BASE;
389 uint32_t saveDSPBCURSOR_BASE;
390 uint32_t saveDSPACURSOR_POS;
391 uint32_t saveDSPBCURSOR_POS;
Alan Cox648a8e32012-03-08 16:00:31 +0000392 uint32_t saveOV_OVADD;
393 uint32_t saveOV_OGAMC0;
394 uint32_t saveOV_OGAMC1;
395 uint32_t saveOV_OGAMC2;
396 uint32_t saveOV_OGAMC3;
397 uint32_t saveOV_OGAMC4;
398 uint32_t saveOV_OGAMC5;
399 uint32_t saveOVC_OVADD;
400 uint32_t saveOVC_OGAMC0;
401 uint32_t saveOVC_OGAMC1;
402 uint32_t saveOVC_OGAMC2;
403 uint32_t saveOVC_OGAMC3;
404 uint32_t saveOVC_OGAMC4;
405 uint32_t saveOVC_OGAMC5;
406
407 /* DPST register save */
408 uint32_t saveHISTOGRAM_INT_CONTROL_REG;
409 uint32_t saveHISTOGRAM_LOGIC_CONTROL_REG;
410 uint32_t savePWM_CONTROL_LOGIC;
411};
412
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000413struct medfield_state {
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000414 uint32_t saveMIPI;
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000415 uint32_t saveMIPI_C;
416
417 uint32_t savePFIT_CONTROL;
418 uint32_t savePFIT_PGM_RATIOS;
419 uint32_t saveHDMIPHYMISCCTL;
420 uint32_t saveHDMIB_CONTROL;
421};
422
Alan Cox09016a12012-03-14 12:00:29 +0000423struct cdv_state {
424 uint32_t saveDSPCLK_GATE_D;
425 uint32_t saveRAMCLK_GATE_D;
426 uint32_t saveDSPARB;
427 uint32_t saveDSPFW[6];
428 uint32_t saveADPA;
429 uint32_t savePP_CONTROL;
430 uint32_t savePFIT_PGM_RATIOS;
431 uint32_t saveLVDS;
432 uint32_t savePFIT_CONTROL;
433 uint32_t savePP_ON_DELAYS;
434 uint32_t savePP_OFF_DELAYS;
435 uint32_t savePP_CYCLE;
436 uint32_t saveVGACNTRL;
437 uint32_t saveIER;
438 uint32_t saveIMR;
439 u8 saveLBB;
440};
441
Alan Coxc6265ff2012-03-08 16:02:05 +0000442struct psb_save_area {
Alan Cox62563042012-05-11 11:30:16 +0100443 struct psb_pipe pipe[3];
Alan Coxc6265ff2012-03-08 16:02:05 +0000444 uint32_t saveBSM;
445 uint32_t saveVBT;
446 union {
447 struct psb_state psb;
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000448 struct medfield_state mdfld;
Alan Cox09016a12012-03-14 12:00:29 +0000449 struct cdv_state cdv;
Alan Coxc6265ff2012-03-08 16:02:05 +0000450 };
451 uint32_t saveBLC_PWM_CTL2;
452 uint32_t saveBLC_PWM_CTL;
453};
454
Alan Cox5c49fd32011-11-03 18:22:04 +0000455struct psb_ops;
456
Alan Cox04bd5642011-11-16 22:39:32 +0000457#define PSB_NUM_PIPE 3
458
Alan Cox5c49fd32011-11-03 18:22:04 +0000459struct drm_psb_private {
460 struct drm_device *dev;
Patrik Jakobsson26579292013-09-16 18:02:40 +0200461 struct pci_dev *aux_pdev; /* Currently only used by mrst */
Alan Cox5c49fd32011-11-03 18:22:04 +0000462 const struct psb_ops *ops;
Alan Cox8512e072012-05-11 11:30:53 +0100463 const struct psb_offset *regmap;
Alan Cox1fb28e92012-04-25 14:37:14 +0100464
465 struct child_device_config *child_dev;
466 int child_dev_num;
Alan Cox5c49fd32011-11-03 18:22:04 +0000467
468 struct psb_gtt gtt;
469
470 /* GTT Memory manager */
471 struct psb_gtt_mm *gtt_mm;
472 struct page *scratch_page;
Kirill A. Shutemoveab37602012-05-03 15:07:46 +0100473 u32 __iomem *gtt_map;
Alan Cox5c49fd32011-11-03 18:22:04 +0000474 uint32_t stolen_base;
Kirill A. Shutemov37214ca2012-05-03 15:08:26 +0100475 u8 __iomem *vram_addr;
Alan Cox5c49fd32011-11-03 18:22:04 +0000476 unsigned long vram_stolen_size;
477 int gtt_initialized;
478 u16 gmch_ctrl; /* Saved GTT setup */
479 u32 pge_ctl;
480
481 struct mutex gtt_mutex;
482 struct resource *gtt_mem; /* Our PCI resource */
483
484 struct psb_mmu_driver *mmu;
485 struct psb_mmu_pd *pf_pd;
486
487 /*
488 * Register base
489 */
490
Kirill A. Shutemov846a6032012-05-03 15:08:08 +0100491 uint8_t __iomem *sgx_reg;
492 uint8_t __iomem *vdc_reg;
Patrik Jakobsson26579292013-09-16 18:02:40 +0200493 uint8_t __iomem *aux_reg; /* Auxillary vdc pipe regs */
Alan Cox5c49fd32011-11-03 18:22:04 +0000494 uint32_t gatt_free_offset;
495
496 /*
497 * Fencing / irq.
498 */
499
500 uint32_t vdc_irq_mask;
501 uint32_t pipestat[PSB_NUM_PIPE];
502
503 spinlock_t irqmask_lock;
504
505 /*
506 * Power
507 */
508
509 bool suspended;
510 bool display_power;
511 int display_count;
512
513 /*
514 * Modesetting
515 */
516 struct psb_intel_mode_device mode_dev;
Alan Cox4ab2c7f2012-05-14 12:04:00 +0100517 bool modeset; /* true if we have done the mode_device setup */
Alan Cox5c49fd32011-11-03 18:22:04 +0000518
519 struct drm_crtc *plane_to_crtc_mapping[PSB_NUM_PIPE];
520 struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE];
521 uint32_t num_pipe;
522
523 /*
524 * OSPM info (Power management base) (can go ?)
525 */
526 uint32_t ospm_base;
527
528 /*
529 * Sizes info
530 */
531
Alan Cox5c49fd32011-11-03 18:22:04 +0000532 u32 fuse_reg_value;
533 u32 video_device_fuse;
534
535 /* PCI revision ID for B0:D2:F0 */
536 uint8_t platform_rev_id;
537
Patrik Jakobsson5c0c1d52011-12-19 21:40:58 +0000538 /* gmbus */
539 struct intel_gmbus *gmbus;
Patrik Jakobsson26579292013-09-16 18:02:40 +0200540 uint8_t __iomem *gmbus_reg;
Patrik Jakobsson5c0c1d52011-12-19 21:40:58 +0000541
Patrik Jakobsson57369952011-12-19 21:41:10 +0000542 /* Used by SDVO */
543 int crt_ddc_pin;
544 /* FIXME: The mappings should be parsed from bios but for now we can
545 pretend there are no mappings available */
546 struct sdvo_device_mapping sdvo_mappings[2];
547 u32 hotplug_supported_mask;
548 struct drm_property *broadcast_rgb_property;
549 struct drm_property *force_audio_property;
550
Alan Cox5c49fd32011-11-03 18:22:04 +0000551 /*
552 * LVDS info
553 */
554 int backlight_duty_cycle; /* restore backlight to this value */
555 bool panel_wants_dither;
556 struct drm_display_mode *panel_fixed_mode;
557 struct drm_display_mode *lfp_lvds_vbt_mode;
558 struct drm_display_mode *sdvo_lvds_vbt_mode;
559
560 struct bdb_lvds_backlight *lvds_bl; /* LVDS backlight info from VBT */
Patrik Jakobssona12d6a02011-12-19 21:41:22 +0000561 struct psb_intel_i2c_chan *lvds_i2c_bus; /* FIXME: Remove this? */
Alan Cox5c49fd32011-11-03 18:22:04 +0000562
563 /* Feature bits from the VBIOS */
564 unsigned int int_tv_support:1;
565 unsigned int lvds_dither:1;
566 unsigned int lvds_vbt:1;
567 unsigned int int_crt_support:1;
568 unsigned int lvds_use_ssc:1;
569 int lvds_ssc_freq;
570 bool is_lvds_on;
571 bool is_mipi_on;
572 u32 mipi_ctrl_display;
573
574 unsigned int core_freq;
575 uint32_t iLVDS_enable;
576
577 /* Runtime PM state */
578 int rpm_enabled;
579
580 /* MID specific */
Kirill A. Shutemov4086b1e2012-05-03 16:27:21 +0100581 bool has_gct;
Alan Cox5c49fd32011-11-03 18:22:04 +0000582 struct oaktrail_gct_data gct_data;
583
Alan Cox933315a2012-03-08 16:00:17 +0000584 /* Oaktrail HDMI state */
Alan Cox5c49fd32011-11-03 18:22:04 +0000585 struct oaktrail_hdmi_dev *hdmi_priv;
Alan Cox933315a2012-03-08 16:00:17 +0000586
Alan Cox5c49fd32011-11-03 18:22:04 +0000587 /*
588 * Register state
589 */
Alan Coxc6265ff2012-03-08 16:02:05 +0000590
591 struct psb_save_area regs;
592
Alan Cox5c49fd32011-11-03 18:22:04 +0000593 /* MSI reg save */
594 uint32_t msi_addr;
595 uint32_t msi_data;
596
Alan Coxae0a2462012-04-25 14:38:32 +0100597 /*
598 * Hotplug handling
599 */
600
601 struct work_struct hotplug_work;
Alan Cox5c49fd32011-11-03 18:22:04 +0000602
603 /*
Alan Cox5c49fd32011-11-03 18:22:04 +0000604 * LID-Switch
605 */
606 spinlock_t lid_lock;
607 struct timer_list lid_timer;
608 struct psb_intel_opregion opregion;
Alan Cox5c49fd32011-11-03 18:22:04 +0000609 u32 lid_last_state;
610
611 /*
612 * Watchdog
613 */
614
615 uint32_t apm_reg;
616 uint16_t apm_base;
617
618 /*
619 * Used for modifying backlight from
620 * xrandr -- consider removing and using HAL instead
621 */
622 struct backlight_device *backlight_device;
623 struct drm_property *backlight_property;
Zhao Yakuid112a812012-08-08 13:55:55 +0000624 bool backlight_enabled;
625 int backlight_level;
Alan Cox5c49fd32011-11-03 18:22:04 +0000626 uint32_t blc_adj1;
627 uint32_t blc_adj2;
628
629 void *fbdev;
630
631 /* 2D acceleration */
Alan Cox9242fe22011-11-29 22:27:10 +0000632 spinlock_t lock_2d;
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000633
634 /*
635 * Panel brightness
636 */
637 int brightness;
638 int brightness_adjusted;
639
640 bool dsr_enable;
641 u32 dsr_fb_update;
642 bool dpi_panel_on[3];
643 void *dsi_configs[2];
644 u32 bpp;
645 u32 bpp2;
646
647 u32 pipeconf[3];
648 u32 dspcntr[3];
649
650 int mdfld_panel_id;
Alan Cox642c52f2012-04-25 14:36:34 +0100651
652 bool dplla_96mhz; /* DPLL data from the VBT */
Zhao Yakuid112a812012-08-08 13:55:55 +0000653
654 struct {
655 int rate;
656 int lanes;
657 int preemphasis;
658 int vswing;
659
660 bool initialized;
661 bool support;
662 int bpp;
663 struct edp_power_seq pps;
664 } edp;
665 uint8_t panel_type;
Alan Cox5c49fd32011-11-03 18:22:04 +0000666};
667
668
669/*
670 * Operations for each board type
671 */
672
673struct psb_ops {
674 const char *name;
675 unsigned int accel_2d:1;
676 int pipes; /* Number of output pipes */
677 int crtcs; /* Number of CRTCs */
678 int sgx_offset; /* Base offset of SGX device */
Alan Coxd235e642012-04-25 14:38:07 +0100679 int hdmi_mask; /* Mask of HDMI CRTCs */
680 int lvds_mask; /* Mask of LVDS CRTCs */
Patrik Jakobssoncf8efd32013-09-16 17:54:54 +0200681 int sdvo_mask; /* Mask of SDVO CRTCs */
Patrik Jakobssonbc794822012-05-21 15:27:30 +0100682 int cursor_needs_phys; /* If cursor base reg need physical address */
Alan Cox5c49fd32011-11-03 18:22:04 +0000683
684 /* Sub functions */
685 struct drm_crtc_helper_funcs const *crtc_helper;
686 struct drm_crtc_funcs const *crtc_funcs;
Patrik Jakobsson5ea75e02013-06-30 21:39:00 +0200687 const struct gma_clock_funcs *clock_funcs;
Alan Cox5c49fd32011-11-03 18:22:04 +0000688
689 /* Setup hooks */
690 int (*chip_setup)(struct drm_device *dev);
691 void (*chip_teardown)(struct drm_device *dev);
Alan Coxd235e642012-04-25 14:38:07 +0100692 /* Optional helper caller after modeset */
693 void (*errata)(struct drm_device *dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000694
695 /* Display management hooks */
696 int (*output_init)(struct drm_device *dev);
Alan Cox68cb6382012-04-25 14:38:20 +0100697 int (*hotplug)(struct drm_device *dev);
698 void (*hotplug_enable)(struct drm_device *dev, bool on);
Alan Cox5c49fd32011-11-03 18:22:04 +0000699 /* Power management hooks */
700 void (*init_pm)(struct drm_device *dev);
701 int (*save_regs)(struct drm_device *dev);
702 int (*restore_regs)(struct drm_device *dev);
703 int (*power_up)(struct drm_device *dev);
704 int (*power_down)(struct drm_device *dev);
Patrik Jakobsson28a81942013-08-14 19:14:17 +0200705 void (*update_wm)(struct drm_device *dev, struct drm_crtc *crtc);
Patrik Jakobsson75346fe2013-08-15 00:54:44 +0200706 void (*disable_sr)(struct drm_device *dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000707
708 void (*lvds_bl_power)(struct drm_device *dev, bool on);
709#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
710 /* Backlight */
711 int (*backlight_init)(struct drm_device *dev);
712#endif
713 int i2c_bus; /* I2C bus identifier for Moorestown */
714};
715
716
717
Alan Cox5c49fd32011-11-03 18:22:04 +0000718extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int);
719extern int drm_pick_crtcs(struct drm_device *dev);
720
721static inline struct drm_psb_private *psb_priv(struct drm_device *dev)
722{
723 return (struct drm_psb_private *) dev->dev_private;
724}
725
726/*
Alan Cox5c49fd32011-11-03 18:22:04 +0000727 *psb_irq.c
728 */
729
Daniel Vettere9f0d762013-12-11 11:34:42 +0100730extern irqreturn_t psb_irq_handler(int irq, void *arg);
Alan Cox5c49fd32011-11-03 18:22:04 +0000731extern int psb_irq_enable_dpst(struct drm_device *dev);
732extern int psb_irq_disable_dpst(struct drm_device *dev);
733extern void psb_irq_preinstall(struct drm_device *dev);
734extern int psb_irq_postinstall(struct drm_device *dev);
735extern void psb_irq_uninstall(struct drm_device *dev);
736extern void psb_irq_turn_on_dpst(struct drm_device *dev);
737extern void psb_irq_turn_off_dpst(struct drm_device *dev);
738
739extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
740extern int psb_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
741extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
742extern int psb_enable_vblank(struct drm_device *dev, int crtc);
743extern void psb_disable_vblank(struct drm_device *dev, int crtc);
744void
745psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
746
747void
748psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
749
750extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc);
751
752/*
Alan Cox5c49fd32011-11-03 18:22:04 +0000753 * framebuffer.c
754 */
755extern int psbfb_probed(struct drm_device *dev);
756extern int psbfb_remove(struct drm_device *dev,
757 struct drm_framebuffer *fb);
758/*
759 * accel_2d.c
760 */
761extern void psbfb_copyarea(struct fb_info *info,
762 const struct fb_copyarea *region);
763extern int psbfb_sync(struct fb_info *info);
764extern void psb_spank(struct drm_psb_private *dev_priv);
765
766/*
767 * psb_reset.c
768 */
769
770extern void psb_lid_timer_init(struct drm_psb_private *dev_priv);
771extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
772extern void psb_print_pagefault(struct drm_psb_private *dev_priv);
773
774/* modesetting */
775extern void psb_modeset_init(struct drm_device *dev);
776extern void psb_modeset_cleanup(struct drm_device *dev);
777extern int psb_fbdev_init(struct drm_device *dev);
778
779/* backlight.c */
780int gma_backlight_init(struct drm_device *dev);
781void gma_backlight_exit(struct drm_device *dev);
Zhao Yakuid112a812012-08-08 13:55:55 +0000782void gma_backlight_disable(struct drm_device *dev);
783void gma_backlight_enable(struct drm_device *dev);
784void gma_backlight_set(struct drm_device *dev, int v);
Alan Cox5c49fd32011-11-03 18:22:04 +0000785
786/* oaktrail_crtc.c */
787extern const struct drm_crtc_helper_funcs oaktrail_helper_funcs;
788
789/* oaktrail_lvds.c */
790extern void oaktrail_lvds_init(struct drm_device *dev,
791 struct psb_intel_mode_device *mode_dev);
792
793/* psb_intel_display.c */
794extern const struct drm_crtc_helper_funcs psb_intel_helper_funcs;
795extern const struct drm_crtc_funcs psb_intel_crtc_funcs;
796
797/* psb_intel_lvds.c */
798extern const struct drm_connector_helper_funcs
799 psb_intel_lvds_connector_helper_funcs;
800extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
801
802/* gem.c */
Alan Cox5c49fd32011-11-03 18:22:04 +0000803extern void psb_gem_free_object(struct drm_gem_object *obj);
804extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
805 struct drm_file *file);
806extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
807 struct drm_mode_create_dumb *args);
Alan Cox5c49fd32011-11-03 18:22:04 +0000808extern int psb_gem_dumb_map_gtt(struct drm_file *file, struct drm_device *dev,
809 uint32_t handle, uint64_t *offset);
810extern int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
811extern int psb_gem_create_ioctl(struct drm_device *dev, void *data,
812 struct drm_file *file);
813extern int psb_gem_mmap_ioctl(struct drm_device *dev, void *data,
814 struct drm_file *file);
815
816/* psb_device.c */
817extern const struct psb_ops psb_chip_ops;
818
819/* oaktrail_device.c */
820extern const struct psb_ops oaktrail_chip_ops;
821
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000822/* mdlfd_device.c */
823extern const struct psb_ops mdfld_chip_ops;
824
Alan Cox5c49fd32011-11-03 18:22:04 +0000825/* cdv_device.c */
826extern const struct psb_ops cdv_chip_ops;
827
828/*
829 * Debug print bits setting
830 */
831#define PSB_D_GENERAL (1 << 0)
832#define PSB_D_INIT (1 << 1)
833#define PSB_D_IRQ (1 << 2)
834#define PSB_D_ENTRY (1 << 3)
835/* debug the get H/V BP/FP count */
836#define PSB_D_HV (1 << 4)
837#define PSB_D_DBI_BF (1 << 5)
838#define PSB_D_PM (1 << 6)
839#define PSB_D_RENDER (1 << 7)
840#define PSB_D_REG (1 << 8)
841#define PSB_D_MSVDX (1 << 9)
842#define PSB_D_TOPAZ (1 << 10)
843
Alan Cox5c49fd32011-11-03 18:22:04 +0000844extern int drm_idle_check_interval;
845
846/*
847 * Utilities
848 */
849
850static inline u32 MRST_MSG_READ32(uint port, uint offset)
851{
852 int mcr = (0xD0<<24) | (port << 16) | (offset << 8);
853 uint32_t ret_val = 0;
854 struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
855 pci_write_config_dword(pci_root, 0xD0, mcr);
856 pci_read_config_dword(pci_root, 0xD4, &ret_val);
857 pci_dev_put(pci_root);
858 return ret_val;
859}
860static inline void MRST_MSG_WRITE32(uint port, uint offset, u32 value)
861{
862 int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0;
863 struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
864 pci_write_config_dword(pci_root, 0xD4, value);
865 pci_write_config_dword(pci_root, 0xD0, mcr);
866 pci_dev_put(pci_root);
867}
868static inline u32 MDFLD_MSG_READ32(uint port, uint offset)
869{
870 int mcr = (0x10<<24) | (port << 16) | (offset << 8);
871 uint32_t ret_val = 0;
872 struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
873 pci_write_config_dword(pci_root, 0xD0, mcr);
874 pci_read_config_dword(pci_root, 0xD4, &ret_val);
875 pci_dev_put(pci_root);
876 return ret_val;
877}
878static inline void MDFLD_MSG_WRITE32(uint port, uint offset, u32 value)
879{
880 int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0;
881 struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
882 pci_write_config_dword(pci_root, 0xD4, value);
883 pci_write_config_dword(pci_root, 0xD0, mcr);
884 pci_dev_put(pci_root);
885}
886
887static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg)
888{
889 struct drm_psb_private *dev_priv = dev->dev_private;
890 return ioread32(dev_priv->vdc_reg + reg);
891}
892
Patrik Jakobsson26579292013-09-16 18:02:40 +0200893static inline uint32_t REGISTER_READ_AUX(struct drm_device *dev, uint32_t reg)
894{
895 struct drm_psb_private *dev_priv = dev->dev_private;
896 return ioread32(dev_priv->aux_reg + reg);
897}
898
Alan Cox5c49fd32011-11-03 18:22:04 +0000899#define REG_READ(reg) REGISTER_READ(dev, (reg))
Patrik Jakobsson26579292013-09-16 18:02:40 +0200900#define REG_READ_AUX(reg) REGISTER_READ_AUX(dev, (reg))
Alan Cox5c49fd32011-11-03 18:22:04 +0000901
Patrik Jakobssonb97b8282013-11-07 00:14:18 +0100902/* Useful for post reads */
903static inline uint32_t REGISTER_READ_WITH_AUX(struct drm_device *dev,
904 uint32_t reg, int aux)
905{
906 uint32_t val;
907
908 if (aux)
909 val = REG_READ_AUX(reg);
910 else
911 val = REG_READ(reg);
912
913 return val;
914}
915
916#define REG_READ_WITH_AUX(reg, aux) REGISTER_READ_WITH_AUX(dev, (reg), (aux))
917
Alan Cox5c49fd32011-11-03 18:22:04 +0000918static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg,
Patrik Jakobsson26579292013-09-16 18:02:40 +0200919 uint32_t val)
Alan Cox5c49fd32011-11-03 18:22:04 +0000920{
921 struct drm_psb_private *dev_priv = dev->dev_private;
922 iowrite32((val), dev_priv->vdc_reg + (reg));
923}
924
Patrik Jakobsson26579292013-09-16 18:02:40 +0200925static inline void REGISTER_WRITE_AUX(struct drm_device *dev, uint32_t reg,
926 uint32_t val)
927{
928 struct drm_psb_private *dev_priv = dev->dev_private;
929 iowrite32((val), dev_priv->aux_reg + (reg));
930}
931
Alan Cox5c49fd32011-11-03 18:22:04 +0000932#define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
Patrik Jakobsson26579292013-09-16 18:02:40 +0200933#define REG_WRITE_AUX(reg, val) REGISTER_WRITE_AUX(dev, (reg), (val))
Alan Cox5c49fd32011-11-03 18:22:04 +0000934
Patrik Jakobssonb97b8282013-11-07 00:14:18 +0100935static inline void REGISTER_WRITE_WITH_AUX(struct drm_device *dev, uint32_t reg,
936 uint32_t val, int aux)
937{
938 if (aux)
939 REG_WRITE_AUX(reg, val);
940 else
941 REG_WRITE(reg, val);
942}
943
944#define REG_WRITE_WITH_AUX(reg, val, aux) REGISTER_WRITE_WITH_AUX(dev, (reg), (val), (aux))
945
Alan Cox5c49fd32011-11-03 18:22:04 +0000946static inline void REGISTER_WRITE16(struct drm_device *dev,
947 uint32_t reg, uint32_t val)
948{
949 struct drm_psb_private *dev_priv = dev->dev_private;
950 iowrite16((val), dev_priv->vdc_reg + (reg));
951}
952
953#define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
954
955static inline void REGISTER_WRITE8(struct drm_device *dev,
956 uint32_t reg, uint32_t val)
957{
958 struct drm_psb_private *dev_priv = dev->dev_private;
959 iowrite8((val), dev_priv->vdc_reg + (reg));
960}
961
962#define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
963
964#define PSB_WVDC32(_val, _offs) iowrite32(_val, dev_priv->vdc_reg + (_offs))
965#define PSB_RVDC32(_offs) ioread32(dev_priv->vdc_reg + (_offs))
966
967/* #define TRAP_SGX_PM_FAULT 1 */
968#ifdef TRAP_SGX_PM_FAULT
969#define PSB_RSGX32(_offs) \
970({ \
971 if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
972 printk(KERN_ERR \
973 "access sgx when it's off!! (READ) %s, %d\n", \
974 __FILE__, __LINE__); \
975 melay(1000); \
976 } \
977 ioread32(dev_priv->sgx_reg + (_offs)); \
978})
979#else
980#define PSB_RSGX32(_offs) ioread32(dev_priv->sgx_reg + (_offs))
981#endif
982#define PSB_WSGX32(_val, _offs) iowrite32(_val, dev_priv->sgx_reg + (_offs))
983
984#define MSVDX_REG_DUMP 0
985
986#define PSB_WMSVDX32(_val, _offs) iowrite32(_val, dev_priv->msvdx_reg + (_offs))
987#define PSB_RMSVDX32(_offs) ioread32(dev_priv->msvdx_reg + (_offs))
988
989#endif