blob: b686e56646ebd4b8abe6ba53582dd4e595484f29 [file] [log] [blame]
Alan Cox5c49fd32011-11-03 18:22:04 +00001/**************************************************************************
2 * Copyright (c) 2007-2011, Intel Corporation.
3 * All Rights Reserved.
4 * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA.
5 * All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 **************************************************************************/
21
22#include <drm/drmP.h>
23#include <drm/drm.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000024#include "psb_drv.h"
25#include "framebuffer.h"
26#include "psb_reg.h"
27#include "psb_intel_reg.h"
28#include "intel_bios.h"
29#include "mid_bios.h"
30#include <drm/drm_pciids.h>
31#include "power.h"
32#include <linux/cpu.h>
33#include <linux/notifier.h>
34#include <linux/spinlock.h>
35#include <linux/pm_runtime.h>
36#include <acpi/video.h>
Dave Airlieaf3a2cf2011-11-16 12:13:30 +000037#include <linux/module.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000038
Arthur Borsboomf90cd812014-03-15 22:12:17 +010039static struct drm_driver driver;
40static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Alan Cox5c49fd32011-11-03 18:22:04 +000041
Arthur Borsboom9083eb32014-03-15 22:12:18 +010042/*
43 * The table below contains a mapping of the PCI vendor ID and the PCI Device ID
44 * to the different groups of PowerVR 5-series chip designs
45 *
46 * 0x8086 = Intel Corporation
47 *
48 * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx
49 * PowerVR SGX535 - Moorestown - Intel GMA 600
50 * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx
51 * PowerVR SGX540 - Medfield - Intel Atom Z2460
52 * PowerVR SGX544MP2 - Medfield -
53 * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600
54 * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700,
55 * N2800
56 */
Alan Cox5c49fd32011-11-03 18:22:04 +000057static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
58 { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
59 { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
Alan Cox0cecdd82011-12-19 21:06:35 +000060#if defined(CONFIG_DRM_GMA600)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010061 { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
62 { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
63 { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
64 { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
65 { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
66 { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
67 { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
68 { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
69 { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
Alan Cox5c49fd32011-11-03 18:22:04 +000070#endif
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000071#if defined(CONFIG_DRM_MEDFIELD)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010072 { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
73 { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
74 { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
75 { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
76 { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
77 { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
78 { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
79 { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000080#endif
Alan Coxb6195aa2011-12-29 14:37:03 +000081#if defined(CONFIG_DRM_GMA3600)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010082 { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
83 { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
84 { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
85 { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
86 { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
87 { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
88 { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
89 { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
90 { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
91 { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
92 { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
93 { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
94 { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
95 { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
96 { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
97 { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
Alan Cox5c49fd32011-11-03 18:22:04 +000098#endif
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +000099 { 0, }
Alan Cox5c49fd32011-11-03 18:22:04 +0000100};
101MODULE_DEVICE_TABLE(pci, pciidlist);
102
103/*
104 * Standard IOCTLs.
105 */
Rob Clarkbaa70942013-08-02 13:27:49 -0400106static const struct drm_ioctl_desc psb_ioctls[] = {
Alan Cox5c49fd32011-11-03 18:22:04 +0000107};
108
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100109static void psb_driver_lastclose(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000110{
Daniel Vetter71475732012-12-02 21:55:41 +0100111 int ret;
112 struct drm_psb_private *dev_priv = dev->dev_private;
113 struct psb_fbdev *fbdev = dev_priv->fbdev;
114
Daniel Vetter0a819512012-12-02 01:33:17 +0100115 drm_modeset_lock_all(dev);
Daniel Vetter71475732012-12-02 21:55:41 +0100116 ret = drm_fb_helper_restore_fbdev_mode(&fbdev->psb_fb_helper);
117 if (ret)
118 DRM_DEBUG("failed to restore crtc mode\n");
Daniel Vetter0a819512012-12-02 01:33:17 +0100119 drm_modeset_unlock_all(dev);
Daniel Vetter71475732012-12-02 21:55:41 +0100120
Alan Cox5c49fd32011-11-03 18:22:04 +0000121 return;
122}
123
Alan Cox5c49fd32011-11-03 18:22:04 +0000124static int psb_do_init(struct drm_device *dev)
125{
126 struct drm_psb_private *dev_priv = dev->dev_private;
127 struct psb_gtt *pg = &dev_priv->gtt;
128
129 uint32_t stolen_gtt;
130
Alan Cox5c49fd32011-11-03 18:22:04 +0000131 if (pg->mmu_gatt_start & 0x0FFFFFFF) {
132 dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
Arthur Borsboomaf3765c2014-03-15 22:12:16 +0100133 return -EINVAL;
Alan Cox5c49fd32011-11-03 18:22:04 +0000134 }
135
Alan Cox5c49fd32011-11-03 18:22:04 +0000136 stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
137 stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100138 stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
Alan Cox5c49fd32011-11-03 18:22:04 +0000139
140 dev_priv->gatt_free_offset = pg->mmu_gatt_start +
141 (stolen_gtt << PAGE_SHIFT) * 1024;
142
Alan Cox5c49fd32011-11-03 18:22:04 +0000143 spin_lock_init(&dev_priv->irqmask_lock);
Alan Cox9242fe22011-11-29 22:27:10 +0000144 spin_lock_init(&dev_priv->lock_2d);
Alan Cox5c49fd32011-11-03 18:22:04 +0000145
146 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
147 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
148 PSB_RSGX32(PSB_CR_BIF_BANK1);
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100149
150 /* Do not bypass any MMU access, let them pagefault instead */
151 PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK),
152 PSB_CR_BIF_CTRL);
153 PSB_RSGX32(PSB_CR_BIF_CTRL);
154
Alan Cox5c49fd32011-11-03 18:22:04 +0000155 psb_spank(dev_priv);
156
157 /* mmu_gatt ?? */
158 PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100159 PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */
160
Alan Cox5c49fd32011-11-03 18:22:04 +0000161 return 0;
Alan Cox5c49fd32011-11-03 18:22:04 +0000162}
163
164static int psb_driver_unload(struct drm_device *dev)
165{
166 struct drm_psb_private *dev_priv = dev->dev_private;
167
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100168 /* TODO: Kill vblank etc here */
Alan Cox5c49fd32011-11-03 18:22:04 +0000169
170 if (dev_priv) {
Alan Cox4ab2c7f2012-05-14 12:04:00 +0100171 if (dev_priv->backlight_device)
172 gma_backlight_exit(dev);
173 psb_modeset_cleanup(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000174
175 if (dev_priv->ops->chip_teardown)
176 dev_priv->ops->chip_teardown(dev);
Alan Cox6607e022012-05-14 12:03:34 +0100177
178 psb_intel_opregion_fini(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000179
180 if (dev_priv->pf_pd) {
181 psb_mmu_free_pagedir(dev_priv->pf_pd);
182 dev_priv->pf_pd = NULL;
183 }
184 if (dev_priv->mmu) {
185 struct psb_gtt *pg = &dev_priv->gtt;
186
187 down_read(&pg->sem);
188 psb_mmu_remove_pfn_sequence(
189 psb_mmu_get_default_pd
190 (dev_priv->mmu),
191 pg->mmu_gatt_start,
192 dev_priv->vram_stolen_size >> PAGE_SHIFT);
193 up_read(&pg->sem);
194 psb_mmu_driver_takedown(dev_priv->mmu);
195 dev_priv->mmu = NULL;
196 }
197 psb_gtt_takedown(dev);
198 if (dev_priv->scratch_page) {
Alan Cox18963442012-04-25 14:36:13 +0100199 set_pages_wb(dev_priv->scratch_page, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000200 __free_page(dev_priv->scratch_page);
201 dev_priv->scratch_page = NULL;
202 }
203 if (dev_priv->vdc_reg) {
204 iounmap(dev_priv->vdc_reg);
205 dev_priv->vdc_reg = NULL;
206 }
207 if (dev_priv->sgx_reg) {
208 iounmap(dev_priv->sgx_reg);
209 dev_priv->sgx_reg = NULL;
210 }
Patrik Jakobsson26579292013-09-16 18:02:40 +0200211 if (dev_priv->aux_reg) {
212 iounmap(dev_priv->aux_reg);
213 dev_priv->aux_reg = NULL;
214 }
215 if (dev_priv->aux_pdev)
216 pci_dev_put(dev_priv->aux_pdev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000217
Alan Cox4ab2c7f2012-05-14 12:04:00 +0100218 /* Destroy VBT data */
219 psb_intel_destroy_bios(dev);
220
Alan Cox5c49fd32011-11-03 18:22:04 +0000221 kfree(dev_priv);
222 dev->dev_private = NULL;
Alan Cox5c49fd32011-11-03 18:22:04 +0000223 }
Alan Cox5c49fd32011-11-03 18:22:04 +0000224 gma_power_uninit(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000225 return 0;
226}
227
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100228static int psb_driver_load(struct drm_device *dev, unsigned long flags)
Alan Cox5c49fd32011-11-03 18:22:04 +0000229{
230 struct drm_psb_private *dev_priv;
Patrik Jakobsson26579292013-09-16 18:02:40 +0200231 unsigned long resource_start, resource_len;
Alan Cox5c49fd32011-11-03 18:22:04 +0000232 unsigned long irqflags;
233 int ret = -ENOMEM;
Alan Cox5c49fd32011-11-03 18:22:04 +0000234 struct drm_connector *connector;
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200235 struct gma_encoder *gma_encoder;
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100236 struct psb_gtt *pg;
Alan Cox5c49fd32011-11-03 18:22:04 +0000237
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100238 /* allocating and initializing driver private data */
Alan Cox5c49fd32011-11-03 18:22:04 +0000239 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
240 if (dev_priv == NULL)
241 return -ENOMEM;
242
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100243 dev_priv->ops = (struct psb_ops *)flags;
Alan Cox5c49fd32011-11-03 18:22:04 +0000244 dev_priv->dev = dev;
245 dev->dev_private = (void *) dev_priv;
246
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100247 pg = &dev_priv->gtt;
248
Dave Airlie466e69b2011-12-19 11:15:29 +0000249 pci_set_master(dev->pdev);
250
Alan Cox5c49fd32011-11-03 18:22:04 +0000251 dev_priv->num_pipe = dev_priv->ops->pipes;
252
253 resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
254
255 dev_priv->vdc_reg =
256 ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
257 if (!dev_priv->vdc_reg)
258 goto out_err;
259
260 dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
261 PSB_SGX_SIZE);
262 if (!dev_priv->sgx_reg)
263 goto out_err;
264
Patrik Jakobsson26579292013-09-16 18:02:40 +0200265 if (IS_MRST(dev)) {
266 dev_priv->aux_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(3, 0));
267
268 if (dev_priv->aux_pdev) {
269 resource_start = pci_resource_start(dev_priv->aux_pdev,
270 PSB_AUX_RESOURCE);
271 resource_len = pci_resource_len(dev_priv->aux_pdev,
272 PSB_AUX_RESOURCE);
273 dev_priv->aux_reg = ioremap_nocache(resource_start,
274 resource_len);
275 if (!dev_priv->aux_reg)
276 goto out_err;
277
278 DRM_DEBUG_KMS("Found aux vdc");
279 } else {
280 /* Couldn't find the aux vdc so map to primary vdc */
281 dev_priv->aux_reg = dev_priv->vdc_reg;
282 DRM_DEBUG_KMS("Couldn't find aux pci device");
283 }
284 dev_priv->gmbus_reg = dev_priv->aux_reg;
285 } else {
286 dev_priv->gmbus_reg = dev_priv->vdc_reg;
287 }
288
Alan Coxd839ede2012-05-03 15:06:18 +0100289 psb_intel_opregion_setup(dev);
290
Alan Cox5c49fd32011-11-03 18:22:04 +0000291 ret = dev_priv->ops->chip_setup(dev);
292 if (ret)
293 goto out_err;
294
295 /* Init OSPM support */
296 gma_power_init(dev);
297
298 ret = -ENOMEM;
299
300 dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
301 if (!dev_priv->scratch_page)
302 goto out_err;
303
304 set_pages_uc(dev_priv->scratch_page, 1);
305
306 ret = psb_gtt_init(dev, 0);
307 if (ret)
308 goto out_err;
309
Patrik Jakobsson8f394872014-01-05 00:27:51 +0100310 dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0);
Alan Cox5c49fd32011-11-03 18:22:04 +0000311 if (!dev_priv->mmu)
312 goto out_err;
313
Alan Cox5c49fd32011-11-03 18:22:04 +0000314 dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
315 if (!dev_priv->pf_pd)
316 goto out_err;
317
Alan Cox5c49fd32011-11-03 18:22:04 +0000318 ret = psb_do_init(dev);
319 if (ret)
320 return ret;
321
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100322 /* Add stolen memory to SGX MMU */
323 down_read(&pg->sem);
324 ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu),
325 dev_priv->stolen_base >> PAGE_SHIFT,
326 pg->gatt_start,
327 pg->stolen_size >> PAGE_SHIFT, 0);
328 up_read(&pg->sem);
329
330 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
331 psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
332
Alan Cox5c49fd32011-11-03 18:22:04 +0000333 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
334 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
335
Alan Coxd839ede2012-05-03 15:06:18 +0100336 acpi_video_register();
Alan Cox5c49fd32011-11-03 18:22:04 +0000337
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100338 /* Setup vertical blanking handling */
Alan Cox5c49fd32011-11-03 18:22:04 +0000339 ret = drm_vblank_init(dev, dev_priv->num_pipe);
340 if (ret)
341 goto out_err;
342
343 /*
344 * Install interrupt handlers prior to powering off SGX or else we will
345 * crash.
346 */
347 dev_priv->vdc_irq_mask = 0;
348 dev_priv->pipestat[0] = 0;
349 dev_priv->pipestat[1] = 0;
350 dev_priv->pipestat[2] = 0;
351 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
352 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
353 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
354 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
355 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
Alan Cox62363a42012-05-11 11:33:17 +0100356
357 drm_irq_install(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000358
Ville Syrjäläba0bf122013-10-04 14:53:33 +0300359 dev->vblank_disable_allowed = true;
Alan Cox5c49fd32011-11-03 18:22:04 +0000360 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Alan Cox5c49fd32011-11-03 18:22:04 +0000361 dev->driver->get_vblank_counter = psb_get_vblank_counter;
362
Alan Coxf9f23a72011-12-29 14:38:07 +0000363 psb_modeset_init(dev);
364 psb_fbdev_init(dev);
365 drm_kms_helper_poll_init(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000366
367 /* Only add backlight support if we have LVDS output */
368 list_for_each_entry(connector, &dev->mode_config.connector_list,
369 head) {
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200370 gma_encoder = gma_attached_encoder(connector);
Alan Cox5c49fd32011-11-03 18:22:04 +0000371
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200372 switch (gma_encoder->type) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000373 case INTEL_OUTPUT_LVDS:
374 case INTEL_OUTPUT_MIPI:
375 ret = gma_backlight_init(dev);
376 break;
377 }
378 }
379
380 if (ret)
381 return ret;
Alan Cox166973e2012-07-16 17:52:45 +0100382 psb_intel_opregion_enable_asle(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000383#if 0
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100384 /* Enable runtime pm at last */
Alan Cox5c49fd32011-11-03 18:22:04 +0000385 pm_runtime_enable(&dev->pdev->dev);
386 pm_runtime_set_active(&dev->pdev->dev);
387#endif
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100388 /* Intel drm driver load is done, continue doing pvr load */
Alan Cox5c49fd32011-11-03 18:22:04 +0000389 return 0;
390out_err:
391 psb_driver_unload(dev);
392 return ret;
393}
394
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000395static int psb_driver_device_is_agp(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000396{
397 return 0;
398}
399
Alan Cox5c49fd32011-11-03 18:22:04 +0000400static inline void get_brightness(struct backlight_device *bd)
401{
402#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
403 if (bd) {
404 bd->props.brightness = bd->ops->get_brightness(bd);
405 backlight_update_status(bd);
406 }
407#endif
408}
409
Alan Cox5c49fd32011-11-03 18:22:04 +0000410static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
411 unsigned long arg)
412{
413 struct drm_file *file_priv = filp->private_data;
414 struct drm_device *dev = file_priv->minor->dev;
415 struct drm_psb_private *dev_priv = dev->dev_private;
416 static unsigned int runtime_allowed;
417
418 if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
419 runtime_allowed++;
420 pm_runtime_allow(&dev->pdev->dev);
421 dev_priv->rpm_enabled = 1;
422 }
423 return drm_ioctl(filp, cmd, arg);
424 /* FIXME: do we need to wrap the other side of this */
425}
426
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100427/*
428 * When a client dies:
Alan Cox5c49fd32011-11-03 18:22:04 +0000429 * - Check for and clean up flipped page state
430 */
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000431static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
Alan Cox5c49fd32011-11-03 18:22:04 +0000432{
433}
434
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100435static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
436{
437 return drm_get_pci_dev(pdev, ent, &driver);
438}
439
440
441static void psb_pci_remove(struct pci_dev *pdev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000442{
443 struct drm_device *dev = pci_get_drvdata(pdev);
444 drm_put_dev(dev);
445}
446
447static const struct dev_pm_ops psb_pm_ops = {
448 .resume = gma_power_resume,
449 .suspend = gma_power_suspend,
Patrik Jakobsson888eef22013-04-06 00:45:22 +0200450 .thaw = gma_power_thaw,
451 .freeze = gma_power_freeze,
452 .restore = gma_power_restore,
Alan Cox5c49fd32011-11-03 18:22:04 +0000453 .runtime_suspend = psb_runtime_suspend,
454 .runtime_resume = psb_runtime_resume,
455 .runtime_idle = psb_runtime_idle,
456};
457
Laurent Pinchart78b68552012-05-17 13:27:22 +0200458static const struct vm_operations_struct psb_gem_vm_ops = {
Alan Cox5c49fd32011-11-03 18:22:04 +0000459 .fault = psb_gem_fault,
460 .open = drm_gem_vm_open,
461 .close = drm_gem_vm_close,
462};
463
Ilija Hadzic1595c562011-11-27 11:08:33 -0500464static const struct file_operations psb_gem_fops = {
465 .owner = THIS_MODULE,
466 .open = drm_open,
467 .release = drm_release,
468 .unlocked_ioctl = psb_unlocked_ioctl,
469 .mmap = drm_gem_mmap,
470 .poll = drm_poll,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500471 .read = drm_read,
472};
473
Alan Cox5c49fd32011-11-03 18:22:04 +0000474static struct drm_driver driver = {
475 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100476 DRIVER_MODESET | DRIVER_GEM,
Alan Cox5c49fd32011-11-03 18:22:04 +0000477 .load = psb_driver_load,
478 .unload = psb_driver_unload,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100479 .lastclose = psb_driver_lastclose,
480 .preclose = psb_driver_preclose,
Alan Cox5c49fd32011-11-03 18:22:04 +0000481
Alan Cox5c49fd32011-11-03 18:22:04 +0000482 .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
483 .device_is_agp = psb_driver_device_is_agp,
484 .irq_preinstall = psb_irq_preinstall,
485 .irq_postinstall = psb_irq_postinstall,
486 .irq_uninstall = psb_irq_uninstall,
487 .irq_handler = psb_irq_handler,
488 .enable_vblank = psb_enable_vblank,
489 .disable_vblank = psb_disable_vblank,
490 .get_vblank_counter = psb_get_vblank_counter,
Alan Cox5c49fd32011-11-03 18:22:04 +0000491
Alan Cox5c49fd32011-11-03 18:22:04 +0000492 .gem_free_object = psb_gem_free_object,
493 .gem_vm_ops = &psb_gem_vm_ops,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100494
Alan Cox5c49fd32011-11-03 18:22:04 +0000495 .dumb_create = psb_gem_dumb_create,
496 .dumb_map_offset = psb_gem_dumb_map_gtt,
Daniel Vetter43387b32013-07-16 09:12:04 +0200497 .dumb_destroy = drm_gem_dumb_destroy,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100498 .ioctls = psb_ioctls,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500499 .fops = &psb_gem_fops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000500 .name = DRIVER_NAME,
501 .desc = DRIVER_DESC,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100502 .date = DRIVER_DATE,
503 .major = DRIVER_MAJOR,
504 .minor = DRIVER_MINOR,
505 .patchlevel = DRIVER_PATCHLEVEL
Alan Cox5c49fd32011-11-03 18:22:04 +0000506};
507
508static struct pci_driver psb_pci_driver = {
509 .name = DRIVER_NAME,
510 .id_table = pciidlist,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100511 .probe = psb_pci_probe,
512 .remove = psb_pci_remove,
513 .driver.pm = &psb_pm_ops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000514};
515
Alan Cox5c49fd32011-11-03 18:22:04 +0000516static int __init psb_init(void)
517{
518 return drm_pci_init(&driver, &psb_pci_driver);
519}
520
521static void __exit psb_exit(void)
522{
523 drm_pci_exit(&driver, &psb_pci_driver);
524}
525
526late_initcall(psb_init);
527module_exit(psb_exit);
528
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100529MODULE_AUTHOR(DRIVER_AUTHOR);
Alan Cox5c49fd32011-11-03 18:22:04 +0000530MODULE_DESCRIPTION(DRIVER_DESC);
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100531MODULE_LICENSE(DRIVER_LICENSE);