Release 4.11 drivers/pci/dwc/pcie-designware.c
/*
* Synopsys Designware PCIe host controller driver
*
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Author: Jingoo Han <jg1.han@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/delay.h>
#include <linux/of.h>
#include <linux/types.h>
#include "pcie-designware.h"
/* PCIe Port Logic registers */
#define PLR_OFFSET 0x700
#define PCIE_PHY_DEBUG_R1 (PLR_OFFSET + 0x2c)
#define PCIE_PHY_DEBUG_R1_LINK_UP (0x1 << 4)
#define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (0x1 << 29)
int dw_pcie_read(void __iomem *addr, int size, u32 *val)
{
if ((uintptr_t)addr & (size - 1)) {
*val = 0;
return PCIBIOS_BAD_REGISTER_NUMBER;
}
if (size == 4) {
*val = readl(addr);
} else if (size == 2) {
*val = readw(addr);
} else if (size == 1) {
*val = readb(addr);
} else {
*val = 0;
return PCIBIOS_BAD_REGISTER_NUMBER;
}
return PCIBIOS_SUCCESSFUL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 49 | 47.12% | 2 | 33.33% |
Gabriele Paoloni | 48 | 46.15% | 2 | 33.33% |
Kishon Vijay Abraham I | 7 | 6.73% | 2 | 33.33% |
Total | 104 | 100.00% | 6 | 100.00% |
int dw_pcie_write(void __iomem *addr, int size, u32 val)
{
if ((uintptr_t)addr & (size - 1))
return PCIBIOS_BAD_REGISTER_NUMBER;
if (size == 4)
writel(val, addr);
else if (size == 2)
writew(val, addr);
else if (size == 1)
writeb(val, addr);
else
return PCIBIOS_BAD_REGISTER_NUMBER;
return PCIBIOS_SUCCESSFUL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 63 | 78.75% | 2 | 50.00% |
Gabriele Paoloni | 16 | 20.00% | 1 | 25.00% |
Kishon Vijay Abraham I | 1 | 1.25% | 1 | 25.00% |
Total | 80 | 100.00% | 4 | 100.00% |
u32 dw_pcie_readl_dbi(struct dw_pcie *pci, u32 reg)
{
if (pci->ops->readl_dbi)
return pci->ops->readl_dbi(pci, reg);
return readl(pci->dbi_base + reg);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 22 | 51.16% | 2 | 40.00% |
Kishon Vijay Abraham I | 9 | 20.93% | 1 | 20.00% |
Seungwon Jeon | 7 | 16.28% | 1 | 20.00% |
Björn Helgaas | 5 | 11.63% | 1 | 20.00% |
Total | 43 | 100.00% | 5 | 100.00% |
void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
{
if (pci->ops->writel_dbi)
pci->ops->writel_dbi(pci, reg, val);
else
writel(val, pci->dbi_base + reg);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 30 | 61.22% | 2 | 40.00% |
Kishon Vijay Abraham I | 9 | 18.37% | 1 | 20.00% |
Seungwon Jeon | 6 | 12.24% | 1 | 20.00% |
Björn Helgaas | 4 | 8.16% | 1 | 20.00% |
Total | 49 | 100.00% | 5 | 100.00% |
static u32 dw_pcie_readl_unroll(struct dw_pcie *pci, u32 index, u32 reg)
{
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
return dw_pcie_readl_dbi(pci, offset + reg);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Joao Pinto | 28 | 80.00% | 1 | 25.00% |
Kishon Vijay Abraham I | 4 | 11.43% | 1 | 25.00% |
Jingoo Han | 2 | 5.71% | 1 | 25.00% |
Seungwon Jeon | 1 | 2.86% | 1 | 25.00% |
Total | 35 | 100.00% | 4 | 100.00% |
static void dw_pcie_writel_unroll(struct dw_pcie *pci, u32 index, u32 reg,
u32 val)
{
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
dw_pcie_writel_dbi(pci, offset + reg, val);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 15 | 38.46% | 2 | 28.57% |
Joao Pinto | 14 | 35.90% | 1 | 14.29% |
Kishon Vijay Abraham I | 4 | 10.26% | 1 | 14.29% |
Björn Helgaas | 4 | 10.26% | 2 | 28.57% |
Seungwon Jeon | 2 | 5.13% | 1 | 14.29% |
Total | 39 | 100.00% | 7 | 100.00% |
void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
u64 cpu_addr, u64 pci_addr, u32 size)
{
u32 retries, val;
if (pci->iatu_unroll_enabled) {
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_LOWER_BASE,
lower_32_bits(cpu_addr));
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_UPPER_BASE,
upper_32_bits(cpu_addr));
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
lower_32_bits(cpu_addr + size - 1));
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
lower_32_bits(pci_addr));
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
upper_32_bits(pci_addr));
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
type);
dw_pcie_writel_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
PCIE_ATU_ENABLE);
} else {
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT,
PCIE_ATU_REGION_OUTBOUND | index);
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_BASE,
lower_32_bits(cpu_addr));
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_BASE,
upper_32_bits(cpu_addr));
dw_pcie_writel_dbi(pci, PCIE_ATU_LIMIT,
lower_32_bits(cpu_addr + size - 1));
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_TARGET,
lower_32_bits(pci_addr));
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_TARGET,
upper_32_bits(pci_addr));
dw_pcie_writel_dbi(pci, PCIE_ATU_CR1, type);
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, PCIE_ATU_ENABLE);
}
/*
* Make sure ATU enable takes effect before any subsequent config
* and I/O accesses.
*/
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
if (pci->iatu_unroll_enabled)
val = dw_pcie_readl_unroll(pci, index,
PCIE_ATU_UNR_REGION_CTRL2);
else
val = dw_pcie_readl_dbi(pci, PCIE_ATU_CR2);
if (val == PCIE_ATU_ENABLE)
return;
usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX);
}
dev_err(pci->dev, "iATU is not being enabled\n");
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Joao Pinto | 128 | 43.24% | 2 | 22.22% |
JiSheng Zhang | 85 | 28.72% | 1 | 11.11% |
Björn Helgaas | 32 | 10.81% | 3 | 33.33% |
Kishon Vijay Abraham I | 31 | 10.47% | 1 | 11.11% |
Stanimir Varbanov | 13 | 4.39% | 1 | 11.11% |
Jingoo Han | 7 | 2.36% | 1 | 11.11% |
Total | 296 | 100.00% | 9 | 100.00% |
int dw_pcie_wait_for_link(struct dw_pcie *pci)
{
int retries;
/* check if the link is up or not */
for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) {
if (dw_pcie_link_up(pci)) {
dev_info(pci->dev, "link up\n");
return 0;
}
usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX);
}
dev_err(pci->dev, "phy link never came up\n");
return -ETIMEDOUT;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kishon Vijay Abraham I | 32 | 45.71% | 1 | 20.00% |
Jingoo Han | 31 | 44.29% | 1 | 20.00% |
Harro Haan | 3 | 4.29% | 1 | 20.00% |
Lucas Stach | 3 | 4.29% | 1 | 20.00% |
Pratyush Anand | 1 | 1.43% | 1 | 20.00% |
Total | 70 | 100.00% | 5 | 100.00% |
int dw_pcie_link_up(struct dw_pcie *pci)
{
u32 val;
if (pci->ops->link_up)
return pci->ops->link_up(pci);
val = readl(pci->dbi_base + PCIE_PHY_DEBUG_R1);
return ((val & PCIE_PHY_DEBUG_R1_LINK_UP) &&
(!(val & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING)));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kishon Vijay Abraham I | 42 | 70.00% | 1 | 20.00% |
Jingoo Han | 14 | 23.33% | 2 | 40.00% |
Murali Karicheri | 2 | 3.33% | 1 | 20.00% |
Björn Helgaas | 2 | 3.33% | 1 | 20.00% |
Total | 60 | 100.00% | 5 | 100.00% |
void dw_pcie_setup(struct dw_pcie *pci)
{
int ret;
u32 val;
u32 lanes;
struct device *dev = pci->dev;
struct device_node *np = dev->of_node;
ret = of_property_read_u32(np, "num-lanes", &lanes);
if (ret)
lanes = 0;
/* set the number of lanes */
val = dw_pcie_readl_dbi(pci, PCIE_PORT_LINK_CONTROL);
val &= ~PORT_LINK_MODE_MASK;
switch (lanes) {
case 1:
val |= PORT_LINK_MODE_1_LANES;
break;
case 2:
val |= PORT_LINK_MODE_2_LANES;
break;
case 4:
val |= PORT_LINK_MODE_4_LANES;
break;
case 8:
val |= PORT_LINK_MODE_8_LANES;
break;
default:
dev_err(pci->dev, "num-lanes %u: invalid value\n", lanes);
return;
}
dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val);
/* set link width speed control register */
val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
val &= ~PORT_LOGIC_LINK_WIDTH_MASK;
switch (lanes) {
case 1:
val |= PORT_LOGIC_LINK_WIDTH_1_LANES;
break;
case 2:
val |= PORT_LOGIC_LINK_WIDTH_2_LANES;
break;
case 4:
val |= PORT_LOGIC_LINK_WIDTH_4_LANES;
break;
case 8:
val |= PORT_LOGIC_LINK_WIDTH_8_LANES;
break;
}
dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 100 | 51.55% | 2 | 20.00% |
Kishon Vijay Abraham I | 57 | 29.38% | 3 | 30.00% |
Zhou Wang | 16 | 8.25% | 1 | 10.00% |
Gabriele Paoloni | 12 | 6.19% | 1 | 10.00% |
Björn Helgaas | 8 | 4.12% | 2 | 20.00% |
Mohit Kumar | 1 | 0.52% | 1 | 10.00% |
Total | 194 | 100.00% | 10 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jingoo Han | 342 | 34.20% | 3 | 10.34% |
Kishon Vijay Abraham I | 200 | 20.00% | 6 | 20.69% |
Joao Pinto | 182 | 18.20% | 3 | 10.34% |
JiSheng Zhang | 90 | 9.00% | 2 | 6.90% |
Gabriele Paoloni | 76 | 7.60% | 3 | 10.34% |
Björn Helgaas | 55 | 5.50% | 4 | 13.79% |
Seungwon Jeon | 16 | 1.60% | 1 | 3.45% |
Zhou Wang | 16 | 1.60% | 1 | 3.45% |
Stanimir Varbanov | 13 | 1.30% | 1 | 3.45% |
Harro Haan | 3 | 0.30% | 1 | 3.45% |
Lucas Stach | 3 | 0.30% | 1 | 3.45% |
Murali Karicheri | 2 | 0.20% | 1 | 3.45% |
Pratyush Anand | 1 | 0.10% | 1 | 3.45% |
Mohit Kumar | 1 | 0.10% | 1 | 3.45% |
Total | 1000 | 100.00% | 29 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.