]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/pci/host/pci-layerscape.c
PCI: layerscape: Remove ls_pcie_establish_link()
[karo-tx-linux.git] / drivers / pci / host / pci-layerscape.c
1 /*
2  * PCIe host controller driver for Freescale Layerscape SoCs
3  *
4  * Copyright (C) 2014 Freescale Semiconductor.
5  *
6   * Author: Minghuan Lian <Minghuan.Lian@freescale.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
13 #include <linux/kernel.h>
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/of_pci.h>
17 #include <linux/of_platform.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_address.h>
20 #include <linux/pci.h>
21 #include <linux/platform_device.h>
22 #include <linux/resource.h>
23 #include <linux/mfd/syscon.h>
24 #include <linux/regmap.h>
25
26 #include "pcie-designware.h"
27
28 /* PEX1/2 Misc Ports Status Register */
29 #define SCFG_PEXMSCPORTSR(pex_idx)      (0x94 + (pex_idx) * 4)
30 #define LTSSM_STATE_SHIFT       20
31 #define LTSSM_STATE_MASK        0x3f
32 #define LTSSM_PCIE_L0           0x11 /* L0 state */
33
34 /* Symbol Timer Register and Filter Mask Register 1 */
35 #define PCIE_STRFMR1 0x71c
36
37 struct ls_pcie {
38         struct list_head node;
39         struct device *dev;
40         struct pci_bus *bus;
41         void __iomem *dbi;
42         struct regmap *scfg;
43         struct pcie_port pp;
44         int index;
45         int msi_irq;
46 };
47
48 #define to_ls_pcie(x)   container_of(x, struct ls_pcie, pp)
49
50 static int ls_pcie_link_up(struct pcie_port *pp)
51 {
52         u32 state;
53         struct ls_pcie *pcie = to_ls_pcie(pp);
54
55         regmap_read(pcie->scfg, SCFG_PEXMSCPORTSR(pcie->index), &state);
56         state = (state >> LTSSM_STATE_SHIFT) & LTSSM_STATE_MASK;
57
58         if (state < LTSSM_PCIE_L0)
59                 return 0;
60
61         return 1;
62 }
63
64 static void ls_pcie_host_init(struct pcie_port *pp)
65 {
66         struct ls_pcie *pcie = to_ls_pcie(pp);
67         u32 val;
68
69         dw_pcie_setup_rc(pp);
70
71         /*
72          * LS1021A Workaround for internal TKT228622
73          * to fix the INTx hang issue
74          */
75         val = ioread32(pcie->dbi + PCIE_STRFMR1);
76         val &= 0xffff;
77         iowrite32(val, pcie->dbi + PCIE_STRFMR1);
78 }
79
80 static struct pcie_host_ops ls_pcie_host_ops = {
81         .link_up = ls_pcie_link_up,
82         .host_init = ls_pcie_host_init,
83 };
84
85 static int ls_add_pcie_port(struct ls_pcie *pcie)
86 {
87         struct pcie_port *pp;
88         int ret;
89
90         pp = &pcie->pp;
91         pp->dev = pcie->dev;
92         pp->dbi_base = pcie->dbi;
93         pp->root_bus_nr = -1;
94         pp->ops = &ls_pcie_host_ops;
95
96         ret = dw_pcie_host_init(pp);
97         if (ret) {
98                 dev_err(pp->dev, "failed to initialize host\n");
99                 return ret;
100         }
101
102         return 0;
103 }
104
105 static int __init ls_pcie_probe(struct platform_device *pdev)
106 {
107         struct ls_pcie *pcie;
108         struct resource *dbi_base;
109         u32 index[2];
110         int ret;
111
112         pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL);
113         if (!pcie)
114                 return -ENOMEM;
115
116         pcie->dev = &pdev->dev;
117
118         dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
119         pcie->dbi = devm_ioremap_resource(&pdev->dev, dbi_base);
120         if (IS_ERR(pcie->dbi)) {
121                 dev_err(&pdev->dev, "missing *regs* space\n");
122                 return PTR_ERR(pcie->dbi);
123         }
124
125         pcie->scfg = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
126                                                      "fsl,pcie-scfg");
127         if (IS_ERR(pcie->scfg)) {
128                 dev_err(&pdev->dev, "No syscfg phandle specified\n");
129                 return PTR_ERR(pcie->scfg);
130         }
131
132         ret = of_property_read_u32_array(pdev->dev.of_node,
133                                          "fsl,pcie-scfg", index, 2);
134         if (ret)
135                 return ret;
136         pcie->index = index[1];
137
138         ret = ls_add_pcie_port(pcie);
139         if (ret < 0)
140                 return ret;
141
142         platform_set_drvdata(pdev, pcie);
143
144         return 0;
145 }
146
147 static const struct of_device_id ls_pcie_of_match[] = {
148         { .compatible = "fsl,ls1021a-pcie" },
149         { },
150 };
151 MODULE_DEVICE_TABLE(of, ls_pcie_of_match);
152
153 static struct platform_driver ls_pcie_driver = {
154         .driver = {
155                 .name = "layerscape-pcie",
156                 .of_match_table = ls_pcie_of_match,
157         },
158 };
159
160 module_platform_driver_probe(ls_pcie_driver, ls_pcie_probe);
161
162 MODULE_AUTHOR("Minghuan Lian <Minghuan.Lian@freescale.com>");
163 MODULE_DESCRIPTION("Freescale Layerscape PCIe host controller driver");
164 MODULE_LICENSE("GPL v2");