Add functionality to ipu3-cio2 driver allowing software_node connections to sensors on platforms designed for Windows
Subsystems (2)
RFC PATCH v2 1/1 Add functionality to ipu3-cio2 driver allowing software_node connections to sensors on platforms designed for Windows
Currently on platforms designed for Windows, connections between CIO2 and sensors are not properly defined in DSDT. This patch extends the ipu3-cio2 driver to compensate by building software_node connections, parsing the connection properties from the sensor's SSDB buffer.
---
This patch is dependent on another (which implements the software node graph family of functions):
https://lore.kernel.org/linux-media/[email protected]/
Major changes for the v2 (on top of a myriad of fixes probably too minor to call out - thank you everybody for the comments)
* Built against media_tree instead of linus's tree - there's no T: entry in maintainers for the ipu3-cio2 driver but I see there're recent changes in media_tree so thought this was the better option.
* Moved from a separate module to integrating the changes into the ipu3-cio2 driver itself.
There was some difference of opinion about the desirability of this, but I think that this option won out. I have attempted to address the concerns about bloating everyone's kernel by conditionally compiling the extension in based on config settings; although I don't have an ipu3 device that doesn't need these changes (so haven't been able to test that properly) - it certainly seems to be working as expected.
Compiling things in like this did require renaming either the module or the ipu3-cio2.c file, I chose the module to keep patch size down - let me know if that was the wrong choice.
* Error handling has been switched so each function cleans itself up properly rather than one single "clean up everything" function.
* Indentation fixed for create_endpoint_properties()
* Creation of the software_nodes moved to its own function
* Clock frequency property moved to the device fwnode instead of the endpoint's
* Reprobe of the sensors added at the end of connect_supported_devices(). This is needed to allow probe() calls from the drivers to pick up new properties. This required some unusual behaviour; because we're overwriting the fwnode of the device ACPI device to driver matching will no longer work. To work around that, I'm cloning the driver but adding an i2c_device_id table to it so that fallback i2c matching works. This driver is unregistered if the module is removed. I don't especially like this solution, but I couldn't see a better way to solve this problem.
Suggested changes that I didn't make:
Sakari - link-frequencies doesn't seem to be available in the SSDB buffer or anywhere else that I can see in DSDT unfortunately, so I didn't add that as a property. Also, I left the iterator as an int until that discussion came to a conclusive answer.
MAINTAINERS | 1 + drivers/media/pci/intel/ipu3/Kconfig | 15 + drivers/media/pci/intel/ipu3/Makefile | 8 +- drivers/media/pci/intel/ipu3/cio2-bridge.c | 433 +++++++++++++++++++++ drivers/media/pci/intel/ipu3/cio2-bridge.h | 110 ++++++ drivers/media/pci/intel/ipu3/ipu3-cio2.c | 21 + drivers/media/pci/intel/ipu3/ipu3-cio2.h | 18 + 7 files changed, 605 insertions(+), 1 deletion(-) create mode 100644 drivers/media/pci/intel/ipu3/cio2-bridge.c create mode 100644 drivers/media/pci/intel/ipu3/cio2-bridge.h
MAINTAINERS +1 -0
@@ -8848,6 +8848,7 @@ INTEL IPU3 CSI-2 CIO2 DRIVER M: Yong Zhi <[email protected]> M: Sakari Ailus <[email protected]> M: Bingbu Cao <[email protected]> +M: Dan Scally <[email protected]> R: Tianshu Qiu <[email protected]> L: [email protected] S: Maintained
drivers/media/pci/intel/ipu3/Kconfig +15 -0
@@ -16,3 +16,18 @@ config VIDEO_IPU3_CIO2 Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 connected camera. The module will be called ipu3-cio2. + +config CIO2_BRIDGE + bool "IPU3 CIO2 Sensors Bridge" + depends on VIDEO_IPU3_CIO2 + help + This extension provides an API for the ipu3-cio2 driver to create + connections to cameras that are hidden in SSDB buffer in ACPI. It + can be used to enable support for cameras in detachable / hybrid + devices that ship with Windows. + + Say y here if your device is a detachable / hybrid laptop that comes + with Windows installed by the OEM, for example the Microsoft Surface + line, Lenovo Miix line or Dell 7285. + + If in doubt, say n here.
drivers/media/pci/intel/ipu3/Makefile +7 -1
@@ -1,2 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o +obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2-driver.o + +ipu3-cio2-driver-objs += ipu3-cio2.o + +ifeq ($(CONFIG_CIO2_BRIDGE), y) +ipu3-cio2-driver-objs += cio2-bridge.o +endif
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +433 -0
433 lines not on this page · raw message
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +110 -0
110 lines not on this page · raw message
drivers/media/pci/intel/ipu3/ipu3-cio2.c +21 -0
@@ -1711,8 +1711,26 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) {struct cio2_device *cio2; +struct fwnode_handle *endpoint;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 (pci_dev->dev.fwnode,NULL ); +if (!endpoint) { + r =cio2_bridge_build (pci_dev); +if (r) +return r; + } + cio2 =devm_kzalloc (&pci_dev->dev,sizeof (*cio2),GFP_KERNEL );if (!cio2)return -ENOMEM ;
@@ -1820,6 +1838,9 @@ static void cio2_pci_remove(struct pci_dev *pci_dev) {struct cio2_device *cio2 =pci_get_drvdata (pci_dev); +if (is_software_node (pci_dev->dev.fwnode)) +cio2_bridge_burn (pci_dev); +media_device_unregister (&cio2->media_dev);v4l2_async_notifier_unregister (&cio2->notifier);v4l2_async_notifier_cleanup (&cio2->notifier);
drivers/media/pci/intel/ipu3/ipu3-cio2.h +18 -0
@@ -436,4 +436,22 @@ static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq) return container_of(vq, struct cio2_queue, vbq); } +#ifdef CONFIG_CIO2_BRIDGE + +int cio2_bridge_build (struct pci_dev *cio2); +void cio2_bridge_burn (struct pci_dev *cio2); + +#else + +int cio2_bridge_build (struct pci_dev *cio2) +{ +return 0 ; +} + +void cio2_bridge_burn (struct pci_dev *cio2) +{ +} + +#endif +#endif
Signature · 1 line
2.17.1
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20200930]
[cannot apply to linus/master sparc-next/master v5.9-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Scally/Add-functionality-to-ipu3-cio2-driver-allowing-software_node-connections-to-sensors-on-platforms-designed-for-Windows/20201001-173514 base: git://linuxtv.org/media_tree.git master config: alpha-allyesconfig (attached as .config) compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/0b4280b9a2af4e6b29ec3c9bb5f8d004873e8550
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Scally/Add-functionality-to-ipu3-cio2-driver-allowing-software_node-connections-to-sensors-on-platforms-designed-for-Windows/20201001-173514 git checkout 0b4280b9a2af4e6b29ec3c9bb5f8d004873e8550
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/media/pci/intel/ipu3/cio2-bridge.c: In function 'cio2_bridge_reprobe_sensor':
>> drivers/media/pci/intel/ipu3/cio2-bridge.c:227:21: warning: variable 'client' set but not used [-Wunused-but-set-variable]
227 | struct i2c_client *client;
| ^~~~~~
drivers/media/pci/intel/ipu3/cio2-bridge.c: At top level:
>> drivers/media/pci/intel/ipu3/cio2-bridge.c:370:5: warning: no previous prototype for 'cio2_bridge_build' [-Wmissing-prototypes]
370 | int cio2_bridge_build(struct pci_dev *cio2)
| ^~~~~~~~~~~~~~~~~
>> drivers/media/pci/intel/ipu3/cio2-bridge.c:424:6: warning: no previous prototype for 'cio2_bridge_burn' [-Wmissing-prototypes]
424 | void cio2_bridge_burn(struct pci_dev *cio2)
| ^~~~~~~~~~~~~~~~
drivers/media/pci/intel/ipu3/cio2-bridge.c: In function 'cio2_bridge_unregister_sensors':
>> drivers/media/pci/intel/ipu3/cio2-bridge.c:214:3: warning: ignoring return value of 'device_reprobe', declared with attribute warn_unused_result [-Wunused-result]
214 | device_reprobe(sensor->dev);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/client +227 drivers/media/pci/intel/ipu3/cio2-bridge.c
192
193 static void cio2_bridge_unregister_sensors(void)
194 {
195 int i, j;
196 struct sensor *sensor;
197
198 for (i = 0; i < bridge.n_sensors; i++) {
199 sensor = &bridge.sensors[i];
200
201 for (j = 4; j >= 0; j--)
202 software_node_unregister(&sensor->swnodes[j]);
203
204 /*
205 * Give the sensor its original fwnode back or the next time
206 * it's probed will fail, because ACPI matching doesn't work
207 * when your fwnode doesn't have acpi_device_fwnode_ops.
208 */
209 sensor->dev->fwnode = sensor->fwnode;
210 fwnode_handle_put(sensor->fwnode);
211
212 device_release_driver(sensor->dev);
213 i2c_del_driver(&sensor->new_drv);
> 214 device_reprobe(sensor->dev);
215 put_device(sensor->dev);
216 }
217 }
218
219 /*
220 * We have to reprobe the sensor in order for .probe() calls to be able to read
221 * the fwnode properties we set, but having just overwritten the ACPI fwnode
222 * the usual matching won't work by default. We need to clone the existing
223 * driver but add an i2c_device_id so the matching works.
224 */
225 static int cio2_bridge_reprobe_sensor(struct sensor *sensor, int index)
226 {
> 227 struct i2c_client *client;
228 int ret;
229
230 client = container_of(sensor->dev, struct i2c_client, dev);
231
232 sensor->old_drv = container_of(sensor->dev->driver, struct i2c_driver,
233 driver);
234
235 sensor->new_drv.driver.name = supported_devices[index].i2c_id[0].name;
236 sensor->new_drv.probe_new = sensor->old_drv->probe_new;
237 sensor->new_drv.remove = sensor->old_drv->remove;
238 sensor->new_drv.id_table = supported_devices[index].i2c_id;
239
240 device_release_driver(sensor->dev);
241
242 ret = i2c_add_driver(&sensor->new_drv);
243 if (ret)
244 return ret;
245
246 ret = device_reprobe(sensor->dev);
247 if (ret)
248 goto err_remove_new_drv;
249
250 return 0;
251
252 err_remove_new_drv:
253 i2c_del_driver(&sensor->new_drv);
254
255 return ret;
256 }
257
258 static int connect_supported_devices(void)
259 {
260 struct acpi_device *adev;
261 struct device *dev;
262 struct sensor_bios_data ssdb;
263 struct sensor *sensor;
264 struct fwnode_handle *fwnode;
265 struct v4l2_subdev *sd;
266 int i, j, ret;
267
268 ret = 0;
269
270 for (i = 0; i < ARRAY_SIZE(supported_devices); i++) {
271 adev = acpi_dev_get_first_match_dev(supported_devices[i].hid,
272 NULL, -1);
273 if (!adev)
274 continue;
275
276 dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
277 if (!dev) {
278 ret = -EPROBE_DEFER;
279 goto err_rollback;
280 }
281
282 /*
283 * We need to clone the driver of any sensors that we connect,
284 * so if they're probing we need to wait until they're finished
285 */
286
287 if (dev->links.status == DL_DEV_PROBING) {
288 ret = -EPROBE_DEFER;
289 goto err_free_dev;
290 }
291
292 /*
293 * If a sensor has no driver, we want to continue to try and
294 * link others
295 */
296 sd = dev_get_drvdata(dev);
297 if (!sd)
298 goto cont_free_dev;
299
300 sensor = &bridge.sensors[bridge.n_sensors];
301 sensor->dev = dev;
302
303 snprintf(sensor->name, 20, "%s", supported_devices[i].hid);
304
305 sensor->fwnode = fwnode_handle_get(dev->fwnode);
306 if (!sensor->fwnode)
307 goto err_free_dev;
308
309 ret = get_acpi_ssdb_sensor_data(dev, &ssdb);
310 if (ret)
311 goto err_free_fwnode;
312
313 ret = create_fwnode_properties(sensor, &ssdb);
314 if (ret)
315 goto err_free_fwnode;
316
317 ret = create_connection_swnodes(sensor, &ssdb);
318 if (ret)
319 goto err_free_fwnode;
320
321 ret = software_node_register_nodes(sensor->swnodes);
322 if (ret)
323 goto err_free_fwnode;
324
325 fwnode = software_node_fwnode(&sensor->swnodes[SWNODE_SENSOR_HID]);
326 if (!fwnode) {
327 ret = -ENODEV;
328 goto err_free_swnodes;
329 }
330
331 fwnode->secondary = ERR_PTR(-ENODEV);
332 dev->fwnode = fwnode;
333
334 ret = cio2_bridge_reprobe_sensor(sensor, i);
335 if (ret)
336 goto err_free_swnodes;
337
338 pr_info("cio2-bridge: Found supported device %s\n",
339 supported_devices[i].hid);
340
341 bridge.n_sensors++;
342 continue;
343 cont_free_dev:
344 put_device(dev);
345 continue;
346 err_free_swnodes:
347 for (j = 4; j >= 0; j--)
348 software_node_unregister(&sensor->swnodes[j]);
349 err_free_fwnode:
350 fwnode_handle_put(sensor->fwnode);
351 err_free_dev:
352 put_device(dev);
353 err_rollback:
354 /*
355 * If an iteration of this loop results in -EPROBE_DEFER then
356 * we need to roll back any sensors that were successfully
357 * registered. Any other error and we'll skip that step, as
358 * it seems better to have one successfully connected sensor.
359 */
360
361 if (ret == -EPROBE_DEFER)
362 cio2_bridge_unregister_sensors();
363
364 break;
365 }
366
367 return ret;
368 }
369
> 370 int cio2_bridge_build(struct pci_dev *cio2)
371 {
372 struct fwnode_handle *fwnode;
373 int ret;
374
375 pci_dev_get(cio2);
376
377 ret = software_node_register(&cio2_hid_node);
378 if (ret < 0) {
379 pr_err("cio2-bridge: Failed to register the CIO2 HID node\n");
380 goto err_put_cio2;
381 }
382
383 ret = connect_supported_devices();
384 if (ret == -EPROBE_DEFER)
385 goto err_unregister_cio2;
386
387 if (bridge.n_sensors == 0) {
388 ret = -EPROBE_DEFER;
389 goto err_unregister_cio2;
390 }
391
392 pr_info("cio2-bridge: Connected %d cameras\n", bridge.n_sensors);
393
394 fwnode = software_node_fwnode(&cio2_hid_node);
395 if (!fwnode) {
396 pr_err("Error getting fwnode from cio2 software_node\n");
397 ret = -ENODEV;
398 goto err_unregister_sensors;
399 }
400
401 /*
402 * We store the pci_dev's existing fwnode, because in the event we
403 * want to reload the ipu3-cio2 driver we need to give the device its
404 * original fwnode back to prevent problems.
405 */
406
407 bridge.cio2_fwnode = fwnode_handle_get(cio2->dev.fwnode);
408
409 fwnode->secondary = ERR_PTR(-ENODEV);
410 cio2->dev.fwnode = fwnode;
411
412 return 0;
413
414 err_unregister_sensors:
415 cio2_bridge_unregister_sensors();
416 err_unregister_cio2:
417 software_node_unregister(&cio2_hid_node);
418 err_put_cio2:
419 pci_dev_put(cio2);
420
421 return ret;
422 }
423
> 424 void cio2_bridge_burn(struct pci_dev *cio2)---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20201001]
[cannot apply to linus/master v5.9-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Scally/Add-functionality-to-ipu3-cio2-driver-allowing-software_node-connections-to-sensors-on-platforms-designed-for-Windows/20201001-173514 base: git://linuxtv.org/media_tree.git master config: i386-randconfig-a001-20200930 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/0b4280b9a2af4e6b29ec3c9bb5f8d004873e8550 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Daniel-Scally/Add-functionality-to-ipu3-cio2-driver-allowing-software_node-connections-to-sensors-on-platforms-designed-for-Windows/20201001-173514 git checkout 0b4280b9a2af4e6b29ec3c9bb5f8d004873e8550 # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from drivers/media/pci/intel/ipu3/ipu3-cio2.c:30:
>> drivers/media/pci/intel/ipu3/ipu3-cio2.h:446:5: warning: no previous prototype for 'cio2_bridge_build' [-Wmissing-prototypes]
446 | int cio2_bridge_build(struct pci_dev *cio2)
| ^~~~~~~~~~~~~~~~~
>> drivers/media/pci/intel/ipu3/ipu3-cio2.h:451:6: warning: no previous prototype for 'cio2_bridge_burn' [-Wmissing-prototypes] 451 | void cio2_bridge_burn(struct pci_dev *cio2)
| ^~~~~~~~~~~~~~~~
vim +/cio2_bridge_build +446 drivers/media/pci/intel/ipu3/ipu3-cio2.h
445
> 446 int cio2_bridge_build(struct pci_dev *cio2)
447 {
448 return 0;
449 }
450
> 451 void cio2_bridge_burn(struct pci_dev *cio2) 452 {
453 }
454
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
On Thu, Oct 01, 2020 at 10:33:26AM +0100, Daniel Scally wrote:
Awesome work!
My, almost minor, comments below.
Quoted 4 lines
Currently on platforms designed for Windows, connections between CIO2 and sensors are not properly defined in DSDT. This patch extends the ipu3-cio2 driver to compensate by building
software_nodeconnections, parsing the connection properties from the sensor's SSDB buffer.
Drop trailing space here and in other places if any.
Quoted 3 lines
Suggested-by Jordan Hand <[email protected]>Signed-off-by Daniel Scally <[email protected]>
In the tag block should not be blank lines.
...
Quoted 3 lines
* Built against
media_treeinstead of linus's tree - there's no T: entry in maintainers for the ipu3-cio2 driver but I see there're recent changes inmedia_treeso thought this was the better option.
Make sense to include T: entry as well (maybe as a separate patch).
...
drivers/media/pci/intel/ipu3/Kconfig config VIDEO_IPU3_CIO2 · line 29
Quoted 10 lines
drivers/media/pci/intel/ipu3/Kconfig +10
-0+config CIO2_BRIDGE + bool "IPU3 CIO2 Sensors Bridge" + depends on VIDEO_IPU3_CIO2 + help + This extension provides an API for the ipu3-cio2 driver to create + connections to cameras that are hidden in SSDB buffer in ACPI. It + can be used to enable support for cameras in detachable / hybrid + devices that ship with Windows. + + Say y here if your device is a detachable / hybrid laptop that comes
y -> Y
drivers/media/pci/intel/ipu3/Kconfig config VIDEO_IPU3_CIO2 · line 31
Quoted 2 lines
drivers/media/pci/intel/ipu3/Kconfig +2
-0+ with Windows installed by the OEM, for example the Microsoft Surface + line, Lenovo Miix line or Dell 7285.
Reads better in a form of an enumeration, like
- Microsoft Surface (all existing)
- Lenovo Miix (all existing)
- Dell 7285
drivers/media/pci/intel/ipu3/Kconfig config VIDEO_IPU3_CIO2 · line 33
Quoted 1 line
drivers/media/pci/intel/ipu3/Kconfig +1
-0+ If in doubt, say n here.
n -> N
...
drivers/media/pci/intel/ipu3/Makefile line 8
Quoted 8 lines
drivers/media/pci/intel/ipu3/Makefile +7
-1-obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o +obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2-driver.o + +ipu3-cio2-driver-objs += ipu3-cio2.o + +ifeq ($(CONFIG_CIO2_BRIDGE), y) +ipu3-cio2-driver-objs += cio2-bridge.o +endif
objs is for userspace tools, here use
ipu3-cio2-driver-y += ipu3-cio2.o ipu3-cio2-driver-$(CONFIG_CIO2_BRIDGE) = cio2-bridge.o
And actually would be nice to keep the name, so means rename ipu3-cio2.c to something like cio2-main.c. In such case you will have:
obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
ipu3-cio2-y += cio2-main.o
ipu3-cio2-$(CONFIG_CIO2_BRIDGE) = cio2-bridge.o
...
Quoted 1 line
+// SPDX-License-Identifier: GPL-2.0
Author line perhaps?
...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 18
Quoted 6 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +5
-0+/* +* Extend this array with ACPI Hardware ID's of devices known to be +* working +*/ +
Redundant blank like.
drivers/media/pci/intel/ipu3/cio2-bridge.c line 22
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+static const struct ipu3_sensor supported_devices[] = { +IPU3_SENSOR ("INT33BE" ,"INT33BE:00" ), +IPU3_SENSOR ("OVTI2680" ,"OVTI2680:00" ), +IPU3_SENSOR ("OVTI5648" ,"OVTI5648:00" )
In such cases please leave comma at the last item as well. Easier to extend w/o an additional churn.
On top of that, please avoid putting *instance* names, i.e. the second parameters in your macro call. What code should do is to take _HID (first parameter) and call acpi_dev_match_first_dev() or so.
drivers/media/pci/intel/ipu3/cio2-bridge.c line 25
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +2
-0+}; +static struct software_node cio2_hid_node = {CIO2_HID , };
Here, nevertheless, comma can be removed, since update will need to change entire line anyway.
drivers/media/pci/intel/ipu3/cio2-bridge.c line 31
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +3
-0+static const char *const port_names[] = { +"port0" ,"port1" ,"port2" ,"port3" +};
+ Comma (can be prolonged in the next / previous lines).
...
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+static int read_acpi_block (struct device *dev,char *id,void *data,u32 size) +{ +union acpi_object *obj; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };
drivers/media/pci/intel/ipu3/cio2-bridge.c line 65
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+struct acpi_handle *handle =ACPI_HANDLE (dev); +acpi_status status; +int ret; + + status =acpi_evaluate_object (handle, id,NULL , &buffer); +if (ACPI_FAILURE (status)) +return -ENODEV ; + + obj = buffer.pointer; +if (!obj || obj->type !=ACPI_TYPE_BUFFER ) {
!obj case doesn't require freeing and I would say the error message can be amended in such case.
Quoted 9 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +9
-0+dev_err (dev,"Could't read acpi buffer\n" ); + ret = -ENODEV ; + goto err_free_buff; + } + +if (obj->buffer.length > size) { +dev_err (dev,"Given buffer is too small\n" ); + ret = -ENODEV ; + goto err_free_buff;
drivers/media/pci/intel/ipu3/cio2-bridge.c line 83
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +9
-0+ } + +memcpy (data, obj->buffer.pointer, obj->buffer.length); +kfree (buffer.pointer); + +return obj->buffer.length; +err_free_buff: +kfree (buffer.pointer); +return ret;
This may be deduplicated by adding ret = obj->buffer.length; in the success branch. In such case the label would be named out_free_buf.
Quoted 1 line
+}
...
Quoted 9 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +8
-0+static int create_fwnode_properties (struct sensor *sensor, +struct sensor_bios_data *ssdb) +{ +struct property_entry *ep_props; +struct property_entry *cio2_props; +struct property_entry *dev_props; +u32 *data_lanes; +int i;
drivers/media/pci/intel/ipu3/cio2-bridge.c line 122
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+/* device fwnode properties */ + dev_props =kcalloc (3 ,sizeof (*dev_props),GFP_KERNEL ); +if (!dev_props) +return -ENOMEM ; + + dev_props[0 ] =PROPERTY_ENTRY_U32 ("clock-frequency" , ssdb->mclkspeed); + dev_props[1 ] =PROPERTY_ENTRY_U8 ("rotation" , ssdb->degree); + +memcpy (sensor->dev_props, dev_props,sizeof (*dev_props) *3 ); +kfree (dev_props);
Why you can't do it on stack?
drivers/media/pci/intel/ipu3/cio2-bridge.c line 125
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +2
-0+/* endpoint fwnode properties */ +
Redundant blank like
Quoted 11 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+ data_lanes =devm_kmalloc_array (sensor->dev, ssdb->lanes,sizeof (u32), +GFP_KERNEL ); + +if (!data_lanes) +return -ENOMEM ; + +for (i =0 ; i < ssdb->lanes; i++) + data_lanes[i] = i +1 ; + ep_props =kcalloc (4 ,sizeof (*ep_props),GFP_KERNEL ); +if (!ep_props)
drivers/media/pci/intel/ipu3/cio2-bridge.c line 146
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+return -ENOMEM ; + + ep_props[0 ] =PROPERTY_ENTRY_U32 ("bus-type" ,5 ); + ep_props[1 ] =PROPERTY_ENTRY_U32_ARRAY_LEN ("data-lanes" , + data_lanes, + ssdb->lanes); + ep_props[2 ] = remote_endpoints[(bridge.n_sensors *2 ) +ENDPOINT_SENSOR ]; + +memcpy (sensor->ep_props, ep_props,sizeof (*ep_props) *4 ); +kfree (ep_props);
Why can't be done on stack?
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+ +/* cio2 endpoint props */ + + cio2_props =kcalloc (3 ,sizeof (*cio2_props),GFP_KERNEL );
drivers/media/pci/intel/ipu3/cio2-bridge.c line 160
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+if (!cio2_props) +return -ENOMEM ; + + cio2_props[0 ] =PROPERTY_ENTRY_U32_ARRAY_LEN ("data-lanes" , + data_lanes, + ssdb->lanes); + cio2_props[1 ] = remote_endpoints[(bridge.n_sensors *2 ) +ENDPOINT_CIO2 ]; + +memcpy (sensor->cio2_props, cio2_props,sizeof (*cio2_props) *3 ); +kfree (cio2_props);
Ditto.
Something like
union {
...
cio2_properties[3];
} properties;
memset(properties, 0, sizeof(properties));(and please spell properties instead of props)
Quoted 17 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +17
-0+return 0 ; +} + +static int create_connection_swnodes (struct sensor *sensor, +struct sensor_bios_data *ssdb) +{ +struct software_node *nodes; + + nodes =kcalloc (6 ,sizeof (*nodes),GFP_KERNEL ); +if (!nodes) +return -ENOMEM ; + + nodes[SWNODE_SENSOR_HID ] =NODE_SENSOR (sensor->name, + sensor->dev_props); + nodes[SWNODE_SENSOR_PORT ] =NODE_PORT ("port0" , + &sensor->swnodes[SWNODE_SENSOR_HID ]); + nodes[SWNODE_SENSOR_ENDPOINT] = NODE_ENDPOINT("endpoint0",
drivers/media/pci/intel/ipu3/cio2-bridge.c line 188
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+ &sensor->swnodes[SWNODE_SENSOR_PORT ], + sensor->ep_props); + nodes[SWNODE_CIO2_PORT ] =NODE_PORT (port_names[ssdb->link], + &cio2_hid_node); + nodes[SWNODE_CIO2_ENDPOINT ] =NODE_ENDPOINT ("endpoint0" , + &sensor->swnodes[SWNODE_CIO2_PORT ], + sensor->cio2_props); + +memcpy (sensor->swnodes, nodes,sizeof (*nodes) *6 ); +kfree (nodes);
Also, why not on stack?
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (j = 4; j >= 0; j--) + software_node_unregister(&sensor->swnodes[j]);
Seems we may need a simple helper for this (test_printf.c has similar case), so, what about do it here for now and probably then move to somewhere like swnode.h or whatever holds it.
static inline software_node_unregister_nodes_reverse(const struct software_node *nodes)
{
unsigned int i = 0;
while (nodes[i].name)
i++;
while (i--)
software_node_unregister(&nodes[i]);
}...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 230
Quoted 1 line
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +1
-0+ client = container_of(sensor->dev, struct i2c_client, dev);
Shouldn't be rather i2c_verify_client() ?
...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 233
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +2
-0+ sensor->old_drv = container_of(sensor->dev->driver, struct i2c_driver, + driver);
to_i2c_driver() ?
...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 269
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +2
-0+ ret =0 ; +
No need to have a blank line here (check other similar places in the code).
drivers/media/pci/intel/ipu3/cio2-bridge.c line 272
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +3
-0+for (i =0 ; i <ARRAY_SIZE (supported_devices); i++) { + adev =acpi_dev_get_first_match_dev (supported_devices[i].hid, +NULL ,-1 );
Keep it one line, easy to read.
Quoted 21 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +21
-0+if (!adev) +continue ; + + dev =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); +if (!dev) { + ret = -EPROBE_DEFER ; + goto err_rollback; + } + +/* +* We need to clone the driver of any sensors that we connect, +* so if they're probing we need to wait until they're finished +*/ + +if (dev->links.status ==DL_DEV_PROBING ) { + ret = -EPROBE_DEFER ; + goto err_free_dev; + } + +/* +* If a sensor has no driver, we want to continue to try and
drivers/media/pci/intel/ipu3/cio2-bridge.c line 303
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+* link others +*/ + sd =dev_get_drvdata (dev); +if (!sd) + goto cont_free_dev; + + sensor = &bridge.sensors[bridge.n_sensors]; + sensor->dev = dev; + +snprintf (sensor->name,20 ,"%s" , supported_devices[i].hid);
include/linux/mod_devicetable.h:454:#define I2C_NAME_SIZE 20
Quoted 25 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +25
-0+ sensor->fwnode =fwnode_handle_get (dev->fwnode); +if (!sensor->fwnode) + goto err_free_dev; + + ret =get_acpi_ssdb_sensor_data (dev, &ssdb); +if (ret) + goto err_free_fwnode; + + ret =create_fwnode_properties (sensor, &ssdb); +if (ret) + goto err_free_fwnode; + + ret =create_connection_swnodes (sensor, &ssdb); +if (ret) + goto err_free_fwnode; + + ret =software_node_register_nodes (sensor->swnodes); +if (ret) + goto err_free_fwnode; + + fwnode =software_node_fwnode (&sensor->swnodes[SWNODE_SENSOR_HID ]); +if (!fwnode) { + ret = -ENODEV ; + goto err_free_swnodes; + }
drivers/media/pci/intel/ipu3/cio2-bridge.c line 339
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +9
-0+ + fwnode->secondary =ERR_PTR (-ENODEV ); + dev->fwnode = fwnode; + + ret =cio2_bridge_reprobe_sensor (sensor, i); +if (ret) + goto err_free_swnodes; +pr_info ("cio2-bridge: Found supported device %s\n" , + supported_devices[i].hid);
Use dev_*() [dev_info()] instead of pr_*() ones.
drivers/media/pci/intel/ipu3/cio2-bridge.c line 348
Quoted 9 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +8
-0+ bridge.n_sensors++; +continue ; +cont_free_dev: +put_device (dev); +continue ; +err_free_swnodes: +for (j =4 ; j >=0 ; j--) +software_node_unregister (&sensor->swnodes[j]);
See above.
Quoted 6 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +6
-0+err_free_fwnode: +fwnode_handle_put (sensor->fwnode); +err_free_dev: +put_device (dev); +err_rollback: +/*
drivers/media/pci/intel/ipu3/cio2-bridge.c line 364
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +10
-0+* If an iteration of this loop results in -EPROBE_DEFER then +* we need to roll back any sensors that were successfully +* registered. Any other error and we'll skip that step, as +* it seems better to have one successfully connected sensor. +*/ + +if (ret == -EPROBE_DEFER ) +cio2_bridge_unregister_sensors (); + +break ;
This is (all err_* labels) invariant to the loop (you break it), so, move out of the loop...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 83
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +3
-0+ } + +return ret;
...somewhere here.
...
drivers/media/pci/intel/ipu3/cio2-bridge.c line 379
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +3
-0+ ret =software_node_register (&cio2_hid_node); +if (ret <0 ) { +pr_err ("cio2-bridge: Failed to register the CIO2 HID node\n" );
dev_err() and so on.
Quoted 2 lines
(quoted diff) +2
-0+ goto err_put_cio2; + }
...
Quoted 1 line
+#define
__NO_VERSION__
What is this for?
...
drivers/media/pci/intel/ipu3/cio2-bridge.h line 23
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +4
-0+#define NODE_SENSOR (_HID, _PROPS) \ + ((const struct software_node) { \ + .name = _HID, \ + .properties = _PROPS \
Leave comma.
Quoted 1 line
(quoted diff) +1
-0+ })
...
drivers/media/pci/intel/ipu3/cio2-bridge.h line 44
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +6
-0+#define IPU3_SENSOR (_HID, _CLIENT) \ + { \ + .hid = _HID, \ + .i2c_id = { \ + {_CLIENT, 0}, \ + { }, \
No comma for terminator type of entries.
drivers/media/pci/intel/ipu3/cio2-bridge.h line 45
Quoted 1 line
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +1
-0+ } \
Leave comma.
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/media/pci/intel/ipu3/cio2-bridge.h line 49
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +2
-0+struct ipu3_sensor { +const char hid[20 ];
Shouldn't be rather 9?
#define ACPI_ID_LEN 9
Quoted 2 lines
(quoted diff) +2
-0+ const struct i2c_device_id i2c_id[2]; +};
...
drivers/media/pci/intel/ipu3/cio2-bridge.h line 54
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +2
-0+struct sensor { +char name[20 ];
I guess it's predefined by I²C ID.
drivers/media/pci/intel/ipu3/cio2-bridge.h line 59
Quoted 5 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +5
-0+struct device *dev; +struct software_node swnodes[6 ]; +struct property_entry dev_props[3 ]; +struct property_entry ep_props[4 ]; +struct property_entry cio2_props[3 ];
I'm now wondering why you can't simply put properties directly to here and do that kcalloc / memcpy() in few functions? I mean to drop those calls and assign properties directly. You even won't need to memset() and stack for them!
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +4
-0+struct fwnode_handle *fwnode; +struct i2c_driver *old_drv; +struct i2c_driver new_drv; +};
...
Quoted 1 line
+} __attribute__((__packed__));
__packed is enough (it's in compiler.h IIRC).
...
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1715
Quoted 3 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0struct cio2_device *cio2; +struct fwnode_handle *endpoint;int r;
Reverse xmas tree order.
...
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1727
Quoted 1 line
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0+ endpoint =fwnode_graph_get_next_endpoint (pci_dev->dev.fwnode,NULL );
dev_fwnode()
Quoted 5 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c +5
-0+if (!endpoint) { + r =cio2_bridge_build (pci_dev); +if (r) +return r; + }
...
Quoted 1 line
+#ifdef
CONFIG_CIO2_BRIDGE
IS_ENABLED()
drivers/media/pci/intel/ipu3/ipu3-cio2.h static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq) · line 449
Quoted 10 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.h +10
-0+ +int cio2_bridge_build (struct pci_dev *cio2); +void cio2_bridge_burn (struct pci_dev *cio2); + +#else + +int cio2_bridge_build (struct pci_dev *cio2) +{ +return 0 ; +}
One line.
drivers/media/pci/intel/ipu3/cio2-bridge.c line 433
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +3
-0+void cio2_bridge_burn (struct pci_dev *cio2) +{ +}
One line.
Quoted 1 line
+#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy - sorry for delayed reply, busy week
Quoted 4 lines · Andy Shevchenko
On Thu, Oct 01, 2020 at 10:33:26AM +0100, Daniel Scally wrote:
Awesome work!
My, almost minor, comments below.
Thanks as always for your help - great comments. I'll work through and make the changes you suggest to this code and also...
Quoted 4 lines
Quoted 3 lines
* Built against
media_treeinstead of linus's tree - there's no T: entry in maintainers for the ipu3-cio2 driver but I see there're recent changes inmedia_treeso thought this was the better option.Make sense to include T: entry as well (maybe as a separate patch).
...I agree with your other email re. turning this into a series and making the additional changes you suggested, so I'll do that too for the v3.
Just a couple comments / queries:
Quoted 2 lines
Quoted 1 line
+// SPDX-License-Identifier: GPL-2.0
Author line perhaps?
You mean literally just like /* Authored By: Dan Scally */ or something? OK, no problem.
Quoted 10 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c line 22
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+static const struct ipu3_sensor supported_devices[] = { +IPU3_SENSOR ("INT33BE" ,"INT33BE:00" ), +IPU3_SENSOR ("OVTI2680" ,"OVTI2680:00" ), +IPU3_SENSOR ("OVTI5648" ,"OVTI5648:00" )In such cases please leave comma at the last item as well. Easier to extend w/o an additional churn.
On top of that, please avoid putting *instance* names, i.e. the second parameters in your macro call. What code should do is to take
_HID(first parameter) and callacpi_dev_match_first_dev()or so.
Yeah I was originally using the i2c_client's name field (this comes into play during cio2_bridge_reprobe_sensor()) but the matching refused to work using anything but a string literal. Let me take another look at this then.
Quoted 3 lines
Quoted 1 line
+static struct
software_nodecio2_hid_node= {CIO2_HID, };Here, nevertheless, comma can be removed, since update will need to change entire line anyway.
Trailing commas where lists can be extended, otherwise none - got it.
Quoted 8 lines
Quoted 8 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +8
-0+static int read_acpi_block (struct device *dev,char *id,void *data,u32 size) +{ +union acpi_object *obj; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_handle *handle =ACPI_HANDLE (dev); +acpi_status status; +int ret; +
Quoted 8 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c line 65
Quoted 6 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +6
-0+ status =acpi_evaluate_object (handle, id,NULL , &buffer); +if (ACPI_FAILURE (status)) +return -ENODEV ; + + obj = buffer.pointer; +if (!obj || obj->type !=ACPI_TYPE_BUFFER ) {!obj case doesn't require freeing and I would say the error message can be amended in such case.
Oops - you suggested that in the last version too and I missed it, sorry about that. I'll split those two failure modes out.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (j = 4; j >= 0; j--) + software_node_unregister(&sensor->swnodes[j]);Seems we may need a simple helper for this (
test_printf.chas similar case), so, what about do it here for now and probably then move to somewhere likeswnode.hor whatever holds it.static inline
software_node_unregister_nodes_reverse(const struct software_node *nodes)
Quoted 8 lines
{
unsigned int i = 0;
while (nodes[i].name)
i++;
while (i--)
software_node_unregister(&nodes[i]);
}Yeah this is a good idea; I see you suggest a new patch for it in your other email; I'll do a series in the future and add this to the swnode source file at the same time as doing the changes that you, Heikki and Sakari suggested for the other patch.
Quoted 2 lines
Quoted 1 line
+#define
__NO_VERSION__What is this for?
Somehow I got on the outdated page for compiling modules spanning multiple files in the linux kernel module programming guide; it's suggested there but not in the newer version. I shall remove it.
Quoted 8 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h line 59
Quoted 5 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +5
-0+struct device *dev; +struct software_node swnodes[6 ]; +struct property_entry dev_props[3 ]; +struct property_entry ep_props[4 ]; +struct property_entry cio2_props[3 ];I'm now wondering why you can't simply put properties directly to here and do that kcalloc /
memcpy()in few functions? I mean to drop those calls and assign properties directly. You even won't need tomemset()and stack for them!
I thought you were hinting that I should use kcalloc in the comments from the last patch to get an array of zero valued entries but I guess I misunderstood - I can just memset these arrays to 0 and assign all but the last entry directly and that seems to work fine, so I'll switch to that.
Quoted 4 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1715
Quoted 3 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0struct cio2_device *cio2; +struct fwnode_handle *endpoint;int r;Reverse xmas tree order.
TIL - thanks, I'll do a pass over the rest of it and make sure that I follow that everywhere else too
Quoted 2 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1727
Quoted 1 line
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0+ endpoint =fwnode_graph_get_next_endpoint (pci_dev->dev.fwnode,NULL );
dev_fwnode()
I avoided that thinking there might be a case where a CIO2 device has a fwnode but not endpoints defined for some reason, but I'm not familiar enough to judge whether that situation will ever occur - if it's safe to do it that way then I'll switch it over.
Quoted 7 lines · Dan Scally
Quoted 4 lines · Andy Shevchenko
On Thu, Oct 01, 2020 at 10:33:26AM +0100, Daniel Scally wrote:
Awesome work!
My, almost minor, comments below.Thanks as always for your help - great comments. I'll work through and make the changes you suggest to this code and also...
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
* Built against
media_treeinstead of linus's tree - there's no T: entry in maintainers for the ipu3-cio2 driver but I see there're recent changes inmedia_treeso thought this was the better option.Make sense to include T: entry as well (maybe as a separate patch).
...I agree with your other email re. turning this into a series and making the additional changes you suggested, so I'll do that too for the v3.
I forgot to mention module rename as a separate patch. So, something like 6 (or more) in a series I would expect.
...
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
+// SPDX-License-Identifier: GPL-2.0
Author line perhaps?
You mean literally just like /* Authored By: Dan Scally */ or something? OK, no problem.
* Author: Dan Scally <[email protected]>
...
Quoted 7 lines
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c line 22
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+static const struct ipu3_sensor supported_devices[] = { +IPU3_SENSOR ("INT33BE" ,"INT33BE:00" ), +IPU3_SENSOR ("OVTI2680" ,"OVTI2680:00" ), +IPU3_SENSOR ("OVTI5648" ,"OVTI5648:00" )In such cases please leave comma at the last item as well. Easier to extend w/o an additional churn.
Quoted 7 lines
Quoted 3 lines
On top of that, please avoid putting *instance* names, i.e. the second parameters in your macro call. What code should do is to take
_HID(first parameter) and callacpi_dev_match_first_dev()or so.Yeah I was originally using the i2c_client's name field (this comes into play during
cio2_bridge_reprobe_sensor()) but the matching refused to work using anything but a string literal. Let me take another look at this then.
I meant that you get an instance name from the first found device, like
char instance_name[I2C...];
adev = first_match_dev();
if (adev) {
snprintf(instance_name, ..., acpi_dev_name(adev));
...
} else {
...
}...
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
+static struct
software_nodecio2_hid_node= {CIO2_HID, };Here, nevertheless, comma can be removed, since update will need to change entire line anyway.
Trailing commas where lists can be extended, otherwise none - got it.
Just use a common sense. Simple extrapolate it to the next change, if any, among the same lines.
...
Quoted 15 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (j = 4; j >= 0; j--) + software_node_unregister(&sensor->swnodes[j]);Seems we may need a simple helper for this (
test_printf.chas similar case), so, what about do it here for now and probably then move to somewhere likeswnode.hor whatever holds it.static inline
software_node_unregister_nodes_reverse(const struct software_node *nodes)Quoted 8 lines
{ unsigned int i = 0; while (nodes[i].name) i++; while (i--) software_node_unregister(&nodes[i]); }
Quoted 4 lines
Yeah this is a good idea; I see you suggest a new patch for it in your other email; I'll do a series in the future and add this to the swnode source file at the same time as doing the changes that you, Heikki and Sakari suggested for the other patch.
Yes, thanks!
...
Quoted 11 lines
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h line 59
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h new file +4
-0+struct software_node swnodes[6 ]; +struct property_entry dev_props[3 ]; +struct property_entry ep_props[4 ]; +struct property_entry cio2_props[3 ];I'm now wondering why you can't simply put properties directly to here and do that kcalloc /
memcpy()in few functions? I mean to drop those calls and assign properties directly. You even won't need tomemset()and stack for them!I thought you were hinting that I should use kcalloc in the comments from the last patch to get an array of zero valued entries but I guess I misunderstood - I can just memset these arrays to 0 and assign all but the last entry directly and that seems to work fine, so I'll switch to that.
The idea behind that any kcalloc() or kzalloc() against a container (whatever data structure that has those property arrays) will do it for you. So, I think neither kcalloc() nor stack is needed. Instantiate properties directly in the arrays of sensor data structure.
...
Quoted 6 lines
Quoted 2 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1727
Quoted 1 line
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0+ endpoint =fwnode_graph_get_next_endpoint (pci_dev->dev.fwnode,NULL );
dev_fwnode()I avoided that thinking there might be a case where a CIO2 device has a fwnode but not endpoints defined for some reason, but I'm not familiar enough to judge whether that situation will ever occur - if it's safe to do it that way then I'll switch it over.
I meant
endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&pci_dev->dev), NULL);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines
...I agree with your other email re. turning this into a series and making the additional changes you suggested, so I'll do that too for the v3.
I forgot to mention module rename as a separate patch. So, something like 6 (or more) in a series I would expect.
Yeah no problem, I'll do that too.
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
+// SPDX-License-Identifier: GPL-2.0
Author line perhaps?
You mean literally just like /* Authored By: Dan Scally */ or something? OK, no problem.
* Author: Dan Scally <[email protected]>
Okedokey
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c line 22
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c new file +4
-0+static const struct ipu3_sensor supported_devices[] = { +IPU3_SENSOR ("INT33BE" ,"INT33BE:00" ), +IPU3_SENSOR ("OVTI2680" ,"OVTI2680:00" ), +IPU3_SENSOR ("OVTI5648" ,"OVTI5648:00" )In such cases please leave comma at the last item as well. Easier to extend w/o an additional churn.
Quoted 7 lines
Quoted 3 lines
On top of that, please avoid putting *instance* names, i.e. the second parameters in your macro call. What code should do is to take
_HID(first parameter) and callacpi_dev_match_first_dev()or so.Yeah I was originally using the i2c_client's name field (this comes into play during
cio2_bridge_reprobe_sensor()) but the matching refused to work using anything but a string literal. Let me take another look at this then.I meant that you get an instance name from the first found device, like
Quoted 9 lines
char instance_name[I2C...];
adev = first_match_dev();
if (adev) {
snprintf(instance_name, ..., acpi_dev_name(adev));
...
} else {
...
}Ah, yes, this is better than messing around getting the i2c_client - thanks
Quoted 8 lines
Quoted 4 lines
I thought you were hinting that I should use kcalloc in the comments from the last patch to get an array of zero valued entries but I guess I misunderstood - I can just memset these arrays to 0 and assign all but the last entry directly and that seems to work fine, so I'll switch to that.
The idea behind that any
kcalloc()orkzalloc()against a container (whatever data structure that has those property arrays) will do it for you. So, I think neitherkcalloc()nor stack is needed. Instantiate properties directly in the arrays of sensor data structure.
Will do
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1727
Quoted 1 line
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1
-0+ endpoint =fwnode_graph_get_next_endpoint (pci_dev->dev.fwnode,NULL );
dev_fwnode()I avoided that thinking there might be a case where a CIO2 device has a fwnode but not endpoints defined for some reason, but I'm not familiar enough to judge whether that situation will ever occur - if it's safe to do it that way then I'll switch it over.
I meant
endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&pci_dev->dev), NULL);
Ah! Of course, I'll make that change too, thanks
On Thu, Oct 01, 2020 at 10:33:26AM +0100, Daniel Scally wrote:
...
Quoted 4 lines
This patch is dependent on another (which implements the software node graph family of functions):
More thoughts about the (future) series. Can you rather do a series of patches to understand what is going on here. I see something like this:
patch 1. Add unregister_nodes_reverse()
2. Use above in test_printf.c
3. Add that graph support patch
4. Add T: to MAINTAINERS for IPU3-CIO2
5. Add this patch
Signature · 2 lines
With Best Regards, Andy Shevchenko