diff mbox series

[v14,15/18] media: i2c: ds90ub953: Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK

Message ID 20230616135922.442979-16-tomi.valkeinen@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series i2c-atr and FPDLink | expand

Commit Message

Tomi Valkeinen June 16, 2023, 1:59 p.m. UTC
Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK flag to configure the CSI-2 RX
continuous/non-continuous clock register.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/i2c/ds90ub953.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko June 16, 2023, 2:33 p.m. UTC | #1
On Fri, Jun 16, 2023 at 04:59:19PM +0300, Tomi Valkeinen wrote:
> Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK flag to configure the CSI-2 RX
> continuous/non-continuous clock register.

...

>  	struct regmap		*regmap;

I forgot if we discussed this along with i2c_client *client nearby. Since I
reviewed Hans' patches the pure struct device *dev (instead of *client) might
make more sense, despite being duplicative with regmap associated device.

>  	u32			num_data_lanes;
> +	bool			non_cont_clk;
>  
>  	struct gpio_chip	gpio_chip;

And also try to place this as a first member and see (by using bloat-o-meter,
for example) if it saves bytes.

I'm wondering if we have tools like pahole but which suggests the better layout
based on the code generation... Maybe something along with clang?
Tomi Valkeinen June 19, 2023, 10:37 a.m. UTC | #2
On 16/06/2023 17:33, Andy Shevchenko wrote:
> On Fri, Jun 16, 2023 at 04:59:19PM +0300, Tomi Valkeinen wrote:
>> Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK flag to configure the CSI-2 RX
>> continuous/non-continuous clock register.
> 
> ...
> 
>>   	struct regmap		*regmap;
> 
> I forgot if we discussed this along with i2c_client *client nearby. Since I
> reviewed Hans' patches the pure struct device *dev (instead of *client) might
> make more sense, despite being duplicative with regmap associated device.
> 
>>   	u32			num_data_lanes;
>> +	bool			non_cont_clk;
>>   
>>   	struct gpio_chip	gpio_chip;
> 
> And also try to place this as a first member and see (by using bloat-o-meter,
> for example) if it saves bytes.
> 
> I'm wondering if we have tools like pahole but which suggests the better layout
> based on the code generation... Maybe something along with clang?

Isn't all this a bit on the side of pointless micro-optimizations? We're 
talking about possibly saving a few tens of bytes in a struct that's 
likely allocated a few times, by possibly messing up the (cosmetic) 
grouping and ordering of the fields in the struct?

If there's a common rule-of-thumb wrt. struct members that everyone 
should follow, I'm good with that and can change this accordingly. But 
just trying to hunt for a field order that happens to save a few bytes 
here... It doesn't sound like time well spent.

If things were perfect, this would be something the compiler would 
optimize, presuming the field ordering in the struct doesn't matter.

  Tomi
diff mbox series

Patch

diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index 5b586855c77b..f2e950a00d64 100644
--- a/drivers/media/i2c/ds90ub953.c
+++ b/drivers/media/i2c/ds90ub953.c
@@ -138,6 +138,7 @@  struct ub953_data {
 	struct regmap		*regmap;
 
 	u32			num_data_lanes;
+	bool			non_cont_clk;
 
 	struct gpio_chip	gpio_chip;
 
@@ -1140,6 +1141,9 @@  static int ub953_parse_dt(struct ub953_data *priv)
 
 	priv->num_data_lanes = nlanes;
 
+	priv->non_cont_clk = vep.bus.mipi_csi2.flags &
+			     V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
+
 	return 0;
 }
 
@@ -1202,7 +1206,7 @@  static int ub953_hw_init(struct ub953_data *priv)
 		return dev_err_probe(dev, ret, "i2c init failed\n");
 
 	ub953_write(priv, UB953_REG_GENERAL_CFG,
-		    UB953_REG_GENERAL_CFG_CONT_CLK |
+		    (priv->non_cont_clk ? 0 : UB953_REG_GENERAL_CFG_CONT_CLK) |
 		    ((priv->num_data_lanes - 1) << UB953_REG_GENERAL_CFG_CSI_LANE_SEL_SHIFT) |
 		    UB953_REG_GENERAL_CFG_CRC_TX_GEN_ENABLE);