mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Wolfram Sang" <wsa@kernel.org>,
	"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
	"Matti Vaittinen" <Matti.Vaittinen@fi.rohmeurope.com>,
	"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Peter Rosin" <peda@axentia.se>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Michael Tretter" <m.tretter@pengutronix.de>,
	"Shawn Tu" <shawnx.tu@intel.com>,
	"Hans Verkuil" <hverkuil@xs4all.nl>,
	"Mike Pagano" <mpagano@gentoo.org>,
	"Krzysztof Hałasa" <khalasa@piap.pl>,
	"Marek Vasut" <marex@denx.de>,
	"Satish Nagireddy" <satish.nagireddy@getcruise.com>
Subject: Re: [PATCH v9 0/8] i2c-atr and FPDLink
Date: Thu, 16 Feb 2023 17:53:19 +0200	[thread overview]
Message-ID: <Y+5Rb17FTG4IxcE0@smile.fi.intel.com> (raw)
In-Reply-To: <20230216140747.445477-1-tomi.valkeinen@ideasonboard.com>

On Thu, Feb 16, 2023 at 04:07:39PM +0200, Tomi Valkeinen wrote:

...

> +	if (!c2a)

I would expect here dev_warn() to let user know about "shouldn't happened, but
have happened" situation.

> +		return; /* This shouldn't happen */

...

