cam_sensor.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __UAPI_CAM_SENSOR_H__
  6. #define __UAPI_CAM_SENSOR_H__
  7. #include <linux/types.h>
  8. #include <linux/ioctl.h>
  9. #include <media/cam_defs.h>
  10. #define CAM_SENSOR_PROBE_CMD (CAM_COMMON_OPCODE_MAX + 1)
  11. #define CAM_FLASH_MAX_LED_TRIGGERS 2
  12. #define MAX_OIS_NAME_SIZE 32
  13. #define CAM_CSIPHY_SECURE_MODE_ENABLED 1
  14. #define CAM_SENSOR_NAME_MAX_SIZE 32
  15. #define SKEW_CAL_MASK BIT(1)
  16. #define PREAMBLE_PATTEN_CAL_MASK BIT(2)
  17. enum camera_sensor_cmd_type {
  18. CAMERA_SENSOR_CMD_TYPE_INVALID,
  19. CAMERA_SENSOR_CMD_TYPE_PROBE,
  20. CAMERA_SENSOR_CMD_TYPE_PWR_UP,
  21. CAMERA_SENSOR_CMD_TYPE_PWR_DOWN,
  22. CAMERA_SENSOR_CMD_TYPE_I2C_INFO,
  23. CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_WR,
  24. CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_RD,
  25. CAMERA_SENSOR_CMD_TYPE_I2C_CONT_WR,
  26. CAMERA_SENSOR_CMD_TYPE_I2C_CONT_RD,
  27. CAMERA_SENSOR_CMD_TYPE_WAIT,
  28. CAMERA_SENSOR_FLASH_CMD_TYPE_INIT_INFO,
  29. CAMERA_SENSOR_FLASH_CMD_TYPE_FIRE,
  30. CAMERA_SENSOR_FLASH_CMD_TYPE_RER,
  31. CAMERA_SENSOR_FLASH_CMD_TYPE_QUERYCURR,
  32. CAMERA_SENSOR_FLASH_CMD_TYPE_WIDGET,
  33. CAMERA_SENSOR_CMD_TYPE_RD_DATA,
  34. CAMERA_SENSOR_FLASH_CMD_TYPE_INIT_FIRE,
  35. CAMERA_SENSOR_CMD_TYPE_MAX,
  36. };
  37. enum cam_actuator_packet_opcodes {
  38. CAM_ACTUATOR_PACKET_OPCODE_INIT,
  39. CAM_ACTUATOR_PACKET_AUTO_MOVE_LENS,
  40. CAM_ACTUATOR_PACKET_MANUAL_MOVE_LENS,
  41. CAM_ACTUATOR_PACKET_OPCODE_READ
  42. };
  43. enum cam_eeprom_packet_opcodes {
  44. CAM_EEPROM_PACKET_OPCODE_INIT,
  45. CAM_EEPROM_WRITE
  46. };
  47. enum cam_ois_packet_opcodes {
  48. CAM_OIS_PACKET_OPCODE_INIT,
  49. CAM_OIS_PACKET_OPCODE_OIS_CONTROL,
  50. CAM_OIS_PACKET_OPCODE_READ,
  51. CAM_OIS_PACKET_OPCODE_WRITE_TIME
  52. };
  53. enum camera_sensor_i2c_op_code {
  54. CAMERA_SENSOR_I2C_OP_INVALID,
  55. CAMERA_SENSOR_I2C_OP_RNDM_WR,
  56. CAMERA_SENSOR_I2C_OP_RNDM_WR_VERF,
  57. CAMERA_SENSOR_I2C_OP_CONT_WR_BRST,
  58. CAMERA_SENSOR_I2C_OP_CONT_WR_BRST_VERF,
  59. CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN,
  60. CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN_VERF,
  61. CAMERA_SENSOR_I2C_OP_MAX,
  62. };
  63. enum camera_sensor_wait_op_code {
  64. CAMERA_SENSOR_WAIT_OP_INVALID,
  65. CAMERA_SENSOR_WAIT_OP_COND,
  66. CAMERA_SENSOR_WAIT_OP_HW_UCND,
  67. CAMERA_SENSOR_WAIT_OP_SW_UCND,
  68. CAMERA_SENSOR_WAIT_OP_MAX,
  69. };
  70. enum cam_sensor_packet_opcodes {
  71. CAM_SENSOR_PACKET_OPCODE_SENSOR_STREAMON,
  72. CAM_SENSOR_PACKET_OPCODE_SENSOR_UPDATE,
  73. CAM_SENSOR_PACKET_OPCODE_SENSOR_INITIAL_CONFIG,
  74. CAM_SENSOR_PACKET_OPCODE_SENSOR_PROBE,
  75. CAM_SENSOR_PACKET_OPCODE_SENSOR_CONFIG,
  76. CAM_SENSOR_PACKET_OPCODE_SENSOR_STREAMOFF,
  77. CAM_SENSOR_PACKET_OPCODE_SENSOR_READ,
  78. CAM_SENSOR_PACKET_OPCODE_SENSOR_FRAME_SKIP_UPDATE,
  79. CAM_SENSOR_PACKET_OPCODE_SENSOR_PROBE_V2,
  80. CAM_SENSOR_PACKET_OPCODE_SENSOR_NOP = 127
  81. };
  82. /**
  83. * struct cam_sensor_query_cap - capabilities info for sensor
  84. *
  85. * @slot_info : Indicates about the slotId or cell Index
  86. * @secure_camera : Camera is in secure/Non-secure mode
  87. * @pos_pitch : Sensor position pitch
  88. * @pos_roll : Sensor position roll
  89. * @pos_yaw : Sensor position yaw
  90. * @actuator_slot_id : Actuator slot id which connected to sensor
  91. * @eeprom_slot_id : EEPROM slot id which connected to sensor
  92. * @ois_slot_id : OIS slot id which connected to sensor
  93. * @flash_slot_id : Flash slot id which connected to sensor
  94. * @csiphy_slot_id : CSIphy slot id which connected to sensor
  95. *
  96. */
  97. struct cam_sensor_query_cap {
  98. __u32 slot_info;
  99. __u32 secure_camera;
  100. __u32 pos_pitch;
  101. __u32 pos_roll;
  102. __u32 pos_yaw;
  103. __u32 actuator_slot_id;
  104. __u32 eeprom_slot_id;
  105. __u32 ois_slot_id;
  106. __u32 flash_slot_id;
  107. __u32 csiphy_slot_id;
  108. } __attribute__((packed));
  109. /**
  110. * struct cam_csiphy_query_cap - capabilities info for csiphy
  111. *
  112. * @slot_info : Indicates about the slotId or cell Index
  113. * @version : CSIphy version
  114. * @clk lane : Of the 5 lanes, informs lane configured
  115. * as clock lane
  116. * @reserved
  117. */
  118. struct cam_csiphy_query_cap {
  119. __u32 slot_info;
  120. __u32 version;
  121. __u32 clk_lane;
  122. __u32 reserved;
  123. } __attribute__((packed));
  124. /**
  125. * struct cam_actuator_query_cap - capabilities info for actuator
  126. *
  127. * @slot_info : Indicates about the slotId or cell Index
  128. * @reserved
  129. */
  130. struct cam_actuator_query_cap {
  131. __u32 slot_info;
  132. __u32 reserved;
  133. } __attribute__((packed));
  134. /**
  135. * struct cam_eeprom_query_cap_t - capabilities info for eeprom
  136. *
  137. * @slot_info : Indicates about the slotId or cell Index
  138. * @eeprom_kernel_probe : Indicates about the kernel or userspace probe
  139. */
  140. struct cam_eeprom_query_cap_t {
  141. __u32 slot_info;
  142. __u16 eeprom_kernel_probe;
  143. __u16 is_multimodule_mode;
  144. } __attribute__((packed));
  145. /**
  146. * struct cam_ois_query_cap_t - capabilities info for ois
  147. *
  148. * @slot_info : Indicates about the slotId or cell Index
  149. */
  150. struct cam_ois_query_cap_t {
  151. __u32 slot_info;
  152. __u16 reserved;
  153. } __attribute__((packed));
  154. /**
  155. * struct cam_cmd_i2c_info - Contains slave I2C related info
  156. *
  157. * @slave_addr : Slave address
  158. * @i2c_freq_mode : 4 bits are used for I2c freq mode
  159. * @cmd_type : Explains type of command
  160. */
  161. struct cam_cmd_i2c_info {
  162. __u32 slave_addr;
  163. __u8 i2c_freq_mode;
  164. __u8 cmd_type;
  165. __u16 reserved;
  166. } __attribute__((packed));
  167. /**
  168. * struct cam_ois_opcode - Contains OIS opcode
  169. *
  170. * @prog : OIS FW prog register address
  171. * @coeff : OIS FW coeff register address
  172. * @pheripheral : OIS pheripheral
  173. * @memory : OIS memory
  174. */
  175. struct cam_ois_opcode {
  176. __u32 prog;
  177. __u32 coeff;
  178. __u32 pheripheral;
  179. __u32 memory;
  180. } __attribute__((packed));
  181. /**
  182. * struct cam_cmd_ois_info - Contains OIS slave info
  183. *
  184. * @slave_addr : OIS i2c slave address
  185. * @i2c_freq_mode : i2c frequency mode
  186. * @cmd_type : Explains type of command
  187. * @ois_fw_flag : indicates if fw is present or not
  188. * @is_ois_calib : indicates the calibration data is available
  189. * @ois_name : OIS name
  190. * @opcode : opcode
  191. */
  192. struct cam_cmd_ois_info {
  193. __u32 slave_addr;
  194. __u8 i2c_freq_mode;
  195. __u8 cmd_type;
  196. __u8 ois_fw_flag;
  197. __u8 is_ois_calib;
  198. char ois_name[MAX_OIS_NAME_SIZE];
  199. struct cam_ois_opcode opcode;
  200. } __attribute__((packed));
  201. /**
  202. * struct cam_cmd_probe - Contains sensor slave info
  203. *
  204. * @data_type : Slave register data type
  205. * @addr_type : Slave register address type
  206. * @op_code : Don't Care
  207. * @cmd_type : Explains type of command
  208. * @reg_addr : Slave register address
  209. * @expected_data : Data expected at slave register address
  210. * @data_mask : Data mask if only few bits are valid
  211. * @camera_id : Indicates the slot to which camera
  212. * needs to be probed
  213. * @reserved
  214. */
  215. struct cam_cmd_probe {
  216. __u8 data_type;
  217. __u8 addr_type;
  218. __u8 op_code;
  219. __u8 cmd_type;
  220. __u32 reg_addr;
  221. __u32 expected_data;
  222. __u32 data_mask;
  223. __u16 camera_id;
  224. __u16 reserved;
  225. } __attribute__((packed));
  226. /**
  227. * struct cam_cmd_probe_v2 - Contains sensor slave info version 2
  228. *
  229. * @data_type : Slave register data type
  230. * @addr_type : Slave register address type
  231. * @op_code : Don't Care
  232. * @cmd_type : Explains type of command
  233. * @reg_addr : Slave register address
  234. * @expected_data : Data expected at slave register address
  235. * @data_mask : Data mask if only few bits are valid
  236. * @camera_id : Indicates the slot to which camera
  237. * needs to be probed
  238. * @pipeline_delay : Pipeline delay
  239. * @logical_camera_id : Logical Camera ID
  240. * @sensor_name : Sensor's name
  241. * @reserved
  242. */
  243. struct cam_cmd_probe_v2 {
  244. __u8 data_type;
  245. __u8 addr_type;
  246. __u8 op_code;
  247. __u8 cmd_type;
  248. __u32 reg_addr;
  249. __u32 expected_data;
  250. __u32 data_mask;
  251. __u16 camera_id;
  252. __u16 pipeline_delay;
  253. __u32 logical_camera_id;
  254. char sensor_name[CAM_SENSOR_NAME_MAX_SIZE];
  255. __u32 reserved[4];
  256. } __attribute__((packed));
  257. /**
  258. * struct cam_power_settings - Contains sensor power setting info
  259. *
  260. * @power_seq_type : Type of power sequence
  261. * @reserved
  262. * @config_val_low : Lower 32 bit value configuration value
  263. * @config_val_high : Higher 32 bit value configuration value
  264. *
  265. */
  266. struct cam_power_settings {
  267. __u16 power_seq_type;
  268. __u16 reserved;
  269. __u32 config_val_low;
  270. __u32 config_val_high;
  271. } __attribute__((packed));
  272. /**
  273. * struct cam_cmd_power - Explains about the power settings
  274. *
  275. * @count : Number of power settings follows
  276. * @reserved
  277. * @cmd_type : Explains type of command
  278. * @power_settings : Contains power setting info
  279. */
  280. struct cam_cmd_power {
  281. __u32 count;
  282. __u8 reserved;
  283. __u8 cmd_type;
  284. __u16 more_reserved;
  285. struct cam_power_settings power_settings[1];
  286. } __attribute__((packed));
  287. /**
  288. * struct i2c_rdwr_header - header of READ/WRITE I2C command
  289. *
  290. * @ count : Number of registers / data / reg-data pairs
  291. * @ op_code : Operation code
  292. * @ cmd_type : Command buffer type
  293. * @ data_type : I2C data type
  294. * @ addr_type : I2C address type
  295. * @ reserved
  296. */
  297. struct i2c_rdwr_header {
  298. __u32 count;
  299. __u8 op_code;
  300. __u8 cmd_type;
  301. __u8 data_type;
  302. __u8 addr_type;
  303. } __attribute__((packed));
  304. /**
  305. * struct i2c_random_wr_payload - payload for I2C random write
  306. *
  307. * @ reg_addr : Register address
  308. * @ reg_data : Register data
  309. *
  310. */
  311. struct i2c_random_wr_payload {
  312. __u32 reg_addr;
  313. __u32 reg_data;
  314. } __attribute__((packed));
  315. /**
  316. * struct cam_cmd_i2c_random_wr - I2C random write command
  317. * @ header : header of READ/WRITE I2C command
  318. * @ random_wr_payload : payload for I2C random write
  319. */
  320. struct cam_cmd_i2c_random_wr {
  321. struct i2c_rdwr_header header;
  322. struct i2c_random_wr_payload random_wr_payload[1];
  323. } __attribute__((packed));
  324. /**
  325. * struct cam_cmd_read - I2C read command
  326. * @ reg_data : Register data
  327. * @ reserved
  328. */
  329. struct cam_cmd_read {
  330. __u32 reg_data;
  331. __u32 reserved;
  332. } __attribute__((packed));
  333. /**
  334. * struct cam_cmd_i2c_continuous_wr - I2C continuous write command
  335. * @ header : header of READ/WRITE I2C command
  336. * @ reg_addr : Register address
  337. * @ data_read : I2C read command
  338. */
  339. struct cam_cmd_i2c_continuous_wr {
  340. struct i2c_rdwr_header header;
  341. __u32 reg_addr;
  342. struct cam_cmd_read data_read[1];
  343. } __attribute__((packed));
  344. /**
  345. * struct cam_cmd_i2c_random_rd - I2C random read command
  346. * @ header : header of READ/WRITE I2C command
  347. * @ data_read : I2C read command
  348. */
  349. struct cam_cmd_i2c_random_rd {
  350. struct i2c_rdwr_header header;
  351. struct cam_cmd_read data_read[1];
  352. } __attribute__((packed));
  353. /**
  354. * struct cam_cmd_i2c_continuous_rd - I2C continuous continuous read command
  355. * @ header : header of READ/WRITE I2C command
  356. * @ reg_addr : Register address
  357. *
  358. */
  359. struct cam_cmd_i2c_continuous_rd {
  360. struct i2c_rdwr_header header;
  361. __u32 reg_addr;
  362. } __attribute__((packed));
  363. /**
  364. * struct cam_cmd_conditional_wait - Conditional wait command
  365. * @data_type : Data type
  366. * @addr_type : Address type
  367. * @op_code : Opcode
  368. * @cmd_type : Explains type of command
  369. * @timeout : Timeout for retries
  370. * @reserved
  371. * @reg_addr : Register Address
  372. * @reg_data : Register data
  373. * @data_mask : Data mask if only few bits are valid
  374. * @camera_id : Indicates the slot to which camera
  375. * needs to be probed
  376. *
  377. */
  378. struct cam_cmd_conditional_wait {
  379. __u8 data_type;
  380. __u8 addr_type;
  381. __u16 reserved;
  382. __u8 op_code;
  383. __u8 cmd_type;
  384. __u16 timeout;
  385. __u32 reg_addr;
  386. __u32 reg_data;
  387. __u32 data_mask;
  388. } __attribute__((packed));
  389. /**
  390. * struct cam_cmd_unconditional_wait - Un-conditional wait command
  391. * @delay : Delay
  392. * @op_code : Opcode
  393. * @cmd_type : Explains type of command
  394. */
  395. struct cam_cmd_unconditional_wait {
  396. __s16 delay;
  397. __s16 reserved;
  398. __u8 op_code;
  399. __u8 cmd_type;
  400. __u16 reserved1;
  401. } __attribute__((packed));
  402. /**
  403. * cam_csiphy_info : Provides cmdbuffer structre
  404. * @lane_assign : Lane sensor will be using
  405. * @mipi_flags : Phy flags for differnt calibration operations
  406. * @lane_cnt : Total number of lanes
  407. * @secure_mode : Secure mode flag to enable / disable
  408. * @settle_time : Settling time in ms
  409. * @data_rate : Data rate
  410. *
  411. */
  412. struct cam_csiphy_info {
  413. __u16 reserved;
  414. __u16 lane_assign;
  415. __u16 mipi_flags;
  416. __u8 lane_cnt;
  417. __u8 secure_mode;
  418. __u64 settle_time;
  419. __u64 data_rate;
  420. } __attribute__((packed));
  421. /**
  422. * cam_csiphy_acquire_dev_info : Information needed for
  423. * csiphy at the time of acquire
  424. * @combo_mode : Indicates the device mode of operation
  425. * @cphy_dphy_combo_mode : Info regarding cphy_dphy_combo mode
  426. * @csiphy_3phase : Details whether 3Phase / 2Phase operation
  427. * @reserve
  428. *
  429. */
  430. struct cam_csiphy_acquire_dev_info {
  431. __u32 combo_mode;
  432. __u16 cphy_dphy_combo_mode;
  433. __u8 csiphy_3phase;
  434. __u8 reserve;
  435. } __attribute__((packed));
  436. /**
  437. * cam_sensor_acquire_dev : Updates sensor acuire cmd
  438. * @device_handle : Updates device handle
  439. * @session_handle : Session handle for acquiring device
  440. * @handle_type : Resource handle type
  441. * @reserved
  442. * @info_handle : Handle to additional info
  443. * needed for sensor sub modules
  444. *
  445. */
  446. struct cam_sensor_acquire_dev {
  447. __u32 session_handle;
  448. __u32 device_handle;
  449. __u32 handle_type;
  450. __u32 reserved;
  451. __u64 info_handle;
  452. } __attribute__((packed));
  453. /**
  454. * cam_sensor_streamon_dev : StreamOn command for the sensor
  455. * @session_handle : Session handle for acquiring device
  456. * @device_handle : Updates device handle
  457. * @handle_type : Resource handle type
  458. * @reserved
  459. * @info_handle : Information Needed at the time of streamOn
  460. *
  461. */
  462. struct cam_sensor_streamon_dev {
  463. __u32 session_handle;
  464. __u32 device_handle;
  465. __u32 handle_type;
  466. __u32 reserved;
  467. __u64 info_handle;
  468. } __attribute__((packed));
  469. /**
  470. * struct cam_flash_init : Init command for the flash
  471. * @flash_type : flash hw type
  472. * @reserved
  473. * @cmd_type : command buffer type
  474. */
  475. struct cam_flash_init {
  476. __u32 flash_type;
  477. __u8 reserved;
  478. __u8 cmd_type;
  479. __u16 reserved1;
  480. } __attribute__((packed));
  481. /**
  482. * struct cam_flash_set_rer : RedEyeReduction command buffer
  483. *
  484. * @count : Number of flash leds
  485. * @opcode : Command buffer opcode
  486. * CAM_FLASH_FIRE_RER
  487. * @cmd_type : command buffer operation type
  488. * @num_iteration : Number of led turn on/off sequence
  489. * @reserved
  490. * @led_on_delay_ms : flash led turn on time in ms
  491. * @led_off_delay_ms : flash led turn off time in ms
  492. * @led_current_ma : flash led current in ma
  493. *
  494. */
  495. struct cam_flash_set_rer {
  496. __u32 count;
  497. __u8 opcode;
  498. __u8 cmd_type;
  499. __u16 num_iteration;
  500. __u32 led_on_delay_ms;
  501. __u32 led_off_delay_ms;
  502. __u32 led_current_ma[CAM_FLASH_MAX_LED_TRIGGERS];
  503. } __attribute__((packed));
  504. /**
  505. * struct cam_flash_set_on_off : led turn on/off command buffer
  506. *
  507. * @count : Number of Flash leds
  508. * @opcode : Command buffer opcodes
  509. * CAM_FLASH_FIRE_LOW
  510. * CAM_FLASH_FIRE_HIGH
  511. * CAM_FLASH_OFF
  512. * @cmd_type : Command buffer operation type
  513. * @led_current_ma : Flash led current in ma
  514. * @time_on_duration_ns : Flash time on duration in ns
  515. * @led_on_wait_time_ns : Flash led turn on wait time in ns
  516. *
  517. */
  518. struct cam_flash_set_on_off {
  519. __u32 count;
  520. __u8 opcode;
  521. __u8 cmd_type;
  522. __u16 reserved;
  523. __u32 led_current_ma[CAM_FLASH_MAX_LED_TRIGGERS];
  524. __u64 time_on_duration_ns;
  525. __u64 led_on_wait_time_ns;
  526. } __attribute__((packed));
  527. /**
  528. * struct cam_flash_query_curr : query current command buffer
  529. *
  530. * @reserved
  531. * @opcode : command buffer opcode
  532. * @cmd_type : command buffer operation type
  533. * @query_current_ma : battery current in ma
  534. *
  535. */
  536. struct cam_flash_query_curr {
  537. __u16 reserved;
  538. __u8 opcode;
  539. __u8 cmd_type;
  540. __u32 query_current_ma;
  541. } __attribute__ ((packed));
  542. /**
  543. * struct cam_flash_query_cap : capabilities info for flash
  544. *
  545. * @slot_info : Indicates about the slotId or cell Index
  546. * @max_current_flash : max supported current for flash
  547. * @max_duration_flash : max flash turn on duration
  548. * @max_current_torch : max supported current for torch
  549. *
  550. */
  551. struct cam_flash_query_cap_info {
  552. __u32 slot_info;
  553. __u32 max_current_flash[CAM_FLASH_MAX_LED_TRIGGERS];
  554. __u32 max_duration_flash[CAM_FLASH_MAX_LED_TRIGGERS];
  555. __u32 max_current_torch[CAM_FLASH_MAX_LED_TRIGGERS];
  556. } __attribute__ ((packed));
  557. #endif