From patchwork Tue Sep 25 11:29:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 974359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="hfGMygxF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42KJlF5w9Kz9s9G for ; Tue, 25 Sep 2018 21:30:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729008AbeIYRhB (ORCPT ); Tue, 25 Sep 2018 13:37:01 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33240 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728748AbeIYRhB (ORCPT ); Tue, 25 Sep 2018 13:37:01 -0400 Received: by mail-wr1-f65.google.com with SMTP id f10-v6so1940896wrs.0 for ; Tue, 25 Sep 2018 04:29:53 -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; bh=GouxdyTHU9i9Loy0LmNBdxtdwBLssrPOdktLXVPYhow=; b=hfGMygxFYqaX14WLWI7AXYI/4ik6XgHwO51hW5u/tEJxcV6gzCm0tbWSXIWDywiCLM jB2FB33tF0QN/PGQl2WzxDO4qYc6cjbMALTxWLhYgfAPy9eWWX6Mkayh7Me+FGvGqREX 72BN5tO3H6loDOsuv5E1VpjcIKxcNwxJ9ny2i/7XWIbAjY7zgaq4OPY0sW/J6H1fsJfv zsqo+pK8kHPHppocaIyUjeEsbH+1pIHSBncprcI9Qkxbez83IOdHPhWXmlXeeeMzquB+ VIqCIl9BGcjHVNpv9E5UDnd/nQpf9uRQmU9vJyndtCdzvhzxoRqRSnkduBPyoDZE7Gjd 2BdQ== 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=GouxdyTHU9i9Loy0LmNBdxtdwBLssrPOdktLXVPYhow=; b=a2FdxLg0O2+KCUD8qV0g1jWLJ4o1IyJ1htWHWkamNWBf/K7LDawMS1I4LARWn2412H N78zQ9YZVXJPiccllTCpeRBpw945obREg0QtwrBXCi9F/2j2HSalx2kO/jnOlg7uwS0o QDcKUEFR6M6/bjKGVnuXvA/mRcdEKlBLL/kL1v4tACb0m1naHG1uGnhWuxptUbc28qNl UPn1eTGZh/dhMzcjnCApRE0wMk1B6FHtv3PUGLIO7LRI03XEPtwu2DAH1YoVMADlrZFd HG5UFpGKWCN23xOnClr+niJRJGzxra3arENpFnTmbi17hQhPiVuPDWg+G3Q+WCuLi1m/ LsGA== X-Gm-Message-State: ABuFfojwwxXcHSZZN8QzUNS32wbKH6U2N8+8LgKqCx8qL8pIFW3GTcRY SenvJ76On2KYj4eN/F8ql0nRFA== X-Google-Smtp-Source: ACcGV60eTlojAAuvYbOVRCHTras4nZ76gjTg+AHFkvmsvsV3crXuZG5D3Y2fiINfx95lvCe3H2VDtA== X-Received: by 2002:a5d:47c1:: with SMTP id l1-v6mr563666wrs.188.1537874993238; Tue, 25 Sep 2018 04:29:53 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id i9-v6sm1705670wro.82.2018.09.25.04.29.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 04:29:52 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Bamvor Jian Zhang , Vincent Whitchurch , Mika Westerberg , Rob Herring Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2] gpio: mockup: use device properties instead of platform_data Date: Tue, 25 Sep 2018 13:29:46 +0200 Message-Id: <20180925112946.30629-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some users want to introduce device tree support to the mockup driver. Let's make it easier by switching to using generic device properties. The driver stays compatible with previous use cases and after this conversion there'll be no need to change the way probing of mockup GPIO chips works. Tested with libgpiod test suite. Signed-off-by: Bartosz Golaszewski --- v1 -> v2: - dropped an unnecessary check when reading the base gpio number property drivers/gpio/gpio-mockup.c | 82 ++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index d66b7a768ecd..8269cffc2967 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "gpiolib.h" @@ -28,6 +29,8 @@ * of GPIO lines. */ #define GPIO_MOCKUP_MAX_RANGES (GPIO_MOCKUP_MAX_GC * 2) +/* Maximum of three properties + the sentinel. */ +#define GPIO_MOCKUP_MAX_PROP 4 #define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__) @@ -59,13 +62,6 @@ struct gpio_mockup_dbgfs_private { int offset; }; -struct gpio_mockup_platform_data { - int base; - int ngpio; - int index; - bool named_lines; -}; - static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES]; static int gpio_mockup_num_ranges; module_param_array(gpio_mockup_ranges, int, &gpio_mockup_num_ranges, 0400); @@ -255,26 +251,37 @@ static int gpio_mockup_name_lines(struct device *dev, static int gpio_mockup_probe(struct platform_device *pdev) { - struct gpio_mockup_platform_data *pdata; struct gpio_mockup_chip *chip; struct gpio_chip *gc; - int rv, base, ngpio; struct device *dev; - char *name; + const char *name; + int rv, base; + u16 ngpio; dev = &pdev->dev; - pdata = dev_get_platdata(dev); - base = pdata->base; - ngpio = pdata->ngpio; + + rv = device_property_read_u32(dev, "gpio-base", &base); + if (rv) + base = -1; + + rv = device_property_read_u16(dev, "nr-gpios", &ngpio); + if (rv) + return rv; + + rv = device_property_read_string(dev, "chip-name", &name); + if (rv) + name = NULL; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - name = devm_kasprintf(dev, GFP_KERNEL, "%s-%c", - pdev->name, pdata->index); - if (!name) - return -ENOMEM; + if (!name) { + name = devm_kasprintf(dev, GFP_KERNEL, + "%s-%c", pdev->name, pdev->id + 'A'); + if (!name) + return -ENOMEM; + } gc = &chip->gc; gc->base = base; @@ -295,7 +302,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (!chip->lines) return -ENOMEM; - if (pdata->named_lines) { + if (device_property_read_bool(dev, "named-gpio-lines")) { rv = gpio_mockup_name_lines(dev, chip); if (rv) return rv; @@ -339,9 +346,11 @@ static void gpio_mockup_unregister_pdevs(void) static int __init gpio_mockup_init(void) { - int i, num_chips, err = 0, index = 'A'; - struct gpio_mockup_platform_data pdata; + struct property_entry properties[GPIO_MOCKUP_MAX_PROP]; + int i, prop, num_chips, err = 0, base; + struct platform_device_info pdevinfo; struct platform_device *pdev; + u16 ngpio; if ((gpio_mockup_num_ranges < 2) || (gpio_mockup_num_ranges % 2) || @@ -371,17 +380,28 @@ static int __init gpio_mockup_init(void) } for (i = 0; i < num_chips; i++) { - pdata.index = index++; - pdata.base = gpio_mockup_range_base(i); - pdata.ngpio = pdata.base < 0 - ? gpio_mockup_range_ngpio(i) - : gpio_mockup_range_ngpio(i) - pdata.base; - pdata.named_lines = gpio_mockup_named_lines; - - pdev = platform_device_register_resndata(NULL, - GPIO_MOCKUP_NAME, - i, NULL, 0, &pdata, - sizeof(pdata)); + memset(properties, 0, sizeof(properties)); + memset(&pdevinfo, 0, sizeof(pdevinfo)); + prop = 0; + + base = gpio_mockup_range_base(i); + if (base >= 0) + properties[prop++] = PROPERTY_ENTRY_U32("gpio-base", + base); + + ngpio = base < 0 ? gpio_mockup_range_ngpio(i) + : 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"); + + pdevinfo.name = GPIO_MOCKUP_NAME; + pdevinfo.id = i; + pdevinfo.properties = properties; + + pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { gpio_mockup_err("error registering device"); platform_driver_unregister(&gpio_mockup_driver);