2 * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/clk.h>
21 #include <linux/miscdevice.h>
22 #include <linux/slab.h>
23 #include <linux/uaccess.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/gpio.h>
26 #include <linux/module.h>
27 #include <linux/regmap.h>
28 #include <linux/gpio.h>
30 #include <linux/of_device.h>
31 #include <linux/of_gpio.h>
32 #include <linux/sysedp.h>
33 #include <media/ov5693.h>
34 #include <media/nvc.h>
36 #define OV5693_ID 0x5693
37 #define OV5693_SENSOR_TYPE NVC_IMAGER_TYPE_RAW
38 #define OV5693_RES_CHG_WAIT_TIME_MS 100
39 #define OV5693_SIZEOF_I2C_BUF 16
40 #define OV5693_TABLE_WAIT_MS 0
41 #define OV5693_TABLE_END 1
42 #define OV5693_TABLE_RESET 2
43 #define OV5693_TABLE_RESET_TIMEOUT 50
44 #define OV5693_LENS_MAX_APERTURE 0 /* _INT2FLOAT_DIVISOR */
45 #define OV5693_LENS_FNUMBER 0 /* _INT2FLOAT_DIVISOR */
46 #define OV5693_LENS_FOCAL_LENGTH 6120 /* _INT2FLOAT_DIVISOR */
47 #define OV5693_LENS_VIEW_ANGLE_H 60000 /* _INT2FLOAT_DIVISOR */
48 #define OV5693_LENS_VIEW_ANGLE_V 60000 /* _INT2FLOAT_DIVISOR */
49 #define OV5693_OTP_BUF_SIZE 16
50 #define OV5693_FUSE_ID_SIZE 8
52 static struct nvc_gpio_init ov5693_gpio[] = {
53 { OV5693_GPIO_TYPE_PWRDN, GPIOF_OUT_INIT_LOW, "pwrdn", false, true, },
58 struct i2c_client *i2c_client;
59 struct ov5693_platform_data *pdata;
61 struct miscdevice miscdev;
64 struct nvc_gpio gpio[ARRAY_SIZE(ov5693_gpio)];
65 struct ov5693_power_rail regulators;
70 unsigned test_pattern;
71 struct nvc_imager_static_nvc sdata;
73 struct nvc_fuseid fuseid;
74 struct regmap *regmap;
75 struct regulator *ext_vcm_vdd;
76 struct ov5693_cal_data cal;
77 struct sysedp_consumer *sysedpc;
79 struct ov5693_eeprom_data eeprom[OV5693_EEPROM_NUM_BLOCKS];
80 u8 eeprom_buf[OV5693_EEPROM_SIZE];
88 struct ov5693_mode_data {
89 struct nvc_imager_mode sensor_mode;
90 struct nvc_imager_dynamic_nvc sensor_dnvc;
91 struct ov5693_reg *p_mode_i2c;
94 static struct ov5693_platform_data ov5693_dflt_pdata = {
101 * NOTE: static vs dynamic
102 * If a member in the nvc_imager_static_nvc structure is not actually
103 * static data, then leave blank and add the parameter to the parameter
104 * read function that dynamically reads the data. The NVC user driver
105 * will call the parameter read for the data if the member data is 0.
106 * If the dynamic data becomes static during probe (a one time read
107 * such as device ID) then add the dynamic read to the _sdata_init
110 static struct nvc_imager_static_nvc ov5693_dflt_sdata = {
111 .api_version = NVC_IMAGER_API_STATIC_VER,
112 .sensor_type = OV5693_SENSOR_TYPE,
113 .bits_per_pixel = 10,
114 .sensor_id = OV5693_ID,
115 .sensor_id_minor = 0,
116 .focal_len = OV5693_LENS_FOCAL_LENGTH,
117 .max_aperture = OV5693_LENS_MAX_APERTURE,
118 .fnumber = OV5693_LENS_FNUMBER,
119 .view_angle_h = OV5693_LENS_VIEW_ANGLE_H,
120 .view_angle_v = OV5693_LENS_VIEW_ANGLE_V,
121 .res_chg_wait_time = OV5693_RES_CHG_WAIT_TIME_MS,
124 static const struct ov5693_reg ov5693_2592x1944_i2c[] = {
125 {OV5693_TABLE_RESET, 0},/* Including sw reset */
346 {0x4800, 0x20}, /* dis-continuous */
387 {OV5693_TABLE_END, 0x0000}
390 static const struct ov5693_reg ov5693_1296x972_i2c[] = {
391 {OV5693_TABLE_RESET, 0},/* Including sw reset */
593 {0x4800, 0x20}, /* dis-continuous */
634 {OV5693_TABLE_END, 0x0000}
637 static const struct ov5693_reg ov5693_1920x1080_i2c[] = {
638 {OV5693_TABLE_RESET, 0x0},/*, 0xIncluding, 0xsw, 0xreset, 0x*/
840 {0x4800, 0x20}, /* dis-continuous */
881 {OV5693_TABLE_END, 0x0000}
885 static const struct ov5693_reg ov5693_1280x720_120fps_i2c[] = {
886 {OV5693_TABLE_RESET, 0},/* Including sw reset */
1088 {0x4800, 0x20}, /* dis-continuous */
1129 {OV5693_TABLE_END, 0x0000}
1132 static const struct ov5693_reg ov5693_2592x1944_HDR_24fps_i2c[] = {
1133 {OV5693_TABLE_RESET, 0},/* Including sw reset */
1336 {0x4800, 0x20}, /* dis-continuous */
1377 {OV5693_TABLE_END, 0x0000}
1380 static const struct ov5693_reg ov5693_1920x1080_HDR_30fps_i2c[] = {
1381 {OV5693_TABLE_RESET, 0},/* Including sw reset */
1584 {0x4800, 0x20}, /* dis-continuous */
1625 {OV5693_TABLE_END, 0x0000}
1628 static const struct ov5693_reg ov5693_1296x972_HDR_30fps_i2c[] = {
1629 {OV5693_TABLE_RESET, 0},/* Including sw reset */
1832 {0x4800, 0x20}, /* dis-continuous */
1873 {OV5693_TABLE_END, 0x0000}
1876 static const struct ov5693_reg ov5693_1280x720_HDR_60fps_i2c[] = {
1877 {OV5693_TABLE_RESET, 0},/* Including sw reset */
2080 {0x4800, 0x20}, /* dis-continuous */
2121 {OV5693_TABLE_END, 0x0000}
2125 OV5693_MODE_2592x1944 = 0,
2126 OV5693_MODE_1920x1080,
2127 OV5693_MODE_1296x972,
2128 OV5693_MODE_1280x720_120FPS,
2129 OV5693_MODE_2592x1944_HDR,
2130 OV5693_MODE_1920x1080_HDR,
2131 OV5693_MODE_1296x972_HDR,
2132 OV5693_MODE_1280x720_HDR_60FPS,
2135 static const struct ov5693_reg *mode_table[] = {
2136 [OV5693_MODE_2592x1944] = ov5693_2592x1944_i2c,
2137 [OV5693_MODE_1920x1080] = ov5693_1920x1080_i2c,
2138 [OV5693_MODE_1296x972] = ov5693_1296x972_i2c,
2139 [OV5693_MODE_1280x720_120FPS] = ov5693_1280x720_120fps_i2c,
2140 [OV5693_MODE_2592x1944_HDR] = ov5693_2592x1944_HDR_24fps_i2c,
2141 [OV5693_MODE_1920x1080_HDR] = ov5693_1920x1080_HDR_30fps_i2c,
2142 [OV5693_MODE_1296x972_HDR] = ov5693_1296x972_HDR_30fps_i2c,
2143 [OV5693_MODE_1280x720_HDR_60FPS] = ov5693_1280x720_HDR_60fps_i2c,
2146 static int ov5693_i2c_wr_table(struct ov5693_info *info,
2147 const struct ov5693_reg table[])
2151 const struct ov5693_reg *next, *n_next;
2153 u8 i2c_buf[OV5693_SIZEOF_I2C_BUF];
2155 u8 *b_ptr = i2c_buf;
2157 for (next = table; next->addr != OV5693_TABLE_END; next++) {
2158 if (next->addr == OV5693_TABLE_WAIT_MS) {
2161 } else if (next->addr == OV5693_TABLE_RESET) {
2162 err = regmap_write(info->regmap, 0x0100, 0x00);
2168 if (buf_count == 0) {
2170 i2c_reg = next->addr;
2173 *b_ptr++ = next->val;
2176 if (n_next->addr == next->addr + 1 &&
2177 n_next->addr != OV5693_TABLE_WAIT_MS &&
2178 buf_count < OV5693_SIZEOF_I2C_BUF &&
2179 n_next->addr != OV5693_TABLE_RESET &&
2180 n_next->addr != OV5693_TABLE_END)
2183 err = regmap_bulk_write(info->regmap, i2c_reg,
2184 i2c_buf, buf_count);
2195 static inline int ov5693_frame_length_reg(struct ov5693_reg *regs,
2198 regs->addr = 0x380E;
2199 regs->val = (frame_length >> 8) & 0xff;
2200 (regs + 1)->addr = 0x380F;
2201 (regs + 1)->val = (frame_length) & 0xff;
2206 static inline int ov5693_coarse_time_reg(struct ov5693_reg *regs,
2207 u32 coarse_time, u32 coarse_time_short)
2211 regs->addr = 0x3500;
2212 regs->val = (coarse_time >> 12) & 0xff;
2213 (regs + 1)->addr = 0x3501;
2214 (regs + 1)->val = (coarse_time >> 4) & 0xff;
2215 (regs + 2)->addr = 0x3502;
2216 (regs + 2)->val = (coarse_time & 0xf) << 4;
2220 if (coarse_time_short != OV5693_INVALID_COARSE_TIME) {
2221 (regs + 3)->addr = 0x3506;
2222 (regs + 3)->val = (coarse_time_short >> 12) & 0xff;
2223 (regs + 4)->addr = 0x3507;
2224 (regs + 4)->val = (coarse_time_short >> 4) & 0xff;
2225 (regs + 5)->addr = 0x3508;
2226 (regs + 5)->val = (coarse_time_short & 0xf) << 4;
2234 #define OV5693_ENTER_GROUP_HOLD(group_hold) \
2237 reg_list[offset].addr = 0x3208; \
2238 reg_list[offset].val = 0x01;\
2243 #define OV5693_LEAVE_GROUP_HOLD(group_hold) \
2246 reg_list[offset].addr = 0x3208; \
2247 reg_list[offset].val = 0x11;\
2249 reg_list[offset].addr = 0x3208; \
2250 reg_list[offset].val = 0x61;\
2255 static int ov5693_set_frame_length(struct ov5693_info *info,
2256 u32 frame_length, bool group_hold)
2258 struct ov5693_reg reg_list[9];
2262 OV5693_ENTER_GROUP_HOLD(group_hold);
2263 offset += ov5693_frame_length_reg(reg_list + offset, frame_length);
2264 OV5693_LEAVE_GROUP_HOLD(group_hold);
2266 reg_list[offset].addr = OV5693_TABLE_END;
2269 err = ov5693_i2c_wr_table(info, reg_list);
2274 static int ov5693_set_coarse_time(struct ov5693_info *info,
2275 u32 coarse_time, u32 coarse_time_short,
2278 struct ov5693_reg reg_list[16];
2282 OV5693_ENTER_GROUP_HOLD(group_hold);
2283 offset += ov5693_coarse_time_reg(reg_list + offset,
2286 OV5693_LEAVE_GROUP_HOLD(group_hold);
2288 reg_list[offset].addr = OV5693_TABLE_END;
2291 err = ov5693_i2c_wr_table(info, reg_list);
2296 static inline int ov5693_gain_reg(struct ov5693_reg *regs, u32 gain)
2298 (regs)->addr = 0x350A;
2299 (regs)->val = gain >> 8;
2301 (regs + 1)->addr = 0x350B;
2302 (regs + 1)->val = gain & 0x00FF;
2307 static int ov5693_bin_wr(struct ov5693_info *info, u8 enable)
2311 if (enable == info->bin_en)
2315 info->bin_en = enable;
2316 dev_dbg(&info->i2c_client->dev, "%s bin_en=%x err=%d\n",
2317 __func__, info->bin_en, err);
2321 static int ov5693_exposure_wr(struct ov5693_info *info,
2322 struct ov5693_mode *mode)
2324 struct ov5693_reg reg_list[16];
2327 bool group_hold = true; /* To use GROUP_HOLD macros */
2329 OV5693_ENTER_GROUP_HOLD(group_hold);
2330 offset += ov5693_coarse_time_reg(reg_list + offset,
2332 mode->coarse_time_short);
2333 offset += ov5693_gain_reg(reg_list + offset, mode->gain);
2334 OV5693_LEAVE_GROUP_HOLD(group_hold);
2336 reg_list[offset].addr = OV5693_TABLE_END;
2337 err = ov5693_i2c_wr_table(info, reg_list);
2343 static int ov5693_set_gain(struct ov5693_info *info, u32 gain, bool group_hold)
2345 struct ov5693_reg reg_list[9];
2349 OV5693_ENTER_GROUP_HOLD(group_hold);
2350 offset += ov5693_gain_reg(reg_list + offset, gain);
2351 OV5693_LEAVE_GROUP_HOLD(group_hold);
2353 reg_list[offset].addr = OV5693_TABLE_END;
2356 err = ov5693_i2c_wr_table(info, reg_list);
2361 static int ov5693_awb_wr(struct ov5693_info *info)
2363 struct ov5693_reg reg_list[10];
2364 int rg, bg, rg_typical, bg_typical;
2365 int R_gain, G_gain, B_gain, G_gain_R, G_gain_B;
2369 if (info->cal.loaded == 0)
2372 /* update AWB calibration data to register lists */
2373 rg = info->cal.rg_ratio;
2374 bg = info->cal.bg_ratio;
2375 rg_typical = info->cal.rg_ratio_typical;
2376 bg_typical = info->cal.bg_ratio_typical;
2378 if ((rg == 0) || (bg == 0) || (rg_typical == 0) || (bg_typical == 0))
2381 if (bg < bg_typical) {
2382 if (rg < rg_typical) {
2384 B_gain = 0x400 * bg_typical / bg;
2385 R_gain = 0x400 * rg_typical / rg;
2388 G_gain = 0x400 * rg / rg_typical;
2389 B_gain = G_gain * bg_typical / bg;
2392 if (rg < rg_typical) {
2394 G_gain = 0x400 * bg / bg_typical;
2395 R_gain = G_gain * rg_typical / rg;
2397 G_gain_B = 0x400 * bg / bg_typical;
2398 G_gain_R = 0x400 * rg / rg_typical;
2399 if (G_gain_B > G_gain_R) {
2402 R_gain = G_gain * rg_typical / rg;
2406 B_gain = G_gain * bg_typical / bg;
2412 if (R_gain > 0x400) {
2413 reg_list[offset].addr = 0x3400;
2414 reg_list[offset].val = R_gain >> 8;
2416 reg_list[offset].addr = 0x3401;
2417 reg_list[offset].val = R_gain & 0x00ff;
2420 if (G_gain > 0x400) {
2421 reg_list[offset].addr = 0x3402;
2422 reg_list[offset].val = G_gain >> 8;
2424 reg_list[offset].addr = 0x3403;
2425 reg_list[offset].val = G_gain & 0x00ff;
2428 if (B_gain > 0x400) {
2429 reg_list[offset].addr = 0x3404;
2430 reg_list[offset].val = B_gain >> 8;
2432 reg_list[offset].addr = 0x3405;
2433 reg_list[offset].val = B_gain & 0x00ff;
2436 reg_list[offset].addr = OV5693_TABLE_END;
2439 err = ov5693_i2c_wr_table(info, reg_list);
2444 static int ov5693_lsc_wr(struct ov5693_info *info)
2446 struct ov5693_reg reg_list[64];
2451 if (info->cal.loaded == 0)
2455 reg_list[offset].addr = 0x5000;
2456 reg_list[offset].val = 0x86;
2458 for (i = 0; i < 62; i++) {
2459 reg_list[offset].addr = 0x5800 + i;
2460 reg_list[offset].val = info->cal.lenc[i];
2463 reg_list[offset].addr = OV5693_TABLE_END;
2466 err = ov5693_i2c_wr_table(info, reg_list);
2471 static int ov5693_set_group_hold(struct ov5693_info *info,
2472 struct ov5693_ae *ae)
2475 struct ov5693_reg reg_list[16];
2477 bool group_hold = true; /* To use GROUP_HOLD macros */
2479 OV5693_ENTER_GROUP_HOLD(group_hold);
2480 if (ae->gain_enable)
2481 offset += ov5693_gain_reg(reg_list + offset,
2483 if (ae->frame_length_enable)
2484 offset += ov5693_frame_length_reg(reg_list + offset,
2486 if (ae->coarse_time_enable)
2487 offset += ov5693_coarse_time_reg(reg_list + offset,
2488 ae->coarse_time, ae->coarse_time_short);
2489 OV5693_LEAVE_GROUP_HOLD(group_hold);
2491 reg_list[offset].addr = OV5693_TABLE_END;
2492 err |= ov5693_i2c_wr_table(info, reg_list);
2497 static int ov5693_gpio_rd(struct ov5693_info *info,
2498 enum ov5693_gpio_type type)
2502 if (info->gpio[type].gpio) {
2503 val = gpio_get_value_cansleep(info->gpio[type].gpio);
2504 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
2505 info->gpio[type].gpio, val);
2506 if (!info->gpio[type].active_high)
2510 return val; /* return read value or error */
2513 static int ov5693_gpio_wr(struct ov5693_info *info,
2514 enum ov5693_gpio_type type,
2515 int val) /* val: 0=deassert, 1=assert */
2519 if (info->gpio[type].gpio) {
2520 if (!info->gpio[type].active_high)
2524 gpio_set_value_cansleep(info->gpio[type].gpio, val);
2525 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
2526 info->gpio[type].gpio, val);
2528 return err; /* return value written or error */
2531 static void ov5693_gpio_pwrdn(struct ov5693_info *info, int val)
2535 prev_val = ov5693_gpio_rd(info, OV5693_GPIO_TYPE_PWRDN);
2536 if ((prev_val < 0) || (val == prev_val))
2539 ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, val);
2540 if (!val && prev_val)
2541 /* if transition from assert to deassert then delay for I2C */
2545 static void ov5693_gpio_exit(struct ov5693_info *info)
2549 for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
2550 if (info->gpio[i].gpio && info->gpio[i].own)
2551 gpio_free(info->gpio[i].gpio);
2555 static void ov5693_gpio_init(struct ov5693_info *info)
2558 unsigned long flags;
2564 if (!info->pdata->gpio_count || !info->pdata->gpio)
2567 for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
2568 type = ov5693_gpio[i].gpio_type;
2569 for (j = 0; j < info->pdata->gpio_count; j++) {
2570 if (type == info->pdata->gpio[j].gpio_type)
2573 if (j == info->pdata->gpio_count)
2576 info->gpio[type].gpio = info->pdata->gpio[j].gpio;
2577 if (ov5693_gpio[i].use_flags) {
2578 flags = ov5693_gpio[i].flags;
2579 info->gpio[type].active_high =
2580 ov5693_gpio[i].active_high;
2582 info->gpio[type].active_high =
2583 info->pdata->gpio[j].active_high;
2584 if (info->gpio[type].active_high)
2585 flags = GPIOF_OUT_INIT_LOW;
2587 flags = GPIOF_OUT_INIT_HIGH;
2589 if (!info->pdata->gpio[j].init_en)
2592 snprintf(label, sizeof(label), "ov5693_%u_%s",
2593 info->pdata->num, ov5693_gpio[i].label);
2594 err = gpio_request_one(info->gpio[type].gpio, flags, label);
2596 dev_err(&info->i2c_client->dev,
2597 "%s ERR %s %u\n", __func__, label,
2598 info->gpio[type].gpio);
2600 info->gpio[type].own = true;
2601 dev_dbg(&info->i2c_client->dev,
2602 "%s %s %u\n", __func__, label,
2603 info->gpio[type].gpio);
2608 static void ov5693_mclk_disable(struct ov5693_info *info)
2610 dev_dbg(&info->i2c_client->dev, "%s: disable MCLK\n", __func__);
2611 clk_disable_unprepare(info->mclk);
2614 static int ov5693_mclk_enable(struct ov5693_info *info)
2617 unsigned long mclk_init_rate = 24000000;
2619 dev_dbg(&info->i2c_client->dev, "%s: enable MCLK with %lu Hz\n",
2620 __func__, mclk_init_rate);
2622 err = clk_set_rate(info->mclk, mclk_init_rate);
2624 err = clk_prepare_enable(info->mclk);
2629 static int ov5693_power_off(struct ov5693_info *info)
2631 struct ov5693_power_rail *pw = &info->regulators;
2634 if (false == info->power_on)
2637 if (info->pdata && info->pdata->power_off) {
2638 err = info->pdata->power_off(pw);
2641 info->power_on = false;
2642 ov5693_mclk_disable(info);
2643 sysedp_set_state(info->sysedpc, 0);
2645 dev_err(&info->i2c_client->dev,
2646 "%s ERR: has no power_off function\n", __func__);
2652 static int ov5693_power_on(struct ov5693_info *info, bool standby)
2654 struct ov5693_power_rail *pw = &info->regulators;
2657 if (true == info->power_on)
2660 err = ov5693_mclk_enable(info);
2664 if (info->pdata && info->pdata->power_on) {
2665 err = info->pdata->power_on(pw);
2667 info->power_on = true;
2668 info->pwr_dev = NVC_PWR_ON;
2671 dev_err(&info->i2c_client->dev,
2672 "%s ERR: has no power_on function\n", __func__);
2677 ov5693_mclk_disable(info);
2682 static int ov5693_pm_wr(struct ov5693_info *info, int pwr)
2686 if ((info->pdata->cfg & (NVC_CFG_OFF2STDBY | NVC_CFG_BOOT_INIT)) &&
2687 (pwr == NVC_PWR_OFF ||
2688 pwr == NVC_PWR_STDBY_OFF))
2689 pwr = NVC_PWR_STDBY;
2690 if (pwr == info->pwr_dev)
2694 case NVC_PWR_OFF_FORCE:
2696 case NVC_PWR_STDBY_OFF:
2697 err = ov5693_power_off(info);
2698 info->mode_valid = false;
2703 err = ov5693_power_on(info, true);
2708 err = ov5693_power_on(info, false);
2717 dev_err(&info->i2c_client->dev, "%s err %d\n", __func__, err);
2720 info->pwr_dev = pwr;
2721 dev_dbg(&info->i2c_client->dev, "%s pwr_dev=%d\n",
2722 __func__, info->pwr_dev);
2729 static int ov5693_pm_dev_wr(struct ov5693_info *info, int pwr)
2731 if (info->mode_enable)
2733 if (pwr < info->pwr_api)
2734 pwr = info->pwr_api;
2735 return ov5693_pm_wr(info, pwr);
2738 static void ov5693_pm_exit(struct ov5693_info *info)
2740 ov5693_pm_wr(info, NVC_PWR_OFF_FORCE);
2742 ov5693_gpio_exit(info);
2745 static void ov5693_regulator_get(struct ov5693_info *info,
2746 struct regulator **vreg,
2747 const char vreg_name[])
2749 struct regulator *reg = NULL;
2752 reg = devm_regulator_get(&info->i2c_client->dev, vreg_name);
2754 dev_err(&info->i2c_client->dev, "%s %s ERR: %d\n",
2755 __func__, vreg_name, (int)reg);
2758 dev_dbg(&info->i2c_client->dev, "%s: %s\n",
2759 __func__, vreg_name);
2765 static void ov5693_pm_init(struct ov5693_info *info)
2767 struct ov5693_power_rail *pw = &info->regulators;
2769 ov5693_gpio_init(info);
2771 ov5693_regulator_get(info, &pw->avdd, info->pdata->regulators.avdd);
2773 ov5693_regulator_get(info, &pw->dvdd, info->pdata->regulators.dvdd);
2775 ov5693_regulator_get(info, &pw->dovdd, info->pdata->regulators.dovdd);
2777 info->power_on = false;
2780 static int ov5693_mode_able(struct ov5693_info *info, bool mode_enable)
2789 err = regmap_write(info->regmap, 0x0100, val);
2791 info->mode_enable = mode_enable;
2792 dev_dbg(&info->i2c_client->dev, "%s streaming=%x\n",
2793 __func__, info->mode_enable);
2795 ov5693_pm_dev_wr(info, NVC_PWR_STDBY);
2800 static int ov5693_mode_wr_full(struct ov5693_info *info, u32 mode_index)
2804 ov5693_pm_dev_wr(info, NVC_PWR_ON);
2805 ov5693_bin_wr(info, 0);
2806 err = ov5693_i2c_wr_table(info, mode_table[mode_index]);
2808 dev_dbg(&info->i2c_client->dev,
2809 "init done(mode=%d)!!!\n", mode_index);
2810 info->mode_index = mode_index;
2811 info->mode_valid = true;
2813 dev_dbg(&info->i2c_client->dev,
2814 "init error(mode=%d)!!!\n", mode_index);
2815 info->mode_valid = false;
2821 static int ov5693_set_mode(struct ov5693_info *info,
2822 struct ov5693_mode *mode)
2827 if (!mode->res_x && !mode->res_y) {
2828 if (mode->frame_length || mode->coarse_time || mode->gain) {
2829 /* write exposure only */
2830 err = ov5693_exposure_wr(info, mode);
2833 /* turn off streaming */
2834 err = ov5693_mode_able(info, false);
2839 if (mode->hdr_en == true) {
2840 if (mode->res_x == 2592 && mode->res_y == 1944)
2841 mode_index = OV5693_MODE_2592x1944_HDR;
2842 else if (mode->res_x == 1296 && mode->res_y == 972)
2843 mode_index = OV5693_MODE_1296x972_HDR;
2844 else if (mode->res_x == 1920 && mode->res_y == 1080)
2845 mode_index = OV5693_MODE_1920x1080_HDR;
2846 else if (mode->res_x == 1280 && mode->res_y == 720)
2847 mode_index = OV5693_MODE_1280x720_HDR_60FPS;
2849 if (mode->res_x == 2592 && mode->res_y == 1944)
2850 mode_index = OV5693_MODE_2592x1944;
2851 else if (mode->res_x == 1296 && mode->res_y == 972)
2852 mode_index = OV5693_MODE_1296x972;
2853 else if (mode->res_x == 1920 && mode->res_y == 1080)
2854 mode_index = OV5693_MODE_1920x1080;
2855 else if (mode->res_x == 1280 && mode->res_y == 720)
2856 mode_index = OV5693_MODE_1280x720_120FPS;
2859 /* request highest edp state */
2860 sysedp_set_state(info->sysedpc, 1);
2862 if (!info->mode_valid || (info->mode_index != mode_index))
2863 err = ov5693_mode_wr_full(info, mode_index);
2865 dev_dbg(&info->i2c_client->dev, "%s short mode\n", __func__);
2866 dev_dbg(&info->i2c_client->dev, "%s: mode #: %d\n",
2867 __func__, mode_index);
2868 dev_dbg(&info->i2c_client->dev, "%s: AE: %d, %d, %d\n",
2869 __func__, mode->frame_length,
2870 mode->coarse_time, mode->gain);
2871 err |= ov5693_exposure_wr(info, mode);
2873 info->mode_valid = false;
2874 dev_err(&info->i2c_client->dev,
2875 "%s set_mode error\n", __func__);
2876 goto ov5693_mode_wr_err;
2878 err = ov5693_awb_wr(info);
2880 info->mode_valid = false;
2881 dev_err(&info->i2c_client->dev,
2882 "%s:%d awb cal write error\n", __func__, __LINE__);
2883 goto ov5693_mode_wr_err;
2885 err = ov5693_lsc_wr(info);
2887 info->mode_valid = false;
2888 dev_err(&info->i2c_client->dev,
2889 "%s:%d lsc cal write error\n", __func__, __LINE__);
2890 goto ov5693_mode_wr_err;
2892 err = regmap_write(info->regmap, 0x0100, 0x01);
2894 info->mode_valid = false;
2895 dev_err(&info->i2c_client->dev,
2896 "%s:%d stream on failed\n", __func__, __LINE__);
2897 goto ov5693_mode_wr_err;
2903 if (!info->mode_enable)
2904 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
2908 static int ov5693_get_fuse_id(struct ov5693_info *info)
2910 /* fuse stored at ov5693 bank 0 */
2912 /* delay to ensure i2c is ready after poweron */
2913 usleep_range(150, 200);
2914 err = regmap_write(info->regmap, 0x0100, 0x01);
2916 dev_err(&info->i2c_client->dev,
2917 "%s ERR %d: cannot write stream mode\n", __func__,
2921 usleep_range(10000, 11000);
2923 err = regmap_write(info->regmap, 0x3D84, 0xC0);
2925 dev_err(&info->i2c_client->dev,
2926 "%s ERR %d: cannot write bank index 0\n", __func__,
2930 usleep_range(10000, 11000);
2932 err = regmap_write(info->regmap, 0x3D81, 0x01);
2934 dev_err(&info->i2c_client->dev,
2935 "%s ERR %d: cannot load OTP data\n", __func__, err);
2938 usleep_range(10000, 11000);
2940 err = regmap_bulk_read(info->regmap, 0x3D00,
2941 info->fuseid.data, OV5693_FUSE_ID_SIZE);
2943 dev_err(&info->i2c_client->dev,
2944 "%s ERR %d: cannot read OTP buffer\n", __func__,
2949 info->fuseid.size = OV5693_FUSE_ID_SIZE;
2954 static int ov5693_read_otp_bank(struct ov5693_info *info,
2955 struct ov5693_otp_bank *bank)
2959 err = regmap_write(info->regmap, 0x0100, 0x01);
2961 dev_err(&info->i2c_client->dev,
2962 "%s ERR %d: cannot write stream mode\n", __func__,
2966 err = regmap_write(info->regmap, 0x3d84, 0xc0 | bank->id);
2968 dev_err(&info->i2c_client->dev,
2969 "%s ERR %d: cannot write bank index %d\n", __func__,
2973 err = regmap_write(info->regmap, 0x3d81, 0x01);
2975 dev_err(&info->i2c_client->dev,
2976 "%s ERR %d: cannot load OTP data\n", __func__, err);
2979 usleep_range(1000, 11000);
2980 err = regmap_bulk_read(info->regmap, 0x3d00, bank->buf, 16);
2982 dev_err(&info->i2c_client->dev,
2983 "%s ERR %d: cannot read OTP buffer\n", __func__,
2992 ov5693_eeprom_device_release(struct ov5693_info *info)
2996 for (i = 0; i < OV5693_EEPROM_NUM_BLOCKS; i++) {
2997 if (info->eeprom[i].i2c_client != NULL) {
2998 i2c_unregister_device(info->eeprom[i].i2c_client);
2999 info->eeprom[i].i2c_client = NULL;
3007 ov5693_eeprom_device_init(struct ov5693_info *info)
3009 char *dev_name = "eeprom_ov5693";
3010 static struct regmap_config eeprom_regmap_config = {
3017 for (i = 0; i < OV5693_EEPROM_NUM_BLOCKS; i++) {
3018 info->eeprom[i].adap = i2c_get_adapter(
3019 info->i2c_client->adapter->nr);
3020 memset(&info->eeprom[i].brd, 0, sizeof(info->eeprom[i].brd));
3021 strncpy(info->eeprom[i].brd.type, dev_name,
3022 sizeof(info->eeprom[i].brd.type));
3023 info->eeprom[i].brd.addr = OV5693_EEPROM_ADDRESS + i;
3024 info->eeprom[i].i2c_client = i2c_new_device(
3025 info->eeprom[i].adap, &info->eeprom[i].brd);
3027 info->eeprom[i].regmap = devm_regmap_init_i2c(
3028 info->eeprom[i].i2c_client, &eeprom_regmap_config);
3029 if (IS_ERR(info->eeprom[i].regmap)) {
3030 err = PTR_ERR(info->eeprom[i].regmap);
3031 ov5693_eeprom_device_release(info);
3040 ov5693_read_eeprom(struct ov5693_info *info, u8 reg, u16 length, u8 *buf)
3042 return regmap_raw_read(info->eeprom[0].regmap, reg, &buf[reg], length);
3046 ov5693_write_eeprom(struct ov5693_info *info, u16 addr, u8 val)
3048 return regmap_write(info->eeprom[addr >> 8].regmap, addr & 0xFF, val);
3051 static long ov5693_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3053 struct ov5693_info *info = file->private_data;
3056 switch (_IOC_NR(cmd)) {
3057 case _IOC_NR(OV5693_IOCTL_SET_POWER):
3059 u32 powerlevel = (u32) arg;
3063 if (powerlevel > NVC_PWR_ON) {
3064 dev_err(&info->i2c_client->dev,
3065 "%s:Invalid power level.\n",
3070 err = ov5693_pm_wr(info, powerlevel);
3073 case _IOC_NR(OV5693_IOCTL_GET_CAPS):
3074 if (copy_to_user((void __user *)arg,
3076 sizeof(struct nvc_imager_cap))) {
3077 dev_err(&info->i2c_client->dev,
3078 "%s copy_to_user err line %d\n",
3079 __func__, __LINE__);
3083 case _IOC_NR(OV5693_IOCTL_SET_MODE):
3085 struct ov5693_mode mode;
3086 if (copy_from_user(&mode,
3087 (const void __user *)arg,
3088 sizeof(struct ov5693_mode))) {
3089 dev_err(&info->i2c_client->dev,
3090 "%s:Failed to get mode from user.\n",
3094 return ov5693_set_mode(info, &mode);
3096 case _IOC_NR(OV5693_IOCTL_GET_STATUS): {
3098 if (copy_to_user((void __user *)arg, &status, sizeof(status))) {
3099 dev_err(&info->i2c_client->dev,
3100 "%s:Failed to copy status to user.\n",
3107 case _IOC_NR(OV5693_IOCTL_SET_GROUP_HOLD): {
3108 struct ov5693_ae ae;
3109 if (copy_from_user(&ae, (const void __user *)arg,
3110 sizeof(struct ov5693_ae))) {
3111 dev_dbg(&info->i2c_client->dev,
3112 "%s:fail group hold\n", __func__);
3116 return ov5693_set_group_hold(info, &ae);
3119 case _IOC_NR(OV5693_IOCTL_SET_FRAME_LENGTH):
3120 return ov5693_set_frame_length(info, (u32)arg, true);
3122 case _IOC_NR(OV5693_IOCTL_SET_COARSE_TIME):
3123 return ov5693_set_coarse_time(info, (u32)arg,
3124 OV5693_INVALID_COARSE_TIME, true);
3126 case _IOC_NR(OV5693_IOCTL_SET_HDR_COARSE_TIME):
3128 struct ov5693_hdr *hdrcoarse = (struct ov5693_hdr *)arg;
3129 int ret = ov5693_set_coarse_time(info,
3130 hdrcoarse->coarse_time_long,
3131 hdrcoarse->coarse_time_short,
3136 case _IOC_NR(OV5693_IOCTL_SET_GAIN):
3137 return ov5693_set_gain(info, (u32)arg, true);
3139 case _IOC_NR(OV5693_IOCTL_GET_FUSEID):
3141 err = ov5693_get_fuse_id(info);
3144 dev_err(&info->i2c_client->dev, "%s:Failed to get fuse id info.\n",
3148 if (copy_to_user((void __user *)arg,
3150 sizeof(struct nvc_fuseid))) {
3151 dev_dbg(&info->i2c_client->dev, "%s:Fail copy fuse id to user space\n",
3158 case _IOC_NR(OV5693_IOCTL_READ_OTP_BANK):
3160 struct ov5693_otp_bank bank;
3161 if (copy_from_user(&bank,
3162 (const void __user *)arg,
3164 dev_err(&info->i2c_client->dev,
3165 "%s %d copy_from_user err\n",
3166 __func__, __LINE__);
3170 err = ov5693_read_otp_bank(info, &bank);
3174 if (copy_to_user((void __user *)arg,
3177 dev_err(&info->i2c_client->dev,
3178 "%s %d copy_to_user err\n",
3179 __func__, __LINE__);
3185 case _IOC_NR(OV5693_IOCTL_SET_CAL_DATA):
3187 if (copy_from_user(&info->cal, (const void __user *)arg,
3188 sizeof(info->cal))) {
3189 dev_err(&info->i2c_client->dev,
3190 "%s %d copy_from_user err\n",
3191 __func__, __LINE__);
3197 case _IOC_NR(OV5693_IOCTL_GET_EEPROM_DATA):
3199 if (!info->pdata->has_eeprom)
3202 ov5693_read_eeprom(info,
3207 if (copy_to_user((void __user *)arg,
3208 info->eeprom_buf, OV5693_EEPROM_SIZE)) {
3209 dev_err(&info->i2c_client->dev,
3210 "%s:Failed to copy status to user\n",
3217 case _IOC_NR(OV5693_IOCTL_SET_EEPROM_DATA):
3221 if (!info->pdata->has_eeprom)
3224 if (copy_from_user(info->eeprom_buf,
3225 (const void __user *)arg, OV5693_EEPROM_SIZE)) {
3226 dev_err(&info->i2c_client->dev,
3227 "%s:Failed to read from user buffer\n",
3231 for (i = 0; i < OV5693_EEPROM_SIZE; i++) {
3232 ov5693_write_eeprom(info,
3234 info->eeprom_buf[i]);
3241 dev_err(&info->i2c_client->dev, "%s unsupported ioctl: %x\n",
3247 static void ov5693_sdata_init(struct ov5693_info *info)
3249 memcpy(&info->sdata, &ov5693_dflt_sdata, sizeof(info->sdata));
3250 if (info->pdata->lens_focal_length)
3251 info->sdata.focal_len = info->pdata->lens_focal_length;
3252 if (info->pdata->lens_max_aperture)
3253 info->sdata.max_aperture = info->pdata->lens_max_aperture;
3254 if (info->pdata->lens_fnumber)
3255 info->sdata.fnumber = info->pdata->lens_fnumber;
3256 if (info->pdata->lens_view_angle_h)
3257 info->sdata.view_angle_h = info->pdata->lens_view_angle_h;
3258 if (info->pdata->lens_view_angle_v)
3259 info->sdata.view_angle_v = info->pdata->lens_view_angle_v;
3262 static int ov5693_open(struct inode *inode, struct file *file)
3265 struct miscdevice *miscdev = file->private_data;
3266 struct ov5693_info *info = dev_get_drvdata(miscdev->parent);
3268 if (atomic_xchg(&info->in_use, 1))
3271 file->private_data = info;
3272 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3274 err = ov5693_power_on(info, false);
3278 static int ov5693_release(struct inode *inode, struct file *file)
3280 struct ov5693_info *info = file->private_data;
3282 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3283 ov5693_pm_wr(info, NVC_PWR_OFF);
3284 file->private_data = NULL;
3285 WARN_ON(!atomic_xchg(&info->in_use, 0));
3289 static const struct file_operations ov5693_fileops = {
3290 .owner = THIS_MODULE,
3291 .open = ov5693_open,
3292 .unlocked_ioctl = ov5693_ioctl,
3293 #ifdef CONFIG_COMPAT
3294 .compat_ioctl = ov5693_ioctl,
3296 .release = ov5693_release,
3299 static void ov5693_del(struct ov5693_info *info)
3301 ov5693_pm_exit(info);
3305 static int ov5693_remove(struct i2c_client *client)
3307 struct ov5693_info *info = i2c_get_clientdata(client);
3309 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3310 misc_deregister(&info->miscdev);
3311 sysedp_free_consumer(info->sysedpc);
3312 if (info->pdata->has_eeprom)
3313 ov5693_eeprom_device_release(info);
3318 static struct of_device_id ov5693_of_match[] = {
3319 { .compatible = "nvidia,ov5693", },
3323 MODULE_DEVICE_TABLE(of, ov5693_of_match);
3325 static int ov5693_platform_power_on(struct ov5693_power_rail *pw)
3328 struct ov5693_info *info = container_of(pw, struct ov5693_info,
3331 if (info->pdata->use_vcm_vdd) {
3332 err = regulator_enable(info->ext_vcm_vdd);
3334 goto ov5693_vcm_fail;
3337 ov5693_gpio_pwrdn(info, 0);
3338 usleep_range(10, 20);
3340 err = regulator_enable(pw->avdd);
3342 goto ov5693_avdd_fail;
3344 err = regulator_enable(pw->dovdd);
3346 goto ov5693_iovdd_fail;
3349 ov5693_gpio_pwrdn(info, 1);
3351 usleep_range(300, 310);
3356 regulator_disable(pw->avdd);
3359 if (info->pdata->use_vcm_vdd)
3360 regulator_disable(info->ext_vcm_vdd);
3363 pr_err("%s FAILED\n", __func__);
3367 static int ov5693_platform_power_off(struct ov5693_power_rail *pw)
3369 struct ov5693_info *info = container_of(pw, struct ov5693_info,
3372 usleep_range(21, 25);
3373 ov5693_gpio_pwrdn(info, 0);
3376 regulator_disable(pw->dovdd);
3377 regulator_disable(pw->avdd);
3378 if (info->pdata->use_vcm_vdd)
3379 regulator_disable(info->ext_vcm_vdd);
3384 static int ov5693_parse_dt_gpio(struct device_node *np, const char *name,
3385 enum ov5693_gpio_type type,
3386 struct nvc_gpio_pdata *pdata)
3388 enum of_gpio_flags gpio_flags;
3390 if (of_find_property(np, name, NULL)) {
3391 pdata->gpio = of_get_named_gpio_flags(np, name, 0, &gpio_flags);
3392 pdata->gpio_type = type;
3393 pdata->init_en = true;
3394 pdata->active_high = !(gpio_flags & OF_GPIO_ACTIVE_LOW);
3400 static struct ov5693_platform_data *ov5693_parse_dt(struct i2c_client *client)
3402 struct device_node *np = client->dev.of_node;
3403 struct ov5693_platform_data *pdata;
3404 struct nvc_gpio_pdata *gpio_pdata = NULL;
3406 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
3408 dev_err(&client->dev, "Failed to allocate pdata\n");
3409 return ERR_PTR(-ENOMEM);
3412 gpio_pdata = devm_kzalloc(&client->dev,
3413 sizeof(*gpio_pdata) * ARRAY_SIZE(ov5693_gpio), GFP_KERNEL);
3415 dev_err(&client->dev, "cannot allocate gpio data memory\n");
3416 return ERR_PTR(-ENOMEM);
3419 /* init with default platform data values */
3420 memcpy(pdata, &ov5693_dflt_pdata, sizeof(*pdata));
3422 /* extra regulators info */
3423 pdata->use_vcm_vdd = of_property_read_bool(np, "nvidia,use-vcm-vdd");
3426 of_property_read_u32(np, "nvidia,num", &pdata->num);
3427 of_property_read_string(np, "nvidia,dev-name", &pdata->dev_name);
3430 pdata->gpio_count = 0;
3431 pdata->gpio_count += ov5693_parse_dt_gpio(np,
3432 "reset-gpios", OV5693_GPIO_TYPE_PWRDN,
3433 &gpio_pdata[pdata->gpio_count]);
3434 pdata->gpio = gpio_pdata;
3436 /* MCLK clock info */
3437 of_property_read_string(np, "nvidia,mclk_name",
3440 /* ov5693 power functions */
3441 pdata->power_on = ov5693_platform_power_on;
3442 pdata->power_off = ov5693_platform_power_off;
3447 static int ov5693_probe(
3448 struct i2c_client *client,
3449 const struct i2c_device_id *id)
3451 struct ov5693_info *info;
3452 unsigned long clock_probe_rate;
3454 const char *mclk_name;
3455 static struct regmap_config ov5693_regmap_config = {
3461 dev_dbg(&client->dev, "%s\n", __func__);
3462 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
3464 dev_err(&client->dev, "%s: kzalloc error\n", __func__);
3468 info->i2c_client = client;
3469 if (client->dev.of_node) {
3470 info->pdata = ov5693_parse_dt(client);
3471 if (IS_ERR(info->pdata)) {
3472 err = PTR_ERR(info->pdata);
3473 dev_err(&client->dev,
3474 "Failed to parse OF node: %d\n", err);
3477 } else if (client->dev.platform_data)
3478 info->pdata = client->dev.platform_data;
3480 info->pdata = &ov5693_dflt_pdata;
3481 dev_dbg(&client->dev,
3482 "%s No platform data. Using defaults.\n",
3485 if (info->pdata->use_vcm_vdd) {
3486 info->ext_vcm_vdd = devm_regulator_get(&info->i2c_client->dev,
3488 if (WARN_ON(IS_ERR(info->ext_vcm_vdd))) {
3489 err = PTR_ERR(info->ext_vcm_vdd);
3490 dev_err(&client->dev,
3491 "ext_vcm_vdd get failed %d\n", err);
3492 info->ext_vcm_vdd = NULL;
3497 info->regmap = devm_regmap_init_i2c(client, &ov5693_regmap_config);
3498 if (IS_ERR(info->regmap)) {
3499 err = PTR_ERR(info->regmap);
3500 dev_err(&client->dev,
3501 "Failed to allocate register map: %d\n", err);
3505 if (info->pdata->has_eeprom) {
3506 err = ov5693_eeprom_device_init(info);
3508 dev_err(&client->dev,
3509 "Failed to allocate eeprom register map: %d\n", err);
3514 mclk_name = info->pdata->mclk_name ?
3515 info->pdata->mclk_name : "default_mclk";
3516 info->mclk = devm_clk_get(&client->dev, mclk_name);
3517 if (IS_ERR(info->mclk)) {
3518 dev_err(&client->dev, "%s: unable to get clock %s\n",
3519 __func__, mclk_name);
3520 return PTR_ERR(info->mclk);
3523 i2c_set_clientdata(client, info);
3524 ov5693_pm_init(info);
3525 if (IS_ERR(info->regulators.avdd) || IS_ERR(info->regulators.dovdd))
3528 ov5693_sdata_init(info);
3529 if (info->pdata->cfg & (NVC_CFG_NODEV | NVC_CFG_BOOT_INIT)) {
3530 if (info->pdata->probe_clock) {
3531 clock_probe_rate = 6000; /* initial_clcok*/
3532 clock_probe_rate *= 1000;
3533 info->pdata->probe_clock(clock_probe_rate);
3535 ov5693_pm_dev_wr(info, NVC_PWR_COMM);
3536 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
3537 if (info->pdata->probe_clock)
3538 info->pdata->probe_clock(0);
3540 if (info->pdata->dev_name != NULL)
3541 strncpy(info->devname, info->pdata->dev_name,
3542 sizeof(info->devname) - 1);
3544 strncpy(info->devname, "ov5693", sizeof(info->devname) - 1);
3545 if (info->pdata->num)
3546 snprintf(info->devname, sizeof(info->devname), "%s.%u",
3547 info->devname, info->pdata->num);
3549 info->miscdev.name = info->devname;
3550 info->miscdev.fops = &ov5693_fileops;
3551 info->miscdev.minor = MISC_DYNAMIC_MINOR;
3552 info->miscdev.parent = &client->dev;
3553 if (misc_register(&info->miscdev)) {
3554 dev_err(&client->dev, "%s unable to register misc device %s\n",
3555 __func__, info->devname);
3560 info->sysedpc = sysedp_create_consumer("ov5693", info->devname);
3562 dev_dbg(&client->dev, "ov5693 sensor driver loading done\n");
3566 static const struct i2c_device_id ov5693_id[] = {
3572 MODULE_DEVICE_TABLE(i2c, ov5693_id);
3574 static struct i2c_driver ov5693_i2c_driver = {
3577 .owner = THIS_MODULE,
3578 .of_match_table = ov5693_of_match,
3580 .id_table = ov5693_id,
3581 .probe = ov5693_probe,
3582 .remove = ov5693_remove,
3585 module_i2c_driver(ov5693_i2c_driver);
3586 MODULE_LICENSE("GPL v2");