12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2830825d6SPaul Mackerras /* 3830825d6SPaul Mackerras * Functions for setting up and using a MPC106 northbridge 4830825d6SPaul Mackerras * Extracted from arch/powerpc/platforms/powermac/pci.c. 5830825d6SPaul Mackerras * 6830825d6SPaul Mackerras * Copyright (C) 2003 Benjamin Herrenschmuidt (benh@kernel.crashing.org) 7830825d6SPaul Mackerras * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) 8830825d6SPaul Mackerras */ 9830825d6SPaul Mackerras #include <linux/kernel.h> 10830825d6SPaul Mackerras #include <linux/pci.h> 11830825d6SPaul Mackerras #include <linux/init.h> 12*e6f6390aSChristophe Leroy #include <linux/of.h> 13830825d6SPaul Mackerras 14830825d6SPaul Mackerras #include <asm/io.h> 15830825d6SPaul Mackerras #include <asm/pci-bridge.h> 16830825d6SPaul Mackerras #include <asm/grackle.h> 17830825d6SPaul Mackerras 18830825d6SPaul Mackerras #define GRACKLE_CFA(b, d, o) (0x80 | ((b) << 8) | ((d) << 16) \ 19830825d6SPaul Mackerras | (((o) & ~3) << 24)) 20830825d6SPaul Mackerras 21830825d6SPaul Mackerras #define GRACKLE_PICR1_STG 0x00000040 22830825d6SPaul Mackerras #define GRACKLE_PICR1_LOOPSNOOP 0x00000010 23830825d6SPaul Mackerras 24830825d6SPaul Mackerras /* N.B. this is called before bridges is initialized, so we can't 25830825d6SPaul Mackerras use grackle_pcibios_{read,write}_config_dword. */ 26830825d6SPaul Mackerras static inline void grackle_set_stg(struct pci_controller* bp, int enable) 27830825d6SPaul Mackerras { 28830825d6SPaul Mackerras unsigned int val; 29830825d6SPaul Mackerras 30830825d6SPaul Mackerras out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8)); 31830825d6SPaul Mackerras val = in_le32(bp->cfg_data); 32830825d6SPaul Mackerras val = enable? (val | GRACKLE_PICR1_STG) : 33830825d6SPaul Mackerras (val & ~GRACKLE_PICR1_STG); 34830825d6SPaul Mackerras out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8)); 35830825d6SPaul Mackerras out_le32(bp->cfg_data, val); 36830825d6SPaul Mackerras (void)in_le32(bp->cfg_data); 37830825d6SPaul Mackerras } 38830825d6SPaul Mackerras 39830825d6SPaul Mackerras static inline void grackle_set_loop_snoop(struct pci_controller *bp, int enable) 40830825d6SPaul Mackerras { 41830825d6SPaul Mackerras unsigned int val; 42830825d6SPaul Mackerras 43830825d6SPaul Mackerras out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8)); 44830825d6SPaul Mackerras val = in_le32(bp->cfg_data); 45830825d6SPaul Mackerras val = enable? (val | GRACKLE_PICR1_LOOPSNOOP) : 46830825d6SPaul Mackerras (val & ~GRACKLE_PICR1_LOOPSNOOP); 47830825d6SPaul Mackerras out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8)); 48830825d6SPaul Mackerras out_le32(bp->cfg_data, val); 49830825d6SPaul Mackerras (void)in_le32(bp->cfg_data); 50830825d6SPaul Mackerras } 51830825d6SPaul Mackerras 52830825d6SPaul Mackerras void __init setup_grackle(struct pci_controller *hose) 53830825d6SPaul Mackerras { 542e56ff20SKumar Gala setup_indirect_pci(hose, 0xfec00000, 0xfee00000, 0); 5571a157e8SGrant Likely if (of_machine_is_compatible("PowerMac1,1")) 560e47ff1cSRob Herring pci_add_flags(PCI_REASSIGN_ALL_BUS); 5771a157e8SGrant Likely if (of_machine_is_compatible("AAPL,PowerBook1998")) 58830825d6SPaul Mackerras grackle_set_loop_snoop(hose, 1); 59830825d6SPaul Mackerras #if 0 /* Disabled for now, HW problems ??? */ 60830825d6SPaul Mackerras grackle_set_stg(hose, 1); 61830825d6SPaul Mackerras #endif 62830825d6SPaul Mackerras } 63