18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2013, Steffen Trumtrar <s.trumtrar@pengutronix.de>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * based on drivers/clk/tegra/clk.h
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __SOCFPGA_CLK_H
98c2ecf20Sopenharmony_ci#define __SOCFPGA_CLK_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Clock Manager offsets */
148c2ecf20Sopenharmony_ci#define CLKMGR_CTRL		0x0
158c2ecf20Sopenharmony_ci#define CLKMGR_BYPASS		0x4
168c2ecf20Sopenharmony_ci#define CLKMGR_DBCTRL		0x10
178c2ecf20Sopenharmony_ci#define CLKMGR_L4SRC		0x70
188c2ecf20Sopenharmony_ci#define CLKMGR_PERPLL_SRC	0xAC
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define SOCFPGA_MAX_PARENTS		5
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define streq(a, b) (strcmp((a), (b)) == 0)
238c2ecf20Sopenharmony_ci#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
248c2ecf20Sopenharmony_ci	((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define SYSMGR_SDMMC_CTRL_SET_AS10(smplsel, drvsel) \
278c2ecf20Sopenharmony_ci	((((smplsel) & 0x7) << 4) | (((drvsel) & 0x7) << 0))
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciextern void __iomem *clk_mgr_base_addr;
308c2ecf20Sopenharmony_ciextern void __iomem *clk_mgr_a10_base_addr;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_civoid __init socfpga_pll_init(struct device_node *node);
338c2ecf20Sopenharmony_civoid __init socfpga_periph_init(struct device_node *node);
348c2ecf20Sopenharmony_civoid __init socfpga_gate_init(struct device_node *node);
358c2ecf20Sopenharmony_civoid socfpga_a10_pll_init(struct device_node *node);
368c2ecf20Sopenharmony_civoid socfpga_a10_periph_init(struct device_node *node);
378c2ecf20Sopenharmony_civoid socfpga_a10_gate_init(struct device_node *node);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistruct socfpga_pll {
408c2ecf20Sopenharmony_ci	struct clk_gate	hw;
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct socfpga_gate_clk {
448c2ecf20Sopenharmony_ci	struct clk_gate hw;
458c2ecf20Sopenharmony_ci	char *parent_name;
468c2ecf20Sopenharmony_ci	u32 fixed_div;
478c2ecf20Sopenharmony_ci	void __iomem *div_reg;
488c2ecf20Sopenharmony_ci	void __iomem *bypass_reg;
498c2ecf20Sopenharmony_ci	struct regmap *sys_mgr_base_addr;
508c2ecf20Sopenharmony_ci	u32 width;	/* only valid if div_reg != 0 */
518c2ecf20Sopenharmony_ci	u32 shift;	/* only valid if div_reg != 0 */
528c2ecf20Sopenharmony_ci	u32 bypass_shift;      /* only valid if bypass_reg != 0 */
538c2ecf20Sopenharmony_ci	u32 clk_phase[2];
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct socfpga_periph_clk {
578c2ecf20Sopenharmony_ci	struct clk_gate hw;
588c2ecf20Sopenharmony_ci	char *parent_name;
598c2ecf20Sopenharmony_ci	u32 fixed_div;
608c2ecf20Sopenharmony_ci	void __iomem *div_reg;
618c2ecf20Sopenharmony_ci	void __iomem *bypass_reg;
628c2ecf20Sopenharmony_ci	u32 width;      /* only valid if div_reg != 0 */
638c2ecf20Sopenharmony_ci	u32 shift;      /* only valid if div_reg != 0 */
648c2ecf20Sopenharmony_ci	u32 bypass_shift;      /* only valid if bypass_reg != 0 */
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#endif /* SOCFPGA_CLK_H */
68