88#include "isp-fw.h"
99#include "isp-iommu.h"
1010
11+ #define ISP_MAX_PRESETS 32
12+
1113struct isp_setfile {
1214 u32 version ;
1315 u32 magic ;
1416 const char * path ;
1517 size_t size ;
1618};
1719
18- struct isp_preset {
19- u32 index ;
20- u32 width ;
21- u32 height ;
22- u32 x1 ;
23- u32 y1 ;
24- u32 x2 ;
25- u32 y2 ;
26- u32 orig_width ;
27- u32 orig_height ;
28- };
29-
3020// clang-format off
3121static const struct isp_setfile isp_setfiles [] = {
32- [ISP_IMX248_1820_01 ] = {0x248 , 0x18200103 , "isp/1820_01XX.dat" , 0x442c },
33- [ISP_IMX248_1822_02 ] = {0x248 , 0x18220201 , "isp/1822_02XX.dat" , 0x442c },
34- [ISP_IMX343_5221_02 ] = {0x343 , 0x52210211 , "isp/5221_02XX.dat" , 0x4870 },
35- [ISP_IMX354_9251_02 ] = {0x354 , 0x92510208 , "isp/9251_02XX.dat" , 0xa5ec },
36- [ISP_IMX356_4820_01 ] = {0x356 , 0x48200107 , "isp/4820_01XX.dat" , 0x9324 },
37- [ISP_IMX356_4820_02 ] = {0x356 , 0x48200206 , "isp/4820_02XX.dat" , 0x9324 },
38- [ISP_IMX364_8720_01 ] = {0x364 , 0x87200103 , "isp/8720_01XX.dat" , 0x36ac },
39- [ISP_IMX364_8723_01 ] = {0x364 , 0x87230101 , "isp/8723_01XX.dat" , 0x361c },
40- [ISP_IMX372_3820_01 ] = {0x372 , 0x38200108 , "isp/3820_01XX.dat" , 0xfdb0 },
41- [ISP_IMX372_3820_02 ] = {0x372 , 0x38200205 , "isp/3820_02XX.dat" , 0xfdb0 },
42- [ISP_IMX372_3820_11 ] = {0x372 , 0x38201104 , "isp/3820_11XX.dat" , 0xfdb0 },
43- [ISP_IMX372_3820_12 ] = {0x372 , 0x38201204 , "isp/3820_12XX.dat" , 0xfdb0 },
44- [ISP_IMX405_9720_01 ] = {0x405 , 0x97200102 , "isp/9720_01XX.dat" , 0x92c8 },
45- [ISP_IMX405_9721_01 ] = {0x405 , 0x97210102 , "isp/9721_01XX.dat" , 0x9818 },
46- [ISP_IMX405_9723_01 ] = {0x405 , 0x97230101 , "isp/9723_01XX.dat" , 0x92c8 },
47- [ISP_IMX414_2520_01 ] = {0x414 , 0x25200102 , "isp/2520_01XX.dat" , 0xa444 },
48- [ISP_IMX503_7820_01 ] = {0x503 , 0x78200109 , "isp/7820_01XX.dat" , 0xb268 },
49- [ISP_IMX503_7820_02 ] = {0x503 , 0x78200206 , "isp/7820_02XX.dat" , 0xb268 },
50- [ISP_IMX505_3921_01 ] = {0x505 , 0x39210102 , "isp/3921_01XX.dat" , 0x89b0 },
51- [ISP_IMX514_2820_01 ] = {0x514 , 0x28200108 , "isp/2820_01XX.dat" , 0xa198 },
52- [ISP_IMX514_2820_02 ] = {0x514 , 0x28200205 , "isp/2820_02XX.dat" , 0xa198 },
53- [ISP_IMX514_2820_03 ] = {0x514 , 0x28200305 , "isp/2820_03XX.dat" , 0xa198 },
54- [ISP_IMX514_2820_04 ] = {0x514 , 0x28200405 , "isp/2820_04XX.dat" , 0xa198 },
55- [ISP_IMX558_1921_01 ] = {0x558 , 0x19210106 , "isp/1921_01XX.dat" , 0xad40 },
56- [ISP_IMX558_1922_02 ] = {0x558 , 0x19220201 , "isp/1922_02XX.dat" , 0xad40 },
57- [ISP_IMX603_7920_01 ] = {0x603 , 0x79200109 , "isp/7920_01XX.dat" , 0xad2c },
58- [ISP_IMX603_7920_02 ] = {0x603 , 0x79200205 , "isp/7920_02XX.dat" , 0xad2c },
59- [ISP_IMX603_7921_01 ] = {0x603 , 0x79210104 , "isp/7921_01XX.dat" , 0xad90 },
60- [ISP_IMX613_4920_01 ] = {0x613 , 0x49200108 , "isp/4920_01XX.dat" , 0x9324 },
61- [ISP_IMX613_4920_02 ] = {0x613 , 0x49200204 , "isp/4920_02XX.dat" , 0x9324 },
62- [ISP_IMX614_2921_01 ] = {0x614 , 0x29210107 , "isp/2921_01XX.dat" , 0xed6c },
63- [ISP_IMX614_2921_02 ] = {0x614 , 0x29210202 , "isp/2921_02XX.dat" , 0xed6c },
64- [ISP_IMX614_2922_02 ] = {0x614 , 0x29220201 , "isp/2922_02XX.dat" , 0xed6c },
65- [ISP_IMX633_3622_01 ] = {0x633 , 0x36220111 , "isp/3622_01XX.dat" , 0x100d4 },
66- [ISP_IMX703_7721_01 ] = {0x703 , 0x77210106 , "isp/7721_01XX.dat" , 0x936c },
67- [ISP_IMX703_7722_01 ] = {0x703 , 0x77220106 , "isp/7722_01XX.dat" , 0xac20 },
68- [ISP_IMX713_4721_01 ] = {0x713 , 0x47210107 , "isp/4721_01XX.dat" , 0x936c },
69- [ISP_IMX713_4722_01 ] = {0x713 , 0x47220109 , "isp/4722_01XX.dat" , 0x9218 },
70- [ISP_IMX714_2022_01 ] = {0x714 , 0x20220107 , "isp/2022_01XX.dat" , 0xa198 },
71- [ISP_IMX772_3721_01 ] = {0x772 , 0x37210106 , "isp/3721_01XX.dat" , 0xfdf8 },
72- [ISP_IMX772_3721_11 ] = {0x772 , 0x37211106 , "isp/3721_11XX.dat" , 0xfe14 },
73- [ISP_IMX772_3722_01 ] = {0x772 , 0x37220104 , "isp/3722_01XX.dat" , 0xfca4 },
74- [ISP_IMX772_3723_01 ] = {0x772 , 0x37230106 , "isp/3723_01XX.dat" , 0xfca4 },
75- [ISP_IMX814_2123_01 ] = {0x814 , 0x21230101 , "isp/2123_01XX.dat" , 0xed54 },
76- [ISP_IMX853_7622_01 ] = {0x853 , 0x76220112 , "isp/7622_01XX.dat" , 0x247f8 },
77- [ISP_IMX913_7523_01 ] = {0x913 , 0x75230107 , "isp/7523_01XX.dat" , 0x247f8 },
78- [ISP_VD56G0_6221_01 ] = {0xd56 , 0x62210102 , "isp/6221_01XX.dat" , 0x1b80 },
79- [ISP_VD56G0_6222_01 ] = {0xd56 , 0x62220102 , "isp/6222_01XX.dat" , 0x1b80 },
80- };
81-
82- // one day we will do this intelligently
83- static const struct isp_preset isp_presets [] = {
84- [ISP_IMX248_1820_01 ] = {0 , 1280 , 720 , 8 , 8 , 1280 , 720 , 1296 , 736 }, // J293AP
85- [ISP_IMX558_1921_01 ] = {1 , 1920 , 1080 , 0 , 0 , 1920 , 1080 , 1920 , 1080 }, // J316sAP, J415AP
22+ [ISP_IMX248_1820_01 ] = {0x248 , 0x18200103 , "apple/isp_1820_01XX.dat" , 0x442c },
23+ [ISP_IMX248_1822_02 ] = {0x248 , 0x18220201 , "apple/isp_1822_02XX.dat" , 0x442c },
24+ [ISP_IMX343_5221_02 ] = {0x343 , 0x52210211 , "apple/isp_5221_02XX.dat" , 0x4870 },
25+ [ISP_IMX354_9251_02 ] = {0x354 , 0x92510208 , "apple/isp_9251_02XX.dat" , 0xa5ec },
26+ [ISP_IMX356_4820_01 ] = {0x356 , 0x48200107 , "apple/isp_4820_01XX.dat" , 0x9324 },
27+ [ISP_IMX356_4820_02 ] = {0x356 , 0x48200206 , "apple/isp_4820_02XX.dat" , 0x9324 },
28+ [ISP_IMX364_8720_01 ] = {0x364 , 0x87200103 , "apple/isp_8720_01XX.dat" , 0x36ac },
29+ [ISP_IMX364_8723_01 ] = {0x364 , 0x87230101 , "apple/isp_8723_01XX.dat" , 0x361c },
30+ [ISP_IMX372_3820_01 ] = {0x372 , 0x38200108 , "apple/isp_3820_01XX.dat" , 0xfdb0 },
31+ [ISP_IMX372_3820_02 ] = {0x372 , 0x38200205 , "apple/isp_3820_02XX.dat" , 0xfdb0 },
32+ [ISP_IMX372_3820_11 ] = {0x372 , 0x38201104 , "apple/isp_3820_11XX.dat" , 0xfdb0 },
33+ [ISP_IMX372_3820_12 ] = {0x372 , 0x38201204 , "apple/isp_3820_12XX.dat" , 0xfdb0 },
34+ [ISP_IMX405_9720_01 ] = {0x405 , 0x97200102 , "apple/isp_9720_01XX.dat" , 0x92c8 },
35+ [ISP_IMX405_9721_01 ] = {0x405 , 0x97210102 , "apple/isp_9721_01XX.dat" , 0x9818 },
36+ [ISP_IMX405_9723_01 ] = {0x405 , 0x97230101 , "apple/isp_9723_01XX.dat" , 0x92c8 },
37+ [ISP_IMX414_2520_01 ] = {0x414 , 0x25200102 , "apple/isp_2520_01XX.dat" , 0xa444 },
38+ [ISP_IMX503_7820_01 ] = {0x503 , 0x78200109 , "apple/isp_7820_01XX.dat" , 0xb268 },
39+ [ISP_IMX503_7820_02 ] = {0x503 , 0x78200206 , "apple/isp_7820_02XX.dat" , 0xb268 },
40+ [ISP_IMX505_3921_01 ] = {0x505 , 0x39210102 , "apple/isp_3921_01XX.dat" , 0x89b0 },
41+ [ISP_IMX514_2820_01 ] = {0x514 , 0x28200108 , "apple/isp_2820_01XX.dat" , 0xa198 },
42+ [ISP_IMX514_2820_02 ] = {0x514 , 0x28200205 , "apple/isp_2820_02XX.dat" , 0xa198 },
43+ [ISP_IMX514_2820_03 ] = {0x514 , 0x28200305 , "apple/isp_2820_03XX.dat" , 0xa198 },
44+ [ISP_IMX514_2820_04 ] = {0x514 , 0x28200405 , "apple/isp_2820_04XX.dat" , 0xa198 },
45+ [ISP_IMX558_1921_01 ] = {0x558 , 0x19210106 , "apple/isp_1921_01XX.dat" , 0xad40 },
46+ [ISP_IMX558_1922_02 ] = {0x558 , 0x19220201 , "apple/isp_1922_02XX.dat" , 0xad40 },
47+ [ISP_IMX603_7920_01 ] = {0x603 , 0x79200109 , "apple/isp_7920_01XX.dat" , 0xad2c },
48+ [ISP_IMX603_7920_02 ] = {0x603 , 0x79200205 , "apple/isp_7920_02XX.dat" , 0xad2c },
49+ [ISP_IMX603_7921_01 ] = {0x603 , 0x79210104 , "apple/isp_7921_01XX.dat" , 0xad90 },
50+ [ISP_IMX613_4920_01 ] = {0x613 , 0x49200108 , "apple/isp_4920_01XX.dat" , 0x9324 },
51+ [ISP_IMX613_4920_02 ] = {0x613 , 0x49200204 , "apple/isp_4920_02XX.dat" , 0x9324 },
52+ [ISP_IMX614_2921_01 ] = {0x614 , 0x29210107 , "apple/isp_2921_01XX.dat" , 0xed6c },
53+ [ISP_IMX614_2921_02 ] = {0x614 , 0x29210202 , "apple/isp_2921_02XX.dat" , 0xed6c },
54+ [ISP_IMX614_2922_02 ] = {0x614 , 0x29220201 , "apple/isp_2922_02XX.dat" , 0xed6c },
55+ [ISP_IMX633_3622_01 ] = {0x633 , 0x36220111 , "apple/isp_3622_01XX.dat" , 0x100d4 },
56+ [ISP_IMX703_7721_01 ] = {0x703 , 0x77210106 , "apple/isp_7721_01XX.dat" , 0x936c },
57+ [ISP_IMX703_7722_01 ] = {0x703 , 0x77220106 , "apple/isp_7722_01XX.dat" , 0xac20 },
58+ [ISP_IMX713_4721_01 ] = {0x713 , 0x47210107 , "apple/isp_4721_01XX.dat" , 0x936c },
59+ [ISP_IMX713_4722_01 ] = {0x713 , 0x47220109 , "apple/isp_4722_01XX.dat" , 0x9218 },
60+ [ISP_IMX714_2022_01 ] = {0x714 , 0x20220107 , "apple/isp_2022_01XX.dat" , 0xa198 },
61+ [ISP_IMX772_3721_01 ] = {0x772 , 0x37210106 , "apple/isp_3721_01XX.dat" , 0xfdf8 },
62+ [ISP_IMX772_3721_11 ] = {0x772 , 0x37211106 , "apple/isp_3721_11XX.dat" , 0xfe14 },
63+ [ISP_IMX772_3722_01 ] = {0x772 , 0x37220104 , "apple/isp_3722_01XX.dat" , 0xfca4 },
64+ [ISP_IMX772_3723_01 ] = {0x772 , 0x37230106 , "apple/isp_3723_01XX.dat" , 0xfca4 },
65+ [ISP_IMX814_2123_01 ] = {0x814 , 0x21230101 , "apple/isp_2123_01XX.dat" , 0xed54 },
66+ [ISP_IMX853_7622_01 ] = {0x853 , 0x76220112 , "apple/isp_7622_01XX.dat" , 0x247f8 },
67+ [ISP_IMX913_7523_01 ] = {0x913 , 0x75230107 , "apple/isp_7523_01XX.dat" , 0x247f8 },
68+ [ISP_VD56G0_6221_01 ] = {0xd56 , 0x62210102 , "apple/isp_6221_01XX.dat" , 0x1b80 },
69+ [ISP_VD56G0_6222_01 ] = {0xd56 , 0x62220102 , "apple/isp_6222_01XX.dat" , 0x1b80 },
8670};
8771// clang-format on
8872
@@ -182,125 +166,69 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch)
182166 return err ;
183167}
184168
185- static int isp_ch_cache_sensor_info (struct apple_isp * isp , u32 ch )
169+ static int isp_ch_get_camera_preset (struct apple_isp * isp , u32 ch , u32 ps )
186170{
187- struct isp_format * fmt = isp_get_format (isp , ch );
188171 int err = 0 ;
189172
190- struct cmd_ch_info * args ; /* Too big to allocate on stack */
173+ struct cmd_ch_camera_config * args ; /* Too big to allocate on stack */
191174 args = kzalloc (sizeof (* args ), GFP_KERNEL );
192175 if (!args )
193176 return - ENOMEM ;
194177
195- err = isp_cmd_ch_info_get (isp , ch , args );
178+ err = isp_cmd_ch_camera_config_get (isp , ch , ps , args );
196179 if (err )
197180 goto exit ;
198181
199- dev_info (isp -> dev , "found sensor %x %s on ch %d\n" , args -> version ,
200- args -> module_sn , ch );
201-
202- fmt -> version = args -> version ;
203- fmt -> num_presets = args -> num_presets ;
204-
205- pr_info ("apple-isp: ch: CISP_CMD_CH_INFO_GET: %d\n" , ch );
206- print_hex_dump (KERN_INFO , "apple-isp: ch: " , DUMP_PREFIX_NONE , 32 , 4 ,
182+ pr_info ("apple-isp: ps: CISP_CMD_CH_CAMERA_CONFIG_GET: %d\n" , ps );
183+ print_hex_dump (KERN_INFO , "apple-isp: ps: " , DUMP_PREFIX_NONE , 32 , 4 ,
207184 args , sizeof (* args ), false);
208185
209- err = isp_ch_get_sensor_id (isp , ch );
210- if (err || (fmt -> id != ISP_IMX248_1820_01 && fmt -> id != ISP_IMX558_1921_01 )) {
211- dev_err (isp -> dev ,
212- "ch %d: unsupported sensor. Please file a bug report with hardware info & dmesg trace.\n" ,
213- ch );
214- return - ENODEV ;
215- }
216-
217186exit :
218187 kfree (args );
219188
220189 return err ;
221190}
222191
223- static int isp_ch_get_camera_preset (struct apple_isp * isp , u32 ch , u32 ps )
192+ static int isp_ch_cache_sensor_info (struct apple_isp * isp , u32 ch )
224193{
194+ struct isp_format * fmt = isp_get_format (isp , ch );
225195 int err = 0 ;
226196
227- struct cmd_ch_camera_config * args ; /* Too big to allocate on stack */
197+ struct cmd_ch_info * args ; /* Too big to allocate on stack */
228198 args = kzalloc (sizeof (* args ), GFP_KERNEL );
229199 if (!args )
230200 return - ENOMEM ;
231201
232- err = isp_cmd_ch_camera_config_get (isp , ch , ps , args );
202+ err = isp_cmd_ch_info_get (isp , ch , args );
233203 if (err )
234204 goto exit ;
235205
236- pr_info ("apple-isp: ps: CISP_CMD_CH_CAMERA_CONFIG_GET: %d\n" , ps );
237- print_hex_dump (KERN_INFO , "apple-isp: ps: " , DUMP_PREFIX_NONE , 32 , 4 ,
238- args , sizeof (* args ), false);
206+ dev_info (isp -> dev , "found sensor %x %s on ch %d\n" , args -> version ,
207+ args -> module_sn , ch );
239208
240- exit :
241- kfree (args );
209+ fmt -> version = args -> version ;
242210
243- return err ;
244- }
211+ pr_info ("apple-isp: ch: CISP_CMD_CH_INFO_GET: %d\n" , ch );
212+ print_hex_dump (KERN_INFO , "apple-isp: ch: " , DUMP_PREFIX_NONE , 32 , 4 ,
213+ args , sizeof (* args ), false);
245214
246- static void isp_ch_dump_camera_presets (struct apple_isp * isp , u32 ch )
247- {
248- struct isp_format * fmt = isp_get_format (isp , ch );
249- for (u32 ps = 0 ; ps < fmt -> num_presets ; ps ++ ) {
250- isp_ch_get_camera_preset (isp , ch , ps );
215+ err = isp_ch_get_sensor_id (isp , ch );
216+ if (err ||
217+ (fmt -> id != ISP_IMX248_1820_01 && fmt -> id != ISP_IMX558_1921_01 )) {
218+ dev_err (isp -> dev ,
219+ "ch %d: unsupported sensor. Please file a bug report with hardware info & dmesg trace.\n" ,
220+ ch );
221+ return - ENODEV ;
251222 }
252- }
253-
254- static int isp_ch_cache_camera_preset (struct apple_isp * isp , u32 ch )
255- {
256- struct isp_format * fmt = isp_get_format (isp , ch );
257- const struct isp_preset * preset = & isp_presets [fmt -> id ];
258- size_t total_size ;
259-
260- isp_ch_dump_camera_presets (isp , ch );
261-
262- fmt -> preset = preset -> index ;
263-
264- fmt -> width = preset -> width ;
265- fmt -> height = preset -> height ;
266-
267- fmt -> x1 = preset -> x1 ;
268- fmt -> y1 = preset -> y1 ;
269- fmt -> x2 = preset -> x2 ;
270- fmt -> y2 = preset -> y2 ;
271-
272- /* I really fucking hope they all use NV12. */
273- fmt -> num_planes = 2 ;
274- fmt -> plane_size [0 ] = fmt -> width * fmt -> height ;
275- fmt -> plane_size [1 ] = fmt -> plane_size [0 ] / 2 ;
276-
277- total_size = 0 ;
278- for (int i = 0 ; i < fmt -> num_planes ; i ++ )
279- total_size += fmt -> plane_size [i ];
280- fmt -> total_size = total_size ;
281-
282- return 0 ;
283- }
284-
285- static int isp_ch_cache_camera_info (struct apple_isp * isp , u32 ch )
286- {
287- int err ;
288223
289- err = isp_ch_cache_sensor_info (isp , ch );
290- if (err ) {
291- dev_err (isp -> dev , "ch %d: failed to cache sensor info: %d\n" ,
292- ch , err );
293- return err ;
224+ for (u32 ps = 0 ; ps < args -> num_presets ; ps ++ ) {
225+ isp_ch_get_camera_preset (isp , ch , ps );
294226 }
295227
296- err = isp_ch_cache_camera_preset (isp , ch );
297- if (err ) {
298- dev_err (isp -> dev , "ch %d: failed to cache camera preset: %d\n" ,
299- ch , err );
300- return err ;
301- }
228+ exit :
229+ kfree (args );
302230
303- return 0 ;
231+ return err ;
304232}
305233
306234static int isp_detect_camera (struct apple_isp * isp )
@@ -338,7 +266,13 @@ static int isp_detect_camera(struct apple_isp *isp)
338266 isp -> num_channels = args .num_channels ;
339267 isp -> current_ch = 0 ;
340268
341- return isp_ch_cache_camera_info (isp , isp -> current_ch ); /* I told you */
269+ err = isp_ch_cache_sensor_info (isp , isp -> current_ch );
270+ if (err ) {
271+ dev_err (isp -> dev , "failed to cache sensor info\n" );
272+ return err ;
273+ }
274+
275+ return 0 ;
342276}
343277
344278int apple_isp_detect_camera (struct apple_isp * isp )
@@ -408,6 +342,12 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch)
408342 err );
409343 }
410344
345+ if (isp -> hw -> gen >= ISP_GEN_T8112 ) {
346+ err = isp_cmd_ch_lpdp_hs_receiver_tuning_set (isp , ch , 1 , 15 );
347+ if (err )
348+ return err ;
349+ }
350+
411351 err = isp_cmd_ch_sbs_enable (isp , ch , 1 );
412352 if (err )
413353 return err ;
@@ -421,17 +361,21 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch)
421361 if (err )
422362 return err ;
423363
424- err = isp_cmd_ch_camera_config_select (isp , ch , fmt -> preset );
364+ err = isp_cmd_ch_camera_config_select (isp , ch , fmt -> preset -> index );
425365 if (err )
426366 return err ;
427367
428- err = isp_cmd_ch_crop_set (isp , ch , fmt -> x1 , fmt -> y1 , fmt -> x2 , fmt -> y2 );
368+ err = isp_cmd_ch_crop_set (isp , ch , fmt -> preset -> crop_offset .x ,
369+ fmt -> preset -> crop_offset .y ,
370+ fmt -> preset -> crop_size .x ,
371+ fmt -> preset -> crop_size .y );
429372 if (err )
430373 return err ;
431374
432- err = isp_cmd_ch_output_config_set (isp , ch , fmt -> width , fmt -> height ,
433- CISP_COLORSPACE_REC709 ,
434- CISP_OUTPUT_FORMAT_NV12 );
375+ err = isp_cmd_ch_output_config_set (isp , ch , fmt -> preset -> output_dim .x ,
376+ fmt -> preset -> output_dim .y ,
377+ fmt -> strides , CISP_COLORSPACE_REC709 ,
378+ CISP_OUTPUT_FORMAT_YUV_2PLANE );
435379 if (err )
436380 return err ;
437381
@@ -443,7 +387,7 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch)
443387 if (err )
444388 return err ;
445389
446- err = isp_cmd_ch_mbnr_enable (isp , ch , 0 , 1 , 1 );
390+ err = isp_cmd_ch_mbnr_enable (isp , ch , 0 , ISP_MBNR_MODE_ENABLE , 1 );
447391 if (err )
448392 return err ;
449393
0 commit comments