Device connections

Introduction

Devices often have connections to other devices that are outside of the directchild/parent relationship. A serial or network communication controller, whichcould be a PCI device, may need to be able to get a reference to its PHYcomponent, which could be attached for example to the I2C bus. Some devicedrivers need to be able to control the clocks or the GPIOs for their devices,and so on.

Device connections are generic descriptions of any type of connection betweentwo separate devices.

Device connections alone do not create a dependency between the two devices.They are only descriptions which are not tied to either of the devices directly.A dependency between the two devices exists only if one of the two endpointdevices requests a reference to the other. The descriptions themselves can bedefined in firmware (not yet supported) or they can be built-in.

Usage

Device connections should exist before device->probe callback is called foreither endpoint device in the description. If the connections are defined infirmware, this is not a problem. It should be considered if the connectiondescriptions are “built-in”, and need to be added separately.

The connection description consists of the names of the two devices with theconnection, i.e. the endpoints, and unique identifier for the connection whichis needed if there are multiple connections between the two devices.

After a description exists, the devices in it can request reference to the otherendpoint device, or they can request the description itself.

API

void *device_connection_find_match(structdevice * dev, const char * con_id, void * data, devcon_match_fn_t match)

Find physical connection to a device

Parameters

structdevice*dev
Device with the connection
constchar*con_id
Identifier for the connection
void*data
Data for the match function
devcon_match_fn_tmatch
Function to check and convert the connection description

Description

Find a connection with unique identifiercon_id betweendev and anotherdevice.match will be used to convert the connection description to data thecaller is expecting to be returned.

structdevice *device_connection_find(structdevice * dev, const char * con_id)

Find two devices connected together

Parameters

structdevice*dev
Device with the connection
constchar*con_id
Identifier for the connection

Description

Find a connection with unique identifiercon_id betweendev andanother device. On success returns handle to the device that is connectedtodev, with the reference count for the found device incremented. ReturnsNULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when aconnection was found but the other device has not been enumerated yet.

voiddevice_connection_add(structdevice_connection * con)

Register a connection description

Parameters

structdevice_connection*con
The connection description to be registered
voiddevice_connection_remove(structdevice_connection * con)

Unregister connection description

Parameters

structdevice_connection*con
The connection description to be unregistered