Lines Matching +full:keep +full:- +full:pll +full:- +full:enabled
1 // SPDX-License-Identifier: GPL-2.0
57 * Note that the following SMBus, CAUSE, GPIO and PLL register addresses
59 * memory-mapped region whose addresses are specified in either the DT or
69 /* Reference clock for Bluefield - 156 MHz. */
72 /* Constant used to determine the PLL frequency. */
77 /* PLL registers. */
90 * as interrupt enabled bits.
127 * as interrupt enabled bits.
151 * SMBUS GW0 -> bits[26:25]
152 * SMBUS GW1 -> bits[28:27]
153 * SMBUS GW2 -> bits[30:29]
171 * frequency based on PLL parameters.
175 /* Core PLL TYU configuration. */
180 /* Core PLL YU configuration. */
248 #define MLXBF_I2C_MASTER_DATA_W_LENGTH (MLXBF_I2C_MASTER_DATA_DESC_SIZE - 1)
324 .end = (addr) + (size) - 1, \
347 MLXBF_I2C_CHIP_TYPE_1, /* Mellanox BlueField-1 chip. */
348 MLXBF_I2C_CHIP_TYPE_2, /* Mellanox BlueField-2 chip. */
349 MLXBF_I2C_CHIP_TYPE_3 /* Mellanox BlueField-3 chip. */
409 /* Callback to calculate the core PLL frequency. */
434 /* Core PLL frequency. */
509 * de-asserted then the SMBus expects the following GW configuration in mlxbf_i2c_smbus_transaction_success()
525 * or some positive number indicating a non-fault return.
540 readl_poll_timeout_atomic(priv->mst->io + MLXBF_I2C_SMBUS_MASTER_GW, in mlxbf_i2c_smbus_check_status()
545 cause_status_bits = readl(priv->mst_cause->io + in mlxbf_i2c_smbus_check_status()
553 master_status_bits = readl(priv->mst->io + in mlxbf_i2c_smbus_check_status()
569 return -EIO; in mlxbf_i2c_smbus_check_status()
572 return -EAGAIN; in mlxbf_i2c_smbus_check_status()
574 return -ETIMEDOUT; in mlxbf_i2c_smbus_check_status()
587 * Copy data bytes from 4-byte aligned source buffer. in mlxbf_i2c_smbus_write_data()
591 * when writing data bytes to the 32 * 32-bit HW Data registers in mlxbf_i2c_smbus_write_data()
597 iowrite32be(data32, priv->mst->io + addr + offset); in mlxbf_i2c_smbus_write_data()
599 iowrite32be(data32, priv->slv->io + addr + offset); in mlxbf_i2c_smbus_write_data()
610 mask = sizeof(u32) - 1; in mlxbf_i2c_smbus_read_data()
616 * reading data bytes from the 32 * 32-bit HW Data registers in mlxbf_i2c_smbus_read_data()
622 data32 = ioread32be(priv->mst->io + addr + offset); in mlxbf_i2c_smbus_read_data()
624 data32 = ioread32be(priv->slv->io + addr + offset); in mlxbf_i2c_smbus_read_data()
632 data32 = ioread32be(priv->mst->io + addr + offset); in mlxbf_i2c_smbus_read_data()
634 data32 = ioread32be(priv->slv->io + addr + offset); in mlxbf_i2c_smbus_read_data()
663 writel(0x0, priv->mst->io + MLXBF_I2C_SMBUS_MASTER_STATUS); in mlxbf_i2c_smbus_enable()
665 writel(~0x0, priv->mst_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_smbus_enable()
667 writel(0x0, priv->mst->io + MLXBF_I2C_SMBUS_MASTER_PEC); in mlxbf_i2c_smbus_enable()
669 writel(0x0, priv->mst->io + priv->chip->smbus_master_rs_bytes_off); in mlxbf_i2c_smbus_enable()
672 writel(command, priv->mst->io + MLXBF_I2C_SMBUS_MASTER_GW); in mlxbf_i2c_smbus_enable()
697 if (request->operation_cnt > MLXBF_I2C_SMBUS_MAX_OP_CNT) in mlxbf_i2c_smbus_start_transaction()
698 return -EINVAL; in mlxbf_i2c_smbus_start_transaction()
708 slave = request->slave & GENMASK(6, 0); in mlxbf_i2c_smbus_start_transaction()
715 ret = readl_poll_timeout_atomic(priv->mst->io + MLXBF_I2C_SMBUS_MASTER_GW, in mlxbf_i2c_smbus_start_transaction()
720 return -EBUSY; in mlxbf_i2c_smbus_start_transaction()
725 * it returns -ETIMEDOUT when the bit is asserted, 0 if not. in mlxbf_i2c_smbus_start_transaction()
727 ret = readl_poll_timeout_atomic(priv->mst->io + priv->chip->smbus_master_fsm_off, in mlxbf_i2c_smbus_start_transaction()
731 ret = -EBUSY; in mlxbf_i2c_smbus_start_transaction()
738 for (op_idx = 0; op_idx < request->operation_cnt; op_idx++) { in mlxbf_i2c_smbus_start_transaction()
739 operation = &request->operation[op_idx]; in mlxbf_i2c_smbus_start_transaction()
740 flags = operation->flags; in mlxbf_i2c_smbus_start_transaction()
756 write_len += operation->length; in mlxbf_i2c_smbus_start_transaction()
757 if (data_idx + operation->length > in mlxbf_i2c_smbus_start_transaction()
759 ret = -ENOBUFS; in mlxbf_i2c_smbus_start_transaction()
763 operation->buffer, operation->length); in mlxbf_i2c_smbus_start_transaction()
764 data_idx += operation->length; in mlxbf_i2c_smbus_start_transaction()
784 read_len = operation->length - 1; in mlxbf_i2c_smbus_start_transaction()
785 read_buf = operation->buffer; in mlxbf_i2c_smbus_start_transaction()
826 priv->mst->io + priv->chip->smbus_master_fsm_off); in mlxbf_i2c_smbus_start_transaction()
831 writel(0, priv->mst->io + MLXBF_I2C_SMBUS_MASTER_GW); in mlxbf_i2c_smbus_start_transaction()
842 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_1; in mlxbf_i2c_smbus_quick_command()
844 request->operation[0].length = 0; in mlxbf_i2c_smbus_quick_command()
845 request->operation[0].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_quick_command()
846 request->operation[0].flags |= read ? MLXBF_I2C_F_READ : 0; in mlxbf_i2c_smbus_quick_command()
852 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_1; in mlxbf_i2c_smbus_byte_func()
854 request->operation[0].length = 1; in mlxbf_i2c_smbus_byte_func()
855 request->operation[0].length += pec_check; in mlxbf_i2c_smbus_byte_func()
857 request->operation[0].flags = MLXBF_I2C_F_SMBUS_OPERATION; in mlxbf_i2c_smbus_byte_func()
858 request->operation[0].flags |= read ? in mlxbf_i2c_smbus_byte_func()
860 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_byte_func()
862 request->operation[0].buffer = data; in mlxbf_i2c_smbus_byte_func()
869 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_data_byte_func()
871 request->operation[0].length = 1; in mlxbf_i2c_smbus_data_byte_func()
872 request->operation[0].flags = in mlxbf_i2c_smbus_data_byte_func()
874 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_data_byte_func()
875 request->operation[0].buffer = command; in mlxbf_i2c_smbus_data_byte_func()
877 request->operation[1].length = 1; in mlxbf_i2c_smbus_data_byte_func()
878 request->operation[1].length += pec_check; in mlxbf_i2c_smbus_data_byte_func()
879 request->operation[1].flags = read ? in mlxbf_i2c_smbus_data_byte_func()
881 request->operation[1].buffer = data; in mlxbf_i2c_smbus_data_byte_func()
888 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_data_word_func()
890 request->operation[0].length = 1; in mlxbf_i2c_smbus_data_word_func()
891 request->operation[0].flags = in mlxbf_i2c_smbus_data_word_func()
893 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_data_word_func()
894 request->operation[0].buffer = command; in mlxbf_i2c_smbus_data_word_func()
896 request->operation[1].length = 2; in mlxbf_i2c_smbus_data_word_func()
897 request->operation[1].length += pec_check; in mlxbf_i2c_smbus_data_word_func()
898 request->operation[1].flags = read ? in mlxbf_i2c_smbus_data_word_func()
900 request->operation[1].buffer = data; in mlxbf_i2c_smbus_data_word_func()
908 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_i2c_block_func()
910 request->operation[0].length = 1; in mlxbf_i2c_smbus_i2c_block_func()
911 request->operation[0].flags = in mlxbf_i2c_smbus_i2c_block_func()
913 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_i2c_block_func()
914 request->operation[0].buffer = command; in mlxbf_i2c_smbus_i2c_block_func()
917 request->operation[0].flags |= MLXBF_I2C_F_WRITE_WITHOUT_STOP; in mlxbf_i2c_smbus_i2c_block_func()
924 request->operation[1].length = in mlxbf_i2c_smbus_i2c_block_func()
927 request->operation[1].flags = read ? in mlxbf_i2c_smbus_i2c_block_func()
933 request->operation[1].buffer = data + 1; in mlxbf_i2c_smbus_i2c_block_func()
935 *data_len = request->operation[1].length; in mlxbf_i2c_smbus_i2c_block_func()
946 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_2; in mlxbf_i2c_smbus_block_func()
948 request->operation[0].length = 1; in mlxbf_i2c_smbus_block_func()
949 request->operation[0].flags = in mlxbf_i2c_smbus_block_func()
951 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_block_func()
952 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_block_func()
953 request->operation[0].buffer = command; in mlxbf_i2c_smbus_block_func()
955 request->operation[1].length = in mlxbf_i2c_smbus_block_func()
958 request->operation[1].flags = read ? in mlxbf_i2c_smbus_block_func()
960 request->operation[1].buffer = data + 1; in mlxbf_i2c_smbus_block_func()
962 *data_len = request->operation[1].length; in mlxbf_i2c_smbus_block_func()
973 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_3; in mlxbf_i2c_smbus_process_call_func()
975 request->operation[0].length = 1; in mlxbf_i2c_smbus_process_call_func()
976 request->operation[0].flags = in mlxbf_i2c_smbus_process_call_func()
978 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_process_call_func()
979 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_process_call_func()
980 request->operation[0].buffer = command; in mlxbf_i2c_smbus_process_call_func()
982 request->operation[1].length = 2; in mlxbf_i2c_smbus_process_call_func()
983 request->operation[1].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_process_call_func()
984 request->operation[1].buffer = data; in mlxbf_i2c_smbus_process_call_func()
986 request->operation[2].length = 3; in mlxbf_i2c_smbus_process_call_func()
987 request->operation[2].flags = MLXBF_I2C_F_READ; in mlxbf_i2c_smbus_process_call_func()
988 request->operation[2].buffer = data; in mlxbf_i2c_smbus_process_call_func()
998 request->operation_cnt = MLXBF_I2C_SMBUS_OP_CNT_3; in mlxbf_i2c_smbus_blk_process_call_func()
1000 request->operation[0].length = 1; in mlxbf_i2c_smbus_blk_process_call_func()
1001 request->operation[0].flags = in mlxbf_i2c_smbus_blk_process_call_func()
1003 request->operation[0].flags |= MLXBF_I2C_F_SMBUS_BLOCK; in mlxbf_i2c_smbus_blk_process_call_func()
1004 request->operation[0].flags |= (pec_check) ? MLXBF_I2C_F_SMBUS_PEC : 0; in mlxbf_i2c_smbus_blk_process_call_func()
1005 request->operation[0].buffer = command; in mlxbf_i2c_smbus_blk_process_call_func()
1010 request->operation[1].length = length - pec_check; in mlxbf_i2c_smbus_blk_process_call_func()
1011 request->operation[1].flags = MLXBF_I2C_F_WRITE; in mlxbf_i2c_smbus_blk_process_call_func()
1012 request->operation[1].buffer = data; in mlxbf_i2c_smbus_blk_process_call_func()
1014 request->operation[2].length = length; in mlxbf_i2c_smbus_blk_process_call_func()
1015 request->operation[2].flags = MLXBF_I2C_F_READ; in mlxbf_i2c_smbus_blk_process_call_func()
1016 request->operation[2].buffer = data; in mlxbf_i2c_smbus_blk_process_call_func()
1025 return priv->chip->type == type; in mlxbf_i2c_has_chip_type()
1031 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_get_shared_resource()
1036 res = chip->shared_res[res_idx]; in mlxbf_i2c_get_shared_resource()
1037 if (res && res->type == type) in mlxbf_i2c_get_shared_resource()
1049 struct device *dev = &pdev->dev; in mlxbf_i2c_init_resource()
1052 return -EINVAL; in mlxbf_i2c_init_resource()
1057 return -ENOMEM; in mlxbf_i2c_init_resource()
1059 tmp_res->io = devm_platform_get_and_ioremap_resource(pdev, type, &tmp_res->params); in mlxbf_i2c_init_resource()
1060 if (IS_ERR(tmp_res->io)) { in mlxbf_i2c_init_resource()
1062 return PTR_ERR(tmp_res->io); in mlxbf_i2c_init_resource()
1065 tmp_res->type = type; in mlxbf_i2c_init_resource()
1082 * Time = --------- x 10^9 => Ticks = Time x Frequency x 10^-9 in mlxbf_i2c_get_ticks()
1085 frequency = priv->frequency; in mlxbf_i2c_get_ticks()
1110 timer = mlxbf_i2c_set_timer(priv, timings->scl_high, in mlxbf_i2c_set_timings()
1113 timer |= mlxbf_i2c_set_timer(priv, timings->scl_low, in mlxbf_i2c_set_timings()
1116 writel(timer, priv->timer->io + in mlxbf_i2c_set_timings()
1119 timer = mlxbf_i2c_set_timer(priv, timings->sda_rise, false, in mlxbf_i2c_set_timings()
1121 timer |= mlxbf_i2c_set_timer(priv, timings->sda_fall, false, in mlxbf_i2c_set_timings()
1123 timer |= mlxbf_i2c_set_timer(priv, timings->scl_rise, false, in mlxbf_i2c_set_timings()
1125 timer |= mlxbf_i2c_set_timer(priv, timings->scl_fall, false, in mlxbf_i2c_set_timings()
1127 writel(timer, priv->timer->io + in mlxbf_i2c_set_timings()
1130 timer = mlxbf_i2c_set_timer(priv, timings->hold_start, true, in mlxbf_i2c_set_timings()
1132 timer |= mlxbf_i2c_set_timer(priv, timings->hold_data, true, in mlxbf_i2c_set_timings()
1134 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_TIMER_THOLD); in mlxbf_i2c_set_timings()
1136 timer = mlxbf_i2c_set_timer(priv, timings->setup_start, true, in mlxbf_i2c_set_timings()
1138 timer |= mlxbf_i2c_set_timer(priv, timings->setup_stop, true, in mlxbf_i2c_set_timings()
1140 writel(timer, priv->timer->io + in mlxbf_i2c_set_timings()
1143 timer = mlxbf_i2c_set_timer(priv, timings->setup_data, true, in mlxbf_i2c_set_timings()
1145 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_TIMER_TSETUP_DATA); in mlxbf_i2c_set_timings()
1147 timer = mlxbf_i2c_set_timer(priv, timings->buf, false, in mlxbf_i2c_set_timings()
1149 timer |= mlxbf_i2c_set_timer(priv, timings->thigh_max, false, in mlxbf_i2c_set_timings()
1151 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_THIGH_MAX_TBUF); in mlxbf_i2c_set_timings()
1153 timer = mlxbf_i2c_set_timer(priv, timings->timeout, false, in mlxbf_i2c_set_timings()
1155 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_SCL_LOW_TIMEOUT); in mlxbf_i2c_set_timings()
1220 struct device *dev = &pdev->dev; in mlxbf_i2c_init_timings()
1225 ret = device_property_read_u32(dev, "clock-frequency", &config_khz); in mlxbf_i2c_init_timings()
1257 struct device *dev = &pdev->dev; in mlxbf_i2c_get_gpio()
1263 return -EPERM; in mlxbf_i2c_get_gpio()
1270 lockdep_assert_held(gpio_res->lock); in mlxbf_i2c_get_gpio()
1273 if (gpio_res->io) in mlxbf_i2c_get_gpio()
1276 params = gpio_res->params; in mlxbf_i2c_get_gpio()
1279 if (!devm_request_mem_region(dev, params->start, size, params->name)) in mlxbf_i2c_get_gpio()
1280 return -EFAULT; in mlxbf_i2c_get_gpio()
1282 gpio_res->io = devm_ioremap(dev, params->start, size); in mlxbf_i2c_get_gpio()
1283 if (!gpio_res->io) { in mlxbf_i2c_get_gpio()
1284 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_get_gpio()
1285 return -ENOMEM; in mlxbf_i2c_get_gpio()
1295 struct device *dev = &pdev->dev; in mlxbf_i2c_release_gpio()
1302 mutex_lock(gpio_res->lock); in mlxbf_i2c_release_gpio()
1304 if (gpio_res->io) { in mlxbf_i2c_release_gpio()
1306 params = gpio_res->params; in mlxbf_i2c_release_gpio()
1307 devm_iounmap(dev, gpio_res->io); in mlxbf_i2c_release_gpio()
1308 devm_release_mem_region(dev, params->start, in mlxbf_i2c_release_gpio()
1312 mutex_unlock(gpio_res->lock); in mlxbf_i2c_release_gpio()
1321 struct device *dev = &pdev->dev; in mlxbf_i2c_get_corepll()
1328 return -EPERM; in mlxbf_i2c_get_corepll()
1335 lockdep_assert_held(corepll_res->lock); in mlxbf_i2c_get_corepll()
1338 if (corepll_res->io) in mlxbf_i2c_get_corepll()
1341 params = corepll_res->params; in mlxbf_i2c_get_corepll()
1344 if (!devm_request_mem_region(dev, params->start, size, params->name)) in mlxbf_i2c_get_corepll()
1345 return -EFAULT; in mlxbf_i2c_get_corepll()
1347 corepll_res->io = devm_ioremap(dev, params->start, size); in mlxbf_i2c_get_corepll()
1348 if (!corepll_res->io) { in mlxbf_i2c_get_corepll()
1349 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_get_corepll()
1350 return -ENOMEM; in mlxbf_i2c_get_corepll()
1360 struct device *dev = &pdev->dev; in mlxbf_i2c_release_corepll()
1366 mutex_lock(corepll_res->lock); in mlxbf_i2c_release_corepll()
1368 if (corepll_res->io) { in mlxbf_i2c_release_corepll()
1370 params = corepll_res->params; in mlxbf_i2c_release_corepll()
1371 devm_iounmap(dev, corepll_res->io); in mlxbf_i2c_release_corepll()
1372 devm_release_mem_region(dev, params->start, in mlxbf_i2c_release_corepll()
1376 mutex_unlock(corepll_res->lock); in mlxbf_i2c_release_corepll()
1385 struct device *dev = &pdev->dev; in mlxbf_i2c_init_master()
1395 return -EPERM; in mlxbf_i2c_init_master()
1403 mutex_lock(gpio_res->lock); in mlxbf_i2c_init_master()
1408 mutex_unlock(gpio_res->lock); in mlxbf_i2c_init_master()
1413 * TYU - Configuration for GPIO pins. Those pins must be asserted in in mlxbf_i2c_init_master()
1423 config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0); in mlxbf_i2c_init_master()
1424 config_reg = MLXBF_I2C_GPIO_SMBUS_GW_ASSERT_PINS(priv->bus, in mlxbf_i2c_init_master()
1426 writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FUNC_EN_0); in mlxbf_i2c_init_master()
1428 config_reg = readl(gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN); in mlxbf_i2c_init_master()
1429 config_reg = MLXBF_I2C_GPIO_SMBUS_GW_RESET_PINS(priv->bus, in mlxbf_i2c_init_master()
1431 writel(config_reg, gpio_res->io + MLXBF_I2C_GPIO_0_FORCE_OE_EN); in mlxbf_i2c_init_master()
1433 mutex_unlock(gpio_res->lock); in mlxbf_i2c_init_master()
1445 corepll_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1); in mlxbf_i2c_calculate_freq_from_tyu()
1447 /* Get Core PLL configuration bits. */ in mlxbf_i2c_calculate_freq_from_tyu()
1453 * Compute PLL output frequency as follow: in mlxbf_i2c_calculate_freq_from_tyu()
1456 * PLL_OUT_FREQ = PLL_IN_FREQ * ---------------------------- in mlxbf_i2c_calculate_freq_from_tyu()
1474 corepll_reg1_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG1); in mlxbf_i2c_calculate_freq_from_yu()
1475 corepll_reg2_val = readl(corepll_res->io + MLXBF_I2C_CORE_PLL_REG2); in mlxbf_i2c_calculate_freq_from_yu()
1477 /* Get Core PLL configuration bits */ in mlxbf_i2c_calculate_freq_from_yu()
1483 * Compute PLL output frequency as follow: in mlxbf_i2c_calculate_freq_from_yu()
1486 * PLL_OUT_FREQ = PLL_IN_FREQ * ---------------------------- in mlxbf_i2c_calculate_freq_from_yu()
1500 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_calculate_corepll_freq()
1502 struct device *dev = &pdev->dev; in mlxbf_i2c_calculate_corepll_freq()
1503 u64 *freq = &priv->frequency; in mlxbf_i2c_calculate_corepll_freq()
1509 return -EPERM; in mlxbf_i2c_calculate_corepll_freq()
1519 mutex_lock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1521 if (!chip->calculate_freq) { in mlxbf_i2c_calculate_corepll_freq()
1522 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1523 return -EPERM; in mlxbf_i2c_calculate_corepll_freq()
1529 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1533 mlxbf_i2c_corepll_frequency = chip->calculate_freq(corepll_res); in mlxbf_i2c_calculate_corepll_freq()
1535 mutex_unlock(corepll_res->lock); in mlxbf_i2c_calculate_corepll_freq()
1549 return -EPERM; in mlxbf_i2c_slave_enable()
1554 * Read the slave registers. There are 4 * 32-bit slave registers. in mlxbf_i2c_slave_enable()
1555 * Each slave register can hold up to 4 * 8-bit slave configuration: in mlxbf_i2c_slave_enable()
1556 * 1) A 7-bit address in mlxbf_i2c_slave_enable()
1557 * 2) And a status bit (1 if enabled, 0 if not). in mlxbf_i2c_slave_enable()
1561 slave_reg = readl(priv->slv->io + in mlxbf_i2c_slave_enable()
1564 * Each register holds 4 slave addresses. So, we have to keep in mlxbf_i2c_slave_enable()
1581 slave_reg |= (slave->addr << (byte * 8)); in mlxbf_i2c_slave_enable()
1583 writel(slave_reg, priv->slv->io + in mlxbf_i2c_slave_enable()
1590 priv->slave[(reg * 4) + byte] = slave; in mlxbf_i2c_slave_enable()
1600 return -EBUSY; in mlxbf_i2c_slave_enable()
1611 * Read the slave registers. There are 4 * 32-bit slave registers. in mlxbf_i2c_slave_disable()
1612 * Each slave register can hold up to 4 * 8-bit slave configuration: in mlxbf_i2c_slave_disable()
1613 * 1) A 7-bit address in mlxbf_i2c_slave_disable()
1614 * 2) And a status bit (1 if enabled, 0 if not). in mlxbf_i2c_slave_disable()
1618 slave_reg = readl(priv->slv->io + in mlxbf_i2c_slave_disable()
1639 writel(slave_reg, priv->slv->io + in mlxbf_i2c_slave_disable()
1643 priv->slave[(reg * 4) + byte] = NULL; in mlxbf_i2c_slave_disable()
1653 return -ENXIO; in mlxbf_i2c_slave_disable()
1665 * Unlike BlueField-1 platform, the coalesce registers is a dedicated in mlxbf_i2c_init_coalesce()
1672 return -EPERM; in mlxbf_i2c_init_coalesce()
1679 lockdep_assert_held(mlxbf_i2c_gpio_res->lock); in mlxbf_i2c_init_coalesce()
1682 if (coalesce_res->io) { in mlxbf_i2c_init_coalesce()
1683 priv->coalesce = coalesce_res; in mlxbf_i2c_init_coalesce()
1687 params = coalesce_res->params; in mlxbf_i2c_init_coalesce()
1690 if (!request_mem_region(params->start, size, params->name)) in mlxbf_i2c_init_coalesce()
1691 return -EFAULT; in mlxbf_i2c_init_coalesce()
1693 coalesce_res->io = ioremap(params->start, size); in mlxbf_i2c_init_coalesce()
1694 if (!coalesce_res->io) { in mlxbf_i2c_init_coalesce()
1695 release_mem_region(params->start, size); in mlxbf_i2c_init_coalesce()
1696 return -ENOMEM; in mlxbf_i2c_init_coalesce()
1699 priv->coalesce = coalesce_res; in mlxbf_i2c_init_coalesce()
1702 ret = mlxbf_i2c_init_resource(pdev, &priv->coalesce, in mlxbf_i2c_init_coalesce()
1713 struct device *dev = &pdev->dev; in mlxbf_i2c_release_coalesce()
1717 coalesce_res = priv->coalesce; in mlxbf_i2c_release_coalesce()
1719 if (coalesce_res->io) { in mlxbf_i2c_release_coalesce()
1720 params = coalesce_res->params; in mlxbf_i2c_release_coalesce()
1723 mutex_lock(coalesce_res->lock); in mlxbf_i2c_release_coalesce()
1724 iounmap(coalesce_res->io); in mlxbf_i2c_release_coalesce()
1725 release_mem_region(params->start, size); in mlxbf_i2c_release_coalesce()
1726 mutex_unlock(coalesce_res->lock); in mlxbf_i2c_release_coalesce()
1728 devm_release_mem_region(dev, params->start, size); in mlxbf_i2c_release_coalesce()
1738 struct device *dev = &pdev->dev; in mlxbf_i2c_init_slave()
1743 writel(0, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_FSM); in mlxbf_i2c_init_slave()
1748 * MLXBF_I2C_CAUSE_WRITE_SUCCESS, these are enabled when an external in mlxbf_i2c_init_slave()
1752 writel(~0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_init_slave()
1755 writel(int_reg, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_EVTEN0); in mlxbf_i2c_init_slave()
1758 writel(0x1, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_i2c_init_slave()
1773 const struct mlxbf_i2c_chip_info *chip = priv->chip; in mlxbf_i2c_has_coalesce()
1780 slave_shift = chip->type != MLXBF_I2C_CHIP_TYPE_1 ? in mlxbf_i2c_has_coalesce()
1782 priv->bus + MLXBF_I2C_CAUSE_TYU_SLAVE_BIT; in mlxbf_i2c_has_coalesce()
1784 coalesce0_reg = readl(priv->coalesce->io + MLXBF_I2C_CAUSE_COALESCE_0); in mlxbf_i2c_has_coalesce()
1791 cause_reg = readl(priv->slv_cause->io + MLXBF_I2C_CAUSE_ARBITER); in mlxbf_i2c_has_coalesce()
1798 writel(~0x0, priv->slv_cause->io + MLXBF_I2C_CAUSE_OR_CLEAR); in mlxbf_i2c_has_coalesce()
1809 if (!priv->slave[i]) in mlxbf_i2c_get_slave_from_addr()
1812 if (priv->slave[i]->addr == addr) in mlxbf_i2c_get_slave_from_addr()
1813 return priv->slave[i]; in mlxbf_i2c_get_slave_from_addr()
1836 data32 = ioread32be(priv->slv->io + in mlxbf_i2c_irq_send()
1847 ret = -ENXIO; in mlxbf_i2c_irq_send()
1886 write_size = (byte_cnt - 1) & 0x7f; in mlxbf_i2c_irq_send()
1899 writel(control32, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_GW); in mlxbf_i2c_irq_send()
1905 readl_poll_timeout_atomic(priv->slv_cause->io + MLXBF_I2C_CAUSE_ARBITER, in mlxbf_i2c_irq_send()
1911 writel(0x0, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES); in mlxbf_i2c_irq_send()
1912 writel(0x0, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_PEC); in mlxbf_i2c_irq_send()
1913 writel(0x1, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_i2c_irq_send()
1940 ret = -EINVAL; in mlxbf_i2c_irq_recv()
1967 writel(0x0, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_RS_MASTER_BYTES); in mlxbf_i2c_irq_recv()
1968 writel(0x0, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_PEC); in mlxbf_i2c_irq_recv()
1969 writel(0x1, priv->slv->io + MLXBF_I2C_SMBUS_SLAVE_READY); in mlxbf_i2c_irq_recv()
1985 * - Receive data and send response to master. in mlxbf_i2c_irq()
1986 * - Send data and release slave GW. in mlxbf_i2c_irq()
1999 * bytes from/to master. These are defined by 8-bits each. If the lower in mlxbf_i2c_irq()
2004 rw_bytes_reg = readl(priv->slv->io + in mlxbf_i2c_irq()
2048 dev_dbg(&adap->dev, "smbus quick, slave 0x%02x\n", addr); in mlxbf_i2c_smbus_xfer()
2053 read ? &data->byte : &command, read, in mlxbf_i2c_smbus_xfer()
2055 dev_dbg(&adap->dev, "smbus %s byte, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2060 mlxbf_i2c_smbus_data_byte_func(&request, &command, &data->byte, in mlxbf_i2c_smbus_xfer()
2062 dev_dbg(&adap->dev, "smbus %s byte data at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2068 (u8 *)&data->word, read, pec); in mlxbf_i2c_smbus_xfer()
2069 dev_dbg(&adap->dev, "smbus %s word data at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2074 byte_cnt = data->block[0]; in mlxbf_i2c_smbus_xfer()
2075 mlxbf_i2c_smbus_i2c_block_func(&request, &command, data->block, in mlxbf_i2c_smbus_xfer()
2077 dev_dbg(&adap->dev, "i2c %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2082 byte_cnt = read ? I2C_SMBUS_BLOCK_MAX : data->block[0]; in mlxbf_i2c_smbus_xfer()
2083 mlxbf_i2c_smbus_block_func(&request, &command, data->block, in mlxbf_i2c_smbus_xfer()
2085 dev_dbg(&adap->dev, "smbus %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2091 (u8 *)&data->word, pec); in mlxbf_i2c_smbus_xfer()
2092 dev_dbg(&adap->dev, "process call, wr/rd at 0x%02x, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2097 byte_cnt = data->block[0]; in mlxbf_i2c_smbus_xfer()
2099 data->block, &byte_cnt, in mlxbf_i2c_smbus_xfer()
2101 dev_dbg(&adap->dev, "block process call, wr/rd %d bytes, slave 0x%02x.\n", in mlxbf_i2c_smbus_xfer()
2106 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command %d\n", in mlxbf_i2c_smbus_xfer()
2108 return -EOPNOTSUPP; in mlxbf_i2c_smbus_xfer()
2118 struct mlxbf_i2c_priv *priv = i2c_get_adapdata(slave->adapter); in mlxbf_i2c_reg_slave()
2119 struct device *dev = &slave->dev; in mlxbf_i2c_reg_slave()
2126 if (slave->flags & (I2C_CLIENT_TEN | I2C_CLIENT_PEC)) { in mlxbf_i2c_reg_slave()
2128 return -EAFNOSUPPORT; in mlxbf_i2c_reg_slave()
2140 struct mlxbf_i2c_priv *priv = i2c_get_adapdata(slave->adapter); in mlxbf_i2c_unreg_slave()
2141 struct device *dev = &slave->dev; in mlxbf_i2c_unreg_slave()
2147 * 2) Freeing priv->slave at the corresponding index in mlxbf_i2c_unreg_slave()
2149 ret = mlxbf_i2c_slave_disable(priv, slave->addr); in mlxbf_i2c_unreg_slave()
2151 dev_err(dev, "Unable to find slave 0x%x\n", slave->addr); in mlxbf_i2c_unreg_slave()
2221 return -ENOENT; in mlxbf_i2c_acpi_probe()
2225 return -ENODEV; in mlxbf_i2c_acpi_probe()
2227 priv->chip = (struct mlxbf_i2c_chip_info *)aid->driver_data; in mlxbf_i2c_acpi_probe()
2235 priv->bus = bus_id; in mlxbf_i2c_acpi_probe()
2242 struct device *dev = &pdev->dev; in mlxbf_i2c_probe()
2250 return -ENOMEM; in mlxbf_i2c_probe()
2258 * Starting BlueField-3 SoC, the "smbus" resource was broken down into 3 in mlxbf_i2c_probe()
2264 priv->resource_version = resource_version; in mlxbf_i2c_probe()
2266 if (priv->chip->type < MLXBF_I2C_CHIP_TYPE_3 && resource_version == 0) { in mlxbf_i2c_probe()
2267 priv->timer = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); in mlxbf_i2c_probe()
2268 if (!priv->timer) in mlxbf_i2c_probe()
2269 return -ENOMEM; in mlxbf_i2c_probe()
2271 priv->mst = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); in mlxbf_i2c_probe()
2272 if (!priv->mst) in mlxbf_i2c_probe()
2273 return -ENOMEM; in mlxbf_i2c_probe()
2275 priv->slv = devm_kzalloc(dev, sizeof(struct mlxbf_i2c_resource), GFP_KERNEL); in mlxbf_i2c_probe()
2276 if (!priv->slv) in mlxbf_i2c_probe()
2277 return -ENOMEM; in mlxbf_i2c_probe()
2279 ret = mlxbf_i2c_init_resource(pdev, &priv->smbus, in mlxbf_i2c_probe()
2284 priv->timer->io = priv->smbus->io; in mlxbf_i2c_probe()
2285 priv->mst->io = priv->smbus->io + MLXBF_I2C_MST_ADDR_OFFSET; in mlxbf_i2c_probe()
2286 priv->slv->io = priv->smbus->io + MLXBF_I2C_SLV_ADDR_OFFSET; in mlxbf_i2c_probe()
2288 ret = mlxbf_i2c_init_resource(pdev, &priv->timer, in mlxbf_i2c_probe()
2293 ret = mlxbf_i2c_init_resource(pdev, &priv->mst, in mlxbf_i2c_probe()
2298 ret = mlxbf_i2c_init_resource(pdev, &priv->slv, in mlxbf_i2c_probe()
2304 ret = mlxbf_i2c_init_resource(pdev, &priv->mst_cause, in mlxbf_i2c_probe()
2309 ret = mlxbf_i2c_init_resource(pdev, &priv->slv_cause, in mlxbf_i2c_probe()
2314 adap = &priv->adap; in mlxbf_i2c_probe()
2315 adap->owner = THIS_MODULE; in mlxbf_i2c_probe()
2316 adap->class = I2C_CLASS_HWMON; in mlxbf_i2c_probe()
2317 adap->algo = &mlxbf_i2c_algo; in mlxbf_i2c_probe()
2318 adap->quirks = &mlxbf_i2c_quirks; in mlxbf_i2c_probe()
2319 adap->dev.parent = dev; in mlxbf_i2c_probe()
2320 adap->dev.of_node = dev->of_node; in mlxbf_i2c_probe()
2321 adap->nr = priv->bus; in mlxbf_i2c_probe()
2323 snprintf(adap->name, sizeof(adap->name), "i2c%d", adap->nr); in mlxbf_i2c_probe()
2326 /* Read Core PLL frequency. */ in mlxbf_i2c_probe()
2331 priv->frequency = MLXBF_I2C_COREPLL_FREQ; in mlxbf_i2c_probe()
2340 * does not really hurt, then keep the code as is. in mlxbf_i2c_probe()
2345 priv->bus); in mlxbf_i2c_probe()
2360 priv->irq = irq; in mlxbf_i2c_probe()
2378 struct device *dev = &pdev->dev; in mlxbf_i2c_remove()
2381 if (priv->chip->type < MLXBF_I2C_CHIP_TYPE_3 && priv->resource_version == 0) { in mlxbf_i2c_remove()
2382 params = priv->smbus->params; in mlxbf_i2c_remove()
2383 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2385 params = priv->timer->params; in mlxbf_i2c_remove()
2386 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2388 params = priv->mst->params; in mlxbf_i2c_remove()
2389 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2391 params = priv->slv->params; in mlxbf_i2c_remove()
2392 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2395 params = priv->mst_cause->params; in mlxbf_i2c_remove()
2396 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2398 params = priv->slv_cause->params; in mlxbf_i2c_remove()
2399 devm_release_mem_region(dev, params->start, resource_size(params)); in mlxbf_i2c_remove()
2406 if (--mlxbf_i2c_bus_count == 0) { in mlxbf_i2c_remove()
2413 devm_free_irq(dev, priv->irq, priv); in mlxbf_i2c_remove()
2415 i2c_del_adapter(&priv->adap); in mlxbf_i2c_remove()
2422 .name = "i2c-mlxbf",