15c49fd3aSAlan Cox /************************************************************************** 25c49fd3aSAlan Cox * Copyright (c) 2007-2011, Intel Corporation. 35c49fd3aSAlan Cox * All Rights Reserved. 45c49fd3aSAlan Cox * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA. 55c49fd3aSAlan Cox * All Rights Reserved. 65c49fd3aSAlan Cox * 75c49fd3aSAlan Cox * This program is free software; you can redistribute it and/or modify it 85c49fd3aSAlan Cox * under the terms and conditions of the GNU General Public License, 95c49fd3aSAlan Cox * version 2, as published by the Free Software Foundation. 105c49fd3aSAlan Cox * 115c49fd3aSAlan Cox * This program is distributed in the hope it will be useful, but WITHOUT 125c49fd3aSAlan Cox * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 135c49fd3aSAlan Cox * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 145c49fd3aSAlan Cox * more details. 155c49fd3aSAlan Cox * 165c49fd3aSAlan Cox * You should have received a copy of the GNU General Public License along with 175c49fd3aSAlan Cox * this program; if not, write to the Free Software Foundation, Inc., 185c49fd3aSAlan Cox * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 195c49fd3aSAlan Cox * 205c49fd3aSAlan Cox **************************************************************************/ 215c49fd3aSAlan Cox 225c49fd3aSAlan Cox #include <drm/drmP.h> 235c49fd3aSAlan Cox #include <drm/drm.h> 245c49fd3aSAlan Cox #include "psb_drv.h" 255c49fd3aSAlan Cox #include "framebuffer.h" 265c49fd3aSAlan Cox #include "psb_reg.h" 275c49fd3aSAlan Cox #include "psb_intel_reg.h" 285c49fd3aSAlan Cox #include "intel_bios.h" 295c49fd3aSAlan Cox #include "mid_bios.h" 305c49fd3aSAlan Cox #include <drm/drm_pciids.h> 315c49fd3aSAlan Cox #include "power.h" 325c49fd3aSAlan Cox #include <linux/cpu.h> 335c49fd3aSAlan Cox #include <linux/notifier.h> 345c49fd3aSAlan Cox #include <linux/spinlock.h> 355c49fd3aSAlan Cox #include <linux/pm_runtime.h> 365c49fd3aSAlan Cox #include <acpi/video.h> 37af3a2cfbSDave Airlie #include <linux/module.h> 38ed3ba079SLaura Abbott #include <asm/set_memory.h> 395c49fd3aSAlan Cox 40f90cd811SArthur Borsboom static struct drm_driver driver; 41f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 425c49fd3aSAlan Cox 439083eb38SArthur Borsboom /* 449083eb38SArthur Borsboom * The table below contains a mapping of the PCI vendor ID and the PCI Device ID 459083eb38SArthur Borsboom * to the different groups of PowerVR 5-series chip designs 469083eb38SArthur Borsboom * 479083eb38SArthur Borsboom * 0x8086 = Intel Corporation 489083eb38SArthur Borsboom * 499083eb38SArthur Borsboom * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx 509083eb38SArthur Borsboom * PowerVR SGX535 - Moorestown - Intel GMA 600 519083eb38SArthur Borsboom * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx 529083eb38SArthur Borsboom * PowerVR SGX540 - Medfield - Intel Atom Z2460 539083eb38SArthur Borsboom * PowerVR SGX544MP2 - Medfield - 549083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600 559083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700, 569083eb38SArthur Borsboom * N2800 579083eb38SArthur Borsboom */ 589baa3c34SBenoit Taine static const struct pci_device_id pciidlist[] = { 595c49fd3aSAlan Cox { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 605c49fd3aSAlan Cox { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 610cecdd81SAlan Cox #if defined(CONFIG_DRM_GMA600) 625c49fd3aSAlan Cox { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 635c49fd3aSAlan Cox { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 645c49fd3aSAlan Cox { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 655c49fd3aSAlan Cox { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 665c49fd3aSAlan Cox { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 675c49fd3aSAlan Cox { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 685c49fd3aSAlan Cox { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 695c49fd3aSAlan Cox { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 7056125db1SAlan Cox { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 715c49fd3aSAlan Cox #endif 72026abc33SKirill A. Shutemov #if defined(CONFIG_DRM_MEDFIELD) 73026abc33SKirill A. Shutemov { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 74026abc33SKirill A. Shutemov { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 75026abc33SKirill A. Shutemov { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 76026abc33SKirill A. Shutemov { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 77026abc33SKirill A. Shutemov { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 78026abc33SKirill A. Shutemov { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 79026abc33SKirill A. Shutemov { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 80026abc33SKirill A. Shutemov { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 81026abc33SKirill A. Shutemov #endif 82b6195aabSAlan Cox #if defined(CONFIG_DRM_GMA3600) 835c49fd3aSAlan Cox { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 845c49fd3aSAlan Cox { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 855c49fd3aSAlan Cox { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 865c49fd3aSAlan Cox { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 875c49fd3aSAlan Cox { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 885c49fd3aSAlan Cox { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 895c49fd3aSAlan Cox { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 905c49fd3aSAlan Cox { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 919aa65a2bSAlan Cox { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 929aa65a2bSAlan Cox { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 939aa65a2bSAlan Cox { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 949aa65a2bSAlan Cox { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 959aa65a2bSAlan Cox { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 969aa65a2bSAlan Cox { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 979aa65a2bSAlan Cox { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 989aa65a2bSAlan Cox { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 995c49fd3aSAlan Cox #endif 100aa53f533SKirill A. Shutemov { 0, } 1015c49fd3aSAlan Cox }; 1025c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist); 1035c49fd3aSAlan Cox 1045c49fd3aSAlan Cox /* 1055c49fd3aSAlan Cox * Standard IOCTLs. 1065c49fd3aSAlan Cox */ 107baa70943SRob Clark static const struct drm_ioctl_desc psb_ioctls[] = { 1085c49fd3aSAlan Cox }; 1095c49fd3aSAlan Cox 110f90cd811SArthur Borsboom static void psb_driver_lastclose(struct drm_device *dev) 1115c49fd3aSAlan Cox { 1127147573aSDaniel Vetter int ret; 1137147573aSDaniel Vetter struct drm_psb_private *dev_priv = dev->dev_private; 1147147573aSDaniel Vetter struct psb_fbdev *fbdev = dev_priv->fbdev; 1157147573aSDaniel Vetter 1165ea1f752SRob Clark ret = drm_fb_helper_restore_fbdev_mode_unlocked(&fbdev->psb_fb_helper); 1177147573aSDaniel Vetter if (ret) 1187147573aSDaniel Vetter DRM_DEBUG("failed to restore crtc mode\n"); 1197147573aSDaniel Vetter 1205c49fd3aSAlan Cox return; 1215c49fd3aSAlan Cox } 1225c49fd3aSAlan Cox 1235c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev) 1245c49fd3aSAlan Cox { 1255c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1265c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1275c49fd3aSAlan Cox 1285c49fd3aSAlan Cox uint32_t stolen_gtt; 1295c49fd3aSAlan Cox 1305c49fd3aSAlan Cox if (pg->mmu_gatt_start & 0x0FFFFFFF) { 1315c49fd3aSAlan Cox dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); 132af3765c7SArthur Borsboom return -EINVAL; 1335c49fd3aSAlan Cox } 1345c49fd3aSAlan Cox 1355c49fd3aSAlan Cox stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; 1365c49fd3aSAlan Cox stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; 137f90cd811SArthur Borsboom stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; 1385c49fd3aSAlan Cox 1395c49fd3aSAlan Cox dev_priv->gatt_free_offset = pg->mmu_gatt_start + 1405c49fd3aSAlan Cox (stolen_gtt << PAGE_SHIFT) * 1024; 1415c49fd3aSAlan Cox 1425c49fd3aSAlan Cox spin_lock_init(&dev_priv->irqmask_lock); 1439242fe23SAlan Cox spin_lock_init(&dev_priv->lock_2d); 1445c49fd3aSAlan Cox 1455c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); 1465c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); 1475c49fd3aSAlan Cox PSB_RSGX32(PSB_CR_BIF_BANK1); 148ae012bdcSPatrik Jakobsson 149ae012bdcSPatrik Jakobsson /* Do not bypass any MMU access, let them pagefault instead */ 150ae012bdcSPatrik Jakobsson PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK), 1515c49fd3aSAlan Cox PSB_CR_BIF_CTRL); 152ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_CTRL); 153ae012bdcSPatrik Jakobsson 1545c49fd3aSAlan Cox psb_spank(dev_priv); 1555c49fd3aSAlan Cox 1565c49fd3aSAlan Cox /* mmu_gatt ?? */ 1575c49fd3aSAlan Cox PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); 158ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */ 159ae012bdcSPatrik Jakobsson 1605c49fd3aSAlan Cox return 0; 1615c49fd3aSAlan Cox } 1625c49fd3aSAlan Cox 16311b3c20bSGabriel Krisman Bertazi static void psb_driver_unload(struct drm_device *dev) 1645c49fd3aSAlan Cox { 1655c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1665c49fd3aSAlan Cox 1679083eb38SArthur Borsboom /* TODO: Kill vblank etc here */ 1685c49fd3aSAlan Cox 1695c49fd3aSAlan Cox if (dev_priv) { 1704ab2c7f1SAlan Cox if (dev_priv->backlight_device) 1714ab2c7f1SAlan Cox gma_backlight_exit(dev); 1724ab2c7f1SAlan Cox psb_modeset_cleanup(dev); 1735c49fd3aSAlan Cox 1745c49fd3aSAlan Cox if (dev_priv->ops->chip_teardown) 1755c49fd3aSAlan Cox dev_priv->ops->chip_teardown(dev); 1766607e024SAlan Cox 1776607e024SAlan Cox psb_intel_opregion_fini(dev); 1785c49fd3aSAlan Cox 1795c49fd3aSAlan Cox if (dev_priv->pf_pd) { 1805c49fd3aSAlan Cox psb_mmu_free_pagedir(dev_priv->pf_pd); 1815c49fd3aSAlan Cox dev_priv->pf_pd = NULL; 1825c49fd3aSAlan Cox } 1835c49fd3aSAlan Cox if (dev_priv->mmu) { 1845c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1855c49fd3aSAlan Cox 1865c49fd3aSAlan Cox down_read(&pg->sem); 1875c49fd3aSAlan Cox psb_mmu_remove_pfn_sequence( 1885c49fd3aSAlan Cox psb_mmu_get_default_pd 1895c49fd3aSAlan Cox (dev_priv->mmu), 1905c49fd3aSAlan Cox pg->mmu_gatt_start, 1915c49fd3aSAlan Cox dev_priv->vram_stolen_size >> PAGE_SHIFT); 1925c49fd3aSAlan Cox up_read(&pg->sem); 1935c49fd3aSAlan Cox psb_mmu_driver_takedown(dev_priv->mmu); 1945c49fd3aSAlan Cox dev_priv->mmu = NULL; 1955c49fd3aSAlan Cox } 1965c49fd3aSAlan Cox psb_gtt_takedown(dev); 1975c49fd3aSAlan Cox if (dev_priv->scratch_page) { 1981896344bSAlan Cox set_pages_wb(dev_priv->scratch_page, 1); 1995c49fd3aSAlan Cox __free_page(dev_priv->scratch_page); 2005c49fd3aSAlan Cox dev_priv->scratch_page = NULL; 2015c49fd3aSAlan Cox } 2025c49fd3aSAlan Cox if (dev_priv->vdc_reg) { 2035c49fd3aSAlan Cox iounmap(dev_priv->vdc_reg); 2045c49fd3aSAlan Cox dev_priv->vdc_reg = NULL; 2055c49fd3aSAlan Cox } 2065c49fd3aSAlan Cox if (dev_priv->sgx_reg) { 2075c49fd3aSAlan Cox iounmap(dev_priv->sgx_reg); 2085c49fd3aSAlan Cox dev_priv->sgx_reg = NULL; 2095c49fd3aSAlan Cox } 2102657929dSPatrik Jakobsson if (dev_priv->aux_reg) { 2112657929dSPatrik Jakobsson iounmap(dev_priv->aux_reg); 2122657929dSPatrik Jakobsson dev_priv->aux_reg = NULL; 2132657929dSPatrik Jakobsson } 2142657929dSPatrik Jakobsson pci_dev_put(dev_priv->aux_pdev); 2155a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 2165c49fd3aSAlan Cox 2174ab2c7f1SAlan Cox /* Destroy VBT data */ 2184ab2c7f1SAlan Cox psb_intel_destroy_bios(dev); 2194ab2c7f1SAlan Cox 2205c49fd3aSAlan Cox kfree(dev_priv); 2215c49fd3aSAlan Cox dev->dev_private = NULL; 2225c49fd3aSAlan Cox } 2235c49fd3aSAlan Cox gma_power_uninit(dev); 2245c49fd3aSAlan Cox } 2255c49fd3aSAlan Cox 226f90cd811SArthur Borsboom static int psb_driver_load(struct drm_device *dev, unsigned long flags) 2275c49fd3aSAlan Cox { 2285c49fd3aSAlan Cox struct drm_psb_private *dev_priv; 2292657929dSPatrik Jakobsson unsigned long resource_start, resource_len; 2305c49fd3aSAlan Cox unsigned long irqflags; 2315c49fd3aSAlan Cox int ret = -ENOMEM; 2325c49fd3aSAlan Cox struct drm_connector *connector; 233367e4408SPatrik Jakobsson struct gma_encoder *gma_encoder; 234ae012bdcSPatrik Jakobsson struct psb_gtt *pg; 2355c49fd3aSAlan Cox 2369083eb38SArthur Borsboom /* allocating and initializing driver private data */ 2375c49fd3aSAlan Cox dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 2385c49fd3aSAlan Cox if (dev_priv == NULL) 2395c49fd3aSAlan Cox return -ENOMEM; 2405c49fd3aSAlan Cox 241f90cd811SArthur Borsboom dev_priv->ops = (struct psb_ops *)flags; 2425c49fd3aSAlan Cox dev_priv->dev = dev; 2435c49fd3aSAlan Cox dev->dev_private = (void *) dev_priv; 2445c49fd3aSAlan Cox 245ae012bdcSPatrik Jakobsson pg = &dev_priv->gtt; 246ae012bdcSPatrik Jakobsson 247466e69b8SDave Airlie pci_set_master(dev->pdev); 248466e69b8SDave Airlie 2495c49fd3aSAlan Cox dev_priv->num_pipe = dev_priv->ops->pipes; 2505c49fd3aSAlan Cox 2515c49fd3aSAlan Cox resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); 2525c49fd3aSAlan Cox 2535c49fd3aSAlan Cox dev_priv->vdc_reg = 2545c49fd3aSAlan Cox ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); 2555c49fd3aSAlan Cox if (!dev_priv->vdc_reg) 2565c49fd3aSAlan Cox goto out_err; 2575c49fd3aSAlan Cox 2585c49fd3aSAlan Cox dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, 2595c49fd3aSAlan Cox PSB_SGX_SIZE); 2605c49fd3aSAlan Cox if (!dev_priv->sgx_reg) 2615c49fd3aSAlan Cox goto out_err; 2625c49fd3aSAlan Cox 2632657929dSPatrik Jakobsson if (IS_MRST(dev)) { 2642657929dSPatrik Jakobsson dev_priv->aux_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(3, 0)); 2652657929dSPatrik Jakobsson 2662657929dSPatrik Jakobsson if (dev_priv->aux_pdev) { 2672657929dSPatrik Jakobsson resource_start = pci_resource_start(dev_priv->aux_pdev, 2682657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2692657929dSPatrik Jakobsson resource_len = pci_resource_len(dev_priv->aux_pdev, 2702657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2712657929dSPatrik Jakobsson dev_priv->aux_reg = ioremap_nocache(resource_start, 2722657929dSPatrik Jakobsson resource_len); 2732657929dSPatrik Jakobsson if (!dev_priv->aux_reg) 2742657929dSPatrik Jakobsson goto out_err; 2752657929dSPatrik Jakobsson 2762657929dSPatrik Jakobsson DRM_DEBUG_KMS("Found aux vdc"); 2772657929dSPatrik Jakobsson } else { 2782657929dSPatrik Jakobsson /* Couldn't find the aux vdc so map to primary vdc */ 2792657929dSPatrik Jakobsson dev_priv->aux_reg = dev_priv->vdc_reg; 2802657929dSPatrik Jakobsson DRM_DEBUG_KMS("Couldn't find aux pci device"); 2812657929dSPatrik Jakobsson } 2822657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->aux_reg; 2835a52b1f2SJan Safrata 2845a52b1f2SJan Safrata dev_priv->lpc_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(31, 0)); 2855a52b1f2SJan Safrata if (dev_priv->lpc_pdev) { 2865a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2875a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2885a52b1f2SJan Safrata pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA, 2895a52b1f2SJan Safrata (u32)dev_priv->lpc_gpio_base | (1L<<31)); 2905a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2915a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2925a52b1f2SJan Safrata dev_priv->lpc_gpio_base &= 0xffc0; 2935a52b1f2SJan Safrata if (dev_priv->lpc_gpio_base) 2945a52b1f2SJan Safrata DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n", 2955a52b1f2SJan Safrata dev_priv->lpc_gpio_base); 2965a52b1f2SJan Safrata else { 2975a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 2985a52b1f2SJan Safrata dev_priv->lpc_pdev = NULL; 2995a52b1f2SJan Safrata } 3005a52b1f2SJan Safrata } 3012657929dSPatrik Jakobsson } else { 3022657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->vdc_reg; 3032657929dSPatrik Jakobsson } 3042657929dSPatrik Jakobsson 305d839ede4SAlan Cox psb_intel_opregion_setup(dev); 306d839ede4SAlan Cox 3075c49fd3aSAlan Cox ret = dev_priv->ops->chip_setup(dev); 3085c49fd3aSAlan Cox if (ret) 3095c49fd3aSAlan Cox goto out_err; 3105c49fd3aSAlan Cox 3115c49fd3aSAlan Cox /* Init OSPM support */ 3125c49fd3aSAlan Cox gma_power_init(dev); 3135c49fd3aSAlan Cox 3145c49fd3aSAlan Cox ret = -ENOMEM; 3155c49fd3aSAlan Cox 3165c49fd3aSAlan Cox dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); 3175c49fd3aSAlan Cox if (!dev_priv->scratch_page) 3185c49fd3aSAlan Cox goto out_err; 3195c49fd3aSAlan Cox 3205c49fd3aSAlan Cox set_pages_uc(dev_priv->scratch_page, 1); 3215c49fd3aSAlan Cox 3225c49fd3aSAlan Cox ret = psb_gtt_init(dev, 0); 3235c49fd3aSAlan Cox if (ret) 3245c49fd3aSAlan Cox goto out_err; 3255c49fd3aSAlan Cox 3268f394872SPatrik Jakobsson dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0); 3275c49fd3aSAlan Cox if (!dev_priv->mmu) 3285c49fd3aSAlan Cox goto out_err; 3295c49fd3aSAlan Cox 3305c49fd3aSAlan Cox dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); 3315c49fd3aSAlan Cox if (!dev_priv->pf_pd) 3325c49fd3aSAlan Cox goto out_err; 3335c49fd3aSAlan Cox 3345c49fd3aSAlan Cox ret = psb_do_init(dev); 3355c49fd3aSAlan Cox if (ret) 3365c49fd3aSAlan Cox return ret; 3375c49fd3aSAlan Cox 338ae012bdcSPatrik Jakobsson /* Add stolen memory to SGX MMU */ 339ae012bdcSPatrik Jakobsson down_read(&pg->sem); 340ae012bdcSPatrik Jakobsson ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu), 341ae012bdcSPatrik Jakobsson dev_priv->stolen_base >> PAGE_SHIFT, 342ae012bdcSPatrik Jakobsson pg->gatt_start, 343ae012bdcSPatrik Jakobsson pg->stolen_size >> PAGE_SHIFT, 0); 344ae012bdcSPatrik Jakobsson up_read(&pg->sem); 345ae012bdcSPatrik Jakobsson 346ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); 347ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(dev_priv->pf_pd, 1); 348ae012bdcSPatrik Jakobsson 3495c49fd3aSAlan Cox PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); 3505c49fd3aSAlan Cox PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); 3515c49fd3aSAlan Cox 352d839ede4SAlan Cox acpi_video_register(); 3535c49fd3aSAlan Cox 3549083eb38SArthur Borsboom /* Setup vertical blanking handling */ 3555c49fd3aSAlan Cox ret = drm_vblank_init(dev, dev_priv->num_pipe); 3565c49fd3aSAlan Cox if (ret) 3575c49fd3aSAlan Cox goto out_err; 3585c49fd3aSAlan Cox 3595c49fd3aSAlan Cox /* 3605c49fd3aSAlan Cox * Install interrupt handlers prior to powering off SGX or else we will 3615c49fd3aSAlan Cox * crash. 3625c49fd3aSAlan Cox */ 3635c49fd3aSAlan Cox dev_priv->vdc_irq_mask = 0; 3645c49fd3aSAlan Cox dev_priv->pipestat[0] = 0; 3655c49fd3aSAlan Cox dev_priv->pipestat[1] = 0; 3665c49fd3aSAlan Cox dev_priv->pipestat[2] = 0; 3675c49fd3aSAlan Cox spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 3685c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 3695c49fd3aSAlan Cox PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); 3705c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); 3715c49fd3aSAlan Cox spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); 37262363a48SAlan Cox 373bb0f1b5cSDaniel Vetter drm_irq_install(dev, dev->pdev->irq); 3745c49fd3aSAlan Cox 3755c49fd3aSAlan Cox dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3765c49fd3aSAlan Cox dev->driver->get_vblank_counter = psb_get_vblank_counter; 3775c49fd3aSAlan Cox 3785c49fd3aSAlan Cox psb_modeset_init(dev); 3795c49fd3aSAlan Cox psb_fbdev_init(dev); 3805c49fd3aSAlan Cox drm_kms_helper_poll_init(dev); 3815c49fd3aSAlan Cox 3825c49fd3aSAlan Cox /* Only add backlight support if we have LVDS output */ 3835c49fd3aSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 3845c49fd3aSAlan Cox head) { 385367e4408SPatrik Jakobsson gma_encoder = gma_attached_encoder(connector); 3865c49fd3aSAlan Cox 387367e4408SPatrik Jakobsson switch (gma_encoder->type) { 3885c49fd3aSAlan Cox case INTEL_OUTPUT_LVDS: 3895c49fd3aSAlan Cox case INTEL_OUTPUT_MIPI: 3905c49fd3aSAlan Cox ret = gma_backlight_init(dev); 3915c49fd3aSAlan Cox break; 3925c49fd3aSAlan Cox } 3935c49fd3aSAlan Cox } 3945c49fd3aSAlan Cox 3955c49fd3aSAlan Cox if (ret) 3965c49fd3aSAlan Cox return ret; 397166973e5SAlan Cox psb_intel_opregion_enable_asle(dev); 3985c49fd3aSAlan Cox #if 0 3999083eb38SArthur Borsboom /* Enable runtime pm at last */ 4005c49fd3aSAlan Cox pm_runtime_enable(&dev->pdev->dev); 4015c49fd3aSAlan Cox pm_runtime_set_active(&dev->pdev->dev); 4025c49fd3aSAlan Cox #endif 4035c49fd3aSAlan Cox /* Intel drm driver load is done, continue doing pvr load */ 4045c49fd3aSAlan Cox return 0; 4055c49fd3aSAlan Cox out_err: 4065c49fd3aSAlan Cox psb_driver_unload(dev); 4075c49fd3aSAlan Cox return ret; 4085c49fd3aSAlan Cox } 4095c49fd3aSAlan Cox 4105c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd) 4115c49fd3aSAlan Cox { 4125c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE 4135c49fd3aSAlan Cox if (bd) { 4145c49fd3aSAlan Cox bd->props.brightness = bd->ops->get_brightness(bd); 4155c49fd3aSAlan Cox backlight_update_status(bd); 4165c49fd3aSAlan Cox } 4175c49fd3aSAlan Cox #endif 4185c49fd3aSAlan Cox } 4195c49fd3aSAlan Cox 4205c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, 4215c49fd3aSAlan Cox unsigned long arg) 4225c49fd3aSAlan Cox { 4235c49fd3aSAlan Cox struct drm_file *file_priv = filp->private_data; 4245c49fd3aSAlan Cox struct drm_device *dev = file_priv->minor->dev; 4255c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 4265c49fd3aSAlan Cox static unsigned int runtime_allowed; 4275c49fd3aSAlan Cox 4285c49fd3aSAlan Cox if (runtime_allowed == 1 && dev_priv->is_lvds_on) { 4295c49fd3aSAlan Cox runtime_allowed++; 4305c49fd3aSAlan Cox pm_runtime_allow(&dev->pdev->dev); 4315c49fd3aSAlan Cox dev_priv->rpm_enabled = 1; 4325c49fd3aSAlan Cox } 4335c49fd3aSAlan Cox return drm_ioctl(filp, cmd, arg); 4345c49fd3aSAlan Cox /* FIXME: do we need to wrap the other side of this */ 4355c49fd3aSAlan Cox } 4365c49fd3aSAlan Cox 437f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 438f90cd811SArthur Borsboom { 439f90cd811SArthur Borsboom return drm_get_pci_dev(pdev, ent, &driver); 440f90cd811SArthur Borsboom } 441f90cd811SArthur Borsboom 442f90cd811SArthur Borsboom 443f90cd811SArthur Borsboom static void psb_pci_remove(struct pci_dev *pdev) 4445c49fd3aSAlan Cox { 4455c49fd3aSAlan Cox struct drm_device *dev = pci_get_drvdata(pdev); 4465c49fd3aSAlan Cox drm_put_dev(dev); 4475c49fd3aSAlan Cox } 4485c49fd3aSAlan Cox 4495c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = { 4505c49fd3aSAlan Cox .resume = gma_power_resume, 4515c49fd3aSAlan Cox .suspend = gma_power_suspend, 452888eef2eSPatrik Jakobsson .thaw = gma_power_thaw, 453888eef2eSPatrik Jakobsson .freeze = gma_power_freeze, 454888eef2eSPatrik Jakobsson .restore = gma_power_restore, 4555c49fd3aSAlan Cox .runtime_suspend = psb_runtime_suspend, 4565c49fd3aSAlan Cox .runtime_resume = psb_runtime_resume, 4575c49fd3aSAlan Cox .runtime_idle = psb_runtime_idle, 4585c49fd3aSAlan Cox }; 4595c49fd3aSAlan Cox 46078b68556SLaurent Pinchart static const struct vm_operations_struct psb_gem_vm_ops = { 4615c49fd3aSAlan Cox .fault = psb_gem_fault, 4625c49fd3aSAlan Cox .open = drm_gem_vm_open, 4635c49fd3aSAlan Cox .close = drm_gem_vm_close, 4645c49fd3aSAlan Cox }; 4655c49fd3aSAlan Cox 4661595c568SIlija Hadzic static const struct file_operations psb_gem_fops = { 4671595c568SIlija Hadzic .owner = THIS_MODULE, 4681595c568SIlija Hadzic .open = drm_open, 4691595c568SIlija Hadzic .release = drm_release, 4701595c568SIlija Hadzic .unlocked_ioctl = psb_unlocked_ioctl, 4710a97c81aSPatrik Jakobsson .compat_ioctl = drm_compat_ioctl, 4721595c568SIlija Hadzic .mmap = drm_gem_mmap, 4731595c568SIlija Hadzic .poll = drm_poll, 4741595c568SIlija Hadzic .read = drm_read, 4751595c568SIlija Hadzic }; 4761595c568SIlija Hadzic 4775c49fd3aSAlan Cox static struct drm_driver driver = { 4785c49fd3aSAlan Cox .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ 47974867e3dSDaniel Vetter DRIVER_MODESET | DRIVER_GEM, 4805c49fd3aSAlan Cox .load = psb_driver_load, 4815c49fd3aSAlan Cox .unload = psb_driver_unload, 482f90cd811SArthur Borsboom .lastclose = psb_driver_lastclose, 4835c49fd3aSAlan Cox 484f95aeb17SDamien Lespiau .num_ioctls = ARRAY_SIZE(psb_ioctls), 4855c49fd3aSAlan Cox .irq_preinstall = psb_irq_preinstall, 4865c49fd3aSAlan Cox .irq_postinstall = psb_irq_postinstall, 4875c49fd3aSAlan Cox .irq_uninstall = psb_irq_uninstall, 4885c49fd3aSAlan Cox .irq_handler = psb_irq_handler, 4895c49fd3aSAlan Cox .enable_vblank = psb_enable_vblank, 4905c49fd3aSAlan Cox .disable_vblank = psb_disable_vblank, 4915c49fd3aSAlan Cox .get_vblank_counter = psb_get_vblank_counter, 4925c49fd3aSAlan Cox 4935c49fd3aSAlan Cox .gem_free_object = psb_gem_free_object, 4945c49fd3aSAlan Cox .gem_vm_ops = &psb_gem_vm_ops, 495f90cd811SArthur Borsboom 4965c49fd3aSAlan Cox .dumb_create = psb_gem_dumb_create, 4975c49fd3aSAlan Cox .dumb_map_offset = psb_gem_dumb_map_gtt, 49843387b37SDaniel Vetter .dumb_destroy = drm_gem_dumb_destroy, 499f90cd811SArthur Borsboom .ioctls = psb_ioctls, 5001595c568SIlija Hadzic .fops = &psb_gem_fops, 5015c49fd3aSAlan Cox .name = DRIVER_NAME, 5025c49fd3aSAlan Cox .desc = DRIVER_DESC, 503f90cd811SArthur Borsboom .date = DRIVER_DATE, 504f90cd811SArthur Borsboom .major = DRIVER_MAJOR, 505f90cd811SArthur Borsboom .minor = DRIVER_MINOR, 506f90cd811SArthur Borsboom .patchlevel = DRIVER_PATCHLEVEL 5075c49fd3aSAlan Cox }; 5085c49fd3aSAlan Cox 5095c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = { 5105c49fd3aSAlan Cox .name = DRIVER_NAME, 5115c49fd3aSAlan Cox .id_table = pciidlist, 512f90cd811SArthur Borsboom .probe = psb_pci_probe, 513f90cd811SArthur Borsboom .remove = psb_pci_remove, 514f90cd811SArthur Borsboom .driver.pm = &psb_pm_ops, 5155c49fd3aSAlan Cox }; 5165c49fd3aSAlan Cox 5175c49fd3aSAlan Cox static int __init psb_init(void) 5185c49fd3aSAlan Cox { 519*10631d72SDaniel Vetter return pci_register_driver(&psb_pci_driver); 5205c49fd3aSAlan Cox } 5215c49fd3aSAlan Cox 5225c49fd3aSAlan Cox static void __exit psb_exit(void) 5235c49fd3aSAlan Cox { 524*10631d72SDaniel Vetter pci_unregister_driver(&psb_pci_driver); 5255c49fd3aSAlan Cox } 5265c49fd3aSAlan Cox 5275c49fd3aSAlan Cox late_initcall(psb_init); 5285c49fd3aSAlan Cox module_exit(psb_exit); 5295c49fd3aSAlan Cox 530f90cd811SArthur Borsboom MODULE_AUTHOR(DRIVER_AUTHOR); 5315c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC); 532f90cd811SArthur Borsboom MODULE_LICENSE(DRIVER_LICENSE); 533