-
Notifications
You must be signed in to change notification settings - Fork 160
/
fthd_isp.c
1433 lines (1161 loc) · 37.2 KB
/
fthd_isp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SPDX-License-Identifier: GPL-2.0-only
*
* FacetimeHD camera driver
*
* Copyright (C) 2014 Patrik Jakobsson ([email protected])
*
*/
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/acpi.h>
#include <linux/firmware.h>
#include <linux/dmi.h>
#include "fthd_drv.h"
#include "fthd_hw.h"
#include "fthd_reg.h"
#include "fthd_ringbuf.h"
#include "fthd_isp.h"
int isp_mem_init(struct fthd_private *dev_priv)
{
struct resource *root = &dev_priv->pdev->resource[FTHD_PCI_S2_MEM];
dev_priv->mem = kzalloc(sizeof(struct resource), GFP_KERNEL);
if (!dev_priv->mem)
return -ENOMEM;
dev_priv->mem->start = root->start;
dev_priv->mem->end = root->end;
/* Preallocate 8mb for the firmware */
dev_priv->firmware = isp_mem_create(dev_priv, FTHD_MEM_FIRMWARE,
FTHD_MEM_FW_SIZE);
if (!dev_priv->firmware) {
dev_err(&dev_priv->pdev->dev,
"Failed to preallocate firmware memory\n");
return -ENOMEM;
}
return 0;
}
struct isp_mem_obj *isp_mem_create(struct fthd_private *dev_priv,
unsigned int type, resource_size_t size)
{
struct isp_mem_obj *obj;
struct resource *root = dev_priv->mem;
int ret;
obj = kzalloc(sizeof(struct isp_mem_obj), GFP_KERNEL);
if (!obj)
return NULL;
obj->type = type;
obj->base.name = "S2 ISP";
ret = allocate_resource(root, &obj->base, size, root->start, root->end,
PAGE_SIZE, NULL, NULL);
if (ret) {
dev_err(&dev_priv->pdev->dev,
"Failed to allocate resource (size: %Ld, start: %Ld, end: %Ld)\n",
size, root->start, root->end);
kfree(obj);
obj = NULL;
}
obj->offset = obj->base.start - root->start;
obj->size = size;
obj->size_aligned = obj->base.end - obj->base.start;
return obj;
}
int isp_mem_destroy(struct isp_mem_obj *obj)
{
if (obj) {
release_resource(&obj->base);
kfree(obj);
obj = NULL;
}
return 0;
}
static int isp_acpi_set_power(struct fthd_private *dev_priv, int power)
{
acpi_status status;
acpi_handle handle;
struct acpi_object_list arg_list;
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
union acpi_object args[1];
union acpi_object *result;
int ret = 0;
handle = ACPI_HANDLE(&dev_priv->pdev->dev);
if(!handle) {
dev_err(&dev_priv->pdev->dev,
"Failed to get S2 CMPE ACPI handle\n");
ret = -ENODEV;
goto out;
}
args[0].type = ACPI_TYPE_INTEGER;
args[0].integer.value = power;
arg_list.count = 1;
arg_list.pointer = args;
status = acpi_evaluate_object(handle, "CMPE", &arg_list, &buffer);
if (ACPI_FAILURE(status)) {
dev_err(&dev_priv->pdev->dev,
"Failed to execute S2 CMPE ACPI method\n");
ret = -ENODEV;
goto out;
}
result = buffer.pointer;
if (result->type != ACPI_TYPE_INTEGER || result->integer.value != 0) {
dev_err(&dev_priv->pdev->dev,
"Invalid ACPI response (len: %Ld)\n", buffer.length);
ret = -EINVAL;
}
out:
kfree(buffer.pointer);
return ret;
}
static int isp_enable_sensor(struct fthd_private *dev_priv)
{
return 0;
}
static int isp_load_firmware(struct fthd_private *dev_priv)
{
const struct firmware *fw;
int ret = 0;
ret = request_firmware(&fw, "facetimehd/firmware.bin", &dev_priv->pdev->dev);
if (ret)
return ret;
/* Firmware memory is preallocated at init time */
if (!dev_priv->firmware)
return -ENOMEM;
if (dev_priv->firmware->base.start != dev_priv->mem->start) {
dev_err(&dev_priv->pdev->dev,
"Misaligned firmware memory object (offset: %lu)\n",
dev_priv->firmware->offset);
isp_mem_destroy(dev_priv->firmware);
dev_priv->firmware = NULL;
return -EBUSY;
}
FTHD_S2_MEMCPY_TOIO(dev_priv->firmware->offset, fw->data, fw->size);
/* Might need a flush here if we map ISP memory cached */
dev_info(&dev_priv->pdev->dev, "Loaded firmware, size: %lukb\n",
fw->size / 1024);
release_firmware(fw);
return ret;
}
static void isp_free_channel_info(struct fthd_private *priv)
{
struct fw_channel *chan;
int i;
for(i = 0; i < priv->num_channels; i++) {
chan = priv->channels[i];
if (!chan)
continue;
kfree(chan->name);
kfree(chan);
priv->channels[i] = NULL;
}
kfree(priv->channels);
priv->channels = NULL;
}
static struct fw_channel *isp_get_chan_index(struct fthd_private *priv, const char *name)
{
int i;
for(i = 0; i < priv->num_channels; i++) {
if (!strcasecmp(priv->channels[i]->name, name))
return priv->channels[i];
}
return NULL;
}
static int isp_fill_channel_info(struct fthd_private *dev_priv, int offset, int num_channels)
{
struct isp_channel_info info;
struct fw_channel *chan;
int i;
if (!num_channels)
return -EINVAL;
dev_priv->channels = kzalloc(num_channels * sizeof(struct fw_channel *), GFP_KERNEL);
if (!dev_priv->channels)
goto out;
dev_priv->num_channels = num_channels;
for(i = 0; i < num_channels; i++) {
FTHD_S2_MEMCPY_FROMIO(&info, offset + i * 256, sizeof(info));
chan = kzalloc(sizeof(struct fw_channel), GFP_KERNEL);
if (!chan)
goto out;
dev_priv->channels[i] = chan;
pr_debug("Channel %d: %s, type %d, source %d, size %d, offset %x\n",
i, info.name, info.type, info.source, info.size, info.offset);
chan->name = kstrdup(info.name, GFP_KERNEL);
if (!chan->name)
goto out;
chan->type = info.type;
chan->source = info.source;
chan->size = info.size;
chan->offset = info.offset;
spin_lock_init(&chan->lock);
init_waitqueue_head(&chan->wq);
}
dev_priv->channel_terminal = isp_get_chan_index(dev_priv, "TERMINAL");
dev_priv->channel_debug = isp_get_chan_index(dev_priv, "DEBUG");
dev_priv->channel_shared_malloc = isp_get_chan_index(dev_priv, "SHAREDMALLOC");
dev_priv->channel_io = isp_get_chan_index(dev_priv, "IO");
dev_priv->channel_buf_h2t = isp_get_chan_index(dev_priv, "BUF_H2T");
dev_priv->channel_buf_t2h = isp_get_chan_index(dev_priv, "BUF_T2H");
dev_priv->channel_io_t2h = isp_get_chan_index(dev_priv, "IO_T2H");
if (!dev_priv->channel_terminal || !dev_priv->channel_debug
|| !dev_priv->channel_shared_malloc || !dev_priv->channel_io
|| !dev_priv->channel_buf_h2t || !dev_priv->channel_buf_t2h
|| !dev_priv->channel_io_t2h) {
dev_err(&dev_priv->pdev->dev, "did not find all of the required channels\n");
goto out;
}
return 0;
out:
isp_free_channel_info(dev_priv);
return -ENOMEM;
}
static int fthd_isp_cmd(struct fthd_private *dev_priv, enum fthd_isp_cmds command, void *buf,
int request_len, int *response_len)
{
struct isp_mem_obj *request;
struct isp_cmd_hdr cmd;
u32 address, request_size, response_size;
u32 entry;
int len, ret;
memset(&cmd, 0, sizeof(cmd));
if (response_len) {
len = max(request_len, *response_len);
} else {
len = request_len;
}
len += sizeof(struct isp_cmd_hdr);
pr_debug("sending cmd %d to firmware\n", command);
request = isp_mem_create(dev_priv, FTHD_MEM_CMD, len);
if (!request) {
dev_err(&dev_priv->pdev->dev, "failed to allocate cmd memory object\n");
return -ENOMEM;
}
cmd.opcode = command;
FTHD_S2_MEMCPY_TOIO(request->offset, &cmd, sizeof(struct isp_cmd_hdr));
if (request_len)
FTHD_S2_MEMCPY_TOIO(request->offset + sizeof(struct isp_cmd_hdr), buf, request_len);
ret = fthd_channel_ringbuf_send(dev_priv, dev_priv->channel_io,
request->offset, request_len + 8, (response_len ? *response_len : 0) + 8, &entry);
if (ret)
goto out;
if (entry == (u32)-1) {
ret = -EIO;
goto out;
}
if (command == CISP_CMD_POWER_DOWN) {
/* powerdown doesn't seem to generate a response */
ret = 0;
goto out;
}
ret = fthd_channel_wait_ready(dev_priv, dev_priv->channel_io, entry, 2000);
if (ret) {
if (response_len)
*response_len = 0;
goto out;
}
FTHD_S2_MEMCPY_FROMIO(&cmd, request->offset, sizeof(struct isp_cmd_hdr));
address = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_ADDRESS_FLAGS);
request_size = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_REQUEST_SIZE);
response_size = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_RESPONSE_SIZE);
/* XXX: response size in the ringbuf is zero after command completion, how is buffer size
verification done? */
if (response_len && *response_len)
FTHD_S2_MEMCPY_FROMIO(buf, (address & ~3) + sizeof(struct isp_cmd_hdr),
*response_len);
pr_debug("status %04x, request_len %d response len %d address_flags %x\n", cmd.status,
request_size, response_size, address);
ret = cmd.status ? -EIO : 0;
out:
isp_mem_destroy(request);
return ret;
}
int fthd_isp_debug_cmd(struct fthd_private *dev_priv, enum fthd_isp_cmds command, void *buf,
int request_len, int *response_len)
{
struct isp_mem_obj *request;
struct isp_cmd_hdr cmd;
u32 address, request_size, response_size;
u32 entry;
int len, ret;
memset(&cmd, 0, sizeof(cmd));
if (response_len) {
len = max(request_len, *response_len);
} else {
len = request_len;
}
len += sizeof(struct isp_cmd_hdr);
pr_debug("sending debug cmd %d to firmware\n", command);
request = isp_mem_create(dev_priv, FTHD_MEM_CMD, len);
if (!request) {
dev_err(&dev_priv->pdev->dev, "failed to allocate cmd memory object\n");
return -ENOMEM;
}
cmd.opcode = command;
FTHD_S2_MEMCPY_TOIO(request->offset, &cmd, sizeof(struct isp_cmd_hdr));
if (request_len)
FTHD_S2_MEMCPY_TOIO(request->offset + sizeof(struct isp_cmd_hdr), buf, request_len);
ret = fthd_channel_ringbuf_send(dev_priv, dev_priv->channel_debug,
request->offset, request_len + 8, (response_len ? *response_len : 0) + 8, &entry);
if (ret)
goto out;
if (entry == (u32)-1) {
ret = -EIO;
goto out;
}
ret = fthd_channel_wait_ready(dev_priv, dev_priv->channel_debug, entry, 20000);
if (ret) {
if (response_len)
*response_len = 0;
goto out;
}
FTHD_S2_MEMCPY_FROMIO(&cmd, request->offset, sizeof(struct isp_cmd_hdr));
address = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_ADDRESS_FLAGS);
request_size = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_REQUEST_SIZE);
response_size = FTHD_S2_MEM_READ(entry + FTHD_RINGBUF_RESPONSE_SIZE);
/* XXX: response size in the ringbuf is zero after command completion, how is buffer size
verification done? */
if (response_len && *response_len)
FTHD_S2_MEMCPY_FROMIO(buf, (address & ~3) + sizeof(struct isp_cmd_hdr),
*response_len);
pr_info("status %04x, request_len %d response len %d address_flags %x\n", cmd.status,
request_size, response_size, address);
ret = 0;
out:
isp_mem_destroy(request);
return ret;
}
int fthd_isp_cmd_start(struct fthd_private *dev_priv)
{
pr_debug("sending start cmd to firmware\n");
return fthd_isp_cmd(dev_priv, CISP_CMD_START, NULL, 0, NULL);
}
int fthd_isp_cmd_channel_start(struct fthd_private *dev_priv)
{
struct isp_cmd_channel_start cmd;
pr_debug("sending channel start cmd to firmware\n");
cmd.channel = 0;
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_START, &cmd, sizeof(cmd), NULL);
}
int fthd_isp_cmd_channel_stop(struct fthd_private *dev_priv)
{
struct isp_cmd_channel_stop cmd;
cmd.channel = 0;
pr_debug("sending channel stop cmd to firmware\n");
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_STOP, &cmd, sizeof(cmd), NULL);
}
int fthd_isp_cmd_stop(struct fthd_private *dev_priv)
{
return fthd_isp_cmd(dev_priv, CISP_CMD_STOP, NULL, 0, NULL);
}
static int fthd_isp_cmd_powerdown(struct fthd_private *dev_priv)
{
return fthd_isp_cmd(dev_priv, CISP_CMD_POWER_DOWN, NULL, 0, NULL);
}
static void isp_free_set_file(struct fthd_private *dev_priv)
{
if (dev_priv->set_file)
isp_mem_destroy(dev_priv->set_file);
}
int isp_powerdown(struct fthd_private *dev_priv)
{
int retries;
u32 reg;
FTHD_ISP_REG_WRITE(0xf7fbdff9, 0xc3000);
fthd_isp_cmd_powerdown(dev_priv);
for (retries = 0; retries < 100; retries++) {
reg = FTHD_ISP_REG_READ(0xc3000);
if (reg == 0x8042006)
break;
mdelay(10);
}
if (retries >= 100) {
dev_info(&dev_priv->pdev->dev, "deinit failed!\n");
return -EIO;
}
return 0;
}
int isp_uninit(struct fthd_private *dev_priv)
{
FTHD_ISP_REG_WRITE(0x00000000, 0x40004);
FTHD_ISP_REG_WRITE(0x00000000, ISP_IRQ_ENABLE);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc0008);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc000c);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc0010);
FTHD_ISP_REG_WRITE(0x00000000, 0xc1004);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc100c);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc1014);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc101c);
FTHD_ISP_REG_WRITE(0xffffffff, 0xc1024);
mdelay(1);
FTHD_ISP_REG_WRITE(0, 0xc0000);
FTHD_ISP_REG_WRITE(0, 0xc0004);
FTHD_ISP_REG_WRITE(0, 0xc0008);
FTHD_ISP_REG_WRITE(0, 0xc000c);
FTHD_ISP_REG_WRITE(0, 0xc0010);
FTHD_ISP_REG_WRITE(0, 0xc0014);
FTHD_ISP_REG_WRITE(0, 0xc0018);
FTHD_ISP_REG_WRITE(0, 0xc001c);
FTHD_ISP_REG_WRITE(0, 0xc0020);
FTHD_ISP_REG_WRITE(0, 0xc0024);
FTHD_ISP_REG_WRITE(0xffffffff, ISP_IRQ_CLEAR);
isp_free_channel_info(dev_priv);
isp_free_set_file(dev_priv);
isp_mem_destroy(dev_priv->firmware);
kfree(dev_priv->mem);
return 0;
}
int fthd_isp_cmd_print_enable(struct fthd_private *dev_priv, int enable)
{
struct isp_cmd_print_enable cmd;
cmd.enable = enable;
return fthd_isp_cmd(dev_priv, CISP_CMD_PRINT_ENABLE, &cmd, sizeof(cmd), NULL);
}
int fthd_isp_cmd_set_loadfile(struct fthd_private *dev_priv)
{
struct isp_cmd_set_loadfile cmd;
struct isp_mem_obj *file;
const struct firmware *fw;
const char *filename = NULL;
const char *vendor, *board;
int ret = 0;
pr_debug("set loadfile\n");
vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
board = dmi_get_system_info(DMI_BOARD_NAME);
memset(&cmd, 0, sizeof(cmd));
switch(dev_priv->sensor_id1) {
case 0x164:
filename = "facetimehd/8221_01XX.dat";
break;
case 0x190:
filename = "facetimehd/1222_01XX.dat";
break;
case 0x8830:
filename = "facetimehd/9112_01XX.dat";
break;
case 0x9770:
if (vendor && board && !strcmp(vendor, "Apple Inc.") &&
!strncmp(board, "MacBookAir", sizeof("MacBookAir")-1)) {
filename = "facetimehd/1771_01XX.dat";
break;
}
switch(dev_priv->sensor_id0) {
case 4:
filename = "facetimehd/1874_01XX.dat";
break;
default:
filename = "facetimehd/1871_01XX.dat";
break;
}
break;
case 0x9774:
switch(dev_priv->sensor_id0) {
case 4:
filename = "facetimehd/1674_01XX.dat";
break;
case 5:
filename = "facetimehd/1675_01XX.dat";
break;
default:
filename = "facetimehd/1671_01XX.dat";
break;
}
break;
default:
break;
}
if (!filename) {
pr_debug("no set file for sensorid %04x %04x found\n",
dev_priv->sensor_id0, dev_priv->sensor_id1);
return 0;
}
/* The set file is allowed to be missing but we don't get calibration */
ret = request_firmware(&fw, filename, &dev_priv->pdev->dev);
if (ret)
return 0;
/* Firmware memory is preallocated at init time */
BUG_ON(dev_priv->set_file);
file = isp_mem_create(dev_priv, FTHD_MEM_SET_FILE, fw->size);
FTHD_S2_MEMCPY_TOIO(file->offset, fw->data, fw->size);
release_firmware(fw);
dev_priv->set_file = file;
pr_debug("set file: addr %08lx, size %d\n", file->offset, (int)file->size);
cmd.addr = file->offset;
cmd.length = file->size;
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_SET_FILE_LOAD, &cmd, sizeof(cmd), NULL);
}
int fthd_isp_cmd_channel_info(struct fthd_private *dev_priv)
{
struct isp_cmd_channel_info cmd;
int ret, len;
pr_debug("sending ch info\n");
memset(&cmd, 0, sizeof(cmd));
len = sizeof(cmd);
ret = fthd_isp_cmd(dev_priv, CISP_CMD_CH_INFO_GET, &cmd, sizeof(cmd), &len);
print_hex_dump_bytes("CHINFO ", DUMP_PREFIX_OFFSET, &cmd, sizeof(cmd));
pr_debug("sensor id: %04x %04x\n", cmd.sensorid0, cmd.sensorid1);
pr_debug("sensor count: %d\n", cmd.sensor_count);
pr_debug("camera module serial number string: %s\n", cmd.camera_module_serial_number);
pr_debug("sensor serial number: %02X%02X%02X%02X%02X%02X%02X%02X\n",
cmd.sensor_serial_number[0], cmd.sensor_serial_number[1],
cmd.sensor_serial_number[2], cmd.sensor_serial_number[3],
cmd.sensor_serial_number[4], cmd.sensor_serial_number[5],
cmd.sensor_serial_number[6], cmd.sensor_serial_number[7]);
dev_priv->sensor_id0 = cmd.sensorid0;
dev_priv->sensor_id1 = cmd.sensorid1;
dev_priv->sensor_count = cmd.sensor_count;
return ret;
}
int fthd_isp_cmd_camera_config(struct fthd_private *dev_priv)
{
struct isp_cmd_config cmd;
int ret, len;
pr_debug("sending camera config\n");
memset(&cmd, 0, sizeof(cmd));
len = sizeof(cmd);
ret = fthd_isp_cmd(dev_priv, CISP_CMD_CONFIG_GET, &cmd, sizeof(cmd), &len);
if (!ret)
print_hex_dump_bytes("CAMINFO ", DUMP_PREFIX_OFFSET, &cmd, sizeof(cmd));
return ret;
}
int fthd_isp_cmd_channel_camera_config(struct fthd_private *dev_priv)
{
struct isp_cmd_channel_camera_config cmd;
int ret, len, i;
char prefix[16];
pr_debug("sending ch camera config\n");
memset(&cmd, 0, sizeof(cmd));
for(i = 0; i < dev_priv->sensor_count; i++) {
cmd.channel = i;
len = sizeof(cmd);
ret = fthd_isp_cmd(dev_priv, CISP_CMD_CH_CAMERA_CONFIG_GET, &cmd, sizeof(cmd), &len);
if (ret)
break;
snprintf(prefix, sizeof(prefix)-1, "CAMCONF%d ", i);
print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, &cmd, sizeof(cmd));
}
return ret;
}
int fthd_isp_cmd_channel_camera_config_select(struct fthd_private *dev_priv, int channel, int config)
{
struct isp_cmd_channel_camera_config_select cmd;
int len;
pr_debug("set camera config: %d\n", config);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.config = config;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_CAMERA_CONFIG_SELECT, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_crop_set(struct fthd_private *dev_priv, int channel,
int x1, int y1, int x2, int y2)
{
struct isp_cmd_channel_set_crop cmd;
int len;
pr_debug("set crop: [%d, %d] -> [%d, %d]\n", x1, y1, x2, y2);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.x1 = x1;
cmd.y2 = y2;
cmd.x2 = x2;
cmd.y2 = y2;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_CROP_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_output_config_set(struct fthd_private *dev_priv, int channel, int x, int y, int pixelformat)
{
struct isp_cmd_channel_output_config cmd;
int len;
pr_debug("output config: [%d, %d]\n", x, y);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.x1 = x; /* Y size */
cmd.x2 = x * 2; /* Chroma size? */
cmd.x3 = x;
cmd.y1 = y;
/* pixel formats:
* 0 - plane 0 Y plane 1 UV
1 - YUYV
2 - YVYU
*/
cmd.pixelformat = pixelformat;
cmd.unknown3 = 0;
cmd.unknown5 = 0x7ff;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_OUTPUT_CONFIG_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_recycle_mode(struct fthd_private *dev_priv, int channel, int mode)
{
struct isp_cmd_channel_recycle_mode cmd;
int len;
pr_debug("set recycle mode %d\n", mode);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.mode = mode;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_BUFFER_RECYCLE_MODE_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_buffer_return(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_buffer_return cmd;
int len;
pr_debug("buffer return\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_BUFFER_RETURN, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_recycle_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_recycle_mode cmd;
int len;
pr_debug("start recycle\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_BUFFER_RECYCLE_START, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_drc_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_drc_start cmd;
int len;
pr_debug("start drc\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_DRC_START, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_tone_curve_adaptation_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_tone_curve_adaptation_start cmd;
int len;
pr_debug("tone curve adaptation start\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_TONE_CURVE_ADAPTATION_START, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_sif_pixel_format(struct fthd_private *dev_priv, int channel, int param1, int param2)
{
struct isp_cmd_channel_sif_format_set cmd;
int len;
pr_debug("set pixel format %d, %d\n", param1, param2);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.param1 = param1;
cmd.param2 = param2;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_SIF_PIXEL_FORMAT_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_error_handling_config(struct fthd_private *dev_priv, int channel, int param1, int param2)
{
struct isp_cmd_channel_camera_err_handle_config cmd;
int len;
pr_debug("set error handling config %d, %d\n", param1, param2);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.param1 = param1;
cmd.param2 = param2;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_CAMERA_ERR_HANDLE_CONFIG, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_streaming_mode(struct fthd_private *dev_priv, int channel, int mode)
{
struct isp_cmd_channel_streaming_mode cmd;
int len;
pr_debug("set streaming mode %d\n", mode);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.mode = mode;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_STREAMING_MODE_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_frame_rate_min(struct fthd_private *dev_priv, int channel, int rate)
{
struct isp_cmd_channel_frame_rate_set cmd;
int len;
pr_debug("set ae frame rate min %d\n", rate);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.rate = rate;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_AE_FRAME_RATE_MIN_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_frame_rate_max(struct fthd_private *dev_priv, int channel, int rate)
{
struct isp_cmd_channel_frame_rate_set cmd;
int len;
pr_debug("set ae frame rate max %d\n", rate);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.rate = rate;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_AE_FRAME_RATE_MAX_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_ae_speed_set(struct fthd_private *dev_priv, int channel, int speed)
{
struct isp_cmd_channel_ae_speed_set cmd;
int len;
pr_debug("set ae speed %d\n", speed);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.speed = speed;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_AE_SPEED_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_ae_stability_set(struct fthd_private *dev_priv, int channel, int stability)
{
struct isp_cmd_channel_ae_stability_set cmd;
int len;
pr_debug("set ae stability %d\n", stability);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.stability = stability;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_AE_STABILITY_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_ae_stability_to_stable_set(struct fthd_private *dev_priv, int channel, int value)
{
struct isp_cmd_channel_ae_stability_to_stable_set cmd;
int len;
pr_debug("set ae stability to stable %d\n", value);
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
cmd.value = value;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_AE_STABILITY_TO_STABLE_SET, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_face_detection_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_face_detection_start cmd;
int len;
pr_debug("face detection start\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_FACE_DETECTION_START, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_face_detection_stop(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_face_detection_stop cmd;
int len;
pr_debug("face detection stop\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_FACE_DETECTION_STOP, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_face_detection_enable(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_face_detection_enable cmd;
int len;
pr_debug("face detection enable\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_FACE_DETECTION_ENABLE, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_face_detection_disable(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_face_detection_disable cmd;
int len;
pr_debug("face detection disable\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_CH_FACE_DETECTION_DISABLE, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_temporal_filter_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_temporal_filter_start cmd;
int len;
pr_debug("temporal filter start\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_TEMPORAL_FILTER_START, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_temporal_filter_stop(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_temporal_filter_stop cmd;
int len;
pr_debug("temporal filter stop\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_TEMPORAL_FILTER_STOP, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_temporal_filter_enable(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_temporal_filter_enable cmd;
int len;
pr_debug("temporal filter enable\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_TEMPORAL_FILTER_ENABLE, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_temporal_filter_disable(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_temporal_filter_disable cmd;
int len;
pr_debug("temporal filter disable\n");
memset(&cmd, 0, sizeof(cmd));
cmd.channel = channel;
len = sizeof(cmd);
return fthd_isp_cmd(dev_priv, CISP_CMD_APPLE_CH_TEMPORAL_FILTER_DISABLE, &cmd, sizeof(cmd), &len);
}
int fthd_isp_cmd_channel_motion_history_start(struct fthd_private *dev_priv, int channel)
{
struct isp_cmd_channel_motion_history_start cmd;
int len;