Bootlin logo

Elixir Cross Referencer

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
/*
 * Copyright (C) 2012 Texas Instruments Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * Contributors:
 *      Manjunath Hadli <manjunath.hadli@ti.com>
 *      Prabhakar Lad <prabhakar.lad@ti.com>
 */

#include <linux/delay.h>
#include "dm365_isif.h"
#include "vpfe_mc_capture.h"

#define MAX_WIDTH	4096
#define MAX_HEIGHT	4096

static const unsigned int isif_fmts[] = {
	MEDIA_BUS_FMT_YUYV8_2X8,
	MEDIA_BUS_FMT_UYVY8_2X8,
	MEDIA_BUS_FMT_YUYV8_1X16,
	MEDIA_BUS_FMT_YUYV10_1X20,
	MEDIA_BUS_FMT_SGRBG12_1X12,
	MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8,
	MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
};

#define ISIF_COLPTN_R_Ye	0x0
#define ISIF_COLPTN_Gr_Cy	0x1
#define ISIF_COLPTN_Gb_G	0x2
#define ISIF_COLPTN_B_Mg	0x3

#define ISIF_CCOLP_CP01_0	0
#define ISIF_CCOLP_CP03_2	2
#define ISIF_CCOLP_CP05_4	4
#define ISIF_CCOLP_CP07_6	6
#define ISIF_CCOLP_CP11_0	8
#define ISIF_CCOLP_CP13_2	10
#define ISIF_CCOLP_CP15_4	12
#define ISIF_CCOLP_CP17_6	14

static const u32 isif_sgrbg_pattern =
	ISIF_COLPTN_Gr_Cy <<  ISIF_CCOLP_CP01_0 |
	ISIF_COLPTN_R_Ye  << ISIF_CCOLP_CP03_2 |
	ISIF_COLPTN_B_Mg  << ISIF_CCOLP_CP05_4 |
	ISIF_COLPTN_Gb_G  << ISIF_CCOLP_CP07_6 |
	ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP11_0 |
	ISIF_COLPTN_R_Ye  << ISIF_CCOLP_CP13_2 |
	ISIF_COLPTN_B_Mg  << ISIF_CCOLP_CP15_4 |
	ISIF_COLPTN_Gb_G  << ISIF_CCOLP_CP17_6;

static const u32 isif_srggb_pattern =
	ISIF_COLPTN_R_Ye  << ISIF_CCOLP_CP01_0 |
	ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP03_2 |
	ISIF_COLPTN_Gb_G  << ISIF_CCOLP_CP05_4 |
	ISIF_COLPTN_B_Mg  << ISIF_CCOLP_CP07_6 |
	ISIF_COLPTN_R_Ye  << ISIF_CCOLP_CP11_0 |
	ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP13_2 |
	ISIF_COLPTN_Gb_G  << ISIF_CCOLP_CP15_4 |
	ISIF_COLPTN_B_Mg  << ISIF_CCOLP_CP17_6;

static inline u32 isif_read(void __iomem *base_addr, u32 offset)
{
	return readl(base_addr + offset);
}

static inline void isif_write(void __iomem *base_addr, u32 val, u32 offset)
{
	writel(val, base_addr + offset);
}

static inline u32 isif_merge(void __iomem *base_addr, u32 mask, u32 val,
			     u32 offset)
{
	u32 new_val = (isif_read(base_addr, offset) & ~mask) | (val & mask);

	isif_write(base_addr, new_val, offset);

	return new_val;
}

static void isif_enable_output_to_sdram(struct vpfe_isif_device *isif, int en)
{
	isif_merge(isif->isif_cfg.base_addr, ISIF_SYNCEN_WEN_MASK,
		   en << ISIF_SYNCEN_WEN_SHIFT, SYNCEN);
}

static inline void
isif_regw_lin_tbl(struct vpfe_isif_device *isif, u32 val, u32 offset, int i)
{
	if (!i)
		writel(val, isif->isif_cfg.linear_tbl0_addr + offset);
	else
		writel(val, isif->isif_cfg.linear_tbl1_addr + offset);
}

static void isif_disable_all_modules(struct vpfe_isif_device *isif)
{
	/* disable BC */
	isif_write(isif->isif_cfg.base_addr, 0, CLAMPCFG);
	/* disable vdfc */
	isif_write(isif->isif_cfg.base_addr, 0, DFCCTL);
	/* disable CSC */
	isif_write(isif->isif_cfg.base_addr, 0, CSCCTL);
	/* disable linearization */
	isif_write(isif->isif_cfg.base_addr, 0, LINCFG0);
}

static void isif_enable(struct vpfe_isif_device *isif, int en)
{
	if (!en)
		/* Before disable isif, disable all ISIF modules */
		isif_disable_all_modules(isif);

	/*
	 * wait for next VD. Assume lowest scan rate is 12 Hz. So
	 * 100 msec delay is good enough
	 */
	msleep(100);
	isif_merge(isif->isif_cfg.base_addr, ISIF_SYNCEN_VDHDEN_MASK,
		   en, SYNCEN);
}

/*
 * ISIF helper functions
 */

#define DM365_ISIF_MDFS_OFFSET		15
#define DM365_ISIF_MDFS_MASK		0x1

/* get field id in isif hardware */
enum v4l2_field vpfe_isif_get_fid(struct vpfe_device *vpfe_dev)
{
	struct vpfe_isif_device *isif = &vpfe_dev->vpfe_isif;
	u32 field_status;

	field_status = isif_read(isif->isif_cfg.base_addr, MODESET);
	return (field_status >> DM365_ISIF_MDFS_OFFSET) &
		DM365_ISIF_MDFS_MASK;
}

static int
isif_set_pixel_format(struct vpfe_isif_device *isif, unsigned int pixfmt)
{
	if (isif->formats[ISIF_PAD_SINK].code == MEDIA_BUS_FMT_SGRBG12_1X12) {
		if (pixfmt == V4L2_PIX_FMT_SBGGR16)
			isif->isif_cfg.data_pack = ISIF_PACK_16BIT;
		else if ((pixfmt == V4L2_PIX_FMT_SGRBG10DPCM8) ||
				(pixfmt == V4L2_PIX_FMT_SGRBG10ALAW8))
			isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
		else
			return -EINVAL;

		isif->isif_cfg.bayer.pix_fmt = ISIF_PIXFMT_RAW;
		isif->isif_cfg.bayer.v4l2_pix_fmt = pixfmt;
	} else {
		if (pixfmt == V4L2_PIX_FMT_YUYV)
			isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_YCBYCR;
		else if (pixfmt == V4L2_PIX_FMT_UYVY)
			isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_CBYCRY;
		else
			return -EINVAL;

		isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
		isif->isif_cfg.ycbcr.v4l2_pix_fmt = pixfmt;
	}

	return 0;
}

static int
isif_set_frame_format(struct vpfe_isif_device *isif,
		      enum isif_frmfmt frm_fmt)
{
	if (isif->formats[ISIF_PAD_SINK].code == MEDIA_BUS_FMT_SGRBG12_1X12)
		isif->isif_cfg.bayer.frm_fmt = frm_fmt;
	else
		isif->isif_cfg.ycbcr.frm_fmt = frm_fmt;

	return 0;
}

static int isif_set_image_window(struct vpfe_isif_device *isif)
{
	struct v4l2_rect *win = &isif->crop;

	if (isif->formats[ISIF_PAD_SINK].code == MEDIA_BUS_FMT_SGRBG12_1X12) {
		isif->isif_cfg.bayer.win.top = win->top;
		isif->isif_cfg.bayer.win.left = win->left;
		isif->isif_cfg.bayer.win.width = win->width;
		isif->isif_cfg.bayer.win.height = win->height;
		return 0;
	}
	isif->isif_cfg.ycbcr.win.top = win->top;
	isif->isif_cfg.ycbcr.win.left = win->left;
	isif->isif_cfg.ycbcr.win.width = win->width;
	isif->isif_cfg.ycbcr.win.height = win->height;

	return 0;
}

static int
isif_set_buftype(struct vpfe_isif_device *isif, enum isif_buftype buf_type)
{
	if (isif->formats[ISIF_PAD_SINK].code == MEDIA_BUS_FMT_SGRBG12_1X12)
		isif->isif_cfg.bayer.buf_type = buf_type;
	else
		isif->isif_cfg.ycbcr.buf_type = buf_type;

	return 0;
}

/* configure format in isif hardware */
static int
isif_config_format(struct vpfe_device *vpfe_dev, unsigned int pad)
{
	struct vpfe_isif_device *vpfe_isif = &vpfe_dev->vpfe_isif;
	enum isif_frmfmt frm_fmt = ISIF_FRMFMT_INTERLACED;
	struct v4l2_pix_format format;
	int ret = 0;

	v4l2_fill_pix_format(&format, &vpfe_dev->vpfe_isif.formats[pad]);
	mbus_to_pix(&vpfe_dev->vpfe_isif.formats[pad], &format);

	if (isif_set_pixel_format(vpfe_isif, format.pixelformat) < 0) {
		v4l2_err(&vpfe_dev->v4l2_dev,
			 "Failed to set pixel format in isif\n");
		return -EINVAL;
	}

	/* call for s_crop will override these values */
	vpfe_isif->crop.left = 0;
	vpfe_isif->crop.top = 0;
	vpfe_isif->crop.width = format.width;
	vpfe_isif->crop.height = format.height;

	/* configure the image window */
	isif_set_image_window(vpfe_isif);

	switch (vpfe_dev->vpfe_isif.formats[pad].field) {
	case V4L2_FIELD_INTERLACED:
		/* do nothing, since it is default */
		ret = isif_set_buftype(vpfe_isif, ISIF_BUFTYPE_FLD_INTERLEAVED);
		break;

	case V4L2_FIELD_NONE:
		frm_fmt = ISIF_FRMFMT_PROGRESSIVE;
		/* buffer type only applicable for interlaced scan */
		break;

	case V4L2_FIELD_SEQ_TB:
		ret = isif_set_buftype(vpfe_isif, ISIF_BUFTYPE_FLD_SEPARATED);
		break;

	default:
		return -EINVAL;
	}

	/* set the frame format */
	if (!ret)
		ret = isif_set_frame_format(vpfe_isif, frm_fmt);

	return ret;
}

