From patchwork Wed Feb 4 16:23:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 436422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BF329140129 for ; Thu, 5 Feb 2015 03:23:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966245AbbBDQXw (ORCPT ); Wed, 4 Feb 2015 11:23:52 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:58861 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965319AbbBDQXw (ORCPT ); Wed, 4 Feb 2015 11:23:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From; bh=rcFOT9oLA6bln/nZmiuEqFpac0kHaainpaXTnRSqn6A=; b=DGA4YCbKCHKqQV/scepiC+XHwyIKic7zas87fwM1z7l6H3ulSj5M4lzks7jQFJNxGKrfmW0xmYvVBzL7ItIJKcaQsQH471yotpH5dh+xFTh/IYNcZVsH9mRrUSNGhuA9Db20qYXSbpX8TQAcTO1mw3JtQ7rl+9GmWtBp1QkniGM=; Received: from mailnull by bh-25.webhostbox.net with sa-checked (Exim 4.82) (envelope-from ) id 1YJ2k2-000ebW-Tp for linux-i2c@vger.kernel.org; Wed, 04 Feb 2015 16:23:51 +0000 Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:50118 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.82) (envelope-from ) id 1YJ2jx-000eYF-SH; Wed, 04 Feb 2015 16:23:46 +0000 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-Spam-Checker-Version: spamc_ctasd client on localost X-Spam-Level: X-Spam-Status: No, score=0.0 required=50.0 tests=SpamClass_Unknown, VirusClass_Unknown autolearn=disabled version=1.0.0 X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A020206.54D24797.0024, 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: 2 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-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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,