for (i = 0; i < num_data_lanes; i++) { if (lanes_used & BIT(array[i])) { if (have_data_lanes || !use_default_lane_mapping)
pr_warn("duplicated lane %u in data-lanes, using defaults\n",
array[i]);
use_default_lane_mapping = true;
}
lanes_used |= BIT(array[i]);
if (have_data_lanes)
pr_debug("lane %u position %u\n", i, array[i]);
}
rval = fwnode_property_count_u32(fwnode, "lane-polarities"); if (rval > 0) { if (rval != 1 + num_data_lanes /* clock+data */) {
pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
1 + num_data_lanes, rval); return -EINVAL;
}
have_lane_polarities = true;
}
rval = fwnode_property_count_u32(fwnode, "line-orders"); if (rval > 0) { if (rval != num_data_lanes) {
pr_warn("invalid number of line-orders entries (need %u, got %u)\n",
num_data_lanes, rval); return -EINVAL;
}
have_line_orders = true;
}
if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
clock_lane = v;
pr_debug("clock lane position %u\n", v);
have_clk_lane = true;
}
if (have_clk_lane && lanes_used & BIT(clock_lane) &&
!use_default_lane_mapping) {
pr_warn("duplicated lane %u in clock-lanes, using defaults\n",
v);
use_default_lane_mapping = true;
}
if (fwnode_property_present(fwnode, "clock-noncontinuous")) {
flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
pr_debug("non-continuous clock\n");
}
if (bus_type == V4L2_MBUS_CSI2_DPHY ||
bus_type == V4L2_MBUS_CSI2_CPHY ||
lanes_used || have_clk_lane || flags) { /* Only D-PHY has a clock lane. */ unsignedint dfl_data_lane_index =
bus_type == V4L2_MBUS_CSI2_DPHY;
if (use_default_lane_mapping) {
bus->clock_lane = 0; for (i = 0; i < num_data_lanes; i++)
bus->data_lanes[i] = dfl_data_lane_index + i;
} else {
bus->clock_lane = clock_lane; for (i = 0; i < num_data_lanes; i++)
bus->data_lanes[i] = array[i];
}
if (have_lane_polarities) {
fwnode_property_read_u32_array(fwnode, "lane-polarities", array,
1 + num_data_lanes);
for (i = 0; i < 1 + num_data_lanes; i++) {
bus->lane_polarities[i] = array[i];
pr_debug("lane %u polarity %sinverted",
i, array[i] ? "" : "not ");
}
} else {
pr_debug("no lane polarities defined, assuming not inverted\n");
}
if (have_line_orders) {
fwnode_property_read_u32_array(fwnode, "line-orders", array,
num_data_lanes);
for (i = 0; i < num_data_lanes; i++) { staticconstchar * const orders[] = { "ABC", "ACB", "BAC", "BCA", "CAB", "CBA"
};
if (array[i] >= ARRAY_SIZE(orders)) {
pr_warn("lane %u invalid line-order assuming ABC (got %u)\n",
i, array[i]);
bus->line_orders[i] =
V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC; continue;
}
bus->line_orders[i] = array[i];
pr_debug("lane %u line order %s", i,
orders[array[i]]);
}
} else { for (i = 0; i < num_data_lanes; i++)
bus->line_orders[i] =
V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC;
pr_debug("no line orders defined, assuming ABC\n");
}
}
pr_debug("===== begin parsing endpoint %pfw\n", fwnode);
fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
pr_debug("fwnode video bus type %s (%u), mbus type %s (%u)\n",
v4l2_fwnode_bus_type_to_string(bus_type), bus_type,
v4l2_fwnode_mbus_type_to_string(vep->bus_type),
vep->bus_type);
mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type); if (mbus_type == V4L2_MBUS_INVALID) {
pr_debug("unsupported bus type %u\n", bus_type); return -EINVAL;
}
if (vep->bus_type != V4L2_MBUS_UNKNOWN) { if (mbus_type != V4L2_MBUS_UNKNOWN &&
vep->bus_type != mbus_type) {
pr_debug("expecting bus type %s\n",
v4l2_fwnode_mbus_type_to_string(vep->bus_type)); return -ENXIO;
}
} else {
vep->bus_type = mbus_type;
}
switch (vep->bus_type) { case V4L2_MBUS_UNKNOWN:
rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
V4L2_MBUS_UNKNOWN); if (rval) return rval;
if (vep->bus_type == V4L2_MBUS_UNKNOWN)
v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep,
V4L2_MBUS_UNKNOWN);
pr_debug("assuming media bus type %s (%u)\n",
v4l2_fwnode_mbus_type_to_string(vep->bus_type),
vep->bus_type);
break; case V4L2_MBUS_CCP2: case V4L2_MBUS_CSI1:
v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, vep->bus_type);
break; case V4L2_MBUS_CSI2_DPHY: case V4L2_MBUS_CSI2_CPHY:
rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
vep->bus_type); if (rval) return rval;
break; case V4L2_MBUS_PARALLEL: case V4L2_MBUS_BT656:
v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep,
vep->bus_type);
break; default:
pr_warn("unsupported bus type %u\n", mbus_type); return -EINVAL;
}
fwnode_graph_parse_endpoint(fwnode, &vep->base);
return 0;
}
int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, struct v4l2_fwnode_endpoint *vep)
{ int ret;
ret = __v4l2_fwnode_endpoint_parse(fwnode, vep);
pr_debug("===== end parsing endpoint %pfw\n", fwnode);
staticenum v4l2_connector_type
v4l2_fwnode_get_connector_type(struct fwnode_handle *fwnode)
{ constchar *type_name; int err;
if (!fwnode) return V4L2_CONN_UNKNOWN;
/* The connector-type is stored within the compatible string. */
err = fwnode_property_read_string(fwnode, "compatible", &type_name); if (err) return V4L2_CONN_UNKNOWN;
/* * v4l2_fwnode_reference_parse - parse references for async sub-devices * @dev: the device node the properties of which are parsed for references * @notifier: the async notifier where the async subdevs will be added * @prop: the name of the property * * Return: 0 on success * -ENOENT if no entries were found * -ENOMEM if memory allocation failed * -EINVAL if property parsing failed
*/ staticint v4l2_fwnode_reference_parse(struct device *dev, struct v4l2_async_notifier *notifier, constchar *prop)
{ struct fwnode_reference_args args; unsignedint index; int ret;
asd = v4l2_async_nf_add_fwnode(notifier, args.fwnode, struct v4l2_async_connection);
fwnode_handle_put(args.fwnode); if (IS_ERR(asd)) { /* not an error if asd already exists */ if (PTR_ERR(asd) == -EEXIST) continue;
return PTR_ERR(asd);
}
}
/* -ENOENT here means successful parsing */ if (ret != -ENOENT) return ret;
/* Return -ENOENT if no references were found */ return index ? 0 : -ENOENT;
}
/* * v4l2_fwnode_reference_get_int_prop - parse a reference with integer * arguments * @fwnode: fwnode to read @prop from * @notifier: notifier for @dev * @prop: the name of the property * @index: the index of the reference to get * @props: the array of integer property names * @nprops: the number of integer property names in @nprops * * First find an fwnode referred to by the reference at @index in @prop. * * Then under that fwnode, @nprops times, for each property in @props, * iteratively follow child nodes starting from fwnode such that they have the * property in @props array at the index of the child node distance from the * root node and the value of that property matching with the integer argument * of the reference, at the same index. * * The child fwnode reached at the end of the iteration is then returned to the * caller. * * The core reason for this is that you cannot refer to just any node in ACPI. * So to refer to an endpoint (easy in DT) you need to refer to a device, then * provide a list of (property name, property value) tuples where each tuple * uniquely identifies a child node. The first tuple identifies a child directly * underneath the device fwnode, the next tuple identifies a child node * underneath the fwnode identified by the previous tuple, etc. until you * reached the fwnode you need. * * THIS EXAMPLE EXISTS MERELY TO DOCUMENT THIS FUNCTION. DO NOT USE IT AS A * REFERENCE IN HOW ACPI TABLES SHOULD BE WRITTEN!! See documentation under * Documentation/firmware-guide/acpi/dsd/ instead and especially graph.txt, * data-node-references.txt and leds.txt . * * Scope (\_SB.PCI0.I2C2) * { * Device (CAM0) * { * Name (_DSD, Package () { * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), * Package () { * Package () { * "compatible", * Package () { "nokia,smia" } * }, * }, * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), * Package () { * Package () { "port0", "PRT0" }, * } * }) * Name (PRT0, Package() { * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), * Package () { * Package () { "port", 0 }, * }, * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), * Package () { * Package () { "endpoint0", "EP00" }, * } * }) * Name (EP00, Package() { * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), * Package () { * Package () { "endpoint", 0 }, * Package () { * "remote-endpoint", * Package() { * \_SB.PCI0.ISP, 4, 0 * } * }, * } * }) * } * } * * Scope (\_SB.PCI0) * { * Device (ISP) * { * Name (_DSD, Package () { * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), * Package () { * Package () { "port4", "PRT4" }, * } * }) * * Name (PRT4, Package() { * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), * Package () { * Package () { "port", 4 }, * }, * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), * Package () { * Package () { "endpoint0", "EP40" }, * } * }) * * Name (EP40, Package() { * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), * Package () { * Package () { "endpoint", 0 }, * Package () { * "remote-endpoint", * Package () { * \_SB.PCI0.I2C2.CAM0, * 0, 0 * } * }, * } * }) * } * } * * From the EP40 node under ISP device, you could parse the graph remote * endpoint using v4l2_fwnode_reference_get_int_prop with these arguments: * * @fwnode: fwnode referring to EP40 under ISP. * @prop: "remote-endpoint" * @index: 0 * @props: "port", "endpoint" * @nprops: 2 * * And you'd get back fwnode referring to EP00 under CAM0. * * The same works the other way around: if you use EP00 under CAM0 as the * fwnode, you'll get fwnode referring to EP40 under ISP. * * The same example in DT syntax would look like this: * * cam: cam0 { * compatible = "nokia,smia"; * * port { * port = <0>; * endpoint { * endpoint = <0>; * remote-endpoint = <&isp 4 0>; * }; * }; * }; * * isp: isp { * ports { * port@4 { * port = <4>; * endpoint { * endpoint = <0>; * remote-endpoint = <&cam 0 0>; * }; * }; * }; * }; * * Return: 0 on success * -ENOENT if no entries (or the property itself) were found * -EINVAL if property parsing otherwise failed * -ENOMEM if memory allocation failed
*/ staticstruct fwnode_handle *
v4l2_fwnode_reference_get_int_prop(struct fwnode_handle *fwnode, constchar *prop, unsignedint index, constchar * const *props, unsignedint nprops)
{ struct fwnode_reference_args fwnode_args;
u64 *args = fwnode_args.args; struct fwnode_handle *child; int ret;
/* * Obtain remote fwnode as well as the integer arguments. * * Note that right now both -ENODATA and -ENOENT may signal * out-of-bounds access. Return -ENOENT in that case.
*/
ret = fwnode_property_get_reference_args(fwnode, prop, NULL, nprops,
index, &fwnode_args); if (ret) return ERR_PTR(ret == -ENODATA ? -ENOENT : ret);
/* * Find a node in the tree under the referred fwnode corresponding to * the integer arguments.
*/
fwnode = fwnode_args.fwnode; while (nprops--) {
u32 val;
/* Loop over all child nodes under fwnode. */
fwnode_for_each_child_node(fwnode, child) { if (fwnode_property_read_u32(child, *props, &val)) continue;
/* Found property, see if its value matches. */ if (val == *args) break;
}
fwnode_handle_put(fwnode);
/* No property found; return an error here. */ if (!child) {
fwnode = ERR_PTR(-ENOENT); break;
}
/* * v4l2_fwnode_reference_parse_int_props - parse references for async * sub-devices * @dev: struct device pointer * @notifier: notifier for @dev * @prop: the name of the property * @props: the array of integer property names * @nprops: the number of integer properties * * Use v4l2_fwnode_reference_get_int_prop to find fwnodes through reference in * property @prop with integer arguments with child nodes matching in properties * @props. Then, set up V4L2 async sub-devices for those fwnodes in the notifier * accordingly. * * While it is technically possible to use this function on DT, it is only * meaningful on ACPI. On Device tree you can refer to any node in the tree but * on ACPI the references are limited to devices. * * Return: 0 on success * -ENOENT if no entries (or the property itself) were found * -EINVAL if property parsing otherwisefailed * -ENOMEM if memory allocation failed
*/ staticint
v4l2_fwnode_reference_parse_int_props(struct device *dev, struct v4l2_async_notifier *notifier, conststruct v4l2_fwnode_int_props *p)
{ struct fwnode_handle *fwnode; unsignedint index; int ret; constchar *prop = p->name; constchar * const *props = p->props; unsignedint nprops = p->nprops;
index = 0; do {
fwnode = v4l2_fwnode_reference_get_int_prop(dev_fwnode(dev),
prop, index,
props, nprops); if (IS_ERR(fwnode)) { /* * Note that right now both -ENODATA and -ENOENT may * signal out-of-bounds access. Return the error in * cases other than that.
*/ if (PTR_ERR(fwnode) != -ENOENT &&
PTR_ERR(fwnode) != -ENODATA) return PTR_ERR(fwnode); break;
}
fwnode_handle_put(fwnode);
index++;
} while (1);
asd = v4l2_async_nf_add_fwnode(notifier, fwnode, struct v4l2_async_connection);
fwnode_handle_put(fwnode); if (IS_ERR(asd)) {
ret = PTR_ERR(asd); /* not an error if asd already exists */ if (ret == -EEXIST) continue;
/** * v4l2_async_nf_parse_fwnode_sensor - parse common references on * sensors for async sub-devices * @dev: the device node the properties of which are parsed for references * @notifier: the async notifier where the async subdevs will be added * * Parse common sensor properties for remote devices related to the * sensor and set up async sub-devices for them. * * Any notifier populated using this function must be released with a call to * v4l2_async_nf_release() after it has been unregistered and the async * sub-devices are no longer in use, even in the case the function returned an * error. * * Return: 0 on success * -ENOMEM if memory allocation failed * -EINVAL if property parsing failed
*/ staticint
v4l2_async_nf_parse_fwnode_sensor(struct device *dev, struct v4l2_async_notifier *notifier)
{ staticconstchar * const led_props[] = { "led" }; staticconststruct v4l2_fwnode_int_props props[] = {
{ "flash-leds", led_props, ARRAY_SIZE(led_props) },
{ "mipi-img-flash-leds", },
{ "lens-focus", },
{ "mipi-img-lens-focus", },
}; unsignedint i;
for (i = 0; i < ARRAY_SIZE(props); i++) { int ret;
if (props[i].props && is_acpi_node(dev_fwnode(dev)))
ret = v4l2_fwnode_reference_parse_int_props(dev,
notifier,
&props[i]); else
ret = v4l2_fwnode_reference_parse(dev, notifier,
props[i].name); if (ret && ret != -ENOENT) {
dev_warn(dev, "parsing property \"%s\" failed (%d)\n",
props[i].name, ret); return ret;
}
}
return 0;
}
int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
{ struct v4l2_async_notifier *notifier; int ret;
if (WARN_ON(!sd->dev)) return -ENODEV;
notifier = kzalloc(sizeof(*notifier), GFP_KERNEL); if (!notifier) return -ENOMEM;
v4l2_async_subdev_nf_init(notifier, sd);
ret = v4l2_subdev_get_privacy_led(sd); if (ret < 0) goto out_cleanup;
ret = v4l2_async_nf_parse_fwnode_sensor(sd->dev, notifier); if (ret < 0) goto out_cleanup;
ret = v4l2_async_nf_register(notifier); if (ret < 0) goto out_cleanup;
ret = v4l2_async_register_subdev(sd); if (ret < 0) goto out_unregister;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.