forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/i2c/tc35874x.c
....@@ -41,6 +41,7 @@
4141 #include <linux/v4l2-dv-timings.h>
4242 #include <linux/hdmi.h>
4343 #include <linux/version.h>
44
+#include <linux/compat.h>
4445 #include <linux/rk-camera-module.h>
4546 #include <media/v4l2-dv-timings.h>
4647 #include <media/v4l2-device.h>
....@@ -1517,7 +1518,7 @@
15171518 static irqreturn_t tc35874x_irq_handler(int irq, void *dev_id)
15181519 {
15191520 struct tc35874x_state *state = dev_id;
1520
- bool handled;
1521
+ bool handled = false;
15211522
15221523 tc35874x_isr(&state->sd, 0, &handled);
15231524
....@@ -1660,11 +1661,11 @@
16601661 }
16611662
16621663 static int tc35874x_g_mbus_config(struct v4l2_subdev *sd,
1663
- struct v4l2_mbus_config *cfg)
1664
+ unsigned int pad, struct v4l2_mbus_config *cfg)
16641665 {
16651666 struct tc35874x_state *state = to_state(sd);
16661667
1667
- cfg->type = V4L2_MBUS_CSI2;
1668
+ cfg->type = V4L2_MBUS_CSI2_DPHY;
16681669
16691670 /* Support for non-continuous CSI-2 clock is missing in the driver */
16701671 cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
....@@ -1747,8 +1748,7 @@
17471748 if (fie->index >= ARRAY_SIZE(supported_modes))
17481749 return -EINVAL;
17491750
1750
- if (fie->code != MEDIA_BUS_FMT_UYVY8_2X8)
1751
- return -EINVAL;
1751
+ fie->code = MEDIA_BUS_FMT_UYVY8_2X8;
17521752
17531753 fie->width = supported_modes[fie->index].width;
17541754 fie->height = supported_modes[fie->index].height;
....@@ -1997,8 +1997,11 @@
19971997 }
19981998
19991999 ret = tc35874x_ioctl(sd, cmd, inf);
2000
- if (!ret)
2000
+ if (!ret) {
20012001 ret = copy_to_user(up, inf, sizeof(*inf));
2002
+ if (ret)
2003
+ ret = -EFAULT;
2004
+ }
20022005 kfree(inf);
20032006 break;
20042007 case RKMODULE_AWB_CFG:
....@@ -2011,6 +2014,8 @@
20112014 ret = copy_from_user(cfg, up, sizeof(*cfg));
20122015 if (!ret)
20132016 ret = tc35874x_ioctl(sd, cmd, cfg);
2017
+ else
2018
+ ret = -EFAULT;
20142019 kfree(cfg);
20152020 break;
20162021 default:
....@@ -2048,7 +2053,6 @@
20482053 .s_dv_timings = tc35874x_s_dv_timings,
20492054 .g_dv_timings = tc35874x_g_dv_timings,
20502055 .query_dv_timings = tc35874x_query_dv_timings,
2051
- .g_mbus_config = tc35874x_g_mbus_config,
20522056 .s_stream = tc35874x_s_stream,
20532057 .g_frame_interval = tc35874x_g_frame_interval,
20542058 };
....@@ -2063,6 +2067,7 @@
20632067 .set_edid = tc35874x_s_edid,
20642068 .enum_dv_timings = tc35874x_enum_dv_timings,
20652069 .dv_timings_cap = tc35874x_dv_timings_cap,
2070
+ .get_mbus_config = tc35874x_g_mbus_config,
20662071 };
20672072
20682073 static const struct v4l2_subdev_ops tc35874x_ops = {
....@@ -2129,7 +2134,7 @@
21292134 static int tc35874x_probe_of(struct tc35874x_state *state)
21302135 {
21312136 struct device *dev = &state->i2c_client->dev;
2132
- struct v4l2_fwnode_endpoint *endpoint;
2137
+ struct v4l2_fwnode_endpoint endpoint = { .bus_type = 0 };
21332138 struct device_node *ep;
21342139 struct clk *refclk;
21352140 u32 bps_pr_lane;
....@@ -2149,21 +2154,21 @@
21492154 return -EINVAL;
21502155 }
21512156
2152
- endpoint = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep));
2153
- if (IS_ERR(endpoint)) {
2157
+ ret = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(ep), &endpoint);
2158
+ if (ret) {
21542159 dev_err(dev, "failed to parse endpoint\n");
2155
- return PTR_ERR(endpoint);
2160
+ goto put_node;
21562161 }
21572162
2158
- if (endpoint->bus_type != V4L2_MBUS_CSI2 ||
2159
- endpoint->bus.mipi_csi2.num_data_lanes == 0 ||
2160
- endpoint->nr_of_link_frequencies == 0) {
2163
+ if (endpoint.bus_type != V4L2_MBUS_CSI2_DPHY ||
2164
+ endpoint.bus.mipi_csi2.num_data_lanes == 0 ||
2165
+ endpoint.nr_of_link_frequencies == 0) {
21612166 dev_err(dev, "missing CSI-2 properties in endpoint\n");
21622167 goto free_endpoint;
21632168 }
21642169
2165
- state->csi_lanes_in_use = endpoint->bus.mipi_csi2.num_data_lanes;
2166
- state->bus = endpoint->bus.mipi_csi2;
2170
+ state->csi_lanes_in_use = endpoint.bus.mipi_csi2.num_data_lanes;
2171
+ state->bus = endpoint.bus.mipi_csi2;
21672172
21682173 ret = clk_prepare_enable(refclk);
21692174 if (ret) {
....@@ -2196,7 +2201,7 @@
21962201 * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps.
21972202 * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60.
21982203 */
2199
- bps_pr_lane = 2 * endpoint->link_frequencies[0];
2204
+ bps_pr_lane = 2 * endpoint.link_frequencies[0];
22002205 if (bps_pr_lane < 62500000U || bps_pr_lane > 1000000000U) {
22012206 dev_err(dev, "unsupported bps per lane: %u bps\n", bps_pr_lane);
22022207 goto disable_clk;
....@@ -2242,7 +2247,9 @@
22422247 disable_clk:
22432248 clk_disable_unprepare(refclk);
22442249 free_endpoint:
2245
- v4l2_fwnode_endpoint_free(endpoint);
2250
+ v4l2_fwnode_endpoint_free(&endpoint);
2251
+put_node:
2252
+ of_node_put(ep);
22462253 return ret;
22472254 }
22482255 #else