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