diff options
Diffstat (limited to 'target/linux/brcm47xx-2.6/files/drivers/ssb')
6 files changed, 108 insertions, 83 deletions
diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/driver_chipcommon.c b/target/linux/brcm47xx-2.6/files/drivers/ssb/driver_chipcommon.c index 8e511c77b5..a283de9e3a 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/driver_chipcommon.c +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/driver_chipcommon.c @@ -293,15 +293,15 @@ void ssb_chipco_timing_init(struct ssb_chipcommon *cc, /* set register for external IO to control LED. */ chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11); - tmp = ceildiv(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ - tmp |= ceildiv(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ - tmp |= ceildiv(240, ns); /* Waitcount-0 = 240ns */ + tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ + tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */ + tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */ chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ /* Set timing for the flash */ - tmp = ceildiv(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ - tmp |= ceildiv(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ - tmp |= ceildiv(120, ns); /* Waitcount-0 = 120nS */ + tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */ + tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */ + tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */ if ((bus->chip_id == 0x5365) || (dev->id.revision < 9)) chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp); @@ -312,10 +312,10 @@ void ssb_chipco_timing_init(struct ssb_chipcommon *cc, if (bus->chip_id == 0x5350) { /* Enable EXTIF */ - tmp = ceildiv(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ - tmp |= ceildiv(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ - tmp |= ceildiv(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ - tmp |= ceildiv(120, ns); /* Waitcount-0 = 120ns */ + tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */ + tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */ + tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */ + tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */ chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */ } } diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/main.c b/target/linux/brcm47xx-2.6/files/drivers/ssb/main.c index a2d22312ca..a892f1dafc 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/main.c +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/main.c @@ -32,7 +32,7 @@ MODULE_LICENSE("GPL"); static LIST_HEAD(attach_queue); static LIST_HEAD(buses); -static int nr_buses; +static unsigned int next_busnumber; static DEFINE_MUTEX(buses_mutex); static void ssb_buses_lock(void); @@ -365,7 +365,7 @@ static int ssb_devices_register(struct ssb_bus *bus) dev->release = ssb_release_dev; dev->bus = &ssb_bustype; snprintf(dev->bus_id, sizeof(dev->bus_id), - "ssb%d:%d", bus->busnumber, dev_idx); + "ssb%u:%d", bus->busnumber, dev_idx); switch (bus->bustype) { case SSB_BUSTYPE_PCI: @@ -435,17 +435,6 @@ static int ssb_attach_queued_buses(void) return err; } -static void ssb_get_boardtype(struct ssb_bus *bus) -{//FIXME for pcmcia? - if (bus->bustype != SSB_BUSTYPE_PCI) { - /* Must set board_vendor, board_type and board_rev - * before calling ssb_bus_*_register() */ - assert(bus->board_vendor && bus->board_type); - return; - } - ssb_pci_get_boardtype(bus); -} - static u16 ssb_ssb_read16(struct ssb_device *dev, u16 offset) { struct ssb_bus *bus = dev->bus; @@ -485,7 +474,26 @@ static const struct ssb_bus_ops ssb_ssb_ops = { .write32 = ssb_ssb_write32, }; +static int ssb_fetch_invariants(struct ssb_bus *bus, + int (*get_invariants)(struct ssb_bus *bus, + struct ssb_init_invariants *iv)) +{ + struct ssb_init_invariants iv; + int err; + + memset(&iv, 0, sizeof(iv)); + err = get_invariants(bus, &iv); + if (err) + goto out; + memcpy(&bus->boardinfo, &iv.boardinfo, sizeof(iv.boardinfo)); + memcpy(&bus->sprom, &iv.sprom, sizeof(iv.sprom)); +out: + return err; +} + static int ssb_bus_register(struct ssb_bus *bus, + int (*get_invariants)(struct ssb_bus *bus, + struct ssb_init_invariants *iv), unsigned long baseaddr) { int err; @@ -493,13 +501,12 @@ static int ssb_bus_register(struct ssb_bus *bus, spin_lock_init(&bus->bar_lock); INIT_LIST_HEAD(&bus->list); - ssb_get_boardtype(bus); /* Powerup the bus */ err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1); if (err) goto out; ssb_buses_lock(); - bus->busnumber = nr_buses; + bus->busnumber = next_busnumber; /* Scan for devices (cores) */ err = ssb_bus_scan(bus, baseaddr); if (err) @@ -517,6 +524,9 @@ static int ssb_bus_register(struct ssb_bus *bus, /* Initialize basic system devices (if available) */ ssb_chipcommon_init(&bus->chipco); ssb_mipscore_init(&bus->mipscore); + err = ssb_fetch_invariants(bus, get_invariants); + if (err) + goto err_pcmcia_exit; /* Queue it for attach */ list_add_tail(&bus->list, &attach_queue); @@ -526,7 +536,7 @@ static int ssb_bus_register(struct ssb_bus *bus, if (err) goto err_dequeue; } - nr_buses++; + next_busnumber++; ssb_buses_unlock(); out: @@ -534,7 +544,7 @@ out: err_dequeue: list_del(&bus->list); -/* err_pcmcia_exit: */ +err_pcmcia_exit: /* ssb_pcmcia_exit(bus); */ err_pci_exit: ssb_pci_exit(bus); @@ -556,7 +566,7 @@ int ssb_bus_pcibus_register(struct ssb_bus *bus, bus->host_pci = host_pci; bus->ops = &ssb_pci_ops; - err = ssb_bus_register(bus, 0); + err = ssb_bus_register(bus, ssb_pci_get_invariants, 0); if (!err) { ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found on " "PCI device %s\n", host_pci->dev.bus_id); @@ -570,17 +580,15 @@ EXPORT_SYMBOL(ssb_bus_pcibus_register); #ifdef CONFIG_SSB_PCMCIAHOST int ssb_bus_pcmciabus_register(struct ssb_bus *bus, struct pcmcia_device *pcmcia_dev, - unsigned long baseaddr, - void (*fill_sprom)(struct ssb_sprom *sprom)) + unsigned long baseaddr) { int err; bus->bustype = SSB_BUSTYPE_PCMCIA; bus->host_pcmcia = pcmcia_dev; bus->ops = &ssb_pcmcia_ops; - fill_sprom(&bus->sprom); - err = ssb_bus_register(bus, baseaddr); + err = ssb_bus_register(bus, ssb_pcmcia_get_invariants, baseaddr); if (!err) { ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found on " "PCMCIA device %s\n", pcmcia_dev->devname); @@ -593,15 +601,15 @@ EXPORT_SYMBOL(ssb_bus_pcmciabus_register); int ssb_bus_ssbbus_register(struct ssb_bus *bus, unsigned long baseaddr, - void (*fill_sprom)(struct ssb_sprom *sprom)) + int (*get_invariants)(struct ssb_bus *bus, + struct ssb_init_invariants *iv)) { int err; bus->bustype = SSB_BUSTYPE_SSB; bus->ops = &ssb_ssb_ops; - fill_sprom(&bus->sprom); - err = ssb_bus_register(bus, baseaddr); + err = ssb_bus_register(bus, get_invariants, baseaddr); if (!err) { ssb_printk(KERN_INFO PFX "Sonics Silicon Backplane found at " "address 0x%08lX\n", baseaddr); diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/pci.c b/target/linux/brcm47xx-2.6/files/drivers/ssb/pci.c index fcd8e871cb..f9dc28f51f 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/pci.c +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/pci.c @@ -330,12 +330,12 @@ static void sprom_extract_r1(struct ssb_sprom_r1 *out, const u16 *in) SPEX(gpio2, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P2, 0); SPEX(gpio3, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P3, SSB_SPROM1_GPIOB_P3_SHIFT); - SPEX(maxpwr_a, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_A, 0); - SPEX(maxpwr_bg, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_BG, - SSB_SPROM1_MAXPWR_BG_SHIFT); - SPEX(itssi_a, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_A, 0); - SPEX(itssi_bg, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_BG, - SSB_SPROM1_ITSSI_BG_SHIFT); + SPEX(maxpwr_a, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_A, + SSB_SPROM1_MAXPWR_A_SHIFT); + SPEX(maxpwr_bg, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_BG, 0); + SPEX(itssi_a, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_A, + SSB_SPROM1_ITSSI_A_SHIFT); + SPEX(itssi_bg, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_BG, 0); SPEX(boardflags_lo, SSB_SPROM1_BFLLO, 0xFFFF, 0); SPEX(antenna_gain_a, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_A, 0); SPEX(antenna_gain_bg, SSB_SPROM1_AGAIN, SSB_SPROM1_AGAIN_BG, @@ -407,7 +407,8 @@ static void sprom_extract_r3(struct ssb_sprom_r3 *out, const u16 *in) out->ofdmgpo |= (in[SPOFF(SSB_SPROM3_OFDMGPO) + 1] & 0x00FF) << 8; } -static int sprom_extract(struct ssb_sprom *out, const u16 *in) +static int sprom_extract(struct ssb_bus *bus, + struct ssb_sprom *out, const u16 *in) { memset(out, 0, sizeof(*out)); @@ -415,16 +416,23 @@ static int sprom_extract(struct ssb_sprom *out, const u16 *in) SPEX(crc, SSB_SPROM_REVISION, SSB_SPROM_REVISION_CRC, SSB_SPROM_REVISION_CRC_SHIFT); - if (out->revision == 0) - goto unsupported; - if (out->revision >= 1 && out->revision <= 3) + if ((bus->chip_id & 0xFF00) == 0x4400) { + /* Workaround: The BCM44XX chip has a stupid revision + * number stored in the SPROM. + * Always extract r1. */ sprom_extract_r1(&out->r1, in); - if (out->revision >= 2 && out->revision <= 3) - sprom_extract_r2(&out->r2, in); - if (out->revision == 3) - sprom_extract_r3(&out->r3, in); - if (out->revision >= 4) - goto unsupported; + } else { + if (out->revision == 0) + goto unsupported; + if (out->revision >= 1 && out->revision <= 3) + sprom_extract_r1(&out->r1, in); + if (out->revision >= 2 && out->revision <= 3) + sprom_extract_r2(&out->r2, in); + if (out->revision == 3) + sprom_extract_r3(&out->r3, in); + if (out->revision >= 4) + goto unsupported; + } return 0; unsupported: @@ -434,13 +442,12 @@ unsupported: return 0; } -int ssb_pci_sprom_get(struct ssb_bus *bus) +static int ssb_pci_sprom_get(struct ssb_bus *bus, + struct ssb_sprom *sprom) { int err = -ENOMEM; u16 *buf; - assert(bus->bustype == SSB_BUSTYPE_PCI); - buf = kcalloc(SSB_SPROMSIZE_WORDS, sizeof(u16), GFP_KERNEL); if (!buf) goto out; @@ -450,21 +457,36 @@ int ssb_pci_sprom_get(struct ssb_bus *bus) ssb_printk(KERN_WARNING PFX "WARNING: Invalid SPROM CRC (corrupt SPROM)\n"); } - err = sprom_extract(&bus->sprom, buf); + err = sprom_extract(bus, sprom, buf); kfree(buf); out: return err; } -void ssb_pci_get_boardtype(struct ssb_bus *bus) +static void ssb_pci_get_boardinfo(struct ssb_bus *bus, + struct ssb_boardinfo *bi) { pci_read_config_word(bus->host_pci, PCI_SUBSYSTEM_VENDOR_ID, - &bus->board_vendor); + &bi->vendor); pci_read_config_word(bus->host_pci, PCI_SUBSYSTEM_ID, - &bus->board_type); + &bi->type); pci_read_config_word(bus->host_pci, PCI_REVISION_ID, - &bus->board_rev); + &bi->rev); +} + +int ssb_pci_get_invariants(struct ssb_bus *bus, + struct ssb_init_invariants *iv) +{ + int err; + + err = ssb_pci_sprom_get(bus, &iv->sprom); + if (err) + goto out; + ssb_pci_get_boardinfo(bus, &iv->boardinfo); + +out: + return err; } static u16 ssb_pci_read16(struct ssb_device *dev, u16 offset) @@ -660,13 +682,7 @@ int ssb_pci_init(struct ssb_bus *bus) err = device_create_file(&pdev->dev, &dev_attr_ssb_sprom); if (err) goto out; - err = ssb_pci_sprom_get(bus); - if (err) - goto err_remove_sprom_file; out: return err; -err_remove_sprom_file: - device_remove_file(&pdev->dev, &dev_attr_ssb_sprom); - return err; } diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/pcmcia.c b/target/linux/brcm47xx-2.6/files/drivers/ssb/pcmcia.c index 60cf5ad0f7..b9085633eb 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/pcmcia.c +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/pcmcia.c @@ -222,6 +222,13 @@ const struct ssb_bus_ops ssb_pcmcia_ops = { .write32 = ssb_pcmcia_write32, }; +int ssb_pcmcia_get_invariants(struct ssb_bus *bus, + struct ssb_init_invariants *iv) +{ + //TODO + return 0; +} + int ssb_pcmcia_init(struct ssb_bus *bus) { conf_reg_t reg; diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/scan.c b/target/linux/brcm47xx-2.6/files/drivers/ssb/scan.c index feaf1e57d0..b5d909c3a5 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/scan.c +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/scan.c @@ -202,7 +202,11 @@ void ssb_iounmap(struct ssb_bus *bus) iounmap(bus->mmio); break; case SSB_BUSTYPE_PCI: +#ifdef CONFIG_SSB_PCIHOST pci_iounmap(bus->host_pci, bus->mmio); +#else + assert(0); /* Can't reach this code. */ +#endif break; } bus->mmio = NULL; @@ -222,7 +226,11 @@ static void __iomem * ssb_ioremap(struct ssb_bus *bus, mmio = ioremap(baseaddr, SSB_CORE_SIZE); break; case SSB_BUSTYPE_PCI: +#ifdef CONFIG_SSB_PCIHOST mmio = pci_iomap(bus->host_pci, 0, ~0UL); +#else + assert(0); /* Can't reach this code. */ +#endif break; } diff --git a/target/linux/brcm47xx-2.6/files/drivers/ssb/ssb_private.h b/target/linux/brcm47xx-2.6/files/drivers/ssb/ssb_private.h index ae1fc0633d..d00d186074 100644 --- a/target/linux/brcm47xx-2.6/files/drivers/ssb/ssb_private.h +++ b/target/linux/brcm47xx-2.6/files/drivers/ssb/ssb_private.h @@ -51,8 +51,8 @@ extern int ssb_pci_switch_coreidx(struct ssb_bus *bus, u8 coreidx); extern int ssb_pci_xtal(struct ssb_bus *bus, u32 what, int turn_on); -extern int ssb_pci_sprom_get(struct ssb_bus *bus); -extern void ssb_pci_get_boardtype(struct ssb_bus *bus); +extern int ssb_pci_get_invariants(struct ssb_bus *bus, + struct ssb_init_invariants *iv); extern void ssb_pci_exit(struct ssb_bus *bus); extern int ssb_pci_init(struct ssb_bus *bus); extern const struct ssb_bus_ops ssb_pci_ops; @@ -74,13 +74,6 @@ static inline int ssb_pci_xtal(struct ssb_bus *bus, u32 what, { return 0; } -static inline int ssb_pci_sprom_get(struct ssb_bus *bus) -{ - return 0; -} -static inline void ssb_pci_get_boardtype(struct ssb_bus *bus) -{ -} static inline void ssb_pci_exit(struct ssb_bus *bus) { } @@ -99,6 +92,8 @@ extern int ssb_pcmcia_switch_coreidx(struct ssb_bus *bus, u8 coreidx); extern int ssb_pcmcia_switch_segment(struct ssb_bus *bus, u8 seg); +extern int ssb_pcmcia_get_invariants(struct ssb_bus *bus, + struct ssb_init_invariants *iv); extern int ssb_pcmcia_init(struct ssb_bus *bus); extern const struct ssb_bus_ops ssb_pcmcia_ops; #else /* CONFIG_SSB_PCMCIAHOST */ @@ -139,13 +134,4 @@ extern int ssb_devices_thaw(struct ssb_bus *bus); extern struct ssb_bus * ssb_pci_dev_to_bus(struct pci_dev *pdev); #endif /* CONFIG_SSB_PCIHOST */ - -/* Ceiling division helper. Divides x by y. */ -static inline -unsigned long ceildiv(unsigned long x, unsigned long y) -{ - return ((x + (y - 1)) / y); -} - - #endif /* LINUX_SSB_PRIVATE_H_ */ |