From patchwork Wed Nov 30 02:57:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tnhuynh@apm.com X-Patchwork-Id: 9453495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 27E5C6071C for ; Wed, 30 Nov 2016 02:57:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFC3B28473 for ; Wed, 30 Nov 2016 02:57:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2C992847A; Wed, 30 Nov 2016 02:57:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 462AA28478 for ; Wed, 30 Nov 2016 02:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754090AbcK3C5p (ORCPT ); Tue, 29 Nov 2016 21:57:45 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:36453 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754504AbcK3C5o (ORCPT ); Tue, 29 Nov 2016 21:57:44 -0500 Received: by mail-pg0-f54.google.com with SMTP id f188so76138151pgc.3 for ; Tue, 29 Nov 2016 18:57:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=SLbAGEMJvhqn9httDpsJRsfnYjsPAe8T0JSc8xbu2N8=; b=M+IjK+xH8IHLyy5s+HGxxJk3RZjt/KORL5qf0MwE8Px52rK01sOxhneaym/t7Ni7rN a7Julk/EcUA9r2twa6nr8MzWdQlIBehHG8X6hXktzwUKJL/JbTjYaJQsZIsAujuKf3jn a6V/i5BJ5LXDGSrusiraksADlrRdJDp2r/CA4= 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; bh=SLbAGEMJvhqn9httDpsJRsfnYjsPAe8T0JSc8xbu2N8=; b=bS2RoHghG26lkGTkLf0GbqcOeartUtl7Qo89AKv6YzZ8HXVGRpsKTRqjAqc3JkKYhF 2jz1HNQ0mAatoZrktLjWjey0u02KuzehA03jGduiBYyG9lSde1l6WeHnzeJtYCDB/Avf SCFDMIRAzvyPrGWFswlbPoDEY+pODEUIYLooEQEwbuLtGd5jTVV3brk1759WleCqG9AO 9cYE11IFOMVL4kTYew3YOs38ukHlmX27zzHeQ3k4VU80cJWAC4DAWYfCPhMtovBGpRaV qpOptMvvZXOGk5kVUy0DFtM1nnqAhYwpuwe6QKV2xolUxAl+Lyel58qWDemk/xq6E8N6 HI9g== X-Gm-Message-State: AKaTC00ZNoAnW1ajEG/WDnvGPG8IMC7MG3J9uM6iwJfTb1qCz2Yy+SousO8lv8pYPM56+TOv X-Received: by 10.84.129.131 with SMTP id b3mr67053359plb.54.1480474662519; Tue, 29 Nov 2016 18:57:42 -0800 (PST) Received: from localhost.localdomain ([118.69.219.197]) by smtp.gmail.com with ESMTPSA id 24sm98062570pfh.41.2016.11.29.18.57.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 18:57:41 -0800 (PST) From: Tin Huynh To: Alessandro Zummo , Alexandre Belloni Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, rtc-linux@googlegroups.com, Loc Ho , Thang Nguyen , Phong Vo , patches@apm.com, Tin Huynh Subject: [PATCH V1] rtc: ds1307: Add ACPI support Date: Wed, 30 Nov 2016 09:57:31 +0700 Message-Id: <1480474651-13984-1-git-send-email-tnhuynh@apm.com> X-Mailer: git-send-email 1.7.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enables ACPI support for rtc-ds1307 driver. Signed-off-by: Tin Huynh --- drivers/rtc/rtc-ds1307.c | 51 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 43 insertions(+), 8 deletions(-) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 4e31036..2a1a4d3 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -11,6 +11,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -191,6 +192,26 @@ static u8 do_trickle_setup_ds1339(struct i2c_client *, }; MODULE_DEVICE_TABLE(i2c, ds1307_id); +#ifdef CONFIG_ACPI +static const struct acpi_device_id ds1307_acpi_ids[] = { + { .id = "DS1307", .driver_data = ds_1307 }, + { .id = "DS1337", .driver_data = ds_1337 }, + { .id = "DS1338", .driver_data = ds_1338 }, + { .id = "DS1339", .driver_data = ds_1339 }, + { .id = "DS1388", .driver_data = ds_1388 }, + { .id = "DS1340", .driver_data = ds_1340 }, + { .id = "DS3231", .driver_data = ds_3231 }, + { .id = "M41T00", .driver_data = m41t00 }, + { .id = "MCP7940X", .driver_data = mcp794xx }, + { .id = "MCP7941X", .driver_data = mcp794xx }, + { .id = "PT7C4338", .driver_data = ds_1307 }, + { .id = "RX8025", .driver_data = rx_8025 }, + { .id = "ISL12057", .driver_data = ds_1337 }, + { } +}; +MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids); +#endif + /*----------------------------------------------------------------------*/ #define BLOCK_DATA_MAX_TRIES 10 @@ -874,7 +895,7 @@ static u8 do_trickle_setup_ds1339(struct i2c_client *client, return setup; } -static void ds1307_trickle_of_init(struct i2c_client *client, +static void ds1307_trickle_init(struct i2c_client *client, struct chip_desc *chip) { uint32_t ohms = 0; @@ -882,9 +903,10 @@ static void ds1307_trickle_of_init(struct i2c_client *client, if (!chip->do_trickle_setup) goto out; - if (of_property_read_u32(client->dev.of_node, "trickle-resistor-ohms" , &ohms)) + if (device_property_read_u32(&client->dev, "trickle-resistor-ohms", + &ohms)) goto out; - if (of_property_read_bool(client->dev.of_node, "trickle-diode-disable")) + if (device_property_read_bool(&client->dev, "trickle-diode-disable")) diode = false; chip->trickle_charger_setup = chip->do_trickle_setup(client, ohms, diode); @@ -1268,7 +1290,7 @@ static int ds1307_probe(struct i2c_client *client, struct ds1307 *ds1307; int err = -ENODEV; int tmp, wday; - struct chip_desc *chip = &chips[id->driver_data]; + struct chip_desc *chip; struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); bool want_irq = false; bool ds1307_can_wakeup_device = false; @@ -1297,11 +1319,23 @@ static int ds1307_probe(struct i2c_client *client, i2c_set_clientdata(client, ds1307); ds1307->client = client; - ds1307->type = id->driver_data; + if (id) { + chip = &chips[id->driver_data]; + ds1307->type = id->driver_data; + } else { + const struct acpi_device_id *acpi_id; + + acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids), + &client->dev); + if (!acpi_id) + return -ENODEV; + chip = &chips[acpi_id->driver_data]; + ds1307->type = acpi_id->driver_data; + } - if (!pdata && client->dev.of_node) - ds1307_trickle_of_init(client, chip); - else if (pdata && pdata->trickle_charger_setup) + if (!pdata) + ds1307_trickle_init(client, chip); + else if (pdata->trickle_charger_setup) chip->trickle_charger_setup = pdata->trickle_charger_setup; if (chip->trickle_charger_setup && chip->trickle_charger_reg) { @@ -1678,6 +1712,7 @@ static int ds1307_remove(struct i2c_client *client) static struct i2c_driver ds1307_driver = { .driver = { .name = "rtc-ds1307", + .acpi_match_table = ACPI_PTR(ds1307_acpi_ids), }, .probe = ds1307_probe, .remove = ds1307_remove,