Lines Matching +full:segment +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * (e.g. smbalert) are handled in a separate i2c-smbus module.
9 * All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
16 #include <linux/i2c-smbus.h>
20 #include "i2c-core.h"
42 * i2c_smbus_pec - Incremental CRC8 over the given input data array
59 /* Assume a 7-bit address, which is reasonable for SMBus */
67 return i2c_smbus_pec(pec, msg->buf, msg->len); in i2c_smbus_msg_pec()
73 msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg); in i2c_smbus_add_pec()
74 msg->len++; in i2c_smbus_add_pec()
84 u8 rpec = msg->buf[--msg->len]; in i2c_smbus_check_pec()
90 return -EBADMSG; in i2c_smbus_check_pec()
96 * i2c_smbus_read_byte - SMBus "receive byte" protocol
107 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_read_byte()
115 * i2c_smbus_write_byte - SMBus "send byte" protocol
124 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_write_byte()
130 * i2c_smbus_read_byte_data - SMBus "read byte" protocol
142 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_read_byte_data()
150 * i2c_smbus_write_byte_data - SMBus "write byte" protocol
163 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_write_byte_data()
170 * i2c_smbus_read_word_data - SMBus "read word" protocol
175 * else a 16-bit unsigned "word" received from the device.
182 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_read_word_data()
190 * i2c_smbus_write_word_data - SMBus "write word" protocol
193 * @value: 16-bit "word" being written
203 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_write_word_data()
210 * i2c_smbus_read_block_data - SMBus "block read" protocol
230 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_read_block_data()
242 * i2c_smbus_write_block_data - SMBus "block write" protocol
260 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_write_block_data()
276 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_read_i2c_block_data()
296 return i2c_smbus_xfer(client->adapter, client->addr, client->flags, in i2c_smbus_write_i2c_block_data()
304 bool is_read = msg->flags & I2C_M_RD; in i2c_smbus_try_get_dmabuf()
311 msg->buf = dma_buf; in i2c_smbus_try_get_dmabuf()
312 msg->flags |= I2C_M_DMA_SAFE; in i2c_smbus_try_get_dmabuf()
315 msg->buf[0] = init_val; in i2c_smbus_try_get_dmabuf()
375 msgbuf0[1] = data->byte; in i2c_smbus_xfer_emulated()
383 msgbuf0[1] = data->word & 0xff; in i2c_smbus_xfer_emulated()
384 msgbuf0[2] = data->word >> 8; in i2c_smbus_xfer_emulated()
392 msgbuf0[1] = data->word & 0xff; in i2c_smbus_xfer_emulated()
393 msgbuf0[2] = data->word >> 8; in i2c_smbus_xfer_emulated()
402 msg[0].len = data->block[0] + 2; in i2c_smbus_xfer_emulated()
404 dev_err(&adapter->dev, in i2c_smbus_xfer_emulated()
406 data->block[0]); in i2c_smbus_xfer_emulated()
407 return -EINVAL; in i2c_smbus_xfer_emulated()
411 memcpy(msg[0].buf + 1, data->block, msg[0].len - 1); in i2c_smbus_xfer_emulated()
417 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { in i2c_smbus_xfer_emulated()
418 dev_err(&adapter->dev, in i2c_smbus_xfer_emulated()
420 data->block[0]); in i2c_smbus_xfer_emulated()
421 return -EINVAL; in i2c_smbus_xfer_emulated()
424 msg[0].len = data->block[0] + 2; in i2c_smbus_xfer_emulated()
426 memcpy(msg[0].buf + 1, data->block, msg[0].len - 1); in i2c_smbus_xfer_emulated()
434 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { in i2c_smbus_xfer_emulated()
435 dev_err(&adapter->dev, "Invalid block %s size %d\n", in i2c_smbus_xfer_emulated()
437 data->block[0]); in i2c_smbus_xfer_emulated()
438 return -EINVAL; in i2c_smbus_xfer_emulated()
442 msg[1].len = data->block[0]; in i2c_smbus_xfer_emulated()
445 msg[0].len = data->block[0] + 1; in i2c_smbus_xfer_emulated()
448 memcpy(msg[0].buf + 1, data->block + 1, data->block[0]); in i2c_smbus_xfer_emulated()
452 dev_err(&adapter->dev, "Unsupported transaction %d\n", size); in i2c_smbus_xfer_emulated()
453 return -EOPNOTSUPP; in i2c_smbus_xfer_emulated()
465 if (msg[nmsgs - 1].flags & I2C_M_RD) in i2c_smbus_xfer_emulated()
466 msg[nmsgs - 1].len++; in i2c_smbus_xfer_emulated()
473 status = -EIO; in i2c_smbus_xfer_emulated()
479 if (wants_pec && (msg[nmsgs - 1].flags & I2C_M_RD)) { in i2c_smbus_xfer_emulated()
480 status = i2c_smbus_check_pec(partial_pec, &msg[nmsgs - 1]); in i2c_smbus_xfer_emulated()
488 data->byte = msgbuf0[0]; in i2c_smbus_xfer_emulated()
491 data->byte = msgbuf1[0]; in i2c_smbus_xfer_emulated()
495 data->word = msgbuf1[0] | (msgbuf1[1] << 8); in i2c_smbus_xfer_emulated()
498 memcpy(data->block + 1, msg[1].buf, data->block[0]); in i2c_smbus_xfer_emulated()
503 dev_err(&adapter->dev, in i2c_smbus_xfer_emulated()
506 status = -EPROTO; in i2c_smbus_xfer_emulated()
509 memcpy(data->block, msg[1].buf, msg[1].buf[0] + 1); in i2c_smbus_xfer_emulated()
523 * i2c_smbus_xfer - execute SMBus protocol operations
578 xfer_func = adapter->algo->smbus_xfer; in __i2c_smbus_xfer()
580 if (adapter->algo->smbus_xfer_atomic) in __i2c_smbus_xfer()
581 xfer_func = adapter->algo->smbus_xfer_atomic; in __i2c_smbus_xfer()
582 else if (adapter->algo->master_xfer_atomic) in __i2c_smbus_xfer()
589 for (res = 0, try = 0; try <= adapter->retries; try++) { in __i2c_smbus_xfer()
592 if (res != -EAGAIN) in __i2c_smbus_xfer()
595 orig_jiffies + adapter->timeout)) in __i2c_smbus_xfer()
599 if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) in __i2c_smbus_xfer()
622 * i2c_smbus_read_i2c_block_data_or_emulated - read block or emulate
636 * effect as a byte read. Before using this function you must double-check
649 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) in i2c_smbus_read_i2c_block_data_or_emulated()
652 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) in i2c_smbus_read_i2c_block_data_or_emulated()
653 return -EOPNOTSUPP; in i2c_smbus_read_i2c_block_data_or_emulated()
655 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) { in i2c_smbus_read_i2c_block_data_or_emulated()
679 * i2c_new_smbus_alert_device - get ara client for SMBus alert support
684 * Setup handling of the SMBus alert protocol on a given I2C bus segment.
708 struct device *parent = adapter->dev.parent; in i2c_setup_smbus_alert()
716 irq = device_property_match_string(parent, "interrupt-names", "smbus_alert"); in i2c_setup_smbus_alert()
717 if (irq < 0 && irq != -EINVAL && irq != -ENODATA) in i2c_setup_smbus_alert()
721 if (irq < 0 && !device_property_present(parent, "smbalert-gpios")) in i2c_setup_smbus_alert()