bcm27xx: update patches from RPi foundation
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0688-media-i2c-ov5647-Support-V4L2_CID_PIXEL_RATE.patch
1 From e947a531a5c6a61fc568dc6a502543e1145efc29 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 29 Apr 2020 12:25:13 +0100
4 Subject: [PATCH] media: i2c: ov5647: Support V4L2_CID_PIXEL_RATE
5
6 Clients need to know the pixel rate in order to compute exposure
7 and frame rate values.
8 Advertise it.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12  drivers/media/i2c/ov5647.c | 31 +++++++++++++++++++++++++++----
13  1 file changed, 27 insertions(+), 4 deletions(-)
14
15 --- a/drivers/media/i2c/ov5647.c
16 +++ b/drivers/media/i2c/ov5647.c
17 @@ -89,6 +89,8 @@ struct ov5647_mode {
18         /* Analog crop rectangle. */
19         struct v4l2_rect crop;
20  
21 +       u64 pixel_rate;
22 +
23         struct regval_list              *reg_list;
24         unsigned int                    num_regs;
25  };
26 @@ -103,6 +105,7 @@ struct ov5647 {
27         struct gpio_desc                *pwdn;
28         unsigned int                    flags;
29         struct v4l2_ctrl_handler        ctrls;
30 +       struct v4l2_ctrl                *pixel_rate;
31         bool                            write_mode_regs;
32  };
33  
34 @@ -601,6 +604,7 @@ static struct ov5647_mode supported_mode
35                         .width = 1280,
36                         .height = 960,
37                 },
38 +               .pixel_rate = 77291670,
39                 ov5647_640x480_8bit,
40                 ARRAY_SIZE(ov5647_640x480_8bit)
41         },
42 @@ -624,6 +628,7 @@ static struct ov5647_mode supported_mode
43                         .width = 2592,
44                         .height = 1944
45                 },
46 +               .pixel_rate = 87500000,
47                 ov5647_2592x1944_10bit,
48                 ARRAY_SIZE(ov5647_2592x1944_10bit)
49         },
50 @@ -645,6 +650,7 @@ static struct ov5647_mode supported_mode
51                         .width = 1928,
52                         .height = 1080,
53                 },
54 +               .pixel_rate = 81666700,
55                 ov5647_1080p30_10bit,
56                 ARRAY_SIZE(ov5647_1080p30_10bit)
57         },
58 @@ -665,6 +671,7 @@ static struct ov5647_mode supported_mode
59                         .width = 2592,
60                         .height = 1944,
61                 },
62 +               .pixel_rate = 81666700,
63                 ov5647_2x2binned_10bit,
64                 ARRAY_SIZE(ov5647_2x2binned_10bit)
65         },
66 @@ -686,6 +693,7 @@ static struct ov5647_mode supported_mode
67                         .width = 2560,
68                         .height = 1920,
69                 },
70 +               .pixel_rate = 55000000,
71                 ov5647_640x480_10bit,
72                 ARRAY_SIZE(ov5647_640x480_10bit)
73         },
74 @@ -1163,6 +1171,11 @@ static int ov5647_set_fmt(struct v4l2_su
75                 if (state->mode != mode)
76                         state->write_mode_regs = true;
77                 state->mode = mode;
78 +
79 +               __v4l2_ctrl_modify_range(state->pixel_rate,
80 +                                        mode->pixel_rate,
81 +                                        mode->pixel_rate, 1,
82 +                                        mode->pixel_rate);
83         }
84  
85         mutex_unlock(&state->lock);
86 @@ -1379,6 +1392,9 @@ static int ov5647_s_ctrl(struct v4l2_ctr
87         case V4L2_CID_EXPOSURE:
88                 ret = ov5647_s_exposure(sd, ctrl->val);
89                 break;
90 +       case V4L2_CID_PIXEL_RATE:
91 +               /* Read-only, but we adjust it based on mode. */
92 +               break;
93         default:
94                 dev_info(&client->dev,
95                          "ctrl(id:0x%x,val:0x%x) is not handled\n",
96 @@ -1436,7 +1452,7 @@ static int ov5647_probe(struct i2c_clien
97         mutex_init(&sensor->lock);
98  
99         /* Initialise controls. */
100 -       v4l2_ctrl_handler_init(&sensor->ctrls, 3);
101 +       v4l2_ctrl_handler_init(&sensor->ctrls, 6);
102         v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
103                           V4L2_CID_AUTOGAIN,
104                           0,  /* min */
105 @@ -1469,6 +1485,16 @@ static int ov5647_probe(struct i2c_clien
106                                  32);  /* default, 32 = 2.0x */
107         ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
108  
109 +       /* Set the default mode before we init the subdev */
110 +       sensor->mode = OV5647_DEFAULT_MODE;
111 +
112 +       /* By default, PIXEL_RATE is read only, but it does change per mode */
113 +       sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
114 +                                              V4L2_CID_PIXEL_RATE,
115 +                                              sensor->mode->pixel_rate,
116 +                                              sensor->mode->pixel_rate, 1,
117 +                                              sensor->mode->pixel_rate);
118 +
119         if (sensor->ctrls.error) {
120                 ret = sensor->ctrls.error;
121                 dev_err(&client->dev, "%s control init failed (%d)\n",
122 @@ -1477,9 +1503,6 @@ static int ov5647_probe(struct i2c_clien
123         }
124         sensor->sd.ctrl_handler = &sensor->ctrls;
125  
126 -       /* Set the default mode before we init the subdev */
127 -       sensor->mode = OV5647_DEFAULT_MODE;
128 -
129         /* Write out the register set over I2C on stream-on. */
130         sensor->write_mode_regs = true;
131