10 #include <linux/kernel.h>
11 #include <linux/device.h>
16 #include <linux/slab.h>
28 struct pm_clock_entry {
40 static void pm_clk_acquire(
struct device *
dev,
struct pm_clock_entry *
ce)
42 ce->clk =
clk_get(dev, ce->con_id);
43 if (IS_ERR(ce->clk)) {
44 ce->status = PCE_STATUS_ERROR;
46 ce->status = PCE_STATUS_ACQUIRED;
47 dev_dbg(dev,
"Clock %s managed by runtime PM.\n", ce->con_id);
59 int pm_clk_add(
struct device *dev,
const char *con_id)
62 struct pm_clock_entry *
ce;
69 dev_err(dev,
"Not enough memory for clock entry.\n");
77 "Not enough memory for clock connection ID.\n");
83 pm_clk_acquire(dev, ce);
85 spin_lock_irq(&psd->
lock);
87 spin_unlock_irq(&psd->
lock);
95 static void __pm_clk_remove(
struct pm_clock_entry *ce)
100 if (ce->status < PCE_STATUS_ERROR) {
101 if (ce->status == PCE_STATUS_ENABLED)
104 if (ce->status >= PCE_STATUS_ACQUIRED)
120 void pm_clk_remove(
struct device *dev,
const char *con_id)
123 struct pm_clock_entry *
ce;
128 spin_lock_irq(&psd->
lock);
131 if (!con_id && !ce->con_id)
133 else if (!con_id || !ce->con_id)
135 else if (!
strcmp(con_id, ce->con_id))
139 spin_unlock_irq(&psd->
lock);
144 spin_unlock_irq(&psd->
lock);
156 void pm_clk_init(
struct device *dev)
160 INIT_LIST_HEAD(&psd->clock_list);
170 int pm_clk_create(
struct device *dev)
183 void pm_clk_destroy(
struct device *dev)
186 struct pm_clock_entry *
ce, *
c;
192 INIT_LIST_HEAD(&
list);
194 spin_lock_irq(&psd->
lock);
199 spin_unlock_irq(&psd->lock);
211 #ifdef CONFIG_PM_RUNTIME
220 struct pm_clock_entry *
ce;
223 dev_dbg(dev,
"%s()\n", __func__);
231 if (ce->status < PCE_STATUS_ERROR) {
232 if (ce->status == PCE_STATUS_ENABLED)
234 ce->status = PCE_STATUS_ACQUIRED;
238 spin_unlock_irqrestore(&psd->
lock, flags);
250 struct pm_clock_entry *
ce;
253 dev_dbg(dev,
"%s()\n", __func__);
261 if (ce->status < PCE_STATUS_ERROR) {
263 ce->status = PCE_STATUS_ENABLED;
267 spin_unlock_irqrestore(&psd->
lock, flags);
296 dev_dbg(dev,
"%s() %ld\n", __func__, action);
305 error = pm_clk_create(dev);
311 for (con_id = clknb->
con_ids; *con_id; con_id++)
312 pm_clk_add(dev, *con_id);
314 pm_clk_add(dev,
NULL);
341 struct pm_clock_entry *
ce;
344 dev_dbg(dev,
"%s()\n", __func__);
355 spin_unlock_irqrestore(&psd->lock, flags);
367 struct pm_clock_entry *
ce;
370 dev_dbg(dev,
"%s()\n", __func__);
373 if (!psd || !dev->driver)
381 spin_unlock_irqrestore(&psd->lock, flags);
393 static void enable_clock(
struct device *dev,
const char *con_id)
401 dev_info(dev,
"Runtime PM disabled, clock forced on.\n");
410 static void disable_clock(
struct device *dev,
const char *con_id)
418 dev_info(dev,
"Runtime PM disabled, clock forced off.\n");
434 unsigned long action,
void *data)
440 dev_dbg(dev,
"%s() %ld\n", __func__, action);
447 for (con_id = clknb->
con_ids; *con_id; con_id++)
448 enable_clock(dev, *con_id);
450 enable_clock(dev,
NULL);
455 for (con_id = clknb->
con_ids; *con_id; con_id++)
456 disable_clock(dev, *con_id);
458 disable_clock(dev,
NULL);
484 clknb->
nb.notifier_call = pm_clk_notify;