soc_camera_platform.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Generic Platform Camera Driver Header
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  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. #ifndef __SOC_CAMERA_H__
  11. #define __SOC_CAMERA_H__
  12. #include <linux/videodev2.h>
  13. #include <media/soc_camera.h>
  14. #include <media/v4l2-mediabus.h>
  15. struct device;
  16. struct soc_camera_platform_info {
  17. const char *format_name;
  18. unsigned long format_depth;
  19. struct v4l2_mbus_framefmt format;
  20. unsigned long mbus_param;
  21. enum v4l2_mbus_type mbus_type;
  22. struct soc_camera_device *icd;
  23. int (*set_capture)(struct soc_camera_platform_info *info, int enable);
  24. };
  25. static inline void soc_camera_platform_release(struct platform_device **pdev)
  26. {
  27. *pdev = NULL;
  28. }
  29. static inline int soc_camera_platform_add(struct soc_camera_device *icd,
  30. struct platform_device **pdev,
  31. struct soc_camera_link *plink,
  32. void (*release)(struct device *dev),
  33. int id)
  34. {
  35. struct soc_camera_platform_info *info = plink->priv;
  36. int ret;
  37. if (icd->link != plink)
  38. return -ENODEV;
  39. if (*pdev)
  40. return -EBUSY;
  41. *pdev = platform_device_alloc("soc_camera_platform", id);
  42. if (!*pdev)
  43. return -ENOMEM;
  44. info->icd = icd;
  45. (*pdev)->dev.platform_data = info;
  46. (*pdev)->dev.release = release;
  47. ret = platform_device_add(*pdev);
  48. if (ret < 0) {
  49. platform_device_put(*pdev);
  50. *pdev = NULL;
  51. info->icd = NULL;
  52. }
  53. return ret;
  54. }
  55. static inline void soc_camera_platform_del(const struct soc_camera_device *icd,
  56. struct platform_device *pdev,
  57. const struct soc_camera_link *plink)
  58. {
  59. if (icd->link != plink || !pdev)
  60. return;
  61. platform_device_unregister(pdev);
  62. }
  63. #endif /* __SOC_CAMERA_H__ */