18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CHRP pci routines. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/kernel.h> 78c2ecf20Sopenharmony_ci#include <linux/pci.h> 88c2ecf20Sopenharmony_ci#include <linux/delay.h> 98c2ecf20Sopenharmony_ci#include <linux/string.h> 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci#include <linux/pgtable.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <asm/io.h> 148c2ecf20Sopenharmony_ci#include <asm/irq.h> 158c2ecf20Sopenharmony_ci#include <asm/hydra.h> 168c2ecf20Sopenharmony_ci#include <asm/prom.h> 178c2ecf20Sopenharmony_ci#include <asm/machdep.h> 188c2ecf20Sopenharmony_ci#include <asm/sections.h> 198c2ecf20Sopenharmony_ci#include <asm/pci-bridge.h> 208c2ecf20Sopenharmony_ci#include <asm/grackle.h> 218c2ecf20Sopenharmony_ci#include <asm/rtas.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "chrp.h" 248c2ecf20Sopenharmony_ci#include "gg2.h" 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* LongTrail */ 278c2ecf20Sopenharmony_civoid __iomem *gg2_pci_config_base; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * The VLSI Golden Gate II has only 512K of PCI configuration space, so we 318c2ecf20Sopenharmony_ci * limit the bus number to 3 bits 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic int gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off, 358c2ecf20Sopenharmony_ci int len, u32 *val) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci volatile void __iomem *cfg_data; 388c2ecf20Sopenharmony_ci struct pci_controller *hose = pci_bus_to_host(bus); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci if (bus->number > 7) 418c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 428c2ecf20Sopenharmony_ci /* 438c2ecf20Sopenharmony_ci * Note: the caller has already checked that off is 448c2ecf20Sopenharmony_ci * suitably aligned and that len is 1, 2 or 4. 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_ci cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off); 478c2ecf20Sopenharmony_ci switch (len) { 488c2ecf20Sopenharmony_ci case 1: 498c2ecf20Sopenharmony_ci *val = in_8(cfg_data); 508c2ecf20Sopenharmony_ci break; 518c2ecf20Sopenharmony_ci case 2: 528c2ecf20Sopenharmony_ci *val = in_le16(cfg_data); 538c2ecf20Sopenharmony_ci break; 548c2ecf20Sopenharmony_ci default: 558c2ecf20Sopenharmony_ci *val = in_le32(cfg_data); 568c2ecf20Sopenharmony_ci break; 578c2ecf20Sopenharmony_ci } 588c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic int gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off, 628c2ecf20Sopenharmony_ci int len, u32 val) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci volatile void __iomem *cfg_data; 658c2ecf20Sopenharmony_ci struct pci_controller *hose = pci_bus_to_host(bus); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (bus->number > 7) 688c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 698c2ecf20Sopenharmony_ci /* 708c2ecf20Sopenharmony_ci * Note: the caller has already checked that off is 718c2ecf20Sopenharmony_ci * suitably aligned and that len is 1, 2 or 4. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_ci cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off); 748c2ecf20Sopenharmony_ci switch (len) { 758c2ecf20Sopenharmony_ci case 1: 768c2ecf20Sopenharmony_ci out_8(cfg_data, val); 778c2ecf20Sopenharmony_ci break; 788c2ecf20Sopenharmony_ci case 2: 798c2ecf20Sopenharmony_ci out_le16(cfg_data, val); 808c2ecf20Sopenharmony_ci break; 818c2ecf20Sopenharmony_ci default: 828c2ecf20Sopenharmony_ci out_le32(cfg_data, val); 838c2ecf20Sopenharmony_ci break; 848c2ecf20Sopenharmony_ci } 858c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic struct pci_ops gg2_pci_ops = 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci .read = gg2_read_config, 918c2ecf20Sopenharmony_ci .write = gg2_write_config, 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* 958c2ecf20Sopenharmony_ci * Access functions for PCI config space using RTAS calls. 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_cistatic int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset, 988c2ecf20Sopenharmony_ci int len, u32 *val) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci struct pci_controller *hose = pci_bus_to_host(bus); 1018c2ecf20Sopenharmony_ci unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8) 1028c2ecf20Sopenharmony_ci | (((bus->number - hose->first_busno) & 0xff) << 16) 1038c2ecf20Sopenharmony_ci | (hose->global_number << 24); 1048c2ecf20Sopenharmony_ci int ret = -1; 1058c2ecf20Sopenharmony_ci int rval; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len); 1088c2ecf20Sopenharmony_ci *val = ret; 1098c2ecf20Sopenharmony_ci return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset, 1138c2ecf20Sopenharmony_ci int len, u32 val) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci struct pci_controller *hose = pci_bus_to_host(bus); 1168c2ecf20Sopenharmony_ci unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8) 1178c2ecf20Sopenharmony_ci | (((bus->number - hose->first_busno) & 0xff) << 16) 1188c2ecf20Sopenharmony_ci | (hose->global_number << 24); 1198c2ecf20Sopenharmony_ci int rval; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL, 1228c2ecf20Sopenharmony_ci addr, len, val); 1238c2ecf20Sopenharmony_ci return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL; 1248c2ecf20Sopenharmony_ci} 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic struct pci_ops rtas_pci_ops = 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci .read = rtas_read_config, 1298c2ecf20Sopenharmony_ci .write = rtas_write_config, 1308c2ecf20Sopenharmony_ci}; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_civolatile struct Hydra __iomem *Hydra = NULL; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciint __init 1358c2ecf20Sopenharmony_cihydra_init(void) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci struct device_node *np; 1388c2ecf20Sopenharmony_ci struct resource r; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci np = of_find_node_by_name(NULL, "mac-io"); 1418c2ecf20Sopenharmony_ci if (np == NULL || of_address_to_resource(np, 0, &r)) { 1428c2ecf20Sopenharmony_ci of_node_put(np); 1438c2ecf20Sopenharmony_ci return 0; 1448c2ecf20Sopenharmony_ci } 1458c2ecf20Sopenharmony_ci of_node_put(np); 1468c2ecf20Sopenharmony_ci Hydra = ioremap(r.start, resource_size(&r)); 1478c2ecf20Sopenharmony_ci printk("Hydra Mac I/O at %llx\n", (unsigned long long)r.start); 1488c2ecf20Sopenharmony_ci printk("Hydra Feature_Control was %x", 1498c2ecf20Sopenharmony_ci in_le32(&Hydra->Feature_Control)); 1508c2ecf20Sopenharmony_ci out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN | 1518c2ecf20Sopenharmony_ci HYDRA_FC_SCSI_CELL_EN | 1528c2ecf20Sopenharmony_ci HYDRA_FC_SCCA_ENABLE | 1538c2ecf20Sopenharmony_ci HYDRA_FC_SCCB_ENABLE | 1548c2ecf20Sopenharmony_ci HYDRA_FC_ARB_BYPASS | 1558c2ecf20Sopenharmony_ci HYDRA_FC_MPIC_ENABLE | 1568c2ecf20Sopenharmony_ci HYDRA_FC_SLOW_SCC_PCLK | 1578c2ecf20Sopenharmony_ci HYDRA_FC_MPIC_IS_MASTER)); 1588c2ecf20Sopenharmony_ci printk(", now %x\n", in_le32(&Hydra->Feature_Control)); 1598c2ecf20Sopenharmony_ci return 1; 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define PRG_CL_RESET_VALID 0x00010000 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic void __init 1658c2ecf20Sopenharmony_cisetup_python(struct pci_controller *hose, struct device_node *dev) 1668c2ecf20Sopenharmony_ci{ 1678c2ecf20Sopenharmony_ci u32 __iomem *reg; 1688c2ecf20Sopenharmony_ci u32 val; 1698c2ecf20Sopenharmony_ci struct resource r; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci if (of_address_to_resource(dev, 0, &r)) { 1728c2ecf20Sopenharmony_ci printk(KERN_ERR "No address for Python PCI controller\n"); 1738c2ecf20Sopenharmony_ci return; 1748c2ecf20Sopenharmony_ci } 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci /* Clear the magic go-slow bit */ 1778c2ecf20Sopenharmony_ci reg = ioremap(r.start + 0xf6000, 0x40); 1788c2ecf20Sopenharmony_ci BUG_ON(!reg); 1798c2ecf20Sopenharmony_ci val = in_be32(®[12]); 1808c2ecf20Sopenharmony_ci if (val & PRG_CL_RESET_VALID) { 1818c2ecf20Sopenharmony_ci out_be32(®[12], val & ~PRG_CL_RESET_VALID); 1828c2ecf20Sopenharmony_ci in_be32(®[12]); 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci iounmap(reg); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010, 0); 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* Marvell Discovery II based Pegasos 2 */ 1908c2ecf20Sopenharmony_cistatic void __init setup_peg2(struct pci_controller *hose, struct device_node *dev) 1918c2ecf20Sopenharmony_ci{ 1928c2ecf20Sopenharmony_ci struct device_node *root = of_find_node_by_path("/"); 1938c2ecf20Sopenharmony_ci struct device_node *rtas; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci rtas = of_find_node_by_name (root, "rtas"); 1968c2ecf20Sopenharmony_ci if (rtas) { 1978c2ecf20Sopenharmony_ci hose->ops = &rtas_pci_ops; 1988c2ecf20Sopenharmony_ci of_node_put(rtas); 1998c2ecf20Sopenharmony_ci } else { 2008c2ecf20Sopenharmony_ci printk ("RTAS supporting Pegasos OF not found, please upgrade" 2018c2ecf20Sopenharmony_ci " your firmware\n"); 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci pci_add_flags(PCI_REASSIGN_ALL_BUS); 2048c2ecf20Sopenharmony_ci /* keep the reference to the root node */ 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_civoid __init 2088c2ecf20Sopenharmony_cichrp_find_bridges(void) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci struct device_node *dev; 2118c2ecf20Sopenharmony_ci const int *bus_range; 2128c2ecf20Sopenharmony_ci int len, index = -1; 2138c2ecf20Sopenharmony_ci struct pci_controller *hose; 2148c2ecf20Sopenharmony_ci const unsigned int *dma; 2158c2ecf20Sopenharmony_ci const char *model, *machine; 2168c2ecf20Sopenharmony_ci int is_longtrail = 0, is_mot = 0, is_pegasos = 0; 2178c2ecf20Sopenharmony_ci struct device_node *root = of_find_node_by_path("/"); 2188c2ecf20Sopenharmony_ci struct resource r; 2198c2ecf20Sopenharmony_ci /* 2208c2ecf20Sopenharmony_ci * The PCI host bridge nodes on some machines don't have 2218c2ecf20Sopenharmony_ci * properties to adequately identify them, so we have to 2228c2ecf20Sopenharmony_ci * look at what sort of machine this is as well. 2238c2ecf20Sopenharmony_ci */ 2248c2ecf20Sopenharmony_ci machine = of_get_property(root, "model", NULL); 2258c2ecf20Sopenharmony_ci if (machine != NULL) { 2268c2ecf20Sopenharmony_ci is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0; 2278c2ecf20Sopenharmony_ci is_mot = strncmp(machine, "MOT", 3) == 0; 2288c2ecf20Sopenharmony_ci if (strncmp(machine, "Pegasos2", 8) == 0) 2298c2ecf20Sopenharmony_ci is_pegasos = 2; 2308c2ecf20Sopenharmony_ci else if (strncmp(machine, "Pegasos", 7) == 0) 2318c2ecf20Sopenharmony_ci is_pegasos = 1; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci for_each_child_of_node(root, dev) { 2348c2ecf20Sopenharmony_ci if (!of_node_is_type(dev, "pci")) 2358c2ecf20Sopenharmony_ci continue; 2368c2ecf20Sopenharmony_ci ++index; 2378c2ecf20Sopenharmony_ci /* The GG2 bridge on the LongTrail doesn't have an address */ 2388c2ecf20Sopenharmony_ci if (of_address_to_resource(dev, 0, &r) && !is_longtrail) { 2398c2ecf20Sopenharmony_ci printk(KERN_WARNING "Can't use %pOF: no address\n", 2408c2ecf20Sopenharmony_ci dev); 2418c2ecf20Sopenharmony_ci continue; 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci bus_range = of_get_property(dev, "bus-range", &len); 2448c2ecf20Sopenharmony_ci if (bus_range == NULL || len < 2 * sizeof(int)) { 2458c2ecf20Sopenharmony_ci printk(KERN_WARNING "Can't get bus-range for %pOF\n", 2468c2ecf20Sopenharmony_ci dev); 2478c2ecf20Sopenharmony_ci continue; 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci if (bus_range[1] == bus_range[0]) 2508c2ecf20Sopenharmony_ci printk(KERN_INFO "PCI bus %d", bus_range[0]); 2518c2ecf20Sopenharmony_ci else 2528c2ecf20Sopenharmony_ci printk(KERN_INFO "PCI buses %d..%d", 2538c2ecf20Sopenharmony_ci bus_range[0], bus_range[1]); 2548c2ecf20Sopenharmony_ci printk(" controlled by %pOF", dev); 2558c2ecf20Sopenharmony_ci if (!is_longtrail) 2568c2ecf20Sopenharmony_ci printk(" at %llx", (unsigned long long)r.start); 2578c2ecf20Sopenharmony_ci printk("\n"); 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci hose = pcibios_alloc_controller(dev); 2608c2ecf20Sopenharmony_ci if (!hose) { 2618c2ecf20Sopenharmony_ci printk("Can't allocate PCI controller structure for %pOF\n", 2628c2ecf20Sopenharmony_ci dev); 2638c2ecf20Sopenharmony_ci continue; 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci hose->first_busno = hose->self_busno = bus_range[0]; 2668c2ecf20Sopenharmony_ci hose->last_busno = bus_range[1]; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci model = of_get_property(dev, "model", NULL); 2698c2ecf20Sopenharmony_ci if (model == NULL) 2708c2ecf20Sopenharmony_ci model = "<none>"; 2718c2ecf20Sopenharmony_ci if (strncmp(model, "IBM, Python", 11) == 0) { 2728c2ecf20Sopenharmony_ci setup_python(hose, dev); 2738c2ecf20Sopenharmony_ci } else if (is_mot 2748c2ecf20Sopenharmony_ci || strncmp(model, "Motorola, Grackle", 17) == 0) { 2758c2ecf20Sopenharmony_ci setup_grackle(hose); 2768c2ecf20Sopenharmony_ci } else if (is_longtrail) { 2778c2ecf20Sopenharmony_ci void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000); 2788c2ecf20Sopenharmony_ci hose->ops = &gg2_pci_ops; 2798c2ecf20Sopenharmony_ci hose->cfg_data = p; 2808c2ecf20Sopenharmony_ci gg2_pci_config_base = p; 2818c2ecf20Sopenharmony_ci } else if (is_pegasos == 1) { 2828c2ecf20Sopenharmony_ci setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc, 0); 2838c2ecf20Sopenharmony_ci } else if (is_pegasos == 2) { 2848c2ecf20Sopenharmony_ci setup_peg2(hose, dev); 2858c2ecf20Sopenharmony_ci } else if (!strncmp(model, "IBM,CPC710", 10)) { 2868c2ecf20Sopenharmony_ci setup_indirect_pci(hose, 2878c2ecf20Sopenharmony_ci r.start + 0x000f8000, 2888c2ecf20Sopenharmony_ci r.start + 0x000f8010, 2898c2ecf20Sopenharmony_ci 0); 2908c2ecf20Sopenharmony_ci if (index == 0) { 2918c2ecf20Sopenharmony_ci dma = of_get_property(dev, "system-dma-base", 2928c2ecf20Sopenharmony_ci &len); 2938c2ecf20Sopenharmony_ci if (dma && len >= sizeof(*dma)) { 2948c2ecf20Sopenharmony_ci dma = (unsigned int *) 2958c2ecf20Sopenharmony_ci (((unsigned long)dma) + 2968c2ecf20Sopenharmony_ci len - sizeof(*dma)); 2978c2ecf20Sopenharmony_ci pci_dram_offset = *dma; 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci } 3008c2ecf20Sopenharmony_ci } else { 3018c2ecf20Sopenharmony_ci printk("No methods for %pOF (model %s), using RTAS\n", 3028c2ecf20Sopenharmony_ci dev, model); 3038c2ecf20Sopenharmony_ci hose->ops = &rtas_pci_ops; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci pci_process_bridge_OF_ranges(hose, dev, index == 0); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci /* check the first bridge for a property that we can 3098c2ecf20Sopenharmony_ci use to set pci_dram_offset */ 3108c2ecf20Sopenharmony_ci dma = of_get_property(dev, "ibm,dma-ranges", &len); 3118c2ecf20Sopenharmony_ci if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) { 3128c2ecf20Sopenharmony_ci pci_dram_offset = dma[2] - dma[3]; 3138c2ecf20Sopenharmony_ci printk("pci_dram_offset = %lx\n", pci_dram_offset); 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci of_node_put(root); 3178c2ecf20Sopenharmony_ci} 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci/* SL82C105 IDE Control/Status Register */ 3208c2ecf20Sopenharmony_ci#define SL82C105_IDECSR 0x40 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci/* Fixup for Winbond ATA quirk, required for briq mostly because the 3238c2ecf20Sopenharmony_ci * 8259 is configured for level sensitive IRQ 14 and so wants the 3248c2ecf20Sopenharmony_ci * ATA controller to be set to fully native mode or bad things 3258c2ecf20Sopenharmony_ci * will happen. 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_cistatic void chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105) 3288c2ecf20Sopenharmony_ci{ 3298c2ecf20Sopenharmony_ci u8 progif; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci /* If non-briq machines need that fixup too, please speak up */ 3328c2ecf20Sopenharmony_ci if (!machine_is(chrp) || _chrp_type != _CHRP_briq) 3338c2ecf20Sopenharmony_ci return; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if ((sl82c105->class & 5) != 5) { 3368c2ecf20Sopenharmony_ci printk("W83C553: Switching SL82C105 IDE to PCI native mode\n"); 3378c2ecf20Sopenharmony_ci /* Enable SL82C105 PCI native IDE mode */ 3388c2ecf20Sopenharmony_ci pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif); 3398c2ecf20Sopenharmony_ci pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05); 3408c2ecf20Sopenharmony_ci sl82c105->class |= 0x05; 3418c2ecf20Sopenharmony_ci /* Disable SL82C105 second port */ 3428c2ecf20Sopenharmony_ci pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003); 3438c2ecf20Sopenharmony_ci /* Clear IO BARs, they will be reassigned */ 3448c2ecf20Sopenharmony_ci pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_0, 0); 3458c2ecf20Sopenharmony_ci pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_1, 0); 3468c2ecf20Sopenharmony_ci pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_2, 0); 3478c2ecf20Sopenharmony_ci pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_3, 0); 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105, 3518c2ecf20Sopenharmony_ci chrp_pci_fixup_winbond_ata); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/* Pegasos2 firmware version 20040810 configures the built-in IDE controller 3548c2ecf20Sopenharmony_ci * in legacy mode, but sets the PCI registers to PCI native mode. 3558c2ecf20Sopenharmony_ci * The chip can only operate in legacy mode, so force the PCI class into legacy 3568c2ecf20Sopenharmony_ci * mode as well. The same fixup must be done to the class-code property in 3578c2ecf20Sopenharmony_ci * the IDE node /pci@80000000/ide@C,1 3588c2ecf20Sopenharmony_ci */ 3598c2ecf20Sopenharmony_cistatic void chrp_pci_fixup_vt8231_ata(struct pci_dev *viaide) 3608c2ecf20Sopenharmony_ci{ 3618c2ecf20Sopenharmony_ci u8 progif; 3628c2ecf20Sopenharmony_ci struct pci_dev *viaisa; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci if (!machine_is(chrp) || _chrp_type != _CHRP_Pegasos) 3658c2ecf20Sopenharmony_ci return; 3668c2ecf20Sopenharmony_ci if (viaide->irq != 14) 3678c2ecf20Sopenharmony_ci return; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL); 3708c2ecf20Sopenharmony_ci if (!viaisa) 3718c2ecf20Sopenharmony_ci return; 3728c2ecf20Sopenharmony_ci dev_info(&viaide->dev, "Fixing VIA IDE, force legacy mode on\n"); 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif); 3758c2ecf20Sopenharmony_ci pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5); 3768c2ecf20Sopenharmony_ci viaide->class &= ~0x5; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci pci_dev_put(viaisa); 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, chrp_pci_fixup_vt8231_ata); 381