From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754856AbbK3Q0N (ORCPT ); Mon, 30 Nov 2015 11:26:13 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:9591 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753839AbbK3Q0K (ORCPT ); Mon, 30 Nov 2015 11:26:10 -0500 From: Paul Burton To: CC: Paul Burton , Alexandre Belloni , , Alessandro Zummo , Subject: [PATCH 16/28] rtc: m41t80: add devicetree probe support Date: Mon, 30 Nov 2015 16:21:41 +0000 Message-ID: <1448900513-20856-17-git-send-email-paul.burton@imgtec.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448900513-20856-1-git-send-email-paul.burton@imgtec.com> References: <1448900513-20856-1-git-send-email-paul.burton@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.100.200.236] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow the m41t80 RTC driver to be probed via devicetree. Signed-off-by: Paul Burton --- 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 #include #include +#include #include #include #include @@ -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