From patchwork Sun May 29 21:53:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 68801 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1113294qge; Sun, 29 May 2016 14:55:08 -0700 (PDT) X-Received: by 10.66.255.102 with SMTP id ap6mr9378397pad.2.1464558907939; Sun, 29 May 2016 14:55:07 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si20406980pfb.36.2016.05.29.14.55.07; Sun, 29 May 2016 14:55:07 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932752AbcE2Vyy (ORCPT + 30 others); Sun, 29 May 2016 17:54:54 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36435 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932680AbcE2Vy2 (ORCPT ); Sun, 29 May 2016 17:54:28 -0400 Received: by mail-wm0-f50.google.com with SMTP id n129so61531960wmn.1 for ; Sun, 29 May 2016 14:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+FZWjk299OLWcOCrixG0EbrELQvfinmKe/0lMMKAaDQ=; b=aE1yMzj9h9fbHgFJuYPkOIU6gPZuAkw5XJhyQ4iQuOhOaMxcqIfeuF0q+pE/ft1iWA WsRv47gZ8g5427xA9AMhnyI/EGO/kyiZ+Ajj5whzvEoiK5QaKB/guQBoCPl82hS/Gbvm 6257Bd4/a/ft++3yc786rwWrv4r72I3YPfDEOjjt5k3buNWdRt+hJyuPVicG8+9bT2E9 KDN0Zp+FFUPI6dEHOyFwG8k0Z3uWI/hvSps3lDT3f7nlNFH0I9F0fuEvycGZXHoU8SpQ qoxrXJC0efQn2P3MHqqYKhJYZs0HdDkGjQ/hz9iH7866Isony0rqq30PxZvxWoOLhVW9 2wlQ== 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=+FZWjk299OLWcOCrixG0EbrELQvfinmKe/0lMMKAaDQ=; b=nIKEMieSUDdDDv/N+Kr7EbeTx4cBK4bG+FxZXqhItLz4tbxJiqbym/+G20Y7F/CG1e u3zQF7DK/TalCsPmoIyAfiPf/ZdigBf6vYC2uRkQ8mwFsMvIMz1dqCU7TFXeXsdX1ri9 iCnPJHRa9XaXN2tO8ppLP7XnTPV/QplZecUQeuGzzVW6vYioP1h4e/hzWVi+qS+Opl+O zjAJH7j/V/1w89QSGsH1h87cFRhBBUYiWSoPotwsUwCA6RqQBhCQ+LUXkJQVOl47fZ6n 6Q4Dp7Jqb/OdlKlZP7Lwi8jH0SH2lo6K2uxLLOaLQjt6K9jbGNEfXQs5hXkwl6yyImK9 dD5Q== X-Gm-Message-State: ALyK8tIFBV9z7YgTV9/u77IJir/5uuH72+mQ65tLrfYgtnTBSgZxvpcrDw4TmzFcgPJgdgsW X-Received: by 10.194.185.211 with SMTP id fe19mr12266112wjc.119.1464558867341; Sun, 29 May 2016 14:54:27 -0700 (PDT) Received: from bgdev-debian.lan (jua06-1-82-242-157-225.fbx.proxad.net. [82.242.157.225]) by smtp.gmail.com with ESMTPSA id a128sm20490367wme.16.2016.05.29.14.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 May 2016 14:54:26 -0700 (PDT) From: Bartosz Golaszewski To: Wolfram Sang , linux-i2c , LKML , Andrew Lunn , Srinivas Kandagatla , Maxime Ripard , GregKH Cc: Bartosz Golaszewski Subject: [PATCH 13/14] eeprom: at24: add support for at24mac series Date: Sun, 29 May 2016 23:53:51 +0200 Message-Id: <1464558832-2262-14-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464558832-2262-1-git-send-email-bgolaszewski@baylibre.com> References: <1464558832-2262-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new read function to the at24 driver allowing to retrieve the factory-programmed mac address embedded in chips from the at24mac family. These chips can be instantiated similarily to the at24cs family, except that there's no way of having access to both the serial number and the mac address at the same time - the user must instantiate either an at24cs or at24mac device as both special memory areas are accessible on the same slave address. Signed-off-by: Bartosz Golaszewski --- drivers/misc/eeprom/at24.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 2.7.4 diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 0b5240d..b3afe15 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -347,6 +347,36 @@ static ssize_t at24_eeprom_read_serial(struct at24_data *at24, char *buf, return -ETIMEDOUT; } +static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf, + unsigned int offset, size_t count) +{ + unsigned long timeout, read_time; + struct i2c_client *client; + struct i2c_msg msg[2]; + u8 addrbuf[2]; + int status; + + client = at24_translate_offset(at24, &offset); + + memset(msg, 0, sizeof(msg)); + msg[0].addr = client->addr; + msg[0].buf = addrbuf; + addrbuf[0] = 0x90 + offset; + msg[0].len = 1; + msg[1].addr = client->addr; + msg[1].flags = I2C_M_RD; + msg[1].buf = buf; + msg[1].len = count; + + loop_until_timeout(timeout, read_time) { + status = i2c_transfer(client->adapter, msg, 2); + if (status == 2) + return count; + } + + return -ETIMEDOUT; +} + /* * Note that if the hardware write-protect pin is pulled high, the whole * chip is normally write protected. But there are plenty of product @@ -648,8 +678,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) at24->chip = chip; at24->num_addresses = num_addresses; + if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) { + dev_err(&client->dev, + "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); + return -EINVAL; + } + if (chip.flags & AT24_FLAG_SERIAL) { at24->read_func = at24_eeprom_read_serial; + } else if (chip.flags & AT24_FLAG_MAC) { + at24->read_func = at24_eeprom_read_mac; } else { at24->read_func = at24->use_smbus ? at24_eeprom_read_smbus : at24_eeprom_read_i2c;