> -	static const struct v4l2_mbus_framefmt format = {
> +	static const struct v4l2_mbus_framefmt informat = {

Naming a bit confusing. Is it "information" that cut or what?

in_format

> +	static const struct v4l2_mbus_framefmt outformat = {

out_format

...

> -out_unlock:
> +out:

Why?

...

> +/*
> + * (Possible) TODOs

TODOs:

> + *
> + * - PM for serializer and remote peripherals. We need to manage:
> + *   - VPOC
> + *     - Power domain? Regulator? Somehow any remote device should be able to
> + *       cause the VPOC to be turned on.
> + *   - Link between the deserializer and the serializer
> + *     - Related to VPOC management. We probably always want to turn on the VPOC
> + *       and then enable the link.
> + *   - Serializer's services: i2c, gpios, power
> + *     - The serializer needs to resume before the remote peripherals can
> + *       e.g. use the i2c.
> + *     - How to handle gpios? Reserving a gpio essentially keeps the provider
> + *       (serializer) always powered on.
> + * - Do we need a new bus for the FPD-Link? At the moment the serializers
> + *   are children of the same i2c-adapter where the deserializer resides.
> + * - i2c-atr could be made embeddable instead of allocatable.
> + */

...

>  struct atr_alias_table_entry {
>  	u16 alias_id;	/* Alias ID from DT */
>  
> -	bool reserved;
> +	bool in_use;
>  	u8 nport;
>  	u8 slave_id;	/* i2c client's local i2c address */
>  	u8 port_reg_idx;

Wouldn't be wiser to move boolean at the end so if any obscure
architecture/compiler makes it longer than a byte it won't increase the memory
footprint. (Actually wouldn't it be aligned to u16 followed by u8 as well as
they are different types?)

>  };

...

> +static int ub960_read16(struct ub960_data *priv, u8 reg, u16 *val)
> +{
> +	struct device *dev = &priv->client->dev;
> +	unsigned int v1, v2;
> +	int ret;
> +
> +	mutex_lock(&priv->reg_lock);
> +
> +	ret = regmap_read(priv->regmap, reg, &v1);
> +	if (ret) {
> +		dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n",
> +			__func__, reg, ret);
> +		goto out_unlock;
> +	}
> +
> +	ret = regmap_read(priv->regmap, reg + 1, &v2);
> +	if (ret) {
> +		dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n",
> +			__func__, reg + 1, ret);
> +		goto out_unlock;
> +	}

Wondering why bulk read can't be used against properly typed __be16 variable?

> +	*val = (v1 << 8) | v2;

+ be16_to_cpu() here.

> +out_unlock:
> +	mutex_unlock(&priv->reg_lock);
> +
> +	return ret;
> +}

...

> +static int ub960_rxport_read16(struct ub960_data *priv, u8 nport, u8 reg,
> +			       u16 *val)
>  {

Ditto.

> +}

...

>  	struct i2c_board_info ser_info = {
> -		.of_node = to_of_node(rxport->remote_fwnode),
> -		.fwnode = rxport->remote_fwnode,

> +		.of_node = to_of_node(rxport->ser.fwnode),
> +		.fwnode = rxport->ser.fwnode,

Why do you need to have both?!

>  		.platform_data = ser_pdata,
>  	};

...

> +	for (nport = 0; nport < priv->hw_data->num_rxports; ++nport) {

Pre-increment is non-standard in the kernel.

> +		struct ub960_rxport *rxport = priv->rxports[nport];
> +		struct v4l2_mbus_frame_desc desc;
> +		int ret;
> +		u8 cur_vc;
> +
> +		if (!rxport)
> +			continue;
> +
> +		ret = v4l2_subdev_call(rxport->source.sd, pad, get_frame_desc,
> +				       rxport->source.pad, &desc);
> +		if (ret)
> +			return ret;
> +
> +		if (desc.type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2)
> +			continue;

		cur_vc = desc.entry[0].bus.csi2.vc;

> +		for (i = 0; i < desc.num_entries; ++i) {
> +			u8 vc = desc.entry[i].bus.csi2.vc;

> +			if (i == 0) {
> +				cur_vc = vc;
> +				continue;
> +			}

This is an invariant to the loop, see above.

> +			if (vc == cur_vc)
> +				continue;
> +
> +			dev_err(&priv->client->dev,
> +				"rx%u: source with multiple virtual-channels is not supported\n",
> +				nport);
> +			return -ENODEV;
> +		}
> +	}

...

> +	for (i = 0; i < 6; ++i)
>  		ub960_read(priv, UB960_SR_FPD3_RX_ID(i), &id[i]);
>  	id[6] = 0;

Wondering if this magic can be defined.

...

> +	priv->atr.aliases = devm_kcalloc(dev, table_size,
> +					 sizeof(struct atr_alias_table_entry),

	sizeof(*priv->atr.aliases) ?

> +					 GFP_KERNEL);
> +	if (!priv->atr.aliases)
>  		return -ENOMEM;

...

>  	if (ret) {
>  		if (ret != -EINVAL) {
> -			dev_err(dev,
> -				"rx%u: failed to read 'ti,strobe-pos': %d\n",
> -				nport, ret);
> +			dev_err(dev, "rx%u: failed to read '%s': %d\n", nport,
> +				"ti,strobe-pos", ret);
>  			return ret;
>  		}
>  	} else if (strobe_pos < UB960_MIN_MANUAL_STROBE_POS ||
> @@ -3512,8 +3403,8 @@ ub960_parse_dt_rxport_link_properties(struct ub960_data *priv,
>  	ret = fwnode_property_read_u32(link_fwnode, "ti,eq-level", &eq_level);
>  	if (ret) {
>  		if (ret != -EINVAL) {
> -			dev_err(dev, "rx%u: failed to read 'ti,eq-level': %d\n",
> -				nport, ret);
> +			dev_err(dev, "rx%u: failed to read '%s': %d\n", nport,
> +				"ti,eq-level", ret);
>  			return ret;
>  		}
>  	} else if (eq_level > UB960_MAX_EQ_LEVEL) {


Seems like you may do (in both cases) similar to the above:

	var = 0;
	ret = read_u32();
	if (ret && ret != -EINVAL) {
		// error handling
	}
	if (var > limit) {
		// another error handling
	}

...

> +	static const char *vpoc_names[UB960_MAX_RX_NPORTS] = { "vpoc0", "vpoc1",
> +							       "vpoc2", "vpoc3" };

Wouldn't be better to format it as

	static const char *vpoc_names[UB960_MAX_RX_NPORTS] = {
		"vpoc0", "vpoc1", "vpoc2", "vpoc3",
	};

?

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2023-02-16 15:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 14:07 Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 1/8] i2c: add I2C Address Translator (ATR) support Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 2/8] media: subdev: Split V4L2_SUBDEV_ROUTING_NO_STREAM_MIX Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 3/8] dt-bindings: media: add TI DS90UB913 FPD-Link III Serializer Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 4/8] dt-bindings: media: add TI DS90UB953 " Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 5/8] dt-bindings: media: add TI DS90UB960 FPD-Link III Deserializer Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 6/8] media: i2c: add DS90UB960 driver Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 7/8] media: i2c: add DS90UB913 driver Tomi Valkeinen
2023-02-16 14:07 ` [PATCH v9 8/8] media: i2c: add DS90UB953 driver Tomi Valkeinen
2023-02-16 15:53 ` Andy Shevchenko [this message]
2023-02-17  6:57   ` [PATCH v9 0/8] i2c-atr and FPDLink Tomi Valkeinen
2023-02-17 11:24     ` Andy Shevchenko
2023-02-17 12:57       ` Tomi Valkeinen
2023-02-17 13:45         ` Andy Shevchenko
2023-03-02 15:52           ` Tomi Valkeinen
2023-03-02 16:16             ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y+5Rb17FTG4IxcE0@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=Matti.Vaittinen@fi.rohmeurope.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hverkuil@xs4all.nl \
    --cc=khalasa@piap.pl \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=m.tretter@pengutronix.de \
    --cc=marex@denx.de \
    --cc=mchehab@kernel.org \
    --cc=mpagano@gentoo.org \
    --cc=peda@axentia.se \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=satish.nagireddy@getcruise.com \
    --cc=shawnx.tu@intel.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®