18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Functions for setting up and using a MPC106 northbridge
48c2ecf20Sopenharmony_ci * Extracted from arch/powerpc/platforms/powermac/pci.c.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2003 Benjamin Herrenschmuidt (benh@kernel.crashing.org)
78c2ecf20Sopenharmony_ci * Copyright (C) 1997 Paul Mackerras (paulus@samba.org)
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/pci.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <asm/io.h>
148c2ecf20Sopenharmony_ci#include <asm/prom.h>
158c2ecf20Sopenharmony_ci#include <asm/pci-bridge.h>
168c2ecf20Sopenharmony_ci#include <asm/grackle.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define GRACKLE_CFA(b, d, o)	(0x80 | ((b) << 8) | ((d) << 16) \
198c2ecf20Sopenharmony_ci				 | (((o) & ~3) << 24))
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define GRACKLE_PICR1_STG		0x00000040
228c2ecf20Sopenharmony_ci#define GRACKLE_PICR1_LOOPSNOOP		0x00000010
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* N.B. this is called before bridges is initialized, so we can't
258c2ecf20Sopenharmony_ci   use grackle_pcibios_{read,write}_config_dword. */
268c2ecf20Sopenharmony_cistatic inline void grackle_set_stg(struct pci_controller* bp, int enable)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	unsigned int val;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
318c2ecf20Sopenharmony_ci	val = in_le32(bp->cfg_data);
328c2ecf20Sopenharmony_ci	val = enable? (val | GRACKLE_PICR1_STG) :
338c2ecf20Sopenharmony_ci		(val & ~GRACKLE_PICR1_STG);
348c2ecf20Sopenharmony_ci	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
358c2ecf20Sopenharmony_ci	out_le32(bp->cfg_data, val);
368c2ecf20Sopenharmony_ci	(void)in_le32(bp->cfg_data);
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic inline void grackle_set_loop_snoop(struct pci_controller *bp, int enable)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	unsigned int val;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
448c2ecf20Sopenharmony_ci	val = in_le32(bp->cfg_data);
458c2ecf20Sopenharmony_ci	val = enable? (val | GRACKLE_PICR1_LOOPSNOOP) :
468c2ecf20Sopenharmony_ci		(val & ~GRACKLE_PICR1_LOOPSNOOP);
478c2ecf20Sopenharmony_ci	out_be32(bp->cfg_addr, GRACKLE_CFA(0, 0, 0xa8));
488c2ecf20Sopenharmony_ci	out_le32(bp->cfg_data, val);
498c2ecf20Sopenharmony_ci	(void)in_le32(bp->cfg_data);
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_civoid __init setup_grackle(struct pci_controller *hose)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	setup_indirect_pci(hose, 0xfec00000, 0xfee00000, 0);
558c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("PowerMac1,1"))
568c2ecf20Sopenharmony_ci		pci_add_flags(PCI_REASSIGN_ALL_BUS);
578c2ecf20Sopenharmony_ci	if (of_machine_is_compatible("AAPL,PowerBook1998"))
588c2ecf20Sopenharmony_ci		grackle_set_loop_snoop(hose, 1);
598c2ecf20Sopenharmony_ci#if 0	/* Disabled for now, HW problems ??? */
608c2ecf20Sopenharmony_ci	grackle_set_stg(hose, 1);
618c2ecf20Sopenharmony_ci#endif
628c2ecf20Sopenharmony_ci}
63