From: David Daney <ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org,
Michael Hennerich
<michael.hennerich-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>,
David Daney <david.daney-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org>,
Greg Kroah-Hartman
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Axel Lin <axel.lin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH 3/3] eeprom/of: Add device tree bindings to at25.
Date: Fri, 11 May 2012 15:05:23 -0700 [thread overview]
Message-ID: <1336773923-17866-4-git-send-email-ddaney.cavm@gmail.com> (raw)
In-Reply-To: <1336773923-17866-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: David Daney <david.daney-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org>
We can extract the "pagesize", "size" and "address-width" from the
device tree so that SPI eeproms can be fully specified in the device
tree.
Also add a MODULE_DEVICE_TABLE so the drivers can be automatically bound.
Signed-off-by: David Daney <david.daney-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org>
Cc: Michael Hennerich <michael.hennerich-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: Axel Lin <axel.lin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/misc/eeprom/at25.c | 61 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 01ab3c9..609ee72 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -16,6 +16,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/sched.h>
+#include <linux/of.h>
#include <linux/spi/spi.h>
#include <linux/spi/eeprom.h>
@@ -293,6 +294,9 @@ static int at25_probe(struct spi_device *spi)
{
struct at25_data *at25 = NULL;
const struct spi_eeprom *chip;
+#ifdef CONFIG_OF
+ struct spi_eeprom of_chip;
+#endif
int err;
int sr;
int addrlen;
@@ -300,9 +304,51 @@ static int at25_probe(struct spi_device *spi)
/* Chip description */
chip = spi->dev.platform_data;
if (!chip) {
- dev_dbg(&spi->dev, "no chip description\n");
- err = -ENODEV;
- goto fail;
+#ifdef CONFIG_OF
+ if (spi->dev.of_node) {
+ u32 val;
+ memset(&of_chip, 0, sizeof(of_chip));
+ if (of_property_read_u32(spi->dev.of_node, "pagesize", &val)) {
+ dev_dbg(&spi->dev, "no \"pagesize\" property\n");
+ err = -ENODEV;
+ goto fail;
+ }
+ of_chip.page_size = val;
+ if (of_property_read_u32(spi->dev.of_node, "size", &val)) {
+ dev_dbg(&spi->dev, "no \"size\" property\n");
+ err = -ENODEV;
+ goto fail;
+ }
+ of_chip.byte_len = val;
+ if (of_property_read_u32(spi->dev.of_node, "address-width", &val)) {
+ dev_dbg(&spi->dev, "no \"address-width\" property\n");
+ err = -ENODEV;
+ goto fail;
+ }
+ switch (val) {
+ case 8:
+ of_chip.flags |= EE_ADDR1;
+ break;
+ case 16:
+ of_chip.flags |= EE_ADDR2;
+ break;
+ case 24:
+ of_chip.flags |= EE_ADDR3;
+ break;
+ default:
+ dev_dbg(&spi->dev, "bad \"address-width\" property: %u\n", val);
+ err = -EINVAL;
+ goto fail;
+ }
+ strlcpy(of_chip.name, spi->dev.of_node->name, sizeof(of_chip.name));
+ chip = &of_chip;
+ } else
+#endif
+ {
+ dev_dbg(&spi->dev, "no chip description\n");
+ err = -ENODEV;
+ goto fail;
+ }
}
/* For now we only support 8/16/24 bit addressing */
@@ -396,11 +442,19 @@ static int __devexit at25_remove(struct spi_device *spi)
/*-------------------------------------------------------------------------*/
+static const struct spi_device_id at25_id[] = {
+ {"at25", 0},
+ {"m95256", 0},
+ { }
+};
+MODULE_DEVICE_TABLE(spi, at25_id);
+
static struct spi_driver at25_driver = {
.driver = {
.name = "at25",
.owner = THIS_MODULE,
},
+ .id_table = at25_id,
.probe = at25_probe,
.remove = __devexit_p(at25_remove),
};
@@ -410,4 +464,3 @@ module_spi_driver(at25_driver);
MODULE_DESCRIPTION("Driver for most SPI EEPROMs");
MODULE_AUTHOR("David Brownell");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("spi:at25");
--
1.7.2.3
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
next prev parent reply other threads:[~2012-05-11 22:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 22:05 [PATCH 0/3] of/spi/eeprom: Configure at25 from device tree and autoload its driver David Daney
[not found] ` <1336773923-17866-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-05-11 22:05 ` [PATCH 1/3] of: Add prefix parameter to of_modalias_node() David Daney
2012-05-20 5:54 ` Grant Likely
2012-05-20 6:08 ` Grant Likely
2012-05-22 19:45 ` David Daney
2012-05-22 20:09 ` Grant Likely
2012-05-22 22:49 ` David Daney
[not found] ` <4FBC1807.4050402-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-05-22 23:01 ` Grant Likely
2012-05-11 22:05 ` [PATCH 2/3] spi: Use consistent MODALIAS values David Daney
2012-05-11 22:05 ` David Daney [this message]
2012-05-15 15:47 ` [PATCH 3/3] eeprom/of: Add device tree bindings to at25 Greg Kroah-Hartman
2012-05-20 6:14 ` Grant Likely
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=1336773923-17866-4-git-send-email-ddaney.cavm@gmail.com \
--to=ddaney.cavm-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=axel.lin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=david.daney-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
--cc=michael.hennerich-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/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).