linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Scally <djrscally@gmail.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linus.walleij@linaro.org,
	prabhakar.mahadev-lad.rj@bp.renesas.com,
	heikki.krogerus@linux.intel.com, dmitry.torokhov@gmail.com,
	laurent.pinchart+renesas@ideasonboard.com,
	kieran.bingham+renesas@ideasonboard.com,
	jacopo+renesas@jmondi.org, robh@kernel.org, davem@davemloft.net,
	linux@rasmusvillemoes.dk, andriy.shevchenko@linux.intel.com,
	sergey.senozhatsky@gmail.com, rostedt@goodmis.org,
	pmladek@suse.com, mchehab@kernel.org, tian.shu.qiu@intel.com,
	bingbu.cao@intel.com, sakari.ailus@linux.intel.com,
	yong.zhi@intel.com, rafael@kernel.org,
	gregkh@linuxfoundation.org, kitakar@gmail.com
Subject: Re: [RFC PATCH v3 9/9] ipu3-cio2: Add functionality allowing software_node connections to sensors on platforms designed for Windows
Date: Sat, 24 Oct 2020 21:28:07 +0100	[thread overview]
Message-ID: <18a3661c-4bee-7421-9121-acd65401cf16@gmail.com> (raw)
In-Reply-To: <20201024151458.GA3774@valkosipuli.retiisi.org.uk>

