public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Yassine Oudjana <y.oudjana@protonmail.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Bjorn Andersson" <andersson@kernel.org>,
	"Konrad Dybcio" <konradybcio@kernel.org>,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nicolas.schier@linux.dev>,
	"Alexander Sverdlin" <alexander.sverdlin@gmail.com>,
	"Sean Nyekjaer" <sean@geanix.com>,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
	"Matti Vaittinen" <mazziesaccount@gmail.com>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Ramona Gradinariu" <ramona.gradinariu@analog.com>,
	"Yo-Jung (Leo) Lin" <0xff07@gmail.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Barnabás Czémán" <barnabas.czeman@mainlining.org>,
	"Danila Tikhonov" <danila@jiaxyga.com>,
	"Antoni Pokusinski" <apokusinski01@gmail.com>,
	"Vasileios Amoiridis" <vassilisamir@gmail.com>,
	"Petar Stoykov" <pd.pstoykov@gmail.com>,
	"shuaijie wang" <wangshuaijie@awinic.com>,
	"Yasin Lee" <yasin.lee.x@gmail.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Pawan Gupta" <pawan.kumar.gupta@linux.intel.com>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Yassine Oudjana" <yassine.oudjana@gmail.com>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org,
	linux-kbuild@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: Add Qualcomm Sensor Manager drivers
Date: Sat, 12 Apr 2025 12:21:22 +0100	[thread overview]
Message-ID: <20250412122122.43d1b2a7@jic23-huawei> (raw)
In-Reply-To: <fc9af95b-abbf-454c-97e1-b884baa5317c@protonmail.com>

> >> +
> >> +static void qcom_smgr_accel_remove(struct platform_device *pdev)  
> > 
> > I'm surprised to see a platform device here - will read on but I
> > doubt that is the way to go.  Maybe an auxbus or similar or
> > just squashing this all down to be registered directly by
> > the parent driver.  
> I got the idea from cros_ec_sensors which also deals with a similar 
> sensor hub paradigm.

