xref: /linux/drivers/clk/sunxi/clk-factors.h (revision 9919d44f)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2e874a669SEmilio López #ifndef __MACH_SUNXI_CLK_FACTORS_H
3e874a669SEmilio López #define __MACH_SUNXI_CLK_FACTORS_H
4e874a669SEmilio López 
5e874a669SEmilio López #include <linux/clk-provider.h>
6601da9d0SMaxime Ripard #include <linux/spinlock.h>
7e874a669SEmilio López 
8e874a669SEmilio López #define SUNXI_FACTORS_NOT_APPLICABLE	(0)
9e874a669SEmilio López 
10e874a669SEmilio López struct clk_factors_config {
11e874a669SEmilio López 	u8 nshift;
12e874a669SEmilio López 	u8 nwidth;
13e874a669SEmilio López 	u8 kshift;
14e874a669SEmilio López 	u8 kwidth;
15e874a669SEmilio López 	u8 mshift;
16e874a669SEmilio López 	u8 mwidth;
17e874a669SEmilio López 	u8 pshift;
18e874a669SEmilio López 	u8 pwidth;
199a5e6c7eSChen-Yu Tsai 	u8 n_start;
20e874a669SEmilio López };
21e874a669SEmilio López 
22cfa63688SChen-Yu Tsai struct factors_request {
23cfa63688SChen-Yu Tsai 	unsigned long rate;
24cfa63688SChen-Yu Tsai 	unsigned long parent_rate;
25435b7be1SChen-Yu Tsai 	u8 parent_index;
26cfa63688SChen-Yu Tsai 	u8 n;
27cfa63688SChen-Yu Tsai 	u8 k;
28cfa63688SChen-Yu Tsai 	u8 m;
29cfa63688SChen-Yu Tsai 	u8 p;
30cfa63688SChen-Yu Tsai };
31cfa63688SChen-Yu Tsai 
32601da9d0SMaxime Ripard struct factors_data {
33601da9d0SMaxime Ripard 	int enable;
34601da9d0SMaxime Ripard 	int mux;
35e94f8cb3SChen-Yu Tsai 	int muxmask;
36b3e919e0SChen-Yu Tsai 	const struct clk_factors_config *table;
37cfa63688SChen-Yu Tsai 	void (*getter)(struct factors_request *req);
38435b7be1SChen-Yu Tsai 	void (*recalc)(struct factors_request *req);
39601da9d0SMaxime Ripard 	const char *name;
40601da9d0SMaxime Ripard };
41601da9d0SMaxime Ripard 
4240a5dcbaSEmilio López struct clk_factors {
4340a5dcbaSEmilio López 	struct clk_hw hw;
4440a5dcbaSEmilio López 	void __iomem *reg;
45b3e919e0SChen-Yu Tsai 	const struct clk_factors_config *config;
46cfa63688SChen-Yu Tsai 	void (*get_factors)(struct factors_request *req);
47435b7be1SChen-Yu Tsai 	void (*recalc)(struct factors_request *req);
4840a5dcbaSEmilio López 	spinlock_t *lock;
494cbeaebbSChen-Yu Tsai 	/* for cleanup */
504cbeaebbSChen-Yu Tsai 	struct clk_mux *mux;
514cbeaebbSChen-Yu Tsai 	struct clk_gate *gate;
5240a5dcbaSEmilio López };
5340a5dcbaSEmilio López 
547c74c220SHans de Goede struct clk *sunxi_factors_register(struct device_node *node,
55601da9d0SMaxime Ripard 				   const struct factors_data *data,
567c74c220SHans de Goede 				   spinlock_t *lock,
577c74c220SHans de Goede 				   void __iomem *reg);
58*9919d44fSStephen Boyd struct clk *sunxi_factors_register_critical(struct device_node *node,
59*9919d44fSStephen Boyd 					    const struct factors_data *data,
60*9919d44fSStephen Boyd 					    spinlock_t *lock,
61*9919d44fSStephen Boyd 					    void __iomem *reg);
62601da9d0SMaxime Ripard 
634cbeaebbSChen-Yu Tsai void sunxi_factors_unregister(struct device_node *node, struct clk *clk);
644cbeaebbSChen-Yu Tsai 
65e874a669SEmilio López #endif
66