linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: robh+dt@kernel.org, mark.rutland@arm.com, nsekhar@ti.com,
	david@lechnology.com, wsa@the-dreams.de
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-i2c@vger.kernel.org, nicolas.ferre@microchip.com,
	ludovic.desroches@microchip.com,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 2/3] drivers: misc: eeprom: at24: support reading mac eeprom from different addresses
Date: Thu, 6 Jul 2017 13:16:56 +0300	[thread overview]
Message-ID: <1499336217-16913-3-git-send-email-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <1499336217-16913-1-git-send-email-claudiu.beznea@microchip.com>

Add support for reading MAC address from different offsets of EEPROM. The
offset is initialized via device tree. If nothing is given as input the
old value, 0x90, is used. In this way the driver could be used as generic
driver for different vendor memories by only changing the reading offset
via device tree.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/misc/eeprom/at24.c         | 5 ++++-
 include/linux/platform_data/at24.h | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 764ff5df..53c2b03 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -365,7 +365,7 @@ static ssize_t at24_eeprom_read_mac(struct at24_data *at24, char *buf,
 	memset(msg, 0, sizeof(msg));
 	msg[0].addr = client->addr;
 	msg[0].buf = addrbuf;
-	addrbuf[0] = 0x90 + offset;
+	addrbuf[0] = at24->chip.mac_offset + offset;
 	msg[0].len = 1;
 	msg[1].addr = client->addr;
 	msg[1].flags = I2C_M_RD;
@@ -581,6 +581,9 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip)
 		 */
 		chip->page_size = 1;
 	}
+	err = device_property_read_u32(dev, "mac-offset", &chip->mac_offset);
+	if (err)
+		chip->mac_offset = 0x90;
 }
 
 static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
diff --git a/include/linux/platform_data/at24.h b/include/linux/platform_data/at24.h
index 271a4e2..4e9523e 100644
--- a/include/linux/platform_data/at24.h
+++ b/include/linux/platform_data/at24.h
@@ -42,6 +42,7 @@
 
 struct at24_platform_data {
 	u32		byte_len;		/* size (sum of all addr) */
+	u32		mac_offset;
 	u16		page_size;		/* for writes */
 	u8		flags;
 #define AT24_FLAG_ADDR16	BIT(7)	/* address pointer is 16 bit */
-- 
2.7.4

  parent reply	other threads:[~2017-07-06 10:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 10:16 [PATCH 0/3] Add at24 functionality to read MAC form different EEPROM offsets Claudiu Beznea
2017-07-06 10:16 ` [PATCH 1/3] dt-bindings: i2c: eeprom: document all at24 bindings Claudiu Beznea
     [not found]   ` <1499336217-16913-2-git-send-email-claudiu.beznea-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org>
2017-07-10  3:44     ` Rob Herring
2017-07-06 10:16 ` Claudiu Beznea [this message]
2017-07-06 10:16 ` [PATCH 3/3] dt-bindings: i2c: eeprom: document "mac-offset" binding Claudiu Beznea
2017-07-10  3:46   ` Rob Herring
2017-07-19  9:08     ` m18063

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1499336217-16913-3-git-send-email-claudiu.beznea@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=david@lechnology.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=mark.rutland@arm.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=nsekhar@ti.com \
    --cc=robh+dt@kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).