From patchwork Tue Sep 26 19:35:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114281 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4205103qgf; Tue, 26 Sep 2017 12:36:04 -0700 (PDT) X-Received: by 10.99.121.135 with SMTP id u129mr12154786pgc.260.1506454564268; Tue, 26 Sep 2017 12:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506454564; cv=none; d=google.com; s=arc-20160816; b=hwRiVVAtVQiksKEcteNWcd/8+Ho0jakdJxECO4Od1LZIUBVMNRWsnkIWP0z/JCGj8T IaDDhFteuBBy/MuIgryWH+llAUpAXgELTvThoZH3V3F1PfuwFcg1k6R6ObSjOwhvAJpX 88WwXQJc6cJ8L2+2qa9hATaK9nLFzsEieayLLuXfNJjbQpGg/YCKraLSYwBdQBtXjB/k 3rV2zIqWncqtDSmtnPRmxLldfnJVqTogsR2C/TuxYaDhsWailV8aCvWUQdNCN6FT+/4d 4xxoc6IPktwVUvhyoeJFmABZd1yjdqHEt+O4RWmLX0Xm4UlrARY9Nq0yI8nnwslD47VA 4YCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=0GWe5C6ipV1kxsvaW1N/jiEtxqYwFEwtdeQGu3LE66o=; b=WK1R2LqqiydT8kyoZlNzljqylkNSMDAqkUVZvYbwZEpzha88pXWkpNIGn3/jw8bm4n U24QUP4AXr2y6okL7+Z+/N24Q9J8UMQ/tfbIU9Q9sBJZhSeAoHZSw9EaTGscOEegdItg R/xfI6Jofzwbc5iajnBiXpRQQDsQLw9Q3HbggJcR6bJGod3H/SwLcKBW3wH7ooSUxWJH i5kFn6GR70PfLKckTlW2t1EDY5k5nhrdpu8ySXl10Tz74I1+UaxorHFHjsDHi+gKp4tf J1IfZwY1tlZa9gwxPZpm/HNnh5Bh80AGjm4ueOVG2Bd0E4Hg/D0kXkXzS5zQeegWWkGq cXTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IlyUG8Tp; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si6242978pgb.564.2017.09.26.12.36.03; Tue, 26 Sep 2017 12:36:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=@linaro.org header.s=google header.b=IlyUG8Tp; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031910AbdIZTgC (ORCPT + 5 others); Tue, 26 Sep 2017 15:36:02 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:44654 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030327AbdIZTgA (ORCPT ); Tue, 26 Sep 2017 15:36:00 -0400 Received: by mail-pf0-f175.google.com with SMTP id e1so6037166pfk.1 for ; Tue, 26 Sep 2017 12:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=p59iiKt2jV6flVL3R+svv8MFpBCVz7GI4ECL0qr0U3A=; b=IlyUG8TpkZpYWXXTxoQf/4kOsldysvS5/CAyCEl+RABzZMCY3nfvu07nJR2oMIx5ok VTRGq1AYH1pvvcWrJQTrIhusiIiPJGoYhmw297ulG66T6uD8T/RvQ6mg50wIfrkISiUW PfntdXs7FpfqaWGkLzoTREzJ6gIpwbWrgJH/g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=p59iiKt2jV6flVL3R+svv8MFpBCVz7GI4ECL0qr0U3A=; b=tBiipr9RYuCjNJJNFM4zME9b65KV+xyUhQrpmGyubsfbMYpo5viWq02GMRrfrvxXYs oTojkbmwgcCDY29P/+6ocoFi1cEvNGtdu8c/YfL0jcHCMuLLvLz7lahOXoeYcQwPRnW1 5OF4AAYC90iPT+HhpMP9561ogbLqVL4pxTZ0+u/5/wCim6So28DHCdsm1qUdmaXkNNUt 7vBnqVD31ObBMr0op67HNmvGHyuyLmH9RshJ3vu7hcz2uLVFbzgNKWYr1+9J3zkZiSlG LIkq5s3T5HYBmRiRPtg7NhjoWtG4+HrvD+9uxg/Bta+DHYO3l9gh9egtkcHxBpY8xcJp 2xiw== X-Gm-Message-State: AHPjjUjEGfqjBvXnB3qTp4b2DKEnJtpwQ+HrzWkhJG1EqDTAFgBIaJ5a IC20iMh30UfiY3s0k5a/L7UUoQFntx4= X-Google-Smtp-Source: AOwi7QB82T2SNyfnsImmCJdMGHpi5AKxht9+STpE9hvLtrI0mq4XwQMYcsy2OYy34wdKBccVNBCsQQ== X-Received: by 10.84.224.66 with SMTP id a2mr11691080plt.207.1506454559783; Tue, 26 Sep 2017 12:35:59 -0700 (PDT) Received: from localhost.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id v10sm20057447pgf.8.2017.09.26.12.35.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 12:35:59 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij Subject: [PATCH 1/2] gpio: Get rid of _prefix and __prefixes Date: Tue, 26 Sep 2017 21:35:52 +0200 Message-Id: <20170926193552.21809-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The arbitrarily marking of a function with _ or __ is taking to mean "perform some inner core of the caller" or something like that. At other times, this syntax has a totally different meaning. I don't like this since it is unambious and unhelpful to people reading the code, so replace it with _commit() suffixes. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 52 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) -- 2.13.5 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" 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/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c952ef1b2f46..3c2065d0aed1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2013,7 +2013,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove_pin_ranges); * on each other, and help provide better diagnostics in debugfs. * They're called even less than the "set direction" calls. */ -static int __gpiod_request(struct gpio_desc *desc, const char *label) +static int gpiod_request_commit(struct gpio_desc *desc, const char *label) { struct gpio_chip *chip = desc->gdev->chip; int status; @@ -2106,7 +2106,7 @@ int gpiod_request(struct gpio_desc *desc, const char *label) gdev = desc->gdev; if (try_module_get(gdev->owner)) { - status = __gpiod_request(desc, label); + status = gpiod_request_commit(desc, label); if (status < 0) module_put(gdev->owner); else @@ -2119,7 +2119,7 @@ int gpiod_request(struct gpio_desc *desc, const char *label) return status; } -static bool __gpiod_free(struct gpio_desc *desc) +static bool gpiod_free_commit(struct gpio_desc *desc) { bool ret = false; unsigned long flags; @@ -2154,7 +2154,7 @@ static bool __gpiod_free(struct gpio_desc *desc) void gpiod_free(struct gpio_desc *desc) { - if (desc && desc->gdev && __gpiod_free(desc)) { + if (desc && desc->gdev && gpiod_free_commit(desc)) { module_put(desc->gdev->owner); put_device(&desc->gdev->dev); } else { @@ -2217,7 +2217,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, return desc; } - err = __gpiod_request(desc, label); + err = gpiod_request_commit(desc, label); if (err < 0) return ERR_PTR(err); @@ -2235,7 +2235,7 @@ EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); void gpiochip_free_own_desc(struct gpio_desc *desc) { if (desc) - __gpiod_free(desc); + gpiod_free_commit(desc); } EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); @@ -2291,7 +2291,7 @@ static int gpio_set_drive_single_ended(struct gpio_chip *gc, unsigned offset, return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; } -static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) +static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) { struct gpio_chip *gc = desc->gdev->chip; int val = !!value; @@ -2358,7 +2358,7 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) int gpiod_direction_output_raw(struct gpio_desc *desc, int value) { VALIDATE_DESC(desc); - return _gpiod_direction_output_raw(desc, value); + return gpiod_direction_output_raw_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); @@ -2381,7 +2381,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) value = !value; else value = !!value; - return _gpiod_direction_output_raw(desc, value); + return gpiod_direction_output_raw_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_direction_output); @@ -2448,7 +2448,7 @@ EXPORT_SYMBOL_GPL(gpiod_is_active_low); * that the GPIO was actually requested. */ -static int _gpiod_get_raw_value(const struct gpio_desc *desc) +static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) { struct gpio_chip *chip; int offset; @@ -2477,7 +2477,7 @@ int gpiod_get_raw_value(const struct gpio_desc *desc) VALIDATE_DESC(desc); /* Should be using gpio_get_value_cansleep() */ WARN_ON(desc->gdev->chip->can_sleep); - return _gpiod_get_raw_value(desc); + return gpiod_get_raw_value_commit(desc); } EXPORT_SYMBOL_GPL(gpiod_get_raw_value); @@ -2499,7 +2499,7 @@ int gpiod_get_value(const struct gpio_desc *desc) /* Should be using gpio_get_value_cansleep() */ WARN_ON(desc->gdev->chip->can_sleep); - value = _gpiod_get_raw_value(desc); + value = gpiod_get_raw_value_commit(desc); if (value < 0) return value; @@ -2511,11 +2511,11 @@ int gpiod_get_value(const struct gpio_desc *desc) EXPORT_SYMBOL_GPL(gpiod_get_value); /* - * _gpio_set_open_drain_value() - Set the open drain gpio's value. + * gpio_set_open_drain_value_commit() - Set the open drain gpio's value. * @desc: gpio descriptor whose state need to be set. * @value: Non-zero for setting it HIGH otherwise it will set to LOW. */ -static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) +static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value) { int err = 0; struct gpio_chip *chip = desc->gdev->chip; @@ -2542,7 +2542,7 @@ static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) * @desc: gpio descriptor whose state need to be set. * @value: Non-zero for setting it HIGH otherwise it will set to LOW. */ -static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) +static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value) { int err = 0; struct gpio_chip *chip = desc->gdev->chip; @@ -2564,16 +2564,16 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) __func__, err); } -static void _gpiod_set_raw_value(struct gpio_desc *desc, bool value) +static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value) { struct gpio_chip *chip; chip = desc->gdev->chip; trace_gpio_value(desc_to_gpio(desc), 0, value); if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) - _gpio_set_open_drain_value(desc, value); + gpio_set_open_drain_value_commit(desc, value); else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) - _gpio_set_open_source_value(desc, value); + gpio_set_open_source_value_commit(desc, value); else chip->set(chip, gpio_chip_hwgpio(desc), value); } @@ -2631,9 +2631,9 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, * open drain and open source outputs are set individually */ if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { - _gpio_set_open_drain_value(desc, value); + gpio_set_open_drain_value_commit(desc, value); } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { - _gpio_set_open_source_value(desc, value); + gpio_set_open_source_value_commit(desc, value); } else { __set_bit(hwgpio, mask); if (value) @@ -2667,7 +2667,7 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int value) VALIDATE_DESC_VOID(desc); /* Should be using gpiod_set_value_cansleep() */ WARN_ON(desc->gdev->chip->can_sleep); - _gpiod_set_raw_value(desc, value); + gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_raw_value); @@ -2689,7 +2689,7 @@ void gpiod_set_value(struct gpio_desc *desc, int value) WARN_ON(desc->gdev->chip->can_sleep); if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) value = !value; - _gpiod_set_raw_value(desc, value); + gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_value); @@ -2908,7 +2908,7 @@ int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) { might_sleep_if(extra_checks); VALIDATE_DESC(desc); - return _gpiod_get_raw_value(desc); + return gpiod_get_raw_value_commit(desc); } EXPORT_SYMBOL_GPL(gpiod_get_raw_value_cansleep); @@ -2927,7 +2927,7 @@ int gpiod_get_value_cansleep(const struct gpio_desc *desc) might_sleep_if(extra_checks); VALIDATE_DESC(desc); - value = _gpiod_get_raw_value(desc); + value = gpiod_get_raw_value_commit(desc); if (value < 0) return value; @@ -2952,7 +2952,7 @@ void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) { might_sleep_if(extra_checks); VALIDATE_DESC_VOID(desc); - _gpiod_set_raw_value(desc, value); + gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_raw_value_cansleep); @@ -2972,7 +2972,7 @@ void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) VALIDATE_DESC_VOID(desc); if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) value = !value; - _gpiod_set_raw_value(desc, value); + gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep); From patchwork Tue Sep 26 19:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114282 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4205205qgf; Tue, 26 Sep 2017 12:36:12 -0700 (PDT) X-Received: by 10.99.103.66 with SMTP id b63mr11734144pgc.392.1506454572438; Tue, 26 Sep 2017 12:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506454572; cv=none; d=google.com; s=arc-20160816; b=x1JPDKxTs2smDsvvQvCIv9JQcbXJZKDB7gEWQ5DSFCzr1IrlUmL4VH/qWkbHYNj+hA hrkCosbpJll65keJsZHLTuI+5mkP0Q5FAC3dvsMfAthsEShzqnTbDJk6P9AEjeaE4lZh DKuDDo38Opbxu/VROcNIDeMTnRYceICmPs7vhfOjls3unn8kLS84IBzGPJJ1DChKq9nx ikSIuumlkNUEmQZxcSq8i20ie/iBQdYBW6UYc7O4M6ktFfa5mXWiEjq3uzsupsWGB2Nk FFv5tJDLxZqsczzLg5vDaDC0dglFb2zpjTQrrvDu40cv1xLRKO9OhwE+TAIz0XSdVYiS HRPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=y3Qjy61TNUKKmCqTnjoWNBEz6m/O1cx6aCY8fMdvWX0=; b=ADTxasWTe3pZbhTqRHaHijiinyUyW09reBRfwBRsMdD0tyVaE4cDiWWnc/Wn1At/p+ zkop4AJwyhVi+cy2vy5t6MBGTE/ea2qPNw7twq40bXZ16tjOnQN864b/g5kVw38fa1Zq ODfC9vj6QlRvWwR+ya/RyA/2A8v1JJu/JbFgWD2LT4Ov9OquXvA9MOX5dB+pBTD2nzcv 70nB+ufux7UFnHzG2Zo745fRo1ZWrx8Cvwk7hRzFzF0TMTKcbTJ+kTAPScFZXEn0GI0n 6EkZMyjp0EPD7cqQZq8mX9wyUKivuHRbtZN9rak/gjSMaN9utUEfrmgyppgSqa0O7VTY oRlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZZz0qn9K; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si6242978pgb.564.2017.09.26.12.36.12; Tue, 26 Sep 2017 12:36:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-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=@linaro.org header.s=google header.b=ZZz0qn9K; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031911AbdIZTgL (ORCPT + 5 others); Tue, 26 Sep 2017 15:36:11 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:46448 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030327AbdIZTgJ (ORCPT ); Tue, 26 Sep 2017 15:36:09 -0400 Received: by mail-pf0-f177.google.com with SMTP id r68so6031318pfj.3 for ; Tue, 26 Sep 2017 12:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=vX4qVmHesDJpHEMf7ddfIxUjenp5wZaLHwi5XMYbons=; b=ZZz0qn9Kb//TmHIGImG9BSImRMNZTTxwkCrIisY3OcG4d/tQ3WO17od6T1X7T9GNOC L1LXYgoGmFUw1Ji4uZolflMRnWqZmdSPxXaFEWIzcmaskQW1vka6T+s+tNkhSrckIl6v CohMVd8+B/ssLsX7Prp/KuyPir6R62tq9qm2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vX4qVmHesDJpHEMf7ddfIxUjenp5wZaLHwi5XMYbons=; b=CTUWSa4LF42PcXPoHyMmqwd6AoJfTBdv7STD/MUsltYEiSISntNb4LCLZEEl1FRD+/ NEW6L8I2m3Hna2HkCxG4OL7s82os4+rI/5Jh9QCofSLg1BJyKfScmE41ZLvksQYsBxEI e5b7EKNfWVf3mAsskqi3c3umcdTtvvefDQepRElpsFF309Md8EGwiDB+rwZc9uXSEKPF GzZ79h6uVRhaz7WFGLN862gAwsOrnTehy9xMTvL1Ls/Sg7bWlHww0pVj7JJQsoegnRZJ x6joKkiDjEmAKfCp4sfFT9ES5LS0OsJixEglldLb70v/a9kuu5NLdqfmvfLhiGoPyhrK 6U2w== X-Gm-Message-State: AHPjjUjceXaYJhbA/mLB3FTVr8rDrkXxt6M0EZg8sPN1+gIs+B3c6mlT wPQatS2IO5bWxBeUyD8dOTxPInI38CI= X-Google-Smtp-Source: AOwi7QA9TX6/+oSjCBJYQSU0S2DddpXHU2sjLXynqeQAsQD70M5UwJ8m+8izmRSFJUK+iG4j3TTAKg== X-Received: by 10.101.83.72 with SMTP id w8mr11941960pgr.226.1506454569223; Tue, 26 Sep 2017 12:36:09 -0700 (PDT) Received: from localhost.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id n10sm17511310pfh.121.2017.09.26.12.36.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 12:36:08 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij Subject: [PATCH 2/2] gpio: Alter semantics of *raw* operations to actually be raw Date: Tue, 26 Sep 2017 21:36:03 +0200 Message-Id: <20170926193603.21859-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Currently calls to: gpiod_direction_output_raw() gpiod_set_raw_value() gpiod_set_raw_array_value() gpiod_set_raw_value_cansleep() gpiod_set_raw_array_value_cansleep() Respect that we do not want to invert the value written, but will still apply special open drain/open source semantics if the line has an open drain/open source flag. It also forbids us from driving an output marked as an interrupt line. This does not fit with the function name and expected semantics. In the w1 host driver (for example) we need to handle a line as open drain but sometimes force it to pull up, which means we should be able to use the gpiod_set_raw_value() for this, but it currently does not work. There are also use cases where users actually want to drive a line used by an interrupt. This is what they should be expected to use the *raw* accessors for. I have looked over the current users of this API and they do not seem to be using the *raw* accessors with open drain or open source so let's augment this behaviour before we have users expecting the inconsistent semantic. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 90 ++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 43 deletions(-) -- 2.13.5 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" 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/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 3c2065d0aed1..f50518d61c81 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2297,38 +2297,6 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) int val = !!value; int ret; - /* GPIOs used for IRQs shall not be set as output */ - if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { - gpiod_err(desc, - "%s: tried to set a GPIO tied to an IRQ as output\n", - __func__); - return -EIO; - } - - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { - /* First see if we can enable open drain in hardware */ - ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), - PIN_CONFIG_DRIVE_OPEN_DRAIN); - if (!ret) - goto set_output_value; - /* Emulate open drain by not actively driving the line high */ - if (val) - return gpiod_direction_input(desc); - } - else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { - ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), - PIN_CONFIG_DRIVE_OPEN_SOURCE); - if (!ret) - goto set_output_value; - /* Emulate open source by not actively driving the line low */ - if (!val) - return gpiod_direction_input(desc); - } else { - gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), - PIN_CONFIG_DRIVE_PUSH_PULL); - } - -set_output_value: if (!gc->set || !gc->direction_output) { gpiod_warn(desc, "%s: missing set() or direction_output() operations\n", @@ -2376,11 +2344,47 @@ EXPORT_SYMBOL_GPL(gpiod_direction_output_raw); */ int gpiod_direction_output(struct gpio_desc *desc, int value) { + struct gpio_chip *gc = desc->gdev->chip; + int ret; + VALIDATE_DESC(desc); if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) value = !value; else value = !!value; + + /* GPIOs used for IRQs shall not be set as output */ + if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { + gpiod_err(desc, + "%s: tried to set a GPIO tied to an IRQ as output\n", + __func__); + return -EIO; + } + + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { + /* First see if we can enable open drain in hardware */ + ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), + PIN_CONFIG_DRIVE_OPEN_DRAIN); + if (!ret) + goto set_output_value; + /* Emulate open drain by not actively driving the line high */ + if (value) + return gpiod_direction_input(desc); + } + else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { + ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), + PIN_CONFIG_DRIVE_OPEN_SOURCE); + if (!ret) + goto set_output_value; + /* Emulate open source by not actively driving the line low */ + if (!value) + return gpiod_direction_input(desc); + } else { + gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), + PIN_CONFIG_DRIVE_PUSH_PULL); + } + +set_output_value: return gpiod_direction_output_raw_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_direction_output); @@ -2570,12 +2574,7 @@ static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value) chip = desc->gdev->chip; trace_gpio_value(desc_to_gpio(desc), 0, value); - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) - gpio_set_open_drain_value_commit(desc, value); - else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) - gpio_set_open_source_value_commit(desc, value); - else - chip->set(chip, gpio_chip_hwgpio(desc), value); + chip->set(chip, gpio_chip_hwgpio(desc), value); } /* @@ -2630,9 +2629,9 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, * collect all normal outputs belonging to the same chip * open drain and open source outputs are set individually */ - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags) && !raw) { gpio_set_open_drain_value_commit(desc, value); - } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { + } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags) && !raw) { gpio_set_open_source_value_commit(desc, value); } else { __set_bit(hwgpio, mask); @@ -2676,8 +2675,8 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_value); * @desc: gpio whose value will be assigned * @value: value to assign * - * Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into - * account + * Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW, + * OPEN_DRAIN and OPEN_SOURCE flags into account. * * This function should be called from contexts where we cannot sleep, and will * complain if the GPIO chip functions potentially sleep. @@ -2689,7 +2688,12 @@ void gpiod_set_value(struct gpio_desc *desc, int value) WARN_ON(desc->gdev->chip->can_sleep); if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) value = !value; - gpiod_set_raw_value_commit(desc, value); + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) + gpio_set_open_drain_value_commit(desc, value); + else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) + gpio_set_open_source_value_commit(desc, value); + else + gpiod_set_raw_value_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_set_value);