4848
4949#define AR71XX_PCI_IRQ_COUNT 5
5050
51- static DEFINE_SPINLOCK (ar71xx_pci_lock );
52- static void __iomem * ar71xx_pcicfg_base ;
51+ struct ar71xx_pci_controller {
52+ void __iomem * cfg_base ;
53+ spinlock_t lock ;
54+ int irq ;
55+ struct pci_controller pci_ctrl ;
56+ };
5357
5458/* Byte lane enable bits */
5559static const u8 ar71xx_pci_ble_table [4 ][4 ] = {
@@ -92,9 +96,18 @@ static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
9296 return ret ;
9397}
9498
95- static int ar71xx_pci_check_error (int quiet )
99+ static inline struct ar71xx_pci_controller *
100+ pci_bus_to_ar71xx_controller (struct pci_bus * bus )
96101{
97- void __iomem * base = ar71xx_pcicfg_base ;
102+ struct pci_controller * hose ;
103+
104+ hose = (struct pci_controller * ) bus -> sysdata ;
105+ return container_of (hose , struct ar71xx_pci_controller , pci_ctrl );
106+ }
107+
108+ static int ar71xx_pci_check_error (struct ar71xx_pci_controller * apc , int quiet )
109+ {
110+ void __iomem * base = apc -> cfg_base ;
98111 u32 pci_err ;
99112 u32 ahb_err ;
100113
@@ -129,9 +142,10 @@ static int ar71xx_pci_check_error(int quiet)
129142 return !!(ahb_err | pci_err );
130143}
131144
132- static inline void ar71xx_pci_local_write (int where , int size , u32 value )
145+ static inline void ar71xx_pci_local_write (struct ar71xx_pci_controller * apc ,
146+ int where , int size , u32 value )
133147{
134- void __iomem * base = ar71xx_pcicfg_base ;
148+ void __iomem * base = apc -> cfg_base ;
135149 u32 ad_cbe ;
136150
137151 value = value << (8 * (where & 3 ));
@@ -147,7 +161,8 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
147161 unsigned int devfn ,
148162 int where , int size , u32 cmd )
149163{
150- void __iomem * base = ar71xx_pcicfg_base ;
164+ struct ar71xx_pci_controller * apc = pci_bus_to_ar71xx_controller (bus );
165+ void __iomem * base = apc -> cfg_base ;
151166 u32 addr ;
152167
153168 addr = ar71xx_pci_bus_addr (bus , devfn , where );
@@ -156,13 +171,14 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
156171 __raw_writel (cmd | ar71xx_pci_get_ble (where , size , 0 ),
157172 base + AR71XX_PCI_REG_CFG_CBE );
158173
159- return ar71xx_pci_check_error (1 );
174+ return ar71xx_pci_check_error (apc , 1 );
160175}
161176
162177static int ar71xx_pci_read_config (struct pci_bus * bus , unsigned int devfn ,
163178 int where , int size , u32 * value )
164179{
165- void __iomem * base = ar71xx_pcicfg_base ;
180+ struct ar71xx_pci_controller * apc = pci_bus_to_ar71xx_controller (bus );
181+ void __iomem * base = apc -> cfg_base ;
166182 unsigned long flags ;
167183 u32 data ;
168184 int err ;
@@ -171,7 +187,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
171187 ret = PCIBIOS_SUCCESSFUL ;
172188 data = ~0 ;
173189
174- spin_lock_irqsave (& ar71xx_pci_lock , flags );
190+ spin_lock_irqsave (& apc -> lock , flags );
175191
176192 err = ar71xx_pci_set_cfgaddr (bus , devfn , where , size ,
177193 AR71XX_PCI_CFG_CMD_READ );
@@ -180,7 +196,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
180196 else
181197 data = __raw_readl (base + AR71XX_PCI_REG_CFG_RDDATA );
182198
183- spin_unlock_irqrestore (& ar71xx_pci_lock , flags );
199+ spin_unlock_irqrestore (& apc -> lock , flags );
184200
185201 * value = (data >> (8 * (where & 3 ))) & ar71xx_pci_read_mask [size & 7 ];
186202
@@ -190,15 +206,16 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
190206static int ar71xx_pci_write_config (struct pci_bus * bus , unsigned int devfn ,
191207 int where , int size , u32 value )
192208{
193- void __iomem * base = ar71xx_pcicfg_base ;
209+ struct ar71xx_pci_controller * apc = pci_bus_to_ar71xx_controller (bus );
210+ void __iomem * base = apc -> cfg_base ;
194211 unsigned long flags ;
195212 int err ;
196213 int ret ;
197214
198215 value = value << (8 * (where & 3 ));
199216 ret = PCIBIOS_SUCCESSFUL ;
200217
201- spin_lock_irqsave (& ar71xx_pci_lock , flags );
218+ spin_lock_irqsave (& apc -> lock , flags );
202219
203220 err = ar71xx_pci_set_cfgaddr (bus , devfn , where , size ,
204221 AR71XX_PCI_CFG_CMD_WRITE );
@@ -207,7 +224,7 @@ static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
207224 else
208225 __raw_writel (value , base + AR71XX_PCI_REG_CFG_WRDATA );
209226
210- spin_unlock_irqrestore (& ar71xx_pci_lock , flags );
227+ spin_unlock_irqrestore (& apc -> lock , flags );
211228
212229 return ret ;
213230}
@@ -231,12 +248,6 @@ static struct resource ar71xx_pci_mem_resource = {
231248 .flags = IORESOURCE_MEM
232249};
233250
234- static struct pci_controller ar71xx_pci_controller = {
235- .pci_ops = & ar71xx_pci_ops ,
236- .mem_resource = & ar71xx_pci_mem_resource ,
237- .io_resource = & ar71xx_pci_io_resource ,
238- };
239-
240251static void ar71xx_pci_irq_handler (unsigned int irq , struct irq_desc * desc )
241252{
242253 void __iomem * base = ath79_reset_base ;
@@ -294,7 +305,7 @@ static struct irq_chip ar71xx_pci_irq_chip = {
294305 .irq_mask_ack = ar71xx_pci_irq_mask ,
295306};
296307
297- static void ar71xx_pci_irq_init (int irq )
308+ static void ar71xx_pci_irq_init (struct ar71xx_pci_controller * apc )
298309{
299310 void __iomem * base = ath79_reset_base ;
300311 int i ;
@@ -309,7 +320,7 @@ static void ar71xx_pci_irq_init(int irq)
309320 irq_set_chip_and_handler (i , & ar71xx_pci_irq_chip ,
310321 handle_level_irq );
311322
312- irq_set_chained_handler (irq , ar71xx_pci_irq_handler );
323+ irq_set_chained_handler (apc -> irq , ar71xx_pci_irq_handler );
313324}
314325
315326static void ar71xx_pci_reset (void )
@@ -336,35 +347,46 @@ static void ar71xx_pci_reset(void)
336347
337348static int ar71xx_pci_probe (struct platform_device * pdev )
338349{
350+ struct ar71xx_pci_controller * apc ;
339351 struct resource * res ;
340- int irq ;
341352 u32 t ;
342353
354+ apc = devm_kzalloc (& pdev -> dev , sizeof (struct ar71xx_pci_controller ),
355+ GFP_KERNEL );
356+ if (!apc )
357+ return - ENOMEM ;
358+
359+ spin_lock_init (& apc -> lock );
360+
343361 res = platform_get_resource_byname (pdev , IORESOURCE_MEM , "cfg_base" );
344362 if (!res )
345363 return - EINVAL ;
346364
347- ar71xx_pcicfg_base = devm_request_and_ioremap (& pdev -> dev , res );
348- if (!ar71xx_pcicfg_base )
365+ apc -> cfg_base = devm_request_and_ioremap (& pdev -> dev , res );
366+ if (!apc -> cfg_base )
349367 return - ENOMEM ;
350368
351- irq = platform_get_irq (pdev , 0 );
352- if (irq < 0 )
369+ apc -> irq = platform_get_irq (pdev , 0 );
370+ if (apc -> irq < 0 )
353371 return - EINVAL ;
354372
355373 ar71xx_pci_reset ();
356374
357375 /* setup COMMAND register */
358376 t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
359377 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK ;
360- ar71xx_pci_local_write (PCI_COMMAND , 4 , t );
378+ ar71xx_pci_local_write (apc , PCI_COMMAND , 4 , t );
361379
362380 /* clear bus errors */
363- ar71xx_pci_check_error (1 );
381+ ar71xx_pci_check_error (apc , 1 );
382+
383+ ar71xx_pci_irq_init (apc );
364384
365- ar71xx_pci_irq_init (irq );
385+ apc -> pci_ctrl .pci_ops = & ar71xx_pci_ops ;
386+ apc -> pci_ctrl .mem_resource = & ar71xx_pci_mem_resource ;
387+ apc -> pci_ctrl .io_resource = & ar71xx_pci_io_resource ;
366388
367- register_pci_controller (& ar71xx_pci_controller );
389+ register_pci_controller (& apc -> pci_ctrl );
368390
369391 return 0 ;
370392}
0 commit comments