soc_camera_platform.h 1.8 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 bus_param;
  21. unsigned long mbus_param;
  22. enum v4l2_mbus_type mbus_type;
  23. struct soc_camera_device *icd;
  24. int (*set_capture)(struct soc_camera_platform_info *info, int enable);
  25. };
  26. static inline void soc_camera_platform_release(struct platform_device **pdev)
  27. {
  28. *pdev = NULL;
  29. }
  30. static inline int soc_camera_platform_add(struct soc_camera_device *icd,
  31. struct platform_device **pdev,
  32. struct soc_camera_link *plink,
  33. void (*release)(struct device *dev),
  34. int id)
  35. {
  36. struct soc_camera_platform_info *info = plink->priv;
  37. int ret;
  38. if (icd->link != plink)
  39. return -ENODEV;
  40. if (*pdev)
  41. return -EBUSY;
  42. *pdev = platform_device_alloc("soc_camera_platform", id);
  43. if (!*pdev)
  44. return -ENOMEM;
  45. info->icd = icd;
  46. (*pdev)->dev.platform_data = info;
  47. (*pdev)->dev.release = release;
  48. ret = platform_device_add(*pdev);
  49. if (ret < 0) {
  50. platform_device_put(*pdev);
  51. *pdev = NULL;
  52. info->icd = NULL;
  53. }
  54. return ret;
  55. }
  56. static inline void soc_camera_platform_del(const struct soc_camera_device *icd,
  57. struct platform_device *pdev,
  58. const struct soc_camera_link *plink)
  59. {
  60. if (icd->link != plink || !pdev)
  61. return;
  62. platform_device_unregister(pdev);
  63. }
  64. #endif /* __SOC_CAMERA_H__ */