v4l2-clk.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 v4l2_clk {
  22. struct list_head list;
  23. const struct v4l2_clk_ops *ops;
  24. const char *dev_id;
  25. const char *id;
  26. int enable;
  27. struct mutex lock; /* Protect the enable count */
  28. atomic_t use_count;
  29. void *priv;
  30. };
  31. struct v4l2_clk_ops {
  32. struct module *owner;
  33. int (*enable)(struct v4l2_clk *clk);
  34. void (*disable)(struct v4l2_clk *clk);
  35. unsigned long (*get_rate)(struct v4l2_clk *clk);
  36. int (*set_rate)(struct v4l2_clk *clk, unsigned long);
  37. };
  38. struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
  39. const char *dev_name,
  40. const char *name, void *priv);
  41. void v4l2_clk_unregister(struct v4l2_clk *clk);
  42. struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
  43. void v4l2_clk_put(struct v4l2_clk *clk);
  44. int v4l2_clk_enable(struct v4l2_clk *clk);
  45. void v4l2_clk_disable(struct v4l2_clk *clk);
  46. unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
  47. int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
  48. struct module;
  49. struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
  50. const char *id, unsigned long rate, struct module *owner);
  51. void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
  52. static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
  53. const char *id,
  54. unsigned long rate)
  55. {
  56. return __v4l2_clk_register_fixed(dev_id, 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