soc_camera_platform.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_subdev_desc *ssdd =
  36. (struct soc_camera_subdev_desc *)plink;
  37. struct soc_camera_platform_info *info = ssdd->drv_priv;
  38. int ret;
  39. if (&icd->sdesc->subdev_desc != ssdd)
  40. return -ENODEV;
  41. if (*pdev)
  42. return -EBUSY;
  43. *pdev = platform_device_alloc("soc_camera_platform", id);
  44. if (!*pdev)
  45. return -ENOMEM;
  46. info->icd = icd;
  47. (*pdev)->dev.platform_data = info;
  48. (*pdev)->dev.release = release;
  49. ret = platform_device_add(*pdev);
  50. if (ret < 0) {
  51. platform_device_put(*pdev);
  52. *pdev = NULL;
  53. info->icd = NULL;
  54. }
  55. return ret;
  56. }
  57. static inline void soc_camera_platform_del(const struct soc_camera_device *icd,
  58. struct platform_device *pdev,
  59. const struct soc_camera_link *plink)
  60. {
  61. const struct soc_camera_subdev_desc *ssdd =
  62. (const struct soc_camera_subdev_desc *)plink;
  63. if (&icd->sdesc->subdev_desc != ssdd || !pdev)
  64. return;
  65. platform_device_unregister(pdev);
  66. }
  67. #endif /* __SOC_CAMERA_H__ */