blob: ac32ab5aa002705c69d0636fff461951fd4c283d [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>
Laura Abbotted3ba072017-05-08 15:58:17 -070038#include <asm/set_memory.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000039
Arthur Borsboomf90cd812014-03-15 22:12:17 +010040static struct drm_driver driver;
41static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Alan Cox5c49fd32011-11-03 18:22:04 +000042
Arthur Borsboom9083eb32014-03-15 22:12:18 +010043/*
44 * The table below contains a mapping of the PCI vendor ID and the PCI Device ID
45 * to the different groups of PowerVR 5-series chip designs
46 *
47 * 0x8086 = Intel Corporation
48 *
49 * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx
50 * PowerVR SGX535 - Moorestown - Intel GMA 600
51 * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx
52 * PowerVR SGX540 - Medfield - Intel Atom Z2460
53 * PowerVR SGX544MP2 - Medfield -
54 * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600
55 * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700,
56 * N2800
57 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020058static const struct pci_device_id pciidlist[] = {
Alan Cox5c49fd32011-11-03 18:22:04 +000059 { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
60 { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
Alan Cox0cecdd82011-12-19 21:06:35 +000061#if defined(CONFIG_DRM_GMA600)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010062 { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
63 { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
64 { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
65 { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
66 { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
67 { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
68 { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
69 { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
70 { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops },
Alan Cox5c49fd32011-11-03 18:22:04 +000071#endif
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000072#if defined(CONFIG_DRM_MEDFIELD)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010073 { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
74 { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
75 { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
76 { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
77 { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
78 { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
79 { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
80 { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops },
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000081#endif
Alan Coxb6195aa2011-12-29 14:37:03 +000082#if defined(CONFIG_DRM_GMA3600)
Arthur Borsboomf90cd812014-03-15 22:12:17 +010083 { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
84 { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
85 { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
86 { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
87 { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
88 { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
89 { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
90 { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
91 { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
92 { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
93 { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
94 { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
95 { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
96 { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
97 { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
98 { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops },
Alan Cox5c49fd32011-11-03 18:22:04 +000099#endif
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +0000100 { 0, }
Alan Cox5c49fd32011-11-03 18:22:04 +0000101};
102MODULE_DEVICE_TABLE(pci, pciidlist);
103
104/*
105 * Standard IOCTLs.
106 */
Rob Clarkbaa70942013-08-02 13:27:49 -0400107static const struct drm_ioctl_desc psb_ioctls[] = {
Alan Cox5c49fd32011-11-03 18:22:04 +0000108};
109
Alan Cox5c49fd32011-11-03 18:22:04 +0000110static int psb_do_init(struct drm_device *dev)
111{
112 struct drm_psb_private *dev_priv = dev->dev_private;
113 struct psb_gtt *pg = &dev_priv->gtt;
114
115 uint32_t stolen_gtt;
116
Alan Cox5c49fd32011-11-03 18:22:04 +0000117 if (pg->mmu_gatt_start & 0x0FFFFFFF) {
118 dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
Arthur Borsboomaf3765c2014-03-15 22:12:16 +0100119 return -EINVAL;
Alan Cox5c49fd32011-11-03 18:22:04 +0000120 }
121
Alan Cox5c49fd32011-11-03 18:22:04 +0000122 stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
123 stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100124 stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
Alan Cox5c49fd32011-11-03 18:22:04 +0000125
126 dev_priv->gatt_free_offset = pg->mmu_gatt_start +
127 (stolen_gtt << PAGE_SHIFT) * 1024;
128
Alan Cox5c49fd32011-11-03 18:22:04 +0000129 spin_lock_init(&dev_priv->irqmask_lock);
Alan Cox9242fe22011-11-29 22:27:10 +0000130 spin_lock_init(&dev_priv->lock_2d);
Alan Cox5c49fd32011-11-03 18:22:04 +0000131
132 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
133 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
134 PSB_RSGX32(PSB_CR_BIF_BANK1);
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100135
136 /* Do not bypass any MMU access, let them pagefault instead */
137 PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK),
138 PSB_CR_BIF_CTRL);
139 PSB_RSGX32(PSB_CR_BIF_CTRL);
140
Alan Cox5c49fd32011-11-03 18:22:04 +0000141 psb_spank(dev_priv);
142
143 /* mmu_gatt ?? */
144 PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100145 PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */
146
Alan Cox5c49fd32011-11-03 18:22:04 +0000147 return 0;
Alan Cox5c49fd32011-11-03 18:22:04 +0000148}
149
Gabriel Krisman Bertazi11b3c202017-01-06 15:57:31 -0200150static void psb_driver_unload(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000151{
152 struct drm_psb_private *dev_priv = dev->dev_private;
153
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100154 /* TODO: Kill vblank etc here */
Alan Cox5c49fd32011-11-03 18:22:04 +0000155
156 if (dev_priv) {
Alan Cox4ab2c7f2012-05-14 12:04:00 +0100157 if (dev_priv->backlight_device)
158 gma_backlight_exit(dev);
159 psb_modeset_cleanup(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000160
161 if (dev_priv->ops->chip_teardown)
162 dev_priv->ops->chip_teardown(dev);
Alan Cox6607e022012-05-14 12:03:34 +0100163
164 psb_intel_opregion_fini(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000165
166 if (dev_priv->pf_pd) {
167 psb_mmu_free_pagedir(dev_priv->pf_pd);
168 dev_priv->pf_pd = NULL;
169 }
170 if (dev_priv->mmu) {
171 struct psb_gtt *pg = &dev_priv->gtt;
172
173 down_read(&pg->sem);
174 psb_mmu_remove_pfn_sequence(
175 psb_mmu_get_default_pd
176 (dev_priv->mmu),
177 pg->mmu_gatt_start,
178 dev_priv->vram_stolen_size >> PAGE_SHIFT);
179 up_read(&pg->sem);
180 psb_mmu_driver_takedown(dev_priv->mmu);
181 dev_priv->mmu = NULL;
182 }
183 psb_gtt_takedown(dev);
184 if (dev_priv->scratch_page) {
Alan Cox18963442012-04-25 14:36:13 +0100185 set_pages_wb(dev_priv->scratch_page, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000186 __free_page(dev_priv->scratch_page);
187 dev_priv->scratch_page = NULL;
188 }
189 if (dev_priv->vdc_reg) {
190 iounmap(dev_priv->vdc_reg);
191 dev_priv->vdc_reg = NULL;
192 }
193 if (dev_priv->sgx_reg) {
194 iounmap(dev_priv->sgx_reg);
195 dev_priv->sgx_reg = NULL;
196 }
Patrik Jakobsson26579292013-09-16 18:02:40 +0200197 if (dev_priv->aux_reg) {
198 iounmap(dev_priv->aux_reg);
199 dev_priv->aux_reg = NULL;
200 }
Markus Elfring44fb4b82016-07-22 10:30:30 +0200201 pci_dev_put(dev_priv->aux_pdev);
202 pci_dev_put(dev_priv->lpc_pdev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000203
Alan Cox4ab2c7f2012-05-14 12:04:00 +0100204 /* Destroy VBT data */
205 psb_intel_destroy_bios(dev);
206
Alan Cox5c49fd32011-11-03 18:22:04 +0000207 kfree(dev_priv);
208 dev->dev_private = NULL;
Alan Cox5c49fd32011-11-03 18:22:04 +0000209 }
Alan Cox5c49fd32011-11-03 18:22:04 +0000210 gma_power_uninit(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000211}
212
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100213static int psb_driver_load(struct drm_device *dev, unsigned long flags)
Alan Cox5c49fd32011-11-03 18:22:04 +0000214{
215 struct drm_psb_private *dev_priv;
Patrik Jakobsson26579292013-09-16 18:02:40 +0200216 unsigned long resource_start, resource_len;
Alan Cox5c49fd32011-11-03 18:22:04 +0000217 unsigned long irqflags;
218 int ret = -ENOMEM;
Alan Cox5c49fd32011-11-03 18:22:04 +0000219 struct drm_connector *connector;
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200220 struct gma_encoder *gma_encoder;
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100221 struct psb_gtt *pg;
Alan Cox5c49fd32011-11-03 18:22:04 +0000222
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100223 /* allocating and initializing driver private data */
Alan Cox5c49fd32011-11-03 18:22:04 +0000224 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
225 if (dev_priv == NULL)
226 return -ENOMEM;
227
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100228 dev_priv->ops = (struct psb_ops *)flags;
Alan Cox5c49fd32011-11-03 18:22:04 +0000229 dev_priv->dev = dev;
230 dev->dev_private = (void *) dev_priv;
231
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100232 pg = &dev_priv->gtt;
233
Dave Airlie466e69b2011-12-19 11:15:29 +0000234 pci_set_master(dev->pdev);
235
Alan Cox5c49fd32011-11-03 18:22:04 +0000236 dev_priv->num_pipe = dev_priv->ops->pipes;
237
238 resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
239
240 dev_priv->vdc_reg =
241 ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
242 if (!dev_priv->vdc_reg)
243 goto out_err;
244
245 dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
246 PSB_SGX_SIZE);
247 if (!dev_priv->sgx_reg)
248 goto out_err;
249
Patrik Jakobsson26579292013-09-16 18:02:40 +0200250 if (IS_MRST(dev)) {
Sinan Kayaba99d832017-12-19 00:37:44 -0500251 int domain = pci_domain_nr(dev->pdev->bus);
252
253 dev_priv->aux_pdev =
254 pci_get_domain_bus_and_slot(domain, 0,
255 PCI_DEVFN(3, 0));
Patrik Jakobsson26579292013-09-16 18:02:40 +0200256
257 if (dev_priv->aux_pdev) {
258 resource_start = pci_resource_start(dev_priv->aux_pdev,
259 PSB_AUX_RESOURCE);
260 resource_len = pci_resource_len(dev_priv->aux_pdev,
261 PSB_AUX_RESOURCE);
262 dev_priv->aux_reg = ioremap_nocache(resource_start,
263 resource_len);
264 if (!dev_priv->aux_reg)
265 goto out_err;
266
267 DRM_DEBUG_KMS("Found aux vdc");
268 } else {
269 /* Couldn't find the aux vdc so map to primary vdc */
270 dev_priv->aux_reg = dev_priv->vdc_reg;
271 DRM_DEBUG_KMS("Couldn't find aux pci device");
272 }
273 dev_priv->gmbus_reg = dev_priv->aux_reg;
Jan Safrata5a52b1f2014-09-26 10:40:29 +0200274
Sinan Kayaba99d832017-12-19 00:37:44 -0500275 dev_priv->lpc_pdev =
276 pci_get_domain_bus_and_slot(domain, 0,
277 PCI_DEVFN(31, 0));
Jan Safrata5a52b1f2014-09-26 10:40:29 +0200278 if (dev_priv->lpc_pdev) {
279 pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA,
280 &dev_priv->lpc_gpio_base);
281 pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA,
282 (u32)dev_priv->lpc_gpio_base | (1L<<31));
283 pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA,
284 &dev_priv->lpc_gpio_base);
285 dev_priv->lpc_gpio_base &= 0xffc0;
286 if (dev_priv->lpc_gpio_base)
287 DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n",
288 dev_priv->lpc_gpio_base);
289 else {
290 pci_dev_put(dev_priv->lpc_pdev);
291 dev_priv->lpc_pdev = NULL;
292 }
293 }
Patrik Jakobsson26579292013-09-16 18:02:40 +0200294 } else {
295 dev_priv->gmbus_reg = dev_priv->vdc_reg;
296 }
297
Alan Coxd839ede2012-05-03 15:06:18 +0100298 psb_intel_opregion_setup(dev);
299
Alan Cox5c49fd32011-11-03 18:22:04 +0000300 ret = dev_priv->ops->chip_setup(dev);
301 if (ret)
302 goto out_err;
303
304 /* Init OSPM support */
305 gma_power_init(dev);
306
307 ret = -ENOMEM;
308
309 dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
310 if (!dev_priv->scratch_page)
311 goto out_err;
312
313 set_pages_uc(dev_priv->scratch_page, 1);
314
315 ret = psb_gtt_init(dev, 0);
316 if (ret)
317 goto out_err;
318
Patrik Jakobsson8f394872014-01-05 00:27:51 +0100319 dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0);
Alan Cox5c49fd32011-11-03 18:22:04 +0000320 if (!dev_priv->mmu)
321 goto out_err;
322
Alan Cox5c49fd32011-11-03 18:22:04 +0000323 dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
324 if (!dev_priv->pf_pd)
325 goto out_err;
326
Alan Cox5c49fd32011-11-03 18:22:04 +0000327 ret = psb_do_init(dev);
328 if (ret)
329 return ret;
330
Patrik Jakobssonae012bd2014-01-04 22:11:17 +0100331 /* Add stolen memory to SGX MMU */
332 down_read(&pg->sem);
333 ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu),
334 dev_priv->stolen_base >> PAGE_SHIFT,
335 pg->gatt_start,
336 pg->stolen_size >> PAGE_SHIFT, 0);
337 up_read(&pg->sem);
338
339 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
340 psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
341
Alan Cox5c49fd32011-11-03 18:22:04 +0000342 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
343 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
344
Alan Coxd839ede2012-05-03 15:06:18 +0100345 acpi_video_register();
Alan Cox5c49fd32011-11-03 18:22:04 +0000346
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100347 /* Setup vertical blanking handling */
Alan Cox5c49fd32011-11-03 18:22:04 +0000348 ret = drm_vblank_init(dev, dev_priv->num_pipe);
349 if (ret)
350 goto out_err;
351
352 /*
353 * Install interrupt handlers prior to powering off SGX or else we will
354 * crash.
355 */
356 dev_priv->vdc_irq_mask = 0;
357 dev_priv->pipestat[0] = 0;
358 dev_priv->pipestat[1] = 0;
359 dev_priv->pipestat[2] = 0;
360 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
361 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
362 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
363 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
364 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
Alan Cox62363a42012-05-11 11:33:17 +0100365
Daniel Vetterbb0f1b52013-11-03 21:09:27 +0100366 drm_irq_install(dev, dev->pdev->irq);
Alan Cox5c49fd32011-11-03 18:22:04 +0000367
Alan Cox5c49fd32011-11-03 18:22:04 +0000368 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Alan Cox5c49fd32011-11-03 18:22:04 +0000369 dev->driver->get_vblank_counter = psb_get_vblank_counter;
370
Alan Coxf9f23a72011-12-29 14:38:07 +0000371 psb_modeset_init(dev);
372 psb_fbdev_init(dev);
373 drm_kms_helper_poll_init(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000374
375 /* Only add backlight support if we have LVDS output */
376 list_for_each_entry(connector, &dev->mode_config.connector_list,
377 head) {
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200378 gma_encoder = gma_attached_encoder(connector);
Alan Cox5c49fd32011-11-03 18:22:04 +0000379
Patrik Jakobsson367e4402013-07-22 17:45:26 +0200380 switch (gma_encoder->type) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000381 case INTEL_OUTPUT_LVDS:
382 case INTEL_OUTPUT_MIPI:
383 ret = gma_backlight_init(dev);
384 break;
385 }
386 }
387
388 if (ret)
389 return ret;
Alan Cox166973e2012-07-16 17:52:45 +0100390 psb_intel_opregion_enable_asle(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000391#if 0
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100392 /* Enable runtime pm at last */
Alan Cox5c49fd32011-11-03 18:22:04 +0000393 pm_runtime_enable(&dev->pdev->dev);
394 pm_runtime_set_active(&dev->pdev->dev);
395#endif
Arthur Borsboom9083eb32014-03-15 22:12:18 +0100396 /* Intel drm driver load is done, continue doing pvr load */
Alan Cox5c49fd32011-11-03 18:22:04 +0000397 return 0;
398out_err:
399 psb_driver_unload(dev);
400 return ret;
401}
402
Alan Cox5c49fd32011-11-03 18:22:04 +0000403static inline void get_brightness(struct backlight_device *bd)
404{
405#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
406 if (bd) {
407 bd->props.brightness = bd->ops->get_brightness(bd);
408 backlight_update_status(bd);
409 }
410#endif
411}
412
Alan Cox5c49fd32011-11-03 18:22:04 +0000413static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
414 unsigned long arg)
415{
416 struct drm_file *file_priv = filp->private_data;
417 struct drm_device *dev = file_priv->minor->dev;
418 struct drm_psb_private *dev_priv = dev->dev_private;
419 static unsigned int runtime_allowed;
420
421 if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
422 runtime_allowed++;
423 pm_runtime_allow(&dev->pdev->dev);
424 dev_priv->rpm_enabled = 1;
425 }
426 return drm_ioctl(filp, cmd, arg);
427 /* FIXME: do we need to wrap the other side of this */
428}
429
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100430static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
431{
432 return drm_get_pci_dev(pdev, ent, &driver);
433}
434
435
436static void psb_pci_remove(struct pci_dev *pdev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000437{
438 struct drm_device *dev = pci_get_drvdata(pdev);
439 drm_put_dev(dev);
440}
441
442static const struct dev_pm_ops psb_pm_ops = {
443 .resume = gma_power_resume,
444 .suspend = gma_power_suspend,
Patrik Jakobsson888eef22013-04-06 00:45:22 +0200445 .thaw = gma_power_thaw,
446 .freeze = gma_power_freeze,
447 .restore = gma_power_restore,
Alan Cox5c49fd32011-11-03 18:22:04 +0000448 .runtime_suspend = psb_runtime_suspend,
449 .runtime_resume = psb_runtime_resume,
450 .runtime_idle = psb_runtime_idle,
451};
452
Laurent Pinchart78b68552012-05-17 13:27:22 +0200453static const struct vm_operations_struct psb_gem_vm_ops = {
Alan Cox5c49fd32011-11-03 18:22:04 +0000454 .fault = psb_gem_fault,
455 .open = drm_gem_vm_open,
456 .close = drm_gem_vm_close,
457};
458
Ilija Hadzic1595c562011-11-27 11:08:33 -0500459static const struct file_operations psb_gem_fops = {
460 .owner = THIS_MODULE,
461 .open = drm_open,
462 .release = drm_release,
463 .unlocked_ioctl = psb_unlocked_ioctl,
Patrik Jakobsson0a97c812016-11-01 15:43:15 +0100464 .compat_ioctl = drm_compat_ioctl,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500465 .mmap = drm_gem_mmap,
466 .poll = drm_poll,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500467 .read = drm_read,
468};
469
Alan Cox5c49fd32011-11-03 18:22:04 +0000470static struct drm_driver driver = {
471 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100472 DRIVER_MODESET | DRIVER_GEM,
Alan Cox5c49fd32011-11-03 18:22:04 +0000473 .load = psb_driver_load,
474 .unload = psb_driver_unload,
Noralf Trønnescdc13f62017-12-05 19:24:58 +0100475 .lastclose = drm_fb_helper_lastclose,
Alan Cox5c49fd32011-11-03 18:22:04 +0000476
Damien Lespiauf95aeb12014-06-09 14:39:49 +0100477 .num_ioctls = ARRAY_SIZE(psb_ioctls),
Alan Cox5c49fd32011-11-03 18:22:04 +0000478 .irq_preinstall = psb_irq_preinstall,
479 .irq_postinstall = psb_irq_postinstall,
480 .irq_uninstall = psb_irq_uninstall,
481 .irq_handler = psb_irq_handler,
482 .enable_vblank = psb_enable_vblank,
483 .disable_vblank = psb_disable_vblank,
484 .get_vblank_counter = psb_get_vblank_counter,
Alan Cox5c49fd32011-11-03 18:22:04 +0000485
Alan Cox5c49fd32011-11-03 18:22:04 +0000486 .gem_free_object = psb_gem_free_object,
487 .gem_vm_ops = &psb_gem_vm_ops,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100488
Alan Cox5c49fd32011-11-03 18:22:04 +0000489 .dumb_create = psb_gem_dumb_create,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100490 .ioctls = psb_ioctls,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500491 .fops = &psb_gem_fops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000492 .name = DRIVER_NAME,
493 .desc = DRIVER_DESC,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100494 .date = DRIVER_DATE,
495 .major = DRIVER_MAJOR,
496 .minor = DRIVER_MINOR,
497 .patchlevel = DRIVER_PATCHLEVEL
Alan Cox5c49fd32011-11-03 18:22:04 +0000498};
499
500static struct pci_driver psb_pci_driver = {
501 .name = DRIVER_NAME,
502 .id_table = pciidlist,
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100503 .probe = psb_pci_probe,
504 .remove = psb_pci_remove,
505 .driver.pm = &psb_pm_ops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000506};
507
Alan Cox5c49fd32011-11-03 18:22:04 +0000508static int __init psb_init(void)
509{
Daniel Vetter10631d72017-05-24 16:51:40 +0200510 return pci_register_driver(&psb_pci_driver);
Alan Cox5c49fd32011-11-03 18:22:04 +0000511}
512
513static void __exit psb_exit(void)
514{
Daniel Vetter10631d72017-05-24 16:51:40 +0200515 pci_unregister_driver(&psb_pci_driver);
Alan Cox5c49fd32011-11-03 18:22:04 +0000516}
517
518late_initcall(psb_init);
519module_exit(psb_exit);
520
Arthur Borsboomf90cd812014-03-15 22:12:17 +0100521MODULE_AUTHOR(DRIVER_AUTHOR);
Alan Cox5c49fd32011-11-03 18:22:04 +0000522MODULE_DESCRIPTION(DRIVER_DESC);
Greg Kroah-Hartman0df12b32017-11-17 15:16:32 +0100523MODULE_LICENSE("GPL");