blob: 4b7abec27558da2a700fcb88d9bf481e93ae551f [file] [log] [blame]
Shefali Jain0dc6e782017-11-27 13:06:27 +05301/*
2 * Copyright (c) 2014, 2017, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef __ARCH_ARM_MSM_CLOCK_CONTROLLER_H
16#define __ARCH_ARM_MSM_CLOCK_CONTROLLER_H
17
18#include <linux/list.h>
19#include <linux/clkdev.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22
23#define dt_err(np, fmt, ...) \
24 pr_err("%s: " fmt, np->name, ##__VA_ARGS__)
25#define dt_prop_err(np, str, fmt, ...) \
26 dt_err(np, "%s: " fmt, str, ##__VA_ARGS__)
27
28/**
29 * struct msmclk_parser
30 * @compatible
31 * matches compatible property from devicetree
32 * @parsedt
33 * constructs & returns an instance of the appropriate obj based on
34 * the data from devicetree.
35 */
36struct msmclk_parser {
37 struct list_head list;
38 char *compatible;
39 void * (*parsedt)(struct device *dev, struct device_node *of);
40};
41
42#define MSMCLK_PARSER(fn, str, id) \
43static struct msmclk_parser _msmclk_##fn##id = { \
44 .list = LIST_HEAD_INIT(_msmclk_##fn##id.list), \
45 .compatible = str, \
46 .parsedt = fn, \
47}; \
48static int __init _msmclk_init_##fn##id(void) \
49{ \
50 msmclk_parser_register(&_msmclk_##fn##id); \
51 return 0; \
52} \
53early_initcall(_msmclk_init_##fn##id)
54
55/*
56 * struct msmclk_data
57 * @base
58 * ioremapped region for sub_devices
59 * @list
60 * tracks all registered driver instances
61 * @htable
62 * tracks all registered child clocks
63 * @clk_tbl
64 * array of clk_lookup to be registered with the clock framework
65 */
66#define HASHTABLE_SIZE 200
67struct msmclk_data {
68 void __iomem *base;
69 struct device *dev;
70 struct list_head list;
71 struct hlist_head htable[HASHTABLE_SIZE];
72 struct clk_lookup *clk_tbl;
73 int clk_tbl_size;
74 int max_clk_tbl_size;
75};
76
77#if defined(CONFIG_MSM_CLK_CONTROLLER_V2)
78
79/* Utility functions */
80int of_property_count_phandles(struct device_node *np, char *propname);
81int of_property_read_phandle_index(struct device_node *np, char *propname,
82 int index, phandle *p);
83void *msmclk_generic_clk_init(struct device *dev, struct device_node *np,
84 struct clk *c);
85
86/*
87 * msmclk_parser_register
88 * Registers a parser which will be matched with a node from dt
89 * according to the compatible string.
90 */
91void msmclk_parser_register(struct msmclk_parser *p);
92
93/*
94 * msmclk_parse_phandle
95 * On hashtable miss, the corresponding entry will be retrieved from
96 * devicetree, and added to the hashtable.
97 */
98void *msmclk_parse_phandle(struct device *dev, phandle key);
99/*
100 * msmclk_lookup_phandle
101 * Straightforward hashtable lookup
102 */
103void *msmclk_lookup_phandle(struct device *dev, phandle key);
104
105int __init msmclk_init(void);
106#else
107
108static inline int of_property_count_phandles(struct device_node *np,
109 char *propname)
110{
111 return 0;
112}
113
114static inline int of_property_read_phandle_index(struct device_node *np,
115 char *propname, int index, phandle *p)
116{
117 return 0;
118}
119
120static inline void *msmclk_generic_clk_init(struct device *dev,
121 struct device_node *np, struct clk *c)
122{
123 return ERR_PTR(-EINVAL);
124}
125
126static inline void msmclk_parser_register(struct msmclk_parser *p) {};
127
128static inline void *msmclk_parse_phandle(struct device *dev, phandle key)
129{
130 return ERR_PTR(-EINVAL);
131}
132
133static inline void *msmclk_lookup_phandle(struct device *dev, phandle key)
134{
135 return ERR_PTR(-EINVAL);
136}
137
138static inline int __init msmclk_init(void)
139{
140 return 0;
141}
142
143#endif /* CONFIG_MSM_CLK_CONTROLLER_V2 */
144#endif /* __ARCH_ARM_MSM_CLOCK_CONTROLLER_H */