Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * PCIe host controller driver for Freescale Layerscape SoCs
  4 *
  5 * Copyright (C) 2014 Freescale Semiconductor.
  6 * Copyright 2021 NXP
  7 *
  8 * Author: Minghuan Lian <Minghuan.Lian@freescale.com>
  9 */
 10
 11#include <linux/delay.h>
 12#include <linux/kernel.h>
 13#include <linux/interrupt.h>
 14#include <linux/init.h>
 15#include <linux/iopoll.h>
 16#include <linux/of_pci.h>
 17#include <linux/of_platform.h>
 
 18#include <linux/of_address.h>
 19#include <linux/pci.h>
 20#include <linux/platform_device.h>
 21#include <linux/resource.h>
 22#include <linux/mfd/syscon.h>
 23#include <linux/regmap.h>
 24
 25#include "../../pci.h"
 26#include "pcie-designware.h"
 27
 
 
 
 
 
 
 28/* PEX Internal Configuration Registers */
 29#define PCIE_STRFMR1		0x71c /* Symbol Timer & Filter Mask Register1 */
 30#define PCIE_ABSERR		0x8d0 /* Bridge Slave Error Response Register */
 31#define PCIE_ABSERR_SETTING	0x9401 /* Forward error of non-posted request */
 32
 33/* PF Message Command Register */
 34#define LS_PCIE_PF_MCR		0x2c
 35#define PF_MCR_PTOMR		BIT(0)
 36#define PF_MCR_EXL2S		BIT(1)
 37
 38/* LS1021A PEXn PM Write Control Register */
 39#define SCFG_PEXPMWRCR(idx)	(0x5c + (idx) * 0x64)
 40#define PMXMTTURNOFF		BIT(31)
 41#define SCFG_PEXSFTRSTCR	0x190
 42#define PEXSR(idx)		BIT(idx)
 43
 44/* LS1043A PEX PME control register */
 45#define SCFG_PEXPMECR		0x144
 46#define PEXPME(idx)		BIT(31 - (idx) * 4)
 47
 48/* LS1043A PEX LUT debug register */
 49#define LS_PCIE_LDBG	0x7fc
 50#define LDBG_SR		BIT(30)
 51#define LDBG_WE		BIT(31)
 52
 53#define PCIE_IATU_NUM		6
 54
 55struct ls_pcie_drvdata {
 56	const u32 pf_lut_off;
 
 
 57	const struct dw_pcie_host_ops *ops;
 58	int (*exit_from_l2)(struct dw_pcie_rp *pp);
 59	bool scfg_support;
 60	bool pm_support;
 61};
 62
 63struct ls_pcie {
 64	struct dw_pcie *pci;
 65	const struct ls_pcie_drvdata *drvdata;
 66	void __iomem *pf_lut_base;
 67	struct regmap *scfg;
 
 68	int index;
 69	bool big_endian;
 70};
 71
 72#define ls_pcie_pf_lut_readl_addr(addr)	ls_pcie_pf_lut_readl(pcie, addr)
 73#define to_ls_pcie(x)	dev_get_drvdata((x)->dev)
 74
 75static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
 76{
 77	struct dw_pcie *pci = pcie->pci;
 78	u32 header_type;
 79
 80	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
 81	header_type &= PCI_HEADER_TYPE_MASK;
 82
 83	return header_type == PCI_HEADER_TYPE_BRIDGE;
 84}
 85
 86/* Clear multi-function bit */
 87static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
 88{
 89	struct dw_pcie *pci = pcie->pci;
 90
 91	iowrite8(PCI_HEADER_TYPE_BRIDGE, pci->dbi_base + PCI_HEADER_TYPE);
 92}
 93
 94/* Drop MSG TLP except for Vendor MSG */
 95static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
 96{
 97	u32 val;
 98	struct dw_pcie *pci = pcie->pci;
 99
100	val = ioread32(pci->dbi_base + PCIE_STRFMR1);
101	val &= 0xDFFFFFFF;
102	iowrite32(val, pci->dbi_base + PCIE_STRFMR1);
103}
104
105/* Forward error response of outbound non-posted requests */
106static void ls_pcie_fix_error_response(struct ls_pcie *pcie)
107{
108	struct dw_pcie *pci = pcie->pci;
109
110	iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR);
 
