From patchwork Tue May 2 09:12:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Reid X-Patchwork-Id: 757488 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wHFw33vv0z9s7M for ; Tue, 2 May 2017 19:13:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751225AbdEBJNw (ORCPT ); Tue, 2 May 2017 05:13:52 -0400 Received: from anchovy2.45ru.net.au ([203.30.46.146]:42992 "EHLO anchovy.45ru.net.au" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751581AbdEBJMm (ORCPT ); Tue, 2 May 2017 05:12:42 -0400 Received: (qmail 552 invoked by uid 5089); 2 May 2017 09:12:39 -0000 Received: by simscan 1.2.0 ppid: 481, pid: 484, t: 0.0340s 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 anchovy3.45ru.net.au with ESMTPA; 2 May 2017 09:12:39 -0000 Received: by preid-centos7.electromag.com.au (Postfix, from userid 1000) id C0E1C302E22AA; Tue, 2 May 2017 17:12:37 +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, benjamin.tissoires@redhat.com Subject: [PATCH v6 3/8] i2c: i2c-smbus: add of_i2c_setup_smbus_alert Date: Tue, 2 May 2017 17:12:21 +0800 Message-Id: <1493716346-58517-4-git-send-email-preid@electromag.com.au> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1493716346-58517-1-git-send-email-preid@electromag.com.au> References: <1493716346-58517-1-git-send-email-preid@electromag.com.au> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 Acked-by: Rob Herring --- 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 */