2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2003, 2004 Ralf Baechle (ralf@linux-mips.org)
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/pci.h>
12 #include <asm/marvell.h>
14 static int mv_read_config(struct pci_bus
*bus
, unsigned int devfn
,
15 int where
, int size
, u32
* val
)
17 struct mv_pci_controller
*mvbc
= bus
->sysdata
;
18 unsigned long address_reg
, data_reg
;
21 address_reg
= mvbc
->config_addr
;
22 data_reg
= mvbc
->config_vreg
;
24 /* Accessing device 31 crashes those Marvells. Since years.
25 Will they ever make sane controllers ... */
26 if (PCI_SLOT(devfn
) == 31)
27 return PCIBIOS_DEVICE_NOT_FOUND
;
29 address
= (bus
->number
<< 16) | (devfn
<< 8) |
30 (where
& 0xfc) | 0x80000000;
32 /* start the configuration cycle */
33 MV_WRITE(address_reg
, address
);
37 *val
= MV_READ_8(data_reg
+ (where
& 0x3));
41 *val
= MV_READ_16(data_reg
+ (where
& 0x3));
45 *val
= MV_READ(data_reg
);
49 return PCIBIOS_SUCCESSFUL
;
52 static int mv_write_config(struct pci_bus
*bus
, unsigned int devfn
,
53 int where
, int size
, u32 val
)
55 struct mv_pci_controller
*mvbc
= bus
->sysdata
;
56 unsigned long address_reg
, data_reg
;
59 address_reg
= mvbc
->config_addr
;
60 data_reg
= mvbc
->config_vreg
;
62 /* Accessing device 31 crashes those Marvells. Since years.
63 Will they ever make sane controllers ... */
64 if (PCI_SLOT(devfn
) == 31)
65 return PCIBIOS_DEVICE_NOT_FOUND
;
67 address
= (bus
->number
<< 16) | (devfn
<< 8) |
68 (where
& 0xfc) | 0x80000000;
70 /* start the configuration cycle */
71 MV_WRITE(address_reg
, address
);
75 MV_WRITE_8(data_reg
+ (where
& 0x3), val
);
79 MV_WRITE_16(data_reg
+ (where
& 0x3), val
);
83 MV_WRITE(data_reg
, val
);
87 return PCIBIOS_SUCCESSFUL
;
90 struct pci_ops mv_pci_ops
= {
91 .read
= mv_read_config
,
92 .write
= mv_write_config