67
67
#define EXP_CAP_ID_OFFSET 0x70
68
68
69
69
struct dra7xx_pcie {
70
- struct pcie_port pp ;
70
+ struct dw_pcie * pci ;
71
71
void __iomem * base ; /* DT ti_conf */
72
72
int phy_count ; /* DT phy-names count */
73
73
struct phy * * phy ;
74
74
int link_gen ;
75
75
struct irq_domain * irq_domain ;
76
76
};
77
77
78
- #define to_dra7xx_pcie (x ) container_of ((x), struct dra7xx_pcie, pp )
78
+ #define to_dra7xx_pcie (x ) dev_get_drvdata ((x)->dev )
79
79
80
80
static inline u32 dra7xx_pcie_readl (struct dra7xx_pcie * pcie , u32 offset )
81
81
{
@@ -88,42 +88,42 @@ static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset,
88
88
writel (value , pcie -> base + offset );
89
89
}
90
90
91
- static int dra7xx_pcie_link_up (struct pcie_port * pp )
91
+ static int dra7xx_pcie_link_up (struct dw_pcie * pci )
92
92
{
93
- struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pp );
93
+ struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pci );
94
94
u32 reg = dra7xx_pcie_readl (dra7xx , PCIECTRL_DRA7XX_CONF_PHY_CS );
95
95
96
96
return !!(reg & LINK_UP );
97
97
}
98
98
99
99
static int dra7xx_pcie_establish_link (struct dra7xx_pcie * dra7xx )
100
100
{
101
- struct pcie_port * pp = & dra7xx -> pp ;
102
- struct device * dev = pp -> dev ;
101
+ struct dw_pcie * pci = dra7xx -> pci ;
102
+ struct device * dev = pci -> dev ;
103
103
u32 reg ;
104
104
u32 exp_cap_off = EXP_CAP_ID_OFFSET ;
105
105
106
- if (dw_pcie_link_up (pp )) {
106
+ if (dw_pcie_link_up (pci )) {
107
107
dev_err (dev , "link is already up\n" );
108
108
return 0 ;
109
109
}
110
110
111
111
if (dra7xx -> link_gen == 1 ) {
112
- dw_pcie_read (pp -> dbi_base + exp_cap_off + PCI_EXP_LNKCAP ,
112
+ dw_pcie_read (pci -> dbi_base + exp_cap_off + PCI_EXP_LNKCAP ,
113
113
4 , & reg );
114
114
if ((reg & PCI_EXP_LNKCAP_SLS ) != PCI_EXP_LNKCAP_SLS_2_5GB ) {
115
115
reg &= ~((u32 )PCI_EXP_LNKCAP_SLS );
116
116
reg |= PCI_EXP_LNKCAP_SLS_2_5GB ;
117
- dw_pcie_write (pp -> dbi_base + exp_cap_off +
117
+ dw_pcie_write (pci -> dbi_base + exp_cap_off +
118
118
PCI_EXP_LNKCAP , 4 , reg );
119
119
}
120
120
121
- dw_pcie_read (pp -> dbi_base + exp_cap_off + PCI_EXP_LNKCTL2 ,
121
+ dw_pcie_read (pci -> dbi_base + exp_cap_off + PCI_EXP_LNKCTL2 ,
122
122
2 , & reg );
123
123
if ((reg & PCI_EXP_LNKCAP_SLS ) != PCI_EXP_LNKCAP_SLS_2_5GB ) {
124
124
reg &= ~((u32 )PCI_EXP_LNKCAP_SLS );
125
125
reg |= PCI_EXP_LNKCAP_SLS_2_5GB ;
126
- dw_pcie_write (pp -> dbi_base + exp_cap_off +
126
+ dw_pcie_write (pci -> dbi_base + exp_cap_off +
127
127
PCI_EXP_LNKCTL2 , 2 , reg );
128
128
}
129
129
}
@@ -132,7 +132,7 @@ static int dra7xx_pcie_establish_link(struct dra7xx_pcie *dra7xx)
132
132
reg |= LTSSM_EN ;
133
133
dra7xx_pcie_writel (dra7xx , PCIECTRL_DRA7XX_CONF_DEVICE_CMD , reg );
134
134
135
- return dw_pcie_wait_for_link (pp );
135
+ return dw_pcie_wait_for_link (pci );
136
136
}
137
137
138
138
static void dra7xx_pcie_enable_interrupts (struct dra7xx_pcie * dra7xx )
@@ -149,7 +149,8 @@ static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie *dra7xx)
149
149
150
150
static void dra7xx_pcie_host_init (struct pcie_port * pp )
151
151
{
152
- struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pp );
152
+ struct dw_pcie * pci = to_dw_pcie_from_pp (pp );
153
+ struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pci );
153
154
154
155
pp -> io_base &= DRA7XX_CPU_TO_BUS_ADDR ;
155
156
pp -> mem_base &= DRA7XX_CPU_TO_BUS_ADDR ;
@@ -163,8 +164,7 @@ static void dra7xx_pcie_host_init(struct pcie_port *pp)
163
164
dra7xx_pcie_enable_interrupts (dra7xx );
164
165
}
165
166
166
- static struct pcie_host_ops dra7xx_pcie_host_ops = {
167
- .link_up = dra7xx_pcie_link_up ,
167
+ static struct dw_pcie_host_ops dra7xx_pcie_host_ops = {
168
168
.host_init = dra7xx_pcie_host_init ,
169
169
};
170
170
@@ -183,8 +183,9 @@ static const struct irq_domain_ops intx_domain_ops = {
183
183
184
184
static int dra7xx_pcie_init_irq_domain (struct pcie_port * pp )
185
185
{
186
- struct device * dev = pp -> dev ;
187
- struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pp );
186
+ struct dw_pcie * pci = to_dw_pcie_from_pp (pp );
187
+ struct device * dev = pci -> dev ;
188
+ struct dra7xx_pcie * dra7xx = to_dra7xx_pcie (pci );
188
189
struct device_node * node = dev -> of_node ;
189
190
struct device_node * pcie_intc_node = of_get_next_child (node , NULL );
190
191
@@ -206,7 +207,8 @@ static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
206
207
static irqreturn_t dra7xx_pcie_msi_irq_handler (int irq , void * arg )
207
208
{
208
209
struct dra7xx_pcie * dra7xx = arg ;
209
- struct pcie_port * pp = & dra7xx -> pp ;
210
+ struct dw_pcie * pci = dra7xx -> pci ;
211
+ struct pcie_port * pp = & pci -> pp ;
210
212
u32 reg ;
211
213
212
214
reg = dra7xx_pcie_readl (dra7xx , PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI );
@@ -233,7 +235,8 @@ static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
233
235
static irqreturn_t dra7xx_pcie_irq_handler (int irq , void * arg )
234
236
{
235
237
struct dra7xx_pcie * dra7xx = arg ;
236
- struct device * dev = dra7xx -> pp .dev ;
238
+ struct dw_pcie * pci = dra7xx -> pci ;
239
+ struct device * dev = pci -> dev ;
237
240
u32 reg ;
238
241
239
242
reg = dra7xx_pcie_readl (dra7xx , PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN );
@@ -288,8 +291,9 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
288
291
struct platform_device * pdev )
289
292
{
290
293
int ret ;
291
- struct pcie_port * pp = & dra7xx -> pp ;
292
- struct device * dev = pp -> dev ;
294
+ struct dw_pcie * pci = dra7xx -> pci ;
295
+ struct pcie_port * pp = & pci -> pp ;
296
+ struct device * dev = pci -> dev ;
293
297
struct resource * res ;
294
298
295
299
pp -> irq = platform_get_irq (pdev , 1 );
@@ -311,8 +315,8 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
311
315
return ret ;
312
316
313
317
res = platform_get_resource_byname (pdev , IORESOURCE_MEM , "rc_dbics" );
314
- pp -> dbi_base = devm_ioremap (dev , res -> start , resource_size (res ));
315
- if (!pp -> dbi_base )
318
+ pci -> dbi_base = devm_ioremap (dev , res -> start , resource_size (res ));
319
+ if (!pci -> dbi_base )
316
320
return - ENOMEM ;
317
321
318
322
ret = dw_pcie_host_init (pp );
@@ -324,6 +328,10 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
324
328
return 0 ;
325
329
}
326
330
331
+ static const struct dw_pcie_ops dw_pcie_ops = {
332
+ .link_up = dra7xx_pcie_link_up ,
333
+ };
334
+
327
335
static void dra7xx_pcie_disable_phy (struct dra7xx_pcie * dra7xx )
328
336
{
329
337
int phy_count = dra7xx -> phy_count ;
@@ -373,8 +381,9 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
373
381
struct phy * * phy ;
374
382
void __iomem * base ;
375
383
struct resource * res ;
376
- struct dra7xx_pcie * dra7xx ;
384
+ struct dw_pcie * pci ;
377
385
struct pcie_port * pp ;
386
+ struct dra7xx_pcie * dra7xx ;
378
387
struct device * dev = & pdev -> dev ;
379
388
struct device_node * np = dev -> of_node ;
380
389
char name [10 ];
@@ -384,8 +393,14 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
384
393
if (!dra7xx )
385
394
return - ENOMEM ;
386
395
387
- pp = & dra7xx -> pp ;
388
- pp -> dev = dev ;
396
+ pci = devm_kzalloc (dev , sizeof (* pci ), GFP_KERNEL );
397
+ if (!pci )
398
+ return - ENOMEM ;
399
+
400
+ pci -> dev = dev ;
401
+ pci -> ops = & dw_pcie_ops ;
402
+
403
+ pp = & pci -> pp ;
389
404
pp -> ops = & dra7xx_pcie_host_ops ;
390
405
391
406
irq = platform_get_irq (pdev , 0 );
@@ -425,6 +440,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
425
440
426
441
dra7xx -> base = base ;
427
442
dra7xx -> phy = phy ;
443
+ dra7xx -> pci = pci ;
428
444
dra7xx -> phy_count = phy_count ;
429
445
430
446
ret = dra7xx_pcie_enable_phy (dra7xx );
@@ -477,27 +493,27 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
477
493
static int dra7xx_pcie_suspend (struct device * dev )
478
494
{
479
495
struct dra7xx_pcie * dra7xx = dev_get_drvdata (dev );
480
- struct pcie_port * pp = & dra7xx -> pp ;
496
+ struct dw_pcie * pci = dra7xx -> pci ;
481
497
u32 val ;
482
498
483
499
/* clear MSE */
484
- val = dw_pcie_readl_rc ( pp , PCI_COMMAND );
500
+ val = dw_pcie_readl_dbi ( pci , PCI_COMMAND );
485
501
val &= ~PCI_COMMAND_MEMORY ;
486
- dw_pcie_writel_rc ( pp , PCI_COMMAND , val );
502
+ dw_pcie_writel_dbi ( pci , PCI_COMMAND , val );
487
503
488
504
return 0 ;
489
505
}
490
506
491
507
static int dra7xx_pcie_resume (struct device * dev )
492
508
{
493
509
struct dra7xx_pcie * dra7xx = dev_get_drvdata (dev );
494
- struct pcie_port * pp = & dra7xx -> pp ;
510
+ struct dw_pcie * pci = dra7xx -> pci ;
495
511
u32 val ;
496
512
497
513
/* set MSE */
498
- val = dw_pcie_readl_rc ( pp , PCI_COMMAND );
514
+ val = dw_pcie_readl_dbi ( pci , PCI_COMMAND );
499
515
val |= PCI_COMMAND_MEMORY ;
500
- dw_pcie_writel_rc ( pp , PCI_COMMAND , val );
516
+ dw_pcie_writel_dbi ( pci , PCI_COMMAND , val );
501
517
502
518
return 0 ;
503
519
}
0 commit comments