| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * jaguar1 driver |
|---|
| 4 | | - * |
|---|
| 5 | | - * V0.0X01.0X01 add workqueue to detect ahd state. |
|---|
| 4 | + * V0.0X01.0X00 first version. |
|---|
| 5 | + * V0.0X01.0X01 fix kernel5.10 compile error. |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | */ |
|---|
| 8 | 8 | |
|---|
| .. | .. |
|---|
| 39 | 39 | #include "jaguar1_video_eq.h" |
|---|
| 40 | 40 | #include "jaguar1_mipi.h" |
|---|
| 41 | 41 | #include "jaguar1_drv.h" |
|---|
| 42 | | - |
|---|
| 43 | | -#define WORK_QUEUE |
|---|
| 44 | | - |
|---|
| 45 | | -#ifdef WORK_QUEUE |
|---|
| 46 | | -#include <linux/workqueue.h> |
|---|
| 47 | | - |
|---|
| 48 | | -struct sensor_state_check_work { |
|---|
| 49 | | - struct workqueue_struct *state_check_wq; |
|---|
| 50 | | - struct delayed_work d_work; |
|---|
| 51 | | -}; |
|---|
| 52 | | - |
|---|
| 53 | | -#endif |
|---|
| 42 | +#include "jaguar1_v4l2.h" |
|---|
| 54 | 43 | |
|---|
| 55 | 44 | #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x1) |
|---|
| 56 | 45 | |
|---|
| .. | .. |
|---|
| 81 | 70 | |
|---|
| 82 | 71 | /* #define FORCE_720P */ |
|---|
| 83 | 72 | |
|---|
| 84 | | -enum jaguar1_max_pad { |
|---|
| 85 | | - PAD0, |
|---|
| 86 | | - PAD1, |
|---|
| 87 | | - PAD2, |
|---|
| 88 | | - PAD3, |
|---|
| 89 | | - PAD_MAX, |
|---|
| 90 | | -}; |
|---|
| 91 | | - |
|---|
| 92 | 73 | struct jaguar1_gpio { |
|---|
| 93 | 74 | int pltfrm_gpio; |
|---|
| 94 | 75 | const char *label; |
|---|
| .. | .. |
|---|
| 113 | 94 | struct jaguar1_framesize { |
|---|
| 114 | 95 | u16 width; |
|---|
| 115 | 96 | u16 height; |
|---|
| 97 | + struct v4l2_fract max_fps; |
|---|
| 116 | 98 | enum NC_VIVO_CH_FORMATDEF fmt_idx; |
|---|
| 99 | + __u32 field; |
|---|
| 117 | 100 | }; |
|---|
| 118 | 101 | |
|---|
| 119 | 102 | struct jaguar1_default_rect { |
|---|
| 120 | 103 | unsigned int width; |
|---|
| 121 | 104 | unsigned int height; |
|---|
| 122 | | -}; |
|---|
| 123 | | - |
|---|
| 124 | | -enum jaguar1_hot_plug_state { |
|---|
| 125 | | - PLUG_IN = 0, |
|---|
| 126 | | - PLUG_OUT, |
|---|
| 127 | | - PLUG_STATE_MAX, |
|---|
| 128 | 105 | }; |
|---|
| 129 | 106 | |
|---|
| 130 | 107 | struct jaguar1 { |
|---|
| .. | .. |
|---|
| 157 | 134 | const struct jaguar1_framesize *frame_size; |
|---|
| 158 | 135 | int streaming; |
|---|
| 159 | 136 | struct jaguar1_default_rect defrect; |
|---|
| 160 | | -#ifdef WORK_QUEUE |
|---|
| 161 | | - struct sensor_state_check_work plug_state_check; |
|---|
| 162 | | - u8 cur_detect_status; |
|---|
| 163 | | - u8 last_detect_status; |
|---|
| 164 | | - u64 timestamp0; |
|---|
| 165 | | - u64 timestamp1; |
|---|
| 166 | | -#endif |
|---|
| 167 | | - bool hot_plug; |
|---|
| 168 | | - u8 is_reset; |
|---|
| 169 | | - struct semaphore reg_sem; |
|---|
| 170 | 137 | }; |
|---|
| 171 | 138 | |
|---|
| 172 | 139 | #define to_jaguar1(sd) container_of(sd, struct jaguar1, subdev) |
|---|
| .. | .. |
|---|
| 176 | 143 | { |
|---|
| 177 | 144 | .width = 2560, |
|---|
| 178 | 145 | .height = 1440, |
|---|
| 146 | + .max_fps = { |
|---|
| 147 | + .numerator = 10000, |
|---|
| 148 | + .denominator = 250000, |
|---|
| 149 | + }, |
|---|
| 179 | 150 | .fmt_idx = AHD20_720P_25P, |
|---|
| 180 | 151 | } |
|---|
| 181 | 152 | #else |
|---|
| 182 | 153 | { |
|---|
| 154 | + .width = 960, |
|---|
| 155 | + .height = 480, |
|---|
| 156 | + .max_fps = { |
|---|
| 157 | + .numerator = 10000, |
|---|
| 158 | + .denominator = 250000, |
|---|
| 159 | + }, |
|---|
| 160 | + .fmt_idx = AHD20_SD_H960_2EX_Btype_NT, |
|---|
| 161 | + .field = V4L2_FIELD_INTERLACED, |
|---|
| 162 | + }, |
|---|
| 163 | + { |
|---|
| 164 | + .width = 960, |
|---|
| 165 | + .height = 576, |
|---|
| 166 | + .max_fps = { |
|---|
| 167 | + .numerator = 10000, |
|---|
| 168 | + .denominator = 300000, |
|---|
| 169 | + }, |
|---|
| 170 | + .fmt_idx = AHD20_SD_H960_2EX_Btype_PAL, |
|---|
| 171 | + .field = V4L2_FIELD_INTERLACED, |
|---|
| 172 | + }, |
|---|
| 173 | + { |
|---|
| 183 | 174 | .width = 1280, |
|---|
| 184 | 175 | .height = 720, |
|---|
| 176 | + .max_fps = { |
|---|
| 177 | + .numerator = 10000, |
|---|
| 178 | + .denominator = 250000, |
|---|
| 179 | + }, |
|---|
| 185 | 180 | .fmt_idx = AHD20_720P_25P_EX_Btype, |
|---|
| 181 | + .field = V4L2_FIELD_NONE |
|---|
| 186 | 182 | }, |
|---|
| 187 | 183 | { |
|---|
| 188 | 184 | .width = 1920, |
|---|
| 189 | 185 | .height = 1080, |
|---|
| 186 | + .max_fps = { |
|---|
| 187 | + .numerator = 10000, |
|---|
| 188 | + .denominator = 250000, |
|---|
| 189 | + }, |
|---|
| 190 | 190 | .fmt_idx = AHD20_1080P_25P, |
|---|
| 191 | + .field = V4L2_FIELD_NONE |
|---|
| 191 | 192 | }, |
|---|
| 192 | 193 | { |
|---|
| 193 | 194 | .width = 2560, |
|---|
| 194 | 195 | .height = 1440, |
|---|
| 196 | + .max_fps = { |
|---|
| 197 | + .numerator = 10000, |
|---|
| 198 | + .denominator = 250000, |
|---|
| 199 | + }, |
|---|
| 195 | 200 | .fmt_idx = AHD20_720P_25P, |
|---|
| 201 | + .field = V4L2_FIELD_NONE |
|---|
| 196 | 202 | } |
|---|
| 197 | 203 | #endif |
|---|
| 198 | 204 | }; |
|---|
| .. | .. |
|---|
| 206 | 212 | static const s64 link_freq_menu_items[] = { |
|---|
| 207 | 213 | JAGUAR1_LINK_FREQ |
|---|
| 208 | 214 | }; |
|---|
| 209 | | - |
|---|
| 210 | | -/* sensor register write */ |
|---|
| 211 | | -static int jaguar1_write(struct i2c_client *client, u8 reg, u8 val) |
|---|
| 212 | | -{ |
|---|
| 213 | | - struct i2c_msg msg; |
|---|
| 214 | | - u8 buf[2]; |
|---|
| 215 | | - int ret; |
|---|
| 216 | | - |
|---|
| 217 | | - dev_dbg(&client->dev, "write reg(0x%x val:0x%x)!\n", reg, val); |
|---|
| 218 | | - buf[0] = reg & 0xFF; |
|---|
| 219 | | - buf[1] = val; |
|---|
| 220 | | - |
|---|
| 221 | | - msg.addr = client->addr; |
|---|
| 222 | | - msg.flags = client->flags; |
|---|
| 223 | | - msg.buf = buf; |
|---|
| 224 | | - msg.len = sizeof(buf); |
|---|
| 225 | | - |
|---|
| 226 | | - ret = i2c_transfer(client->adapter, &msg, 1); |
|---|
| 227 | | - if (ret >= 0) |
|---|
| 228 | | - return 0; |
|---|
| 229 | | - |
|---|
| 230 | | - dev_err(&client->dev, |
|---|
| 231 | | - "jaguar1 write reg(0x%x val:0x%x) failed !\n", reg, val); |
|---|
| 232 | | - |
|---|
| 233 | | - return ret; |
|---|
| 234 | | -} |
|---|
| 235 | | - |
|---|
| 236 | | -/* sensor register read */ |
|---|
| 237 | | -static int jaguar1_read(struct i2c_client *client, u8 reg, u8 *val) |
|---|
| 238 | | -{ |
|---|
| 239 | | - struct i2c_msg msg[2]; |
|---|
| 240 | | - u8 buf[1]; |
|---|
| 241 | | - int ret; |
|---|
| 242 | | - |
|---|
| 243 | | - buf[0] = reg & 0xFF; |
|---|
| 244 | | - |
|---|
| 245 | | - msg[0].addr = client->addr; |
|---|
| 246 | | - msg[0].flags = client->flags; |
|---|
| 247 | | - msg[0].buf = buf; |
|---|
| 248 | | - msg[0].len = sizeof(buf); |
|---|
| 249 | | - |
|---|
| 250 | | - msg[1].addr = client->addr; |
|---|
| 251 | | - msg[1].flags = client->flags | I2C_M_RD; |
|---|
| 252 | | - msg[1].buf = buf; |
|---|
| 253 | | - msg[1].len = 1; |
|---|
| 254 | | - |
|---|
| 255 | | - ret = i2c_transfer(client->adapter, msg, 2); |
|---|
| 256 | | - if (ret >= 0) { |
|---|
| 257 | | - *val = buf[0]; |
|---|
| 258 | | - return 0; |
|---|
| 259 | | - } |
|---|
| 260 | | - |
|---|
| 261 | | - dev_err(&client->dev, "jaguar1 read reg(0x%x) failed !\n", reg); |
|---|
| 262 | | - |
|---|
| 263 | | - return ret; |
|---|
| 264 | | -} |
|---|
| 265 | | - |
|---|
| 266 | 215 | static int __jaguar1_power_on(struct jaguar1 *jaguar1) |
|---|
| 267 | 216 | { |
|---|
| 268 | 217 | u32 i; |
|---|
| .. | .. |
|---|
| 391 | 340 | struct jaguar1 *jaguar1 = to_jaguar1(sd); |
|---|
| 392 | 341 | int ret = 0; |
|---|
| 393 | 342 | |
|---|
| 394 | | - dev_info(&client->dev, "%s: on %d\n", __func__, on); |
|---|
| 343 | + dev_dbg(&client->dev, "%s: on %d\n", __func__, on); |
|---|
| 395 | 344 | mutex_lock(&jaguar1->mutex); |
|---|
| 396 | 345 | |
|---|
| 397 | 346 | /* If the power state is not modified - no work to do. */ |
|---|
| .. | .. |
|---|
| 402 | 351 | ret = __jaguar1_power_on(jaguar1); |
|---|
| 403 | 352 | if (ret < 0) |
|---|
| 404 | 353 | goto exit; |
|---|
| 405 | | - jaguar1->power_on = true; |
|---|
| 406 | 354 | |
|---|
| 355 | + jaguar1->power_on = true; |
|---|
| 407 | 356 | } else { |
|---|
| 408 | 357 | __jaguar1_power_off(jaguar1); |
|---|
| 409 | 358 | jaguar1->power_on = false; |
|---|
| 410 | | - |
|---|
| 411 | 359 | } |
|---|
| 412 | 360 | |
|---|
| 413 | 361 | exit: |
|---|
| .. | .. |
|---|
| 479 | 427 | format->colorspace = V4L2_COLORSPACE_SRGB; |
|---|
| 480 | 428 | format->code = jaguar1_formats[0].code; |
|---|
| 481 | 429 | jaguar1->frame_size = match; |
|---|
| 482 | | - format->field = V4L2_FIELD_NONE; |
|---|
| 430 | + format->field = match->field; |
|---|
| 483 | 431 | } |
|---|
| 484 | 432 | |
|---|
| 485 | | -static inline bool jaguar1_no_signal(struct v4l2_subdev *sd, u8 *novid); |
|---|
| 486 | 433 | static int jaguar1_stream(struct v4l2_subdev *sd, int on) |
|---|
| 487 | 434 | { |
|---|
| 488 | 435 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| .. | .. |
|---|
| 491 | 438 | enum NC_VIVO_CH_FORMATDEF fmt_idx; |
|---|
| 492 | 439 | int ch; |
|---|
| 493 | 440 | |
|---|
| 494 | | - dev_info(&client->dev, "%s: on %d\n", __func__, on); |
|---|
| 441 | + dev_dbg(&client->dev, "%s: on %d\n", __func__, on); |
|---|
| 495 | 442 | mutex_lock(&jaguar1->mutex); |
|---|
| 496 | 443 | on = !!on; |
|---|
| 497 | 444 | |
|---|
| .. | .. |
|---|
| 508 | 455 | video_init.ch_param[ch].interface = YUV_422; |
|---|
| 509 | 456 | } |
|---|
| 510 | 457 | jaguar1_start(&video_init); |
|---|
| 511 | | -#ifdef WORK_QUEUE |
|---|
| 512 | | - jaguar1->hot_plug = false; |
|---|
| 513 | | - jaguar1->is_reset = 0; |
|---|
| 514 | | - usleep_range(20000, 21000); |
|---|
| 515 | | - /* get power on state first*/ |
|---|
| 516 | | - jaguar1_no_signal(sd, &jaguar1->last_detect_status); |
|---|
| 517 | | - /* check hot plug state */ |
|---|
| 518 | | - if (jaguar1->plug_state_check.state_check_wq) { |
|---|
| 519 | | - dev_info(&client->dev, "%s queue_delayed_work 1000ms", __func__); |
|---|
| 520 | | - queue_delayed_work(jaguar1->plug_state_check.state_check_wq, |
|---|
| 521 | | - &jaguar1->plug_state_check.d_work, |
|---|
| 522 | | - msecs_to_jiffies(1000)); |
|---|
| 523 | | - } |
|---|
| 524 | | - jaguar1->timestamp0 = ktime_get_ns(); |
|---|
| 525 | | -#endif |
|---|
| 526 | 458 | } else { |
|---|
| 527 | 459 | jaguar1_stop(); |
|---|
| 528 | | -#ifdef WORK_QUEUE |
|---|
| 529 | | - jaguar1->timestamp1 = ktime_get_ns(); |
|---|
| 530 | | - /* if stream off & on interval too short, do repower */ |
|---|
| 531 | | - if (div_u64((jaguar1->timestamp1 - jaguar1->timestamp0), 1000000) < 1200) { |
|---|
| 532 | | - dev_info(&client->dev, "stream on/off too short, do power off & on!"); |
|---|
| 533 | | - __jaguar1_power_off(jaguar1); |
|---|
| 534 | | - usleep_range(40000, 41000); |
|---|
| 535 | | - __jaguar1_power_on(jaguar1); |
|---|
| 536 | | - } |
|---|
| 537 | | - cancel_delayed_work_sync(&jaguar1->plug_state_check.d_work); |
|---|
| 538 | | - dev_info(&client->dev, "cancle_queue_delayed_work"); |
|---|
| 539 | | -#endif |
|---|
| 540 | 460 | } |
|---|
| 541 | 461 | |
|---|
| 542 | 462 | jaguar1->streaming = on; |
|---|
| .. | .. |
|---|
| 585 | 505 | return 0; |
|---|
| 586 | 506 | } |
|---|
| 587 | 507 | |
|---|
| 588 | | -/* indicate N4 no signal channel */ |
|---|
| 589 | | -static inline bool jaguar1_no_signal(struct v4l2_subdev *sd, u8 *novid) |
|---|
| 508 | +static int jaguar1_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, |
|---|
| 509 | + struct v4l2_mbus_config *cfg) |
|---|
| 590 | 510 | { |
|---|
| 591 | | - struct jaguar1 *jaguar1 = to_jaguar1(sd); |
|---|
| 592 | | - struct i2c_client *client = jaguar1->client; |
|---|
| 593 | | - u8 videoloss = 0; |
|---|
| 594 | | - u8 temp = 0; |
|---|
| 595 | | - int ch, ret; |
|---|
| 596 | | - bool no_signal = false; |
|---|
| 511 | + cfg->type = V4L2_MBUS_CSI2_DPHY; |
|---|
| 512 | + cfg->flags = V4L2_MBUS_CSI2_4_LANE | |
|---|
| 513 | + V4L2_MBUS_CSI2_CHANNELS; |
|---|
| 597 | 514 | |
|---|
| 598 | | - jaguar1_write(client, 0xff, 0x00); |
|---|
| 599 | | - for (ch = 0 ; ch < 4; ch++) { |
|---|
| 600 | | - ret = jaguar1_read(client, 0xa4 + ch, &temp); |
|---|
| 601 | | - if (ret < 0) |
|---|
| 602 | | - dev_err(&client->dev, "Failed to read videoloss state!\n"); |
|---|
| 603 | | - videoloss |= (temp << ch); |
|---|
| 604 | | - } |
|---|
| 605 | | - *novid = videoloss; |
|---|
| 606 | | - dev_dbg(&client->dev, "%s: video loss status:0x%x.\n", __func__, videoloss); |
|---|
| 607 | | - if (videoloss == 0xf) { |
|---|
| 608 | | - dev_dbg(&client->dev, "%s: all channels No Video detected.\n", __func__); |
|---|
| 609 | | - no_signal = true; |
|---|
| 610 | | - } else { |
|---|
| 611 | | - dev_dbg(&client->dev, "%s: channel has some video detection.\n", __func__); |
|---|
| 612 | | - no_signal = false; |
|---|
| 613 | | - } |
|---|
| 614 | | - return no_signal; |
|---|
| 615 | | -} |
|---|
| 616 | | - |
|---|
| 617 | | -/* indicate N4 channel locked status */ |
|---|
| 618 | | -static inline bool jaguar1_sync(struct v4l2_subdev *sd, u8 *lock_st) |
|---|
| 619 | | -{ |
|---|
| 620 | | - struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| 621 | | - u8 video_lock_status = 0; |
|---|
| 622 | | - u8 temp = 0; |
|---|
| 623 | | - int ch, ret; |
|---|
| 624 | | - bool has_sync = false; |
|---|
| 625 | | - |
|---|
| 626 | | - jaguar1_write(client, 0xff, 0x00); |
|---|
| 627 | | - for (ch = 0 ; ch < 4; ch++) { |
|---|
| 628 | | - ret = jaguar1_read(client, 0xd0 + ch, &temp); |
|---|
| 629 | | - if (ret < 0) |
|---|
| 630 | | - dev_err(&client->dev, "Failed to read LOCK status!\n"); |
|---|
| 631 | | - video_lock_status |= (temp << ch); |
|---|
| 632 | | - } |
|---|
| 633 | | - |
|---|
| 634 | | - dev_dbg(&client->dev, "%s: video AGC LOCK status:0x%x.\n", |
|---|
| 635 | | - __func__, video_lock_status); |
|---|
| 636 | | - *lock_st = video_lock_status; |
|---|
| 637 | | - if (video_lock_status) { |
|---|
| 638 | | - dev_dbg(&client->dev, "%s: channel has AGC LOCK.\n", __func__); |
|---|
| 639 | | - has_sync = true; |
|---|
| 640 | | - } else { |
|---|
| 641 | | - dev_dbg(&client->dev, "%s: channel has no AGC LOCK.\n", __func__); |
|---|
| 642 | | - has_sync = false; |
|---|
| 643 | | - } |
|---|
| 644 | | - return has_sync; |
|---|
| 645 | | -} |
|---|
| 646 | | - |
|---|
| 647 | | -#ifdef WORK_QUEUE |
|---|
| 648 | | -static void jaguar1_plug_state_check_work(struct work_struct *work) |
|---|
| 649 | | -{ |
|---|
| 650 | | - struct sensor_state_check_work *params_check = |
|---|
| 651 | | - container_of(work, struct sensor_state_check_work, d_work.work); |
|---|
| 652 | | - struct jaguar1 *jaguar1 = |
|---|
| 653 | | - container_of(params_check, struct jaguar1, plug_state_check); |
|---|
| 654 | | - struct i2c_client *client = jaguar1->client; |
|---|
| 655 | | - struct v4l2_subdev *sd = &jaguar1->subdev; |
|---|
| 656 | | - u8 novid_status = 0x00; |
|---|
| 657 | | - u8 sync_status = 0x00; |
|---|
| 658 | | - |
|---|
| 659 | | - down(&jaguar1->reg_sem); |
|---|
| 660 | | - jaguar1_no_signal(sd, &novid_status); |
|---|
| 661 | | - jaguar1_sync(sd, &sync_status); |
|---|
| 662 | | - up(&jaguar1->reg_sem); |
|---|
| 663 | | - jaguar1->cur_detect_status = novid_status; |
|---|
| 664 | | - |
|---|
| 665 | | - /* detect state change to determine is there has plug motion */ |
|---|
| 666 | | - novid_status = jaguar1->cur_detect_status ^ jaguar1->last_detect_status; |
|---|
| 667 | | - if (novid_status) |
|---|
| 668 | | - jaguar1->hot_plug = true; |
|---|
| 669 | | - else |
|---|
| 670 | | - jaguar1->hot_plug = false; |
|---|
| 671 | | - jaguar1->last_detect_status = jaguar1->cur_detect_status; |
|---|
| 672 | | - |
|---|
| 673 | | - if (jaguar1->hot_plug) |
|---|
| 674 | | - dev_info(&client->dev, "%s has plug motion? (%s)", __func__, |
|---|
| 675 | | - jaguar1->hot_plug ? "true" : "false"); |
|---|
| 676 | | - if (jaguar1->hot_plug) { |
|---|
| 677 | | - dev_dbg(&client->dev, "queue_delayed_work 1500ms, if has hot plug motion."); |
|---|
| 678 | | - queue_delayed_work(jaguar1->plug_state_check.state_check_wq, |
|---|
| 679 | | - &jaguar1->plug_state_check.d_work, msecs_to_jiffies(1500)); |
|---|
| 680 | | - jaguar1_write(client, 0xFF, 0x20); |
|---|
| 681 | | - jaguar1_write(client, 0x00, 0x00); |
|---|
| 682 | | - //jaguar1_write(client, 0x00, (sync_status << 4) | sync_status); |
|---|
| 683 | | - usleep_range(3000, 5000); |
|---|
| 684 | | - jaguar1_write(client, 0x00, 0xFF); |
|---|
| 685 | | - } else { |
|---|
| 686 | | - dev_dbg(&client->dev, "queue_delayed_work 100ms, if no hot plug motion."); |
|---|
| 687 | | - queue_delayed_work(jaguar1->plug_state_check.state_check_wq, |
|---|
| 688 | | - &jaguar1->plug_state_check.d_work, msecs_to_jiffies(100)); |
|---|
| 689 | | - } |
|---|
| 690 | | -} |
|---|
| 691 | | -#endif |
|---|
| 692 | | - |
|---|
| 693 | | -static int jaguar1_g_input_status(struct v4l2_subdev *sd, u32 *status) |
|---|
| 694 | | -{ |
|---|
| 695 | | - struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| 696 | | - struct jaguar1 *jaguar1 = to_jaguar1(sd); |
|---|
| 697 | | - int ret; |
|---|
| 698 | | - u8 temp_novid; |
|---|
| 699 | | - u8 temp_lock_st; |
|---|
| 700 | | - |
|---|
| 701 | | - if (!jaguar1->power_on) { |
|---|
| 702 | | - ret = __jaguar1_power_on(jaguar1); |
|---|
| 703 | | - if (ret < 0) |
|---|
| 704 | | - goto exit; |
|---|
| 705 | | - usleep_range(40000, 50000); |
|---|
| 706 | | - jaguar1->power_on = true; |
|---|
| 707 | | - } |
|---|
| 708 | | - |
|---|
| 709 | | - *status = 0; |
|---|
| 710 | | - *status |= jaguar1_no_signal(sd, &temp_novid) ? V4L2_IN_ST_NO_SIGNAL : 0; |
|---|
| 711 | | - *status |= jaguar1_sync(sd, &temp_lock_st) ? 0 : V4L2_IN_ST_NO_SYNC; |
|---|
| 712 | | - |
|---|
| 713 | | - dev_info(&client->dev, "%s: status = 0x%x\n", __func__, *status); |
|---|
| 714 | | - |
|---|
| 715 | | -exit: |
|---|
| 716 | 515 | return 0; |
|---|
| 717 | 516 | } |
|---|
| 718 | 517 | |
|---|
| 719 | | -static int jaguar1_g_mbus_config(struct v4l2_subdev *sd, |
|---|
| 720 | | - struct v4l2_mbus_config *cfg) |
|---|
| 518 | +static int jaguar1_enum_frame_interval(struct v4l2_subdev *sd, |
|---|
| 519 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 520 | + struct v4l2_subdev_frame_interval_enum *fie) |
|---|
| 721 | 521 | { |
|---|
| 722 | | - cfg->type = V4L2_MBUS_CSI2; |
|---|
| 723 | | - cfg->flags = V4L2_MBUS_CSI2_4_LANE | |
|---|
| 724 | | - V4L2_MBUS_CSI2_CHANNELS | |
|---|
| 725 | | - V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; |
|---|
| 522 | + if (fie->index >= ARRAY_SIZE(jaguar1_framesizes)) |
|---|
| 523 | + return -EINVAL; |
|---|
| 524 | + |
|---|
| 525 | + fie->code = jaguar1_formats[0].code; |
|---|
| 526 | + |
|---|
| 527 | + fie->width = jaguar1_framesizes[fie->index].width; |
|---|
| 528 | + fie->height = jaguar1_framesizes[fie->index].height; |
|---|
| 529 | + fie->interval = jaguar1_framesizes[fie->index].max_fps; |
|---|
| 726 | 530 | |
|---|
| 727 | 531 | return 0; |
|---|
| 728 | 532 | } |
|---|
| .. | .. |
|---|
| 833 | 637 | return ret; |
|---|
| 834 | 638 | } |
|---|
| 835 | 639 | |
|---|
| 640 | +static int jaguar1_g_frame_interval(struct v4l2_subdev *sd, |
|---|
| 641 | + struct v4l2_subdev_frame_interval *fi) |
|---|
| 642 | +{ |
|---|
| 643 | + struct jaguar1 *jaguar1 = to_jaguar1(sd); |
|---|
| 644 | + const struct jaguar1_framesize *size = jaguar1->frame_size; |
|---|
| 645 | + |
|---|
| 646 | + mutex_lock(&jaguar1->mutex); |
|---|
| 647 | + fi->interval = size->max_fps; |
|---|
| 648 | + mutex_unlock(&jaguar1->mutex); |
|---|
| 649 | + |
|---|
| 650 | + return 0; |
|---|
| 651 | +} |
|---|
| 652 | + |
|---|
| 836 | 653 | static void jaguar1_get_module_inf(struct jaguar1 *jaguar1, |
|---|
| 837 | 654 | struct rkmodule_inf *inf) |
|---|
| 838 | 655 | { |
|---|
| .. | .. |
|---|
| 843 | 660 | strlcpy(inf->base.lens, jaguar1->len_name, sizeof(inf->base.lens)); |
|---|
| 844 | 661 | } |
|---|
| 845 | 662 | |
|---|
| 846 | | -static void jaguar1_get_vicap_rst_inf(struct jaguar1 *jaguar1, |
|---|
| 847 | | - struct rkmodule_vicap_reset_info *rst_info) |
|---|
| 848 | | -{ |
|---|
| 849 | | - struct i2c_client *client = jaguar1->client; |
|---|
| 850 | | - |
|---|
| 851 | | - rst_info->is_reset = jaguar1->hot_plug; |
|---|
| 852 | | - jaguar1->hot_plug = false; |
|---|
| 853 | | - rst_info->src = RKCIF_RESET_SRC_ERR_HOTPLUG; |
|---|
| 854 | | - if (rst_info->is_reset) |
|---|
| 855 | | - dev_info(&client->dev, "%s: rst_info->is_reset:%d.\n", |
|---|
| 856 | | - __func__, rst_info->is_reset); |
|---|
| 857 | | -} |
|---|
| 858 | | - |
|---|
| 859 | | -static void jaguar1_set_vicap_rst_inf(struct jaguar1 *jaguar1, |
|---|
| 860 | | - struct rkmodule_vicap_reset_info rst_info) |
|---|
| 861 | | -{ |
|---|
| 862 | | - jaguar1->is_reset = rst_info.is_reset; |
|---|
| 863 | | - jaguar1->hot_plug = rst_info.is_reset; |
|---|
| 864 | | -} |
|---|
| 865 | | - |
|---|
| 866 | | -static void jaguar1_set_streaming(struct jaguar1 *jaguar1, int on) |
|---|
| 867 | | -{ |
|---|
| 868 | | - struct i2c_client *client = jaguar1->client; |
|---|
| 869 | | - |
|---|
| 870 | | - |
|---|
| 871 | | - dev_info(&client->dev, "%s: on: %d\n", __func__, on); |
|---|
| 872 | | - down(&jaguar1->reg_sem); |
|---|
| 873 | | - if (on) { |
|---|
| 874 | | - /* enter mipi clk normal operation */ |
|---|
| 875 | | - jaguar1_write(client, 0xff, 0x21); |
|---|
| 876 | | - jaguar1_write(client, 0x46, 0x00); |
|---|
| 877 | | - } else { |
|---|
| 878 | | - /* enter mipi clk powerdown */ |
|---|
| 879 | | - jaguar1_write(client, 0xff, 0x21); |
|---|
| 880 | | - jaguar1_write(client, 0x46, 0x01); |
|---|
| 881 | | - } |
|---|
| 882 | | - up(&jaguar1->reg_sem); |
|---|
| 883 | | -} |
|---|
| 884 | | - |
|---|
| 885 | 663 | static long jaguar1_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) |
|---|
| 886 | 664 | { |
|---|
| 887 | 665 | struct jaguar1 *jaguar1 = to_jaguar1(sd); |
|---|
| 888 | 666 | long ret = 0; |
|---|
| 889 | | - u32 stream = 0; |
|---|
| 890 | 667 | |
|---|
| 891 | 668 | switch (cmd) { |
|---|
| 892 | 669 | case RKMODULE_GET_MODULE_INFO: |
|---|
| 893 | 670 | jaguar1_get_module_inf(jaguar1, (struct rkmodule_inf *)arg); |
|---|
| 894 | 671 | break; |
|---|
| 895 | | - case RKMODULE_GET_VICAP_RST_INFO: |
|---|
| 896 | | - jaguar1_get_vicap_rst_inf(jaguar1, (struct rkmodule_vicap_reset_info *)arg); |
|---|
| 897 | | - break; |
|---|
| 898 | | - case RKMODULE_SET_VICAP_RST_INFO: |
|---|
| 899 | | - jaguar1_set_vicap_rst_inf(jaguar1, *(struct rkmodule_vicap_reset_info *)arg); |
|---|
| 900 | | - break; |
|---|
| 901 | 672 | case RKMODULE_GET_START_STREAM_SEQ: |
|---|
| 902 | 673 | *(int *)arg = RKMODULE_START_STREAM_FRONT; |
|---|
| 903 | | - break; |
|---|
| 904 | | - case RKMODULE_SET_QUICK_STREAM: |
|---|
| 905 | | - stream = *((u32 *)arg); |
|---|
| 906 | | - jaguar1_set_streaming(jaguar1, !!stream); |
|---|
| 907 | 674 | break; |
|---|
| 908 | 675 | default: |
|---|
| 909 | 676 | ret = -ENOTTY; |
|---|
| .. | .. |
|---|
| 920 | 687 | void __user *up = compat_ptr(arg); |
|---|
| 921 | 688 | struct rkmodule_inf *inf; |
|---|
| 922 | 689 | struct rkmodule_awb_cfg *cfg; |
|---|
| 923 | | - struct rkmodule_vicap_reset_info *vicap_rst_inf; |
|---|
| 924 | 690 | long ret; |
|---|
| 925 | 691 | int *seq; |
|---|
| 926 | | - u32 stream = 0; |
|---|
| 927 | 692 | |
|---|
| 928 | 693 | switch (cmd) { |
|---|
| 929 | 694 | case RKMODULE_GET_MODULE_INFO: |
|---|
| .. | .. |
|---|
| 955 | 720 | ret = -EFAULT; |
|---|
| 956 | 721 | kfree(cfg); |
|---|
| 957 | 722 | break; |
|---|
| 958 | | - case RKMODULE_GET_VICAP_RST_INFO: |
|---|
| 959 | | - vicap_rst_inf = kzalloc(sizeof(*vicap_rst_inf), GFP_KERNEL); |
|---|
| 960 | | - if (!vicap_rst_inf) { |
|---|
| 961 | | - ret = -ENOMEM; |
|---|
| 962 | | - return ret; |
|---|
| 963 | | - } |
|---|
| 964 | | - |
|---|
| 965 | | - ret = jaguar1_ioctl(sd, cmd, vicap_rst_inf); |
|---|
| 966 | | - if (!ret) { |
|---|
| 967 | | - ret = copy_to_user(up, vicap_rst_inf, sizeof(*vicap_rst_inf)); |
|---|
| 968 | | - if (ret) |
|---|
| 969 | | - ret = -EFAULT; |
|---|
| 970 | | - } |
|---|
| 971 | | - kfree(vicap_rst_inf); |
|---|
| 972 | | - break; |
|---|
| 973 | | - case RKMODULE_SET_VICAP_RST_INFO: |
|---|
| 974 | | - vicap_rst_inf = kzalloc(sizeof(*vicap_rst_inf), GFP_KERNEL); |
|---|
| 975 | | - if (!vicap_rst_inf) { |
|---|
| 976 | | - ret = -ENOMEM; |
|---|
| 977 | | - return ret; |
|---|
| 978 | | - } |
|---|
| 979 | | - |
|---|
| 980 | | - ret = copy_from_user(vicap_rst_inf, up, sizeof(*vicap_rst_inf)); |
|---|
| 981 | | - if (!ret) |
|---|
| 982 | | - ret = jaguar1_ioctl(sd, cmd, vicap_rst_inf); |
|---|
| 983 | | - else |
|---|
| 984 | | - ret = -EFAULT; |
|---|
| 985 | | - kfree(vicap_rst_inf); |
|---|
| 986 | | - break; |
|---|
| 987 | 723 | case RKMODULE_GET_START_STREAM_SEQ: |
|---|
| 988 | 724 | seq = kzalloc(sizeof(*seq), GFP_KERNEL); |
|---|
| 989 | 725 | if (!seq) { |
|---|
| .. | .. |
|---|
| 998 | 734 | ret = -EFAULT; |
|---|
| 999 | 735 | } |
|---|
| 1000 | 736 | kfree(seq); |
|---|
| 1001 | | - break; |
|---|
| 1002 | | - case RKMODULE_SET_QUICK_STREAM: |
|---|
| 1003 | | - ret = copy_from_user(&stream, up, sizeof(u32)); |
|---|
| 1004 | | - if (!ret) |
|---|
| 1005 | | - ret = jaguar1_ioctl(sd, cmd, &stream); |
|---|
| 1006 | | - else |
|---|
| 1007 | | - ret = -EFAULT; |
|---|
| 1008 | 737 | break; |
|---|
| 1009 | 738 | default: |
|---|
| 1010 | 739 | ret = -ENOIOCTLCMD; |
|---|
| .. | .. |
|---|
| 1041 | 770 | }; |
|---|
| 1042 | 771 | |
|---|
| 1043 | 772 | static const struct v4l2_subdev_video_ops jaguar1_video_ops = { |
|---|
| 1044 | | - .g_input_status = jaguar1_g_input_status, |
|---|
| 1045 | 773 | .s_stream = jaguar1_stream, |
|---|
| 1046 | | - .g_mbus_config = jaguar1_g_mbus_config, |
|---|
| 774 | + .g_frame_interval = jaguar1_g_frame_interval, |
|---|
| 1047 | 775 | }; |
|---|
| 1048 | 776 | |
|---|
| 1049 | 777 | static const struct v4l2_subdev_pad_ops jaguar1_subdev_pad_ops = { |
|---|
| 1050 | 778 | .enum_mbus_code = jaguar1_enum_mbus_code, |
|---|
| 1051 | 779 | .enum_frame_size = jaguar1_enum_frame_sizes, |
|---|
| 780 | + .enum_frame_interval = jaguar1_enum_frame_interval, |
|---|
| 1052 | 781 | .get_fmt = jaguar1_get_fmt, |
|---|
| 1053 | 782 | .set_fmt = jaguar1_set_fmt, |
|---|
| 783 | + .get_mbus_config = jaguar1_g_mbus_config, |
|---|
| 1054 | 784 | }; |
|---|
| 1055 | 785 | |
|---|
| 1056 | 786 | static const struct v4l2_subdev_core_ops jaguar1_core_ops = { |
|---|
| .. | .. |
|---|
| 1248 | 978 | sd = &jaguar1->subdev; |
|---|
| 1249 | 979 | v4l2_i2c_subdev_init(sd, client, &jaguar1_subdev_ops); |
|---|
| 1250 | 980 | ret = jaguar1_initialize_controls(jaguar1); |
|---|
| 981 | + if (ret) { |
|---|
| 982 | + dev_err(dev, "Failed to initialize controls jaguar1\n"); |
|---|
| 983 | + return ret; |
|---|
| 984 | + } |
|---|
| 1251 | 985 | |
|---|
| 1252 | 986 | __jaguar1_power_on(jaguar1); |
|---|
| 1253 | | - ret |= jaguar1_init(i2c_adapter_id(client->adapter)); |
|---|
| 987 | + ret = jaguar1_init(i2c_adapter_id(client->adapter)); |
|---|
| 1254 | 988 | if (ret) { |
|---|
| 1255 | 989 | dev_err(dev, "Failed to init jaguar1\n"); |
|---|
| 1256 | 990 | __jaguar1_power_off(jaguar1); |
|---|
| .. | .. |
|---|
| 1258 | 992 | |
|---|
| 1259 | 993 | return ret; |
|---|
| 1260 | 994 | } |
|---|
| 1261 | | - sema_init(&jaguar1->reg_sem, 1); |
|---|
| 995 | + |
|---|
| 1262 | 996 | #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API |
|---|
| 1263 | 997 | sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
|---|
| 1264 | 998 | #endif |
|---|
| .. | .. |
|---|
| 1298 | 1032 | pm_runtime_enable(dev); |
|---|
| 1299 | 1033 | pm_runtime_idle(dev); |
|---|
| 1300 | 1034 | |
|---|
| 1301 | | -#ifdef WORK_QUEUE |
|---|
| 1302 | | - /* init work_queue for state_check */ |
|---|
| 1303 | | - INIT_DELAYED_WORK(&jaguar1->plug_state_check.d_work, jaguar1_plug_state_check_work); |
|---|
| 1304 | | - jaguar1->plug_state_check.state_check_wq = |
|---|
| 1305 | | - create_singlethread_workqueue("jaguar1_work_queue"); |
|---|
| 1306 | | - if (jaguar1->plug_state_check.state_check_wq == NULL) { |
|---|
| 1307 | | - dev_err(dev, "%s(%d): %s create failed.\n", __func__, __LINE__, |
|---|
| 1308 | | - "jaguar1_work_queue"); |
|---|
| 1309 | | - } |
|---|
| 1310 | | - jaguar1->cur_detect_status = 0x0; |
|---|
| 1311 | | - jaguar1->last_detect_status = 0x0; |
|---|
| 1312 | | - jaguar1->hot_plug = false; |
|---|
| 1313 | | - jaguar1->is_reset = 0; |
|---|
| 1314 | | - |
|---|
| 1315 | | -#endif |
|---|
| 1316 | | - |
|---|
| 1035 | + v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, |
|---|
| 1036 | + client->addr << 1, client->adapter->name); |
|---|
| 1317 | 1037 | return 0; |
|---|
| 1318 | 1038 | |
|---|
| 1319 | 1039 | err_power_off: |
|---|
| .. | .. |
|---|
| 1340 | 1060 | if (!pm_runtime_status_suspended(&client->dev)) |
|---|
| 1341 | 1061 | __jaguar1_power_off(jaguar1); |
|---|
| 1342 | 1062 | pm_runtime_set_suspended(&client->dev); |
|---|
| 1343 | | -#ifdef WORK_QUEUE |
|---|
| 1344 | | - if (jaguar1->plug_state_check.state_check_wq != NULL) |
|---|
| 1345 | | - destroy_workqueue(jaguar1->plug_state_check.state_check_wq); |
|---|
| 1346 | | -#endif |
|---|
| 1063 | + |
|---|
| 1347 | 1064 | return 0; |
|---|
| 1348 | 1065 | } |
|---|
| 1349 | 1066 | |
|---|
| .. | .. |
|---|
| 1371 | 1088 | .id_table = jaguar1_match_id, |
|---|
| 1372 | 1089 | }; |
|---|
| 1373 | 1090 | |
|---|
| 1374 | | -static int __init sensor_mod_init(void) |
|---|
| 1091 | +int nvp6324_sensor_mod_init(void) |
|---|
| 1375 | 1092 | { |
|---|
| 1376 | 1093 | return i2c_add_driver(&jaguar1_i2c_driver); |
|---|
| 1377 | 1094 | } |
|---|
| 1095 | + |
|---|
| 1096 | +#ifndef CONFIG_VIDEO_REVERSE_IMAGE |
|---|
| 1097 | +device_initcall_sync(nvp6324_sensor_mod_init); |
|---|
| 1098 | +#endif |
|---|
| 1378 | 1099 | |
|---|
| 1379 | 1100 | static void __exit sensor_mod_exit(void) |
|---|
| 1380 | 1101 | { |
|---|
| 1381 | 1102 | i2c_del_driver(&jaguar1_i2c_driver); |
|---|
| 1382 | 1103 | } |
|---|
| 1383 | 1104 | |
|---|
| 1384 | | -device_initcall_sync(sensor_mod_init); |
|---|
| 1385 | 1105 | module_exit(sensor_mod_exit); |
|---|
| 1386 | 1106 | |
|---|
| 1387 | 1107 | MODULE_DESCRIPTION("jaguar1 sensor driver"); |
|---|