soc_camera_platform.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Generic Platform Camera Driver
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. * Based on mt9m001 driver,
  6. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/videodev2.h>
  18. #include <media/v4l2-common.h>
  19. #include <media/soc_camera.h>
  20. #include <media/soc_camera_platform.h>
  21. struct soc_camera_platform_priv {
  22. struct soc_camera_platform_info *info;
  23. struct soc_camera_device icd;
  24. struct soc_camera_data_format format;
  25. };
  26. static struct soc_camera_platform_info *
  27. soc_camera_platform_get_info(struct soc_camera_device *icd)
  28. {
  29. struct soc_camera_platform_priv *priv;
  30. priv = container_of(icd, struct soc_camera_platform_priv, icd);
  31. return priv->info;
  32. }
  33. static int soc_camera_platform_init(struct soc_camera_device *icd)
  34. {
  35. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  36. if (p->power)
  37. p->power(1);
  38. return 0;
  39. }
  40. static int soc_camera_platform_release(struct soc_camera_device *icd)
  41. {
  42. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  43. if (p->power)
  44. p->power(0);
  45. return 0;
  46. }
  47. static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
  48. {
  49. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  50. return p->set_capture(p, 1);
  51. }
  52. static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
  53. {
  54. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  55. return p->set_capture(p, 0);
  56. }
  57. static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
  58. unsigned long flags)
  59. {
  60. return 0;
  61. }
  62. static unsigned long
  63. soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
  64. {
  65. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  66. return p->bus_param;
  67. }
  68. static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
  69. __u32 pixfmt, struct v4l2_rect *rect)
  70. {
  71. return 0;
  72. }
  73. static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
  74. struct v4l2_format *f)
  75. {
  76. struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
  77. struct v4l2_pix_format *pix = &f->fmt.pix;
  78. pix->width = p->format.width;
  79. pix->height = p->format.height;
  80. return 0;
  81. }
  82. static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
  83. {
  84. struct soc_camera_platform_priv *priv;
  85. priv = container_of(icd, struct soc_camera_platform_priv, icd);
  86. priv->format.name = priv->info->format_name;
  87. priv->format.depth = priv->info->format_depth;
  88. priv->format.fourcc = priv->info->format.pixelformat;
  89. priv->format.colorspace = priv->info->format.colorspace;
  90. icd->formats = &priv->format;
  91. icd->num_formats = 1;
  92. return soc_camera_video_start(icd);
  93. }
  94. static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
  95. {
  96. soc_camera_video_stop(icd);
  97. }
  98. static struct soc_camera_ops soc_camera_platform_ops = {
  99. .owner = THIS_MODULE,
  100. .probe = soc_camera_platform_video_probe,
  101. .remove = soc_camera_platform_video_remove,
  102. .init = soc_camera_platform_init,
  103. .release = soc_camera_platform_release,
  104. .start_capture = soc_camera_platform_start_capture,
  105. .stop_capture = soc_camera_platform_stop_capture,
  106. .set_fmt = soc_camera_platform_set_fmt,
  107. .try_fmt = soc_camera_platform_try_fmt,
  108. .set_bus_param = soc_camera_platform_set_bus_param,
  109. .query_bus_param = soc_camera_platform_query_bus_param,
  110. };
  111. static int soc_camera_platform_probe(struct platform_device *pdev)
  112. {
  113. struct soc_camera_platform_priv *priv;
  114. struct soc_camera_platform_info *p;
  115. struct soc_camera_device *icd;
  116. int ret;
  117. p = pdev->dev.platform_data;
  118. if (!p)
  119. return -EINVAL;
  120. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  121. if (!priv)
  122. return -ENOMEM;
  123. priv->info = p;
  124. platform_set_drvdata(pdev, priv);
  125. icd = &priv->icd;
  126. icd->ops = &soc_camera_platform_ops;
  127. icd->control = &pdev->dev;
  128. icd->width_min = 0;
  129. icd->width_max = priv->info->format.width;
  130. icd->height_min = 0;
  131. icd->height_max = priv->info->format.height;
  132. icd->y_skip_top = 0;
  133. icd->iface = priv->info->iface;
  134. ret = soc_camera_device_register(icd);
  135. if (ret)
  136. kfree(priv);
  137. return ret;
  138. }
  139. static int soc_camera_platform_remove(struct platform_device *pdev)
  140. {
  141. struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
  142. soc_camera_device_unregister(&priv->icd);
  143. kfree(priv);
  144. return 0;
  145. }
  146. static struct platform_driver soc_camera_platform_driver = {
  147. .driver = {
  148. .name = "soc_camera_platform",
  149. },
  150. .probe = soc_camera_platform_probe,
  151. .remove = soc_camera_platform_remove,
  152. };
  153. static int __init soc_camera_platform_module_init(void)
  154. {
  155. return platform_driver_register(&soc_camera_platform_driver);
  156. }
  157. static void __exit soc_camera_platform_module_exit(void)
  158. {
  159. platform_driver_unregister(&soc_camera_platform_driver);
  160. }
  161. module_init(soc_camera_platform_module_init);
  162. module_exit(soc_camera_platform_module_exit);
  163. MODULE_DESCRIPTION("SoC Camera Platform driver");
  164. MODULE_AUTHOR("Magnus Damm");
  165. MODULE_LICENSE("GPL v2");