18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * SAMA7G5 PMC code.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Claudiu Beznea <claudiu.beznea@microchip.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#include <linux/clk.h>
118c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
128c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
138c2ecf20Sopenharmony_ci#include <linux/slab.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <dt-bindings/clock/at91.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "pmc.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define SAMA7G5_INIT_TABLE(_table, _count)		\
208c2ecf20Sopenharmony_ci	do {						\
218c2ecf20Sopenharmony_ci		u8 _i;					\
228c2ecf20Sopenharmony_ci		for (_i = 0; _i < (_count); _i++)	\
238c2ecf20Sopenharmony_ci			(_table)[_i] = _i;		\
248c2ecf20Sopenharmony_ci	} while (0)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define SAMA7G5_FILL_TABLE(_to, _from, _count)		\
278c2ecf20Sopenharmony_ci	do {						\
288c2ecf20Sopenharmony_ci		u8 _i;					\
298c2ecf20Sopenharmony_ci		for (_i = 0; _i < (_count); _i++) {	\
308c2ecf20Sopenharmony_ci			(_to)[_i] = (_from)[_i];	\
318c2ecf20Sopenharmony_ci		}					\
328c2ecf20Sopenharmony_ci	} while (0)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(pmc_pll_lock);
358c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(pmc_mckX_lock);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/**
388c2ecf20Sopenharmony_ci * PLL clocks identifiers
398c2ecf20Sopenharmony_ci * @PLL_ID_CPU:		CPU PLL identifier
408c2ecf20Sopenharmony_ci * @PLL_ID_SYS:		System PLL identifier
418c2ecf20Sopenharmony_ci * @PLL_ID_DDR:		DDR PLL identifier
428c2ecf20Sopenharmony_ci * @PLL_ID_IMG:		Image subsystem PLL identifier
438c2ecf20Sopenharmony_ci * @PLL_ID_BAUD:	Baud PLL identifier
448c2ecf20Sopenharmony_ci * @PLL_ID_AUDIO:	Audio PLL identifier
458c2ecf20Sopenharmony_ci * @PLL_ID_ETH:		Ethernet PLL identifier
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_cienum pll_ids {
488c2ecf20Sopenharmony_ci	PLL_ID_CPU,
498c2ecf20Sopenharmony_ci	PLL_ID_SYS,
508c2ecf20Sopenharmony_ci	PLL_ID_DDR,
518c2ecf20Sopenharmony_ci	PLL_ID_IMG,
528c2ecf20Sopenharmony_ci	PLL_ID_BAUD,
538c2ecf20Sopenharmony_ci	PLL_ID_AUDIO,
548c2ecf20Sopenharmony_ci	PLL_ID_ETH,
558c2ecf20Sopenharmony_ci	PLL_ID_MAX,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/**
598c2ecf20Sopenharmony_ci * PLL type identifiers
608c2ecf20Sopenharmony_ci * @PLL_TYPE_FRAC:	fractional PLL identifier
618c2ecf20Sopenharmony_ci * @PLL_TYPE_DIV:	divider PLL identifier
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_cienum pll_type {
648c2ecf20Sopenharmony_ci	PLL_TYPE_FRAC,
658c2ecf20Sopenharmony_ci	PLL_TYPE_DIV,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Layout for fractional PLLs. */
698c2ecf20Sopenharmony_cistatic const struct clk_pll_layout pll_layout_frac = {
708c2ecf20Sopenharmony_ci	.mul_mask	= GENMASK(31, 24),
718c2ecf20Sopenharmony_ci	.frac_mask	= GENMASK(21, 0),
728c2ecf20Sopenharmony_ci	.mul_shift	= 24,
738c2ecf20Sopenharmony_ci	.frac_shift	= 0,
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* Layout for DIVPMC dividers. */
778c2ecf20Sopenharmony_cistatic const struct clk_pll_layout pll_layout_divpmc = {
788c2ecf20Sopenharmony_ci	.div_mask	= GENMASK(7, 0),
798c2ecf20Sopenharmony_ci	.endiv_mask	= BIT(29),
808c2ecf20Sopenharmony_ci	.div_shift	= 0,
818c2ecf20Sopenharmony_ci	.endiv_shift	= 29,
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* Layout for DIVIO dividers. */
858c2ecf20Sopenharmony_cistatic const struct clk_pll_layout pll_layout_divio = {
868c2ecf20Sopenharmony_ci	.div_mask	= GENMASK(19, 12),
878c2ecf20Sopenharmony_ci	.endiv_mask	= BIT(30),
888c2ecf20Sopenharmony_ci	.div_shift	= 12,
898c2ecf20Sopenharmony_ci	.endiv_shift	= 30,
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/**
938c2ecf20Sopenharmony_ci * PLL clocks description
948c2ecf20Sopenharmony_ci * @n:		clock name
958c2ecf20Sopenharmony_ci * @p:		clock parent
968c2ecf20Sopenharmony_ci * @l:		clock layout
978c2ecf20Sopenharmony_ci * @t:		clock type
988c2ecf20Sopenharmony_ci * @f:		true if clock is critical and cannot be disabled
998c2ecf20Sopenharmony_ci * @eid:	export index in sama7g5->chws[] array
1008c2ecf20Sopenharmony_ci */
1018c2ecf20Sopenharmony_cistatic const struct {
1028c2ecf20Sopenharmony_ci	const char *n;
1038c2ecf20Sopenharmony_ci	const char *p;
1048c2ecf20Sopenharmony_ci	const struct clk_pll_layout *l;
1058c2ecf20Sopenharmony_ci	u8 t;
1068c2ecf20Sopenharmony_ci	u8 c;
1078c2ecf20Sopenharmony_ci	u8 eid;
1088c2ecf20Sopenharmony_ci} sama7g5_plls[][PLL_ID_MAX] = {
1098c2ecf20Sopenharmony_ci	[PLL_ID_CPU] = {
1108c2ecf20Sopenharmony_ci		{ .n = "cpupll_fracck",
1118c2ecf20Sopenharmony_ci		  .p = "mainck",
1128c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1138c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC,
1148c2ecf20Sopenharmony_ci		  .c = 1, },
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci		{ .n = "cpupll_divpmcck",
1178c2ecf20Sopenharmony_ci		  .p = "cpupll_fracck",
1188c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1198c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV,
1208c2ecf20Sopenharmony_ci		  .c = 1, },
1218c2ecf20Sopenharmony_ci	},
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	[PLL_ID_SYS] = {
1248c2ecf20Sopenharmony_ci		{ .n = "syspll_fracck",
1258c2ecf20Sopenharmony_ci		  .p = "mainck",
1268c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1278c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC,
1288c2ecf20Sopenharmony_ci		  .c = 1, },
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci		{ .n = "syspll_divpmcck",
1318c2ecf20Sopenharmony_ci		  .p = "syspll_fracck",
1328c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1338c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV,
1348c2ecf20Sopenharmony_ci		  .c = 1, },
1358c2ecf20Sopenharmony_ci	},
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	[PLL_ID_DDR] = {
1388c2ecf20Sopenharmony_ci		{ .n = "ddrpll_fracck",
1398c2ecf20Sopenharmony_ci		  .p = "mainck",
1408c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1418c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC,
1428c2ecf20Sopenharmony_ci		  .c = 1, },
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci		{ .n = "ddrpll_divpmcck",
1458c2ecf20Sopenharmony_ci		  .p = "ddrpll_fracck",
1468c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1478c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV,
1488c2ecf20Sopenharmony_ci		  .c = 1, },
1498c2ecf20Sopenharmony_ci	},
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	[PLL_ID_IMG] = {
1528c2ecf20Sopenharmony_ci		{ .n = "imgpll_fracck",
1538c2ecf20Sopenharmony_ci		  .p = "mainck",
1548c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1558c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC, },
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci		{ .n = "imgpll_divpmcck",
1588c2ecf20Sopenharmony_ci		  .p = "imgpll_fracck",
1598c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1608c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV, },
1618c2ecf20Sopenharmony_ci	},
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	[PLL_ID_BAUD] = {
1648c2ecf20Sopenharmony_ci		{ .n = "baudpll_fracck",
1658c2ecf20Sopenharmony_ci		  .p = "mainck",
1668c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1678c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC, },
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci		{ .n = "baudpll_divpmcck",
1708c2ecf20Sopenharmony_ci		  .p = "baudpll_fracck",
1718c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1728c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV, },
1738c2ecf20Sopenharmony_ci	},
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	[PLL_ID_AUDIO] = {
1768c2ecf20Sopenharmony_ci		{ .n = "audiopll_fracck",
1778c2ecf20Sopenharmony_ci		  .p = "main_xtal",
1788c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1798c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC, },
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci		{ .n = "audiopll_divpmcck",
1828c2ecf20Sopenharmony_ci		  .p = "audiopll_fracck",
1838c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
1848c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV,
1858c2ecf20Sopenharmony_ci		  .eid = PMC_I2S0_MUX, },
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci		{ .n = "audiopll_diviock",
1888c2ecf20Sopenharmony_ci		  .p = "audiopll_fracck",
1898c2ecf20Sopenharmony_ci		  .l = &pll_layout_divio,
1908c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV,
1918c2ecf20Sopenharmony_ci		  .eid = PMC_I2S1_MUX, },
1928c2ecf20Sopenharmony_ci	},
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	[PLL_ID_ETH] = {
1958c2ecf20Sopenharmony_ci		{ .n = "ethpll_fracck",
1968c2ecf20Sopenharmony_ci		  .p = "main_xtal",
1978c2ecf20Sopenharmony_ci		  .l = &pll_layout_frac,
1988c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_FRAC, },
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci		{ .n = "ethpll_divpmcck",
2018c2ecf20Sopenharmony_ci		  .p = "ethpll_fracck",
2028c2ecf20Sopenharmony_ci		  .l = &pll_layout_divpmc,
2038c2ecf20Sopenharmony_ci		  .t = PLL_TYPE_DIV, },
2048c2ecf20Sopenharmony_ci	},
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/**
2088c2ecf20Sopenharmony_ci * Master clock (MCK[1..4]) description
2098c2ecf20Sopenharmony_ci * @n:			clock name
2108c2ecf20Sopenharmony_ci * @ep:			extra parents names array
2118c2ecf20Sopenharmony_ci * @ep_chg_chg_id:	index in parents array that specifies the changeable
2128c2ecf20Sopenharmony_ci *			parent
2138c2ecf20Sopenharmony_ci * @ep_count:		extra parents count
2148c2ecf20Sopenharmony_ci * @ep_mux_table:	mux table for extra parents
2158c2ecf20Sopenharmony_ci * @id:			clock id
2168c2ecf20Sopenharmony_ci * @c:			true if clock is critical and cannot be disabled
2178c2ecf20Sopenharmony_ci */
2188c2ecf20Sopenharmony_cistatic const struct {
2198c2ecf20Sopenharmony_ci	const char *n;
2208c2ecf20Sopenharmony_ci	const char *ep[4];
2218c2ecf20Sopenharmony_ci	int ep_chg_id;
2228c2ecf20Sopenharmony_ci	u8 ep_count;
2238c2ecf20Sopenharmony_ci	u8 ep_mux_table[4];
2248c2ecf20Sopenharmony_ci	u8 id;
2258c2ecf20Sopenharmony_ci	u8 c;
2268c2ecf20Sopenharmony_ci} sama7g5_mckx[] = {
2278c2ecf20Sopenharmony_ci	{ .n = "mck1",
2288c2ecf20Sopenharmony_ci	  .id = 1,
2298c2ecf20Sopenharmony_ci	  .ep = { "syspll_divpmcck", },
2308c2ecf20Sopenharmony_ci	  .ep_mux_table = { 5, },
2318c2ecf20Sopenharmony_ci	  .ep_count = 1,
2328c2ecf20Sopenharmony_ci	  .ep_chg_id = INT_MIN,
2338c2ecf20Sopenharmony_ci	  .c = 1, },
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	{ .n = "mck2",
2368c2ecf20Sopenharmony_ci	  .id = 2,
2378c2ecf20Sopenharmony_ci	  .ep = { "ddrpll_divpmcck", },
2388c2ecf20Sopenharmony_ci	  .ep_mux_table = { 6, },
2398c2ecf20Sopenharmony_ci	  .ep_count = 1,
2408c2ecf20Sopenharmony_ci	  .ep_chg_id = INT_MIN,
2418c2ecf20Sopenharmony_ci	  .c = 1, },
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	{ .n = "mck3",
2448c2ecf20Sopenharmony_ci	  .id = 3,
2458c2ecf20Sopenharmony_ci	  .ep = { "syspll_divpmcck", "ddrpll_divpmcck", "imgpll_divpmcck", },
2468c2ecf20Sopenharmony_ci	  .ep_mux_table = { 5, 6, 7, },
2478c2ecf20Sopenharmony_ci	  .ep_count = 3,
2488c2ecf20Sopenharmony_ci	  .ep_chg_id = 6, },
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	{ .n = "mck4",
2518c2ecf20Sopenharmony_ci	  .id = 4,
2528c2ecf20Sopenharmony_ci	  .ep = { "syspll_divpmcck", },
2538c2ecf20Sopenharmony_ci	  .ep_mux_table = { 5, },
2548c2ecf20Sopenharmony_ci	  .ep_count = 1,
2558c2ecf20Sopenharmony_ci	  .ep_chg_id = INT_MIN,
2568c2ecf20Sopenharmony_ci	  .c = 1, },
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/**
2608c2ecf20Sopenharmony_ci * System clock description
2618c2ecf20Sopenharmony_ci * @n:	clock name
2628c2ecf20Sopenharmony_ci * @p:	clock parent name
2638c2ecf20Sopenharmony_ci * @id: clock id
2648c2ecf20Sopenharmony_ci */
2658c2ecf20Sopenharmony_cistatic const struct {
2668c2ecf20Sopenharmony_ci	const char *n;
2678c2ecf20Sopenharmony_ci	const char *p;
2688c2ecf20Sopenharmony_ci	u8 id;
2698c2ecf20Sopenharmony_ci} sama7g5_systemck[] = {
2708c2ecf20Sopenharmony_ci	{ .n = "pck0",		.p = "prog0", .id = 8, },
2718c2ecf20Sopenharmony_ci	{ .n = "pck1",		.p = "prog1", .id = 9, },
2728c2ecf20Sopenharmony_ci	{ .n = "pck2",		.p = "prog2", .id = 10, },
2738c2ecf20Sopenharmony_ci	{ .n = "pck3",		.p = "prog3", .id = 11, },
2748c2ecf20Sopenharmony_ci	{ .n = "pck4",		.p = "prog4", .id = 12, },
2758c2ecf20Sopenharmony_ci	{ .n = "pck5",		.p = "prog5", .id = 13, },
2768c2ecf20Sopenharmony_ci	{ .n = "pck6",		.p = "prog6", .id = 14, },
2778c2ecf20Sopenharmony_ci	{ .n = "pck7",		.p = "prog7", .id = 15, },
2788c2ecf20Sopenharmony_ci};
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci/* Mux table for programmable clocks. */
2818c2ecf20Sopenharmony_cistatic u32 sama7g5_prog_mux_table[] = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, };
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/**
2848c2ecf20Sopenharmony_ci * Peripheral clock description
2858c2ecf20Sopenharmony_ci * @n:		clock name
2868c2ecf20Sopenharmony_ci * @p:		clock parent name
2878c2ecf20Sopenharmony_ci * @r:		clock range values
2888c2ecf20Sopenharmony_ci * @id:		clock id
2898c2ecf20Sopenharmony_ci * @chgp:	index in parent array of the changeable parent
2908c2ecf20Sopenharmony_ci */
2918c2ecf20Sopenharmony_cistatic const struct {
2928c2ecf20Sopenharmony_ci	const char *n;
2938c2ecf20Sopenharmony_ci	const char *p;
2948c2ecf20Sopenharmony_ci	struct clk_range r;
2958c2ecf20Sopenharmony_ci	u8 chgp;
2968c2ecf20Sopenharmony_ci	u8 id;
2978c2ecf20Sopenharmony_ci} sama7g5_periphck[] = {
2988c2ecf20Sopenharmony_ci	{ .n = "pioA_clk",	.p = "mck0", .id = 11, },
2998c2ecf20Sopenharmony_ci	{ .n = "sfr_clk",	.p = "mck1", .id = 19, },
3008c2ecf20Sopenharmony_ci	{ .n = "hsmc_clk",	.p = "mck1", .id = 21, },
3018c2ecf20Sopenharmony_ci	{ .n = "xdmac0_clk",	.p = "mck1", .id = 22, },
3028c2ecf20Sopenharmony_ci	{ .n = "xdmac1_clk",	.p = "mck1", .id = 23, },
3038c2ecf20Sopenharmony_ci	{ .n = "xdmac2_clk",	.p = "mck1", .id = 24, },
3048c2ecf20Sopenharmony_ci	{ .n = "acc_clk",	.p = "mck1", .id = 25, },
3058c2ecf20Sopenharmony_ci	{ .n = "aes_clk",	.p = "mck1", .id = 27, },
3068c2ecf20Sopenharmony_ci	{ .n = "tzaesbasc_clk",	.p = "mck1", .id = 28, },
3078c2ecf20Sopenharmony_ci	{ .n = "asrc_clk",	.p = "mck1", .id = 30, .r = { .max = 200000000, }, },
3088c2ecf20Sopenharmony_ci	{ .n = "cpkcc_clk",	.p = "mck0", .id = 32, },
3098c2ecf20Sopenharmony_ci	{ .n = "csi_clk",	.p = "mck3", .id = 33, .r = { .max = 266000000, }, .chgp = 1, },
3108c2ecf20Sopenharmony_ci	{ .n = "csi2dc_clk",	.p = "mck3", .id = 34, .r = { .max = 266000000, }, .chgp = 1, },
3118c2ecf20Sopenharmony_ci	{ .n = "eic_clk",	.p = "mck1", .id = 37, },
3128c2ecf20Sopenharmony_ci	{ .n = "flex0_clk",	.p = "mck1", .id = 38, },
3138c2ecf20Sopenharmony_ci	{ .n = "flex1_clk",	.p = "mck1", .id = 39, },
3148c2ecf20Sopenharmony_ci	{ .n = "flex2_clk",	.p = "mck1", .id = 40, },
3158c2ecf20Sopenharmony_ci	{ .n = "flex3_clk",	.p = "mck1", .id = 41, },
3168c2ecf20Sopenharmony_ci	{ .n = "flex4_clk",	.p = "mck1", .id = 42, },
3178c2ecf20Sopenharmony_ci	{ .n = "flex5_clk",	.p = "mck1", .id = 43, },
3188c2ecf20Sopenharmony_ci	{ .n = "flex6_clk",	.p = "mck1", .id = 44, },
3198c2ecf20Sopenharmony_ci	{ .n = "flex7_clk",	.p = "mck1", .id = 45, },
3208c2ecf20Sopenharmony_ci	{ .n = "flex8_clk",	.p = "mck1", .id = 46, },
3218c2ecf20Sopenharmony_ci	{ .n = "flex9_clk",	.p = "mck1", .id = 47, },
3228c2ecf20Sopenharmony_ci	{ .n = "flex10_clk",	.p = "mck1", .id = 48, },
3238c2ecf20Sopenharmony_ci	{ .n = "flex11_clk",	.p = "mck1", .id = 49, },
3248c2ecf20Sopenharmony_ci	{ .n = "gmac0_clk",	.p = "mck1", .id = 51, },
3258c2ecf20Sopenharmony_ci	{ .n = "gmac1_clk",	.p = "mck1", .id = 52, },
3268c2ecf20Sopenharmony_ci	{ .n = "icm_clk",	.p = "mck1", .id = 55, },
3278c2ecf20Sopenharmony_ci	{ .n = "isc_clk",	.p = "mck3", .id = 56, .r = { .max = 266000000, }, .chgp = 1, },
3288c2ecf20Sopenharmony_ci	{ .n = "i2smcc0_clk",	.p = "mck1", .id = 57, .r = { .max = 200000000, }, },
3298c2ecf20Sopenharmony_ci	{ .n = "i2smcc1_clk",	.p = "mck1", .id = 58, .r = { .max = 200000000, }, },
3308c2ecf20Sopenharmony_ci	{ .n = "matrix_clk",	.p = "mck1", .id = 60, },
3318c2ecf20Sopenharmony_ci	{ .n = "mcan0_clk",	.p = "mck1", .id = 61, .r = { .max = 200000000, }, },
3328c2ecf20Sopenharmony_ci	{ .n = "mcan1_clk",	.p = "mck1", .id = 62, .r = { .max = 200000000, }, },
3338c2ecf20Sopenharmony_ci	{ .n = "mcan2_clk",	.p = "mck1", .id = 63, .r = { .max = 200000000, }, },
3348c2ecf20Sopenharmony_ci	{ .n = "mcan3_clk",	.p = "mck1", .id = 64, .r = { .max = 200000000, }, },
3358c2ecf20Sopenharmony_ci	{ .n = "mcan4_clk",	.p = "mck1", .id = 65, .r = { .max = 200000000, }, },
3368c2ecf20Sopenharmony_ci	{ .n = "mcan5_clk",	.p = "mck1", .id = 66, .r = { .max = 200000000, }, },
3378c2ecf20Sopenharmony_ci	{ .n = "pdmc0_clk",	.p = "mck1", .id = 68, .r = { .max = 200000000, }, },
3388c2ecf20Sopenharmony_ci	{ .n = "pdmc1_clk",	.p = "mck1", .id = 69, .r = { .max = 200000000, }, },
3398c2ecf20Sopenharmony_ci	{ .n = "pit64b0_clk",	.p = "mck1", .id = 70, },
3408c2ecf20Sopenharmony_ci	{ .n = "pit64b1_clk",	.p = "mck1", .id = 71, },
3418c2ecf20Sopenharmony_ci	{ .n = "pit64b2_clk",	.p = "mck1", .id = 72, },
3428c2ecf20Sopenharmony_ci	{ .n = "pit64b3_clk",	.p = "mck1", .id = 73, },
3438c2ecf20Sopenharmony_ci	{ .n = "pit64b4_clk",	.p = "mck1", .id = 74, },
3448c2ecf20Sopenharmony_ci	{ .n = "pit64b5_clk",	.p = "mck1", .id = 75, },
3458c2ecf20Sopenharmony_ci	{ .n = "pwm_clk",	.p = "mck1", .id = 77, },
3468c2ecf20Sopenharmony_ci	{ .n = "qspi0_clk",	.p = "mck1", .id = 78, },
3478c2ecf20Sopenharmony_ci	{ .n = "qspi1_clk",	.p = "mck1", .id = 79, },
3488c2ecf20Sopenharmony_ci	{ .n = "sdmmc0_clk",	.p = "mck1", .id = 80, },
3498c2ecf20Sopenharmony_ci	{ .n = "sdmmc1_clk",	.p = "mck1", .id = 81, },
3508c2ecf20Sopenharmony_ci	{ .n = "sdmmc2_clk",	.p = "mck1", .id = 82, },
3518c2ecf20Sopenharmony_ci	{ .n = "sha_clk",	.p = "mck1", .id = 83, },
3528c2ecf20Sopenharmony_ci	{ .n = "spdifrx_clk",	.p = "mck1", .id = 84, .r = { .max = 200000000, }, },
3538c2ecf20Sopenharmony_ci	{ .n = "spdiftx_clk",	.p = "mck1", .id = 85, .r = { .max = 200000000, }, },
3548c2ecf20Sopenharmony_ci	{ .n = "ssc0_clk",	.p = "mck1", .id = 86, .r = { .max = 200000000, }, },
3558c2ecf20Sopenharmony_ci	{ .n = "ssc1_clk",	.p = "mck1", .id = 87, .r = { .max = 200000000, }, },
3568c2ecf20Sopenharmony_ci	{ .n = "tcb0_ch0_clk",	.p = "mck1", .id = 88, .r = { .max = 200000000, }, },
3578c2ecf20Sopenharmony_ci	{ .n = "tcb0_ch1_clk",	.p = "mck1", .id = 89, .r = { .max = 200000000, }, },
3588c2ecf20Sopenharmony_ci	{ .n = "tcb0_ch2_clk",	.p = "mck1", .id = 90, .r = { .max = 200000000, }, },
3598c2ecf20Sopenharmony_ci	{ .n = "tcb1_ch0_clk",	.p = "mck1", .id = 91, .r = { .max = 200000000, }, },
3608c2ecf20Sopenharmony_ci	{ .n = "tcb1_ch1_clk",	.p = "mck1", .id = 92, .r = { .max = 200000000, }, },
3618c2ecf20Sopenharmony_ci	{ .n = "tcb1_ch2_clk",	.p = "mck1", .id = 93, .r = { .max = 200000000, }, },
3628c2ecf20Sopenharmony_ci	{ .n = "tcpca_clk",	.p = "mck1", .id = 94, },
3638c2ecf20Sopenharmony_ci	{ .n = "tcpcb_clk",	.p = "mck1", .id = 95, },
3648c2ecf20Sopenharmony_ci	{ .n = "tdes_clk",	.p = "mck1", .id = 96, },
3658c2ecf20Sopenharmony_ci	{ .n = "trng_clk",	.p = "mck1", .id = 97, },
3668c2ecf20Sopenharmony_ci	{ .n = "udphsa_clk",	.p = "mck1", .id = 104, },
3678c2ecf20Sopenharmony_ci	{ .n = "udphsb_clk",	.p = "mck1", .id = 105, },
3688c2ecf20Sopenharmony_ci	{ .n = "uhphs_clk",	.p = "mck1", .id = 106, },
3698c2ecf20Sopenharmony_ci};
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/**
3728c2ecf20Sopenharmony_ci * Generic clock description
3738c2ecf20Sopenharmony_ci * @n:			clock name
3748c2ecf20Sopenharmony_ci * @pp:			PLL parents
3758c2ecf20Sopenharmony_ci * @pp_mux_table:	PLL parents mux table
3768c2ecf20Sopenharmony_ci * @r:			clock output range
3778c2ecf20Sopenharmony_ci * @pp_chg_id:		id in parrent array of changeable PLL parent
3788c2ecf20Sopenharmony_ci * @pp_count:		PLL parents count
3798c2ecf20Sopenharmony_ci * @id:			clock id
3808c2ecf20Sopenharmony_ci */
3818c2ecf20Sopenharmony_cistatic const struct {
3828c2ecf20Sopenharmony_ci	const char *n;
3838c2ecf20Sopenharmony_ci	const char *pp[8];
3848c2ecf20Sopenharmony_ci	const char pp_mux_table[8];
3858c2ecf20Sopenharmony_ci	struct clk_range r;
3868c2ecf20Sopenharmony_ci	int pp_chg_id;
3878c2ecf20Sopenharmony_ci	u8 pp_count;
3888c2ecf20Sopenharmony_ci	u8 id;
3898c2ecf20Sopenharmony_ci} sama7g5_gck[] = {
3908c2ecf20Sopenharmony_ci	{ .n  = "adc_gclk",
3918c2ecf20Sopenharmony_ci	  .id = 26,
3928c2ecf20Sopenharmony_ci	  .r = { .max = 100000000, },
3938c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "audiopll_divpmcck", },
3948c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 9, },
3958c2ecf20Sopenharmony_ci	  .pp_count = 3,
3968c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	{ .n  = "asrc_gclk",
3998c2ecf20Sopenharmony_ci	  .id = 30,
4008c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4018c2ecf20Sopenharmony_ci	  .pp = { "audiopll_divpmcck", },
4028c2ecf20Sopenharmony_ci	  .pp_mux_table = { 9, },
4038c2ecf20Sopenharmony_ci	  .pp_count = 1,
4048c2ecf20Sopenharmony_ci	  .pp_chg_id = 4, },
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	{ .n  = "csi_gclk",
4078c2ecf20Sopenharmony_ci	  .id = 33,
4088c2ecf20Sopenharmony_ci	  .r = { .max = 27000000  },
4098c2ecf20Sopenharmony_ci	  .pp = { "ddrpll_divpmcck", "imgpll_divpmcck", },
4108c2ecf20Sopenharmony_ci	  .pp_mux_table = { 6, 7, },
4118c2ecf20Sopenharmony_ci	  .pp_count = 2,
4128c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	{ .n  = "flex0_gclk",
4158c2ecf20Sopenharmony_ci	  .id = 38,
4168c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4178c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4188c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4198c2ecf20Sopenharmony_ci	  .pp_count = 2,
4208c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	{ .n  = "flex1_gclk",
4238c2ecf20Sopenharmony_ci	  .id = 39,
4248c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4258c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4268c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4278c2ecf20Sopenharmony_ci	  .pp_count = 2,
4288c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	{ .n  = "flex2_gclk",
4318c2ecf20Sopenharmony_ci	  .id = 40,
4328c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4338c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4348c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4358c2ecf20Sopenharmony_ci	  .pp_count = 2,
4368c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	{ .n  = "flex3_gclk",
4398c2ecf20Sopenharmony_ci	  .id = 41,
4408c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4418c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4428c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4438c2ecf20Sopenharmony_ci	  .pp_count = 2,
4448c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	{ .n  = "flex4_gclk",
4478c2ecf20Sopenharmony_ci	  .id = 42,
4488c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4498c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4508c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4518c2ecf20Sopenharmony_ci	  .pp_count = 2,
4528c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	{ .n  = "flex5_gclk",
4558c2ecf20Sopenharmony_ci	  .id = 43,
4568c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4578c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4588c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4598c2ecf20Sopenharmony_ci	  .pp_count = 2,
4608c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	{ .n  = "flex6_gclk",
4638c2ecf20Sopenharmony_ci	  .id = 44,
4648c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4658c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4668c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4678c2ecf20Sopenharmony_ci	  .pp_count = 2,
4688c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	{ .n  = "flex7_gclk",
4718c2ecf20Sopenharmony_ci	  .id = 45,
4728c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4738c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4748c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4758c2ecf20Sopenharmony_ci	  .pp_count = 2,
4768c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci	{ .n  = "flex8_gclk",
4798c2ecf20Sopenharmony_ci	  .id = 46,
4808c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4818c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4828c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4838c2ecf20Sopenharmony_ci	  .pp_count = 2,
4848c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci	{ .n  = "flex9_gclk",
4878c2ecf20Sopenharmony_ci	  .id = 47,
4888c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4898c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4908c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4918c2ecf20Sopenharmony_ci	  .pp_count = 2,
4928c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	{ .n  = "flex10_gclk",
4958c2ecf20Sopenharmony_ci	  .id = 48,
4968c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
4978c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
4988c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
4998c2ecf20Sopenharmony_ci	  .pp_count = 2,
5008c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	{ .n  = "flex11_gclk",
5038c2ecf20Sopenharmony_ci	  .id = 49,
5048c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5058c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5068c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5078c2ecf20Sopenharmony_ci	  .pp_count = 2,
5088c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	{ .n  = "gmac0_gclk",
5118c2ecf20Sopenharmony_ci	  .id = 51,
5128c2ecf20Sopenharmony_ci	  .r = { .max = 125000000 },
5138c2ecf20Sopenharmony_ci	  .pp = { "ethpll_divpmcck", },
5148c2ecf20Sopenharmony_ci	  .pp_mux_table = { 10, },
5158c2ecf20Sopenharmony_ci	  .pp_count = 1,
5168c2ecf20Sopenharmony_ci	  .pp_chg_id = 4, },
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	{ .n  = "gmac1_gclk",
5198c2ecf20Sopenharmony_ci	  .id = 52,
5208c2ecf20Sopenharmony_ci	  .r = { .max = 50000000  },
5218c2ecf20Sopenharmony_ci	  .pp = { "ethpll_divpmcck", },
5228c2ecf20Sopenharmony_ci	  .pp_mux_table = { 10, },
5238c2ecf20Sopenharmony_ci	  .pp_count = 1,
5248c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	{ .n  = "gmac0_tsu_gclk",
5278c2ecf20Sopenharmony_ci	  .id = 53,
5288c2ecf20Sopenharmony_ci	  .r = { .max = 300000000 },
5298c2ecf20Sopenharmony_ci	  .pp = { "audiopll_divpmcck", "ethpll_divpmcck", },
5308c2ecf20Sopenharmony_ci	  .pp_mux_table = { 9, 10, },
5318c2ecf20Sopenharmony_ci	  .pp_count = 2,
5328c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci	{ .n  = "gmac1_tsu_gclk",
5358c2ecf20Sopenharmony_ci	  .id = 54,
5368c2ecf20Sopenharmony_ci	  .r = { .max = 300000000 },
5378c2ecf20Sopenharmony_ci	  .pp = { "audiopll_divpmcck", "ethpll_divpmcck", },
5388c2ecf20Sopenharmony_ci	  .pp_mux_table = { 9, 10, },
5398c2ecf20Sopenharmony_ci	  .pp_count = 2,
5408c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	{ .n  = "i2smcc0_gclk",
5438c2ecf20Sopenharmony_ci	  .id = 57,
5448c2ecf20Sopenharmony_ci	  .r = { .max = 100000000 },
5458c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
5468c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
5478c2ecf20Sopenharmony_ci	  .pp_count = 2,
5488c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	{ .n  = "i2smcc1_gclk",
5518c2ecf20Sopenharmony_ci	  .id = 58,
5528c2ecf20Sopenharmony_ci	  .r = { .max = 100000000 },
5538c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
5548c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
5558c2ecf20Sopenharmony_ci	  .pp_count = 2,
5568c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	{ .n  = "mcan0_gclk",
5598c2ecf20Sopenharmony_ci	  .id = 61,
5608c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5618c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5628c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5638c2ecf20Sopenharmony_ci	  .pp_count = 2,
5648c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	{ .n  = "mcan1_gclk",
5678c2ecf20Sopenharmony_ci	  .id = 62,
5688c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5698c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5708c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5718c2ecf20Sopenharmony_ci	  .pp_count = 2,
5728c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	{ .n  = "mcan2_gclk",
5758c2ecf20Sopenharmony_ci	  .id = 63,
5768c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5778c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5788c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5798c2ecf20Sopenharmony_ci	  .pp_count = 2,
5808c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci	{ .n  = "mcan3_gclk",
5838c2ecf20Sopenharmony_ci	  .id = 64,
5848c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5858c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5868c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5878c2ecf20Sopenharmony_ci	  .pp_count = 2,
5888c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	{ .n  = "mcan4_gclk",
5918c2ecf20Sopenharmony_ci	  .id = 65,
5928c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
5938c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
5948c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
5958c2ecf20Sopenharmony_ci	  .pp_count = 2,
5968c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	{ .n  = "mcan5_gclk",
5998c2ecf20Sopenharmony_ci	  .id = 66,
6008c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6018c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
6028c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
6038c2ecf20Sopenharmony_ci	  .pp_count = 2,
6048c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	{ .n  = "pdmc0_gclk",
6078c2ecf20Sopenharmony_ci	  .id = 68,
6088c2ecf20Sopenharmony_ci	  .r = { .max = 50000000  },
6098c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
6108c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
6118c2ecf20Sopenharmony_ci	  .pp_count = 2,
6128c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	{ .n  = "pdmc1_gclk",
6158c2ecf20Sopenharmony_ci	  .id = 69,
6168c2ecf20Sopenharmony_ci	  .r = { .max = 50000000, },
6178c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
6188c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
6198c2ecf20Sopenharmony_ci	  .pp_count = 2,
6208c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci	{ .n  = "pit64b0_gclk",
6238c2ecf20Sopenharmony_ci	  .id = 70,
6248c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6258c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6268c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6278c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6288c2ecf20Sopenharmony_ci	  .pp_count = 5,
6298c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	{ .n  = "pit64b1_gclk",
6328c2ecf20Sopenharmony_ci	  .id = 71,
6338c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6348c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6358c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6368c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6378c2ecf20Sopenharmony_ci	  .pp_count = 5,
6388c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci	{ .n  = "pit64b2_gclk",
6418c2ecf20Sopenharmony_ci	  .id = 72,
6428c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6438c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6448c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6458c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6468c2ecf20Sopenharmony_ci	  .pp_count = 5,
6478c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	{ .n  = "pit64b3_gclk",
6508c2ecf20Sopenharmony_ci	  .id = 73,
6518c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6528c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6538c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6548c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6558c2ecf20Sopenharmony_ci	  .pp_count = 5,
6568c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci	{ .n  = "pit64b4_gclk",
6598c2ecf20Sopenharmony_ci	  .id = 74,
6608c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6618c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6628c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6638c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6648c2ecf20Sopenharmony_ci	  .pp_count = 5,
6658c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci	{ .n  = "pit64b5_gclk",
6688c2ecf20Sopenharmony_ci	  .id = 75,
6698c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6708c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
6718c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
6728c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
6738c2ecf20Sopenharmony_ci	  .pp_count = 5,
6748c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	{ .n  = "qspi0_gclk",
6778c2ecf20Sopenharmony_ci	  .id = 78,
6788c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6798c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
6808c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
6818c2ecf20Sopenharmony_ci	  .pp_count = 2,
6828c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	{ .n  = "qspi1_gclk",
6858c2ecf20Sopenharmony_ci	  .id = 79,
6868c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
6878c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
6888c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
6898c2ecf20Sopenharmony_ci	  .pp_count = 2,
6908c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci	{ .n  = "sdmmc0_gclk",
6938c2ecf20Sopenharmony_ci	  .id = 80,
6948c2ecf20Sopenharmony_ci	  .r = { .max = 208000000 },
6958c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
6968c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
6978c2ecf20Sopenharmony_ci	  .pp_count = 2,
6988c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci	{ .n  = "sdmmc1_gclk",
7018c2ecf20Sopenharmony_ci	  .id = 81,
7028c2ecf20Sopenharmony_ci	  .r = { .max = 208000000 },
7038c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
7048c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
7058c2ecf20Sopenharmony_ci	  .pp_count = 2,
7068c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	{ .n  = "sdmmc2_gclk",
7098c2ecf20Sopenharmony_ci	  .id = 82,
7108c2ecf20Sopenharmony_ci	  .r = { .max = 208000000 },
7118c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
7128c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 8, },
7138c2ecf20Sopenharmony_ci	  .pp_count = 2,
7148c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	{ .n  = "spdifrx_gclk",
7178c2ecf20Sopenharmony_ci	  .id = 84,
7188c2ecf20Sopenharmony_ci	  .r = { .max = 150000000 },
7198c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
7208c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
7218c2ecf20Sopenharmony_ci	  .pp_count = 2,
7228c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	{ .n = "spdiftx_gclk",
7258c2ecf20Sopenharmony_ci	  .id = 85,
7268c2ecf20Sopenharmony_ci	  .r = { .max = 25000000  },
7278c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
7288c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 9, },
7298c2ecf20Sopenharmony_ci	  .pp_count = 2,
7308c2ecf20Sopenharmony_ci	  .pp_chg_id = 5, },
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	{ .n  = "tcb0_ch0_gclk",
7338c2ecf20Sopenharmony_ci	  .id = 88,
7348c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
7358c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
7368c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
7378c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
7388c2ecf20Sopenharmony_ci	  .pp_count = 5,
7398c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	{ .n  = "tcb1_ch0_gclk",
7428c2ecf20Sopenharmony_ci	  .id = 91,
7438c2ecf20Sopenharmony_ci	  .r = { .max = 200000000 },
7448c2ecf20Sopenharmony_ci	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
7458c2ecf20Sopenharmony_ci		  "audiopll_divpmcck", "ethpll_divpmcck", },
7468c2ecf20Sopenharmony_ci	  .pp_mux_table = { 5, 7, 8, 9, 10, },
7478c2ecf20Sopenharmony_ci	  .pp_count = 5,
7488c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	{ .n  = "tcpca_gclk",
7518c2ecf20Sopenharmony_ci	  .id = 94,
7528c2ecf20Sopenharmony_ci	  .r = { .max = 32768, },
7538c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	{ .n  = "tcpcb_gclk",
7568c2ecf20Sopenharmony_ci	  .id = 95,
7578c2ecf20Sopenharmony_ci	  .r = { .max = 32768, },
7588c2ecf20Sopenharmony_ci	  .pp_chg_id = INT_MIN, },
7598c2ecf20Sopenharmony_ci};
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci/* PLL output range. */
7628c2ecf20Sopenharmony_cistatic const struct clk_range pll_outputs[] = {
7638c2ecf20Sopenharmony_ci	{ .min = 2343750, .max = 1200000000 },
7648c2ecf20Sopenharmony_ci};
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci/* PLL characteristics. */
7678c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics pll_characteristics = {
7688c2ecf20Sopenharmony_ci	.input = { .min = 12000000, .max = 50000000 },
7698c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(pll_outputs),
7708c2ecf20Sopenharmony_ci	.output = pll_outputs,
7718c2ecf20Sopenharmony_ci};
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci/* MCK0 characteristics. */
7748c2ecf20Sopenharmony_cistatic const struct clk_master_characteristics mck0_characteristics = {
7758c2ecf20Sopenharmony_ci	.output = { .min = 140000000, .max = 200000000 },
7768c2ecf20Sopenharmony_ci	.divisors = { 1, 2, 4, 3 },
7778c2ecf20Sopenharmony_ci	.have_div3_pres = 1,
7788c2ecf20Sopenharmony_ci};
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci/* MCK0 layout. */
7818c2ecf20Sopenharmony_cistatic const struct clk_master_layout mck0_layout = {
7828c2ecf20Sopenharmony_ci	.mask = 0x373,
7838c2ecf20Sopenharmony_ci	.pres_shift = 4,
7848c2ecf20Sopenharmony_ci	.offset = 0x28,
7858c2ecf20Sopenharmony_ci};
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci/* Programmable clock layout. */
7888c2ecf20Sopenharmony_cistatic const struct clk_programmable_layout programmable_layout = {
7898c2ecf20Sopenharmony_ci	.pres_mask = 0xff,
7908c2ecf20Sopenharmony_ci	.pres_shift = 8,
7918c2ecf20Sopenharmony_ci	.css_mask = 0x1f,
7928c2ecf20Sopenharmony_ci	.have_slck_mck = 0,
7938c2ecf20Sopenharmony_ci	.is_pres_direct = 1,
7948c2ecf20Sopenharmony_ci};
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci/* Peripheral clock layout. */
7978c2ecf20Sopenharmony_cistatic const struct clk_pcr_layout sama7g5_pcr_layout = {
7988c2ecf20Sopenharmony_ci	.offset = 0x88,
7998c2ecf20Sopenharmony_ci	.cmd = BIT(31),
8008c2ecf20Sopenharmony_ci	.gckcss_mask = GENMASK(12, 8),
8018c2ecf20Sopenharmony_ci	.pid_mask = GENMASK(6, 0),
8028c2ecf20Sopenharmony_ci};
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_cistatic void __init sama7g5_pmc_setup(struct device_node *np)
8058c2ecf20Sopenharmony_ci{
8068c2ecf20Sopenharmony_ci	const char *td_slck_name, *md_slck_name, *mainxtal_name;
8078c2ecf20Sopenharmony_ci	struct pmc_data *sama7g5_pmc;
8088c2ecf20Sopenharmony_ci	const char *parent_names[10];
8098c2ecf20Sopenharmony_ci	void **alloc_mem = NULL;
8108c2ecf20Sopenharmony_ci	int alloc_mem_size = 0;
8118c2ecf20Sopenharmony_ci	struct regmap *regmap;
8128c2ecf20Sopenharmony_ci	struct clk_hw *hw;
8138c2ecf20Sopenharmony_ci	bool bypass;
8148c2ecf20Sopenharmony_ci	int i, j;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	i = of_property_match_string(np, "clock-names", "td_slck");
8178c2ecf20Sopenharmony_ci	if (i < 0)
8188c2ecf20Sopenharmony_ci		return;
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	td_slck_name = of_clk_get_parent_name(np, i);
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci	i = of_property_match_string(np, "clock-names", "md_slck");
8238c2ecf20Sopenharmony_ci	if (i < 0)
8248c2ecf20Sopenharmony_ci		return;
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci	md_slck_name = of_clk_get_parent_name(np, i);
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	i = of_property_match_string(np, "clock-names", "main_xtal");
8298c2ecf20Sopenharmony_ci	if (i < 0)
8308c2ecf20Sopenharmony_ci		return;
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	mainxtal_name = of_clk_get_parent_name(np, i);
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	regmap = device_node_to_regmap(np);
8358c2ecf20Sopenharmony_ci	if (IS_ERR(regmap))
8368c2ecf20Sopenharmony_ci		return;
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci	sama7g5_pmc = pmc_data_allocate(PMC_I2S1_MUX + 1,
8398c2ecf20Sopenharmony_ci					nck(sama7g5_systemck),
8408c2ecf20Sopenharmony_ci					nck(sama7g5_periphck),
8418c2ecf20Sopenharmony_ci					nck(sama7g5_gck), 8);
8428c2ecf20Sopenharmony_ci	if (!sama7g5_pmc)
8438c2ecf20Sopenharmony_ci		return;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci	alloc_mem = kmalloc(sizeof(void *) *
8468c2ecf20Sopenharmony_ci			    (ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck)),
8478c2ecf20Sopenharmony_ci			    GFP_KERNEL);
8488c2ecf20Sopenharmony_ci	if (!alloc_mem)
8498c2ecf20Sopenharmony_ci		goto err_free;
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci	hw = at91_clk_register_main_rc_osc(regmap, "main_rc_osc", 12000000,
8528c2ecf20Sopenharmony_ci					   50000000);
8538c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
8548c2ecf20Sopenharmony_ci		goto err_free;
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci	bypass = of_property_read_bool(np, "atmel,osc-bypass");
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci	hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
8598c2ecf20Sopenharmony_ci					bypass);
8608c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
8618c2ecf20Sopenharmony_ci		goto err_free;
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	parent_names[0] = "main_rc_osc";
8648c2ecf20Sopenharmony_ci	parent_names[1] = "main_osc";
8658c2ecf20Sopenharmony_ci	hw = at91_clk_register_sam9x5_main(regmap, "mainck", parent_names, 2);
8668c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
8678c2ecf20Sopenharmony_ci		goto err_free;
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	sama7g5_pmc->chws[PMC_MAIN] = hw;
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci	for (i = 0; i < PLL_ID_MAX; i++) {
8728c2ecf20Sopenharmony_ci		for (j = 0; j < 3; j++) {
8738c2ecf20Sopenharmony_ci			struct clk_hw *parent_hw;
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci			if (!sama7g5_plls[i][j].n)
8768c2ecf20Sopenharmony_ci				continue;
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci			switch (sama7g5_plls[i][j].t) {
8798c2ecf20Sopenharmony_ci			case PLL_TYPE_FRAC:
8808c2ecf20Sopenharmony_ci				if (!strcmp(sama7g5_plls[i][j].p, "mainck"))
8818c2ecf20Sopenharmony_ci					parent_hw = sama7g5_pmc->chws[PMC_MAIN];
8828c2ecf20Sopenharmony_ci				else
8838c2ecf20Sopenharmony_ci					parent_hw = __clk_get_hw(of_clk_get_by_name(np,
8848c2ecf20Sopenharmony_ci						sama7g5_plls[i][j].p));
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci				hw = sam9x60_clk_register_frac_pll(regmap,
8878c2ecf20Sopenharmony_ci					&pmc_pll_lock, sama7g5_plls[i][j].n,
8888c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].p, parent_hw, i,
8898c2ecf20Sopenharmony_ci					&pll_characteristics,
8908c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].l,
8918c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].c);
8928c2ecf20Sopenharmony_ci				break;
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci			case PLL_TYPE_DIV:
8958c2ecf20Sopenharmony_ci				hw = sam9x60_clk_register_div_pll(regmap,
8968c2ecf20Sopenharmony_ci					&pmc_pll_lock, sama7g5_plls[i][j].n,
8978c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].p, i,
8988c2ecf20Sopenharmony_ci					&pll_characteristics,
8998c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].l,
9008c2ecf20Sopenharmony_ci					sama7g5_plls[i][j].c);
9018c2ecf20Sopenharmony_ci				break;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci			default:
9048c2ecf20Sopenharmony_ci				continue;
9058c2ecf20Sopenharmony_ci			}
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_ci			if (IS_ERR(hw))
9088c2ecf20Sopenharmony_ci				goto err_free;
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci			if (sama7g5_plls[i][j].eid)
9118c2ecf20Sopenharmony_ci				sama7g5_pmc->chws[sama7g5_plls[i][j].eid] = hw;
9128c2ecf20Sopenharmony_ci		}
9138c2ecf20Sopenharmony_ci	}
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	parent_names[0] = md_slck_name;
9168c2ecf20Sopenharmony_ci	parent_names[1] = "mainck";
9178c2ecf20Sopenharmony_ci	parent_names[2] = "cpupll_divpmcck";
9188c2ecf20Sopenharmony_ci	parent_names[3] = "syspll_divpmcck";
9198c2ecf20Sopenharmony_ci	hw = at91_clk_register_master(regmap, "mck0", 4, parent_names,
9208c2ecf20Sopenharmony_ci				      &mck0_layout, &mck0_characteristics);
9218c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
9228c2ecf20Sopenharmony_ci		goto err_free;
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_ci	sama7g5_pmc->chws[PMC_MCK] = hw;
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	parent_names[0] = md_slck_name;
9278c2ecf20Sopenharmony_ci	parent_names[1] = td_slck_name;
9288c2ecf20Sopenharmony_ci	parent_names[2] = "mainck";
9298c2ecf20Sopenharmony_ci	parent_names[3] = "mck0";
9308c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(sama7g5_mckx); i++) {
9318c2ecf20Sopenharmony_ci		u8 num_parents = 4 + sama7g5_mckx[i].ep_count;
9328c2ecf20Sopenharmony_ci		u32 *mux_table;
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci		mux_table = kmalloc_array(num_parents, sizeof(*mux_table),
9358c2ecf20Sopenharmony_ci					  GFP_KERNEL);
9368c2ecf20Sopenharmony_ci		if (!mux_table)
9378c2ecf20Sopenharmony_ci			goto err_free;
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci		SAMA7G5_INIT_TABLE(mux_table, 4);
9408c2ecf20Sopenharmony_ci		SAMA7G5_FILL_TABLE(&mux_table[4], sama7g5_mckx[i].ep_mux_table,
9418c2ecf20Sopenharmony_ci				   sama7g5_mckx[i].ep_count);
9428c2ecf20Sopenharmony_ci		SAMA7G5_FILL_TABLE(&parent_names[4], sama7g5_mckx[i].ep,
9438c2ecf20Sopenharmony_ci				   sama7g5_mckx[i].ep_count);
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci		hw = at91_clk_sama7g5_register_master(regmap, sama7g5_mckx[i].n,
9468c2ecf20Sopenharmony_ci				   num_parents, parent_names, mux_table,
9478c2ecf20Sopenharmony_ci				   &pmc_mckX_lock, sama7g5_mckx[i].id,
9488c2ecf20Sopenharmony_ci				   sama7g5_mckx[i].c,
9498c2ecf20Sopenharmony_ci				   sama7g5_mckx[i].ep_chg_id);
9508c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
9518c2ecf20Sopenharmony_ci			goto err_free;
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_ci		alloc_mem[alloc_mem_size++] = mux_table;
9548c2ecf20Sopenharmony_ci	}
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	hw = at91_clk_sama7g5_register_utmi(regmap, "utmick", "main_xtal");
9578c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
9588c2ecf20Sopenharmony_ci		goto err_free;
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci	sama7g5_pmc->chws[PMC_UTMI] = hw;
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	parent_names[0] = md_slck_name;
9638c2ecf20Sopenharmony_ci	parent_names[1] = td_slck_name;
9648c2ecf20Sopenharmony_ci	parent_names[2] = "mainck";
9658c2ecf20Sopenharmony_ci	parent_names[3] = "mck0";
9668c2ecf20Sopenharmony_ci	parent_names[4] = "syspll_divpmcck";
9678c2ecf20Sopenharmony_ci	parent_names[5] = "ddrpll_divpmcck";
9688c2ecf20Sopenharmony_ci	parent_names[6] = "imgpll_divpmcck";
9698c2ecf20Sopenharmony_ci	parent_names[7] = "baudpll_divpmcck";
9708c2ecf20Sopenharmony_ci	parent_names[8] = "audiopll_divpmcck";
9718c2ecf20Sopenharmony_ci	parent_names[9] = "ethpll_divpmcck";
9728c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
9738c2ecf20Sopenharmony_ci		char name[6];
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci		snprintf(name, sizeof(name), "prog%d", i);
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_ci		hw = at91_clk_register_programmable(regmap, name, parent_names,
9788c2ecf20Sopenharmony_ci						    10, i,
9798c2ecf20Sopenharmony_ci						    &programmable_layout,
9808c2ecf20Sopenharmony_ci						    sama7g5_prog_mux_table);
9818c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
9828c2ecf20Sopenharmony_ci			goto err_free;
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ci		sama7g5_pmc->pchws[i] = hw;
9858c2ecf20Sopenharmony_ci	}
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(sama7g5_systemck); i++) {
9888c2ecf20Sopenharmony_ci		hw = at91_clk_register_system(regmap, sama7g5_systemck[i].n,
9898c2ecf20Sopenharmony_ci					      sama7g5_systemck[i].p,
9908c2ecf20Sopenharmony_ci					      sama7g5_systemck[i].id);
9918c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
9928c2ecf20Sopenharmony_ci			goto err_free;
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci		sama7g5_pmc->shws[sama7g5_systemck[i].id] = hw;
9958c2ecf20Sopenharmony_ci	}
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(sama7g5_periphck); i++) {
9988c2ecf20Sopenharmony_ci		hw = at91_clk_register_sam9x5_peripheral(regmap, &pmc_pcr_lock,
9998c2ecf20Sopenharmony_ci						&sama7g5_pcr_layout,
10008c2ecf20Sopenharmony_ci						sama7g5_periphck[i].n,
10018c2ecf20Sopenharmony_ci						sama7g5_periphck[i].p,
10028c2ecf20Sopenharmony_ci						sama7g5_periphck[i].id,
10038c2ecf20Sopenharmony_ci						&sama7g5_periphck[i].r,
10048c2ecf20Sopenharmony_ci						sama7g5_periphck[i].chgp ? 0 :
10058c2ecf20Sopenharmony_ci						INT_MIN);
10068c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
10078c2ecf20Sopenharmony_ci			goto err_free;
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci		sama7g5_pmc->phws[sama7g5_periphck[i].id] = hw;
10108c2ecf20Sopenharmony_ci	}
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci	parent_names[0] = md_slck_name;
10138c2ecf20Sopenharmony_ci	parent_names[1] = td_slck_name;
10148c2ecf20Sopenharmony_ci	parent_names[2] = "mainck";
10158c2ecf20Sopenharmony_ci	parent_names[3] = "mck0";
10168c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(sama7g5_gck); i++) {
10178c2ecf20Sopenharmony_ci		u8 num_parents = 4 + sama7g5_gck[i].pp_count;
10188c2ecf20Sopenharmony_ci		u32 *mux_table;
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ci		mux_table = kmalloc_array(num_parents, sizeof(*mux_table),
10218c2ecf20Sopenharmony_ci					  GFP_KERNEL);
10228c2ecf20Sopenharmony_ci		if (!mux_table)
10238c2ecf20Sopenharmony_ci			goto err_free;
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_ci		SAMA7G5_INIT_TABLE(mux_table, 4);
10268c2ecf20Sopenharmony_ci		SAMA7G5_FILL_TABLE(&mux_table[4], sama7g5_gck[i].pp_mux_table,
10278c2ecf20Sopenharmony_ci				   sama7g5_gck[i].pp_count);
10288c2ecf20Sopenharmony_ci		SAMA7G5_FILL_TABLE(&parent_names[4], sama7g5_gck[i].pp,
10298c2ecf20Sopenharmony_ci				   sama7g5_gck[i].pp_count);
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci		hw = at91_clk_register_generated(regmap, &pmc_pcr_lock,
10328c2ecf20Sopenharmony_ci						 &sama7g5_pcr_layout,
10338c2ecf20Sopenharmony_ci						 sama7g5_gck[i].n,
10348c2ecf20Sopenharmony_ci						 parent_names, mux_table,
10358c2ecf20Sopenharmony_ci						 num_parents,
10368c2ecf20Sopenharmony_ci						 sama7g5_gck[i].id,
10378c2ecf20Sopenharmony_ci						 &sama7g5_gck[i].r,
10388c2ecf20Sopenharmony_ci						 sama7g5_gck[i].pp_chg_id);
10398c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
10408c2ecf20Sopenharmony_ci			goto err_free;
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci		sama7g5_pmc->ghws[sama7g5_gck[i].id] = hw;
10438c2ecf20Sopenharmony_ci		alloc_mem[alloc_mem_size++] = mux_table;
10448c2ecf20Sopenharmony_ci	}
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_pmc_get, sama7g5_pmc);
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci	return;
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_cierr_free:
10518c2ecf20Sopenharmony_ci	if (alloc_mem) {
10528c2ecf20Sopenharmony_ci		for (i = 0; i < alloc_mem_size; i++)
10538c2ecf20Sopenharmony_ci			kfree(alloc_mem[i]);
10548c2ecf20Sopenharmony_ci		kfree(alloc_mem);
10558c2ecf20Sopenharmony_ci	}
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ci	kfree(sama7g5_pmc);
10588c2ecf20Sopenharmony_ci}
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_ci/* Some clks are used for a clocksource */
10618c2ecf20Sopenharmony_ciCLK_OF_DECLARE(sama7g5_pmc, "microchip,sama7g5-pmc", sama7g5_pmc_setup);
1062