/*
 * isif_try_format() - Try video format on a pad
 * @isif: VPFE isif device
 * @cfg: V4L2 subdev pad config
 * @fmt: pointer to v4l2 subdev format structure
 */
static void
isif_try_format(struct vpfe_isif_device *isif,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *fmt)
{
	unsigned int width = fmt->format.width;
	unsigned int height = fmt->format.height;
	unsigned int i;

	for (i = 0; i < ARRAY_SIZE(isif_fmts); i++) {
		if (fmt->format.code == isif_fmts[i])
			break;
	}

	/* If not found, use YUYV8_2x8 as default */
	if (i >= ARRAY_SIZE(isif_fmts))
		fmt->format.code = MEDIA_BUS_FMT_YUYV8_2X8;

	/* Clamp the size. */
	fmt->format.width = clamp_t(u32, width, 32, MAX_WIDTH);
	fmt->format.height = clamp_t(u32, height, 32, MAX_HEIGHT);

	/* The data formatter truncates the number of horizontal output
	 * pixels to a multiple of 16. To avoid clipping data, allow
	 * callers to request an output size bigger than the input size
	 * up to the nearest multiple of 16.
	 */
	if (fmt->pad == ISIF_PAD_SOURCE)
		fmt->format.width &= ~15;
}

/*
 * vpfe_isif_buffer_isr() - isif module non-progressive buffer scheduling isr
 * @isif: Pointer to isif subdevice.
 */
void vpfe_isif_buffer_isr(struct vpfe_isif_device *isif)
{
	struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
	struct vpfe_video_device *video = &isif->video_out;
	enum v4l2_field field;
	int fid;

	if (!video->started)
		return;

	field = video->fmt.fmt.pix.field;

	if (field == V4L2_FIELD_NONE) {
		/* handle progressive frame capture */
		if (video->cur_frm != video->next_frm)
			vpfe_video_process_buffer_complete(video);
		return;
	}

	/* interlaced or TB capture check which field we
	 * are in hardware
	 */
	fid = vpfe_isif_get_fid(vpfe_dev);

	/* switch the software maintained field id */
	video->field_id ^= 1;
	if (fid == video->field_id) {
		/* we are in-sync here,continue */
		if (fid == 0) {
			/*
			 * One frame is just being captured. If the
			 * next frame is available, release the current
			 * frame and move on
			 */
			if (video->cur_frm != video->next_frm)
				vpfe_video_process_buffer_complete(video);
			/*
			 * based on whether the two fields are stored
			 * interleavely or separately in memory,
			 * reconfigure the ISIF memory address
			 */
			if (field == V4L2_FIELD_SEQ_TB)
				vpfe_video_schedule_bottom_field(video);
			return;
		}
		/*
		 * if one field is just being captured configure
		 * the next frame get the next frame from the
		 * empty queue if no frame is available hold on
		 * to the current buffer
		 */
		spin_lock(&video->dma_queue_lock);
		if (!list_empty(&video->dma_queue) &&
		video->cur_frm == video->next_frm)
			vpfe_video_schedule_next_buffer(video);
		spin_unlock(&video->dma_queue_lock);
	} else if (fid == 0) {
		/*
		 * out of sync. Recover from any hardware out-of-sync.
		 * May loose one frame
		 */
		video->field_id = fid;
	}
}

/*
 * vpfe_isif_vidint1_isr() - ISIF module progressive buffer scheduling isr
 * @isif: Pointer to isif subdevice.
 */
void vpfe_isif_vidint1_isr(struct vpfe_isif_device *isif)
{
	struct vpfe_video_device *video = &isif->video_out;

	if (!video->started)
		return;

	spin_lock(&video->dma_queue_lock);
	if (video->fmt.fmt.pix.field == V4L2_FIELD_NONE &&
	    !list_empty(&video->dma_queue) && video->cur_frm == video->next_frm)
		vpfe_video_schedule_next_buffer(video);

	spin_unlock(&video->dma_queue_lock);
}

/*
 * VPFE video operations
 */

static int isif_video_queue(struct vpfe_device *vpfe_dev, unsigned long addr)
{
	struct vpfe_isif_device *isif = &vpfe_dev->vpfe_isif;

	isif_write(isif->isif_cfg.base_addr, (addr >> 21) &
		ISIF_CADU_BITS, CADU);
	isif_write(isif->isif_cfg.base_addr, (addr >> 5) &
		ISIF_CADL_BITS, CADL);

	return 0;
}

static const struct vpfe_video_operations isif_video_ops = {
	.queue = isif_video_queue,
};

/*
 * V4L2 subdev operations
 */

/* Parameter operations */
static int isif_get_params(struct v4l2_subdev *sd, void *params)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);

	/* only raw module parameters can be set through the IOCTL */
	if (isif->formats[ISIF_PAD_SINK].code != MEDIA_BUS_FMT_SGRBG12_1X12)
		return -EINVAL;
	memcpy(params, &isif->isif_cfg.bayer.config_params,
			sizeof(isif->isif_cfg.bayer.config_params));
	return 0;
}

static int isif_validate_df_csc_params(struct vpfe_isif_df_csc *df_csc)
{
	struct vpfe_isif_color_space_conv *csc;
	int err = -EINVAL;
	int i;

	if (!df_csc->df_or_csc) {
		/* csc configuration */
		csc = &df_csc->csc;
		if (csc->en) {
			for (i = 0; i < VPFE_ISIF_CSC_NUM_COEFF; i++)
				if (csc->coeff[i].integer >
				    ISIF_CSC_COEF_INTEG_MASK ||
				    csc->coeff[i].decimal >
				    ISIF_CSC_COEF_DECIMAL_MASK) {
					pr_err("Invalid CSC coefficients\n");
					return err;
				}
		}
	}
	if (df_csc->start_pix > ISIF_DF_CSC_SPH_MASK) {
		pr_err("Invalid df_csc start pix value\n");
		return err;
	}

	if (df_csc->num_pixels > ISIF_DF_NUMPIX) {
		pr_err("Invalid df_csc num pixels value\n");
		return err;
	}

	if (df_csc->start_line > ISIF_DF_CSC_LNH_MASK) {
		pr_err("Invalid df_csc start_line value\n");
		return err;
	}

	if (df_csc->num_lines > ISIF_DF_NUMLINES) {
		pr_err("Invalid df_csc num_lines value\n");
		return err;
	}

	return 0;
}

#define DM365_ISIF_MAX_VDFLSFT		4
#define DM365_ISIF_MAX_VDFSLV		4095
#define DM365_ISIF_MAX_DFCMEM0		0x1fff
#define DM365_ISIF_MAX_DFCMEM1		0x1fff

static int isif_validate_dfc_params(struct vpfe_isif_dfc *dfc)
{
	int err = -EINVAL;
	int i;

	if (!dfc->en)
		return 0;

	if (dfc->corr_whole_line > 1) {
		pr_err("Invalid corr_whole_line value\n");
		return err;
	}

	if (dfc->def_level_shift > DM365_ISIF_MAX_VDFLSFT) {
		pr_err("Invalid def_level_shift value\n");
		return err;
	}

	if (dfc->def_sat_level > DM365_ISIF_MAX_VDFSLV) {
		pr_err("Invalid def_sat_level value\n");
		return err;
	}

	if (!dfc->num_vdefects ||
	    dfc->num_vdefects > VPFE_ISIF_VDFC_TABLE_SIZE) {
		pr_err("Invalid num_vdefects value\n");
		return err;
	}

	for (i = 0; i < VPFE_ISIF_VDFC_TABLE_SIZE; i++) {
		if (dfc->table[i].pos_vert > DM365_ISIF_MAX_DFCMEM0) {
			pr_err("Invalid pos_vert value\n");
			return err;
		}
		if (dfc->table[i].pos_horz > DM365_ISIF_MAX_DFCMEM1) {
			pr_err("Invalid pos_horz value\n");
			return err;
		}
	}

	return 0;
}

#define DM365_ISIF_MAX_CLVRV			0xfff
#define DM365_ISIF_MAX_CLDC			0x1fff
#define DM365_ISIF_MAX_CLHSH			0x1fff
#define DM365_ISIF_MAX_CLHSV			0x1fff
#define DM365_ISIF_MAX_CLVSH			0x1fff
#define DM365_ISIF_MAX_CLVSV			0x1fff
#define DM365_ISIF_MAX_HEIGHT_BLACK_REGION	0x1fff

static int isif_validate_bclamp_params(struct vpfe_isif_black_clamp *bclamp)
{
	int err = -EINVAL;

	if (bclamp->dc_offset > DM365_ISIF_MAX_CLDC) {
		pr_err("Invalid bclamp dc_offset value\n");
		return err;
	}
	if (!bclamp->en)
		return 0;
	if (bclamp->horz.clamp_pix_limit > 1) {
		pr_err("Invalid bclamp horz clamp_pix_limit value\n");
		return err;
	}
	if (bclamp->horz.win_count_calc < 1 ||
			bclamp->horz.win_count_calc > 32) {
		pr_err("Invalid bclamp horz win_count_calc value\n");
		return err;
	}
	if (bclamp->horz.win_start_h_calc > DM365_ISIF_MAX_CLHSH) {
		pr_err("Invalid bclamp win_start_v_calc value\n");
		return err;
	}

	if (bclamp->horz.win_start_v_calc > DM365_ISIF_MAX_CLHSV) {
		pr_err("Invalid bclamp win_start_v_calc value\n");
		return err;
	}
	if (bclamp->vert.reset_clamp_val > DM365_ISIF_MAX_CLVRV) {
		pr_err("Invalid bclamp reset_clamp_val value\n");
		return err;
	}
	if (bclamp->vert.ob_v_sz_calc > DM365_ISIF_MAX_HEIGHT_BLACK_REGION) {
		pr_err("Invalid bclamp ob_v_sz_calc value\n");
		return err;
	}
	if (bclamp->vert.ob_start_h > DM365_ISIF_MAX_CLVSH) {
		pr_err("Invalid bclamp ob_start_h value\n");
		return err;
	}
	if (bclamp->vert.ob_start_v > DM365_ISIF_MAX_CLVSV) {
		pr_err("Invalid bclamp ob_start_h value\n");
		return err;
	}
	return 0;
}

