Lines Matching +full:slave +full:- +full:addr
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 */
63 u8 addr = i2c_8bit_addr_from_msg(msg); in i2c_smbus_msg_pec() local
64 pec = i2c_smbus_pec(pec, &addr, 1); in i2c_smbus_msg_pec()
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
97 * @client: Handle to slave device
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
116 * @client: Handle to slave device
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
131 * @client: Handle to slave device
132 * @command: Byte interpreted by slave
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
151 * @client: Handle to slave device
152 * @command: Byte interpreted by slave
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
171 * @client: Handle to slave device
172 * @command: Byte interpreted by slave
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
191 * @client: Handle to slave device
192 * @command: Byte interpreted by slave
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
211 * @client: Handle to slave device
212 * @command: Byte interpreted by slave
214 * the data returned by the slave. SMBus allows at most 32 bytes.
217 * else the number of data bytes in the slave's response.
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
243 * @client: Handle to slave device
244 * @command: Byte interpreted by slave
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()
322 static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, in i2c_smbus_xfer_emulated() argument
340 .addr = addr, in i2c_smbus_xfer_emulated()
345 .addr = addr, in i2c_smbus_xfer_emulated()
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
525 * @addr: Address of SMBus slave on that bus
528 * @command: Byte interpreted by slave, for protocols which use such bytes
535 s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, in i2c_smbus_xfer() argument
545 res = __i2c_smbus_xfer(adapter, addr, flags, read_write, in i2c_smbus_xfer()
553 s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, in __i2c_smbus_xfer() argument
557 int (*xfer_func)(struct i2c_adapter *adap, u16 addr, in __i2c_smbus_xfer()
571 trace_smbus_write(adapter, addr, flags, read_write, in __i2c_smbus_xfer()
573 trace_smbus_read(adapter, addr, flags, read_write, in __i2c_smbus_xfer()
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()
590 res = xfer_func(adapter, addr, flags, read_write, 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()
607 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, in __i2c_smbus_xfer()
612 trace_smbus_reply(adapter, addr, flags, read_write, in __i2c_smbus_xfer()
614 trace_smbus_result(adapter, addr, flags, read_write, in __i2c_smbus_xfer()
622 * i2c_smbus_read_i2c_block_data_or_emulated - read block or emulate
623 * @client: Handle to slave device
624 * @command: Byte interpreted by slave
627 * the data returned by the slave. SMBus allows at most
634 * The addresses of the I2C slave device that are accessed with this function
636 * effect as a byte read. Before using this function you must double-check
637 * if the I2C slave does support exchanging a block transfer with a byte
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
708 struct device *parent = adapter->dev.parent; in i2c_setup_smbus_alert()
715 irq = device_property_match_string(parent, "interrupt-names", "smbus_alert"); in i2c_setup_smbus_alert()
716 if (irq == -EINVAL || irq == -ENODATA) in i2c_setup_smbus_alert()