From patchwork Mon Jan 26 16:58:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Priit Laes X-Patchwork-Id: 5711411 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8833BC058D for ; Mon, 26 Jan 2015 17:02:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FC882012B for ; Mon, 26 Jan 2015 17:02:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C206320108 for ; Mon, 26 Jan 2015 17:02:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YFn1j-0001vQ-0w; Mon, 26 Jan 2015 17:00:39 +0000 Received: from gn237.zone.eu ([217.146.67.237]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YFn1f-0001o7-CF for linux-arm-kernel@lists.infradead.org; Mon, 26 Jan 2015 17:00:37 +0000 Received: from localhost (112-218-191-90.dyn.estpak.ee [90.191.218.112]) (Authenticated sender: plaes@plaes.org) by gn237.zone.eu (Postfix) with ESMTPSA id AEF6C3008046; Mon, 26 Jan 2015 19:00:05 +0200 (EET) From: Priit Laes To: Subject: [PATCH] arm: sunxi: input: RFC: Add sysfs voltage for sun4i-lradc driver Date: Mon, 26 Jan 2015 18:58:32 +0200 Message-Id: <1422291516-24895-1-git-send-email-plaes@plaes.org> X-Mailer: git-send-email 2.2.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150126_090035_779574_BDB73DF2 X-CRM114-Status: GOOD ( 15.86 ) X-Spam-Score: 0.0 (/) Cc: Priit Laes , "open list:ABI/API" , Dmitry Torokhov , open list , Hans de Goede , linux-sunxi@googlegroups.com, "open list:SUN4I LOW RES ADC..." , Maxime Ripard , "moderated list:ARM/Allwinner A1X..." X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- .../ABI/testing/sysfs-driver-input-sun4i-lradc | 4 ++ drivers/input/keyboard/sun4i-lradc-keys.c | 49 +++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-input-sun4i-lradc diff --git a/Documentation/ABI/testing/sysfs-driver-input-sun4i-lradc b/Documentation/ABI/testing/sysfs-driver-input-sun4i-lradc new file mode 100644 index 0000000..e4e6448 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-input-sun4i-lradc @@ -0,0 +1,4 @@ +What: /sys/class/input/input(x)/device/voltage +Date: February 2015 +Contact: Priit Laes +Description: ADC output voltage in microvolts or 0 if device is not opened. diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c index cc8f7dd..c0ab8ec 100644 --- a/drivers/input/keyboard/sun4i-lradc-keys.c +++ b/drivers/input/keyboard/sun4i-lradc-keys.c @@ -79,10 +79,27 @@ struct sun4i_lradc_data { u32 vref; }; +static u32 sun4i_lradc_read_voltage(struct sun4i_lradc_data *lradc) +{ + u32 val = readl(lradc->base + LRADC_DATA0) & 0x3f; + return val * lradc->vref / 63; +}; + +static ssize_t +sun4i_lradc_dev_voltage_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sun4i_lradc_data *lradc = dev_get_drvdata(dev); + + return sprintf(buf, "%u\n", sun4i_lradc_read_voltage(lradc)); +} + +static const DEVICE_ATTR(voltage, S_IRUGO, sun4i_lradc_dev_voltage_show, NULL); + static irqreturn_t sun4i_lradc_irq(int irq, void *dev_id) { struct sun4i_lradc_data *lradc = dev_id; - u32 i, ints, val, voltage, diff, keycode = 0, closest = 0xffffffff; + u32 i, ints, voltage, diff, keycode = 0, closest = 0xffffffff; ints = readl(lradc->base + LRADC_INTS); @@ -97,8 +114,7 @@ static irqreturn_t sun4i_lradc_irq(int irq, void *dev_id) } if ((ints & CHAN0_KEYDOWN_IRQ) && lradc->chan0_keycode == 0) { - val = readl(lradc->base + LRADC_DATA0) & 0x3f; - voltage = val * lradc->vref / 63; + voltage = sun4i_lradc_read_voltage(lradc); for (i = 0; i < lradc->chan0_map_count; i++) { diff = abs(lradc->chan0_map[i].voltage - voltage); @@ -156,7 +172,7 @@ static void sun4i_lradc_close(struct input_dev *dev) } static int sun4i_lradc_load_dt_keymap(struct device *dev, - struct sun4i_lradc_data *lradc) + struct sun4i_lradc_data *lradc) { struct device_node *np, *pp; int i; @@ -168,8 +184,8 @@ static int sun4i_lradc_load_dt_keymap(struct device *dev, lradc->chan0_map_count = of_get_child_count(np); if (lradc->chan0_map_count == 0) { - dev_err(dev, "keymap is missing in device tree\n"); - return -EINVAL; + dev_info(dev, "keymap is missing in device tree\n"); + return 0; } lradc->chan0_map = devm_kmalloc_array(dev, lradc->chan0_map_count, @@ -185,19 +201,19 @@ static int sun4i_lradc_load_dt_keymap(struct device *dev, error = of_property_read_u32(pp, "channel", &channel); if (error || channel != 0) { - dev_err(dev, "%s: Inval channel prop\n", pp->name); + dev_err(dev, "%s: Invalid 'channel' property\n", pp->name); return -EINVAL; } error = of_property_read_u32(pp, "voltage", &map->voltage); if (error) { - dev_err(dev, "%s: Inval voltage prop\n", pp->name); + dev_err(dev, "%s: Invalid 'voltage' property\n", pp->name); return -EINVAL; } error = of_property_read_u32(pp, "linux,code", &map->keycode); if (error) { - dev_err(dev, "%s: Inval linux,code prop\n", pp->name); + dev_err(dev, "%s: Invalid 'linux,code' property\n", pp->name); return -EINVAL; } @@ -257,14 +273,26 @@ static int sun4i_lradc_probe(struct platform_device *pdev) if (error) return error; - error = input_register_device(lradc->input); + error = device_create_file(dev, &dev_attr_voltage); if (error) return error; + error = input_register_device(lradc->input); + if (error) { + device_remove_file(&pdev->dev, &dev_attr_voltage); + return error; + } + platform_set_drvdata(pdev, lradc); return 0; } +static int sun4i_lradc_remove(struct platform_device *pdev) +{ + device_remove_file(&pdev->dev, &dev_attr_voltage); + return 0; +} + static const struct of_device_id sun4i_lradc_of_match[] = { { .compatible = "allwinner,sun4i-a10-lradc-keys", }, { /* sentinel */ } @@ -277,6 +305,7 @@ static struct platform_driver sun4i_lradc_driver = { .of_match_table = of_match_ptr(sun4i_lradc_of_match), }, .probe = sun4i_lradc_probe, + .remove = sun4i_lradc_remove, }; module_platform_driver(sun4i_lradc_driver);