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