static int
isif_validate_raw_params(struct vpfe_isif_raw_config *params)
{
	int ret;

	ret = isif_validate_df_csc_params(&params->df_csc);
	if (ret)
		return ret;
	ret = isif_validate_dfc_params(&params->dfc);
	if (ret)
		return ret;
	return isif_validate_bclamp_params(&params->bclamp);
}

static int isif_set_params(struct v4l2_subdev *sd, void *params)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct vpfe_isif_raw_config isif_raw_params;
	int ret = -EINVAL;

	/* only raw module parameters can be set through the IOCTL */
	if (isif->formats[ISIF_PAD_SINK].code != MEDIA_BUS_FMT_SGRBG12_1X12)
		return ret;

	memcpy(&isif_raw_params, params, sizeof(isif_raw_params));
	if (!isif_validate_raw_params(&isif_raw_params)) {
		memcpy(&isif->isif_cfg.bayer.config_params, &isif_raw_params,
			sizeof(isif_raw_params));
		ret = 0;
	}
	return ret;
}
/*
 * isif_ioctl() - isif module private ioctl's
 * @sd: VPFE isif V4L2 subdevice
 * @cmd: ioctl command
 * @arg: ioctl argument
 *
 * Return 0 on success or a negative error code otherwise.
 */
static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
{
	switch (cmd) {
	case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
		return isif_set_params(sd, arg);

	case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
		return isif_get_params(sd, arg);

	default:
		return -ENOIOCTLCMD;
	}
}

static void isif_config_gain_offset(struct vpfe_isif_device *isif)
{
	struct vpfe_isif_gain_offsets_adj *gain_off_ptr =
		&isif->isif_cfg.bayer.config_params.gain_offset;
	void __iomem *base = isif->isif_cfg.base_addr;
	u32 val;

	val = ((gain_off_ptr->gain_sdram_en & 1) << GAIN_SDRAM_EN_SHIFT) |
	      ((gain_off_ptr->gain_ipipe_en & 1) << GAIN_IPIPE_EN_SHIFT) |
	      ((gain_off_ptr->gain_h3a_en & 1) << GAIN_H3A_EN_SHIFT) |
	      ((gain_off_ptr->offset_sdram_en & 1) << OFST_SDRAM_EN_SHIFT) |
	      ((gain_off_ptr->offset_ipipe_en & 1) << OFST_IPIPE_EN_SHIFT) |
	      ((gain_off_ptr->offset_h3a_en & 1) << OFST_H3A_EN_SHIFT);
	isif_merge(base, GAIN_OFFSET_EN_MASK, val, CGAMMAWD);

	isif_write(base, isif->isif_cfg.isif_gain_params.cr_gain, CRGAIN);
	isif_write(base, isif->isif_cfg.isif_gain_params.cgr_gain, CGRGAIN);
	isif_write(base, isif->isif_cfg.isif_gain_params.cgb_gain, CGBGAIN);
	isif_write(base, isif->isif_cfg.isif_gain_params.cb_gain, CBGAIN);
	isif_write(base, isif->isif_cfg.isif_gain_params.offset & OFFSET_MASK,
		   COFSTA);

}

static void isif_config_bclamp(struct vpfe_isif_device *isif,
		   struct vpfe_isif_black_clamp *bc)
{
	u32 val;

	/**
	 * DC Offset is always added to image data irrespective of bc enable
	 * status
	 */
	val = bc->dc_offset & ISIF_BC_DCOFFSET_MASK;
	isif_write(isif->isif_cfg.base_addr, val, CLDCOFST);

	if (!bc->en)
		return;

	val = (bc->bc_mode_color & ISIF_BC_MODE_COLOR_MASK) <<
		ISIF_BC_MODE_COLOR_SHIFT;

	/* Enable BC and horizontal clamp calculation paramaters */
	val = val | 1 | ((bc->horz.mode & ISIF_HORZ_BC_MODE_MASK) <<
	      ISIF_HORZ_BC_MODE_SHIFT);

	isif_write(isif->isif_cfg.base_addr, val, CLAMPCFG);

	if (bc->horz.mode != VPFE_ISIF_HORZ_BC_DISABLE) {
		/*
		 * Window count for calculation
		 * Base window selection
		 * pixel limit
		 * Horizontal size of window
		 * vertical size of the window
		 * Horizontal start position of the window
		 * Vertical start position of the window
		 */
		val = (bc->horz.win_count_calc & ISIF_HORZ_BC_WIN_COUNT_MASK) |
		      ((bc->horz.base_win_sel_calc & 1) <<
		      ISIF_HORZ_BC_WIN_SEL_SHIFT) |
		      ((bc->horz.clamp_pix_limit & 1) <<
		      ISIF_HORZ_BC_PIX_LIMIT_SHIFT) |
		      ((bc->horz.win_h_sz_calc &
		      ISIF_HORZ_BC_WIN_H_SIZE_MASK) <<
		      ISIF_HORZ_BC_WIN_H_SIZE_SHIFT) |
		      ((bc->horz.win_v_sz_calc &
		      ISIF_HORZ_BC_WIN_V_SIZE_MASK) <<
		      ISIF_HORZ_BC_WIN_V_SIZE_SHIFT);

		isif_write(isif->isif_cfg.base_addr, val, CLHWIN0);

		val = bc->horz.win_start_h_calc & ISIF_HORZ_BC_WIN_START_H_MASK;
		isif_write(isif->isif_cfg.base_addr, val, CLHWIN1);

		val = bc->horz.win_start_v_calc & ISIF_HORZ_BC_WIN_START_V_MASK;
		isif_write(isif->isif_cfg.base_addr, val, CLHWIN2);
	}

	/* vertical clamp calculation paramaters */
	/* OB H Valid */
	val = bc->vert.ob_h_sz_calc & ISIF_VERT_BC_OB_H_SZ_MASK;

	/* Reset clamp value sel for previous line */
	val |= (bc->vert.reset_val_sel & ISIF_VERT_BC_RST_VAL_SEL_MASK) <<
				ISIF_VERT_BC_RST_VAL_SEL_SHIFT;

	/* Line average coefficient */
	val |= bc->vert.line_ave_coef << ISIF_VERT_BC_LINE_AVE_COEF_SHIFT;
	isif_write(isif->isif_cfg.base_addr, val, CLVWIN0);

	/* Configured reset value */
	if (bc->vert.reset_val_sel == VPFE_ISIF_VERT_BC_USE_CONFIG_CLAMP_VAL) {
		val = bc->vert.reset_clamp_val & ISIF_VERT_BC_RST_VAL_MASK;
		isif_write(isif->isif_cfg.base_addr, val, CLVRV);
	}

	/* Optical Black horizontal start position */
	val = bc->vert.ob_start_h & ISIF_VERT_BC_OB_START_HORZ_MASK;
	isif_write(isif->isif_cfg.base_addr, val, CLVWIN1);

	/* Optical Black vertical start position */
	val = bc->vert.ob_start_v & ISIF_VERT_BC_OB_START_VERT_MASK;
	isif_write(isif->isif_cfg.base_addr, val, CLVWIN2);

	val = bc->vert.ob_v_sz_calc & ISIF_VERT_BC_OB_VERT_SZ_MASK;
	isif_write(isif->isif_cfg.base_addr, val, CLVWIN3);

	/* Vertical start position for BC subtraction */
	val = bc->vert_start_sub & ISIF_BC_VERT_START_SUB_V_MASK;
	isif_write(isif->isif_cfg.base_addr, val, CLSV);
}

/* This function will configure the window size to be capture in ISIF reg */
static void
isif_setwin(struct vpfe_isif_device *isif, struct v4l2_rect *image_win,
	    enum isif_frmfmt frm_fmt, int ppc, int mode)
{
	int horz_nr_pixels;
	int vert_nr_lines;
	int horz_start;
	int vert_start;
	int mid_img;

	/*
	 * ppc - per pixel count. indicates how many pixels per cell
	 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
	 * raw capture this is 1
	 */
	horz_start = image_win->left << (ppc - 1);
	horz_nr_pixels = (image_win->width << (ppc - 1)) - 1;

	/* Writing the horizontal info into the registers */
	isif_write(isif->isif_cfg.base_addr,
		   horz_start & START_PX_HOR_MASK, SPH);
	isif_write(isif->isif_cfg.base_addr,
		   horz_nr_pixels & NUM_PX_HOR_MASK, LNH);
	vert_start = image_win->top;

	if (frm_fmt == ISIF_FRMFMT_INTERLACED) {
		vert_nr_lines = (image_win->height >> 1) - 1;
		vert_start >>= 1;
		/* To account for VD since line 0 doesn't have any data */
		vert_start += 1;
	} else {
		/* To account for VD since line 0 doesn't have any data */
		vert_start += 1;
		vert_nr_lines = image_win->height - 1;
		/* configure VDINT0 and VDINT1 */
		mid_img = vert_start + (image_win->height / 2);
		isif_write(isif->isif_cfg.base_addr, mid_img, VDINT1);
	}

