Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: i2c: s5k5baf: Use V4L2 legacy sensor clock helper

Several camera sensor drivers access the "clock-frequency" property
directly to retrieve the external clock rate, or modify the clock rate
of the external clock programmatically. Both behaviours are valid on a
subset of ACPI platforms, but are considered deprecated on OF platforms,
and do not support ACPI platforms that implement MIPI DisCo for Imaging.
Implementing them manually in drivers is deprecated, as that can
encourage copying deprecated behaviour for OF platforms in new drivers,
and lead to differences in behaviour between drivers. Instead, drivers
that need to preserve the deprecated OF behaviour should use the
devm_v4l2_sensor_clk_get_legacy() helper.

This driver supports OF platforms only. The "clocks" property has always
been specified as mandatory in the DT bindings and the "clock-frequency"
property has always been optional. Both properties were initially set in
the upstream DT sources. The driver retrieves the clock, retrieves the
clock rate from the "clock-frequency" property if available or uses a
fixed default otherwise, and sets the clock rate. This is deprecated
behaviour for OF.

Switch to using the devm_v4l2_sensor_clk_get_legacy() helper. This
preserves setting the clock rate on OF platforms. Should support for OF
platforms that set the clock rate through clock-frequency be considered
unneeded in the future, the driver will only need to switch to
devm_v4l2_sensor_clk_get() without any other change.

For all meaningful purposes, devm_v4l2_sensor_clk_get_legacy() returns
-EPROBE_DEFER in situations when the driver would want to defer probing.
Replace the hardcoded -EPROBE_DEFER error with propagating the error
code from devm_v4l2_sensor_clk_get_legacy().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
5bf86863 75b5888a

+5 -16
+5 -16
drivers/media/i2c/s5k5baf.c
··· 284 284 struct regulator_bulk_data supplies[S5K5BAF_NUM_SUPPLIES]; 285 285 286 286 struct clk *clock; 287 - u32 mclk_frequency; 288 287 289 288 struct s5k5baf_fw *fw; 290 289 ··· 575 576 576 577 static void s5k5baf_hw_set_clocks(struct s5k5baf *state) 577 578 { 578 - unsigned long mclk = state->mclk_frequency / 1000; 579 + unsigned long mclk = clk_get_rate(state->clock) / 1000; 579 580 u16 status; 580 581 static const u16 nseq_clk_cfg[] = { 581 582 NSEQ(REG_I_USE_NPVI_CLOCKS, ··· 944 945 ret = regulator_bulk_enable(S5K5BAF_NUM_SUPPLIES, state->supplies); 945 946 if (ret < 0) 946 947 goto err; 947 - 948 - ret = clk_set_rate(state->clock, state->mclk_frequency); 949 - if (ret < 0) 950 - goto err_reg_dis; 951 948 952 949 ret = clk_prepare_enable(state->clock); 953 950 if (ret < 0) ··· 1836 1841 return -EINVAL; 1837 1842 } 1838 1843 1839 - ret = of_property_read_u32(node, "clock-frequency", 1840 - &state->mclk_frequency); 1841 - if (ret < 0) { 1842 - state->mclk_frequency = S5K5BAF_DEFAULT_MCLK_FREQ; 1843 - dev_info(dev, "using default %u Hz clock frequency\n", 1844 - state->mclk_frequency); 1845 - } 1846 - 1847 1844 node_ep = of_graph_get_endpoint_by_regs(node, 0, -1); 1848 1845 if (!node_ep) { 1849 1846 dev_err(dev, "no endpoint defined at node %pOF\n", node); ··· 1954 1967 if (ret < 0) 1955 1968 goto err_me; 1956 1969 1957 - state->clock = devm_v4l2_sensor_clk_get(state->sd.dev, S5K5BAF_CLK_NAME); 1970 + state->clock = devm_v4l2_sensor_clk_get_legacy(state->sd.dev, 1971 + S5K5BAF_CLK_NAME, false, 1972 + S5K5BAF_DEFAULT_MCLK_FREQ); 1958 1973 if (IS_ERR(state->clock)) { 1959 - ret = -EPROBE_DEFER; 1974 + ret = PTR_ERR(state->clock); 1960 1975 goto err_me; 1961 1976 } 1962 1977