blob: c4c6c8ea129ab1aac99d80d77307bdfe7518be4c [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},
Alan Cox9aa65a22012-05-11 11:32:46 +010082 { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
83 { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
84 { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
85 { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
86 { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
87 { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
88 { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
89 { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
Alan Cox5c49fd32011-11-03 18:22:04 +000090#endif
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +000091 { 0, }
Alan Cox5c49fd32011-11-03 18:22:04 +000092};
93MODULE_DEVICE_TABLE(pci, pciidlist);
94
95/*
96 * Standard IOCTLs.
97 */
98
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000099#define DRM_IOCTL_GMA_ADB \
Alan Cox770179d2011-11-16 22:39:18 +0000100 DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000101#define DRM_IOCTL_GMA_MODE_OPERATION \
Alan Cox770179d2011-11-16 22:39:18 +0000102 DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000103 struct drm_psb_mode_operation_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000104#define DRM_IOCTL_GMA_STOLEN_MEMORY \
Alan Cox770179d2011-11-16 22:39:18 +0000105 DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000106 struct drm_psb_stolen_memory_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000107#define DRM_IOCTL_GMA_GAMMA \
Alan Cox770179d2011-11-16 22:39:18 +0000108 DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000109 struct drm_psb_dpst_lut_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000110#define DRM_IOCTL_GMA_DPST_BL \
Alan Cox770179d2011-11-16 22:39:18 +0000111 DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000112 uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000113#define DRM_IOCTL_GMA_GET_PIPE_FROM_CRTC_ID \
Alan Cox770179d2011-11-16 22:39:18 +0000114 DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000115 struct drm_psb_get_pipe_from_crtc_id_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000116#define DRM_IOCTL_GMA_GEM_CREATE \
Alan Cox770179d2011-11-16 22:39:18 +0000117 DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000118 struct drm_psb_gem_create)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000119#define DRM_IOCTL_GMA_GEM_MMAP \
Alan Cox770179d2011-11-16 22:39:18 +0000120 DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000121 struct drm_psb_gem_mmap)
122
Alan Cox5c49fd32011-11-03 18:22:04 +0000123static int psb_adb_ioctl(struct drm_device *dev, void *data,
124 struct drm_file *file_priv);
125static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
126 struct drm_file *file_priv);
127static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
128 struct drm_file *file_priv);
Alan Cox5c49fd32011-11-03 18:22:04 +0000129static int psb_gamma_ioctl(struct drm_device *dev, void *data,
130 struct drm_file *file_priv);
131static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
132 struct drm_file *file_priv);
133
Alan Cox5c49fd32011-11-03 18:22:04 +0000134static struct drm_ioctl_desc psb_ioctls[] = {
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000135 DRM_IOCTL_DEF_DRV(GMA_ADB, psb_adb_ioctl, DRM_AUTH),
136 DRM_IOCTL_DEF_DRV(GMA_MODE_OPERATION, psb_mode_operation_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000137 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000138 DRM_IOCTL_DEF_DRV(GMA_STOLEN_MEMORY, psb_stolen_memory_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000139 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000140 DRM_IOCTL_DEF_DRV(GMA_GAMMA, psb_gamma_ioctl, DRM_AUTH),
141 DRM_IOCTL_DEF_DRV(GMA_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
142 DRM_IOCTL_DEF_DRV(GMA_GET_PIPE_FROM_CRTC_ID,
Alan Cox5c49fd32011-11-03 18:22:04 +0000143 psb_intel_get_pipe_from_crtc_id, 0),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000144 DRM_IOCTL_DEF_DRV(GMA_GEM_CREATE, psb_gem_create_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000145 DRM_UNLOCKED | DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000146 DRM_IOCTL_DEF_DRV(GMA_GEM_MMAP, psb_gem_mmap_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000147 DRM_UNLOCKED | DRM_AUTH),
148};
149
150static void psb_lastclose(struct drm_device *dev)
151{
152 return;
153}
154
155static void psb_do_takedown(struct drm_device *dev)
156{
Alan Cox5c49fd32011-11-03 18:22:04 +0000157}
158
159static int psb_do_init(struct drm_device *dev)
160{
161 struct drm_psb_private *dev_priv = dev->dev_private;
162 struct psb_gtt *pg = &dev_priv->gtt;
163
164 uint32_t stolen_gtt;
165
166 int ret = -ENOMEM;
167
168 if (pg->mmu_gatt_start & 0x0FFFFFFF) {
169 dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
170 ret = -EINVAL;
171 goto out_err;
172 }
173
174
175 stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
176 stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
177 stolen_gtt =
178 (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
179
180 dev_priv->gatt_free_offset = pg->mmu_gatt_start +
181 (stolen_gtt << PAGE_SHIFT) * 1024;
182
Alan Cox5c49fd32011-11-03 18:22:04 +0000183 spin_lock_init(&dev_priv->irqmask_lock);
Alan Cox9242fe22011-11-29 22:27:10 +0000184 spin_lock_init(&dev_priv->lock_2d);
Alan Cox5c49fd32011-11-03 18:22:04 +0000185
186 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
187 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
188 PSB_RSGX32(PSB_CR_BIF_BANK1);
189 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
190 PSB_CR_BIF_CTRL);
191 psb_spank(dev_priv);
192
193 /* mmu_gatt ?? */
194 PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
195 return 0;
196out_err:
197 psb_do_takedown(dev);
198 return ret;
199}
200
201static int psb_driver_unload(struct drm_device *dev)
202{
203 struct drm_psb_private *dev_priv = dev->dev_private;
204
205 /* Kill vblank etc here */
206
207 gma_backlight_exit(dev);
Alan Coxf9f23a72011-12-29 14:38:07 +0000208 psb_modeset_cleanup(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000209
210 if (dev_priv) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000211
212 if (dev_priv->ops->chip_teardown)
213 dev_priv->ops->chip_teardown(dev);
Alan Cox6607e022012-05-14 12:03:34 +0100214
215 psb_intel_opregion_fini(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000216 psb_do_takedown(dev);
217
218
219 if (dev_priv->pf_pd) {
220 psb_mmu_free_pagedir(dev_priv->pf_pd);
221 dev_priv->pf_pd = NULL;
222 }
223 if (dev_priv->mmu) {
224 struct psb_gtt *pg = &dev_priv->gtt;
225
226 down_read(&pg->sem);
227 psb_mmu_remove_pfn_sequence(
228 psb_mmu_get_default_pd
229 (dev_priv->mmu),
230 pg->mmu_gatt_start,
231 dev_priv->vram_stolen_size >> PAGE_SHIFT);
232 up_read(&pg->sem);
233 psb_mmu_driver_takedown(dev_priv->mmu);
234 dev_priv->mmu = NULL;
235 }
236 psb_gtt_takedown(dev);
237 if (dev_priv->scratch_page) {
Alan Cox18963442012-04-25 14:36:13 +0100238 set_pages_wb(dev_priv->scratch_page, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000239 __free_page(dev_priv->scratch_page);
240 dev_priv->scratch_page = NULL;
241 }
242 if (dev_priv->vdc_reg) {
243 iounmap(dev_priv->vdc_reg);
244 dev_priv->vdc_reg = NULL;
245 }
246 if (dev_priv->sgx_reg) {
247 iounmap(dev_priv->sgx_reg);
248 dev_priv->sgx_reg = NULL;
249 }
250
251 kfree(dev_priv);
252 dev->dev_private = NULL;
253
254 /*destroy VBT data*/
255 psb_intel_destroy_bios(dev);
256 }
257
258 gma_power_uninit(dev);
259
260 return 0;
261}
262
263
264static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
265{
266 struct drm_psb_private *dev_priv;
267 unsigned long resource_start;
Alan Cox5c49fd32011-11-03 18:22:04 +0000268 unsigned long irqflags;
269 int ret = -ENOMEM;
Alan Cox5c49fd32011-11-03 18:22:04 +0000270 struct drm_connector *connector;
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000271 struct psb_intel_encoder *psb_intel_encoder;
Alan Cox5c49fd32011-11-03 18:22:04 +0000272
273 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
274 if (dev_priv == NULL)
275 return -ENOMEM;
276
277 dev_priv->ops = (struct psb_ops *)chipset;
278 dev_priv->dev = dev;
279 dev->dev_private = (void *) dev_priv;
280
Dave Airlie466e69b2011-12-19 11:15:29 +0000281 pci_set_master(dev->pdev);
282
Alan Cox5c49fd32011-11-03 18:22:04 +0000283 dev_priv->num_pipe = dev_priv->ops->pipes;
284
285 resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
286
287 dev_priv->vdc_reg =
288 ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
289 if (!dev_priv->vdc_reg)
290 goto out_err;
291
292 dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
293 PSB_SGX_SIZE);
294 if (!dev_priv->sgx_reg)
295 goto out_err;
296
Alan Coxd839ede2012-05-03 15:06:18 +0100297 psb_intel_opregion_setup(dev);
298
Alan Cox5c49fd32011-11-03 18:22:04 +0000299 ret = dev_priv->ops->chip_setup(dev);
300 if (ret)
301 goto out_err;
302
303 /* Init OSPM support */
304 gma_power_init(dev);
305
306 ret = -ENOMEM;
307
308 dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
309 if (!dev_priv->scratch_page)
310 goto out_err;
311
312 set_pages_uc(dev_priv->scratch_page, 1);
313
314 ret = psb_gtt_init(dev, 0);
315 if (ret)
316 goto out_err;
317
318 dev_priv->mmu = psb_mmu_driver_init((void *)0,
319 drm_psb_trap_pagefaults, 0,
320 dev_priv);
321 if (!dev_priv->mmu)
322 goto out_err;
323
Alan Cox5c49fd32011-11-03 18:22:04 +0000324 dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
325 if (!dev_priv->pf_pd)
326 goto out_err;
327
328 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
329 psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
330
331 ret = psb_do_init(dev);
332 if (ret)
333 return ret;
334
335 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
336 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
337
Alan Coxd839ede2012-05-03 15:06:18 +0100338 acpi_video_register();
Alan Cox5c49fd32011-11-03 18:22:04 +0000339
340 ret = drm_vblank_init(dev, dev_priv->num_pipe);
341 if (ret)
342 goto out_err;
343
344 /*
345 * Install interrupt handlers prior to powering off SGX or else we will
346 * crash.
347 */
348 dev_priv->vdc_irq_mask = 0;
349 dev_priv->pipestat[0] = 0;
350 dev_priv->pipestat[1] = 0;
351 dev_priv->pipestat[2] = 0;
352 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
353 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
354 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
355 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
356 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
Alan Cox62363a42012-05-11 11:33:17 +0100357
358 drm_irq_install(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000359
360 dev->vblank_disable_allowed = 1;
361
362 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
363
364 dev->driver->get_vblank_counter = psb_get_vblank_counter;
365
Alan Coxf9f23a72011-12-29 14:38:07 +0000366 psb_modeset_init(dev);
367 psb_fbdev_init(dev);
368 drm_kms_helper_poll_init(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000369
370 /* Only add backlight support if we have LVDS output */
371 list_for_each_entry(connector, &dev->mode_config.connector_list,
372 head) {
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000373 psb_intel_encoder = psb_intel_attached_encoder(connector);
Alan Cox5c49fd32011-11-03 18:22:04 +0000374
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000375 switch (psb_intel_encoder->type) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000376 case INTEL_OUTPUT_LVDS:
377 case INTEL_OUTPUT_MIPI:
378 ret = gma_backlight_init(dev);
379 break;
380 }
381 }
382
383 if (ret)
384 return ret;
385#if 0
386 /*enable runtime pm at last*/
387 pm_runtime_enable(&dev->pdev->dev);
388 pm_runtime_set_active(&dev->pdev->dev);
389#endif
390 /*Intel drm driver load is done, continue doing pvr load*/
391 return 0;
392out_err:
393 psb_driver_unload(dev);
394 return ret;
395}
396
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000397static int psb_driver_device_is_agp(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000398{
399 return 0;
400}
401
Alan Cox5c49fd32011-11-03 18:22:04 +0000402static inline void get_brightness(struct backlight_device *bd)
403{
404#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
405 if (bd) {
406 bd->props.brightness = bd->ops->get_brightness(bd);
407 backlight_update_status(bd);
408 }
409#endif
410}
411
412static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
413 struct drm_file *file_priv)
414{
415 struct drm_psb_private *dev_priv = psb_priv(dev);
416 uint32_t *arg = data;
417
418 dev_priv->blc_adj2 = *arg;
419 get_brightness(dev_priv->backlight_device);
420 return 0;
421}
422
423static int psb_adb_ioctl(struct drm_device *dev, void *data,
424 struct drm_file *file_priv)
425{
426 struct drm_psb_private *dev_priv = psb_priv(dev);
427 uint32_t *arg = data;
428
429 dev_priv->blc_adj1 = *arg;
430 get_brightness(dev_priv->backlight_device);
431 return 0;
432}
433
Alan Cox5c49fd32011-11-03 18:22:04 +0000434static int psb_gamma_ioctl(struct drm_device *dev, void *data,
435 struct drm_file *file_priv)
436{
437 struct drm_psb_dpst_lut_arg *lut_arg = data;
438 struct drm_mode_object *obj;
439 struct drm_crtc *crtc;
440 struct drm_connector *connector;
441 struct psb_intel_crtc *psb_intel_crtc;
442 int i = 0;
443 int32_t obj_id;
444
445 obj_id = lut_arg->output_id;
446 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
447 if (!obj) {
448 dev_dbg(dev->dev, "Invalid Connector object.\n");
449 return -EINVAL;
450 }
451
452 connector = obj_to_connector(obj);
453 crtc = connector->encoder->crtc;
454 psb_intel_crtc = to_psb_intel_crtc(crtc);
455
456 for (i = 0; i < 256; i++)
457 psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
458
459 psb_intel_crtc_load_lut(crtc);
460
461 return 0;
462}
463
464static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
465 struct drm_file *file_priv)
466{
467 uint32_t obj_id;
468 uint16_t op;
469 struct drm_mode_modeinfo *umode;
470 struct drm_display_mode *mode = NULL;
471 struct drm_psb_mode_operation_arg *arg;
472 struct drm_mode_object *obj;
473 struct drm_connector *connector;
Alan Cox5c49fd32011-11-03 18:22:04 +0000474 struct drm_connector_helper_funcs *connector_funcs;
475 int ret = 0;
476 int resp = MODE_OK;
Alan Cox5c49fd32011-11-03 18:22:04 +0000477
478 arg = (struct drm_psb_mode_operation_arg *)data;
479 obj_id = arg->obj_id;
480 op = arg->operation;
481
482 switch (op) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000483 case PSB_MODE_OPERATION_MODE_VALID:
484 umode = &arg->mode;
485
486 mutex_lock(&dev->mode_config.mutex);
487
488 obj = drm_mode_object_find(dev, obj_id,
489 DRM_MODE_OBJECT_CONNECTOR);
490 if (!obj) {
491 ret = -EINVAL;
492 goto mode_op_out;
493 }
494
495 connector = obj_to_connector(obj);
496
497 mode = drm_mode_create(dev);
498 if (!mode) {
499 ret = -ENOMEM;
500 goto mode_op_out;
501 }
502
503 /* drm_crtc_convert_umode(mode, umode); */
504 {
505 mode->clock = umode->clock;
506 mode->hdisplay = umode->hdisplay;
507 mode->hsync_start = umode->hsync_start;
508 mode->hsync_end = umode->hsync_end;
509 mode->htotal = umode->htotal;
510 mode->hskew = umode->hskew;
511 mode->vdisplay = umode->vdisplay;
512 mode->vsync_start = umode->vsync_start;
513 mode->vsync_end = umode->vsync_end;
514 mode->vtotal = umode->vtotal;
515 mode->vscan = umode->vscan;
516 mode->vrefresh = umode->vrefresh;
517 mode->flags = umode->flags;
518 mode->type = umode->type;
519 strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
520 mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
521 }
522
523 connector_funcs = (struct drm_connector_helper_funcs *)
524 connector->helper_private;
525
526 if (connector_funcs->mode_valid) {
527 resp = connector_funcs->mode_valid(connector, mode);
Alan Cox61bedf72011-11-16 22:38:42 +0000528 arg->data = resp;
Alan Cox5c49fd32011-11-03 18:22:04 +0000529 }
530
531 /*do some clean up work*/
532 if (mode)
533 drm_mode_destroy(dev, mode);
534mode_op_out:
535 mutex_unlock(&dev->mode_config.mutex);
536 return ret;
537
538 default:
539 dev_dbg(dev->dev, "Unsupported psb mode operation\n");
540 return -EOPNOTSUPP;
541 }
542
543 return 0;
544}
545
546static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
547 struct drm_file *file_priv)
548{
549 struct drm_psb_private *dev_priv = psb_priv(dev);
550 struct drm_psb_stolen_memory_arg *arg = data;
551
552 arg->base = dev_priv->stolen_base;
553 arg->size = dev_priv->vram_stolen_size;
554
555 return 0;
556}
557
Alan Cox5c49fd32011-11-03 18:22:04 +0000558static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
559{
560 return 0;
561}
562
563static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
564{
565}
566
567static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
568 unsigned long arg)
569{
570 struct drm_file *file_priv = filp->private_data;
571 struct drm_device *dev = file_priv->minor->dev;
572 struct drm_psb_private *dev_priv = dev->dev_private;
573 static unsigned int runtime_allowed;
574
575 if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
576 runtime_allowed++;
577 pm_runtime_allow(&dev->pdev->dev);
578 dev_priv->rpm_enabled = 1;
579 }
580 return drm_ioctl(filp, cmd, arg);
581 /* FIXME: do we need to wrap the other side of this */
582}
583
584
585/* When a client dies:
586 * - Check for and clean up flipped page state
587 */
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000588static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
Alan Cox5c49fd32011-11-03 18:22:04 +0000589{
590}
591
592static void psb_remove(struct pci_dev *pdev)
593{
594 struct drm_device *dev = pci_get_drvdata(pdev);
595 drm_put_dev(dev);
596}
597
598static const struct dev_pm_ops psb_pm_ops = {
599 .resume = gma_power_resume,
600 .suspend = gma_power_suspend,
601 .runtime_suspend = psb_runtime_suspend,
602 .runtime_resume = psb_runtime_resume,
603 .runtime_idle = psb_runtime_idle,
604};
605
606static struct vm_operations_struct psb_gem_vm_ops = {
607 .fault = psb_gem_fault,
608 .open = drm_gem_vm_open,
609 .close = drm_gem_vm_close,
610};
611
Ilija Hadzic1595c562011-11-27 11:08:33 -0500612static const struct file_operations psb_gem_fops = {
613 .owner = THIS_MODULE,
614 .open = drm_open,
615 .release = drm_release,
616 .unlocked_ioctl = psb_unlocked_ioctl,
617 .mmap = drm_gem_mmap,
618 .poll = drm_poll,
619 .fasync = drm_fasync,
620 .read = drm_read,
621};
622
Alan Cox5c49fd32011-11-03 18:22:04 +0000623static struct drm_driver driver = {
624 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
625 DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
626 .load = psb_driver_load,
627 .unload = psb_driver_unload,
628
629 .ioctls = psb_ioctls,
630 .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
631 .device_is_agp = psb_driver_device_is_agp,
632 .irq_preinstall = psb_irq_preinstall,
633 .irq_postinstall = psb_irq_postinstall,
634 .irq_uninstall = psb_irq_uninstall,
635 .irq_handler = psb_irq_handler,
636 .enable_vblank = psb_enable_vblank,
637 .disable_vblank = psb_disable_vblank,
638 .get_vblank_counter = psb_get_vblank_counter,
639 .lastclose = psb_lastclose,
640 .open = psb_driver_open,
641 .preclose = psb_driver_preclose,
642 .postclose = psb_driver_close,
643 .reclaim_buffers = drm_core_reclaim_buffers,
644
645 .gem_init_object = psb_gem_init_object,
646 .gem_free_object = psb_gem_free_object,
647 .gem_vm_ops = &psb_gem_vm_ops,
648 .dumb_create = psb_gem_dumb_create,
649 .dumb_map_offset = psb_gem_dumb_map_gtt,
650 .dumb_destroy = psb_gem_dumb_destroy,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500651 .fops = &psb_gem_fops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000652 .name = DRIVER_NAME,
653 .desc = DRIVER_DESC,
654 .date = PSB_DRM_DRIVER_DATE,
655 .major = PSB_DRM_DRIVER_MAJOR,
656 .minor = PSB_DRM_DRIVER_MINOR,
657 .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
658};
659
660static struct pci_driver psb_pci_driver = {
661 .name = DRIVER_NAME,
662 .id_table = pciidlist,
663 .probe = psb_probe,
664 .remove = psb_remove,
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +0000665 .driver = {
666 .pm = &psb_pm_ops,
667 }
Alan Cox5c49fd32011-11-03 18:22:04 +0000668};
669
670static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
671{
Alan Cox5c49fd32011-11-03 18:22:04 +0000672 return drm_get_pci_dev(pdev, ent, &driver);
673}
674
675static int __init psb_init(void)
676{
677 return drm_pci_init(&driver, &psb_pci_driver);
678}
679
680static void __exit psb_exit(void)
681{
682 drm_pci_exit(&driver, &psb_pci_driver);
683}
684
685late_initcall(psb_init);
686module_exit(psb_exit);
687
688MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
689MODULE_DESCRIPTION(DRIVER_DESC);
690MODULE_LICENSE("GPL");