From patchwork Sat Apr 26 05:46:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 4067441 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 09E039F1F4 for ; Sat, 26 Apr 2014 05:47:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1551E2038F for ; Sat, 26 Apr 2014 05:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A88EE20381 for ; Sat, 26 Apr 2014 05:47:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750718AbaDZFrW (ORCPT ); Sat, 26 Apr 2014 01:47:22 -0400 Received: from fallback6.mail.ru ([94.100.176.134]:42094 "EHLO fallback6.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750715AbaDZFrW (ORCPT ); Sat, 26 Apr 2014 01:47:22 -0400 Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) by fallback6.mail.ru (mPOP.Fallback_MX) with ESMTP id BE7A33B5EC47 for ; Sat, 26 Apr 2014 09:47:20 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Message-Id:Date:Subject:Cc:To:From; bh=xechRuQvz2wRoz1Vqba9OQESboDzbTuC4SZtR25hwUU=; b=flgvtCVUuaCMTsWoIO4hzzhegZhJtcKUaF5tFR6+45YV+2jI/IgcYAmCnXf8s/3klo8I03EVYrgpoDHRg5NASRD7FJRpEkjvtEXFRBXIFvUgxlbjMGlNcpBu37C42OIvKao1V+XtIG5SW3qdmHoBjM49ck7obQ0GrvZBow3L1/U=; Received: from [5.18.98.0] (port=63948 helo=shc.zet) by smtp15.mail.ru with esmtpa (envelope-from ) id 1WdvS3-0007SC-15; Sat, 26 Apr 2014 09:47:03 +0400 From: Alexander Shiyan To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Alexander Shiyan Subject: [PATCH v2] input: gpio-beeper: Simplify GPIO handling Date: Sat, 26 Apr 2014 09:46:54 +0400 Message-Id: <1398491214-14936-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.3.2 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Mras: Ok Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RDNS_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 This patch simplifies GPIO handling in the driver by using GPIO functions based on descriptors. As a result this driver now can be used for boards without DT support. Signed-off-by: Alexander Shiyan --- drivers/input/misc/Kconfig | 2 +- drivers/input/misc/gpio-beeper.c | 34 +++++++++++++++------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 5928ea7..2ff4425 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -224,7 +224,7 @@ config INPUT_GP2A config INPUT_GPIO_BEEPER tristate "Generic GPIO Beeper support" - depends on OF_GPIO + depends on GPIOLIB help Say Y here if you have a beeper connected to a GPIO pin. diff --git a/drivers/input/misc/gpio-beeper.c b/drivers/input/misc/gpio-beeper.c index b757435..4b90877 100644 --- a/drivers/input/misc/gpio-beeper.c +++ b/drivers/input/misc/gpio-beeper.c @@ -1,7 +1,7 @@ /* * Generic GPIO beeper driver * - * Copyright (C) 2013 Alexander Shiyan + * Copyright (C) 2013-2014 Alexander Shiyan * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -19,14 +19,13 @@ struct gpio_beeper { struct work_struct work; - int gpio; - bool active_low; - bool beeping; + struct gpio_desc *desc; + int beeping; }; -static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) +static void gpio_beeper_toggle(struct gpio_beeper *beep, int val) { - gpio_set_value_cansleep(beep->gpio, on ^ beep->active_low); + gpiod_set_value_cansleep(beep->desc, val); } static void gpio_beeper_work(struct work_struct *work) @@ -59,24 +58,24 @@ static void gpio_beeper_close(struct input_dev *input) struct gpio_beeper *beep = input_get_drvdata(input); cancel_work_sync(&beep->work); - gpio_beeper_toggle(beep, false); + gpio_beeper_toggle(beep, 0); } static int gpio_beeper_probe(struct platform_device *pdev) { struct gpio_beeper *beep; - enum of_gpio_flags flags; struct input_dev *input; - unsigned long gflags; int err; beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); if (!beep) return -ENOMEM; - beep->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); - if (!gpio_is_valid(beep->gpio)) - return beep->gpio; + beep->desc = devm_gpiod_get(&pdev->dev, NULL); + if (!beep->desc) + return -EINVAL; + if (IS_ERR(beep->desc)) + return PTR_ERR(beep->desc); input = devm_input_allocate_device(&pdev->dev); if (!input) @@ -94,10 +93,7 @@ static int gpio_beeper_probe(struct platform_device *pdev) input_set_capability(input, EV_SND, SND_BELL); - beep->active_low = flags & OF_GPIO_ACTIVE_LOW; - gflags = beep->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; - - err = devm_gpio_request_one(&pdev->dev, beep->gpio, gflags, pdev->name); + err = gpiod_direction_output(beep->desc, 0); if (err) return err; @@ -106,7 +102,7 @@ static int gpio_beeper_probe(struct platform_device *pdev) return input_register_device(input); } -static struct of_device_id gpio_beeper_of_match[] = { +static struct of_device_id __maybe_unused gpio_beeper_of_match[] = { { .compatible = BEEPER_MODNAME, }, { } }; @@ -116,7 +112,7 @@ static struct platform_driver gpio_beeper_platform_driver = { .driver = { .name = BEEPER_MODNAME, .owner = THIS_MODULE, - .of_match_table = gpio_beeper_of_match, + .of_match_table = of_match_ptr(gpio_beeper_of_match), }, .probe = gpio_beeper_probe, };