18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
38c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
48c2ecf20Sopenharmony_ci#include <linux/slab.h>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <dt-bindings/clock/at91.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "pmc.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistruct sck {
118c2ecf20Sopenharmony_ci	char *n;
128c2ecf20Sopenharmony_ci	char *p;
138c2ecf20Sopenharmony_ci	u8 id;
148c2ecf20Sopenharmony_ci};
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct pck {
178c2ecf20Sopenharmony_ci	char *n;
188c2ecf20Sopenharmony_ci	u8 id;
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct at91sam926x_data {
228c2ecf20Sopenharmony_ci	const struct clk_pll_layout *plla_layout;
238c2ecf20Sopenharmony_ci	const struct clk_pll_characteristics *plla_characteristics;
248c2ecf20Sopenharmony_ci	const struct clk_pll_layout *pllb_layout;
258c2ecf20Sopenharmony_ci	const struct clk_pll_characteristics *pllb_characteristics;
268c2ecf20Sopenharmony_ci	const struct clk_master_characteristics *mck_characteristics;
278c2ecf20Sopenharmony_ci	const struct sck *sck;
288c2ecf20Sopenharmony_ci	const struct pck *pck;
298c2ecf20Sopenharmony_ci	u8 num_sck;
308c2ecf20Sopenharmony_ci	u8 num_pck;
318c2ecf20Sopenharmony_ci	u8 num_progck;
328c2ecf20Sopenharmony_ci	bool has_slck;
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic const struct clk_master_characteristics sam9260_mck_characteristics = {
368c2ecf20Sopenharmony_ci	.output = { .min = 0, .max = 105000000 },
378c2ecf20Sopenharmony_ci	.divisors = { 1, 2, 4, 0 },
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic u8 sam9260_plla_out[] = { 0, 2 };
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic u16 sam9260_plla_icpll[] = { 1, 1 };
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const struct clk_range sam9260_plla_outputs[] = {
458c2ecf20Sopenharmony_ci	{ .min = 80000000, .max = 160000000 },
468c2ecf20Sopenharmony_ci	{ .min = 150000000, .max = 240000000 },
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9260_plla_characteristics = {
508c2ecf20Sopenharmony_ci	.input = { .min = 1000000, .max = 32000000 },
518c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9260_plla_outputs),
528c2ecf20Sopenharmony_ci	.output = sam9260_plla_outputs,
538c2ecf20Sopenharmony_ci	.icpll = sam9260_plla_icpll,
548c2ecf20Sopenharmony_ci	.out = sam9260_plla_out,
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic u8 sam9260_pllb_out[] = { 1 };
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic u16 sam9260_pllb_icpll[] = { 1 };
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic const struct clk_range sam9260_pllb_outputs[] = {
628c2ecf20Sopenharmony_ci	{ .min = 70000000, .max = 130000000 },
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9260_pllb_characteristics = {
668c2ecf20Sopenharmony_ci	.input = { .min = 1000000, .max = 5000000 },
678c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9260_pllb_outputs),
688c2ecf20Sopenharmony_ci	.output = sam9260_pllb_outputs,
698c2ecf20Sopenharmony_ci	.icpll = sam9260_pllb_icpll,
708c2ecf20Sopenharmony_ci	.out = sam9260_pllb_out,
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic const struct sck at91sam9260_systemck[] = {
748c2ecf20Sopenharmony_ci	{ .n = "uhpck", .p = "usbck",    .id = 6 },
758c2ecf20Sopenharmony_ci	{ .n = "udpck", .p = "usbck",    .id = 7 },
768c2ecf20Sopenharmony_ci	{ .n = "pck0",  .p = "prog0",    .id = 8 },
778c2ecf20Sopenharmony_ci	{ .n = "pck1",  .p = "prog1",    .id = 9 },
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic const struct pck at91sam9260_periphck[] = {
818c2ecf20Sopenharmony_ci	{ .n = "pioA_clk",   .id = 2 },
828c2ecf20Sopenharmony_ci	{ .n = "pioB_clk",   .id = 3 },
838c2ecf20Sopenharmony_ci	{ .n = "pioC_clk",   .id = 4 },
848c2ecf20Sopenharmony_ci	{ .n = "adc_clk",    .id = 5 },
858c2ecf20Sopenharmony_ci	{ .n = "usart0_clk", .id = 6 },
868c2ecf20Sopenharmony_ci	{ .n = "usart1_clk", .id = 7 },
878c2ecf20Sopenharmony_ci	{ .n = "usart2_clk", .id = 8 },
888c2ecf20Sopenharmony_ci	{ .n = "mci0_clk",   .id = 9 },
898c2ecf20Sopenharmony_ci	{ .n = "udc_clk",    .id = 10 },
908c2ecf20Sopenharmony_ci	{ .n = "twi0_clk",   .id = 11 },
918c2ecf20Sopenharmony_ci	{ .n = "spi0_clk",   .id = 12 },
928c2ecf20Sopenharmony_ci	{ .n = "spi1_clk",   .id = 13 },
938c2ecf20Sopenharmony_ci	{ .n = "ssc0_clk",   .id = 14 },
948c2ecf20Sopenharmony_ci	{ .n = "tc0_clk",    .id = 17 },
958c2ecf20Sopenharmony_ci	{ .n = "tc1_clk",    .id = 18 },
968c2ecf20Sopenharmony_ci	{ .n = "tc2_clk",    .id = 19 },
978c2ecf20Sopenharmony_ci	{ .n = "ohci_clk",   .id = 20 },
988c2ecf20Sopenharmony_ci	{ .n = "macb0_clk",  .id = 21 },
998c2ecf20Sopenharmony_ci	{ .n = "isi_clk",    .id = 22 },
1008c2ecf20Sopenharmony_ci	{ .n = "usart3_clk", .id = 23 },
1018c2ecf20Sopenharmony_ci	{ .n = "uart0_clk",  .id = 24 },
1028c2ecf20Sopenharmony_ci	{ .n = "uart1_clk",  .id = 25 },
1038c2ecf20Sopenharmony_ci	{ .n = "tc3_clk",    .id = 26 },
1048c2ecf20Sopenharmony_ci	{ .n = "tc4_clk",    .id = 27 },
1058c2ecf20Sopenharmony_ci	{ .n = "tc5_clk",    .id = 28 },
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic struct at91sam926x_data at91sam9260_data = {
1098c2ecf20Sopenharmony_ci	.plla_layout = &at91rm9200_pll_layout,
1108c2ecf20Sopenharmony_ci	.plla_characteristics = &sam9260_plla_characteristics,
1118c2ecf20Sopenharmony_ci	.pllb_layout = &at91rm9200_pll_layout,
1128c2ecf20Sopenharmony_ci	.pllb_characteristics = &sam9260_pllb_characteristics,
1138c2ecf20Sopenharmony_ci	.mck_characteristics = &sam9260_mck_characteristics,
1148c2ecf20Sopenharmony_ci	.sck = at91sam9260_systemck,
1158c2ecf20Sopenharmony_ci	.num_sck = ARRAY_SIZE(at91sam9260_systemck),
1168c2ecf20Sopenharmony_ci	.pck = at91sam9260_periphck,
1178c2ecf20Sopenharmony_ci	.num_pck = ARRAY_SIZE(at91sam9260_periphck),
1188c2ecf20Sopenharmony_ci	.num_progck = 2,
1198c2ecf20Sopenharmony_ci	.has_slck = true,
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic const struct clk_master_characteristics sam9g20_mck_characteristics = {
1238c2ecf20Sopenharmony_ci	.output = { .min = 0, .max = 133000000 },
1248c2ecf20Sopenharmony_ci	.divisors = { 1, 2, 4, 6 },
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic u8 sam9g20_plla_out[] = { 0, 1, 2, 3, 0, 1, 2, 3 };
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic u16 sam9g20_plla_icpll[] = { 0, 0, 0, 0, 1, 1, 1, 1 };
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic const struct clk_range sam9g20_plla_outputs[] = {
1328c2ecf20Sopenharmony_ci	{ .min = 745000000, .max = 800000000 },
1338c2ecf20Sopenharmony_ci	{ .min = 695000000, .max = 750000000 },
1348c2ecf20Sopenharmony_ci	{ .min = 645000000, .max = 700000000 },
1358c2ecf20Sopenharmony_ci	{ .min = 595000000, .max = 650000000 },
1368c2ecf20Sopenharmony_ci	{ .min = 545000000, .max = 600000000 },
1378c2ecf20Sopenharmony_ci	{ .min = 495000000, .max = 550000000 },
1388c2ecf20Sopenharmony_ci	{ .min = 445000000, .max = 500000000 },
1398c2ecf20Sopenharmony_ci	{ .min = 400000000, .max = 450000000 },
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9g20_plla_characteristics = {
1438c2ecf20Sopenharmony_ci	.input = { .min = 2000000, .max = 32000000 },
1448c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9g20_plla_outputs),
1458c2ecf20Sopenharmony_ci	.output = sam9g20_plla_outputs,
1468c2ecf20Sopenharmony_ci	.icpll = sam9g20_plla_icpll,
1478c2ecf20Sopenharmony_ci	.out = sam9g20_plla_out,
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic u8 sam9g20_pllb_out[] = { 0 };
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic u16 sam9g20_pllb_icpll[] = { 0 };
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic const struct clk_range sam9g20_pllb_outputs[] = {
1558c2ecf20Sopenharmony_ci	{ .min = 30000000, .max = 100000000 },
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9g20_pllb_characteristics = {
1598c2ecf20Sopenharmony_ci	.input = { .min = 2000000, .max = 32000000 },
1608c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9g20_pllb_outputs),
1618c2ecf20Sopenharmony_ci	.output = sam9g20_pllb_outputs,
1628c2ecf20Sopenharmony_ci	.icpll = sam9g20_pllb_icpll,
1638c2ecf20Sopenharmony_ci	.out = sam9g20_pllb_out,
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistatic struct at91sam926x_data at91sam9g20_data = {
1678c2ecf20Sopenharmony_ci	.plla_layout = &at91sam9g45_pll_layout,
1688c2ecf20Sopenharmony_ci	.plla_characteristics = &sam9g20_plla_characteristics,
1698c2ecf20Sopenharmony_ci	.pllb_layout = &at91sam9g20_pllb_layout,
1708c2ecf20Sopenharmony_ci	.pllb_characteristics = &sam9g20_pllb_characteristics,
1718c2ecf20Sopenharmony_ci	.mck_characteristics = &sam9g20_mck_characteristics,
1728c2ecf20Sopenharmony_ci	.sck = at91sam9260_systemck,
1738c2ecf20Sopenharmony_ci	.num_sck = ARRAY_SIZE(at91sam9260_systemck),
1748c2ecf20Sopenharmony_ci	.pck = at91sam9260_periphck,
1758c2ecf20Sopenharmony_ci	.num_pck = ARRAY_SIZE(at91sam9260_periphck),
1768c2ecf20Sopenharmony_ci	.num_progck = 2,
1778c2ecf20Sopenharmony_ci	.has_slck = true,
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic const struct clk_master_characteristics sam9261_mck_characteristics = {
1818c2ecf20Sopenharmony_ci	.output = { .min = 0, .max = 94000000 },
1828c2ecf20Sopenharmony_ci	.divisors = { 1, 2, 4, 0 },
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic const struct clk_range sam9261_plla_outputs[] = {
1868c2ecf20Sopenharmony_ci	{ .min = 80000000, .max = 200000000 },
1878c2ecf20Sopenharmony_ci	{ .min = 190000000, .max = 240000000 },
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9261_plla_characteristics = {
1918c2ecf20Sopenharmony_ci	.input = { .min = 1000000, .max = 32000000 },
1928c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9261_plla_outputs),
1938c2ecf20Sopenharmony_ci	.output = sam9261_plla_outputs,
1948c2ecf20Sopenharmony_ci	.icpll = sam9260_plla_icpll,
1958c2ecf20Sopenharmony_ci	.out = sam9260_plla_out,
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic u8 sam9261_pllb_out[] = { 1 };
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic u16 sam9261_pllb_icpll[] = { 1 };
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic const struct clk_range sam9261_pllb_outputs[] = {
2038c2ecf20Sopenharmony_ci	{ .min = 70000000, .max = 130000000 },
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9261_pllb_characteristics = {
2078c2ecf20Sopenharmony_ci	.input = { .min = 1000000, .max = 5000000 },
2088c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9261_pllb_outputs),
2098c2ecf20Sopenharmony_ci	.output = sam9261_pllb_outputs,
2108c2ecf20Sopenharmony_ci	.icpll = sam9261_pllb_icpll,
2118c2ecf20Sopenharmony_ci	.out = sam9261_pllb_out,
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic const struct sck at91sam9261_systemck[] = {
2158c2ecf20Sopenharmony_ci	{ .n = "uhpck", .p = "usbck",    .id = 6 },
2168c2ecf20Sopenharmony_ci	{ .n = "udpck", .p = "usbck",    .id = 7 },
2178c2ecf20Sopenharmony_ci	{ .n = "pck0",  .p = "prog0",    .id = 8 },
2188c2ecf20Sopenharmony_ci	{ .n = "pck1",  .p = "prog1",    .id = 9 },
2198c2ecf20Sopenharmony_ci	{ .n = "pck2",  .p = "prog2",    .id = 10 },
2208c2ecf20Sopenharmony_ci	{ .n = "pck3",  .p = "prog3",    .id = 11 },
2218c2ecf20Sopenharmony_ci	{ .n = "hclk0", .p = "masterck", .id = 16 },
2228c2ecf20Sopenharmony_ci	{ .n = "hclk1", .p = "masterck", .id = 17 },
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic const struct pck at91sam9261_periphck[] = {
2268c2ecf20Sopenharmony_ci	{ .n = "pioA_clk",   .id = 2, },
2278c2ecf20Sopenharmony_ci	{ .n = "pioB_clk",   .id = 3, },
2288c2ecf20Sopenharmony_ci	{ .n = "pioC_clk",   .id = 4, },
2298c2ecf20Sopenharmony_ci	{ .n = "usart0_clk", .id = 6, },
2308c2ecf20Sopenharmony_ci	{ .n = "usart1_clk", .id = 7, },
2318c2ecf20Sopenharmony_ci	{ .n = "usart2_clk", .id = 8, },
2328c2ecf20Sopenharmony_ci	{ .n = "mci0_clk",   .id = 9, },
2338c2ecf20Sopenharmony_ci	{ .n = "udc_clk",    .id = 10, },
2348c2ecf20Sopenharmony_ci	{ .n = "twi0_clk",   .id = 11, },
2358c2ecf20Sopenharmony_ci	{ .n = "spi0_clk",   .id = 12, },
2368c2ecf20Sopenharmony_ci	{ .n = "spi1_clk",   .id = 13, },
2378c2ecf20Sopenharmony_ci	{ .n = "ssc0_clk",   .id = 14, },
2388c2ecf20Sopenharmony_ci	{ .n = "ssc1_clk",   .id = 15, },
2398c2ecf20Sopenharmony_ci	{ .n = "ssc2_clk",   .id = 16, },
2408c2ecf20Sopenharmony_ci	{ .n = "tc0_clk",    .id = 17, },
2418c2ecf20Sopenharmony_ci	{ .n = "tc1_clk",    .id = 18, },
2428c2ecf20Sopenharmony_ci	{ .n = "tc2_clk",    .id = 19, },
2438c2ecf20Sopenharmony_ci	{ .n = "ohci_clk",   .id = 20, },
2448c2ecf20Sopenharmony_ci	{ .n = "lcd_clk",    .id = 21, },
2458c2ecf20Sopenharmony_ci};
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_cistatic struct at91sam926x_data at91sam9261_data = {
2488c2ecf20Sopenharmony_ci	.plla_layout = &at91rm9200_pll_layout,
2498c2ecf20Sopenharmony_ci	.plla_characteristics = &sam9261_plla_characteristics,
2508c2ecf20Sopenharmony_ci	.pllb_layout = &at91rm9200_pll_layout,
2518c2ecf20Sopenharmony_ci	.pllb_characteristics = &sam9261_pllb_characteristics,
2528c2ecf20Sopenharmony_ci	.mck_characteristics = &sam9261_mck_characteristics,
2538c2ecf20Sopenharmony_ci	.sck = at91sam9261_systemck,
2548c2ecf20Sopenharmony_ci	.num_sck = ARRAY_SIZE(at91sam9261_systemck),
2558c2ecf20Sopenharmony_ci	.pck = at91sam9261_periphck,
2568c2ecf20Sopenharmony_ci	.num_pck = ARRAY_SIZE(at91sam9261_periphck),
2578c2ecf20Sopenharmony_ci	.num_progck = 4,
2588c2ecf20Sopenharmony_ci};
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic const struct clk_master_characteristics sam9263_mck_characteristics = {
2618c2ecf20Sopenharmony_ci	.output = { .min = 0, .max = 120000000 },
2628c2ecf20Sopenharmony_ci	.divisors = { 1, 2, 4, 0 },
2638c2ecf20Sopenharmony_ci};
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistatic const struct clk_range sam9263_pll_outputs[] = {
2668c2ecf20Sopenharmony_ci	{ .min = 80000000, .max = 200000000 },
2678c2ecf20Sopenharmony_ci	{ .min = 190000000, .max = 240000000 },
2688c2ecf20Sopenharmony_ci};
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic const struct clk_pll_characteristics sam9263_pll_characteristics = {
2718c2ecf20Sopenharmony_ci	.input = { .min = 1000000, .max = 32000000 },
2728c2ecf20Sopenharmony_ci	.num_output = ARRAY_SIZE(sam9263_pll_outputs),
2738c2ecf20Sopenharmony_ci	.output = sam9263_pll_outputs,
2748c2ecf20Sopenharmony_ci	.icpll = sam9260_plla_icpll,
2758c2ecf20Sopenharmony_ci	.out = sam9260_plla_out,
2768c2ecf20Sopenharmony_ci};
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cistatic const struct sck at91sam9263_systemck[] = {
2798c2ecf20Sopenharmony_ci	{ .n = "uhpck", .p = "usbck",    .id = 6 },
2808c2ecf20Sopenharmony_ci	{ .n = "udpck", .p = "usbck",    .id = 7 },
2818c2ecf20Sopenharmony_ci	{ .n = "pck0",  .p = "prog0",    .id = 8 },
2828c2ecf20Sopenharmony_ci	{ .n = "pck1",  .p = "prog1",    .id = 9 },
2838c2ecf20Sopenharmony_ci	{ .n = "pck2",  .p = "prog2",    .id = 10 },
2848c2ecf20Sopenharmony_ci	{ .n = "pck3",  .p = "prog3",    .id = 11 },
2858c2ecf20Sopenharmony_ci};
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_cistatic const struct pck at91sam9263_periphck[] = {
2888c2ecf20Sopenharmony_ci	{ .n = "pioA_clk",   .id = 2, },
2898c2ecf20Sopenharmony_ci	{ .n = "pioB_clk",   .id = 3, },
2908c2ecf20Sopenharmony_ci	{ .n = "pioCDE_clk", .id = 4, },
2918c2ecf20Sopenharmony_ci	{ .n = "usart0_clk", .id = 7, },
2928c2ecf20Sopenharmony_ci	{ .n = "usart1_clk", .id = 8, },
2938c2ecf20Sopenharmony_ci	{ .n = "usart2_clk", .id = 9, },
2948c2ecf20Sopenharmony_ci	{ .n = "mci0_clk",   .id = 10, },
2958c2ecf20Sopenharmony_ci	{ .n = "mci1_clk",   .id = 11, },
2968c2ecf20Sopenharmony_ci	{ .n = "can_clk",    .id = 12, },
2978c2ecf20Sopenharmony_ci	{ .n = "twi0_clk",   .id = 13, },
2988c2ecf20Sopenharmony_ci	{ .n = "spi0_clk",   .id = 14, },
2998c2ecf20Sopenharmony_ci	{ .n = "spi1_clk",   .id = 15, },
3008c2ecf20Sopenharmony_ci	{ .n = "ssc0_clk",   .id = 16, },
3018c2ecf20Sopenharmony_ci	{ .n = "ssc1_clk",   .id = 17, },
3028c2ecf20Sopenharmony_ci	{ .n = "ac97_clk",   .id = 18, },
3038c2ecf20Sopenharmony_ci	{ .n = "tcb_clk",    .id = 19, },
3048c2ecf20Sopenharmony_ci	{ .n = "pwm_clk",    .id = 20, },
3058c2ecf20Sopenharmony_ci	{ .n = "macb0_clk",  .id = 21, },
3068c2ecf20Sopenharmony_ci	{ .n = "g2de_clk",   .id = 23, },
3078c2ecf20Sopenharmony_ci	{ .n = "udc_clk",    .id = 24, },
3088c2ecf20Sopenharmony_ci	{ .n = "isi_clk",    .id = 25, },
3098c2ecf20Sopenharmony_ci	{ .n = "lcd_clk",    .id = 26, },
3108c2ecf20Sopenharmony_ci	{ .n = "dma_clk",    .id = 27, },
3118c2ecf20Sopenharmony_ci	{ .n = "ohci_clk",   .id = 29, },
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic struct at91sam926x_data at91sam9263_data = {
3158c2ecf20Sopenharmony_ci	.plla_layout = &at91rm9200_pll_layout,
3168c2ecf20Sopenharmony_ci	.plla_characteristics = &sam9263_pll_characteristics,
3178c2ecf20Sopenharmony_ci	.pllb_layout = &at91rm9200_pll_layout,
3188c2ecf20Sopenharmony_ci	.pllb_characteristics = &sam9263_pll_characteristics,
3198c2ecf20Sopenharmony_ci	.mck_characteristics = &sam9263_mck_characteristics,
3208c2ecf20Sopenharmony_ci	.sck = at91sam9263_systemck,
3218c2ecf20Sopenharmony_ci	.num_sck = ARRAY_SIZE(at91sam9263_systemck),
3228c2ecf20Sopenharmony_ci	.pck = at91sam9263_periphck,
3238c2ecf20Sopenharmony_ci	.num_pck = ARRAY_SIZE(at91sam9263_periphck),
3248c2ecf20Sopenharmony_ci	.num_progck = 4,
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistatic void __init at91sam926x_pmc_setup(struct device_node *np,
3288c2ecf20Sopenharmony_ci					 struct at91sam926x_data *data)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	const char *slowxtal_name, *mainxtal_name;
3318c2ecf20Sopenharmony_ci	struct pmc_data *at91sam9260_pmc;
3328c2ecf20Sopenharmony_ci	u32 usb_div[] = { 1, 2, 4, 0 };
3338c2ecf20Sopenharmony_ci	const char *parent_names[6];
3348c2ecf20Sopenharmony_ci	const char *slck_name;
3358c2ecf20Sopenharmony_ci	struct regmap *regmap;
3368c2ecf20Sopenharmony_ci	struct clk_hw *hw;
3378c2ecf20Sopenharmony_ci	int i;
3388c2ecf20Sopenharmony_ci	bool bypass;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	i = of_property_match_string(np, "clock-names", "slow_xtal");
3418c2ecf20Sopenharmony_ci	if (i < 0)
3428c2ecf20Sopenharmony_ci		return;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	slowxtal_name = of_clk_get_parent_name(np, i);
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	i = of_property_match_string(np, "clock-names", "main_xtal");
3478c2ecf20Sopenharmony_ci	if (i < 0)
3488c2ecf20Sopenharmony_ci		return;
3498c2ecf20Sopenharmony_ci	mainxtal_name = of_clk_get_parent_name(np, i);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	regmap = device_node_to_regmap(np);
3528c2ecf20Sopenharmony_ci	if (IS_ERR(regmap))
3538c2ecf20Sopenharmony_ci		return;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	at91sam9260_pmc = pmc_data_allocate(PMC_PLLBCK + 1,
3568c2ecf20Sopenharmony_ci					    ndck(data->sck, data->num_sck),
3578c2ecf20Sopenharmony_ci					    ndck(data->pck, data->num_pck),
3588c2ecf20Sopenharmony_ci					    0, data->num_progck);
3598c2ecf20Sopenharmony_ci	if (!at91sam9260_pmc)
3608c2ecf20Sopenharmony_ci		return;
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	bypass = of_property_read_bool(np, "atmel,osc-bypass");
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
3658c2ecf20Sopenharmony_ci					bypass);
3668c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
3678c2ecf20Sopenharmony_ci		goto err_free;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	hw = at91_clk_register_rm9200_main(regmap, "mainck", "main_osc");
3708c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
3718c2ecf20Sopenharmony_ci		goto err_free;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	at91sam9260_pmc->chws[PMC_MAIN] = hw;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	if (data->has_slck) {
3768c2ecf20Sopenharmony_ci		hw = clk_hw_register_fixed_rate_with_accuracy(NULL,
3778c2ecf20Sopenharmony_ci							      "slow_rc_osc",
3788c2ecf20Sopenharmony_ci							      NULL, 0, 32768,
3798c2ecf20Sopenharmony_ci							      50000000);
3808c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
3818c2ecf20Sopenharmony_ci			goto err_free;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci		parent_names[0] = "slow_rc_osc";
3848c2ecf20Sopenharmony_ci		parent_names[1] = "slow_xtal";
3858c2ecf20Sopenharmony_ci		hw = at91_clk_register_sam9260_slow(regmap, "slck",
3868c2ecf20Sopenharmony_ci						    parent_names, 2);
3878c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
3888c2ecf20Sopenharmony_ci			goto err_free;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci		at91sam9260_pmc->chws[PMC_SLOW] = hw;
3918c2ecf20Sopenharmony_ci		slck_name = "slck";
3928c2ecf20Sopenharmony_ci	} else {
3938c2ecf20Sopenharmony_ci		slck_name = slowxtal_name;
3948c2ecf20Sopenharmony_ci	}
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	hw = at91_clk_register_pll(regmap, "pllack", "mainck", 0,
3978c2ecf20Sopenharmony_ci				   data->plla_layout,
3988c2ecf20Sopenharmony_ci				   data->plla_characteristics);
3998c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
4008c2ecf20Sopenharmony_ci		goto err_free;
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	at91sam9260_pmc->chws[PMC_PLLACK] = hw;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	hw = at91_clk_register_pll(regmap, "pllbck", "mainck", 1,
4058c2ecf20Sopenharmony_ci				   data->pllb_layout,
4068c2ecf20Sopenharmony_ci				   data->pllb_characteristics);
4078c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
4088c2ecf20Sopenharmony_ci		goto err_free;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	at91sam9260_pmc->chws[PMC_PLLBCK] = hw;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	parent_names[0] = slck_name;
4138c2ecf20Sopenharmony_ci	parent_names[1] = "mainck";
4148c2ecf20Sopenharmony_ci	parent_names[2] = "pllack";
4158c2ecf20Sopenharmony_ci	parent_names[3] = "pllbck";
4168c2ecf20Sopenharmony_ci	hw = at91_clk_register_master(regmap, "masterck", 4, parent_names,
4178c2ecf20Sopenharmony_ci				      &at91rm9200_master_layout,
4188c2ecf20Sopenharmony_ci				      data->mck_characteristics);
4198c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
4208c2ecf20Sopenharmony_ci		goto err_free;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	at91sam9260_pmc->chws[PMC_MCK] = hw;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	hw = at91rm9200_clk_register_usb(regmap, "usbck", "pllbck", usb_div);
4258c2ecf20Sopenharmony_ci	if (IS_ERR(hw))
4268c2ecf20Sopenharmony_ci		goto err_free;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	parent_names[0] = slck_name;
4298c2ecf20Sopenharmony_ci	parent_names[1] = "mainck";
4308c2ecf20Sopenharmony_ci	parent_names[2] = "pllack";
4318c2ecf20Sopenharmony_ci	parent_names[3] = "pllbck";
4328c2ecf20Sopenharmony_ci	for (i = 0; i < data->num_progck; i++) {
4338c2ecf20Sopenharmony_ci		char name[6];
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci		snprintf(name, sizeof(name), "prog%d", i);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci		hw = at91_clk_register_programmable(regmap, name,
4388c2ecf20Sopenharmony_ci						    parent_names, 4, i,
4398c2ecf20Sopenharmony_ci						    &at91rm9200_programmable_layout,
4408c2ecf20Sopenharmony_ci						    NULL);
4418c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
4428c2ecf20Sopenharmony_ci			goto err_free;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci		at91sam9260_pmc->pchws[i] = hw;
4458c2ecf20Sopenharmony_ci	}
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	for (i = 0; i < data->num_sck; i++) {
4488c2ecf20Sopenharmony_ci		hw = at91_clk_register_system(regmap, data->sck[i].n,
4498c2ecf20Sopenharmony_ci					      data->sck[i].p,
4508c2ecf20Sopenharmony_ci					      data->sck[i].id);
4518c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
4528c2ecf20Sopenharmony_ci			goto err_free;
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci		at91sam9260_pmc->shws[data->sck[i].id] = hw;
4558c2ecf20Sopenharmony_ci	}
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	for (i = 0; i < data->num_pck; i++) {
4588c2ecf20Sopenharmony_ci		hw = at91_clk_register_peripheral(regmap,
4598c2ecf20Sopenharmony_ci						  data->pck[i].n,
4608c2ecf20Sopenharmony_ci						  "masterck",
4618c2ecf20Sopenharmony_ci						  data->pck[i].id);
4628c2ecf20Sopenharmony_ci		if (IS_ERR(hw))
4638c2ecf20Sopenharmony_ci			goto err_free;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci		at91sam9260_pmc->phws[data->pck[i].id] = hw;
4668c2ecf20Sopenharmony_ci	}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_pmc_get, at91sam9260_pmc);
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	return;
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_cierr_free:
4738c2ecf20Sopenharmony_ci	kfree(at91sam9260_pmc);
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_cistatic void __init at91sam9260_pmc_setup(struct device_node *np)
4778c2ecf20Sopenharmony_ci{
4788c2ecf20Sopenharmony_ci	at91sam926x_pmc_setup(np, &at91sam9260_data);
4798c2ecf20Sopenharmony_ci}
4808c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(at91sam9260_pmc, "atmel,at91sam9260-pmc",
4818c2ecf20Sopenharmony_ci		      at91sam9260_pmc_setup);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_cistatic void __init at91sam9261_pmc_setup(struct device_node *np)
4848c2ecf20Sopenharmony_ci{
4858c2ecf20Sopenharmony_ci	at91sam926x_pmc_setup(np, &at91sam9261_data);
4868c2ecf20Sopenharmony_ci}
4878c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(at91sam9261_pmc, "atmel,at91sam9261-pmc",
4888c2ecf20Sopenharmony_ci		      at91sam9261_pmc_setup);
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_cistatic void __init at91sam9263_pmc_setup(struct device_node *np)
4918c2ecf20Sopenharmony_ci{
4928c2ecf20Sopenharmony_ci	at91sam926x_pmc_setup(np, &at91sam9263_data);
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(at91sam9263_pmc, "atmel,at91sam9263-pmc",
4958c2ecf20Sopenharmony_ci		      at91sam9263_pmc_setup);
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_cistatic void __init at91sam9g20_pmc_setup(struct device_node *np)
4988c2ecf20Sopenharmony_ci{
4998c2ecf20Sopenharmony_ci	at91sam926x_pmc_setup(np, &at91sam9g20_data);
5008c2ecf20Sopenharmony_ci}
5018c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(at91sam9g20_pmc, "atmel,at91sam9g20-pmc",
5028c2ecf20Sopenharmony_ci		      at91sam9g20_pmc_setup);
503