Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2721875rwl; Mon, 27 Mar 2023 04:31:50 -0700 (PDT) X-Google-Smtp-Source: AK7set+1kudfWKfJZSKLqaJsTBJS+zLKbmqmabZoFZmO7hUFETufldUNeJBORIbfyraHy+Ts3cI1 X-Received: by 2002:a05:6a20:1221:b0:d5:9216:9182 with SMTP id v33-20020a056a20122100b000d592169182mr10684258pzf.9.1679916710101; Mon, 27 Mar 2023 04:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679916710; cv=none; d=google.com; s=arc-20160816; b=VumLGUYxgzx35lk0FblPbaK8Hwolt9y8+ga8Z7gQYvnxtXkhaRBttqsMpGhLqWQiOp jjdm9IWr5cJKu1RNBclz86p9leLa1aPurFR/8v1xFxeD3Cd94n5vYdCOgbiN9Ki+/WiP CGNumGZ+QUj/8FGhpO+frtZfwA9bhnUn3HvToS7j7qt7tH9TvYAmlr7pATQlO2UYHDss OUapb87bdt5fQGUFB/Zrp5+mtduQG64Wb6ll4gC4lHB0tjhHt3NGYQ0hnoVxt+K9Xaa2 CxBGQRADE9FLnJGqu8+jU15ZmPfsP4tX83EGDs+iPuQ49SrSWmZ2Nsqgn1/odQgKP994 hs3A== 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=9uX8vt2PYc487rq3YUXldXmpNm0OhbdOysG+Mxt30UM=; b=PKtdYiijzktc+Zr9OZU0DjE8sDX8vGFA7dip+GiLiKZqM7XLt8I2UDOfZE4jJKKBGx co5Zw7bmx2JVzkSN99c9AeL+eu44z8stSRcHFs3xoihVQRDGTjIg5ti5z8bohtmkgewJ cSy03CVEdkgGOsDixhaHgBEBpc8N3rPg7CNRxEMbOMRORp56HddOmAsG50silhlisJ46 hBCzPHYS7fG4y2SbV8OtKeiB+fEK84CGOK18loIXdP+5eJVL9OcHRo0xy+qMx8rNetf9 TfUgxTXTLqFZasoEIo9TGNb3RR8aPjVxThLwmzfL3chCEzHhZU509wUevmJfRYbh2Vnu 2lVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bMIo5+P9; 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 191-20020a6304c8000000b004fb171df693si28366145pge.352.2023.03.27.04.31.38; Mon, 27 Mar 2023 04:31:50 -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=bMIo5+P9; 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 S232267AbjC0L0n (ORCPT + 99 others); Mon, 27 Mar 2023 07:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjC0L0m (ORCPT ); Mon, 27 Mar 2023 07:26:42 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB95A423A; Mon, 27 Mar 2023 04:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679916401; x=1711452401; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=hC5O2GCfOP2p66Bv6Vdwwm3MQaXMKKcdAvP9wRixTW8=; b=bMIo5+P9DaAlzmi0Deh/UUWQ5cDooDIlBYEhziFyijTub82qIEdQcwFy VD8mc4QLm1hnwMaoPyKTH/R7FaV8xOsohWCLR+MXf5vPX/jJOPyzDhT/U piykB+DdhbmA28CSQlcz6f+3MGXFtA8C8E4R8BAerFVoIKRvG2HghZt+x XAEDJnZh8dm1v0lmYjM/RnEXUe9Fq5Jk9juS09ZW7MSV7MSqpJA42K3JV XwQFwSS0nCF+/d9HCKx7pgUj1npq8pY/WYyyOPcSCD4EIMibizdr32yRZ XqBYDqc0K/xN/R5Nvp+VPe+0HHoaZhZ1yKW7SRjjiX8ifepjLo/ei8WFJ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="320639759" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="320639759" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 04:26:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="827009535" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="827009535" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2023 04:26:39 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pgkzl-009Bwz-1c; Mon, 27 Mar 2023 14:26:37 +0300 Date: Mon, 27 Mar 2023 14:26:37 +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 , techsupport@winsystems.com, Paul Demetrotion , Michael Walle Subject: Re: [PATCH v5 3/3] gpio: ws16c48: Migrate to the regmap API Message-ID: References: <58531b1b2428e4d5d2ea79e721f7ef6450665280.1679845842.git.william.gray@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <58531b1b2428e4d5d2ea79e721f7ef6450665280.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_NONE,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:59PM -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. > > The WinSystems WS16C48 provides the following registers: > > Offset 0x0-0x5: Port 0-5 I/O > Offset 0x6: Int_Pending > Offset 0x7: Page/Lock > Offset 0x8-0xA (Page 1): Pol_0-Pol_2 > Offset 0x8-0xA (Page 2): Enab_0-Enab_2 > Offset 0x8-0xA (Page 3): Int_ID0-Int_ID2 > > Port 0-5 I/O provides access to 48 lines of digital I/O across six > registers, each bit position corresponding to the respective line. > Writing a 1 to a respective bit position causes that output pin to sink > current, while writing a 0 to the same bit position causes that output > pin to go to a high-impedance state and allows it to be used an input. > Reads on a port report the inverted state (0 = high, 1 = low) of an I/O > pin when used in input mode. Interrupts are supported on Port 0-2. > > Int_Pending is a read-only register that reports the combined state of > the INT_ID0 through INT_ID2 registers; an interrupt pending is indicated > when any of the low three bits are set. > > The Page/Lock register provides the following bits: > > Bit 0-5: Port 0-5 I/O Lock > Bit 6-7: Page 0-3 Selection > > For Bits 0-5, writing a 1 to a respective bit position locks the output > state of the corresponding I/O port. Writing the page number to Bits 6-7 > selects that respective register page for use. > > Pol_0-Pol_2 are accessible when Page 1 is selected. Writing a 1 to a > respective bit position selects the rising edge detection interrupts for > that input line, while writing a 0 to the same bit position selects the > falling edge detection interrupts. > > Enab_0-Enab_2 are accessible when Page 2 is selected. Writing a 1 to a > respective bit position enables interrupts for that input line, while > writing a 0 to that same bit position clears and disables interrupts for > that input line. > > Int_ID0-Int_ID2 are accessible when Page 3 is selected. A respective bit > when read as a 1 indicates that an edge of the polarity set in the > corresponding polarity register was detected for the corresponding input > line. Writing any value to this register clears all pending interrupts > for the register. ... > +static const struct regmap_config ws16c48_regmap_config = { > + .reg_bits = 8, > + .reg_stride = 1, > + .val_bits = 8, > + .io_port = true, > + .max_register = 0xA, > + .wr_table = &ws16c48_wr_table, > + .rd_table = &ws16c48_rd_table, > + .volatile_table = &ws16c48_volatile_table, > + .cache_type = REGCACHE_FLAT, > +}; Do we need regmap lock? ... > /** > * struct ws16c48_gpio - GPIO device private data structure > - * @chip: instance of the gpio_chip > - * @io_state: bit I/O state (whether bit is set to input or output) > - * @out_state: output bits state > + * @map: regmap for the device > * @lock: synchronization lock to prevent I/O race conditions > * @irq_mask: I/O bits affected by interrupts > - * @flow_mask: IRQ flow type mask for the respective I/O bits > - * @reg: I/O address offset for the device registers > */ > struct ws16c48_gpio { > - struct gpio_chip chip; > - unsigned char io_state[6]; > - unsigned char out_state[6]; > + struct regmap *map; > raw_spinlock_t lock; > - unsigned long irq_mask; > - unsigned long flow_mask; > - struct ws16c48_reg __iomem *reg; > + u8 irq_mask[WS16C48_NUM_IRQS / WS16C48_NGPIO_PER_REG]; Looking at this (and also thinking about the previous patch) perhaps this should be declared as DECLARE_BITMAP(...); and corresponding bit ops to be used? > }; ... > +static int ws16c48_handle_pre_irq(void *const irq_drv_data) > { > + struct ws16c48_gpio *const ws16c48gpio = irq_drv_data; > > + /* Lock to prevent Page/Lock register change while we handle IRQ */ > + raw_spin_lock(&ws16c48gpio->lock); > > return 0; > } Hmm... Don't we have irq bus lock and unlock callbacks for this? ... > +static int ws16c48_handle_post_irq(void *const irq_drv_data) > { > + struct ws16c48_gpio *const ws16c48gpio = irq_drv_data; > > + raw_spin_unlock(&ws16c48gpio->lock); > > return 0; > } Ditto. Also shouldn't you annotate them for sparse so it won't complain about unbalanced locks? ... > +exit_early: exit_unlock() ? > raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags); > + return ret; ... > + err = regmap_write(map, WS16C48_ENAB, 0x00); WS16C48_ENAB + 0 (for the sake of symmetry with the below)? > + if (err) > + return err; > + err = regmap_write(map, WS16C48_ENAB + 1, 0x00); > + if (err) > + return err; > + err = regmap_write(map, WS16C48_ENAB + 2, 0x00); > + if (err) > + return err; -- With Best Regards, Andy Shevchenko