From patchwork Fri Apr 13 10:24:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133350 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp572922ljb; Fri, 13 Apr 2018 03:24:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/Q2oah9bjp1wfceQfxQ/AJfoVcH7ChUjeV143R0VLZsIns02a9QF2LWxsZDAFs0YGAZ2V X-Received: by 10.99.116.76 with SMTP id e12mr3617170pgn.270.1523615071578; Fri, 13 Apr 2018 03:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523615071; cv=none; d=google.com; s=arc-20160816; b=z9McXKoPj/jLndBsy695DSgdt5xOmbXeQHW31RWwko/9WRsJbqN1ihUMnXwnPj/TcX FDk7rHkneGqe8C0LC/Z0Eb2i0SSLEnKsrNsOAvLz0fwgoa9nd8LmlMyk6S1jNrHcucqW BO90MqmHqOHnrhiPZOYQKZoA54FToeLbRGLtfzJfSlakXKwjlsOjDLhx8E6ASNQzyg7d Jq3dabkypMpxZpr3kMEmRIWoKnDtQLNIuLKsgO7xirydyTr+Nz2BjBDyOKNpQRU8/B+p MGsSTtCVwkY/4oI4vG/pQaim4K6RecfSk/TUOwVwHmpFOT+QWv7eM1rGO9rAgt0pEsF5 oIUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xTdRn4sOOOzg9vVpng22uOSYrO9COBzbFp8hNWDn/aE=; b=eRriJ0QQNLTMKWsuisQEgjG92/qKt1JWfvGVd37Zd8cgb+9qXx2pZh7uY/hFZ1eLWv EA4OOuCOG70Cgy29Ks4LlE3HfDROvW+4ak1rpx2b4yMTk+H4Io/nzp/1iZA7qjIjCg4t Y92mGsNAWZNFYIUF8Pd7CXr9gVlzRrLEUIezhWmLMshBh6s565at/ZqDs74IDnXtYPhD 0NV6leVBlaE2tAMkk69LA/NCZ5ztETd1ziH8qiQk7tjIIRlCy0vscAzKfTBxNVVN6Ut6 uw0yJLRuKxYeYVooOkLQQhGU2BWPhlq8WXMXlgv6YDoiqm0A05UuQ6t4LiU7NZMFWoFF 41Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KmS2YPrV; 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 44-v6si5101266pla.376.2018.04.13.03.24.31; Fri, 13 Apr 2018 03:24:31 -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=KmS2YPrV; 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 S1753099AbeDMKYa (ORCPT + 5 others); Fri, 13 Apr 2018 06:24:30 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43315 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbeDMKYa (ORCPT ); Fri, 13 Apr 2018 06:24:30 -0400 Received: by mail-lf0-f67.google.com with SMTP id v207-v6so11870196lfa.10 for ; Fri, 13 Apr 2018 03:24:29 -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:in-reply-to:references; bh=4xSDZrFhiVzNg6qzME55uTU6osxICtcjU5z/C/QSRg0=; b=KmS2YPrVmdYxxXdZCzp1Veul3qpngyf4jdcloqc7MvqhU4uLhM6MaP5b/5bypRUXM1 /7VehM+3CN6osJfNil12Z8zpWU3C7sCIOtiTPucuFntVVnMXCDF7yiqyMte7b2yZ8XmC kvQhc+muA1f8TMfaiiUNFXMIiHRl3va/ADTRs= 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; bh=4xSDZrFhiVzNg6qzME55uTU6osxICtcjU5z/C/QSRg0=; b=rVdkQTrNqqSXNuIBK1aAdHNqxBBMnuxFFeWuUe1/Rcxvr6xtqrqeYyn3d9si/E6H0c LNUpMm+ZquHHVgmjlm9kbHuqNUfnggbLQFwdQAOrpy1tjComdnngnJX6Kuxfq8DyjUft XqxdgFJagxFcwDkii7KaCQzfxlxxe84qhmYTTF9tv10E0dPo+zpckVnzYyjgXUmzGU4p wgZaOhmV7D6AqzktOv/sGq0YNF7t6ruVfxzBSJ7nOLMrvs4pdV1ur4ADE9IbwI0mMTbv 7OhLZB6Tx3pEJLc8wMGHpwYkDCc3E+j/aggtKTXnzAqjmQVrefLREk0SPAUAdyUHqYiD hFRQ== X-Gm-Message-State: ALQs6tCR/+ss6wIZYDGzxKYyjbWv0fnqBWw3cLQY1vpBbNJ7E73Xb6av hwEn2ZjS8WDJVMcWqrCBSQMIC6hltxM= X-Received: by 2002:a19:d085:: with SMTP id h127-v6mr7634531lfg.29.1523615068602; Fri, 13 Apr 2018 03:24:28 -0700 (PDT) Received: from genomnajs.payandsurf.com ([192.36.80.8]) by smtp.gmail.com with ESMTPSA id c4sm915360lja.97.2018.04.13.03.24.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 03:24:27 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Keguang Zhang , Jiaxun Yang , Huacai Chen , linux-mips@linux-mips.org Subject: [PATCH 2/3] gpio: loongson: Create a dynamic platform device Date: Fri, 13 Apr 2018 12:24:20 +0200 Message-Id: <20180413102421.23939-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180413102421.23939-1-linus.walleij@linaro.org> References: <20180413102421.23939-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org It is pretty helpful to create some kind of device for backing the GPIO chips, especially when preparing the driver for using GENERIC_GPIO, so let's create a simple platform device and a simple platform device driver and create the gpiochip in the .probe() routine for the device driver. Keep all at the core initcall so the behaviour is the same as before. Cc: Keguang Zhang Cc: Jiaxun Yang Cc: Huacai Chen Cc: linux-mips@linux-mips.org Signed-off-by: Linus Walleij --- drivers/gpio/gpio-loongson.c | 47 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) -- 2.14.3 -- 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/gpio-loongson.c b/drivers/gpio/gpio-loongson.c index 973d82a29442..3c9d4f3ed550 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -97,19 +98,45 @@ static int loongson_gpio_direction_output(struct gpio_chip *chip, return 0; } -static struct gpio_chip loongson_chip = { - .label = "Loongson-gpio-chip", - .direction_input = loongson_gpio_direction_input, - .get = loongson_gpio_get_value, - .direction_output = loongson_gpio_direction_output, - .set = loongson_gpio_set_value, - .base = 0, - .ngpio = LOONGSON_N_GPIO, - .can_sleep = false, +static int loongson_gpio_probe(struct platform_device *pdev) +{ + struct gpio_chip *gc; + struct device *dev = &pdev->dev; + + gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + if (!gc) + return -ENOMEM; + + gc->label = "loongson-gpio-chip"; + gc->base = 0; + gc->ngpio = LOONGSON_N_GPIO; + gc->get = loongson_gpio_get_value; + gc->set = loongson_gpio_set_value; + gc->direction_input = loongson_gpio_direction_input; + gc->direction_output = loongson_gpio_direction_output; + + return gpiochip_add_data(gc, NULL); +} + +static struct platform_driver loongson_gpio_driver = { + .driver = { + .name = "loongson-gpio", + }, + .probe = loongson_gpio_probe, }; static int __init loongson_gpio_setup(void) { - return gpiochip_add_data(&loongson_chip, NULL); + struct platform_device *pdev; + int ret; + + ret = platform_driver_register(&loongson_gpio_driver); + if (ret) { + pr_err("error registering loongson GPIO driver\n"); + return ret; + } + + pdev = platform_device_register_simple("loongson-gpio", -1, NULL, 0); + return PTR_ERR_OR_ZERO(pdev); } postcore_initcall(loongson_gpio_setup);