/* * struct csi2dc_format - CSI2DC format type struct * @mbus_code: Media bus code for the format * @dt: Data type constant for this format
*/ struct csi2dc_format {
u32 mbus_code;
u32 dt;
};
/* * struct csi2dc_device - CSI2DC device driver data/config struct * @base: Register map base address * @csi2dc_sd: v4l2 subdevice for the csi2dc device * This is the subdevice that the csi2dc device itself * registers in v4l2 subsystem * @dev: struct device for this csi2dc device * @pclk: Peripheral clock reference * Input clock that clocks the hardware block internal * logic * @scck: Sensor Controller clock reference * Input clock that is used to generate the pixel clock * @format: Current saved format used in g/s fmt * @cur_fmt: Current state format * @try_fmt: Try format that is being tried * @pads: Media entity pads for the csi2dc subdevice * @clk_gated: Whether the clock is gated or free running * @video_pipe: Whether video pipeline is configured * @parallel_mode: The underlying subdevice is connected on a parallel bus * @vc: Current set virtual channel * @notifier: Async notifier that is used to bound the underlying * subdevice to the csi2dc subdevice * @input_sd: Reference to the underlying subdevice bound to the * csi2dc subdevice * @remote_pad: Pad number of the underlying subdevice that is linked * to the csi2dc subdevice sink pad.
*/ struct csi2dc_device { void __iomem *base; struct v4l2_subdev csi2dc_sd; struct device *dev; struct clk *pclk; struct clk *scck;
/* * Setting the source pad is disabled. * The same format is being propagated from the sink to source.
*/ if (req_fmt->pad == CSI2DC_PAD_SOURCE) return -EINVAL;
for (i = 0; i < ARRAY_SIZE(csi2dc_formats); i++) {
fmt = &csi2dc_formats[i]; if (req_fmt->format.code == fmt->mbus_code)
try_fmt = fmt;
fmt++;
}
/* in case we could not find the desired format, default to something */ if (!try_fmt) {
try_fmt = &csi2dc_formats[0];
dev_dbg(csi2dc->dev, "CSI2DC unsupported format 0x%x, defaulting to 0x%x\n",
req_fmt->format.code, csi2dc_formats[0].mbus_code);
}
if (req_fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
v4l2_try_fmt = v4l2_subdev_state_get_format(sd_state,
req_fmt->pad);
*v4l2_try_fmt = req_fmt->format; /* Trying on the sink pad makes the source pad change too */
v4l2_try_fmt = v4l2_subdev_state_get_format(sd_state,
CSI2DC_PAD_SOURCE);
*v4l2_try_fmt = req_fmt->format;
/* if we are just trying, we are done */ return 0;
}
/* save the format for later requests */
csi2dc->format = req_fmt->format;
/* update config */
csi2dc->cur_fmt = try_fmt;
dev_dbg(csi2dc->dev, "new format set: 0x%x @%dx%d\n",
csi2dc->format.code, csi2dc->format.width,
csi2dc->format.height);
return 0;
}
staticint csi2dc_power(struct csi2dc_device *csi2dc, int on)
{ int ret = 0;
if (on) {
ret = clk_prepare_enable(csi2dc->pclk); if (ret) {
dev_err(csi2dc->dev, "failed to enable pclk:%d\n", ret); return ret;
}
ret = clk_prepare_enable(csi2dc->scck); if (ret) {
dev_err(csi2dc->dev, "failed to enable scck:%d\n", ret);
clk_disable_unprepare(csi2dc->pclk); return ret;
}
/* if powering up, deassert reset line */
csi2dc_writel(csi2dc, CSI2DC_GCTLR, CSI2DC_GCTLR_SWRST);
} else { /* if powering down, assert reset line */
csi2dc_writel(csi2dc, CSI2DC_GCTLR, 0);
pad = media_entity_get_fwnode_pad(&subdev->entity, asd->match.fwnode,
MEDIA_PAD_FL_SOURCE); if (pad < 0) {
dev_err(csi2dc->dev, "Failed to find pad for %s\n",
subdev->name); return pad;
}
csi2dc->remote_pad = pad;
ret = media_create_pad_link(&csi2dc->input_sd->entity,
csi2dc->remote_pad,
&csi2dc->csi2dc_sd.entity, 0,
MEDIA_LNK_FL_ENABLED); if (ret) {
dev_err(csi2dc->dev, "Failed to create pad link: %s to %s\n",
csi2dc->input_sd->entity.name,
csi2dc->csi2dc_sd.entity.name); return ret;
}
dev_dbg(csi2dc->dev, "link with %s pad: %d\n",
csi2dc->input_sd->name, csi2dc->remote_pad);
input_fwnode = fwnode_graph_get_next_endpoint(of_fwnode_handle(of_node),
NULL); if (!input_fwnode) {
dev_err(csi2dc->dev, "missing port node at %pOF, input node is mandatory.\n",
of_node); return -EINVAL;
}
ret = v4l2_fwnode_endpoint_parse(input_fwnode, &input_endpoint); if (ret) {
dev_err(csi2dc->dev, "endpoint not defined at %pOF\n", of_node); goto csi2dc_of_parse_err;
}
if (input_endpoint.bus_type == V4L2_MBUS_PARALLEL ||
input_endpoint.bus_type == V4L2_MBUS_BT656) {
csi2dc->parallel_mode = true;
dev_dbg(csi2dc->dev, "subdevice connected on parallel interface\n");
}
if (input_endpoint.bus_type == V4L2_MBUS_CSI2_DPHY) {
csi2dc->clk_gated = input_endpoint.bus.mipi_csi2.flags &
V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
dev_dbg(csi2dc->dev, "subdevice connected on serial interface\n");
dev_dbg(csi2dc->dev, "DT: %s clock\n",
csi2dc->clk_gated ? "gated" : "free running");
}
if (output_fwnode)
ret = v4l2_fwnode_endpoint_parse(output_fwnode,
&output_endpoint);
fwnode_handle_put(output_fwnode);
if (!output_fwnode || ret) {
dev_info(csi2dc->dev, "missing output node at %pOF, data pipe available only.\n",
of_node);
} else { if (output_endpoint.bus_type != V4L2_MBUS_PARALLEL &&
output_endpoint.bus_type != V4L2_MBUS_BT656) {
dev_err(csi2dc->dev, "output port must be parallel/bt656.\n");
ret = -EINVAL; goto csi2dc_of_parse_err;
}
staticint csi2dc_probe(struct platform_device *pdev)
{ struct device *dev = &pdev->dev; struct csi2dc_device *csi2dc; int ret = 0;
u32 ver;
csi2dc = devm_kzalloc(dev, sizeof(*csi2dc), GFP_KERNEL); if (!csi2dc) return -ENOMEM;
csi2dc->dev = dev;
csi2dc->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(csi2dc->base)) {
dev_err(dev, "base address not set\n"); return PTR_ERR(csi2dc->base);
}
csi2dc->pclk = devm_clk_get(dev, "pclk"); if (IS_ERR(csi2dc->pclk)) {
ret = PTR_ERR(csi2dc->pclk);
dev_err(dev, "failed to get pclk: %d\n", ret); return ret;
}
csi2dc->scck = devm_clk_get(dev, "scck"); if (IS_ERR(csi2dc->scck)) {
ret = PTR_ERR(csi2dc->scck);
dev_err(dev, "failed to get scck: %d\n", ret); return ret;
}
/* turn power on to validate capabilities */
ret = csi2dc_power(csi2dc, true); if (ret < 0) goto csi2dc_probe_cleanup_notifier;
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
ver = csi2dc_readl(csi2dc, CSI2DC_VERSION);
/* * we must register the subdev after PM runtime has been requested, * otherwise we might bound immediately and request pm_runtime_resume * before runtime_enable.
*/
ret = v4l2_async_register_subdev(&csi2dc->csi2dc_sd); if (ret) {
dev_err(csi2dc->dev, "failed to register the subdevice\n"); goto csi2dc_probe_cleanup_notifier;
}
dev_info(dev, "Microchip CSI2DC version %x\n", ver);
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.