blob: 1583c270cbd554a1f775220762a4b1ddc51e7270 [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,
Jigarkumar Zala35226272017-04-19 16:05:24 -070053 CAM_FLASH_STATE_LOW,
54 CAM_FLASH_STATE_HIGH,
55 CAM_FLASH_STATE_RELEASE,
56};
57
58/**
59 * struct cam_flash_intf_params
60 * @device_hdl : Device Handle
61 * @session_hdl : Session Handle
62 * @link_hdl : Link Handle
63 * @ops : KMD operations
64 * @crm_cb : Callback API pointers
65 */
66struct cam_flash_intf_params {
67 int32_t device_hdl;
68 int32_t session_hdl;
69 int32_t link_hdl;
70 struct cam_req_mgr_kmd_ops ops;
71 struct cam_req_mgr_crm_cb *crm_cb;
72};
73
74/**
75 * struct cam_flash_common_attr
76 * @is_settings_valid : Notify the valid settings
77 * @request_id : Request id provided by umd
78 * @count : Number of led count
79 * @cmd_type : Command buffer type
80 */
81struct cam_flash_common_attr {
82 bool is_settings_valid;
83 int32_t request_id;
84 uint16_t count;
85 uint8_t cmd_type;
86};
87
88/**
89 * struct flash_init_packet
90 * @cmn_attr : Provides common attributes
91 * @flash_type : Flash type(PMIC/I2C/GPIO)
92 */
93struct cam_flash_init_packet {
94 struct cam_flash_common_attr cmn_attr;
95 uint8_t flash_type;
96};
97
98/**
99 * struct flash_frame_setting
100 * @cmn_attr : Provides common attributes
101 * @num_iterations : Iterations used to perform RER
102 * @led_on_delay_ms : LED on time in milisec
103 * @led_off_delay_ms : LED off time in milisec
104 * @opcode : Command buffer opcode
105 * @led_current_ma[] : LED current array in miliamps
106 *
107 */
108struct cam_flash_frame_setting {
109 struct cam_flash_common_attr cmn_attr;
110 uint16_t num_iterations;
111 uint16_t led_on_delay_ms;
112 uint16_t led_off_delay_ms;
113 int8_t opcode;
114 uint32_t led_current_ma[CAM_FLASH_MAX_LED_TRIGGERS];
115};
116
117/**
118 * struct cam_flash_private_soc
119 * @switch_trigger_name : Switch trigger name
120 * @flash_trigger_name : Flash trigger name array
121 * @flash_op_current : Flash operational current
122 * @flash_max_current : Max supported current for LED in flash mode
123 * @flash_max_duration : Max turn on duration for LED in Flash mode
124 * @torch_trigger_name : Torch trigger name array
125 * @torch_op_current : Torch operational current
126 * @torch_max_current : Max supported current for LED in torch mode
127 */
128
129struct cam_flash_private_soc {
130 const char *switch_trigger_name;
131 const char *flash_trigger_name[CAM_FLASH_MAX_LED_TRIGGERS];
132 uint32_t flash_op_current[CAM_FLASH_MAX_LED_TRIGGERS];
133 uint32_t flash_max_current[CAM_FLASH_MAX_LED_TRIGGERS];
134 uint32_t flash_max_duration[CAM_FLASH_MAX_LED_TRIGGERS];
135 const char *torch_trigger_name[CAM_FLASH_MAX_LED_TRIGGERS];
136 uint32_t torch_op_current[CAM_FLASH_MAX_LED_TRIGGERS];
137 uint32_t torch_max_current[CAM_FLASH_MAX_LED_TRIGGERS];
138};
139
140/**
141 * struct cam_flash_ctrl
142 * @soc_info : Soc related information
143 * @pdev : Platform device
144 * @per_frame[] : Per_frame setting array
145 * @nrt_info : NonRealTime settings
146 * @of_node : Of Node ptr
147 * @v4l2_dev_str : V4L2 device structure
148 * @bridge_intf : CRM interface
149 * @flash_init_setting : Init command buffer structure
150 * @switch_trigger : Switch trigger ptr
151 * @flash_num_sources : Number of flash sources
152 * @torch_num_source : Number of torch sources
153 * @flash_mutex : Mutex for flash operations
154 * @flash_wq_mutex : Mutex for flash apply setting
155 * @flash_state : Current flash state (LOW/OFF/ON/INIT)
156 * @flash_type : Flash types (PMIC/I2C/GPIO)
157 * @is_regulator_enable : Regulator disable/enable notifier
158 * @flash_trigger : Flash trigger ptr
159 * @torch_trigger : Torch trigger ptr
160 */
161struct cam_flash_ctrl {
162 struct cam_hw_soc_info soc_info;
163 struct platform_device *pdev;
164 struct cam_flash_frame_setting per_frame[MAX_PER_FRAME_ARRAY];
165 struct cam_flash_frame_setting nrt_info;
166 struct device_node *of_node;
167 struct cam_subdev v4l2_dev_str;
168 struct cam_flash_intf_params bridge_intf;
169 struct cam_flash_init_packet flash_init_setting;
170 struct led_trigger *switch_trigger;
171 uint32_t flash_num_sources;
172 uint32_t torch_num_sources;
173 struct mutex flash_mutex;
174 struct mutex flash_wq_mutex;
175 enum cam_flash_state flash_state;
176 uint8_t flash_type;
177 bool is_regulator_enabled;
178 struct led_trigger *flash_trigger[CAM_FLASH_MAX_LED_TRIGGERS];
179 struct led_trigger *torch_trigger[CAM_FLASH_MAX_LED_TRIGGERS];
180};
181
182#endif /*_CAM_FLASH_DEV_H_*/