Loading...
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 | /*
* Support for OmniVision OV5693 1080p HD camera sensor.
*
* Copyright (c) 2013 Intel Corporation. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/kmod.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/moduleparam.h>
#include <media/v4l2-device.h>
#include <linux/io.h>
#include <linux/acpi.h>
#include "../../include/linux/atomisp_gmin_platform.h"
#include "ov5693.h"
#include "ad5823.h"
#define __cci_delay(t) \
do { \
if ((t) < 10) { \
usleep_range((t) * 1000, ((t) + 1) * 1000); \
} else { \
msleep((t)); \
} \
} while (0)
/* Value 30ms reached through experimentation on byt ecs.
* The DS specifies a much lower value but when using a smaller value
* the I2C bus sometimes locks up permanently when starting the camera.
* This issue could not be reproduced on cht, so we can reduce the
* delay value to a lower value when insmod.
*/
static uint up_delay = 30;
module_param(up_delay, uint, 0644);
MODULE_PARM_DESC(up_delay, "Delay prior to the first CCI transaction for ov5693");
static int vcm_ad_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
{
int err;
struct i2c_msg msg;
u8 buf[2];
buf[0] = reg;
buf[1] = val;
msg.addr = VCM_ADDR;
msg.flags = 0;
msg.len = 2;
msg.buf = &buf[0];
err = i2c_transfer(client->adapter, &msg, 1);
if (err != 1) {
dev_err(&client->dev, "%s: vcm i2c fail, err code = %d\n",
__func__, err);
return -EIO;
}
return 0;
}
static int ad5823_i2c_write(struct i2c_client *client, u8 reg, u8 val)
{
struct i2c_msg msg;
u8 buf[2];
buf[0] = reg;
buf[1] = val;
msg.addr = AD5823_VCM_ADDR;
msg.flags = 0;
msg.len = 0x02;
msg.buf = &buf[0];
if (i2c_transfer(client->adapter, &msg, 1) != 1)
return -EIO;
return 0;
}
static int ad5823_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
{
struct i2c_msg msg[2];
u8 buf[2];
buf[0] = reg;
buf[1] = 0;
msg[0].addr = AD5823_VCM_ADDR;
msg[0].flags = 0;
msg[0].len = 0x01;
msg[0].buf = &buf[0];
msg[1].addr = 0x0c;
msg[1].flags = I2C_M_RD;
msg[1].len = 0x01;
msg[1].buf = &buf[1];
*val = 0;
if (i2c_transfer(client->adapter, msg, 2) != 2)
return -EIO;
*val = buf[1];
return 0;
}
static const uint32_t ov5693_embedded_effective_size = 28;
/* i2c read/write stuff */
static int ov5693_read_reg(struct i2c_client *client,
u16 data_length, u16 reg, u16 *val)
{
int err;
struct i2c_msg msg[2];
unsigned char data[6];
if (!client->adapter) {
dev_err(&client->dev, "%s error, no client->adapter\n",
__func__);
return -ENODEV;
}
if (data_length != OV5693_8BIT && data_length != OV5693_16BIT
&& data_length != OV5693_32BIT) {
dev_err(&client->dev, "%s error, invalid data length\n",
__func__);
return -EINVAL;
}
memset(msg, 0, sizeof(msg));
msg[0].addr = client->addr;
msg[0].flags = 0;
msg[0].len = I2C_MSG_LENGTH;
msg[0].buf = data;
/* high byte goes out first */
data[0] = (u8)(reg >> 8);
data[1] = (u8)(reg & 0xff);
msg[1].addr = client->addr;
msg[1].len = data_length;
msg[1].flags = I2C_M_RD;
msg[1].buf = data;
err = i2c_transfer(client->adapter, msg, 2);
if (err != 2) {
if (err >= 0)
err = -EIO;
dev_err(&client->dev,
"read from offset 0x%x error %d", reg, err);
return err;
}
*val = 0;
/* high byte comes first */
if (data_length == OV5693_8BIT)
*val = (u8)data[0];
else if (data_length == OV5693_16BIT)
*val = be16_to_cpu(*(u16 *)&data[0]);
else
*val = be32_to_cpu(*(u32 *)&data[0]);
return 0;
}
static int ov5693_i2c_write(struct i2c_client *client, u16 len, u8 *data)
{
struct i2c_msg msg;
const int num_msg = 1;
int ret;
msg.addr = client->addr;
msg.flags = 0;
msg.len = len;
msg.buf = data;
ret = i2c_transfer(client->adapter, &msg, 1);
return ret == num_msg ? 0 : -EIO;
}
static int vcm_dw_i2c_write(struct i2c_client *client, u16 data)
{
struct i2c_msg msg;
const int num_msg = 1;
int ret;
u16 val;
val = cpu_to_be16(data);
msg.addr = VCM_ADDR;
msg.flags = 0;
msg.len = OV5693_16BIT;
msg.buf = (u8 *)&val;
ret = i2c_transfer(client->adapter, &msg, 1);
return ret == num_msg ? 0 : -EIO;
}
/* Theory: per datasheet, the two VCMs both allow for a 2-byte read.
* The DW9714 doesn't actually specify what this does (it has a
* two-byte write-only protocol, but specifies the read sequence as
* legal), but it returns the same data (zeroes) always, after an
* undocumented initial NAK. The AD5823 has a one-byte address
* register to which all writes go, and subsequent reads will cycle
* through the 8 bytes of registers. Notably, the default values (the
* device is always power-cycled affirmatively, so we can rely on
* these) in AD5823 are not pairwise repetitions of the same 16 bit
* word. So all we have to do is sequentially read two bytes at a
* time and see if we detect a difference in any of the first four
* pairs. */
static int vcm_detect(struct i2c_client *client)
{
int i, ret;
struct i2c_msg msg;
u16 data0 = 0, data;
for (i = 0; i < 4; i++) {
msg.addr = VCM_ADDR;
msg.flags = I2C_M_RD;
msg.len = sizeof(data);
msg.buf = (u8 *)&data;
ret = i2c_transfer(client->adapter, &msg, 1);
/* DW9714 always fails the first read and returns
* zeroes for subsequent ones */
if (i == 0 && ret == -EREMOTEIO) {
data0 = 0;
continue;
}
if (i == 0)
data0 = data;
if (data != data0)
return VCM_AD5823;
}
return ret == 1 ? VCM_DW9714 : ret;
}
static int ov5693_write_reg(struct i2c_client *client, u16 data_length,
u16 reg, u16 val)
{
int ret;
unsigned char data[4] = {0};
u16 *wreg = (u16 *)data;
const u16 len = data_length + sizeof(u16); /* 16-bit address + data */
if (data_length != OV5693_8BIT && data_length != OV5693_16BIT) {
dev_err(&client->dev,
"%s error, invalid data_length\n", __func__);
return -EINVAL;
}
/* high byte goes out first */
*wreg = cpu_to_be16(reg);
if (data_length == OV5693_8BIT) {
data[2] = (u8)(val);
} else {
/* OV5693_16BIT */
u16 *wdata = (u16 *)&data[2];
*wdata = cpu_to_be16(val);
}
ret = ov5693_i2c_write(client, len, data);
if (ret)
dev_err(&client->dev,
"write error: wrote 0x%x to offset 0x%x error %d",
val, reg, ret);
return ret;
}
/*
* ov5693_write_reg_array - Initializes a list of OV5693 registers
* @client: i2c driver client structure
* @reglist: list of registers to be written
*
* This function initializes a list of registers. When consecutive addresses
* are found in a row on the list, this function creates a buffer and sends
* consecutive data in a single i2c_transfer().
*
* __ov5693_flush_reg_array, __ov5693_buf_reg_array() and
* __ov5693_write_reg_is_consecutive() are internal functions to
* ov5693_write_reg_array_fast() and should be not used anywhere else.
*
*/
static int __ov5693_flush_reg_array(struct i2c_client *client,
struct ov5693_write_ctrl *ctrl)
{
u16 size;
if (ctrl->index == 0)
return 0;
size = sizeof(u16) + ctrl->index; /* 16-bit address + data */
ctrl->buffer.addr = cpu_to_be16(ctrl->buffer.addr);
ctrl->index = 0;
return ov5693_i2c_write(client, size, (u8 *)&ctrl->buffer);
}
static int __ov5693_buf_reg_array(struct i2c_client *client,
struct ov5693_write_ctrl *ctrl,
const struct ov5693_reg *next)
{
int size;
u16 *data16;
switch (next->type) {
case OV5693_8BIT:
size = 1;
ctrl->buffer.data[ctrl->index] = (u8)next->val;
break;
case OV5693_16BIT:
size = 2;
data16 = (u16 *)&ctrl->buffer.data[ctrl->index];
*data16 = cpu_to_be16((u16)next->val);
break;
default:
return -EINVAL;
}
/* When first item is added, we need to store its starting address */
if (ctrl->index == 0)
ctrl->buffer.addr = next->reg;
ctrl->index += size;
/*
* Buffer cannot guarantee free space for u32? Better flush it to avoid
* possible lack of memory for next item.
*/
if (ctrl->index + sizeof(u16) >= OV5693_MAX_WRITE_BUF_SIZE)
return __ov5693_flush_reg_array(client, ctrl);
return 0;
}
static int __ov5693_write_reg_is_consecutive(struct i2c_client *client,
struct ov5693_write_ctrl *ctrl,
const struct ov5693_reg *next)
{
if (ctrl->index == 0)
return 1;
return ctrl->buffer.addr + ctrl->index == next->reg;
}
static int ov5693_write_reg_array(struct i2c_client *client,
const struct ov5693_reg *reglist)
{
const struct ov5693_reg *next = reglist;
struct ov5693_write_ctrl ctrl;
int err;
ctrl.index = 0;
for (; next->type != OV5693_TOK_TERM; next++) {
switch (next->type & OV5693_TOK_MASK) {
case OV5693_TOK_DELAY:
err = __ov5693_flush_reg_array(client, &ctrl);
if (err)
return err;
msleep(next->val);
break;
default:
/*
* If next address is not consecutive, data needs to be
* flushed before proceed.
*/
if (!__ov5693_write_reg_is_consecutive(client, &ctrl,
next)) {
err = __ov5693_flush_reg_array(client, &ctrl);
if (err)
return err;
}
err = __ov5693_buf_reg_array(client, &ctrl, next);
if (err) {
dev_err(&client->dev,
"%s: write error, aborted\n",
__func__);
return err;
}
break;
}
}
return __ov5693_flush_reg_array(client, &ctrl);
}
static int ov5693_g_focal(struct v4l2_subdev *sd, s32 *val)
{
*val = (OV5693_FOCAL_LENGTH_NUM << 16) | OV5693_FOCAL_LENGTH_DEM;
return 0;
}
static int ov5693_g_fnumber(struct v4l2_subdev *sd, s32 *val)
{
/*const f number for imx*/
*val = (OV5693_F_NUMBER_DEFAULT_NUM << 16) | OV5693_F_NUMBER_DEM;
return 0;
}
static int ov5693_g_fnumber_range(struct v4l2_subdev *sd, s32 *val)
{
*val = (OV5693_F_NUMBER_DEFAULT_NUM << 24) |
(OV5693_F_NUMBER_DEM << 16) |
(OV5693_F_NUMBER_DEFAULT_NUM << 8) | OV5693_F_NUMBER_DEM;
return 0;
}
static int ov5693_g_bin_factor_x(struct v4l2_subdev *sd, s32 *val)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
*val = ov5693_res[dev->fmt_idx].bin_factor_x;
return 0;
}
static int ov5693_g_bin_factor_y(struct v4l2_subdev *sd, s32 *val)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
*val = ov5693_res[dev->fmt_idx].bin_factor_y;
return 0;
}
static int ov5693_get_intg_factor(struct i2c_client *client,
struct camera_mipi_info *info,
const struct ov5693_resolution *res)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct atomisp_sensor_mode_data *buf = &info->data;
unsigned int pix_clk_freq_hz;
u16 reg_val;
int ret;
if (info == NULL)
return -EINVAL;
/* pixel clock */
pix_clk_freq_hz = res->pix_clk_freq * 1000000;
dev->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
buf->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
/* get integration time */
buf->coarse_integration_time_min = OV5693_COARSE_INTG_TIME_MIN;
buf->coarse_integration_time_max_margin =
OV5693_COARSE_INTG_TIME_MAX_MARGIN;
buf->fine_integration_time_min = OV5693_FINE_INTG_TIME_MIN;
buf->fine_integration_time_max_margin =
OV5693_FINE_INTG_TIME_MAX_MARGIN;
buf->fine_integration_time_def = OV5693_FINE_INTG_TIME_MIN;
buf->frame_length_lines = res->lines_per_frame;
buf->line_length_pck = res->pixels_per_line;
buf->read_mode = res->bin_mode;
/* get the cropping and output resolution to ISP for this mode. */
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_HORIZONTAL_START_H, ®_val);
if (ret)
return ret;
buf->crop_horizontal_start = reg_val;
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_VERTICAL_START_H, ®_val);
if (ret)
return ret;
buf->crop_vertical_start = reg_val;
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_HORIZONTAL_END_H, ®_val);
if (ret)
return ret;
buf->crop_horizontal_end = reg_val;
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_VERTICAL_END_H, ®_val);
if (ret)
return ret;
buf->crop_vertical_end = reg_val;
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_HORIZONTAL_OUTPUT_SIZE_H, ®_val);
if (ret)
return ret;
buf->output_width = reg_val;
ret = ov5693_read_reg(client, OV5693_16BIT,
OV5693_VERTICAL_OUTPUT_SIZE_H, ®_val);
if (ret)
return ret;
buf->output_height = reg_val;
buf->binning_factor_x = res->bin_factor_x ?
res->bin_factor_x : 1;
buf->binning_factor_y = res->bin_factor_y ?
res->bin_factor_y : 1;
return 0;
}
static long __ov5693_set_exposure(struct v4l2_subdev *sd, int coarse_itg,
int gain, int digitgain)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov5693_device *dev = to_ov5693_sensor(sd);
u16 vts, hts;
int ret, exp_val;
hts = ov5693_res[dev->fmt_idx].pixels_per_line;
vts = ov5693_res[dev->fmt_idx].lines_per_frame;
/*If coarse_itg is larger than 1<<15, can not write to reg directly.
The way is to write coarse_itg/2 to the reg, meanwhile write 2*hts
to the reg. */
if (coarse_itg > (1 << 15)) {
hts = hts * 2;
coarse_itg = (int)coarse_itg / 2;
}
/* group hold */
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_GROUP_ACCESS, 0x00);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_GROUP_ACCESS);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_TIMING_HTS_H, (hts >> 8) & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_TIMING_HTS_H);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_TIMING_HTS_L, hts & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_TIMING_HTS_L);
return ret;
}
/* Increase the VTS to match exposure + MARGIN */
if (coarse_itg > vts - OV5693_INTEGRATION_TIME_MARGIN)
vts = (u16) coarse_itg + OV5693_INTEGRATION_TIME_MARGIN;
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_TIMING_VTS_H, (vts >> 8) & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_TIMING_VTS_H);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_TIMING_VTS_L, vts & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_TIMING_VTS_L);
return ret;
}
/* set exposure */
/* Lower four bit should be 0*/
exp_val = coarse_itg << 4;
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_L, exp_val & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_EXPOSURE_L);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_M, (exp_val >> 8) & 0xFF);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_EXPOSURE_M);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_H, (exp_val >> 16) & 0x0F);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_EXPOSURE_H);
return ret;
}
/* Analog gain */
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_AGC_L, gain & 0xff);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_AGC_L);
return ret;
}
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_AGC_H, (gain >> 8) & 0xff);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_AGC_H);
return ret;
}
/* Digital gain */
if (digitgain) {
ret = ov5693_write_reg(client, OV5693_16BIT,
OV5693_MWB_RED_GAIN_H, digitgain);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_MWB_RED_GAIN_H);
return ret;
}
ret = ov5693_write_reg(client, OV5693_16BIT,
OV5693_MWB_GREEN_GAIN_H, digitgain);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_MWB_RED_GAIN_H);
return ret;
}
ret = ov5693_write_reg(client, OV5693_16BIT,
OV5693_MWB_BLUE_GAIN_H, digitgain);
if (ret) {
dev_err(&client->dev, "%s: write %x error, aborted\n",
__func__, OV5693_MWB_RED_GAIN_H);
return ret;
}
}
/* End group */
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_GROUP_ACCESS, 0x10);
if (ret)
return ret;
/* Delay launch group */
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_GROUP_ACCESS, 0xa0);
if (ret)
return ret;
return ret;
}
static int ov5693_set_exposure(struct v4l2_subdev *sd, int exposure,
int gain, int digitgain)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
int ret;
mutex_lock(&dev->input_lock);
ret = __ov5693_set_exposure(sd, exposure, gain, digitgain);
mutex_unlock(&dev->input_lock);
return ret;
}
static long ov5693_s_exposure(struct v4l2_subdev *sd,
struct atomisp_exposure *exposure)
{
u16 coarse_itg = exposure->integration_time[0];
u16 analog_gain = exposure->gain[0];
u16 digital_gain = exposure->gain[1];
/* we should not accept the invalid value below */
if (analog_gain == 0) {
struct i2c_client *client = v4l2_get_subdevdata(sd);
v4l2_err(client, "%s: invalid value\n", __func__);
return -EINVAL;
}
return ov5693_set_exposure(sd, coarse_itg, analog_gain, digital_gain);
}
static int ov5693_read_otp_reg_array(struct i2c_client *client, u16 size,
u16 addr, u8 *buf)
{
u16 index;
int ret;
u16 *pVal = NULL;
for (index = 0; index <= size; index++) {
pVal = (u16 *) (buf + index);
ret =
ov5693_read_reg(client, OV5693_8BIT, addr + index,
pVal);
if (ret)
return ret;
}
return 0;
}
static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov5693_device *dev = to_ov5693_sensor(sd);
int ret;
int i;
u8 *b = buf;
dev->otp_size = 0;
for (i = 1; i < OV5693_OTP_BANK_MAX; i++) {
/*set bank NO and OTP read mode. */
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_BANK_REG, (i | 0xc0)); //[7:6] 2'b11 [5:0] bank no
if (ret) {
dev_err(&client->dev, "failed to prepare OTP page\n");
return ret;
}
//pr_debug("write 0x%x->0x%x\n",OV5693_OTP_BANK_REG,(i|0xc0));
/*enable read */
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_READ_REG, OV5693_OTP_MODE_READ); // enable :1
if (ret) {
dev_err(&client->dev,
"failed to set OTP reading mode page");
return ret;
}
//pr_debug("write 0x%x->0x%x\n",OV5693_OTP_READ_REG,OV5693_OTP_MODE_READ);
/* Reading the OTP data array */
ret = ov5693_read_otp_reg_array(client, OV5693_OTP_BANK_SIZE,
OV5693_OTP_START_ADDR,
b);
if (ret) {
dev_err(&client->dev, "failed to read OTP data\n");
return ret;
}
//pr_debug("BANK[%2d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, *b, *(b+1), *(b+2), *(b+3), *(b+4), *(b+5), *(b+6), *(b+7), *(b+8), *(b+9), *(b+10), *(b+11), *(b+12), *(b+13), *(b+14), *(b+15));
//Intel OTP map, try to read 320byts first.
if (21 == i) {
if ((*b) == 0) {
dev->otp_size = 320;
break;
} else {
b = buf;
continue;
}
} else if (24 == i) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data.
if ((*b) == 0) {
dev->otp_size = 32;
break;
} else {
b = buf;
continue;
}
} else if (27 == i) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again.
if ((*b) == 0) {
dev->otp_size = 32;
break;
} else {
dev->otp_size = 0; // no OTP data.
break;
}
}
b = b + OV5693_OTP_BANK_SIZE;
}
return 0;
}
/*
* Read otp data and store it into a kmalloced buffer.
* The caller must kfree the buffer when no more needed.
* @size: set to the size of the returned otp data.
*/
static void *ov5693_otp_read(struct v4l2_subdev *sd)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
u8 *buf;
int ret;
buf = devm_kzalloc(&client->dev, (OV5693_OTP_DATA_SIZE + 16), GFP_KERNEL);
if (!buf)
return ERR_PTR(-ENOMEM);
//otp valid after mipi on and sw stream on
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x00);
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_SW_STREAM, OV5693_START_STREAMING);
ret = __ov5693_otp_read(sd, buf);
//mipi off and sw stream off after otp read
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x0f);
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_SW_STREAM, OV5693_STOP_STREAMING);
/* Driver has failed to find valid data */
if (ret) {
dev_err(&client->dev, "sensor found no valid OTP data\n");
return ERR_PTR(ret);
}
return buf;
}
static int ov5693_g_priv_int_data(struct v4l2_subdev *sd,
struct v4l2_private_int_data *priv)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov5693_device *dev = to_ov5693_sensor(sd);
u8 __user *to = priv->data;
u32 read_size = priv->size;
int ret;
/* No need to copy data if size is 0 */
if (!read_size)
goto out;
if (IS_ERR(dev->otp_data)) {
dev_err(&client->dev, "OTP data not available");
return PTR_ERR(dev->otp_data);
}
/* Correct read_size value only if bigger than maximum */
if (read_size > OV5693_OTP_DATA_SIZE)
read_size = OV5693_OTP_DATA_SIZE;
ret = copy_to_user(to, dev->otp_data, read_size);
if (ret) {
dev_err(&client->dev, "%s: failed to copy OTP data to user\n",
__func__);
return -EFAULT;
}
pr_debug("%s read_size:%d\n", __func__, read_size);
out:
/* Return correct size */
priv->size = dev->otp_size;
return 0;
}
static long ov5693_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
{
switch (cmd) {
case ATOMISP_IOC_S_EXPOSURE:
return ov5693_s_exposure(sd, arg);
case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
return ov5693_g_priv_int_data(sd, arg);
default:
return -EINVAL;
}
return 0;
}
/* This returns the exposure time being used. This should only be used
for filling in EXIF data, not for actual image processing. */
static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
u16 reg_v, reg_v2;
int ret;
/* get exposure */
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_L,
®_v);
if (ret)
goto err;
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_M,
®_v2);
if (ret)
goto err;
reg_v += reg_v2 << 8;
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_EXPOSURE_H,
®_v2);
if (ret)
goto err;
*value = reg_v + (((u32)reg_v2 << 16));
err:
return ret;
}
static int ad5823_t_focus_vcm(struct v4l2_subdev *sd, u16 val)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = -EINVAL;
u8 vcm_code;
ret = ad5823_i2c_read(client, AD5823_REG_VCM_CODE_MSB, &vcm_code);
if (ret)
return ret;
/* set reg VCM_CODE_MSB Bit[1:0] */
vcm_code = (vcm_code & VCM_CODE_MSB_MASK) |
((val >> 8) & ~VCM_CODE_MSB_MASK);
ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB, vcm_code);
if (ret)
return ret;
/* set reg VCM_CODE_LSB Bit[7:0] */
ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_LSB, (val & 0xff));
if (ret)
return ret;
/* set required vcm move time */
vcm_code = AD5823_RESONANCE_PERIOD / AD5823_RESONANCE_COEF
- AD5823_HIGH_FREQ_RANGE;
ret = ad5823_i2c_write(client, AD5823_REG_VCM_MOVE_TIME, vcm_code);
return ret;
}
int ad5823_t_focus_abs(struct v4l2_subdev *sd, s32 value)
{
int ret;
value = min(value, AD5823_MAX_FOCUS_POS);
ret = ad5823_t_focus_vcm(sd, value);
return ret;
}
static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0;
dev_dbg(&client->dev, "%s: FOCUS_POS: 0x%x\n", __func__, value);
value = clamp(value, 0, OV5693_VCM_MAX_FOCUS_POS);
if (dev->vcm == VCM_DW9714) {
if (dev->vcm_update) {
ret = vcm_dw_i2c_write(client, VCM_PROTECTION_OFF);
if (ret)
return ret;
ret = vcm_dw_i2c_write(client, DIRECT_VCM);
if (ret)
return ret;
ret = vcm_dw_i2c_write(client, VCM_PROTECTION_ON);
if (ret)
return ret;
dev->vcm_update = false;
}
ret = vcm_dw_i2c_write(client,
vcm_val(value, VCM_DEFAULT_S));
} else if (dev->vcm == VCM_AD5823) {
ad5823_t_focus_abs(sd, value);
}
if (ret == 0) {
dev->number_of_steps = value - dev->focus;
dev->focus = value;
getnstimeofday(&(dev->timestamp_t_focus_abs));
} else
dev_err(&client->dev,
"%s: i2c failed. ret %d\n", __func__, ret);
return ret;
}
static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
return ov5693_t_focus_abs(sd, dev->focus + value);
}
#define DELAY_PER_STEP_NS 1000000
#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
static int ov5693_q_focus_status(struct v4l2_subdev *sd, s32 *value)
{
u32 status = 0;
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct timespec temptime;
const struct timespec timedelay = {
0,
min((u32)abs(dev->number_of_steps) * DELAY_PER_STEP_NS,
(u32)DELAY_MAX_PER_STEP_NS),
};
getnstimeofday(&temptime);
temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs));
if (timespec_compare(&temptime, &timedelay) <= 0) {
status |= ATOMISP_FOCUS_STATUS_MOVING;
status |= ATOMISP_FOCUS_HP_IN_PROGRESS;
} else {
status |= ATOMISP_FOCUS_STATUS_ACCEPTS_NEW_MOVE;
status |= ATOMISP_FOCUS_HP_COMPLETE;
}
*value = status;
return 0;
}
static int ov5693_q_focus_abs(struct v4l2_subdev *sd, s32 *value)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
s32 val;
ov5693_q_focus_status(sd, &val);
if (val & ATOMISP_FOCUS_STATUS_MOVING)
*value = dev->focus - dev->number_of_steps;
else
*value = dev->focus;
return 0;
}
static int ov5693_t_vcm_slew(struct v4l2_subdev *sd, s32 value)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
dev->number_of_steps = value;
dev->vcm_update = true;
return 0;
}
static int ov5693_t_vcm_timing(struct v4l2_subdev *sd, s32 value)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
dev->number_of_steps = value;
dev->vcm_update = true;
return 0;
}
static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct ov5693_device *dev =
container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
int ret = 0;
switch (ctrl->id) {
case V4L2_CID_FOCUS_ABSOLUTE:
dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
__func__, ctrl->val);
ret = ov5693_t_focus_abs(&dev->sd, ctrl->val);
break;
case V4L2_CID_FOCUS_RELATIVE:
dev_dbg(&client->dev, "%s: CID_FOCUS_RELATIVE:%d.\n",
__func__, ctrl->val);
ret = ov5693_t_focus_rel(&dev->sd, ctrl->val);
break;
case V4L2_CID_VCM_SLEW:
ret = ov5693_t_vcm_slew(&dev->sd, ctrl->val);
break;
case V4L2_CID_VCM_TIMEING:
ret = ov5693_t_vcm_timing(&dev->sd, ctrl->val);
break;
default:
ret = -EINVAL;
}
return ret;
}
static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{
struct ov5693_device *dev =
container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
int ret = 0;
switch (ctrl->id) {
case V4L2_CID_EXPOSURE_ABSOLUTE:
ret = ov5693_q_exposure(&dev->sd, &ctrl->val);
break;
case V4L2_CID_FOCAL_ABSOLUTE:
ret = ov5693_g_focal(&dev->sd, &ctrl->val);
break;
case V4L2_CID_FNUMBER_ABSOLUTE:
ret = ov5693_g_fnumber(&dev->sd, &ctrl->val);
break;
case V4L2_CID_FNUMBER_RANGE:
ret = ov5693_g_fnumber_range(&dev->sd, &ctrl->val);
break;
case V4L2_CID_FOCUS_ABSOLUTE:
ret = ov5693_q_focus_abs(&dev->sd, &ctrl->val);
break;
case V4L2_CID_FOCUS_STATUS:
ret = ov5693_q_focus_status(&dev->sd, &ctrl->val);
break;
case V4L2_CID_BIN_FACTOR_HORZ:
ret = ov5693_g_bin_factor_x(&dev->sd, &ctrl->val);
break;
case V4L2_CID_BIN_FACTOR_VERT:
ret = ov5693_g_bin_factor_y(&dev->sd, &ctrl->val);
break;
default:
ret = -EINVAL;
}
return ret;
}
static const struct v4l2_ctrl_ops ctrl_ops = {
.s_ctrl = ov5693_s_ctrl,
.g_volatile_ctrl = ov5693_g_volatile_ctrl
};
struct v4l2_ctrl_config ov5693_controls[] = {
{
.ops = &ctrl_ops,
.id = V4L2_CID_EXPOSURE_ABSOLUTE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "exposure",
.min = 0x0,
.max = 0xffff,
.step = 0x01,
.def = 0x00,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FOCAL_ABSOLUTE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "focal length",
.min = OV5693_FOCAL_LENGTH_DEFAULT,
.max = OV5693_FOCAL_LENGTH_DEFAULT,
.step = 0x01,
.def = OV5693_FOCAL_LENGTH_DEFAULT,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FNUMBER_ABSOLUTE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "f-number",
.min = OV5693_F_NUMBER_DEFAULT,
.max = OV5693_F_NUMBER_DEFAULT,
.step = 0x01,
.def = OV5693_F_NUMBER_DEFAULT,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FNUMBER_RANGE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "f-number range",
.min = OV5693_F_NUMBER_RANGE,
.max = OV5693_F_NUMBER_RANGE,
.step = 0x01,
.def = OV5693_F_NUMBER_RANGE,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FOCUS_ABSOLUTE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "focus move absolute",
.min = 0,
.max = OV5693_VCM_MAX_FOCUS_POS,
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FOCUS_RELATIVE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "focus move relative",
.min = OV5693_VCM_MAX_FOCUS_NEG,
.max = OV5693_VCM_MAX_FOCUS_POS,
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_FOCUS_STATUS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "focus status",
.min = 0,
.max = 100, /* allow enum to grow in the future */
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_VCM_SLEW,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "vcm slew",
.min = 0,
.max = OV5693_VCM_SLEW_STEP_MAX,
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_VCM_TIMEING,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "vcm step time",
.min = 0,
.max = OV5693_VCM_SLEW_TIME_MAX,
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_BIN_FACTOR_HORZ,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "horizontal binning factor",
.min = 0,
.max = OV5693_BIN_FACTOR_MAX,
.step = 1,
.def = 0,
.flags = 0,
},
{
.ops = &ctrl_ops,
.id = V4L2_CID_BIN_FACTOR_VERT,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "vertical binning factor",
.min = 0,
.max = OV5693_BIN_FACTOR_MAX,
.step = 1,
.def = 0,
.flags = 0,
},
};
static int ov5693_init(struct v4l2_subdev *sd)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret;
pr_info("%s\n", __func__);
mutex_lock(&dev->input_lock);
dev->vcm_update = false;
if (dev->vcm == VCM_AD5823) {
ret = vcm_ad_i2c_wr8(client, 0x01, 0x01); /* vcm init test */
if (ret)
dev_err(&client->dev,
"vcm reset failed\n");
/*change the mode*/
ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB,
AD5823_RING_CTRL_ENABLE);
if (ret)
dev_err(&client->dev,
"vcm enable ringing failed\n");
ret = ad5823_i2c_write(client, AD5823_REG_MODE,
AD5823_ARC_RES1);
if (ret)
dev_err(&client->dev,
"vcm change mode failed\n");
}
/*change initial focus value for ad5823*/
if (dev->vcm == VCM_AD5823) {
dev->focus = AD5823_INIT_FOCUS_POS;
ov5693_t_focus_abs(sd, AD5823_INIT_FOCUS_POS);
} else {
dev->focus = 0;
ov5693_t_focus_abs(sd, 0);
}
mutex_unlock(&dev->input_lock);
return 0;
}
static int power_ctrl(struct v4l2_subdev *sd, bool flag)
{
int ret;
struct ov5693_device *dev = to_ov5693_sensor(sd);
if (!dev || !dev->platform_data)
return -ENODEV;
/* Non-gmin platforms use the legacy callback */
if (dev->platform_data->power_ctrl)
return dev->platform_data->power_ctrl(sd, flag);
/* This driver assumes "internal DVDD, PWDNB tied to DOVDD".
* In this set up only gpio0 (XSHUTDN) should be available
* but in some products (for example ECS) gpio1 (PWDNB) is
* also available. If gpio1 is available we emulate it being
* tied to DOVDD here. */
if (flag) {
ret = dev->platform_data->v2p8_ctrl(sd, 1);
dev->platform_data->gpio1_ctrl(sd, 1);
if (ret == 0) {
ret = dev->platform_data->v1p8_ctrl(sd, 1);
if (ret) {
dev->platform_data->gpio1_ctrl(sd, 0);
ret = dev->platform_data->v2p8_ctrl(sd, 0);
}
}
} else {
dev->platform_data->gpio1_ctrl(sd, 0);
ret = dev->platform_data->v1p8_ctrl(sd, 0);
ret |= dev->platform_data->v2p8_ctrl(sd, 0);
}
return ret;
}
static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)
{
int ret;
struct ov5693_device *dev = to_ov5693_sensor(sd);
if (!dev || !dev->platform_data)
return -ENODEV;
/* Non-gmin platforms use the legacy callback */
if (dev->platform_data->gpio_ctrl)
return dev->platform_data->gpio_ctrl(sd, flag);
ret = dev->platform_data->gpio0_ctrl(sd, flag);
return ret;
}
static int __power_up(struct v4l2_subdev *sd)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret;
if (NULL == dev->platform_data) {
dev_err(&client->dev,
"no camera_sensor_platform_data");
return -ENODEV;
}
/* power control */
ret = power_ctrl(sd, 1);
if (ret)
goto fail_power;
/* according to DS, at least 5ms is needed between DOVDD and PWDN */
/* add this delay time to 10~11ms*/
usleep_range(10000, 11000);
/* gpio ctrl */
ret = gpio_ctrl(sd, 1);
if (ret) {
ret = gpio_ctrl(sd, 1);
if (ret)
goto fail_power;
}
/* flis clock control */
ret = dev->platform_data->flisclk_ctrl(sd, 1);
if (ret)
goto fail_clk;
__cci_delay(up_delay);
return 0;
fail_clk:
gpio_ctrl(sd, 0);
fail_power:
power_ctrl(sd, 0);
dev_err(&client->dev, "sensor power-up failed\n");
return ret;
}
static int power_down(struct v4l2_subdev *sd)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0;
dev->focus = OV5693_INVALID_CONFIG;
if (NULL == dev->platform_data) {
dev_err(&client->dev,
"no camera_sensor_platform_data");
return -ENODEV;
}
ret = dev->platform_data->flisclk_ctrl(sd, 0);
if (ret)
dev_err(&client->dev, "flisclk failed\n");
/* gpio ctrl */
ret = gpio_ctrl(sd, 0);
if (ret) {
ret = gpio_ctrl(sd, 0);
if (ret)
dev_err(&client->dev, "gpio failed 2\n");
}
/* power control */
ret = power_ctrl(sd, 0);
if (ret)
dev_err(&client->dev, "vprog failed.\n");
return ret;
}
static int power_up(struct v4l2_subdev *sd)
{
static const int retry_count = 4;
int i, ret;
for (i = 0; i < retry_count; i++) {
ret = __power_up(sd);
if (!ret)
return 0;
power_down(sd);
}
return ret;
}
static int ov5693_s_power(struct v4l2_subdev *sd, int on)
{
int ret;
pr_info("%s: on %d\n", __func__, on);
if (on == 0)
return power_down(sd);
else {
ret = power_up(sd);
if (!ret) {
ret = ov5693_init(sd);
/* restore settings */
ov5693_res = ov5693_res_preview;
N_RES = N_RES_PREVIEW;
}
}
return ret;
}
/*
* distance - calculate the distance
* @res: resolution
* @w: width
* @h: height
*
* Get the gap between res_w/res_h and w/h.
* distance = (res_w/res_h - w/h) / (w/h) * 8192
* res->width/height smaller than w/h wouldn't be considered.
* The gap of ratio larger than 1/8 wouldn't be considered.
* Returns the value of gap or -1 if fail.
*/
#define LARGEST_ALLOWED_RATIO_MISMATCH 1024
static int distance(struct ov5693_resolution *res, u32 w, u32 h)
{
int ratio;
int distance;
if (w == 0 || h == 0 ||
res->width < w || res->height < h)
return -1;
ratio = res->width << 13;
ratio /= w;
ratio *= h;
ratio /= res->height;
distance = abs(ratio - 8192);
if (distance > LARGEST_ALLOWED_RATIO_MISMATCH)
return -1;
return distance;
}
/* Return the nearest higher resolution index
* Firstly try to find the approximate aspect ratio resolution
* If we find multiple same AR resolutions, choose the
* minimal size.
*/
static int nearest_resolution_index(int w, int h)
{
int i;
int idx = -1;
int dist;
int min_dist = INT_MAX;
int min_res_w = INT_MAX;
struct ov5693_resolution *tmp_res = NULL;
for (i = 0; i < N_RES; i++) {
tmp_res = &ov5693_res[i];
dist = distance(tmp_res, w, h);
if (dist == -1)
continue;
if (dist < min_dist) {
min_dist = dist;
idx = i;
min_res_w = ov5693_res[i].width;
continue;
}
if (dist == min_dist && ov5693_res[i].width < min_res_w)
idx = i;
}
return idx;
}
static int get_resolution_index(int w, int h)
{
int i;
for (i = 0; i < N_RES; i++) {
if (w != ov5693_res[i].width)
continue;
if (h != ov5693_res[i].height)
continue;
return i;
}
return -1;
}
/* TODO: remove it. */
static int startup(struct v4l2_subdev *sd)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0;
ret = ov5693_write_reg(client, OV5693_8BIT,
OV5693_SW_RESET, 0x01);
if (ret) {
dev_err(&client->dev, "ov5693 reset err.\n");
return ret;
}
ret = ov5693_write_reg_array(client, ov5693_global_setting);
if (ret) {
dev_err(&client->dev, "ov5693 write register err.\n");
return ret;
}
ret = ov5693_write_reg_array(client, ov5693_res[dev->fmt_idx].regs);
if (ret) {
dev_err(&client->dev, "ov5693 write register err.\n");
return ret;
}
return ret;
}
static int ov5693_set_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
struct v4l2_mbus_framefmt *fmt = &format->format;
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct camera_mipi_info *ov5693_info = NULL;
int ret = 0;
int idx;
if (format->pad)
return -EINVAL;
if (!fmt)
return -EINVAL;
ov5693_info = v4l2_get_subdev_hostdata(sd);
if (ov5693_info == NULL)
return -EINVAL;
mutex_lock(&dev->input_lock);
idx = nearest_resolution_index(fmt->width, fmt->height);
if (idx == -1) {
/* return the largest resolution */
fmt->width = ov5693_res[N_RES - 1].width;
fmt->height = ov5693_res[N_RES - 1].height;
} else {
fmt->width = ov5693_res[idx].width;
fmt->height = ov5693_res[idx].height;
}
fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
cfg->try_fmt = *fmt;
mutex_unlock(&dev->input_lock);
return 0;
}
dev->fmt_idx = get_resolution_index(fmt->width, fmt->height);
if (dev->fmt_idx == -1) {
dev_err(&client->dev, "get resolution fail\n");
mutex_unlock(&dev->input_lock);
return -EINVAL;
}
ret = startup(sd);
if (ret) {
int i = 0;
dev_err(&client->dev, "ov5693 startup err, retry to power up\n");
for (i = 0; i < OV5693_POWER_UP_RETRY_NUM; i++) {
dev_err(&client->dev,
"ov5693 retry to power up %d/%d times, result: ",
i+1, OV5693_POWER_UP_RETRY_NUM);
power_down(sd);
ret = power_up(sd);
if (!ret) {
mutex_unlock(&dev->input_lock);
ov5693_init(sd);
mutex_lock(&dev->input_lock);
} else {
dev_err(&client->dev, "power up failed, continue\n");
continue;
}
ret = startup(sd);
if (ret) {
dev_err(&client->dev, " startup FAILED!\n");
} else {
dev_err(&client->dev, " startup SUCCESS!\n");
break;
}
}
}
/*
* After sensor settings are set to HW, sometimes stream is started.
* This would cause ISP timeout because ISP is not ready to receive
* data yet. So add stop streaming here.
*/
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
OV5693_STOP_STREAMING);
if (ret)
dev_warn(&client->dev, "ov5693 stream off err\n");
ret = ov5693_get_intg_factor(client, ov5693_info,
&ov5693_res[dev->fmt_idx]);
if (ret) {
dev_err(&client->dev, "failed to get integration_factor\n");
goto err;
}
ov5693_info->metadata_width = fmt->width * 10 / 8;
ov5693_info->metadata_height = 1;
ov5693_info->metadata_effective_width = &ov5693_embedded_effective_size;
err:
mutex_unlock(&dev->input_lock);
return ret;
}
static int ov5693_get_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
struct v4l2_mbus_framefmt *fmt = &format->format;
struct ov5693_device *dev = to_ov5693_sensor(sd);
if (format->pad)
return -EINVAL;
if (!fmt)
return -EINVAL;
fmt->width = ov5693_res[dev->fmt_idx].width;
fmt->height = ov5693_res[dev->fmt_idx].height;
fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
return 0;
}
static int ov5693_detect(struct i2c_client *client)
{
struct i2c_adapter *adapter = client->adapter;
u16 high, low;
int ret;
u16 id;
u8 revision;
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
return -ENODEV;
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_SC_CMMN_CHIP_ID_H, &high);
if (ret) {
dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
return -ENODEV;
}
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_SC_CMMN_CHIP_ID_L, &low);
id = ((((u16) high) << 8) | (u16) low);
if (id != OV5693_ID) {
dev_err(&client->dev, "sensor ID error 0x%x\n", id);
return -ENODEV;
}
ret = ov5693_read_reg(client, OV5693_8BIT,
OV5693_SC_CMMN_SUB_ID, &high);
revision = (u8) high & 0x0f;
dev_dbg(&client->dev, "sensor_revision = 0x%x\n", revision);
dev_dbg(&client->dev, "detect ov5693 success\n");
return 0;
}
static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret;
mutex_lock(&dev->input_lock);
ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
enable ? OV5693_START_STREAMING :
OV5693_STOP_STREAMING);
mutex_unlock(&dev->input_lock);
return ret;
}
static int ov5693_s_config(struct v4l2_subdev *sd,
int irq, void *platform_data)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
int ret = 0;
if (platform_data == NULL)
return -ENODEV;
dev->platform_data =
(struct camera_sensor_platform_data *)platform_data;
mutex_lock(&dev->input_lock);
/* power off the module, then power on it in future
* as first power on by board may not fulfill the
* power on sequqence needed by the module
*/
ret = power_down(sd);
if (ret) {
dev_err(&client->dev, "ov5693 power-off err.\n");
goto fail_power_off;
}
ret = power_up(sd);
if (ret) {
dev_err(&client->dev, "ov5693 power-up err.\n");
goto fail_power_on;
}
if (!dev->vcm)
dev->vcm = vcm_detect(client);
ret = dev->platform_data->csi_cfg(sd, 1);
if (ret)
goto fail_csi_cfg;
/* config & detect sensor */
ret = ov5693_detect(client);
if (ret) {
dev_err(&client->dev, "ov5693_detect err s_config.\n");
goto fail_csi_cfg;
}
dev->otp_data = ov5693_otp_read(sd);
/* turn off sensor, after probed */
ret = power_down(sd);
if (ret) {
dev_err(&client->dev, "ov5693 power-off err.\n");
goto fail_csi_cfg;
}
mutex_unlock(&dev->input_lock);
return ret;
fail_csi_cfg:
dev->platform_data->csi_cfg(sd, 0);
fail_power_on:
power_down(sd);
dev_err(&client->dev, "sensor power-gating failed\n");
fail_power_off:
mutex_unlock(&dev->input_lock);
return ret;
}
static int ov5693_g_parm(struct v4l2_subdev *sd,
struct v4l2_streamparm *param)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
if (!param)
return -EINVAL;
if (param->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
dev_err(&client->dev, "unsupported buffer type.\n");
return -EINVAL;
}
memset(param, 0, sizeof(*param));
param->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (dev->fmt_idx >= 0 && dev->fmt_idx < N_RES) {
param->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
param->parm.capture.timeperframe.numerator = 1;
param->parm.capture.capturemode = dev->run_mode;
param->parm.capture.timeperframe.denominator =
ov5693_res[dev->fmt_idx].fps;
}
return 0;
}
static int ov5693_s_parm(struct v4l2_subdev *sd,
struct v4l2_streamparm *param)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
dev->run_mode = param->parm.capture.capturemode;
mutex_lock(&dev->input_lock);
switch (dev->run_mode) {
case CI_MODE_VIDEO:
ov5693_res = ov5693_res_video;
N_RES = N_RES_VIDEO;
break;
case CI_MODE_STILL_CAPTURE:
ov5693_res = ov5693_res_still;
N_RES = N_RES_STILL;
break;
default:
ov5693_res = ov5693_res_preview;
N_RES = N_RES_PREVIEW;
}
mutex_unlock(&dev->input_lock);
return 0;
}
static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *interval)
{
struct ov5693_device *dev = to_ov5693_sensor(sd);
interval->interval.numerator = 1;
interval->interval.denominator = ov5693_res[dev->fmt_idx].fps;
return 0;
}
static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_mbus_code_enum *code)
{
if (code->index >= MAX_FMTS)
return -EINVAL;
code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
return 0;
}
static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_frame_size_enum *fse)
{
int index = fse->index;
if (index >= N_RES)
return -EINVAL;
fse->min_width = ov5693_res[index].width;
fse->min_height = ov5693_res[index].height;
fse->max_width = ov5693_res[index].width;
fse->max_height = ov5693_res[index].height;
return 0;
}
static const struct v4l2_subdev_video_ops ov5693_video_ops = {
.s_stream = ov5693_s_stream,
.g_parm = ov5693_g_parm,
.s_parm = ov5693_s_parm,
.g_frame_interval = ov5693_g_frame_interval,
};
static const struct v4l2_subdev_core_ops ov5693_core_ops = {
.s_power = ov5693_s_power,
.ioctl = ov5693_ioctl,
};
static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
.enum_mbus_code = ov5693_enum_mbus_code,
.enum_frame_size = ov5693_enum_frame_size,
.get_fmt = ov5693_get_fmt,
.set_fmt = ov5693_set_fmt,
};
static const struct v4l2_subdev_ops ov5693_ops = {
.core = &ov5693_core_ops,
.video = &ov5693_video_ops,
.pad = &ov5693_pad_ops,
};
static int ov5693_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct ov5693_device *dev = to_ov5693_sensor(sd);
dev_dbg(&client->dev, "ov5693_remove...\n");
dev->platform_data->csi_cfg(sd, 0);
v4l2_device_unregister_subdev(sd);
atomisp_gmin_remove_subdev(sd);
media_entity_cleanup(&dev->sd.entity);
v4l2_ctrl_handler_free(&dev->ctrl_handler);
kfree(dev);
return 0;
}
static int ov5693_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct ov5693_device *dev;
int i2c;
int ret = 0;
void *pdata = client->dev.platform_data;
struct acpi_device *adev;
unsigned int i;
/* Firmware workaround: Some modules use a "secondary default"
* address of 0x10 which doesn't appear on schematics, and
* some BIOS versions haven't gotten the memo. Work around
* via config. */
i2c = gmin_get_var_int(&client->dev, "I2CAddr", -1);
if (i2c != -1) {
dev_info(&client->dev,
"Overriding firmware-provided I2C address (0x%x) with 0x%x\n",
client->addr, i2c);
client->addr = i2c;
}
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
dev_err(&client->dev, "out of memory\n");
return -ENOMEM;
}
mutex_init(&dev->input_lock);
dev->fmt_idx = 0;
v4l2_i2c_subdev_init(&(dev->sd), client, &ov5693_ops);
adev = ACPI_COMPANION(&client->dev);
if (adev) {
adev->power.flags.power_resources = 0;
pdata = gmin_camera_platform_data(&dev->sd,
ATOMISP_INPUT_FORMAT_RAW_10,
atomisp_bayer_order_bggr);
}
if (!pdata)
goto out_free;
ret = ov5693_s_config(&dev->sd, client->irq, pdata);
if (ret)
goto out_free;
ret = atomisp_register_i2c_module(&dev->sd, pdata, RAW_CAMERA);
if (ret)
goto out_free;
dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
dev->pad.flags = MEDIA_PAD_FL_SOURCE;
dev->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
ret =
v4l2_ctrl_handler_init(&dev->ctrl_handler,
ARRAY_SIZE(ov5693_controls));
if (ret) {
ov5693_remove(client);
return ret;
}
for (i = 0; i < ARRAY_SIZE(ov5693_controls); i++)
v4l2_ctrl_new_custom(&dev->ctrl_handler, &ov5693_controls[i],
NULL);
if (dev->ctrl_handler.error) {
ov5693_remove(client);
return dev->ctrl_handler.error;
}
/* Use same lock for controls as for everything else. */
dev->ctrl_handler.lock = &dev->input_lock;
dev->sd.ctrl_handler = &dev->ctrl_handler;
ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad);
if (ret)
ov5693_remove(client);
return ret;
out_free:
v4l2_device_unregister_subdev(&dev->sd);
kfree(dev);
return ret;
}
MODULE_DEVICE_TABLE(i2c, ov5693_id);
static const struct acpi_device_id ov5693_acpi_match[] = {
{"INT33BE"},
{},
};
MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
static struct i2c_driver ov5693_driver = {
.driver = {
.name = OV5693_NAME,
.acpi_match_table = ACPI_PTR(ov5693_acpi_match),
},
.probe = ov5693_probe,
.remove = ov5693_remove,
.id_table = ov5693_id,
};
static int init_ov5693(void)
{
return i2c_add_driver(&ov5693_driver);
}
static void exit_ov5693(void)
{
i2c_del_driver(&ov5693_driver);
}
module_init(init_ov5693);
module_exit(exit_ov5693);
MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
MODULE_LICENSE("GPL");
|