mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Merge branch 'pci/controller/dwc'
- Factor pcie_valid_speed() and pci_bus_speed2lnkctl2() out of bwctrl so they can be shared by the DWC core (Hans Zhang) * pci/controller/dwc: PCI: dwc: Use common speed conversion function PCI: Move pci_bus_speed2lnkctl2() to public header PCI: Add public pcie_valid_speed() for shared validation
This commit is contained in:
@@ -842,8 +842,10 @@ EXPORT_SYMBOL_GPL(dw_pcie_upconfig_setup);
|
||||
|
||||
static void dw_pcie_link_set_max_speed(struct dw_pcie *pci)
|
||||
{
|
||||
u32 cap, ctrl2, link_speed;
|
||||
u32 cap, ctrl2;
|
||||
enum pci_bus_speed link_speed;
|
||||
u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
|
||||
u16 ctrl2_speed;
|
||||
|
||||
cap = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCAP);
|
||||
|
||||
@@ -860,30 +862,18 @@ static void dw_pcie_link_set_max_speed(struct dw_pcie *pci)
|
||||
ctrl2 = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCTL2);
|
||||
ctrl2 &= ~PCI_EXP_LNKCTL2_TLS;
|
||||
|
||||
switch (pcie_get_link_speed(pci->max_link_speed)) {
|
||||
case PCIE_SPEED_2_5GT:
|
||||
link_speed = PCI_EXP_LNKCTL2_TLS_2_5GT;
|
||||
break;
|
||||
case PCIE_SPEED_5_0GT:
|
||||
link_speed = PCI_EXP_LNKCTL2_TLS_5_0GT;
|
||||
break;
|
||||
case PCIE_SPEED_8_0GT:
|
||||
link_speed = PCI_EXP_LNKCTL2_TLS_8_0GT;
|
||||
break;
|
||||
case PCIE_SPEED_16_0GT:
|
||||
link_speed = PCI_EXP_LNKCTL2_TLS_16_0GT;
|
||||
break;
|
||||
default:
|
||||
link_speed = pcie_get_link_speed(pci->max_link_speed);
|
||||
ctrl2_speed = pci_bus_speed2lnkctl2(link_speed);
|
||||
if (ctrl2_speed == 0) {
|
||||
/* Use hardware capability */
|
||||
link_speed = FIELD_GET(PCI_EXP_LNKCAP_SLS, cap);
|
||||
ctrl2_speed = FIELD_GET(PCI_EXP_LNKCAP_SLS, cap);
|
||||
ctrl2 &= ~PCI_EXP_LNKCTL2_HASD;
|
||||
break;
|
||||
}
|
||||
|
||||
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCTL2, ctrl2 | link_speed);
|
||||
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCTL2, ctrl2 | ctrl2_speed);
|
||||
|
||||
cap &= ~((u32)PCI_EXP_LNKCAP_SLS);
|
||||
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, cap | link_speed);
|
||||
dw_pcie_writel_dbi(pci, offset + PCI_EXP_LNKCAP, cap | ctrl2_speed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef DRIVERS_PCI_H
|
||||
#define DRIVERS_PCI_H
|
||||
|
||||
#include <linux/bug.h>
|
||||
#include <linux/align.h>
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/pci.h>
|
||||
@@ -599,6 +600,28 @@ void pci_bus_put(struct pci_bus *bus);
|
||||
(speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \
|
||||
0)
|
||||
|
||||
static inline bool pcie_valid_speed(enum pci_bus_speed speed)
|
||||
{
|
||||
return (speed >= PCIE_SPEED_2_5GT) && (speed <= PCIE_SPEED_64_0GT);
|
||||
}
|
||||
|
||||
static inline u16 pci_bus_speed2lnkctl2(enum pci_bus_speed speed)
|
||||
{
|
||||
static const u8 speed_conv[] = {
|
||||
[PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT,
|
||||
[PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT,
|
||||
[PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT,
|
||||
[PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT,
|
||||
[PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT,
|
||||
[PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT,
|
||||
};
|
||||
|
||||
if (WARN_ON_ONCE(!pcie_valid_speed(speed)))
|
||||
return 0;
|
||||
|
||||
return speed_conv[speed];
|
||||
}
|
||||
|
||||
static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed)
|
||||
{
|
||||
switch (speed) {
|
||||
|
||||
@@ -48,28 +48,6 @@ struct pcie_bwctrl_data {
|
||||
/* Prevent port removal during Link Speed changes. */
|
||||
static DECLARE_RWSEM(pcie_bwctrl_setspeed_rwsem);
|
||||
|
||||
static bool pcie_valid_speed(enum pci_bus_speed speed)
|
||||
{
|
||||
return (speed >= PCIE_SPEED_2_5GT) && (speed <= PCIE_SPEED_64_0GT);
|
||||
}
|
||||
|
||||
static u16 pci_bus_speed2lnkctl2(enum pci_bus_speed speed)
|
||||
{
|
||||
static const u8 speed_conv[] = {
|
||||
[PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT,
|
||||
[PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT,
|
||||
[PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT,
|
||||
[PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT,
|
||||
[PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT,
|
||||
[PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT,
|
||||
};
|
||||
|
||||
if (WARN_ON_ONCE(!pcie_valid_speed(speed)))
|
||||
return 0;
|
||||
|
||||
return speed_conv[speed];
|
||||
}
|
||||
|
||||
static inline u16 pcie_supported_speeds2target_speed(u8 supported_speeds)
|
||||
{
|
||||
return __fls(supported_speeds);
|
||||
|
||||
Reference in New Issue
Block a user