	if (!mode)
		isif_write(isif->isif_cfg.base_addr, 0, VDINT0);
	else
		isif_write(isif->isif_cfg.base_addr, vert_nr_lines, VDINT0);
	isif_write(isif->isif_cfg.base_addr,
		   vert_start & START_VER_ONE_MASK, SLV0);
	isif_write(isif->isif_cfg.base_addr,
		   vert_start & START_VER_TWO_MASK, SLV1);
	isif_write(isif->isif_cfg.base_addr,
		   vert_nr_lines & NUM_LINES_VER, LNV);
}

#define DM365_ISIF_DFCMWR_MEMORY_WRITE		1
#define DM365_ISIF_DFCMRD_MEMORY_READ		0x2

static void
isif_config_dfc(struct vpfe_isif_device *isif, struct vpfe_isif_dfc *vdfc)
{
#define DFC_WRITE_WAIT_COUNT	1000
	u32 count = DFC_WRITE_WAIT_COUNT;
	u32 val;
	int i;

	if (!vdfc->en)
		return;

	/* Correction mode */
	val = (vdfc->corr_mode & ISIF_VDFC_CORR_MOD_MASK) <<
	       ISIF_VDFC_CORR_MOD_SHIFT;

	/* Correct whole line or partial */
	if (vdfc->corr_whole_line)
		val |= 1 << ISIF_VDFC_CORR_WHOLE_LN_SHIFT;

	/* level shift value */
	val |= (vdfc->def_level_shift & ISIF_VDFC_LEVEL_SHFT_MASK) <<
		ISIF_VDFC_LEVEL_SHFT_SHIFT;

	isif_write(isif->isif_cfg.base_addr, val, DFCCTL);

	/* Defect saturation level */
	val = vdfc->def_sat_level & ISIF_VDFC_SAT_LEVEL_MASK;
	isif_write(isif->isif_cfg.base_addr, val, VDFSATLV);

	isif_write(isif->isif_cfg.base_addr, vdfc->table[0].pos_vert &
		   ISIF_VDFC_POS_MASK, DFCMEM0);
	isif_write(isif->isif_cfg.base_addr, vdfc->table[0].pos_horz &
		   ISIF_VDFC_POS_MASK, DFCMEM1);
	if (vdfc->corr_mode == VPFE_ISIF_VDFC_NORMAL ||
	    vdfc->corr_mode == VPFE_ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
		isif_write(isif->isif_cfg.base_addr,
			   vdfc->table[0].level_at_pos, DFCMEM2);
		isif_write(isif->isif_cfg.base_addr,
			   vdfc->table[0].level_up_pixels, DFCMEM3);
		isif_write(isif->isif_cfg.base_addr,
			   vdfc->table[0].level_low_pixels, DFCMEM4);
	}

	val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
	/* set DFCMARST and set DFCMWR */
	val |= 1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT;
	val |= 1;
	isif_write(isif->isif_cfg.base_addr, val, DFCMEMCTL);

	while (count && (isif_read(isif->isif_cfg.base_addr, DFCMEMCTL) & 0x01))
		count--;

	val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
	if (!count) {
		pr_debug("defect table write timeout !!\n");
		return;
	}

	for (i = 1; i < vdfc->num_vdefects; i++) {
		isif_write(isif->isif_cfg.base_addr, vdfc->table[i].pos_vert &
			ISIF_VDFC_POS_MASK, DFCMEM0);

		isif_write(isif->isif_cfg.base_addr, vdfc->table[i].pos_horz &
			ISIF_VDFC_POS_MASK, DFCMEM1);

		if (vdfc->corr_mode == VPFE_ISIF_VDFC_NORMAL ||
		    vdfc->corr_mode == VPFE_ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
			isif_write(isif->isif_cfg.base_addr,
				   vdfc->table[i].level_at_pos, DFCMEM2);
			isif_write(isif->isif_cfg.base_addr,
				   vdfc->table[i].level_up_pixels, DFCMEM3);
			isif_write(isif->isif_cfg.base_addr,
				   vdfc->table[i].level_low_pixels, DFCMEM4);
		}
		val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
		/* clear DFCMARST and set DFCMWR */
		val &= ~(1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT);
		val |= 1;
		isif_write(isif->isif_cfg.base_addr, val, DFCMEMCTL);

		count = DFC_WRITE_WAIT_COUNT;
		while (count && (isif_read(isif->isif_cfg.base_addr,
			DFCMEMCTL) & 0x01))
			count--;

		val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
		if (!count) {
			pr_debug("defect table write timeout !!\n");
			return;
		}
	}
	if (vdfc->num_vdefects < VPFE_ISIF_VDFC_TABLE_SIZE) {
		/* Extra cycle needed */
		isif_write(isif->isif_cfg.base_addr, 0, DFCMEM0);
		isif_write(isif->isif_cfg.base_addr,
			   DM365_ISIF_MAX_DFCMEM1, DFCMEM1);
		isif_write(isif->isif_cfg.base_addr,
			   DM365_ISIF_DFCMWR_MEMORY_WRITE, DFCMEMCTL);
	}
	/* enable VDFC */
	isif_merge(isif->isif_cfg.base_addr, (1 << ISIF_VDFC_EN_SHIFT),
		   (1 << ISIF_VDFC_EN_SHIFT), DFCCTL);

	isif_merge(isif->isif_cfg.base_addr, (1 << ISIF_VDFC_EN_SHIFT),
		   (0 << ISIF_VDFC_EN_SHIFT), DFCCTL);

	isif_write(isif->isif_cfg.base_addr, 0x6, DFCMEMCTL);
	for (i = 0; i < vdfc->num_vdefects; i++) {
		count = DFC_WRITE_WAIT_COUNT;
		while (count &&
			(isif_read(isif->isif_cfg.base_addr, DFCMEMCTL) & 0x2))
			count--;
		val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
		if (!count) {
			pr_debug("defect table write timeout !!\n");
			return;
		}
		isif_write(isif->isif_cfg.base_addr,
			   DM365_ISIF_DFCMRD_MEMORY_READ, DFCMEMCTL);
	}
}

static void
isif_config_csc(struct vpfe_isif_device *isif, struct vpfe_isif_df_csc *df_csc)
{
	u32 val1;
	u32 val2;
	u32 i;

	if (!df_csc->csc.en) {
		isif_write(isif->isif_cfg.base_addr, 0, CSCCTL);
		return;
	}
	/* initialize all bits to 0 */
	val1 = 0;
	for (i = 0; i < VPFE_ISIF_CSC_NUM_COEFF; i++) {
		if ((i % 2) == 0) {
			/* CSCM - LSB */
			val1 = ((df_csc->csc.coeff[i].integer &
				ISIF_CSC_COEF_INTEG_MASK) <<
				ISIF_CSC_COEF_INTEG_SHIFT) |
				((df_csc->csc.coeff[i].decimal &
				ISIF_CSC_COEF_DECIMAL_MASK));
		} else {

			/* CSCM - MSB */
			val2 = ((df_csc->csc.coeff[i].integer &
				ISIF_CSC_COEF_INTEG_MASK) <<
				ISIF_CSC_COEF_INTEG_SHIFT) |
				((df_csc->csc.coeff[i].decimal &
				ISIF_CSC_COEF_DECIMAL_MASK));
			val2 <<= ISIF_CSCM_MSB_SHIFT;
			val2 |= val1;
			isif_write(isif->isif_cfg.base_addr, val2,
				   (CSCM0 + ((i-1) << 1)));
		}
	}
	/* program the active area */
	isif_write(isif->isif_cfg.base_addr, df_csc->start_pix &
		ISIF_DF_CSC_SPH_MASK, FMTSPH);
	/*
	 * one extra pixel as required for CSC. Actually number of
	 * pixel - 1 should be configured in this register. So we
	 * need to subtract 1 before writing to FMTSPH, but we will
	 * not do this since csc requires one extra pixel
	 */
	isif_write(isif->isif_cfg.base_addr, df_csc->num_pixels &
		ISIF_DF_CSC_SPH_MASK, FMTLNH);
	isif_write(isif->isif_cfg.base_addr, df_csc->start_line &
		ISIF_DF_CSC_SPH_MASK, FMTSLV);
	/*
	 * one extra line as required for CSC. See reason documented for
	 * num_pixels
	 */
	isif_write(isif->isif_cfg.base_addr, df_csc->num_lines &
		ISIF_DF_CSC_SPH_MASK, FMTLNV);
	/* Enable CSC */
	isif_write(isif->isif_cfg.base_addr, 1, CSCCTL);
}

static void
isif_config_linearization(struct vpfe_isif_device *isif,
			  struct vpfe_isif_linearize *linearize)
{
	u32 val;
	u32 i;

	if (!linearize->en) {
		isif_write(isif->isif_cfg.base_addr, 0, LINCFG0);
		return;
	}
	/* shift value for correction */
	val = (linearize->corr_shft & ISIF_LIN_CORRSFT_MASK) <<
	      ISIF_LIN_CORRSFT_SHIFT;
	/* enable */
	val |= 1;
	isif_write(isif->isif_cfg.base_addr, val, LINCFG0);
	/* Scale factor */
	val = (linearize->scale_fact.integer & 1) <<
	      ISIF_LIN_SCALE_FACT_INTEG_SHIFT;
	val |= linearize->scale_fact.decimal & ISIF_LIN_SCALE_FACT_DECIMAL_MASK;
	isif_write(isif->isif_cfg.base_addr, val, LINCFG1);

	for (i = 0; i < VPFE_ISIF_LINEAR_TAB_SIZE; i++) {
		val = linearize->table[i] & ISIF_LIN_ENTRY_MASK;
		if (i%2)
			isif_regw_lin_tbl(isif, val, ((i >> 1) << 2), 1);
		else
			isif_regw_lin_tbl(isif, val, ((i >> 1) << 2), 0);
	}
}

