From patchwork Tue Oct 20 08:43:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 55284 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id 697AF23024 for ; Tue, 20 Oct 2015 08:44:24 +0000 (UTC) Received: by lffy185 with SMTP id y185sf1875377lff.2 for ; Tue, 20 Oct 2015 01:44:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=D7LZlgNEK5cAMT4eQ62+6pE96+irmDxH5kBubfGGBq0=; b=WMBSFRJp9EoJeOWAFYgsjL2p9dS8h/vCzpXI2eFFL8zu99srNLHp6oIo4yjTG9mbJK 1It+KhYTj/O7fEEsa7SITXvrQJPZVgdtnIZArruFKeKyz5r41qVE9h9IpqiUXGT9SVZ2 jfYqMSw0mSycMjPPM9yB2QLMJ5LnvD0aj/q2a0qF7BOv9RFroH4qHUsXlNhbap8eoH5B 9WEIkezfTSBAHYY0jKB+2GO8SYGh50oNZyh6TeV2VZHWv2Wxx9jd7ysYHXABVT6ltD0A BUtpg/zwjgSu3u7HkvXLlh6yXTP3wQUF46YxABmnHBdRkRfw//TFOyYA3ICnWhCAEwsW w0xw== X-Gm-Message-State: ALoCoQlXkhYHf/gyWdgdoddZNcf0+wVA1i2rhGMsBYf1QIAmdrzhiltaZ9Y9DUeOUr0HvUpnibWa X-Received: by 10.112.150.229 with SMTP id ul5mr385432lbb.2.1445330663411; Tue, 20 Oct 2015 01:44:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.44.12 with SMTP id s12ls44385lfs.90.gmail; Tue, 20 Oct 2015 01:44:23 -0700 (PDT) X-Received: by 10.112.235.65 with SMTP id uk1mr1018485lbc.118.1445330663100; Tue, 20 Oct 2015 01:44:23 -0700 (PDT) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id x138si1436492lfd.127.2015.10.20.01.44.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Oct 2015 01:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lffv3 with SMTP id v3so2016499lff.0 for ; Tue, 20 Oct 2015 01:44:23 -0700 (PDT) X-Received: by 10.25.28.73 with SMTP id c70mr575297lfc.76.1445330662961; Tue, 20 Oct 2015 01:44:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1941864lbq; Tue, 20 Oct 2015 01:44:22 -0700 (PDT) X-Received: by 10.66.141.199 with SMTP id rq7mr2663456pab.140.1445330661910; Tue, 20 Oct 2015 01:44:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ra4si3594478pab.126.2015.10.20.01.44.20; Tue, 20 Oct 2015 01:44:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932208AbbJTIn5 (ORCPT + 28 others); Tue, 20 Oct 2015 04:43:57 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:36521 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932140AbbJTInu (ORCPT ); Tue, 20 Oct 2015 04:43:50 -0400 Received: by wicfx6 with SMTP id fx6so34462085wic.1 for ; Tue, 20 Oct 2015 01:43:48 -0700 (PDT) X-Received: by 10.180.86.129 with SMTP id p1mr3082455wiz.83.1445330628638; Tue, 20 Oct 2015 01:43:48 -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.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Oct 2015 01:43:48 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang Cc: linux-i2c , LKML , Bartosz Golaszewski Subject: [RESEND PATCH 5/9] eeprom: at24: export the serial number through sysfs Date: Tue, 20 Oct 2015 10:43:23 +0200 Message-Id: <1445330607-12470-6-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-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bgolaszewski@baylibre.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The at24 driver is now capable of reading the serial number from at24cs EEPROM chips. Export the serial number through sysfs. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 4d4a793..0eded22 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -64,6 +64,7 @@ struct at24_data { */ struct mutex lock; struct bin_attribute bin; + struct bin_attribute *bin_serial; u8 *writebuf; unsigned write_max; @@ -102,6 +103,7 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); #define AT24_BITMASK(x) (BIT(x) - 1) +#define AT24CS_SERIAL_SIZE 16 #define AT24CS_SERIAL_ADDR(addr) (addr + 0x08) /* create non-zero magic value for given eeprom parameters */ @@ -156,10 +158,8 @@ static struct i2c_client *at24_translate_offset(struct at24_data *at24, return at24->client[i]; } -static int __attribute__((unused)) at24cs_eeprom_serial_read( - struct at24_data *at24, - char *buf, unsigned offset, - size_t count) +static int at24cs_eeprom_serial_read(struct at24_data *at24, char *buf, + unsigned offset, size_t count) { unsigned long timeout, read_time; struct i2c_client *client; @@ -221,6 +221,16 @@ static int __attribute__((unused)) at24cs_eeprom_serial_read( return -ETIMEDOUT; } +static ssize_t at24cs_bin_serial_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + struct at24_data *at24; + + at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); + return at24cs_eeprom_serial_read(at24, buf, off, count); +} + static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, unsigned offset, size_t count) { @@ -637,6 +647,30 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->bin.read = at24_bin_read; at24->bin.size = chip.byte_len; + if (at24->chip.flags & AT24_FLAG_SERIAL) { + /* + * For EEPROMs containing the serial number export an + * additional file allowing allowing convenvient access + * to it from user-space. + */ + at24->bin_serial = devm_kzalloc(&client->dev, + sizeof(struct bin_attribute), + GFP_KERNEL); + if (!at24->bin_serial) + return -ENOMEM; + + sysfs_bin_attr_init(at24->bin_serial); + at24->bin_serial->attr.name = "serial"; + at24->bin_serial->attr.mode = S_IRUSR; + at24->bin_serial->read = at24cs_bin_serial_read; + at24->bin_serial->size = AT24CS_SERIAL_SIZE; + + err = sysfs_create_bin_file(&client->dev.kobj, + at24->bin_serial); + if (err) + goto err_clients; + } + at24->macc.read = at24_macc_read; writable = !(chip.flags & AT24_FLAG_READONLY); @@ -736,6 +770,8 @@ static int at24_remove(struct i2c_client *client) at24 = i2c_get_clientdata(client); sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); + if (at24->bin_serial) + sysfs_remove_bin_file(&client->dev.kobj, at24->bin_serial); for (i = 1; i < at24->num_addresses; i++) i2c_unregister_device(at24->client[i]);