Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1.  
  2. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  3.  
  4. #include <linux/clk.h>
  5. #include <linux/delay.h>
  6. #include <linux/gpio/consumer.h>
  7. #include <linux/i2c.h>
  8. #include <linux/log2.h>
  9. #include <linux/mutex.h>
  10. #include <linux/of.h>
  11. #include <linux/regmap.h>
  12. #include <linux/slab.h>
  13. #include <linux/videodev2.h>
  14. #include <linux/v4l2-mediabus.h>
  15. #include <linux/module.h>
  16.  
  17. #include <media/v4l2-ctrls.h>
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-of.h>
  20. #include <media/v4l2-subdev.h>
  21.  
  22. struct ar0135 {
  23. struct v4l2_subdev subdev;
  24. struct media_pad pad;
  25.  
  26. struct v4l2_mbus_framefmt format;
  27. struct v4l2_rect crop;
  28.  
  29. struct {
  30. struct v4l2_ctrl *link_freq;
  31. };
  32.  
  33. struct mutex power_lock;
  34. int power_count;
  35.  
  36. struct regmap *regmap;
  37. struct gpio_desc *reset_gpio;
  38.  
  39. struct clk *xclk;
  40. int xclk_freq;
  41. };
  42.  
  43. static struct ar0135 *to_ar0135(struct v4l2_subdev *sd)
  44. {
  45. return container_of(sd, struct ar0135, subdev);
  46. }
  47.  
  48. static int ar0135_s_stream(struct v4l2_subdev *subdev, int enable)
  49. {
  50. return 0;
  51. }
  52.  
  53. /* -----------------------------------------------------------------------------
  54. * V4L2 subdev core operations
  55. */
  56.  
  57. static int ar0135_set_power(struct v4l2_subdev *subdev, int on)
  58. {
  59. return 0;
  60. }
  61.  
  62. /* -----------------------------------------------------------------------------
  63. * V4L2 subdev internal operations
  64. */
  65.  
  66. static int ar0135_registered(struct v4l2_subdev *subdev)
  67. {
  68. pr_info("registered");
  69. return 0;
  70. }
  71.  
  72. static struct v4l2_subdev_core_ops ar0135_subdev_core_ops = {
  73. .s_power = ar0135_set_power,
  74. };
  75.  
  76. static struct v4l2_subdev_video_ops ar0135_subdev_video_ops = {
  77. .s_stream = ar0135_s_stream,
  78. };
  79.  
  80. static struct v4l2_subdev_ops ar0135_subdev_ops = {
  81. .core = &ar0135_subdev_core_ops,
  82. .video = &ar0135_subdev_video_ops,
  83. };
  84.  
  85. static const struct v4l2_subdev_internal_ops ar0135_subdev_internal_ops = {
  86. .registered = ar0135_registered,
  87. };
  88.  
  89. /* -----------------------------------------------------------------------------
  90. * Driver initialization and probing
  91. */
  92.  
  93. static int ar0135_probe(struct i2c_client *client,
  94. const struct i2c_device_id *did)
  95. {
  96. struct ar0135 *ar0135;
  97. int ret;
  98.  
  99. pr_info("starting probe");
  100.  
  101. ar0135 = devm_kzalloc(&client->dev, sizeof(*ar0135), GFP_KERNEL);
  102. if (!ar0135)
  103. return -ENOMEM;
  104.  
  105. v4l2_i2c_subdev_init(&ar0135->subdev, client, &ar0135_subdev_ops);
  106. ar0135->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  107.  
  108. ar0135->subdev.internal_ops = &ar0135_subdev_internal_ops;
  109.  
  110. ar0135->pad.flags = MEDIA_PAD_FL_SOURCE;
  111. ar0135->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  112. ret = media_entity_pads_init(&ar0135->subdev.entity, 1, &ar0135->pad);
  113. if (ret < 0)
  114. goto err;
  115.  
  116. ar0135->subdev.dev = &client->dev;
  117. ret = v4l2_async_register_subdev(&ar0135->subdev);
  118. if (ret < 0)
  119. goto err;
  120.  
  121. pr_info("finished probe");
  122.  
  123. return 0;
  124.  
  125. err:
  126. media_entity_cleanup(&ar0135->subdev.entity);
  127. return ret;
  128. }
  129.  
  130. static int ar0135_remove(struct i2c_client *client)
  131. {
  132. struct v4l2_subdev *subdev = i2c_get_clientdata(client);
  133.  
  134. v4l2_async_unregister_subdev(subdev);
  135. media_entity_cleanup(&subdev->entity);
  136.  
  137. return 0;
  138. }
  139.  
  140. static const struct i2c_device_id ar0135_id[] = {
  141. { "ar0135", 0 },
  142. {}
  143. };
  144. MODULE_DEVICE_TABLE(i2c, ar0135_id);
  145.  
  146. #if IS_ENABLED(CONFIG_OF)
  147. static const struct of_device_id ar0135_of_match[] = {
  148. { .compatible = "onsemi,ar0135" },
  149. {}
  150. };
  151. MODULE_DEVICE_TABLE(of, ar0135_of_match);
  152. #endif
  153.  
  154. static struct i2c_driver ar0135_driver = {
  155. .driver = {
  156. .name = "ar0135",
  157. .of_match_table = of_match_ptr(ar0135_of_match),
  158. },
  159. .probe = ar0135_probe,
  160. .remove = ar0135_remove,
  161. .id_table = ar0135_id,
  162. };
  163.  
  164. module_i2c_driver(ar0135_driver);
  165.  
  166. MODULE_DESCRIPTION("ON Semiconductor AR0135 Sensor");
  167. MODULE_AUTHOR("Jack Mitchell <jack@embed.me.uk>");
  168. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement