2 * Generic SH-4 / SH-4A PCIC operations (SH7751, SH7780).
4 * Copyright (C) 2002 - 2009 Paul Mundt
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License v2. See the file "COPYING" in the main directory of this archive
10 #include <linux/pci.h>
12 #include <linux/spinlock.h>
13 #include <asm/addrspace.h>
17 * Direct access to PCI hardware...
19 #define CONFIG_CMD(bus, devfn, where) \
20 (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
23 * Functions for accessing PCI configuration space with type 1 accesses
25 static int sh4_pci_read(struct pci_bus
*bus
, unsigned int devfn
,
26 int where
, int size
, u32
*val
)
28 struct pci_channel
*chan
= bus
->sysdata
;
33 * PCIPDR may only be accessed as 32 bit words,
34 * so we must do byte alignment by hand
36 raw_spin_lock_irqsave(&pci_config_lock
, flags
);
37 pci_write_reg(chan
, CONFIG_CMD(bus
, devfn
, where
), SH4_PCIPAR
);
38 data
= pci_read_reg(chan
, SH4_PCIPDR
);
39 raw_spin_unlock_irqrestore(&pci_config_lock
, flags
);
43 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
46 *val
= (data
>> ((where
& 2) << 3)) & 0xffff;
52 return PCIBIOS_FUNC_NOT_SUPPORTED
;
55 return PCIBIOS_SUCCESSFUL
;
59 * Since SH4 only does 32bit access we'll have to do a read,
60 * mask,write operation.
61 * We'll allow an odd byte offset, though it should be illegal.
63 static int sh4_pci_write(struct pci_bus
*bus
, unsigned int devfn
,
64 int where
, int size
, u32 val
)
66 struct pci_channel
*chan
= bus
->sysdata
;
71 raw_spin_lock_irqsave(&pci_config_lock
, flags
);
72 pci_write_reg(chan
, CONFIG_CMD(bus
, devfn
, where
), SH4_PCIPAR
);
73 data
= pci_read_reg(chan
, SH4_PCIPDR
);
74 raw_spin_unlock_irqrestore(&pci_config_lock
, flags
);
78 shift
= (where
& 3) << 3;
79 data
&= ~(0xff << shift
);
80 data
|= ((val
& 0xff) << shift
);
83 shift
= (where
& 2) << 3;
84 data
&= ~(0xffff << shift
);
85 data
|= ((val
& 0xffff) << shift
);
91 return PCIBIOS_FUNC_NOT_SUPPORTED
;
94 pci_write_reg(chan
, data
, SH4_PCIPDR
);
96 return PCIBIOS_SUCCESSFUL
;
99 struct pci_ops sh4_pci_ops
= {
100 .read
= sh4_pci_read
,
101 .write
= sh4_pci_write
,
104 int __attribute__((weak
)) pci_fixup_pcic(struct pci_channel
*chan
)