Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp240185pxk; Thu, 24 Sep 2020 04:40:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe3QOmjZKlYhn2bOfvZcuau2EidUX7D3vli24g1GcI/3fI82s+HOpQo9puqiI2+yLXQgub X-Received: by 2002:a17:906:a093:: with SMTP id q19mr490891ejy.295.1600947658930; Thu, 24 Sep 2020 04:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600947658; cv=none; d=google.com; s=arc-20160816; b=U44dEiPM1mGZIfqdUyDuGHQC7J3XbS/H13bVrp39iRPILn87HCXyVVnlMIFIwSg1wO GquqmlKKvLyU1QWJFrw6G6FvnlNJ2jGgDh4QAYN2umgaUCw9h8/2BQQHp36M/o1obmyI 3y3wlUSpV9hwE2uQ6Rqf6LLHKqX2jhVf+YEvHioTSlE2lE3K/UJrg/kb4rqxDxJOEmsJ zobCMRfcYRBOaQI4rM1WBgOn9umrqjGE2eMvDa8wAkew2vmlnr7olSXPVvVGrw9TEQDT iIGINkleezs6PePvG2ycCVyJBgGMhzopXFRzWb4/y2O/CRoQ0R/m65SX5ik40IYPq9yl yOUg== 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=iVGXPtrofifr0EKk808e6soMrHsX0INLF+uZEESKl5Y=; b=nYkJ3wWLkS7AgRG9HnZXmf9PVFIACSF3SJBSngF1cLsQU1mrYx2NEE/z+Q2DFPFUJX QYmANEb6L5ROqvNrtsAjYREcG61Okc52gj9vcTLYE6gv5dqfU9aZF/fIYxsv3Qy7GVuY FF7eRBB7fSS80RR+OCWcw4yiDMuaasDWYAqMcMSmVXu0kYYvCGeCWtBIxJz+oKVCdJpf wVKH/qYgL4PWyXKYuZCZ2iohJ5MLkFMwFbj3Hqv0qbgOdN5rdOVvQyTzz8cqCT7+vZPL VA1mSe+ZwPprArb+jQbTBBxGO3xjyGaIP7LWYiOBdOh7p9Ye+S0KojUlkspHa6bvxSk7 bYbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=UFTTEf9B; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si1699906ejo.316.2020.09.24.04.40.34; Thu, 24 Sep 2020 04:40:58 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=UFTTEf9B; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727584AbgIXLjO (ORCPT + 99 others); Thu, 24 Sep 2020 07:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727589AbgIXLjD (ORCPT ); Thu, 24 Sep 2020 07:39:03 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42C19C0613D4 for ; Thu, 24 Sep 2020 04:39:03 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id k15so3413614wrn.10 for ; Thu, 24 Sep 2020 04:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iVGXPtrofifr0EKk808e6soMrHsX0INLF+uZEESKl5Y=; b=UFTTEf9BWbHqjwQYp0mES49EUeBixSGdVgi1ewRSl//tj1LtzGRiw+vR4iGOClKzS4 i4a4/y5X9VHhYmOnX7mITKIMqprPZ41Ll/49iwUZaobJVdbN4CnYP3nhWj8ORFesschL l9/EY8fpds2AdnDtlrf/a2td8mWjIeya0OxRtHj5FM0FFSj8+FHsYsst3C2cRu2uOGG+ PEjg9stni/Mf0sdlBRB03Su1k/Ohi28pKZvBtssWzaDnTcWR7GdgUBxnDHVlHfIwAOgm Gbsj5K+I7+qVr2q2I07L2C5TOCldD1jwOQBer9XYCspKkWM6SdlRk5TV2YXYPNPshpc0 7B1g== 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=iVGXPtrofifr0EKk808e6soMrHsX0INLF+uZEESKl5Y=; b=TWLNGE5V4gIQF2b7tJT3ug3EKupP0adftHb5K+PXtQd08MRxGx/WqeXN/5HgyzSvEr vbcwg2j+73WtXPyanG3ggu9qb9ddoaBimm0XbwRE/wvv1QYfCrd0r0di2nbzPMcqFOhV oTTF5GA5MkOi+PHZIH9plXeDdJ8XxOrlifsYgy0ZIKCcOCuVshuMB/sAaYF/Rqq2EOUc P5ycwQw7GAbha9wrPRoeJakPo6OYIaPdSCabtAvtPiBbZqsIrmNw7Sv85chuHMZXtd4K Y1Kt8h2idMnAr7OS+cj0wyrqeZ2HCs2bfwCeHNB/9aa+5sUuEgci4obPt58F03KpCc+z vTIg== X-Gm-Message-State: AOAM530E/LyUaYcRd8ZQHvC5e6LlN0DNxLoZY1I/q/pn24ne7LFToEyv AqjAMMobradP336J2OEC1fMyXg== X-Received: by 2002:adf:b306:: with SMTP id j6mr4432039wrd.279.1600947541914; Thu, 24 Sep 2020 04:39:01 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-68-20.w2-15.abo.wanadoo.fr. [2.15.159.20]) by smtp.gmail.com with ESMTPSA id y207sm3390133wmc.17.2020.09.24.04.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:39:01 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 8/9] gpio: mockup: use the generic 'gpio-line-names' property Date: Thu, 24 Sep 2020 13:38:41 +0200 Message-Id: <20200924113842.11670-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200924113842.11670-1-brgl@bgdev.pl> References: <20200924113842.11670-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski GPIO line names are currently created by the driver from the chip label. We'll want to support custom formats for line names (for instance: to name all lines the same) for user-space tests so create them in the module init function and pass them to the driver using the standard 'gpio-line-names' property. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 70 +++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 5b2686f9e07d..c35fd05de395 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "gpiolib.h" @@ -374,29 +375,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, } } -static int gpio_mockup_name_lines(struct device *dev, - struct gpio_mockup_chip *chip) -{ - struct gpio_chip *gc = &chip->gc; - char **names; - int i; - - names = devm_kcalloc(dev, gc->ngpio, sizeof(char *), GFP_KERNEL); - if (!names) - return -ENOMEM; - - for (i = 0; i < gc->ngpio; i++) { - names[i] = devm_kasprintf(dev, GFP_KERNEL, - "%s-%d", gc->label, i); - if (!names[i]) - return -ENOMEM; - } - - gc->names = (const char *const *)names; - - return 0; -} - static void gpio_mockup_dispose_mappings(void *data) { struct gpio_mockup_chip *chip = data; @@ -464,12 +442,6 @@ static int gpio_mockup_probe(struct platform_device *pdev) for (i = 0; i < gc->ngpio; i++) chip->lines[i].dir = GPIO_LINE_DIRECTION_IN; - if (device_property_read_bool(dev, "named-gpio-lines")) { - rv = gpio_mockup_name_lines(dev, chip); - if (rv) - return rv; - } - chip->irq_sim_domain = devm_irq_domain_create_sim(dev, NULL, gc->ngpio); if (IS_ERR(chip->irq_sim_domain)) @@ -510,6 +482,27 @@ static void gpio_mockup_unregister_pdevs(void) } } +static __init char **gpio_mockup_make_line_names(const char *label, + unsigned int num_lines) +{ + unsigned int i; + char **names; + + names = kcalloc(num_lines + 1, sizeof(char *), GFP_KERNEL); + if (!names) + return NULL; + + for (i = 0; i < num_lines; i++) { + names[i] = kasprintf(GFP_KERNEL, "%s-%u", label, i); + if (!names[i]) { + kfree_strarray(names, i); + return NULL; + } + } + + return names; +} + static int __init gpio_mockup_init(void) { struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; @@ -517,6 +510,7 @@ static int __init gpio_mockup_init(void) struct platform_device_info pdevinfo; struct platform_device *pdev; char chip_label[32]; + char **line_names; u16 ngpio; if ((gpio_mockup_num_ranges < 2) || @@ -549,6 +543,7 @@ static int __init gpio_mockup_init(void) memset(properties, 0, sizeof(properties)); memset(&pdevinfo, 0, sizeof(pdevinfo)); prop = 0; + line_names = NULL; snprintf(chip_label, sizeof(chip_label), "gpio-mockup-%c", i + 'A'); @@ -564,15 +559,26 @@ static int __init gpio_mockup_init(void) : gpio_mockup_range_ngpio(i) - base; properties[prop++] = PROPERTY_ENTRY_U16("nr-gpios", ngpio); - if (gpio_mockup_named_lines) - properties[prop++] = PROPERTY_ENTRY_BOOL( - "named-gpio-lines"); + if (gpio_mockup_named_lines) { + line_names = gpio_mockup_make_line_names(chip_label, + ngpio); + if (!line_names) { + platform_driver_unregister(&gpio_mockup_driver); + gpio_mockup_unregister_pdevs(); + return -ENOMEM; + } + + properties[prop++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( + "gpio-line-names", + line_names, ngpio); + } pdevinfo.name = "gpio-mockup"; pdevinfo.id = i; pdevinfo.properties = properties; pdev = platform_device_register_full(&pdevinfo); + kfree_strarray(line_names, line_names ? ngpio : 0); if (IS_ERR(pdev)) { pr_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver); -- 2.26.1