blob: 1e63c5b2d5f4cb6866127100be2274a7095641cd [file] [log] [blame]
Emilio Lópeze874a662013-02-25 11:44:26 -03001#ifndef __MACH_SUNXI_CLK_FACTORS_H
2#define __MACH_SUNXI_CLK_FACTORS_H
3
4#include <linux/clk-provider.h>
Maxime Ripard601da9d2014-07-04 22:24:52 +02005#include <linux/spinlock.h>
Emilio Lópeze874a662013-02-25 11:44:26 -03006
7#define SUNXI_FACTORS_NOT_APPLICABLE (0)
8
9struct clk_factors_config {
10 u8 nshift;
11 u8 nwidth;
12 u8 kshift;
13 u8 kwidth;
14 u8 mshift;
15 u8 mwidth;
16 u8 pshift;
17 u8 pwidth;
Chen-Yu Tsai9a5e6c72014-06-26 23:55:41 +080018 u8 n_start;
Emilio Lópeze874a662013-02-25 11:44:26 -030019};
20
Chen-Yu Tsaicfa636882016-01-25 21:15:42 +080021struct factors_request {
22 unsigned long rate;
23 unsigned long parent_rate;
Chen-Yu Tsai435b7be2016-01-25 21:15:43 +080024 u8 parent_index;
Chen-Yu Tsaicfa636882016-01-25 21:15:42 +080025 u8 n;
26 u8 k;
27 u8 m;
28 u8 p;
29};
30
Maxime Ripard601da9d2014-07-04 22:24:52 +020031struct factors_data {
32 int enable;
33 int mux;
Chen-Yu Tsaie94f8cb32014-10-20 22:10:26 +080034 int muxmask;
Chen-Yu Tsaib3e919e2016-01-25 21:15:38 +080035 const struct clk_factors_config *table;
Chen-Yu Tsaicfa636882016-01-25 21:15:42 +080036 void (*getter)(struct factors_request *req);
Chen-Yu Tsai435b7be2016-01-25 21:15:43 +080037 void (*recalc)(struct factors_request *req);
Maxime Ripard601da9d2014-07-04 22:24:52 +020038 const char *name;
39};
40
Emilio López40a5dcb2013-12-23 00:32:32 -030041struct clk_factors {
42 struct clk_hw hw;
43 void __iomem *reg;
Chen-Yu Tsaib3e919e2016-01-25 21:15:38 +080044 const struct clk_factors_config *config;
Chen-Yu Tsaicfa636882016-01-25 21:15:42 +080045 void (*get_factors)(struct factors_request *req);
Chen-Yu Tsai435b7be2016-01-25 21:15:43 +080046 void (*recalc)(struct factors_request *req);
Emilio López40a5dcb2013-12-23 00:32:32 -030047 spinlock_t *lock;
Chen-Yu Tsai4cbeaeb2016-01-25 21:15:40 +080048 /* for cleanup */
49 struct clk_mux *mux;
50 struct clk_gate *gate;
Emilio López40a5dcb2013-12-23 00:32:32 -030051};
52
Hans de Goede7c74c222014-11-23 14:38:07 +010053struct clk *sunxi_factors_register(struct device_node *node,
54 const struct factors_data *data,
55 spinlock_t *lock,
56 void __iomem *reg);
Maxime Ripard601da9d2014-07-04 22:24:52 +020057
Chen-Yu Tsai4cbeaeb2016-01-25 21:15:40 +080058void sunxi_factors_unregister(struct device_node *node, struct clk *clk);
59
Emilio Lópeze874a662013-02-25 11:44:26 -030060#endif