bcm27xx: import latest patches from the RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0797-media-i2c-ov6650-Use-new-get-set-_mbus_config-ops.patch
1 From 0dd7e12bb7dc81e09440f3330465c31349497dc3 Mon Sep 17 00:00:00 2001
2 From: Jacopo Mondi <jacopo+renesas@jmondi.org>
3 Date: Tue, 16 Jun 2020 16:12:38 +0200
4 Subject: [PATCH]_mbus_config
5 ops
6
7 Upstream https://patchwork.linuxtv.org/patch/64674/
8
9 Use the new get_mbus_config and set_mbus_config pad operations in place
10 of the video operations currently in use.
11
12 Compared to other drivers where the same conversion has been performed,
13 ov6650 proved to be a bit more tricky, as the existing g_mbus_config
14 implementation did not report the currently applied configuration but
15 the set of all possible configuration options.
16
17 Adapt the driver to support the semantic of the two newly introduced
18 operations:
19 - get_mbus_config reports the current media bus configuration
20 - set_mbus_config applies only changes explicitly requested and updates
21 the provided cfg parameter to report what has actually been applied to
22 the hardware.
23
24 Compile-tested only.
25
26 Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
27 ---
28 drivers/media/i2c/ov6650.c | 56 ++++++++++++++++++++++++++------------
29 1 file changed, 39 insertions(+), 17 deletions(-)
30
31 --- a/drivers/media/i2c/ov6650.c
32 +++ b/drivers/media/i2c/ov6650.c
33 @@ -909,46 +909,68 @@ static const struct v4l2_subdev_core_ops
34 };
35
36 /* Request bus settings on camera side */
37 -static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
38 - struct v4l2_mbus_config *cfg)
39 +static int ov6650_get_mbus_config(struct v4l2_subdev *sd,
40 + unsigned int pad,
41 + struct v4l2_mbus_config *cfg)
42 {
43 + struct i2c_client *client = v4l2_get_subdevdata(sd);
44 + u8 comj, comf;
45 + int ret;
46 +
47 + ret = ov6650_reg_read(client, REG_COMJ, &comj);
48 + if (ret)
49 + return ret;
50 +
51 + ret = ov6650_reg_read(client, REG_COMF, &comf);
52 + if (ret)
53 + return ret;
54
55 - cfg->flags = V4L2_MBUS_MASTER |
56 - V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
57 - V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
58 - V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
59 - V4L2_MBUS_DATA_ACTIVE_HIGH;
60 + cfg->flags = V4L2_MBUS_MASTER
61 + | ((comj & COMJ_VSYNC_HIGH) ? V4L2_MBUS_VSYNC_ACTIVE_HIGH
62 + : V4L2_MBUS_VSYNC_ACTIVE_LOW)
63 + | ((comf & COMF_HREF_LOW) ? V4L2_MBUS_HSYNC_ACTIVE_LOW
64 + : V4L2_MBUS_HSYNC_ACTIVE_HIGH)
65 + | ((comj & COMJ_PCLK_RISING) ? V4L2_MBUS_PCLK_SAMPLE_RISING
66 + : V4L2_MBUS_PCLK_SAMPLE_FALLING);
67 cfg->type = V4L2_MBUS_PARALLEL;
68
69 return 0;
70 }
71
72 /* Alter bus settings on camera side */
73 -static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
74 - const struct v4l2_mbus_config *cfg)
75 +static int ov6650_set_mbus_config(struct v4l2_subdev *sd,
76 + unsigned int pad,
77 + struct v4l2_mbus_config *cfg)
78 {
79 struct i2c_client *client = v4l2_get_subdevdata(sd);
80 - int ret;
81 + int ret = 0;
82
83 if (cfg->flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
84 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
85 - else
86 + else if (cfg->flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
87 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
88 if (ret)
89 - return ret;
90 + goto error;
91
92 if (cfg->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
93 ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
94 - else
95 + else if (cfg->flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
96 ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
97 if (ret)
98 - return ret;
99 + goto error;
100
101 if (cfg->flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
102 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
103 - else
104 + else if (cfg->flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
105 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
106
107 +error:
108 + /*
109 + * Update the configuration to report what is actually applied to
110 + * the hardware.
111 + */
112 + ov6650_get_mbus_config(sd, pad, cfg);
113 +
114 return ret;
115 }
116
117 @@ -956,8 +978,6 @@ static const struct v4l2_subdev_video_op
118 .s_stream = ov6650_s_stream,
119 .g_frame_interval = ov6650_g_frame_interval,
120 .s_frame_interval = ov6650_s_frame_interval,
121 - .g_mbus_config = ov6650_g_mbus_config,
122 - .s_mbus_config = ov6650_s_mbus_config,
123 };
124
125 static const struct v4l2_subdev_pad_ops ov6650_pad_ops = {
126 @@ -966,6 +986,8 @@ static const struct v4l2_subdev_pad_ops
127 .set_selection = ov6650_set_selection,
128 .get_fmt = ov6650_get_fmt,
129 .set_fmt = ov6650_set_fmt,
130 + .get_mbus_config = ov6650_get_mbus_config,
131 + .set_mbus_config = ov6650_set_mbus_config,
132 };
133
134 static const struct v4l2_subdev_ops ov6650_subdev_ops = {