static void
isif_config_culling(struct vpfe_isif_device *isif, struct vpfe_isif_cul *cul)
{
	u32 val;

	/* Horizontal pattern */
	val = cul->hcpat_even << CULL_PAT_EVEN_LINE_SHIFT;
	val |= cul->hcpat_odd;
	isif_write(isif->isif_cfg.base_addr, val, CULH);
	/* vertical pattern */
	isif_write(isif->isif_cfg.base_addr, cul->vcpat, CULV);
	/* LPF */
	isif_merge(isif->isif_cfg.base_addr, ISIF_LPF_MASK << ISIF_LPF_SHIFT,
		   cul->en_lpf << ISIF_LPF_SHIFT, MODESET);
}

static int isif_get_pix_fmt(u32 mbus_code)
{
	switch (mbus_code) {
	case MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8:
	case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8:
	case MEDIA_BUS_FMT_SGRBG12_1X12:
		return ISIF_PIXFMT_RAW;

	case MEDIA_BUS_FMT_YUYV8_2X8:
	case MEDIA_BUS_FMT_UYVY8_2X8:
	case MEDIA_BUS_FMT_YUYV10_2X10:
	case MEDIA_BUS_FMT_Y8_1X8:
		return ISIF_PIXFMT_YCBCR_8BIT;

	case MEDIA_BUS_FMT_YUYV8_1X16:
	case MEDIA_BUS_FMT_YUYV10_1X20:
		return ISIF_PIXFMT_YCBCR_16BIT;

	default:
		break;
	}
	return -EINVAL;
}

#define ISIF_INTERLACE_INVERSE_MODE		0x4b6d
#define ISIF_INTERLACE_NON_INVERSE_MODE		0x0b6d
#define ISIF_PROGRESSIVE_INVERSE_MODE		0x4000
#define ISIF_PROGRESSIVE_NON_INVERSE_MODE	0x0000

static int isif_config_raw(struct v4l2_subdev *sd, int mode)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct isif_params_raw *params = &isif->isif_cfg.bayer;
	struct vpfe_isif_raw_config *module_params =
				&isif->isif_cfg.bayer.config_params;
	struct v4l2_mbus_framefmt *format;
	int pix_fmt;
	u32 val;

	format = &isif->formats[ISIF_PAD_SINK];

	/* In case of user has set BT656IF earlier, it should be reset
	 * when configuring for raw input.
	 */
	isif_write(isif->isif_cfg.base_addr, 0, REC656IF);
	/* Configure CCDCFG register
	 * Set CCD Not to swap input since input is RAW data
	 * Set FID detection function to Latch at V-Sync
	 * Set WENLOG - isif valid area
	 * Set TRGSEL
	 * Set EXTRG
	 * Packed to 8 or 16 bits
	 */
	val = ISIF_YCINSWP_RAW | ISIF_CCDCFG_FIDMD_LATCH_VSYNC |
	      ISIF_CCDCFG_WENLOG_AND | ISIF_CCDCFG_TRGSEL_WEN |
	      ISIF_CCDCFG_EXTRG_DISABLE | (isif->isif_cfg.data_pack &
	      ISIF_DATA_PACK_MASK);
	isif_write(isif->isif_cfg.base_addr, val, CCDCFG);

	pix_fmt = isif_get_pix_fmt(format->code);
	if (pix_fmt < 0) {
		pr_debug("Invalid pix_fmt(input mode)\n");
		return -EINVAL;
	}
	/*
	 * Configure the vertical sync polarity(MODESET.VDPOL)
	 * Configure the horizontal sync polarity (MODESET.HDPOL)
	 * Configure frame id polarity (MODESET.FLDPOL)
	 * Configure data polarity
	 * Configure External WEN Selection
	 * Configure frame format(progressive or interlace)
	 * Configure pixel format (Input mode)
	 * Configure the data shift
	 */
	val = ISIF_VDHDOUT_INPUT | ((params->vd_pol & ISIF_VD_POL_MASK) <<
	      ISIF_VD_POL_SHIFT) | ((params->hd_pol & ISIF_HD_POL_MASK) <<
	      ISIF_HD_POL_SHIFT) | ((params->fid_pol & ISIF_FID_POL_MASK) <<
	      ISIF_FID_POL_SHIFT) | ((ISIF_DATAPOL_NORMAL &
	      ISIF_DATAPOL_MASK) << ISIF_DATAPOL_SHIFT) | ((ISIF_EXWEN_DISABLE &
	      ISIF_EXWEN_MASK) << ISIF_EXWEN_SHIFT) | ((params->frm_fmt &
	      ISIF_FRM_FMT_MASK) << ISIF_FRM_FMT_SHIFT) | ((pix_fmt &
	      ISIF_INPUT_MASK) << ISIF_INPUT_SHIFT);

	/* currently only MEDIA_BUS_FMT_SGRBG12_1X12 is
	 * supported. shift appropriately depending on
	 * different MBUS fmt's added
	 */
	if (format->code == MEDIA_BUS_FMT_SGRBG12_1X12)
		val |= ((VPFE_ISIF_NO_SHIFT &
			ISIF_DATASFT_MASK) << ISIF_DATASFT_SHIFT);

	isif_write(isif->isif_cfg.base_addr, val, MODESET);
	/*
	 * Configure GAMMAWD register
	 * CFA pattern setting
	 */
	val = (params->cfa_pat & ISIF_GAMMAWD_CFA_MASK) <<
		ISIF_GAMMAWD_CFA_SHIFT;
	/* Gamma msb */
	if (params->v4l2_pix_fmt == V4L2_PIX_FMT_SGRBG10ALAW8)
		val = val | ISIF_ALAW_ENABLE;

	val = val | ((params->data_msb & ISIF_ALAW_GAMA_WD_MASK) <<
			ISIF_ALAW_GAMA_WD_SHIFT);

	isif_write(isif->isif_cfg.base_addr, val, CGAMMAWD);
	/* Configure DPCM compression settings */
	if (params->v4l2_pix_fmt == V4L2_PIX_FMT_SGRBG10DPCM8) {
		val =  1 << ISIF_DPCM_EN_SHIFT;
		val |= (params->dpcm_predictor &
			ISIF_DPCM_PREDICTOR_MASK) << ISIF_DPCM_PREDICTOR_SHIFT;
	}
	isif_write(isif->isif_cfg.base_addr, val, MISC);
	/* Configure Gain & Offset */
	isif_config_gain_offset(isif);
	/* Configure Color pattern */
	if (format->code == MEDIA_BUS_FMT_SGRBG12_1X12)
		val = isif_sgrbg_pattern;
	else
		/* default set to rggb */
		val = isif_srggb_pattern;

	isif_write(isif->isif_cfg.base_addr, val, CCOLP);

	/* Configure HSIZE register  */
	val = (params->horz_flip_en & ISIF_HSIZE_FLIP_MASK) <<
	      ISIF_HSIZE_FLIP_SHIFT;

	/* calculate line offset in 32 bytes based on pack value */
	if (isif->isif_cfg.data_pack == ISIF_PACK_8BIT)
		val |= ((params->win.width + 31) >> 5) & ISIF_LINEOFST_MASK;
	else if (isif->isif_cfg.data_pack == ISIF_PACK_12BIT)
		val |= ((((params->win.width + (params->win.width >> 2)) +
			31) >> 5) & ISIF_LINEOFST_MASK);
	else
		val |= (((params->win.width * 2) + 31) >> 5) &
			ISIF_LINEOFST_MASK;
	isif_write(isif->isif_cfg.base_addr, val, HSIZE);
	/* Configure SDOFST register  */
	if (params->frm_fmt == ISIF_FRMFMT_INTERLACED) {
		if (params->image_invert_en)
			/* For interlace inverse mode */
			isif_write(isif->isif_cfg.base_addr,
				   ISIF_INTERLACE_INVERSE_MODE, SDOFST);
		else
			/* For interlace non inverse mode */
			isif_write(isif->isif_cfg.base_addr,
				   ISIF_INTERLACE_NON_INVERSE_MODE, SDOFST);
	} else if (params->frm_fmt == ISIF_FRMFMT_PROGRESSIVE) {
		if (params->image_invert_en)
			isif_write(isif->isif_cfg.base_addr,
				   ISIF_PROGRESSIVE_INVERSE_MODE, SDOFST);
		else
			/* For progessive non inverse mode */
			isif_write(isif->isif_cfg.base_addr,
				   ISIF_PROGRESSIVE_NON_INVERSE_MODE, SDOFST);
	}
	/* Configure video window */
	isif_setwin(isif, &params->win, params->frm_fmt, 1, mode);
	/* Configure Black Clamp */
	isif_config_bclamp(isif, &module_params->bclamp);
	/* Configure Vertical Defection Pixel Correction */
	isif_config_dfc(isif, &module_params->dfc);
	if (!module_params->df_csc.df_or_csc)
		/* Configure Color Space Conversion */
		isif_config_csc(isif, &module_params->df_csc);

	isif_config_linearization(isif, &module_params->linearize);
	/* Configure Culling */
	isif_config_culling(isif, &module_params->culling);
	/* Configure Horizontal and vertical offsets(DFC,LSC,Gain) */
	val = module_params->horz_offset & ISIF_DATA_H_OFFSET_MASK;
	isif_write(isif->isif_cfg.base_addr, val, DATAHOFST);

	val = module_params->vert_offset & ISIF_DATA_V_OFFSET_MASK;
	isif_write(isif->isif_cfg.base_addr, val, DATAVOFST);

	return 0;
}

#define DM365_ISIF_HSIZE_MASK		0xffffffe0
#define DM365_ISIF_SDOFST_2_LINES	0x00000249

