From patchwork Tue May 10 16:11:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 67466 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2212136qge; Tue, 10 May 2016 09:11:49 -0700 (PDT) X-Received: by 10.66.100.197 with SMTP id fa5mr58965645pab.25.1462896708902; Tue, 10 May 2016 09:11:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yx4si3568837pac.109.2016.05.10.09.11.48; Tue, 10 May 2016 09:11:48 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.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 S1752157AbcEJQLr (ORCPT + 1 other); Tue, 10 May 2016 12:11:47 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34256 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751782AbcEJQLq (ORCPT ); Tue, 10 May 2016 12:11:46 -0400 Received: by mail-pf0-f195.google.com with SMTP id 145so1285869pfz.1 for ; Tue, 10 May 2016 09:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DEk4bcOrlLxEwYWMn5CuDuVirVDazpw+7sjNBPZVS9E=; b=un672M1aGKqMeaoioU7IJjf1S4f01ER+MHzA0zMs5YIYCzNwMduwvorGZOYobJHma3 VJwuHB/teq6OoFT0gXnND90pFeSMypfFIJRCc4ZZiET0j9t1YVoKDOayC8sr6tEaVBNc LxvVULg9V7xurDGz6n7o2HVmIFtb93ozFFOvVgfPnvtXSNbRZ9SttusJLwxJ6B0/8kP7 uUxu+odEbrhDLAEOGmaYREye6ASDZdVt863oc3MmXFMV8EUJr9K4VVbF7HoAhukF1ajQ 9e6oQwAV18eeZOR5osa5kJ7jwSbULoY5x4RiME5ttD2VhNHPVpqqvleoRYsAiDlK88P3 VV+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DEk4bcOrlLxEwYWMn5CuDuVirVDazpw+7sjNBPZVS9E=; b=jAXg4eV9KzzIt7IYnyUMZoBVD92jObN49WFYt+BJziCfOF+UwGQio/QXuGIWeMcfz+ IzSefngQqQ83xBhWmJxqO61eqIfl9boJfq7qWBoXL1qiU+KcXisLiebdBs8EBN1/eOJ2 hd16m+7Rr26Ysk44ohm8/TBOncE8Z4eXfEH3SHssjT/9NMj4Gh7ZebbcGjjbvBQb5j3m G1GdsmHh4H2OqvGyJwBHCUF+kjspdMiiGFoYjyWMLsk14Za4nETXBeLnV9yT1GpLYOlu YYUvYscd1KZ6D3+FUextkYKG8MFmC69TIykUjNatvIhHYMthid60IqhRDAK1m6UVwqqZ 9C8g== X-Gm-Message-State: AOPr4FV/Buna+K6l+TJo/VeOExLbvEwxMzb35G3IsDtUC5PT2QoSE6ETUrjxCElSEIykeA== X-Received: by 10.98.34.72 with SMTP id i69mr59251358pfi.153.1462896705910; Tue, 10 May 2016 09:11:45 -0700 (PDT) Received: from serve.minyard.net ([108.19.215.157]) by smtp.gmail.com with ESMTPSA id m190sm5592033pfm.29.2016.05.10.09.11.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 May 2016 09:11:45 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 63AFADD4; Tue, 10 May 2016 11:11:43 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id DDBF030052B; Tue, 10 May 2016 11:11:41 -0500 (CDT) From: minyard@acm.org To: Wolfram Sang , linux-i2c@vger.kernel.org, Jean Delvare Cc: minyard@acm.org, Corey Minyard Subject: [PATCH v2 2/3] i2c-smbus: Allow parms to be passed in from sysfs new_device Date: Tue, 10 May 2016 11:11:38 -0500 Message-Id: <1462896699-1627-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462896699-1627-1-git-send-email-minyard@acm.org> References: <1462896699-1627-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.7.4 -- 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 7748fd6..4f099ad 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)