1 // SPDX-License-Identifier: GPL-2.0-only
3 * MIPI DisCo for Imaging support.
5 * Copyright (C) 2023 Intel Corporation
7 * Support MIPI DisCo for Imaging by parsing ACPI _CRS CSI-2 records defined in
8 * Section 6.4.3.8.2.4 "Camera Serial Interface (CSI-2) Connection Resource
9 * Descriptor" of ACPI 6.5 and using device properties defined by the MIPI DisCo
10 * for Imaging specification.
12 * The implementation looks for the information in the ACPI namespace (CSI-2
13 * resource descriptors in _CRS) and constructs software nodes compatible with
14 * Documentation/firmware-guide/acpi/dsd/graph.rst to represent the CSI-2
15 * connection graph. The software nodes are then populated with the data
16 * extracted from the _CRS CSI-2 resource descriptors and the MIPI DisCo
17 * for Imaging device properties present in _DSD for the ACPI device objects
18 * with CSI-2 connections.
21 #include <linux/acpi.h>
22 #include <linux/dmi.h>
23 #include <linux/limits.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/overflow.h>
27 #include <linux/types.h>
28 #include <linux/slab.h>
29 #include <linux/string.h>
31 #include <media/v4l2-fwnode.h>
35 static LIST_HEAD(acpi_mipi_crs_csi2_list
);
37 static void acpi_mipi_data_tag(acpi_handle handle
, void *context
)
41 /* Connection data extracted from one _CRS CSI-2 resource descriptor. */
42 struct crs_csi2_connection
{
43 struct list_head entry
;
44 struct acpi_resource_csi2_serialbus csi2_data
;
45 acpi_handle remote_handle
;
49 /* Data extracted from _CRS CSI-2 resource descriptors for one device. */
51 struct list_head entry
;
53 struct acpi_device_software_nodes
*swnodes
;
54 struct list_head connections
;
58 struct csi2_resources_walk_data
{
60 struct list_head connections
;
63 static acpi_status
parse_csi2_resource(struct acpi_resource
*res
, void *context
)
65 struct csi2_resources_walk_data
*crwd
= context
;
66 struct acpi_resource_csi2_serialbus
*csi2_res
;
67 struct acpi_resource_source
*csi2_res_src
;
68 u16 csi2_res_src_length
;
69 struct crs_csi2_connection
*conn
;
70 acpi_handle remote_handle
;
72 if (res
->type
!= ACPI_RESOURCE_TYPE_SERIAL_BUS
)
75 csi2_res
= &res
->data
.csi2_serial_bus
;
77 if (csi2_res
->type
!= ACPI_RESOURCE_SERIAL_TYPE_CSI2
)
80 csi2_res_src
= &csi2_res
->resource_source
;
81 if (ACPI_FAILURE(acpi_get_handle(NULL
, csi2_res_src
->string_ptr
,
83 acpi_handle_debug(crwd
->handle
,
84 "unable to find resource source\n");
87 csi2_res_src_length
= csi2_res_src
->string_length
;
88 if (!csi2_res_src_length
) {
89 acpi_handle_debug(crwd
->handle
,
90 "invalid resource source string length\n");
94 conn
= kmalloc(struct_size(conn
, remote_name
, csi2_res_src_length
+ 1),
99 conn
->csi2_data
= *csi2_res
;
100 strscpy(conn
->remote_name
, csi2_res_src
->string_ptr
, csi2_res_src_length
);
101 conn
->csi2_data
.resource_source
.string_ptr
= conn
->remote_name
;
102 conn
->remote_handle
= remote_handle
;
104 list_add(&conn
->entry
, &crwd
->connections
);
109 static struct crs_csi2
*acpi_mipi_add_crs_csi2(acpi_handle handle
,
110 struct list_head
*list
)
112 struct crs_csi2
*csi2
;
114 csi2
= kzalloc(sizeof(*csi2
), GFP_KERNEL
);
118 csi2
->handle
= handle
;
119 INIT_LIST_HEAD(&csi2
->connections
);
120 csi2
->port_count
= 1;
122 if (ACPI_FAILURE(acpi_attach_data(handle
, acpi_mipi_data_tag
, csi2
))) {
127 list_add(&csi2
->entry
, list
);
132 static struct crs_csi2
*acpi_mipi_get_crs_csi2(acpi_handle handle
)
134 struct crs_csi2
*csi2
;
136 if (ACPI_FAILURE(acpi_get_data_full(handle
, acpi_mipi_data_tag
,
137 (void **)&csi2
, NULL
)))
143 static void csi_csr2_release_connections(struct list_head
*list
)
145 struct crs_csi2_connection
*conn
, *conn_tmp
;
147 list_for_each_entry_safe(conn
, conn_tmp
, list
, entry
) {
148 list_del(&conn
->entry
);
153 static void acpi_mipi_del_crs_csi2(struct crs_csi2
*csi2
)
155 list_del(&csi2
->entry
);
156 acpi_detach_data(csi2
->handle
, acpi_mipi_data_tag
);
157 kfree(csi2
->swnodes
);
158 csi_csr2_release_connections(&csi2
->connections
);
163 * acpi_mipi_check_crs_csi2 - Look for CSI-2 resources in _CRS
164 * @handle: Device object handle to evaluate _CRS for.
166 * Find all CSI-2 resource descriptors in the given device's _CRS
167 * and collect them into a list.
169 void acpi_mipi_check_crs_csi2(acpi_handle handle
)
171 struct csi2_resources_walk_data crwd
= {
173 .connections
= LIST_HEAD_INIT(crwd
.connections
),
175 struct crs_csi2
*csi2
;
178 * Avoid allocating _CRS CSI-2 objects for devices without any CSI-2
179 * resource descriptions in _CRS to reduce overhead.
181 acpi_walk_resources(handle
, METHOD_NAME__CRS
, parse_csi2_resource
, &crwd
);
182 if (list_empty(&crwd
.connections
))
186 * Create a _CRS CSI-2 entry to store the extracted connection
187 * information and add it to the global list.
189 csi2
= acpi_mipi_add_crs_csi2(handle
, &acpi_mipi_crs_csi2_list
);
191 csi_csr2_release_connections(&crwd
.connections
);
192 return; /* Nothing really can be done about this. */
195 list_replace(&crwd
.connections
, &csi2
->connections
);
198 #define NO_CSI2_PORT (UINT_MAX - 1)
200 static void alloc_crs_csi2_swnodes(struct crs_csi2
*csi2
)
202 size_t port_count
= csi2
->port_count
;
203 struct acpi_device_software_nodes
*swnodes
;
208 * Allocate memory for ports, node pointers (number of nodes +
209 * 1 (guardian), nodes (root + number of ports * 2 (because for
210 * every port there is an endpoint)).
212 if (check_mul_overflow(sizeof(*swnodes
->ports
) +
213 sizeof(*swnodes
->nodes
) * 2 +
214 sizeof(*swnodes
->nodeptrs
) * 2,
215 port_count
, &alloc_size
) ||
216 check_add_overflow(sizeof(*swnodes
) +
217 sizeof(*swnodes
->nodes
) +
218 sizeof(*swnodes
->nodeptrs
) * 2,
219 alloc_size
, &alloc_size
)) {
220 acpi_handle_info(csi2
->handle
,
221 "too many _CRS CSI-2 resource handles (%zu)",
226 swnodes
= kmalloc(alloc_size
, GFP_KERNEL
);
230 swnodes
->ports
= (struct acpi_device_software_node_port
*)(swnodes
+ 1);
231 swnodes
->nodes
= (struct software_node
*)(swnodes
->ports
+ port_count
);
232 swnodes
->nodeptrs
= (const struct software_node
**)(swnodes
->nodes
+ 1 +
234 swnodes
->num_ports
= port_count
;
236 for (i
= 0; i
< 2 * port_count
+ 1; i
++)
237 swnodes
->nodeptrs
[i
] = &swnodes
->nodes
[i
];
239 swnodes
->nodeptrs
[i
] = NULL
;
241 for (i
= 0; i
< port_count
; i
++)
242 swnodes
->ports
[i
].port_nr
= NO_CSI2_PORT
;
244 csi2
->swnodes
= swnodes
;
247 #define ACPI_CRS_CSI2_PHY_TYPE_C 0
248 #define ACPI_CRS_CSI2_PHY_TYPE_D 1
250 static unsigned int next_csi2_port_index(struct acpi_device_software_nodes
*swnodes
,
251 unsigned int port_nr
)
255 for (i
= 0; i
< swnodes
->num_ports
; i
++) {
256 struct acpi_device_software_node_port
*port
= &swnodes
->ports
[i
];
258 if (port
->port_nr
== port_nr
)
261 if (port
->port_nr
== NO_CSI2_PORT
) {
262 port
->port_nr
= port_nr
;
270 /* Print graph port name into a buffer, return non-zero on failure. */
271 #define GRAPH_PORT_NAME(var, num) \
272 (snprintf((var), sizeof(var), SWNODE_GRAPH_PORT_NAME_FMT, (num)) >= \
275 static void extract_crs_csi2_conn_info(acpi_handle local_handle
,
276 struct acpi_device_software_nodes
*local_swnodes
,
277 struct crs_csi2_connection
*conn
)
279 struct crs_csi2
*remote_csi2
= acpi_mipi_get_crs_csi2(conn
->remote_handle
);
280 struct acpi_device_software_nodes
*remote_swnodes
;
281 struct acpi_device_software_node_port
*local_port
, *remote_port
;
282 struct software_node
*local_node
, *remote_node
;
283 unsigned int local_index
, remote_index
;
284 unsigned int bus_type
;
287 * If the previous steps have failed to make room for a _CRS CSI-2
288 * representation for the remote end of the given connection, skip it.
293 remote_swnodes
= remote_csi2
->swnodes
;
297 switch (conn
->csi2_data
.phy_type
) {
298 case ACPI_CRS_CSI2_PHY_TYPE_C
:
299 bus_type
= V4L2_FWNODE_BUS_TYPE_CSI2_CPHY
;
302 case ACPI_CRS_CSI2_PHY_TYPE_D
:
303 bus_type
= V4L2_FWNODE_BUS_TYPE_CSI2_DPHY
;
307 acpi_handle_info(local_handle
, "unknown CSI-2 PHY type %u\n",
308 conn
->csi2_data
.phy_type
);
312 local_index
= next_csi2_port_index(local_swnodes
,
313 conn
->csi2_data
.local_port_instance
);
314 if (WARN_ON_ONCE(local_index
>= local_swnodes
->num_ports
))
317 remote_index
= next_csi2_port_index(remote_swnodes
,
318 conn
->csi2_data
.resource_source
.index
);
319 if (WARN_ON_ONCE(remote_index
>= remote_swnodes
->num_ports
))
322 local_port
= &local_swnodes
->ports
[local_index
];
323 local_node
= &local_swnodes
->nodes
[ACPI_DEVICE_SWNODE_EP(local_index
)];
324 local_port
->crs_csi2_local
= true;
326 remote_port
= &remote_swnodes
->ports
[remote_index
];
327 remote_node
= &remote_swnodes
->nodes
[ACPI_DEVICE_SWNODE_EP(remote_index
)];
329 local_port
->remote_ep
[0] = SOFTWARE_NODE_REFERENCE(remote_node
);
330 remote_port
->remote_ep
[0] = SOFTWARE_NODE_REFERENCE(local_node
);
332 local_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_REMOTE_EP
] =
333 PROPERTY_ENTRY_REF_ARRAY("remote-endpoint",
334 local_port
->remote_ep
);
336 local_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_BUS_TYPE
] =
337 PROPERTY_ENTRY_U32("bus-type", bus_type
);
339 local_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_REG
] =
340 PROPERTY_ENTRY_U32("reg", 0);
342 local_port
->port_props
[ACPI_DEVICE_SWNODE_PORT_REG
] =
343 PROPERTY_ENTRY_U32("reg", conn
->csi2_data
.local_port_instance
);
345 if (GRAPH_PORT_NAME(local_port
->port_name
,
346 conn
->csi2_data
.local_port_instance
))
347 acpi_handle_info(local_handle
, "local port %u name too long",
348 conn
->csi2_data
.local_port_instance
);
350 remote_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_REMOTE_EP
] =
351 PROPERTY_ENTRY_REF_ARRAY("remote-endpoint",
352 remote_port
->remote_ep
);
354 remote_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_BUS_TYPE
] =
355 PROPERTY_ENTRY_U32("bus-type", bus_type
);
357 remote_port
->ep_props
[ACPI_DEVICE_SWNODE_EP_REG
] =
358 PROPERTY_ENTRY_U32("reg", 0);
360 remote_port
->port_props
[ACPI_DEVICE_SWNODE_PORT_REG
] =
361 PROPERTY_ENTRY_U32("reg", conn
->csi2_data
.resource_source
.index
);
363 if (GRAPH_PORT_NAME(remote_port
->port_name
,
364 conn
->csi2_data
.resource_source
.index
))
365 acpi_handle_info(local_handle
, "remote port %u name too long",
366 conn
->csi2_data
.resource_source
.index
);
369 static void prepare_crs_csi2_swnodes(struct crs_csi2
*csi2
)
371 struct acpi_device_software_nodes
*local_swnodes
= csi2
->swnodes
;
372 acpi_handle local_handle
= csi2
->handle
;
373 struct crs_csi2_connection
*conn
;
375 /* Bail out if the allocation of swnodes has failed. */
379 list_for_each_entry(conn
, &csi2
->connections
, entry
)
380 extract_crs_csi2_conn_info(local_handle
, local_swnodes
, conn
);
384 * acpi_mipi_scan_crs_csi2 - Create ACPI _CRS CSI-2 software nodes
386 * Note that this function must be called before any struct acpi_device objects
387 * are bound to any ACPI drivers or scan handlers, so it cannot assume the
388 * existence of struct acpi_device objects for every device present in the ACPI
391 * acpi_scan_lock in scan.c must be held when calling this function.
393 void acpi_mipi_scan_crs_csi2(void)
395 struct crs_csi2
*csi2
;
398 /* Count references to each ACPI handle in the CSI-2 connection graph. */
399 list_for_each_entry(csi2
, &acpi_mipi_crs_csi2_list
, entry
) {
400 struct crs_csi2_connection
*conn
;
402 list_for_each_entry(conn
, &csi2
->connections
, entry
) {
403 struct crs_csi2
*remote_csi2
;
407 remote_csi2
= acpi_mipi_get_crs_csi2(conn
->remote_handle
);
409 remote_csi2
->port_count
++;
413 * The remote endpoint has no _CRS CSI-2 list entry yet,
414 * so create one for it and add it to the list.
416 acpi_mipi_add_crs_csi2(conn
->remote_handle
, &aux_list
);
419 list_splice(&aux_list
, &acpi_mipi_crs_csi2_list
);
422 * Allocate software nodes for representing the CSI-2 information.
424 * This needs to be done for all of the list entries in one go, because
425 * they may point to each other without restrictions and the next step
426 * relies on the availability of swnodes memory for each list entry.
428 list_for_each_entry(csi2
, &acpi_mipi_crs_csi2_list
, entry
)
429 alloc_crs_csi2_swnodes(csi2
);
432 * Set up software node properties using data from _CRS CSI-2 resource
435 list_for_each_entry(csi2
, &acpi_mipi_crs_csi2_list
, entry
)
436 prepare_crs_csi2_swnodes(csi2
);
440 * Get the index of the next property in the property array, with a given
443 #define NEXT_PROPERTY(index, max) \
444 (WARN_ON((index) > ACPI_DEVICE_SWNODE_##max) ? \
445 ACPI_DEVICE_SWNODE_##max : (index)++)
447 static void init_csi2_port_local(struct acpi_device
*adev
,
448 struct acpi_device_software_node_port
*port
,
449 struct fwnode_handle
*port_fwnode
,
452 acpi_handle handle
= acpi_device_handle(adev
);
453 unsigned int num_link_freqs
;
456 ret
= fwnode_property_count_u64(port_fwnode
, "mipi-img-link-frequencies");
460 num_link_freqs
= ret
;
461 if (num_link_freqs
> ACPI_DEVICE_CSI2_DATA_LANES
) {
462 acpi_handle_info(handle
, "Too many link frequencies: %u\n",
464 num_link_freqs
= ACPI_DEVICE_CSI2_DATA_LANES
;
467 ret
= fwnode_property_read_u64_array(port_fwnode
,
468 "mipi-img-link-frequencies",
469 port
->link_frequencies
,
472 acpi_handle_info(handle
, "Unable to get link frequencies (%d)\n",
477 port
->ep_props
[NEXT_PROPERTY(index
, EP_LINK_FREQUENCIES
)] =
478 PROPERTY_ENTRY_U64_ARRAY_LEN("link-frequencies",
479 port
->link_frequencies
,
483 static void init_csi2_port(struct acpi_device
*adev
,
484 struct acpi_device_software_nodes
*swnodes
,
485 struct acpi_device_software_node_port
*port
,
486 struct fwnode_handle
*port_fwnode
,
487 unsigned int port_index
)
489 unsigned int ep_prop_index
= ACPI_DEVICE_SWNODE_EP_CLOCK_LANES
;
490 acpi_handle handle
= acpi_device_handle(adev
);
491 u8 val
[ACPI_DEVICE_CSI2_DATA_LANES
];
495 if (GRAPH_PORT_NAME(port
->port_name
, port
->port_nr
))
498 swnodes
->nodes
[ACPI_DEVICE_SWNODE_PORT(port_index
)] =
499 SOFTWARE_NODE(port
->port_name
, port
->port_props
,
500 &swnodes
->nodes
[ACPI_DEVICE_SWNODE_ROOT
]);
502 ret
= fwnode_property_read_u8(port_fwnode
, "mipi-img-clock-lane", val
);
504 port
->ep_props
[NEXT_PROPERTY(ep_prop_index
, EP_CLOCK_LANES
)] =
505 PROPERTY_ENTRY_U32("clock-lanes", val
[0]);
507 ret
= fwnode_property_count_u8(port_fwnode
, "mipi-img-data-lanes");
511 if (num_lanes
> ACPI_DEVICE_CSI2_DATA_LANES
) {
512 acpi_handle_info(handle
, "Too many data lanes: %u\n",
514 num_lanes
= ACPI_DEVICE_CSI2_DATA_LANES
;
517 ret
= fwnode_property_read_u8_array(port_fwnode
,
518 "mipi-img-data-lanes",
523 for (i
= 0; i
< num_lanes
; i
++)
524 port
->data_lanes
[i
] = val
[i
];
526 port
->ep_props
[NEXT_PROPERTY(ep_prop_index
, EP_DATA_LANES
)] =
527 PROPERTY_ENTRY_U32_ARRAY_LEN("data-lanes",
533 ret
= fwnode_property_count_u8(port_fwnode
, "mipi-img-lane-polarities");
535 acpi_handle_debug(handle
, "Lane polarity bytes missing\n");
536 } else if (ret
* BITS_PER_TYPE(u8
) < num_lanes
+ 1) {
537 acpi_handle_info(handle
, "Too few lane polarity bits (%zu vs. %d)\n",
538 ret
* BITS_PER_TYPE(u8
), num_lanes
+ 1);
540 unsigned long mask
= 0;
541 int byte_count
= ret
;
545 * The total number of lanes is ACPI_DEVICE_CSI2_DATA_LANES + 1
546 * (data lanes + clock lane). It is not expected to ever be
547 * greater than the number of bits in an unsigned long
548 * variable, but ensure that this is the case.
550 BUILD_BUG_ON(BITS_PER_TYPE(unsigned long) <= ACPI_DEVICE_CSI2_DATA_LANES
);
552 if (byte_count
> sizeof(mask
)) {
553 acpi_handle_info(handle
, "Too many lane polarities: %d\n",
555 byte_count
= sizeof(mask
);
557 fwnode_property_read_u8_array(port_fwnode
, "mipi-img-lane-polarities",
560 for (i
= 0; i
< byte_count
; i
++)
561 mask
|= (unsigned long)val
[i
] << BITS_PER_TYPE(u8
) * i
;
563 for (i
= 0; i
<= num_lanes
; i
++)
564 port
->lane_polarities
[i
] = test_bit(i
, &mask
);
566 port
->ep_props
[NEXT_PROPERTY(ep_prop_index
, EP_LANE_POLARITIES
)] =
567 PROPERTY_ENTRY_U32_ARRAY_LEN("lane-polarities",
568 port
->lane_polarities
,
572 swnodes
->nodes
[ACPI_DEVICE_SWNODE_EP(port_index
)] =
573 SOFTWARE_NODE("endpoint@0", swnodes
->ports
[port_index
].ep_props
,
574 &swnodes
->nodes
[ACPI_DEVICE_SWNODE_PORT(port_index
)]);
576 if (port
->crs_csi2_local
)
577 init_csi2_port_local(adev
, port
, port_fwnode
, ep_prop_index
);
580 #define MIPI_IMG_PORT_PREFIX "mipi-img-port-"
582 static struct fwnode_handle
*get_mipi_port_handle(struct fwnode_handle
*adev_fwnode
,
583 unsigned int port_nr
)
585 char port_name
[sizeof(MIPI_IMG_PORT_PREFIX
) + 2];
587 if (snprintf(port_name
, sizeof(port_name
), "%s%u",
588 MIPI_IMG_PORT_PREFIX
, port_nr
) >= sizeof(port_name
))
591 return fwnode_get_named_child_node(adev_fwnode
, port_name
);
594 static void init_crs_csi2_swnodes(struct crs_csi2
*csi2
)
596 struct acpi_buffer buffer
= { .length
= ACPI_ALLOCATE_BUFFER
};
597 struct acpi_device_software_nodes
*swnodes
= csi2
->swnodes
;
598 acpi_handle handle
= csi2
->handle
;
599 unsigned int prop_index
= 0;
600 struct fwnode_handle
*adev_fwnode
;
601 struct acpi_device
*adev
;
608 * Bail out if the swnodes are not available (either they have not been
609 * allocated or they have been assigned to the device already).
614 adev
= acpi_fetch_acpi_dev(handle
);
618 adev_fwnode
= acpi_fwnode_handle(adev
);
621 * If the "rotation" property is not present, but _PLD is there,
622 * evaluate it to get the "rotation" value.
624 if (!fwnode_property_present(adev_fwnode
, "rotation")) {
625 struct acpi_pld_info
*pld
;
627 status
= acpi_get_physical_device_location(handle
, &pld
);
628 if (ACPI_SUCCESS(status
)) {
629 swnodes
->dev_props
[NEXT_PROPERTY(prop_index
, DEV_ROTATION
)] =
630 PROPERTY_ENTRY_U32("rotation",
631 pld
->rotation
* 45U);
636 if (!fwnode_property_read_u32(adev_fwnode
, "mipi-img-clock-frequency", &val
))
637 swnodes
->dev_props
[NEXT_PROPERTY(prop_index
, DEV_CLOCK_FREQUENCY
)] =
638 PROPERTY_ENTRY_U32("clock-frequency", val
);
640 if (!fwnode_property_read_u32(adev_fwnode
, "mipi-img-led-max-current", &val
))
641 swnodes
->dev_props
[NEXT_PROPERTY(prop_index
, DEV_LED_MAX_MICROAMP
)] =
642 PROPERTY_ENTRY_U32("led-max-microamp", val
);
644 if (!fwnode_property_read_u32(adev_fwnode
, "mipi-img-flash-max-current", &val
))
645 swnodes
->dev_props
[NEXT_PROPERTY(prop_index
, DEV_FLASH_MAX_MICROAMP
)] =
646 PROPERTY_ENTRY_U32("flash-max-microamp", val
);
648 if (!fwnode_property_read_u32(adev_fwnode
, "mipi-img-flash-max-timeout-us", &val
))
649 swnodes
->dev_props
[NEXT_PROPERTY(prop_index
, DEV_FLASH_MAX_TIMEOUT_US
)] =
650 PROPERTY_ENTRY_U32("flash-max-timeout-us", val
);
652 status
= acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
653 if (ACPI_FAILURE(status
)) {
654 acpi_handle_info(handle
, "Unable to get the path name\n");
658 swnodes
->nodes
[ACPI_DEVICE_SWNODE_ROOT
] =
659 SOFTWARE_NODE(buffer
.pointer
, swnodes
->dev_props
, NULL
);
661 for (i
= 0; i
< swnodes
->num_ports
; i
++) {
662 struct acpi_device_software_node_port
*port
= &swnodes
->ports
[i
];
663 struct fwnode_handle
*port_fwnode
;
666 * The MIPI DisCo for Imaging specification defines _DSD device
667 * properties for providing CSI-2 port parameters that can be
668 * accessed through the generic device properties framework. To
669 * access them, it is first necessary to find the data node
670 * representing the port under the given ACPI device object.
672 port_fwnode
= get_mipi_port_handle(adev_fwnode
, port
->port_nr
);
674 acpi_handle_info(handle
,
675 "MIPI port name too long for port %u\n",
680 init_csi2_port(adev
, swnodes
, port
, port_fwnode
, i
);
682 fwnode_handle_put(port_fwnode
);
685 ret
= software_node_register_node_group(swnodes
->nodeptrs
);
687 acpi_handle_info(handle
,
688 "Unable to register software nodes (%d)\n", ret
);
692 adev
->swnodes
= swnodes
;
693 adev_fwnode
->secondary
= software_node_fwnode(swnodes
->nodes
);
696 * Prevents the swnodes from this csi2 entry from being assigned again
697 * or freed prematurely.
699 csi2
->swnodes
= NULL
;
703 * acpi_mipi_init_crs_csi2_swnodes - Initialize _CRS CSI-2 software nodes
705 * Use MIPI DisCo for Imaging device properties to finalize the initialization
706 * of CSI-2 software nodes for all ACPI device objects that have been already
709 void acpi_mipi_init_crs_csi2_swnodes(void)
711 struct crs_csi2
*csi2
, *csi2_tmp
;
713 list_for_each_entry_safe(csi2
, csi2_tmp
, &acpi_mipi_crs_csi2_list
, entry
)
714 init_crs_csi2_swnodes(csi2
);
718 * acpi_mipi_crs_csi2_cleanup - Free _CRS CSI-2 temporary data
720 void acpi_mipi_crs_csi2_cleanup(void)
722 struct crs_csi2
*csi2
, *csi2_tmp
;
724 list_for_each_entry_safe(csi2
, csi2_tmp
, &acpi_mipi_crs_csi2_list
, entry
)
725 acpi_mipi_del_crs_csi2(csi2
);
729 #include <asm/cpu_device_id.h>
730 #include <asm/intel-family.h>
732 /* CPU matches for Dell generations with broken ACPI MIPI DISCO info */
733 static const struct x86_cpu_id dell_broken_mipi_disco_cpu_gens
[] = {
734 X86_MATCH_VFM(INTEL_TIGERLAKE
, NULL
),
735 X86_MATCH_VFM(INTEL_TIGERLAKE_L
, NULL
),
736 X86_MATCH_VFM(INTEL_ALDERLAKE
, NULL
),
737 X86_MATCH_VFM(INTEL_ALDERLAKE_L
, NULL
),
738 X86_MATCH_VFM(INTEL_RAPTORLAKE
, NULL
),
739 X86_MATCH_VFM(INTEL_RAPTORLAKE_P
, NULL
),
740 X86_MATCH_VFM(INTEL_RAPTORLAKE_S
, NULL
),
744 static const char *strnext(const char *s1
, const char *s2
)
751 return s1
+ strlen(s2
);
755 * acpi_graph_ignore_port - Tell whether a port node should be ignored
756 * @handle: The ACPI handle of the node (which may be a port node)
758 * Return: true if a port node should be ignored and the data to that should
759 * come from other sources instead (Windows ACPI definitions and
760 * ipu-bridge). This is currently used to ignore bad port nodes related to IPU6
761 * ("IPU?") and camera sensor devices ("LNK?") in certain Dell systems with
764 bool acpi_graph_ignore_port(acpi_handle handle
)
766 const char *path
= NULL
, *orig_path
;
767 static bool dmi_tested
, ignore_port
;
770 if (dmi_name_in_vendors("Dell Inc.") &&
771 x86_match_cpu(dell_broken_mipi_disco_cpu_gens
))
780 /* Check if the device is either "IPU" or "LNK" (sensor). */
781 orig_path
= acpi_handle_path(handle
);
784 path
= strnext(orig_path
, "IPU");
786 path
= strnext(orig_path
, "LNK");
790 if (!(isdigit(path
[0]) && path
[1] == '.'))
793 /* Check if the node has a "PRT" prefix. */
794 path
= strnext(path
, "PRT");
795 if (path
&& isdigit(path
[0]) && !path
[1]) {
796 acpi_handle_debug(handle
, "ignoring data node\n");