From patchwork Mon Oct 12 14:31:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 54768 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 2789C22DB6 for ; Mon, 12 Oct 2015 14:32:27 +0000 (UTC) Received: by wicid10 with SMTP id id10sf10636760wic.2 for ; Mon, 12 Oct 2015 07:32:26 -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=OdQh4d4opBNr6TtcuztKkTkiKdvUyryOdlA9Zx09joaQAEp+DuC628N9FhMlDdPiqR wbEQoggBvDRhqhPVZ5ByI9nIjnGArcScqcKWOgCc8jf1Z21xBo6QSrhVAxU2Xt5EgDfD g2TLz08ZV1Uhbyb4HLfiWf50MRjVeJQPvOQEPnZ03t5T7stLIOxs6vm4iaC8yGTpUdo6 Efa2S+/tFi1zUZhyLVm0cqpv7B8FP9eulYFJiS06E5VmjkxsD8uKms4wLbl7mRq8W46B Uh7ca9/uAeXzpoZCOjp61qQuDvLGKF08jn7opueGQ4iTelaZhIZGR+qe44q1D9bfhFYb ABMg== X-Gm-Message-State: ALoCoQlB0W7ykfldfrk6WitmxByxsWce2fiTtMkLYeqtPfYQYvmSh3x3kI+IzC6yIuWYh7LtW0jO X-Received: by 10.112.140.202 with SMTP id ri10mr5036580lbb.10.1444660346493; Mon, 12 Oct 2015 07:32:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.83.82 with SMTP id h79ls488784lfb.76.gmail; Mon, 12 Oct 2015 07:32:26 -0700 (PDT) X-Received: by 10.25.148.196 with SMTP id w187mr8338100lfd.77.1444660346318; Mon, 12 Oct 2015 07:32:26 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id y13si11410331lfd.178.2015.10.12.07.32.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 07:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbwr8 with SMTP id r8so143411295lbw.2 for ; Mon, 12 Oct 2015 07:32:26 -0700 (PDT) X-Received: by 10.25.19.99 with SMTP id j96mr2308812lfi.106.1444660346102; Mon, 12 Oct 2015 07:32:26 -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 w3csp1583126lbq; Mon, 12 Oct 2015 07:32:25 -0700 (PDT) X-Received: by 10.107.131.38 with SMTP id f38mr2040280iod.100.1444660341749; Mon, 12 Oct 2015 07:32:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g141si12260254iog.91.2015.10.12.07.32.21; Mon, 12 Oct 2015 07:32: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 S1752757AbbJLOcS (ORCPT + 30 others); Mon, 12 Oct 2015 10:32:18 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:34917 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbbJLOcL (ORCPT ); Mon, 12 Oct 2015 10:32:11 -0400 Received: by wicge5 with SMTP id ge5so152895006wic.0 for ; Mon, 12 Oct 2015 07:32:10 -0700 (PDT) X-Received: by 10.180.10.101 with SMTP id h5mr15547548wib.27.1444660330189; Mon, 12 Oct 2015 07:32:10 -0700 (PDT) Received: from localhost.localdomain (LPoitiers-656-1-62-228.w90-63.abo.wanadoo.fr. [90.63.143.228]) by smtp.gmail.com with ESMTPSA id az6sm11102907wib.12.2015.10.12.07.32.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 07:32:09 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang Cc: linux-i2c , LKML , Patrick Titiano , Bartosz Golaszewski Subject: [PATCH 5/9] eeprom: at24: export the serial number through sysfs Date: Mon, 12 Oct 2015 16:31:17 +0200 Message-Id: <1444660281-19150-6-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444660281-19150-1-git-send-email-bgolaszewski@baylibre.com> References: <1444660281-19150-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.217.169 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]);