/* This function will configure ISIF for YCbCr parameters. */
static int isif_config_ycbcr(struct v4l2_subdev *sd, int mode)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct isif_ycbcr_config *params = &isif->isif_cfg.ycbcr;
	struct v4l2_mbus_framefmt *format;
	int pix_fmt;
	u32 modeset;
	u32 ccdcfg;

	format = &isif->formats[ISIF_PAD_SINK];
	/*
	 * first reset the ISIF
	 * all registers have default values after reset
	 * This is important since we assume default values to be set in
	 * a lot of registers that we didn't touch
	 */
	/* start with all bits zero */
	ccdcfg = 0;
	modeset = 0;
	pix_fmt = isif_get_pix_fmt(format->code);
	if (pix_fmt < 0) {
		pr_debug("Invalid pix_fmt(input mode)\n");
		return -EINVAL;
	}
	/* configure pixel format or input mode */
	modeset = modeset | ((pix_fmt & ISIF_INPUT_MASK) <<
		  ISIF_INPUT_SHIFT) | ((params->frm_fmt & ISIF_FRM_FMT_MASK) <<
		  ISIF_FRM_FMT_SHIFT) | (((params->fid_pol &
		  ISIF_FID_POL_MASK) << ISIF_FID_POL_SHIFT)) |
		  (((params->hd_pol & ISIF_HD_POL_MASK) << ISIF_HD_POL_SHIFT)) |
		  (((params->vd_pol & ISIF_VD_POL_MASK) << ISIF_VD_POL_SHIFT));
	/* pack the data to 8-bit CCDCCFG */
	switch (format->code) {
	case MEDIA_BUS_FMT_YUYV8_2X8:
	case MEDIA_BUS_FMT_UYVY8_2X8:
		if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
			pr_debug("Invalid pix_fmt(input mode)\n");
			return -EINVAL;
		}
		modeset |= ((VPFE_PINPOL_NEGATIVE & ISIF_VD_POL_MASK) <<
				ISIF_VD_POL_SHIFT);
		isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
		ccdcfg = ccdcfg | ISIF_PACK_8BIT | ISIF_YCINSWP_YCBCR;
		break;

	case MEDIA_BUS_FMT_YUYV10_2X10:
		if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
			pr_debug("Invalid pix_fmt(input mode)\n");
			return -EINVAL;
		}
		/* setup BT.656, embedded sync  */
		isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
		/* enable 10 bit mode in ccdcfg */
		ccdcfg = ccdcfg | ISIF_PACK_8BIT | ISIF_YCINSWP_YCBCR |
			ISIF_BW656_ENABLE;
		break;

	case MEDIA_BUS_FMT_YUYV10_1X20:
		if (pix_fmt != ISIF_PIXFMT_YCBCR_16BIT) {
			pr_debug("Invalid pix_fmt(input mode)\n");
			return -EINVAL;
		}
		isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
		break;

	case MEDIA_BUS_FMT_Y8_1X8:
		ccdcfg |= ISIF_PACK_8BIT;
		ccdcfg |= ISIF_YCINSWP_YCBCR;
		if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
			pr_debug("Invalid pix_fmt(input mode)\n");
			return -EINVAL;
		}
		break;

	case MEDIA_BUS_FMT_YUYV8_1X16:
		if (pix_fmt != ISIF_PIXFMT_YCBCR_16BIT) {
			pr_debug("Invalid pix_fmt(input mode)\n");
			return -EINVAL;
		}
		break;

	default:
		/* should never come here */
		pr_debug("Invalid interface type\n");
		return -EINVAL;
	}
	isif_write(isif->isif_cfg.base_addr, modeset, MODESET);
	/* Set up pix order */
	ccdcfg |= (params->pix_order & ISIF_PIX_ORDER_MASK) <<
		ISIF_PIX_ORDER_SHIFT;
	isif_write(isif->isif_cfg.base_addr, ccdcfg, CCDCFG);
	/* configure video window */
	if (format->code == MEDIA_BUS_FMT_YUYV10_1X20 ||
			format->code == MEDIA_BUS_FMT_YUYV8_1X16)
		isif_setwin(isif, &params->win, params->frm_fmt, 1, mode);
	else
		isif_setwin(isif, &params->win, params->frm_fmt, 2, mode);

	/*
	 * configure the horizontal line offset
	 * this is done by rounding up width to a multiple of 16 pixels
	 * and multiply by two to account for y:cb:cr 4:2:2 data
	 */
	isif_write(isif->isif_cfg.base_addr,
		   ((((params->win.width * 2) + 31) &
		   DM365_ISIF_HSIZE_MASK) >> 5), HSIZE);

	/* configure the memory line offset */
	if (params->frm_fmt == ISIF_FRMFMT_INTERLACED &&
	    params->buf_type == ISIF_BUFTYPE_FLD_INTERLEAVED)
		/* two fields are interleaved in memory */
		isif_write(isif->isif_cfg.base_addr,
			   DM365_ISIF_SDOFST_2_LINES, SDOFST);
	return 0;
}

static int isif_configure(struct v4l2_subdev *sd, int mode)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct v4l2_mbus_framefmt *format;

	format = &isif->formats[ISIF_PAD_SINK];

	switch (format->code) {
	case MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8:
	case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8:
	case MEDIA_BUS_FMT_SGRBG12_1X12:
		return isif_config_raw(sd, mode);

	case MEDIA_BUS_FMT_YUYV8_2X8:
	case MEDIA_BUS_FMT_UYVY8_2X8:
	case MEDIA_BUS_FMT_YUYV10_2X10:
	case MEDIA_BUS_FMT_Y8_1X8:
	case MEDIA_BUS_FMT_YUYV8_1X16:
	case MEDIA_BUS_FMT_YUYV10_1X20:
		return isif_config_ycbcr(sd, mode);

	default:
		break;
	}
	return -EINVAL;
}

/*
 * isif_set_stream() - Enable/Disable streaming on the ISIF module
 * @sd: VPFE ISIF V4L2 subdevice
 * @enable: Enable/disable stream
 */
static int isif_set_stream(struct v4l2_subdev *sd, int enable)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	int ret;

	if (enable) {
		ret = isif_configure(sd,
			(isif->output == ISIF_OUTPUT_MEMORY) ? 0 : 1);
		if (ret)
			return ret;
		if (isif->output == ISIF_OUTPUT_MEMORY)
			isif_enable_output_to_sdram(isif, 1);
		isif_enable(isif, 1);
	} else {
		isif_enable(isif, 0);
		isif_enable_output_to_sdram(isif, 0);
	}

	return 0;
}

/*
 * __isif_get_format() - helper function for getting isif format
 * @isif: pointer to isif private structure.
 * @pad: pad number.
 * @cfg: V4L2 subdev pad config
 * @which: wanted subdev format.
 */
static struct v4l2_mbus_framefmt *
__isif_get_format(struct vpfe_isif_device *isif,
		  struct v4l2_subdev_pad_config *cfg, unsigned int pad,
		  enum v4l2_subdev_format_whence which)
{
	if (which == V4L2_SUBDEV_FORMAT_TRY) {
		struct v4l2_subdev_format fmt;

		fmt.pad = pad;
		fmt.which = which;

		return v4l2_subdev_get_try_format(&isif->subdev, cfg, pad);
	}
	return &isif->formats[pad];
}

/*
 * isif_set_format() - set format on pad
 * @sd    : VPFE ISIF device
 * @cfg   : V4L2 subdev pad config
 * @fmt   : pointer to v4l2 subdev format structure
 *
 * Return 0 on success or -EINVAL if format or pad is invalid
 */
static int
isif_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *fmt)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
	struct v4l2_mbus_framefmt *format;

	format = __isif_get_format(isif, cfg, fmt->pad, fmt->which);
	if (format == NULL)
		return -EINVAL;

	isif_try_format(isif, cfg, fmt);
	memcpy(format, &fmt->format, sizeof(*format));

	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
		return 0;

	if (fmt->pad == ISIF_PAD_SOURCE)
		return isif_config_format(vpfe_dev, fmt->pad);

	return 0;
}

/*
 * isif_get_format() - Retrieve the video format on a pad
 * @sd: VPFE ISIF V4L2 subdevice
 * @cfg: V4L2 subdev pad config
 * @fmt: pointer to v4l2 subdev format structure
 *
 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
 * to the format type.
 */
static int
isif_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *fmt)
{
	struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
	struct v4l2_mbus_framefmt *format;

	format = __isif_get_format(vpfe_isif, cfg, fmt->pad, fmt->which);
	if (format == NULL)
		return -EINVAL;

	memcpy(&fmt->format, format, sizeof(fmt->format));

	return 0;
}

/*
 * isif_enum_frame_size() - enum frame sizes on pads
 * @sd: VPFE isif V4L2 subdevice
 * @cfg: V4L2 subdev pad config
 * @code: pointer to v4l2_subdev_frame_size_enum structure
 */
static int
isif_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
		     struct v4l2_subdev_frame_size_enum *fse)
{
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	struct v4l2_subdev_format format;

	if (fse->index != 0)
		return -EINVAL;

	format.pad = fse->pad;
	format.format.code = fse->code;
	format.format.width = 1;
	format.format.height = 1;
	format.which = fse->which;
	isif_try_format(isif, cfg, &format);
	fse->min_width = format.format.width;
	fse->min_height = format.format.height;

	if (format.format.code != fse->code)
		return -EINVAL;

	format.pad = fse->pad;
	format.format.code = fse->code;
	format.format.width = -1;
	format.format.height = -1;
	format.which = fse->which;
	isif_try_format(isif, cfg, &format);
	fse->max_width = format.format.width;
	fse->max_height = format.format.height;

	return 0;
}

