From patchwork Mon May 1 08:49:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 9706343 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 AA62F60391 for ; Mon, 1 May 2017 08:57:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93A412582C for ; Mon, 1 May 2017 08:57:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 865CE26D05; Mon, 1 May 2017 08:57:02 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 D8835262FF for ; Mon, 1 May 2017 08:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2997142AbdEAI4v (ORCPT ); Mon, 1 May 2017 04:56:51 -0400 Received: from anchovy3.45ru.net.au ([203.30.46.155]:40818 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757091AbdEAI4r (ORCPT ); Mon, 1 May 2017 04:56:47 -0400 Received: (qmail 16391 invoked by uid 5089); 1 May 2017 08:50:04 -0000 Received: by simscan 1.2.0 ppid: 16343, pid: 16345, t: 0.0279s scanners: regex: 1.2.0 attach: 1.2.0 clamav: 0.88.3/m:40/d:1950 X-RBL: $rbltext Received: from unknown (HELO preid-centos7.electromag.com.au) (preid@electromag.com.au@203.59.230.133) by anchovy2.45ru.net.au with ESMTPA; 1 May 2017 08:50:03 -0000 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id 0203A302E22B1; Mon, 1 May 2017 16:50:02 +0800 (AWST) From: Phil Reid To: wsa@the-dreams.de, robh+dt@kernel.org, mark.rutland@arm.com, sre@kernel.org, peda@axentia.se, preid@electromag.com.au, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v5 3/9] i2c: i2c-smbus: add of_i2c_setup_smbus_alert Date: Mon, 1 May 2017 16:49:53 +0800 Message-Id: <1493628599-30552-4-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1493628599-30552-1-git-send-email-preid@electromag.com.au> References: <1493628599-30552-1-git-send-email-preid@electromag.com.au> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit adds of_i2c_setup_smbus_alert which allows the smbalert driver to be attached to an i2c adapter via the device tree. Signed-off-by: Phil Reid --- Documentation/devicetree/bindings/i2c/i2c.txt | 4 +-- drivers/i2c/i2c-smbus.c | 35 +++++++++++++++++++++++++++ include/linux/i2c-smbus.h | 9 +++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt index cee9d50..1126398 100644 --- a/Documentation/devicetree/bindings/i2c/i2c.txt +++ b/Documentation/devicetree/bindings/i2c/i2c.txt @@ -59,8 +59,8 @@ wants to support one of the below features, it should adapt the bindings below. interrupts used by the device. - interrupt-names - "irq" and "wakeup" names are recognized by I2C core, other names are - left to individual drivers. + "irq", "wakeup" and "smbus_alert" names are recognized by I2C core, + other names are left to individual drivers. - host-notify device uses SMBus host notify protocol instead of interrupt line. diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index df0e2fa..a8f8439 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -238,6 +239,40 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, } EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); +int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) +{ + struct i2c_client *client; + struct i2c_smbus_alert_setup *setup; + struct i2c_board_info info = { + I2C_BOARD_INFO("smbus_alert", 0x0c), + }; + int irq; + + if (!adap->dev.of_node) + return 0; + + irq = of_irq_get_byname(adap->dev.of_node, "smbus_alert"); + if (irq == -EINVAL || irq == -ENODATA) + return 0; + else if (irq < 0) + return irq; + + setup = devm_kzalloc(&adap->dev, sizeof(struct i2c_smbus_alert_setup), + GFP_KERNEL); + if (!setup) + return -ENOMEM; + + setup->irq = irq; + info.platform_data = setup; + + client = i2c_new_device(adap, &info); + if (!client) + return -ENODEV; + + return 0; +} +EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert); + /** * i2c_handle_smbus_alert - Handle an SMBus alert * @ara: the ARA client on the relevant adapter diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h index a138502..4732d09 100644 --- a/include/linux/i2c-smbus.h +++ b/include/linux/i2c-smbus.h @@ -50,4 +50,13 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, struct i2c_smbus_alert_setup *setup); int i2c_handle_smbus_alert(struct i2c_client *ara); +#if IS_ENABLED(CONFIG_I2C_SMBUS) +int of_i2c_setup_smbus_alert(struct i2c_adapter *adap); +#else +static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) +{ + return 0; +} +#endif + #endif /* _LINUX_I2C_SMBUS_H */