Path: blob/master/arch/powerpc/platforms/chrp/pci.c
10820 views
/*1* CHRP pci routines.2*/34#include <linux/kernel.h>5#include <linux/pci.h>6#include <linux/delay.h>7#include <linux/string.h>8#include <linux/init.h>910#include <asm/io.h>11#include <asm/pgtable.h>12#include <asm/irq.h>13#include <asm/hydra.h>14#include <asm/prom.h>15#include <asm/machdep.h>16#include <asm/sections.h>17#include <asm/pci-bridge.h>18#include <asm/grackle.h>19#include <asm/rtas.h>2021#include "chrp.h"22#include "gg2.h"2324/* LongTrail */25void __iomem *gg2_pci_config_base;2627/*28* The VLSI Golden Gate II has only 512K of PCI configuration space, so we29* limit the bus number to 3 bits30*/3132int gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off,33int len, u32 *val)34{35volatile void __iomem *cfg_data;36struct pci_controller *hose = pci_bus_to_host(bus);3738if (bus->number > 7)39return PCIBIOS_DEVICE_NOT_FOUND;40/*41* Note: the caller has already checked that off is42* suitably aligned and that len is 1, 2 or 4.43*/44cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);45switch (len) {46case 1:47*val = in_8(cfg_data);48break;49case 2:50*val = in_le16(cfg_data);51break;52default:53*val = in_le32(cfg_data);54break;55}56return PCIBIOS_SUCCESSFUL;57}5859int gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off,60int len, u32 val)61{62volatile void __iomem *cfg_data;63struct pci_controller *hose = pci_bus_to_host(bus);6465if (bus->number > 7)66return PCIBIOS_DEVICE_NOT_FOUND;67/*68* Note: the caller has already checked that off is69* suitably aligned and that len is 1, 2 or 4.70*/71cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);72switch (len) {73case 1:74out_8(cfg_data, val);75break;76case 2:77out_le16(cfg_data, val);78break;79default:80out_le32(cfg_data, val);81break;82}83return PCIBIOS_SUCCESSFUL;84}8586static struct pci_ops gg2_pci_ops =87{88.read = gg2_read_config,89.write = gg2_write_config,90};9192/*93* Access functions for PCI config space using RTAS calls.94*/95int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,96int len, u32 *val)97{98struct pci_controller *hose = pci_bus_to_host(bus);99unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)100| (((bus->number - hose->first_busno) & 0xff) << 16)101| (hose->global_number << 24);102int ret = -1;103int rval;104105rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);106*val = ret;107return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;108}109110int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,111int len, u32 val)112{113struct pci_controller *hose = pci_bus_to_host(bus);114unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)115| (((bus->number - hose->first_busno) & 0xff) << 16)116| (hose->global_number << 24);117int rval;118119rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,120addr, len, val);121return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;122}123124static struct pci_ops rtas_pci_ops =125{126.read = rtas_read_config,127.write = rtas_write_config,128};129130volatile struct Hydra __iomem *Hydra = NULL;131132int __init133hydra_init(void)134{135struct device_node *np;136struct resource r;137138np = of_find_node_by_name(NULL, "mac-io");139if (np == NULL || of_address_to_resource(np, 0, &r)) {140of_node_put(np);141return 0;142}143of_node_put(np);144Hydra = ioremap(r.start, r.end-r.start);145printk("Hydra Mac I/O at %llx\n", (unsigned long long)r.start);146printk("Hydra Feature_Control was %x",147in_le32(&Hydra->Feature_Control));148out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN |149HYDRA_FC_SCSI_CELL_EN |150HYDRA_FC_SCCA_ENABLE |151HYDRA_FC_SCCB_ENABLE |152HYDRA_FC_ARB_BYPASS |153HYDRA_FC_MPIC_ENABLE |154HYDRA_FC_SLOW_SCC_PCLK |155HYDRA_FC_MPIC_IS_MASTER));156printk(", now %x\n", in_le32(&Hydra->Feature_Control));157return 1;158}159160#define PRG_CL_RESET_VALID 0x00010000161162static void __init163setup_python(struct pci_controller *hose, struct device_node *dev)164{165u32 __iomem *reg;166u32 val;167struct resource r;168169if (of_address_to_resource(dev, 0, &r)) {170printk(KERN_ERR "No address for Python PCI controller\n");171return;172}173174/* Clear the magic go-slow bit */175reg = ioremap(r.start + 0xf6000, 0x40);176BUG_ON(!reg);177val = in_be32(®[12]);178if (val & PRG_CL_RESET_VALID) {179out_be32(®[12], val & ~PRG_CL_RESET_VALID);180in_be32(®[12]);181}182iounmap(reg);183184setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010, 0);185}186187/* Marvell Discovery II based Pegasos 2 */188static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev)189{190struct device_node *root = of_find_node_by_path("/");191struct device_node *rtas;192193rtas = of_find_node_by_name (root, "rtas");194if (rtas) {195hose->ops = &rtas_pci_ops;196of_node_put(rtas);197} else {198printk ("RTAS supporting Pegasos OF not found, please upgrade"199" your firmware\n");200}201ppc_pci_add_flags(PPC_PCI_REASSIGN_ALL_BUS);202/* keep the reference to the root node */203}204205void __init206chrp_find_bridges(void)207{208struct device_node *dev;209const int *bus_range;210int len, index = -1;211struct pci_controller *hose;212const unsigned int *dma;213const char *model, *machine;214int is_longtrail = 0, is_mot = 0, is_pegasos = 0;215struct device_node *root = of_find_node_by_path("/");216struct resource r;217/*218* The PCI host bridge nodes on some machines don't have219* properties to adequately identify them, so we have to220* look at what sort of machine this is as well.221*/222machine = of_get_property(root, "model", NULL);223if (machine != NULL) {224is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;225is_mot = strncmp(machine, "MOT", 3) == 0;226if (strncmp(machine, "Pegasos2", 8) == 0)227is_pegasos = 2;228else if (strncmp(machine, "Pegasos", 7) == 0)229is_pegasos = 1;230}231for (dev = root->child; dev != NULL; dev = dev->sibling) {232if (dev->type == NULL || strcmp(dev->type, "pci") != 0)233continue;234++index;235/* The GG2 bridge on the LongTrail doesn't have an address */236if (of_address_to_resource(dev, 0, &r) && !is_longtrail) {237printk(KERN_WARNING "Can't use %s: no address\n",238dev->full_name);239continue;240}241bus_range = of_get_property(dev, "bus-range", &len);242if (bus_range == NULL || len < 2 * sizeof(int)) {243printk(KERN_WARNING "Can't get bus-range for %s\n",244dev->full_name);245continue;246}247if (bus_range[1] == bus_range[0])248printk(KERN_INFO "PCI bus %d", bus_range[0]);249else250printk(KERN_INFO "PCI buses %d..%d",251bus_range[0], bus_range[1]);252printk(" controlled by %s", dev->full_name);253if (!is_longtrail)254printk(" at %llx", (unsigned long long)r.start);255printk("\n");256257hose = pcibios_alloc_controller(dev);258if (!hose) {259printk("Can't allocate PCI controller structure for %s\n",260dev->full_name);261continue;262}263hose->first_busno = hose->self_busno = bus_range[0];264hose->last_busno = bus_range[1];265266model = of_get_property(dev, "model", NULL);267if (model == NULL)268model = "<none>";269if (strncmp(model, "IBM, Python", 11) == 0) {270setup_python(hose, dev);271} else if (is_mot272|| strncmp(model, "Motorola, Grackle", 17) == 0) {273setup_grackle(hose);274} else if (is_longtrail) {275void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000);276hose->ops = &gg2_pci_ops;277hose->cfg_data = p;278gg2_pci_config_base = p;279} else if (is_pegasos == 1) {280setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc, 0);281} else if (is_pegasos == 2) {282setup_peg2(hose, dev);283} else if (!strncmp(model, "IBM,CPC710", 10)) {284setup_indirect_pci(hose,285r.start + 0x000f8000,286r.start + 0x000f8010,2870);288if (index == 0) {289dma = of_get_property(dev, "system-dma-base",290&len);291if (dma && len >= sizeof(*dma)) {292dma = (unsigned int *)293(((unsigned long)dma) +294len - sizeof(*dma));295pci_dram_offset = *dma;296}297}298} else {299printk("No methods for %s (model %s), using RTAS\n",300dev->full_name, model);301hose->ops = &rtas_pci_ops;302}303304pci_process_bridge_OF_ranges(hose, dev, index == 0);305306/* check the first bridge for a property that we can307use to set pci_dram_offset */308dma = of_get_property(dev, "ibm,dma-ranges", &len);309if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {310pci_dram_offset = dma[2] - dma[3];311printk("pci_dram_offset = %lx\n", pci_dram_offset);312}313}314of_node_put(root);315}316317/* SL82C105 IDE Control/Status Register */318#define SL82C105_IDECSR 0x40319320/* Fixup for Winbond ATA quirk, required for briq mostly because the321* 8259 is configured for level sensitive IRQ 14 and so wants the322* ATA controller to be set to fully native mode or bad things323* will happen.324*/325static void __devinit chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105)326{327u8 progif;328329/* If non-briq machines need that fixup too, please speak up */330if (!machine_is(chrp) || _chrp_type != _CHRP_briq)331return;332333if ((sl82c105->class & 5) != 5) {334printk("W83C553: Switching SL82C105 IDE to PCI native mode\n");335/* Enable SL82C105 PCI native IDE mode */336pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif);337pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05);338sl82c105->class |= 0x05;339/* Disable SL82C105 second port */340pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003);341/* Clear IO BARs, they will be reassigned */342pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_0, 0);343pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_1, 0);344pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_2, 0);345pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_3, 0);346}347}348DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,349chrp_pci_fixup_winbond_ata);350351/* Pegasos2 firmware version 20040810 configures the built-in IDE controller352* in legacy mode, but sets the PCI registers to PCI native mode.353* The chip can only operate in legacy mode, so force the PCI class into legacy354* mode as well. The same fixup must be done to the class-code property in355* the IDE node /pci@80000000/ide@C,1356*/357static void chrp_pci_fixup_vt8231_ata(struct pci_dev *viaide)358{359u8 progif;360struct pci_dev *viaisa;361362if (!machine_is(chrp) || _chrp_type != _CHRP_Pegasos)363return;364if (viaide->irq != 14)365return;366367viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);368if (!viaisa)369return;370dev_info(&viaide->dev, "Fixing VIA IDE, force legacy mode on\n");371372pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif);373pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5);374viaide->class &= ~0x5;375376pci_dev_put(viaisa);377}378DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, chrp_pci_fixup_vt8231_ata);379380381