18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Linaro Ltd.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Author: Linus Walleij <linus.walleij@linaro.org>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
88c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2, as
98c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
158c2ecf20Sopenharmony_ci#include <linux/regmap.h>
168c2ecf20Sopenharmony_ci#include <linux/of.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define GLOBAL_WORD_ID				0x00
198c2ecf20Sopenharmony_ci#define GEMINI_GLOBAL_ARB1_CTRL			0x2c
208c2ecf20Sopenharmony_ci#define GEMINI_ARB1_BURST_MASK			GENMASK(21, 16)
218c2ecf20Sopenharmony_ci#define GEMINI_ARB1_BURST_SHIFT			16
228c2ecf20Sopenharmony_ci/* These all define the priority on the BUS2 backplane */
238c2ecf20Sopenharmony_ci#define GEMINI_ARB1_PRIO_MASK			GENMASK(9, 0)
248c2ecf20Sopenharmony_ci#define GEMINI_ARB1_DMAC_HIGH_PRIO		BIT(0)
258c2ecf20Sopenharmony_ci#define GEMINI_ARB1_IDE_HIGH_PRIO		BIT(1)
268c2ecf20Sopenharmony_ci#define GEMINI_ARB1_RAID_HIGH_PRIO		BIT(2)
278c2ecf20Sopenharmony_ci#define GEMINI_ARB1_SECURITY_HIGH_PRIO		BIT(3)
288c2ecf20Sopenharmony_ci#define GEMINI_ARB1_GMAC0_HIGH_PRIO		BIT(4)
298c2ecf20Sopenharmony_ci#define GEMINI_ARB1_GMAC1_HIGH_PRIO		BIT(5)
308c2ecf20Sopenharmony_ci#define GEMINI_ARB1_USB0_HIGH_PRIO		BIT(6)
318c2ecf20Sopenharmony_ci#define GEMINI_ARB1_USB1_HIGH_PRIO		BIT(7)
328c2ecf20Sopenharmony_ci#define GEMINI_ARB1_PCI_HIGH_PRIO		BIT(8)
338c2ecf20Sopenharmony_ci#define GEMINI_ARB1_TVE_HIGH_PRIO		BIT(9)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define GEMINI_DEFAULT_BURST_SIZE		0x20
368c2ecf20Sopenharmony_ci#define GEMINI_DEFAULT_PRIO			(GEMINI_ARB1_GMAC0_HIGH_PRIO | \
378c2ecf20Sopenharmony_ci						 GEMINI_ARB1_GMAC1_HIGH_PRIO)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic int __init gemini_soc_init(void)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	struct regmap *map;
428c2ecf20Sopenharmony_ci	u32 rev;
438c2ecf20Sopenharmony_ci	u32 val;
448c2ecf20Sopenharmony_ci	int ret;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	/* Multiplatform guard, only proceed on Gemini */
478c2ecf20Sopenharmony_ci	if (!of_machine_is_compatible("cortina,gemini"))
488c2ecf20Sopenharmony_ci		return 0;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	map = syscon_regmap_lookup_by_compatible("cortina,gemini-syscon");
518c2ecf20Sopenharmony_ci	if (IS_ERR(map))
528c2ecf20Sopenharmony_ci		return PTR_ERR(map);
538c2ecf20Sopenharmony_ci	ret = regmap_read(map, GLOBAL_WORD_ID, &rev);
548c2ecf20Sopenharmony_ci	if (ret)
558c2ecf20Sopenharmony_ci		return ret;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	val = (GEMINI_DEFAULT_BURST_SIZE << GEMINI_ARB1_BURST_SHIFT) |
588c2ecf20Sopenharmony_ci		GEMINI_DEFAULT_PRIO;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	/* Set up system arbitration */
618c2ecf20Sopenharmony_ci	regmap_update_bits(map,
628c2ecf20Sopenharmony_ci			   GEMINI_GLOBAL_ARB1_CTRL,
638c2ecf20Sopenharmony_ci			   GEMINI_ARB1_BURST_MASK | GEMINI_ARB1_PRIO_MASK,
648c2ecf20Sopenharmony_ci			   val);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	pr_info("Gemini SoC %04x revision %02x, set arbitration %08x\n",
678c2ecf20Sopenharmony_ci		rev >> 8, rev & 0xff, val);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	return 0;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_cisubsys_initcall(gemini_soc_init);
72