111}
112
113static u32 ls_pcie_pf_lut_readl(struct ls_pcie *pcie, u32 off)
114{
115	if (pcie->big_endian)
116		return ioread32be(pcie->pf_lut_base + off);
117
118	return ioread32(pcie->pf_lut_base + off);
119}
120
121static void ls_pcie_pf_lut_writel(struct ls_pcie *pcie, u32 off, u32 val)
122{
123	if (pcie->big_endian)
124		iowrite32be(val, pcie->pf_lut_base + off);
125	else
126		iowrite32(val, pcie->pf_lut_base + off);
127}
128
129static void ls_pcie_send_turnoff_msg(struct dw_pcie_rp *pp)
130{
131	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
132	struct ls_pcie *pcie = to_ls_pcie(pci);
133	u32 val;
134	int ret;
135
136	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_PF_MCR);
137	val |= PF_MCR_PTOMR;
138	ls_pcie_pf_lut_writel(pcie, LS_PCIE_PF_MCR, val);
139
140	ret = readx_poll_timeout(ls_pcie_pf_lut_readl_addr, LS_PCIE_PF_MCR,
141				 val, !(val & PF_MCR_PTOMR),
142				 PCIE_PME_TO_L2_TIMEOUT_US/10,
143				 PCIE_PME_TO_L2_TIMEOUT_US);
144	if (ret)
145		dev_err(pcie->pci->dev, "PME_Turn_off timeout\n");
146}
147
148static int ls_pcie_exit_from_l2(struct dw_pcie_rp *pp)
149{
150	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
151	struct ls_pcie *pcie = to_ls_pcie(pci);
152	u32 val;
153	int ret;
154
155	/*
156	 * Set PF_MCR_EXL2S bit in LS_PCIE_PF_MCR register for the link
157	 * to exit L2 state.
158	 */
159	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_PF_MCR);
160	val |= PF_MCR_EXL2S;
161	ls_pcie_pf_lut_writel(pcie, LS_PCIE_PF_MCR, val);
162
163	/*
164	 * L2 exit timeout of 10ms is not defined in the specifications,
165	 * it was chosen based on empirical observations.
166	 */
167	ret = readx_poll_timeout(ls_pcie_pf_lut_readl_addr, LS_PCIE_PF_MCR,
168				 val, !(val & PF_MCR_EXL2S),
169				 1000,
170				 10000);
171	if (ret)
172		dev_err(pcie->pci->dev, "L2 exit timeout\n");
173
174	return ret;
175}
176
177static int ls_pcie_host_init(struct dw_pcie_rp *pp)
 
 
 
 
 
 
 
 
178{
179	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
180	struct ls_pcie *pcie = to_ls_pcie(pci);
181
 
 
 
 
 
 
182	ls_pcie_fix_error_response(pcie);
183
184	dw_pcie_dbi_ro_wr_en(pci);
185	ls_pcie_clear_multifunction(pcie);
186	dw_pcie_dbi_ro_wr_dis(pci);
187
188	ls_pcie_drop_msg_tlp(pcie);
189
190	return 0;
191}
192
193static void scfg_pcie_send_turnoff_msg(struct regmap *scfg, u32 reg, u32 mask)
194{
195	/* Send PME_Turn_Off message */
196	regmap_write_bits(scfg, reg, mask, mask);
197
198	/*
199	 * There is no specific register to check for PME_To_Ack from endpoint.
200	 * So on the safe side, wait for PCIE_PME_TO_L2_TIMEOUT_US.
201	 */
202	mdelay(PCIE_PME_TO_L2_TIMEOUT_US/1000);
203
204	/*
205	 * Layerscape hardware reference manual recommends clearing the PMXMTTURNOFF bit
206	 * to complete the PME_Turn_Off handshake.
207	 */
208	regmap_write_bits(scfg, reg, mask, 0);
209}
210
211static void ls1021a_pcie_send_turnoff_msg(struct dw_pcie_rp *pp)
212{
213	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
214	struct ls_pcie *pcie = to_ls_pcie(pci);
215
216	scfg_pcie_send_turnoff_msg(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), PMXMTTURNOFF);
217}
218
219static int scfg_pcie_exit_from_l2(struct regmap *scfg, u32 reg, u32 mask)
220{
221	/* Reset the PEX wrapper to bring the link out of L2 */
222	regmap_write_bits(scfg, reg, mask, mask);
223	regmap_write_bits(scfg, reg, mask, 0);
224
225	return 0;
226}
227
228static int ls1021a_pcie_exit_from_l2(struct dw_pcie_rp *pp)
229{
230	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
231	struct ls_pcie *pcie = to_ls_pcie(pci);
 
 
 
232
233	return scfg_pcie_exit_from_l2(pcie->scfg, SCFG_PEXSFTRSTCR, PEXSR(pcie->index));
234}
 
 
 
 
 
 
235
236static void ls1043a_pcie_send_turnoff_msg(struct dw_pcie_rp *pp)
237{
238	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
239	struct ls_pcie *pcie = to_ls_pcie(pci);
 
 
240
241	scfg_pcie_send_turnoff_msg(pcie->scfg, SCFG_PEXPMECR, PEXPME(pcie->index));
242}
243
244static int ls1043a_pcie_exit_from_l2(struct dw_pcie_rp *pp)
245{
246	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
247	struct ls_pcie *pcie = to_ls_pcie(pci);
248	u32 val;
 
249
250	/*
251	 * Reset the PEX wrapper to bring the link out of L2.
252	 * LDBG_WE: allows the user to have write access to the PEXDBG[SR] for both setting and
253	 *	    clearing the soft reset on the PEX module.
254	 * LDBG_SR: When SR is set to 1, the PEX module enters soft reset.
255	 */
256	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_LDBG);
257	val |= LDBG_WE;
258	ls_pcie_pf_lut_writel(pcie, LS_PCIE_LDBG, val);
259
260	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_LDBG);
261	val |= LDBG_SR;
262	ls_pcie_pf_lut_writel(pcie, LS_PCIE_LDBG, val);
263
264	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_LDBG);
265	val &= ~LDBG_SR;
266	ls_pcie_pf_lut_writel(pcie, LS_PCIE_LDBG, val);
267
268	val = ls_pcie_pf_lut_readl(pcie, LS_PCIE_LDBG);
269	val &= ~LDBG_WE;
270	ls_pcie_pf_lut_writel(pcie, LS_PCIE_LDBG, val);
271
 
