Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3617796pxk; Mon, 21 Sep 2020 20:13:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzpnixoZKlvl2yccfw9nHByDm36HmjfLePNLtezwRviTeO9Zy1fx69TqXHqKCaFp5nu0nB X-Received: by 2002:a50:fd83:: with SMTP id o3mr1888445edt.176.1600744428572; Mon, 21 Sep 2020 20:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600744428; cv=none; d=google.com; s=arc-20160816; b=DM19kPDQJ0y/yDKg6dBMv3Bkd3yDV+BUrQfSPEVzc8o60saYG394WJt1vKe9pCtciE 4Ib/mn/jrUt/ypaEONIuw+FL0mqLoGD6kU+z9c17jSTZMFKfbaYgVCD/3/Zu/GGB2IRF QWvyLsb8C2ZazrwNgFkpNk6LJniNr+jevHk8niVV2uO/0UB+mq8uMWRnOlcuHAc+FL81 D1mLTuDQtgVgwczJvZ03XW6W7kUxmYT0+qJeTXFxq8NHQqodV+NZpUddDm8ebUnW3/rD hUHfpF3ICcRff+woXI2pF26Xkws8YUGxa1I5C7PzE6cxeE0wshiXCBDcljAq6mTpKmZ4 B1Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yxKIyBLT5u8uwfgnqH40ev+Mr1LACz2e+jVMDRAal6w=; b=zE8FVw5h38wtKM8INQDcUM2ugR3Se4XnI7i38wz7StQXWVhHBBW6H6mYYw/tfgse5c xJnivsYnzx8d7X/0QfnhlDXlWJkVJvS2V5M+8CY0o0ZD39BEeGyteaXhp5LrD5KhlkqQ VlfaPuIq/HtJEB5BphnkOyY/p1Cu1yv+E8sriCIsv+zNjxx74JWNZDVAp232Y7nRlLrV eirpo836zpeIM1UaEiS21z15TdUd1c4VF8pEfUYuFf30WuxgWfmIlL2wrYNQLUv9xWsL vI6XrmthZqZ6WyjhlVFGRP2hpqYj5TtUCXkEm2SZB9b8MPEMCdDlfY31Im3g4BTvEWLG f6OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=noWDh3ZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da18si9012054edb.466.2020.09.21.20.13.25; Mon, 21 Sep 2020 20:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=noWDh3ZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729929AbgIVCgF (ORCPT + 99 others); Mon, 21 Sep 2020 22:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729924AbgIVCgF (ORCPT ); Mon, 21 Sep 2020 22:36:05 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC1AC061755; Mon, 21 Sep 2020 19:36:05 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id x22so6258398pfo.12; Mon, 21 Sep 2020 19:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yxKIyBLT5u8uwfgnqH40ev+Mr1LACz2e+jVMDRAal6w=; b=noWDh3ZC2u8vSs1HCTAdPIjLJ1WHipmYM3lFWjo9ZBKbSoN02GaaKK54x8KPhSdmEm M8C5mwI64iI6nQpGikVHOAHk7UwkzyZkUMrjizdAIO3YzkuWPpaHZqSdiJBkxnlGfkcq R+xgylD0xYC9DMIU/VRTbzUx6aD9fN+DKaIPhukcrekstTm3iOl9hA+/angESIOBhNEn RRzGYAtbIJ/Y/UodQEFVkxpYEHFlorZmMfmLirDzNdZ1CRPLF3/l+yjvnFKmmEQ6HD8N 4UOL8Hkor/Stw7bImXg8TZ7umaY7OATbazGIUWTH4nTPqQCGE2bh2KAzxtzpibqmHeDY LXqg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=yxKIyBLT5u8uwfgnqH40ev+Mr1LACz2e+jVMDRAal6w=; b=AKpFyxDuYR73k7eRonp5n2wdpLu2F8K9VI0kSI9sil+Koj6VvaFihYjTE3fiQLBwzb 6jDl6aDzqcScj3nwxg5UjRBapzTaQOd/VNP+44BD+Y/MuhqJhgalycjX1emlMqgszqFM 5pVBtNauKmpPqDR3KDoTxgWwRAf6Ti4L0o52X3HRNQUGY46bJgDJWfjWK8mJkXcff0hw AsY0FAYK1bvv1yICONsjPJ/vRGMTvDF2peECi0GXNdgPY8UNHNxYUQqkncVyphK2jAkt pfq8/LTPAdWnSCnnN85F++7TiDVUzo9haiCriyAFb8LiC4UUlml2hjRYKhJXVxwer9NZ 3J3w== X-Gm-Message-State: AOAM5329ktfnfXx1111NwS2kBE1mAZTbyPfiIPJgFxAvE10WpWziFsBw BoLG1TfxmP7fdsKpv8Ofv2XXJgSendZ5qQ== X-Received: by 2002:a62:5586:0:b029:13e:d13d:a12c with SMTP id j128-20020a6255860000b029013ed13da12cmr2421699pfb.20.1600742164436; Mon, 21 Sep 2020 19:36:04 -0700 (PDT) Received: from sol.lan (106-69-189-59.dyn.iinet.net.au. [106.69.189.59]) by smtp.gmail.com with ESMTPSA id j19sm13321390pfi.51.2020.09.21.19.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 19:36:03 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org, andy.shevchenko@gmail.com Cc: arnd@arndb.de, Kent Gibson Subject: [PATCH v9 11/20] gpiolib: cdev: support GPIO_V2_LINE_SET_VALUES_IOCTL Date: Tue, 22 Sep 2020 10:31:42 +0800 Message-Id: <20200922023151.387447-12-warthog618@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200922023151.387447-1-warthog618@gmail.com> References: <20200922023151.387447-1-warthog618@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for the GPIO_V2_LINE_SET_VALUES_IOCTL. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index debd3b277523..ba951f74e569 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -813,6 +813,65 @@ static long linereq_get_values(struct linereq *lr, void __user *ip) return 0; } +static long linereq_set_values_unlocked(struct linereq *lr, + struct gpio_v2_line_values *lv) +{ + DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); + struct gpio_desc **descs; + unsigned int i, didx, num_set; + int ret; + + bitmap_zero(vals, GPIO_V2_LINES_MAX); + for (num_set = 0, i = 0; i < lr->num_lines; i++) { + if (lv->mask & BIT_ULL(i)) { + if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) + return -EPERM; + if (lv->bits & BIT_ULL(i)) + __set_bit(num_set, vals); + num_set++; + descs = &lr->lines[i].desc; + } + } + if (num_set == 0) + return -EINVAL; + + if (num_set != 1) { + /* build compacted desc array and values */ + descs = kmalloc_array(num_set, sizeof(*descs), GFP_KERNEL); + if (!descs) + return -ENOMEM; + for (didx = 0, i = 0; i < lr->num_lines; i++) { + if (lv->mask & BIT_ULL(i)) { + descs[didx] = lr->lines[i].desc; + didx++; + } + } + } + ret = gpiod_set_array_value_complex(false, true, num_set, + descs, NULL, vals); + + if (num_set != 1) + kfree(descs); + return ret; +} + +static long linereq_set_values(struct linereq *lr, void __user *ip) +{ + struct gpio_v2_line_values lv; + int ret; + + if (copy_from_user(&lv, ip, sizeof(lv))) + return -EFAULT; + + mutex_lock(&lr->config_mutex); + + ret = linereq_set_values_unlocked(lr, &lv); + + mutex_unlock(&lr->config_mutex); + + return ret; +} + static long linereq_set_config_unlocked(struct linereq *lr, struct gpio_v2_line_config *lc) { @@ -889,6 +948,8 @@ static long linereq_ioctl(struct file *file, unsigned int cmd, if (cmd == GPIO_V2_LINE_GET_VALUES_IOCTL) return linereq_get_values(lr, ip); + else if (cmd == GPIO_V2_LINE_SET_VALUES_IOCTL) + return linereq_set_values(lr, ip); else if (cmd == GPIO_V2_LINE_SET_CONFIG_IOCTL) return linereq_set_config(lr, ip); -- 2.28.0