• Home
  • Raw
  • Download

Lines Matching +full:keep +full:- +full:pll +full:- +full:enabled

1 // SPDX-License-Identifier: GPL-2.0
53 * Note that the following SMBus, CAUSE, GPIO and PLL register addresses
55 * memory-mapped region whose addresses are specified in either the DT or
65 /* Reference clock for Bluefield - 156 MHz. */
68 /* Constant used to determine the PLL frequency. */
71 /* PLL registers. */
85 * as interrupt enabled bits.
122 * as interrupt enabled bits.
150 * SMBUS GW0 -> bits[26:25]
151 * SMBUS GW1 -> bits[28:27]
152 * SMBUS GW2 -> bits[30:29]
185 * frequency based on PLL parameters.
189 /* Core PLL TYU configuration. */
198 /* Core PLL YU configuration. */
207 /* Core PLL frequency. */
222 * When enabled, the master will issue a stop condition in case of
257 #define MLXBF_I2C_MASTER_DATA_W_LENGTH (MLXBF_I2C_MASTER_DATA_DESC_SIZE - 1)
389 .end = (addr) + (size) - 1, \
416 MLXBF_I2C_CHIP_TYPE_1, /* Mellanox BlueField-1 chip. */
417 MLXBF_I2C_CHIP_TYPE_2, /* Mallanox BlueField-2 chip. */
425 /* Callback to calculate the core PLL frequency. */
508 } while (timeout-- != 0); in mlxbf_smbus_poll()
524 if (mlxbf_smbus_poll(priv->smbus->io, addr, mask, true, timeout)) in mlxbf_smbus_master_wait_for_idle()
537 * de-asserted then the SMBus expects the following GW configuration in mlxbf_i2c_smbus_transaction_success()
553 * or some positive number indicating a non-fault return.
567 mlxbf_smbus_poll(priv->smbus->io, MLXBF_I2C_SMBUS_MASTER_GW, in mlxbf_i2c_smbus_check_status()
572 cause_status_bits = readl(priv->mst_cause->io + in mlxbf_i2c_smbus_check_status()
580 master_status_bits = readl(priv->smbus->io + in mlxbf_i2c_smbus_check_status()
596 return -EIO; in mlxbf_i2c_smbus_check_status()
599 return -EAGAIN; in mlxbf_i2c_smbus_check_status()
601 return -ETIMEDOUT; in mlxbf_i2c_smbus_check_status()
613 * Copy data bytes from 4-byte aligned source buffer. in mlxbf_i2c_smbus_write_data()
617 * when writing data bytes to the 32 * 32-bit HW Data registers in mlxbf_i2c_smbus_write_data()
622 iowrite32be(data32, priv->smbus->io + addr + offset); in mlxbf_i2c_smbus_write_data()
632 mask = sizeof(u32) - 1; in mlxbf_i2c_smbus_read_data()
638 * reading data bytes from the 32 * 32-bit HW Data registers in mlxbf_i2c_smbus_read_data()
643 data32 = ioread32be(priv->smbus->io + addr + offset); in mlxbf_i2c_smbus_read_data()
650 data32 = ioread32be(priv->smbus->io + addr + offset); in mlxbf_i2c_smbus_read_data()
676 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_STATUS); in mlxbf_i2c_smbus_enable()
678 writel(~0x0, priv->smbus->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_smbus_enable()
680 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_PEC); in mlxbf_i2c_smbus_enable()
682 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_RS_BYTES); in mlxbf_i2c_smbus_enable()
685 writel(command, priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_GW); in mlxbf_i2c_smbus_enable()
707 if (request->operation_cnt > MLXBF_I2C_SMBUS_MAX_OP_CNT) in mlxbf_i2c_smbus_start_transaction()
708 return -EINVAL; in mlxbf_i2c_smbus_start_transaction()
718 slave = request->slave & GENMASK(6, 0); in mlxbf_i2c_smbus_start_transaction()
723 return -EBUSY; in mlxbf_i2c_smbus_start_transaction()
728 for (op_idx = 0; op_idx < request->operation_cnt; op_idx++) { in mlxbf_i2c_smbus_start_transaction()
729 operation = &request->operation[op_idx]; in mlxbf_i2c_smbus_start_transaction()
730 flags = operation->flags; in mlxbf_i2c_smbus_start_transaction()
746 write_len += operation->length; in mlxbf_i2c_smbus_start_transaction()
748 operation->buffer, operation->length); in mlxbf_i2c_smbus_start_transaction()
749 data_idx += operation->length; in mlxbf_i2c_smbus_start_transaction()
760 read_len = operation->length - 1; in mlxbf_i2c_smbus_start_transaction()
761 read_buf = operation->buffer; in mlxbf_i2c_smbus_start_transaction()
802 priv->smbus->io + MLXBF_I2C_SMBUS_MASTER_FSM); in mlxbf_i2c_smbus_start_transaction()
814 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_1; in mlxbf_i2c_smbus_quick_command()
816 request->operation[0].length = 0; in mlxbf_i2c_smbus_quick_command()
817 request->operation[0].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_quick_command()
818 request->operation[0].flags |= read ? MLXBF_I2C_F_READ : 0; in mlxbf_i2c_smbus_quick_command()
824 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_1; in mlxbf_i2c_smbus_byte_func()
826 request->operation[0].length = 1; in mlxbf_i2c_smbus_byte_func()
827 request->operation[0].length += pec_check; in mlxbf_i2c_smbus_byte_func()
829 request->operation[0].flags = MLXBF_I2C_F_SMBUS_OPERATION; in mlxbf_i2c_smbus_byte_func()
830 request->operation[0].flags |= read ? in mlxbf_i2c_smbus_byte_func()
832 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_byte_func()
834 request->operation[0].buffer = data; in mlxbf_i2c_smbus_byte_func()
841 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_data_byte_func()
843 request->operation[0].length = 1; in mlxbf_i2c_smbus_data_byte_func()
844 request->operation[0].flags = in mlxbf_i2c_smbus_data_byte_func()
846 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_data_byte_func()
847 request->operation[0].buffer = command; in mlxbf_i2c_smbus_data_byte_func()
849 request->operation[1].length = 1; in mlxbf_i2c_smbus_data_byte_func()
850 request->operation[1].length += pec_check; in mlxbf_i2c_smbus_data_byte_func()
851 request->operation[1].flags = read ? in mlxbf_i2c_smbus_data_byte_func()
853 request->operation[1].buffer = data; in mlxbf_i2c_smbus_data_byte_func()
860 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_data_word_func()
862 request->operation[0].length = 1; in mlxbf_i2c_smbus_data_word_func()
863 request->operation[0].flags = in mlxbf_i2c_smbus_data_word_func()
865 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_data_word_func()
866 request->operation[0].buffer = command; in mlxbf_i2c_smbus_data_word_func()
868 request->operation[1].length = 2; in mlxbf_i2c_smbus_data_word_func()
869 request->operation[1].length += pec_check; in mlxbf_i2c_smbus_data_word_func()
870 request->operation[1].flags = read ? in mlxbf_i2c_smbus_data_word_func()
872 request->operation[1].buffer = data; in mlxbf_i2c_smbus_data_word_func()
880 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_i2c_block_func()
882 request->operation[0].length = 1; in mlxbf_i2c_smbus_i2c_block_func()
883 request->operation[0].flags = in mlxbf_i2c_smbus_i2c_block_func()
885 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_i2c_block_func()
886 request->operation[0].buffer = command; in mlxbf_i2c_smbus_i2c_block_func()
893 request->operation[1].length = in mlxbf_i2c_smbus_i2c_block_func()
896 request->operation[1].flags = read ? in mlxbf_i2c_smbus_i2c_block_func()
902 request->operation[1].buffer = data + 1; in mlxbf_i2c_smbus_i2c_block_func()
904 *data_len = request->operation[1].length; in mlxbf_i2c_smbus_i2c_block_func()
915 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_block_func()
917 request->operation[0].length = 1; in mlxbf_i2c_smbus_block_func()
918 request->operation[0].flags = in mlxbf_i2c_smbus_block_func()
920 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_block_func()
921 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_block_func()
922 request->operation[0].buffer = command; in mlxbf_i2c_smbus_block_func()
924 request->operation[1].length = in mlxbf_i2c_smbus_block_func()
927 request->operation[1].flags = read ? in mlxbf_i2c_smbus_block_func()
929 request->operation[1].buffer = data + 1; in mlxbf_i2c_smbus_block_func()
931 *data_len = request->operation[1].length; in mlxbf_i2c_smbus_block_func()
942 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_3; in mlxbf_i2c_smbus_process_call_func()
944 request->operation[0].length = 1; in mlxbf_i2c_smbus_process_call_func()
945 request->operation[0].flags = in mlxbf_i2c_smbus_process_call_func()
947 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_process_call_func()
948 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_process_call_func()
949 request->operation[0].buffer = command; in mlxbf_i2c_smbus_process_call_func()
951 request->operation[1].length = 2; in mlxbf_i2c_smbus_process_call_func()
952 request->operation[1].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_process_call_func()
953 request->operation[1].buffer = data; in mlxbf_i2c_smbus_process_call_func()
955 request->operation[2].length = 3; in mlxbf_i2c_smbus_process_call_func()
956 request->operation[2].flags = MLXBF_I2C_F_READ; in mlxbf_i2c_smbus_process_call_func()
957 request->operation[2].buffer = data; in mlxbf_i2c_smbus_process_call_func()
967 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_3; in mlxbf_i2c_smbus_blk_process_call_func()
969 request->operation[0].length = 1; in mlxbf_i2c_smbus_blk_process_call_func()
970 request->operation[0].flags = in mlxbf_i2c_smbus_blk_process_call_func()
972 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_blk_process_call_func()
973 request->operation[0].flags |= (pec_check) ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_blk_process_call_func()
974 request->operation[0].buffer = command; in mlxbf_i2c_smbus_blk_process_call_func()
979 request->operation[1].length = length - pec_check; in mlxbf_i2c_smbus_blk_process_call_func()
980 request->operation[1].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_blk_process_call_func()
981 request->operation[1].buffer = data; in mlxbf_i2c_smbus_blk_process_call_func()
983 request->operation[2].length = length; in mlxbf_i2c_smbus_blk_process_call_func()
984 request->operation[2].flags = MLXBF_I2C_F_READ; in mlxbf_i2c_smbus_blk_process_call_func()
985 request->operation[2].buffer = data; in mlxbf_i2c_smbus_blk_process_call_func()
994 return priv->chip->type == type; in mlxbf_i2c_has_chip_type()
1000 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_get_shared_resource()
1005 res = chip->shared_res[res_idx]; in mlxbf_i2c_get_shared_resource()
1006 if (res && res->type == type) in mlxbf_i2c_get_shared_resource()
1018 struct device *dev = &pdev->dev; in mlxbf_i2c_init_resource()
1021 return -EINVAL; in mlxbf_i2c_init_resource()
1026 return -ENOMEM; in mlxbf_i2c_init_resource()
1028 tmp_res->params = platform_get_resource(pdev, IORESOURCE_MEM, type); in mlxbf_i2c_init_resource()
1029 if (!tmp_res->params) { in mlxbf_i2c_init_resource()
1031 return -EIO; in mlxbf_i2c_init_resource()
1034 tmp_res->io = devm_ioremap_resource(dev, tmp_res->params); in mlxbf_i2c_init_resource()
1035 if (IS_ERR(tmp_res->io)) { in mlxbf_i2c_init_resource()
1037 return PTR_ERR(tmp_res->io); in mlxbf_i2c_init_resource()
1040 tmp_res->type = type; in mlxbf_i2c_init_resource()
1057 * Time = --------- x 10^9 => Ticks = Time x Frequency x 10^-9 in mlxbf_i2c_get_ticks()
1060 frequency = priv->frequency; in mlxbf_i2c_get_ticks()
1085 timer = mlxbf_i2c_set_timer(priv, timings->scl_high, in mlxbf_i2c_set_timings()
1088 timer |= mlxbf_i2c_set_timer(priv, timings->scl_low, in mlxbf_i2c_set_timings()
1091 writel(timer, priv->smbus->io + in mlxbf_i2c_set_timings()
1094 timer = mlxbf_i2c_set_timer(priv, timings->sda_rise, false, in mlxbf_i2c_set_timings()
1096 timer |= mlxbf_i2c_set_timer(priv, timings->sda_fall, false, in mlxbf_i2c_set_timings()
1098 timer |= mlxbf_i2c_set_timer(priv, timings->scl_rise, false, in mlxbf_i2c_set_timings()
1100 timer |= mlxbf_i2c_set_timer(priv, timings->scl_fall, false, in mlxbf_i2c_set_timings()
1102 writel(timer, priv->smbus->io + in mlxbf_i2c_set_timings()
1105 timer = mlxbf_i2c_set_timer(priv, timings->hold_start, true, in mlxbf_i2c_set_timings()
1107 timer |= mlxbf_i2c_set_timer(priv, timings->hold_data, true, in mlxbf_i2c_set_timings()
1109 writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_TIMER_THOLD); in mlxbf_i2c_set_timings()
1111 timer = mlxbf_i2c_set_timer(priv, timings->setup_start, true, in mlxbf_i2c_set_timings()
1113 timer |= mlxbf_i2c_set_timer(priv, timings->setup_stop, true, in mlxbf_i2c_set_timings()
1115 writel(timer, priv->smbus->io + in mlxbf_i2c_set_timings()
1118 timer = mlxbf_i2c_set_timer(priv, timings->setup_data, true, in mlxbf_i2c_set_timings()
1120 writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_TIMER_TSETUP_DATA); in mlxbf_i2c_set_timings()
1122 timer = mlxbf_i2c_set_timer(priv, timings->buf, false, in mlxbf_i2c_set_timings()
1124 timer |= mlxbf_i2c_set_timer(priv, timings->thigh_max, false, in mlxbf_i2c_set_timings()
1126 writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_THIGH_MAX_TBUF); in mlxbf_i2c_set_timings()
1128 timer = timings->timeout; in mlxbf_i2c_set_timings()
1129 writel(timer, priv->smbus->io + MLXBF_I2C_SMBUS_SCL_LOW_TIMEOUT); in mlxbf_i2c_set_timings()
1139 * Note that the mlxbf_i2c_timings->timeout value is not related to the
1198 struct device *dev = &pdev->dev; in mlxbf_i2c_init_timings()
1203 ret = device_property_read_u32(dev, "clock-frequency", &config_khz); in mlxbf_i2c_init_timings()
1235 struct device *dev = &pdev->dev; in mlxbf_i2c_get_gpio()
1241 return -EPERM; in mlxbf_i2c_get_gpio()
1248 lockdep_assert_held(gpio_res->lock); in mlxbf_i2c_get_gpio()
1251 if (gpio_res->io) in mlxbf_i2c_get_gpio()
1254 params = gpio_res->params; in mlxbf_i2c_get_gpio()
1257 if (!devm_request_mem_region(dev, params->start, size, params->name)) in mlxbf_i2c_get_gpio()
1258 return -EFAULT; in mlxbf_i2c_get_gpio()
1260 gpio_res->io = devm_ioremap(dev, params->start, size); in mlxbf_i2c_get_gpio()
1261 if (!gpio_res->io) { in mlxbf_i2c_get_gpio()
1262 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_get_gpio()
1263 return -ENOMEM; in mlxbf_i2c_get_gpio()
1273 struct device *dev = &pdev->dev; in mlxbf_i2c_release_gpio()
1280 mutex_lock(gpio_res->lock); in mlxbf_i2c_release_gpio()
1282 if (gpio_res->io) { in mlxbf_i2c_release_gpio()
1284 params = gpio_res->params; in mlxbf_i2c_release_gpio()
1285 devm_iounmap(dev, gpio_res->io); in mlxbf_i2c_release_gpio()
1286 devm_release_mem_region(dev, params->start, in mlxbf_i2c_release_gpio()
1290 mutex_unlock(gpio_res->lock); in mlxbf_i2c_release_gpio()
1299 struct device *dev = &pdev->dev; in mlxbf_i2c_get_corepll()
1306 return -EPERM; in mlxbf_i2c_get_corepll()
1313 lockdep_assert_held(corepll_res->lock); in mlxbf_i2c_get_corepll()
1316 if (corepll_res->io) in mlxbf_i2c_get_corepll()
1319 params = corepll_res->params; in mlxbf_i2c_get_corepll()
1322 if (!devm_request_mem_region(dev, params->start, size, params->name)) in mlxbf_i2c_get_corepll()
1323 return -EFAULT; in mlxbf_i2c_get_corepll()
1325 corepll_res->io = devm_ioremap(dev, params->start, size); in mlxbf_i2c_get_corepll()
1326 if (!corepll_res->io) { in mlxbf_i2c_get_corepll()
1327 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_get_corepll()
1328 return -ENOMEM; in mlxbf_i2c_get_corepll()
1338 struct device *dev = &pdev->dev; in mlxbf_i2c_release_corepll()
1344 mutex_lock(corepll_res->lock); in mlxbf_i2c_release_corepll()
1346 if (corepll_res->io) { in mlxbf_i2c_release_corepll()
1348 params = corepll_res->params; in mlxbf_i2c_release_corepll()
1349 devm_iounmap(dev, corepll_res->io); in mlxbf_i2c_release_corepll()
1350 devm_release_mem_region(dev, params->start, in mlxbf_i2c_release_corepll()
1354 mutex_unlock(corepll_res->lock); in mlxbf_i2c_release_corepll()
1363 struct device *dev = &pdev->dev; in mlxbf_i2c_init_master()
1373 return -EPERM; in mlxbf_i2c_init_master()
1381 mutex_lock(gpio_res->lock); in mlxbf_i2c_init_master()
1386 mutex_unlock(gpio_res->lock); in mlxbf_i2c_init_master()
1391 * TYU - Configuration for GPIO pins. Those pins must be asserted in in mlxbf_i2c_init_master()
1401 config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0); in mlxbf_i2c_init_master()
1402 config_reg = MLXBF_I2C_GPIO_SMBUS_GW_ASSERT_PINS(priv->bus, in mlxbf_i2c_init_master()
1404 writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0); in mlxbf_i2c_init_master()
1406 config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN); in mlxbf_i2c_init_master()
1407 config_reg = MLXBF_I2C_GPIO_SMBUS_GW_RESET_PINS(priv->bus, in mlxbf_i2c_init_master()
1409 writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN); in mlxbf_i2c_init_master()
1411 mutex_unlock(gpio_res->lock); in mlxbf_i2c_init_master()
1425 corepll_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1); in mlxbf_calculate_freq_from_tyu()
1427 /* Get Core PLL configuration bits. */ in mlxbf_calculate_freq_from_tyu()
1436 * Compute PLL output frequency as follow: in mlxbf_calculate_freq_from_tyu()
1439 * PLL_OUT_FREQ = PLL_IN_FREQ * ---------------------------- in mlxbf_calculate_freq_from_tyu()
1460 corepll_reg1_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1); in mlxbf_calculate_freq_from_yu()
1461 corepll_reg2_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG2); in mlxbf_calculate_freq_from_yu()
1463 /* Get Core PLL configuration bits */ in mlxbf_calculate_freq_from_yu()
1472 * Compute PLL output frequency as follow: in mlxbf_calculate_freq_from_yu()
1475 * PLL_OUT_FREQ = PLL_IN_FREQ * ---------------------------- in mlxbf_calculate_freq_from_yu()
1490 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_calculate_corepll_freq()
1492 struct device *dev = &pdev->dev; in mlxbf_i2c_calculate_corepll_freq()
1493 u64 *freq = &priv->frequency; in mlxbf_i2c_calculate_corepll_freq()
1499 return -EPERM; in mlxbf_i2c_calculate_corepll_freq()
1509 mutex_lock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1511 if (!chip->calculate_freq) { in mlxbf_i2c_calculate_corepll_freq()
1512 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1513 return -EPERM; in mlxbf_i2c_calculate_corepll_freq()
1519 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1523 mlxbf_i2c_corepll_frequency = chip->calculate_freq(corepll_res); in mlxbf_i2c_calculate_corepll_freq()
1525 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1542 return -EPERM; in mlxbf_slave_enable()
1548 * Read the slave registers. There are 4 * 32-bit slave registers. in mlxbf_slave_enable()
1549 * Each slave register can hold up to 4 * 8-bit slave configuration in mlxbf_slave_enable()
1550 * (7-bit address, 1 status bit (1 if enabled, 0 if not)). in mlxbf_slave_enable()
1553 slave_reg = readl(priv->smbus->io + in mlxbf_slave_enable()
1556 * Each register holds 4 slave addresses. So, we have to keep in mlxbf_slave_enable()
1566 * enabled bit should be unset. This slot might be used in mlxbf_slave_enable()
1578 * slave address already exists and it's enabled, in mlxbf_slave_enable()
1598 return -EINVAL; /* No room for a new slave address. */ in mlxbf_slave_enable()
1611 writel(slave_reg, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + in mlxbf_slave_enable()
1621 struct i2c_client *client = priv->slave; in mlxbf_slave_disable()
1626 addr = client->addr; in mlxbf_slave_disable()
1631 * Read the slave registers. There are 4 * 32-bit slave registers. in mlxbf_slave_disable()
1632 * Each slave register can hold up to 4 * 8-bit slave configuration in mlxbf_slave_disable()
1633 * (7-bit address, 1 status bit (1 if enabled, 0 if not)). in mlxbf_slave_disable()
1636 slave_reg = readl(priv->smbus->io + in mlxbf_slave_disable()
1644 * Each register holds 4 slave addresses. So, we have to keep in mlxbf_slave_disable()
1676 writel(slave_reg, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_ADDR_CFG + in mlxbf_slave_disable()
1691 * Unlike BlueField-1 platform, the coalesce registers is a dedicated in mlxbf_i2c_init_coalesce()
1698 return -EPERM; in mlxbf_i2c_init_coalesce()
1705 lockdep_assert_held(mlxbf_i2c_gpio_res->lock); in mlxbf_i2c_init_coalesce()
1708 if (coalesce_res->io) { in mlxbf_i2c_init_coalesce()
1709 priv->coalesce = coalesce_res; in mlxbf_i2c_init_coalesce()
1713 params = coalesce_res->params; in mlxbf_i2c_init_coalesce()
1716 if (!request_mem_region(params->start, size, params->name)) in mlxbf_i2c_init_coalesce()
1717 return -EFAULT; in mlxbf_i2c_init_coalesce()
1719 coalesce_res->io = ioremap(params->start, size); in mlxbf_i2c_init_coalesce()
1720 if (!coalesce_res->io) { in mlxbf_i2c_init_coalesce()
1721 release_mem_region(params->start, size); in mlxbf_i2c_init_coalesce()
1722 return -ENOMEM; in mlxbf_i2c_init_coalesce()
1725 priv->coalesce = coalesce_res; in mlxbf_i2c_init_coalesce()
1728 ret = mlxbf_i2c_init_resource(pdev, &priv->coalesce, in mlxbf_i2c_init_coalesce()
1739 struct device *dev = &pdev->dev; in mlxbf_i2c_release_coalesce()
1743 coalesce_res = priv->coalesce; in mlxbf_i2c_release_coalesce()
1745 if (coalesce_res->io) { in mlxbf_i2c_release_coalesce()
1746 params = coalesce_res->params; in mlxbf_i2c_release_coalesce()
1749 mutex_lock(coalesce_res->lock); in mlxbf_i2c_release_coalesce()
1750 iounmap(coalesce_res->io); in mlxbf_i2c_release_coalesce()
1751 release_mem_region(params->start, size); in mlxbf_i2c_release_coalesce()
1752 mutex_unlock(coalesce_res->lock); in mlxbf_i2c_release_coalesce()
1754 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_release_coalesce()
1764 struct device *dev = &pdev->dev; in mlxbf_i2c_init_slave()
1769 writel(0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_FSM); in mlxbf_i2c_init_slave()
1774 * MLXBF_I2C_CAUSE_WRITE_SUCCESS, these are enabled when an external in mlxbf_i2c_init_slave()
1778 writel(~0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_init_slave()
1781 writel(int_reg, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_EVTEN0); in mlxbf_i2c_init_slave()
1784 writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_i2c_init_slave()
1799 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_has_coalesce()
1806 slave_shift = chip->type != MLXBF_I2C_CHIP_TYPE_1 ? in mlxbf_i2c_has_coalesce()
1808 priv->bus + MLXBF_I2C_CAUSE_TYU_SLAVE_BIT; in mlxbf_i2c_has_coalesce()
1810 coalesce0_reg = readl(priv->coalesce->io + MLXBF_I2C_CAUSE_COALESCE_0); in mlxbf_i2c_has_coalesce()
1817 cause_reg = readl(priv->slv_cause->io + MLXBF_I2C_CAUSE_ARBITER); in mlxbf_i2c_has_coalesce()
1824 writel(~0x0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_has_coalesce()
1835 if (mlxbf_smbus_poll(priv->slv_cause->io, addr, mask, false, timeout)) in mlxbf_smbus_slave_wait_for_idle()
1846 struct i2c_client *slave = priv->slave; in mlxbf_smbus_irq_send()
1851 return -EINVAL; in mlxbf_smbus_irq_send()
1864 data32 = ioread32be(priv->smbus->io + in mlxbf_smbus_irq_send()
1877 if (slave->addr != addr) in mlxbf_smbus_irq_send()
1878 return -EINVAL; in mlxbf_smbus_irq_send()
1917 write_size = (byte_cnt - 1) & 0x7f; in mlxbf_smbus_irq_send()
1930 writel(control32, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_GW); in mlxbf_smbus_irq_send()
1939 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES); in mlxbf_smbus_irq_send()
1940 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_PEC); in mlxbf_smbus_irq_send()
1941 writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_smbus_irq_send()
1950 struct i2c_client *slave = priv->slave; in mlxbf_smbus_irq_recv()
1955 return -EINVAL; in mlxbf_smbus_irq_recv()
1963 if (slave->addr != addr) in mlxbf_smbus_irq_recv()
1964 return -EINVAL; in mlxbf_smbus_irq_recv()
1986 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES); in mlxbf_smbus_irq_recv()
1987 writel(0x0, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_PEC); in mlxbf_smbus_irq_recv()
1988 writel(0x1, priv->smbus->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_smbus_irq_recv()
2004 * - Receive data and send response to master. in mlxbf_smbus_irq()
2005 * - Send data and release slave GW. in mlxbf_smbus_irq()
2018 * bytes from/to master. These are defined by 8-bits each. If the lower in mlxbf_smbus_irq()
2023 rw_bytes_reg = readl(priv->smbus->io + in mlxbf_smbus_irq()
2067 dev_dbg(&adap->dev, "smbus quick, slave 0x%02x\n", addr); in mlxbf_i2c_smbus_xfer()
2072 read ? &data->byte : &command, read, in mlxbf_i2c_smbus_xfer()
2074 dev_dbg(&adap->dev, "smbus %s byte, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2079 mlxbf_i2c_smbus_data_byte_func(&request, &command, &data->byte, in mlxbf_i2c_smbus_xfer()
2081 dev_dbg(&adap->dev, "smbus %s byte data at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2087 (u8 *)&data->word, read, pec); in mlxbf_i2c_smbus_xfer()
2088 dev_dbg(&adap->dev, "smbus %s word data at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2093 byte_cnt = data->block[0]; in mlxbf_i2c_smbus_xfer()
2094 mlxbf_i2c_smbus_i2c_block_func(&request, &command, data->block, in mlxbf_i2c_smbus_xfer()
2096 dev_dbg(&adap->dev, "i2c %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2101 byte_cnt = read ? I2C_SMBUS_BLOCK_MAX : data->block[0]; in mlxbf_i2c_smbus_xfer()
2102 mlxbf_i2c_smbus_block_func(&request, &command, data->block, in mlxbf_i2c_smbus_xfer()
2104 dev_dbg(&adap->dev, "smbus %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2110 (u8 *)&data->word, pec); in mlxbf_i2c_smbus_xfer()
2111 dev_dbg(&adap->dev, "process call, wr/rd at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2116 byte_cnt = data->block[0]; in mlxbf_i2c_smbus_xfer()
2118 data->block, &byte_cnt, in mlxbf_i2c_smbus_xfer()
2120 dev_dbg(&adap->dev, "block process call, wr/rd %d bytes, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2125 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command %d\n", in mlxbf_i2c_smbus_xfer()
2127 return -EOPNOTSUPP; in mlxbf_i2c_smbus_xfer()
2137 struct mlxbf_i2c_priv *priv = i2c_get_adapdata(slave->adapter); in mlxbf_i2c_reg_slave()
2140 if (priv->slave) in mlxbf_i2c_reg_slave()
2141 return -EBUSY; in mlxbf_i2c_reg_slave()
2147 if (slave->flags & (I2C_CLIENT_TEN | I2C_CLIENT_PEC)) in mlxbf_i2c_reg_slave()
2148 return -EAFNOSUPPORT; in mlxbf_i2c_reg_slave()
2150 ret = mlxbf_slave_enable(priv, slave->addr); in mlxbf_i2c_reg_slave()
2154 priv->slave = slave; in mlxbf_i2c_reg_slave()
2161 struct mlxbf_i2c_priv *priv = i2c_get_adapdata(slave->adapter); in mlxbf_i2c_unreg_slave()
2164 WARN_ON(!priv->slave); in mlxbf_i2c_unreg_slave()
2171 priv->slave = NULL; in mlxbf_i2c_unreg_slave()
2214 .compatible = "mellanox,i2c-mlxbf1",
2218 .compatible = "mellanox,i2c-mlxbf2",
2244 return -ENOENT; in mlxbf_i2c_acpi_probe()
2248 return -ENXIO; in mlxbf_i2c_acpi_probe()
2252 return -ENODEV; in mlxbf_i2c_acpi_probe()
2254 priv->chip = (struct mlxbf_i2c_chip_info *)aid->driver_data; in mlxbf_i2c_acpi_probe()
2259 return -ENODEV; in mlxbf_i2c_acpi_probe()
2264 priv->bus = bus_id; in mlxbf_i2c_acpi_probe()
2271 return -ENOENT; in mlxbf_i2c_acpi_probe()
2278 int bus_id = -1; in mlxbf_i2c_of_probe()
2280 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in mlxbf_i2c_of_probe()
2281 oid = of_match_node(mlxbf_i2c_dt_ids, dev->of_node); in mlxbf_i2c_of_probe()
2283 return -ENODEV; in mlxbf_i2c_of_probe()
2285 priv->chip = oid->data; in mlxbf_i2c_of_probe()
2287 bus_id = of_alias_get_id(dev->of_node, "i2c"); in mlxbf_i2c_of_probe()
2289 priv->bus = bus_id; in mlxbf_i2c_of_probe()
2302 struct device *dev = &pdev->dev; in mlxbf_i2c_probe()
2309 return -ENOMEM; in mlxbf_i2c_probe()
2312 if (ret < 0 && ret != -ENOENT && ret != -ENXIO) in mlxbf_i2c_probe()
2318 ret = mlxbf_i2c_init_resource(pdev, &priv->smbus, in mlxbf_i2c_probe()
2325 ret = mlxbf_i2c_init_resource(pdev, &priv->mst_cause, in mlxbf_i2c_probe()
2332 ret = mlxbf_i2c_init_resource(pdev, &priv->slv_cause, in mlxbf_i2c_probe()
2339 adap = &priv->adap; in mlxbf_i2c_probe()
2340 adap->owner = THIS_MODULE; in mlxbf_i2c_probe()
2341 adap->class = I2C_CLASS_HWMON; in mlxbf_i2c_probe()
2342 adap->algo = &mlxbf_i2c_algo; in mlxbf_i2c_probe()
2343 adap->quirks = &mlxbf_i2c_quirks; in mlxbf_i2c_probe()
2344 adap->dev.parent = dev; in mlxbf_i2c_probe()
2345 adap->dev.of_node = dev->of_node; in mlxbf_i2c_probe()
2346 adap->nr = priv->bus; in mlxbf_i2c_probe()
2348 snprintf(adap->name, sizeof(adap->name), "i2c%d", adap->nr); in mlxbf_i2c_probe()
2351 /* Read Core PLL frequency. */ in mlxbf_i2c_probe()
2356 priv->frequency = MLXBF_I2C_COREPLL_FREQ; in mlxbf_i2c_probe()
2365 * does not really hurt, then keep the code as is. in mlxbf_i2c_probe()
2370 priv->bus); in mlxbf_i2c_probe()
2389 priv->irq = irq; in mlxbf_i2c_probe()
2407 struct device *dev = &pdev->dev; in mlxbf_i2c_remove()
2410 params = priv->smbus->params; in mlxbf_i2c_remove()
2411 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2413 params = priv->mst_cause->params; in mlxbf_i2c_remove()
2414 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2416 params = priv->slv_cause->params; in mlxbf_i2c_remove()
2417 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2424 if (--mlxbf_i2c_bus_count == 0) { in mlxbf_i2c_remove()
2431 devm_free_irq(dev, priv->irq, priv); in mlxbf_i2c_remove()
2433 i2c_del_adapter(&priv->adap); in mlxbf_i2c_remove()
2442 .name = "i2c-mlxbf",