Commit | Line | Data |
---|---|---|
f59d3ee8 VK |
1 | /* |
2 | * Generic OPP Interface | |
3 | * | |
4 | * Copyright (C) 2009-2010 Texas Instruments Incorporated. | |
5 | * Nishanth Menon | |
6 | * Romit Dasgupta | |
7 | * Kevin Hilman | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #ifndef __DRIVER_OPP_H__ | |
15 | #define __DRIVER_OPP_H__ | |
16 | ||
17 | #include <linux/device.h> | |
18 | #include <linux/kernel.h> | |
19 | #include <linux/list.h> | |
20 | #include <linux/pm_opp.h> | |
21 | #include <linux/rculist.h> | |
22 | #include <linux/rcupdate.h> | |
23 | ||
24 | /* | |
25 | * Internal data structure organization with the OPP layer library is as | |
26 | * follows: | |
27 | * dev_opp_list (root) | |
28 | * |- device 1 (represents voltage domain 1) | |
29 | * | |- opp 1 (availability, freq, voltage) | |
30 | * | |- opp 2 .. | |
31 | * ... ... | |
32 | * | `- opp n .. | |
33 | * |- device 2 (represents the next voltage domain) | |
34 | * ... | |
35 | * `- device m (represents mth voltage domain) | |
36 | * device 1, 2.. are represented by dev_opp structure while each opp | |
37 | * is represented by the opp structure. | |
38 | */ | |
39 | ||
40 | /** | |
41 | * struct dev_pm_opp - Generic OPP description structure | |
42 | * @node: opp list node. The nodes are maintained throughout the lifetime | |
43 | * of boot. It is expected only an optimal set of OPPs are | |
44 | * added to the library by the SoC framework. | |
45 | * RCU usage: opp list is traversed with RCU locks. node | |
46 | * modification is possible realtime, hence the modifications | |
47 | * are protected by the dev_opp_list_lock for integrity. | |
48 | * IMPORTANT: the opp nodes should be maintained in increasing | |
49 | * order. | |
50 | * @dynamic: not-created from static DT entries. | |
51 | * @available: true/false - marks if this OPP as available or not | |
52 | * @turbo: true if turbo (boost) OPP | |
53 | * @rate: Frequency in hertz | |
54 | * @u_volt: Target voltage in microvolts corresponding to this OPP | |
55 | * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP | |
56 | * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP | |
57 | * @u_amp: Maximum current drawn by the device in microamperes | |
58 | * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's | |
59 | * frequency from any other OPP's frequency. | |
60 | * @dev_opp: points back to the device_opp struct this opp belongs to | |
61 | * @rcu_head: RCU callback head used for deferred freeing | |
62 | * @np: OPP's device node. | |
63 | * | |
64 | * This structure stores the OPP information for a given device. | |
65 | */ | |
66 | struct dev_pm_opp { | |
67 | struct list_head node; | |
68 | ||
69 | bool available; | |
70 | bool dynamic; | |
71 | bool turbo; | |
72 | unsigned long rate; | |
73 | ||
74 | unsigned long u_volt; | |
75 | unsigned long u_volt_min; | |
76 | unsigned long u_volt_max; | |
77 | unsigned long u_amp; | |
78 | unsigned long clock_latency_ns; | |
79 | ||
80 | struct device_opp *dev_opp; | |
81 | struct rcu_head rcu_head; | |
82 | ||
83 | struct device_node *np; | |
84 | }; | |
85 | ||
86 | /** | |
87 | * struct device_list_opp - devices managed by 'struct device_opp' | |
88 | * @node: list node | |
89 | * @dev: device to which the struct object belongs | |
90 | * @rcu_head: RCU callback head used for deferred freeing | |
91 | * | |
92 | * This is an internal data structure maintaining the list of devices that are | |
93 | * managed by 'struct device_opp'. | |
94 | */ | |
95 | struct device_list_opp { | |
96 | struct list_head node; | |
97 | const struct device *dev; | |
98 | struct rcu_head rcu_head; | |
99 | }; | |
100 | ||
101 | /** | |
102 | * struct device_opp - Device opp structure | |
103 | * @node: list node - contains the devices with OPPs that | |
104 | * have been registered. Nodes once added are not modified in this | |
105 | * list. | |
106 | * RCU usage: nodes are not modified in the list of device_opp, | |
107 | * however addition is possible and is secured by dev_opp_list_lock | |
108 | * @srcu_head: notifier head to notify the OPP availability changes. | |
109 | * @rcu_head: RCU callback head used for deferred freeing | |
110 | * @dev_list: list of devices that share these OPPs | |
111 | * @opp_list: list of opps | |
112 | * @np: struct device_node pointer for opp's DT node. | |
113 | * @shared_opp: OPP is shared between multiple devices. | |
114 | * | |
115 | * This is an internal data structure maintaining the link to opps attached to | |
116 | * a device. This structure is not meant to be shared to users as it is | |
117 | * meant for book keeping and private to OPP library. | |
118 | * | |
119 | * Because the opp structures can be used from both rcu and srcu readers, we | |
120 | * need to wait for the grace period of both of them before freeing any | |
121 | * resources. And so we have used kfree_rcu() from within call_srcu() handlers. | |
122 | */ | |
123 | struct device_opp { | |
124 | struct list_head node; | |
125 | ||
126 | struct srcu_notifier_head srcu_head; | |
127 | struct rcu_head rcu_head; | |
128 | struct list_head dev_list; | |
129 | struct list_head opp_list; | |
130 | ||
131 | struct device_node *np; | |
132 | unsigned long clock_latency_ns_max; | |
133 | bool shared_opp; | |
134 | struct dev_pm_opp *suspend_opp; | |
135 | }; | |
136 | ||
137 | /* Routines internal to opp core */ | |
138 | struct device_opp *_find_device_opp(struct device *dev); | |
139 | struct device_list_opp *_add_list_dev(const struct device *dev, | |
140 | struct device_opp *dev_opp); | |
141 | struct device_node *_of_get_opp_desc_node(struct device *dev); | |
142 | ||
143 | #endif /* __DRIVER_OPP_H__ */ |