v4l2-clk.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * V4L2 clock service
  3. *
  4. * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * ATTENTION: This is a temporary API and it shall be replaced by the generic
  11. * clock API, when the latter becomes widely available.
  12. */
  13. #ifndef MEDIA_V4L2_CLK_H
  14. #define MEDIA_V4L2_CLK_H
  15. #include <linux/atomic.h>
  16. #include <linux/export.h>
  17. #include <linux/list.h>
  18. #include <linux/mutex.h>
  19. struct module;
  20. struct device;
  21. struct clk;
  22. struct v4l2_clk {
  23. struct list_head list;
  24. const struct v4l2_clk_ops *ops;
  25. const char *dev_id;
  26. int enable;
  27. struct mutex lock; /* Protect the enable count */
  28. atomic_t use_count;
  29. struct clk *clk;
  30. void *priv;
  31. };
  32. struct v4l2_clk_ops {
  33. struct module *owner;
  34. int (*enable)(struct v4l2_clk *clk);
  35. void (*disable)(struct v4l2_clk *clk);
  36. unsigned long (*get_rate)(struct v4l2_clk *clk);
  37. int (*set_rate)(struct v4l2_clk *clk, unsigned long);
  38. };
  39. struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
  40. const char *dev_name,
  41. void *priv);
  42. void v4l2_clk_unregister(struct v4l2_clk *clk);
  43. struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
  44. void v4l2_clk_put(struct v4l2_clk *clk);
  45. int v4l2_clk_enable(struct v4l2_clk *clk);
  46. void v4l2_clk_disable(struct v4l2_clk *clk);
  47. unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
  48. int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
  49. struct module;
  50. struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
  51. unsigned long rate, struct module *owner);
  52. void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
  53. static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
  54. unsigned long rate)
  55. {
  56. return __v4l2_clk_register_fixed(dev_id, rate, THIS_MODULE);
  57. }
  58. #define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
  59. "%d-%04x", adap, client)
  60. #endif