Lines Matching +full:read +full:- +full:strobe +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the Texas Instruments DS90UB960-Q1 video deserializer
12 * - PM for serializer and remote peripherals. We need to manage:
13 * - VPOC
14 * - Power domain? Regulator? Somehow any remote device should be able to
16 * - Link between the deserializer and the serializer
17 * - Related to VPOC management. We probably always want to turn on the VPOC
19 * - Serializer's services: i2c, gpios, power
20 * - The serializer needs to resume before the remote peripherals can
22 * - How to handle gpios? Reserving a gpio essentially keeps the provider
24 * - Do we need a new bus for the FPD-Link? At the moment the serializers
25 * are children of the same i2c-adapter where the deserializer resides.
26 * - i2c-atr could be made embeddable instead of allocatable.
32 #include <linux/delay.h>
35 #include <linux/i2c-atr.h>
51 #include <media/mipi-csi2.h>
52 #include <media/v4l2-ctrls.h>
53 #include <media/v4l2-fwnode.h>
54 #include <media/v4l2-subdev.h>
82 * 0x00-0x32 Shared (UB960_SR)
83 * 0x33-0x3a CSI-2 TX (per-port paged on DS90UB960, shared on 954) (UB960_TR)
85 * 0x4d-0x7f FPD-Link RX, per-port paged (UB960_RR)
86 * 0xb0-0xbf Shared (UB960_SR)
87 * 0xd0-0xdf FPD-Link RX, per-port paged (UB960_RR)
88 * 0xf0-0xf5 Shared (UB960_SR)
89 * 0xf8-0xfb Shared (UB960_SR)
94 * UB960_RR_* = FPD-Link RX, per-port paged register
95 * UB960_TR_* = CSI-2 TX, per-port paged register
444 #define UB960_MIN_AEQ_STROBE_POS -7
449 #define UB960_MIN_MANUAL_STROBE_POS -(7 + UB960_MANUAL_STROBE_EXTRA_DELAY)
451 #define UB960_NUM_MANUAL_STROBE_POS (UB960_MAX_MANUAL_STROBE_POS - UB960_MIN_MANUAL_STROBE_POS + 1)
455 #define UB960_NUM_EQ_LEVELS (UB960_MAX_EQ_LEVEL - UB960_MIN_EQ_LEVEL + 1)
482 u8 nport; /* RX port number, and index in priv->rxport[] */
542 u8 nport; /* TX port number, and index in priv->txport[] */
594 } strobe; member
604 return pad < priv->hw_data->num_rxports; in ub960_pad_is_sink()
609 return pad >= priv->hw_data->num_rxports; in ub960_pad_is_source()
617 return pad - priv->hw_data->num_rxports; in ub960_pad_to_port()
677 for (; it.nport < priv->hw_data->num_rxports; it.nport++) { in ub960_iter_rxport()
678 it.rxport = priv->rxports[it.nport]; in ub960_iter_rxport()
684 it.rxport->cdr_mode != RXPORT_CDR_FPD4) in ub960_iter_rxport()
699 it.nport < (priv)->hw_data->num_rxports; \
706 it.nport < (priv)->hw_data->num_rxports; \
715 it.nport < (priv)->hw_data->num_rxports; \
720 /* -----------------------------------------------------------------------------
726 struct device *dev = &priv->client->dev; in ub960_read()
733 mutex_lock(&priv->reg_lock); in ub960_read()
735 ret = regmap_read(priv->regmap, reg, &v); in ub960_read()
737 dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n", in ub960_read()
745 mutex_unlock(&priv->reg_lock); in ub960_read()
755 struct device *dev = &priv->client->dev; in ub960_write()
761 mutex_lock(&priv->reg_lock); in ub960_write()
763 ret = regmap_write(priv->regmap, reg, val); in ub960_write()
768 mutex_unlock(&priv->reg_lock); in ub960_write()
779 struct device *dev = &priv->client->dev; in ub960_update_bits()
785 mutex_lock(&priv->reg_lock); in ub960_update_bits()
787 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_update_bits()
792 mutex_unlock(&priv->reg_lock); in ub960_update_bits()
802 struct device *dev = &priv->client->dev; in ub960_read16()
809 mutex_lock(&priv->reg_lock); in ub960_read16()
811 ret = regmap_bulk_read(priv->regmap, reg, &__v, sizeof(__v)); in ub960_read16()
813 dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n", in ub960_read16()
821 mutex_unlock(&priv->reg_lock); in ub960_read16()
831 struct device *dev = &priv->client->dev; in ub960_rxport_select()
834 lockdep_assert_held(&priv->reg_lock); in ub960_rxport_select()
836 if (priv->reg_current.rxport == nport) in ub960_rxport_select()
839 ret = regmap_write(priv->regmap, UB960_SR_FPD3_PORT_SEL, in ub960_rxport_select()
847 priv->reg_current.rxport = nport; in ub960_rxport_select()
855 struct device *dev = &priv->client->dev; in ub960_rxport_read()
862 mutex_lock(&priv->reg_lock); in ub960_rxport_read()
868 ret = regmap_read(priv->regmap, reg, &v); in ub960_rxport_read()
870 dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n", in ub960_rxport_read()
878 mutex_unlock(&priv->reg_lock); in ub960_rxport_read()
889 struct device *dev = &priv->client->dev; in ub960_rxport_write()
895 mutex_lock(&priv->reg_lock); in ub960_rxport_write()
901 ret = regmap_write(priv->regmap, reg, val); in ub960_rxport_write()
907 mutex_unlock(&priv->reg_lock); in ub960_rxport_write()
918 struct device *dev = &priv->client->dev; in ub960_rxport_update_bits()
924 mutex_lock(&priv->reg_lock); in ub960_rxport_update_bits()
930 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_rxport_update_bits()
936 mutex_unlock(&priv->reg_lock); in ub960_rxport_update_bits()
947 struct device *dev = &priv->client->dev; in ub960_rxport_read16()
954 mutex_lock(&priv->reg_lock); in ub960_rxport_read16()
960 ret = regmap_bulk_read(priv->regmap, reg, &__v, sizeof(__v)); in ub960_rxport_read16()
962 dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n", in ub960_rxport_read16()
970 mutex_unlock(&priv->reg_lock); in ub960_rxport_read16()
980 struct device *dev = &priv->client->dev; in ub960_txport_select()
983 lockdep_assert_held(&priv->reg_lock); in ub960_txport_select()
985 if (priv->reg_current.txport == nport) in ub960_txport_select()
988 ret = regmap_write(priv->regmap, UB960_SR_CSI_PORT_SEL, in ub960_txport_select()
996 priv->reg_current.txport = nport; in ub960_txport_select()
1004 struct device *dev = &priv->client->dev; in ub960_txport_read()
1011 mutex_lock(&priv->reg_lock); in ub960_txport_read()
1017 ret = regmap_read(priv->regmap, reg, &v); in ub960_txport_read()
1019 dev_err(dev, "%s: cannot read register 0x%02x (%d)!\n", in ub960_txport_read()
1027 mutex_unlock(&priv->reg_lock); in ub960_txport_read()
1038 struct device *dev = &priv->client->dev; in ub960_txport_write()
1044 mutex_lock(&priv->reg_lock); in ub960_txport_write()
1050 ret = regmap_write(priv->regmap, reg, val); in ub960_txport_write()
1056 mutex_unlock(&priv->reg_lock); in ub960_txport_write()
1067 struct device *dev = &priv->client->dev; in ub960_txport_update_bits()
1073 mutex_lock(&priv->reg_lock); in ub960_txport_update_bits()
1079 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_txport_update_bits()
1085 mutex_unlock(&priv->reg_lock); in ub960_txport_update_bits()
1095 struct device *dev = &priv->client->dev; in ub960_select_ind_reg_block()
1098 lockdep_assert_held(&priv->reg_lock); in ub960_select_ind_reg_block()
1100 if (priv->reg_current.indirect_target == block) in ub960_select_ind_reg_block()
1103 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_CTL, block << 2); in ub960_select_ind_reg_block()
1110 priv->reg_current.indirect_target = block; in ub960_select_ind_reg_block()
1118 struct device *dev = &priv->client->dev; in ub960_read_ind()
1125 mutex_lock(&priv->reg_lock); in ub960_read_ind()
1131 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_read_ind()
1139 ret = regmap_read(priv->regmap, UB960_SR_IND_ACC_DATA, &v); in ub960_read_ind()
1150 mutex_unlock(&priv->reg_lock); in ub960_read_ind()
1161 struct device *dev = &priv->client->dev; in ub960_write_ind()
1167 mutex_lock(&priv->reg_lock); in ub960_write_ind()
1173 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_write_ind()
1181 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_DATA, val); in ub960_write_ind()
1190 mutex_unlock(&priv->reg_lock); in ub960_write_ind()
1201 struct device *dev = &priv->client->dev; in ub960_ind_update_bits()
1207 mutex_lock(&priv->reg_lock); in ub960_ind_update_bits()
1213 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_ind_update_bits()
1221 ret = regmap_update_bits(priv->regmap, UB960_SR_IND_ACC_DATA, mask, in ub960_ind_update_bits()
1231 mutex_unlock(&priv->reg_lock); in ub960_ind_update_bits()
1241 struct device *dev = &priv->client->dev; in ub960_reset()
1253 mutex_lock(&priv->reg_lock); in ub960_reset()
1255 ret = regmap_read_poll_timeout(priv->regmap, UB960_SR_RESET, v, in ub960_reset()
1258 mutex_unlock(&priv->reg_lock); in ub960_reset()
1266 /* -----------------------------------------------------------------------------
1267 * I2C-ATR (address translator)
1274 struct ub960_rxport *rxport = priv->rxports[chan_id]; in ub960_atr_attach_addr()
1275 struct device *dev = &priv->client->dev; in ub960_atr_attach_addr()
1279 guard(mutex)(&rxport->aliased_addrs_lock); in ub960_atr_attach_addr()
1281 for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { in ub960_atr_attach_addr()
1282 if (!rxport->aliased_addrs[reg_idx]) in ub960_atr_attach_addr()
1286 if (reg_idx == ARRAY_SIZE(rxport->aliased_addrs)) { in ub960_atr_attach_addr()
1287 dev_err(dev, "rx%u: alias pool exhausted\n", rxport->nport); in ub960_atr_attach_addr()
1288 return -EADDRNOTAVAIL; in ub960_atr_attach_addr()
1291 rxport->aliased_addrs[reg_idx] = addr; in ub960_atr_attach_addr()
1302 rxport->nport, addr, alias, reg_idx); in ub960_atr_attach_addr()
1311 struct ub960_rxport *rxport = priv->rxports[chan_id]; in ub960_atr_detach_addr()
1312 struct device *dev = &priv->client->dev; in ub960_atr_detach_addr()
1316 guard(mutex)(&rxport->aliased_addrs_lock); in ub960_atr_detach_addr()
1318 for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { in ub960_atr_detach_addr()
1319 if (rxport->aliased_addrs[reg_idx] == addr) in ub960_atr_detach_addr()
1323 if (reg_idx == ARRAY_SIZE(rxport->aliased_addrs)) { in ub960_atr_detach_addr()
1325 rxport->nport, addr); in ub960_atr_detach_addr()
1329 rxport->aliased_addrs[reg_idx] = 0; in ub960_atr_detach_addr()
1335 rxport->nport, addr, ret); in ub960_atr_detach_addr()
1339 dev_dbg(dev, "rx%u: client 0x%02x released at slot %u\n", rxport->nport, in ub960_atr_detach_addr()
1350 struct device *dev = &priv->client->dev; in ub960_init_atr()
1351 struct i2c_adapter *parent_adap = priv->client->adapter; in ub960_init_atr()
1353 priv->atr = i2c_atr_new(parent_adap, dev, &ub960_atr_ops, in ub960_init_atr()
1354 priv->hw_data->num_rxports, 0); in ub960_init_atr()
1355 if (IS_ERR(priv->atr)) in ub960_init_atr()
1356 return PTR_ERR(priv->atr); in ub960_init_atr()
1358 i2c_atr_set_driver_data(priv->atr, priv); in ub960_init_atr()
1365 i2c_atr_delete(priv->atr); in ub960_uninit_atr()
1366 priv->atr = NULL; in ub960_uninit_atr()
1369 /* -----------------------------------------------------------------------------
1377 struct device *dev = &priv->client->dev; in ub960_parse_dt_txport()
1384 return -ENOMEM; in ub960_parse_dt_txport()
1386 txport->priv = priv; in ub960_parse_dt_txport()
1387 txport->nport = nport; in ub960_parse_dt_txport()
1396 txport->non_continous_clk = vep.bus.mipi_csi2.flags & in ub960_parse_dt_txport()
1399 txport->num_data_lanes = vep.bus.mipi_csi2.num_data_lanes; in ub960_parse_dt_txport()
1402 ret = -EINVAL; in ub960_parse_dt_txport()
1406 priv->tx_link_freq[0] = vep.link_frequencies[0]; in ub960_parse_dt_txport()
1407 priv->tx_data_rate = priv->tx_link_freq[0] * 2; in ub960_parse_dt_txport()
1409 if (priv->tx_data_rate != MHZ(1600) && in ub960_parse_dt_txport()
1410 priv->tx_data_rate != MHZ(1200) && in ub960_parse_dt_txport()
1411 priv->tx_data_rate != MHZ(800) && in ub960_parse_dt_txport()
1412 priv->tx_data_rate != MHZ(400)) { in ub960_parse_dt_txport()
1413 dev_err(dev, "tx%u: invalid 'link-frequencies' value\n", nport); in ub960_parse_dt_txport()
1414 ret = -EINVAL; in ub960_parse_dt_txport()
1420 priv->txports[nport] = txport; in ub960_parse_dt_txport()
1434 struct device *dev = &priv->client->dev; in ub960_csi_handle_events()
1452 /* -----------------------------------------------------------------------------
1462 if (!it.rxport->vpoc) in ub960_rxport_enable_vpocs()
1465 ret = regulator_enable(it.rxport->vpoc); in ub960_rxport_enable_vpocs()
1475 while (failed_nport--) { in ub960_rxport_enable_vpocs()
1476 struct ub960_rxport *rxport = priv->rxports[failed_nport]; in ub960_rxport_enable_vpocs()
1478 if (!rxport || !rxport->vpoc) in ub960_rxport_enable_vpocs()
1481 regulator_disable(rxport->vpoc); in ub960_rxport_enable_vpocs()
1490 if (!it.rxport->vpoc) in ub960_rxport_disable_vpocs()
1493 regulator_disable(it.rxport->vpoc); in ub960_rxport_disable_vpocs()
1564 *strobe_pos = data_delay - clk_delay; in ub960_rxport_get_strobe_pos()
1579 clk_delay = abs(strobe_pos) - UB960_MANUAL_STROBE_EXTRA_DELAY; in ub960_rxport_set_strobe_pos()
1581 data_delay = strobe_pos - UB960_MANUAL_STROBE_EXTRA_DELAY; in ub960_rxport_set_strobe_pos()
1599 /* Convert the signed strobe pos to positive zero based value */ in ub960_rxport_set_strobe_range()
1600 strobe_min -= UB960_MIN_AEQ_STROBE_POS; in ub960_rxport_set_strobe_range()
1601 strobe_max -= UB960_MIN_AEQ_STROBE_POS; in ub960_rxport_set_strobe_range()
1638 eq_stage_2_select_value = eq_level - eq_stage_max; in ub960_rxport_set_eq_level()
1678 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_config_eq()
1683 if (priv->strobe.manual) { in ub960_rxport_config_eq()
1700 /* Set AEQ strobe range */ in ub960_rxport_config_eq()
1701 ret = ub960_rxport_set_strobe_range(priv, priv->strobe.min, in ub960_rxport_config_eq()
1702 priv->strobe.max); in ub960_rxport_config_eq()
1709 if (priv->strobe.manual) in ub960_rxport_config_eq()
1711 rxport->eq.strobe_pos); in ub960_rxport_config_eq()
1718 if (rxport->eq.manual_eq) { in ub960_rxport_config_eq()
1720 rxport->eq.manual.eq_level); in ub960_rxport_config_eq()
1733 rxport->eq.aeq.eq_level_min, in ub960_rxport_config_eq()
1734 rxport->eq.aeq.eq_level_max); in ub960_rxport_config_eq()
1824 * Wait for the RX ports to lock, have no errors and have stable strobe position
1831 struct device *dev = &priv->client->dev; in ub960_rxport_wait_locks()
1845 if (port_mask >= BIT(priv->hw_data->num_rxports)) in ub960_rxport_wait_locks()
1846 return -EINVAL; in ub960_rxport_wait_locks()
1857 priv->hw_data->num_rxports) { in ub960_rxport_wait_locks()
1858 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_wait_locks()
1868 if (!ok && rxport->cdr_mode == RXPORT_CDR_FPD4) in ub960_rxport_wait_locks()
1908 for_each_set_bit(nport, &port_mask, priv->hw_data->num_rxports) { in ub960_rxport_wait_locks()
1909 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_wait_locks()
1927 if (priv->hw_data->is_ub9702) { in ub960_rxport_wait_locks()
1956 switch (rxport->rx_mode) { in ub960_calc_bc_clk_rate_ub960()
1978 return clk_get_rate(priv->refclk) * mult / div; in ub960_calc_bc_clk_rate_ub960()
1984 switch (rxport->rx_mode) { in ub960_calc_bc_clk_rate_ub9702()
2004 struct ub960_data *priv = rxport->priv; in ub960_rxport_serializer_write()
2005 struct device *dev = &priv->client->dev; in ub960_rxport_serializer_write()
2014 ret = i2c_smbus_xfer(priv->client->adapter, rxport->ser.alias, 0, in ub960_rxport_serializer_write()
2019 rxport->nport, reg, ret); in ub960_rxport_serializer_write()
2030 struct ub960_data *priv = rxport->priv; in ub960_rxport_serializer_read()
2031 struct device *dev = &priv->client->dev; in ub960_rxport_serializer_read()
2038 ret = i2c_smbus_xfer(priv->client->adapter, rxport->ser.alias, in ub960_rxport_serializer_read()
2039 priv->client->flags, I2C_SMBUS_READ, reg, in ub960_rxport_serializer_read()
2043 "rx%u: cannot read serializer register 0x%02x (%d)!\n", in ub960_rxport_serializer_read()
2044 rxport->nport, reg, ret); in ub960_rxport_serializer_read()
2056 struct ub960_data *priv = rxport->priv; in ub960_serializer_temp_ramp()
2057 short temp_dynamic_offset[] = {-1, -1, 0, 0, 1, 1, 1, 3}; in ub960_serializer_temp_ramp()
2059 u8 nport = rxport->nport; in ub960_serializer_temp_ramp()
2064 if (!fwnode_device_is_compatible(rxport->ser.fwnode, "ti,ds90ub953-q1")) in ub960_serializer_temp_ramp()
2067 /* Read current serializer die temperature */ in ub960_serializer_temp_ramp()
2122 /* Disable I2C passthrough and auto-ack on BC */ in ub960_serializer_temp_ramp()
2133 struct ub960_data *priv = rxport->priv; in ub960_rxport_bc_ser_config()
2134 struct device *dev = &priv->client->dev; in ub960_rxport_bc_ser_config()
2135 u8 nport = rxport->nport; in ub960_rxport_bc_ser_config()
2139 if (rxport->ser.addr < 0) { in ub960_rxport_bc_ser_config()
2147 * Note: the code here probably only works for CSI-2 serializers in in ub960_rxport_bc_ser_config()
2152 /* Enable I2C passthrough and auto-ack on BC */ in ub960_rxport_bc_ser_config()
2168 /* Disable I2C passthrough and auto-ack on BC */ in ub960_rxport_bc_ser_config()
2179 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_add_serializer()
2180 struct device *dev = &priv->client->dev; in ub960_rxport_add_serializer()
2181 struct ds90ub9xx_platform_data *ser_pdata = &rxport->ser.pdata; in ub960_rxport_add_serializer()
2183 .fwnode = rxport->ser.fwnode, in ub960_rxport_add_serializer()
2187 ser_pdata->port = nport; in ub960_rxport_add_serializer()
2188 ser_pdata->atr = priv->atr; in ub960_rxport_add_serializer()
2189 if (priv->hw_data->is_ub9702) in ub960_rxport_add_serializer()
2190 ser_pdata->bc_rate = ub960_calc_bc_clk_rate_ub9702(priv, rxport); in ub960_rxport_add_serializer()
2192 ser_pdata->bc_rate = ub960_calc_bc_clk_rate_ub960(priv, rxport); in ub960_rxport_add_serializer()
2197 * the FPD-Link. in ub960_rxport_add_serializer()
2199 ser_info.addr = rxport->ser.alias; in ub960_rxport_add_serializer()
2200 rxport->ser.client = in ub960_rxport_add_serializer()
2201 i2c_new_client_device(priv->client->adapter, &ser_info); in ub960_rxport_add_serializer()
2202 if (IS_ERR(rxport->ser.client)) { in ub960_rxport_add_serializer()
2205 return PTR_ERR(rxport->ser.client); in ub960_rxport_add_serializer()
2208 dev_dbg(dev, "rx%u: remote serializer at alias 0x%02x (%u-%04x)\n", in ub960_rxport_add_serializer()
2209 nport, rxport->ser.client->addr, in ub960_rxport_add_serializer()
2210 rxport->ser.client->adapter->nr, rxport->ser.client->addr); in ub960_rxport_add_serializer()
2217 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_remove_serializer()
2219 i2c_unregister_device(rxport->ser.client); in ub960_rxport_remove_serializer()
2220 rxport->ser.client = NULL; in ub960_rxport_remove_serializer()
2240 while (failed_nport--) { in ub960_rxport_add_serializers()
2241 struct ub960_rxport *rxport = priv->rxports[failed_nport]; in ub960_rxport_add_serializers()
2261 unsigned int nport = txport->nport; in ub960_init_tx_port()
2265 * From the datasheet: "initial CSI Skew-Calibration in ub960_init_tx_port()
2268 if (priv->tx_data_rate == MHZ(1600)) in ub960_init_tx_port()
2271 csi_ctl |= (4 - txport->num_data_lanes) << 4; in ub960_init_tx_port()
2273 if (!txport->non_continous_clk) in ub960_init_tx_port()
2283 switch (priv->tx_data_rate) { in ub960_init_tx_ports_ub960()
2309 switch (priv->tx_data_rate) { in ub960_init_tx_ports_ub9702()
2355 if (priv->hw_data->is_ub9702) in ub960_init_tx_ports()
2363 for (unsigned int nport = 0; nport < priv->hw_data->num_txports; in ub960_init_tx_ports()
2365 struct ub960_txport *txport = priv->txports[nport]; in ub960_init_tx_ports()
2381 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub960()
2388 * 0 - 2.5 Mbps (DS90UB913A-Q1 / DS90UB933-Q1) in ub960_init_rx_port_ub960()
2389 * 2 - 10 Mbps in ub960_init_rx_port_ub960()
2390 * 6 - 50 Mbps (DS90UB953-Q1) in ub960_init_rx_port_ub960()
2396 switch (rxport->rx_mode) { in ub960_init_rx_port_ub960()
2412 return -EINVAL; in ub960_init_rx_port_ub960()
2419 switch (rxport->rx_mode) { in ub960_init_rx_port_ub960()
2421 /* FPD3_MODE = RAW10 Mode (DS90UB913A-Q1 / DS90UB933-Q1 compatible) */ in ub960_init_rx_port_ub960()
2427 * RAW10_8BIT_CTL = 0b10 : 8-bit processing using upper 8 bits in ub960_init_rx_port_ub960()
2439 return -EINVAL; in ub960_init_rx_port_ub960()
2443 /* CSI-2 Mode (DS90UB953-Q1 compatible) */ in ub960_init_rx_port_ub960()
2452 rxport->lv_fv_pol, &ret); in ub960_init_rx_port_ub960()
2465 rxport->ser.alias << 1, &ret); in ub960_init_rx_port_ub960()
2479 struct device *dev = &priv->client->dev; in ub960_init_rx_ports_ub960()
2504 ret = -EIO; in ub960_init_rx_ports_ub960()
2587 if (priv->rxports[nport]->cdr_mode == RXPORT_CDR_FPD4) { in ub960_set_bc_drv_config_ub9702()
2739 * RAW10_8BIT_CTL = 0b11 : 8-bit processing using lower 8 bits in ub960_set_raw10_dvp_mode_ub9702()
2740 * 0b10 : 8-bit processing using upper 8 bits in ub960_set_raw10_dvp_mode_ub9702()
2747 priv->rxports[nport]->lv_fv_pol, &ret); in ub960_set_raw10_dvp_mode_ub9702()
2766 struct device *dev = &priv->client->dev; in ub960_configure_rx_port_ub9702()
2767 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_configure_rx_port_ub9702()
2779 switch (rxport->cdr_mode) { in ub960_configure_rx_port_ub9702()
2781 switch (rxport->rx_mode) { in ub960_configure_rx_port_ub9702()
2787 dev_dbg(dev, "rx%u: FPD-Link IV SYNC mode\n", nport); in ub960_configure_rx_port_ub9702()
2794 dev_dbg(dev, "rx%u: FPD-Link IV ASYNC mode\n", nport); in ub960_configure_rx_port_ub9702()
2798 rxport->rx_mode); in ub960_configure_rx_port_ub9702()
2799 return -EINVAL; in ub960_configure_rx_port_ub9702()
2804 switch (rxport->rx_mode) { in ub960_configure_rx_port_ub9702()
2810 dev_dbg(dev, "rx%u: FPD-Link III SYNC mode\n", nport); in ub960_configure_rx_port_ub9702()
2817 dev_dbg(dev, "rx%u: FPD-Link III RAW10 DVP mode\n", in ub960_configure_rx_port_ub9702()
2821 dev_err(&priv->client->dev, in ub960_configure_rx_port_ub9702()
2823 rxport->rx_mode); in ub960_configure_rx_port_ub9702()
2824 return -EINVAL; in ub960_configure_rx_port_ub9702()
2829 dev_err(&priv->client->dev, "rx%u: unsupported CDR mode %u\n", in ub960_configure_rx_port_ub9702()
2830 nport, rxport->cdr_mode); in ub960_configure_rx_port_ub9702()
2831 return -EINVAL; in ub960_configure_rx_port_ub9702()
2840 struct device *dev = &priv->client->dev; in ub960_lock_recovery_ub9702()
2863 /* Restart AEQ by changing max to 0 --> 0x23 */ in ub960_lock_recovery_ub9702()
2907 /* Restart AEQ by changing max to 0 --> 0x23 */ in ub960_lock_recovery_ub9702()
2946 return -EIO; in ub960_lock_recovery_ub9702()
2952 struct device *dev = &priv->client->dev; in ub960_enable_aeq_lms_ub9702()
3009 dev_dbg(dev, "rx%u: enable FPD-Link IV AEQ LMS\n", nport); in ub960_enable_aeq_lms_ub9702()
3017 struct device *dev = &priv->client->dev; in ub960_enable_dfe_lms_ub9702()
3038 dev_dbg(dev, "rx%u: enabled FPD-Link IV DFE LMS", nport); in ub960_enable_dfe_lms_ub9702()
3045 struct device *dev = &priv->client->dev; in ub960_init_rx_ports_ub9702()
3067 if (it.rxport->ser.addr >= 0) { in ub960_init_rx_ports_ub9702()
3073 it.rxport->ser.addr << 1 | in ub960_init_rx_ports_ub9702()
3078 /* Set serializer I2C alias with auto-ack */ in ub960_init_rx_ports_ub9702()
3080 it.rxport->ser.alias << 1 | in ub960_init_rx_ports_ub9702()
3088 if (fwnode_device_is_compatible(it.rxport->ser.fwnode, in ub960_init_rx_ports_ub9702()
3089 "ti,ds90ub971-q1")) { in ub960_init_rx_ports_ub9702()
3116 if (it.rxport->cdr_mode == RXPORT_CDR_FPD4) in ub960_init_rx_ports_ub9702()
3219 ret = -EIO; in ub960_init_rx_ports_ub9702()
3231 /* Clear serializer I2C alias auto-ack */ in ub960_init_rx_ports_ub9702()
3277 struct device *dev = &priv->client->dev; in ub960_rxport_handle_events()
3284 /* Read interrupts (also clears most of them) */ in ub960_rxport_handle_events()
3392 /* -----------------------------------------------------------------------------
3420 for_each_active_route(&state->routing, route) { in ub960_get_vc_maps()
3423 rx = ub960_pad_to_port(priv, route->sink_pad); in ub960_get_vc_maps()
3427 tx = ub960_pad_to_port(priv, route->source_pad); in ub960_get_vc_maps()
3436 struct device *dev = &priv->client->dev; in ub960_enable_tx_port()
3447 struct device *dev = &priv->client->dev; in ub960_disable_tx_port()
3457 struct device *dev = &priv->client->dev; in ub960_enable_rx_port()
3468 struct device *dev = &priv->client->dev; in ub960_disable_rx_port()
3489 ret = v4l2_subdev_call(it.rxport->source.sd, pad, in ub960_validate_stream_vcs()
3490 get_frame_desc, it.rxport->source.pad, in ub960_validate_stream_vcs()
3507 dev_err(&priv->client->dev, in ub960_validate_stream_vcs()
3508 "rx%u: source with multiple virtual-channels is not supported\n", in ub960_validate_stream_vcs()
3510 return -ENODEV; in ub960_validate_stream_vcs()
3538 for_each_active_route(&state->routing, route) { in ub960_configure_ports_for_streaming()
3545 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_configure_ports_for_streaming()
3547 rxport = priv->rxports[nport]; in ub960_configure_ports_for_streaming()
3549 return -EINVAL; in ub960_configure_ports_for_streaming()
3551 txport = priv->txports[ub960_pad_to_port(priv, route->source_pad)]; in ub960_configure_ports_for_streaming()
3553 return -EINVAL; in ub960_configure_ports_for_streaming()
3555 rx_data[nport].tx_port = ub960_pad_to_port(priv, route->source_pad); in ub960_configure_ports_for_streaming()
3560 if (rxport->rx_mode == RXPORT_MODE_CSI2_SYNC || in ub960_configure_ports_for_streaming()
3561 rxport->rx_mode == RXPORT_MODE_CSI2_NONSYNC) in ub960_configure_ports_for_streaming()
3565 return -EPIPE; in ub960_configure_ports_for_streaming()
3567 fmt = v4l2_subdev_state_get_format(state, route->sink_pad, in ub960_configure_ports_for_streaming()
3568 route->sink_stream); in ub960_configure_ports_for_streaming()
3570 return -EPIPE; in ub960_configure_ports_for_streaming()
3572 ub960_fmt = ub960_find_format(fmt->code); in ub960_configure_ports_for_streaming()
3574 return -EPIPE; in ub960_configure_ports_for_streaming()
3576 if (ub960_fmt->meta) { in ub960_configure_ports_for_streaming()
3577 if (fmt->height > 3) { in ub960_configure_ports_for_streaming()
3578 dev_err(&priv->client->dev, in ub960_configure_ports_for_streaming()
3580 nport, fmt->height); in ub960_configure_ports_for_streaming()
3581 return -EPIPE; in ub960_configure_ports_for_streaming()
3584 rx_data[nport].meta_dt = ub960_fmt->datatype; in ub960_configure_ports_for_streaming()
3585 rx_data[nport].meta_lines = fmt->height; in ub960_configure_ports_for_streaming()
3587 rx_data[nport].pixel_dt = ub960_fmt->datatype; in ub960_configure_ports_for_streaming()
3607 switch (it.rxport->rx_mode) { in ub960_configure_ports_for_streaming()
3627 if (!priv->hw_data->is_ub9702) { in ub960_configure_ports_for_streaming()
3665 if (priv->stream_enable_mask[i]) in ub960_update_streaming_status()
3669 priv->streaming = i < UB960_MAX_NPORTS; in ub960_update_streaming_status()
3677 struct device *dev = &priv->client->dev; in ub960_enable_streams()
3683 if (!priv->streaming) { in ub960_enable_streams()
3691 if (!priv->stream_enable_mask[source_pad]) { in ub960_enable_streams()
3698 priv->stream_enable_mask[source_pad] |= source_streams_mask; in ub960_enable_streams()
3701 for_each_active_route(&state->routing, route) { in ub960_enable_streams()
3704 if (route->source_pad != source_pad) in ub960_enable_streams()
3707 if (!(source_streams_mask & BIT_ULL(route->source_stream))) in ub960_enable_streams()
3710 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_enable_streams()
3712 sink_streams[nport] |= BIT_ULL(route->sink_stream); in ub960_enable_streams()
3722 if (!priv->stream_enable_mask[nport]) { in ub960_enable_streams()
3730 priv->stream_enable_mask[nport] |= sink_streams[nport]; in ub960_enable_streams()
3736 priv->rxports[nport]->source.sd, in ub960_enable_streams()
3737 priv->rxports[nport]->source.pad, in ub960_enable_streams()
3740 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_enable_streams()
3742 if (!priv->stream_enable_mask[nport]) in ub960_enable_streams()
3750 priv->streaming = true; in ub960_enable_streams()
3763 priv->rxports[nport]->source.sd, in ub960_enable_streams()
3764 priv->rxports[nport]->source.pad, in ub960_enable_streams()
3769 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_enable_streams()
3772 if (!priv->stream_enable_mask[nport]) in ub960_enable_streams()
3776 priv->stream_enable_mask[source_pad] &= ~source_streams_mask; in ub960_enable_streams()
3778 if (!priv->stream_enable_mask[source_pad]) in ub960_enable_streams()
3792 struct device *dev = &priv->client->dev; in ub960_disable_streams()
3798 for_each_active_route(&state->routing, route) { in ub960_disable_streams()
3801 if (route->source_pad != source_pad) in ub960_disable_streams()
3804 if (!(source_streams_mask & BIT_ULL(route->source_stream))) in ub960_disable_streams()
3807 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_disable_streams()
3809 sink_streams[nport] |= BIT_ULL(route->sink_stream); in ub960_disable_streams()
3822 priv->rxports[nport]->source.sd, in ub960_disable_streams()
3823 priv->rxports[nport]->source.pad, in ub960_disable_streams()
3828 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_disable_streams()
3831 if (!priv->stream_enable_mask[nport]) in ub960_disable_streams()
3837 priv->stream_enable_mask[source_pad] &= ~source_streams_mask; in ub960_disable_streams()
3839 if (!priv->stream_enable_mask[source_pad]) in ub960_disable_streams()
3869 if (routing->num_routes > V4L2_FRAME_DESC_ENTRY_MAX) in _ub960_set_routing()
3870 return -E2BIG; in _ub960_set_routing()
3892 if (which == V4L2_SUBDEV_FORMAT_ACTIVE && priv->streaming) in ub960_set_routing()
3893 return -EBUSY; in ub960_set_routing()
3905 struct device *dev = &priv->client->dev; in ub960_get_frame_desc()
3909 return -EINVAL; in ub960_get_frame_desc()
3911 fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; in ub960_get_frame_desc()
3913 state = v4l2_subdev_lock_and_get_active_state(&priv->sd); in ub960_get_frame_desc()
3917 for_each_active_route(&state->routing, route) { in ub960_get_frame_desc()
3923 if (route->source_pad != pad) in ub960_get_frame_desc()
3926 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_get_frame_desc()
3928 ret = v4l2_subdev_call(priv->rxports[nport]->source.sd, pad, in ub960_get_frame_desc()
3930 priv->rxports[nport]->source.pad, in ub960_get_frame_desc()
3935 route->sink_pad); in ub960_get_frame_desc()
3940 if (source_fd.entry[i].stream == route->sink_stream) { in ub960_get_frame_desc()
3949 ret = -EPIPE; in ub960_get_frame_desc()
3953 fd->entry[fd->num_entries].stream = route->source_stream; in ub960_get_frame_desc()
3954 fd->entry[fd->num_entries].flags = source_entry->flags; in ub960_get_frame_desc()
3955 fd->entry[fd->num_entries].length = source_entry->length; in ub960_get_frame_desc()
3956 fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode; in ub960_get_frame_desc()
3958 fd->entry[fd->num_entries].bus.csi2.vc = vc_map[nport]; in ub960_get_frame_desc()
3961 fd->entry[fd->num_entries].bus.csi2.dt = in ub960_get_frame_desc()
3962 source_entry->bus.csi2.dt; in ub960_get_frame_desc()
3968 route->source_stream); in ub960_get_frame_desc()
3971 ret = -EINVAL; in ub960_get_frame_desc()
3975 ub960_fmt = ub960_find_format(fmt->code); in ub960_get_frame_desc()
3978 ret = -EINVAL; in ub960_get_frame_desc()
3982 fd->entry[fd->num_entries].bus.csi2.dt = in ub960_get_frame_desc()
3983 ub960_fmt->datatype; in ub960_get_frame_desc()
3986 fd->num_entries++; in ub960_get_frame_desc()
4002 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE && priv->streaming) in ub960_set_fmt()
4003 return -EBUSY; in ub960_set_fmt()
4006 if (ub960_pad_is_source(priv, format->pad)) in ub960_set_fmt()
4013 if (!ub960_find_format(format->format.code)) in ub960_set_fmt()
4014 format->format.code = ub960_formats[0].code; in ub960_set_fmt()
4016 fmt = v4l2_subdev_state_get_format(state, format->pad, format->stream); in ub960_set_fmt()
4018 return -EINVAL; in ub960_set_fmt()
4020 *fmt = format->format; in ub960_set_fmt()
4022 fmt = v4l2_subdev_state_get_opposite_stream_format(state, format->pad, in ub960_set_fmt()
4023 format->stream); in ub960_set_fmt()
4025 return -EINVAL; in ub960_set_fmt()
4027 *fmt = format->format; in ub960_set_fmt()
4041 .source_pad = priv->hw_data->num_rxports, in ub960_init_state()
4069 struct device *dev = &priv->client->dev; in ub960_log_status_ub960_sp_eq()
4075 /* Strobe */ in ub960_log_status_ub960_sp_eq()
4081 dev_info(dev, "\t%s strobe\n", in ub960_log_status_ub960_sp_eq()
4091 ((v >> UB960_XR_SFILTER_CFG_SFILTER_MIN_SHIFT) & 0xf) - 7, in ub960_log_status_ub960_sp_eq()
4092 ((v >> UB960_XR_SFILTER_CFG_SFILTER_MAX_SHIFT) & 0xf) - 7); in ub960_log_status_ub960_sp_eq()
4134 struct device *dev = &priv->client->dev; in ub960_log_status()
4151 for (unsigned int nport = 0; nport < priv->hw_data->num_txports; in ub960_log_status()
4153 struct ub960_txport *txport = priv->txports[nport]; in ub960_log_status()
4261 if (!priv->hw_data->is_ub9702) { in ub960_log_status()
4308 /* -----------------------------------------------------------------------------
4323 dev_dbg(&priv->client->dev, "INTERRUPT_STS %x\n", int_sts); in ub960_handle_events()
4329 dev_dbg(&priv->client->dev, "FWD_STS %#02x\n", fwd_sts); in ub960_handle_events()
4331 for (unsigned int i = 0; i < priv->hw_data->num_txports; i++) { in ub960_handle_events()
4358 schedule_delayed_work(&priv->poll_work, in ub960_handler_work()
4366 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_txport_free_ports()
4367 struct ub960_txport *txport = priv->txports[nport]; in ub960_txport_free_ports()
4373 priv->txports[nport] = NULL; in ub960_txport_free_ports()
4380 fwnode_handle_put(it.rxport->source.ep_fwnode); in ub960_rxport_free_ports()
4381 fwnode_handle_put(it.rxport->ser.fwnode); in ub960_rxport_free_ports()
4383 mutex_destroy(&it.rxport->aliased_addrs_lock); in ub960_rxport_free_ports()
4386 priv->rxports[it.nport] = NULL; in ub960_rxport_free_ports()
4395 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport_link_properties()
4396 unsigned int nport = rxport->nport; in ub960_parse_dt_rxport_link_properties()
4407 ret = fwnode_property_read_u32(link_fwnode, "ti,cdr-mode", &cdr_mode); in ub960_parse_dt_rxport_link_properties()
4408 if (ret < 0 && ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
4409 dev_err(dev, "rx%u: failed to read '%s': %d\n", nport, in ub960_parse_dt_rxport_link_properties()
4410 "ti,cdr-mode", ret); in ub960_parse_dt_rxport_link_properties()
4415 dev_err(dev, "rx%u: bad 'ti,cdr-mode' %u\n", nport, cdr_mode); in ub960_parse_dt_rxport_link_properties()
4416 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4419 if (!priv->hw_data->is_fpdlink4 && cdr_mode == RXPORT_CDR_FPD4) { in ub960_parse_dt_rxport_link_properties()
4420 dev_err(dev, "rx%u: FPD-Link 4 CDR not supported\n", nport); in ub960_parse_dt_rxport_link_properties()
4421 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4424 rxport->cdr_mode = cdr_mode; in ub960_parse_dt_rxport_link_properties()
4426 ret = fwnode_property_read_u32(link_fwnode, "ti,rx-mode", &rx_mode); in ub960_parse_dt_rxport_link_properties()
4428 dev_err(dev, "rx%u: failed to read '%s': %d\n", nport, in ub960_parse_dt_rxport_link_properties()
4429 "ti,rx-mode", ret); in ub960_parse_dt_rxport_link_properties()
4434 dev_err(dev, "rx%u: bad 'ti,rx-mode' %u\n", nport, rx_mode); in ub960_parse_dt_rxport_link_properties()
4435 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4441 dev_err(dev, "rx%u: unsupported 'ti,rx-mode' %u\n", nport, in ub960_parse_dt_rxport_link_properties()
4443 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4448 rxport->rx_mode = rx_mode; in ub960_parse_dt_rxport_link_properties()
4450 /* EQ & Strobe related */ in ub960_parse_dt_rxport_link_properties()
4453 rxport->eq.manual_eq = false; in ub960_parse_dt_rxport_link_properties()
4454 rxport->eq.aeq.eq_level_min = UB960_MIN_EQ_LEVEL; in ub960_parse_dt_rxport_link_properties()
4455 rxport->eq.aeq.eq_level_max = UB960_MAX_EQ_LEVEL; in ub960_parse_dt_rxport_link_properties()
4457 ret = fwnode_property_read_u32(link_fwnode, "ti,strobe-pos", in ub960_parse_dt_rxport_link_properties()
4460 if (ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
4461 dev_err(dev, "rx%u: failed to read '%s': %d\n", nport, in ub960_parse_dt_rxport_link_properties()
4462 "ti,strobe-pos", ret); in ub960_parse_dt_rxport_link_properties()
4468 dev_err(dev, "rx%u: illegal 'strobe-pos' value: %d\n", in ub960_parse_dt_rxport_link_properties()
4470 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4473 /* NOTE: ignored unless global manual strobe pos is also set */ in ub960_parse_dt_rxport_link_properties()
4474 rxport->eq.strobe_pos = strobe_pos; in ub960_parse_dt_rxport_link_properties()
4475 if (!priv->strobe.manual) in ub960_parse_dt_rxport_link_properties()
4477 "rx%u: 'ti,strobe-pos' ignored as 'ti,manual-strobe' not set\n", in ub960_parse_dt_rxport_link_properties()
4481 ret = fwnode_property_read_u32(link_fwnode, "ti,eq-level", &eq_level); in ub960_parse_dt_rxport_link_properties()
4483 if (ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
4484 dev_err(dev, "rx%u: failed to read '%s': %d\n", nport, in ub960_parse_dt_rxport_link_properties()
4485 "ti,eq-level", ret); in ub960_parse_dt_rxport_link_properties()
4490 dev_err(dev, "rx%u: illegal 'ti,eq-level' value: %d\n", in ub960_parse_dt_rxport_link_properties()
4492 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4495 rxport->eq.manual_eq = true; in ub960_parse_dt_rxport_link_properties()
4496 rxport->eq.manual.eq_level = eq_level; in ub960_parse_dt_rxport_link_properties()
4499 ret = fwnode_property_read_u32(link_fwnode, "i2c-alias", in ub960_parse_dt_rxport_link_properties()
4502 dev_err(dev, "rx%u: failed to read '%s': %d\n", nport, in ub960_parse_dt_rxport_link_properties()
4503 "i2c-alias", ret); in ub960_parse_dt_rxport_link_properties()
4506 rxport->ser.alias = ser_i2c_alias; in ub960_parse_dt_rxport_link_properties()
4508 rxport->ser.fwnode = fwnode_get_named_child_node(link_fwnode, "serializer"); in ub960_parse_dt_rxport_link_properties()
4509 if (!rxport->ser.fwnode) { in ub960_parse_dt_rxport_link_properties()
4511 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
4514 ret = fwnode_property_read_u32(rxport->ser.fwnode, "reg", in ub960_parse_dt_rxport_link_properties()
4517 rxport->ser.addr = -EINVAL; in ub960_parse_dt_rxport_link_properties()
4519 rxport->ser.addr = ser_i2c_addr; in ub960_parse_dt_rxport_link_properties()
4528 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport_ep_properties()
4530 unsigned int nport = rxport->nport; in ub960_parse_dt_rxport_ep_properties()
4535 rxport->source.ep_fwnode = fwnode_graph_get_remote_endpoint(ep_fwnode); in ub960_parse_dt_rxport_ep_properties()
4536 if (!rxport->source.ep_fwnode) { in ub960_parse_dt_rxport_ep_properties()
4538 return -ENODEV; in ub960_parse_dt_rxport_ep_properties()
4543 switch (rxport->rx_mode) { in ub960_parse_dt_rxport_ep_properties()
4563 rxport->lv_fv_pol = (hsync_hi ? UB960_RR_PORT_CONFIG2_LV_POL_LOW : 0) | in ub960_parse_dt_rxport_ep_properties()
4569 fwnode_handle_put(rxport->source.ep_fwnode); in ub960_parse_dt_rxport_ep_properties()
4580 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport()
4586 return -ENOMEM; in ub960_parse_dt_rxport()
4588 priv->rxports[nport] = rxport; in ub960_parse_dt_rxport()
4590 rxport->nport = nport; in ub960_parse_dt_rxport()
4591 rxport->priv = priv; in ub960_parse_dt_rxport()
4597 rxport->vpoc = devm_regulator_get_optional(dev, vpoc_names[nport]); in ub960_parse_dt_rxport()
4598 if (IS_ERR(rxport->vpoc)) { in ub960_parse_dt_rxport()
4599 ret = PTR_ERR(rxport->vpoc); in ub960_parse_dt_rxport()
4600 if (ret == -ENODEV) { in ub960_parse_dt_rxport()
4601 rxport->vpoc = NULL; in ub960_parse_dt_rxport()
4613 mutex_init(&rxport->aliased_addrs_lock); in ub960_parse_dt_rxport()
4618 fwnode_handle_put(rxport->ser.fwnode); in ub960_parse_dt_rxport()
4620 priv->rxports[nport] = NULL; in ub960_parse_dt_rxport()
4653 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxports()
4660 return -ENODEV; in ub960_parse_dt_rxports()
4664 priv->strobe.min = 2; in ub960_parse_dt_rxports()
4665 priv->strobe.max = 3; in ub960_parse_dt_rxports()
4667 priv->strobe.manual = fwnode_property_read_bool(links_fwnode, "ti,manual-strobe"); in ub960_parse_dt_rxports()
4709 struct device *dev = &priv->client->dev; in ub960_parse_dt_txports()
4713 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_parse_dt_txports()
4714 unsigned int port = nport + priv->hw_data->num_rxports; in ub960_parse_dt_txports()
4757 struct ub960_data *priv = sd_to_ub960(notifier->sd); in ub960_notify_bound()
4758 struct ub960_rxport *rxport = to_ub960_asd(asd)->rxport; in ub960_notify_bound()
4759 struct device *dev = &priv->client->dev; in ub960_notify_bound()
4760 u8 nport = rxport->nport; in ub960_notify_bound()
4763 ret = media_entity_get_fwnode_pad(&subdev->entity, in ub960_notify_bound()
4764 rxport->source.ep_fwnode, in ub960_notify_bound()
4767 dev_err(dev, "Failed to find pad for %s\n", subdev->name); in ub960_notify_bound()
4771 rxport->source.sd = subdev; in ub960_notify_bound()
4772 rxport->source.pad = ret; in ub960_notify_bound()
4774 ret = media_create_pad_link(&rxport->source.sd->entity, in ub960_notify_bound()
4775 rxport->source.pad, &priv->sd.entity, nport, in ub960_notify_bound()
4779 dev_err(dev, "Unable to link %s:%u -> %s:%u\n", in ub960_notify_bound()
4780 rxport->source.sd->name, rxport->source.pad, in ub960_notify_bound()
4781 priv->sd.name, nport); in ub960_notify_bound()
4786 if (!it.rxport->source.sd) { in ub960_notify_bound()
4799 struct ub960_rxport *rxport = to_ub960_asd(asd)->rxport; in ub960_notify_unbind()
4801 rxport->source.sd = NULL; in ub960_notify_unbind()
4811 struct device *dev = &priv->client->dev; in ub960_v4l2_notifier_register()
4814 v4l2_async_subdev_nf_init(&priv->notifier, &priv->sd); in ub960_v4l2_notifier_register()
4819 asd = v4l2_async_nf_add_fwnode(&priv->notifier, in ub960_v4l2_notifier_register()
4820 it.rxport->source.ep_fwnode, in ub960_v4l2_notifier_register()
4825 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_register()
4829 asd->rxport = it.rxport; in ub960_v4l2_notifier_register()
4832 priv->notifier.ops = &ub960_notify_ops; in ub960_v4l2_notifier_register()
4834 ret = v4l2_async_nf_register(&priv->notifier); in ub960_v4l2_notifier_register()
4837 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_register()
4846 v4l2_async_nf_unregister(&priv->notifier); in ub960_v4l2_notifier_unregister()
4847 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_unregister()
4852 struct device *dev = &priv->client->dev; in ub960_create_subdev()
4856 v4l2_i2c_subdev_init(&priv->sd, priv->client, &ub960_subdev_ops); in ub960_create_subdev()
4857 priv->sd.internal_ops = &ub960_internal_ops; in ub960_create_subdev()
4859 v4l2_ctrl_handler_init(&priv->ctrl_handler, 1); in ub960_create_subdev()
4860 priv->sd.ctrl_handler = &priv->ctrl_handler; in ub960_create_subdev()
4862 v4l2_ctrl_new_int_menu(&priv->ctrl_handler, NULL, V4L2_CID_LINK_FREQ, in ub960_create_subdev()
4863 ARRAY_SIZE(priv->tx_link_freq) - 1, 0, in ub960_create_subdev()
4864 priv->tx_link_freq); in ub960_create_subdev()
4866 if (priv->ctrl_handler.error) { in ub960_create_subdev()
4867 ret = priv->ctrl_handler.error; in ub960_create_subdev()
4871 priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ub960_create_subdev()
4873 priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in ub960_create_subdev()
4874 priv->sd.entity.ops = &ub960_entity_ops; in ub960_create_subdev()
4876 for (i = 0; i < priv->hw_data->num_rxports + priv->hw_data->num_txports; i++) { in ub960_create_subdev()
4877 priv->pads[i].flags = ub960_pad_is_sink(priv, i) ? in ub960_create_subdev()
4882 ret = media_entity_pads_init(&priv->sd.entity, in ub960_create_subdev()
4883 priv->hw_data->num_rxports + in ub960_create_subdev()
4884 priv->hw_data->num_txports, in ub960_create_subdev()
4885 priv->pads); in ub960_create_subdev()
4889 priv->sd.state_lock = priv->sd.ctrl_handler->lock; in ub960_create_subdev()
4891 ret = v4l2_subdev_init_finalize(&priv->sd); in ub960_create_subdev()
4901 ret = v4l2_async_register_subdev(&priv->sd); in ub960_create_subdev()
4912 v4l2_subdev_cleanup(&priv->sd); in ub960_create_subdev()
4914 media_entity_cleanup(&priv->sd.entity); in ub960_create_subdev()
4916 v4l2_ctrl_handler_free(&priv->ctrl_handler); in ub960_create_subdev()
4924 v4l2_async_unregister_subdev(&priv->sd); in ub960_destroy_subdev()
4926 v4l2_subdev_cleanup(&priv->sd); in ub960_destroy_subdev()
4928 media_entity_cleanup(&priv->sd.entity); in ub960_destroy_subdev()
4929 v4l2_ctrl_handler_free(&priv->ctrl_handler); in ub960_destroy_subdev()
4949 struct device *dev = &priv->client->dev; in ub960_get_hw_resources()
4951 priv->regmap = devm_regmap_init_i2c(priv->client, &ub960_regmap_config); in ub960_get_hw_resources()
4952 if (IS_ERR(priv->regmap)) in ub960_get_hw_resources()
4953 return PTR_ERR(priv->regmap); in ub960_get_hw_resources()
4955 priv->vddio = devm_regulator_get(dev, "vddio"); in ub960_get_hw_resources()
4956 if (IS_ERR(priv->vddio)) in ub960_get_hw_resources()
4957 return dev_err_probe(dev, PTR_ERR(priv->vddio), in ub960_get_hw_resources()
4960 /* get power-down pin from DT */ in ub960_get_hw_resources()
4961 priv->pd_gpio = in ub960_get_hw_resources()
4963 if (IS_ERR(priv->pd_gpio)) in ub960_get_hw_resources()
4964 return dev_err_probe(dev, PTR_ERR(priv->pd_gpio), in ub960_get_hw_resources()
4967 priv->refclk = devm_clk_get(dev, "refclk"); in ub960_get_hw_resources()
4968 if (IS_ERR(priv->refclk)) in ub960_get_hw_resources()
4969 return dev_err_probe(dev, PTR_ERR(priv->refclk), in ub960_get_hw_resources()
4977 struct device *dev = &priv->client->dev; in ub960_enable_core_hw()
4983 ret = regulator_enable(priv->vddio); in ub960_enable_core_hw()
4988 ret = clk_prepare_enable(priv->refclk); in ub960_enable_core_hw()
4994 if (priv->pd_gpio) { in ub960_enable_core_hw()
4995 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_enable_core_hw()
4998 gpiod_set_value_cansleep(priv->pd_gpio, 0); in ub960_enable_core_hw()
5010 dev_err_probe(dev, ret, "Cannot read first register, abort\n"); in ub960_enable_core_hw()
5014 dev_dbg(dev, "Found %s (rev/mask %#04x)\n", priv->hw_data->model, in ub960_enable_core_hw()
5021 if (priv->hw_data->is_ub9702) in ub960_enable_core_hw()
5032 clk_get_rate(priv->refclk) / HZ_PER_MHZ); in ub960_enable_core_hw()
5040 if (priv->hw_data->is_ub9702) { in ub960_enable_core_hw()
5052 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_enable_core_hw()
5053 clk_disable_unprepare(priv->refclk); in ub960_enable_core_hw()
5055 regulator_disable(priv->vddio); in ub960_enable_core_hw()
5062 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_disable_core_hw()
5063 clk_disable_unprepare(priv->refclk); in ub960_disable_core_hw()
5064 regulator_disable(priv->vddio); in ub960_disable_core_hw()
5069 struct device *dev = &client->dev; in ub960_probe()
5075 return -ENOMEM; in ub960_probe()
5077 priv->client = client; in ub960_probe()
5079 priv->hw_data = device_get_match_data(dev); in ub960_probe()
5081 mutex_init(&priv->reg_lock); in ub960_probe()
5083 INIT_DELAYED_WORK(&priv->poll_work, ub960_handler_work); in ub960_probe()
5089 priv->reg_current.indirect_target = 0xff; in ub960_probe()
5090 priv->reg_current.rxport = 0xff; in ub960_probe()
5091 priv->reg_current.txport = 0xff; in ub960_probe()
5113 if (priv->hw_data->is_ub9702) in ub960_probe()
5133 if (client->irq) in ub960_probe()
5136 schedule_delayed_work(&priv->poll_work, in ub960_probe()
5159 mutex_destroy(&priv->reg_lock); in ub960_probe()
5168 cancel_delayed_work_sync(&priv->poll_work); in ub960_remove()
5177 mutex_destroy(&priv->reg_lock); in ub960_remove()
5195 { "ds90ub960-q1", (kernel_ulong_t)&ds90ub960_hw },
5196 { "ds90ub9702-q1", (kernel_ulong_t)&ds90ub9702_hw },
5202 { .compatible = "ti,ds90ub960-q1", .data = &ds90ub960_hw },
5203 { .compatible = "ti,ds90ub9702-q1", .data = &ds90ub9702_hw },
5220 MODULE_DESCRIPTION("Texas Instruments FPD-Link III/IV Deserializers Driver");