Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2692733rwl; Mon, 27 Mar 2023 04:06:08 -0700 (PDT) X-Google-Smtp-Source: AKy350b6M8JJ52cyseRhyfMf3Q9GttnQA8QumuCJ2qr77nTIkvvAvgKo6kr2UmNwQJ3zydXMraRd X-Received: by 2002:a17:90b:1e08:b0:23d:1118:4e98 with SMTP id pg8-20020a17090b1e0800b0023d11184e98mr12246702pjb.23.1679915168224; Mon, 27 Mar 2023 04:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679915168; cv=none; d=google.com; s=arc-20160816; b=h7aUA7eCridkETLeFa56pDuwYUvtzd2tJUJLQo8k+8I3y599pLPXhnGFXZYAs8CI8m sBsVpEASJo3tYxDKmHRirHu2sGPOmu1ur/ofXuF1gG8e0cUAy24ugzBjjyUc62cevKzj GkEIPdRxd+e/SNs66HH5ozUTjqolOVor9zuMpo9oU1RTntSgtnYSYD6rEoyt5zFn3nQT 4Can7RHK6OIl8jLYz+bDTy18DASQrmFok8iYBjxQmcxStMQ/gN0QamefzcdYOhB1Ohh0 xLQuvNOJ0AuCJTKlOAUXoJRIn34z7e5l8NB0wYyXP5NfQxANvBZZI2Qdl3s57TZv6nd5 Wbxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=l9xMWB7hwO8B9AwuNZZ69aQPYLZL1bhanztE1dJH3fs=; b=D5FSzB0iD51UE3x+NGhEUVDadpITzR6fjWe/XOkYp0l0bUqysz3eItM1Y0b0Ykbr6a 8URh4Kl5KPTp5WMJgSp5R/Br4LjDWaFbNpWF/LXCW26QxxYtokNX8W5rkthB5mohUWfq oZZyFqKjh7eNwEkD6vzAhtQNyCX5I4m2SZ4NVgNRLr5SzEPML+xbDXeBdjBtlpdRdrfk ArUzht17uevAaQj4zPrlJAYHce2xNlV67FRVrB5ci5VjU7OeVR0cmWmyA59Qgq4Su6jC chtaeWIDYUdOB5WocwaFk+zWNEdS1K7xbvLhi2Quscv6WX324RupYil3ItYMWUds3j6p W+XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IMAr4m20; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a17090301d200b0019a9f8bdba0si1775026plh.62.2023.03.27.04.05.54; Mon, 27 Mar 2023 04:06:08 -0700 (PDT) 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=@intel.com header.s=Intel header.b=IMAr4m20; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbjC0K7w (ORCPT + 99 others); Mon, 27 Mar 2023 06:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjC0K7r (ORCPT ); Mon, 27 Mar 2023 06:59:47 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADB044A0; Mon, 27 Mar 2023 03:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679914786; x=1711450786; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=aJzI+wMPKlXPUgKnnSLNAYwqiP4hDT7bkOx2JUB8ZsU=; b=IMAr4m20fzhnjSR/WaP3nV2bazINcf7U/RNNP3fXS809fhBp+us5P5/V 2atAyJmqSneEVNLkiP9vkmZ7BoM+awM28e4DknexTKSBoSeDT9ceQEoe9 AOmCLK5rClcNJhvfVOEJ2ndV0/GfEnTnDZHSsmapbcIrzyo50sfCDlKYH IGq8vwzJTm0/bou16+NTvNQRoneDA3fJZczOGOG3iPOa7DVPSqtIicZFv 2wimg+HmzY7LbhfXFE4S7RhI1NBJNNEd3W5C6Uz55q2/Iiq2SKDGP6MOt 8aJ2EmlYsMJHhw/21/+iyH7EfAEZcM1XIZ8P81pYcSTNj2mJZ+cUiMEIV Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="319891371" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="319891371" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 03:59:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="747958128" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="747958128" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga008.fm.intel.com with ESMTP; 27 Mar 2023 03:59:40 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pgkZe-009BUh-2x; Mon, 27 Mar 2023 13:59:38 +0300 Date: Mon, 27 Mar 2023 13:59:38 +0300 From: Andy Shevchenko To: William Breathitt Gray Cc: Linus Walleij , Bartosz Golaszewski , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Mark Brown , Arnaud de Turckheim , John Hentges , Jay Dolan , Michael Walle Subject: Re: [PATCH v5 2/3] gpio: pcie-idio-24: Migrate to the regmap API Message-ID: References: <8ae7f448360068172b06fedb6a568373b73521bc.1679845842.git.william.gray@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ae7f448360068172b06fedb6a568373b73521bc.1679845842.git.william.gray@linaro.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_NONE autolearn=unavailable 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 On Sun, Mar 26, 2023 at 12:25:58PM -0400, William Breathitt Gray wrote: > 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. > > For the PCIe-IDIO-24 series of devices, the following BARs are > available: > > BAR[0]: memory mapped PEX8311 > BAR[1]: I/O mapped PEX8311 > BAR[2]: I/O mapped card registers > > There are 24 FET Output lines, 24 Isolated Input lines, and 8 TTL/CMOS > lines (which may be configured for either output or input). The GPIO > lines are exposed by the following card registers: > > Base +0x0-0x2 (Read/Write): FET Outputs > Base +0xB (Read/Write): TTL/CMOS > Base +0x4-0x6 (Read): Isolated Inputs > Base +0x7 (Read): TTL/CMOS > > In order for the device to support interrupts, the PLX PEX8311 internal > PCI wire interrupt and local interrupt input must first be enabled. > > The following card registers for Change-Of-State may be used: > > Base +0x8-0xA (Read): COS Status Inputs > Base +0x8-0xA (Write): COS Clear Inputs > Base +0xB (Read): COS Status TTL/CMOS > Base +0xB (Write): COS Clear TTL/CMOS > Base +0xE (Read/Write): COS Enable > > The COS Enable register is used to enable/disable interrupts and > configure the interrupt levels; each bit maps to a group of eight inputs > as described below: > > Bit 0: IRQ EN Rising Edge IN0-7 > Bit 1: IRQ EN Rising Edge IN8-15 > Bit 2: IRQ EN Rising Edge IN16-23 > Bit 3: IRQ EN Rising Edge TTL0-7 > Bit 4: IRQ EN Falling Edge IN0-7 > Bit 5: IRQ EN Falling Edge IN8-15 > Bit 6: IRQ EN Falling Edge IN16-23 > Bit 7: IRQ EN Falling Edge TTL0-7 > > An interrupt is asserted when a change-of-state matching the interrupt > level configuration respective for a particular group of eight inputs > with enabled COS is detected. > > The COS Status registers may be read to determine which inputs have > changed; if interrupts were enabled, an IRQ will be generated for the > set bits in these registers. Writing the value read from the COS Status > register back to the respective COS Clear register will clear just those > interrupts. ... > Cc: Arnaud de Turckheim > Cc: John Hentges > Cc: Jay Dolan You can use --cc parameter to the `git format-patch`. ... > +static const struct regmap_config pex8311_intcsr_regmap_config = { > + .name = "pex8311_intcsr", > + .reg_bits = 32, > + .reg_stride = 1, > + .reg_base = PLX_PEX8311_PCI_LCS_INTCSR, > + .val_bits = 32, > + .io_port = true, > + .max_register = 0x0, > +}; Do you need regmap lock? If so, what for? ... > +static const struct regmap_config idio_24_regmap_config = { > + .reg_bits = 8, > + .reg_stride = 1, > + .val_bits = 8, > + .io_port = true, > + .max_register = 0xF, > + .wr_table = &idio_24_wr_table, > + .rd_table = &idio_24_rd_table, > + .volatile_table = &idio_24_volatile_table, > + .cache_type = REGCACHE_FLAT, > +}; Ditto. ... > +static int idio_24_set_type_config(unsigned int **const buf, const unsigned int type, > + const struct regmap_irq *const irq_data, const int idx, > + void *const irq_drv_data) > { > + const unsigned int offset = irq_data->reg_offset; > + const unsigned int rising = COS_ENABLE_RISING << offset; > + const unsigned int falling = COS_ENABLE_FALLING << offset; > + const unsigned int mask = COS_ENABLE_BOTH << offset; > + struct idio_24_gpio *const idio24gpio = irq_drv_data; > + unsigned int new; > + unsigned int cos_enable; > + int ret; > + > + switch (type) { > + case IRQ_TYPE_EDGE_RISING: > + new = rising; > + break; > + case IRQ_TYPE_EDGE_FALLING: > + new = falling; > + break; > + case IRQ_TYPE_EDGE_BOTH: > + new = mask; > + break; > + default: > + return -EINVAL; > } > > + raw_spin_lock(&idio24gpio->lock); > > + /* replace old bitmap with new bitmap */ > + idio24gpio->irq_type = (idio24gpio->irq_type & ~mask) | (new & mask); > > + ret = regmap_read(idio24gpio->map, IDIO_24_COS_ENABLE, &cos_enable); > + if (ret) > + goto exit_early; > > + /* if COS is currently enabled then update the edge type */ > + if (cos_enable & mask) { > + ret = regmap_update_bits(idio24gpio->map, IDIO_24_COS_ENABLE, mask, > + idio24gpio->irq_type); > + goto exit_early; > } > +exit_early: More descriptive is to call it exit_unlock: The rule of thumb is to explain what _will_ happen, if we goto $LABEL. > + raw_spin_unlock(&idio24gpio->lock); > > + return ret; > } -- With Best Regards, Andy Shevchenko