From patchwork Tue Oct 20 08:43:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 532838 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 974791401DE for ; Tue, 20 Oct 2015 19:46:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932094AbbJTInt (ORCPT ); Tue, 20 Oct 2015 04:43:49 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:35144 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753636AbbJTInp (ORCPT ); Tue, 20 Oct 2015 04:43:45 -0400 Received: by wicll6 with SMTP id ll6so34315147wic.0 for ; Tue, 20 Oct 2015 01:43:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=toqO0ho3KDCBBdcSLKBD87wAgODAa4alD4LfystkLzQ=; b=RWbj3k41ghSHxu9+p6qh1M0417c6NwwjFY6rnao4rSGGKj5rBrnM/AFxz3z6+JEwDP 8cuD2ZSxEhryDDG3VGwa1OBULZK9otFb97TMx3BfeDaTumXwT9IlAI1pe0o677SIdd2D q6egNsYIWQQ8liUs8PAgIXfiXbfN6zsmi9rN11jzAmPwnayhlRcOiUz45xdkga0xZkNU sYybfjPu9IJq8IyjN/ZqE64glhWdkaibIPjJ0YMGJmMXUvY5G5EOTLZhUnx8HdM0qski e4/3dEOMINY87QS4m8dX99vvj0TFcspGrg7kut8H/KOLn2m5OVUBvkd4aRJCBRvinFc/ hciA== X-Gm-Message-State: ALoCoQmdqXKPONT/KPZ3bd6yotcTsqIzerMiPfdNtKDG+1mqnzzdb+2YFrrnJmqyWBJes+DXacvF X-Received: by 10.180.187.178 with SMTP id ft18mr3237871wic.10.1445330624113; Tue, 20 Oct 2015 01:43:44 -0700 (PDT) Received: from localhost.localdomain (cag06-6-78-235-100-105.fbx.proxad.net. [78.235.100.105]) by smtp.gmail.com with ESMTPSA id kr10sm2390754wjc.25.2015.10.20.01.43.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Oct 2015 01:43:43 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang Cc: linux-i2c , LKML , Bartosz Golaszewski Subject: [RESEND PATCH 3/9] eeprom: at24: tie up an additional address for at24cs series Date: Tue, 20 Oct 2015 10:43:21 +0200 Message-Id: <1445330607-12470-4-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445330607-12470-1-git-send-email-bgolaszewski@baylibre.com> References: <1445330607-12470-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The at24cs series EEPROM chips have an additional read-only memory area, that is visible on a different i2c slave address. Tie it up with a dummy device. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index c6cb7f8..3a75a52 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -102,6 +102,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); #define AT24_BITMASK(x) (BIT(x) - 1) +#define AT24CS_SERIAL_ADDR(addr) (addr + 0x08) + /* create non-zero magic value for given eeprom parameters */ #define AT24_DEVICE_MAGIC(_len, _flags) \ ((1 << AT24_SIZE_FLAGS | (_flags)) \ @@ -543,6 +545,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) if (chip.flags & AT24_FLAG_TAKE8ADDR) num_addresses = 8; + else if (chip.flags & AT24_FLAG_SERIAL) + num_addresses = 2; else num_addresses = DIV_ROUND_UP(chip.byte_len, (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); @@ -601,12 +605,30 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->client[0] = client; /* use dummy devices for multiple-address chips */ - for (i = 1; i < num_addresses; i++) { - at24->client[i] = i2c_new_dummy(client->adapter, + if (at24->chip.flags & AT24_FLAG_TAKE8ADDR) { + for (i = 1; i < num_addresses; i++) { + at24->client[i] = i2c_new_dummy(client->adapter, + client->addr + i); + if (!at24->client[i]) { + dev_err(&client->dev, + "address 0x%02x unavailable\n", client->addr + i); - if (!at24->client[i]) { + err = -EADDRINUSE; + goto err_clients; + } + } + } + + /* + * at24cs series tie up an additional address for the memory area + * contining the serial number + */ + if (at24->chip.flags & AT24_FLAG_SERIAL) { + at24->client[1] = i2c_new_dummy(client->adapter, + AT24CS_SERIAL_ADDR(client->addr)); + if (!at24->client[1]) { dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); + AT24CS_SERIAL_ADDR(client->addr)); err = -EADDRINUSE; goto err_clients; }