[PATCH 16/28] rtc: m41t80: add devicetree probe support

From: Paul Burton
Date: Mon Nov 30 2015 - 11:26:16 EST


Allow the m41t80 RTC driver to be probed via devicetree.

Signed-off-by: Paul Burton <paul.burton@xxxxxxxxxx>
---

drivers/rtc/rtc-m41t80.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index a82937e..d3b29fc 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -20,6 +20,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/rtc.h>
#include <linux/slab.h>
#include <linux/mutex.h>
@@ -85,6 +86,14 @@ static const struct i2c_device_id m41t80_id[] = {
};
MODULE_DEVICE_TABLE(i2c, m41t80_id);

+#ifdef CONFIG_OF
+static const struct of_device_id m41t80_of_match[] = {
+ { .compatible = "st,m41t81s", .name = "m41t81s" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, m41t80_of_match);
+#endif
+
struct m41t80_data {
u8 features;
struct rtc_device *rtc;
@@ -637,6 +646,22 @@ static int m41t80_probe(struct i2c_client *client,
struct rtc_device *rtc = NULL;
struct rtc_time tm;
struct m41t80_data *clientdata = NULL;
+ const struct of_device_id *of_id;
+
+ if (!id && client->dev.of_node) {
+ of_id = of_match_node(of_match_ptr(m41t80_of_match),
+ client->dev.of_node);
+ for (id = m41t80_id; id->name[0]; id++) {
+ if (strcmp(of_id->name, id->name) == 0)
+ break;
+ }
+ if (!id->name[0])
+ id = NULL;
+ }
+ if (!id) {
+ dev_err(&client->dev, "No i2c_device_id found\n");
+ return -EINVAL;
+ }

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C
| I2C_FUNC_SMBUS_BYTE_DATA))
@@ -728,6 +753,7 @@ static int m41t80_remove(struct i2c_client *client)
static struct i2c_driver m41t80_driver = {
.driver = {
.name = "rtc-m41t80",
+ .of_match_table = of_match_ptr(m41t80_of_match),
},
.probe = m41t80_probe,
.remove = m41t80_remove,
--
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/