On 24/10/2020 16:14, Sakari Ailus wrote:
> Hi Daniel,
>
> Thanks for the update.
Thanks for the comments as always
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Author: Dan Scally <djrscally@gmail.com>
> /* Author: ... */
>
> But not the SPDX tag.
Weird - okedokey
>> +#include <linux/acpi.h>
>> +#include <linux/device.h>
>> +#include <linux/fwnode.h>
>> +#include <linux/i2c.h>
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/pci.h>
>> +#include <linux/property.h>
>> +#include <media/v4l2-subdev.h>
>> +
>> +#include "cio2-bridge.h"
>> +
>> +/*
>> + * Extend this array with ACPI Hardware ID's of devices known to be
>> + * working
>> + */
>> +static const char * const supported_devices[] = {
>> +	"INT33BE",
>> +	"OVTI2680",
>> +};
>> +
>> +static struct software_node cio2_hid_node = { CIO2_HID };
>> +
>> +static struct cio2_bridge bridge;
>> +
>> +static const char * const port_names[] = {
>> +	"port0", "port1", "port2", "port3"
>> +};
>> +
>> +static const struct property_entry remote_endpoints[] = {
> How about another dimension, for local and remote? Or make it a struct with
> local and remote fields. Perhaps a struct would be better?
>
> This could also be nicer to initialise in a function.
Sure; a struct probably would be cleaner I agree. I shall make that change
>> +static int create_fwnode_properties(struct sensor *sensor,
>> +				    struct sensor_bios_data *ssdb)
>> +{
>> +	struct property_entry *cio2_properties = sensor->cio2_properties;
>> +	struct property_entry *dev_properties = sensor->dev_properties;
>> +	struct property_entry *ep_properties = sensor->ep_properties;
>> +	int i;
>> +
>> +	/* device fwnode properties */
>> +	memset(dev_properties, 0, sizeof(struct property_entry) * 3);
> I'd put them all to the struct itself. Then the compiler will be able to
> check array indices.
Makes sense; I think I was just trying to save line length in the rest
of that function by that.
>> +
>> +	dev_properties[0] = PROPERTY_ENTRY_U32("clock-frequency",
>> +					       ssdb->mclkspeed);
>> +	dev_properties[1] = PROPERTY_ENTRY_U8("rotation", ssdb->degree);
>> +
>> +	/* endpoint fwnode properties */
>> +	memset(ep_properties, 0, sizeof(struct property_entry) * 4);
>> +
>> +	sensor->data_lanes = kmalloc_array(ssdb->lanes, sizeof(u32),
>> +					   GFP_KERNEL);
>> +
>> +	if (!sensor->data_lanes)
>> +		return -ENOMEM;
>> +
>> +	for (i = 0; i < ssdb->lanes; i++)
>> +		sensor->data_lanes[i] = i + 1;
>> +
>> +	ep_properties[0] = PROPERTY_ENTRY_U32("bus-type", 5);
>> +	ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN("data-lanes",
>> +							sensor->data_lanes,
>> +							ssdb->lanes);
>> +	ep_properties[2] = remote_endpoints[(bridge.n_sensors * 2) + ENDPOINT_SENSOR];
>> +
>> +	/* cio2 endpoint props */
>> +	memset(cio2_properties, 0, sizeof(struct property_entry) * 3);
>> +
>> +	cio2_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN("data-lanes",
>> +							  sensor->data_lanes,
>> +							  ssdb->lanes);
>> +	cio2_properties[1] = remote_endpoints[(bridge.n_sensors * 2) + ENDPOINT_CIO2];
>> +
>> +	return 0;
>> +}
>> +
>> +static int create_connection_swnodes(struct sensor *sensor,
>> +				     struct sensor_bios_data *ssdb)
>> +{
>> +	struct software_node *nodes = sensor->swnodes;
>> +
>> +	memset(nodes, 0, sizeof(struct software_node) * 6);
> Could you make the index an enum, and add an item to the end used to tell
> the number of entries. It could be called e.g. NR_OF_SENSOR_SWNODES.
Ooh I like that, it's neat; thanks - will do.
>> +int cio2_bridge_build(struct pci_dev *cio2)
>> +{
>> +	struct fwnode_handle *fwnode;
>> +	int ret;
>> +
>> +	pci_dev_get(cio2);
> Could you check that this isn't used by more than one user? The current
> implementation assumes that. I'm not sure if there could be more instances
> of CIO2 but if there were, that'd be an issue currently.

I can check; can't think of anything better than just failing out if it
turns out to be in use already though - any ideas or is that appropriate?

>> +struct sensor {
> How about calling this e.g. cio2_sensor? sensor is rather generic.
Yup, will probably prefix all such generically named vars with cio2_*
and functions with cio2_bridge_*().
>> +	char name[ACPI_ID_LEN];
>> +	struct device *dev;
>> +	struct acpi_device *adev;
>> +	struct software_node swnodes[6];
>> +	struct property_entry dev_properties[3];
>> +	struct property_entry ep_properties[4];
>> +	struct property_entry cio2_properties[3];
>> +	u32 *data_lanes;
> The maximum is four so you could as well make this static.
Ack
>> +};
>> +
>> +struct cio2_bridge {
>> +	int n_sensors;
> Do you need negative values? %u, too, if not.
I do not, I will switch to using unsigned.
>> diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
>> index f68ef0f6b..827457110 100644
>> --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
>> +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
>> @@ -1715,9 +1715,27 @@ static void cio2_queues_exit(struct cio2_device *cio2)
>>  static int cio2_pci_probe(struct pci_dev *pci_dev,
>>  			  const struct pci_device_id *id)
>>  {
>> +	struct fwnode_handle *endpoint;
>>  	struct cio2_device *cio2;
>>  	int r;
>>  
>> +	/*
>> +	 * On some platforms no connections to sensors are defined in firmware,
>> +	 * if the device has no endpoints then we can try to build those as
>> +	 * software_nodes parsed from SSDB.
>> +	 *
>> +	 * This may EPROBE_DEFER if supported devices are found defined in ACPI
>> +	 * but not yet ready for use (either not attached to the i2c bus yet,
>> +	 * or not done probing themselves).
>> +	 */
>> +
>> +	endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&pci_dev->dev), NULL);
>> +	if (!endpoint) {
>> +		r = cio2_bridge_build(pci_dev);
>> +		if (r)
>> +			return r;
>> +	}
> } else {
> 	fwnode_handle_put(endpoint);
> }
Ah, of course, thank you.

  reply	other threads:[~2020-10-24 20:28 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 22:58 [RFC PATCH v3 0/9] Add functionality to ipu3-cio2 driver allowing software_node connections to sensors on platforms designed for Windows Daniel Scally
2020-10-19 22:58 ` [RFC PATCH v3 1/9] software_node: Add helper function to unregister arrays of software_nodes ordered parent to child Daniel Scally
2020-10-20  9:22   ` Andy Shevchenko
2020-10-20 10:05   ` Sakari Ailus
2020-10-20 11:01     ` Andy Shevchenko
2020-10-20 11:02       ` Andy Shevchenko
2020-10-20 11:04       ` Heikki Krogerus
2020-10-20 22:52     ` Dan Scally
2020-10-21  9:40       ` Andy Shevchenko
2020-10-21  9:54         ` Dan Scally
2020-10-19 22:58 ` [RFC PATCH v3 2/9] lib/test_printf.c: Use helper function to unwind array of software_nodes Daniel Scally
2020-10-20  7:23   ` Petr Mladek
2020-10-20  9:20   ` Andy Shevchenko
2020-10-19 22:58 ` [RFC PATCH v3 3/9] software_node: Fix failure to hold refcount in software_node_get_next_child Daniel Scally
2020-10-20 12:44   ` Rafael J. Wysocki
2020-10-20 13:31   ` Sakari Ailus
2020-10-20 23:25     ` Dan Scally
2020-10-21  9:33       ` Andy Shevchenko
2020-10-21  9:37         ` Sakari Ailus
2020-10-21  9:56         ` Dan Scally
2020-10-19 22:58 ` [RFC PATCH v3 4/9] software_node: Add support for fwnode_graph*() family of functions Daniel Scally
2020-10-20  9:17   ` Andy Shevchenko
2020-10-20 12:35   ` Sakari Ailus
2020-10-20 13:32     ` Sakari Ailus
2020-10-19 22:58 ` [RFC PATCH v3 5/9] ipu3-cio2: Add T: entry to MAINTAINERS Daniel Scally
2020-10-20  9:16   ` Andy Shevchenko
2020-10-24  0:28   ` Laurent Pinchart
2020-10-19 22:59 ` [RFC PATCH v3 6/9] ipu3-cio2: Rename ipu3-cio2.c to allow module to be built from multiple sources files retaining ipu3-cio2 name Daniel Scally
2020-10-20  9:15   ` Andy Shevchenko
2020-10-20 20:41     ` Dan Scally
2020-10-24  0:34   ` Laurent Pinchart
2020-10-19 22:59 ` [RFC PATCH v3 7/9] ipu3-cio2: Check if pci_dev->dev's fwnode is a software_node in cio2_parse_firmware() and set FWNODE_GRAPH_DEVICE_DISABLED if so Daniel Scally
2020-10-20  9:19   ` Andy Shevchenko
2020-10-20 12:06     ` Sakari Ailus
2020-10-20 19:56       ` Dan Scally
2020-10-20 22:49         ` Sakari Ailus
2020-10-20 22:55           ` Dan Scally
2020-10-24  0:39           ` Laurent Pinchart
2020-10-24 14:29             ` Sakari Ailus
2020-10-24 16:33               ` Dan Scally
2020-10-24 16:55                 ` Laurent Pinchart
2020-10-19 22:59 ` [RFC PATCH v3 8/9] media: v4l2-core: v4l2-async: Check possible match in match_fwnode based on sd->fwnode->secondary Daniel Scally
2020-10-19 22:59 ` [RFC PATCH v3 9/9] ipu3-cio2: Add functionality allowing software_node connections to sensors on platforms designed for Windows Daniel Scally
2020-10-20  9:41   ` Andy Shevchenko
2020-10-21 22:05     ` Daniel Scally
2020-10-22 13:40       ` Andy Shevchenko
2020-10-23 10:06         ` Dan Scally
2020-10-24  1:24   ` Laurent Pinchart
2020-10-24  8:50     ` Dan Scally
2020-10-24  9:37       ` Laurent Pinchart
2020-10-24 22:28         ` Daniel Scally
2020-10-24 22:36           ` Laurent Pinchart
2020-10-24 22:50             ` Daniel Scally
2020-10-26  8:20             ` Dan Scally
2020-10-26 16:05               ` Andy Shevchenko
2020-10-29 20:17                 ` Laurent Pinchart
2020-10-29 22:36                   ` Dan Scally
2020-10-26 16:10         ` Andy Shevchenko
2020-10-29 20:19           ` Laurent Pinchart
2020-10-29 20:26             ` Andy Shevchenko
2020-10-29 21:29               ` Laurent Pinchart
2020-10-29 22:22                 ` Andy Shevchenko
2020-10-29 22:51                   ` Laurent Pinchart
2020-11-13 10:02                     ` Dan Scally
2020-11-13 16:22                       ` Laurent Pinchart
2020-11-13 19:45                         ` Andy Shevchenko
2020-11-15  8:45                           ` Daniel Scally
2020-11-16  8:53                           ` Laurent Pinchart
2020-11-16 13:57                             ` Andy Shevchenko
2020-11-16 14:10                               ` Laurent Pinchart
2020-11-16 14:15                                 ` Dan Scally
2020-11-16 16:16                                   ` Andy Shevchenko
2020-11-17 12:01                                     ` Dan Scally
2020-11-17 16:42                                       ` Andy Shevchenko
2020-11-17 22:59                                         ` Dan Scally
2020-10-24 15:11     ` Sakari Ailus
2020-10-24 15:14   ` Sakari Ailus
2020-10-24 20:28     ` Dan Scally [this message]
2020-10-25 11:18       ` Sakari Ailus
2020-10-20  9:24 ` [RFC PATCH v3 0/9] Add functionality to ipu3-cio2 driver " Andy Shevchenko
2020-10-20 13:38 ` Rafael J. Wysocki
2020-10-21 20:59   ` Daniel Scally

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=18a3661c-4bee-7421-9121-acd65401cf16@gmail.com \
    --to=djrscally@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=davem@davemloft.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=kitakar@gmail.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mchehab@kernel.org \
    --cc=pmladek@suse.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@intel.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;
as well as URLs for NNTP newsgroup(s).