From patchwork Tue Nov 22 07:11:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 25020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2823927wrr; Wed, 23 Nov 2022 06:29:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UBlbLtqvLKUE7OLMfH1FFX6OZpHC6lIJBQalL3LGmwokO6nEAH0NIbF7uWjTCjiFYNxOx X-Received: by 2002:a17:907:c787:b0:7ad:8035:ae3d with SMTP id tz7-20020a170907c78700b007ad8035ae3dmr15563449ejc.46.1669213750242; Wed, 23 Nov 2022 06:29:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669213750; cv=none; d=google.com; s=arc-20160816; b=nZlUyK7eTLtnBWtJ26hRa4YUaJvVuUq37/0ZonKsFo3B0tRzSo4BxoqXtdLqiPuFNu kNpkK8OyRMEexlgouPByTdZH6GPizVh6O6+/uI9Bn6Jls3pkUXC6FqFk5EmB7pxEy3Bg XvX8yzecPh01rD9QX6gTQpWG3cXjnYNvT3Wfzq9y6JKC2Un047GlTMD+YNkdbeNJ7stM HS3hEM8M6ajFPrIecY9v18TrKDi3tKZQ6BFzXhBuOq2YVDC70FeReWDTwRYWcO2X3h7g O7P7lsW8Iau3Dt7UAHcDP/h4QVit1Jy9KxEggbfSDjWE7raTXRFkoAiqinCv09/AumqV bT1w== 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=birQUGg9QWXN0aePteHiAYkZnp+VjTQ5j5vWqQ7GHnU=; b=uyi5POSqNnwEEzUQYQGta7nB76nFdJsPucSqDKrvY92N7Bnmt77nzTJ8PcBcJKSIQg E/9WAcvESSql3EGGyJ9z1zxIS+ahMjnZ1LNZTsErMb7IFKsP09fYNXs4feAj0baqnvOl n9Zy1TbwTdQRpLKX9wvcp7r4uNB8vjHjT2qP43CLqOHKRLj+l961pHa7KzZbsrQ499xL bVH3iYNkg2xFT4S6jnExKsrKR/IwC8nV3voLSekMkncmf/wdqueM/CgaV+eHM6weLtUu USgsPLPCbxQxXC+6xdsK7gKL1zp25D2eO0/k3PPhqIgsSJkYhvVcDiXMtJclYJSrmLBN UczQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DNbNCdND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a056402280900b0046189831142si16183752ede.7.2022.11.23.06.28.43; Wed, 23 Nov 2022 06:29:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DNbNCdND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236380AbiKWO1b (ORCPT + 99 others); Wed, 23 Nov 2022 09:27:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238136AbiKWO0R (ORCPT ); Wed, 23 Nov 2022 09:26:17 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7681E2E69C for ; Wed, 23 Nov 2022 06:25:28 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id d7so12483275qkk.3 for ; Wed, 23 Nov 2022 06:25:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=birQUGg9QWXN0aePteHiAYkZnp+VjTQ5j5vWqQ7GHnU=; b=DNbNCdNDnu5unW5EFQHQ8KM5JqtzxntLQAZOfSn2jVK19k+uJ/WFw8rj9KwvnFK7JD hmuVkTRpfIrydwjgxK1J8HpGlVZOL+7UurKpj4+/ZGdgil68vev2AniFKdGlYzvlGiox O7IooOhocH1PYtA2+IeKB6t2RejFKrKYpezV62WV0KRlA+jr243LrARCtRCmyFsYj8/c Q/aBvN4kwH1KQMN8Hle4gNhtDbk20rPMWMEcC2tMadws6BFiAAczZrtgG5B4Ate4I7Qy u99mj7vp3CJ0Sea/w4s0nH68FY3Lr+bJjGSOLaq7BxIsPCz6lJVcFYmDQLn0tiR7BAA9 MMZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=birQUGg9QWXN0aePteHiAYkZnp+VjTQ5j5vWqQ7GHnU=; b=Fs+Pbc6Xt0FvRbL4aI/s9v99Nj7FweOfVEOVdju6gdISGwTpqE51g+Z/bV3o/lYhZ/ GA71jHyvpbILC+CYwhDwc7YYqTo3Jq1ka5rVqK95Dt7RK0jLG0Rcyje7PMxOyov64mgN 94BxbmuuGKs2dWlLuVraYQFYl+cjEs+4mPLolqLkz8nWWl5dmC4TaxC8tBixC0KU4rxu q3Hn0MDgpYLJUPp1a7thUkRJCZtAIawnhlRW9eZMzNNQBVGwOEtoFm5W2JYt1ShMbNKm i8+bphRz8YzlY78Oc5DCLJTcYIRSuhTKxV2L+VBKOIRKNFwBxFWuKPLwLn9odo81Mvbw cXRQ== X-Gm-Message-State: ANoB5pmxTB/zGZ1KTq5/f3ShLZj6fBizCbgM5HIn27f0wGeV5RTreZ3D J73+sJJXSxgBgUFJmjHBgdB/7g== X-Received: by 2002:a05:620a:51ca:b0:6ec:fa04:d97c with SMTP id cx10-20020a05620a51ca00b006ecfa04d97cmr9001010qkb.764.1669213527332; Wed, 23 Nov 2022 06:25:27 -0800 (PST) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id b28-20020a05620a127c00b006f9c2be0b4bsm11718802qkl.135.2022.11.23.06.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 06:25:26 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org, brgl@bgdev.pl Cc: andriy.shevchenko@linux.intel.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, michael@walle.cc, broonie@kernel.org, William Breathitt Gray Subject: [PATCH v3 8/9] gpio: gpio-mm: Migrate to regmap API Date: Tue, 22 Nov 2022 02:11:05 -0500 Message-Id: <4c7d582e4078e265d7a8d39d3aa746e573233a4e.1669100542.git.william.gray@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750297477292057778?= X-GMAIL-MSGID: =?utf-8?q?1750297477292057778?= The regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver. The gpio-mm module is migrated to the new i8255 library interface leveraging the gpio-regmap API. Suggested-by: Andy Shevchenko Signed-off-by: William Breathitt Gray Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-gpio-mm.c | 153 +++++++----------------------------- 1 file changed, 29 insertions(+), 124 deletions(-) diff --git a/drivers/gpio/gpio-gpio-mm.c b/drivers/gpio/gpio-gpio-mm.c index 2689671b6b01..ba8847485660 100644 --- a/drivers/gpio/gpio-gpio-mm.c +++ b/drivers/gpio/gpio-gpio-mm.c @@ -8,13 +8,13 @@ */ #include #include -#include -#include #include #include #include #include #include +#include +#include #include "gpio-i8255.h" @@ -30,83 +30,22 @@ MODULE_PARM_DESC(base, "Diamond Systems GPIO-MM base addresses"); #define GPIOMM_NUM_PPI 2 -/** - * struct gpiomm_gpio - GPIO device private data structure - * @chip: instance of the gpio_chip - * @ppi_state: Programmable Peripheral Interface group states - * @ppi: Programmable Peripheral Interface groups - */ -struct gpiomm_gpio { - struct gpio_chip chip; - struct i8255_state ppi_state[GPIOMM_NUM_PPI]; - struct i8255 __iomem *ppi; +static const struct regmap_range gpiomm_volatile_ranges[] = { + i8255_volatile_regmap_range(0x0), i8255_volatile_regmap_range(0x4), +}; +static const struct regmap_access_table gpiomm_volatile_table = { + .yes_ranges = gpiomm_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(gpiomm_volatile_ranges), +}; +static const struct regmap_config gpiomm_regmap_config = { + .reg_bits = 8, + .reg_stride = 1, + .val_bits = 8, + .io_port = true, + .max_register = 0x7, + .volatile_table = &gpiomm_volatile_table, + .cache_type = REGCACHE_FLAT, }; - -static int gpiomm_gpio_get_direction(struct gpio_chip *chip, - unsigned int offset) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - if (i8255_get_direction(gpiommgpio->ppi_state, offset)) - return GPIO_LINE_DIRECTION_IN; - - return GPIO_LINE_DIRECTION_OUT; -} - -static int gpiomm_gpio_direction_input(struct gpio_chip *chip, - unsigned int offset) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - i8255_direction_input(gpiommgpio->ppi, gpiommgpio->ppi_state, offset); - - return 0; -} - -static int gpiomm_gpio_direction_output(struct gpio_chip *chip, - unsigned int offset, int value) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - i8255_direction_output(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, - value); - - return 0; -} - -static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - return i8255_get(gpiommgpio->ppi, offset); -} - -static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, - unsigned long *bits) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - i8255_get_multiple(gpiommgpio->ppi, mask, bits, chip->ngpio); - - return 0; -} - -static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, - int value) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - i8255_set(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, value); -} - -static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, - unsigned long *mask, unsigned long *bits) -{ - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); - - i8255_set_multiple(gpiommgpio->ppi, gpiommgpio->ppi_state, mask, bits, - chip->ngpio); -} #define GPIOMM_NGPIO 48 static const char *gpiomm_names[GPIOMM_NGPIO] = { @@ -120,30 +59,11 @@ static const char *gpiomm_names[GPIOMM_NGPIO] = { "Port 2C2", "Port 2C3", "Port 2C4", "Port 2C5", "Port 2C6", "Port 2C7", }; -static void gpiomm_init_dio(struct i8255 __iomem *const ppi, - struct i8255_state *const ppi_state) -{ - const unsigned long ngpio = 24; - const unsigned long mask = GENMASK(ngpio - 1, 0); - const unsigned long bits = 0; - unsigned long i; - - /* Initialize all GPIO to output 0 */ - for (i = 0; i < GPIOMM_NUM_PPI; i++) { - i8255_mode0_output(&ppi[i]); - i8255_set_multiple(&ppi[i], &ppi_state[i], &mask, &bits, ngpio); - } -} - static int gpiomm_probe(struct device *dev, unsigned int id) { - struct gpiomm_gpio *gpiommgpio; const char *const name = dev_name(dev); - int err; - - gpiommgpio = devm_kzalloc(dev, sizeof(*gpiommgpio), GFP_KERNEL); - if (!gpiommgpio) - return -ENOMEM; + struct i8255_regmap_config config = {0}; + void __iomem *regs; if (!devm_request_region(dev, base[id], GPIOMM_EXTENT, name)) { dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", @@ -151,34 +71,19 @@ static int gpiomm_probe(struct device *dev, unsigned int id) return -EBUSY; } - gpiommgpio->ppi = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); - if (!gpiommgpio->ppi) + regs = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); + if (!regs) return -ENOMEM; - gpiommgpio->chip.label = name; - gpiommgpio->chip.parent = dev; - gpiommgpio->chip.owner = THIS_MODULE; - gpiommgpio->chip.base = -1; - gpiommgpio->chip.ngpio = GPIOMM_NGPIO; - gpiommgpio->chip.names = gpiomm_names; - gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction; - gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; - gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; - gpiommgpio->chip.get = gpiomm_gpio_get; - gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; - gpiommgpio->chip.set = gpiomm_gpio_set; - gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; - - i8255_state_init(gpiommgpio->ppi_state, GPIOMM_NUM_PPI); - gpiomm_init_dio(gpiommgpio->ppi, gpiommgpio->ppi_state); - - err = devm_gpiochip_add_data(dev, &gpiommgpio->chip, gpiommgpio); - if (err) { - dev_err(dev, "GPIO registering failed (%d)\n", err); - return err; - } + config.map = devm_regmap_init_mmio(dev, regs, &gpiomm_regmap_config); + if (IS_ERR(config.map)) + return PTR_ERR(config.map); + + config.parent = dev; + config.num_ppi = GPIOMM_NUM_PPI; + config.names = gpiomm_names; - return 0; + return devm_i8255_regmap_register(dev, &config); } static struct isa_driver gpiomm_driver = {