sensor_common.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program;
  43. *
  44. *****************************************************************************
  45. *
  46. * Note: This software is released under dual MIT and GPL licenses. A
  47. * recipient may use this file under the terms of either the MIT license or
  48. * GPL License. If you wish to use only one license not the other, you can
  49. * indicate your decision by deleting one of the above license notices in your
  50. * version of this file.
  51. *
  52. *****************************************************************************/
  53. #ifndef _SENSOR_COMMON_H_
  54. #define _SENSOR_COMMON_H_
  55. #include <linux/uaccess.h>
  56. #include <linux/cdev.h>
  57. #include <linux/debugfs.h>
  58. #include <linux/delay.h>
  59. #include <linux/gpio.h>
  60. #include <linux/io.h>
  61. #include <linux/kernel.h>
  62. #include <linux/module.h>
  63. #include <linux/of.h>
  64. #include <linux/of_address.h>
  65. #include <linux/of_gpio.h>
  66. #include <linux/phy/phy.h>
  67. #include <linux/phy/phy-mipi-dphy.h>
  68. #include <linux/platform_device.h>
  69. #include <linux/spinlock.h>
  70. #include "vvsensor.h"
  71. #define UNDEFINED_IN_DTS 0xFF
  72. struct vvcam_sensor_driver_dev
  73. {
  74. struct cdev cdev;
  75. dev_t devt;
  76. struct class *class;
  77. struct mutex vvmutex;
  78. struct platform_device *pdev;
  79. void *private;
  80. };
  81. struct vvcam_sensor_function_s
  82. {
  83. uint8_t sensor_name[16];
  84. uint32_t reserve_id;
  85. uint32_t sensor_clk;
  86. struct sensor_mipi_info mipi_info;
  87. int32_t (*sensor_get_chip_id) (void *ctx, uint32_t *chip_id);
  88. int32_t (*sensor_init) (void *ctx, struct vvcam_mode_info *pmode);
  89. int32_t (*sensor_set_stream) (void *ctx, uint32_t status);
  90. int32_t (*sensor_set_exp) (void *ctx, uint32_t exp_line);
  91. int32_t (*sensor_set_vs_exp) (void *ctx, uint32_t exp_line);
  92. int32_t (*sensor_set_gain) (void *ctx, uint32_t gain);
  93. int32_t (*sensor_set_vs_gain) (void *ctx, uint32_t gain);
  94. int32_t (*sensor_set_fps) (void *ctx, uint32_t fps);
  95. int32_t (*sensor_set_resolution)(void *ctx, uint32_t width, uint32_t height);
  96. int32_t (*sensor_set_hdr_mode) (void *ctx, uint32_t hdr_mode);
  97. int32_t (*sensor_query) (void *ctx, struct vvcam_mode_info_array *pmode_info_arry);
  98. };
  99. #define VVCAM_SENSOR_MAX_REGULATORS 10
  100. struct vvcam_sensor_regulators {
  101. struct regulator *supply[VVCAM_SENSOR_MAX_REGULATORS];
  102. const char *name[VVCAM_SENSOR_MAX_REGULATORS];
  103. unsigned int voltage[VVCAM_SENSOR_MAX_REGULATORS];
  104. unsigned int delay_us[VVCAM_SENSOR_MAX_REGULATORS];
  105. int num;
  106. };
  107. struct vvcam_sensor_dev {
  108. struct device* dev;
  109. long phy_addr;
  110. long reg_size;
  111. void __iomem *base;
  112. int32_t device_idx;
  113. uint8_t i2c_bus;
  114. void* i2c_client;
  115. struct vvcam_sccb_cfg_s sensor_sccb_cfg;
  116. struct vvcam_sccb_cfg_s focus_sccb_cfg;
  117. struct vvcam_sensor_function_s sensor_func;
  118. struct vvcam_mode_info sensor_mode;
  119. struct vvcam_ae_info_s ae_info;
  120. const char *sensor_name;
  121. struct vvcam_sensor_regulators regulators;
  122. int pdn_pin;
  123. int pdn_pin_is_busy;
  124. unsigned int pdn_delay_us;
  125. int rst_pin;
  126. int rst_pin_is_busy;
  127. wait_queue_head_t err_wait;
  128. int err_mask;
  129. };
  130. extern int32_t sensor_reset(void *dev);
  131. extern int32_t sensor_set_clk(void *dev, uint32_t clk);
  132. extern int32_t sensor_get_clk(void *dev, uint32_t *pclk);
  133. extern int32_t sensor_set_power(void *dev, uint32_t power);
  134. extern int32_t sensor_get_power(void *dev, uint32_t *ppower);
  135. int32_t vvcam_sensor_i2c_write(struct vvcam_sensor_dev *dev, uint32_t address, uint32_t data);
  136. int32_t vvcam_sensor_i2c_read(struct vvcam_sensor_dev *dev, uint32_t address, uint32_t *pdata);
  137. int vvnative_sensor_init(struct vvcam_sensor_dev *dev);
  138. int vvnative_sensor_deinit(struct vvcam_sensor_dev *dev);
  139. long sensor_priv_ioctl(struct vvcam_sensor_dev *dev, unsigned int cmd, void __user *args);
  140. #endif