diff options
Diffstat (limited to 'drivers/media/video/rj54n1cb0c.c')
| -rw-r--r-- | drivers/media/video/rj54n1cb0c.c | 474 |
1 files changed, 378 insertions, 96 deletions
diff --git a/drivers/media/video/rj54n1cb0c.c b/drivers/media/video/rj54n1cb0c.c index 373f2a30a677..7e42989ce0e4 100644 --- a/drivers/media/video/rj54n1cb0c.c +++ b/drivers/media/video/rj54n1cb0c.c | |||
| @@ -13,9 +13,11 @@ | |||
| 13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
| 14 | #include <linux/videodev2.h> | 14 | #include <linux/videodev2.h> |
| 15 | 15 | ||
| 16 | #include <media/rj54n1cb0c.h> | ||
| 17 | #include <media/soc_camera.h> | ||
| 18 | #include <media/soc_mediabus.h> | ||
| 16 | #include <media/v4l2-subdev.h> | 19 | #include <media/v4l2-subdev.h> |
| 17 | #include <media/v4l2-chip-ident.h> | 20 | #include <media/v4l2-chip-ident.h> |
| 18 | #include <media/soc_camera.h> | ||
| 19 | 21 | ||
| 20 | #define RJ54N1_DEV_CODE 0x0400 | 22 | #define RJ54N1_DEV_CODE 0x0400 |
| 21 | #define RJ54N1_DEV_CODE2 0x0401 | 23 | #define RJ54N1_DEV_CODE2 0x0401 |
| @@ -38,6 +40,7 @@ | |||
| 38 | #define RJ54N1_H_OBEN_OFS 0x0413 | 40 | #define RJ54N1_H_OBEN_OFS 0x0413 |
| 39 | #define RJ54N1_V_OBEN_OFS 0x0414 | 41 | #define RJ54N1_V_OBEN_OFS 0x0414 |
| 40 | #define RJ54N1_RESIZE_CONTROL 0x0415 | 42 | #define RJ54N1_RESIZE_CONTROL 0x0415 |
| 43 | #define RJ54N1_STILL_CONTROL 0x0417 | ||
| 41 | #define RJ54N1_INC_USE_SEL_H 0x0425 | 44 | #define RJ54N1_INC_USE_SEL_H 0x0425 |
| 42 | #define RJ54N1_INC_USE_SEL_L 0x0426 | 45 | #define RJ54N1_INC_USE_SEL_L 0x0426 |
| 43 | #define RJ54N1_MIRROR_STILL_MODE 0x0427 | 46 | #define RJ54N1_MIRROR_STILL_MODE 0x0427 |
| @@ -49,10 +52,21 @@ | |||
| 49 | #define RJ54N1_RA_SEL_UL 0x0530 | 52 | #define RJ54N1_RA_SEL_UL 0x0530 |
| 50 | #define RJ54N1_BYTE_SWAP 0x0531 | 53 | #define RJ54N1_BYTE_SWAP 0x0531 |
| 51 | #define RJ54N1_OUT_SIGPO 0x053b | 54 | #define RJ54N1_OUT_SIGPO 0x053b |
| 55 | #define RJ54N1_WB_SEL_WEIGHT_I 0x054e | ||
| 56 | #define RJ54N1_BIT8_WB 0x0569 | ||
| 57 | #define RJ54N1_HCAPS_WB 0x056a | ||
| 58 | #define RJ54N1_VCAPS_WB 0x056b | ||
| 59 | #define RJ54N1_HCAPE_WB 0x056c | ||
| 60 | #define RJ54N1_VCAPE_WB 0x056d | ||
| 61 | #define RJ54N1_EXPOSURE_CONTROL 0x058c | ||
| 52 | #define RJ54N1_FRAME_LENGTH_S_H 0x0595 | 62 | #define RJ54N1_FRAME_LENGTH_S_H 0x0595 |
| 53 | #define RJ54N1_FRAME_LENGTH_S_L 0x0596 | 63 | #define RJ54N1_FRAME_LENGTH_S_L 0x0596 |
| 54 | #define RJ54N1_FRAME_LENGTH_P_H 0x0597 | 64 | #define RJ54N1_FRAME_LENGTH_P_H 0x0597 |
| 55 | #define RJ54N1_FRAME_LENGTH_P_L 0x0598 | 65 | #define RJ54N1_FRAME_LENGTH_P_L 0x0598 |
| 66 | #define RJ54N1_PEAK_H 0x05b7 | ||
| 67 | #define RJ54N1_PEAK_50 0x05b8 | ||
| 68 | #define RJ54N1_PEAK_60 0x05b9 | ||
| 69 | #define RJ54N1_PEAK_DIFF 0x05ba | ||
| 56 | #define RJ54N1_IOC 0x05ef | 70 | #define RJ54N1_IOC 0x05ef |
| 57 | #define RJ54N1_TG_BYPASS 0x0700 | 71 | #define RJ54N1_TG_BYPASS 0x0700 |
| 58 | #define RJ54N1_PLL_L 0x0701 | 72 | #define RJ54N1_PLL_L 0x0701 |
| @@ -68,6 +82,7 @@ | |||
| 68 | #define RJ54N1_OCLK_SEL_EN 0x0713 | 82 | #define RJ54N1_OCLK_SEL_EN 0x0713 |
| 69 | #define RJ54N1_CLK_RST 0x0717 | 83 | #define RJ54N1_CLK_RST 0x0717 |
| 70 | #define RJ54N1_RESET_STANDBY 0x0718 | 84 | #define RJ54N1_RESET_STANDBY 0x0718 |
| 85 | #define RJ54N1_FWFLG 0x07fe | ||
| 71 | 86 | ||
| 72 | #define E_EXCLK (1 << 7) | 87 | #define E_EXCLK (1 << 7) |
| 73 | #define SOFT_STDBY (1 << 4) | 88 | #define SOFT_STDBY (1 << 4) |
| @@ -78,29 +93,53 @@ | |||
| 78 | #define RESIZE_HOLD_SEL (1 << 2) | 93 | #define RESIZE_HOLD_SEL (1 << 2) |
| 79 | #define RESIZE_GO (1 << 1) | 94 | #define RESIZE_GO (1 << 1) |
| 80 | 95 | ||
| 96 | /* | ||
| 97 | * When cropping, the camera automatically centers the cropped region, there | ||
| 98 | * doesn't seem to be a way to specify an explicit location of the rectangle. | ||
| 99 | */ | ||
| 81 | #define RJ54N1_COLUMN_SKIP 0 | 100 | #define RJ54N1_COLUMN_SKIP 0 |
| 82 | #define RJ54N1_ROW_SKIP 0 | 101 | #define RJ54N1_ROW_SKIP 0 |
| 83 | #define RJ54N1_MAX_WIDTH 1600 | 102 | #define RJ54N1_MAX_WIDTH 1600 |
| 84 | #define RJ54N1_MAX_HEIGHT 1200 | 103 | #define RJ54N1_MAX_HEIGHT 1200 |
| 85 | 104 | ||
| 105 | #define PLL_L 2 | ||
| 106 | #define PLL_N 0x31 | ||
| 107 | |||
| 86 | /* I2C addresses: 0x50, 0x51, 0x60, 0x61 */ | 108 | /* I2C addresses: 0x50, 0x51, 0x60, 0x61 */ |
| 87 | 109 | ||
| 88 | static const struct soc_camera_data_format rj54n1_colour_formats[] = { | 110 | /* RJ54N1CB0C has only one fixed colorspace per pixelcode */ |
| 89 | { | 111 | struct rj54n1_datafmt { |
| 90 | .name = "YUYV", | 112 | enum v4l2_mbus_pixelcode code; |
| 91 | .depth = 16, | 113 | enum v4l2_colorspace colorspace; |
| 92 | .fourcc = V4L2_PIX_FMT_YUYV, | 114 | }; |
| 93 | .colorspace = V4L2_COLORSPACE_JPEG, | 115 | |
| 94 | }, { | 116 | /* Find a data format by a pixel code in an array */ |
| 95 | .name = "RGB565", | 117 | static const struct rj54n1_datafmt *rj54n1_find_datafmt( |
| 96 | .depth = 16, | 118 | enum v4l2_mbus_pixelcode code, const struct rj54n1_datafmt *fmt, |
| 97 | .fourcc = V4L2_PIX_FMT_RGB565, | 119 | int n) |
| 98 | .colorspace = V4L2_COLORSPACE_SRGB, | 120 | { |
| 99 | } | 121 | int i; |
| 122 | for (i = 0; i < n; i++) | ||
| 123 | if (fmt[i].code == code) | ||
| 124 | return fmt + i; | ||
| 125 | |||
| 126 | return NULL; | ||
| 127 | } | ||
| 128 | |||
| 129 | static const struct rj54n1_datafmt rj54n1_colour_fmts[] = { | ||
| 130 | {V4L2_MBUS_FMT_YUYV8_2X8_LE, V4L2_COLORSPACE_JPEG}, | ||
| 131 | {V4L2_MBUS_FMT_YVYU8_2X8_LE, V4L2_COLORSPACE_JPEG}, | ||
| 132 | {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB}, | ||
| 133 | {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB}, | ||
| 134 | {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB}, | ||
| 135 | {V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE, V4L2_COLORSPACE_SRGB}, | ||
| 136 | {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE, V4L2_COLORSPACE_SRGB}, | ||
| 137 | {V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE, V4L2_COLORSPACE_SRGB}, | ||
| 138 | {V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_COLORSPACE_SRGB}, | ||
| 100 | }; | 139 | }; |
| 101 | 140 | ||
| 102 | struct rj54n1_clock_div { | 141 | struct rj54n1_clock_div { |
| 103 | u8 ratio_tg; | 142 | u8 ratio_tg; /* can be 0 or an odd number */ |
| 104 | u8 ratio_t; | 143 | u8 ratio_t; |
| 105 | u8 ratio_r; | 144 | u8 ratio_r; |
| 106 | u8 ratio_op; | 145 | u8 ratio_op; |
| @@ -109,12 +148,14 @@ struct rj54n1_clock_div { | |||
| 109 | 148 | ||
| 110 | struct rj54n1 { | 149 | struct rj54n1 { |
| 111 | struct v4l2_subdev subdev; | 150 | struct v4l2_subdev subdev; |
| 151 | struct rj54n1_clock_div clk_div; | ||
| 152 | const struct rj54n1_datafmt *fmt; | ||
| 112 | struct v4l2_rect rect; /* Sensor window */ | 153 | struct v4l2_rect rect; /* Sensor window */ |
| 154 | unsigned int tgclk_mhz; | ||
| 155 | bool auto_wb; | ||
| 113 | unsigned short width; /* Output window */ | 156 | unsigned short width; /* Output window */ |
| 114 | unsigned short height; | 157 | unsigned short height; |
| 115 | unsigned short resize; /* Sensor * 1024 / resize = Output */ | 158 | unsigned short resize; /* Sensor * 1024 / resize = Output */ |
| 116 | struct rj54n1_clock_div clk_div; | ||
| 117 | u32 fourcc; | ||
| 118 | unsigned short scale; | 159 | unsigned short scale; |
| 119 | u8 bank; | 160 | u8 bank; |
| 120 | }; | 161 | }; |
| @@ -171,7 +212,7 @@ const static struct rj54n1_reg_val bank_7[] = { | |||
| 171 | {0x714, 0xff}, | 212 | {0x714, 0xff}, |
| 172 | {0x715, 0xff}, | 213 | {0x715, 0xff}, |
| 173 | {0x716, 0x1f}, | 214 | {0x716, 0x1f}, |
| 174 | {0x7FE, 0x02}, | 215 | {0x7FE, 2}, |
| 175 | }; | 216 | }; |
| 176 | 217 | ||
| 177 | const static struct rj54n1_reg_val bank_8[] = { | 218 | const static struct rj54n1_reg_val bank_8[] = { |
| @@ -359,7 +400,7 @@ const static struct rj54n1_reg_val bank_8[] = { | |||
| 359 | {0x8BB, 0x00}, | 400 | {0x8BB, 0x00}, |
| 360 | {0x8BC, 0xFF}, | 401 | {0x8BC, 0xFF}, |
| 361 | {0x8BD, 0x00}, | 402 | {0x8BD, 0x00}, |
| 362 | {0x8FE, 0x02}, | 403 | {0x8FE, 2}, |
| 363 | }; | 404 | }; |
| 364 | 405 | ||
| 365 | const static struct rj54n1_reg_val bank_10[] = { | 406 | const static struct rj54n1_reg_val bank_10[] = { |
| @@ -440,12 +481,24 @@ static int reg_write_multiple(struct i2c_client *client, | |||
| 440 | return 0; | 481 | return 0; |
| 441 | } | 482 | } |
| 442 | 483 | ||
| 443 | static int rj54n1_s_stream(struct v4l2_subdev *sd, int enable) | 484 | static int rj54n1_enum_fmt(struct v4l2_subdev *sd, int index, |
| 485 | enum v4l2_mbus_pixelcode *code) | ||
| 444 | { | 486 | { |
| 445 | /* TODO: start / stop streaming */ | 487 | if ((unsigned int)index >= ARRAY_SIZE(rj54n1_colour_fmts)) |
| 488 | return -EINVAL; | ||
| 489 | |||
| 490 | *code = rj54n1_colour_fmts[index].code; | ||
| 446 | return 0; | 491 | return 0; |
| 447 | } | 492 | } |
| 448 | 493 | ||
| 494 | static int rj54n1_s_stream(struct v4l2_subdev *sd, int enable) | ||
| 495 | { | ||
| 496 | struct i2c_client *client = sd->priv; | ||
| 497 | |||
| 498 | /* Switch between preview and still shot modes */ | ||
| 499 | return reg_set(client, RJ54N1_STILL_CONTROL, (!enable) << 7, 0x80); | ||
| 500 | } | ||
| 501 | |||
| 449 | static int rj54n1_set_bus_param(struct soc_camera_device *icd, | 502 | static int rj54n1_set_bus_param(struct soc_camera_device *icd, |
| 450 | unsigned long flags) | 503 | unsigned long flags) |
| 451 | { | 504 | { |
| @@ -502,6 +555,44 @@ static int rj54n1_commit(struct i2c_client *client) | |||
| 502 | return ret; | 555 | return ret; |
| 503 | } | 556 | } |
| 504 | 557 | ||
| 558 | static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | ||
| 559 | u32 *out_w, u32 *out_h); | ||
| 560 | |||
| 561 | static int rj54n1_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) | ||
| 562 | { | ||
| 563 | struct i2c_client *client = sd->priv; | ||
| 564 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 565 | struct v4l2_rect *rect = &a->c; | ||
| 566 | unsigned int dummy, output_w, output_h, | ||
| 567 | input_w = rect->width, input_h = rect->height; | ||
| 568 | int ret; | ||
| 569 | |||
| 570 | /* arbitrary minimum width and height, edges unimportant */ | ||
| 571 | soc_camera_limit_side(&dummy, &input_w, | ||
| 572 | RJ54N1_COLUMN_SKIP, 8, RJ54N1_MAX_WIDTH); | ||
| 573 | |||
| 574 | soc_camera_limit_side(&dummy, &input_h, | ||
| 575 | RJ54N1_ROW_SKIP, 8, RJ54N1_MAX_HEIGHT); | ||
| 576 | |||
| 577 | output_w = (input_w * 1024 + rj54n1->resize / 2) / rj54n1->resize; | ||
| 578 | output_h = (input_h * 1024 + rj54n1->resize / 2) / rj54n1->resize; | ||
| 579 | |||
| 580 | dev_dbg(&client->dev, "Scaling for %ux%u : %u = %ux%u\n", | ||
| 581 | input_w, input_h, rj54n1->resize, output_w, output_h); | ||
| 582 | |||
| 583 | ret = rj54n1_sensor_scale(sd, &input_w, &input_h, &output_w, &output_h); | ||
| 584 | if (ret < 0) | ||
| 585 | return ret; | ||
| 586 | |||
| 587 | rj54n1->width = output_w; | ||
| 588 | rj54n1->height = output_h; | ||
| 589 | rj54n1->resize = ret; | ||
| 590 | rj54n1->rect.width = input_w; | ||
| 591 | rj54n1->rect.height = input_h; | ||
| 592 | |||
| 593 | return 0; | ||
| 594 | } | ||
| 595 | |||
| 505 | static int rj54n1_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) | 596 | static int rj54n1_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
| 506 | { | 597 | { |
| 507 | struct i2c_client *client = sd->priv; | 598 | struct i2c_client *client = sd->priv; |
| @@ -527,16 +618,17 @@ static int rj54n1_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) | |||
| 527 | return 0; | 618 | return 0; |
| 528 | } | 619 | } |
| 529 | 620 | ||
| 530 | static int rj54n1_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) | 621 | static int rj54n1_g_fmt(struct v4l2_subdev *sd, |
| 622 | struct v4l2_mbus_framefmt *mf) | ||
| 531 | { | 623 | { |
| 532 | struct i2c_client *client = sd->priv; | 624 | struct i2c_client *client = sd->priv; |
| 533 | struct rj54n1 *rj54n1 = to_rj54n1(client); | 625 | struct rj54n1 *rj54n1 = to_rj54n1(client); |
| 534 | struct v4l2_pix_format *pix = &f->fmt.pix; | ||
| 535 | 626 | ||
| 536 | pix->pixelformat = rj54n1->fourcc; | 627 | mf->code = rj54n1->fmt->code; |
| 537 | pix->field = V4L2_FIELD_NONE; | 628 | mf->colorspace = rj54n1->fmt->colorspace; |
| 538 | pix->width = rj54n1->width; | 629 | mf->field = V4L2_FIELD_NONE; |
| 539 | pix->height = rj54n1->height; | 630 | mf->width = rj54n1->width; |
| 631 | mf->height = rj54n1->height; | ||
| 540 | 632 | ||
| 541 | return 0; | 633 | return 0; |
| 542 | } | 634 | } |
| @@ -550,11 +642,44 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 550 | u32 *out_w, u32 *out_h) | 642 | u32 *out_w, u32 *out_h) |
| 551 | { | 643 | { |
| 552 | struct i2c_client *client = sd->priv; | 644 | struct i2c_client *client = sd->priv; |
| 645 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 553 | unsigned int skip, resize, input_w = *in_w, input_h = *in_h, | 646 | unsigned int skip, resize, input_w = *in_w, input_h = *in_h, |
| 554 | output_w = *out_w, output_h = *out_h; | 647 | output_w = *out_w, output_h = *out_h; |
| 555 | u16 inc_sel; | 648 | u16 inc_sel, wb_bit8, wb_left, wb_right, wb_top, wb_bottom; |
| 649 | unsigned int peak, peak_50, peak_60; | ||
| 556 | int ret; | 650 | int ret; |
| 557 | 651 | ||
| 652 | /* | ||
| 653 | * We have a problem with crops, where the window is larger than 512x384 | ||
| 654 | * and output window is larger than a half of the input one. In this | ||
| 655 | * case we have to either reduce the input window to equal or below | ||
| 656 | * 512x384 or the output window to equal or below 1/2 of the input. | ||
| 657 | */ | ||
| 658 | if (output_w > max(512U, input_w / 2)) { | ||
| 659 | if (2 * output_w > RJ54N1_MAX_WIDTH) { | ||
| 660 | input_w = RJ54N1_MAX_WIDTH; | ||
| 661 | output_w = RJ54N1_MAX_WIDTH / 2; | ||
| 662 | } else { | ||
| 663 | input_w = output_w * 2; | ||
| 664 | } | ||
| 665 | |||
| 666 | dev_dbg(&client->dev, "Adjusted output width: in %u, out %u\n", | ||
| 667 | input_w, output_w); | ||
| 668 | } | ||
| 669 | |||
| 670 | if (output_h > max(384U, input_h / 2)) { | ||
| 671 | if (2 * output_h > RJ54N1_MAX_HEIGHT) { | ||
| 672 | input_h = RJ54N1_MAX_HEIGHT; | ||
| 673 | output_h = RJ54N1_MAX_HEIGHT / 2; | ||
| 674 | } else { | ||
| 675 | input_h = output_h * 2; | ||
| 676 | } | ||
| 677 | |||
| 678 | dev_dbg(&client->dev, "Adjusted output height: in %u, out %u\n", | ||
| 679 | input_h, output_h); | ||
| 680 | } | ||
| 681 | |||
| 682 | /* Idea: use the read mode for snapshots, handle separate geometries */ | ||
| 558 | ret = rj54n1_set_rect(client, RJ54N1_X_OUTPUT_SIZE_S_L, | 683 | ret = rj54n1_set_rect(client, RJ54N1_X_OUTPUT_SIZE_S_L, |
| 559 | RJ54N1_Y_OUTPUT_SIZE_S_L, | 684 | RJ54N1_Y_OUTPUT_SIZE_S_L, |
| 560 | RJ54N1_XY_OUTPUT_SIZE_S_H, output_w, output_h); | 685 | RJ54N1_XY_OUTPUT_SIZE_S_H, output_w, output_h); |
| @@ -566,17 +691,27 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 566 | if (ret < 0) | 691 | if (ret < 0) |
| 567 | return ret; | 692 | return ret; |
| 568 | 693 | ||
| 569 | if (output_w > input_w || output_h > input_h) { | 694 | if (output_w > input_w && output_h > input_h) { |
| 570 | input_w = output_w; | 695 | input_w = output_w; |
| 571 | input_h = output_h; | 696 | input_h = output_h; |
| 572 | 697 | ||
| 573 | resize = 1024; | 698 | resize = 1024; |
| 574 | } else { | 699 | } else { |
| 575 | unsigned int resize_x, resize_y; | 700 | unsigned int resize_x, resize_y; |
| 576 | resize_x = input_w * 1024 / output_w; | 701 | resize_x = (input_w * 1024 + output_w / 2) / output_w; |
| 577 | resize_y = input_h * 1024 / output_h; | 702 | resize_y = (input_h * 1024 + output_h / 2) / output_h; |
| 578 | 703 | ||
| 579 | resize = min(resize_x, resize_y); | 704 | /* We want max(resize_x, resize_y), check if it still fits */ |
| 705 | if (resize_x > resize_y && | ||
| 706 | (output_h * resize_x + 512) / 1024 > RJ54N1_MAX_HEIGHT) | ||
| 707 | resize = (RJ54N1_MAX_HEIGHT * 1024 + output_h / 2) / | ||
| 708 | output_h; | ||
| 709 | else if (resize_y > resize_x && | ||
| 710 | (output_w * resize_y + 512) / 1024 > RJ54N1_MAX_WIDTH) | ||
| 711 | resize = (RJ54N1_MAX_WIDTH * 1024 + output_w / 2) / | ||
| 712 | output_w; | ||
| 713 | else | ||
| 714 | resize = max(resize_x, resize_y); | ||
| 580 | 715 | ||
| 581 | /* Prohibited value ranges */ | 716 | /* Prohibited value ranges */ |
| 582 | switch (resize) { | 717 | switch (resize) { |
| @@ -589,12 +724,9 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 589 | case 8160 ... 8191: | 724 | case 8160 ... 8191: |
| 590 | resize = 8159; | 725 | resize = 8159; |
| 591 | break; | 726 | break; |
| 592 | case 16320 ... 16383: | 727 | case 16320 ... 16384: |
| 593 | resize = 16319; | 728 | resize = 16319; |
| 594 | } | 729 | } |
| 595 | |||
| 596 | input_w = output_w * resize / 1024; | ||
| 597 | input_h = output_h * resize / 1024; | ||
| 598 | } | 730 | } |
| 599 | 731 | ||
| 600 | /* Set scaling */ | 732 | /* Set scaling */ |
| @@ -607,9 +739,18 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 607 | 739 | ||
| 608 | /* | 740 | /* |
| 609 | * Configure a skipping bitmask. The sensor will select a skipping value | 741 | * Configure a skipping bitmask. The sensor will select a skipping value |
| 610 | * among set bits automatically. | 742 | * among set bits automatically. This is very unclear in the datasheet |
| 743 | * too. I was told, in this register one enables all skipping values, | ||
| 744 | * that are required for a specific resize, and the camera selects | ||
| 745 | * automatically, which ones to use. But it is unclear how to identify, | ||
| 746 | * which cropping values are needed. Secondly, why don't we just set all | ||
| 747 | * bits and let the camera choose? Would it increase processing time and | ||
| 748 | * reduce the framerate? Using 0xfffc for INC_USE_SEL doesn't seem to | ||
| 749 | * improve the image quality or stability for larger frames (see comment | ||
| 750 | * above), but I didn't check the framerate. | ||
| 611 | */ | 751 | */ |
| 612 | skip = min(resize / 1024, (unsigned)15); | 752 | skip = min(resize / 1024, (unsigned)15); |
| 753 | |||
| 613 | inc_sel = 1 << skip; | 754 | inc_sel = 1 << skip; |
| 614 | 755 | ||
| 615 | if (inc_sel <= 2) | 756 | if (inc_sel <= 2) |
| @@ -621,6 +762,43 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 621 | if (!ret) | 762 | if (!ret) |
| 622 | ret = reg_write(client, RJ54N1_INC_USE_SEL_H, inc_sel >> 8); | 763 | ret = reg_write(client, RJ54N1_INC_USE_SEL_H, inc_sel >> 8); |
| 623 | 764 | ||
| 765 | if (!rj54n1->auto_wb) { | ||
| 766 | /* Auto white balance window */ | ||
| 767 | wb_left = output_w / 16; | ||
| 768 | wb_right = (3 * output_w / 4 - 3) / 4; | ||
| 769 | wb_top = output_h / 16; | ||
| 770 | wb_bottom = (3 * output_h / 4 - 3) / 4; | ||
| 771 | wb_bit8 = ((wb_left >> 2) & 0x40) | ((wb_top >> 4) & 0x10) | | ||
| 772 | ((wb_right >> 6) & 4) | ((wb_bottom >> 8) & 1); | ||
| 773 | |||
| 774 | if (!ret) | ||
| 775 | ret = reg_write(client, RJ54N1_BIT8_WB, wb_bit8); | ||
| 776 | if (!ret) | ||
| 777 | ret = reg_write(client, RJ54N1_HCAPS_WB, wb_left); | ||
| 778 | if (!ret) | ||
| 779 | ret = reg_write(client, RJ54N1_VCAPS_WB, wb_top); | ||
| 780 | if (!ret) | ||
| 781 | ret = reg_write(client, RJ54N1_HCAPE_WB, wb_right); | ||
| 782 | if (!ret) | ||
| 783 | ret = reg_write(client, RJ54N1_VCAPE_WB, wb_bottom); | ||
| 784 | } | ||
| 785 | |||
| 786 | /* Antiflicker */ | ||
| 787 | peak = 12 * RJ54N1_MAX_WIDTH * (1 << 14) * resize / rj54n1->tgclk_mhz / | ||
| 788 | 10000; | ||
| 789 | peak_50 = peak / 6; | ||
| 790 | peak_60 = peak / 5; | ||
| 791 | |||
| 792 | if (!ret) | ||
| 793 | ret = reg_write(client, RJ54N1_PEAK_H, | ||
| 794 | ((peak_50 >> 4) & 0xf0) | (peak_60 >> 8)); | ||
| 795 | if (!ret) | ||
| 796 | ret = reg_write(client, RJ54N1_PEAK_50, peak_50); | ||
| 797 | if (!ret) | ||
| 798 | ret = reg_write(client, RJ54N1_PEAK_60, peak_60); | ||
| 799 | if (!ret) | ||
| 800 | ret = reg_write(client, RJ54N1_PEAK_DIFF, peak / 150); | ||
| 801 | |||
| 624 | /* Start resizing */ | 802 | /* Start resizing */ |
| 625 | if (!ret) | 803 | if (!ret) |
| 626 | ret = reg_write(client, RJ54N1_RESIZE_CONTROL, | 804 | ret = reg_write(client, RJ54N1_RESIZE_CONTROL, |
| @@ -629,8 +807,6 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 629 | if (ret < 0) | 807 | if (ret < 0) |
| 630 | return ret; | 808 | return ret; |
| 631 | 809 | ||
| 632 | dev_dbg(&client->dev, "resize %u, skip %u\n", resize, skip); | ||
| 633 | |||
| 634 | /* Constant taken from manufacturer's example */ | 810 | /* Constant taken from manufacturer's example */ |
| 635 | msleep(230); | 811 | msleep(230); |
| 636 | 812 | ||
| @@ -638,11 +814,14 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h, | |||
| 638 | if (ret < 0) | 814 | if (ret < 0) |
| 639 | return ret; | 815 | return ret; |
| 640 | 816 | ||
| 641 | *in_w = input_w; | 817 | *in_w = (output_w * resize + 512) / 1024; |
| 642 | *in_h = input_h; | 818 | *in_h = (output_h * resize + 512) / 1024; |
| 643 | *out_w = output_w; | 819 | *out_w = output_w; |
| 644 | *out_h = output_h; | 820 | *out_h = output_h; |
| 645 | 821 | ||
| 822 | dev_dbg(&client->dev, "Scaled for %ux%u : %u = %ux%u, skip %u\n", | ||
| 823 | *in_w, *in_h, resize, output_w, output_h, skip); | ||
| 824 | |||
| 646 | return resize; | 825 | return resize; |
| 647 | } | 826 | } |
| 648 | 827 | ||
| @@ -653,14 +832,14 @@ static int rj54n1_set_clock(struct i2c_client *client) | |||
| 653 | 832 | ||
| 654 | /* Enable external clock */ | 833 | /* Enable external clock */ |
| 655 | ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK | SOFT_STDBY); | 834 | ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK | SOFT_STDBY); |
| 656 | /* Leave stand-by */ | 835 | /* Leave stand-by. Note: use this when implementing suspend / resume */ |
| 657 | if (!ret) | 836 | if (!ret) |
| 658 | ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK); | 837 | ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK); |
| 659 | 838 | ||
| 660 | if (!ret) | 839 | if (!ret) |
| 661 | ret = reg_write(client, RJ54N1_PLL_L, 2); | 840 | ret = reg_write(client, RJ54N1_PLL_L, PLL_L); |
| 662 | if (!ret) | 841 | if (!ret) |
| 663 | ret = reg_write(client, RJ54N1_PLL_N, 0x31); | 842 | ret = reg_write(client, RJ54N1_PLL_N, PLL_N); |
| 664 | 843 | ||
| 665 | /* TGCLK dividers */ | 844 | /* TGCLK dividers */ |
| 666 | if (!ret) | 845 | if (!ret) |
| @@ -719,6 +898,7 @@ static int rj54n1_set_clock(struct i2c_client *client) | |||
| 719 | "Resetting RJ54N1CB0C clock failed: %d!\n", ret); | 898 | "Resetting RJ54N1CB0C clock failed: %d!\n", ret); |
| 720 | return -EIO; | 899 | return -EIO; |
| 721 | } | 900 | } |
| 901 | |||
| 722 | /* Start the PLL */ | 902 | /* Start the PLL */ |
| 723 | ret = reg_set(client, RJ54N1_OCLK_DSP, 1, 1); | 903 | ret = reg_set(client, RJ54N1_OCLK_DSP, 1, 1); |
| 724 | 904 | ||
| @@ -731,6 +911,7 @@ static int rj54n1_set_clock(struct i2c_client *client) | |||
| 731 | 911 | ||
| 732 | static int rj54n1_reg_init(struct i2c_client *client) | 912 | static int rj54n1_reg_init(struct i2c_client *client) |
| 733 | { | 913 | { |
| 914 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 734 | int ret = rj54n1_set_clock(client); | 915 | int ret = rj54n1_set_clock(client); |
| 735 | 916 | ||
| 736 | if (!ret) | 917 | if (!ret) |
| @@ -753,14 +934,26 @@ static int rj54n1_reg_init(struct i2c_client *client) | |||
| 753 | if (!ret) | 934 | if (!ret) |
| 754 | ret = reg_write(client, RJ54N1_Y_GAIN, 0x84); | 935 | ret = reg_write(client, RJ54N1_Y_GAIN, 0x84); |
| 755 | 936 | ||
| 756 | /* Mirror the image back: default is upside down and left-to-right... */ | 937 | /* |
| 938 | * Mirror the image back: default is upside down and left-to-right... | ||
| 939 | * Set manual preview / still shot switching | ||
| 940 | */ | ||
| 757 | if (!ret) | 941 | if (!ret) |
| 758 | ret = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 3, 3); | 942 | ret = reg_write(client, RJ54N1_MIRROR_STILL_MODE, 0x27); |
| 759 | 943 | ||
| 760 | if (!ret) | 944 | if (!ret) |
| 761 | ret = reg_write_multiple(client, bank_4, ARRAY_SIZE(bank_4)); | 945 | ret = reg_write_multiple(client, bank_4, ARRAY_SIZE(bank_4)); |
| 946 | |||
| 947 | /* Auto exposure area */ | ||
| 762 | if (!ret) | 948 | if (!ret) |
| 949 | ret = reg_write(client, RJ54N1_EXPOSURE_CONTROL, 0x80); | ||
| 950 | /* Check current auto WB config */ | ||
| 951 | if (!ret) | ||
| 952 | ret = reg_read(client, RJ54N1_WB_SEL_WEIGHT_I); | ||
| 953 | if (ret >= 0) { | ||
| 954 | rj54n1->auto_wb = ret & 0x80; | ||
| 763 | ret = reg_write_multiple(client, bank_5, ARRAY_SIZE(bank_5)); | 955 | ret = reg_write_multiple(client, bank_5, ARRAY_SIZE(bank_5)); |
| 956 | } | ||
| 764 | if (!ret) | 957 | if (!ret) |
| 765 | ret = reg_write_multiple(client, bank_8, ARRAY_SIZE(bank_8)); | 958 | ret = reg_write_multiple(client, bank_8, ARRAY_SIZE(bank_8)); |
| 766 | 959 | ||
| @@ -777,8 +970,9 @@ static int rj54n1_reg_init(struct i2c_client *client) | |||
| 777 | ret = reg_write(client, RJ54N1_RESET_STANDBY, | 970 | ret = reg_write(client, RJ54N1_RESET_STANDBY, |
| 778 | E_EXCLK | DSP_RSTX | TG_RSTX | SEN_RSTX); | 971 | E_EXCLK | DSP_RSTX | TG_RSTX | SEN_RSTX); |
| 779 | 972 | ||
| 973 | /* Start register update? Same register as 0x?FE in many bank_* sets */ | ||
| 780 | if (!ret) | 974 | if (!ret) |
| 781 | ret = reg_write(client, 0x7fe, 2); | 975 | ret = reg_write(client, RJ54N1_FWFLG, 2); |
| 782 | 976 | ||
| 783 | /* Constant taken from manufacturer's example */ | 977 | /* Constant taken from manufacturer's example */ |
| 784 | msleep(700); | 978 | msleep(700); |
| @@ -786,27 +980,44 @@ static int rj54n1_reg_init(struct i2c_client *client) | |||
| 786 | return ret; | 980 | return ret; |
| 787 | } | 981 | } |
| 788 | 982 | ||
| 789 | /* FIXME: streaming output only up to 800x600 is functional */ | 983 | static int rj54n1_try_fmt(struct v4l2_subdev *sd, |
| 790 | static int rj54n1_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) | 984 | struct v4l2_mbus_framefmt *mf) |
| 791 | { | 985 | { |
| 792 | struct v4l2_pix_format *pix = &f->fmt.pix; | 986 | struct i2c_client *client = sd->priv; |
| 987 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 988 | const struct rj54n1_datafmt *fmt; | ||
| 989 | int align = mf->code == V4L2_MBUS_FMT_SBGGR10_1X10 || | ||
| 990 | mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE || | ||
| 991 | mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE || | ||
| 992 | mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE || | ||
| 993 | mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE; | ||
| 994 | |||
| 995 | dev_dbg(&client->dev, "%s: code = %d, width = %u, height = %u\n", | ||
| 996 | __func__, mf->code, mf->width, mf->height); | ||
| 997 | |||
| 998 | fmt = rj54n1_find_datafmt(mf->code, rj54n1_colour_fmts, | ||
| 999 | ARRAY_SIZE(rj54n1_colour_fmts)); | ||
| 1000 | if (!fmt) { | ||
| 1001 | fmt = rj54n1->fmt; | ||
| 1002 | mf->code = fmt->code; | ||
| 1003 | } | ||
| 793 | 1004 | ||
| 794 | pix->field = V4L2_FIELD_NONE; | 1005 | mf->field = V4L2_FIELD_NONE; |
| 1006 | mf->colorspace = fmt->colorspace; | ||
| 795 | 1007 | ||
| 796 | if (pix->width > 800) | 1008 | v4l_bound_align_image(&mf->width, 112, RJ54N1_MAX_WIDTH, align, |
| 797 | pix->width = 800; | 1009 | &mf->height, 84, RJ54N1_MAX_HEIGHT, align, 0); |
| 798 | if (pix->height > 600) | ||
| 799 | pix->height = 600; | ||
| 800 | 1010 | ||
| 801 | return 0; | 1011 | return 0; |
| 802 | } | 1012 | } |
| 803 | 1013 | ||
| 804 | static int rj54n1_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) | 1014 | static int rj54n1_s_fmt(struct v4l2_subdev *sd, |
| 1015 | struct v4l2_mbus_framefmt *mf) | ||
| 805 | { | 1016 | { |
| 806 | struct i2c_client *client = sd->priv; | 1017 | struct i2c_client *client = sd->priv; |
| 807 | struct rj54n1 *rj54n1 = to_rj54n1(client); | 1018 | struct rj54n1 *rj54n1 = to_rj54n1(client); |
| 808 | struct v4l2_pix_format *pix = &f->fmt.pix; | 1019 | const struct rj54n1_datafmt *fmt; |
| 809 | unsigned int output_w, output_h, | 1020 | unsigned int output_w, output_h, max_w, max_h, |
| 810 | input_w = rj54n1->rect.width, input_h = rj54n1->rect.height; | 1021 | input_w = rj54n1->rect.width, input_h = rj54n1->rect.height; |
| 811 | int ret; | 1022 | int ret; |
| 812 | 1023 | ||
| @@ -814,14 +1025,13 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) | |||
| 814 | * The host driver can call us without .try_fmt(), so, we have to take | 1025 | * The host driver can call us without .try_fmt(), so, we have to take |
| 815 | * care ourseleves | 1026 | * care ourseleves |
| 816 | */ | 1027 | */ |
| 817 | ret = rj54n1_try_fmt(sd, f); | 1028 | rj54n1_try_fmt(sd, mf); |
| 818 | 1029 | ||
| 819 | /* | 1030 | /* |
| 820 | * Verify if the sensor has just been powered on. TODO: replace this | 1031 | * Verify if the sensor has just been powered on. TODO: replace this |
| 821 | * with proper PM, when a suitable API is available. | 1032 | * with proper PM, when a suitable API is available. |
| 822 | */ | 1033 | */ |
| 823 | if (!ret) | 1034 | ret = reg_read(client, RJ54N1_RESET_STANDBY); |
| 824 | ret = reg_read(client, RJ54N1_RESET_STANDBY); | ||
| 825 | if (ret < 0) | 1035 | if (ret < 0) |
| 826 | return ret; | 1036 | return ret; |
| 827 | 1037 | ||
| @@ -831,50 +1041,105 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f) | |||
| 831 | return ret; | 1041 | return ret; |
| 832 | } | 1042 | } |
| 833 | 1043 | ||
| 1044 | dev_dbg(&client->dev, "%s: code = %d, width = %u, height = %u\n", | ||
| 1045 | __func__, mf->code, mf->width, mf->height); | ||
| 1046 | |||
| 834 | /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */ | 1047 | /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */ |
| 835 | switch (pix->pixelformat) { | 1048 | switch (mf->code) { |
| 836 | case V4L2_PIX_FMT_YUYV: | 1049 | case V4L2_MBUS_FMT_YUYV8_2X8_LE: |
| 837 | ret = reg_write(client, RJ54N1_OUT_SEL, 0); | 1050 | ret = reg_write(client, RJ54N1_OUT_SEL, 0); |
| 838 | if (!ret) | 1051 | if (!ret) |
| 839 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); | 1052 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); |
| 840 | break; | 1053 | break; |
| 841 | case V4L2_PIX_FMT_RGB565: | 1054 | case V4L2_MBUS_FMT_YVYU8_2X8_LE: |
| 1055 | ret = reg_write(client, RJ54N1_OUT_SEL, 0); | ||
| 1056 | if (!ret) | ||
| 1057 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8); | ||
| 1058 | break; | ||
| 1059 | case V4L2_MBUS_FMT_RGB565_2X8_LE: | ||
| 1060 | ret = reg_write(client, RJ54N1_OUT_SEL, 0x11); | ||
| 1061 | if (!ret) | ||
| 1062 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); | ||
| 1063 | break; | ||
| 1064 | case V4L2_MBUS_FMT_RGB565_2X8_BE: | ||
| 842 | ret = reg_write(client, RJ54N1_OUT_SEL, 0x11); | 1065 | ret = reg_write(client, RJ54N1_OUT_SEL, 0x11); |
| 843 | if (!ret) | 1066 | if (!ret) |
| 1067 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8); | ||
| 1068 | break; | ||
| 1069 | case V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE: | ||
| 1070 | ret = reg_write(client, RJ54N1_OUT_SEL, 4); | ||
| 1071 | if (!ret) | ||
| 844 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); | 1072 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); |
| 1073 | if (!ret) | ||
| 1074 | ret = reg_write(client, RJ54N1_RA_SEL_UL, 0); | ||
| 1075 | break; | ||
| 1076 | case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE: | ||
| 1077 | ret = reg_write(client, RJ54N1_OUT_SEL, 4); | ||
| 1078 | if (!ret) | ||
| 1079 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); | ||
| 1080 | if (!ret) | ||
| 1081 | ret = reg_write(client, RJ54N1_RA_SEL_UL, 8); | ||
| 1082 | break; | ||
| 1083 | case V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE: | ||
| 1084 | ret = reg_write(client, RJ54N1_OUT_SEL, 4); | ||
| 1085 | if (!ret) | ||
| 1086 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8); | ||
| 1087 | if (!ret) | ||
| 1088 | ret = reg_write(client, RJ54N1_RA_SEL_UL, 0); | ||
| 1089 | break; | ||
| 1090 | case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE: | ||
| 1091 | ret = reg_write(client, RJ54N1_OUT_SEL, 4); | ||
| 1092 | if (!ret) | ||
| 1093 | ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8); | ||
| 1094 | if (!ret) | ||
| 1095 | ret = reg_write(client, RJ54N1_RA_SEL_UL, 8); | ||
| 1096 | break; | ||
| 1097 | case V4L2_MBUS_FMT_SBGGR10_1X10: | ||
| 1098 | ret = reg_write(client, RJ54N1_OUT_SEL, 5); | ||
| 845 | break; | 1099 | break; |
| 846 | default: | 1100 | default: |
| 847 | ret = -EINVAL; | 1101 | ret = -EINVAL; |
| 848 | } | 1102 | } |
| 849 | 1103 | ||
| 1104 | /* Special case: a raw mode with 10 bits of data per clock tick */ | ||
| 1105 | if (!ret) | ||
| 1106 | ret = reg_set(client, RJ54N1_OCLK_SEL_EN, | ||
| 1107 | (mf->code == V4L2_MBUS_FMT_SBGGR10_1X10) << 1, 2); | ||
| 1108 | |||
| 850 | if (ret < 0) | 1109 | if (ret < 0) |
| 851 | return ret; | 1110 | return ret; |
| 852 | 1111 | ||
| 853 | /* Supported scales 1:1 - 1:16 */ | 1112 | /* Supported scales 1:1 >= scale > 1:16 */ |
| 854 | if (pix->width < input_w / 16) | 1113 | max_w = mf->width * (16 * 1024 - 1) / 1024; |
| 855 | pix->width = input_w / 16; | 1114 | if (input_w > max_w) |
| 856 | if (pix->height < input_h / 16) | 1115 | input_w = max_w; |
| 857 | pix->height = input_h / 16; | 1116 | max_h = mf->height * (16 * 1024 - 1) / 1024; |
| 1117 | if (input_h > max_h) | ||
| 1118 | input_h = max_h; | ||
| 858 | 1119 | ||
| 859 | output_w = pix->width; | 1120 | output_w = mf->width; |
| 860 | output_h = pix->height; | 1121 | output_h = mf->height; |
| 861 | 1122 | ||
| 862 | ret = rj54n1_sensor_scale(sd, &input_w, &input_h, &output_w, &output_h); | 1123 | ret = rj54n1_sensor_scale(sd, &input_w, &input_h, &output_w, &output_h); |
| 863 | if (ret < 0) | 1124 | if (ret < 0) |
| 864 | return ret; | 1125 | return ret; |
| 865 | 1126 | ||
| 866 | rj54n1->fourcc = pix->pixelformat; | 1127 | fmt = rj54n1_find_datafmt(mf->code, rj54n1_colour_fmts, |
| 1128 | ARRAY_SIZE(rj54n1_colour_fmts)); | ||
| 1129 | |||
| 1130 | rj54n1->fmt = fmt; | ||
| 867 | rj54n1->resize = ret; | 1131 | rj54n1->resize = ret; |
| 868 | rj54n1->rect.width = input_w; | 1132 | rj54n1->rect.width = input_w; |
| 869 | rj54n1->rect.height = input_h; | 1133 | rj54n1->rect.height = input_h; |
| 870 | rj54n1->width = output_w; | 1134 | rj54n1->width = output_w; |
| 871 | rj54n1->height = output_h; | 1135 | rj54n1->height = output_h; |
| 872 | 1136 | ||
| 873 | pix->width = output_w; | 1137 | mf->width = output_w; |
| 874 | pix->height = output_h; | 1138 | mf->height = output_h; |
| 875 | pix->field = V4L2_FIELD_NONE; | 1139 | mf->field = V4L2_FIELD_NONE; |
| 1140 | mf->colorspace = fmt->colorspace; | ||
| 876 | 1141 | ||
| 877 | return ret; | 1142 | return 0; |
| 878 | } | 1143 | } |
| 879 | 1144 | ||
| 880 | static int rj54n1_g_chip_ident(struct v4l2_subdev *sd, | 1145 | static int rj54n1_g_chip_ident(struct v4l2_subdev *sd, |
| @@ -963,6 +1228,14 @@ static const struct v4l2_queryctrl rj54n1_controls[] = { | |||
| 963 | .step = 1, | 1228 | .step = 1, |
| 964 | .default_value = 66, | 1229 | .default_value = 66, |
| 965 | .flags = V4L2_CTRL_FLAG_SLIDER, | 1230 | .flags = V4L2_CTRL_FLAG_SLIDER, |
| 1231 | }, { | ||
| 1232 | .id = V4L2_CID_AUTO_WHITE_BALANCE, | ||
| 1233 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 1234 | .name = "Auto white balance", | ||
| 1235 | .minimum = 0, | ||
| 1236 | .maximum = 1, | ||
| 1237 | .step = 1, | ||
| 1238 | .default_value = 1, | ||
| 966 | }, | 1239 | }, |
| 967 | }; | 1240 | }; |
| 968 | 1241 | ||
| @@ -976,6 +1249,7 @@ static struct soc_camera_ops rj54n1_ops = { | |||
| 976 | static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 1249 | static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
| 977 | { | 1250 | { |
| 978 | struct i2c_client *client = sd->priv; | 1251 | struct i2c_client *client = sd->priv; |
| 1252 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 979 | int data; | 1253 | int data; |
| 980 | 1254 | ||
| 981 | switch (ctrl->id) { | 1255 | switch (ctrl->id) { |
| @@ -998,6 +1272,9 @@ static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | |||
| 998 | 1272 | ||
| 999 | ctrl->value = data / 2; | 1273 | ctrl->value = data / 2; |
| 1000 | break; | 1274 | break; |
| 1275 | case V4L2_CID_AUTO_WHITE_BALANCE: | ||
| 1276 | ctrl->value = rj54n1->auto_wb; | ||
| 1277 | break; | ||
| 1001 | } | 1278 | } |
| 1002 | 1279 | ||
| 1003 | return 0; | 1280 | return 0; |
| @@ -1007,6 +1284,7 @@ static int rj54n1_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | |||
| 1007 | { | 1284 | { |
| 1008 | int data; | 1285 | int data; |
| 1009 | struct i2c_client *client = sd->priv; | 1286 | struct i2c_client *client = sd->priv; |
| 1287 | struct rj54n1 *rj54n1 = to_rj54n1(client); | ||
| 1010 | const struct v4l2_queryctrl *qctrl; | 1288 | const struct v4l2_queryctrl *qctrl; |
| 1011 | 1289 | ||
| 1012 | qctrl = soc_camera_find_qctrl(&rj54n1_ops, ctrl->id); | 1290 | qctrl = soc_camera_find_qctrl(&rj54n1_ops, ctrl->id); |
| @@ -1037,6 +1315,13 @@ static int rj54n1_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | |||
| 1037 | else if (reg_write(client, RJ54N1_Y_GAIN, ctrl->value * 2) < 0) | 1315 | else if (reg_write(client, RJ54N1_Y_GAIN, ctrl->value * 2) < 0) |
| 1038 | return -EIO; | 1316 | return -EIO; |
| 1039 | break; | 1317 | break; |
| 1318 | case V4L2_CID_AUTO_WHITE_BALANCE: | ||
| 1319 | /* Auto WB area - whole image */ | ||
| 1320 | if (reg_set(client, RJ54N1_WB_SEL_WEIGHT_I, ctrl->value << 7, | ||
| 1321 | 0x80) < 0) | ||
| 1322 | return -EIO; | ||
| 1323 | rj54n1->auto_wb = ctrl->value; | ||
| 1324 | break; | ||
| 1040 | } | 1325 | } |
| 1041 | 1326 | ||
| 1042 | return 0; | 1327 | return 0; |
| @@ -1054,10 +1339,12 @@ static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = { | |||
| 1054 | 1339 | ||
| 1055 | static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = { | 1340 | static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = { |
| 1056 | .s_stream = rj54n1_s_stream, | 1341 | .s_stream = rj54n1_s_stream, |
| 1057 | .s_fmt = rj54n1_s_fmt, | 1342 | .s_mbus_fmt = rj54n1_s_fmt, |
| 1058 | .g_fmt = rj54n1_g_fmt, | 1343 | .g_mbus_fmt = rj54n1_g_fmt, |
| 1059 | .try_fmt = rj54n1_try_fmt, | 1344 | .try_mbus_fmt = rj54n1_try_fmt, |
| 1345 | .enum_mbus_fmt = rj54n1_enum_fmt, | ||
| 1060 | .g_crop = rj54n1_g_crop, | 1346 | .g_crop = rj54n1_g_crop, |
| 1347 | .s_crop = rj54n1_s_crop, | ||
| 1061 | .cropcap = rj54n1_cropcap, | 1348 | .cropcap = rj54n1_cropcap, |
| 1062 | }; | 1349 | }; |
| 1063 | 1350 | ||
| @@ -1066,21 +1353,13 @@ static struct v4l2_subdev_ops rj54n1_subdev_ops = { | |||
| 1066 | .video = &rj54n1_subdev_video_ops, | 1353 | .video = &rj54n1_subdev_video_ops, |
| 1067 | }; | 1354 | }; |
| 1068 | 1355 | ||
| 1069 | static int rj54n1_pin_config(struct i2c_client *client) | ||
| 1070 | { | ||
| 1071 | /* | ||
| 1072 | * Experimentally found out IOCTRL wired to 0. TODO: add to platform | ||
| 1073 | * data: 0 or 1 << 7. | ||
| 1074 | */ | ||
| 1075 | return reg_write(client, RJ54N1_IOC, 0); | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | /* | 1356 | /* |
| 1079 | * Interface active, can use i2c. If it fails, it can indeed mean, that | 1357 | * Interface active, can use i2c. If it fails, it can indeed mean, that |
| 1080 | * this wasn't our capture interface, so, we wait for the right one | 1358 | * this wasn't our capture interface, so, we wait for the right one |
| 1081 | */ | 1359 | */ |
| 1082 | static int rj54n1_video_probe(struct soc_camera_device *icd, | 1360 | static int rj54n1_video_probe(struct soc_camera_device *icd, |
| 1083 | struct i2c_client *client) | 1361 | struct i2c_client *client, |
| 1362 | struct rj54n1_pdata *priv) | ||
| 1084 | { | 1363 | { |
| 1085 | int data1, data2; | 1364 | int data1, data2; |
| 1086 | int ret; | 1365 | int ret; |
| @@ -1101,7 +1380,8 @@ static int rj54n1_video_probe(struct soc_camera_device *icd, | |||
| 1101 | goto ei2c; | 1380 | goto ei2c; |
| 1102 | } | 1381 | } |
| 1103 | 1382 | ||
| 1104 | ret = rj54n1_pin_config(client); | 1383 | /* Configure IOCTL polarity from the platform data: 0 or 1 << 7. */ |
| 1384 | ret = reg_write(client, RJ54N1_IOC, priv->ioctl_high << 7); | ||
| 1105 | if (ret < 0) | 1385 | if (ret < 0) |
| 1106 | goto ei2c; | 1386 | goto ei2c; |
| 1107 | 1387 | ||
| @@ -1119,6 +1399,7 @@ static int rj54n1_probe(struct i2c_client *client, | |||
| 1119 | struct soc_camera_device *icd = client->dev.platform_data; | 1399 | struct soc_camera_device *icd = client->dev.platform_data; |
| 1120 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | 1400 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
| 1121 | struct soc_camera_link *icl; | 1401 | struct soc_camera_link *icl; |
| 1402 | struct rj54n1_pdata *rj54n1_priv; | ||
| 1122 | int ret; | 1403 | int ret; |
| 1123 | 1404 | ||
| 1124 | if (!icd) { | 1405 | if (!icd) { |
| @@ -1127,11 +1408,13 @@ static int rj54n1_probe(struct i2c_client *client, | |||
| 1127 | } | 1408 | } |
| 1128 | 1409 | ||
| 1129 | icl = to_soc_camera_link(icd); | 1410 | icl = to_soc_camera_link(icd); |
| 1130 | if (!icl) { | 1411 | if (!icl || !icl->priv) { |
| 1131 | dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n"); | 1412 | dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n"); |
| 1132 | return -EINVAL; | 1413 | return -EINVAL; |
| 1133 | } | 1414 | } |
| 1134 | 1415 | ||
| 1416 | rj54n1_priv = icl->priv; | ||
| 1417 | |||
| 1135 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1418 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
| 1136 | dev_warn(&adapter->dev, | 1419 | dev_warn(&adapter->dev, |
| 1137 | "I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n"); | 1420 | "I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n"); |
| @@ -1153,10 +1436,12 @@ static int rj54n1_probe(struct i2c_client *client, | |||
| 1153 | rj54n1->rect.height = RJ54N1_MAX_HEIGHT; | 1436 | rj54n1->rect.height = RJ54N1_MAX_HEIGHT; |
| 1154 | rj54n1->width = RJ54N1_MAX_WIDTH; | 1437 | rj54n1->width = RJ54N1_MAX_WIDTH; |
| 1155 | rj54n1->height = RJ54N1_MAX_HEIGHT; | 1438 | rj54n1->height = RJ54N1_MAX_HEIGHT; |
| 1156 | rj54n1->fourcc = V4L2_PIX_FMT_YUYV; | 1439 | rj54n1->fmt = &rj54n1_colour_fmts[0]; |
| 1157 | rj54n1->resize = 1024; | 1440 | rj54n1->resize = 1024; |
| 1441 | rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) / | ||
| 1442 | (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1); | ||
| 1158 | 1443 | ||
| 1159 | ret = rj54n1_video_probe(icd, client); | 1444 | ret = rj54n1_video_probe(icd, client, rj54n1_priv); |
| 1160 | if (ret < 0) { | 1445 | if (ret < 0) { |
| 1161 | icd->ops = NULL; | 1446 | icd->ops = NULL; |
| 1162 | i2c_set_clientdata(client, NULL); | 1447 | i2c_set_clientdata(client, NULL); |
| @@ -1164,9 +1449,6 @@ static int rj54n1_probe(struct i2c_client *client, | |||
| 1164 | return ret; | 1449 | return ret; |
| 1165 | } | 1450 | } |
| 1166 | 1451 | ||
| 1167 | icd->formats = rj54n1_colour_formats; | ||
| 1168 | icd->num_formats = ARRAY_SIZE(rj54n1_colour_formats); | ||
| 1169 | |||
| 1170 | return ret; | 1452 | return ret; |
| 1171 | } | 1453 | } |
| 1172 | 1454 | ||
