Skip to content

Commit 29dae45

Browse files
hkallweitAndi Shyti
authored andcommitted
i2c: i801: Add SMBUS_LEN_SENTINEL
Add a sentinel length value that is used to check whether we should read and use the length value provided by the slave device. This simplifies the currently used checks. Signed-off-by: Heiner Kallweit <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 6ff9d46 commit 29dae45

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
206206
STATUS_ERROR_FLAGS)
207207

208+
#define SMBUS_LEN_SENTINEL (I2C_SMBUS_BLOCK_MAX + 1)
209+
208210
/* Older devices have their ID defined in <linux/pci_ids.h> */
209211
#define PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS 0x02a3
210212
#define PCI_DEVICE_ID_INTEL_COMETLAKE_H_SMBUS 0x06a3
@@ -541,9 +543,12 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
541543
static void i801_isr_byte_done(struct i801_priv *priv)
542544
{
543545
if (priv->is_read) {
544-
/* For SMBus block reads, length is received with first byte */
545-
if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
546-
(priv->count == 0)) {
546+
/*
547+
* At transfer start i801_smbus_block_transaction() marks
548+
* the block length as invalid. Check for this sentinel value
549+
* and read the block length from SMBHSTDAT0.
550+
*/
551+
if (priv->len == SMBUS_LEN_SENTINEL) {
547552
priv->len = inb_p(SMBHSTDAT0(priv));
548553
if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
549554
dev_err(&priv->pci_dev->dev,
@@ -698,8 +703,12 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
698703
if (status)
699704
return status;
700705

701-
if (i == 1 && read_write == I2C_SMBUS_READ
702-
&& command != I2C_SMBUS_I2C_BLOCK_DATA) {
706+
/*
707+
* At transfer start i801_smbus_block_transaction() marks
708+
* the block length as invalid. Check for this sentinel value
709+
* and read the block length from SMBHSTDAT0.
710+
*/
711+
if (len == SMBUS_LEN_SENTINEL) {
703712
len = inb_p(SMBHSTDAT0(priv));
704713
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
705714
dev_err(&priv->pci_dev->dev,
@@ -806,7 +815,8 @@ static int i801_smbus_block_transaction(struct i801_priv *priv, union i2c_smbus_
806815
u8 addr, u8 hstcmd, char read_write, int command)
807816
{
808817
if (read_write == I2C_SMBUS_READ && command == I2C_SMBUS_BLOCK_DATA)
809-
data->block[0] = I2C_SMBUS_BLOCK_MAX;
818+
/* Mark block length as invalid */
819+
data->block[0] = SMBUS_LEN_SENTINEL;
810820
else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
811821
return -EPROTO;
812822

0 commit comments

Comments
 (0)