xref: /kernel/linux/linux-5.10/drivers/clk/ti/adpll.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
38c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as
48c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any
78c2ecf20Sopenharmony_ci * kind, whether express or implied; without even the implied warranty
88c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98c2ecf20Sopenharmony_ci * GNU General Public License for more details.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/clk.h>
138c2ecf20Sopenharmony_ci#include <linux/clkdev.h>
148c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
158c2ecf20Sopenharmony_ci#include <linux/delay.h>
168c2ecf20Sopenharmony_ci#include <linux/err.h>
178c2ecf20Sopenharmony_ci#include <linux/io.h>
188c2ecf20Sopenharmony_ci#include <linux/math64.h>
198c2ecf20Sopenharmony_ci#include <linux/module.h>
208c2ecf20Sopenharmony_ci#include <linux/of_device.h>
218c2ecf20Sopenharmony_ci#include <linux/string.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define ADPLL_PLLSS_MMR_LOCK_OFFSET	0x00	/* Managed by MPPULL */
248c2ecf20Sopenharmony_ci#define ADPLL_PLLSS_MMR_LOCK_ENABLED	0x1f125B64
258c2ecf20Sopenharmony_ci#define ADPLL_PLLSS_MMR_UNLOCK_MAGIC	0x1eda4c3d
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_OFFSET		0x00
288c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_PONIN		5
298c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_PGOODIN		4
308c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_RET		3
318c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_ISORET		2
328c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_ISOSCAN		1
338c2ecf20Sopenharmony_ci#define ADPLL_PWRCTRL_OFFMODE		0
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_OFFSET		0x04
368c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_CLKDCOLDOEN	29
378c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_IDLE		23
388c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_CLKOUTEN		20
398c2ecf20Sopenharmony_ci#define ADPLL_CLKINPHIFSEL_ADPLL_S	19	/* REVISIT: which bit? */
408c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_CLKOUTLDOEN_ADPLL_LJ 19
418c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_ULOWCLKEN		18
428c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_CLKDCOLDOPWDNZ	17
438c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_M2PWDNZ		16
448c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_M3PWDNZ_ADPLL_S	15
458c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_LOWCURRSTDBY_ADPLL_S 13
468c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_LPMODE_ADPLL_S	12
478c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_REGM4XEN_ADPLL_S	10
488c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_SELFREQDCO_ADPLL_LJ 10
498c2ecf20Sopenharmony_ci#define ADPLL_CLKCTRL_TINITZ		0
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define ADPLL_TENABLE_OFFSET		0x08
528c2ecf20Sopenharmony_ci#define ADPLL_TENABLEDIV_OFFSET		0x8c
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define ADPLL_M2NDIV_OFFSET		0x10
558c2ecf20Sopenharmony_ci#define ADPLL_M2NDIV_M2			16
568c2ecf20Sopenharmony_ci#define ADPLL_M2NDIV_M2_ADPLL_S_WIDTH	5
578c2ecf20Sopenharmony_ci#define ADPLL_M2NDIV_M2_ADPLL_LJ_WIDTH	7
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define ADPLL_MN2DIV_OFFSET		0x14
608c2ecf20Sopenharmony_ci#define ADPLL_MN2DIV_N2			16
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define ADPLL_FRACDIV_OFFSET		0x18
638c2ecf20Sopenharmony_ci#define ADPLL_FRACDIV_REGSD		24
648c2ecf20Sopenharmony_ci#define ADPLL_FRACDIV_FRACTIONALM	0
658c2ecf20Sopenharmony_ci#define ADPLL_FRACDIV_FRACTIONALM_MASK	0x3ffff
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define ADPLL_BWCTRL_OFFSET		0x1c
688c2ecf20Sopenharmony_ci#define ADPLL_BWCTRL_BWCONTROL		1
698c2ecf20Sopenharmony_ci#define ADPLL_BWCTRL_BW_INCR_DECRZ	0
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define ADPLL_RESERVED_OFFSET		0x20
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define ADPLL_STATUS_OFFSET		0x24
748c2ecf20Sopenharmony_ci#define ADPLL_STATUS_PONOUT		31
758c2ecf20Sopenharmony_ci#define ADPLL_STATUS_PGOODOUT		30
768c2ecf20Sopenharmony_ci#define ADPLL_STATUS_LDOPWDN		29
778c2ecf20Sopenharmony_ci#define ADPLL_STATUS_RECAL_BSTATUS3	28
788c2ecf20Sopenharmony_ci#define ADPLL_STATUS_RECAL_OPPIN	27
798c2ecf20Sopenharmony_ci#define ADPLL_STATUS_PHASELOCK		10
808c2ecf20Sopenharmony_ci#define ADPLL_STATUS_FREQLOCK		9
818c2ecf20Sopenharmony_ci#define ADPLL_STATUS_BYPASSACK		8
828c2ecf20Sopenharmony_ci#define ADPLL_STATUS_LOSSREF		6
838c2ecf20Sopenharmony_ci#define ADPLL_STATUS_CLKOUTENACK	5
848c2ecf20Sopenharmony_ci#define ADPLL_STATUS_LOCK2		4
858c2ecf20Sopenharmony_ci#define ADPLL_STATUS_M2CHANGEACK	3
868c2ecf20Sopenharmony_ci#define ADPLL_STATUS_HIGHJITTER		1
878c2ecf20Sopenharmony_ci#define ADPLL_STATUS_BYPASS		0
888c2ecf20Sopenharmony_ci#define ADPLL_STATUS_PREPARED_MASK	(BIT(ADPLL_STATUS_PHASELOCK) | \
898c2ecf20Sopenharmony_ci					 BIT(ADPLL_STATUS_FREQLOCK))
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define ADPLL_M3DIV_OFFSET		0x28	/* Only on MPUPLL */
928c2ecf20Sopenharmony_ci#define ADPLL_M3DIV_M3			0
938c2ecf20Sopenharmony_ci#define ADPLL_M3DIV_M3_WIDTH		5
948c2ecf20Sopenharmony_ci#define ADPLL_M3DIV_M3_MASK		0x1f
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define ADPLL_RAMPCTRL_OFFSET		0x2c	/* Only on MPUPLL */
978c2ecf20Sopenharmony_ci#define ADPLL_RAMPCTRL_CLKRAMPLEVEL	19
988c2ecf20Sopenharmony_ci#define ADPLL_RAMPCTRL_CLKRAMPRATE	16
998c2ecf20Sopenharmony_ci#define ADPLL_RAMPCTRL_RELOCK_RAMP_EN	0
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define MAX_ADPLL_INPUTS		3
1028c2ecf20Sopenharmony_ci#define MAX_ADPLL_OUTPUTS		4
1038c2ecf20Sopenharmony_ci#define ADPLL_MAX_RETRIES		5
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define to_dco(_hw)	container_of(_hw, struct ti_adpll_dco_data, hw)
1068c2ecf20Sopenharmony_ci#define to_adpll(_hw)	container_of(_hw, struct ti_adpll_data, dco)
1078c2ecf20Sopenharmony_ci#define to_clkout(_hw)	container_of(_hw, struct ti_adpll_clkout_data, hw)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cienum ti_adpll_clocks {
1108c2ecf20Sopenharmony_ci	TI_ADPLL_DCO,
1118c2ecf20Sopenharmony_ci	TI_ADPLL_DCO_GATE,
1128c2ecf20Sopenharmony_ci	TI_ADPLL_N2,
1138c2ecf20Sopenharmony_ci	TI_ADPLL_M2,
1148c2ecf20Sopenharmony_ci	TI_ADPLL_M2_GATE,
1158c2ecf20Sopenharmony_ci	TI_ADPLL_BYPASS,
1168c2ecf20Sopenharmony_ci	TI_ADPLL_HIF,
1178c2ecf20Sopenharmony_ci	TI_ADPLL_DIV2,
1188c2ecf20Sopenharmony_ci	TI_ADPLL_CLKOUT,
1198c2ecf20Sopenharmony_ci	TI_ADPLL_CLKOUT2,
1208c2ecf20Sopenharmony_ci	TI_ADPLL_M3,
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define TI_ADPLL_NR_CLOCKS	(TI_ADPLL_M3 + 1)
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cienum ti_adpll_inputs {
1268c2ecf20Sopenharmony_ci	TI_ADPLL_CLKINP,
1278c2ecf20Sopenharmony_ci	TI_ADPLL_CLKINPULOW,
1288c2ecf20Sopenharmony_ci	TI_ADPLL_CLKINPHIF,
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cienum ti_adpll_s_outputs {
1328c2ecf20Sopenharmony_ci	TI_ADPLL_S_DCOCLKLDO,
1338c2ecf20Sopenharmony_ci	TI_ADPLL_S_CLKOUT,
1348c2ecf20Sopenharmony_ci	TI_ADPLL_S_CLKOUTX2,
1358c2ecf20Sopenharmony_ci	TI_ADPLL_S_CLKOUTHIF,
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cienum ti_adpll_lj_outputs {
1398c2ecf20Sopenharmony_ci	TI_ADPLL_LJ_CLKDCOLDO,
1408c2ecf20Sopenharmony_ci	TI_ADPLL_LJ_CLKOUT,
1418c2ecf20Sopenharmony_ci	TI_ADPLL_LJ_CLKOUTLDO,
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistruct ti_adpll_platform_data {
1458c2ecf20Sopenharmony_ci	const bool is_type_s;
1468c2ecf20Sopenharmony_ci	const int nr_max_inputs;
1478c2ecf20Sopenharmony_ci	const int nr_max_outputs;
1488c2ecf20Sopenharmony_ci	const int output_index;
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistruct ti_adpll_clock {
1528c2ecf20Sopenharmony_ci	struct clk *clk;
1538c2ecf20Sopenharmony_ci	struct clk_lookup *cl;
1548c2ecf20Sopenharmony_ci	void (*unregister)(struct clk *clk);
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistruct ti_adpll_dco_data {
1588c2ecf20Sopenharmony_ci	struct clk_hw hw;
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistruct ti_adpll_clkout_data {
1628c2ecf20Sopenharmony_ci	struct ti_adpll_data *adpll;
1638c2ecf20Sopenharmony_ci	struct clk_gate gate;
1648c2ecf20Sopenharmony_ci	struct clk_hw hw;
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistruct ti_adpll_data {
1688c2ecf20Sopenharmony_ci	struct device *dev;
1698c2ecf20Sopenharmony_ci	const struct ti_adpll_platform_data *c;
1708c2ecf20Sopenharmony_ci	struct device_node *np;
1718c2ecf20Sopenharmony_ci	unsigned long pa;
1728c2ecf20Sopenharmony_ci	void __iomem *iobase;
1738c2ecf20Sopenharmony_ci	void __iomem *regs;
1748c2ecf20Sopenharmony_ci	spinlock_t lock;	/* For ADPLL shared register access */
1758c2ecf20Sopenharmony_ci	const char *parent_names[MAX_ADPLL_INPUTS];
1768c2ecf20Sopenharmony_ci	struct clk *parent_clocks[MAX_ADPLL_INPUTS];
1778c2ecf20Sopenharmony_ci	struct ti_adpll_clock *clocks;
1788c2ecf20Sopenharmony_ci	struct clk_onecell_data outputs;
1798c2ecf20Sopenharmony_ci	struct ti_adpll_dco_data dco;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic const char *ti_adpll_clk_get_name(struct ti_adpll_data *d,
1838c2ecf20Sopenharmony_ci					 int output_index,
1848c2ecf20Sopenharmony_ci					 const char *postfix)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	const char *name;
1878c2ecf20Sopenharmony_ci	int err;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	if (output_index >= 0) {
1908c2ecf20Sopenharmony_ci		err = of_property_read_string_index(d->np,
1918c2ecf20Sopenharmony_ci						    "clock-output-names",
1928c2ecf20Sopenharmony_ci						    output_index,
1938c2ecf20Sopenharmony_ci						    &name);
1948c2ecf20Sopenharmony_ci		if (err)
1958c2ecf20Sopenharmony_ci			return NULL;
1968c2ecf20Sopenharmony_ci	} else {
1978c2ecf20Sopenharmony_ci		name = devm_kasprintf(d->dev, GFP_KERNEL, "%08lx.adpll.%s",
1988c2ecf20Sopenharmony_ci				      d->pa, postfix);
1998c2ecf20Sopenharmony_ci	}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	return name;
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci#define ADPLL_MAX_CON_ID	16	/* See MAX_CON_ID */
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic int ti_adpll_setup_clock(struct ti_adpll_data *d, struct clk *clock,
2078c2ecf20Sopenharmony_ci				int index, int output_index, const char *name,
2088c2ecf20Sopenharmony_ci				void (*unregister)(struct clk *clk))
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	struct clk_lookup *cl;
2118c2ecf20Sopenharmony_ci	const char *postfix = NULL;
2128c2ecf20Sopenharmony_ci	char con_id[ADPLL_MAX_CON_ID];
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	d->clocks[index].clk = clock;
2158c2ecf20Sopenharmony_ci	d->clocks[index].unregister = unregister;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	/* Separate con_id in format "pll040dcoclkldo" to fit MAX_CON_ID */
2188c2ecf20Sopenharmony_ci	postfix = strrchr(name, '.');
2198c2ecf20Sopenharmony_ci	if (postfix && strlen(postfix) > 1) {
2208c2ecf20Sopenharmony_ci		if (strlen(postfix) > ADPLL_MAX_CON_ID)
2218c2ecf20Sopenharmony_ci			dev_warn(d->dev, "clock %s con_id lookup may fail\n",
2228c2ecf20Sopenharmony_ci				 name);
2238c2ecf20Sopenharmony_ci		snprintf(con_id, 16, "pll%03lx%s", d->pa & 0xfff, postfix + 1);
2248c2ecf20Sopenharmony_ci		cl = clkdev_create(clock, con_id, NULL);
2258c2ecf20Sopenharmony_ci		if (!cl)
2268c2ecf20Sopenharmony_ci			return -ENOMEM;
2278c2ecf20Sopenharmony_ci		d->clocks[index].cl = cl;
2288c2ecf20Sopenharmony_ci	} else {
2298c2ecf20Sopenharmony_ci		dev_warn(d->dev, "no con_id for clock %s\n", name);
2308c2ecf20Sopenharmony_ci	}
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	if (output_index < 0)
2338c2ecf20Sopenharmony_ci		return 0;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	d->outputs.clks[output_index] = clock;
2368c2ecf20Sopenharmony_ci	d->outputs.clk_num++;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	return 0;
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic int ti_adpll_init_divider(struct ti_adpll_data *d,
2428c2ecf20Sopenharmony_ci				 enum ti_adpll_clocks index,
2438c2ecf20Sopenharmony_ci				 int output_index, char *name,
2448c2ecf20Sopenharmony_ci				 struct clk *parent_clock,
2458c2ecf20Sopenharmony_ci				 void __iomem *reg,
2468c2ecf20Sopenharmony_ci				 u8 shift, u8 width,
2478c2ecf20Sopenharmony_ci				 u8 clk_divider_flags)
2488c2ecf20Sopenharmony_ci{
2498c2ecf20Sopenharmony_ci	const char *child_name;
2508c2ecf20Sopenharmony_ci	const char *parent_name;
2518c2ecf20Sopenharmony_ci	struct clk *clock;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	child_name = ti_adpll_clk_get_name(d, output_index, name);
2548c2ecf20Sopenharmony_ci	if (!child_name)
2558c2ecf20Sopenharmony_ci		return -EINVAL;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	parent_name = __clk_get_name(parent_clock);
2588c2ecf20Sopenharmony_ci	clock = clk_register_divider(d->dev, child_name, parent_name, 0,
2598c2ecf20Sopenharmony_ci				     reg, shift, width, clk_divider_flags,
2608c2ecf20Sopenharmony_ci				     &d->lock);
2618c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
2628c2ecf20Sopenharmony_ci		dev_err(d->dev, "failed to register divider %s: %li\n",
2638c2ecf20Sopenharmony_ci			name, PTR_ERR(clock));
2648c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
2658c2ecf20Sopenharmony_ci	}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, index, output_index, child_name,
2688c2ecf20Sopenharmony_ci				    clk_unregister_divider);
2698c2ecf20Sopenharmony_ci}
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistatic int ti_adpll_init_mux(struct ti_adpll_data *d,
2728c2ecf20Sopenharmony_ci			     enum ti_adpll_clocks index,
2738c2ecf20Sopenharmony_ci			     char *name, struct clk *clk0,
2748c2ecf20Sopenharmony_ci			     struct clk *clk1,
2758c2ecf20Sopenharmony_ci			     void __iomem *reg,
2768c2ecf20Sopenharmony_ci			     u8 shift)
2778c2ecf20Sopenharmony_ci{
2788c2ecf20Sopenharmony_ci	const char *child_name;
2798c2ecf20Sopenharmony_ci	const char *parents[2];
2808c2ecf20Sopenharmony_ci	struct clk *clock;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	child_name = ti_adpll_clk_get_name(d, -ENODEV, name);
2838c2ecf20Sopenharmony_ci	if (!child_name)
2848c2ecf20Sopenharmony_ci		return -ENOMEM;
2858c2ecf20Sopenharmony_ci	parents[0] = __clk_get_name(clk0);
2868c2ecf20Sopenharmony_ci	parents[1] = __clk_get_name(clk1);
2878c2ecf20Sopenharmony_ci	clock = clk_register_mux(d->dev, child_name, parents, 2, 0,
2888c2ecf20Sopenharmony_ci				 reg, shift, 1, 0, &d->lock);
2898c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
2908c2ecf20Sopenharmony_ci		dev_err(d->dev, "failed to register mux %s: %li\n",
2918c2ecf20Sopenharmony_ci			name, PTR_ERR(clock));
2928c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
2938c2ecf20Sopenharmony_ci	}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, index, -ENODEV, child_name,
2968c2ecf20Sopenharmony_ci				    clk_unregister_mux);
2978c2ecf20Sopenharmony_ci}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic int ti_adpll_init_gate(struct ti_adpll_data *d,
3008c2ecf20Sopenharmony_ci			      enum ti_adpll_clocks index,
3018c2ecf20Sopenharmony_ci			      int output_index, char *name,
3028c2ecf20Sopenharmony_ci			      struct clk *parent_clock,
3038c2ecf20Sopenharmony_ci			      void __iomem *reg,
3048c2ecf20Sopenharmony_ci			      u8 bit_idx,
3058c2ecf20Sopenharmony_ci			      u8 clk_gate_flags)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	const char *child_name;
3088c2ecf20Sopenharmony_ci	const char *parent_name;
3098c2ecf20Sopenharmony_ci	struct clk *clock;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	child_name = ti_adpll_clk_get_name(d, output_index, name);
3128c2ecf20Sopenharmony_ci	if (!child_name)
3138c2ecf20Sopenharmony_ci		return -EINVAL;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	parent_name = __clk_get_name(parent_clock);
3168c2ecf20Sopenharmony_ci	clock = clk_register_gate(d->dev, child_name, parent_name, 0,
3178c2ecf20Sopenharmony_ci				  reg, bit_idx, clk_gate_flags,
3188c2ecf20Sopenharmony_ci				  &d->lock);
3198c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
3208c2ecf20Sopenharmony_ci		dev_err(d->dev, "failed to register gate %s: %li\n",
3218c2ecf20Sopenharmony_ci			name, PTR_ERR(clock));
3228c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
3238c2ecf20Sopenharmony_ci	}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, index, output_index, child_name,
3268c2ecf20Sopenharmony_ci				    clk_unregister_gate);
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic int ti_adpll_init_fixed_factor(struct ti_adpll_data *d,
3308c2ecf20Sopenharmony_ci				      enum ti_adpll_clocks index,
3318c2ecf20Sopenharmony_ci				      char *name,
3328c2ecf20Sopenharmony_ci				      struct clk *parent_clock,
3338c2ecf20Sopenharmony_ci				      unsigned int mult,
3348c2ecf20Sopenharmony_ci				      unsigned int div)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	const char *child_name;
3378c2ecf20Sopenharmony_ci	const char *parent_name;
3388c2ecf20Sopenharmony_ci	struct clk *clock;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	child_name = ti_adpll_clk_get_name(d, -ENODEV, name);
3418c2ecf20Sopenharmony_ci	if (!child_name)
3428c2ecf20Sopenharmony_ci		return -ENOMEM;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	parent_name = __clk_get_name(parent_clock);
3458c2ecf20Sopenharmony_ci	clock = clk_register_fixed_factor(d->dev, child_name, parent_name,
3468c2ecf20Sopenharmony_ci					  0, mult, div);
3478c2ecf20Sopenharmony_ci	if (IS_ERR(clock))
3488c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, index, -ENODEV, child_name,
3518c2ecf20Sopenharmony_ci				    clk_unregister);
3528c2ecf20Sopenharmony_ci}
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic void ti_adpll_set_idle_bypass(struct ti_adpll_data *d)
3558c2ecf20Sopenharmony_ci{
3568c2ecf20Sopenharmony_ci	unsigned long flags;
3578c2ecf20Sopenharmony_ci	u32 v;
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	spin_lock_irqsave(&d->lock, flags);
3608c2ecf20Sopenharmony_ci	v = readl_relaxed(d->regs + ADPLL_CLKCTRL_OFFSET);
3618c2ecf20Sopenharmony_ci	v |= BIT(ADPLL_CLKCTRL_IDLE);
3628c2ecf20Sopenharmony_ci	writel_relaxed(v, d->regs + ADPLL_CLKCTRL_OFFSET);
3638c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&d->lock, flags);
3648c2ecf20Sopenharmony_ci}
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_cistatic void ti_adpll_clear_idle_bypass(struct ti_adpll_data *d)
3678c2ecf20Sopenharmony_ci{
3688c2ecf20Sopenharmony_ci	unsigned long flags;
3698c2ecf20Sopenharmony_ci	u32 v;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	spin_lock_irqsave(&d->lock, flags);
3728c2ecf20Sopenharmony_ci	v = readl_relaxed(d->regs + ADPLL_CLKCTRL_OFFSET);
3738c2ecf20Sopenharmony_ci	v &= ~BIT(ADPLL_CLKCTRL_IDLE);
3748c2ecf20Sopenharmony_ci	writel_relaxed(v, d->regs + ADPLL_CLKCTRL_OFFSET);
3758c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&d->lock, flags);
3768c2ecf20Sopenharmony_ci}
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_cistatic bool ti_adpll_clock_is_bypass(struct ti_adpll_data *d)
3798c2ecf20Sopenharmony_ci{
3808c2ecf20Sopenharmony_ci	u32 v;
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	v = readl_relaxed(d->regs + ADPLL_STATUS_OFFSET);
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci	return v & BIT(ADPLL_STATUS_BYPASS);
3858c2ecf20Sopenharmony_ci}
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci/*
3888c2ecf20Sopenharmony_ci * Locked and bypass are not actually mutually exclusive:  if you only care
3898c2ecf20Sopenharmony_ci * about the DCO clock and not CLKOUT you can clear M2PWDNZ before enabling
3908c2ecf20Sopenharmony_ci * the PLL, resulting in status (FREQLOCK | PHASELOCK | BYPASS) after lock.
3918c2ecf20Sopenharmony_ci */
3928c2ecf20Sopenharmony_cistatic bool ti_adpll_is_locked(struct ti_adpll_data *d)
3938c2ecf20Sopenharmony_ci{
3948c2ecf20Sopenharmony_ci	u32 v = readl_relaxed(d->regs + ADPLL_STATUS_OFFSET);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	return (v & ADPLL_STATUS_PREPARED_MASK) == ADPLL_STATUS_PREPARED_MASK;
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_cistatic int ti_adpll_wait_lock(struct ti_adpll_data *d)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	int retries = ADPLL_MAX_RETRIES;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	do {
4048c2ecf20Sopenharmony_ci		if (ti_adpll_is_locked(d))
4058c2ecf20Sopenharmony_ci			return 0;
4068c2ecf20Sopenharmony_ci		usleep_range(200, 300);
4078c2ecf20Sopenharmony_ci	} while (retries--);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	dev_err(d->dev, "pll failed to lock\n");
4108c2ecf20Sopenharmony_ci	return -ETIMEDOUT;
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_cistatic int ti_adpll_prepare(struct clk_hw *hw)
4148c2ecf20Sopenharmony_ci{
4158c2ecf20Sopenharmony_ci	struct ti_adpll_dco_data *dco = to_dco(hw);
4168c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = to_adpll(dco);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	ti_adpll_clear_idle_bypass(d);
4198c2ecf20Sopenharmony_ci	ti_adpll_wait_lock(d);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	return 0;
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_cistatic void ti_adpll_unprepare(struct clk_hw *hw)
4258c2ecf20Sopenharmony_ci{
4268c2ecf20Sopenharmony_ci	struct ti_adpll_dco_data *dco = to_dco(hw);
4278c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = to_adpll(dco);
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	ti_adpll_set_idle_bypass(d);
4308c2ecf20Sopenharmony_ci}
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic int ti_adpll_is_prepared(struct clk_hw *hw)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	struct ti_adpll_dco_data *dco = to_dco(hw);
4358c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = to_adpll(dco);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	return ti_adpll_is_locked(d);
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci/*
4418c2ecf20Sopenharmony_ci * Note that the DCO clock is never subject to bypass: if the PLL is off,
4428c2ecf20Sopenharmony_ci * dcoclk is low.
4438c2ecf20Sopenharmony_ci */
4448c2ecf20Sopenharmony_cistatic unsigned long ti_adpll_recalc_rate(struct clk_hw *hw,
4458c2ecf20Sopenharmony_ci					  unsigned long parent_rate)
4468c2ecf20Sopenharmony_ci{
4478c2ecf20Sopenharmony_ci	struct ti_adpll_dco_data *dco = to_dco(hw);
4488c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = to_adpll(dco);
4498c2ecf20Sopenharmony_ci	u32 frac_m, divider, v;
4508c2ecf20Sopenharmony_ci	u64 rate;
4518c2ecf20Sopenharmony_ci	unsigned long flags;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	if (ti_adpll_clock_is_bypass(d))
4548c2ecf20Sopenharmony_ci		return 0;
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	spin_lock_irqsave(&d->lock, flags);
4578c2ecf20Sopenharmony_ci	frac_m = readl_relaxed(d->regs + ADPLL_FRACDIV_OFFSET);
4588c2ecf20Sopenharmony_ci	frac_m &= ADPLL_FRACDIV_FRACTIONALM_MASK;
4598c2ecf20Sopenharmony_ci	rate = (u64)readw_relaxed(d->regs + ADPLL_MN2DIV_OFFSET) << 18;
4608c2ecf20Sopenharmony_ci	rate += frac_m;
4618c2ecf20Sopenharmony_ci	rate *= parent_rate;
4628c2ecf20Sopenharmony_ci	divider = (readw_relaxed(d->regs + ADPLL_M2NDIV_OFFSET) + 1) << 18;
4638c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&d->lock, flags);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	do_div(rate, divider);
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	if (d->c->is_type_s) {
4688c2ecf20Sopenharmony_ci		v = readl_relaxed(d->regs + ADPLL_CLKCTRL_OFFSET);
4698c2ecf20Sopenharmony_ci		if (v & BIT(ADPLL_CLKCTRL_REGM4XEN_ADPLL_S))
4708c2ecf20Sopenharmony_ci			rate *= 4;
4718c2ecf20Sopenharmony_ci		rate *= 2;
4728c2ecf20Sopenharmony_ci	}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	return rate;
4758c2ecf20Sopenharmony_ci}
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci/* PLL parent is always clkinp, bypass only affects the children */
4788c2ecf20Sopenharmony_cistatic u8 ti_adpll_get_parent(struct clk_hw *hw)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci	return 0;
4818c2ecf20Sopenharmony_ci}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_cistatic const struct clk_ops ti_adpll_ops = {
4848c2ecf20Sopenharmony_ci	.prepare = ti_adpll_prepare,
4858c2ecf20Sopenharmony_ci	.unprepare = ti_adpll_unprepare,
4868c2ecf20Sopenharmony_ci	.is_prepared = ti_adpll_is_prepared,
4878c2ecf20Sopenharmony_ci	.recalc_rate = ti_adpll_recalc_rate,
4888c2ecf20Sopenharmony_ci	.get_parent = ti_adpll_get_parent,
4898c2ecf20Sopenharmony_ci};
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_cistatic int ti_adpll_init_dco(struct ti_adpll_data *d)
4928c2ecf20Sopenharmony_ci{
4938c2ecf20Sopenharmony_ci	struct clk_init_data init;
4948c2ecf20Sopenharmony_ci	struct clk *clock;
4958c2ecf20Sopenharmony_ci	const char *postfix;
4968c2ecf20Sopenharmony_ci	int width, err;
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	d->outputs.clks = devm_kcalloc(d->dev,
4998c2ecf20Sopenharmony_ci				       MAX_ADPLL_OUTPUTS,
5008c2ecf20Sopenharmony_ci				       sizeof(struct clk *),
5018c2ecf20Sopenharmony_ci				       GFP_KERNEL);
5028c2ecf20Sopenharmony_ci	if (!d->outputs.clks)
5038c2ecf20Sopenharmony_ci		return -ENOMEM;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	if (d->c->output_index < 0)
5068c2ecf20Sopenharmony_ci		postfix = "dco";
5078c2ecf20Sopenharmony_ci	else
5088c2ecf20Sopenharmony_ci		postfix = NULL;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	init.name = ti_adpll_clk_get_name(d, d->c->output_index, postfix);
5118c2ecf20Sopenharmony_ci	if (!init.name)
5128c2ecf20Sopenharmony_ci		return -EINVAL;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	init.parent_names = d->parent_names;
5158c2ecf20Sopenharmony_ci	init.num_parents = d->c->nr_max_inputs;
5168c2ecf20Sopenharmony_ci	init.ops = &ti_adpll_ops;
5178c2ecf20Sopenharmony_ci	init.flags = CLK_GET_RATE_NOCACHE;
5188c2ecf20Sopenharmony_ci	d->dco.hw.init = &init;
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci	if (d->c->is_type_s)
5218c2ecf20Sopenharmony_ci		width = 5;
5228c2ecf20Sopenharmony_ci	else
5238c2ecf20Sopenharmony_ci		width = 4;
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci	/* Internal input clock divider N2 */
5268c2ecf20Sopenharmony_ci	err = ti_adpll_init_divider(d, TI_ADPLL_N2, -ENODEV, "n2",
5278c2ecf20Sopenharmony_ci				    d->parent_clocks[TI_ADPLL_CLKINP],
5288c2ecf20Sopenharmony_ci				    d->regs + ADPLL_MN2DIV_OFFSET,
5298c2ecf20Sopenharmony_ci				    ADPLL_MN2DIV_N2, width, 0);
5308c2ecf20Sopenharmony_ci	if (err)
5318c2ecf20Sopenharmony_ci		return err;
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	clock = devm_clk_register(d->dev, &d->dco.hw);
5348c2ecf20Sopenharmony_ci	if (IS_ERR(clock))
5358c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, TI_ADPLL_DCO, d->c->output_index,
5388c2ecf20Sopenharmony_ci				    init.name, NULL);
5398c2ecf20Sopenharmony_ci}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_cistatic int ti_adpll_clkout_enable(struct clk_hw *hw)
5428c2ecf20Sopenharmony_ci{
5438c2ecf20Sopenharmony_ci	struct ti_adpll_clkout_data *co = to_clkout(hw);
5448c2ecf20Sopenharmony_ci	struct clk_hw *gate_hw = &co->gate.hw;
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	__clk_hw_set_clk(gate_hw, hw);
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	return clk_gate_ops.enable(gate_hw);
5498c2ecf20Sopenharmony_ci}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_cistatic void ti_adpll_clkout_disable(struct clk_hw *hw)
5528c2ecf20Sopenharmony_ci{
5538c2ecf20Sopenharmony_ci	struct ti_adpll_clkout_data *co = to_clkout(hw);
5548c2ecf20Sopenharmony_ci	struct clk_hw *gate_hw = &co->gate.hw;
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	__clk_hw_set_clk(gate_hw, hw);
5578c2ecf20Sopenharmony_ci	clk_gate_ops.disable(gate_hw);
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistatic int ti_adpll_clkout_is_enabled(struct clk_hw *hw)
5618c2ecf20Sopenharmony_ci{
5628c2ecf20Sopenharmony_ci	struct ti_adpll_clkout_data *co = to_clkout(hw);
5638c2ecf20Sopenharmony_ci	struct clk_hw *gate_hw = &co->gate.hw;
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	__clk_hw_set_clk(gate_hw, hw);
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_ci	return clk_gate_ops.is_enabled(gate_hw);
5688c2ecf20Sopenharmony_ci}
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci/* Setting PLL bypass puts clkout and clkoutx2 into bypass */
5718c2ecf20Sopenharmony_cistatic u8 ti_adpll_clkout_get_parent(struct clk_hw *hw)
5728c2ecf20Sopenharmony_ci{
5738c2ecf20Sopenharmony_ci	struct ti_adpll_clkout_data *co = to_clkout(hw);
5748c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = co->adpll;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci	return ti_adpll_clock_is_bypass(d);
5778c2ecf20Sopenharmony_ci}
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_cistatic int ti_adpll_init_clkout(struct ti_adpll_data *d,
5808c2ecf20Sopenharmony_ci				enum ti_adpll_clocks index,
5818c2ecf20Sopenharmony_ci				int output_index, int gate_bit,
5828c2ecf20Sopenharmony_ci				char *name, struct clk *clk0,
5838c2ecf20Sopenharmony_ci				struct clk *clk1)
5848c2ecf20Sopenharmony_ci{
5858c2ecf20Sopenharmony_ci	struct ti_adpll_clkout_data *co;
5868c2ecf20Sopenharmony_ci	struct clk_init_data init;
5878c2ecf20Sopenharmony_ci	struct clk_ops *ops;
5888c2ecf20Sopenharmony_ci	const char *parent_names[2];
5898c2ecf20Sopenharmony_ci	const char *child_name;
5908c2ecf20Sopenharmony_ci	struct clk *clock;
5918c2ecf20Sopenharmony_ci	int err;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	co = devm_kzalloc(d->dev, sizeof(*co), GFP_KERNEL);
5948c2ecf20Sopenharmony_ci	if (!co)
5958c2ecf20Sopenharmony_ci		return -ENOMEM;
5968c2ecf20Sopenharmony_ci	co->adpll = d;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	err = of_property_read_string_index(d->np,
5998c2ecf20Sopenharmony_ci					    "clock-output-names",
6008c2ecf20Sopenharmony_ci					    output_index,
6018c2ecf20Sopenharmony_ci					    &child_name);
6028c2ecf20Sopenharmony_ci	if (err)
6038c2ecf20Sopenharmony_ci		return err;
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	ops = devm_kzalloc(d->dev, sizeof(*ops), GFP_KERNEL);
6068c2ecf20Sopenharmony_ci	if (!ops)
6078c2ecf20Sopenharmony_ci		return -ENOMEM;
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	init.name = child_name;
6108c2ecf20Sopenharmony_ci	init.ops = ops;
6118c2ecf20Sopenharmony_ci	init.flags = 0;
6128c2ecf20Sopenharmony_ci	co->hw.init = &init;
6138c2ecf20Sopenharmony_ci	parent_names[0] = __clk_get_name(clk0);
6148c2ecf20Sopenharmony_ci	parent_names[1] = __clk_get_name(clk1);
6158c2ecf20Sopenharmony_ci	init.parent_names = parent_names;
6168c2ecf20Sopenharmony_ci	init.num_parents = 2;
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci	ops->get_parent = ti_adpll_clkout_get_parent;
6198c2ecf20Sopenharmony_ci	ops->determine_rate = __clk_mux_determine_rate;
6208c2ecf20Sopenharmony_ci	if (gate_bit) {
6218c2ecf20Sopenharmony_ci		co->gate.lock = &d->lock;
6228c2ecf20Sopenharmony_ci		co->gate.reg = d->regs + ADPLL_CLKCTRL_OFFSET;
6238c2ecf20Sopenharmony_ci		co->gate.bit_idx = gate_bit;
6248c2ecf20Sopenharmony_ci		ops->enable = ti_adpll_clkout_enable;
6258c2ecf20Sopenharmony_ci		ops->disable = ti_adpll_clkout_disable;
6268c2ecf20Sopenharmony_ci		ops->is_enabled = ti_adpll_clkout_is_enabled;
6278c2ecf20Sopenharmony_ci	}
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	clock = devm_clk_register(d->dev, &co->hw);
6308c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
6318c2ecf20Sopenharmony_ci		dev_err(d->dev, "failed to register output %s: %li\n",
6328c2ecf20Sopenharmony_ci			name, PTR_ERR(clock));
6338c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
6348c2ecf20Sopenharmony_ci	}
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci	return ti_adpll_setup_clock(d, clock, index, output_index, child_name,
6378c2ecf20Sopenharmony_ci				    NULL);
6388c2ecf20Sopenharmony_ci}
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_cistatic int ti_adpll_init_children_adpll_s(struct ti_adpll_data *d)
6418c2ecf20Sopenharmony_ci{
6428c2ecf20Sopenharmony_ci	int err;
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci	if (!d->c->is_type_s)
6458c2ecf20Sopenharmony_ci		return 0;
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci	/* Internal mux, sources from divider N2 or clkinpulow */
6488c2ecf20Sopenharmony_ci	err = ti_adpll_init_mux(d, TI_ADPLL_BYPASS, "bypass",
6498c2ecf20Sopenharmony_ci				d->clocks[TI_ADPLL_N2].clk,
6508c2ecf20Sopenharmony_ci				d->parent_clocks[TI_ADPLL_CLKINPULOW],
6518c2ecf20Sopenharmony_ci				d->regs + ADPLL_CLKCTRL_OFFSET,
6528c2ecf20Sopenharmony_ci				ADPLL_CLKCTRL_ULOWCLKEN);
6538c2ecf20Sopenharmony_ci	if (err)
6548c2ecf20Sopenharmony_ci		return err;
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	/* Internal divider M2, sources DCO */
6578c2ecf20Sopenharmony_ci	err = ti_adpll_init_divider(d, TI_ADPLL_M2, -ENODEV, "m2",
6588c2ecf20Sopenharmony_ci				    d->clocks[TI_ADPLL_DCO].clk,
6598c2ecf20Sopenharmony_ci				    d->regs + ADPLL_M2NDIV_OFFSET,
6608c2ecf20Sopenharmony_ci				    ADPLL_M2NDIV_M2,
6618c2ecf20Sopenharmony_ci				    ADPLL_M2NDIV_M2_ADPLL_S_WIDTH,
6628c2ecf20Sopenharmony_ci				    CLK_DIVIDER_ONE_BASED);
6638c2ecf20Sopenharmony_ci	if (err)
6648c2ecf20Sopenharmony_ci		return err;
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	/* Internal fixed divider, after M2 before clkout */
6678c2ecf20Sopenharmony_ci	err = ti_adpll_init_fixed_factor(d, TI_ADPLL_DIV2, "div2",
6688c2ecf20Sopenharmony_ci					 d->clocks[TI_ADPLL_M2].clk,
6698c2ecf20Sopenharmony_ci					 1, 2);
6708c2ecf20Sopenharmony_ci	if (err)
6718c2ecf20Sopenharmony_ci		return err;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	/* Output clkout with a mux and gate, sources from div2 or bypass */
6748c2ecf20Sopenharmony_ci	err = ti_adpll_init_clkout(d, TI_ADPLL_CLKOUT, TI_ADPLL_S_CLKOUT,
6758c2ecf20Sopenharmony_ci				   ADPLL_CLKCTRL_CLKOUTEN, "clkout",
6768c2ecf20Sopenharmony_ci				   d->clocks[TI_ADPLL_DIV2].clk,
6778c2ecf20Sopenharmony_ci				   d->clocks[TI_ADPLL_BYPASS].clk);
6788c2ecf20Sopenharmony_ci	if (err)
6798c2ecf20Sopenharmony_ci		return err;
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	/* Output clkoutx2 with a mux and gate, sources from M2 or bypass */
6828c2ecf20Sopenharmony_ci	err = ti_adpll_init_clkout(d, TI_ADPLL_CLKOUT2, TI_ADPLL_S_CLKOUTX2, 0,
6838c2ecf20Sopenharmony_ci				   "clkout2", d->clocks[TI_ADPLL_M2].clk,
6848c2ecf20Sopenharmony_ci				   d->clocks[TI_ADPLL_BYPASS].clk);
6858c2ecf20Sopenharmony_ci	if (err)
6868c2ecf20Sopenharmony_ci		return err;
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	/* Internal mux, sources from DCO and clkinphif */
6898c2ecf20Sopenharmony_ci	if (d->parent_clocks[TI_ADPLL_CLKINPHIF]) {
6908c2ecf20Sopenharmony_ci		err = ti_adpll_init_mux(d, TI_ADPLL_HIF, "hif",
6918c2ecf20Sopenharmony_ci					d->clocks[TI_ADPLL_DCO].clk,
6928c2ecf20Sopenharmony_ci					d->parent_clocks[TI_ADPLL_CLKINPHIF],
6938c2ecf20Sopenharmony_ci					d->regs + ADPLL_CLKCTRL_OFFSET,
6948c2ecf20Sopenharmony_ci					ADPLL_CLKINPHIFSEL_ADPLL_S);
6958c2ecf20Sopenharmony_ci		if (err)
6968c2ecf20Sopenharmony_ci			return err;
6978c2ecf20Sopenharmony_ci	}
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	/* Output clkouthif with a divider M3, sources from hif */
7008c2ecf20Sopenharmony_ci	err = ti_adpll_init_divider(d, TI_ADPLL_M3, TI_ADPLL_S_CLKOUTHIF, "m3",
7018c2ecf20Sopenharmony_ci				    d->clocks[TI_ADPLL_HIF].clk,
7028c2ecf20Sopenharmony_ci				    d->regs + ADPLL_M3DIV_OFFSET,
7038c2ecf20Sopenharmony_ci				    ADPLL_M3DIV_M3,
7048c2ecf20Sopenharmony_ci				    ADPLL_M3DIV_M3_WIDTH,
7058c2ecf20Sopenharmony_ci				    CLK_DIVIDER_ONE_BASED);
7068c2ecf20Sopenharmony_ci	if (err)
7078c2ecf20Sopenharmony_ci		return err;
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	/* Output clock dcoclkldo is the DCO */
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	return 0;
7128c2ecf20Sopenharmony_ci}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_cistatic int ti_adpll_init_children_adpll_lj(struct ti_adpll_data *d)
7158c2ecf20Sopenharmony_ci{
7168c2ecf20Sopenharmony_ci	int err;
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	if (d->c->is_type_s)
7198c2ecf20Sopenharmony_ci		return 0;
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	/* Output clkdcoldo, gated output of DCO */
7228c2ecf20Sopenharmony_ci	err = ti_adpll_init_gate(d, TI_ADPLL_DCO_GATE, TI_ADPLL_LJ_CLKDCOLDO,
7238c2ecf20Sopenharmony_ci				 "clkdcoldo", d->clocks[TI_ADPLL_DCO].clk,
7248c2ecf20Sopenharmony_ci				 d->regs + ADPLL_CLKCTRL_OFFSET,
7258c2ecf20Sopenharmony_ci				 ADPLL_CLKCTRL_CLKDCOLDOEN, 0);
7268c2ecf20Sopenharmony_ci	if (err)
7278c2ecf20Sopenharmony_ci		return err;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	/* Internal divider M2, sources from DCO */
7308c2ecf20Sopenharmony_ci	err = ti_adpll_init_divider(d, TI_ADPLL_M2, -ENODEV,
7318c2ecf20Sopenharmony_ci				    "m2", d->clocks[TI_ADPLL_DCO].clk,
7328c2ecf20Sopenharmony_ci				    d->regs + ADPLL_M2NDIV_OFFSET,
7338c2ecf20Sopenharmony_ci				    ADPLL_M2NDIV_M2,
7348c2ecf20Sopenharmony_ci				    ADPLL_M2NDIV_M2_ADPLL_LJ_WIDTH,
7358c2ecf20Sopenharmony_ci				    CLK_DIVIDER_ONE_BASED);
7368c2ecf20Sopenharmony_ci	if (err)
7378c2ecf20Sopenharmony_ci		return err;
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	/* Output clkoutldo, gated output of M2 */
7408c2ecf20Sopenharmony_ci	err = ti_adpll_init_gate(d, TI_ADPLL_M2_GATE, TI_ADPLL_LJ_CLKOUTLDO,
7418c2ecf20Sopenharmony_ci				 "clkoutldo", d->clocks[TI_ADPLL_M2].clk,
7428c2ecf20Sopenharmony_ci				 d->regs + ADPLL_CLKCTRL_OFFSET,
7438c2ecf20Sopenharmony_ci				 ADPLL_CLKCTRL_CLKOUTLDOEN_ADPLL_LJ,
7448c2ecf20Sopenharmony_ci				 0);
7458c2ecf20Sopenharmony_ci	if (err)
7468c2ecf20Sopenharmony_ci		return err;
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	/* Internal mux, sources from divider N2 or clkinpulow */
7498c2ecf20Sopenharmony_ci	err = ti_adpll_init_mux(d, TI_ADPLL_BYPASS, "bypass",
7508c2ecf20Sopenharmony_ci				d->clocks[TI_ADPLL_N2].clk,
7518c2ecf20Sopenharmony_ci				d->parent_clocks[TI_ADPLL_CLKINPULOW],
7528c2ecf20Sopenharmony_ci				d->regs + ADPLL_CLKCTRL_OFFSET,
7538c2ecf20Sopenharmony_ci				ADPLL_CLKCTRL_ULOWCLKEN);
7548c2ecf20Sopenharmony_ci	if (err)
7558c2ecf20Sopenharmony_ci		return err;
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	/* Output clkout, sources M2 or bypass */
7588c2ecf20Sopenharmony_ci	err = ti_adpll_init_clkout(d, TI_ADPLL_CLKOUT, TI_ADPLL_S_CLKOUT,
7598c2ecf20Sopenharmony_ci				   ADPLL_CLKCTRL_CLKOUTEN, "clkout",
7608c2ecf20Sopenharmony_ci				   d->clocks[TI_ADPLL_M2].clk,
7618c2ecf20Sopenharmony_ci				   d->clocks[TI_ADPLL_BYPASS].clk);
7628c2ecf20Sopenharmony_ci	if (err)
7638c2ecf20Sopenharmony_ci		return err;
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci	return 0;
7668c2ecf20Sopenharmony_ci}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_cistatic void ti_adpll_free_resources(struct ti_adpll_data *d)
7698c2ecf20Sopenharmony_ci{
7708c2ecf20Sopenharmony_ci	int i;
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	for (i = TI_ADPLL_M3; i >= 0; i--) {
7738c2ecf20Sopenharmony_ci		struct ti_adpll_clock *ac = &d->clocks[i];
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci		if (!ac || IS_ERR_OR_NULL(ac->clk))
7768c2ecf20Sopenharmony_ci			continue;
7778c2ecf20Sopenharmony_ci		if (ac->cl)
7788c2ecf20Sopenharmony_ci			clkdev_drop(ac->cl);
7798c2ecf20Sopenharmony_ci		if (ac->unregister)
7808c2ecf20Sopenharmony_ci			ac->unregister(ac->clk);
7818c2ecf20Sopenharmony_ci	}
7828c2ecf20Sopenharmony_ci}
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci/* MPU PLL manages the lock register for all PLLs */
7858c2ecf20Sopenharmony_cistatic void ti_adpll_unlock_all(void __iomem *reg)
7868c2ecf20Sopenharmony_ci{
7878c2ecf20Sopenharmony_ci	u32 v;
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	v = readl_relaxed(reg);
7908c2ecf20Sopenharmony_ci	if (v == ADPLL_PLLSS_MMR_LOCK_ENABLED)
7918c2ecf20Sopenharmony_ci		writel_relaxed(ADPLL_PLLSS_MMR_UNLOCK_MAGIC, reg);
7928c2ecf20Sopenharmony_ci}
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_cistatic int ti_adpll_init_registers(struct ti_adpll_data *d)
7958c2ecf20Sopenharmony_ci{
7968c2ecf20Sopenharmony_ci	int register_offset = 0;
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	if (d->c->is_type_s) {
7998c2ecf20Sopenharmony_ci		register_offset = 8;
8008c2ecf20Sopenharmony_ci		ti_adpll_unlock_all(d->iobase + ADPLL_PLLSS_MMR_LOCK_OFFSET);
8018c2ecf20Sopenharmony_ci	}
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ci	d->regs = d->iobase + register_offset + ADPLL_PWRCTRL_OFFSET;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	return 0;
8068c2ecf20Sopenharmony_ci}
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_cistatic int ti_adpll_init_inputs(struct ti_adpll_data *d)
8098c2ecf20Sopenharmony_ci{
8108c2ecf20Sopenharmony_ci	const char *error = "need at least %i inputs";
8118c2ecf20Sopenharmony_ci	struct clk *clock;
8128c2ecf20Sopenharmony_ci	int nr_inputs;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	nr_inputs = of_clk_get_parent_count(d->np);
8158c2ecf20Sopenharmony_ci	if (nr_inputs < d->c->nr_max_inputs) {
8168c2ecf20Sopenharmony_ci		dev_err(d->dev, error, nr_inputs);
8178c2ecf20Sopenharmony_ci		return -EINVAL;
8188c2ecf20Sopenharmony_ci	}
8198c2ecf20Sopenharmony_ci	of_clk_parent_fill(d->np, d->parent_names, nr_inputs);
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	clock = devm_clk_get(d->dev, d->parent_names[0]);
8228c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
8238c2ecf20Sopenharmony_ci		dev_err(d->dev, "could not get clkinp\n");
8248c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
8258c2ecf20Sopenharmony_ci	}
8268c2ecf20Sopenharmony_ci	d->parent_clocks[TI_ADPLL_CLKINP] = clock;
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	clock = devm_clk_get(d->dev, d->parent_names[1]);
8298c2ecf20Sopenharmony_ci	if (IS_ERR(clock)) {
8308c2ecf20Sopenharmony_ci		dev_err(d->dev, "could not get clkinpulow clock\n");
8318c2ecf20Sopenharmony_ci		return PTR_ERR(clock);
8328c2ecf20Sopenharmony_ci	}
8338c2ecf20Sopenharmony_ci	d->parent_clocks[TI_ADPLL_CLKINPULOW] = clock;
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci	if (d->c->is_type_s) {
8368c2ecf20Sopenharmony_ci		clock =  devm_clk_get(d->dev, d->parent_names[2]);
8378c2ecf20Sopenharmony_ci		if (IS_ERR(clock)) {
8388c2ecf20Sopenharmony_ci			dev_err(d->dev, "could not get clkinphif clock\n");
8398c2ecf20Sopenharmony_ci			return PTR_ERR(clock);
8408c2ecf20Sopenharmony_ci		}
8418c2ecf20Sopenharmony_ci		d->parent_clocks[TI_ADPLL_CLKINPHIF] = clock;
8428c2ecf20Sopenharmony_ci	}
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	return 0;
8458c2ecf20Sopenharmony_ci}
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_cistatic const struct ti_adpll_platform_data ti_adpll_type_s = {
8488c2ecf20Sopenharmony_ci	.is_type_s = true,
8498c2ecf20Sopenharmony_ci	.nr_max_inputs = MAX_ADPLL_INPUTS,
8508c2ecf20Sopenharmony_ci	.nr_max_outputs = MAX_ADPLL_OUTPUTS,
8518c2ecf20Sopenharmony_ci	.output_index = TI_ADPLL_S_DCOCLKLDO,
8528c2ecf20Sopenharmony_ci};
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_cistatic const struct ti_adpll_platform_data ti_adpll_type_lj = {
8558c2ecf20Sopenharmony_ci	.is_type_s = false,
8568c2ecf20Sopenharmony_ci	.nr_max_inputs = MAX_ADPLL_INPUTS - 1,
8578c2ecf20Sopenharmony_ci	.nr_max_outputs = MAX_ADPLL_OUTPUTS - 1,
8588c2ecf20Sopenharmony_ci	.output_index = -EINVAL,
8598c2ecf20Sopenharmony_ci};
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_cistatic const struct of_device_id ti_adpll_match[] = {
8628c2ecf20Sopenharmony_ci	{ .compatible = "ti,dm814-adpll-s-clock", &ti_adpll_type_s },
8638c2ecf20Sopenharmony_ci	{ .compatible = "ti,dm814-adpll-lj-clock", &ti_adpll_type_lj },
8648c2ecf20Sopenharmony_ci	{},
8658c2ecf20Sopenharmony_ci};
8668c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, ti_adpll_match);
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_cistatic int ti_adpll_probe(struct platform_device *pdev)
8698c2ecf20Sopenharmony_ci{
8708c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
8718c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
8728c2ecf20Sopenharmony_ci	const struct of_device_id *match;
8738c2ecf20Sopenharmony_ci	const struct ti_adpll_platform_data *pdata;
8748c2ecf20Sopenharmony_ci	struct ti_adpll_data *d;
8758c2ecf20Sopenharmony_ci	struct resource *res;
8768c2ecf20Sopenharmony_ci	int err;
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	match = of_match_device(ti_adpll_match, dev);
8798c2ecf20Sopenharmony_ci	if (match)
8808c2ecf20Sopenharmony_ci		pdata = match->data;
8818c2ecf20Sopenharmony_ci	else
8828c2ecf20Sopenharmony_ci		return -ENODEV;
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci	d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
8858c2ecf20Sopenharmony_ci	if (!d)
8868c2ecf20Sopenharmony_ci		return -ENOMEM;
8878c2ecf20Sopenharmony_ci	d->dev = dev;
8888c2ecf20Sopenharmony_ci	d->np = node;
8898c2ecf20Sopenharmony_ci	d->c = pdata;
8908c2ecf20Sopenharmony_ci	dev_set_drvdata(d->dev, d);
8918c2ecf20Sopenharmony_ci	spin_lock_init(&d->lock);
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_ci	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8948c2ecf20Sopenharmony_ci	if (!res)
8958c2ecf20Sopenharmony_ci		return -ENODEV;
8968c2ecf20Sopenharmony_ci	d->pa = res->start;
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_ci	d->iobase = devm_ioremap_resource(dev, res);
8998c2ecf20Sopenharmony_ci	if (IS_ERR(d->iobase)) {
9008c2ecf20Sopenharmony_ci		dev_err(dev, "could not get IO base: %li\n",
9018c2ecf20Sopenharmony_ci			PTR_ERR(d->iobase));
9028c2ecf20Sopenharmony_ci		return PTR_ERR(d->iobase);
9038c2ecf20Sopenharmony_ci	}
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci	err = ti_adpll_init_registers(d);
9068c2ecf20Sopenharmony_ci	if (err)
9078c2ecf20Sopenharmony_ci		return err;
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	err = ti_adpll_init_inputs(d);
9108c2ecf20Sopenharmony_ci	if (err)
9118c2ecf20Sopenharmony_ci		return err;
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci	d->clocks = devm_kcalloc(d->dev,
9148c2ecf20Sopenharmony_ci				 TI_ADPLL_NR_CLOCKS,
9158c2ecf20Sopenharmony_ci				 sizeof(struct ti_adpll_clock),
9168c2ecf20Sopenharmony_ci				 GFP_KERNEL);
9178c2ecf20Sopenharmony_ci	if (!d->clocks)
9188c2ecf20Sopenharmony_ci		return -ENOMEM;
9198c2ecf20Sopenharmony_ci
9208c2ecf20Sopenharmony_ci	err = ti_adpll_init_dco(d);
9218c2ecf20Sopenharmony_ci	if (err) {
9228c2ecf20Sopenharmony_ci		dev_err(dev, "could not register dco: %i\n", err);
9238c2ecf20Sopenharmony_ci		goto free;
9248c2ecf20Sopenharmony_ci	}
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	err = ti_adpll_init_children_adpll_s(d);
9278c2ecf20Sopenharmony_ci	if (err)
9288c2ecf20Sopenharmony_ci		goto free;
9298c2ecf20Sopenharmony_ci	err = ti_adpll_init_children_adpll_lj(d);
9308c2ecf20Sopenharmony_ci	if (err)
9318c2ecf20Sopenharmony_ci		goto free;
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	err = of_clk_add_provider(d->np, of_clk_src_onecell_get, &d->outputs);
9348c2ecf20Sopenharmony_ci	if (err)
9358c2ecf20Sopenharmony_ci		goto free;
9368c2ecf20Sopenharmony_ci
9378c2ecf20Sopenharmony_ci	return 0;
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_cifree:
9408c2ecf20Sopenharmony_ci	WARN_ON(1);
9418c2ecf20Sopenharmony_ci	ti_adpll_free_resources(d);
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci	return err;
9448c2ecf20Sopenharmony_ci}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_cistatic int ti_adpll_remove(struct platform_device *pdev)
9478c2ecf20Sopenharmony_ci{
9488c2ecf20Sopenharmony_ci	struct ti_adpll_data *d = dev_get_drvdata(&pdev->dev);
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_ci	ti_adpll_free_resources(d);
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	return 0;
9538c2ecf20Sopenharmony_ci}
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_cistatic struct platform_driver ti_adpll_driver = {
9568c2ecf20Sopenharmony_ci	.driver = {
9578c2ecf20Sopenharmony_ci		.name = "ti-adpll",
9588c2ecf20Sopenharmony_ci		.of_match_table = ti_adpll_match,
9598c2ecf20Sopenharmony_ci	},
9608c2ecf20Sopenharmony_ci	.probe = ti_adpll_probe,
9618c2ecf20Sopenharmony_ci	.remove = ti_adpll_remove,
9628c2ecf20Sopenharmony_ci};
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_cistatic int __init ti_adpll_init(void)
9658c2ecf20Sopenharmony_ci{
9668c2ecf20Sopenharmony_ci	return platform_driver_register(&ti_adpll_driver);
9678c2ecf20Sopenharmony_ci}
9688c2ecf20Sopenharmony_cicore_initcall(ti_adpll_init);
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_cistatic void __exit ti_adpll_exit(void)
9718c2ecf20Sopenharmony_ci{
9728c2ecf20Sopenharmony_ci	platform_driver_unregister(&ti_adpll_driver);
9738c2ecf20Sopenharmony_ci}
9748c2ecf20Sopenharmony_cimodule_exit(ti_adpll_exit);
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Clock driver for dm814x ADPLL");
9778c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:dm814-adpll-clock");
9788c2ecf20Sopenharmony_ciMODULE_AUTHOR("Tony LIndgren <tony@atomide.com>");
9798c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
980