Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 309038
b: refs/heads/master
c: c198441
h: refs/heads/master
v: v3
  • Loading branch information
Gabor Juhos authored and Ralf Baechle committed May 15, 2012
1 parent 1d42183 commit 2046441
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d624bd3cf7835612b25b9ec8db4002624c2dbb32
refs/heads/master: c198441a3f3007752c551a32d5c426f48ae8712d
38 changes: 24 additions & 14 deletions trunk/arch/mips/pci/pci-ar724x.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,47 @@
#include <linux/pci.h>
#include <asm/mach-ath79/pci.h>

#define reg_read(_phys) (*(unsigned int *) KSEG1ADDR(_phys))
#define reg_write(_phys, _val) ((*(unsigned int *) KSEG1ADDR(_phys)) = (_val))

#define AR724X_PCI_DEV_BASE 0x14000000
#define AR724X_PCI_CFG_BASE 0x14000000
#define AR724X_PCI_CFG_SIZE 0x1000
#define AR724X_PCI_MEM_BASE 0x10000000
#define AR724X_PCI_MEM_SIZE 0x08000000

static DEFINE_SPINLOCK(ar724x_pci_lock);
static void __iomem *ar724x_pci_devcfg_base;

static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
int size, uint32_t *value)
{
unsigned long flags, addr, tval, mask;
void __iomem *base;

if (devfn)
return PCIBIOS_DEVICE_NOT_FOUND;

if (where & (size - 1))
return PCIBIOS_BAD_REGISTER_NUMBER;

base = ar724x_pci_devcfg_base;

spin_lock_irqsave(&ar724x_pci_lock, flags);

switch (size) {
case 1:
addr = where & ~3;
mask = 0xff000000 >> ((where % 4) * 8);
tval = reg_read(AR724X_PCI_DEV_BASE + addr);
tval = __raw_readl(base + addr);
tval = tval & ~mask;
*value = (tval >> ((4 - (where % 4))*8));
break;
case 2:
addr = where & ~3;
mask = 0xffff0000 >> ((where % 4)*8);
tval = reg_read(AR724X_PCI_DEV_BASE + addr);
tval = __raw_readl(base + addr);
tval = tval & ~mask;
*value = (tval >> ((4 - (where % 4))*8));
break;
case 4:
*value = reg_read(AR724X_PCI_DEV_BASE + where);
*value = __raw_readl(base + where);
break;
default:
spin_unlock_irqrestore(&ar724x_pci_lock, flags);
Expand All @@ -66,34 +68,37 @@ static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
int size, uint32_t value)
{
unsigned long flags, tval, addr, mask;
void __iomem *base;

if (devfn)
return PCIBIOS_DEVICE_NOT_FOUND;

if (where & (size - 1))
return PCIBIOS_BAD_REGISTER_NUMBER;

base = ar724x_pci_devcfg_base;

spin_lock_irqsave(&ar724x_pci_lock, flags);

switch (size) {
case 1:
addr = (AR724X_PCI_DEV_BASE + where) & ~3;
addr = where & ~3;
mask = 0xff000000 >> ((where % 4)*8);
tval = reg_read(addr);
tval = __raw_readl(base + addr);
tval = tval & ~mask;
tval |= (value << ((4 - (where % 4))*8)) & mask;
reg_write(addr, tval);
__raw_writel(tval, base + addr);
break;
case 2:
addr = (AR724X_PCI_DEV_BASE + where) & ~3;
addr = where & ~3;
mask = 0xffff0000 >> ((where % 4)*8);
tval = reg_read(addr);
tval = __raw_readl(base + addr);
tval = tval & ~mask;
tval |= (value << ((4 - (where % 4))*8)) & mask;
reg_write(addr, tval);
__raw_writel(tval, base + addr);
break;
case 4:
reg_write((AR724X_PCI_DEV_BASE + where), value);
__raw_writel(value, (base + where));
break;
default:
spin_unlock_irqrestore(&ar724x_pci_lock, flags);
Expand Down Expand Up @@ -133,6 +138,11 @@ static struct pci_controller ar724x_pci_controller = {

int __init ar724x_pcibios_init(void)
{
ar724x_pci_devcfg_base = ioremap(AR724X_PCI_CFG_BASE,
AR724X_PCI_CFG_SIZE);
if (ar724x_pci_devcfg_base == NULL)
return -ENOMEM;

register_pci_controller(&ar724x_pci_controller);

return PCIBIOS_SUCCESSFUL;
Expand Down

0 comments on commit 2046441

Please sign in to comment.