blob: 23236796d70959f768958d5a91908bf36affdf8d [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 I47ff3de2014-07-22 15:23:45 -060013#include <linux/err.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/irqdomain.h>
17#include <linux/kernel.h>
Paul Gortmakerd29438d2016-08-24 16:57:47 -040018#include <linux/init.h>
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +053019#include <linux/of_gpio.h>
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060020#include <linux/pci.h>
21#include <linux/phy/phy.h>
22#include <linux/platform_device.h>
23#include <linux/pm_runtime.h>
24#include <linux/resource.h>
25#include <linux/types.h>
26
27#include "pcie-designware.h"
28
29/* PCIe controller wrapper DRA7XX configuration registers */
30
31#define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN 0x0024
32#define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN 0x0028
33#define ERR_SYS BIT(0)
34#define ERR_FATAL BIT(1)
35#define ERR_NONFATAL BIT(2)
36#define ERR_COR BIT(3)
37#define ERR_AXI BIT(4)
38#define ERR_ECRC BIT(5)
39#define PME_TURN_OFF BIT(8)
40#define PME_TO_ACK BIT(9)
41#define PM_PME BIT(10)
42#define LINK_REQ_RST BIT(11)
43#define LINK_UP_EVT BIT(12)
44#define CFG_BME_EVT BIT(13)
45#define CFG_MSE_EVT BIT(14)
46#define INTERRUPTS (ERR_SYS | ERR_FATAL | ERR_NONFATAL | ERR_COR | ERR_AXI | \
47 ERR_ECRC | PME_TURN_OFF | PME_TO_ACK | PM_PME | \
48 LINK_REQ_RST | LINK_UP_EVT | CFG_BME_EVT | CFG_MSE_EVT)
49
50#define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI 0x0034
51#define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI 0x0038
52#define INTA BIT(0)
53#define INTB BIT(1)
54#define INTC BIT(2)
55#define INTD BIT(3)
56#define MSI BIT(4)
57#define LEG_EP_INTERRUPTS (INTA | INTB | INTC | INTD)
58
59#define PCIECTRL_DRA7XX_CONF_DEVICE_CMD 0x0104
60#define LTSSM_EN 0x1
61
62#define PCIECTRL_DRA7XX_CONF_PHY_CS 0x010C
63#define LINK_UP BIT(16)
Gabriele Paoloni883cc172015-10-29 19:56:51 -050064#define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060065
66struct dra7xx_pcie {
67 void __iomem *base;
68 struct phy **phy;
69 int phy_count;
70 struct device *dev;
71 struct pcie_port pp;
72};
73
74#define to_dra7xx_pcie(x) container_of((x), struct dra7xx_pcie, pp)
75
76static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
77{
78 return readl(pcie->base + offset);
79}
80
81static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset,
82 u32 value)
83{
84 writel(value, pcie->base + offset);
85}
86
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +053087static inline u32 dra7xx_pcie_readl_rc(struct pcie_port *pp, u32 offset)
88{
89 return readl(pp->dbi_base + offset);
90}
91
92static inline void dra7xx_pcie_writel_rc(struct pcie_port *pp, u32 offset,
93 u32 value)
94{
95 writel(value, pp->dbi_base + offset);
96}
97
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -060098static int dra7xx_pcie_link_up(struct pcie_port *pp)
99{
100 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
101 u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
102
103 return !!(reg & LINK_UP);
104}
105
106static int dra7xx_pcie_establish_link(struct pcie_port *pp)
107{
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600108 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500109 struct device *dev = pp->dev;
Bjorn Helgaas6cbb2472015-06-02 16:47:17 -0500110 u32 reg;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600111
112 if (dw_pcie_link_up(pp)) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500113 dev_err(dev, "link is already up\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600114 return 0;
115 }
116
117 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
118 reg |= LTSSM_EN;
119 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
120
Joao Pinto886bc5c2016-03-10 14:44:35 -0600121 return dw_pcie_wait_for_link(pp);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600122}
123
124static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
125{
126 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
127
128 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
129 ~INTERRUPTS);
130 dra7xx_pcie_writel(dra7xx,
131 PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, INTERRUPTS);
132 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
133 ~LEG_EP_INTERRUPTS & ~MSI);
134
135 if (IS_ENABLED(CONFIG_PCI_MSI))
136 dra7xx_pcie_writel(dra7xx,
137 PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI, MSI);
138 else
139 dra7xx_pcie_writel(dra7xx,
140 PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
141 LEG_EP_INTERRUPTS);
142}
143
144static void dra7xx_pcie_host_init(struct pcie_port *pp)
145{
Zhou Wang9cdce1c2015-10-29 19:56:58 -0500146 pp->io_base &= DRA7XX_CPU_TO_BUS_ADDR;
147 pp->mem_base &= DRA7XX_CPU_TO_BUS_ADDR;
148 pp->cfg0_base &= DRA7XX_CPU_TO_BUS_ADDR;
149 pp->cfg1_base &= DRA7XX_CPU_TO_BUS_ADDR;
Gabriele Paoloni883cc172015-10-29 19:56:51 -0500150
Jisheng Zhang7e57fd12016-03-16 19:40:33 +0800151 dw_pcie_setup_rc(pp);
152
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600153 dra7xx_pcie_establish_link(pp);
154 if (IS_ENABLED(CONFIG_PCI_MSI))
155 dw_pcie_msi_init(pp);
156 dra7xx_pcie_enable_interrupts(pp);
157}
158
159static struct pcie_host_ops dra7xx_pcie_host_ops = {
160 .link_up = dra7xx_pcie_link_up,
161 .host_init = dra7xx_pcie_host_init,
162};
163
164static int dra7xx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
165 irq_hw_number_t hwirq)
166{
167 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
168 irq_set_chip_data(irq, domain->host_data);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600169
170 return 0;
171}
172
173static const struct irq_domain_ops intx_domain_ops = {
174 .map = dra7xx_pcie_intx_map,
175};
176
177static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
178{
179 struct device *dev = pp->dev;
180 struct device_node *node = dev->of_node;
181 struct device_node *pcie_intc_node = of_get_next_child(node, NULL);
182
183 if (!pcie_intc_node) {
184 dev_err(dev, "No PCIe Intc node found\n");
Christophe JAILLET991bfef2016-07-14 23:18:27 +0200185 return -ENODEV;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600186 }
187
188 pp->irq_domain = irq_domain_add_linear(pcie_intc_node, 4,
189 &intx_domain_ops, pp);
190 if (!pp->irq_domain) {
191 dev_err(dev, "Failed to get a INTx IRQ domain\n");
Christophe JAILLET991bfef2016-07-14 23:18:27 +0200192 return -ENODEV;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600193 }
194
195 return 0;
196}
197
198static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
199{
200 struct pcie_port *pp = arg;
201 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
202 u32 reg;
203
204 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI);
205
206 switch (reg) {
207 case MSI:
208 dw_handle_msi_irq(pp);
209 break;
210 case INTA:
211 case INTB:
212 case INTC:
213 case INTD:
214 generic_handle_irq(irq_find_mapping(pp->irq_domain, ffs(reg)));
215 break;
216 }
217
218 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI, reg);
219
220 return IRQ_HANDLED;
221}
222
223
224static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
225{
226 struct dra7xx_pcie *dra7xx = arg;
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500227 struct device *dev = dra7xx->pp.dev;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600228 u32 reg;
229
230 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN);
231
232 if (reg & ERR_SYS)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500233 dev_dbg(dev, "System Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600234
235 if (reg & ERR_FATAL)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500236 dev_dbg(dev, "Fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600237
238 if (reg & ERR_NONFATAL)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500239 dev_dbg(dev, "Non Fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600240
241 if (reg & ERR_COR)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500242 dev_dbg(dev, "Correctable Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600243
244 if (reg & ERR_AXI)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500245 dev_dbg(dev, "AXI tag lookup fatal Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600246
247 if (reg & ERR_ECRC)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500248 dev_dbg(dev, "ECRC Error\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600249
250 if (reg & PME_TURN_OFF)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500251 dev_dbg(dev,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600252 "Power Management Event Turn-Off message received\n");
253
254 if (reg & PME_TO_ACK)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500255 dev_dbg(dev,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600256 "Power Management Turn-Off Ack message received\n");
257
258 if (reg & PM_PME)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500259 dev_dbg(dev, "PM Power Management Event message received\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600260
261 if (reg & LINK_REQ_RST)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500262 dev_dbg(dev, "Link Request Reset\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600263
264 if (reg & LINK_UP_EVT)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500265 dev_dbg(dev, "Link-up state change\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600266
267 if (reg & CFG_BME_EVT)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500268 dev_dbg(dev, "CFG 'Bus Master Enable' change\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600269
270 if (reg & CFG_MSE_EVT)
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500271 dev_dbg(dev, "CFG 'Memory Space Enable' change\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600272
273 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN, reg);
274
275 return IRQ_HANDLED;
276}
277
Jingoo Hane73044a2014-11-06 14:37:39 +0900278static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
279 struct platform_device *pdev)
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600280{
281 int ret;
282 struct pcie_port *pp;
283 struct resource *res;
284 struct device *dev = &pdev->dev;
285
286 pp = &dra7xx->pp;
287 pp->dev = dev;
288 pp->ops = &dra7xx_pcie_host_ops;
289
290 pp->irq = platform_get_irq(pdev, 1);
291 if (pp->irq < 0) {
292 dev_err(dev, "missing IRQ resource\n");
293 return -EINVAL;
294 }
295
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500296 ret = devm_request_irq(dev, pp->irq, dra7xx_pcie_msi_irq_handler,
Grygorii Strashko8ff0ef92015-12-10 21:18:20 +0200297 IRQF_SHARED | IRQF_NO_THREAD,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600298 "dra7-pcie-msi", pp);
299 if (ret) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500300 dev_err(dev, "failed to request irq\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600301 return ret;
302 }
303
304 if (!IS_ENABLED(CONFIG_PCI_MSI)) {
305 ret = dra7xx_pcie_init_irq_domain(pp);
306 if (ret < 0)
307 return ret;
308 }
309
310 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbics");
311 pp->dbi_base = devm_ioremap(dev, res->start, resource_size(res));
312 if (!pp->dbi_base)
313 return -ENOMEM;
314
315 ret = dw_pcie_host_init(pp);
316 if (ret) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500317 dev_err(dev, "failed to initialize host\n");
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600318 return ret;
319 }
320
321 return 0;
322}
323
324static int __init dra7xx_pcie_probe(struct platform_device *pdev)
325{
326 u32 reg;
327 int ret;
328 int irq;
329 int i;
330 int phy_count;
331 struct phy **phy;
332 void __iomem *base;
333 struct resource *res;
334 struct dra7xx_pcie *dra7xx;
335 struct device *dev = &pdev->dev;
336 struct device_node *np = dev->of_node;
337 char name[10];
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530338 int gpio_sel;
339 enum of_gpio_flags flags;
340 unsigned long gpio_flags;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600341
342 dra7xx = devm_kzalloc(dev, sizeof(*dra7xx), GFP_KERNEL);
343 if (!dra7xx)
344 return -ENOMEM;
345
346 irq = platform_get_irq(pdev, 0);
347 if (irq < 0) {
348 dev_err(dev, "missing IRQ resource\n");
349 return -EINVAL;
350 }
351
352 ret = devm_request_irq(dev, irq, dra7xx_pcie_irq_handler,
353 IRQF_SHARED, "dra7xx-pcie-main", dra7xx);
354 if (ret) {
355 dev_err(dev, "failed to request irq\n");
356 return ret;
357 }
358
359 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ti_conf");
360 base = devm_ioremap_nocache(dev, res->start, resource_size(res));
361 if (!base)
362 return -ENOMEM;
363
364 phy_count = of_property_count_strings(np, "phy-names");
365 if (phy_count < 0) {
366 dev_err(dev, "unable to find the strings\n");
367 return phy_count;
368 }
369
370 phy = devm_kzalloc(dev, sizeof(*phy) * phy_count, GFP_KERNEL);
371 if (!phy)
372 return -ENOMEM;
373
374 for (i = 0; i < phy_count; i++) {
375 snprintf(name, sizeof(name), "pcie-phy%d", i);
376 phy[i] = devm_phy_get(dev, name);
377 if (IS_ERR(phy[i]))
378 return PTR_ERR(phy[i]);
379
380 ret = phy_init(phy[i]);
381 if (ret < 0)
382 goto err_phy;
383
384 ret = phy_power_on(phy[i]);
385 if (ret < 0) {
386 phy_exit(phy[i]);
387 goto err_phy;
388 }
389 }
390
391 dra7xx->base = base;
392 dra7xx->phy = phy;
393 dra7xx->dev = dev;
394 dra7xx->phy_count = phy_count;
395
396 pm_runtime_enable(dev);
397 ret = pm_runtime_get_sync(dev);
Fabio Estevamd3f4caa2015-08-20 01:30:36 -0500398 if (ret < 0) {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600399 dev_err(dev, "pm_runtime_get_sync failed\n");
Kishon Vijay Abraham I0e2bdb02015-07-31 17:55:10 +0530400 goto err_get_sync;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600401 }
402
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530403 gpio_sel = of_get_gpio_flags(dev->of_node, 0, &flags);
404 if (gpio_is_valid(gpio_sel)) {
405 gpio_flags = (flags & OF_GPIO_ACTIVE_LOW) ?
406 GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH;
407 ret = devm_gpio_request_one(dev, gpio_sel, gpio_flags,
408 "pcie_reset");
409 if (ret) {
Bjorn Helgaasc7f81462016-10-06 13:33:06 -0500410 dev_err(dev, "gpio%d request failed, ret %d\n",
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530411 gpio_sel, ret);
412 goto err_gpio;
413 }
414 } else if (gpio_sel == -EPROBE_DEFER) {
415 ret = -EPROBE_DEFER;
416 goto err_gpio;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600417 }
418
419 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
420 reg &= ~LTSSM_EN;
421 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
422
423 platform_set_drvdata(pdev, dra7xx);
424
Jingoo Han23926c82014-11-06 14:30:49 +0900425 ret = dra7xx_add_pcie_port(dra7xx, pdev);
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600426 if (ret < 0)
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530427 goto err_gpio;
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600428
429 return 0;
430
Kishon Vijay Abraham I78bdcad2015-07-28 19:09:09 +0530431err_gpio:
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600432 pm_runtime_put(dev);
Kishon Vijay Abraham I0e2bdb02015-07-31 17:55:10 +0530433
434err_get_sync:
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600435 pm_runtime_disable(dev);
436
437err_phy:
438 while (--i >= 0) {
439 phy_power_off(phy[i]);
440 phy_exit(phy[i]);
441 }
442
443 return ret;
444}
445
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530446#ifdef CONFIG_PM_SLEEP
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530447static int dra7xx_pcie_suspend(struct device *dev)
448{
449 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
450 struct pcie_port *pp = &dra7xx->pp;
451 u32 val;
452
453 /* clear MSE */
454 val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
455 val &= ~PCI_COMMAND_MEMORY;
456 dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
457
458 return 0;
459}
460
461static int dra7xx_pcie_resume(struct device *dev)
462{
463 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
464 struct pcie_port *pp = &dra7xx->pp;
465 u32 val;
466
467 /* set MSE */
468 val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND);
469 val |= PCI_COMMAND_MEMORY;
470 dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val);
471
472 return 0;
473}
474
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530475static int dra7xx_pcie_suspend_noirq(struct device *dev)
476{
477 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
478 int count = dra7xx->phy_count;
479
480 while (count--) {
481 phy_power_off(dra7xx->phy[count]);
482 phy_exit(dra7xx->phy[count]);
483 }
484
485 return 0;
486}
487
488static int dra7xx_pcie_resume_noirq(struct device *dev)
489{
490 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
491 int phy_count = dra7xx->phy_count;
492 int ret;
493 int i;
494
495 for (i = 0; i < phy_count; i++) {
496 ret = phy_init(dra7xx->phy[i]);
497 if (ret < 0)
498 goto err_phy;
499
500 ret = phy_power_on(dra7xx->phy[i]);
501 if (ret < 0) {
502 phy_exit(dra7xx->phy[i]);
503 goto err_phy;
504 }
505 }
506
507 return 0;
508
509err_phy:
510 while (--i >= 0) {
511 phy_power_off(dra7xx->phy[i]);
512 phy_exit(dra7xx->phy[i]);
513 }
514
515 return ret;
516}
517#endif
518
519static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
Kishon Vijay Abraham I389c7092015-07-31 17:55:12 +0530520 SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume)
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530521 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
522 dra7xx_pcie_resume_noirq)
523};
524
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600525static const struct of_device_id of_dra7xx_pcie_match[] = {
526 { .compatible = "ti,dra7-pcie", },
527 {},
528};
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600529
530static struct platform_driver dra7xx_pcie_driver = {
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600531 .driver = {
532 .name = "dra7-pcie",
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600533 .of_match_table = of_dra7xx_pcie_match,
Paul Gortmakerd29438d2016-08-24 16:57:47 -0400534 .suppress_bind_attrs = true,
Kishon Vijay Abraham Ie52eb442015-07-31 17:55:11 +0530535 .pm = &dra7xx_pcie_pm_ops,
Kishon Vijay Abraham I47ff3de2014-07-22 15:23:45 -0600536 },
537};
Paul Gortmakerd29438d2016-08-24 16:57:47 -0400538builtin_platform_driver_probe(dra7xx_pcie_driver, dra7xx_pcie_probe);