blob: 3321da945f0f26599ec51936cedfb978fec6a227 [file] [log] [blame]
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -06001/*
2 * pcie-dra7xx - PCIe controller driver for TI DRA7xx SoCs
3 *
4 * Copyright (C) 2013-2014 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Authors: Kishon Vijay Abraham I <kishon@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +053013#include <linux/delay.h>
Kishon Vijay Abraham I7a4db652017-10-09 14:33:37 +053014#include <linux/device.h>
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060015#include <linux/err.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
18#include <linux/irqdomain.h>
19#include <linux/kernel.h>
Paul Gortmakerd29438d2016-08-24 16:57:47 -040020#include <linux/init.h>
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +053021#include <linux/of_device.h>
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +053022#include <linux/of_gpio.h>
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +053023#include <linux/of_pci.h>
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060024#include <linux/pci.h>
25#include <linux/phy/phy.h>
26#include <linux/platform_device.h>
27#include <linux/pm_runtime.h>
28#include <linux/resource.h>
29#include <linux/types.h>
Kishon Vijay Abraham If7a27572017-03-27 15:15:11 +053030#include <linux/mfd/syscon.h>
31#include <linux/regmap.h>
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060032
33#include "pcie-designware.h"
34
35/* PCIe controller wrapper DRA7XX configuration registers */
36
37#define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN 0x0024
38#define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN 0x0028
39#define ERR_SYS BIT(0)
40#define ERR_FATAL BIT(1)
41#define ERR_NONFATAL BIT(2)
42#define ERR_COR BIT(3)
43#define ERR_AXI BIT(4)
44#define ERR_ECRC BIT(5)
45#define PME_TURN_OFF BIT(8)
46#define PME_TO_ACK BIT(9)
47#define PM_PME BIT(10)
48#define LINK_REQ_RST BIT(11)
49#define LINK_UP_EVT BIT(12)
50#define CFG_BME_EVT BIT(13)
51#define CFG_MSE_EVT BIT(14)
52#define INTERRUPTS (ERR_SYS | ERR_FATAL | ERR_NONFATAL | ERR_COR | ERR_AXI | \
53 ERR_ECRC | PME_TURN_OFF | PME_TO_ACK | PM_PME | \
54 LINK_REQ_RST | LINK_UP_EVT | CFG_BME_EVT | CFG_MSE_EVT)
55
56#define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI 0x0034
57#define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI 0x0038
58#define INTA BIT(0)
59#define INTB BIT(1)
60#define INTC BIT(2)
61#define INTD BIT(3)
62#define MSI BIT(4)
63#define LEG_EP_INTERRUPTS (INTA | INTB | INTC | INTD)
64
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +053065#define PCIECTRL_TI_CONF_DEVICE_TYPE 0x0100
66#define DEVICE_TYPE_EP 0x0
67#define DEVICE_TYPE_LEG_EP 0x1
68#define DEVICE_TYPE_RC 0x4
69
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060070#define PCIECTRL_DRA7XX_CONF_DEVICE_CMD 0x0104
71#define LTSSM_EN 0x1
72
73#define PCIECTRL_DRA7XX_CONF_PHY_CS 0x010C
74#define LINK_UP BIT(16)
Gabriele Paoloni883cc172015-10-29 19:56:51 -050075#define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060076
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +053077#define EXP_CAP_ID_OFFSET 0x70
78
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +053079#define PCIECTRL_TI_CONF_INTX_ASSERT 0x0124
80#define PCIECTRL_TI_CONF_INTX_DEASSERT 0x0128
81
82#define PCIECTRL_TI_CONF_MSI_XMT 0x012c
83#define MSI_REQ_GRANT BIT(0)
84#define MSI_VECTOR_SHIFT 7
85
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060086struct dra7xx_pcie {
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +053087 struct dw_pcie *pci;
Bjorn Helgaas8e5ec412016-10-06 13:33:06 -050088 void __iomem *base; /* DT ti_conf */
89 int phy_count; /* DT phy-names count */
90 struct phy **phy;
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +053091 int link_gen;
Kishon Vijay Abraham Iebe85a42017-01-11 17:36:54 +053092 struct irq_domain *irq_domain;
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +053093 enum dw_pcie_device_mode mode;
94};
95
96struct dra7xx_pcie_of_data {
97 enum dw_pcie_device_mode mode;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060098};
99
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530100#define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600101
102static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
103{
104 return readl(pcie->base + offset);
105}
106
107static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset,
108 u32 value)
109{
110 writel(value, pcie->base + offset);
111}
112
Niklas Casselb6900ae2017-12-20 00:29:36 +0100113static u64 dra7xx_pcie_cpu_addr_fixup(struct dw_pcie *pci, u64 pci_addr)
Kishon Vijay Abraham I2ed6cc72017-03-13 19:13:23 +0530114{
115 return pci_addr & DRA7XX_CPU_TO_BUS_ADDR;
116}
117
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530118static int dra7xx_pcie_link_up(struct dw_pcie *pci)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600119{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530120 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600121 u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
122
123 return !!(reg & LINK_UP);
124}
125
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530126static void dra7xx_pcie_stop_link(struct dw_pcie *pci)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600127{
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530128 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
129 u32 reg;
130
131 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
132 reg &= ~LTSSM_EN;
133 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
134}
135
136static int dra7xx_pcie_establish_link(struct dw_pcie *pci)
137{
138 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530139 struct device *dev = pci->dev;
Bjorn Helgaas6cbb2472015-06-02 16:47:17 -0500140 u32 reg;
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530141 u32 exp_cap_off = EXP_CAP_ID_OFFSET;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600142
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530143 if (dw_pcie_link_up(pci)) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500144 dev_err(dev, "link is already up\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600145 return 0;
146 }
147
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530148 if (dra7xx->link_gen == 1) {
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530149 dw_pcie_read(pci->dbi_base + exp_cap_off + PCI_EXP_LNKCAP,
Kishon Vijay Abraham I19ce01cc2017-02-15 18:48:12 +0530150 4, &reg);
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530151 if ((reg & PCI_EXP_LNKCAP_SLS) != PCI_EXP_LNKCAP_SLS_2_5GB) {
152 reg &= ~((u32)PCI_EXP_LNKCAP_SLS);
153 reg |= PCI_EXP_LNKCAP_SLS_2_5GB;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530154 dw_pcie_write(pci->dbi_base + exp_cap_off +
Kishon Vijay Abraham I19ce01cc2017-02-15 18:48:12 +0530155 PCI_EXP_LNKCAP, 4, reg);
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530156 }
157
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530158 dw_pcie_read(pci->dbi_base + exp_cap_off + PCI_EXP_LNKCTL2,
Kishon Vijay Abraham I19ce01cc2017-02-15 18:48:12 +0530159 2, &reg);
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530160 if ((reg & PCI_EXP_LNKCAP_SLS) != PCI_EXP_LNKCAP_SLS_2_5GB) {
161 reg &= ~((u32)PCI_EXP_LNKCAP_SLS);
162 reg |= PCI_EXP_LNKCAP_SLS_2_5GB;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530163 dw_pcie_write(pci->dbi_base + exp_cap_off +
Kishon Vijay Abraham I19ce01cc2017-02-15 18:48:12 +0530164 PCI_EXP_LNKCTL2, 2, reg);
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530165 }
166 }
167
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600168 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
169 reg |= LTSSM_EN;
170 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
171
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530172 return 0;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600173}
174
Kishon Vijay Abraham I5ffd90a2017-03-27 15:15:07 +0530175static void dra7xx_pcie_enable_msi_interrupts(struct dra7xx_pcie *dra7xx)
176{
177 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
Arvind Yadav40aa52c2017-06-19 15:21:36 +0530178 LEG_EP_INTERRUPTS | MSI);
Kishon Vijay Abraham I5ffd90a2017-03-27 15:15:07 +0530179
180 dra7xx_pcie_writel(dra7xx,
181 PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
182 MSI | LEG_EP_INTERRUPTS);
183}
184
185static void dra7xx_pcie_enable_wrapper_interrupts(struct dra7xx_pcie *dra7xx)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600186{
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600187 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
Arvind Yadav40aa52c2017-06-19 15:21:36 +0530188 INTERRUPTS);
Kishon Vijay Abraham I5ffd90a2017-03-27 15:15:07 +0530189 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN,
190 INTERRUPTS);
191}
192
193static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie *dra7xx)
194{
195 dra7xx_pcie_enable_wrapper_interrupts(dra7xx);
196 dra7xx_pcie_enable_msi_interrupts(dra7xx);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600197}
198
Bjorn Andersson4a301762017-07-15 23:39:45 -0700199static int dra7xx_pcie_host_init(struct pcie_port *pp)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600200{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530201 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
202 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
Bjorn Helgaas21baa1c2016-10-06 13:33:05 -0500203
Jisheng Zhang7e57fd12016-03-16 19:40:33 +0800204 dw_pcie_setup_rc(pp);
205
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530206 dra7xx_pcie_establish_link(pci);
207 dw_pcie_wait_for_link(pci);
Kishon Vijay Abraham Iebe85a42017-01-11 17:36:54 +0530208 dw_pcie_msi_init(pp);
Bjorn Helgaas21baa1c2016-10-06 13:33:05 -0500209 dra7xx_pcie_enable_interrupts(dra7xx);
Bjorn Andersson4a301762017-07-15 23:39:45 -0700210
211 return 0;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600212}
213
Jisheng Zhang4ab2e7c2017-06-05 16:53:46 +0800214static const struct dw_pcie_host_ops dra7xx_pcie_host_ops = {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600215 .host_init = dra7xx_pcie_host_init,
216};
217
218static int dra7xx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
219 irq_hw_number_t hwirq)
220{
221 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
222 irq_set_chip_data(irq, domain->host_data);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600223
224 return 0;
225}
226
227static const struct irq_domain_ops intx_domain_ops = {
228 .map = dra7xx_pcie_intx_map,
Vignesh R524d59f2017-12-29 17:11:30 +0530229 .xlate = pci_irqd_intx_xlate,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600230};
231
232static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
233{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530234 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
235 struct device *dev = pci->dev;
236 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600237 struct device_node *node = dev->of_node;
238 struct device_node *pcie_intc_node = of_get_next_child(node, NULL);
239
240 if (!pcie_intc_node) {
241 dev_err(dev, "No PCIe Intc node found\n");
Christophe JAILLET991bfef2016-07-14 23:18:27 +0200242 return -ENODEV;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600243 }
244
Bjorn Helgaas61534d12017-08-15 16:28:27 -0500245 dra7xx->irq_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
Kishon Vijay Abraham Iebe85a42017-01-11 17:36:54 +0530246 &intx_domain_ops, pp);
247 if (!dra7xx->irq_domain) {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600248 dev_err(dev, "Failed to get a INTx IRQ domain\n");
Christophe JAILLET991bfef2016-07-14 23:18:27 +0200249 return -ENODEV;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600250 }
251
252 return 0;
253}
254
255static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
256{
Bjorn Helgaas21baa1c2016-10-06 13:33:05 -0500257 struct dra7xx_pcie *dra7xx = arg;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530258 struct dw_pcie *pci = dra7xx->pci;
259 struct pcie_port *pp = &pci->pp;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600260 u32 reg;
261
262 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI);
263
264 switch (reg) {
265 case MSI:
266 dw_handle_msi_irq(pp);
267 break;
268 case INTA:
269 case INTB:
270 case INTC:
271 case INTD:
Kishon Vijay Abraham Iebe85a42017-01-11 17:36:54 +0530272 generic_handle_irq(irq_find_mapping(dra7xx->irq_domain,
Vignesh R524d59f2017-12-29 17:11:30 +0530273 ffs(reg) - 1));
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600274 break;
275 }
276
277 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI, reg);
278
279 return IRQ_HANDLED;
280}
281
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600282static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
283{
284 struct dra7xx_pcie *dra7xx = arg;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530285 struct dw_pcie *pci = dra7xx->pci;
286 struct device *dev = pci->dev;
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530287 struct dw_pcie_ep *ep = &pci->ep;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600288 u32 reg;
289
290 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN);
291
292 if (reg & ERR_SYS)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500293 dev_dbg(dev, "System Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600294
295 if (reg & ERR_FATAL)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500296 dev_dbg(dev, "Fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600297
298 if (reg & ERR_NONFATAL)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500299 dev_dbg(dev, "Non Fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600300
301 if (reg & ERR_COR)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500302 dev_dbg(dev, "Correctable Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600303
304 if (reg & ERR_AXI)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500305 dev_dbg(dev, "AXI tag lookup fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600306
307 if (reg & ERR_ECRC)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500308 dev_dbg(dev, "ECRC Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600309
310 if (reg & PME_TURN_OFF)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500311 dev_dbg(dev,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600312 "Power Management Event Turn-Off message received\n");
313
314 if (reg & PME_TO_ACK)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500315 dev_dbg(dev,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600316 "Power Management Turn-Off Ack message received\n");
317
318 if (reg & PM_PME)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500319 dev_dbg(dev, "PM Power Management Event message received\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600320
321 if (reg & LINK_REQ_RST)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500322 dev_dbg(dev, "Link Request Reset\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600323
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530324 if (reg & LINK_UP_EVT) {
325 if (dra7xx->mode == DW_PCIE_EP_TYPE)
326 dw_pcie_ep_linkup(ep);
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500327 dev_dbg(dev, "Link-up state change\n");
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530328 }
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600329
330 if (reg & CFG_BME_EVT)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500331 dev_dbg(dev, "CFG 'Bus Master Enable' change\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600332
333 if (reg & CFG_MSE_EVT)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500334 dev_dbg(dev, "CFG 'Memory Space Enable' change\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600335
336 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN, reg);
337
338 return IRQ_HANDLED;
339}
340
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530341static void dra7xx_pcie_ep_init(struct dw_pcie_ep *ep)
342{
343 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
344 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
Kishon Vijay Abraham I85aa1392017-08-18 20:28:03 +0530345 enum pci_barno bar;
346
347 for (bar = BAR_0; bar <= BAR_5; bar++)
348 dw_pcie_ep_reset_bar(pci, bar);
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530349
350 dra7xx_pcie_enable_wrapper_interrupts(dra7xx);
351}
352
353static void dra7xx_pcie_raise_legacy_irq(struct dra7xx_pcie *dra7xx)
354{
355 dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_INTX_ASSERT, 0x1);
356 mdelay(1);
357 dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_INTX_DEASSERT, 0x1);
358}
359
360static void dra7xx_pcie_raise_msi_irq(struct dra7xx_pcie *dra7xx,
361 u8 interrupt_num)
362{
363 u32 reg;
364
365 reg = (interrupt_num - 1) << MSI_VECTOR_SHIFT;
366 reg |= MSI_REQ_GRANT;
367 dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_MSI_XMT, reg);
368}
369
370static int dra7xx_pcie_raise_irq(struct dw_pcie_ep *ep,
371 enum pci_epc_irq_type type, u8 interrupt_num)
372{
373 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
374 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
375
376 switch (type) {
377 case PCI_EPC_IRQ_LEGACY:
378 dra7xx_pcie_raise_legacy_irq(dra7xx);
379 break;
380 case PCI_EPC_IRQ_MSI:
381 dra7xx_pcie_raise_msi_irq(dra7xx, interrupt_num);
382 break;
383 default:
384 dev_err(pci->dev, "UNKNOWN IRQ type\n");
385 }
386
387 return 0;
388}
389
390static struct dw_pcie_ep_ops pcie_ep_ops = {
391 .ep_init = dra7xx_pcie_ep_init,
392 .raise_irq = dra7xx_pcie_raise_irq,
393};
394
395static int __init dra7xx_add_pcie_ep(struct dra7xx_pcie *dra7xx,
396 struct platform_device *pdev)
397{
398 int ret;
399 struct dw_pcie_ep *ep;
400 struct resource *res;
401 struct device *dev = &pdev->dev;
402 struct dw_pcie *pci = dra7xx->pci;
403
404 ep = &pci->ep;
405 ep->ops = &pcie_ep_ops;
406
407 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics");
408 pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res));
409 if (!pci->dbi_base)
410 return -ENOMEM;
411
412 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ep_dbics2");
413 pci->dbi_base2 = devm_ioremap(dev, res->start, resource_size(res));
414 if (!pci->dbi_base2)
415 return -ENOMEM;
416
417 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
418 if (!res)
419 return -EINVAL;
420
421 ep->phys_base = res->start;
422 ep->addr_size = resource_size(res);
423
424 ret = dw_pcie_ep_init(ep);
425 if (ret) {
426 dev_err(dev, "failed to initialize endpoint\n");
427 return ret;
428 }
429
430 return 0;
431}
432
Jingoo Hane73044a2014-11-06 14:37:39 +0900433static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
434 struct platform_device *pdev)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600435{
436 int ret;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530437 struct dw_pcie *pci = dra7xx->pci;
438 struct pcie_port *pp = &pci->pp;
439 struct device *dev = pci->dev;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600440 struct resource *res;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600441
442 pp->irq = platform_get_irq(pdev, 1);
443 if (pp->irq < 0) {
444 dev_err(dev, "missing IRQ resource\n");
Fabio Estevam2f3ec752017-08-31 14:52:02 -0300445 return pp->irq;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600446 }
447
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500448 ret = devm_request_irq(dev, pp->irq, dra7xx_pcie_msi_irq_handler,
Grygorii Strashko8ff0ef92015-12-10 21:18:20 +0200449 IRQF_SHARED | IRQF_NO_THREAD,
Bjorn Helgaas21baa1c2016-10-06 13:33:05 -0500450 "dra7-pcie-msi", dra7xx);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600451 if (ret) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500452 dev_err(dev, "failed to request irq\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600453 return ret;
454 }
455
Kishon Vijay Abraham Iebe85a42017-01-11 17:36:54 +0530456 ret = dra7xx_pcie_init_irq_domain(pp);
457 if (ret < 0)
458 return ret;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600459
460 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbics");
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530461 pci->dbi_base = devm_ioremap(dev, res->start, resource_size(res));
462 if (!pci->dbi_base)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600463 return -ENOMEM;
464
Niklas Cassel71890ea2017-12-20 00:29:29 +0100465 pp->ops = &dra7xx_pcie_host_ops;
466
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600467 ret = dw_pcie_host_init(pp);
468 if (ret) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500469 dev_err(dev, "failed to initialize host\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600470 return ret;
471 }
472
473 return 0;
474}
475
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530476static const struct dw_pcie_ops dw_pcie_ops = {
Kishon Vijay Abraham I2ed6cc72017-03-13 19:13:23 +0530477 .cpu_addr_fixup = dra7xx_pcie_cpu_addr_fixup,
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530478 .start_link = dra7xx_pcie_establish_link,
479 .stop_link = dra7xx_pcie_stop_link,
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530480 .link_up = dra7xx_pcie_link_up,
481};
482
Kishon Vijay Abraham I1f6c4502017-01-11 17:36:55 +0530483static void dra7xx_pcie_disable_phy(struct dra7xx_pcie *dra7xx)
484{
485 int phy_count = dra7xx->phy_count;
486
487 while (phy_count--) {
488 phy_power_off(dra7xx->phy[phy_count]);
489 phy_exit(dra7xx->phy[phy_count]);
490 }
491}
492
493static int dra7xx_pcie_enable_phy(struct dra7xx_pcie *dra7xx)
494{
495 int phy_count = dra7xx->phy_count;
496 int ret;
497 int i;
498
499 for (i = 0; i < phy_count; i++) {
500 ret = phy_init(dra7xx->phy[i]);
501 if (ret < 0)
502 goto err_phy;
503
504 ret = phy_power_on(dra7xx->phy[i]);
505 if (ret < 0) {
506 phy_exit(dra7xx->phy[i]);
507 goto err_phy;
508 }
509 }
510
511 return 0;
512
513err_phy:
514 while (--i >= 0) {
515 phy_power_off(dra7xx->phy[i]);
516 phy_exit(dra7xx->phy[i]);
517 }
518
519 return ret;
520}
521
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530522static const struct dra7xx_pcie_of_data dra7xx_pcie_rc_of_data = {
523 .mode = DW_PCIE_RC_TYPE,
524};
525
526static const struct dra7xx_pcie_of_data dra7xx_pcie_ep_of_data = {
527 .mode = DW_PCIE_EP_TYPE,
528};
529
530static const struct of_device_id of_dra7xx_pcie_match[] = {
531 {
532 .compatible = "ti,dra7-pcie",
533 .data = &dra7xx_pcie_rc_of_data,
534 },
535 {
536 .compatible = "ti,dra7-pcie-ep",
537 .data = &dra7xx_pcie_ep_of_data,
538 },
539 {},
540};
541
Kishon Vijay Abraham If7a27572017-03-27 15:15:11 +0530542/*
543 * dra7xx_pcie_ep_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
544 * @dra7xx: the dra7xx device where the workaround should be applied
545 *
546 * Access to the PCIe slave port that are not 32-bit aligned will result
547 * in incorrect mapping to TLP Address and Byte enable fields. Therefore,
548 * byte and half-word accesses are not possible to byte offset 0x1, 0x2, or
549 * 0x3.
550 *
551 * To avoid this issue set PCIE_SS1_AXI2OCP_LEGACY_MODE_ENABLE to 1.
552 */
553static int dra7xx_pcie_ep_unaligned_memaccess(struct device *dev)
554{
555 int ret;
556 struct device_node *np = dev->of_node;
557 struct of_phandle_args args;
558 struct regmap *regmap;
559
560 regmap = syscon_regmap_lookup_by_phandle(np,
561 "ti,syscon-unaligned-access");
562 if (IS_ERR(regmap)) {
563 dev_dbg(dev, "can't get ti,syscon-unaligned-access\n");
564 return -EINVAL;
565 }
566
567 ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-unaligned-access",
568 2, 0, &args);
569 if (ret) {
570 dev_err(dev, "failed to parse ti,syscon-unaligned-access\n");
571 return ret;
572 }
573
574 ret = regmap_update_bits(regmap, args.args[0], args.args[1],
575 args.args[1]);
576 if (ret)
577 dev_err(dev, "failed to enable unaligned access\n");
578
579 of_node_put(args.np);
580
581 return ret;
582}
583
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600584static int __init dra7xx_pcie_probe(struct platform_device *pdev)
585{
586 u32 reg;
587 int ret;
588 int irq;
589 int i;
590 int phy_count;
591 struct phy **phy;
Kishon Vijay Abraham I7a4db652017-10-09 14:33:37 +0530592 struct device_link **link;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600593 void __iomem *base;
594 struct resource *res;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530595 struct dw_pcie *pci;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530596 struct dra7xx_pcie *dra7xx;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600597 struct device *dev = &pdev->dev;
598 struct device_node *np = dev->of_node;
599 char name[10];
Kishon Vijay Abraham I602d38b2017-01-11 17:36:52 +0530600 struct gpio_desc *reset;
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530601 const struct of_device_id *match;
602 const struct dra7xx_pcie_of_data *data;
603 enum dw_pcie_device_mode mode;
604
605 match = of_match_device(of_match_ptr(of_dra7xx_pcie_match), dev);
606 if (!match)
607 return -EINVAL;
608
609 data = (struct dra7xx_pcie_of_data *)match->data;
610 mode = (enum dw_pcie_device_mode)data->mode;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600611
612 dra7xx = devm_kzalloc(dev, sizeof(*dra7xx), GFP_KERNEL);
613 if (!dra7xx)
614 return -ENOMEM;
615
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530616 pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
617 if (!pci)
618 return -ENOMEM;
619
620 pci->dev = dev;
621 pci->ops = &dw_pcie_ops;
622
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600623 irq = platform_get_irq(pdev, 0);
624 if (irq < 0) {
Gustavo A. R. Silvaa0d21ba2017-08-09 11:16:03 -0500625 dev_err(dev, "missing IRQ resource: %d\n", irq);
626 return irq;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600627 }
628
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600629 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ti_conf");
630 base = devm_ioremap_nocache(dev, res->start, resource_size(res));
631 if (!base)
632 return -ENOMEM;
633
634 phy_count = of_property_count_strings(np, "phy-names");
635 if (phy_count < 0) {
636 dev_err(dev, "unable to find the strings\n");
637 return phy_count;
638 }
639
640 phy = devm_kzalloc(dev, sizeof(*phy) * phy_count, GFP_KERNEL);
641 if (!phy)
642 return -ENOMEM;
643
Kishon Vijay Abraham I7a4db652017-10-09 14:33:37 +0530644 link = devm_kzalloc(dev, sizeof(*link) * phy_count, GFP_KERNEL);
645 if (!link)
646 return -ENOMEM;
647
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600648 for (i = 0; i < phy_count; i++) {
649 snprintf(name, sizeof(name), "pcie-phy%d", i);
650 phy[i] = devm_phy_get(dev, name);
651 if (IS_ERR(phy[i]))
652 return PTR_ERR(phy[i]);
Kishon Vijay Abraham I7a4db652017-10-09 14:33:37 +0530653
654 link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS);
655 if (!link[i]) {
656 ret = -EINVAL;
657 goto err_link;
658 }
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600659 }
660
661 dra7xx->base = base;
662 dra7xx->phy = phy;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530663 dra7xx->pci = pci;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600664 dra7xx->phy_count = phy_count;
665
Kishon Vijay Abraham I1f6c4502017-01-11 17:36:55 +0530666 ret = dra7xx_pcie_enable_phy(dra7xx);
667 if (ret) {
668 dev_err(dev, "failed to enable phy\n");
669 return ret;
670 }
671
Kishon Vijay Abraham I9bcf0a62017-02-15 18:48:11 +0530672 platform_set_drvdata(pdev, dra7xx);
673
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600674 pm_runtime_enable(dev);
675 ret = pm_runtime_get_sync(dev);
Fabio Estevamd3f4caa2015-08-20 01:30:36 -0500676 if (ret < 0) {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600677 dev_err(dev, "pm_runtime_get_sync failed\n");
Kishon Vijay Abraham I0e2bdb02015-07-31 17:55:10 +0530678 goto err_get_sync;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600679 }
680
Kishon Vijay Abraham I602d38b2017-01-11 17:36:52 +0530681 reset = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
682 if (IS_ERR(reset)) {
683 ret = PTR_ERR(reset);
684 dev_err(&pdev->dev, "gpio request failed, ret %d\n", ret);
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530685 goto err_gpio;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600686 }
687
688 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
689 reg &= ~LTSSM_EN;
690 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
691
Kishon Vijay Abraham Iab5fe4f2017-01-11 17:36:53 +0530692 dra7xx->link_gen = of_pci_get_max_link_speed(np);
693 if (dra7xx->link_gen < 0 || dra7xx->link_gen > 2)
694 dra7xx->link_gen = 2;
695
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530696 switch (mode) {
697 case DW_PCIE_RC_TYPE:
Niklas Casself1aba0a2017-12-20 00:29:30 +0100698 if (!IS_ENABLED(CONFIG_PCI_DRA7XX_HOST)) {
699 ret = -ENODEV;
700 goto err_gpio;
701 }
702
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530703 dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
704 DEVICE_TYPE_RC);
705 ret = dra7xx_add_pcie_port(dra7xx, pdev);
706 if (ret < 0)
707 goto err_gpio;
708 break;
709 case DW_PCIE_EP_TYPE:
Niklas Casself1aba0a2017-12-20 00:29:30 +0100710 if (!IS_ENABLED(CONFIG_PCI_DRA7XX_EP)) {
711 ret = -ENODEV;
712 goto err_gpio;
713 }
714
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530715 dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
716 DEVICE_TYPE_EP);
Kishon Vijay Abraham If7a27572017-03-27 15:15:11 +0530717
718 ret = dra7xx_pcie_ep_unaligned_memaccess(dev);
719 if (ret)
720 goto err_gpio;
721
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530722 ret = dra7xx_add_pcie_ep(dra7xx, pdev);
723 if (ret < 0)
724 goto err_gpio;
725 break;
726 default:
727 dev_err(dev, "INVALID device type %d\n", mode);
728 }
729 dra7xx->mode = mode;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600730
Keerthyd4c7d1a2017-03-13 19:13:28 +0530731 ret = devm_request_irq(dev, irq, dra7xx_pcie_irq_handler,
732 IRQF_SHARED, "dra7xx-pcie-main", dra7xx);
733 if (ret) {
734 dev_err(dev, "failed to request irq\n");
735 goto err_gpio;
736 }
737
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600738 return 0;
739
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530740err_gpio:
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600741 pm_runtime_put(dev);
Kishon Vijay Abraham I0e2bdb02015-07-31 17:55:10 +0530742
743err_get_sync:
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600744 pm_runtime_disable(dev);
Kishon Vijay Abraham I1f6c4502017-01-11 17:36:55 +0530745 dra7xx_pcie_disable_phy(dra7xx);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600746
Kishon Vijay Abraham I7a4db652017-10-09 14:33:37 +0530747err_link:
748 while (--i >= 0)
749 device_link_del(link[i]);
750
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600751 return ret;
752}
753
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530754#ifdef CONFIG_PM_SLEEP
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530755static int dra7xx_pcie_suspend(struct device *dev)
756{
757 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530758 struct dw_pcie *pci = dra7xx->pci;
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530759 u32 val;
760
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530761 if (dra7xx->mode != DW_PCIE_RC_TYPE)
762 return 0;
763
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530764 /* clear MSE */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530765 val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530766 val &= ~PCI_COMMAND_MEMORY;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530767 dw_pcie_writel_dbi(pci, PCI_COMMAND, val);
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530768
769 return 0;
770}
771
772static int dra7xx_pcie_resume(struct device *dev)
773{
774 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530775 struct dw_pcie *pci = dra7xx->pci;
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530776 u32 val;
777
Kishon Vijay Abraham I608793e2017-03-27 15:15:08 +0530778 if (dra7xx->mode != DW_PCIE_RC_TYPE)
779 return 0;
780
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530781 /* set MSE */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530782 val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530783 val |= PCI_COMMAND_MEMORY;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530784 dw_pcie_writel_dbi(pci, PCI_COMMAND, val);
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530785
786 return 0;
787}
788
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530789static int dra7xx_pcie_suspend_noirq(struct device *dev)
790{
791 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530792
Kishon Vijay Abraham I1f6c4502017-01-11 17:36:55 +0530793 dra7xx_pcie_disable_phy(dra7xx);
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530794
795 return 0;
796}
797
798static int dra7xx_pcie_resume_noirq(struct device *dev)
799{
800 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530801 int ret;
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530802
Kishon Vijay Abraham I1f6c4502017-01-11 17:36:55 +0530803 ret = dra7xx_pcie_enable_phy(dra7xx);
804 if (ret) {
805 dev_err(dev, "failed to enable phy\n");
806 return ret;
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530807 }
808
809 return 0;
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530810}
811#endif
812
Vignesh R4751fac2017-12-01 10:36:52 +0530813static void dra7xx_pcie_shutdown(struct platform_device *pdev)
Keerthy9c049be2017-09-20 10:54:15 +0530814{
815 struct device *dev = &pdev->dev;
816 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
817 int ret;
818
819 dra7xx_pcie_stop_link(dra7xx->pci);
820
821 ret = pm_runtime_put_sync(dev);
822 if (ret < 0)
823 dev_dbg(dev, "pm_runtime_put_sync failed\n");
824
825 pm_runtime_disable(dev);
826 dra7xx_pcie_disable_phy(dra7xx);
827}
828
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530829static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530830 SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume)
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530831 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
832 dra7xx_pcie_resume_noirq)
833};
834
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600835static struct platform_driver dra7xx_pcie_driver = {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600836 .driver = {
837 .name = "dra7-pcie",
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600838 .of_match_table = of_dra7xx_pcie_match,
Paul Gortmakerd29438d2016-08-24 16:57:47 -0400839 .suppress_bind_attrs = true,
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530840 .pm = &dra7xx_pcie_pm_ops,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600841 },
Keerthy9c049be2017-09-20 10:54:15 +0530842 .shutdown = dra7xx_pcie_shutdown,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600843};
Paul Gortmakerd29438d2016-08-24 16:57:47 -0400844builtin_platform_driver_probe(dra7xx_pcie_driver, dra7xx_pcie_probe);