Generally the use of platform drivers for subfunctions of something
is now not considered the way to go.  Here there seems to be little
point in spinning out another layer of devices.
> >   
> >> +static void qcom_smgr_buffering_report_handler(struct qmi_handle *hdl,
> >> +					       struct sockaddr_qrtr *sq,
> >> +					       struct qmi_txn *txn,
> >> +					       const void *data)
> >> +{
> >> +	struct qcom_smgr *smgr =
> >> +		container_of(hdl, struct qcom_smgr, sns_smgr_hdl);
> >> +	struct sns_smgr_buffering_report_ind *ind =
> >> +		(struct sns_smgr_buffering_report_ind *)data;  
> > 
> > Casting away a const isn't a good sign. Why do you need to do that?
> > 	const struct sns_smg_buffer_repor_ind *ind = data;
> > should be fine I think.  
> 
> The casted struct was previously not const so I was only casting from 
> void *. I made it const lately but didn't notice this cast. Will change it.

Ok. But never a reason to cast from a void *.  The C spec says that
happens implicitly just fine.

> >> +	ret = qcom_smgr_request_all_sensor_info(smgr, &smgr->sensors);
> >> +	if (ret < 0) {
> >> +		dev_err(smgr->dev, "Failed to get available sensors: %pe\n",
> >> +			ERR_PTR(ret));
> >> +		return ret;
> >> +	}
> >> +	smgr->sensor_count = ret;
> >> +
> >> +	/* Get primary and secondary sensors from each sensor ID */
> >> +	for (i = 0; i < smgr->sensor_count; i++) {
> >> +		ret = qcom_smgr_request_single_sensor_info(smgr,
> >> +							   &smgr->sensors[i]);
> >> +		if (ret < 0) {
> >> +			dev_err(smgr->dev,
> >> +				"Failed to get sensors from ID 0x%02x: %pe\n",
> >> +				smgr->sensors[i].id, ERR_PTR(ret));
> >> +			return ret;
> >> +		}
> >> +
> >> +		for (j = 0; j < smgr->sensors[i].data_type_count; j++) {
> >> +			/* Default to maximum sample rate */
> >> +			smgr->sensors[i].data_types->cur_sample_rate =
> >> +				smgr->sensors[i].data_types->max_sample_rate;
> >> +
> >> +			dev_dbg(smgr->dev, "0x%02x,%d: %s %s\n",
> >> +				smgr->sensors[i].id, j,
> >> +				smgr->sensors[i].data_types[j].vendor,
> >> +				smgr->sensors[i].data_types[j].name);
> >> +		}
> >> +
> >> +		qcom_smgr_register_sensor(smgr, &smgr->sensors[i]);  
> > Above I suggest that maybe you should just skip the platform devices and register
> > directly with IIO as you find the sensors. So have the struct iio_dev->device
> > parent directly off this one.  
> 
> As I said previously I followed the model used in cros_ec_sensors, and 
> it made sense to me since I always see platform devices used to 
> represent firmware-backed devices like this.

In this case you end up with

parent device
    |
    |____________________
    |         |          |
ChildA     ChildB       ChildC  (all platform devices)
    |         |          |
IIODevA    IIODevB      IIODEVC

Today we'd probably do those child devices using auxiliary devices but
aside from that, the only reason to do this is you want to have separate
drivers for each child.

You can just do

parent device
   |
   |_______________________
   |         |             |
IIODevA    IIODevB       IIODevC

for the case where there no separate child drivers.

That is the parent driver can just instantiate the IIO Bus Devices
directly (it's kind of a Class really but a bus for historical reasons).
Various IMUs do this when they have separately controlled sampling frequencies
for different types of sensor or even separate fifos. (They are really
sensor hubs, just connected of SPI or similar).

So it's up to you whether you want the separate per channel type devices and
to handle the potential races around those going away.
qcom_smgr_buffering_report_handler() for instance needs a lock to
stop the child driver being unbound between the checks on iio_dev and the
use of it. With one driver that complexity doesn't occur.
See for example drivers/iio/st_lsm6dsx/ that does it this way.

Also possible would be a single IIO device with multiple buffers.
We only have a few of those though so you might run into missing bits of ABI
taking that path.

Jonathan



  reply	other threads:[~2025-04-12 11:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-06 14:07 [PATCH 0/3] QRTR bus and Qualcomm Sensor Manager IIO drivers Yassine Oudjana
2025-04-06 14:07 ` [PATCH 1/3] net: qrtr: Turn QRTR into a bus Yassine Oudjana
2025-04-06 16:01   ` Jonathan Cameron
2025-04-10 12:10     ` Yassine Oudjana
2025-04-12 10:58       ` Jonathan Cameron
2025-04-10 12:44     ` Yassine Oudjana
2025-04-12 10:59       ` Jonathan Cameron
2025-06-25 22:20     ` Yassine Oudjana
2025-04-06 14:07 ` [PATCH 2/3] net: qrtr: Define macro to convert QMI version and instance to QRTR instance Yassine Oudjana
2025-04-09 14:54   ` Konrad Dybcio
2025-07-05 18:29     ` Yassine Oudjana
2025-07-07 17:06       ` Simon Horman
2025-07-09  7:44         ` Yassine Oudjana
2025-07-09 11:52           ` Simon Horman
2025-04-06 14:08 ` [PATCH 3/3] iio: Add Qualcomm Sensor Manager drivers Yassine Oudjana
2025-04-06 16:29   ` Jonathan Cameron
2025-04-10 12:31     ` Yassine Oudjana
2025-04-12 11:21       ` Jonathan Cameron [this message]
2025-06-18 19:19   ` Luca Weiss
2025-06-25 17:09     ` Yassine Oudjana
2025-04-08 10:27 ` [PATCH 0/3] QRTR bus and Qualcomm Sensor Manager IIO drivers Luca Weiss

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=20250412122122.43d1b2a7@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=0xff07@gmail.com \
    --cc=alexander.sverdlin@gmail.com \
    --cc=andersson@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=antoniu.miclaus@analog.com \
    --cc=apokusinski01@gmail.com \
    --cc=barnabas.czeman@mainlining.org \
    --cc=bp@alien8.de \
    --cc=danila@jiaxyga.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=konradybcio@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=masahiroy@kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=mingo@kernel.org \
    --cc=nathan@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=pabeni@redhat.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=pd.pstoykov@gmail.com \
    --cc=ramona.gradinariu@analog.com \
    --cc=sean@geanix.com \
    --cc=tony.luck@intel.com \
    --cc=vassilisamir@gmail.com \
    --cc=wangshuaijie@awinic.com \
    --cc=y.oudjana@protonmail.com \
    --cc=yasin.lee.x@gmail.com \
    --cc=yassine.oudjana@gmail.com \
    /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