Lines Matching +full:sense +full:- +full:freq

1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
5 * Copyright (C) 2016-2020 Mellanox Technologies
84 for (i = 0; i < len - len % 4; i += 4) in mlxcpld_i2c_lpc_write_buf()
94 for (i = 0; i < len - len % 4; i += 4) in mlxcpld_i2c_lpc_read_buf()
103 u32 addr = priv->base_addr + offs; in mlxcpld_i2c_read_comm()
128 u32 addr = priv->base_addr + offs; in mlxcpld_i2c_write_comm()
152 * Returns 0 if OK, other - in case of invalid parameters.
160 dev_err(priv->dev, "Incorrect 0 num of messages\n"); in mlxcpld_i2c_check_msg_params()
161 return -EINVAL; in mlxcpld_i2c_check_msg_params()
165 dev_err(priv->dev, "Invalid address 0x%03x\n", in mlxcpld_i2c_check_msg_params()
167 return -EINVAL; in mlxcpld_i2c_check_msg_params()
172 dev_err(priv->dev, "Invalid buf in msg[%d]\n", in mlxcpld_i2c_check_msg_params()
174 return -EINVAL; in mlxcpld_i2c_check_msg_params()
177 dev_err(priv->dev, "Invalid addr in msg[%d]\n", in mlxcpld_i2c_check_msg_params()
179 return -EINVAL; in mlxcpld_i2c_check_msg_params()
188 * Returns 0 - transfer completed (both ACK or NACK),
189 * negative - transfer isn't finished.
211 return -EIO; in mlxcpld_i2c_check_status()
218 priv->xfer.msg = msgs; in mlxcpld_i2c_set_transf_data()
219 priv->xfer.msg_num = num; in mlxcpld_i2c_set_transf_data()
227 priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD; in mlxcpld_i2c_set_transf_data()
229 if (priv->xfer.cmd == I2C_M_RD && comm_len != msgs[0].len) { in mlxcpld_i2c_set_transf_data()
230 priv->xfer.addr_width = msgs[0].len; in mlxcpld_i2c_set_transf_data()
231 priv->xfer.data_len = comm_len - priv->xfer.addr_width; in mlxcpld_i2c_set_transf_data()
233 priv->xfer.addr_width = 0; in mlxcpld_i2c_set_transf_data()
234 priv->xfer.data_len = comm_len; in mlxcpld_i2c_set_transf_data()
243 mutex_lock(&priv->lock); in mlxcpld_i2c_reset()
249 mutex_unlock(&priv->lock); in mlxcpld_i2c_reset()
262 return -EIO; in mlxcpld_i2c_check_busy()
272 usleep_range(priv->polling_time / 2, priv->polling_time); in mlxcpld_i2c_wait_for_free()
273 timeout += priv->polling_time; in mlxcpld_i2c_wait_for_free()
277 return -ETIMEDOUT; in mlxcpld_i2c_wait_for_free()
293 usleep_range(priv->polling_time / 2, priv->polling_time); in mlxcpld_i2c_wait_for_tc()
296 timeout += priv->polling_time; in mlxcpld_i2c_wait_for_tc()
301 return -ETIMEDOUT; in mlxcpld_i2c_wait_for_tc()
304 if (priv->xfer.cmd != I2C_M_RD) in mlxcpld_i2c_wait_for_tc()
305 return (priv->xfer.addr_width + priv->xfer.data_len); in mlxcpld_i2c_wait_for_tc()
307 if (priv->xfer.msg_num == 1) in mlxcpld_i2c_wait_for_tc()
312 if (!priv->xfer.msg[i].buf) in mlxcpld_i2c_wait_for_tc()
313 return -EINVAL; in mlxcpld_i2c_wait_for_tc()
317 * requested len. 0xff (line pull-up) will be returned in mlxcpld_i2c_wait_for_tc()
325 if (priv->smbus_block && (val & MLXCPLD_I2C_SMBUS_BLK_BIT)) { in mlxcpld_i2c_wait_for_tc()
329 dev_err(priv->dev, "Incorrect smbus block read message len\n"); in mlxcpld_i2c_wait_for_tc()
330 return -EPROTO; in mlxcpld_i2c_wait_for_tc()
333 datalen = priv->xfer.data_len; in mlxcpld_i2c_wait_for_tc()
337 priv->xfer.msg[i].buf, datalen); in mlxcpld_i2c_wait_for_tc()
342 return -ENXIO; in mlxcpld_i2c_wait_for_tc()
345 return -EINVAL; in mlxcpld_i2c_wait_for_tc()
355 &priv->xfer.data_len, 1); in mlxcpld_i2c_xfer_msg()
357 val = priv->xfer.addr_width; in mlxcpld_i2c_xfer_msg()
359 if (priv->smbus_block && priv->xfer.msg_num >= 2 && in mlxcpld_i2c_xfer_msg()
360 priv->xfer.msg[1].len == 1 && in mlxcpld_i2c_xfer_msg()
361 (priv->xfer.msg[1].flags & I2C_M_RECV_LEN) && in mlxcpld_i2c_xfer_msg()
362 (priv->xfer.msg[1].flags & I2C_M_RD)) in mlxcpld_i2c_xfer_msg()
367 for (i = 0; i < priv->xfer.msg_num; i++) { in mlxcpld_i2c_xfer_msg()
368 if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) { in mlxcpld_i2c_xfer_msg()
371 len, priv->xfer.msg[i].buf, in mlxcpld_i2c_xfer_msg()
372 priv->xfer.msg[i].len); in mlxcpld_i2c_xfer_msg()
373 len += priv->xfer.msg[i].len; in mlxcpld_i2c_xfer_msg()
381 cmd = (priv->xfer.msg[0].addr << 1) | priv->xfer.cmd; in mlxcpld_i2c_xfer_msg()
386 * Generic lpc-i2c transfer.
398 dev_err(priv->dev, "Incorrect message\n"); in mlxcpld_i2c_xfer()
407 dev_err(priv->dev, "LPCI2C bridge is busy\n"); in mlxcpld_i2c_xfer()
412 * so it doesn't make any sense to try to stop it. in mlxcpld_i2c_xfer()
415 * The only reasonable thing - is soft reset. in mlxcpld_i2c_xfer()
419 dev_err(priv->dev, "LPCI2C bridge is busy after reset\n"); in mlxcpld_i2c_xfer()
420 return -EIO; in mlxcpld_i2c_xfer()
426 mutex_lock(&priv->lock); in mlxcpld_i2c_xfer()
434 mutex_unlock(&priv->lock); in mlxcpld_i2c_xfer()
443 if (priv->smbus_block) in mlxcpld_i2c_func()
458 .max_read_len = MLXCPLD_I2C_DATA_REG_SZ - MLXCPLD_I2C_MAX_ADDR_LEN,
465 .max_read_len = MLXCPLD_I2C_DATA_REG_SZ * 2 - MLXCPLD_I2C_MAX_ADDR_LEN,
472 .max_read_len = (MLXCPLD_I2C_DATA_REG_SZ - 4) * 4,
473 .max_write_len = (MLXCPLD_I2C_DATA_REG_SZ - 4) * 4 + MLXCPLD_I2C_MAX_ADDR_LEN,
479 .name = "i2c-mlxcpld",
491 struct mlxreg_core_item *item = pdata->items; in mlxcpld_i2c_set_frequency()
494 u8 freq; in mlxcpld_i2c_set_frequency() local
501 data = item->data; in mlxcpld_i2c_set_frequency()
502 err = regmap_read(pdata->regmap, data->reg, &regval); in mlxcpld_i2c_set_frequency()
507 switch ((regval & data->mask) >> data->bit) { in mlxcpld_i2c_set_frequency()
509 freq = MLXCPLD_I2C_FREQ_1000KHZ_SET; in mlxcpld_i2c_set_frequency()
510 priv->polling_time /= 4; in mlxcpld_i2c_set_frequency()
513 freq = MLXCPLD_I2C_FREQ_400KHZ_SET; in mlxcpld_i2c_set_frequency()
514 priv->polling_time /= 4; in mlxcpld_i2c_set_frequency()
520 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_HALF_CYC_REG, &freq, 1); in mlxcpld_i2c_set_frequency()
532 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mlxcpld_i2c_probe()
534 return -ENOMEM; in mlxcpld_i2c_probe()
536 mutex_init(&priv->lock); in mlxcpld_i2c_probe()
539 priv->dev = &pdev->dev; in mlxcpld_i2c_probe()
540 priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR; in mlxcpld_i2c_probe()
541 priv->polling_time = MLXCPLD_I2C_POLL_TIME; in mlxcpld_i2c_probe()
544 pdata = dev_get_platdata(&pdev->dev); in mlxcpld_i2c_probe()
562 priv->smbus_block = true; in mlxcpld_i2c_probe()
563 if (pdev->id >= -1) in mlxcpld_i2c_probe()
564 mlxcpld_i2c_adapter.nr = pdev->id; in mlxcpld_i2c_probe()
565 priv->adap = mlxcpld_i2c_adapter; in mlxcpld_i2c_probe()
566 priv->adap.dev.parent = &pdev->dev; in mlxcpld_i2c_probe()
567 i2c_set_adapdata(&priv->adap, priv); in mlxcpld_i2c_probe()
569 err = i2c_add_numbered_adapter(&priv->adap); in mlxcpld_i2c_probe()
574 if (pdata && pdata->completion_notify) in mlxcpld_i2c_probe()
575 pdata->completion_notify(pdata->handle, mlxcpld_i2c_adapter.nr); in mlxcpld_i2c_probe()
580 mutex_destroy(&priv->lock); in mlxcpld_i2c_probe()
588 i2c_del_adapter(&priv->adap); in mlxcpld_i2c_remove()
589 mutex_destroy(&priv->lock); in mlxcpld_i2c_remove()
603 MODULE_DESCRIPTION("Mellanox I2C-CPLD controller driver");
605 MODULE_ALIAS("platform:i2c-mlxcpld");