From patchwork Tue Jan 19 17:14:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 59991 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2697620lbb; Tue, 19 Jan 2016 09:14:34 -0800 (PST) X-Received: by 10.98.8.14 with SMTP id c14mr45629673pfd.42.1453223674471; Tue, 19 Jan 2016 09:14:34 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si48653902pfo.112.2016.01.19.09.14.34; Tue, 19 Jan 2016 09:14:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755955AbcASROc (ORCPT + 1 other); Tue, 19 Jan 2016 12:14:32 -0500 Received: from vms173023pub.verizon.net ([206.46.173.23]:42166 "EHLO vms173023pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755652AbcASROb (ORCPT ); Tue, 19 Jan 2016 12:14:31 -0500 X-Greylist: delayed 781 seconds by postgrey-1.27 at vger.kernel.org; Tue, 19 Jan 2016 12:14:31 EST Received: from serve.minyard.net ([173.57.176.17]) by vms173023.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O1700FOMMJS0170@vms173023.mailsrvcs.net> for linux-i2c@vger.kernel.org; Tue, 19 Jan 2016 11:14:17 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=Nc0brD34 c=1 sm=1 tr=0 a=bXmWQgKa9n63w7XTPFb8JQ==:117 a=N54-gffFAAAA:8 a=HL3alpDKAAAA:8 a=oR5dmqMzAAAA:8 a=xqWC_Br6kY4A:10 a=7aQ_Q-yQQ-AA:10 a=fk1lIlRQAAAA:8 a=aYeTdcPHmzu2142WWncA:9 a=2eLuIkkegY2CRdyw:21 a=b71np0fo19gA27E1:21 Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:8d:b94b:720b:cc15]) by serve.minyard.net (Postfix) with ESMTPA id CCD31308B; Tue, 19 Jan 2016 11:14:16 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 0AE0E30076F; Tue, 19 Jan 2016 11:14:15 -0600 (CST) From: minyard@acm.org To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Corey Minyard Subject: [PATCH 3/3] i2c-smbus: Allow parms to be passed in from sysfs new_device Date: Tue, 19 Jan 2016 11:14:14 -0600 Message-id: <1453223654-20724-4-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.5.0 In-reply-to: <1453223654-20724-1-git-send-email-minyard@acm.org> References: <1453223654-20724-1-git-send-email-minyard@acm.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Corey Minyard This allows "irq=" and "edge" to be passed in to the i2c new_device after the name and i2c address. This way the alert can be configured without having to have platform data. Signed-off-by: Corey Minyard --- drivers/i2c/i2c-smbus.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index cecd423..a3b7781 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -23,6 +23,7 @@ #include #include #include +#include struct i2c_smbus_alert { unsigned int alert_edge_triggered:1; @@ -123,15 +124,86 @@ static irqreturn_t smbalert_irq(int irq, void *d) return IRQ_HANDLED; } +static struct i2c_smbus_alert_setup *smbalert_parse_parms(struct device *dev, + const char *parms, + struct i2c_smbus_alert_setup *data) +{ + int rv; + char end; + + if (!parms) + return NULL; + + data->alert_edge_triggered = false; + while (*parms) { + const char *next = parms; + const char *val; + int parmlen; + + while (*next && !isspace(*next) && *next != '=') + next++; + + parmlen = next - parms; + + if (*next == '=') { + next++; + val = next; + while (*next && !isspace(*next)) + next++; + } else { + val = NULL; + } + + if (strncmp(parms, "irq", parmlen) == 0) { + if (!val) { + dev_err(dev, "no irq parm value given\n"); + return NULL; + } + rv = sscanf(val, "%d%c", &data->irq, &end); + if ((rv < 1) || ((rv > 1) && !isspace(end))) { + dev_err(dev, "Invalid irq parm: %s\n", val); + return NULL; + } + } else if (strncmp(parms, "edge", parmlen) == 0) { + if (val) { + dev_err(dev, "Value given with edge parm: %s\n", + val); + return NULL; + } + data->alert_edge_triggered = true; + } else { + dev_err(dev, "Invalid parameter: %s\n", parms); + return NULL; + } + + while (*next && isspace(*next)) + next++; + parms = next; + } + + return data; +} + /* Setup SMBALERT# infrastructure */ static int smbalert_probe(struct i2c_client *ara, const struct i2c_device_id *id) { struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev); + struct i2c_smbus_alert_setup dummy_setup; struct i2c_smbus_alert *alert; struct i2c_adapter *adapter = ara->adapter; int res; + if (ara->parms) + /* Came in through sysfs. */ + setup = smbalert_parse_parms(&ara->dev, ara->parms, + &dummy_setup); + + if (!setup) { + dev_err(&ara->dev, "SMBus alert without setup\n"); + return -ENODEV; + } + alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert), GFP_KERNEL); if (!alert)