/*
 * isif_enum_mbus_code() - enum mbus codes for pads
 * @sd: VPFE isif V4L2 subdevice
 * @cfg: V4L2 subdev pad config
 * @code: pointer to v4l2_subdev_mbus_code_enum structure
 */
static int
isif_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
		    struct v4l2_subdev_mbus_code_enum *code)
{
	switch (code->pad) {
	case ISIF_PAD_SINK:
	case ISIF_PAD_SOURCE:
		if (code->index >= ARRAY_SIZE(isif_fmts))
			return -EINVAL;
		code->code = isif_fmts[code->index];
		break;

	default:
		return -EINVAL;
	}

	return 0;
}

/*
 * isif_pad_set_selection() - set crop rectangle on pad
 * @sd: VPFE isif V4L2 subdevice
 * @cfg: V4L2 subdev pad config
 * @code: pointer to v4l2_subdev_mbus_code_enum structure
 *
 * Return 0 on success, -EINVAL if pad is invalid
 */
static int
isif_pad_set_selection(struct v4l2_subdev *sd,
		       struct v4l2_subdev_pad_config *cfg,
		       struct v4l2_subdev_selection *sel)
{
	struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
	struct v4l2_mbus_framefmt *format;

	/* check whether it's a valid pad and target */
	if (sel->pad != ISIF_PAD_SINK || sel->target != V4L2_SEL_TGT_CROP)
		return -EINVAL;

	format = __isif_get_format(vpfe_isif, cfg, sel->pad, sel->which);
	if (format == NULL)
		return -EINVAL;

	/* check wether crop rect is within limits */
	if (sel->r.top < 0 || sel->r.left < 0 ||
		(sel->r.left + sel->r.width >
		vpfe_isif->formats[ISIF_PAD_SINK].width) ||
		(sel->r.top + sel->r.height >
			vpfe_isif->formats[ISIF_PAD_SINK].height)) {
		sel->r.left = 0;
		sel->r.top = 0;
		sel->r.width = format->width;
		sel->r.height = format->height;
	}
	/* adjust the width to 16 pixel boundary */
	sel->r.width = (sel->r.width + 15) & ~0xf;
	vpfe_isif->crop = sel->r;
	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
		isif_set_image_window(vpfe_isif);
	} else {
		struct v4l2_rect *rect;

		rect = v4l2_subdev_get_try_crop(sd, cfg, ISIF_PAD_SINK);
		memcpy(rect, &vpfe_isif->crop, sizeof(*rect));
	}
	return 0;
}

/*
 * isif_pad_get_selection() - get crop rectangle on pad
 * @sd: VPFE isif V4L2 subdevice
 * @cfg: V4L2 subdev pad config
 * @code: pointer to v4l2_subdev_mbus_code_enum structure
 *
 * Return 0 on success, -EINVAL if pad is invalid
 */
static int
isif_pad_get_selection(struct v4l2_subdev *sd,
		       struct v4l2_subdev_pad_config *cfg,
		       struct v4l2_subdev_selection *sel)
{
	struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);

	/* check whether it's a valid pad and target */
	if (sel->pad != ISIF_PAD_SINK || sel->target != V4L2_SEL_TGT_CROP)
		return -EINVAL;

	if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
		struct v4l2_rect *rect;

		rect = v4l2_subdev_get_try_crop(sd, cfg, ISIF_PAD_SINK);
		memcpy(&sel->r, rect, sizeof(*rect));
	} else {
		sel->r = vpfe_isif->crop;
	}

	return 0;
}

/*
 * isif_init_formats() - Initialize formats on all pads
 * @sd: VPFE isif V4L2 subdevice
 * @fh: V4L2 subdev file handle
 *
 * Initialize all pad formats with default values. Try formats are initialized
 * on the file handle.
 */
static int
isif_init_formats(struct v4l2_subdev *sd,
		  struct v4l2_subdev_fh *fh)
{
	struct v4l2_subdev_format format;
	struct v4l2_subdev_selection sel;

	memset(&format, 0, sizeof(format));
	format.pad = ISIF_PAD_SINK;
	format.which = V4L2_SUBDEV_FORMAT_TRY;
	format.format.code = MEDIA_BUS_FMT_SGRBG12_1X12;
	format.format.width = MAX_WIDTH;
	format.format.height = MAX_HEIGHT;
	isif_set_format(sd, fh->pad, &format);

	memset(&format, 0, sizeof(format));
	format.pad = ISIF_PAD_SOURCE;
	format.which = V4L2_SUBDEV_FORMAT_TRY;
	format.format.code = MEDIA_BUS_FMT_SGRBG12_1X12;
	format.format.width = MAX_WIDTH;
	format.format.height = MAX_HEIGHT;
	isif_set_format(sd, fh->pad, &format);

	memset(&sel, 0, sizeof(sel));
	sel.pad = ISIF_PAD_SINK;
	sel.which = V4L2_SUBDEV_FORMAT_TRY;
	sel.target = V4L2_SEL_TGT_CROP;
	sel.r.width = MAX_WIDTH;
	sel.r.height = MAX_HEIGHT;
	isif_pad_set_selection(sd, fh->pad, &sel);

	return 0;
}

/* subdev core operations */
static const struct v4l2_subdev_core_ops isif_v4l2_core_ops = {
	.ioctl = isif_ioctl,
};

/* subdev file operations */
static const struct v4l2_subdev_internal_ops isif_v4l2_internal_ops = {
	.open = isif_init_formats,
};

/* subdev video operations */
static const struct v4l2_subdev_video_ops isif_v4l2_video_ops = {
	.s_stream = isif_set_stream,
};

/* subdev pad operations */
static const struct v4l2_subdev_pad_ops isif_v4l2_pad_ops = {
	.enum_mbus_code = isif_enum_mbus_code,
	.enum_frame_size = isif_enum_frame_size,
	.get_fmt = isif_get_format,
	.set_fmt = isif_set_format,
	.set_selection = isif_pad_set_selection,
	.get_selection = isif_pad_get_selection,
};

/* subdev operations */
static const struct v4l2_subdev_ops isif_v4l2_ops = {
	.core = &isif_v4l2_core_ops,
	.video = &isif_v4l2_video_ops,
	.pad = &isif_v4l2_pad_ops,
};

/*
 * Media entity operations
 */

/*
 * isif_link_setup() - Setup isif connections
 * @entity: isif media entity
 * @local: Pad at the local end of the link
 * @remote: Pad at the remote end of the link
 * @flags: Link flags
 *
 * return -EINVAL or zero on success
 */
static int
isif_link_setup(struct media_entity *entity, const struct media_pad *local,
		const struct media_pad *remote, u32 flags)
{
	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
	struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
	unsigned int index = local->index;

	/* FIXME: this is actually a hack! */
	if (is_media_entity_v4l2_subdev(remote->entity))
		index |= 2 << 16;

	switch (index) {
	case ISIF_PAD_SINK | 2 << 16:
		/* read from decoder/sensor */
		if (!(flags & MEDIA_LNK_FL_ENABLED)) {
			isif->input = ISIF_INPUT_NONE;
			break;
		}
		if (isif->input != ISIF_INPUT_NONE)
			return -EBUSY;
		isif->input = ISIF_INPUT_PARALLEL;
		break;

	case ISIF_PAD_SOURCE:
		/* write to memory */
		if (flags & MEDIA_LNK_FL_ENABLED)
			isif->output = ISIF_OUTPUT_MEMORY;
		else
			isif->output = ISIF_OUTPUT_NONE;
		break;

	case ISIF_PAD_SOURCE | 2 << 16:
		if (flags & MEDIA_LNK_FL_ENABLED)
			isif->output = ISIF_OUTPUT_IPIPEIF;
		else
			isif->output = ISIF_OUTPUT_NONE;
		break;

	default:
		return -EINVAL;
	}

	return 0;
}
static const struct media_entity_operations isif_media_ops = {
	.link_setup = isif_link_setup,
};

/*
 * vpfe_isif_unregister_entities() - isif unregister entity
 * @isif - pointer to isif subdevice structure.
 */
void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif)
{
	vpfe_video_unregister(&isif->video_out);
	/* unregister subdev */
	v4l2_device_unregister_subdev(&isif->subdev);
	/* cleanup entity */
	media_entity_cleanup(&isif->subdev.entity);
}

static void isif_restore_defaults(struct vpfe_isif_device *isif)
{
	enum vpss_ccdc_source_sel source = VPSS_CCDCIN;
	int i;

	memset(&isif->isif_cfg.bayer.config_params, 0,
	       sizeof(struct vpfe_isif_raw_config));

	isif->isif_cfg.bayer.config_params.linearize.corr_shft =
					VPFE_ISIF_NO_SHIFT;
	isif->isif_cfg.bayer.config_params.linearize.scale_fact.integer = 1;
	isif->isif_cfg.bayer.config_params.culling.hcpat_odd =
			ISIF_CULLING_HCAPT_ODD;
	isif->isif_cfg.bayer.config_params.culling.hcpat_even =
			ISIF_CULLING_HCAPT_EVEN;
	isif->isif_cfg.bayer.config_params.culling.vcpat = ISIF_CULLING_VCAPT;
	/* Enable clock to ISIF, IPIPEIF and BL */
	vpss_enable_clock(VPSS_CCDC_CLOCK, 1);
	vpss_enable_clock(VPSS_IPIPEIF_CLOCK, 1);
	vpss_enable_clock(VPSS_BL_CLOCK, 1);

	/* set all registers to default value */
	for (i = 0; i <= 0x1f8; i += 4)
		isif_write(isif->isif_cfg.base_addr, 0, i);
	/* no culling support */
	isif_write(isif->isif_cfg.base_addr, 0xffff, CULH);
	isif_write(isif->isif_cfg.base_addr, 0xff, CULV);

	/* Set default offset and gain */
	isif_config_gain_offset(isif);
	vpss_select_ccdc_source(source);
}