272	return 0;
273}
274
 
 
 
 
 
275static const struct dw_pcie_host_ops ls_pcie_host_ops = {
276	.init = ls_pcie_host_init,
277	.pme_turn_off = ls_pcie_send_turnoff_msg,
 
 
 
 
278};
279
280static const struct dw_pcie_host_ops ls1021a_pcie_host_ops = {
281	.init = ls_pcie_host_init,
282	.pme_turn_off = ls1021a_pcie_send_turnoff_msg,
283};
284
285static const struct ls_pcie_drvdata ls1021a_drvdata = {
286	.pm_support = true,
287	.scfg_support = true,
288	.ops = &ls1021a_pcie_host_ops,
289	.exit_from_l2 = ls1021a_pcie_exit_from_l2,
290};
291
292static const struct dw_pcie_host_ops ls1043a_pcie_host_ops = {
293	.init = ls_pcie_host_init,
294	.pme_turn_off = ls1043a_pcie_send_turnoff_msg,
 
 
 
 
 
 
 
 
 
 
 
295};
296
297static const struct ls_pcie_drvdata ls1043a_drvdata = {
298	.pf_lut_off = 0x10000,
299	.pm_support = true,
300	.scfg_support = true,
301	.ops = &ls1043a_pcie_host_ops,
302	.exit_from_l2 = ls1043a_pcie_exit_from_l2,
303};
304
305static const struct ls_pcie_drvdata layerscape_drvdata = {
306	.pf_lut_off = 0xc0000,
307	.pm_support = true,
 
308	.ops = &ls_pcie_host_ops,
309	.exit_from_l2 = ls_pcie_exit_from_l2,
310};
311
312static const struct of_device_id ls_pcie_of_match[] = {
313	{ .compatible = "fsl,ls1012a-pcie", .data = &layerscape_drvdata },
314	{ .compatible = "fsl,ls1021a-pcie", .data = &ls1021a_drvdata },
315	{ .compatible = "fsl,ls1028a-pcie", .data = &layerscape_drvdata },
316	{ .compatible = "fsl,ls1043a-pcie", .data = &ls1043a_drvdata },
317	{ .compatible = "fsl,ls1046a-pcie", .data = &layerscape_drvdata },
318	{ .compatible = "fsl,ls2080a-pcie", .data = &layerscape_drvdata },
319	{ .compatible = "fsl,ls2085a-pcie", .data = &layerscape_drvdata },
320	{ .compatible = "fsl,ls2088a-pcie", .data = &layerscape_drvdata },
321	{ .compatible = "fsl,ls1088a-pcie", .data = &layerscape_drvdata },
322	{ },
323};
324
325static int ls_pcie_probe(struct platform_device *pdev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326{
327	struct device *dev = &pdev->dev;
328	struct dw_pcie *pci;
329	struct ls_pcie *pcie;
330	struct resource *dbi_base;
331	u32 index[2];
332	int ret;
333
334	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
335	if (!pcie)
336		return -ENOMEM;
337
338	pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
339	if (!pci)
340		return -ENOMEM;
341
342	pcie->drvdata = of_device_get_match_data(dev);
343
344	pci->dev = dev;
 
 
345	pcie->pci = pci;
346	pci->pp.ops = pcie->drvdata->ops;
347
348	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
349	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
350	if (IS_ERR(pci->dbi_base))
351		return PTR_ERR(pci->dbi_base);
352
353	pcie->big_endian = of_property_read_bool(dev->of_node, "big-endian");
354
355	pcie->pf_lut_base = pci->dbi_base + pcie->drvdata->pf_lut_off;
356
357	if (pcie->drvdata->scfg_support) {
358		pcie->scfg = syscon_regmap_lookup_by_phandle(dev->of_node, "fsl,pcie-scfg");
359		if (IS_ERR(pcie->scfg)) {
360			dev_err(dev, "No syscfg phandle specified\n");
361			return PTR_ERR(pcie->scfg);
362		}
363
364		ret = of_property_read_u32_array(dev->of_node, "fsl,pcie-scfg", index, 2);
365		if (ret)
366			return ret;
367
368		pcie->index = index[1];
369	}
370
371	if (!ls_pcie_is_bridge(pcie))
372		return -ENODEV;
373
374	platform_set_drvdata(pdev, pcie);
375
376	return dw_pcie_host_init(&pci->pp);
377}
378
379static int ls_pcie_suspend_noirq(struct device *dev)
380{
381	struct ls_pcie *pcie = dev_get_drvdata(dev);
382
383	if (!pcie->drvdata->pm_support)
384		return 0;
385
386	return dw_pcie_suspend_noirq(pcie->pci);
387}
388
389static int ls_pcie_resume_noirq(struct device *dev)
390{
391	struct ls_pcie *pcie = dev_get_drvdata(dev);
392	int ret;
393
394	if (!pcie->drvdata->pm_support)
395		return 0;
396
397	ret = pcie->drvdata->exit_from_l2(&pcie->pci->pp);
398	if (ret)
399		return ret;
400
401	return dw_pcie_resume_noirq(pcie->pci);
402}
403
404static const struct dev_pm_ops ls_pcie_pm_ops = {
405	NOIRQ_SYSTEM_SLEEP_PM_OPS(ls_pcie_suspend_noirq, ls_pcie_resume_noirq)
406};
407
408static struct platform_driver ls_pcie_driver = {
409	.probe = ls_pcie_probe,
410	.driver = {
411		.name = "layerscape-pcie",
412		.of_match_table = ls_pcie_of_match,
413		.suppress_bind_attrs = true,
414		.pm = &ls_pcie_pm_ops,
415	},
416};
417builtin_platform_driver(ls_pcie_driver);
v5.4
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * PCIe host controller driver for Freescale Layerscape SoCs
  4 *
  5 * Copyright (C) 2014 Freescale Semiconductor.
 
  6 *
  7 * Author: Minghuan Lian <Minghuan.Lian@freescale.com>
  8 */
  9
 
 10#include <linux/kernel.h>
 11#include <linux/interrupt.h>
 12#include <linux/init.h>
 
 13#include <linux/of_pci.h>
 14#include <linux/of_platform.h>
 15#include <linux/of_irq.h>
 16#include <linux/of_address.h>
 17#include <linux/pci.h>
 18#include <linux/platform_device.h>
 19#include <linux/resource.h>
 20#include <linux/mfd/syscon.h>
 21#include <linux/regmap.h>
 22
 
 23#include "pcie-designware.h"
 24
 25/* PEX1/2 Misc Ports Status Register */
 26#define SCFG_PEXMSCPORTSR(pex_idx)	(0x94 + (pex_idx) * 4)
 27#define LTSSM_STATE_SHIFT	20
 28#define LTSSM_STATE_MASK	0x3f
 29#define LTSSM_PCIE_L0		0x11 /* L0 state */
 30
 31/* PEX Internal Configuration Registers */
 32#define PCIE_STRFMR1		0x71c /* Symbol Timer & Filter Mask Register1 */
 33#define PCIE_ABSERR		0x8d0 /* Bridge Slave Error Response Register */
 34#define PCIE_ABSERR_SETTING	0x9401 /* Forward error of non-posted request */
 35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 36#define PCIE_IATU_NUM		6
 37
 38struct ls_pcie_drvdata {
 39	u32 lut_offset;
 40	u32 ltssm_shift;
 41	u32 lut_dbg;
 42	const struct dw_pcie_host_ops *ops;
 43	const struct dw_pcie_ops *dw_pcie_ops;
 
 
 44};
 45
 46struct ls_pcie {
 47	struct dw_pcie *pci;
 48	void __iomem *lut;
 
 49	struct regmap *scfg;
 50	const struct ls_pcie_drvdata *drvdata;
 51	int index;
 
 52};
 53
 
 54#define to_ls_pcie(x)	dev_get_drvdata((x)->dev)
 55
 56static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
 57{
 58	struct dw_pcie *pci = pcie->pci;
 59	u32 header_type;
 60
 61	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
 62	header_type &= 0x7f;
 63
 64	return header_type == PCI_HEADER_TYPE_BRIDGE;
 65}
 66
 67/* Clear multi-function bit */
 68static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
 69{
 70	struct dw_pcie *pci = pcie->pci;
 71
 72	iowrite8(PCI_HEADER_TYPE_BRIDGE, pci->dbi_base + PCI_HEADER_TYPE);
 73}
 74
 75/* Drop MSG TLP except for Vendor MSG */
 76static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
 77{
 78	u32 val;
 79	struct dw_pcie *pci = pcie->pci;
 80
 81	val = ioread32(pci->dbi_base + PCIE_STRFMR1);
 82	val &= 0xDFFFFFFF;
 83	iowrite32(val, pci->dbi_base + PCIE_STRFMR1);
 84}
 85
 86static void ls_pcie_disable_outbound_atus(struct ls_pcie *pcie)
 
 87{
 88	int i;
 89
 90	for (i = 0; i < PCIE_IATU_NUM; i++)
 91		dw_pcie_disable_atu(pcie->pci, i, DW_PCIE_REGION_OUTBOUND);
 92}
 93
 94static int ls1021_pcie_link_up(struct dw_pcie *pci)
 95{
 96	u32 state;
 97	struct ls_pcie *pcie = to_ls_pcie(pci);
 98
 99	if (!pcie->scfg)
100		return 0;
101
102	regmap_read(pcie->scfg, SCFG_PEXMSCPORTSR(pcie->index), &state);
103	state = (state >> LTSSM_STATE_SHIFT) & LTSSM_STATE_MASK;
 
 
 
 
 
104
105	if (state < LTSSM_PCIE_L0)
106		return 0;
 
 
 
 
107
108	return 1;
 
 
 
 
 
 
 
 
 
109}
110
111static int ls_pcie_link_up(struct dw_pcie *pci)
112{
 
113	struct ls_pcie *pcie = to_ls_pcie(pci);
114	u32 state;
 
115
116	state = (ioread32(pcie->lut + pcie->drvdata->lut_dbg) >>
117		 pcie->drvdata->ltssm_shift) &
118		 LTSSM_STATE_MASK;
 
 
 
 
119
120	if (state < LTSSM_PCIE_L0)
121		return 0;
 
 
 
 
 
 
 
 
122
123	return 1;
124}
125
126/* Forward error response of outbound non-posted requests */
127static void ls_pcie_fix_error_response(struct ls_pcie *pcie)
128{
129	struct dw_pcie *pci = pcie->pci;
130
131	iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR);
132}
133
134static int ls_pcie_host_init(struct pcie_port *pp)
135{
136	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
137	struct ls_pcie *pcie = to_ls_pcie(pci);
138
139	/*
140	 * Disable outbound windows configured by the bootloader to avoid
141	 * one transaction hitting multiple outbound windows.
142	 * dw_pcie_setup_rc() will reconfigure the outbound windows.
143	 */
144	ls_pcie_disable_outbound_atus(pcie);
145	ls_pcie_fix_error_response(pcie);
146
147	dw_pcie_dbi_ro_wr_en(pci);
148	ls_pcie_clear_multifunction(pcie);
149	dw_pcie_dbi_ro_wr_dis(pci);
150
151	ls_pcie_drop_msg_tlp(pcie);
152
153	dw_pcie_setup_rc(pp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
155	return 0;
156}
157
158static int ls1021_pcie_host_init(struct pcie_port *pp)
159{
160	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
161	struct ls_pcie *pcie = to_ls_pcie(pci);
162	struct device *dev = pci->dev;
163	u32 index[2];
164	int ret;
165
166	pcie->scfg = syscon_regmap_lookup_by_phandle(dev->of_node,
167						     "fsl,pcie-scfg");
168	if (IS_ERR(pcie->scfg)) {
169		ret = PTR_ERR(pcie->scfg);
170		dev_err(dev, "No syscfg phandle specified\n");
171		pcie->scfg = NULL;
172		return ret;
173	}
174
175	if (of_property_read_u32_array(dev->of_node,
176				       "fsl,pcie-scfg", index, 2)) {
177		pcie->scfg = NULL;
178		return -EINVAL;
179	}
180	pcie->index = index[1];
181
182	return ls_pcie_host_init(pp);
183}
184
185static int ls_pcie_msi_host_init(struct pcie_port *pp)
186{
187	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
188	struct device *dev = pci->dev;
189	struct device_node *np = dev->of_node;
190	struct device_node *msi_node;
191
192	/*
193	 * The MSI domain is set by the generic of_msi_configure().  This
194	 * .msi_host_init() function keeps us from doing the default MSI
195	 * domain setup in dw_pcie_host_init() and also enforces the
196	 * requirement that "msi-parent" exists.
197	 */
198	msi_node = of_parse_phandle(np, "msi-parent", 0);
199	if (!msi_node) {
200		dev_err(dev, "failed to find msi-parent\n");
201		return -EINVAL;
202	}
 
 
 
 
 
 
 
 
 
 
203
204	of_node_put(msi_node);
205	return 0;
206}
207
208static const struct dw_pcie_host_ops ls1021_pcie_host_ops = {
209	.host_init = ls1021_pcie_host_init,
210	.msi_host_init = ls_pcie_msi_host_init,
211};
212
213static const struct dw_pcie_host_ops ls_pcie_host_ops = {
214	.host_init = ls_pcie_host_init,
215	.msi_host_init = ls_pcie_msi_host_init,
216};
217
218static const struct dw_pcie_ops dw_ls1021_pcie_ops = {
219	.link_up = ls1021_pcie_link_up,
220};
221
222static const struct dw_pcie_ops dw_ls_pcie_ops = {
223	.link_up = ls_pcie_link_up,
 
224};
225
226static const struct ls_pcie_drvdata ls1021_drvdata = {
227	.ops = &ls1021_pcie_host_ops,
228	.dw_pcie_ops = &dw_ls1021_pcie_ops,
 
 
229};
230
231static const struct ls_pcie_drvdata ls1043_drvdata = {
232	.lut_offset = 0x10000,
233	.ltssm_shift = 24,
234	.lut_dbg = 0x7fc,
235	.ops = &ls_pcie_host_ops,
236	.dw_pcie_ops = &dw_ls_pcie_ops,
237};
238
239static const struct ls_pcie_drvdata ls1046_drvdata = {
240	.lut_offset = 0x80000,
241	.ltssm_shift = 24,
242	.lut_dbg = 0x407fc,
243	.ops = &ls_pcie_host_ops,
244	.dw_pcie_ops = &dw_ls_pcie_ops,
245};
246
247static const struct ls_pcie_drvdata ls2080_drvdata = {
248	.lut_offset = 0x80000,
249	.ltssm_shift = 0,
250	.lut_dbg = 0x7fc,
251	.ops = &ls_pcie_host_ops,
252	.dw_pcie_ops = &dw_ls_pcie_ops,
253};
254
255static const struct ls_pcie_drvdata ls2088_drvdata = {
256	.lut_offset = 0x80000,
257	.ltssm_shift = 0,
258	.lut_dbg = 0x407fc,
259	.ops = &ls_pcie_host_ops,
260	.dw_pcie_ops = &dw_ls_pcie_ops,
261};
262
263static const struct of_device_id ls_pcie_of_match[] = {
264	{ .compatible = "fsl,ls1012a-pcie", .data = &ls1046_drvdata },
265	{ .compatible = "fsl,ls1021a-pcie", .data = &ls1021_drvdata },
266	{ .compatible = "fsl,ls1043a-pcie", .data = &ls1043_drvdata },
267	{ .compatible = "fsl,ls1046a-pcie", .data = &ls1046_drvdata },
268	{ .compatible = "fsl,ls2080a-pcie", .data = &ls2080_drvdata },
269	{ .compatible = "fsl,ls2085a-pcie", .data = &ls2080_drvdata },
270	{ .compatible = "fsl,ls2088a-pcie", .data = &ls2088_drvdata },
271	{ .compatible = "fsl,ls1088a-pcie", .data = &ls2088_drvdata },
 
272	{ },
273};
274
275static int __init ls_add_pcie_port(struct ls_pcie *pcie)
276{
277	struct dw_pcie *pci = pcie->pci;
278	struct pcie_port *pp = &pci->pp;
279	struct device *dev = pci->dev;
280	int ret;
281
282	pp->ops = pcie->drvdata->ops;
283
284	ret = dw_pcie_host_init(pp);
285	if (ret) {
286		dev_err(dev, "failed to initialize host\n");
287		return ret;
288	}
289
290	return 0;
291}
292
293static int __init ls_pcie_probe(struct platform_device *pdev)
294{
295	struct device *dev = &pdev->dev;
296	struct dw_pcie *pci;
297	struct ls_pcie *pcie;
298	struct resource *dbi_base;
 
299	int ret;
300
301	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
302	if (!pcie)
303		return -ENOMEM;
304
305	pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
306	if (!pci)
307		return -ENOMEM;
308
309	pcie->drvdata = of_device_get_match_data(dev);
310
311	pci->dev = dev;
312	pci->ops = pcie->drvdata->dw_pcie_ops;
313
314	pcie->pci = pci;
 
315
316	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
317	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
318	if (IS_ERR(pci->dbi_base))
319		return PTR_ERR(pci->dbi_base);
320
321	pcie->lut = pci->dbi_base + pcie->drvdata->lut_offset;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
323	if (!ls_pcie_is_bridge(pcie))
324		return -ENODEV;
325
326	platform_set_drvdata(pdev, pcie);
327
328	ret = ls_add_pcie_port(pcie);
329	if (ret < 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330		return ret;
331
332	return 0;
333}
334
 
 
 
 
335static struct platform_driver ls_pcie_driver = {
 
336	.driver = {
337		.name = "layerscape-pcie",
338		.of_match_table = ls_pcie_of_match,
339		.suppress_bind_attrs = true,
 
340	},
341};
342builtin_platform_driver_probe(ls_pcie_driver, ls_pcie_probe);