soc_camera_platform.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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__ */