blob: 0e85978877e8a933e457b0f3cf2a1025732ab01f [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 Cox838fa582011-11-16 22:39:45 +000024#include "gma_drm.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000025#include "psb_drv.h"
26#include "framebuffer.h"
27#include "psb_reg.h"
28#include "psb_intel_reg.h"
29#include "intel_bios.h"
30#include "mid_bios.h"
31#include <drm/drm_pciids.h>
32#include "power.h"
33#include <linux/cpu.h>
34#include <linux/notifier.h>
35#include <linux/spinlock.h>
36#include <linux/pm_runtime.h>
37#include <acpi/video.h>
Dave Airlieaf3a2cf2011-11-16 12:13:30 +000038#include <linux/module.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000039
40static int drm_psb_trap_pagefaults;
41
Alan Cox5c49fd32011-11-03 18:22:04 +000042static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
43
Alan Cox5c49fd32011-11-03 18:22:04 +000044MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults");
Alan Cox5c49fd32011-11-03 18:22:04 +000045module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600);
46
47
48static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
49 { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
50 { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
Alan Cox0cecdd82011-12-19 21:06:35 +000051#if defined(CONFIG_DRM_GMA600)
Alan Cox5c49fd32011-11-03 18:22:04 +000052 { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
53 { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
54 { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
55 { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
56 { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
57 { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
58 { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
59 { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
Alan Cox56125db2011-12-28 15:16:07 +000060 /* Atom E620 */
61 { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
Alan Cox5c49fd32011-11-03 18:22:04 +000062#endif
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000063#if defined(CONFIG_DRM_MEDFIELD)
64 {0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
65 {0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
66 {0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
67 {0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
68 {0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
69 {0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
70 {0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
71 {0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
72#endif
Alan Coxb6195aa2011-12-29 14:37:03 +000073#if defined(CONFIG_DRM_GMA3600)
Alan Cox5c49fd32011-11-03 18:22:04 +000074 { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
75 { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
76 { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
77 { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
78 { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
79 { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
80 { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
81 { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
82#endif
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +000083 { 0, }
Alan Cox5c49fd32011-11-03 18:22:04 +000084};
85MODULE_DEVICE_TABLE(pci, pciidlist);
86
87/*
88 * Standard IOCTLs.
89 */
90
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000091#define DRM_IOCTL_GMA_ADB \
Alan Cox770179d2011-11-16 22:39:18 +000092 DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000093#define DRM_IOCTL_GMA_MODE_OPERATION \
Alan Cox770179d2011-11-16 22:39:18 +000094 DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +000095 struct drm_psb_mode_operation_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000096#define DRM_IOCTL_GMA_STOLEN_MEMORY \
Alan Cox770179d2011-11-16 22:39:18 +000097 DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +000098 struct drm_psb_stolen_memory_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000099#define DRM_IOCTL_GMA_GAMMA \
Alan Cox770179d2011-11-16 22:39:18 +0000100 DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000101 struct drm_psb_dpst_lut_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000102#define DRM_IOCTL_GMA_DPST_BL \
Alan Cox770179d2011-11-16 22:39:18 +0000103 DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000104 uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000105#define DRM_IOCTL_GMA_GET_PIPE_FROM_CRTC_ID \
Alan Cox770179d2011-11-16 22:39:18 +0000106 DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000107 struct drm_psb_get_pipe_from_crtc_id_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000108#define DRM_IOCTL_GMA_GEM_CREATE \
Alan Cox770179d2011-11-16 22:39:18 +0000109 DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000110 struct drm_psb_gem_create)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000111#define DRM_IOCTL_GMA_GEM_MMAP \
Alan Cox770179d2011-11-16 22:39:18 +0000112 DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000113 struct drm_psb_gem_mmap)
114
Alan Cox5c49fd32011-11-03 18:22:04 +0000115static int psb_adb_ioctl(struct drm_device *dev, void *data,
116 struct drm_file *file_priv);
117static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
118 struct drm_file *file_priv);
119static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
120 struct drm_file *file_priv);
Alan Cox5c49fd32011-11-03 18:22:04 +0000121static int psb_gamma_ioctl(struct drm_device *dev, void *data,
122 struct drm_file *file_priv);
123static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
124 struct drm_file *file_priv);
125
Alan Cox5c49fd32011-11-03 18:22:04 +0000126static struct drm_ioctl_desc psb_ioctls[] = {
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000127 DRM_IOCTL_DEF_DRV(GMA_ADB, psb_adb_ioctl, DRM_AUTH),
128 DRM_IOCTL_DEF_DRV(GMA_MODE_OPERATION, psb_mode_operation_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000129 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000130 DRM_IOCTL_DEF_DRV(GMA_STOLEN_MEMORY, psb_stolen_memory_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000131 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000132 DRM_IOCTL_DEF_DRV(GMA_GAMMA, psb_gamma_ioctl, DRM_AUTH),
133 DRM_IOCTL_DEF_DRV(GMA_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
134 DRM_IOCTL_DEF_DRV(GMA_GET_PIPE_FROM_CRTC_ID,
Alan Cox5c49fd32011-11-03 18:22:04 +0000135 psb_intel_get_pipe_from_crtc_id, 0),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000136 DRM_IOCTL_DEF_DRV(GMA_GEM_CREATE, psb_gem_create_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000137 DRM_UNLOCKED | DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000138 DRM_IOCTL_DEF_DRV(GMA_GEM_MMAP, psb_gem_mmap_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000139 DRM_UNLOCKED | DRM_AUTH),
140};
141
142static void psb_lastclose(struct drm_device *dev)
143{
144 return;
145}
146
147static void psb_do_takedown(struct drm_device *dev)
148{
Alan Cox5c49fd32011-11-03 18:22:04 +0000149}
150
151static int psb_do_init(struct drm_device *dev)
152{
153 struct drm_psb_private *dev_priv = dev->dev_private;
154 struct psb_gtt *pg = &dev_priv->gtt;
155
156 uint32_t stolen_gtt;
157
158 int ret = -ENOMEM;
159
160 if (pg->mmu_gatt_start & 0x0FFFFFFF) {
161 dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
162 ret = -EINVAL;
163 goto out_err;
164 }
165
166
167 stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
168 stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
169 stolen_gtt =
170 (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
171
172 dev_priv->gatt_free_offset = pg->mmu_gatt_start +
173 (stolen_gtt << PAGE_SHIFT) * 1024;
174
175 if (1 || drm_debug) {
176 uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID);
177 uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION);
178 DRM_INFO("SGX core id = 0x%08x\n", core_id);
179 DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n",
180 (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >>
181 _PSB_CC_REVISION_MAJOR_SHIFT,
182 (core_rev & _PSB_CC_REVISION_MINOR_MASK) >>
183 _PSB_CC_REVISION_MINOR_SHIFT);
184 DRM_INFO
185 ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n",
186 (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >>
187 _PSB_CC_REVISION_MAINTENANCE_SHIFT,
188 (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >>
189 _PSB_CC_REVISION_DESIGNER_SHIFT);
190 }
191
192
193 spin_lock_init(&dev_priv->irqmask_lock);
Alan Cox9242fe22011-11-29 22:27:10 +0000194 spin_lock_init(&dev_priv->lock_2d);
Alan Cox5c49fd32011-11-03 18:22:04 +0000195
196 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
197 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
198 PSB_RSGX32(PSB_CR_BIF_BANK1);
199 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
200 PSB_CR_BIF_CTRL);
201 psb_spank(dev_priv);
202
203 /* mmu_gatt ?? */
204 PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
205 return 0;
206out_err:
207 psb_do_takedown(dev);
208 return ret;
209}
210
211static int psb_driver_unload(struct drm_device *dev)
212{
213 struct drm_psb_private *dev_priv = dev->dev_private;
214
215 /* Kill vblank etc here */
216
217 gma_backlight_exit(dev);
Alan Coxf9f23a72011-12-29 14:38:07 +0000218 psb_modeset_cleanup(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000219
220 if (dev_priv) {
Alan Coxd839ede2012-05-03 15:06:18 +0100221 psb_intel_opregion_fini(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000222 psb_lid_timer_takedown(dev_priv);
Alan Cox5c49fd32011-11-03 18:22:04 +0000223
224 if (dev_priv->ops->chip_teardown)
225 dev_priv->ops->chip_teardown(dev);
226 psb_do_takedown(dev);
227
228
229 if (dev_priv->pf_pd) {
230 psb_mmu_free_pagedir(dev_priv->pf_pd);
231 dev_priv->pf_pd = NULL;
232 }
233 if (dev_priv->mmu) {
234 struct psb_gtt *pg = &dev_priv->gtt;
235
236 down_read(&pg->sem);
237 psb_mmu_remove_pfn_sequence(
238 psb_mmu_get_default_pd
239 (dev_priv->mmu),
240 pg->mmu_gatt_start,
241 dev_priv->vram_stolen_size >> PAGE_SHIFT);
242 up_read(&pg->sem);
243 psb_mmu_driver_takedown(dev_priv->mmu);
244 dev_priv->mmu = NULL;
245 }
246 psb_gtt_takedown(dev);
247 if (dev_priv->scratch_page) {
Alan Cox18963442012-04-25 14:36:13 +0100248 set_pages_wb(dev_priv->scratch_page, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000249 __free_page(dev_priv->scratch_page);
250 dev_priv->scratch_page = NULL;
251 }
252 if (dev_priv->vdc_reg) {
253 iounmap(dev_priv->vdc_reg);
254 dev_priv->vdc_reg = NULL;
255 }
256 if (dev_priv->sgx_reg) {
257 iounmap(dev_priv->sgx_reg);
258 dev_priv->sgx_reg = NULL;
259 }
260
261 kfree(dev_priv);
262 dev->dev_private = NULL;
263
264 /*destroy VBT data*/
265 psb_intel_destroy_bios(dev);
266 }
267
268 gma_power_uninit(dev);
269
270 return 0;
271}
272
273
274static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
275{
276 struct drm_psb_private *dev_priv;
277 unsigned long resource_start;
Alan Cox5c49fd32011-11-03 18:22:04 +0000278 unsigned long irqflags;
279 int ret = -ENOMEM;
Alan Cox5c49fd32011-11-03 18:22:04 +0000280 struct drm_connector *connector;
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000281 struct psb_intel_encoder *psb_intel_encoder;
Alan Cox5c49fd32011-11-03 18:22:04 +0000282
283 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
284 if (dev_priv == NULL)
285 return -ENOMEM;
286
287 dev_priv->ops = (struct psb_ops *)chipset;
288 dev_priv->dev = dev;
289 dev->dev_private = (void *) dev_priv;
290
Dave Airlie466e69b2011-12-19 11:15:29 +0000291 pci_set_master(dev->pdev);
292
Patrik Jakobsson84b08fe2011-11-29 22:20:20 +0000293 if (!IS_PSB(dev)) {
294 if (pci_enable_msi(dev->pdev))
295 dev_warn(dev->dev, "Enabling MSI failed!\n");
296 }
297
Alan Cox5c49fd32011-11-03 18:22:04 +0000298 dev_priv->num_pipe = dev_priv->ops->pipes;
299
300 resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
301
302 dev_priv->vdc_reg =
303 ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
304 if (!dev_priv->vdc_reg)
305 goto out_err;
306
307 dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
308 PSB_SGX_SIZE);
309 if (!dev_priv->sgx_reg)
310 goto out_err;
311
Alan Coxd839ede2012-05-03 15:06:18 +0100312 psb_intel_opregion_setup(dev);
313
Alan Cox5c49fd32011-11-03 18:22:04 +0000314 ret = dev_priv->ops->chip_setup(dev);
315 if (ret)
316 goto out_err;
317
318 /* Init OSPM support */
319 gma_power_init(dev);
320
321 ret = -ENOMEM;
322
323 dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
324 if (!dev_priv->scratch_page)
325 goto out_err;
326
327 set_pages_uc(dev_priv->scratch_page, 1);
328
329 ret = psb_gtt_init(dev, 0);
330 if (ret)
331 goto out_err;
332
333 dev_priv->mmu = psb_mmu_driver_init((void *)0,
334 drm_psb_trap_pagefaults, 0,
335 dev_priv);
336 if (!dev_priv->mmu)
337 goto out_err;
338
Alan Cox5c49fd32011-11-03 18:22:04 +0000339 dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
340 if (!dev_priv->pf_pd)
341 goto out_err;
342
343 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
344 psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
345
346 ret = psb_do_init(dev);
347 if (ret)
348 return ret;
349
350 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
351 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
352
Alan Coxd839ede2012-05-03 15:06:18 +0100353 acpi_video_register();
Alan Cox25933dd2012-05-03 15:07:13 +0100354 if (dev_priv->opregion.lid_state)
Alan Cox5c49fd32011-11-03 18:22:04 +0000355 psb_lid_timer_init(dev_priv);
356
357 ret = drm_vblank_init(dev, dev_priv->num_pipe);
358 if (ret)
359 goto out_err;
360
361 /*
362 * Install interrupt handlers prior to powering off SGX or else we will
363 * crash.
364 */
365 dev_priv->vdc_irq_mask = 0;
366 dev_priv->pipestat[0] = 0;
367 dev_priv->pipestat[1] = 0;
368 dev_priv->pipestat[2] = 0;
369 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
370 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
371 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
372 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
373 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
Patrik Jakobssone036ba52011-11-29 22:20:07 +0000374 if (IS_PSB(dev) && drm_core_check_feature(dev, DRIVER_MODESET))
Alan Cox5c49fd32011-11-03 18:22:04 +0000375 drm_irq_install(dev);
376
377 dev->vblank_disable_allowed = 1;
378
379 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
380
381 dev->driver->get_vblank_counter = psb_get_vblank_counter;
382
Alan Coxf9f23a72011-12-29 14:38:07 +0000383 psb_modeset_init(dev);
384 psb_fbdev_init(dev);
385 drm_kms_helper_poll_init(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000386
387 /* Only add backlight support if we have LVDS output */
388 list_for_each_entry(connector, &dev->mode_config.connector_list,
389 head) {
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000390 psb_intel_encoder = psb_intel_attached_encoder(connector);
Alan Cox5c49fd32011-11-03 18:22:04 +0000391
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000392 switch (psb_intel_encoder->type) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000393 case INTEL_OUTPUT_LVDS:
394 case INTEL_OUTPUT_MIPI:
395 ret = gma_backlight_init(dev);
396 break;
397 }
398 }
399
400 if (ret)
401 return ret;
402#if 0
403 /*enable runtime pm at last*/
404 pm_runtime_enable(&dev->pdev->dev);
405 pm_runtime_set_active(&dev->pdev->dev);
406#endif
407 /*Intel drm driver load is done, continue doing pvr load*/
408 return 0;
409out_err:
410 psb_driver_unload(dev);
411 return ret;
412}
413
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000414static int psb_driver_device_is_agp(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000415{
416 return 0;
417}
418
Alan Cox5c49fd32011-11-03 18:22:04 +0000419static inline void get_brightness(struct backlight_device *bd)
420{
421#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
422 if (bd) {
423 bd->props.brightness = bd->ops->get_brightness(bd);
424 backlight_update_status(bd);
425 }
426#endif
427}
428
429static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
430 struct drm_file *file_priv)
431{
432 struct drm_psb_private *dev_priv = psb_priv(dev);
433 uint32_t *arg = data;
434
435 dev_priv->blc_adj2 = *arg;
436 get_brightness(dev_priv->backlight_device);
437 return 0;
438}
439
440static int psb_adb_ioctl(struct drm_device *dev, void *data,
441 struct drm_file *file_priv)
442{
443 struct drm_psb_private *dev_priv = psb_priv(dev);
444 uint32_t *arg = data;
445
446 dev_priv->blc_adj1 = *arg;
447 get_brightness(dev_priv->backlight_device);
448 return 0;
449}
450
Alan Cox5c49fd32011-11-03 18:22:04 +0000451static int psb_gamma_ioctl(struct drm_device *dev, void *data,
452 struct drm_file *file_priv)
453{
454 struct drm_psb_dpst_lut_arg *lut_arg = data;
455 struct drm_mode_object *obj;
456 struct drm_crtc *crtc;
457 struct drm_connector *connector;
458 struct psb_intel_crtc *psb_intel_crtc;
459 int i = 0;
460 int32_t obj_id;
461
462 obj_id = lut_arg->output_id;
463 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
464 if (!obj) {
465 dev_dbg(dev->dev, "Invalid Connector object.\n");
466 return -EINVAL;
467 }
468
469 connector = obj_to_connector(obj);
470 crtc = connector->encoder->crtc;
471 psb_intel_crtc = to_psb_intel_crtc(crtc);
472
473 for (i = 0; i < 256; i++)
474 psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
475
476 psb_intel_crtc_load_lut(crtc);
477
478 return 0;
479}
480
481static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
482 struct drm_file *file_priv)
483{
484 uint32_t obj_id;
485 uint16_t op;
486 struct drm_mode_modeinfo *umode;
487 struct drm_display_mode *mode = NULL;
488 struct drm_psb_mode_operation_arg *arg;
489 struct drm_mode_object *obj;
490 struct drm_connector *connector;
Alan Cox5c49fd32011-11-03 18:22:04 +0000491 struct drm_connector_helper_funcs *connector_funcs;
492 int ret = 0;
493 int resp = MODE_OK;
Alan Cox5c49fd32011-11-03 18:22:04 +0000494
495 arg = (struct drm_psb_mode_operation_arg *)data;
496 obj_id = arg->obj_id;
497 op = arg->operation;
498
499 switch (op) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000500 case PSB_MODE_OPERATION_MODE_VALID:
501 umode = &arg->mode;
502
503 mutex_lock(&dev->mode_config.mutex);
504
505 obj = drm_mode_object_find(dev, obj_id,
506 DRM_MODE_OBJECT_CONNECTOR);
507 if (!obj) {
508 ret = -EINVAL;
509 goto mode_op_out;
510 }
511
512 connector = obj_to_connector(obj);
513
514 mode = drm_mode_create(dev);
515 if (!mode) {
516 ret = -ENOMEM;
517 goto mode_op_out;
518 }
519
520 /* drm_crtc_convert_umode(mode, umode); */
521 {
522 mode->clock = umode->clock;
523 mode->hdisplay = umode->hdisplay;
524 mode->hsync_start = umode->hsync_start;
525 mode->hsync_end = umode->hsync_end;
526 mode->htotal = umode->htotal;
527 mode->hskew = umode->hskew;
528 mode->vdisplay = umode->vdisplay;
529 mode->vsync_start = umode->vsync_start;
530 mode->vsync_end = umode->vsync_end;
531 mode->vtotal = umode->vtotal;
532 mode->vscan = umode->vscan;
533 mode->vrefresh = umode->vrefresh;
534 mode->flags = umode->flags;
535 mode->type = umode->type;
536 strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
537 mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
538 }
539
540 connector_funcs = (struct drm_connector_helper_funcs *)
541 connector->helper_private;
542
543 if (connector_funcs->mode_valid) {
544 resp = connector_funcs->mode_valid(connector, mode);
Alan Cox61bedf72011-11-16 22:38:42 +0000545 arg->data = resp;
Alan Cox5c49fd32011-11-03 18:22:04 +0000546 }
547
548 /*do some clean up work*/
549 if (mode)
550 drm_mode_destroy(dev, mode);
551mode_op_out:
552 mutex_unlock(&dev->mode_config.mutex);
553 return ret;
554
555 default:
556 dev_dbg(dev->dev, "Unsupported psb mode operation\n");
557 return -EOPNOTSUPP;
558 }
559
560 return 0;
561}
562
563static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
564 struct drm_file *file_priv)
565{
566 struct drm_psb_private *dev_priv = psb_priv(dev);
567 struct drm_psb_stolen_memory_arg *arg = data;
568
569 arg->base = dev_priv->stolen_base;
570 arg->size = dev_priv->vram_stolen_size;
571
572 return 0;
573}
574
Alan Cox5c49fd32011-11-03 18:22:04 +0000575static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
576{
577 return 0;
578}
579
580static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
581{
582}
583
584static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
585 unsigned long arg)
586{
587 struct drm_file *file_priv = filp->private_data;
588 struct drm_device *dev = file_priv->minor->dev;
589 struct drm_psb_private *dev_priv = dev->dev_private;
590 static unsigned int runtime_allowed;
591
592 if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
593 runtime_allowed++;
594 pm_runtime_allow(&dev->pdev->dev);
595 dev_priv->rpm_enabled = 1;
596 }
597 return drm_ioctl(filp, cmd, arg);
598 /* FIXME: do we need to wrap the other side of this */
599}
600
601
602/* When a client dies:
603 * - Check for and clean up flipped page state
604 */
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000605static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
Alan Cox5c49fd32011-11-03 18:22:04 +0000606{
607}
608
609static void psb_remove(struct pci_dev *pdev)
610{
611 struct drm_device *dev = pci_get_drvdata(pdev);
612 drm_put_dev(dev);
613}
614
615static const struct dev_pm_ops psb_pm_ops = {
616 .resume = gma_power_resume,
617 .suspend = gma_power_suspend,
618 .runtime_suspend = psb_runtime_suspend,
619 .runtime_resume = psb_runtime_resume,
620 .runtime_idle = psb_runtime_idle,
621};
622
623static struct vm_operations_struct psb_gem_vm_ops = {
624 .fault = psb_gem_fault,
625 .open = drm_gem_vm_open,
626 .close = drm_gem_vm_close,
627};
628
Ilija Hadzic1595c562011-11-27 11:08:33 -0500629static const struct file_operations psb_gem_fops = {
630 .owner = THIS_MODULE,
631 .open = drm_open,
632 .release = drm_release,
633 .unlocked_ioctl = psb_unlocked_ioctl,
634 .mmap = drm_gem_mmap,
635 .poll = drm_poll,
636 .fasync = drm_fasync,
637 .read = drm_read,
638};
639
Alan Cox5c49fd32011-11-03 18:22:04 +0000640static struct drm_driver driver = {
641 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
642 DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
643 .load = psb_driver_load,
644 .unload = psb_driver_unload,
645
646 .ioctls = psb_ioctls,
647 .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
648 .device_is_agp = psb_driver_device_is_agp,
649 .irq_preinstall = psb_irq_preinstall,
650 .irq_postinstall = psb_irq_postinstall,
651 .irq_uninstall = psb_irq_uninstall,
652 .irq_handler = psb_irq_handler,
653 .enable_vblank = psb_enable_vblank,
654 .disable_vblank = psb_disable_vblank,
655 .get_vblank_counter = psb_get_vblank_counter,
656 .lastclose = psb_lastclose,
657 .open = psb_driver_open,
658 .preclose = psb_driver_preclose,
659 .postclose = psb_driver_close,
660 .reclaim_buffers = drm_core_reclaim_buffers,
661
662 .gem_init_object = psb_gem_init_object,
663 .gem_free_object = psb_gem_free_object,
664 .gem_vm_ops = &psb_gem_vm_ops,
665 .dumb_create = psb_gem_dumb_create,
666 .dumb_map_offset = psb_gem_dumb_map_gtt,
667 .dumb_destroy = psb_gem_dumb_destroy,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500668 .fops = &psb_gem_fops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000669 .name = DRIVER_NAME,
670 .desc = DRIVER_DESC,
671 .date = PSB_DRM_DRIVER_DATE,
672 .major = PSB_DRM_DRIVER_MAJOR,
673 .minor = PSB_DRM_DRIVER_MINOR,
674 .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
675};
676
677static struct pci_driver psb_pci_driver = {
678 .name = DRIVER_NAME,
679 .id_table = pciidlist,
680 .probe = psb_probe,
681 .remove = psb_remove,
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +0000682 .driver = {
683 .pm = &psb_pm_ops,
684 }
Alan Cox5c49fd32011-11-03 18:22:04 +0000685};
686
687static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
688{
Alan Cox5c49fd32011-11-03 18:22:04 +0000689 return drm_get_pci_dev(pdev, ent, &driver);
690}
691
692static int __init psb_init(void)
693{
694 return drm_pci_init(&driver, &psb_pci_driver);
695}
696
697static void __exit psb_exit(void)
698{
699 drm_pci_exit(&driver, &psb_pci_driver);
700}
701
702late_initcall(psb_init);
703module_exit(psb_exit);
704
705MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
706MODULE_DESCRIPTION(DRIVER_DESC);
707MODULE_LICENSE("GPL");