blob: a1f8f67f28858be3beb4d54caadb97e0433a4fd7 [file] [log] [blame]
Jigarkumar Zala35226272017-04-19 16:05:24 -07001/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef _CAM_FLASH_DEV_H_
15#define _CAM_FLASH_DEV_H_
16
17#include <linux/leds.h>
18#include <linux/platform_device.h>
19#include <linux/delay.h>
20#include <linux/io.h>
21#include <linux/of.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <media/v4l2-subdev.h>
25#include <media/v4l2-ioctl.h>
26#include <media/v4l2-event.h>
27#include <media/cam_sensor.h>
28#include <media/cam_req_mgr.h>
29#include "cam_req_mgr_util.h"
30#include "cam_req_mgr_interface.h"
31#include "cam_subdev.h"
32#include "cam_mem_mgr.h"
33#include "cam_sensor_cmn_header.h"
34#include "cam_soc_util.h"
35#include "cam_debug_util.h"
36
37#define CAMX_FLASH_DEV_NAME "cam-flash-dev"
38
39#define CAM_FLASH_PIPELINE_DELAY 1
40
41#define CAM_FLASH_PACKET_OPCODE_INIT 0
42#define CAM_FLASH_PACKET_OPCODE_SET_OPS 1
43#define CAM_FLASH_PACKET_OPCODE_NON_REALTIME_SET_OPS 2
44
45enum cam_flash_switch_trigger_ops {
46 LED_SWITCH_OFF = 0,
47 LED_SWITCH_ON,
48};
49
50enum cam_flash_state {
51 CAM_FLASH_STATE_INIT,
Soundrapandian Jeyaprakash8d16e272017-10-12 11:05:37 -070052 CAM_FLASH_STATE_ACQUIRE,
Karthik Anantha Ram4f5d66e2017-10-18 13:59:14 -070053 CAM_FLASH_STATE_START,
Jigarkumar Zala35226272017-04-19 16:05:24 -070054};
55
56/**
57 * struct cam_flash_intf_params
58 * @device_hdl : Device Handle
59 * @session_hdl : Session Handle
60 * @link_hdl : Link Handle
61 * @ops : KMD operations
62 * @crm_cb : Callback API pointers
63 */
64struct cam_flash_intf_params {
65 int32_t device_hdl;
66 int32_t session_hdl;
67 int32_t link_hdl;
68 struct cam_req_mgr_kmd_ops ops;
69 struct cam_req_mgr_crm_cb *crm_cb;
70};
71
72/**
73 * struct cam_flash_common_attr
74 * @is_settings_valid : Notify the valid settings
75 * @request_id : Request id provided by umd
76 * @count : Number of led count
77 * @cmd_type : Command buffer type
78 */
79struct cam_flash_common_attr {
80 bool is_settings_valid;
81 int32_t request_id;
82 uint16_t count;
83 uint8_t cmd_type;
84};
85
86/**
87 * struct flash_init_packet
88 * @cmn_attr : Provides common attributes
89 * @flash_type : Flash type(PMIC/I2C/GPIO)
90 */
91struct cam_flash_init_packet {
92 struct cam_flash_common_attr cmn_attr;
93 uint8_t flash_type;
94};
95
96/**
97 * struct flash_frame_setting
98 * @cmn_attr : Provides common attributes
99 * @num_iterations : Iterations used to perform RER
100 * @led_on_delay_ms : LED on time in milisec
101 * @led_off_delay_ms : LED off time in milisec
102 * @opcode : Command buffer opcode
103 * @led_current_ma[] : LED current array in miliamps
104 *
105 */
106struct cam_flash_frame_setting {
107 struct cam_flash_common_attr cmn_attr;
108 uint16_t num_iterations;
109 uint16_t led_on_delay_ms;
110 uint16_t led_off_delay_ms;
111 int8_t opcode;
112 uint32_t led_current_ma[CAM_FLASH_MAX_LED_TRIGGERS];
113};
114
115/**
116 * struct cam_flash_private_soc
117 * @switch_trigger_name : Switch trigger name
118 * @flash_trigger_name : Flash trigger name array
119 * @flash_op_current : Flash operational current
120 * @flash_max_current : Max supported current for LED in flash mode
121 * @flash_max_duration : Max turn on duration for LED in Flash mode
122 * @torch_trigger_name : Torch trigger name array
123 * @torch_op_current : Torch operational current
124 * @torch_max_current : Max supported current for LED in torch mode
125 */
126
127struct cam_flash_private_soc {
128 const char *switch_trigger_name;
129 const char *flash_trigger_name[CAM_FLASH_MAX_LED_TRIGGERS];
130 uint32_t flash_op_current[CAM_FLASH_MAX_LED_TRIGGERS];
131 uint32_t flash_max_current[CAM_FLASH_MAX_LED_TRIGGERS];
132 uint32_t flash_max_duration[CAM_FLASH_MAX_LED_TRIGGERS];
133 const char *torch_trigger_name[CAM_FLASH_MAX_LED_TRIGGERS];
134 uint32_t torch_op_current[CAM_FLASH_MAX_LED_TRIGGERS];
135 uint32_t torch_max_current[CAM_FLASH_MAX_LED_TRIGGERS];
136};
137
138/**
139 * struct cam_flash_ctrl
140 * @soc_info : Soc related information
141 * @pdev : Platform device
142 * @per_frame[] : Per_frame setting array
143 * @nrt_info : NonRealTime settings
144 * @of_node : Of Node ptr
145 * @v4l2_dev_str : V4L2 device structure
146 * @bridge_intf : CRM interface
147 * @flash_init_setting : Init command buffer structure
148 * @switch_trigger : Switch trigger ptr
149 * @flash_num_sources : Number of flash sources
150 * @torch_num_source : Number of torch sources
151 * @flash_mutex : Mutex for flash operations
152 * @flash_wq_mutex : Mutex for flash apply setting
153 * @flash_state : Current flash state (LOW/OFF/ON/INIT)
154 * @flash_type : Flash types (PMIC/I2C/GPIO)
155 * @is_regulator_enable : Regulator disable/enable notifier
156 * @flash_trigger : Flash trigger ptr
157 * @torch_trigger : Torch trigger ptr
158 */
159struct cam_flash_ctrl {
160 struct cam_hw_soc_info soc_info;
161 struct platform_device *pdev;
162 struct cam_flash_frame_setting per_frame[MAX_PER_FRAME_ARRAY];
163 struct cam_flash_frame_setting nrt_info;
164 struct device_node *of_node;
165 struct cam_subdev v4l2_dev_str;
166 struct cam_flash_intf_params bridge_intf;
167 struct cam_flash_init_packet flash_init_setting;
168 struct led_trigger *switch_trigger;
169 uint32_t flash_num_sources;
170 uint32_t torch_num_sources;
171 struct mutex flash_mutex;
172 struct mutex flash_wq_mutex;
173 enum cam_flash_state flash_state;
174 uint8_t flash_type;
175 bool is_regulator_enabled;
176 struct led_trigger *flash_trigger[CAM_FLASH_MAX_LED_TRIGGERS];
177 struct led_trigger *torch_trigger[CAM_FLASH_MAX_LED_TRIGGERS];
178};
179
180#endif /*_CAM_FLASH_DEV_H_*/