/*
 * vpfe_isif_register_entities() - isif register entity
 * @isif - pointer to isif subdevice structure.
 * @vdev: pointer to v4l2 device structure.
 */
int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
			    struct v4l2_device *vdev)
{
	struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
	unsigned int flags;
	int ret;

	/* Register the subdev */
	ret = v4l2_device_register_subdev(vdev, &isif->subdev);
	if (ret < 0)
		return ret;

	isif_restore_defaults(isif);
	ret = vpfe_video_register(&isif->video_out, vdev);
	if (ret) {
		pr_err("Failed to register isif video out device\n");
		goto out_video_register;
	}
	isif->video_out.vpfe_dev = vpfe_dev;
	flags = 0;
	/* connect isif to video node */
	ret = media_create_pad_link(&isif->subdev.entity, 1,
				       &isif->video_out.video_dev.entity,
				       0, flags);
	if (ret < 0)
		goto out_create_link;
	return 0;
out_create_link:
	vpfe_video_unregister(&isif->video_out);
out_video_register:
	v4l2_device_unregister_subdev(&isif->subdev);
	return ret;
}

/* -------------------------------------------------------------------
 * V4L2 subdev control operations
 */

static int vpfe_isif_s_ctrl(struct v4l2_ctrl *ctrl)
{
	struct vpfe_isif_device *isif =
	     container_of(ctrl->handler, struct vpfe_isif_device, ctrls);
	struct isif_oper_config *config = &isif->isif_cfg;

	switch (ctrl->id) {
	case VPFE_CID_DPCM_PREDICTOR:
		config->bayer.dpcm_predictor = ctrl->val;
		break;

	case VPFE_ISIF_CID_CRGAIN:
		config->isif_gain_params.cr_gain = ctrl->val;
		break;

	case VPFE_ISIF_CID_CGRGAIN:
		config->isif_gain_params.cgr_gain = ctrl->val;
		break;

	case VPFE_ISIF_CID_CGBGAIN:
		config->isif_gain_params.cgb_gain = ctrl->val;
		break;

	case VPFE_ISIF_CID_CBGAIN:
		config->isif_gain_params.cb_gain = ctrl->val;
		break;

	case VPFE_ISIF_CID_GAIN_OFFSET:
		config->isif_gain_params.offset = ctrl->val;
		break;

	default:
		return -EINVAL;
	}
	return 0;
}

static const struct v4l2_ctrl_ops vpfe_isif_ctrl_ops = {
	.s_ctrl = vpfe_isif_s_ctrl,
};

static const struct v4l2_ctrl_config vpfe_isif_dpcm_pred = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_CID_DPCM_PREDICTOR,
	.name = "DPCM Predictor",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = 1,
	.step = 1,
	.def = 0,
};

static const struct v4l2_ctrl_config vpfe_isif_crgain = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_ISIF_CID_CRGAIN,
	.name = "CRGAIN",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = (1 << 12) - 1,
	.step = 1,
	.def = 0,
};

static const struct v4l2_ctrl_config vpfe_isif_cgrgain = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_ISIF_CID_CGRGAIN,
	.name = "CGRGAIN",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = (1 << 12) - 1,
	.step = 1,
	.def = 0,
};

static const struct v4l2_ctrl_config vpfe_isif_cgbgain = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_ISIF_CID_CGBGAIN,
	.name = "CGBGAIN",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = (1 << 12) - 1,
	.step = 1,
	.def = 0,
};

static const struct v4l2_ctrl_config vpfe_isif_cbgain = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_ISIF_CID_CBGAIN,
	.name = "CBGAIN",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = (1 << 12) - 1,
	.step = 1,
	.def = 0,
};

static const struct v4l2_ctrl_config vpfe_isif_gain_offset = {
	.ops = &vpfe_isif_ctrl_ops,
	.id = VPFE_ISIF_CID_GAIN_OFFSET,
	.name = "Gain Offset",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.min = 0,
	.max = (1 << 12) - 1,
	.step = 1,
	.def = 0,
};

static void isif_remove(struct vpfe_isif_device *isif,
			struct platform_device *pdev)
{
	struct resource *res;
	int i = 0;

	iounmap(isif->isif_cfg.base_addr);
	iounmap(isif->isif_cfg.linear_tbl0_addr);
	iounmap(isif->isif_cfg.linear_tbl1_addr);

	while (i < 3) {
		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
		if (res)
			release_mem_region(res->start,
					   resource_size(res));
		i++;
	}
}

static void isif_config_defaults(struct vpfe_isif_device *isif)
{
	isif->isif_cfg.ycbcr.v4l2_pix_fmt = V4L2_PIX_FMT_UYVY;
	isif->isif_cfg.ycbcr.pix_fmt = ISIF_PIXFMT_YCBCR_8BIT;
	isif->isif_cfg.ycbcr.frm_fmt = ISIF_FRMFMT_INTERLACED;
	isif->isif_cfg.ycbcr.fid_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.ycbcr.vd_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.ycbcr.hd_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_CBYCRY;
	isif->isif_cfg.ycbcr.buf_type = ISIF_BUFTYPE_FLD_INTERLEAVED;

	isif->isif_cfg.bayer.v4l2_pix_fmt = V4L2_PIX_FMT_SGRBG10ALAW8;
	isif->isif_cfg.bayer.pix_fmt = ISIF_PIXFMT_RAW;
	isif->isif_cfg.bayer.frm_fmt = ISIF_FRMFMT_PROGRESSIVE;
	isif->isif_cfg.bayer.fid_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.bayer.vd_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.bayer.hd_pol = VPFE_PINPOL_POSITIVE;
	isif->isif_cfg.bayer.cfa_pat = ISIF_CFA_PAT_MOSAIC;
	isif->isif_cfg.bayer.data_msb = ISIF_BIT_MSB_11;
	isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
}
/*
 * vpfe_isif_init() - Initialize V4L2 subdev and media entity
 * @isif: VPFE isif module
 * @pdev: Pointer to platform device structure.
 * Return 0 on success and a negative error code on failure.
 */
int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
{
	struct v4l2_subdev *sd = &isif->subdev;
	struct media_pad *pads = &isif->pads[0];
	struct media_entity *me = &sd->entity;
	static resource_size_t res_len;
	struct resource *res;
	void __iomem *addr;
	int status;
	int i = 0;

	/* Get the ISIF base address, linearization table0 and table1 addr. */
	while (i < 3) {
		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
		if (!res) {
			status = -ENOENT;
			goto fail_nobase_res;
		}
		res_len = resource_size(res);
		res = request_mem_region(res->start, res_len, res->name);
		if (!res) {
			status = -EBUSY;
			goto fail_nobase_res;
		}
		addr = ioremap_nocache(res->start, res_len);
		if (!addr) {
			status = -EBUSY;
			goto fail_base_iomap;
		}
		switch (i) {
		case 0:
			/* ISIF base address */
			isif->isif_cfg.base_addr = addr;
			break;
		case 1:
			/* ISIF linear tbl0 address */
			isif->isif_cfg.linear_tbl0_addr = addr;
			break;
		default:
			/* ISIF linear tbl0 address */
			isif->isif_cfg.linear_tbl1_addr = addr;
			break;
		}
		i++;
	}
	davinci_cfg_reg(DM365_VIN_CAM_WEN);
	davinci_cfg_reg(DM365_VIN_CAM_VD);
	davinci_cfg_reg(DM365_VIN_CAM_HD);
	davinci_cfg_reg(DM365_VIN_YIN4_7_EN);
	davinci_cfg_reg(DM365_VIN_YIN0_3_EN);

	/* queue ops */
	isif->video_out.ops = &isif_video_ops;
	v4l2_subdev_init(sd, &isif_v4l2_ops);
	sd->internal_ops = &isif_v4l2_internal_ops;
	strlcpy(sd->name, "DAVINCI ISIF", sizeof(sd->name));
	sd->grp_id = 1 << 16;	/* group ID for davinci subdevs */
	v4l2_set_subdevdata(sd, isif);
	sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
	pads[ISIF_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
	pads[ISIF_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;

	isif->input = ISIF_INPUT_NONE;
	isif->output = ISIF_OUTPUT_NONE;
	me->ops = &isif_media_ops;
	status = media_entity_pads_init(me, ISIF_PADS_NUM, pads);
	if (status)
		goto isif_fail;
	isif->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	status = vpfe_video_init(&isif->video_out, "ISIF");
	if (status) {
		pr_err("Failed to init isif-out video device\n");
		goto isif_fail;
	}
	v4l2_ctrl_handler_init(&isif->ctrls, 6);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_crgain, NULL);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cgrgain, NULL);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cgbgain, NULL);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cbgain, NULL);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_gain_offset, NULL);
	v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_dpcm_pred, NULL);

	v4l2_ctrl_handler_setup(&isif->ctrls);
	sd->ctrl_handler = &isif->ctrls;
	isif_config_defaults(isif);
	return 0;
fail_base_iomap:
	release_mem_region(res->start, res_len);
	i--;
fail_nobase_res:
	if (isif->isif_cfg.base_addr)
		iounmap(isif->isif_cfg.base_addr);
	if (isif->isif_cfg.linear_tbl0_addr)
		iounmap(isif->isif_cfg.linear_tbl0_addr);

	while (i >= 0) {
		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
		release_mem_region(res->start, res_len);
		i--;
	}
	return status;
isif_fail:
	v4l2_ctrl_handler_free(&isif->ctrls);
	isif_remove(isif, pdev);
	return status;
}

/*
 * vpfe_isif_cleanup - isif module cleanup
 * @isif: pointer to isif subdevice
 * @dev: pointer to platform device structure
 */
void
vpfe_isif_cleanup(struct vpfe_isif_device *isif, struct platform_device *pdev)
{
	isif_remove(isif, pdev);
}