From patchwork Mon Jan 18 17:41:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 8056821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 66A829F440 for ; Mon, 18 Jan 2016 17:45:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 453F82045E for ; Mon, 18 Jan 2016 17:45:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FC45203AA for ; Mon, 18 Jan 2016 17:45:48 +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 1aLDpp-0003md-3G; Mon, 18 Jan 2016 17:43:21 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLDoc-0002sl-Vn for linux-arm-kernel@lists.infradead.org; Mon, 18 Jan 2016 17:42:10 +0000 Received: by mail-pf0-x229.google.com with SMTP id 65so160842141pff.2 for ; Mon, 18 Jan 2016 09:41:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oYuqXl/aTVnG7DD8MO4XgtShRp2lYaLceyLKkZjngVA=; b=fBYlcghKsS4mCHLC5ydahN+9j/PEdDeR/h64hPmwLUsYbnmxLj8Y1TKGpRlVU7U9Sb Zwn4rn4Ru5FONbNTvP4SvOcJeiMC8sHaE/S0mD5zOSZ2VC4WQ+sdVTBVJx1d08Y9dlHW 120v+PKbVzOZXRC8wKH5dltPaom9pw9JMDGgTCbF9ET04nBDCXkDBQV5G5QaonTY1HeA P9WldgzioyvrhJbR1l+7BLm1IezzO6C5NQzBYXnrtfsfaqicY+fk+6f/yjzPKNYn5SiR asl/Br43aRgwy7gXZpqtFzoN686haLHBrA0phSfCVzsaqOb4wTAW7YaOr+MnUFVGWIEk E9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oYuqXl/aTVnG7DD8MO4XgtShRp2lYaLceyLKkZjngVA=; b=MlG21SuT70TtSMw3Xu//GXKjWoTcfhCFohW2JiW0gZ8dbhbsSeMHBwNRFeHD9MD/TH CYoGgE4RB8DMshzRY5j17ylX4vk+NL4o4Wm4e7tCL1iZP2Kg+5GYSDsdPKYCQdtA6FLD mvrvLHni3q2g4C5Ct4iynUpwUiwOVTGe41g4+wsjtPfbOJN8HPlgGDQXsA5E9KI8dM+w 9YkC/pt6c1IF6g3nRKnYswhYRvMIH5+TOthUXKsTXlbCDDLJZdYqy9TRJhixTVSeQaPY ylP8oRnAnSiXJOarKUYIgnOTlf6i9vkjkUG5BPrCBVFYefRO1e1RiP7/AddUuUjkpy/M YqWw== X-Gm-Message-State: AG10YOQGs5Um4mPfmrnwsTr4f1ivHhwTAhu/YlMnIYg7W7HpV3Ue9D8kdKDcRDWlgYyxRw== X-Received: by 10.98.31.207 with SMTP id l76mr31319429pfj.134.1453138906237; Mon, 18 Jan 2016 09:41:46 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.64.149]) by smtp.gmail.com with ESMTPSA id o75sm35479881pfi.17.2016.01.18.09.41.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jan 2016 09:41:45 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org, =?UTF-8?q?Timo=20Ter=C3=A4s?= , Daniel Mack Subject: [PATCH 2/4] Input: rotary_encoder - convert to use gpiod API Date: Mon, 18 Jan 2016 09:41:40 -0800 Message-Id: <1453138902-11657-3-git-send-email-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1453138902-11657-1-git-send-email-dmitry.torokhov@gmail.com> References: <1453138902-11657-1-git-send-email-dmitry.torokhov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160118_094207_204006_4843F5A8 X-CRM114-Status: GOOD ( 18.53 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robert Jarzmik , linux-arm-kernel@lists.infradead.org, Haojian Zhuang , linux-kernel@vger.kernel.org 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.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Instead of using old GPIO API, let's switch to GPIOD API, which automatically handles polarity. Signed-off-by: Dmitry Torokhov --- arch/arm/mach-pxa/raumfeld.c | 21 +++++++++-- drivers/input/misc/rotary_encoder.c | 73 +++++++++++++++++-------------------- include/linux/rotary_encoder.h | 4 -- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c index 36571a9..d156f79 100644 --- a/arch/arm/mach-pxa/raumfeld.c +++ b/arch/arm/mach-pxa/raumfeld.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -366,14 +367,21 @@ static struct pxaohci_platform_data raumfeld_ohci_info = { * Rotary encoder input device */ +static struct gpiod_lookup_table raumfeld_rotary_gpios_table = { + .dev_id = "rotary-encoder", + .table = { + GPIO_LOOKUP_IDX("gpio-0", + GPIO_VOLENC_A, NULL, 0, GPIO_ACTIVE_LOW), + GPIO_LOOKUP_IDX("gpio-0", + GPIO_VOLENC_B, NULL, 1, GPIO_ACTIVE_HIGH), + { }, + }, +}; + static struct rotary_encoder_platform_data raumfeld_rotary_encoder_info = { .steps = 24, .axis = REL_X, .relative_axis = 1, - .gpio_a = GPIO_VOLENC_A, - .gpio_b = GPIO_VOLENC_B, - .inverted_a = 1, - .inverted_b = 0, }; static struct platform_device rotary_encoder_device = { @@ -1051,7 +1059,10 @@ static void __init raumfeld_controller_init(void) int ret; pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config)); + + gpiod_add_lookup_table(&raumfeld_rotary_gpios_table); platform_device_register(&rotary_encoder_device); + spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices)); i2c_register_board_info(0, &raumfeld_controller_i2c_board_info, 1); @@ -1086,6 +1097,8 @@ static void __init raumfeld_speaker_init(void) i2c_register_board_info(0, &raumfeld_connector_i2c_board_info, 1); platform_device_register(&smc91x_device); + + gpiod_add_lookup_table(&raumfeld_rotary_gpios_table); platform_device_register(&rotary_encoder_device); raumfeld_audio_init(); diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index b9a86ca..e913bfb64 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -20,12 +20,11 @@ #include #include #include -#include +#include #include #include #include #include -#include #include #define DRV_NAME "rotary-encoder" @@ -38,6 +37,9 @@ struct rotary_encoder { unsigned int axis; unsigned int pos; + struct gpio_desc *gpio_a; + struct gpio_desc *gpio_b; + unsigned int irq_a; unsigned int irq_b; @@ -47,13 +49,10 @@ struct rotary_encoder { char last_stable; }; -static int rotary_encoder_get_state(const struct rotary_encoder_platform_data *pdata) +static int rotary_encoder_get_state(struct rotary_encoder *encoder) { - int a = !!gpio_get_value_cansleep(pdata->gpio_a); - int b = !!gpio_get_value_cansleep(pdata->gpio_b); - - a ^= pdata->inverted_a; - b ^= pdata->inverted_b; + int a = !!gpiod_get_value_cansleep(encoder->gpio_a); + int b = !!gpiod_get_value_cansleep(encoder->gpio_b); return ((a << 1) | b); } @@ -97,7 +96,7 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) mutex_lock(&encoder->access_mutex); - state = rotary_encoder_get_state(encoder->pdata); + state = rotary_encoder_get_state(encoder); switch (state) { case 0x0: @@ -130,7 +129,7 @@ static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) mutex_lock(&encoder->access_mutex); - state = rotary_encoder_get_state(encoder->pdata); + state = rotary_encoder_get_state(encoder); switch (state) { case 0x00: @@ -160,7 +159,7 @@ static irqreturn_t rotary_encoder_quarter_period_irq(int irq, void *dev_id) mutex_lock(&encoder->access_mutex); - state = rotary_encoder_get_state(encoder->pdata); + state = rotary_encoder_get_state(encoder); /* * We encode the previous and the current state using a byte. @@ -232,12 +231,6 @@ static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct devic of_property_read_u32(np, "rotary-encoder,steps", &pdata->steps); of_property_read_u32(np, "linux,axis", &pdata->axis); - pdata->gpio_a = of_get_gpio_flags(np, 0, &flags); - pdata->inverted_a = flags & OF_GPIO_ACTIVE_LOW; - - pdata->gpio_b = of_get_gpio_flags(np, 1, &flags); - pdata->inverted_b = flags & OF_GPIO_ACTIVE_LOW; - pdata->relative_axis = of_property_read_bool(np, "rotary-encoder,relative-axis"); pdata->rollover = of_property_read_bool(np, "rotary-encoder,rollover"); @@ -294,14 +287,32 @@ static int rotary_encoder_probe(struct platform_device *pdev) if (!encoder) return -ENOMEM; + mutex_init(&encoder->access_mutex); + encoder->pdata = pdata; + + encoder->gpio_a = devm_gpiod_get_index(dev, NULL, 0, GPIOD_IN); + if (IS_ERR(encoder->gpio_a)) { + err = PTR_ERR(encoder->gpio_a); + dev_err(dev, "unable to get GPIO at index 0: %d\n", err); + return err; + } + + encoder->irq_a = gpiod_to_irq(encoder->gpio_a); + + encoder->gpio_b = devm_gpiod_get_index(dev, NULL, 1, GPIOD_IN); + if (IS_ERR(encoder->gpio_b)) { + err = PTR_ERR(encoder->gpio_b); + dev_err(dev, "unable to get GPIO at index 1: %d\n", err); + return err; + } + + encoder->irq_b = gpiod_to_irq(encoder->gpio_b); + input = devm_input_allocate_device(dev); if (!input) return -ENOMEM; - mutex_init(&encoder->access_mutex); - encoder->input = input; - encoder->pdata = pdata; input->name = pdev->name; input->id.bustype = BUS_HOST; @@ -316,32 +327,14 @@ static int rotary_encoder_probe(struct platform_device *pdev) pdata->axis, 0, pdata->steps, 0, 1); } - /* request the GPIOs */ - err = devm_gpio_request_one(dev, pdata->gpio_a, GPIOF_IN, - dev_name(dev)); - if (err) { - dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_a); - return err; - } - - err = devm_gpio_request_one(dev, pdata->gpio_b, GPIOF_IN, - dev_name(dev)); - if (err) { - dev_err(dev, "unable to request GPIO %d\n", pdata->gpio_b); - return err; - } - - encoder->irq_a = gpio_to_irq(pdata->gpio_a); - encoder->irq_b = gpio_to_irq(pdata->gpio_b); - switch (pdata->steps_per_period) { case 4: handler = &rotary_encoder_quarter_period_irq; - encoder->last_stable = rotary_encoder_get_state(pdata); + encoder->last_stable = rotary_encoder_get_state(encoder); break; case 2: handler = &rotary_encoder_half_period_irq; - encoder->last_stable = rotary_encoder_get_state(pdata); + encoder->last_stable = rotary_encoder_get_state(encoder); break; case 1: handler = &rotary_encoder_irq; diff --git a/include/linux/rotary_encoder.h b/include/linux/rotary_encoder.h index fe3dc64..4536c81 100644 --- a/include/linux/rotary_encoder.h +++ b/include/linux/rotary_encoder.h @@ -4,10 +4,6 @@ struct rotary_encoder_platform_data { unsigned int steps; unsigned int axis; - unsigned int gpio_a; - unsigned int gpio_b; - unsigned int inverted_a; - unsigned int inverted_b; unsigned int steps_per_period; bool relative_axis; bool rollover;