1 From 3b21da2334113027d91829e1fabe332cf21522a3 Mon Sep 17 00:00:00 2001
2 From: Daniel Scally <djrscally@gmail.com>
3 Date: Tue, 15 Feb 2022 23:07:31 +0000
4 Subject: [PATCH] media: i2c: Provide ov7251_check_hwcfg()
6 Move the endpoint checking from .probe() to a dedicated function,
7 and additionally check that the firmware provided link frequencies
8 are a match for those supported by the driver. Finally, return
9 -EPROBE_DEFER if the endpoint is not available, as it could be built
10 by the ipu3-cio2 driver if that probes later.
12 Signed-off-by: Daniel Scally <djrscally@gmail.com>
14 drivers/media/i2c/ov7251.c | 84 ++++++++++++++++++++++++++++++--------
15 1 file changed, 66 insertions(+), 18 deletions(-)
17 --- a/drivers/media/i2c/ov7251.c
18 +++ b/drivers/media/i2c/ov7251.c
19 @@ -1255,11 +1255,74 @@ static const struct v4l2_subdev_ops ov72
20 .pad = &ov7251_subdev_pad_ops,
23 +static int ov7251_check_hwcfg(struct ov7251 *ov7251)
25 + struct fwnode_handle *fwnode = dev_fwnode(ov7251->dev);
26 + struct v4l2_fwnode_endpoint bus_cfg = {
27 + .bus_type = V4L2_MBUS_CSI2_DPHY,
29 + struct fwnode_handle *endpoint;
34 + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
36 + return -EPROBE_DEFER; /* could be provided by cio2-bridge */
38 + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &bus_cfg);
39 + fwnode_handle_put(endpoint);
41 + return dev_err_probe(ov7251->dev, ret,
42 + "parsing endpoint node failed\n");
44 + if (bus_cfg.bus_type != V4L2_MBUS_CSI2_DPHY) {
46 + dev_err(ov7251->dev, "invalid bus type (%u), must be (%u)\n",
47 + bus_cfg.bus_type, V4L2_MBUS_CSI2_DPHY);
48 + goto out_free_bus_cfg;
51 + if (bus_cfg.bus.mipi_csi2.num_data_lanes != 1) {
52 + dev_err(ov7251->dev, "only a 1-lane CSI2 config is supported");
54 + goto out_free_bus_cfg;
57 + if (!bus_cfg.nr_of_link_frequencies) {
58 + dev_err(ov7251->dev, "no link frequencies defined\n");
60 + goto out_free_bus_cfg;
64 + for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) {
68 + for (j = 0; j < ARRAY_SIZE(link_freq); j++)
69 + if (bus_cfg.link_frequencies[i] == link_freq[j]) {
75 + if (i == bus_cfg.nr_of_link_frequencies) {
76 + dev_err(ov7251->dev, "no supported link freq found\n");
78 + goto out_free_bus_cfg;
82 + v4l2_fwnode_endpoint_free(&bus_cfg);
87 static int ov7251_probe(struct i2c_client *client)
89 struct v4l2_fwnode_device_properties props;
90 struct device *dev = &client->dev;
91 - struct fwnode_handle *endpoint;
92 struct ov7251 *ov7251;
93 u8 chip_id_high, chip_id_low, chip_rev;
95 @@ -1271,24 +1334,9 @@ static int ov7251_probe(struct i2c_clien
96 ov7251->i2c_client = client;
99 - endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
101 - dev_err(dev, "endpoint node not found\n");
105 - ret = v4l2_fwnode_endpoint_parse(endpoint, &ov7251->ep);
106 - fwnode_handle_put(endpoint);
108 - dev_err(dev, "parsing endpoint node failed\n");
109 + ret = ov7251_check_hwcfg(ov7251);
114 - if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
115 - dev_err(dev, "invalid bus type (%u), must be CSI2 (%u)\n",
116 - ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY);
120 /* get system clock (xclk) */
121 ov7251->xclk = devm_clk_get(dev, "xclk");