Lines Matching +full:i2c +full:- +full:alias +full:- +full:pool
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
21 * e.g. use the i2c.
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.
34 #include <linux/i2c-atr.h>
35 #include <linux/i2c.h>
49 #include <media/i2c/ds90ub9xx.h>
50 #include <media/mipi-csi2.h>
51 #include <media/v4l2-ctrls.h>
52 #include <media/v4l2-fwnode.h>
53 #include <media/v4l2-subdev.h>
58 * If this is defined, the i2c addresses from UB960_DEBUG_I2C_RX_ID to
79 * 0x00-0x32 Shared (UB960_SR)
80 * 0x33-0x3a CSI-2 TX (per-port paged on DS90UB960, shared on 954) (UB960_TR)
82 * 0x4d-0x7f FPD-Link RX, per-port paged (UB960_RR)
83 * 0xb0-0xbf Shared (UB960_SR)
84 * 0xd0-0xdf FPD-Link RX, per-port paged (UB960_RR)
85 * 0xf0-0xf5 Shared (UB960_SR)
86 * 0xf8-0xfb Shared (UB960_SR)
91 * UB960_RR_* = FPD-Link RX, per-port paged register
92 * UB960_TR_* = CSI-2 TX, per-port paged register
402 #define UB960_MIN_AEQ_STROBE_POS -7
407 #define UB960_MIN_MANUAL_STROBE_POS -(7 + UB960_MANUAL_STROBE_EXTRA_DELAY)
409 #define UB960_NUM_MANUAL_STROBE_POS (UB960_MAX_MANUAL_STROBE_POS - UB960_MIN_MANUAL_STROBE_POS + 1)
413 #define UB960_NUM_EQ_LEVELS (UB960_MAX_EQ_LEVEL - UB960_MIN_EQ_LEVEL + 1)
440 u8 nport; /* RX port number, and index in priv->rxport[] */
452 unsigned short alias; /* I2C alias (lower 7 bits) */ member
496 u8 nport; /* TX port number, and index in priv->txport[] */
558 return pad < priv->hw_data->num_rxports; in ub960_pad_is_sink()
563 return pad >= priv->hw_data->num_rxports; in ub960_pad_is_source()
571 return pad - priv->hw_data->num_rxports; in ub960_pad_to_port()
617 /* -----------------------------------------------------------------------------
623 struct device *dev = &priv->client->dev; in ub960_read()
627 mutex_lock(&priv->reg_lock); in ub960_read()
629 ret = regmap_read(priv->regmap, reg, &v); in ub960_read()
639 mutex_unlock(&priv->reg_lock); in ub960_read()
646 struct device *dev = &priv->client->dev; in ub960_write()
649 mutex_lock(&priv->reg_lock); in ub960_write()
651 ret = regmap_write(priv->regmap, reg, val); in ub960_write()
656 mutex_unlock(&priv->reg_lock); in ub960_write()
663 struct device *dev = &priv->client->dev; in ub960_update_bits()
666 mutex_lock(&priv->reg_lock); in ub960_update_bits()
668 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_update_bits()
673 mutex_unlock(&priv->reg_lock); in ub960_update_bits()
680 struct device *dev = &priv->client->dev; in ub960_read16()
684 mutex_lock(&priv->reg_lock); in ub960_read16()
686 ret = regmap_bulk_read(priv->regmap, reg, &__v, sizeof(__v)); in ub960_read16()
696 mutex_unlock(&priv->reg_lock); in ub960_read16()
703 struct device *dev = &priv->client->dev; in ub960_rxport_select()
706 lockdep_assert_held(&priv->reg_lock); in ub960_rxport_select()
708 if (priv->reg_current.rxport == nport) in ub960_rxport_select()
711 ret = regmap_write(priv->regmap, UB960_SR_FPD3_PORT_SEL, in ub960_rxport_select()
719 priv->reg_current.rxport = nport; in ub960_rxport_select()
726 struct device *dev = &priv->client->dev; in ub960_rxport_read()
730 mutex_lock(&priv->reg_lock); in ub960_rxport_read()
736 ret = regmap_read(priv->regmap, reg, &v); in ub960_rxport_read()
746 mutex_unlock(&priv->reg_lock); in ub960_rxport_read()
753 struct device *dev = &priv->client->dev; in ub960_rxport_write()
756 mutex_lock(&priv->reg_lock); in ub960_rxport_write()
762 ret = regmap_write(priv->regmap, reg, val); in ub960_rxport_write()
768 mutex_unlock(&priv->reg_lock); in ub960_rxport_write()
776 struct device *dev = &priv->client->dev; in ub960_rxport_update_bits()
779 mutex_lock(&priv->reg_lock); in ub960_rxport_update_bits()
785 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_rxport_update_bits()
791 mutex_unlock(&priv->reg_lock); in ub960_rxport_update_bits()
799 struct device *dev = &priv->client->dev; in ub960_rxport_read16()
803 mutex_lock(&priv->reg_lock); in ub960_rxport_read16()
809 ret = regmap_bulk_read(priv->regmap, reg, &__v, sizeof(__v)); in ub960_rxport_read16()
819 mutex_unlock(&priv->reg_lock); in ub960_rxport_read16()
826 struct device *dev = &priv->client->dev; in ub960_txport_select()
829 lockdep_assert_held(&priv->reg_lock); in ub960_txport_select()
831 if (priv->reg_current.txport == nport) in ub960_txport_select()
834 ret = regmap_write(priv->regmap, UB960_SR_CSI_PORT_SEL, in ub960_txport_select()
842 priv->reg_current.txport = nport; in ub960_txport_select()
849 struct device *dev = &priv->client->dev; in ub960_txport_read()
853 mutex_lock(&priv->reg_lock); in ub960_txport_read()
859 ret = regmap_read(priv->regmap, reg, &v); in ub960_txport_read()
869 mutex_unlock(&priv->reg_lock); in ub960_txport_read()
876 struct device *dev = &priv->client->dev; in ub960_txport_write()
879 mutex_lock(&priv->reg_lock); in ub960_txport_write()
885 ret = regmap_write(priv->regmap, reg, val); in ub960_txport_write()
891 mutex_unlock(&priv->reg_lock); in ub960_txport_write()
899 struct device *dev = &priv->client->dev; in ub960_txport_update_bits()
902 mutex_lock(&priv->reg_lock); in ub960_txport_update_bits()
908 ret = regmap_update_bits(priv->regmap, reg, mask, val); in ub960_txport_update_bits()
914 mutex_unlock(&priv->reg_lock); in ub960_txport_update_bits()
921 struct device *dev = &priv->client->dev; in ub960_select_ind_reg_block()
924 lockdep_assert_held(&priv->reg_lock); in ub960_select_ind_reg_block()
926 if (priv->reg_current.indirect_target == block) in ub960_select_ind_reg_block()
929 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_CTL, block << 2); in ub960_select_ind_reg_block()
936 priv->reg_current.indirect_target = block; in ub960_select_ind_reg_block()
943 struct device *dev = &priv->client->dev; in ub960_read_ind()
947 mutex_lock(&priv->reg_lock); in ub960_read_ind()
953 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_read_ind()
961 ret = regmap_read(priv->regmap, UB960_SR_IND_ACC_DATA, &v); in ub960_read_ind()
972 mutex_unlock(&priv->reg_lock); in ub960_read_ind()
979 struct device *dev = &priv->client->dev; in ub960_write_ind()
982 mutex_lock(&priv->reg_lock); in ub960_write_ind()
988 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_write_ind()
996 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_DATA, val); in ub960_write_ind()
1005 mutex_unlock(&priv->reg_lock); in ub960_write_ind()
1013 struct device *dev = &priv->client->dev; in ub960_ind_update_bits()
1016 mutex_lock(&priv->reg_lock); in ub960_ind_update_bits()
1022 ret = regmap_write(priv->regmap, UB960_SR_IND_ACC_ADDR, reg); in ub960_ind_update_bits()
1030 ret = regmap_update_bits(priv->regmap, UB960_SR_IND_ACC_DATA, mask, in ub960_ind_update_bits()
1040 mutex_unlock(&priv->reg_lock); in ub960_ind_update_bits()
1045 /* -----------------------------------------------------------------------------
1046 * I2C-ATR (address translator)
1050 const struct i2c_client *client, u16 alias) in ub960_atr_attach_client() argument
1053 struct ub960_rxport *rxport = priv->rxports[chan_id]; in ub960_atr_attach_client()
1054 struct device *dev = &priv->client->dev; in ub960_atr_attach_client()
1057 for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_clients); reg_idx++) { in ub960_atr_attach_client()
1058 if (!rxport->aliased_clients[reg_idx]) in ub960_atr_attach_client()
1062 if (reg_idx == ARRAY_SIZE(rxport->aliased_clients)) { in ub960_atr_attach_client()
1063 dev_err(dev, "rx%u: alias pool exhausted\n", rxport->nport); in ub960_atr_attach_client()
1064 return -EADDRNOTAVAIL; in ub960_atr_attach_client()
1067 rxport->aliased_clients[reg_idx] = client; in ub960_atr_attach_client()
1070 client->addr << 1); in ub960_atr_attach_client()
1072 alias << 1); in ub960_atr_attach_client()
1074 dev_dbg(dev, "rx%u: client 0x%02x assigned alias 0x%02x at slot %u\n", in ub960_atr_attach_client()
1075 rxport->nport, client->addr, alias, reg_idx); in ub960_atr_attach_client()
1084 struct ub960_rxport *rxport = priv->rxports[chan_id]; in ub960_atr_detach_client()
1085 struct device *dev = &priv->client->dev; in ub960_atr_detach_client()
1088 for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_clients); reg_idx++) { in ub960_atr_detach_client()
1089 if (rxport->aliased_clients[reg_idx] == client) in ub960_atr_detach_client()
1093 if (reg_idx == ARRAY_SIZE(rxport->aliased_clients)) { in ub960_atr_detach_client()
1095 rxport->nport, client->addr); in ub960_atr_detach_client()
1099 rxport->aliased_clients[reg_idx] = NULL; in ub960_atr_detach_client()
1103 dev_dbg(dev, "rx%u: client 0x%02x released at slot %u\n", rxport->nport, in ub960_atr_detach_client()
1104 client->addr, reg_idx); in ub960_atr_detach_client()
1114 struct device *dev = &priv->client->dev; in ub960_init_atr()
1115 struct i2c_adapter *parent_adap = priv->client->adapter; in ub960_init_atr()
1117 priv->atr = i2c_atr_new(parent_adap, dev, &ub960_atr_ops, in ub960_init_atr()
1118 priv->hw_data->num_rxports); in ub960_init_atr()
1119 if (IS_ERR(priv->atr)) in ub960_init_atr()
1120 return PTR_ERR(priv->atr); in ub960_init_atr()
1122 i2c_atr_set_driver_data(priv->atr, priv); in ub960_init_atr()
1129 i2c_atr_delete(priv->atr); in ub960_uninit_atr()
1130 priv->atr = NULL; in ub960_uninit_atr()
1133 /* -----------------------------------------------------------------------------
1141 struct device *dev = &priv->client->dev; in ub960_parse_dt_txport()
1148 return -ENOMEM; in ub960_parse_dt_txport()
1150 txport->priv = priv; in ub960_parse_dt_txport()
1151 txport->nport = nport; in ub960_parse_dt_txport()
1160 txport->non_continous_clk = vep.bus.mipi_csi2.flags & in ub960_parse_dt_txport()
1163 txport->num_data_lanes = vep.bus.mipi_csi2.num_data_lanes; in ub960_parse_dt_txport()
1166 ret = -EINVAL; in ub960_parse_dt_txport()
1170 priv->tx_link_freq[0] = vep.link_frequencies[0]; in ub960_parse_dt_txport()
1171 priv->tx_data_rate = priv->tx_link_freq[0] * 2; in ub960_parse_dt_txport()
1173 if (priv->tx_data_rate != MHZ(1600) && in ub960_parse_dt_txport()
1174 priv->tx_data_rate != MHZ(1200) && in ub960_parse_dt_txport()
1175 priv->tx_data_rate != MHZ(800) && in ub960_parse_dt_txport()
1176 priv->tx_data_rate != MHZ(400)) { in ub960_parse_dt_txport()
1177 dev_err(dev, "tx%u: invalid 'link-frequencies' value\n", nport); in ub960_parse_dt_txport()
1178 ret = -EINVAL; in ub960_parse_dt_txport()
1184 priv->txports[nport] = txport; in ub960_parse_dt_txport()
1198 struct device *dev = &priv->client->dev; in ub960_csi_handle_events()
1213 /* -----------------------------------------------------------------------------
1222 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_rxport_enable_vpocs()
1223 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_enable_vpocs()
1225 if (!rxport || !rxport->vpoc) in ub960_rxport_enable_vpocs()
1228 ret = regulator_enable(rxport->vpoc); in ub960_rxport_enable_vpocs()
1236 while (nport--) { in ub960_rxport_enable_vpocs()
1237 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_enable_vpocs()
1239 if (!rxport || !rxport->vpoc) in ub960_rxport_enable_vpocs()
1242 regulator_disable(rxport->vpoc); in ub960_rxport_enable_vpocs()
1252 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_rxport_disable_vpocs()
1253 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_disable_vpocs()
1255 if (!rxport || !rxport->vpoc) in ub960_rxport_disable_vpocs()
1258 regulator_disable(rxport->vpoc); in ub960_rxport_disable_vpocs()
1282 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) in ub960_clear_rx_errors()
1317 *strobe_pos = data_delay - clk_delay; in ub960_rxport_get_strobe_pos()
1331 clk_delay = abs(strobe_pos) - UB960_MANUAL_STROBE_EXTRA_DELAY; in ub960_rxport_set_strobe_pos()
1333 data_delay = strobe_pos - UB960_MANUAL_STROBE_EXTRA_DELAY; in ub960_rxport_set_strobe_pos()
1350 strobe_min -= UB960_MIN_AEQ_STROBE_POS; in ub960_rxport_set_strobe_range()
1351 strobe_max -= UB960_MIN_AEQ_STROBE_POS; in ub960_rxport_set_strobe_range()
1386 eq_stage_2_select_value = eq_level - eq_stage_max; in ub960_rxport_set_eq_level()
1415 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_config_eq()
1419 if (priv->strobe.manual) { in ub960_rxport_config_eq()
1430 ub960_rxport_set_strobe_range(priv, priv->strobe.min, in ub960_rxport_config_eq()
1431 priv->strobe.max); in ub960_rxport_config_eq()
1436 if (priv->strobe.manual) in ub960_rxport_config_eq()
1437 ub960_rxport_set_strobe_pos(priv, nport, rxport->eq.strobe_pos); in ub960_rxport_config_eq()
1441 if (rxport->eq.manual_eq) { in ub960_rxport_config_eq()
1443 rxport->eq.manual.eq_level); in ub960_rxport_config_eq()
1451 rxport->eq.aeq.eq_level_min, in ub960_rxport_config_eq()
1452 rxport->eq.aeq.eq_level_max); in ub960_rxport_config_eq()
1523 struct device *dev = &priv->client->dev; in ub960_rxport_wait_locks()
1537 if (port_mask >= BIT(priv->hw_data->num_rxports)) in ub960_rxport_wait_locks()
1538 return -EINVAL; in ub960_rxport_wait_locks()
1548 priv->hw_data->num_rxports) { in ub960_rxport_wait_locks()
1549 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_wait_locks()
1590 for_each_set_bit(nport, &port_mask, priv->hw_data->num_rxports) { in ub960_rxport_wait_locks()
1591 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_wait_locks()
1605 if (priv->hw_data->is_ub9702) { in ub960_rxport_wait_locks()
1634 switch (rxport->rx_mode) { in ub960_calc_bc_clk_rate_ub960()
1656 return clk_get_rate(priv->refclk) * mult / div; in ub960_calc_bc_clk_rate_ub960()
1662 switch (rxport->rx_mode) { in ub960_calc_bc_clk_rate_ub9702()
1681 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_add_serializer()
1682 struct device *dev = &priv->client->dev; in ub960_rxport_add_serializer()
1683 struct ds90ub9xx_platform_data *ser_pdata = &rxport->ser.pdata; in ub960_rxport_add_serializer()
1685 .of_node = to_of_node(rxport->ser.fwnode), in ub960_rxport_add_serializer()
1686 .fwnode = rxport->ser.fwnode, in ub960_rxport_add_serializer()
1690 ser_pdata->port = nport; in ub960_rxport_add_serializer()
1691 ser_pdata->atr = priv->atr; in ub960_rxport_add_serializer()
1692 if (priv->hw_data->is_ub9702) in ub960_rxport_add_serializer()
1693 ser_pdata->bc_rate = ub960_calc_bc_clk_rate_ub9702(priv, rxport); in ub960_rxport_add_serializer()
1695 ser_pdata->bc_rate = ub960_calc_bc_clk_rate_ub960(priv, rxport); in ub960_rxport_add_serializer()
1698 * The serializer is added under the same i2c adapter as the in ub960_rxport_add_serializer()
1700 * the FPD-Link. in ub960_rxport_add_serializer()
1702 ser_info.addr = rxport->ser.alias; in ub960_rxport_add_serializer()
1703 rxport->ser.client = in ub960_rxport_add_serializer()
1704 i2c_new_client_device(priv->client->adapter, &ser_info); in ub960_rxport_add_serializer()
1705 if (IS_ERR(rxport->ser.client)) { in ub960_rxport_add_serializer()
1706 dev_err(dev, "rx%u: cannot add %s i2c device", nport, in ub960_rxport_add_serializer()
1708 return PTR_ERR(rxport->ser.client); in ub960_rxport_add_serializer()
1711 dev_dbg(dev, "rx%u: remote serializer at alias 0x%02x (%u-%04x)\n", in ub960_rxport_add_serializer()
1712 nport, rxport->ser.client->addr, in ub960_rxport_add_serializer()
1713 rxport->ser.client->adapter->nr, rxport->ser.client->addr); in ub960_rxport_add_serializer()
1720 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_remove_serializer()
1722 i2c_unregister_device(rxport->ser.client); in ub960_rxport_remove_serializer()
1723 rxport->ser.client = NULL; in ub960_rxport_remove_serializer()
1726 /* Add serializer i2c devices for all initialized ports */
1732 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_rxport_add_serializers()
1733 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_add_serializers()
1746 while (nport--) { in ub960_rxport_add_serializers()
1747 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_add_serializers()
1762 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_rxport_remove_serializers()
1763 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_remove_serializers()
1775 unsigned int nport = txport->nport; in ub960_init_tx_port()
1779 * From the datasheet: "initial CSI Skew-Calibration in ub960_init_tx_port()
1782 if (priv->tx_data_rate == MHZ(1600)) in ub960_init_tx_port()
1785 csi_ctl |= (4 - txport->num_data_lanes) << 4; in ub960_init_tx_port()
1787 if (!txport->non_continous_clk) in ub960_init_tx_port()
1801 switch (priv->tx_data_rate) { in ub960_init_tx_ports()
1823 if (priv->hw_data->is_ub9702) { in ub960_init_tx_ports()
1826 switch (priv->tx_data_rate) { in ub960_init_tx_ports()
1843 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_init_tx_ports()
1844 struct ub960_txport *txport = priv->txports[nport]; in ub960_init_tx_ports()
1858 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub960()
1864 * 0 - 2.5 Mbps (DS90UB913A-Q1 / DS90UB933-Q1) in ub960_init_rx_port_ub960()
1865 * 2 - 10 Mbps in ub960_init_rx_port_ub960()
1866 * 6 - 50 Mbps (DS90UB953-Q1) in ub960_init_rx_port_ub960()
1872 switch (rxport->rx_mode) { in ub960_init_rx_port_ub960()
1895 switch (rxport->rx_mode) { in ub960_init_rx_port_ub960()
1897 /* FPD3_MODE = RAW10 Mode (DS90UB913A-Q1 / DS90UB933-Q1 compatible) */ in ub960_init_rx_port_ub960()
1903 * RAW10_8BIT_CTL = 0b10 : 8-bit processing using upper 8 bits in ub960_init_rx_port_ub960()
1918 /* CSI-2 Mode (DS90UB953-Q1 compatible) */ in ub960_init_rx_port_ub960()
1927 rxport->lv_fv_pol); in ub960_init_rx_port_ub960()
1938 /* Enable I2C communication to the serializer via the alias addr */ in ub960_init_rx_port_ub960()
1940 rxport->ser.alias << 1); in ub960_init_rx_port_ub960()
1952 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub9702_fpd3()
1956 switch (rxport->rx_mode) { in ub960_init_rx_port_ub9702_fpd3()
2005 /* serdes_driver_ctl2 control: DS90UB953-Q1/DS90UB933-Q1/DS90UB913A-Q1 */ in ub960_init_rx_port_ub9702_fpd3()
2009 /* RX port to half-rate */ in ub960_init_rx_port_ub9702_fpd3()
2017 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub9702_fpd4_aeq()
2051 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub9702_fpd4()
2054 switch (rxport->rx_mode) { in ub960_init_rx_port_ub9702_fpd4()
2113 unsigned int nport = rxport->nport; in ub960_init_rx_port_ub9702()
2115 if (rxport->cdr_mode == RXPORT_CDR_FPD3) in ub960_init_rx_port_ub9702()
2120 switch (rxport->rx_mode) { in ub960_init_rx_port_ub9702()
2123 * RAW10_8BIT_CTL = 0b11 : 8-bit processing using lower 8 bits in ub960_init_rx_port_ub9702()
2124 * 0b10 : 8-bit processing using upper 8 bits in ub960_init_rx_port_ub9702()
2144 rxport->lv_fv_pol); in ub960_init_rx_port_ub9702()
2155 /* Enable I2C communication to the serializer via the alias addr */ in ub960_init_rx_port_ub9702()
2157 rxport->ser.alias << 1); in ub960_init_rx_port_ub9702()
2162 if (rxport->cdr_mode == RXPORT_CDR_FPD4) { in ub960_init_rx_port_ub9702()
2172 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_init_rx_ports()
2173 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_init_rx_ports()
2178 if (priv->hw_data->is_ub9702) in ub960_init_rx_ports()
2189 struct device *dev = &priv->client->dev; in ub960_rxport_handle_events()
2307 /* -----------------------------------------------------------------------------
2335 for_each_active_route(&state->routing, route) { in ub960_get_vc_maps()
2338 rx = ub960_pad_to_port(priv, route->sink_pad); in ub960_get_vc_maps()
2342 tx = ub960_pad_to_port(priv, route->source_pad); in ub960_get_vc_maps()
2351 struct device *dev = &priv->client->dev; in ub960_enable_tx_port()
2362 struct device *dev = &priv->client->dev; in ub960_disable_tx_port()
2372 struct device *dev = &priv->client->dev; in ub960_enable_rx_port()
2383 struct device *dev = &priv->client->dev; in ub960_disable_rx_port()
2402 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_validate_stream_vcs()
2403 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_validate_stream_vcs()
2411 ret = v4l2_subdev_call(rxport->source.sd, pad, get_frame_desc, in ub960_validate_stream_vcs()
2412 rxport->source.pad, &desc); in ub960_validate_stream_vcs()
2428 dev_err(&priv->client->dev, in ub960_validate_stream_vcs()
2429 "rx%u: source with multiple virtual-channels is not supported\n", in ub960_validate_stream_vcs()
2431 return -ENODEV; in ub960_validate_stream_vcs()
2459 for_each_active_route(&state->routing, route) { in ub960_configure_ports_for_streaming()
2466 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_configure_ports_for_streaming()
2468 rxport = priv->rxports[nport]; in ub960_configure_ports_for_streaming()
2470 return -EINVAL; in ub960_configure_ports_for_streaming()
2472 txport = priv->txports[ub960_pad_to_port(priv, route->source_pad)]; in ub960_configure_ports_for_streaming()
2474 return -EINVAL; in ub960_configure_ports_for_streaming()
2476 rx_data[nport].tx_port = ub960_pad_to_port(priv, route->source_pad); in ub960_configure_ports_for_streaming()
2481 if (rxport->rx_mode == RXPORT_MODE_CSI2_SYNC || in ub960_configure_ports_for_streaming()
2482 rxport->rx_mode == RXPORT_MODE_CSI2_NONSYNC) in ub960_configure_ports_for_streaming()
2486 return -EPIPE; in ub960_configure_ports_for_streaming()
2488 fmt = v4l2_subdev_state_get_format(state, route->sink_pad, in ub960_configure_ports_for_streaming()
2489 route->sink_stream); in ub960_configure_ports_for_streaming()
2491 return -EPIPE; in ub960_configure_ports_for_streaming()
2493 ub960_fmt = ub960_find_format(fmt->code); in ub960_configure_ports_for_streaming()
2495 return -EPIPE; in ub960_configure_ports_for_streaming()
2497 if (ub960_fmt->meta) { in ub960_configure_ports_for_streaming()
2498 if (fmt->height > 3) { in ub960_configure_ports_for_streaming()
2499 dev_err(&priv->client->dev, in ub960_configure_ports_for_streaming()
2501 nport, fmt->height); in ub960_configure_ports_for_streaming()
2502 return -EPIPE; in ub960_configure_ports_for_streaming()
2505 rx_data[nport].meta_dt = ub960_fmt->datatype; in ub960_configure_ports_for_streaming()
2506 rx_data[nport].meta_lines = fmt->height; in ub960_configure_ports_for_streaming()
2508 rx_data[nport].pixel_dt = ub960_fmt->datatype; in ub960_configure_ports_for_streaming()
2520 for (unsigned int nport = 0; nport < priv->hw_data->num_rxports; in ub960_configure_ports_for_streaming()
2522 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_configure_ports_for_streaming()
2528 switch (rxport->rx_mode) { in ub960_configure_ports_for_streaming()
2533 ub960_rxport_write(priv, rxport->nport, in ub960_configure_ports_for_streaming()
2547 if (!priv->hw_data->is_ub9702) { in ub960_configure_ports_for_streaming()
2583 if (priv->stream_enable_mask[i]) in ub960_update_streaming_status()
2587 priv->streaming = i < UB960_MAX_NPORTS; in ub960_update_streaming_status()
2595 struct device *dev = &priv->client->dev; in ub960_enable_streams()
2602 if (!priv->streaming) { in ub960_enable_streams()
2610 if (!priv->stream_enable_mask[source_pad]) { in ub960_enable_streams()
2617 priv->stream_enable_mask[source_pad] |= source_streams_mask; in ub960_enable_streams()
2620 for_each_active_route(&state->routing, route) { in ub960_enable_streams()
2621 if (route->source_pad != source_pad) in ub960_enable_streams()
2624 if (!(source_streams_mask & BIT_ULL(route->source_stream))) in ub960_enable_streams()
2627 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_enable_streams()
2629 sink_streams[nport] |= BIT_ULL(route->sink_stream); in ub960_enable_streams()
2632 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_enable_streams()
2637 if (!priv->stream_enable_mask[nport]) { in ub960_enable_streams()
2645 priv->stream_enable_mask[nport] |= sink_streams[nport]; in ub960_enable_streams()
2651 priv->rxports[nport]->source.sd, in ub960_enable_streams()
2652 priv->rxports[nport]->source.pad, in ub960_enable_streams()
2655 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_enable_streams()
2657 if (!priv->stream_enable_mask[nport]) in ub960_enable_streams()
2665 priv->streaming = true; in ub960_enable_streams()
2678 priv->rxports[nport]->source.sd, in ub960_enable_streams()
2679 priv->rxports[nport]->source.pad, in ub960_enable_streams()
2684 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_enable_streams()
2687 if (!priv->stream_enable_mask[nport]) in ub960_enable_streams()
2691 priv->stream_enable_mask[source_pad] &= ~source_streams_mask; in ub960_enable_streams()
2693 if (!priv->stream_enable_mask[source_pad]) in ub960_enable_streams()
2707 struct device *dev = &priv->client->dev; in ub960_disable_streams()
2714 for_each_active_route(&state->routing, route) { in ub960_disable_streams()
2715 if (route->source_pad != source_pad) in ub960_disable_streams()
2718 if (!(source_streams_mask & BIT_ULL(route->source_stream))) in ub960_disable_streams()
2721 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_disable_streams()
2723 sink_streams[nport] |= BIT_ULL(route->sink_stream); in ub960_disable_streams()
2726 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_disable_streams()
2734 priv->rxports[nport]->source.sd, in ub960_disable_streams()
2735 priv->rxports[nport]->source.pad, in ub960_disable_streams()
2740 priv->stream_enable_mask[nport] &= ~sink_streams[nport]; in ub960_disable_streams()
2743 if (!priv->stream_enable_mask[nport]) in ub960_disable_streams()
2749 priv->stream_enable_mask[source_pad] &= ~source_streams_mask; in ub960_disable_streams()
2751 if (!priv->stream_enable_mask[source_pad]) in ub960_disable_streams()
2781 if (routing->num_routes > V4L2_FRAME_DESC_ENTRY_MAX) in _ub960_set_routing()
2782 return -E2BIG; in _ub960_set_routing()
2804 if (which == V4L2_SUBDEV_FORMAT_ACTIVE && priv->streaming) in ub960_set_routing()
2805 return -EBUSY; in ub960_set_routing()
2817 struct device *dev = &priv->client->dev; in ub960_get_frame_desc()
2821 return -EINVAL; in ub960_get_frame_desc()
2823 fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; in ub960_get_frame_desc()
2825 state = v4l2_subdev_lock_and_get_active_state(&priv->sd); in ub960_get_frame_desc()
2829 for_each_active_route(&state->routing, route) { in ub960_get_frame_desc()
2835 if (route->source_pad != pad) in ub960_get_frame_desc()
2838 nport = ub960_pad_to_port(priv, route->sink_pad); in ub960_get_frame_desc()
2840 ret = v4l2_subdev_call(priv->rxports[nport]->source.sd, pad, in ub960_get_frame_desc()
2842 priv->rxports[nport]->source.pad, in ub960_get_frame_desc()
2847 route->sink_pad); in ub960_get_frame_desc()
2852 if (source_fd.entry[i].stream == route->sink_stream) { in ub960_get_frame_desc()
2861 ret = -EPIPE; in ub960_get_frame_desc()
2865 fd->entry[fd->num_entries].stream = route->source_stream; in ub960_get_frame_desc()
2866 fd->entry[fd->num_entries].flags = source_entry->flags; in ub960_get_frame_desc()
2867 fd->entry[fd->num_entries].length = source_entry->length; in ub960_get_frame_desc()
2868 fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode; in ub960_get_frame_desc()
2870 fd->entry[fd->num_entries].bus.csi2.vc = vc_map[nport]; in ub960_get_frame_desc()
2873 fd->entry[fd->num_entries].bus.csi2.dt = in ub960_get_frame_desc()
2874 source_entry->bus.csi2.dt; in ub960_get_frame_desc()
2880 route->source_stream); in ub960_get_frame_desc()
2883 ret = -EINVAL; in ub960_get_frame_desc()
2887 ub960_fmt = ub960_find_format(fmt->code); in ub960_get_frame_desc()
2890 ret = -EINVAL; in ub960_get_frame_desc()
2894 fd->entry[fd->num_entries].bus.csi2.dt = in ub960_get_frame_desc()
2895 ub960_fmt->datatype; in ub960_get_frame_desc()
2898 fd->num_entries++; in ub960_get_frame_desc()
2914 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE && priv->streaming) in ub960_set_fmt()
2915 return -EBUSY; in ub960_set_fmt()
2918 if (ub960_pad_is_source(priv, format->pad)) in ub960_set_fmt()
2925 if (!ub960_find_format(format->format.code)) in ub960_set_fmt()
2926 format->format.code = ub960_formats[0].code; in ub960_set_fmt()
2928 fmt = v4l2_subdev_state_get_format(state, format->pad, format->stream); in ub960_set_fmt()
2930 return -EINVAL; in ub960_set_fmt()
2932 *fmt = format->format; in ub960_set_fmt()
2934 fmt = v4l2_subdev_state_get_opposite_stream_format(state, format->pad, in ub960_set_fmt()
2935 format->stream); in ub960_set_fmt()
2937 return -EINVAL; in ub960_set_fmt()
2939 *fmt = format->format; in ub960_set_fmt()
2953 .source_pad = priv->hw_data->num_rxports, in ub960_init_state()
2981 struct device *dev = &priv->client->dev; in ub960_log_status_ub960_sp_eq()
3003 ((v >> UB960_XR_SFILTER_CFG_SFILTER_MIN_SHIFT) & 0xf) - 7, in ub960_log_status_ub960_sp_eq()
3004 ((v >> UB960_XR_SFILTER_CFG_SFILTER_MAX_SHIFT) & 0xf) - 7); in ub960_log_status_ub960_sp_eq()
3040 struct device *dev = &priv->client->dev; in ub960_log_status()
3054 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_log_status()
3055 struct ub960_txport *txport = priv->txports[nport]; in ub960_log_status()
3081 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_log_status()
3082 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_log_status()
3117 if (!priv->hw_data->is_ub9702) in ub960_log_status()
3159 /* -----------------------------------------------------------------------------
3175 dev_dbg(&priv->client->dev, "INTERRUPT_STS %x\n", int_sts); in ub960_handle_events()
3181 dev_dbg(&priv->client->dev, "FWD_STS %#02x\n", fwd_sts); in ub960_handle_events()
3183 for (i = 0; i < priv->hw_data->num_txports; i++) { in ub960_handle_events()
3188 for (i = 0; i < priv->hw_data->num_rxports; i++) { in ub960_handle_events()
3189 if (!priv->rxports[i]) in ub960_handle_events()
3207 schedule_delayed_work(&priv->poll_work, in ub960_handler_work()
3215 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_txport_free_ports()
3216 struct ub960_txport *txport = priv->txports[nport]; in ub960_txport_free_ports()
3222 priv->txports[nport] = NULL; in ub960_txport_free_ports()
3230 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_rxport_free_ports()
3231 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_rxport_free_ports()
3236 fwnode_handle_put(rxport->source.ep_fwnode); in ub960_rxport_free_ports()
3237 fwnode_handle_put(rxport->ser.fwnode); in ub960_rxport_free_ports()
3240 priv->rxports[nport] = NULL; in ub960_rxport_free_ports()
3249 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport_link_properties()
3250 unsigned int nport = rxport->nport; in ub960_parse_dt_rxport_link_properties()
3260 ret = fwnode_property_read_u32(link_fwnode, "ti,cdr-mode", &cdr_mode); in ub960_parse_dt_rxport_link_properties()
3261 if (ret < 0 && ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
3263 "ti,cdr-mode", ret); in ub960_parse_dt_rxport_link_properties()
3268 dev_err(dev, "rx%u: bad 'ti,cdr-mode' %u\n", nport, cdr_mode); in ub960_parse_dt_rxport_link_properties()
3269 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3272 if (!priv->hw_data->is_fpdlink4 && cdr_mode == RXPORT_CDR_FPD4) { in ub960_parse_dt_rxport_link_properties()
3273 dev_err(dev, "rx%u: FPD-Link 4 CDR not supported\n", nport); in ub960_parse_dt_rxport_link_properties()
3274 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3277 rxport->cdr_mode = cdr_mode; in ub960_parse_dt_rxport_link_properties()
3279 ret = fwnode_property_read_u32(link_fwnode, "ti,rx-mode", &rx_mode); in ub960_parse_dt_rxport_link_properties()
3282 "ti,rx-mode", ret); in ub960_parse_dt_rxport_link_properties()
3287 dev_err(dev, "rx%u: bad 'ti,rx-mode' %u\n", nport, rx_mode); in ub960_parse_dt_rxport_link_properties()
3288 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3294 dev_err(dev, "rx%u: unsupported 'ti,rx-mode' %u\n", nport, in ub960_parse_dt_rxport_link_properties()
3296 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3301 rxport->rx_mode = rx_mode; in ub960_parse_dt_rxport_link_properties()
3306 rxport->eq.manual_eq = false; in ub960_parse_dt_rxport_link_properties()
3307 rxport->eq.aeq.eq_level_min = UB960_MIN_EQ_LEVEL; in ub960_parse_dt_rxport_link_properties()
3308 rxport->eq.aeq.eq_level_max = UB960_MAX_EQ_LEVEL; in ub960_parse_dt_rxport_link_properties()
3310 ret = fwnode_property_read_u32(link_fwnode, "ti,strobe-pos", in ub960_parse_dt_rxport_link_properties()
3313 if (ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
3315 "ti,strobe-pos", ret); in ub960_parse_dt_rxport_link_properties()
3321 dev_err(dev, "rx%u: illegal 'strobe-pos' value: %d\n", in ub960_parse_dt_rxport_link_properties()
3323 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3327 rxport->eq.strobe_pos = strobe_pos; in ub960_parse_dt_rxport_link_properties()
3328 if (!priv->strobe.manual) in ub960_parse_dt_rxport_link_properties()
3330 "rx%u: 'ti,strobe-pos' ignored as 'ti,manual-strobe' not set\n", in ub960_parse_dt_rxport_link_properties()
3334 ret = fwnode_property_read_u32(link_fwnode, "ti,eq-level", &eq_level); in ub960_parse_dt_rxport_link_properties()
3336 if (ret != -EINVAL) { in ub960_parse_dt_rxport_link_properties()
3338 "ti,eq-level", ret); in ub960_parse_dt_rxport_link_properties()
3343 dev_err(dev, "rx%u: illegal 'ti,eq-level' value: %d\n", in ub960_parse_dt_rxport_link_properties()
3345 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3348 rxport->eq.manual_eq = true; in ub960_parse_dt_rxport_link_properties()
3349 rxport->eq.manual.eq_level = eq_level; in ub960_parse_dt_rxport_link_properties()
3352 ret = fwnode_property_read_u32(link_fwnode, "i2c-alias", in ub960_parse_dt_rxport_link_properties()
3356 "i2c-alias", ret); in ub960_parse_dt_rxport_link_properties()
3359 rxport->ser.alias = ser_i2c_alias; in ub960_parse_dt_rxport_link_properties()
3361 rxport->ser.fwnode = fwnode_get_named_child_node(link_fwnode, "serializer"); in ub960_parse_dt_rxport_link_properties()
3362 if (!rxport->ser.fwnode) { in ub960_parse_dt_rxport_link_properties()
3364 return -EINVAL; in ub960_parse_dt_rxport_link_properties()
3374 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport_ep_properties()
3376 unsigned int nport = rxport->nport; in ub960_parse_dt_rxport_ep_properties()
3381 rxport->source.ep_fwnode = fwnode_graph_get_remote_endpoint(ep_fwnode); in ub960_parse_dt_rxport_ep_properties()
3382 if (!rxport->source.ep_fwnode) { in ub960_parse_dt_rxport_ep_properties()
3384 return -ENODEV; in ub960_parse_dt_rxport_ep_properties()
3389 switch (rxport->rx_mode) { in ub960_parse_dt_rxport_ep_properties()
3409 rxport->lv_fv_pol = (hsync_hi ? UB960_RR_PORT_CONFIG2_LV_POL_LOW : 0) | in ub960_parse_dt_rxport_ep_properties()
3415 fwnode_handle_put(rxport->source.ep_fwnode); in ub960_parse_dt_rxport_ep_properties()
3426 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxport()
3432 return -ENOMEM; in ub960_parse_dt_rxport()
3434 priv->rxports[nport] = rxport; in ub960_parse_dt_rxport()
3436 rxport->nport = nport; in ub960_parse_dt_rxport()
3437 rxport->priv = priv; in ub960_parse_dt_rxport()
3443 rxport->vpoc = devm_regulator_get_optional(dev, vpoc_names[nport]); in ub960_parse_dt_rxport()
3444 if (IS_ERR(rxport->vpoc)) { in ub960_parse_dt_rxport()
3445 ret = PTR_ERR(rxport->vpoc); in ub960_parse_dt_rxport()
3446 if (ret == -ENODEV) { in ub960_parse_dt_rxport()
3447 rxport->vpoc = NULL; in ub960_parse_dt_rxport()
3462 fwnode_handle_put(rxport->ser.fwnode); in ub960_parse_dt_rxport()
3464 priv->rxports[nport] = NULL; in ub960_parse_dt_rxport()
3497 struct device *dev = &priv->client->dev; in ub960_parse_dt_rxports()
3505 return -ENODEV; in ub960_parse_dt_rxports()
3509 priv->strobe.min = 2; in ub960_parse_dt_rxports()
3510 priv->strobe.max = 3; in ub960_parse_dt_rxports()
3512 priv->strobe.manual = fwnode_property_read_bool(links_fwnode, "ti,manual-strobe"); in ub960_parse_dt_rxports()
3514 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_parse_dt_rxports()
3553 struct device *dev = &priv->client->dev; in ub960_parse_dt_txports()
3557 for (nport = 0; nport < priv->hw_data->num_txports; nport++) { in ub960_parse_dt_txports()
3558 unsigned int port = nport + priv->hw_data->num_rxports; in ub960_parse_dt_txports()
3601 struct ub960_data *priv = sd_to_ub960(notifier->sd); in ub960_notify_bound()
3602 struct ub960_rxport *rxport = to_ub960_asd(asd)->rxport; in ub960_notify_bound()
3603 struct device *dev = &priv->client->dev; in ub960_notify_bound()
3604 u8 nport = rxport->nport; in ub960_notify_bound()
3608 ret = media_entity_get_fwnode_pad(&subdev->entity, in ub960_notify_bound()
3609 rxport->source.ep_fwnode, in ub960_notify_bound()
3612 dev_err(dev, "Failed to find pad for %s\n", subdev->name); in ub960_notify_bound()
3616 rxport->source.sd = subdev; in ub960_notify_bound()
3617 rxport->source.pad = ret; in ub960_notify_bound()
3619 ret = media_create_pad_link(&rxport->source.sd->entity, in ub960_notify_bound()
3620 rxport->source.pad, &priv->sd.entity, nport, in ub960_notify_bound()
3624 dev_err(dev, "Unable to link %s:%u -> %s:%u\n", in ub960_notify_bound()
3625 rxport->source.sd->name, rxport->source.pad, in ub960_notify_bound()
3626 priv->sd.name, nport); in ub960_notify_bound()
3630 for (i = 0; i < priv->hw_data->num_rxports; i++) { in ub960_notify_bound()
3631 if (priv->rxports[i] && !priv->rxports[i]->source.sd) { in ub960_notify_bound()
3644 struct ub960_rxport *rxport = to_ub960_asd(asd)->rxport; in ub960_notify_unbind()
3646 rxport->source.sd = NULL; in ub960_notify_unbind()
3656 struct device *dev = &priv->client->dev; in ub960_v4l2_notifier_register()
3660 v4l2_async_subdev_nf_init(&priv->notifier, &priv->sd); in ub960_v4l2_notifier_register()
3662 for (i = 0; i < priv->hw_data->num_rxports; i++) { in ub960_v4l2_notifier_register()
3663 struct ub960_rxport *rxport = priv->rxports[i]; in ub960_v4l2_notifier_register()
3669 asd = v4l2_async_nf_add_fwnode(&priv->notifier, in ub960_v4l2_notifier_register()
3670 rxport->source.ep_fwnode, in ub960_v4l2_notifier_register()
3675 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_register()
3679 asd->rxport = rxport; in ub960_v4l2_notifier_register()
3682 priv->notifier.ops = &ub960_notify_ops; in ub960_v4l2_notifier_register()
3684 ret = v4l2_async_nf_register(&priv->notifier); in ub960_v4l2_notifier_register()
3687 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_register()
3696 v4l2_async_nf_unregister(&priv->notifier); in ub960_v4l2_notifier_unregister()
3697 v4l2_async_nf_cleanup(&priv->notifier); in ub960_v4l2_notifier_unregister()
3702 struct device *dev = &priv->client->dev; in ub960_create_subdev()
3706 v4l2_i2c_subdev_init(&priv->sd, priv->client, &ub960_subdev_ops); in ub960_create_subdev()
3707 priv->sd.internal_ops = &ub960_internal_ops; in ub960_create_subdev()
3709 v4l2_ctrl_handler_init(&priv->ctrl_handler, 1); in ub960_create_subdev()
3710 priv->sd.ctrl_handler = &priv->ctrl_handler; in ub960_create_subdev()
3712 v4l2_ctrl_new_int_menu(&priv->ctrl_handler, NULL, V4L2_CID_LINK_FREQ, in ub960_create_subdev()
3713 ARRAY_SIZE(priv->tx_link_freq) - 1, 0, in ub960_create_subdev()
3714 priv->tx_link_freq); in ub960_create_subdev()
3716 if (priv->ctrl_handler.error) { in ub960_create_subdev()
3717 ret = priv->ctrl_handler.error; in ub960_create_subdev()
3721 priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ub960_create_subdev()
3723 priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in ub960_create_subdev()
3724 priv->sd.entity.ops = &ub960_entity_ops; in ub960_create_subdev()
3726 for (i = 0; i < priv->hw_data->num_rxports + priv->hw_data->num_txports; i++) { in ub960_create_subdev()
3727 priv->pads[i].flags = ub960_pad_is_sink(priv, i) ? in ub960_create_subdev()
3732 ret = media_entity_pads_init(&priv->sd.entity, in ub960_create_subdev()
3733 priv->hw_data->num_rxports + in ub960_create_subdev()
3734 priv->hw_data->num_txports, in ub960_create_subdev()
3735 priv->pads); in ub960_create_subdev()
3739 priv->sd.state_lock = priv->sd.ctrl_handler->lock; in ub960_create_subdev()
3741 ret = v4l2_subdev_init_finalize(&priv->sd); in ub960_create_subdev()
3751 ret = v4l2_async_register_subdev(&priv->sd); in ub960_create_subdev()
3762 v4l2_subdev_cleanup(&priv->sd); in ub960_create_subdev()
3764 media_entity_cleanup(&priv->sd.entity); in ub960_create_subdev()
3766 v4l2_ctrl_handler_free(&priv->ctrl_handler); in ub960_create_subdev()
3774 v4l2_async_unregister_subdev(&priv->sd); in ub960_destroy_subdev()
3776 v4l2_subdev_cleanup(&priv->sd); in ub960_destroy_subdev()
3778 media_entity_cleanup(&priv->sd.entity); in ub960_destroy_subdev()
3779 v4l2_ctrl_handler_free(&priv->ctrl_handler); in ub960_destroy_subdev()
3799 struct device *dev = &priv->client->dev; in ub960_reset()
3809 mutex_lock(&priv->reg_lock); in ub960_reset()
3811 ret = regmap_read_poll_timeout(priv->regmap, UB960_SR_RESET, v, in ub960_reset()
3814 mutex_unlock(&priv->reg_lock); in ub960_reset()
3822 struct device *dev = &priv->client->dev; in ub960_get_hw_resources()
3824 priv->regmap = devm_regmap_init_i2c(priv->client, &ub960_regmap_config); in ub960_get_hw_resources()
3825 if (IS_ERR(priv->regmap)) in ub960_get_hw_resources()
3826 return PTR_ERR(priv->regmap); in ub960_get_hw_resources()
3828 priv->vddio = devm_regulator_get(dev, "vddio"); in ub960_get_hw_resources()
3829 if (IS_ERR(priv->vddio)) in ub960_get_hw_resources()
3830 return dev_err_probe(dev, PTR_ERR(priv->vddio), in ub960_get_hw_resources()
3833 /* get power-down pin from DT */ in ub960_get_hw_resources()
3834 priv->pd_gpio = in ub960_get_hw_resources()
3836 if (IS_ERR(priv->pd_gpio)) in ub960_get_hw_resources()
3837 return dev_err_probe(dev, PTR_ERR(priv->pd_gpio), in ub960_get_hw_resources()
3840 priv->refclk = devm_clk_get(dev, "refclk"); in ub960_get_hw_resources()
3841 if (IS_ERR(priv->refclk)) in ub960_get_hw_resources()
3842 return dev_err_probe(dev, PTR_ERR(priv->refclk), in ub960_get_hw_resources()
3850 struct device *dev = &priv->client->dev; in ub960_enable_core_hw()
3856 ret = regulator_enable(priv->vddio); in ub960_enable_core_hw()
3861 ret = clk_prepare_enable(priv->refclk); in ub960_enable_core_hw()
3867 if (priv->pd_gpio) { in ub960_enable_core_hw()
3868 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_enable_core_hw()
3871 gpiod_set_value_cansleep(priv->pd_gpio, 0); in ub960_enable_core_hw()
3885 dev_dbg(dev, "Found %s (rev/mask %#04x)\n", priv->hw_data->model, in ub960_enable_core_hw()
3892 if (priv->hw_data->is_ub9702) in ub960_enable_core_hw()
3901 clk_get_rate(priv->refclk) / HZ_PER_MHZ); in ub960_enable_core_hw()
3909 if (priv->hw_data->is_ub9702) { in ub960_enable_core_hw()
3920 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_enable_core_hw()
3921 clk_disable_unprepare(priv->refclk); in ub960_enable_core_hw()
3923 regulator_disable(priv->vddio); in ub960_enable_core_hw()
3930 gpiod_set_value_cansleep(priv->pd_gpio, 1); in ub960_disable_core_hw()
3931 clk_disable_unprepare(priv->refclk); in ub960_disable_core_hw()
3932 regulator_disable(priv->vddio); in ub960_disable_core_hw()
3937 struct device *dev = &client->dev; in ub960_probe()
3946 return -ENOMEM; in ub960_probe()
3948 priv->client = client; in ub960_probe()
3950 priv->hw_data = device_get_match_data(dev); in ub960_probe()
3952 mutex_init(&priv->reg_lock); in ub960_probe()
3954 INIT_DELAYED_WORK(&priv->poll_work, ub960_handler_work); in ub960_probe()
3960 priv->reg_current.indirect_target = 0xff; in ub960_probe()
3961 priv->reg_current.rxport = 0xff; in ub960_probe()
3962 priv->reg_current.txport = 0xff; in ub960_probe()
3992 for (nport = 0; nport < priv->hw_data->num_rxports; nport++) { in ub960_probe()
3993 struct ub960_rxport *rxport = priv->rxports[nport]; in ub960_probe()
4006 ret = -EIO; in ub960_probe()
4029 if (client->irq) in ub960_probe()
4032 schedule_delayed_work(&priv->poll_work, in ub960_probe()
4036 for (unsigned int i = 0; i < priv->hw_data->num_rxports; i++) in ub960_probe()
4055 mutex_destroy(&priv->reg_lock); in ub960_probe()
4064 cancel_delayed_work_sync(&priv->poll_work); in ub960_remove()
4073 mutex_destroy(&priv->reg_lock); in ub960_remove()
4091 { "ds90ub960-q1", (kernel_ulong_t)&ds90ub960_hw },
4092 { "ds90ub9702-q1", (kernel_ulong_t)&ds90ub9702_hw },
4095 MODULE_DEVICE_TABLE(i2c, ub960_id);
4098 { .compatible = "ti,ds90ub960-q1", .data = &ds90ub960_hw },
4099 { .compatible = "ti,ds90ub9702-q1", .data = &ds90ub9702_hw },
4116 MODULE_DESCRIPTION("Texas Instruments FPD-Link III/IV Deserializers Driver");