xref: /linux/drivers/clk/davinci/psc.h (revision c2952e271b94f805e8cb73d18e50394689cae508)
1c6ed4d73SDavid Lechner // SPDX-License-Identifier: GPL-2.0
2c6ed4d73SDavid Lechner /*
3c6ed4d73SDavid Lechner  * Clock driver for TI Davinci PSC controllers
4c6ed4d73SDavid Lechner  *
5c6ed4d73SDavid Lechner  * Copyright (C) 2018 David Lechner <david@lechnology.com>
6c6ed4d73SDavid Lechner  */
7c6ed4d73SDavid Lechner 
8c6ed4d73SDavid Lechner #ifndef __CLK_DAVINCI_PSC_H__
9c6ed4d73SDavid Lechner #define __CLK_DAVINCI_PSC_H__
10c6ed4d73SDavid Lechner 
11c6ed4d73SDavid Lechner #include <linux/clk-provider.h>
12c6ed4d73SDavid Lechner #include <linux/types.h>
13c6ed4d73SDavid Lechner 
14c6ed4d73SDavid Lechner /* PSC quirk flags */
15c6ed4d73SDavid Lechner #define LPSC_ALWAYS_ENABLED	BIT(0) /* never disable this clock */
16c6ed4d73SDavid Lechner #define LPSC_SET_RATE_PARENT	BIT(1) /* propagate set_rate to parent clock */
17c6ed4d73SDavid Lechner #define LPSC_FORCE		BIT(2) /* requires MDCTL FORCE bit */
18c6ed4d73SDavid Lechner #define LPSC_LOCAL_RESET	BIT(3) /* acts as reset provider */
19c6ed4d73SDavid Lechner 
20c6ed4d73SDavid Lechner struct davinci_lpsc_clkdev_info {
21c6ed4d73SDavid Lechner 	const char *con_id;
22c6ed4d73SDavid Lechner 	const char *dev_id;
23c6ed4d73SDavid Lechner };
24c6ed4d73SDavid Lechner 
25c6ed4d73SDavid Lechner #define LPSC_CLKDEV(c, d) {	\
26c6ed4d73SDavid Lechner 	.con_id = (c),		\
27c6ed4d73SDavid Lechner 	.dev_id = (d)		\
28c6ed4d73SDavid Lechner }
29c6ed4d73SDavid Lechner 
30c6ed4d73SDavid Lechner #define LPSC_CLKDEV1(n, c, d) \
31c6ed4d73SDavid Lechner static const struct davinci_lpsc_clkdev_info n[] __initconst = {	\
32c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c), (d)),						\
33c6ed4d73SDavid Lechner 	{ }								\
34c6ed4d73SDavid Lechner }
35c6ed4d73SDavid Lechner 
36c6ed4d73SDavid Lechner #define LPSC_CLKDEV2(n, c1, d1, c2, d2) \
37c6ed4d73SDavid Lechner static const struct davinci_lpsc_clkdev_info n[] __initconst = {	\
38c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c1), (d1)),					\
39c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c2), (d2)),					\
40c6ed4d73SDavid Lechner 	{ }								\
41c6ed4d73SDavid Lechner }
42c6ed4d73SDavid Lechner 
43c6ed4d73SDavid Lechner #define LPSC_CLKDEV3(n, c1, d1, c2, d2, c3, d3) \
44c6ed4d73SDavid Lechner static const struct davinci_lpsc_clkdev_info n[] __initconst = {	\
45c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c1), (d1)),					\
46c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c2), (d2)),					\
47c6ed4d73SDavid Lechner 	LPSC_CLKDEV((c3), (d3)),					\
48c6ed4d73SDavid Lechner 	{ }								\
49c6ed4d73SDavid Lechner }
50c6ed4d73SDavid Lechner 
51c6ed4d73SDavid Lechner /**
52c6ed4d73SDavid Lechner  * davinci_lpsc_clk_info - LPSC module-specific clock information
53c6ed4d73SDavid Lechner  * @name: the clock name
54c6ed4d73SDavid Lechner  * @parent: the parent clock name
55c6ed4d73SDavid Lechner  * @cdevs: optional array of clkdev lookup table info
56c6ed4d73SDavid Lechner  * @md: the local module domain (LPSC id)
57c6ed4d73SDavid Lechner  * @pd: the power domain id
58c6ed4d73SDavid Lechner  * @flags: bitmask of LPSC_* flags
59c6ed4d73SDavid Lechner  */
60c6ed4d73SDavid Lechner struct davinci_lpsc_clk_info {
61c6ed4d73SDavid Lechner 	const char *name;
62c6ed4d73SDavid Lechner 	const char *parent;
63c6ed4d73SDavid Lechner 	const struct davinci_lpsc_clkdev_info *cdevs;
64c6ed4d73SDavid Lechner 	u32 md;
65c6ed4d73SDavid Lechner 	u32 pd;
66c6ed4d73SDavid Lechner 	unsigned long flags;
67c6ed4d73SDavid Lechner };
68c6ed4d73SDavid Lechner 
69c6ed4d73SDavid Lechner #define LPSC(m, d, n, p, c, f)	\
70c6ed4d73SDavid Lechner {				\
71c6ed4d73SDavid Lechner 	.name	= #n,		\
72c6ed4d73SDavid Lechner 	.parent	= #p,		\
73c6ed4d73SDavid Lechner 	.cdevs	= (c),		\
74c6ed4d73SDavid Lechner 	.md	= (m),		\
75c6ed4d73SDavid Lechner 	.pd	= (d),		\
76c6ed4d73SDavid Lechner 	.flags	= (f),		\
77c6ed4d73SDavid Lechner }
78c6ed4d73SDavid Lechner 
79c6ed4d73SDavid Lechner int davinci_psc_register_clocks(struct device *dev,
80c6ed4d73SDavid Lechner 				const struct davinci_lpsc_clk_info *info,
81c6ed4d73SDavid Lechner 				u8 num_clks,
82c6ed4d73SDavid Lechner 				void __iomem *base);
83c6ed4d73SDavid Lechner 
84c6ed4d73SDavid Lechner int of_davinci_psc_clk_init(struct device *dev,
85c6ed4d73SDavid Lechner 			    const struct davinci_lpsc_clk_info *info,
86c6ed4d73SDavid Lechner 			    u8 num_clks,
87c6ed4d73SDavid Lechner 			    void __iomem *base);
88c6ed4d73SDavid Lechner 
89c6ed4d73SDavid Lechner /* Device-specific data */
90c6ed4d73SDavid Lechner 
91c6ed4d73SDavid Lechner struct davinci_psc_init_data {
92c6ed4d73SDavid Lechner 	struct clk_bulk_data *parent_clks;
93c6ed4d73SDavid Lechner 	int num_parent_clks;
94c6ed4d73SDavid Lechner 	int (*psc_init)(struct device *dev, void __iomem *base);
95c6ed4d73SDavid Lechner };
96c6ed4d73SDavid Lechner 
97*c2952e27SDavid Lechner extern const struct davinci_psc_init_data da830_psc0_init_data;
98*c2952e27SDavid Lechner extern const struct davinci_psc_init_data da830_psc1_init_data;
99*c2952e27SDavid Lechner 
100c6ed4d73SDavid Lechner #endif /* __CLK_DAVINCI_PSC_H__ */
101