media: i2c: imx219: Add support for 'clock-frequency' parsing
PATCH 1/1 media: i2c: imx219: Add support for 'clock-frequency' parsing
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/media/i2c/imx219.c +12 -2
@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) { + imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +if (imx219->xclk_freq !=IMX219_XCLK_FREQ ) return dev_err_probe(dev, -EINVAL, "xclk frequency not supported: %d Hz\n",
Signature · 1 line
2.48.1
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {
drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +
This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Some drivers will also need to control the clock, so the clock should probably be returned too.
Quoted 3 lines
drivers/media/i2c/imx219.c +0
-0if (imx219->xclk_freq !=IMX219_XCLK_FREQ ) return dev_err_probe(dev, -EINVAL, "xclk frequency not supported: %d Hz\n",
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 47 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
--
Kind Regards
Mehdi Djait
Sakari Ailus
maintainerHi Mehdi,
Quoted 50 lines · Mehdi Djait
Hi Laurent,
Quoted 47 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?
Signature · 3 lines
Regards, Sakari Ailus
Hi Sakari,
Quoted 57 lines · Sakari Ailus
Hi Mehdi,
Quoted 54 lines · Mehdi Djait
Hi Laurent,
Quoted 50 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Some drivers will also need to control the clock, so the clock should probably be returned too.
Quoted 7 lines
Quoted 3 lines
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?
I was thinking about drivers/media/v4l2-core/v4l2-fwnode.c but if v4l2-common.c is more appropriate we can go with that.
--
Kind Regards
Mehdi Djait
Sakari Ailus
maintainerHi Mehdi,
Quoted 62 lines · Mehdi Djait
Hi Sakari,
Quoted 59 lines · Sakari Ailus
Hi Mehdi,
Quoted 56 lines · Mehdi Djait
Hi Laurent,
Quoted 47 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.
That's my suggestion, yes.
Signature · 3 lines
Kind regards, Sakari Ailus
Hi,
Quoted 62 lines · Mehdi Djait
Hi Sakari,
Quoted 59 lines · Sakari Ailus
Hi Mehdi,
Quoted 56 lines · Mehdi Djait
Hi Laurent,
Quoted 47 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 26 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1121
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.
I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Tomi
Sakari Ailus
maintainerMoi,
Quoted 69 lines · Tomi Valkeinen
Hi,
Quoted 66 lines · Mehdi Djait
Hi Sakari,
Quoted 62 lines · Sakari Ailus
Hi Mehdi,
Quoted 48 lines · Mehdi Djait
Hi Laurent,
Quoted 45 lines · Laurent Pinchart
Hi Mehdi,
Thank you for the patch.
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?
Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Signature · 3 lines
Kind regards, Sakari Ailus
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Can ACPI devices support programmable sensor clock frequency ?
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerHi Laurent,
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Signature · 3 lines
Regards, Sakari Ailus
Quoted 76 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 73 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 4 lines
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
I mean external clock, and configurable at runtime.
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerHi Laurent,
Quoted 77 lines · Laurent Pinchart
Quoted 76 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 73 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
Signature · 3 lines
Regards, Sakari Ailus
Quoted 80 lines · Sakari Ailus
Quoted 79 lines · Laurent Pinchart
Quoted 78 lines · Sakari Ailus
Quoted 76 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Can ACPI devices support programmable sensor clock frequency ?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerHi Laurent,
Quoted 84 lines · Laurent Pinchart
Quoted 83 lines · Sakari Ailus
Quoted 82 lines · Laurent Pinchart
Quoted 80 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 24 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency' property when no clock producer is available
Signed-off-by Mehdi Djait <[email protected]>--- drivers/media/i2c/imx219.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/media/i2c/imx219.c +2
-2@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client) "failed to initialize CCI\n");/* Get system clock (xclk) */ - imx219->xclk =devm_clk_get (dev,NULL ); + imx219->xclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (imx219->xclk))return dev_err_probe (dev,PTR_ERR (imx219->xclk),"failed to get xclk\n" ); - imx219->xclk_freq =clk_get_rate (imx219->xclk); +if (imx219->xclk) {drivers/media/i2c/imx219.c static int imx219_probe(struct i2c_client *client) · line 1119
Quoted 10 lines
drivers/media/i2c/imx219.c +10
-0+ imx219->xclk_freq =clk_get_rate (imx219->xclk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &imx219->xclk_freq); +if (ret) +return dev_err_probe (dev, ret, +"failed to get clock frequency" ); + } +This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
That's an interesting idea.
It still could have potential to break something even if it may be unlikely. I don't know what others are doing with clocks (if anything) outside cameras on ACPI.
Maybe a case for an RFC? Doing this would be nice as we could get rid of one of the few remaining DT/ACPI differences in sensor drivers.
That being said, this should not hold back merging the patch.
Signature · 3 lines
Kind regards, Sakari Ailus
Quoted 98 lines · Sakari Ailus
Hi Laurent,
Quoted 84 lines · Laurent Pinchart
Quoted 83 lines · Sakari Ailus
Quoted 82 lines · Laurent Pinchart
Quoted 80 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
Quoted 34 lines · Mehdi Djait
Make the clock producer reference lookup optional
Add support for ACPI-based platforms by parsing the 'clock-frequency'
property when no clock producer is availableSigned-off-by: Mehdi Djait <[email protected]>
---
drivers/media/i2c/imx219.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 2d54cea113e1..a876a6d80a47 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client)
"failed to initialize CCI\n");
/* Get system clock (xclk) */
- imx219->xclk = devm_clk_get(dev, NULL);
+ imx219->xclk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(imx219->xclk))
return dev_err_probe(dev, PTR_ERR(imx219->xclk),
"failed to get xclk\n");
- imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ if (imx219->xclk) {
+ imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ } else {
+ ret = fwnode_property_read_u32(dev_fwnode(dev),
+ "clock-frequency",
+ &imx219->xclk_freq);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to get clock frequency");
+ }
+This doesn't seem specific to the imx219 driver. Could you turn this into a generic V4L2 sensor helper that would take a struct device and a clock name, and return the frequency, either retrieved from the clock, or from the clock-frequency property as a fallback ?
Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should probably be returned too.
Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
That's an interesting idea.
Quoted 8 lines
It still could have potential to break something even if it may be unlikely. I don't know what others are doing with clocks (if anything) outside cameras on ACPI.
Maybe a case for an RFC? Doing this would be nice as we could get rid of one of the few remaining DT/ACPI differences in sensor drivers.
That being said, this should not hold back merging the patch.
An RFC sounds good. For this specific patch, I think we agree we need a helper function. I wonder if the helper could register a fixed clock if there's no clocks property, that way we could easily change the implementation later while minimizing changes to drivers. Some sort of
struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *name);
that sensor drivers would call instead of devm_clk_get(). There may be issues I don't foresee though, but maybe worth trying ?
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent, Hi Sakari,
Quoted 113 lines · Laurent Pinchart
Quoted 98 lines · Sakari Ailus
Hi Laurent,
Quoted 84 lines · Laurent Pinchart
Quoted 83 lines · Sakari Ailus
Quoted 82 lines · Laurent Pinchart
Quoted 80 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 42 lines · Mehdi Djait
Quoted 41 lines · Laurent Pinchart
On Thu, Feb 20, 2025 at 04:49:09PM +0100, Mehdi Djait wrote:
Make the clock producer reference lookup optionalAdd support for ACPI-based platforms by parsing the 'clock-frequency'
property when no clock producer is availableSigned-off-by: Mehdi Djait <[email protected]>
---
drivers/media/i2c/imx219.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 2d54cea113e1..a876a6d80a47 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client)
"failed to initialize CCI\n");
/* Get system clock (xclk) */
- imx219->xclk = devm_clk_get(dev, NULL);
+ imx219->xclk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(imx219->xclk))
return dev_err_probe(dev, PTR_ERR(imx219->xclk),
"failed to get xclk\n");
- imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ if (imx219->xclk) {
+ imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ } else {
+ ret = fwnode_property_read_u32(dev_fwnode(dev),
+ "clock-frequency",
+ &imx219->xclk_freq);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to get clock frequency");
+ }
+This doesn't seem specific to the imx219 driver. Could you turn this
into a generic V4L2 sensor helper that would take a struct device and a
clock name, and return the frequency, either retrieved from the clock,
or from the clock-frequency property as a fallback ?Quoted 7 lines
Quoted 3 lines
Some drivers will also need to control the clock, so the clock should
probably be returned too.Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
That's an interesting idea.
Quoted 8 lines
It still could have potential to break something even if it may be unlikely. I don't know what others are doing with clocks (if anything) outside cameras on ACPI.
Maybe a case for an RFC? Doing this would be nice as we could get rid of one of the few remaining DT/ACPI differences in sensor drivers.
That being said, this should not hold back merging the patch.
An RFC sounds good. For this specific patch, I think we agree we need a helper function. I wonder if the helper could register a fixed clock if there's no clocks property, that way we could easily change the implementation later while minimizing changes to drivers. Some sort of
Quoted 5 lines
struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *name);
that sensor drivers would call instead of
devm_clk_get(). There may be issues I don't foresee though, but maybe worth trying ?
I will give it a try and eventually send patches.
Thanks everyone for all the answers.
--
Kind Regards
Mehdi Djait
Hi everyone,
Quoted 118 lines · Mehdi Djait
Hi Laurent, Hi Sakari,
Quoted 115 lines · Laurent Pinchart
Quoted 98 lines · Sakari Ailus
Hi Laurent,
Quoted 84 lines · Laurent Pinchart
Quoted 83 lines · Sakari Ailus
Quoted 82 lines · Laurent Pinchart
Quoted 80 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
Quoted 49 lines · Mehdi Djait
On Mon, Feb 24, 2025 at 01:06:49AM +0200, Laurent Pinchart wrote:
On Thu, Feb 20, 2025 at 04:49:09PM +0100, Mehdi Djait wrote:
Make the clock producer reference lookup optionalAdd support for ACPI-based platforms by parsing the 'clock-frequency'
property when no clock producer is availableSigned-off-by: Mehdi Djait <[email protected]>
---
drivers/media/i2c/imx219.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 2d54cea113e1..a876a6d80a47 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client)
"failed to initialize CCI\n");
/* Get system clock (xclk) */
- imx219->xclk = devm_clk_get(dev, NULL);
+ imx219->xclk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(imx219->xclk))
return dev_err_probe(dev, PTR_ERR(imx219->xclk),
"failed to get xclk\n");
- imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ if (imx219->xclk) {
+ imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ } else {
+ ret = fwnode_property_read_u32(dev_fwnode(dev),
+ "clock-frequency",
+ &imx219->xclk_freq);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to get clock frequency");
+ }
+This doesn't seem specific to the imx219 driver. Could you turn this
into a generic V4L2 sensor helper that would take a struct device and a
clock name, and return the frequency, either retrieved from the clock,
or from the clock-frequency property as a fallback ?Some drivers will also need to control the clock, so the clock should
probably be returned too.Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in
drivers/media/v4l2-core/v4l2-common.c. Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
That's an interesting idea.
Quoted 8 lines
It still could have potential to break something even if it may be unlikely. I don't know what others are doing with clocks (if anything) outside cameras on ACPI.
Maybe a case for an RFC? Doing this would be nice as we could get rid of one of the few remaining DT/ACPI differences in sensor drivers.
That being said, this should not hold back merging the patch.
An RFC sounds good. For this specific patch, I think we agree we need a helper function. I wonder if the helper could register a fixed clock if there's no clocks property, that way we could easily change the implementation later while minimizing changes to drivers. Some sort of
struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *name);
Quoted 7 lines
Quoted 3 lines
that sensor drivers would call instead of
devm_clk_get(). There may be issues I don't foresee though, but maybe worth trying ?I will give it a try and eventually send patches.
Thanks everyone for all the answers.
While looking around, I found the following:
- ClockInput resource added to ACPI v6.5: https://uefi.org/specs/ACPI/6.5/19_ASL_Reference.html#clockinput-clock-input-resource-descriptor-macro
- commit adding ClockInput resource to acpica: https://github.com/acpica/acpica/commit/661feab5ee01a34af95a389a18c82e79f1aba05a
- commit kernel upstream: 520d4a0ee5b6d9c7a1258ace6caa13a94ac35ef8 "ACPICA: add support
for ClockInput resource (v6.5)"
this does not mean we can use it: I found this out-of-tree patch to supports fixed clock sources
https://github.com/niyas-sait/linux-acpi/blob/main/0001-acpi-add-clock-bindings-for-fixed-clock-resources.patch
it was not sent to the acpi mailing list. It was mentioned in this
dicussion: https://lore.kernel.org/linux-kernel/[email protected]/
Another interesting link: https://linaro.atlassian.net/wiki/spaces/CLIENTPC/pages/28822175758/ACPI+Clock+Input+Resources
Anyway, things to look out for as it seems that people are working on this.
--
Kind Regards
Mehdi Djait
Sakari Ailus
maintainerHi Mehdi,
Quoted 141 lines · Mehdi Djait
Hi everyone,
Quoted 118 lines · Mehdi Djait
Hi Laurent, Hi Sakari,
Quoted 115 lines · Laurent Pinchart
Quoted 98 lines · Sakari Ailus
Hi Laurent,
Quoted 84 lines · Laurent Pinchart
Quoted 83 lines · Sakari Ailus
Quoted 82 lines · Laurent Pinchart
Quoted 80 lines · Sakari Ailus
Quoted 75 lines · Laurent Pinchart
Quoted 64 lines · Sakari Ailus
Quoted 57 lines · Tomi Valkeinen
Quoted 56 lines · Mehdi Djait
Quoted 54 lines · Sakari Ailus
On Mon, Feb 24, 2025 at 08:59:34AM +0100, Mehdi Djait wrote:
On Mon, Feb 24, 2025 at 01:06:49AM +0200, Laurent Pinchart wrote:
On Thu, Feb 20, 2025 at 04:49:09PM +0100, Mehdi Djait wrote:
Make the clock producer reference lookup optionalAdd support for ACPI-based platforms by parsing the 'clock-frequency'
property when no clock producer is availableSigned-off-by: Mehdi Djait <[email protected]>
---
drivers/media/i2c/imx219.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 2d54cea113e1..a876a6d80a47 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1103,12 +1103,22 @@ static int imx219_probe(struct i2c_client *client)
"failed to initialize CCI\n");
/* Get system clock (xclk) */
- imx219->xclk = devm_clk_get(dev, NULL);
+ imx219->xclk = devm_clk_get_optional(dev, NULL);
if (IS_ERR(imx219->xclk))
return dev_err_probe(dev, PTR_ERR(imx219->xclk),
"failed to get xclk\n");
- imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ if (imx219->xclk) {
+ imx219->xclk_freq = clk_get_rate(imx219->xclk);
+ } else {
+ ret = fwnode_property_read_u32(dev_fwnode(dev),
+ "clock-frequency",
+ &imx219->xclk_freq);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to get clock frequency");
+ }
+This doesn't seem specific to the imx219 driver. Could you turn this
into a generic V4L2 sensor helper that would take a struct device and a
clock name, and return the frequency, either retrieved from the clock,
or from the clock-frequency property as a fallback ?Some drivers will also need to control the clock, so the clock should
probably be returned too.Yes, I saw that many sensor drivers have the same issue.
I will try to make it into a generic V4L2 helper and send the patches.
There are other such functions in drivers/media/v4l2-core/v4l2-common.c.
Perhaps this is where the new helper could be located as well?Quoted 5 lines
Quoted 2 lines
I was thinking about
drivers/media/v4l2-core/v4l2-fwnode.cbut ifv4l2-common.cis more appropriate we can go with that.I admit I have no clue about ACPI, but why is this v4l2 specific? Why doesn't clock framework do this for us?
Quoted 9 lines
The "clock-frequency" isn't really specific to ACPI but it's used on some boards with DT, too, that precede the current clock bindings. Clocks aren't generally available to OS in ACPI either but the sensor drivers still need them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for Imaging code deep down in the ACPI framework will offer to drivers as "clock-frequency". A lot of this is actually specific to cameras. On top of that, camera sensors tend to be devices that are used equally on both DT and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the natural place for this code is actually the V4L2 framework.
Quoted 1 line
Can ACPI devices support programmable sensor clock frequency ?
Do you mean sensor's external clock or PLL? And do you mean programmable as configured in system firmware or at runtime?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I mean external clock, and configurable at runtime.
There's basically no standard API to change a clock's frequency at runtime (as there is no API to handle clocks) -- which is why we have a property instead of that presumed API.
I wonder, for ACPI devices that have a clock-frequency property, could we automatically register a fixed-frequency clock ?
That's an interesting idea.
Quoted 8 lines
It still could have potential to break something even if it may be unlikely. I don't know what others are doing with clocks (if anything) outside cameras on ACPI.
Maybe a case for an RFC? Doing this would be nice as we could get rid of one of the few remaining DT/ACPI differences in sensor drivers.
That being said, this should not hold back merging the patch.
An RFC sounds good. For this specific patch, I think we agree we need a helper function. I wonder if the helper could register a fixed clock if there's no clocks property, that way we could easily change the implementation later while minimizing changes to drivers. Some sort of
struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *name);
Quoted 7 lines
Quoted 3 lines
that sensor drivers would call instead of
devm_clk_get(). There may be issues I don't foresee though, but maybe worth trying ?I will give it a try and eventually send patches.
Thanks everyone for all the answers.
While looking around, I found the following:
- ClockInput resource added to ACPI v6.5: https://uefi.org/specs/ACPI/6.5/19_ASL_Reference.html#clockinput-clock-input-resource-descriptor-macro
- commit adding ClockInput resource to acpica: https://github.com/acpica/acpica/commit/661feab5ee01a34af95a389a18c82e79f1aba05a
- commit kernel upstream:520d4a0ee5b6d9c7a1258ace6caa13a94ac35ef8"ACPICA: add support
for ClockInput resource (v6.5)"this does not mean we can use it: I found this out-of-tree patch to supports fixed clock sources
https://github.com/niyas-sait/linux-acpi/blob/main/0001-acpi-add-clock-bindings-for-fixed-clock-resources.patch
it was not sent to the acpi mailing list. It was mentioned in this
dicussion: https://lore.kernel.org/linux-kernel/[email protected]/
Quoted 4 lines
Another interesting link: https://linaro.atlassian.net/wiki/spaces/CLIENTPC/pages/28822175758/ACPI+Clock+Input+Resources
Anyway, things to look out for as it seems that people are working on this.
Nice find. This doesn't answer to the existing needs but good to know there's work being done to support this.
I still think what Laurent suggested should be doable. Clocks based on properties just need to be parsed after resource descriptors, that's all it should take for the two to co-exist.
Signature · 3 lines
Regards, Sakari Ailus