From patchwork Wed Nov 2 23:33:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Austin Boyle X-Patchwork-Id: 123363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ww0-f56.google.com (mail-ww0-f56.google.com [74.125.82.56]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 6DBEFB6F93 for ; Thu, 3 Nov 2011 10:34:09 +1100 (EST) Received: by wwp14 with SMTP id 14sf1445480wwp.11 for ; Wed, 02 Nov 2011 16:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:subject:from:to:cc:date:message-id :mime-version:x-mailer:x-originating-ip:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=NCzlHUBCeSflwoRxlZwghjAAVyqaCyvSMyM/zkOuviA=; b=l+izMREZUiL+5krkAiq7nq5zx4AKFIE9AXL57cw4HCXtRiJLpJnBXu9XdhbVB40vPp XtkGY5JvD0Gb3kfJpQBZV5hFMrUZbeCtPGB3hhpSESq+xxAgZIN1JfL6Njz/5P7RrNyA feoZOl6/m+7/yXaZis9DIZzB4BpdJ/Lx5tjek= Received: by 10.216.131.196 with SMTP id m46mr845740wei.52.1320276844802; Wed, 02 Nov 2011 16:34:04 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.30.142 with SMTP id k14ls1787343eea.4.canary; Wed, 02 Nov 2011 16:34:03 -0700 (PDT) Received: by 10.14.8.139 with SMTP id 11mr371173eer.12.1320276843677; Wed, 02 Nov 2011 16:34:03 -0700 (PDT) Received: by 10.14.8.139 with SMTP id 11mr371172eer.12.1320276843660; Wed, 02 Nov 2011 16:34:03 -0700 (PDT) Received: from mail5.aviatnet.com (mail5.aviatnet.com. [192.147.115.32]) by gmr-mx.google.com with ESMTPS id d10si2213632eed.3.2011.11.02.16.34.02 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 Nov 2011 16:34:03 -0700 (PDT) Received-SPF: pass (google.com: domain of Austin.Boyle@aviatnet.com designates 192.147.115.32 as permitted sender) client-ip=192.147.115.32; Received: from [10.16.1.193] (10.16.1.193) by EXUSCAS2.GNET.global.vpn (10.15.150.12) with Microsoft SMTP Server (TLS) id 14.1.270.1; Wed, 2 Nov 2011 16:34:06 -0700 Subject: [rtc-linux] [PATCH v2] rtc: ds1307: generalise ram size and offset From: Austin Boyle To: Wolfram Sang CC: , David Anderson , Alessandro Zummo , Joakim Tjernlund , , Austin Boyle Date: Thu, 3 Nov 2011 12:33:54 +1300 Message-ID: <1320276834.3000.26.camel@pc786-ubu.gnet.global.vpn> MIME-Version: 1.0 X-Mailer: Evolution 2.28.3 X-Originating-IP: [10.16.1.193] X-Original-Sender: austin.boyle@aviatnet.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of Austin.Boyle@aviatnet.com designates 192.147.115.32 as permitted sender) smtp.mail=Austin.Boyle@aviatnet.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , From: Austin Boyle This patch generalises NVRAM to support RAM with other size and offset, such as the 64 bytes of SRAM on the mcp7941x. Cc: Wolfram Sang Cc: David Anderson Cc: Alessandro Zummo Cc: Joakim Tjernlund Signed-off-by: Austin Boyle --- this patch is based on Wolfram Sang's tree: git://git.pengutronix.de/git/wsa/linux-2.6.git ds1307 patch depends on: rtc: ds1307: comment and format cleanup 21af5f7bd6 rtc: ds1307: simplify irq setup code 8c63e03627 rtc: ds1307: refactor chip_desc table e246db081d rtc: add initial support for mcp7941x parts e69bba2d3a --- a/drivers/rtc/rtc-ds1307.c 2011-10-10 11:22:22.674690998 +1300 +++ b/drivers/rtc/rtc-ds1307.c 2011-11-03 12:17:40.777642801 +1300 @@ -104,6 +104,8 @@ enum ds_type { struct ds1307 { u8 offset; /* register's offset */ + u16 nvram_offset; + u16 nvram_size; u8 regs[11]; enum ds_type type; unsigned long flags; @@ -119,19 +121,19 @@ struct ds1307 { }; struct chip_desc { - unsigned nvram56:1; + unsigned nvram:1; unsigned alarm:1; }; static const struct chip_desc chips[last_ds_type] = { [ds_1307] = { - .nvram56 = 1, + .nvram = 1, }, [ds_1337] = { .alarm = 1, }, [ds_1338] = { - .nvram56 = 1, + .nvram = 1, }, [ds_1339] = { .alarm = 1, @@ -139,6 +141,9 @@ static const struct chip_desc chips[last [ds_3231] = { .alarm = 1, }, + [mcp7941x] = { + .nvram = 1, + }, }; static const struct i2c_device_id ds1307_id[] = { @@ -543,8 +548,6 @@ static const struct rtc_class_ops ds13xx /*----------------------------------------------------------------------*/ -#define NVRAM_SIZE 56 - static ssize_t ds1307_nvram_read(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, @@ -557,14 +560,15 @@ ds1307_nvram_read(struct file *filp, str client = kobj_to_i2c_client(kobj); ds1307 = i2c_get_clientdata(client); - if (unlikely(off >= NVRAM_SIZE)) + if (unlikely(off >= ds1307->nvram_size)) return 0; - if ((off + count) > NVRAM_SIZE) - count = NVRAM_SIZE - off; + if ((off + count) > ds1307->nvram_size) + count = ds1307->nvram_size - off; if (unlikely(!count)) return count; - result = ds1307->read_block_data(client, 8 + off, count, buf); + result = ds1307->read_block_data(client, ds1307->nvram_offset + off, + count, buf); if (result < 0) dev_err(&client->dev, "%s error %d\n", "nvram read", result); return result; @@ -582,14 +586,15 @@ ds1307_nvram_write(struct file *filp, st client = kobj_to_i2c_client(kobj); ds1307 = i2c_get_clientdata(client); - if (unlikely(off >= NVRAM_SIZE)) + if (unlikely(off >= ds1307->nvram_size)) return -EFBIG; - if ((off + count) > NVRAM_SIZE) - count = NVRAM_SIZE - off; + if ((off + count) > ds1307->nvram_size) + count = ds1307->nvram_size - off; if (unlikely(!count)) return count; - result = ds1307->write_block_data(client, 8 + off, count, buf); + result = ds1307->write_block_data(client, ds1307->nvram_offset + off, + count, buf); if (result < 0) { dev_err(&client->dev, "%s error %d\n", "nvram write", result); return result; @@ -605,7 +610,6 @@ static struct bin_attribute nvram = { .read = ds1307_nvram_read, .write = ds1307_nvram_write, - .size = NVRAM_SIZE, }; /*----------------------------------------------------------------------*/ @@ -692,6 +696,9 @@ static int __devinit ds1307_probe(struct break; case rx_8025: + ds1307->nvram_size = 64; /* 64 bytes SRAM */ + ds1307->nvram_offset = 0x20; + tmp = i2c_smbus_read_i2c_block_data(ds1307->client, RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); if (tmp != 2) { @@ -758,6 +765,8 @@ static int __devinit ds1307_probe(struct break; case ds_1388: ds1307->offset = 1; /* Seconds starts at 1 */ + ds1307->nvram_size = 56; /* 56 bytes NVRAM */ + ds1307->nvram_offset = 8; break; default: break; @@ -893,11 +902,12 @@ read_rtc: dev_dbg(&client->dev, "got IRQ %d\n", client->irq); } - if (chip && chip->nvram56) { + if (chip && chip->nvram) { + nvram.size = ds1307->nvram_size; err = sysfs_create_bin_file(&client->dev.kobj, &nvram); if (err == 0) { set_bit(HAS_NVRAM, &ds1307->flags); - dev_info(&client->dev, "56 bytes nvram\n"); + dev_info(&client->dev, "%zd bytes nvram\n", nvram.size); } }