// SPDX-License-Identifier: GPL-2.0-only /* * Intel MID Power Management Unit (PWRMU) device driver * * Copyright (C) 2016, Intel Corporation * * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> * * Intel MID Power Management Unit device driver handles the South Complex PCI * devices such as GPDMA, SPI, I2C, PWM, and so on. By default PCI core * modifies bits in PMCSR register in the PCI configuration space. This is not * enough on some SoCs like Intel Tangier. In such case PCI core sets a new * power state of the device in question through a PM hook registered in struct * pci_platform_pm_ops (see drivers/pci/pci-mid.c).
*/
staticint __update_power_state(struct mid_pwr *pwr, int reg, int bit, intnew)
{ int curstate;
u32 power; int ret;
/* Check if the device is already in desired state */
power = mid_pwr_get_state(pwr, reg);
curstate = (power >> bit) & 3; if (curstate == new) return 0;
/* Update the power state */
mid_pwr_set_state(pwr, reg, (power & ~(3 << bit)) | (new << bit));
/* Send command to SCU */
ret = mid_pwr_wait_for_cmd(pwr, CMD_SET_CFG); if (ret) return ret;
/* Check if the device is already in desired state */
power = mid_pwr_get_state(pwr, reg);
curstate = (power >> bit) & 3; if (curstate != new) return -EAGAIN;
/* Find device in cache or first free cell */ for (j = 0; j < LSS_MAX_SHARED_DEVS; j++) { if (lss[j].pdev == pdev || !lss[j].pdev) break;
}
/* Store the desired state in cache */ if (j < LSS_MAX_SHARED_DEVS) {
lss[j].pdev = pdev;
lss[j].state = state;
} else {
dev_WARN(&pdev->dev, "No room for device in PWRMU LSS cache\n");
weakest = state;
}
/* Find the power state we may use */ for (j = 0; j < LSS_MAX_SHARED_DEVS; j++) { if (lss[j].state < weakest)
weakest = lss[j].state;
}
return weakest;
}
staticint __set_power_state(struct mid_pwr *pwr, struct pci_dev *pdev,
pci_power_t state, int id, int reg, int bit)
{ constchar *name; int ret;
state = __find_weakest_power_state(pwr->lss[id], pdev, state);
name = pci_power_name(state);
ret = __update_power_state(pwr, reg, bit, (__force int)state); if (ret) {
dev_warn(&pdev->dev, "Can't set power state %s: %d\n", name, ret); return ret;
}
dev_vdbg(&pdev->dev, "Set power state %s\n", name); return 0;
}
staticint mid_pwr_set_power_state(struct mid_pwr *pwr, struct pci_dev *pdev,
pci_power_t state)
{ int id, reg, bit; int ret;
id = intel_mid_pwr_get_lss_id(pdev); if (id < 0) return id;
reg = (id * LSS_PWS_BITS) / 32;
bit = (id * LSS_PWS_BITS) % 32;
/* We support states between PCI_D0 and PCI_D3hot */ if (state < PCI_D0)
state = PCI_D0; if (state > PCI_D3hot)
state = PCI_D3hot;
int intel_mid_pwr_get_lss_id(struct pci_dev *pdev)
{ int vndr;
u8 id;
/* * Mapping to PWRMU index is kept in the Logical SubSystem ID byte of * Vendor capability.
*/
vndr = pci_find_capability(pdev, PCI_CAP_ID_VNDR); if (!vndr) return -EINVAL;
/* Read the Logical SubSystem ID byte */
pci_read_config_byte(pdev, vndr + INTEL_MID_PWR_LSS_OFFSET, &id); if (!(id & INTEL_MID_PWR_LSS_TYPE)) return -ENODEV;
id &= ~INTEL_MID_PWR_LSS_TYPE; if (id >= LSS_MAX_DEVS) return -ERANGE;
if (info && info->set_initial_state) {
ret = info->set_initial_state(pwr); if (ret)
dev_warn(dev, "Can't set initial state: %d\n", ret);
}
ret = devm_request_irq(dev, pdev->irq, mid_pwr_irq_handler,
IRQF_NO_SUSPEND, pci_name(pdev), pwr); if (ret) return ret;
pwr->available = true;
midpwr = pwr;
pci_set_drvdata(pdev, pwr); return 0;
}
staticint mid_set_initial_state(struct mid_pwr *pwr, const u32 *states)
{ unsignedint i, j; int ret;
/* * Enable wake events. * * PWRMU supports up to 32 sources for wake up the system. Ungate them * all here.
*/
mid_pwr_set_wake(pwr, 0, 0xffffffff);
mid_pwr_set_wake(pwr, 1, 0xffffffff);
/* * Power off South Complex devices. * * There is a map (see a note below) of 64 devices with 2 bits per each * on 32-bit HW registers. The following calls set all devices to one * known initial state, i.e. PCI_D3hot. This is done in conjunction * with PMCSR setting in arch/x86/pci/intel_mid_pci.c. * * NOTE: The actual device mapping is provided by a platform at run * time using vendor capability of PCI configuration space.
*/
mid_pwr_set_state(pwr, 0, states[0]);
mid_pwr_set_state(pwr, 1, states[1]);
mid_pwr_set_state(pwr, 2, states[2]);
mid_pwr_set_state(pwr, 3, states[3]);
/* Send command to SCU */
ret = mid_pwr_wait_for_cmd(pwr, CMD_SET_CFG); if (ret) return ret;
for (i = 0; i < LSS_MAX_DEVS; i++) { for (j = 0; j < LSS_MAX_SHARED_DEVS; j++)
pwr->lss[i][j].state = PCI_D3hot;
}
/* This table should be in sync with the one in drivers/pci/pci-mid.c */ staticconststruct pci_device_id mid_pwr_pci_ids[] = {
{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PENWELL), (kernel_ulong_t)&pnw_info },
{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_TANGIER), (kernel_ulong_t)&tng_info },
{}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.