15823d089SAndy Shevchenko /* 25823d089SAndy Shevchenko * Intel MID Power Management Unit (PWRMU) device driver 35823d089SAndy Shevchenko * 45823d089SAndy Shevchenko * Copyright (C) 2016, Intel Corporation 55823d089SAndy Shevchenko * 65823d089SAndy Shevchenko * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 75823d089SAndy Shevchenko * 85823d089SAndy Shevchenko * This program is free software; you can redistribute it and/or modify it 95823d089SAndy Shevchenko * under the terms and conditions of the GNU General Public License, 105823d089SAndy Shevchenko * version 2, as published by the Free Software Foundation. 115823d089SAndy Shevchenko * 125823d089SAndy Shevchenko * Intel MID Power Management Unit device driver handles the South Complex PCI 135823d089SAndy Shevchenko * devices such as GPDMA, SPI, I2C, PWM, and so on. By default PCI core 145823d089SAndy Shevchenko * modifies bits in PMCSR register in the PCI configuration space. This is not 155823d089SAndy Shevchenko * enough on some SoCs like Intel Tangier. In such case PCI core sets a new 165823d089SAndy Shevchenko * power state of the device in question through a PM hook registered in struct 175823d089SAndy Shevchenko * pci_platform_pm_ops (see drivers/pci/pci-mid.c). 185823d089SAndy Shevchenko */ 195823d089SAndy Shevchenko 205823d089SAndy Shevchenko #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 215823d089SAndy Shevchenko 225823d089SAndy Shevchenko #include <linux/delay.h> 235823d089SAndy Shevchenko #include <linux/errno.h> 245823d089SAndy Shevchenko #include <linux/init.h> 255823d089SAndy Shevchenko #include <linux/interrupt.h> 265823d089SAndy Shevchenko #include <linux/kernel.h> 275823d089SAndy Shevchenko #include <linux/module.h> 285823d089SAndy Shevchenko #include <linux/mutex.h> 295823d089SAndy Shevchenko #include <linux/pci.h> 305823d089SAndy Shevchenko 315823d089SAndy Shevchenko #include <asm/intel-mid.h> 325823d089SAndy Shevchenko 335823d089SAndy Shevchenko /* Registers */ 345823d089SAndy Shevchenko #define PM_STS 0x00 355823d089SAndy Shevchenko #define PM_CMD 0x04 365823d089SAndy Shevchenko #define PM_ICS 0x08 375823d089SAndy Shevchenko #define PM_WKC(x) (0x10 + (x) * 4) 385823d089SAndy Shevchenko #define PM_WKS(x) (0x18 + (x) * 4) 395823d089SAndy Shevchenko #define PM_SSC(x) (0x20 + (x) * 4) 405823d089SAndy Shevchenko #define PM_SSS(x) (0x30 + (x) * 4) 415823d089SAndy Shevchenko 425823d089SAndy Shevchenko /* Bits in PM_STS */ 435823d089SAndy Shevchenko #define PM_STS_BUSY (1 << 8) 445823d089SAndy Shevchenko 455823d089SAndy Shevchenko /* Bits in PM_CMD */ 465823d089SAndy Shevchenko #define PM_CMD_CMD(x) ((x) << 0) 475823d089SAndy Shevchenko #define PM_CMD_IOC (1 << 8) 485823d089SAndy Shevchenko #define PM_CMD_D3cold (1 << 21) 495823d089SAndy Shevchenko 505823d089SAndy Shevchenko /* List of commands */ 515823d089SAndy Shevchenko #define CMD_SET_CFG 0x01 525823d089SAndy Shevchenko 535823d089SAndy Shevchenko /* Bits in PM_ICS */ 545823d089SAndy Shevchenko #define PM_ICS_INT_STATUS(x) ((x) & 0xff) 555823d089SAndy Shevchenko #define PM_ICS_IE (1 << 8) 565823d089SAndy Shevchenko #define PM_ICS_IP (1 << 9) 575823d089SAndy Shevchenko #define PM_ICS_SW_INT_STS (1 << 10) 585823d089SAndy Shevchenko 595823d089SAndy Shevchenko /* List of interrupts */ 605823d089SAndy Shevchenko #define INT_INVALID 0 615823d089SAndy Shevchenko #define INT_CMD_COMPLETE 1 625823d089SAndy Shevchenko #define INT_CMD_ERR 2 635823d089SAndy Shevchenko #define INT_WAKE_EVENT 3 645823d089SAndy Shevchenko #define INT_LSS_POWER_ERR 4 655823d089SAndy Shevchenko #define INT_S0iX_MSG_ERR 5 665823d089SAndy Shevchenko #define INT_NO_C6 6 675823d089SAndy Shevchenko #define INT_TRIGGER_ERR 7 685823d089SAndy Shevchenko #define INT_INACTIVITY 8 695823d089SAndy Shevchenko 705823d089SAndy Shevchenko /* South Complex devices */ 715823d089SAndy Shevchenko #define LSS_MAX_SHARED_DEVS 4 725823d089SAndy Shevchenko #define LSS_MAX_DEVS 64 735823d089SAndy Shevchenko 745823d089SAndy Shevchenko #define LSS_WS_BITS 1 /* wake state width */ 755823d089SAndy Shevchenko #define LSS_PWS_BITS 2 /* power state width */ 765823d089SAndy Shevchenko 775823d089SAndy Shevchenko /* Supported device IDs */ 78*ca22312dSAndy Shevchenko #define PCI_DEVICE_ID_PENWELL 0x0828 795823d089SAndy Shevchenko #define PCI_DEVICE_ID_TANGIER 0x11a1 805823d089SAndy Shevchenko 815823d089SAndy Shevchenko struct mid_pwr_dev { 825823d089SAndy Shevchenko struct pci_dev *pdev; 835823d089SAndy Shevchenko pci_power_t state; 845823d089SAndy Shevchenko }; 855823d089SAndy Shevchenko 865823d089SAndy Shevchenko struct mid_pwr { 875823d089SAndy Shevchenko struct device *dev; 885823d089SAndy Shevchenko void __iomem *regs; 895823d089SAndy Shevchenko int irq; 905823d089SAndy Shevchenko bool available; 915823d089SAndy Shevchenko 925823d089SAndy Shevchenko struct mutex lock; 935823d089SAndy Shevchenko struct mid_pwr_dev lss[LSS_MAX_DEVS][LSS_MAX_SHARED_DEVS]; 945823d089SAndy Shevchenko }; 955823d089SAndy Shevchenko 965823d089SAndy Shevchenko static struct mid_pwr *midpwr; 975823d089SAndy Shevchenko 985823d089SAndy Shevchenko static u32 mid_pwr_get_state(struct mid_pwr *pwr, int reg) 995823d089SAndy Shevchenko { 1005823d089SAndy Shevchenko return readl(pwr->regs + PM_SSS(reg)); 1015823d089SAndy Shevchenko } 1025823d089SAndy Shevchenko 1035823d089SAndy Shevchenko static void mid_pwr_set_state(struct mid_pwr *pwr, int reg, u32 value) 1045823d089SAndy Shevchenko { 1055823d089SAndy Shevchenko writel(value, pwr->regs + PM_SSC(reg)); 1065823d089SAndy Shevchenko } 1075823d089SAndy Shevchenko 1085823d089SAndy Shevchenko static void mid_pwr_set_wake(struct mid_pwr *pwr, int reg, u32 value) 1095823d089SAndy Shevchenko { 1105823d089SAndy Shevchenko writel(value, pwr->regs + PM_WKC(reg)); 1115823d089SAndy Shevchenko } 1125823d089SAndy Shevchenko 1135823d089SAndy Shevchenko static void mid_pwr_interrupt_disable(struct mid_pwr *pwr) 1145823d089SAndy Shevchenko { 1155823d089SAndy Shevchenko writel(~PM_ICS_IE, pwr->regs + PM_ICS); 1165823d089SAndy Shevchenko } 1175823d089SAndy Shevchenko 1185823d089SAndy Shevchenko static bool mid_pwr_is_busy(struct mid_pwr *pwr) 1195823d089SAndy Shevchenko { 1205823d089SAndy Shevchenko return !!(readl(pwr->regs + PM_STS) & PM_STS_BUSY); 1215823d089SAndy Shevchenko } 1225823d089SAndy Shevchenko 1235823d089SAndy Shevchenko /* Wait 500ms that the latest PWRMU command finished */ 1245823d089SAndy Shevchenko static int mid_pwr_wait(struct mid_pwr *pwr) 1255823d089SAndy Shevchenko { 1265823d089SAndy Shevchenko unsigned int count = 500000; 1275823d089SAndy Shevchenko bool busy; 1285823d089SAndy Shevchenko 1295823d089SAndy Shevchenko do { 1305823d089SAndy Shevchenko busy = mid_pwr_is_busy(pwr); 1315823d089SAndy Shevchenko if (!busy) 1325823d089SAndy Shevchenko return 0; 1335823d089SAndy Shevchenko udelay(1); 1345823d089SAndy Shevchenko } while (--count); 1355823d089SAndy Shevchenko 1365823d089SAndy Shevchenko return -EBUSY; 1375823d089SAndy Shevchenko } 1385823d089SAndy Shevchenko 1395823d089SAndy Shevchenko static int mid_pwr_wait_for_cmd(struct mid_pwr *pwr, u8 cmd) 1405823d089SAndy Shevchenko { 1415823d089SAndy Shevchenko writel(PM_CMD_CMD(cmd), pwr->regs + PM_CMD); 1425823d089SAndy Shevchenko return mid_pwr_wait(pwr); 1435823d089SAndy Shevchenko } 1445823d089SAndy Shevchenko 1455823d089SAndy Shevchenko static int __update_power_state(struct mid_pwr *pwr, int reg, int bit, int new) 1465823d089SAndy Shevchenko { 1475823d089SAndy Shevchenko int curstate; 1485823d089SAndy Shevchenko u32 power; 1495823d089SAndy Shevchenko int ret; 1505823d089SAndy Shevchenko 1515823d089SAndy Shevchenko /* Check if the device is already in desired state */ 1525823d089SAndy Shevchenko power = mid_pwr_get_state(pwr, reg); 1535823d089SAndy Shevchenko curstate = (power >> bit) & 3; 1545823d089SAndy Shevchenko if (curstate == new) 1555823d089SAndy Shevchenko return 0; 1565823d089SAndy Shevchenko 1575823d089SAndy Shevchenko /* Update the power state */ 1585823d089SAndy Shevchenko mid_pwr_set_state(pwr, reg, (power & ~(3 << bit)) | (new << bit)); 1595823d089SAndy Shevchenko 1605823d089SAndy Shevchenko /* Send command to SCU */ 1615823d089SAndy Shevchenko ret = mid_pwr_wait_for_cmd(pwr, CMD_SET_CFG); 1625823d089SAndy Shevchenko if (ret) 1635823d089SAndy Shevchenko return ret; 1645823d089SAndy Shevchenko 1655823d089SAndy Shevchenko /* Check if the device is already in desired state */ 1665823d089SAndy Shevchenko power = mid_pwr_get_state(pwr, reg); 1675823d089SAndy Shevchenko curstate = (power >> bit) & 3; 1685823d089SAndy Shevchenko if (curstate != new) 1695823d089SAndy Shevchenko return -EAGAIN; 1705823d089SAndy Shevchenko 1715823d089SAndy Shevchenko return 0; 1725823d089SAndy Shevchenko } 1735823d089SAndy Shevchenko 1745823d089SAndy Shevchenko static pci_power_t __find_weakest_power_state(struct mid_pwr_dev *lss, 1755823d089SAndy Shevchenko struct pci_dev *pdev, 1765823d089SAndy Shevchenko pci_power_t state) 1775823d089SAndy Shevchenko { 1785823d089SAndy Shevchenko pci_power_t weakest = PCI_D3hot; 1795823d089SAndy Shevchenko unsigned int j; 1805823d089SAndy Shevchenko 1815823d089SAndy Shevchenko /* Find device in cache or first free cell */ 1825823d089SAndy Shevchenko for (j = 0; j < LSS_MAX_SHARED_DEVS; j++) { 1835823d089SAndy Shevchenko if (lss[j].pdev == pdev || !lss[j].pdev) 1845823d089SAndy Shevchenko break; 1855823d089SAndy Shevchenko } 1865823d089SAndy Shevchenko 1875823d089SAndy Shevchenko /* Store the desired state in cache */ 1885823d089SAndy Shevchenko if (j < LSS_MAX_SHARED_DEVS) { 1895823d089SAndy Shevchenko lss[j].pdev = pdev; 1905823d089SAndy Shevchenko lss[j].state = state; 1915823d089SAndy Shevchenko } else { 1925823d089SAndy Shevchenko dev_WARN(&pdev->dev, "No room for device in PWRMU LSS cache\n"); 1935823d089SAndy Shevchenko weakest = state; 1945823d089SAndy Shevchenko } 1955823d089SAndy Shevchenko 1965823d089SAndy Shevchenko /* Find the power state we may use */ 1975823d089SAndy Shevchenko for (j = 0; j < LSS_MAX_SHARED_DEVS; j++) { 1985823d089SAndy Shevchenko if (lss[j].state < weakest) 1995823d089SAndy Shevchenko weakest = lss[j].state; 2005823d089SAndy Shevchenko } 2015823d089SAndy Shevchenko 2025823d089SAndy Shevchenko return weakest; 2035823d089SAndy Shevchenko } 2045823d089SAndy Shevchenko 2055823d089SAndy Shevchenko static int __set_power_state(struct mid_pwr *pwr, struct pci_dev *pdev, 2065823d089SAndy Shevchenko pci_power_t state, int id, int reg, int bit) 2075823d089SAndy Shevchenko { 2085823d089SAndy Shevchenko const char *name; 2095823d089SAndy Shevchenko int ret; 2105823d089SAndy Shevchenko 2115823d089SAndy Shevchenko state = __find_weakest_power_state(pwr->lss[id], pdev, state); 2125823d089SAndy Shevchenko name = pci_power_name(state); 2135823d089SAndy Shevchenko 2145823d089SAndy Shevchenko ret = __update_power_state(pwr, reg, bit, (__force int)state); 2155823d089SAndy Shevchenko if (ret) { 2165823d089SAndy Shevchenko dev_warn(&pdev->dev, "Can't set power state %s: %d\n", name, ret); 2175823d089SAndy Shevchenko return ret; 2185823d089SAndy Shevchenko } 2195823d089SAndy Shevchenko 2205823d089SAndy Shevchenko dev_vdbg(&pdev->dev, "Set power state %s\n", name); 2215823d089SAndy Shevchenko return 0; 2225823d089SAndy Shevchenko } 2235823d089SAndy Shevchenko 2245823d089SAndy Shevchenko static int mid_pwr_set_power_state(struct mid_pwr *pwr, struct pci_dev *pdev, 2255823d089SAndy Shevchenko pci_power_t state) 2265823d089SAndy Shevchenko { 2275823d089SAndy Shevchenko int id, reg, bit; 2285823d089SAndy Shevchenko int ret; 2295823d089SAndy Shevchenko 2305823d089SAndy Shevchenko id = intel_mid_pwr_get_lss_id(pdev); 2315823d089SAndy Shevchenko if (id < 0) 2325823d089SAndy Shevchenko return id; 2335823d089SAndy Shevchenko 2345823d089SAndy Shevchenko reg = (id * LSS_PWS_BITS) / 32; 2355823d089SAndy Shevchenko bit = (id * LSS_PWS_BITS) % 32; 2365823d089SAndy Shevchenko 2375823d089SAndy Shevchenko /* We support states between PCI_D0 and PCI_D3hot */ 2385823d089SAndy Shevchenko if (state < PCI_D0) 2395823d089SAndy Shevchenko state = PCI_D0; 2405823d089SAndy Shevchenko if (state > PCI_D3hot) 2415823d089SAndy Shevchenko state = PCI_D3hot; 2425823d089SAndy Shevchenko 2435823d089SAndy Shevchenko mutex_lock(&pwr->lock); 2445823d089SAndy Shevchenko ret = __set_power_state(pwr, pdev, state, id, reg, bit); 2455823d089SAndy Shevchenko mutex_unlock(&pwr->lock); 2465823d089SAndy Shevchenko return ret; 2475823d089SAndy Shevchenko } 2485823d089SAndy Shevchenko 2495823d089SAndy Shevchenko int intel_mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state) 2505823d089SAndy Shevchenko { 2515823d089SAndy Shevchenko struct mid_pwr *pwr = midpwr; 2525823d089SAndy Shevchenko int ret = 0; 2535823d089SAndy Shevchenko 2545823d089SAndy Shevchenko might_sleep(); 2555823d089SAndy Shevchenko 2565823d089SAndy Shevchenko if (pwr && pwr->available) 2575823d089SAndy Shevchenko ret = mid_pwr_set_power_state(pwr, pdev, state); 2585823d089SAndy Shevchenko dev_vdbg(&pdev->dev, "set_power_state() returns %d\n", ret); 2595823d089SAndy Shevchenko 2605823d089SAndy Shevchenko return 0; 2615823d089SAndy Shevchenko } 2625823d089SAndy Shevchenko EXPORT_SYMBOL_GPL(intel_mid_pci_set_power_state); 2635823d089SAndy Shevchenko 2645823d089SAndy Shevchenko int intel_mid_pwr_get_lss_id(struct pci_dev *pdev) 2655823d089SAndy Shevchenko { 2665823d089SAndy Shevchenko int vndr; 2675823d089SAndy Shevchenko u8 id; 2685823d089SAndy Shevchenko 2695823d089SAndy Shevchenko /* 2705823d089SAndy Shevchenko * Mapping to PWRMU index is kept in the Logical SubSystem ID byte of 2715823d089SAndy Shevchenko * Vendor capability. 2725823d089SAndy Shevchenko */ 2735823d089SAndy Shevchenko vndr = pci_find_capability(pdev, PCI_CAP_ID_VNDR); 2745823d089SAndy Shevchenko if (!vndr) 2755823d089SAndy Shevchenko return -EINVAL; 2765823d089SAndy Shevchenko 2775823d089SAndy Shevchenko /* Read the Logical SubSystem ID byte */ 2785823d089SAndy Shevchenko pci_read_config_byte(pdev, vndr + INTEL_MID_PWR_LSS_OFFSET, &id); 2795823d089SAndy Shevchenko if (!(id & INTEL_MID_PWR_LSS_TYPE)) 2805823d089SAndy Shevchenko return -ENODEV; 2815823d089SAndy Shevchenko 2825823d089SAndy Shevchenko id &= ~INTEL_MID_PWR_LSS_TYPE; 2835823d089SAndy Shevchenko if (id >= LSS_MAX_DEVS) 2845823d089SAndy Shevchenko return -ERANGE; 2855823d089SAndy Shevchenko 2865823d089SAndy Shevchenko return id; 2875823d089SAndy Shevchenko } 2885823d089SAndy Shevchenko 2895823d089SAndy Shevchenko static irqreturn_t mid_pwr_irq_handler(int irq, void *dev_id) 2905823d089SAndy Shevchenko { 2915823d089SAndy Shevchenko struct mid_pwr *pwr = dev_id; 2925823d089SAndy Shevchenko u32 ics; 2935823d089SAndy Shevchenko 2945823d089SAndy Shevchenko ics = readl(pwr->regs + PM_ICS); 2955823d089SAndy Shevchenko if (!(ics & PM_ICS_IP)) 2965823d089SAndy Shevchenko return IRQ_NONE; 2975823d089SAndy Shevchenko 2985823d089SAndy Shevchenko writel(ics | PM_ICS_IP, pwr->regs + PM_ICS); 2995823d089SAndy Shevchenko 3005823d089SAndy Shevchenko dev_warn(pwr->dev, "Unexpected IRQ: %#x\n", PM_ICS_INT_STATUS(ics)); 3015823d089SAndy Shevchenko return IRQ_HANDLED; 3025823d089SAndy Shevchenko } 3035823d089SAndy Shevchenko 3045823d089SAndy Shevchenko struct mid_pwr_device_info { 3055823d089SAndy Shevchenko int (*set_initial_state)(struct mid_pwr *pwr); 3065823d089SAndy Shevchenko }; 3075823d089SAndy Shevchenko 3085823d089SAndy Shevchenko static int mid_pwr_probe(struct pci_dev *pdev, const struct pci_device_id *id) 3095823d089SAndy Shevchenko { 3105823d089SAndy Shevchenko struct mid_pwr_device_info *info = (void *)id->driver_data; 3115823d089SAndy Shevchenko struct device *dev = &pdev->dev; 3125823d089SAndy Shevchenko struct mid_pwr *pwr; 3135823d089SAndy Shevchenko int ret; 3145823d089SAndy Shevchenko 3155823d089SAndy Shevchenko ret = pcim_enable_device(pdev); 3165823d089SAndy Shevchenko if (ret < 0) { 3175823d089SAndy Shevchenko dev_err(&pdev->dev, "error: could not enable device\n"); 3185823d089SAndy Shevchenko return ret; 3195823d089SAndy Shevchenko } 3205823d089SAndy Shevchenko 3215823d089SAndy Shevchenko ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev)); 3225823d089SAndy Shevchenko if (ret) { 3235823d089SAndy Shevchenko dev_err(&pdev->dev, "I/O memory remapping failed\n"); 3245823d089SAndy Shevchenko return ret; 3255823d089SAndy Shevchenko } 3265823d089SAndy Shevchenko 3275823d089SAndy Shevchenko pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); 3285823d089SAndy Shevchenko if (!pwr) 3295823d089SAndy Shevchenko return -ENOMEM; 3305823d089SAndy Shevchenko 3315823d089SAndy Shevchenko pwr->dev = dev; 3325823d089SAndy Shevchenko pwr->regs = pcim_iomap_table(pdev)[0]; 3335823d089SAndy Shevchenko pwr->irq = pdev->irq; 3345823d089SAndy Shevchenko 3355823d089SAndy Shevchenko mutex_init(&pwr->lock); 3365823d089SAndy Shevchenko 3375823d089SAndy Shevchenko /* Disable interrupts */ 3385823d089SAndy Shevchenko mid_pwr_interrupt_disable(pwr); 3395823d089SAndy Shevchenko 3405823d089SAndy Shevchenko if (info && info->set_initial_state) { 3415823d089SAndy Shevchenko ret = info->set_initial_state(pwr); 3425823d089SAndy Shevchenko if (ret) 3435823d089SAndy Shevchenko dev_warn(dev, "Can't set initial state: %d\n", ret); 3445823d089SAndy Shevchenko } 3455823d089SAndy Shevchenko 3465823d089SAndy Shevchenko ret = devm_request_irq(dev, pdev->irq, mid_pwr_irq_handler, 3475823d089SAndy Shevchenko IRQF_NO_SUSPEND, pci_name(pdev), pwr); 3485823d089SAndy Shevchenko if (ret) 3495823d089SAndy Shevchenko return ret; 3505823d089SAndy Shevchenko 3515823d089SAndy Shevchenko pwr->available = true; 3525823d089SAndy Shevchenko midpwr = pwr; 3535823d089SAndy Shevchenko 3545823d089SAndy Shevchenko pci_set_drvdata(pdev, pwr); 3555823d089SAndy Shevchenko return 0; 3565823d089SAndy Shevchenko } 3575823d089SAndy Shevchenko 358*ca22312dSAndy Shevchenko static int mid_set_initial_state(struct mid_pwr *pwr) 3595823d089SAndy Shevchenko { 3605823d089SAndy Shevchenko unsigned int i, j; 3615823d089SAndy Shevchenko int ret; 3625823d089SAndy Shevchenko 3635823d089SAndy Shevchenko /* 3645823d089SAndy Shevchenko * Enable wake events. 3655823d089SAndy Shevchenko * 3665823d089SAndy Shevchenko * PWRMU supports up to 32 sources for wake up the system. Ungate them 3675823d089SAndy Shevchenko * all here. 3685823d089SAndy Shevchenko */ 3695823d089SAndy Shevchenko mid_pwr_set_wake(pwr, 0, 0xffffffff); 3705823d089SAndy Shevchenko mid_pwr_set_wake(pwr, 1, 0xffffffff); 3715823d089SAndy Shevchenko 3725823d089SAndy Shevchenko /* 3735823d089SAndy Shevchenko * Power off South Complex devices. 3745823d089SAndy Shevchenko * 3755823d089SAndy Shevchenko * There is a map (see a note below) of 64 devices with 2 bits per each 3765823d089SAndy Shevchenko * on 32-bit HW registers. The following calls set all devices to one 3775823d089SAndy Shevchenko * known initial state, i.e. PCI_D3hot. This is done in conjunction 3785823d089SAndy Shevchenko * with PMCSR setting in arch/x86/pci/intel_mid_pci.c. 3795823d089SAndy Shevchenko * 3805823d089SAndy Shevchenko * NOTE: The actual device mapping is provided by a platform at run 3815823d089SAndy Shevchenko * time using vendor capability of PCI configuration space. 3825823d089SAndy Shevchenko */ 3835823d089SAndy Shevchenko mid_pwr_set_state(pwr, 0, 0xffffffff); 3845823d089SAndy Shevchenko mid_pwr_set_state(pwr, 1, 0xffffffff); 3855823d089SAndy Shevchenko mid_pwr_set_state(pwr, 2, 0xffffffff); 3865823d089SAndy Shevchenko mid_pwr_set_state(pwr, 3, 0xffffffff); 3875823d089SAndy Shevchenko 3885823d089SAndy Shevchenko /* Send command to SCU */ 3895823d089SAndy Shevchenko ret = mid_pwr_wait_for_cmd(pwr, CMD_SET_CFG); 3905823d089SAndy Shevchenko if (ret) 3915823d089SAndy Shevchenko return ret; 3925823d089SAndy Shevchenko 3935823d089SAndy Shevchenko for (i = 0; i < LSS_MAX_DEVS; i++) { 3945823d089SAndy Shevchenko for (j = 0; j < LSS_MAX_SHARED_DEVS; j++) 3955823d089SAndy Shevchenko pwr->lss[i][j].state = PCI_D3hot; 3965823d089SAndy Shevchenko } 3975823d089SAndy Shevchenko 3985823d089SAndy Shevchenko return 0; 3995823d089SAndy Shevchenko } 4005823d089SAndy Shevchenko 401*ca22312dSAndy Shevchenko static const struct mid_pwr_device_info mid_info = { 402*ca22312dSAndy Shevchenko .set_initial_state = mid_set_initial_state, 4035823d089SAndy Shevchenko }; 4045823d089SAndy Shevchenko 4055823d089SAndy Shevchenko static const struct pci_device_id mid_pwr_pci_ids[] = { 406*ca22312dSAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PENWELL), (kernel_ulong_t)&mid_info }, 407*ca22312dSAndy Shevchenko { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_TANGIER), (kernel_ulong_t)&mid_info }, 4085823d089SAndy Shevchenko {} 4095823d089SAndy Shevchenko }; 4105823d089SAndy Shevchenko MODULE_DEVICE_TABLE(pci, mid_pwr_pci_ids); 4115823d089SAndy Shevchenko 4125823d089SAndy Shevchenko static struct pci_driver mid_pwr_pci_driver = { 4135823d089SAndy Shevchenko .name = "intel_mid_pwr", 4145823d089SAndy Shevchenko .probe = mid_pwr_probe, 4155823d089SAndy Shevchenko .id_table = mid_pwr_pci_ids, 4165823d089SAndy Shevchenko }; 4175823d089SAndy Shevchenko 4185823d089SAndy Shevchenko builtin_pci_driver(mid_pwr_pci_driver); 419