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 22*0c7b178aSSam Ravnborg #include <linux/cpu.h> 23*0c7b178aSSam Ravnborg #include <linux/module.h> 24*0c7b178aSSam Ravnborg #include <linux/notifier.h> 25*0c7b178aSSam Ravnborg #include <linux/pm_runtime.h> 26*0c7b178aSSam Ravnborg #include <linux/spinlock.h> 27*0c7b178aSSam Ravnborg 28*0c7b178aSSam Ravnborg #include <asm/set_memory.h> 29*0c7b178aSSam Ravnborg 30*0c7b178aSSam Ravnborg #include <acpi/video.h> 31*0c7b178aSSam Ravnborg 325c49fd3aSAlan Cox #include <drm/drm.h> 33*0c7b178aSSam Ravnborg #include <drm/drm_drv.h> 34*0c7b178aSSam Ravnborg #include <drm/drm_file.h> 35*0c7b178aSSam Ravnborg #include <drm/drm_ioctl.h> 36*0c7b178aSSam Ravnborg #include <drm/drm_irq.h> 37*0c7b178aSSam Ravnborg #include <drm/drm_pci.h> 38*0c7b178aSSam Ravnborg #include <drm/drm_pciids.h> 39*0c7b178aSSam Ravnborg #include <drm/drm_vblank.h> 40*0c7b178aSSam Ravnborg 415c49fd3aSAlan Cox #include "framebuffer.h" 425c49fd3aSAlan Cox #include "intel_bios.h" 435c49fd3aSAlan Cox #include "mid_bios.h" 445c49fd3aSAlan Cox #include "power.h" 45*0c7b178aSSam Ravnborg #include "psb_drv.h" 46*0c7b178aSSam Ravnborg #include "psb_intel_reg.h" 47*0c7b178aSSam Ravnborg #include "psb_reg.h" 485c49fd3aSAlan Cox 49f90cd811SArthur Borsboom static struct drm_driver driver; 50f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 515c49fd3aSAlan Cox 529083eb38SArthur Borsboom /* 539083eb38SArthur Borsboom * The table below contains a mapping of the PCI vendor ID and the PCI Device ID 549083eb38SArthur Borsboom * to the different groups of PowerVR 5-series chip designs 559083eb38SArthur Borsboom * 569083eb38SArthur Borsboom * 0x8086 = Intel Corporation 579083eb38SArthur Borsboom * 589083eb38SArthur Borsboom * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx 599083eb38SArthur Borsboom * PowerVR SGX535 - Moorestown - Intel GMA 600 609083eb38SArthur Borsboom * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx 619083eb38SArthur Borsboom * PowerVR SGX540 - Medfield - Intel Atom Z2460 629083eb38SArthur Borsboom * PowerVR SGX544MP2 - Medfield - 639083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600 649083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700, 659083eb38SArthur Borsboom * N2800 669083eb38SArthur Borsboom */ 679baa3c34SBenoit Taine static const struct pci_device_id pciidlist[] = { 685c49fd3aSAlan Cox { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 695c49fd3aSAlan Cox { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 700cecdd81SAlan Cox #if defined(CONFIG_DRM_GMA600) 715c49fd3aSAlan Cox { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 725c49fd3aSAlan Cox { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 735c49fd3aSAlan Cox { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 745c49fd3aSAlan Cox { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 755c49fd3aSAlan Cox { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 765c49fd3aSAlan Cox { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 775c49fd3aSAlan Cox { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 785c49fd3aSAlan Cox { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 7956125db1SAlan Cox { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 805c49fd3aSAlan Cox #endif 81026abc33SKirill A. Shutemov #if defined(CONFIG_DRM_MEDFIELD) 82026abc33SKirill A. Shutemov { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 83026abc33SKirill A. Shutemov { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 84026abc33SKirill A. Shutemov { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 85026abc33SKirill A. Shutemov { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 86026abc33SKirill A. Shutemov { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 87026abc33SKirill A. Shutemov { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 88026abc33SKirill A. Shutemov { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 89026abc33SKirill A. Shutemov { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 90026abc33SKirill A. Shutemov #endif 91b6195aabSAlan Cox #if defined(CONFIG_DRM_GMA3600) 925c49fd3aSAlan Cox { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 935c49fd3aSAlan Cox { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 945c49fd3aSAlan Cox { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 955c49fd3aSAlan Cox { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 965c49fd3aSAlan Cox { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 975c49fd3aSAlan Cox { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 985c49fd3aSAlan Cox { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 995c49fd3aSAlan Cox { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1009aa65a2bSAlan Cox { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1019aa65a2bSAlan Cox { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1029aa65a2bSAlan Cox { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1039aa65a2bSAlan Cox { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1049aa65a2bSAlan Cox { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1059aa65a2bSAlan Cox { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1069aa65a2bSAlan Cox { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1079aa65a2bSAlan Cox { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 1085c49fd3aSAlan Cox #endif 109aa53f533SKirill A. Shutemov { 0, } 1105c49fd3aSAlan Cox }; 1115c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist); 1125c49fd3aSAlan Cox 1135c49fd3aSAlan Cox /* 1145c49fd3aSAlan Cox * Standard IOCTLs. 1155c49fd3aSAlan Cox */ 116baa70943SRob Clark static const struct drm_ioctl_desc psb_ioctls[] = { 1175c49fd3aSAlan Cox }; 1185c49fd3aSAlan Cox 1195c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev) 1205c49fd3aSAlan Cox { 1215c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1225c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1235c49fd3aSAlan Cox 1245c49fd3aSAlan Cox uint32_t stolen_gtt; 1255c49fd3aSAlan Cox 1265c49fd3aSAlan Cox if (pg->mmu_gatt_start & 0x0FFFFFFF) { 1275c49fd3aSAlan Cox dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); 128af3765c7SArthur Borsboom return -EINVAL; 1295c49fd3aSAlan Cox } 1305c49fd3aSAlan Cox 1315c49fd3aSAlan Cox stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; 1325c49fd3aSAlan Cox stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; 133f90cd811SArthur Borsboom stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; 1345c49fd3aSAlan Cox 1355c49fd3aSAlan Cox dev_priv->gatt_free_offset = pg->mmu_gatt_start + 1365c49fd3aSAlan Cox (stolen_gtt << PAGE_SHIFT) * 1024; 1375c49fd3aSAlan Cox 1385c49fd3aSAlan Cox spin_lock_init(&dev_priv->irqmask_lock); 1399242fe23SAlan Cox spin_lock_init(&dev_priv->lock_2d); 1405c49fd3aSAlan Cox 1415c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); 1425c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); 1435c49fd3aSAlan Cox PSB_RSGX32(PSB_CR_BIF_BANK1); 144ae012bdcSPatrik Jakobsson 145ae012bdcSPatrik Jakobsson /* Do not bypass any MMU access, let them pagefault instead */ 146ae012bdcSPatrik Jakobsson PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK), 1475c49fd3aSAlan Cox PSB_CR_BIF_CTRL); 148ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_CTRL); 149ae012bdcSPatrik Jakobsson 1505c49fd3aSAlan Cox psb_spank(dev_priv); 1515c49fd3aSAlan Cox 1525c49fd3aSAlan Cox /* mmu_gatt ?? */ 1535c49fd3aSAlan Cox PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); 154ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */ 155ae012bdcSPatrik Jakobsson 1565c49fd3aSAlan Cox return 0; 1575c49fd3aSAlan Cox } 1585c49fd3aSAlan Cox 15911b3c20bSGabriel Krisman Bertazi static void psb_driver_unload(struct drm_device *dev) 1605c49fd3aSAlan Cox { 1615c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1625c49fd3aSAlan Cox 1639083eb38SArthur Borsboom /* TODO: Kill vblank etc here */ 1645c49fd3aSAlan Cox 1655c49fd3aSAlan Cox if (dev_priv) { 1664ab2c7f1SAlan Cox if (dev_priv->backlight_device) 1674ab2c7f1SAlan Cox gma_backlight_exit(dev); 1684ab2c7f1SAlan Cox psb_modeset_cleanup(dev); 1695c49fd3aSAlan Cox 1705c49fd3aSAlan Cox if (dev_priv->ops->chip_teardown) 1715c49fd3aSAlan Cox dev_priv->ops->chip_teardown(dev); 1726607e024SAlan Cox 1736607e024SAlan Cox psb_intel_opregion_fini(dev); 1745c49fd3aSAlan Cox 1755c49fd3aSAlan Cox if (dev_priv->pf_pd) { 1765c49fd3aSAlan Cox psb_mmu_free_pagedir(dev_priv->pf_pd); 1775c49fd3aSAlan Cox dev_priv->pf_pd = NULL; 1785c49fd3aSAlan Cox } 1795c49fd3aSAlan Cox if (dev_priv->mmu) { 1805c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1815c49fd3aSAlan Cox 1825c49fd3aSAlan Cox down_read(&pg->sem); 1835c49fd3aSAlan Cox psb_mmu_remove_pfn_sequence( 1845c49fd3aSAlan Cox psb_mmu_get_default_pd 1855c49fd3aSAlan Cox (dev_priv->mmu), 1865c49fd3aSAlan Cox pg->mmu_gatt_start, 1875c49fd3aSAlan Cox dev_priv->vram_stolen_size >> PAGE_SHIFT); 1885c49fd3aSAlan Cox up_read(&pg->sem); 1895c49fd3aSAlan Cox psb_mmu_driver_takedown(dev_priv->mmu); 1905c49fd3aSAlan Cox dev_priv->mmu = NULL; 1915c49fd3aSAlan Cox } 1925c49fd3aSAlan Cox psb_gtt_takedown(dev); 1935c49fd3aSAlan Cox if (dev_priv->scratch_page) { 1941896344bSAlan Cox set_pages_wb(dev_priv->scratch_page, 1); 1955c49fd3aSAlan Cox __free_page(dev_priv->scratch_page); 1965c49fd3aSAlan Cox dev_priv->scratch_page = NULL; 1975c49fd3aSAlan Cox } 1985c49fd3aSAlan Cox if (dev_priv->vdc_reg) { 1995c49fd3aSAlan Cox iounmap(dev_priv->vdc_reg); 2005c49fd3aSAlan Cox dev_priv->vdc_reg = NULL; 2015c49fd3aSAlan Cox } 2025c49fd3aSAlan Cox if (dev_priv->sgx_reg) { 2035c49fd3aSAlan Cox iounmap(dev_priv->sgx_reg); 2045c49fd3aSAlan Cox dev_priv->sgx_reg = NULL; 2055c49fd3aSAlan Cox } 2062657929dSPatrik Jakobsson if (dev_priv->aux_reg) { 2072657929dSPatrik Jakobsson iounmap(dev_priv->aux_reg); 2082657929dSPatrik Jakobsson dev_priv->aux_reg = NULL; 2092657929dSPatrik Jakobsson } 2102657929dSPatrik Jakobsson pci_dev_put(dev_priv->aux_pdev); 2115a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 2125c49fd3aSAlan Cox 2134ab2c7f1SAlan Cox /* Destroy VBT data */ 2144ab2c7f1SAlan Cox psb_intel_destroy_bios(dev); 2154ab2c7f1SAlan Cox 2165c49fd3aSAlan Cox kfree(dev_priv); 2175c49fd3aSAlan Cox dev->dev_private = NULL; 2185c49fd3aSAlan Cox } 2195c49fd3aSAlan Cox gma_power_uninit(dev); 2205c49fd3aSAlan Cox } 2215c49fd3aSAlan Cox 222f90cd811SArthur Borsboom static int psb_driver_load(struct drm_device *dev, unsigned long flags) 2235c49fd3aSAlan Cox { 2245c49fd3aSAlan Cox struct drm_psb_private *dev_priv; 2252657929dSPatrik Jakobsson unsigned long resource_start, resource_len; 2265c49fd3aSAlan Cox unsigned long irqflags; 2275c49fd3aSAlan Cox int ret = -ENOMEM; 2285c49fd3aSAlan Cox struct drm_connector *connector; 229367e4408SPatrik Jakobsson struct gma_encoder *gma_encoder; 230ae012bdcSPatrik Jakobsson struct psb_gtt *pg; 2315c49fd3aSAlan Cox 2329083eb38SArthur Borsboom /* allocating and initializing driver private data */ 2335c49fd3aSAlan Cox dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 2345c49fd3aSAlan Cox if (dev_priv == NULL) 2355c49fd3aSAlan Cox return -ENOMEM; 2365c49fd3aSAlan Cox 237f90cd811SArthur Borsboom dev_priv->ops = (struct psb_ops *)flags; 2385c49fd3aSAlan Cox dev_priv->dev = dev; 2395c49fd3aSAlan Cox dev->dev_private = (void *) dev_priv; 2405c49fd3aSAlan Cox 241ae012bdcSPatrik Jakobsson pg = &dev_priv->gtt; 242ae012bdcSPatrik Jakobsson 243466e69b8SDave Airlie pci_set_master(dev->pdev); 244466e69b8SDave Airlie 2455c49fd3aSAlan Cox dev_priv->num_pipe = dev_priv->ops->pipes; 2465c49fd3aSAlan Cox 2475c49fd3aSAlan Cox resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); 2485c49fd3aSAlan Cox 2495c49fd3aSAlan Cox dev_priv->vdc_reg = 2505c49fd3aSAlan Cox ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); 2515c49fd3aSAlan Cox if (!dev_priv->vdc_reg) 2525c49fd3aSAlan Cox goto out_err; 2535c49fd3aSAlan Cox 2545c49fd3aSAlan Cox dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, 2555c49fd3aSAlan Cox PSB_SGX_SIZE); 2565c49fd3aSAlan Cox if (!dev_priv->sgx_reg) 2575c49fd3aSAlan Cox goto out_err; 2585c49fd3aSAlan Cox 2592657929dSPatrik Jakobsson if (IS_MRST(dev)) { 260ba99d834SSinan Kaya int domain = pci_domain_nr(dev->pdev->bus); 261ba99d834SSinan Kaya 262ba99d834SSinan Kaya dev_priv->aux_pdev = 263ba99d834SSinan Kaya pci_get_domain_bus_and_slot(domain, 0, 264ba99d834SSinan Kaya 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 284ba99d834SSinan Kaya dev_priv->lpc_pdev = 285ba99d834SSinan Kaya pci_get_domain_bus_and_slot(domain, 0, 286ba99d834SSinan Kaya PCI_DEVFN(31, 0)); 2875a52b1f2SJan Safrata if (dev_priv->lpc_pdev) { 2885a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2895a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2905a52b1f2SJan Safrata pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA, 2915a52b1f2SJan Safrata (u32)dev_priv->lpc_gpio_base | (1L<<31)); 2925a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2935a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2945a52b1f2SJan Safrata dev_priv->lpc_gpio_base &= 0xffc0; 2955a52b1f2SJan Safrata if (dev_priv->lpc_gpio_base) 2965a52b1f2SJan Safrata DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n", 2975a52b1f2SJan Safrata dev_priv->lpc_gpio_base); 2985a52b1f2SJan Safrata else { 2995a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 3005a52b1f2SJan Safrata dev_priv->lpc_pdev = NULL; 3015a52b1f2SJan Safrata } 3025a52b1f2SJan Safrata } 3032657929dSPatrik Jakobsson } else { 3042657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->vdc_reg; 3052657929dSPatrik Jakobsson } 3062657929dSPatrik Jakobsson 307d839ede4SAlan Cox psb_intel_opregion_setup(dev); 308d839ede4SAlan Cox 3095c49fd3aSAlan Cox ret = dev_priv->ops->chip_setup(dev); 3105c49fd3aSAlan Cox if (ret) 3115c49fd3aSAlan Cox goto out_err; 3125c49fd3aSAlan Cox 3135c49fd3aSAlan Cox /* Init OSPM support */ 3145c49fd3aSAlan Cox gma_power_init(dev); 3155c49fd3aSAlan Cox 3165c49fd3aSAlan Cox ret = -ENOMEM; 3175c49fd3aSAlan Cox 3185c49fd3aSAlan Cox dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); 3195c49fd3aSAlan Cox if (!dev_priv->scratch_page) 3205c49fd3aSAlan Cox goto out_err; 3215c49fd3aSAlan Cox 3225c49fd3aSAlan Cox set_pages_uc(dev_priv->scratch_page, 1); 3235c49fd3aSAlan Cox 3245c49fd3aSAlan Cox ret = psb_gtt_init(dev, 0); 3255c49fd3aSAlan Cox if (ret) 3265c49fd3aSAlan Cox goto out_err; 3275c49fd3aSAlan Cox 3288f394872SPatrik Jakobsson dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0); 3295c49fd3aSAlan Cox if (!dev_priv->mmu) 3305c49fd3aSAlan Cox goto out_err; 3315c49fd3aSAlan Cox 3325c49fd3aSAlan Cox dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); 3335c49fd3aSAlan Cox if (!dev_priv->pf_pd) 3345c49fd3aSAlan Cox goto out_err; 3355c49fd3aSAlan Cox 3365c49fd3aSAlan Cox ret = psb_do_init(dev); 3375c49fd3aSAlan Cox if (ret) 3385c49fd3aSAlan Cox return ret; 3395c49fd3aSAlan Cox 340ae012bdcSPatrik Jakobsson /* Add stolen memory to SGX MMU */ 341ae012bdcSPatrik Jakobsson down_read(&pg->sem); 342ae012bdcSPatrik Jakobsson ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu), 343ae012bdcSPatrik Jakobsson dev_priv->stolen_base >> PAGE_SHIFT, 344ae012bdcSPatrik Jakobsson pg->gatt_start, 345ae012bdcSPatrik Jakobsson pg->stolen_size >> PAGE_SHIFT, 0); 346ae012bdcSPatrik Jakobsson up_read(&pg->sem); 347ae012bdcSPatrik Jakobsson 348ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); 349ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(dev_priv->pf_pd, 1); 350ae012bdcSPatrik Jakobsson 3515c49fd3aSAlan Cox PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); 3525c49fd3aSAlan Cox PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); 3535c49fd3aSAlan Cox 354d839ede4SAlan Cox acpi_video_register(); 3555c49fd3aSAlan Cox 3569083eb38SArthur Borsboom /* Setup vertical blanking handling */ 3575c49fd3aSAlan Cox ret = drm_vblank_init(dev, dev_priv->num_pipe); 3585c49fd3aSAlan Cox if (ret) 3595c49fd3aSAlan Cox goto out_err; 3605c49fd3aSAlan Cox 3615c49fd3aSAlan Cox /* 3625c49fd3aSAlan Cox * Install interrupt handlers prior to powering off SGX or else we will 3635c49fd3aSAlan Cox * crash. 3645c49fd3aSAlan Cox */ 3655c49fd3aSAlan Cox dev_priv->vdc_irq_mask = 0; 3665c49fd3aSAlan Cox dev_priv->pipestat[0] = 0; 3675c49fd3aSAlan Cox dev_priv->pipestat[1] = 0; 3685c49fd3aSAlan Cox dev_priv->pipestat[2] = 0; 3695c49fd3aSAlan Cox spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 3705c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 3715c49fd3aSAlan Cox PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); 3725c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); 3735c49fd3aSAlan Cox spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); 37462363a48SAlan Cox 375bb0f1b5cSDaniel Vetter drm_irq_install(dev, dev->pdev->irq); 3765c49fd3aSAlan Cox 3775c49fd3aSAlan Cox dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3785c49fd3aSAlan Cox dev->driver->get_vblank_counter = psb_get_vblank_counter; 3795c49fd3aSAlan Cox 3805c49fd3aSAlan Cox psb_modeset_init(dev); 3815c49fd3aSAlan Cox psb_fbdev_init(dev); 3825c49fd3aSAlan Cox drm_kms_helper_poll_init(dev); 3835c49fd3aSAlan Cox 3845c49fd3aSAlan Cox /* Only add backlight support if we have LVDS output */ 3855c49fd3aSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 3865c49fd3aSAlan Cox head) { 387367e4408SPatrik Jakobsson gma_encoder = gma_attached_encoder(connector); 3885c49fd3aSAlan Cox 389367e4408SPatrik Jakobsson switch (gma_encoder->type) { 3905c49fd3aSAlan Cox case INTEL_OUTPUT_LVDS: 3915c49fd3aSAlan Cox case INTEL_OUTPUT_MIPI: 3925c49fd3aSAlan Cox ret = gma_backlight_init(dev); 3935c49fd3aSAlan Cox break; 3945c49fd3aSAlan Cox } 3955c49fd3aSAlan Cox } 3965c49fd3aSAlan Cox 3975c49fd3aSAlan Cox if (ret) 3985c49fd3aSAlan Cox return ret; 399166973e5SAlan Cox psb_intel_opregion_enable_asle(dev); 4005c49fd3aSAlan Cox #if 0 4019083eb38SArthur Borsboom /* Enable runtime pm at last */ 4025c49fd3aSAlan Cox pm_runtime_enable(&dev->pdev->dev); 4035c49fd3aSAlan Cox pm_runtime_set_active(&dev->pdev->dev); 4045c49fd3aSAlan Cox #endif 4055c49fd3aSAlan Cox /* Intel drm driver load is done, continue doing pvr load */ 4065c49fd3aSAlan Cox return 0; 4075c49fd3aSAlan Cox out_err: 4085c49fd3aSAlan Cox psb_driver_unload(dev); 4095c49fd3aSAlan Cox return ret; 4105c49fd3aSAlan Cox } 4115c49fd3aSAlan Cox 4125c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd) 4135c49fd3aSAlan Cox { 4145c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE 4155c49fd3aSAlan Cox if (bd) { 4165c49fd3aSAlan Cox bd->props.brightness = bd->ops->get_brightness(bd); 4175c49fd3aSAlan Cox backlight_update_status(bd); 4185c49fd3aSAlan Cox } 4195c49fd3aSAlan Cox #endif 4205c49fd3aSAlan Cox } 4215c49fd3aSAlan Cox 4225c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, 4235c49fd3aSAlan Cox unsigned long arg) 4245c49fd3aSAlan Cox { 4255c49fd3aSAlan Cox struct drm_file *file_priv = filp->private_data; 4265c49fd3aSAlan Cox struct drm_device *dev = file_priv->minor->dev; 4275c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 4285c49fd3aSAlan Cox static unsigned int runtime_allowed; 4295c49fd3aSAlan Cox 4305c49fd3aSAlan Cox if (runtime_allowed == 1 && dev_priv->is_lvds_on) { 4315c49fd3aSAlan Cox runtime_allowed++; 4325c49fd3aSAlan Cox pm_runtime_allow(&dev->pdev->dev); 4335c49fd3aSAlan Cox dev_priv->rpm_enabled = 1; 4345c49fd3aSAlan Cox } 4355c49fd3aSAlan Cox return drm_ioctl(filp, cmd, arg); 4365c49fd3aSAlan Cox /* FIXME: do we need to wrap the other side of this */ 4375c49fd3aSAlan Cox } 4385c49fd3aSAlan Cox 439f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 440f90cd811SArthur Borsboom { 441f90cd811SArthur Borsboom return drm_get_pci_dev(pdev, ent, &driver); 442f90cd811SArthur Borsboom } 443f90cd811SArthur Borsboom 444f90cd811SArthur Borsboom 445f90cd811SArthur Borsboom static void psb_pci_remove(struct pci_dev *pdev) 4465c49fd3aSAlan Cox { 4475c49fd3aSAlan Cox struct drm_device *dev = pci_get_drvdata(pdev); 4485c49fd3aSAlan Cox drm_put_dev(dev); 4495c49fd3aSAlan Cox } 4505c49fd3aSAlan Cox 4515c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = { 4525c49fd3aSAlan Cox .resume = gma_power_resume, 4535c49fd3aSAlan Cox .suspend = gma_power_suspend, 454888eef2eSPatrik Jakobsson .thaw = gma_power_thaw, 455888eef2eSPatrik Jakobsson .freeze = gma_power_freeze, 456888eef2eSPatrik Jakobsson .restore = gma_power_restore, 4575c49fd3aSAlan Cox .runtime_suspend = psb_runtime_suspend, 4585c49fd3aSAlan Cox .runtime_resume = psb_runtime_resume, 4595c49fd3aSAlan Cox .runtime_idle = psb_runtime_idle, 4605c49fd3aSAlan Cox }; 4615c49fd3aSAlan Cox 46278b68556SLaurent Pinchart static const struct vm_operations_struct psb_gem_vm_ops = { 4635c49fd3aSAlan Cox .fault = psb_gem_fault, 4645c49fd3aSAlan Cox .open = drm_gem_vm_open, 4655c49fd3aSAlan Cox .close = drm_gem_vm_close, 4665c49fd3aSAlan Cox }; 4675c49fd3aSAlan Cox 4681595c568SIlija Hadzic static const struct file_operations psb_gem_fops = { 4691595c568SIlija Hadzic .owner = THIS_MODULE, 4701595c568SIlija Hadzic .open = drm_open, 4711595c568SIlija Hadzic .release = drm_release, 4721595c568SIlija Hadzic .unlocked_ioctl = psb_unlocked_ioctl, 4730a97c81aSPatrik Jakobsson .compat_ioctl = drm_compat_ioctl, 4741595c568SIlija Hadzic .mmap = drm_gem_mmap, 4751595c568SIlija Hadzic .poll = drm_poll, 4761595c568SIlija Hadzic .read = drm_read, 4771595c568SIlija Hadzic }; 4781595c568SIlija Hadzic 4795c49fd3aSAlan Cox static struct drm_driver driver = { 4801ff49481SDaniel Vetter .driver_features = DRIVER_MODESET | DRIVER_GEM, 4815c49fd3aSAlan Cox .load = psb_driver_load, 4825c49fd3aSAlan Cox .unload = psb_driver_unload, 483cdc13f68SNoralf Trønnes .lastclose = drm_fb_helper_lastclose, 4845c49fd3aSAlan Cox 485f95aeb17SDamien Lespiau .num_ioctls = ARRAY_SIZE(psb_ioctls), 4865c49fd3aSAlan Cox .irq_preinstall = psb_irq_preinstall, 4875c49fd3aSAlan Cox .irq_postinstall = psb_irq_postinstall, 4885c49fd3aSAlan Cox .irq_uninstall = psb_irq_uninstall, 4895c49fd3aSAlan Cox .irq_handler = psb_irq_handler, 4905c49fd3aSAlan Cox .enable_vblank = psb_enable_vblank, 4915c49fd3aSAlan Cox .disable_vblank = psb_disable_vblank, 4925c49fd3aSAlan Cox .get_vblank_counter = psb_get_vblank_counter, 4935c49fd3aSAlan Cox 4945c49fd3aSAlan Cox .gem_free_object = psb_gem_free_object, 4955c49fd3aSAlan Cox .gem_vm_ops = &psb_gem_vm_ops, 496f90cd811SArthur Borsboom 4975c49fd3aSAlan Cox .dumb_create = psb_gem_dumb_create, 498f90cd811SArthur Borsboom .ioctls = psb_ioctls, 4991595c568SIlija Hadzic .fops = &psb_gem_fops, 5005c49fd3aSAlan Cox .name = DRIVER_NAME, 5015c49fd3aSAlan Cox .desc = DRIVER_DESC, 502f90cd811SArthur Borsboom .date = DRIVER_DATE, 503f90cd811SArthur Borsboom .major = DRIVER_MAJOR, 504f90cd811SArthur Borsboom .minor = DRIVER_MINOR, 505f90cd811SArthur Borsboom .patchlevel = DRIVER_PATCHLEVEL 5065c49fd3aSAlan Cox }; 5075c49fd3aSAlan Cox 5085c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = { 5095c49fd3aSAlan Cox .name = DRIVER_NAME, 5105c49fd3aSAlan Cox .id_table = pciidlist, 511f90cd811SArthur Borsboom .probe = psb_pci_probe, 512f90cd811SArthur Borsboom .remove = psb_pci_remove, 513f90cd811SArthur Borsboom .driver.pm = &psb_pm_ops, 5145c49fd3aSAlan Cox }; 5155c49fd3aSAlan Cox 5165c49fd3aSAlan Cox static int __init psb_init(void) 5175c49fd3aSAlan Cox { 51810631d72SDaniel Vetter return pci_register_driver(&psb_pci_driver); 5195c49fd3aSAlan Cox } 5205c49fd3aSAlan Cox 5215c49fd3aSAlan Cox static void __exit psb_exit(void) 5225c49fd3aSAlan Cox { 52310631d72SDaniel Vetter pci_unregister_driver(&psb_pci_driver); 5245c49fd3aSAlan Cox } 5255c49fd3aSAlan Cox 5265c49fd3aSAlan Cox late_initcall(psb_init); 5275c49fd3aSAlan Cox module_exit(psb_exit); 5285c49fd3aSAlan Cox 529f90cd811SArthur Borsboom MODULE_AUTHOR(DRIVER_AUTHOR); 5305c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC); 5310df12b3fSGreg Kroah-Hartman MODULE_LICENSE("GPL"); 532