Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
omap_device.c
Go to the documentation of this file.
1 /*
2  * omap_device implementation
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation
5  * Paul Walmsley, Kevin Hilman
6  *
7  * Developed in collaboration with (alphabetical order): Benoit
8  * Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
9  * Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
10  * Woodruff
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  *
16  * This code provides a consistent interface for OMAP device drivers
17  * to control power management and interconnect properties of their
18  * devices.
19  *
20  * In the medium- to long-term, this code should either be
21  * a) implemented via arch-specific pointers in platform_data
22  * or
23  * b) implemented as a proper omap_bus/omap_device in Linux, no more
24  * platform_data func pointers
25  *
26  *
27  * Guidelines for usage by driver authors:
28  *
29  * 1. These functions are intended to be used by device drivers via
30  * function pointers in struct platform_data. As an example,
31  * omap_device_enable() should be passed to the driver as
32  *
33  * struct foo_driver_platform_data {
34  * ...
35  * int (*device_enable)(struct platform_device *pdev);
36  * ...
37  * }
38  *
39  * Note that the generic "device_enable" name is used, rather than
40  * "omap_device_enable". This is so other architectures can pass in their
41  * own enable/disable functions here.
42  *
43  * This should be populated during device setup:
44  *
45  * ...
46  * pdata->device_enable = omap_device_enable;
47  * ...
48  *
49  * 2. Drivers should first check to ensure the function pointer is not null
50  * before calling it, as in:
51  *
52  * if (pdata->device_enable)
53  * pdata->device_enable(pdev);
54  *
55  * This allows other architectures that don't use similar device_enable()/
56  * device_shutdown() functions to execute normally.
57  *
58  * ...
59  *
60  * Suggested usage by device drivers:
61  *
62  * During device initialization:
63  * device_enable()
64  *
65  * During device idle:
66  * (save remaining device context if necessary)
67  * device_idle();
68  *
69  * During device resume:
70  * device_enable();
71  * (restore context if necessary)
72  *
73  * During device shutdown:
74  * device_shutdown()
75  * (device must be reinitialized at this point to use it again)
76  *
77  */
78 #undef DEBUG
79 
80 #include <linux/kernel.h>
81 #include <linux/export.h>
82 #include <linux/platform_device.h>
83 #include <linux/slab.h>
84 #include <linux/err.h>
85 #include <linux/io.h>
86 #include <linux/clk.h>
87 #include <linux/clkdev.h>
88 #include <linux/pm_runtime.h>
89 #include <linux/of.h>
90 #include <linux/notifier.h>
91 
92 #include <plat/omap_device.h>
93 #include <plat/omap_hwmod.h>
94 #include <plat/clock.h>
95 
96 /* These parameters are passed to _omap_device_{de,}activate() */
97 #define USE_WAKEUP_LAT 0
98 #define IGNORE_WAKEUP_LAT 1
99 
100 static int omap_early_device_register(struct platform_device *pdev);
101 
102 static struct omap_device_pm_latency omap_default_latency[] = {
103  {
104  .deactivate_func = omap_device_idle_hwmods,
105  .activate_func = omap_device_enable_hwmods,
107  }
108 };
109 
110 /* Private functions */
111 
126 static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
127 {
128  struct timespec a, b, c;
129 
130  dev_dbg(&od->pdev->dev, "omap_device: activating\n");
131 
132  while (od->pm_lat_level > 0) {
133  struct omap_device_pm_latency *odpl;
134  unsigned long long act_lat = 0;
135 
136  od->pm_lat_level--;
137 
138  odpl = od->pm_lats + od->pm_lat_level;
139 
140  if (!ignore_lat &&
142  break;
143 
145 
146  /* XXX check return code */
147  odpl->activate_func(od);
148 
150 
151  c = timespec_sub(b, a);
152  act_lat = timespec_to_ns(&c);
153 
154  dev_dbg(&od->pdev->dev,
155  "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
156  od->pm_lat_level, act_lat);
157 
158  if (act_lat > odpl->activate_lat) {
159  odpl->activate_lat_worst = act_lat;
161  odpl->activate_lat = act_lat;
162  dev_dbg(&od->pdev->dev,
163  "new worst case activate latency %d: %llu\n",
164  od->pm_lat_level, act_lat);
165  } else
166  dev_warn(&od->pdev->dev,
167  "activate latency %d higher than expected. (%llu > %d)\n",
168  od->pm_lat_level, act_lat,
169  odpl->activate_lat);
170  }
171 
172  od->dev_wakeup_lat -= odpl->activate_lat;
173  }
174 
175  return 0;
176 }
177 
192 static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
193 {
194  struct timespec a, b, c;
195 
196  dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
197 
198  while (od->pm_lat_level < od->pm_lats_cnt) {
199  struct omap_device_pm_latency *odpl;
200  unsigned long long deact_lat = 0;
201 
202  odpl = od->pm_lats + od->pm_lat_level;
203 
204  if (!ignore_lat &&
205  ((od->dev_wakeup_lat + odpl->activate_lat) >
207  break;
208 
210 
211  /* XXX check return code */
212  odpl->deactivate_func(od);
213 
215 
216  c = timespec_sub(b, a);
217  deact_lat = timespec_to_ns(&c);
218 
219  dev_dbg(&od->pdev->dev,
220  "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
221  od->pm_lat_level, deact_lat);
222 
223  if (deact_lat > odpl->deactivate_lat) {
224  odpl->deactivate_lat_worst = deact_lat;
226  odpl->deactivate_lat = deact_lat;
227  dev_dbg(&od->pdev->dev,
228  "new worst case deactivate latency %d: %llu\n",
229  od->pm_lat_level, deact_lat);
230  } else
231  dev_warn(&od->pdev->dev,
232  "deactivate latency %d higher than expected. (%llu > %d)\n",
233  od->pm_lat_level, deact_lat,
234  odpl->deactivate_lat);
235  }
236 
237  od->dev_wakeup_lat += odpl->activate_lat;
238 
239  od->pm_lat_level++;
240  }
241 
242  return 0;
243 }
244 
245 static void _add_clkdev(struct omap_device *od, const char *clk_alias,
246  const char *clk_name)
247 {
248  struct clk *r;
249  struct clk_lookup *l;
250 
251  if (!clk_alias || !clk_name)
252  return;
253 
254  dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
255 
256  r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
257  if (!IS_ERR(r)) {
258  dev_warn(&od->pdev->dev,
259  "alias %s already exists\n", clk_alias);
260  clk_put(r);
261  return;
262  }
263 
264  r = clk_get(NULL, clk_name);
265  if (IS_ERR(r)) {
266  dev_err(&od->pdev->dev,
267  "clk_get for %s failed\n", clk_name);
268  return;
269  }
270 
271  l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
272  if (!l) {
273  dev_err(&od->pdev->dev,
274  "clkdev_alloc for %s failed\n", clk_alias);
275  return;
276  }
277 
278  clkdev_add(l);
279 }
280 
300 static void _add_hwmod_clocks_clkdev(struct omap_device *od,
301  struct omap_hwmod *oh)
302 {
303  int i;
304 
305  _add_clkdev(od, "fck", oh->main_clk);
306 
307  for (i = 0; i < oh->opt_clks_cnt; i++)
308  _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
309 }
310 
311 
327 static int omap_device_build_from_dt(struct platform_device *pdev)
328 {
329  struct omap_hwmod **hwmods;
330  struct omap_device *od;
331  struct omap_hwmod *oh;
332  struct device_node *node = pdev->dev.of_node;
333  const char *oh_name;
334  int oh_cnt, i, ret = 0;
335 
336  oh_cnt = of_property_count_strings(node, "ti,hwmods");
337  if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
338  dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
339  return -ENODEV;
340  }
341 
342  hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
343  if (!hwmods) {
344  ret = -ENOMEM;
345  goto odbfd_exit;
346  }
347 
348  for (i = 0; i < oh_cnt; i++) {
349  of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
350  oh = omap_hwmod_lookup(oh_name);
351  if (!oh) {
352  dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
353  oh_name);
354  ret = -EINVAL;
355  goto odbfd_exit1;
356  }
357  hwmods[i] = oh;
358  }
359 
360  od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
361  if (!od) {
362  dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
363  oh_name);
364  ret = PTR_ERR(od);
365  goto odbfd_exit1;
366  }
367 
368  /* Fix up missing resource names */
369  for (i = 0; i < pdev->num_resources; i++) {
370  struct resource *r = &pdev->resource[i];
371 
372  if (r->name == NULL)
373  r->name = dev_name(&pdev->dev);
374  }
375 
376  if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
377  omap_device_disable_idle_on_suspend(pdev);
378 
379  pdev->dev.pm_domain = &omap_device_pm_domain;
380 
381 odbfd_exit1:
382  kfree(hwmods);
383 odbfd_exit:
384  return ret;
385 }
386 
387 static int _omap_device_notifier_call(struct notifier_block *nb,
388  unsigned long event, void *dev)
389 {
390  struct platform_device *pdev = to_platform_device(dev);
391  struct omap_device *od;
392 
393  switch (event) {
395  if (pdev->archdata.od)
396  omap_device_delete(pdev->archdata.od);
397  break;
399  if (pdev->dev.of_node)
400  omap_device_build_from_dt(pdev);
401  /* fall through */
402  default:
403  od = to_omap_device(pdev);
404  if (od)
405  od->_driver_status = event;
406  }
407 
408  return NOTIFY_DONE;
409 }
410 
411 
412 /* Public functions for use by core code */
413 
430 {
431  struct omap_device *od;
432  u32 ret = 0;
433 
434  od = to_omap_device(pdev);
435 
436  if (od->hwmods_cnt)
438 
439  return ret;
440 }
441 
451 static int omap_device_count_resources(struct omap_device *od)
452 {
453  int c = 0;
454  int i;
455 
456  for (i = 0; i < od->hwmods_cnt; i++)
457  c += omap_hwmod_count_resources(od->hwmods[i]);
458 
459  pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
460  od->pdev->name, c, od->hwmods_cnt);
461 
462  return c;
463 }
464 
482 static int omap_device_fill_resources(struct omap_device *od,
483  struct resource *res)
484 {
485  int i, r;
486 
487  for (i = 0; i < od->hwmods_cnt; i++) {
488  r = omap_hwmod_fill_resources(od->hwmods[i], res);
489  res += r;
490  }
491 
492  return 0;
493 }
494 
509 static int _od_fill_dma_resources(struct omap_device *od,
510  struct resource *res)
511 {
512  int i, r;
513 
514  for (i = 0; i < od->hwmods_cnt; i++) {
515  r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
516  res += r;
517  }
518 
519  return 0;
520 }
521 
537  struct omap_hwmod **ohs, int oh_cnt,
539  int pm_lats_cnt)
540 {
541  int ret = -ENOMEM;
542  struct omap_device *od;
543  struct resource *res = NULL;
544  int i, res_count;
545  struct omap_hwmod **hwmods;
546 
547  od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
548  if (!od) {
549  ret = -ENOMEM;
550  goto oda_exit1;
551  }
552  od->hwmods_cnt = oh_cnt;
553 
554  hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
555  if (!hwmods)
556  goto oda_exit2;
557 
558  od->hwmods = hwmods;
559  od->pdev = pdev;
560 
561  res_count = omap_device_count_resources(od);
562  /*
563  * DT Boot:
564  * OF framework will construct the resource structure (currently
565  * does for MEM & IRQ resource) and we should respect/use these
566  * resources, killing hwmod dependency.
567  * If pdev->num_resources > 0, we assume that MEM & IRQ resources
568  * have been allocated by OF layer already (through DTB).
569  *
570  * Non-DT Boot:
571  * Here, pdev->num_resources = 0, and we should get all the
572  * resources from hwmod.
573  *
574  * TODO: Once DMA resource is available from OF layer, we should
575  * kill filling any resources from hwmod.
576  */
577  if (res_count > pdev->num_resources) {
578  /* Allocate resources memory to account for new resources */
579  res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
580  if (!res)
581  goto oda_exit3;
582 
583  /*
584  * If pdev->num_resources > 0, then assume that,
585  * MEM and IRQ resources will only come from DT and only
586  * fill DMA resource from hwmod layer.
587  */
588  if (pdev->num_resources && pdev->resource) {
589  dev_dbg(&pdev->dev, "%s(): resources already allocated %d\n",
590  __func__, res_count);
591  memcpy(res, pdev->resource,
592  sizeof(struct resource) * pdev->num_resources);
593  _od_fill_dma_resources(od, &res[pdev->num_resources]);
594  } else {
595  dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n",
596  __func__, res_count);
597  omap_device_fill_resources(od, res);
598  }
599 
600  ret = platform_device_add_resources(pdev, res, res_count);
601  kfree(res);
602 
603  if (ret)
604  goto oda_exit3;
605  }
606 
607  if (!pm_lats) {
608  pm_lats = omap_default_latency;
609  pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
610  }
611 
612  od->pm_lats_cnt = pm_lats_cnt;
613  od->pm_lats = kmemdup(pm_lats,
614  sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
615  GFP_KERNEL);
616  if (!od->pm_lats)
617  goto oda_exit3;
618 
619  pdev->archdata.od = od;
620 
621  for (i = 0; i < oh_cnt; i++) {
622  hwmods[i]->od = od;
623  _add_hwmod_clocks_clkdev(od, hwmods[i]);
624  }
625 
626  return od;
627 
628 oda_exit3:
629  kfree(hwmods);
630 oda_exit2:
631  kfree(od);
632 oda_exit1:
633  dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
634 
635  return ERR_PTR(ret);
636 }
637 
639 {
640  if (!od)
641  return;
642 
643  od->pdev->archdata.od = NULL;
644  kfree(od->pm_lats);
645  kfree(od->hwmods);
646  kfree(od);
647 }
648 
666 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
667  struct omap_hwmod *oh, void *pdata,
668  int pdata_len,
669  struct omap_device_pm_latency *pm_lats,
670  int pm_lats_cnt, int is_early_device)
671 {
672  struct omap_hwmod *ohs[] = { oh };
673 
674  if (!oh)
675  return ERR_PTR(-EINVAL);
676 
677  return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
678  pdata_len, pm_lats, pm_lats_cnt,
679  is_early_device);
680 }
681 
699 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
700  struct omap_hwmod **ohs, int oh_cnt,
701  void *pdata, int pdata_len,
702  struct omap_device_pm_latency *pm_lats,
703  int pm_lats_cnt, int is_early_device)
704 {
705  int ret = -ENOMEM;
706  struct platform_device *pdev;
707  struct omap_device *od;
708 
709  if (!ohs || oh_cnt == 0 || !pdev_name)
710  return ERR_PTR(-EINVAL);
711 
712  if (!pdata && pdata_len > 0)
713  return ERR_PTR(-EINVAL);
714 
715  pdev = platform_device_alloc(pdev_name, pdev_id);
716  if (!pdev) {
717  ret = -ENOMEM;
718  goto odbs_exit;
719  }
720 
721  /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
722  if (pdev->id != -1)
723  dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
724  else
725  dev_set_name(&pdev->dev, "%s", pdev->name);
726 
727  od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
728  if (IS_ERR(od))
729  goto odbs_exit1;
730 
731  ret = platform_device_add_data(pdev, pdata, pdata_len);
732  if (ret)
733  goto odbs_exit2;
734 
735  if (is_early_device)
736  ret = omap_early_device_register(pdev);
737  else
738  ret = omap_device_register(pdev);
739  if (ret)
740  goto odbs_exit2;
741 
742  return pdev;
743 
744 odbs_exit2:
745  omap_device_delete(od);
746 odbs_exit1:
747  platform_device_put(pdev);
748 odbs_exit:
749 
750  pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
751 
752  return ERR_PTR(ret);
753 }
754 
764 static int __init omap_early_device_register(struct platform_device *pdev)
765 {
766  struct platform_device *devices[1];
767 
768  devices[0] = pdev;
769  early_platform_add_devices(devices, 1);
770  return 0;
771 }
772 
773 #ifdef CONFIG_PM_RUNTIME
774 static int _od_runtime_suspend(struct device *dev)
775 {
776  struct platform_device *pdev = to_platform_device(dev);
777  int ret;
778 
779  ret = pm_generic_runtime_suspend(dev);
780 
781  if (!ret)
782  omap_device_idle(pdev);
783 
784  return ret;
785 }
786 
787 static int _od_runtime_idle(struct device *dev)
788 {
789  return pm_generic_runtime_idle(dev);
790 }
791 
792 static int _od_runtime_resume(struct device *dev)
793 {
794  struct platform_device *pdev = to_platform_device(dev);
795 
796  omap_device_enable(pdev);
797 
798  return pm_generic_runtime_resume(dev);
799 }
800 #endif
801 
802 #ifdef CONFIG_SUSPEND
803 static int _od_suspend_noirq(struct device *dev)
804 {
805  struct platform_device *pdev = to_platform_device(dev);
806  struct omap_device *od = to_omap_device(pdev);
807  int ret;
808 
809  /* Don't attempt late suspend on a driver that is not bound */
811  return 0;
812 
813  ret = pm_generic_suspend_noirq(dev);
814 
815  if (!ret && !pm_runtime_status_suspended(dev)) {
816  if (pm_generic_runtime_suspend(dev) == 0) {
818  omap_device_idle(pdev);
820  }
821  }
822 
823  return ret;
824 }
825 
826 static int _od_resume_noirq(struct device *dev)
827 {
828  struct platform_device *pdev = to_platform_device(dev);
829  struct omap_device *od = to_omap_device(pdev);
830 
831  if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
832  !pm_runtime_status_suspended(dev)) {
835  omap_device_enable(pdev);
836  pm_generic_runtime_resume(dev);
837  }
838 
839  return pm_generic_resume_noirq(dev);
840 }
841 #else
842 #define _od_suspend_noirq NULL
843 #define _od_resume_noirq NULL
844 #endif
845 
847  .ops = {
848  SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
849  _od_runtime_idle)
851  .suspend_noirq = _od_suspend_noirq,
852  .resume_noirq = _od_resume_noirq,
853  }
854 };
855 
865 {
866  pr_debug("omap_device: %s: registering\n", pdev->name);
867 
868  pdev->dev.pm_domain = &omap_device_pm_domain;
869  return platform_device_add(pdev);
870 }
871 
872 
873 /* Public functions for use by device drivers through struct platform_data */
874 
889 {
890  int ret;
891  struct omap_device *od;
892 
893  od = to_omap_device(pdev);
894 
895  if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
896  dev_warn(&pdev->dev,
897  "omap_device: %s() called from invalid state %d\n",
898  __func__, od->_state);
899  return -EINVAL;
900  }
901 
902  /* Enable everything if we're enabling this device from scratch */
904  od->pm_lat_level = od->pm_lats_cnt;
905 
906  ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
907 
908  od->dev_wakeup_lat = 0;
911 
912  return ret;
913 }
914 
929 {
930  int ret;
931  struct omap_device *od;
932 
933  od = to_omap_device(pdev);
934 
935  if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
936  dev_warn(&pdev->dev,
937  "omap_device: %s() called from invalid state %d\n",
938  __func__, od->_state);
939  return -EINVAL;
940  }
941 
942  ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
943 
945 
946  return ret;
947 }
948 
961 {
962  int ret, i;
963  struct omap_device *od;
964 
965  od = to_omap_device(pdev);
966 
967  if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
969  dev_warn(&pdev->dev,
970  "omap_device: %s() called from invalid state %d\n",
971  __func__, od->_state);
972  return -EINVAL;
973  }
974 
975  ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
976 
977  for (i = 0; i < od->hwmods_cnt; i++)
978  omap_hwmod_shutdown(od->hwmods[i]);
979 
981 
982  return ret;
983 }
984 
997 int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
998 {
999  struct omap_device *od = to_omap_device(pdev);
1000  int ret = 0;
1001  int i;
1002 
1003  for (i = 0; i < od->hwmods_cnt; i++) {
1004  ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
1005  if (ret)
1006  break;
1007  }
1008 
1009  return ret;
1010 }
1011 
1025  const char *name)
1026 {
1027  struct omap_device *od = to_omap_device(pdev);
1028  int ret = 0;
1029  int i;
1030 
1031  for (i = 0; i < od->hwmods_cnt; i++) {
1032  ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
1033  if (ret)
1034  break;
1035  }
1036 
1037  return ret;
1038 }
1039 
1057  u32 new_wakeup_lat_limit)
1058 {
1059  int ret = -EINVAL;
1060  struct omap_device *od;
1061 
1062  od = to_omap_device(pdev);
1063 
1064  if (new_wakeup_lat_limit == od->dev_wakeup_lat)
1065  return 0;
1066 
1067  od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
1068 
1069  if (od->_state != OMAP_DEVICE_STATE_IDLE)
1070  return 0;
1071  else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
1072  ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
1073  else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
1074  ret = _omap_device_activate(od, USE_WAKEUP_LAT);
1075 
1076  return ret;
1077 }
1078 
1089 {
1090  /*
1091  * XXX Assumes that all omap_hwmod powerdomains are identical.
1092  * This may not necessarily be true. There should be a sanity
1093  * check in here to WARN() if any difference appears.
1094  */
1095  if (!od->hwmods_cnt)
1096  return NULL;
1097 
1098  return omap_hwmod_get_pwrdm(od->hwmods[0]);
1099 }
1100 
1113 {
1114  if (od->hwmods_cnt != 1)
1115  return NULL;
1116 
1117  return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
1118 }
1119 
1128 struct device *omap_device_get_by_hwmod_name(const char *oh_name)
1129 {
1130  struct omap_hwmod *oh;
1131 
1132  if (!oh_name) {
1133  WARN(1, "%s: no hwmod name!\n", __func__);
1134  return ERR_PTR(-EINVAL);
1135  }
1136 
1137  oh = omap_hwmod_lookup(oh_name);
1138  if (IS_ERR_OR_NULL(oh)) {
1139  WARN(1, "%s: no hwmod for %s\n", __func__,
1140  oh_name);
1141  return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
1142  }
1143  if (IS_ERR_OR_NULL(oh->od)) {
1144  WARN(1, "%s: no omap_device for %s\n", __func__,
1145  oh_name);
1146  return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
1147  }
1148 
1149  if (IS_ERR_OR_NULL(oh->od->pdev))
1150  return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
1151 
1152  return &oh->od->pdev->dev;
1153 }
1155 
1156 /*
1157  * Public functions intended for use in omap_device_pm_latency
1158  * .activate_func and .deactivate_func function pointers
1159  */
1160 
1168 {
1169  int i;
1170 
1171  for (i = 0; i < od->hwmods_cnt; i++)
1172  omap_hwmod_enable(od->hwmods[i]);
1173 
1174  /* XXX pass along return value here? */
1175  return 0;
1176 }
1177 
1185 {
1186  int i;
1187 
1188  for (i = 0; i < od->hwmods_cnt; i++)
1189  omap_hwmod_idle(od->hwmods[i]);
1190 
1191  /* XXX pass along return value here? */
1192  return 0;
1193 }
1194 
1203 {
1204  int i;
1205 
1206  for (i = 0; i < od->hwmods_cnt; i++)
1208 
1209  /* XXX pass along return value here? */
1210  return 0;
1211 }
1212 
1221 {
1222  int i;
1223 
1224  for (i = 0; i < od->hwmods_cnt; i++)
1226 
1227  /* XXX pass along return value here? */
1228  return 0;
1229 }
1230 
1231 static struct notifier_block platform_nb = {
1232  .notifier_call = _omap_device_notifier_call,
1233 };
1234 
1235 static int __init omap_device_init(void)
1236 {
1237  bus_register_notifier(&platform_bus_type, &platform_nb);
1238  return 0;
1239 }
1240 core_initcall(omap_device_init);
1241 
1250 static int __init omap_device_late_idle(struct device *dev, void *data)
1251 {
1252  struct platform_device *pdev = to_platform_device(dev);
1253  struct omap_device *od = to_omap_device(pdev);
1254 
1255  if (!od)
1256  return 0;
1257 
1258  /*
1259  * If omap_device state is enabled, but has no driver bound,
1260  * idle it.
1261  */
1263  if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
1264  dev_warn(dev, "%s: enabled but no driver. Idling\n",
1265  __func__);
1266  omap_device_idle(pdev);
1267  }
1268  }
1269 
1270  return 0;
1271 }
1272 
1273 static int __init omap_device_late_init(void)
1274 {
1275  bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
1276  return 0;
1277 }
1278 late_initcall(omap_device_late_init);