• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * drivers/media/i2c/smiapp/smiapp.h
4  *
5  * Generic driver for SMIA/SMIA++ compliant camera modules
6  *
7  * Copyright (C) 2010--2012 Nokia Corporation
8  * Contact: Sakari Ailus <sakari.ailus@iki.fi>
9  */
10 
11 #ifndef __SMIAPP_PRIV_H_
12 #define __SMIAPP_PRIV_H_
13 
14 #include <linux/mutex.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-subdev.h>
17 #include <media/i2c/smiapp.h>
18 
19 #include "smiapp-pll.h"
20 #include "smiapp-reg.h"
21 #include "smiapp-regs.h"
22 #include "smiapp-quirk.h"
23 
24 /*
25  * Standard SMIA++ constants
26  */
27 #define SMIA_VERSION_1			10
28 #define SMIAPP_VERSION_0_8		8 /* Draft 0.8 */
29 #define SMIAPP_VERSION_0_9		9 /* Draft 0.9 */
30 #define SMIAPP_VERSION_1		10
31 
32 #define SMIAPP_PROFILE_0		0
33 #define SMIAPP_PROFILE_1		1
34 #define SMIAPP_PROFILE_2		2
35 
36 #define SMIAPP_NVM_PAGE_SIZE		64	/* bytes */
37 
38 #define SMIAPP_RESET_DELAY_CLOCKS	2400
39 #define SMIAPP_RESET_DELAY(clk)				\
40 	(1000 +	(SMIAPP_RESET_DELAY_CLOCKS * 1000	\
41 		 + (clk) / 1000 - 1) / ((clk) / 1000))
42 
43 #define SMIAPP_COLOUR_COMPONENTS	4
44 
45 #include "smiapp-limits.h"
46 
47 struct smiapp_quirk;
48 
49 #define SMIAPP_MODULE_IDENT_FLAG_REV_LE		(1 << 0)
50 
51 struct smiapp_module_ident {
52 	u8 manufacturer_id;
53 	u16 model_id;
54 	u8 revision_number_major;
55 
56 	u8 flags;
57 
58 	char *name;
59 	const struct smiapp_quirk *quirk;
60 };
61 
62 struct smiapp_module_info {
63 	u32 manufacturer_id;
64 	u32 model_id;
65 	u32 revision_number_major;
66 	u32 revision_number_minor;
67 
68 	u32 module_year;
69 	u32 module_month;
70 	u32 module_day;
71 
72 	u32 sensor_manufacturer_id;
73 	u32 sensor_model_id;
74 	u32 sensor_revision_number;
75 	u32 sensor_firmware_version;
76 
77 	u32 smia_version;
78 	u32 smiapp_version;
79 
80 	u32 smiapp_profile;
81 
82 	char *name;
83 	const struct smiapp_quirk *quirk;
84 };
85 
86 #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk)	\
87 	{ .manufacturer_id = manufacturer,				\
88 	  .model_id = model,						\
89 	  .revision_number_major = rev,					\
90 	  .flags = fl,							\
91 	  .name = _name,						\
92 	  .quirk = _quirk, }
93 
94 #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk)	\
95 	{ .manufacturer_id = manufacturer,				\
96 	  .model_id = model,						\
97 	  .revision_number_major = rev,					\
98 	  .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,			\
99 	  .name = _name,						\
100 	  .quirk = _quirk, }
101 
102 #define SMIAPP_IDENT_L(manufacturer, model, rev, _name)			\
103 	{ .manufacturer_id = manufacturer,				\
104 	  .model_id = model,						\
105 	  .revision_number_major = rev,					\
106 	  .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE,			\
107 	  .name = _name, }
108 
109 #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk)		\
110 	{ .manufacturer_id = manufacturer,				\
111 	  .model_id = model,						\
112 	  .revision_number_major = rev,					\
113 	  .flags = 0,							\
114 	  .name = _name,						\
115 	  .quirk = _quirk, }
116 
117 #define SMIAPP_IDENT(manufacturer, model, rev, _name)			\
118 	{ .manufacturer_id = manufacturer,				\
119 	  .model_id = model,						\
120 	  .revision_number_major = rev,					\
121 	  .flags = 0,							\
122 	  .name = _name, }
123 
124 struct smiapp_reg_limits {
125 	u32 addr;
126 	char *what;
127 };
128 
129 extern struct smiapp_reg_limits smiapp_reg_limits[];
130 
131 struct smiapp_csi_data_format {
132 	u32 code;
133 	u8 width;
134 	u8 compressed;
135 	u8 pixel_order;
136 };
137 
138 #define SMIAPP_SUBDEVS			3
139 
140 #define SMIAPP_PA_PAD_SRC		0
141 #define SMIAPP_PAD_SINK			0
142 #define SMIAPP_PAD_SRC			1
143 #define SMIAPP_PADS			2
144 
145 struct smiapp_binning_subtype {
146 	u8 horizontal:4;
147 	u8 vertical:4;
148 } __packed;
149 
150 struct smiapp_subdev {
151 	struct v4l2_subdev sd;
152 	struct media_pad pads[SMIAPP_PADS];
153 	struct v4l2_rect sink_fmt;
154 	struct v4l2_rect crop[SMIAPP_PADS];
155 	struct v4l2_rect compose; /* compose on sink */
156 	unsigned short sink_pad;
157 	unsigned short source_pad;
158 	int npads;
159 	struct smiapp_sensor *sensor;
160 	struct v4l2_ctrl_handler ctrl_handler;
161 };
162 
163 /*
164  * struct smiapp_sensor - Main device structure
165  */
166 struct smiapp_sensor {
167 	/*
168 	 * "mutex" is used to serialise access to all fields here
169 	 * except v4l2_ctrls at the end of the struct. "mutex" is also
170 	 * used to serialise access to file handle specific
171 	 * information.
172 	 */
173 	struct mutex mutex;
174 	struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
175 	u32 ssds_used;
176 	struct smiapp_subdev *src;
177 	struct smiapp_subdev *binner;
178 	struct smiapp_subdev *scaler;
179 	struct smiapp_subdev *pixel_array;
180 	struct smiapp_hwconfig *hwcfg;
181 	struct regulator *vana;
182 	struct clk *ext_clk;
183 	struct gpio_desc *xshutdown;
184 	u32 limits[SMIAPP_LIMIT_LAST];
185 	u8 nbinning_subtypes;
186 	struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
187 	u32 mbus_frame_fmts;
188 	const struct smiapp_csi_data_format *csi_format;
189 	const struct smiapp_csi_data_format *internal_csi_format;
190 	u32 default_mbus_frame_fmts;
191 	int default_pixel_order;
192 
193 	u8 binning_horizontal;
194 	u8 binning_vertical;
195 
196 	u8 scale_m;
197 	u8 scaling_mode;
198 
199 	u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
200 	u8 frame_skip;
201 	bool active; /* is the sensor powered on? */
202 	u16 embedded_start; /* embedded data start line */
203 	u16 embedded_end;
204 	u16 image_start; /* image data start line */
205 	u16 visible_pixel_start; /* start pixel of the visible image */
206 
207 	bool streaming;
208 	bool dev_init_done;
209 	u8 compressed_min_bpp;
210 
211 	u8 *nvm;		/* nvm memory buffer */
212 	unsigned int nvm_size;	/* bytes */
213 
214 	struct smiapp_module_info minfo;
215 
216 	struct smiapp_pll pll;
217 
218 	/* Is a default format supported for a given BPP? */
219 	unsigned long *valid_link_freqs;
220 
221 	/* Pixel array controls */
222 	struct v4l2_ctrl *analog_gain;
223 	struct v4l2_ctrl *exposure;
224 	struct v4l2_ctrl *hflip;
225 	struct v4l2_ctrl *vflip;
226 	struct v4l2_ctrl *vblank;
227 	struct v4l2_ctrl *hblank;
228 	struct v4l2_ctrl *pixel_rate_parray;
229 	/* src controls */
230 	struct v4l2_ctrl *link_freq;
231 	struct v4l2_ctrl *pixel_rate_csi;
232 	/* test pattern colour components */
233 	struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS];
234 };
235 
236 #define to_smiapp_subdev(_sd)				\
237 	container_of(_sd, struct smiapp_subdev, sd)
238 
239 #define to_smiapp_sensor(_sd)	\
240 	(to_smiapp_subdev(_sd)->sensor)
241 
242 #endif /* __SMIAPP_PRIV_H_ */
243