xref: /linux/drivers/media/pci/intel/ipu-bridge.c (revision a91ee98d8d5804d8f3d32f4208cdb5498b19b970)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Author: Dan Scally <djrscally@gmail.com> */
3 
4 #include <linux/acpi.h>
5 #include <acpi/acpi_bus.h>
6 #include <linux/cleanup.h>
7 #include <linux/device.h>
8 #include <linux/dmi.h>
9 #include <linux/i2c.h>
10 #include <linux/mei_cl_bus.h>
11 #include <linux/pci.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_runtime.h>
14 #include <linux/property.h>
15 #include <linux/string.h>
16 #include <linux/workqueue.h>
17 
18 #include <media/ipu-bridge.h>
19 #include <media/ipu6-pci-table.h>
20 #include <media/v4l2-fwnode.h>
21 
22 #define ADEV_DEV(adev) ACPI_PTR(&((adev)->dev))
23 
24 /*
25  * 92335fcf-3203-4472-af93-7b4453ac29da
26  *
27  * Used to build MEI CSI device name to lookup MEI CSI device by
28  * device_find_child_by_name().
29  */
30 #define MEI_CSI_UUID							\
31 	UUID_LE(0x92335FCF, 0x3203, 0x4472,				\
32 		0xAF, 0x93, 0x7B, 0x44, 0x53, 0xAC, 0x29, 0xDA)
33 
34 /*
35  * IVSC device name
36  *
37  * Used to match IVSC device by ipu_bridge_match_ivsc_dev()
38  */
39 #define IVSC_DEV_NAME "intel_vsc"
40 
41 /*
42  * Extend this array with ACPI Hardware IDs of devices known to be working
43  * plus the number of link-frequencies expected by their drivers, along with
44  * the frequency values in hertz. This is somewhat opportunistic way of adding
45  * support for this for now in the hopes of a better source for the information
46  * (possibly some encoded value in the SSDB buffer that we're unaware of)
47  * becoming apparent in the future.
48  *
49  * Do not add an entry for a sensor that is not actually supported.
50  *
51  * Please keep the list sorted by ACPI HID.
52  */
53 /* IPU6 variants whose CSI-2 receiver needs the ov5693 clock lane gated */
54 static const u16 ipu6_ov5693_ncont_clk[] = {
55 	PCI_DEVICE_ID_INTEL_IPU6,		/* Tiger Lake */
56 	PCI_DEVICE_ID_INTEL_IPU6EP_ADLP,	/* Alder Lake-P */
57 	PCI_DEVICE_ID_INTEL_IPU6EP_ADLN,	/* Alder Lake-N */
58 	0
59 };
60 
61 static const struct ipu_sensor_config ipu_supported_sensors[] = {
62 	/* Himax HM1092 */
63 	IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000),
64 	/* Himax HM11B1 */
65 	IPU_SENSOR_CONFIG("HIMX11B1", 1, 384000000),
66 	/* Himax HM2170 */
67 	IPU_SENSOR_CONFIG("HIMX2170", 1, 384000000),
68 	/* Himax HM2172 */
69 	IPU_SENSOR_CONFIG("HIMX2172", 1, 384000000),
70 	/* GalaxyCore GC0310 */
71 	IPU_SENSOR_CONFIG("INT0310", 1, 55692000),
72 	/* Omnivision OV5693 */
73 	IPU_SENSOR_CONFIG_MATCH_FL("INT33BE", ipu6_ov5693_ncont_clk,
74 				   IPU_BR_FL_CSI2_CLK_NONCONTINUOUS,
75 				   1, 419200000),
76 	IPU_SENSOR_CONFIG("INT33BE", 1, 419200000),
77 	/* Onsemi MT9M114 */
78 	IPU_SENSOR_CONFIG("INT33F0", 1, 384000000),
79 	/* Omnivision OV2740 */
80 	IPU_SENSOR_CONFIG("INT3474", 1, 180000000),
81 	/* Omnivision OV8858 */
82 	IPU_SENSOR_CONFIG("INT3477", 1, 360000000),
83 	/* Omnivision OV5670 */
84 	IPU_SENSOR_CONFIG("INT3479", 1, 422400000),
85 	/* Omnivision OV8865 */
86 	IPU_SENSOR_CONFIG("INT347A", 1, 360000000),
87 	/* Omnivision OV7251 */
88 	IPU_SENSOR_CONFIG("INT347E", 1, 319200000),
89 	/* Hynix Hi-556 */
90 	IPU_SENSOR_CONFIG("INT3537", 1, 437000000),
91 	/* Lontium lt6911uxe */
92 	IPU_SENSOR_CONFIG("INTC10C5", 0),
93 	/* Omnivision OV01A10 / OV01A1B / OV01A1S */
94 	IPU_SENSOR_CONFIG("OVTI01A0", 1, 400000000),
95 	IPU_SENSOR_CONFIG("OVTI01AB", 1, 400000000),
96 	IPU_SENSOR_CONFIG("OVTI01AS", 1, 400000000),
97 	/* Omnivision OV02C10 */
98 	IPU_SENSOR_CONFIG("OVTI02C1", 1, 400000000),
99 	/* Omnivision OV02E10 */
100 	IPU_SENSOR_CONFIG("OVTI02E1", 1, 360000000),
101 	/* Omnivision ov05c10 */
102 	IPU_SENSOR_CONFIG("OVTI05C1", 2, 480000000, 900000000),
103 	/* Omnivision OV08A10 */
104 	IPU_SENSOR_CONFIG("OVTI08A1", 1, 500000000),
105 	/* Omnivision OV08x40 */
106 	IPU_SENSOR_CONFIG("OVTI08F4", 3, 400000000, 749000000, 800000000),
107 	/* Omnivision OV13858 */
108 	IPU_SENSOR_CONFIG("OVTID858", 2, 540000000, 270000000),
109 	/* Omnivision OV13B10 */
110 	IPU_SENSOR_CONFIG("OVTI13B1", 1, 560000000),
111 	IPU_SENSOR_CONFIG("OVTIDB10", 1, 560000000),
112 	/* Omnivision OV2680 */
113 	IPU_SENSOR_CONFIG("OVTI2680", 1, 331200000),
114 	/* Omnivision OV5675 */
115 	IPU_SENSOR_CONFIG("OVTI5675", 1, 450000000),
116 	/* Omnivision OV5693 */
117 	IPU_SENSOR_CONFIG_MATCH_FL("OVTI5693", ipu6_ov5693_ncont_clk,
118 				   IPU_BR_FL_CSI2_CLK_NONCONTINUOUS,
119 				   1, 419200000),
120 	IPU_SENSOR_CONFIG("OVTI5693", 1, 419200000),
121 	/* Omnivision OV8856 */
122 	IPU_SENSOR_CONFIG("OVTI8856", 3, 180000000, 360000000, 720000000),
123 	/* Sony IMX471 */
124 	IPU_SENSOR_CONFIG("SONY471A", 1, 200000000),
125 	/* Sony IMX471 (found on Lenovo X1 Carbon G14) */
126 	IPU_SENSOR_CONFIG("TBE20A0", 1, 200000000),
127 	/* STMicroelectronics VD55G1 (found on Lenovo X1 Carbon G14) */
128 	IPU_SENSOR_CONFIG("TBE20A1", 1, 402000000),
129 	/* Toshiba T4KA3 */
130 	IPU_SENSOR_CONFIG("XMCC0003", 1, 321468000),
131 };
132 
133 /*
134  * DMI matches for laptops which have their sensor mounted upside-down
135  * without reporting a rotation of 180° in neither the SSDB nor the _PLD.
136  */
137 static const struct dmi_system_id upside_down_sensor_dmi_ids[] = {
138 	{
139 		.matches = {
140 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
141 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 13 9340"),
142 		},
143 		.driver_data = "OVTI02C1",
144 	},
145 	{
146 		.matches = {
147 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
148 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 13 9350"),
149 		},
150 		.driver_data = "OVTI02C1",
151 	},
152 	{
153 		.matches = {
154 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
155 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 14 (Dell 14 Premium) DA14250"),
156 		},
157 		.driver_data = "OVTI02C1",
158 	},
159 	{
160 		.matches = {
161 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
162 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 14 9440"),
163 		},
164 		.driver_data = "OVTI02C1",
165 	},
166 	{
167 		.matches = {
168 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
169 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 16 9640"),
170 		},
171 		.driver_data = "OVTI02C1",
172 	},
173 	{
174 		.matches = {
175 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
176 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 16 (Dell 16 Premium) DA16250"),
177 		},
178 		.driver_data = "OVTI02C1",
179 	},
180 	{
181 		.matches = {
182 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
183 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell Pro 14 Premium PA14260"),
184 		},
185 		.driver_data = "OVTI08F4",
186 	},
187 	{
188 		.matches = {
189 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
190 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell 14 Premium DA14250"),
191 		},
192 		.driver_data = "OVTI02C1",
193 	},
194 	/*
195 	 * The first four characters of DMI_BOARD_NAME identify the Lenovo
196 	 * machine type/model. For example, a DMI_BOARD_NAME starting with
197 	 * "21Q6" indicates a ThinkPad X9-15.
198 	 *
199 	 * Reference: https://psref.lenovo.com/
200 	 */
201 	{
202 		/* Lenovo X9-14 */
203 		.matches = {
204 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
205 			DMI_MATCH(DMI_BOARD_NAME, "21QA"),
206 		},
207 		.driver_data = "SONY471A",
208 	},
209 	{
210 		/* Lenovo X9-14 */
211 		.matches = {
212 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
213 			DMI_MATCH(DMI_BOARD_NAME, "21QB"),
214 		},
215 		.driver_data = "SONY471A",
216 	},
217 	{
218 		/* Lenovo X9-15 */
219 		.matches = {
220 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
221 			DMI_MATCH(DMI_BOARD_NAME, "21Q6"),
222 		},
223 		.driver_data = "SONY471A",
224 	},
225 	{
226 		/* Lenovo X9-15 */
227 		.matches = {
228 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
229 			DMI_MATCH(DMI_BOARD_NAME, "21Q7"),
230 		},
231 		.driver_data = "SONY471A",
232 	},
233 	{
234 		.matches = {
235 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
236 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME,
237 					"Surface Pro for Business 11th Edition with Intel"),
238 		},
239 		.driver_data = "OVTID858",
240 	},
241 	{
242 		/* Samsung Galaxy Book5 Pro 360 */
243 		.matches = {
244 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
245 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "960QHA"),
246 		},
247 		.driver_data = "OVTI02E1",
248 	},
249 	{
250 		/* Samsung Galaxy Book3 Ultra */
251 		.matches = {
252 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
253 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "960XFH"),
254 		},
255 		.driver_data = "OVTI02C1",
256 	},
257 	{
258 		/* Samsung Galaxy Book3 Pro */
259 		.matches = {
260 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
261 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "960XFG"),
262 		},
263 		.driver_data = "OVTI02C1",
264 	},
265 	{
266 		/* Microsoft Surface Pro 9, front sensor */
267 		.matches = {
268 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
269 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Pro 9"),
270 		},
271 		.driver_data = "OVTI5693",
272 	},
273 	{
274 		/* Microsoft Surface Pro 9, rear sensor */
275 		.matches = {
276 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
277 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Pro 9"),
278 		},
279 		.driver_data = "OVTID858",
280 	},
281 	{} /* Terminating entry */
282 };
283 
284 static const struct ipu_property_names prop_names = {
285 	.clock_frequency = "clock-frequency",
286 	.rotation = "rotation",
287 	.orientation = "orientation",
288 	.bus_type = "bus-type",
289 	.data_lanes = "data-lanes",
290 	.remote_endpoint = "remote-endpoint",
291 	.link_frequencies = "link-frequencies",
292 	.clock_noncontinuous = "clock-noncontinuous",
293 };
294 
295 static const char * const ipu_vcm_types[] = {
296 	"ad5823",
297 	"dw9714",
298 	"ad5816",
299 	"dw9719",
300 	"dw9718",
301 	"dw9806b",
302 	"wv517s",
303 	"lc898122xa",
304 	"lc898212axb",
305 };
306 
307 /*
308  * Used to figure out IVSC acpi device by ipu_bridge_get_ivsc_acpi_dev()
309  * instead of device and driver match to probe IVSC device.
310  */
311 static const struct acpi_device_id ivsc_acpi_ids[] = {
312 	{ "INTC1059" },
313 	{ "INTC1095" },
314 	{ "INTC100A" },
315 	{ "INTC10CF" },
316 	{ "INTC10DE" }, /* LNL */
317 	{ "INTC10E0" }, /* ARL */
318 	{ "INTC10E1" }, /* PTL */
319 	{ "INTC10FA" }, /* NVL */
320 };
321 
322 /*
323  * The subset of ivsc_acpi_ids[] which are IVSC, rather than CVS, devices. The
324  * CVS IDs are deliberately not listed here: new ones keep being added, whereas
325  * this list is complete.
326  */
327 static const struct acpi_device_id ivsc_only_acpi_ids[] = {
328 	{ "INTC1059" },
329 	{ "INTC1095" },
330 	{ "INTC100A" },
331 	{ "INTC10CF" },
332 	{ }
333 };
334 
335 static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev)
336 {
337 	unsigned int i;
338 
339 	for (i = 0; i < ARRAY_SIZE(ivsc_acpi_ids); i++) {
340 		const struct acpi_device_id *acpi_id = &ivsc_acpi_ids[i];
341 		struct acpi_device *consumer, *ivsc_adev;
342 		acpi_handle handle = acpi_device_handle(ACPI_PTR(adev));
343 
344 		for_each_acpi_dev_match(ivsc_adev, acpi_id->id, NULL, -1)
345 			/* camera sensor depends on IVSC in DSDT if exist */
346 			for_each_acpi_consumer_dev(ivsc_adev, consumer)
347 				if (ACPI_PTR(consumer->handle) == handle) {
348 					acpi_dev_put(consumer);
349 					return ivsc_adev;
350 				}
351 	}
352 
353 	return NULL;
354 }
355 
356 static int ipu_bridge_match_ivsc_dev(struct device *dev, const void *adev)
357 {
358 	if (ACPI_COMPANION(dev) != adev)
359 		return 0;
360 
361 	if (!sysfs_streq(dev_name(dev), IVSC_DEV_NAME))
362 		return 0;
363 
364 	return 1;
365 }
366 
367 static struct device *ipu_bridge_get_ivsc_csi_dev(struct acpi_device *adev)
368 {
369 	struct device *dev, *csi_dev;
370 	uuid_le uuid = MEI_CSI_UUID;
371 	char name[64];
372 
373 	/* IVSC device on platform bus */
374 	dev = bus_find_device(&platform_bus_type, NULL, adev,
375 			      ipu_bridge_match_ivsc_dev);
376 	if (dev) {
377 		snprintf(name, sizeof(name), "%s-%pUl", dev_name(dev), &uuid);
378 
379 		csi_dev = device_find_child_by_name(dev, name);
380 
381 		put_device(dev);
382 
383 		return csi_dev;
384 	}
385 
386 	/*
387 	 * The lookups below match on the ACPI companion alone. That is fine for
388 	 * CVS, which binds a driver to that very device, but not for IVSC: there
389 	 * the ACPI device also has a driverless platform device, which would be
390 	 * returned instead of the mei-csi client. Return NULL for IVSC so that
391 	 * the caller fails and the probe is retried once the IVSC device shows
392 	 * up.
393 	 */
394 	if (!acpi_match_device_ids(adev, ivsc_only_acpi_ids))
395 		return NULL;
396 
397 	/* Try to locate CVS device on the I2C bus */
398 	csi_dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
399 	if (csi_dev)
400 		return csi_dev;
401 
402 	/* Fallback to platform bus for CVS device */
403 	return bus_find_device_by_acpi_dev(&platform_bus_type, adev);
404 }
405 
406 static int ipu_bridge_check_ivsc_dev(struct ipu_sensor *sensor,
407 				     struct acpi_device *sensor_adev)
408 {
409 	struct acpi_device *adev;
410 	struct device *csi_dev;
411 
412 	adev = ipu_bridge_get_ivsc_acpi_dev(sensor_adev);
413 	if (adev) {
414 		csi_dev = ipu_bridge_get_ivsc_csi_dev(adev);
415 		if (!csi_dev) {
416 			dev_err(ADEV_DEV(adev), "Failed to find MEI or CVS CSI dev\n");
417 			acpi_dev_put(adev);
418 			return -ENODEV;
419 		}
420 
421 		sensor->csi_dev = csi_dev;
422 		sensor->ivsc_adev = adev;
423 	}
424 
425 	return 0;
426 }
427 
428 static int ipu_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
429 				       void *data, u32 size)
430 {
431 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
432 	union acpi_object *obj;
433 	acpi_status status;
434 	int ret = 0;
435 
436 	status = acpi_evaluate_object(ACPI_PTR(adev->handle),
437 				      id, NULL, &buffer);
438 	if (ACPI_FAILURE(status))
439 		return -ENODEV;
440 
441 	obj = buffer.pointer;
442 	if (!obj) {
443 		dev_err(ADEV_DEV(adev), "Couldn't locate ACPI buffer\n");
444 		return -ENODEV;
445 	}
446 
447 	if (obj->type != ACPI_TYPE_BUFFER) {
448 		dev_err(ADEV_DEV(adev), "Not an ACPI buffer\n");
449 		ret = -ENODEV;
450 		goto out_free_buff;
451 	}
452 
453 	if (obj->buffer.length > size) {
454 		dev_err(ADEV_DEV(adev), "Given buffer is too small\n");
455 		ret = -EINVAL;
456 		goto out_free_buff;
457 	}
458 
459 	memcpy(data, obj->buffer.pointer, obj->buffer.length);
460 
461 out_free_buff:
462 	kfree(buffer.pointer);
463 	return ret;
464 }
465 
466 static u32 ipu_bridge_parse_rotation(struct acpi_device *adev,
467 				     struct ipu_sensor_ssdb *ssdb)
468 {
469 	const struct dmi_system_id *dmi_id;
470 
471 	/* A machine may have one entry per sensor, so check all matches. */
472 	for (dmi_id = dmi_first_match(upside_down_sensor_dmi_ids); dmi_id;
473 	     dmi_id = dmi_first_match(dmi_id + 1))
474 		if (acpi_dev_hid_match(adev, dmi_id->driver_data))
475 			return 180;
476 
477 	switch (ssdb->degree) {
478 	case IPU_SENSOR_ROTATION_NORMAL:
479 		return 0;
480 	case IPU_SENSOR_ROTATION_INVERTED:
481 		return 180;
482 	default:
483 		dev_warn(ADEV_DEV(adev),
484 			 "Unknown rotation %d. Assume 0 degree rotation\n",
485 			 ssdb->degree);
486 		return 0;
487 	}
488 }
489 
490 static enum v4l2_fwnode_orientation ipu_bridge_parse_orientation(struct acpi_device *adev)
491 {
492 	enum v4l2_fwnode_orientation orientation;
493 	struct acpi_pld_info *pld = NULL;
494 
495 	if (!acpi_get_physical_device_location(ACPI_PTR(adev->handle), &pld)) {
496 		dev_warn(ADEV_DEV(adev), "_PLD call failed, using default orientation\n");
497 		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
498 	}
499 
500 	switch (pld->panel) {
501 	case ACPI_PLD_PANEL_FRONT:
502 		orientation = V4L2_FWNODE_ORIENTATION_FRONT;
503 		break;
504 	case ACPI_PLD_PANEL_BACK:
505 		orientation = V4L2_FWNODE_ORIENTATION_BACK;
506 		break;
507 	case ACPI_PLD_PANEL_TOP:
508 	case ACPI_PLD_PANEL_LEFT:
509 	case ACPI_PLD_PANEL_RIGHT:
510 	case ACPI_PLD_PANEL_UNKNOWN:
511 		orientation = V4L2_FWNODE_ORIENTATION_EXTERNAL;
512 		break;
513 	default:
514 		dev_warn(ADEV_DEV(adev), "Unknown _PLD panel val %d\n",
515 			 pld->panel);
516 		orientation = V4L2_FWNODE_ORIENTATION_EXTERNAL;
517 		break;
518 	}
519 
520 	ACPI_FREE(pld);
521 	return orientation;
522 }
523 
524 int ipu_bridge_parse_ssdb(struct acpi_device *adev, struct ipu_sensor *sensor)
525 {
526 	acpi_handle handle = acpi_device_handle(ACPI_PTR(adev));
527 	struct ipu_sensor_ssdb ssdb = {};
528 	int ret;
529 
530 	ret = ipu_bridge_read_acpi_buffer(adev, "SSDB", &ssdb, sizeof(ssdb));
531 	if (ret)
532 		return ret;
533 
534 	if (ssdb.vcmtype > ARRAY_SIZE(ipu_vcm_types)) {
535 		dev_warn(ADEV_DEV(adev), "Unknown VCM type %d\n", ssdb.vcmtype);
536 		ssdb.vcmtype = 0;
537 	}
538 
539 	if (ssdb.lanes > IPU_MAX_LANES) {
540 		dev_err(ADEV_DEV(adev), "Number of lanes in SSDB is invalid\n");
541 		return -EINVAL;
542 	}
543 
544 	sensor->link = ssdb.link;
545 	sensor->lanes = ssdb.lanes;
546 	sensor->mclkspeed = ssdb.mclkspeed;
547 	sensor->rotation = ipu_bridge_parse_rotation(adev, &ssdb);
548 	sensor->orientation = ipu_bridge_parse_orientation(adev);
549 
550 	acpi_handle_debug(handle,
551 			  "CSI-2 port %u, lanes %u, mclkspeed %u, rotation %u (SSDB %u), orientation %u\n",
552 			  sensor->link, sensor->lanes, sensor->mclkspeed,
553 			  sensor->rotation, ssdb.degree, sensor->orientation);
554 
555 	if (ssdb.vcmtype) {
556 		sensor->vcm_type = ipu_vcm_types[ssdb.vcmtype - 1];
557 		acpi_handle_debug(handle, "VCM %s\n", sensor->vcm_type);
558 	}
559 
560 	return 0;
561 }
562 EXPORT_SYMBOL_NS_GPL(ipu_bridge_parse_ssdb, "INTEL_IPU_BRIDGE");
563 
564 static void ipu_bridge_create_fwnode_properties(
565 	struct ipu_sensor *sensor,
566 	struct ipu_bridge *bridge,
567 	const struct ipu_sensor_config *cfg)
568 {
569 	struct ipu_property_names *names = &sensor->prop_names;
570 	struct software_node *nodes = sensor->swnodes;
571 	unsigned int i = 0;
572 
573 	sensor->prop_names = prop_names;
574 
575 	if (sensor->csi_dev) {
576 		sensor->local_ref[0] =
577 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IVSC_SENSOR_ENDPOINT]);
578 		sensor->remote_ref[0] =
579 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IVSC_IPU_ENDPOINT]);
580 		sensor->ivsc_sensor_ref[0] =
581 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_SENSOR_ENDPOINT]);
582 		sensor->ivsc_ipu_ref[0] =
583 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IPU_ENDPOINT]);
584 
585 		sensor->ivsc_sensor_ep_properties[0] =
586 			PROPERTY_ENTRY_U32(names->bus_type,
587 					   V4L2_FWNODE_BUS_TYPE_CSI2_DPHY);
588 		sensor->ivsc_sensor_ep_properties[1] =
589 			PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes,
590 						     bridge->data_lanes,
591 						     sensor->lanes);
592 		sensor->ivsc_sensor_ep_properties[2] =
593 			PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint,
594 						 sensor->ivsc_sensor_ref);
595 
596 		sensor->ivsc_ipu_ep_properties[0] =
597 			PROPERTY_ENTRY_U32(names->bus_type,
598 					   V4L2_FWNODE_BUS_TYPE_CSI2_DPHY);
599 		sensor->ivsc_ipu_ep_properties[1] =
600 			PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes,
601 						     bridge->data_lanes,
602 						     sensor->lanes);
603 		sensor->ivsc_ipu_ep_properties[2] =
604 			PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint,
605 						 sensor->ivsc_ipu_ref);
606 	} else {
607 		sensor->local_ref[0] =
608 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IPU_ENDPOINT]);
609 		sensor->remote_ref[0] =
610 			SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_SENSOR_ENDPOINT]);
611 	}
612 
613 	sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
614 					sensor->prop_names.clock_frequency,
615 					sensor->mclkspeed);
616 	sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
617 					sensor->prop_names.rotation,
618 					sensor->rotation);
619 	sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
620 					sensor->prop_names.orientation,
621 					sensor->orientation);
622 	if (sensor->vcm_type) {
623 		sensor->vcm_ref[0] =
624 			SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_VCM]);
625 		sensor->dev_properties[3] =
626 			PROPERTY_ENTRY_REF_ARRAY("lens-focus", sensor->vcm_ref);
627 	}
628 
629 	sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_BUS_TYPE)] =
630 		PROPERTY_ENTRY_U32(names->bus_type,
631 				   V4L2_FWNODE_BUS_TYPE_CSI2_DPHY);
632 	sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_DATA_LANES)] =
633 		PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes,
634 					     bridge->data_lanes, sensor->lanes);
635 	sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_REMOTE_EP)] =
636 		PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint,
637 					 sensor->local_ref);
638 
639 	if (cfg->nr_link_freqs > 0)
640 		sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_LINK_FREQUENCIES)] =
641 			PROPERTY_ENTRY_U64_ARRAY_LEN(names->link_frequencies,
642 						     cfg->link_freqs,
643 						     cfg->nr_link_freqs);
644 
645 	if (cfg->flags & IPU_BR_FL_CSI2_CLK_NONCONTINUOUS)
646 		sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_CLOCK_NONCONTINUOUS)] =
647 			PROPERTY_ENTRY_BOOL(names->clock_noncontinuous);
648 
649 	sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN(
650 					sensor->prop_names.data_lanes,
651 					bridge->data_lanes, sensor->lanes);
652 	sensor->ipu_properties[1] = PROPERTY_ENTRY_REF_ARRAY(
653 					sensor->prop_names.remote_endpoint,
654 					sensor->remote_ref);
655 }
656 
657 static void ipu_bridge_init_swnode_names(struct ipu_sensor *sensor)
658 {
659 	snprintf(sensor->node_names.remote_port,
660 		 sizeof(sensor->node_names.remote_port),
661 		 SWNODE_GRAPH_PORT_NAME_FMT, sensor->link);
662 	snprintf(sensor->node_names.port,
663 		 sizeof(sensor->node_names.port),
664 		 SWNODE_GRAPH_PORT_NAME_FMT, 0); /* Always port 0 */
665 	snprintf(sensor->node_names.endpoint,
666 		 sizeof(sensor->node_names.endpoint),
667 		 SWNODE_GRAPH_ENDPOINT_NAME_FMT, 0); /* And endpoint 0 */
668 	if (sensor->vcm_type) {
669 		/* append link to distinguish nodes with same model VCM */
670 		snprintf(sensor->node_names.vcm, sizeof(sensor->node_names.vcm),
671 			 "%s-%u", sensor->vcm_type, sensor->link);
672 	}
673 
674 	if (sensor->csi_dev) {
675 		snprintf(sensor->node_names.ivsc_sensor_port,
676 			 sizeof(sensor->node_names.ivsc_sensor_port),
677 			 SWNODE_GRAPH_PORT_NAME_FMT, 0);
678 		snprintf(sensor->node_names.ivsc_ipu_port,
679 			 sizeof(sensor->node_names.ivsc_ipu_port),
680 			 SWNODE_GRAPH_PORT_NAME_FMT, 1);
681 	}
682 }
683 
684 static void ipu_bridge_init_swnode_group(struct ipu_sensor *sensor)
685 {
686 	struct software_node *nodes = sensor->swnodes;
687 
688 	sensor->group[SWNODE_SENSOR_HID] = &nodes[SWNODE_SENSOR_HID];
689 	sensor->group[SWNODE_SENSOR_PORT] = &nodes[SWNODE_SENSOR_PORT];
690 	sensor->group[SWNODE_SENSOR_ENDPOINT] = &nodes[SWNODE_SENSOR_ENDPOINT];
691 	sensor->group[SWNODE_IPU_PORT] = &nodes[SWNODE_IPU_PORT];
692 	sensor->group[SWNODE_IPU_ENDPOINT] = &nodes[SWNODE_IPU_ENDPOINT];
693 	if (sensor->vcm_type)
694 		sensor->group[SWNODE_VCM] =  &nodes[SWNODE_VCM];
695 
696 	if (sensor->csi_dev) {
697 		sensor->group[SWNODE_IVSC_HID] =
698 					&nodes[SWNODE_IVSC_HID];
699 		sensor->group[SWNODE_IVSC_SENSOR_PORT] =
700 					&nodes[SWNODE_IVSC_SENSOR_PORT];
701 		sensor->group[SWNODE_IVSC_SENSOR_ENDPOINT] =
702 					&nodes[SWNODE_IVSC_SENSOR_ENDPOINT];
703 		sensor->group[SWNODE_IVSC_IPU_PORT] =
704 					&nodes[SWNODE_IVSC_IPU_PORT];
705 		sensor->group[SWNODE_IVSC_IPU_ENDPOINT] =
706 					&nodes[SWNODE_IVSC_IPU_ENDPOINT];
707 
708 		if (sensor->vcm_type)
709 			sensor->group[SWNODE_VCM] = &nodes[SWNODE_VCM];
710 	} else {
711 		if (sensor->vcm_type)
712 			sensor->group[SWNODE_IVSC_HID] = &nodes[SWNODE_VCM];
713 	}
714 }
715 
716 static void ipu_bridge_create_connection_swnodes(struct ipu_bridge *bridge,
717 						 struct ipu_sensor *sensor)
718 {
719 	struct ipu_node_names *names = &sensor->node_names;
720 	struct software_node *nodes = sensor->swnodes;
721 
722 	ipu_bridge_init_swnode_names(sensor);
723 
724 	nodes[SWNODE_SENSOR_HID] = NODE_SENSOR(sensor->name,
725 					       sensor->dev_properties);
726 	nodes[SWNODE_SENSOR_PORT] = NODE_PORT(sensor->node_names.port,
727 					      &nodes[SWNODE_SENSOR_HID]);
728 	nodes[SWNODE_SENSOR_ENDPOINT] = NODE_ENDPOINT(
729 						sensor->node_names.endpoint,
730 						&nodes[SWNODE_SENSOR_PORT],
731 						sensor->ep_properties);
732 	nodes[SWNODE_IPU_PORT] = NODE_PORT(sensor->node_names.remote_port,
733 					   &bridge->ipu_hid_node);
734 	nodes[SWNODE_IPU_ENDPOINT] = NODE_ENDPOINT(
735 						sensor->node_names.endpoint,
736 						&nodes[SWNODE_IPU_PORT],
737 						sensor->ipu_properties);
738 
739 	if (sensor->csi_dev) {
740 		const char *device_hid = "";
741 
742 		device_hid = acpi_device_hid(sensor->ivsc_adev);
743 
744 		snprintf(sensor->ivsc_name, sizeof(sensor->ivsc_name), "%s-%u",
745 			 device_hid, sensor->link);
746 
747 		nodes[SWNODE_IVSC_HID] = NODE_SENSOR(sensor->ivsc_name,
748 						     sensor->ivsc_properties);
749 		nodes[SWNODE_IVSC_SENSOR_PORT] =
750 				NODE_PORT(names->ivsc_sensor_port,
751 					  &nodes[SWNODE_IVSC_HID]);
752 		nodes[SWNODE_IVSC_SENSOR_ENDPOINT] =
753 				NODE_ENDPOINT(names->endpoint,
754 					      &nodes[SWNODE_IVSC_SENSOR_PORT],
755 					      sensor->ivsc_sensor_ep_properties);
756 		nodes[SWNODE_IVSC_IPU_PORT] =
757 				NODE_PORT(names->ivsc_ipu_port,
758 					  &nodes[SWNODE_IVSC_HID]);
759 		nodes[SWNODE_IVSC_IPU_ENDPOINT] =
760 				NODE_ENDPOINT(names->endpoint,
761 					      &nodes[SWNODE_IVSC_IPU_PORT],
762 					      sensor->ivsc_ipu_ep_properties);
763 	}
764 
765 	nodes[SWNODE_VCM] = NODE_VCM(sensor->node_names.vcm);
766 
767 	ipu_bridge_init_swnode_group(sensor);
768 }
769 
770 /*
771  * The actual instantiation must be done from a workqueue to avoid
772  * a deadlock on taking list_lock from v4l2-async twice.
773  */
774 struct ipu_bridge_instantiate_vcm_work_data {
775 	struct work_struct work;
776 	struct device *sensor;
777 	char name[16];
778 	struct i2c_board_info board_info;
779 };
780 
781 static void ipu_bridge_instantiate_vcm_work(struct work_struct *work)
782 {
783 	struct ipu_bridge_instantiate_vcm_work_data *data =
784 		container_of(work, struct ipu_bridge_instantiate_vcm_work_data,
785 			     work);
786 	struct acpi_device *adev = ACPI_COMPANION(data->sensor);
787 	struct i2c_client *vcm_client;
788 	bool put_fwnode = true;
789 	int ret;
790 
791 	/*
792 	 * The client may get probed before the device_link gets added below
793 	 * make sure the sensor is powered-up during probe.
794 	 */
795 	ret = pm_runtime_get_sync(data->sensor);
796 	if (ret < 0) {
797 		dev_err(data->sensor, "Error %d runtime-resuming sensor, cannot instantiate VCM\n",
798 			ret);
799 		goto out_pm_put;
800 	}
801 
802 	/*
803 	 * Note the client is created only once and then kept around
804 	 * even after a rmmod, just like the software-nodes.
805 	 */
806 	vcm_client = i2c_acpi_new_device_by_fwnode(acpi_fwnode_handle(adev),
807 						   1, &data->board_info);
808 	if (IS_ERR(vcm_client)) {
809 		dev_err(data->sensor, "Error instantiating VCM client: %pe\n",
810 			vcm_client);
811 		goto out_pm_put;
812 	}
813 
814 	device_link_add(&vcm_client->dev, data->sensor, DL_FLAG_PM_RUNTIME);
815 
816 	dev_info(data->sensor, "Instantiated %s VCM\n", data->board_info.type);
817 	put_fwnode = false; /* Ownership has passed to the i2c-client */
818 
819 out_pm_put:
820 	pm_runtime_put(data->sensor);
821 	put_device(data->sensor);
822 	if (put_fwnode)
823 		fwnode_handle_put(data->board_info.fwnode);
824 	kfree(data);
825 }
826 
827 int ipu_bridge_instantiate_vcm(struct device *sensor)
828 {
829 	struct ipu_bridge_instantiate_vcm_work_data *data;
830 	struct fwnode_handle *vcm_fwnode;
831 	struct i2c_client *vcm_client;
832 	struct acpi_device *adev;
833 	char *sep;
834 
835 	adev = ACPI_COMPANION(sensor);
836 	if (!adev)
837 		return 0;
838 
839 	vcm_fwnode = fwnode_find_reference(dev_fwnode(sensor), "lens-focus", 0);
840 	if (IS_ERR(vcm_fwnode))
841 		return 0;
842 
843 	/* When reloading modules the client will already exist */
844 	vcm_client = i2c_find_device_by_fwnode(vcm_fwnode);
845 	if (vcm_client) {
846 		fwnode_handle_put(vcm_fwnode);
847 		put_device(&vcm_client->dev);
848 		return 0;
849 	}
850 
851 	data = kzalloc_obj(*data);
852 	if (!data) {
853 		fwnode_handle_put(vcm_fwnode);
854 		return -ENOMEM;
855 	}
856 
857 	INIT_WORK(&data->work, ipu_bridge_instantiate_vcm_work);
858 	data->sensor = get_device(sensor);
859 	snprintf(data->name, sizeof(data->name), "%s-VCM",
860 		 acpi_dev_name(adev));
861 	data->board_info.dev_name = data->name;
862 	data->board_info.fwnode = vcm_fwnode;
863 	snprintf(data->board_info.type, sizeof(data->board_info.type),
864 		 "%pfwP", vcm_fwnode);
865 	/* Strip "-<link>" postfix */
866 	sep = strchrnul(data->board_info.type, '-');
867 	*sep = 0;
868 
869 	queue_work(system_long_wq, &data->work);
870 
871 	return 0;
872 }
873 EXPORT_SYMBOL_NS_GPL(ipu_bridge_instantiate_vcm, "INTEL_IPU_BRIDGE");
874 
875 static int ipu_bridge_instantiate_ivsc(struct ipu_sensor *sensor)
876 {
877 	struct fwnode_handle *fwnode;
878 
879 	if (!sensor->csi_dev)
880 		return 0;
881 
882 	fwnode = software_node_fwnode(&sensor->swnodes[SWNODE_IVSC_HID]);
883 	if (!fwnode)
884 		return -ENODEV;
885 
886 	set_secondary_fwnode(sensor->csi_dev, fwnode);
887 
888 	return 0;
889 }
890 
891 static void ipu_bridge_unregister_sensors(struct ipu_bridge *bridge)
892 {
893 	struct ipu_sensor *sensor;
894 	unsigned int i;
895 
896 	for (i = 0; i < bridge->n_sensors; i++) {
897 		sensor = &bridge->sensors[i];
898 		software_node_unregister_node_group(sensor->group);
899 		acpi_dev_put(sensor->adev);
900 		put_device(sensor->csi_dev);
901 		acpi_dev_put(sensor->ivsc_adev);
902 	}
903 }
904 
905 static int ipu_bridge_connect_sensor(const struct ipu_sensor_config *cfg,
906 				     struct ipu_bridge *bridge)
907 {
908 	struct fwnode_handle *fwnode, *primary;
909 	struct ipu_sensor *sensor;
910 	struct acpi_device *adev = NULL;
911 	int ret;
912 
913 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
914 		if (!ACPI_PTR(adev->status.enabled))
915 			continue;
916 
917 		if (bridge->n_sensors >= IPU_MAX_PORTS) {
918 			acpi_dev_put(adev);
919 			dev_err(bridge->dev, "Exceeded available IPU ports\n");
920 			return -EINVAL;
921 		}
922 
923 		sensor = &bridge->sensors[bridge->n_sensors];
924 
925 		ret = bridge->parse_sensor_fwnode(adev, sensor);
926 		if (ret)
927 			goto err_put_adev;
928 
929 		snprintf(sensor->name, sizeof(sensor->name), "%s-%u",
930 			 cfg->hid, sensor->link);
931 
932 		ret = ipu_bridge_check_ivsc_dev(sensor, adev);
933 		if (ret)
934 			goto err_put_adev;
935 
936 		ipu_bridge_create_fwnode_properties(sensor, bridge, cfg);
937 		ipu_bridge_create_connection_swnodes(bridge, sensor);
938 
939 		ret = software_node_register_node_group(sensor->group);
940 		if (ret)
941 			goto err_put_ivsc;
942 
943 		fwnode = software_node_fwnode(&sensor->swnodes[
944 						      SWNODE_SENSOR_HID]);
945 		if (!fwnode) {
946 			ret = -ENODEV;
947 			goto err_free_swnodes;
948 		}
949 
950 		sensor->adev = ACPI_PTR(acpi_dev_get(adev));
951 
952 		primary = acpi_fwnode_handle(adev);
953 		primary->secondary = fwnode;
954 
955 		ret = ipu_bridge_instantiate_ivsc(sensor);
956 		if (ret)
957 			goto err_free_swnodes;
958 
959 		dev_info(bridge->dev, "Found supported sensor %s (%pfw)\n",
960 			 acpi_dev_name(adev), primary);
961 
962 		bridge->n_sensors++;
963 	}
964 
965 	return 0;
966 
967 err_free_swnodes:
968 	software_node_unregister_node_group(sensor->group);
969 err_put_ivsc:
970 	put_device(sensor->csi_dev);
971 	acpi_dev_put(sensor->ivsc_adev);
972 err_put_adev:
973 	acpi_dev_put(adev);
974 	return ret;
975 }
976 
977 /*
978  * Whether a sensor config applies to the IPU this bridge sits on. A config
979  * listing PCI product IDs only applies to those IPUs.
980  */
981 static bool ipu_bridge_config_matches(const struct ipu_sensor_config *cfg,
982 				      struct ipu_bridge *bridge)
983 {
984 	const u16 *id;
985 
986 	if (!cfg->pci_ids)
987 		return true;
988 
989 	for (id = cfg->pci_ids; *id; id++)
990 		if (*id == bridge->pci_id)
991 			return true;
992 
993 	return false;
994 }
995 
996 static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge)
997 {
998 	const char *done_hid = NULL;
999 	unsigned int i;
1000 	int ret;
1001 
1002 	for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) {
1003 		const struct ipu_sensor_config *cfg =
1004 			&ipu_supported_sensors[i];
1005 
1006 		/*
1007 		 * Entries for one HID are adjacent, IPU-specific ones first,
1008 		 * so the generic entry is skipped once a specific one has
1009 		 * matched and the sensor is not connected twice.
1010 		 */
1011 		if (done_hid && !strcmp(cfg->hid, done_hid))
1012 			continue;
1013 
1014 		if (!ipu_bridge_config_matches(cfg, bridge))
1015 			continue;
1016 
1017 		ret = ipu_bridge_connect_sensor(cfg, bridge);
1018 		if (ret)
1019 			goto err_unregister_sensors;
1020 
1021 		done_hid = cfg->hid;
1022 	}
1023 
1024 	return 0;
1025 
1026 err_unregister_sensors:
1027 	ipu_bridge_unregister_sensors(bridge);
1028 	return ret;
1029 }
1030 
1031 static int ipu_bridge_ivsc_is_ready(void)
1032 {
1033 	struct acpi_device *sensor_adev, *adev;
1034 	struct device *csi_dev;
1035 	bool ready = true;
1036 	unsigned int i;
1037 
1038 	for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) {
1039 		const struct ipu_sensor_config *cfg =
1040 			&ipu_supported_sensors[i];
1041 
1042 		for_each_acpi_dev_match(sensor_adev, cfg->hid, NULL, -1) {
1043 			if (!ACPI_PTR(sensor_adev->status.enabled))
1044 				continue;
1045 
1046 			adev = ipu_bridge_get_ivsc_acpi_dev(sensor_adev);
1047 			if (!adev)
1048 				continue;
1049 
1050 			csi_dev = ipu_bridge_get_ivsc_csi_dev(adev);
1051 			if (!csi_dev)
1052 				ready = false;
1053 
1054 			put_device(csi_dev);
1055 			acpi_dev_put(adev);
1056 		}
1057 	}
1058 
1059 	return ready;
1060 }
1061 
1062 static int ipu_bridge_check_fwnode_graph(struct fwnode_handle *fwnode)
1063 {
1064 	struct fwnode_handle *endpoint;
1065 
1066 	if (IS_ERR_OR_NULL(fwnode))
1067 		return -EINVAL;
1068 
1069 	endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
1070 	if (endpoint) {
1071 		fwnode_handle_put(endpoint);
1072 		return 0;
1073 	}
1074 
1075 	return ipu_bridge_check_fwnode_graph(fwnode->secondary);
1076 }
1077 
1078 struct pci_dev *ipu_bridge_get_ipu6(void)
1079 {
1080 	struct pci_dev *ipu = NULL;
1081 
1082 	for (unsigned int i = 0; !ipu && ipu6_pci_tbl[i].vendor; i++)
1083 		ipu = pci_get_device(ipu6_pci_tbl[i].vendor,
1084 				     ipu6_pci_tbl[i].device, NULL);
1085 
1086 	return ipu;
1087 }
1088 EXPORT_SYMBOL_NS_GPL(ipu_bridge_get_ipu6, "INTEL_IPU_BRIDGE");
1089 
1090 static DEFINE_MUTEX(ipu_bridge_mutex);
1091 
1092 int ipu_bridge_init(struct device *dev,
1093 		    ipu_parse_sensor_fwnode_t parse_sensor_fwnode)
1094 {
1095 	struct fwnode_handle *fwnode;
1096 	struct ipu_bridge *bridge;
1097 	unsigned int i;
1098 	int ret;
1099 
1100 	guard(mutex)(&ipu_bridge_mutex);
1101 
1102 	if (!ipu_bridge_check_fwnode_graph(dev_fwnode(dev)))
1103 		return 0;
1104 
1105 	if (!ipu_bridge_ivsc_is_ready())
1106 		return dev_err_probe(dev, -EPROBE_DEFER,
1107 				     "waiting for IVSC to become ready\n");
1108 
1109 	bridge = kzalloc_obj(*bridge);
1110 	if (!bridge)
1111 		return -ENOMEM;
1112 
1113 	strscpy(bridge->ipu_node_name, IPU_HID,
1114 		sizeof(bridge->ipu_node_name));
1115 	bridge->ipu_hid_node.name = bridge->ipu_node_name;
1116 	bridge->dev = dev;
1117 	bridge->pci_id = dev_is_pci(dev) ? to_pci_dev(dev)->device : 0;
1118 	bridge->parse_sensor_fwnode = parse_sensor_fwnode;
1119 
1120 	ret = software_node_register(&bridge->ipu_hid_node);
1121 	if (ret < 0) {
1122 		dev_err(dev, "Failed to register the IPU HID node\n");
1123 		goto err_free_bridge;
1124 	}
1125 
1126 	/*
1127 	 * Map the lane arrangement, which is fixed for the IPU3 (meaning we
1128 	 * only need one, rather than one per sensor). We include it as a
1129 	 * member of the struct ipu_bridge rather than a global variable so
1130 	 * that it survives if the module is unloaded along with the rest of
1131 	 * the struct.
1132 	 */
1133 	for (i = 0; i < IPU_MAX_LANES; i++)
1134 		bridge->data_lanes[i] = i + 1;
1135 
1136 	ret = ipu_bridge_connect_sensors(bridge);
1137 	if (ret || bridge->n_sensors == 0)
1138 		goto err_unregister_ipu;
1139 
1140 	dev_info(dev, "Connected %d cameras\n", bridge->n_sensors);
1141 
1142 	fwnode = software_node_fwnode(&bridge->ipu_hid_node);
1143 	if (!fwnode) {
1144 		dev_err(dev, "Error getting fwnode from ipu software_node\n");
1145 		ret = -ENODEV;
1146 		goto err_unregister_sensors;
1147 	}
1148 
1149 	set_secondary_fwnode(dev, fwnode);
1150 
1151 	return 0;
1152 
1153 err_unregister_sensors:
1154 	ipu_bridge_unregister_sensors(bridge);
1155 err_unregister_ipu:
1156 	software_node_unregister(&bridge->ipu_hid_node);
1157 err_free_bridge:
1158 	kfree(bridge);
1159 
1160 	return ret;
1161 }
1162 EXPORT_SYMBOL_NS_GPL(ipu_bridge_init, "INTEL_IPU_BRIDGE");
1163 
1164 MODULE_LICENSE("GPL");
1165 MODULE_DESCRIPTION("Intel IPU Sensors Bridge driver");
1166