Lines Matching refs:phy

33 static inline u32 camerarx_read(struct cal_camerarx *phy, u32 offset)
35 return ioread32(phy->base + offset);
38 static inline void camerarx_write(struct cal_camerarx *phy, u32 offset, u32 val)
40 iowrite32(val, phy->base + offset);
48 static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy)
53 ctrl = v4l2_ctrl_find(phy->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE);
55 phy_err(phy, "no pixel rate control in subdev: %s\n",
56 phy->sensor->name);
61 phy_dbg(3, phy, "sensor Pixel Rate: %llu\n", rate);
66 static void cal_camerarx_lane_config(struct cal_camerarx *phy)
68 u32 val = cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance));
72 &phy->endpoint.bus.mipi_csi2;
89 cal_write(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance), val);
90 phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x\n",
91 phy->instance, val);
94 static void cal_camerarx_enable(struct cal_camerarx *phy)
96 u32 num_lanes = phy->cal->data->camerarx[phy->instance].num_lanes;
98 regmap_field_write(phy->fields[F_CAMMODE], 0);
99 /* Always enable all lanes at the phy control level */
100 regmap_field_write(phy->fields[F_LANEENABLE], (1 << num_lanes) - 1);
102 if (phy->fields[F_CSI_MODE])
103 regmap_field_write(phy->fields[F_CSI_MODE], 1);
104 regmap_field_write(phy->fields[F_CTRLCLKEN], 1);
107 void cal_camerarx_disable(struct cal_camerarx *phy)
109 regmap_field_write(phy->fields[F_CTRLCLKEN], 0);
119 static void cal_camerarx_config(struct cal_camerarx *phy, s64 external_rate,
126 &phy->endpoint.bus.mipi_csi2;
140 phy_dbg(1, phy, "csi2_ddrclk_khz: %d\n", csi2_ddrclk_khz);
144 phy_dbg(1, phy, "ths_term: %d (0x%02x)\n", ths_term, ths_term);
148 phy_dbg(1, phy, "ths_settle: %d (0x%02x)\n", ths_settle, ths_settle);
150 reg0 = camerarx_read(phy, CAL_CSI2_PHY_REG0);
156 phy_dbg(1, phy, "CSI2_%d_REG0 = 0x%08x\n", phy->instance, reg0);
157 camerarx_write(phy, CAL_CSI2_PHY_REG0, reg0);
159 reg1 = camerarx_read(phy, CAL_CSI2_PHY_REG1);
166 phy_dbg(1, phy, "CSI2_%d_REG1 = 0x%08x\n", phy->instance, reg1);
167 camerarx_write(phy, CAL_CSI2_PHY_REG1, reg1);
170 static void cal_camerarx_power(struct cal_camerarx *phy, bool enable)
178 cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
184 current_state = cal_read_field(phy->cal,
185 CAL_CSI2_COMPLEXIO_CFG(phy->instance),
195 phy_err(phy, "Failed to power %s complexio\n",
199 static void cal_camerarx_wait_reset(struct cal_camerarx *phy)
205 if (cal_read_field(phy->cal,
206 CAL_CSI2_COMPLEXIO_CFG(phy->instance),
213 if (cal_read_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
216 phy_err(phy, "Timeout waiting for Complex IO reset done\n");
219 static void cal_camerarx_wait_stop_state(struct cal_camerarx *phy)
225 if (cal_read_field(phy->cal,
226 CAL_CSI2_TIMING(phy->instance),
232 if (cal_read_field(phy->cal, CAL_CSI2_TIMING(phy->instance),
234 phy_err(phy, "Timeout waiting for stop state\n");
237 int cal_camerarx_start(struct cal_camerarx *phy, const struct cal_fmt *fmt)
244 external_rate = cal_camerarx_get_external_rate(phy);
248 ret = v4l2_subdev_call(phy->sensor, core, s_power, 1);
250 phy_err(phy, "power on failed in subdev\n");
266 cal_camerarx_lane_config(phy);
272 cal_camerarx_enable(phy);
281 cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
284 phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x De-assert Complex IO Reset\n",
285 phy->instance,
286 cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)));
289 camerarx_read(phy, CAL_CSI2_PHY_REG0);
292 cal_camerarx_config(phy, external_rate, fmt);
304 sscounter = DIV_ROUND_UP(clk_get_rate(phy->cal->fclk), 10000 * 16 * 4);
306 val = cal_read(phy->cal, CAL_CSI2_TIMING(phy->instance));
311 cal_write(phy->cal, CAL_CSI2_TIMING(phy->instance), val);
312 phy_dbg(3, phy, "CAL_CSI2_TIMING(%d) = 0x%08x Stop States\n",
313 phy->instance,
314 cal_read(phy->cal, CAL_CSI2_TIMING(phy->instance)));
317 cal_write_field(phy->cal, CAL_CSI2_TIMING(phy->instance),
319 phy_dbg(3, phy, "CAL_CSI2_TIMING(%d) = 0x%08x Force RXMODE\n",
320 phy->instance,
321 cal_read(phy->cal, CAL_CSI2_TIMING(phy->instance)));
334 cal_camerarx_power(phy, true);
340 ret = v4l2_subdev_call(phy->sensor, video, s_stream, 1);
342 v4l2_subdev_call(phy->sensor, core, s_power, 0);
343 phy_err(phy, "stream on failed in subdev\n");
347 cal_camerarx_wait_reset(phy);
350 cal_camerarx_wait_stop_state(phy);
352 phy_dbg(1, phy, "CSI2_%u_REG1 = 0x%08x (bits 31-28 should be set)\n",
353 phy->instance, camerarx_read(phy, CAL_CSI2_PHY_REG1));
365 void cal_camerarx_stop(struct cal_camerarx *phy)
370 cal_camerarx_power(phy, false);
373 cal_write_field(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance),
379 if (cal_read_field(phy->cal,
380 CAL_CSI2_COMPLEXIO_CFG(phy->instance),
386 phy_dbg(3, phy, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Complex IO in Reset (%d) %s\n",
387 phy->instance,
388 cal_read(phy->cal, CAL_CSI2_COMPLEXIO_CFG(phy->instance)), i,
391 /* Disable the phy */
392 cal_camerarx_disable(phy);
394 if (v4l2_subdev_call(phy->sensor, video, s_stream, 0))
395 phy_err(phy, "stream off failed in subdev\n");
397 ret = v4l2_subdev_call(phy->sensor, core, s_power, 0);
399 phy_err(phy, "power off failed in subdev\n");
421 void cal_camerarx_i913_errata(struct cal_camerarx *phy)
423 u32 reg10 = camerarx_read(phy, CAL_CSI2_PHY_REG10);
427 phy_dbg(1, phy, "CSI2_%d_REG10 = 0x%08x\n", phy->instance, reg10);
428 camerarx_write(phy, CAL_CSI2_PHY_REG10, reg10);
434 void cal_camerarx_enable_irqs(struct cal_camerarx *phy)
445 cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0),
446 CAL_HL_IRQ_CIO_MASK(phy->instance));
447 cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance),
451 cal_write(phy->cal, CAL_HL_IRQENABLE_SET(0), CAL_HL_IRQ_OCPO_ERR_MASK);
455 cal_set_field(&val, 1, CAL_HL_IRQ_MASK(phy->instance));
456 cal_write(phy->cal, CAL_HL_IRQENABLE_SET(1), val);
459 cal_set_field(&val, 1, CAL_HL_IRQ_MASK(phy->instance));
460 cal_write(phy->cal, CAL_HL_IRQENABLE_SET(2), val);
462 cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(0), 0xFF000000);
465 void cal_camerarx_disable_irqs(struct cal_camerarx *phy)
470 cal_write(phy->cal, CAL_HL_IRQENABLE_CLR(0),
471 CAL_HL_IRQ_CIO_MASK(phy->instance));
472 cal_write(phy->cal, CAL_CSI2_COMPLEXIO_IRQENABLE(phy->instance), 0);
476 cal_set_field(&val, 1, CAL_HL_IRQ_MASK(phy->instance));
477 cal_write(phy->cal, CAL_HL_IRQENABLE_CLR(1), val);
480 cal_set_field(&val, 1, CAL_HL_IRQ_MASK(phy->instance));
481 cal_write(phy->cal, CAL_HL_IRQENABLE_CLR(2), val);
483 cal_write(phy->cal, CAL_CSI2_VC_IRQENABLE(0), 0);
486 void cal_camerarx_ppi_enable(struct cal_camerarx *phy)
488 cal_write(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance), BIT(3));
489 cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
493 void cal_camerarx_ppi_disable(struct cal_camerarx *phy)
495 cal_write_field(phy->cal, CAL_CSI2_PPI_CTRL(phy->instance),
500 struct cal_camerarx *phy)
508 phy_data = &cal->data->camerarx[phy->instance];
521 phy->fields[i] = devm_regmap_field_alloc(cal->dev,
524 if (IS_ERR(phy->fields[i])) {
526 return PTR_ERR(phy->fields[i]);
533 static int cal_camerarx_parse_dt(struct cal_camerarx *phy)
535 struct v4l2_fwnode_endpoint *endpoint = &phy->endpoint;
545 ep_node = of_graph_get_endpoint_by_regs(phy->cal->dev->of_node,
546 phy->instance, 0);
552 phy_dbg(3, phy, "Port has no endpoint\n");
559 phy_err(phy, "Failed to parse endpoint\n");
567 phy_err(phy, "Invalid position %u for data lane %u\n",
579 phy_dbg(3, phy,
585 phy->sensor_node = of_graph_get_remote_port_parent(ep_node);
586 if (!phy->sensor_node) {
587 phy_dbg(3, phy, "Can't get remote parent\n");
592 phy_dbg(1, phy, "Found connected device %pOFn\n", phy->sensor_node);
603 struct cal_camerarx *phy;
606 phy = kzalloc(sizeof(*phy), GFP_KERNEL);
607 if (!phy)
610 phy->cal = cal;
611 phy->instance = instance;
613 phy->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
617 phy->base = devm_ioremap_resource(cal->dev, phy->res);
618 if (IS_ERR(phy->base)) {
620 ret = PTR_ERR(phy->base);
625 phy->res->name, &phy->res->start, &phy->res->end);
627 ret = cal_camerarx_regmap_init(cal, phy);
631 ret = cal_camerarx_parse_dt(phy);
635 return phy;
638 kfree(phy);
642 void cal_camerarx_destroy(struct cal_camerarx *phy)
644 if (!phy)
647 of_node_put(phy->sensor_node);
648 kfree(phy);