From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966548AbbBDQX5 (ORCPT ); Wed, 4 Feb 2015 11:23:57 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:58870 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965319AbbBDQXz (ORCPT ); Wed, 4 Feb 2015 11:23:55 -0500 From: Guenter Roeck To: Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH] eeprom: at24: Add support for large EEPROMs connected to SMBus adapters Date: Wed, 4 Feb 2015 08:23:37 -0800 Message-Id: <1423067017-27607-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.1.0 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A020206.54D24799.016D,ss=1,re=0.001,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CTCH-Score: 0.001 X-CTCH-ScoreCust: 0.000 X-CTCH-Rules: C_4847, X-CTCH-SenderID: linux@roeck-us.net X-CTCH-SenderID-Flags: 0 X-CTCH-SenderID-TotalMessages: 3 X-CTCH-SenderID-TotalSpam: 0 X-CTCH-SenderID-TotalSuspected: 0 X-CTCH-SenderID-TotalConfirmed: 0 X-CTCH-SenderID-TotalBulk: 0 X-CTCH-SenderID-TotalVirus: 0 X-CTCH-SenderID-TotalRecipients: 0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: mailgid no entry from get_relayhosts_entry X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Large EEPROMS (24c32 and larger) require a two-byte data address instead of just a single byte. Implement support for such EEPROMs with SMBus commands. Support has limitations (reads are not multi-master safe) and is slow, but it works. Practical use is for a system with 24c32 connected to Intel 82801I (ICH9). Signed-off-by: Guenter Roeck --- drivers/misc/eeprom/at24.c | 52 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 2d3db81..057d35c 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -198,6 +198,8 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, case I2C_SMBUS_BYTE_DATA: count = 1; break; + case I2C_SMBUS_BYTE: + break; default: /* * When we have a better choice than SMBus calls, use a @@ -249,6 +251,27 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, status = count; } break; + case I2C_SMBUS_BYTE: + /* + * 16-bit data address. Write data address as separate + * write operation, then read data without setting + * the address again. This is not multi-master safe, + * but the best we can do. + */ + status = i2c_smbus_write_byte_data(client, + offset >> 8, + offset & 0xff); + if (status < 0) + break; + for (i = 0; i < count; i++) { + status = i2c_smbus_read_byte(client); + if (status < 0) + break; + buf[i] = status; + } + if (status >= 0) + status = count; + break; default: status = i2c_transfer(client->adapter, msg, 2); if (status == 2) @@ -372,6 +395,16 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, status = i2c_smbus_write_i2c_block_data(client, offset, count, buf); break; + case I2C_SMBUS_WORD_DATA: + /* + * 16-bit data address. Transmit data address + * MSB as SMBus command, data address LSB as + * first data byte. + */ + status = i2c_smbus_write_word_data(client, + offset >> 8, + (offset & 0xff) | (buf[0] << 8)); + break; case I2C_SMBUS_BYTE_DATA: status = i2c_smbus_write_byte_data(client, offset, buf[0]); @@ -540,10 +573,13 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) /* Use I2C operations unless we're stuck with SMBus extensions. */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (chip.flags & AT24_FLAG_ADDR16) - return -EPFNOSUPPORT; - - if (i2c_check_functionality(client->adapter, + if (chip.flags & AT24_FLAG_ADDR16) { + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_BYTE_DATA | + I2C_FUNC_SMBUS_READ_BYTE)) + return -EPFNOSUPPORT; + use_smbus = I2C_SMBUS_BYTE; + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; } else if (i2c_check_functionality(client->adapter, @@ -559,7 +595,13 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) /* Use I2C operations unless we're stuck with SMBus extensions. */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, + if (chip.flags & AT24_FLAG_ADDR16) { + if (i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_WRITE_WORD_DATA)) { + use_smbus_write = I2C_SMBUS_WORD_DATA; + chip.page_size = 1; + } + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA; } else if (i2c_check_functionality(client->adapter, -- 2.1.0