2 * Driver for RJ54N1CB0C CMOS Image Sensor from Micron
4 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/delay.h>
12 #include <linux/i2c.h>
13 #include <linux/slab.h>
14 #include <linux/videodev2.h>
16 #include <media/v4l2-subdev.h>
17 #include <media/v4l2-chip-ident.h>
18 #include <media/soc_camera.h>
20 #define RJ54N1_DEV_CODE 0x0400
21 #define RJ54N1_DEV_CODE2 0x0401
22 #define RJ54N1_OUT_SEL 0x0403
23 #define RJ54N1_XY_OUTPUT_SIZE_S_H 0x0404
24 #define RJ54N1_X_OUTPUT_SIZE_S_L 0x0405
25 #define RJ54N1_Y_OUTPUT_SIZE_S_L 0x0406
26 #define RJ54N1_XY_OUTPUT_SIZE_P_H 0x0407
27 #define RJ54N1_X_OUTPUT_SIZE_P_L 0x0408
28 #define RJ54N1_Y_OUTPUT_SIZE_P_L 0x0409
29 #define RJ54N1_LINE_LENGTH_PCK_S_H 0x040a
30 #define RJ54N1_LINE_LENGTH_PCK_S_L 0x040b
31 #define RJ54N1_LINE_LENGTH_PCK_P_H 0x040c
32 #define RJ54N1_LINE_LENGTH_PCK_P_L 0x040d
33 #define RJ54N1_RESIZE_N 0x040e
34 #define RJ54N1_RESIZE_N_STEP 0x040f
35 #define RJ54N1_RESIZE_STEP 0x0410
36 #define RJ54N1_RESIZE_HOLD_H 0x0411
37 #define RJ54N1_RESIZE_HOLD_L 0x0412
38 #define RJ54N1_H_OBEN_OFS 0x0413
39 #define RJ54N1_V_OBEN_OFS 0x0414
40 #define RJ54N1_RESIZE_CONTROL 0x0415
41 #define RJ54N1_INC_USE_SEL_H 0x0425
42 #define RJ54N1_INC_USE_SEL_L 0x0426
43 #define RJ54N1_MIRROR_STILL_MODE 0x0427
44 #define RJ54N1_INIT_START 0x0428
45 #define RJ54N1_SCALE_1_2_LEV 0x0429
46 #define RJ54N1_SCALE_4_LEV 0x042a
47 #define RJ54N1_Y_GAIN 0x04d8
48 #define RJ54N1_APT_GAIN_UP 0x04fa
49 #define RJ54N1_RA_SEL_UL 0x0530
50 #define RJ54N1_BYTE_SWAP 0x0531
51 #define RJ54N1_OUT_SIGPO 0x053b
52 #define RJ54N1_FRAME_LENGTH_S_H 0x0595
53 #define RJ54N1_FRAME_LENGTH_S_L 0x0596
54 #define RJ54N1_FRAME_LENGTH_P_H 0x0597
55 #define RJ54N1_FRAME_LENGTH_P_L 0x0598
56 #define RJ54N1_IOC 0x05ef
57 #define RJ54N1_TG_BYPASS 0x0700
58 #define RJ54N1_PLL_L 0x0701
59 #define RJ54N1_PLL_N 0x0702
60 #define RJ54N1_PLL_EN 0x0704
61 #define RJ54N1_RATIO_TG 0x0706
62 #define RJ54N1_RATIO_T 0x0707
63 #define RJ54N1_RATIO_R 0x0708
64 #define RJ54N1_RAMP_TGCLK_EN 0x0709
65 #define RJ54N1_OCLK_DSP 0x0710
66 #define RJ54N1_RATIO_OP 0x0711
67 #define RJ54N1_RATIO_O 0x0712
68 #define RJ54N1_OCLK_SEL_EN 0x0713
69 #define RJ54N1_CLK_RST 0x0717
70 #define RJ54N1_RESET_STANDBY 0x0718
72 #define E_EXCLK (1 << 7)
73 #define SOFT_STDBY (1 << 4)
74 #define SEN_RSTX (1 << 2)
75 #define TG_RSTX (1 << 1)
76 #define DSP_RSTX (1 << 0)
78 #define RESIZE_HOLD_SEL (1 << 2)
79 #define RESIZE_GO (1 << 1)
81 #define RJ54N1_COLUMN_SKIP 0
82 #define RJ54N1_ROW_SKIP 0
83 #define RJ54N1_MAX_WIDTH 1600
84 #define RJ54N1_MAX_HEIGHT 1200
86 /* I2C addresses: 0x50, 0x51, 0x60, 0x61 */
88 static const struct soc_camera_data_format rj54n1_colour_formats[] = {
92 .fourcc = V4L2_PIX_FMT_YUYV,
93 .colorspace = V4L2_COLORSPACE_JPEG,
97 .fourcc = V4L2_PIX_FMT_RGB565,
98 .colorspace = V4L2_COLORSPACE_SRGB,
102 struct rj54n1_clock_div {
111 struct v4l2_subdev subdev;
112 struct v4l2_rect rect; /* Sensor window */
113 unsigned short width; /* Output window */
114 unsigned short height;
115 unsigned short resize; /* Sensor * 1024 / resize = Output */
116 struct rj54n1_clock_div clk_div;
118 unsigned short scale;
122 struct rj54n1_reg_val {
127 const static struct rj54n1_reg_val bank_4[] = {
148 const static struct rj54n1_reg_val bank_5[] = {
169 const static struct rj54n1_reg_val bank_7[] = {
177 const static struct rj54n1_reg_val bank_8[] = {
365 const static struct rj54n1_reg_val bank_10[] = {
369 /* Clock dividers - these are default register values, divider = register + 1 */
370 const static struct rj54n1_clock_div clk_div = {
371 .ratio_tg = 3 /* default: 5 */,
372 .ratio_t = 4 /* default: 1 */,
373 .ratio_r = 4 /* default: 0 */,
374 .ratio_op = 1 /* default: 5 */,
375 .ratio_o = 9 /* default: 0 */,
378 static struct rj54n1 *to_rj54n1(const struct i2c_client *client)
380 return container_of(i2c_get_clientdata(client), struct rj54n1, subdev);
383 static int reg_read(struct i2c_client *client, const u16 reg)
385 struct rj54n1 *rj54n1 = to_rj54n1(client);
389 if (rj54n1->bank != reg >> 8) {
390 dev_dbg(&client->dev, "[0x%x] = 0x%x\n", 0xff, reg >> 8);
391 ret = i2c_smbus_write_byte_data(client, 0xff, reg >> 8);
394 rj54n1->bank = reg >> 8;
396 return i2c_smbus_read_byte_data(client, reg & 0xff);
399 static int reg_write(struct i2c_client *client, const u16 reg,
402 struct rj54n1 *rj54n1 = to_rj54n1(client);
406 if (rj54n1->bank != reg >> 8) {
407 dev_dbg(&client->dev, "[0x%x] = 0x%x\n", 0xff, reg >> 8);
408 ret = i2c_smbus_write_byte_data(client, 0xff, reg >> 8);
411 rj54n1->bank = reg >> 8;
413 dev_dbg(&client->dev, "[0x%x] = 0x%x\n", reg & 0xff, data);
414 return i2c_smbus_write_byte_data(client, reg & 0xff, data);
417 static int reg_set(struct i2c_client *client, const u16 reg,
418 const u8 data, const u8 mask)
422 ret = reg_read(client, reg);
425 return reg_write(client, reg, (ret & ~mask) | (data & mask));
428 static int reg_write_multiple(struct i2c_client *client,
429 const struct rj54n1_reg_val *rv, const int n)
433 for (i = 0; i < n; i++) {
434 ret = reg_write(client, rv->reg, rv->val);
443 static int rj54n1_s_stream(struct v4l2_subdev *sd, int enable)
445 /* TODO: start / stop streaming */
449 static int rj54n1_set_bus_param(struct soc_camera_device *icd,
452 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
453 struct i2c_client *client = sd->priv;
454 /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
456 if (flags & SOCAM_PCLK_SAMPLE_RISING)
457 return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
459 return reg_write(client, RJ54N1_OUT_SIGPO, 0);
462 static unsigned long rj54n1_query_bus_param(struct soc_camera_device *icd)
464 struct soc_camera_link *icl = to_soc_camera_link(icd);
465 const unsigned long flags =
466 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
467 SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
468 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
469 SOCAM_DATA_ACTIVE_HIGH;
471 return soc_camera_apply_sensor_flags(icl, flags);
474 static int rj54n1_set_rect(struct i2c_client *client,
475 u16 reg_x, u16 reg_y, u16 reg_xy,
476 u32 width, u32 height)
480 ret = reg_write(client, reg_xy,
481 ((width >> 4) & 0x70) |
482 ((height >> 8) & 7));
485 ret = reg_write(client, reg_x, width & 0xff);
487 ret = reg_write(client, reg_y, height & 0xff);
493 * Some commands, specifically certain initialisation sequences, require
494 * a commit operation.
496 static int rj54n1_commit(struct i2c_client *client)
498 int ret = reg_write(client, RJ54N1_INIT_START, 1);
501 ret = reg_write(client, RJ54N1_INIT_START, 0);
505 static int rj54n1_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
507 struct i2c_client *client = sd->priv;
508 struct rj54n1 *rj54n1 = to_rj54n1(client);
511 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
516 static int rj54n1_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
518 a->bounds.left = RJ54N1_COLUMN_SKIP;
519 a->bounds.top = RJ54N1_ROW_SKIP;
520 a->bounds.width = RJ54N1_MAX_WIDTH;
521 a->bounds.height = RJ54N1_MAX_HEIGHT;
522 a->defrect = a->bounds;
523 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
524 a->pixelaspect.numerator = 1;
525 a->pixelaspect.denominator = 1;
530 static int rj54n1_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
532 struct i2c_client *client = sd->priv;
533 struct rj54n1 *rj54n1 = to_rj54n1(client);
534 struct v4l2_pix_format *pix = &f->fmt.pix;
536 pix->pixelformat = rj54n1->fourcc;
537 pix->field = V4L2_FIELD_NONE;
538 pix->width = rj54n1->width;
539 pix->height = rj54n1->height;
545 * The actual geometry configuration routine. It scales the input window into
546 * the output one, updates the window sizes and returns an error or the resize
547 * coefficient on success. Note: we only use the "Fixed Scaling" on this camera.
549 static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h,
550 u32 *out_w, u32 *out_h)
552 struct i2c_client *client = sd->priv;
553 unsigned int skip, resize, input_w = *in_w, input_h = *in_h,
554 output_w = *out_w, output_h = *out_h;
558 ret = rj54n1_set_rect(client, RJ54N1_X_OUTPUT_SIZE_S_L,
559 RJ54N1_Y_OUTPUT_SIZE_S_L,
560 RJ54N1_XY_OUTPUT_SIZE_S_H, output_w, output_h);
562 ret = rj54n1_set_rect(client, RJ54N1_X_OUTPUT_SIZE_P_L,
563 RJ54N1_Y_OUTPUT_SIZE_P_L,
564 RJ54N1_XY_OUTPUT_SIZE_P_H, output_w, output_h);
569 if (output_w > input_w || output_h > input_h) {
575 unsigned int resize_x, resize_y;
576 resize_x = input_w * 1024 / output_w;
577 resize_y = input_h * 1024 / output_h;
579 resize = min(resize_x, resize_y);
581 /* Prohibited value ranges */
592 case 16320 ... 16383:
596 input_w = output_w * resize / 1024;
597 input_h = output_h * resize / 1024;
601 ret = reg_write(client, RJ54N1_RESIZE_HOLD_L, resize & 0xff);
603 ret = reg_write(client, RJ54N1_RESIZE_HOLD_H, resize >> 8);
609 * Configure a skipping bitmask. The sensor will select a skipping value
610 * among set bits automatically.
612 skip = min(resize / 1024, (unsigned)15);
617 else if (resize & 1023 && skip < 15)
618 inc_sel |= 1 << (skip + 1);
620 ret = reg_write(client, RJ54N1_INC_USE_SEL_L, inc_sel & 0xfc);
622 ret = reg_write(client, RJ54N1_INC_USE_SEL_H, inc_sel >> 8);
626 ret = reg_write(client, RJ54N1_RESIZE_CONTROL,
627 RESIZE_HOLD_SEL | RESIZE_GO | 1);
632 dev_dbg(&client->dev, "resize %u, skip %u\n", resize, skip);
634 /* Constant taken from manufacturer's example */
637 ret = reg_write(client, RJ54N1_RESIZE_CONTROL, RESIZE_HOLD_SEL | 1);
649 static int rj54n1_set_clock(struct i2c_client *client)
651 struct rj54n1 *rj54n1 = to_rj54n1(client);
654 /* Enable external clock */
655 ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK | SOFT_STDBY);
658 ret = reg_write(client, RJ54N1_RESET_STANDBY, E_EXCLK);
661 ret = reg_write(client, RJ54N1_PLL_L, 2);
663 ret = reg_write(client, RJ54N1_PLL_N, 0x31);
667 ret = reg_write(client, RJ54N1_RATIO_TG,
668 rj54n1->clk_div.ratio_tg);
670 ret = reg_write(client, RJ54N1_RATIO_T,
671 rj54n1->clk_div.ratio_t);
673 ret = reg_write(client, RJ54N1_RATIO_R,
674 rj54n1->clk_div.ratio_r);
676 /* Enable TGCLK & RAMP */
678 ret = reg_write(client, RJ54N1_RAMP_TGCLK_EN, 3);
680 /* Disable clock output */
682 ret = reg_write(client, RJ54N1_OCLK_DSP, 0);
686 ret = reg_write(client, RJ54N1_RATIO_OP,
687 rj54n1->clk_div.ratio_op);
689 ret = reg_write(client, RJ54N1_RATIO_O,
690 rj54n1->clk_div.ratio_o);
694 ret = reg_write(client, RJ54N1_OCLK_SEL_EN, 1);
696 /* Use PLL for Timing Generator, write 2 to reserved bits */
698 ret = reg_write(client, RJ54N1_TG_BYPASS, 2);
700 /* Take sensor out of reset */
702 ret = reg_write(client, RJ54N1_RESET_STANDBY,
706 ret = reg_write(client, RJ54N1_PLL_EN, 1);
708 /* Wait for PLL to stabilise */
711 /* Enable clock to frequency divider */
713 ret = reg_write(client, RJ54N1_CLK_RST, 1);
716 ret = reg_read(client, RJ54N1_CLK_RST);
718 dev_err(&client->dev,
719 "Resetting RJ54N1CB0C clock failed: %d!\n", ret);
723 ret = reg_set(client, RJ54N1_OCLK_DSP, 1, 1);
727 ret = reg_write(client, RJ54N1_OCLK_SEL_EN, 1);
732 static int rj54n1_reg_init(struct i2c_client *client)
734 int ret = rj54n1_set_clock(client);
737 ret = reg_write_multiple(client, bank_7, ARRAY_SIZE(bank_7));
739 ret = reg_write_multiple(client, bank_10, ARRAY_SIZE(bank_10));
741 /* Set binning divisors */
743 ret = reg_write(client, RJ54N1_SCALE_1_2_LEV, 3 | (7 << 4));
745 ret = reg_write(client, RJ54N1_SCALE_4_LEV, 0xf);
747 /* Switch to fixed resize mode */
749 ret = reg_write(client, RJ54N1_RESIZE_CONTROL,
750 RESIZE_HOLD_SEL | 1);
754 ret = reg_write(client, RJ54N1_Y_GAIN, 0x84);
756 /* Mirror the image back: default is upside down and left-to-right... */
758 ret = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 3, 3);
761 ret = reg_write_multiple(client, bank_4, ARRAY_SIZE(bank_4));
763 ret = reg_write_multiple(client, bank_5, ARRAY_SIZE(bank_5));
765 ret = reg_write_multiple(client, bank_8, ARRAY_SIZE(bank_8));
768 ret = reg_write(client, RJ54N1_RESET_STANDBY,
769 E_EXCLK | DSP_RSTX | SEN_RSTX);
773 ret = rj54n1_commit(client);
775 /* Take DSP, TG, sensor out of reset */
777 ret = reg_write(client, RJ54N1_RESET_STANDBY,
778 E_EXCLK | DSP_RSTX | TG_RSTX | SEN_RSTX);
781 ret = reg_write(client, 0x7fe, 2);
783 /* Constant taken from manufacturer's example */
789 /* FIXME: streaming output only up to 800x600 is functional */
790 static int rj54n1_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
792 struct v4l2_pix_format *pix = &f->fmt.pix;
794 pix->field = V4L2_FIELD_NONE;
796 if (pix->width > 800)
798 if (pix->height > 600)
804 static int rj54n1_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
806 struct i2c_client *client = sd->priv;
807 struct rj54n1 *rj54n1 = to_rj54n1(client);
808 struct v4l2_pix_format *pix = &f->fmt.pix;
809 unsigned int output_w, output_h,
810 input_w = rj54n1->rect.width, input_h = rj54n1->rect.height;
814 * The host driver can call us without .try_fmt(), so, we have to take
817 ret = rj54n1_try_fmt(sd, f);
820 * Verify if the sensor has just been powered on. TODO: replace this
821 * with proper PM, when a suitable API is available.
824 ret = reg_read(client, RJ54N1_RESET_STANDBY);
828 if (!(ret & E_EXCLK)) {
829 ret = rj54n1_reg_init(client);
834 /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */
835 switch (pix->pixelformat) {
836 case V4L2_PIX_FMT_YUYV:
837 ret = reg_write(client, RJ54N1_OUT_SEL, 0);
839 ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8);
841 case V4L2_PIX_FMT_RGB565:
842 ret = reg_write(client, RJ54N1_OUT_SEL, 0x11);
844 ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8);
853 /* Supported scales 1:1 - 1:16 */
854 if (pix->width < input_w / 16)
855 pix->width = input_w / 16;
856 if (pix->height < input_h / 16)
857 pix->height = input_h / 16;
859 output_w = pix->width;
860 output_h = pix->height;
862 ret = rj54n1_sensor_scale(sd, &input_w, &input_h, &output_w, &output_h);
866 rj54n1->fourcc = pix->pixelformat;
867 rj54n1->resize = ret;
868 rj54n1->rect.width = input_w;
869 rj54n1->rect.height = input_h;
870 rj54n1->width = output_w;
871 rj54n1->height = output_h;
873 pix->width = output_w;
874 pix->height = output_h;
875 pix->field = V4L2_FIELD_NONE;
880 static int rj54n1_g_chip_ident(struct v4l2_subdev *sd,
881 struct v4l2_dbg_chip_ident *id)
883 struct i2c_client *client = sd->priv;
885 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
888 if (id->match.addr != client->addr)
891 id->ident = V4L2_IDENT_RJ54N1CB0C;
897 #ifdef CONFIG_VIDEO_ADV_DEBUG
898 static int rj54n1_g_register(struct v4l2_subdev *sd,
899 struct v4l2_dbg_register *reg)
901 struct i2c_client *client = sd->priv;
903 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR ||
904 reg->reg < 0x400 || reg->reg > 0x1fff)
905 /* Registers > 0x0800 are only available from Sharp support */
908 if (reg->match.addr != client->addr)
912 reg->val = reg_read(client, reg->reg);
920 static int rj54n1_s_register(struct v4l2_subdev *sd,
921 struct v4l2_dbg_register *reg)
923 struct i2c_client *client = sd->priv;
925 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR ||
926 reg->reg < 0x400 || reg->reg > 0x1fff)
927 /* Registers >= 0x0800 are only available from Sharp support */
930 if (reg->match.addr != client->addr)
933 if (reg_write(client, reg->reg, reg->val) < 0)
940 static const struct v4l2_queryctrl rj54n1_controls[] = {
942 .id = V4L2_CID_VFLIP,
943 .type = V4L2_CTRL_TYPE_BOOLEAN,
944 .name = "Flip Vertically",
950 .id = V4L2_CID_HFLIP,
951 .type = V4L2_CTRL_TYPE_BOOLEAN,
952 .name = "Flip Horizontally",
959 .type = V4L2_CTRL_TYPE_INTEGER,
965 .flags = V4L2_CTRL_FLAG_SLIDER,
969 static struct soc_camera_ops rj54n1_ops = {
970 .set_bus_param = rj54n1_set_bus_param,
971 .query_bus_param = rj54n1_query_bus_param,
972 .controls = rj54n1_controls,
973 .num_controls = ARRAY_SIZE(rj54n1_controls),
976 static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
978 struct i2c_client *client = sd->priv;
983 data = reg_read(client, RJ54N1_MIRROR_STILL_MODE);
986 ctrl->value = !(data & 1);
989 data = reg_read(client, RJ54N1_MIRROR_STILL_MODE);
992 ctrl->value = !(data & 2);
995 data = reg_read(client, RJ54N1_Y_GAIN);
999 ctrl->value = data / 2;
1006 static int rj54n1_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1009 struct i2c_client *client = sd->priv;
1010 const struct v4l2_queryctrl *qctrl;
1012 qctrl = soc_camera_find_qctrl(&rj54n1_ops, ctrl->id);
1017 case V4L2_CID_VFLIP:
1019 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 1);
1021 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 1, 1);
1025 case V4L2_CID_HFLIP:
1027 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 2);
1029 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 2, 2);
1034 if (ctrl->value > qctrl->maximum ||
1035 ctrl->value < qctrl->minimum)
1037 else if (reg_write(client, RJ54N1_Y_GAIN, ctrl->value * 2) < 0)
1045 static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
1046 .g_ctrl = rj54n1_g_ctrl,
1047 .s_ctrl = rj54n1_s_ctrl,
1048 .g_chip_ident = rj54n1_g_chip_ident,
1049 #ifdef CONFIG_VIDEO_ADV_DEBUG
1050 .g_register = rj54n1_g_register,
1051 .s_register = rj54n1_s_register,
1055 static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
1056 .s_stream = rj54n1_s_stream,
1057 .s_fmt = rj54n1_s_fmt,
1058 .g_fmt = rj54n1_g_fmt,
1059 .try_fmt = rj54n1_try_fmt,
1060 .g_crop = rj54n1_g_crop,
1061 .cropcap = rj54n1_cropcap,
1064 static struct v4l2_subdev_ops rj54n1_subdev_ops = {
1065 .core = &rj54n1_subdev_core_ops,
1066 .video = &rj54n1_subdev_video_ops,
1069 static int rj54n1_pin_config(struct i2c_client *client)
1072 * Experimentally found out IOCTRL wired to 0. TODO: add to platform
1073 * data: 0 or 1 << 7.
1075 return reg_write(client, RJ54N1_IOC, 0);
1079 * 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
1082 static int rj54n1_video_probe(struct soc_camera_device *icd,
1083 struct i2c_client *client)
1088 /* This could be a BUG_ON() or a WARN_ON(), or remove it completely */
1089 if (!icd->dev.parent ||
1090 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
1093 /* Read out the chip version register */
1094 data1 = reg_read(client, RJ54N1_DEV_CODE);
1095 data2 = reg_read(client, RJ54N1_DEV_CODE2);
1097 if (data1 != 0x51 || data2 != 0x10) {
1099 dev_info(&client->dev, "No RJ54N1CB0C found, read 0x%x:0x%x\n",
1104 ret = rj54n1_pin_config(client);
1108 dev_info(&client->dev, "Detected a RJ54N1CB0C chip ID 0x%x:0x%x\n",
1115 static int rj54n1_probe(struct i2c_client *client,
1116 const struct i2c_device_id *did)
1118 struct rj54n1 *rj54n1;
1119 struct soc_camera_device *icd = client->dev.platform_data;
1120 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1121 struct soc_camera_link *icl;
1125 dev_err(&client->dev, "RJ54N1CB0C: missing soc-camera data!\n");
1129 icl = to_soc_camera_link(icd);
1131 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n");
1135 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1136 dev_warn(&adapter->dev,
1137 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n");
1141 rj54n1 = kzalloc(sizeof(struct rj54n1), GFP_KERNEL);
1145 v4l2_i2c_subdev_init(&rj54n1->subdev, client, &rj54n1_subdev_ops);
1147 icd->ops = &rj54n1_ops;
1149 rj54n1->clk_div = clk_div;
1150 rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
1151 rj54n1->rect.top = RJ54N1_ROW_SKIP;
1152 rj54n1->rect.width = RJ54N1_MAX_WIDTH;
1153 rj54n1->rect.height = RJ54N1_MAX_HEIGHT;
1154 rj54n1->width = RJ54N1_MAX_WIDTH;
1155 rj54n1->height = RJ54N1_MAX_HEIGHT;
1156 rj54n1->fourcc = V4L2_PIX_FMT_YUYV;
1157 rj54n1->resize = 1024;
1159 ret = rj54n1_video_probe(icd, client);
1162 i2c_set_clientdata(client, NULL);
1167 icd->formats = rj54n1_colour_formats;
1168 icd->num_formats = ARRAY_SIZE(rj54n1_colour_formats);
1173 static int rj54n1_remove(struct i2c_client *client)
1175 struct rj54n1 *rj54n1 = to_rj54n1(client);
1176 struct soc_camera_device *icd = client->dev.platform_data;
1177 struct soc_camera_link *icl = to_soc_camera_link(icd);
1182 i2c_set_clientdata(client, NULL);
1183 client->driver = NULL;
1189 static const struct i2c_device_id rj54n1_id[] = {
1190 { "rj54n1cb0c", 0 },
1193 MODULE_DEVICE_TABLE(i2c, rj54n1_id);
1195 static struct i2c_driver rj54n1_i2c_driver = {
1197 .name = "rj54n1cb0c",
1199 .probe = rj54n1_probe,
1200 .remove = rj54n1_remove,
1201 .id_table = rj54n1_id,
1204 static int __init rj54n1_mod_init(void)
1206 return i2c_add_driver(&rj54n1_i2c_driver);
1209 static void __exit rj54n1_mod_exit(void)
1211 i2c_del_driver(&rj54n1_i2c_driver);
1214 module_init(rj54n1_mod_init);
1215 module_exit(rj54n1_mod_exit);
1217 MODULE_DESCRIPTION("Sharp RJ54N1CB0C Camera driver");
1218 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
1219 MODULE_LICENSE("GPL v2");