Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6923931rwn; Tue, 13 Sep 2022 10:55:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR5cChP6R4qiVRkRtHvacawWoraZNNJr75mIcEOKsNcvAElLBhCOYzft7VSKxQBq5FS98UWj X-Received: by 2002:a63:1317:0:b0:42a:e7a5:ef5a with SMTP id i23-20020a631317000000b0042ae7a5ef5amr29024348pgl.392.1663091734577; Tue, 13 Sep 2022 10:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663091734; cv=none; d=google.com; s=arc-20160816; b=cc+9nE8d0/OKJ6ZNqERkmYkAu1xpxFgS9eLmYd9I5HIoLZ2gxSzKSCfXKuKWqjGYzL +9rZg7Al3SImGDJNir7TIAZlC526myxtaRqYRCnT8TM12YX12ZdkNSp0sMK9HqQGBrjd hZoQ+8tOo/586ipCMNbnZqNThW8QEAfX9iU2QwjbMF0HIjdvLgE8AoELsU4X7LLI+y0x EI5Kw6+R+7DgBYl2bR72y/MAnwRMpmbnPfc1r9v2a4iuocxmld6mlYGGjOz7cW9LvZh/ 0FHeLLRPOzRVluzFYOrzlVMq0pBdEAG8to3g9C6P5GabYOFeHwYhRlRf9A+OXFTZovFC 5vzA== 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=qlfw3YZQjP7oownSVUSZJ83oibBtswp7fyUahbwhQOM=; b=wujJqb3YAXuHoguH5AeTfU1Ue+I0PvWLXVD1I8QLAJZp/DSkVis/CWOCeyR/6ow6Yz QxpYVy4QctnPRzqm1dEBFp5QrF4VexWpZYtm+Zmc5iGBq43Jbph6EHPStZ5v76GPvOjN PhMN0NwrtQVaR+pvoKgfkXZotA/WRiXOr1Xy5e1hZV+GkRkG0mXt+Dv9OGbSBNz5uSlt 7Xay6XUcWnCOMn4fPSQztLH5OeZW6l8FBT51RY6CHpUhS4K7ddqgjgHjs/fIME0g+MD1 kGrL5vdJ07yu04Sqi5STrhELt666987CPR78caXWaJwmIgJQMTe141WrbX7+2m2Q1ssf 4/eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FEFKV1RR; 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 l71-20020a63914a000000b0041a4f4a2afesi11585050pge.411.2022.09.13.10.55.23; Tue, 13 Sep 2022 10:55:34 -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=FEFKV1RR; 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 S232732AbiIMR2b (ORCPT + 99 others); Tue, 13 Sep 2022 13:28:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbiIMR2B (ORCPT ); Tue, 13 Sep 2022 13:28:01 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5058D53D26; Tue, 13 Sep 2022 09:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663085788; x=1694621788; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=261mO1KgSTtW14tdM99gOkkUmGI9TLXyDOhAtu26Vp8=; b=FEFKV1RR1qmmNB+2TOtgT7Dz60+8CN19ZBpYsKzUJGYDa+dOYJ5mYg11 bS0k1Ggj2wa5hg9LzXGng1pifpH9WflKIRVA4AsPcGzxwqrYtkXs1ZMus H82RSpMbMHrZ057heOfRxzZW8gt/w4+y1VrqaCio05r8k8uO0kM6CeTqk TiJ+uXExGgTzry7mCZL1GT3vho2LrFZYY8karAC6yr2XbURlWqD3Hh+5u eV4CsuGErIkGToWA006XS3gDDDYq//Ul+HzY2WnCHWw7FCDoItrvOy9/z MSTA1ptpDKPr/NIjhCaNRJ0OOdd72y6XGPHfL8ETjvKJIZKI+VH0On7JF w==; X-IronPort-AV: E=McAfee;i="6500,9779,10469"; a="298186600" X-IronPort-AV: E=Sophos;i="5.93,313,1654585200"; d="scan'208";a="298186600" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2022 09:16:28 -0700 X-IronPort-AV: E=Sophos;i="5.93,313,1654585200"; d="scan'208";a="758852127" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2022 09:16:26 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1oY8aG-001psQ-0H; Tue, 13 Sep 2022 19:16:24 +0300 Date: Tue, 13 Sep 2022 19:16:23 +0300 From: Andy Shevchenko To: William Breathitt Gray Cc: brgl@bgdev.pl, linus.walleij@linaro.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Subject: Re: [PATCH 1/3] gpio: idio-16: Introduce the ACCES IDIO-16 GPIO library module Message-ID: References: <6b28fb497c35def57c1920362c82402bed4bd23f.1662927941.git.william.gray@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6b28fb497c35def57c1920362c82402bed4bd23f.1662927941.git.william.gray@linaro.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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, Sep 11, 2022 at 04:34:38PM -0400, William Breathitt Gray wrote: > Exposes consumer library functions to facilitate communication with > devices within the ACCES IDIO-16 family such as the 104-IDIO-16 and > the PCI-IDIO-16. > > A CONFIG_GPIO_IDIO_16 Kconfig option is introduced by this patch. > Modules wanting access to these idio-16 library functions should select > this Kconfig option and import the IDIO_16 symbol namespace. ... > +int idio_16_get(struct idio_16 __iomem *const reg, const unsigned long offset) > +{ > + const unsigned long mask = BIT(offset); > + > + if (offset < 8) > + return !!(ioread8(®->out0_7) & mask); > + > + if (offset < 16) > + return !!(ioread8(®->out8_15) & (mask >> 8)); > + > + if (offset < 24) > + return !!(ioread8(®->in0_7) & (mask >> 16)); > + > + return !!(ioread8(®->in8_15) & (mask >> 24)); For the sake of robustness, since it's a library, I would do if (offset < 32) ... return -EINVAL; > +} > +EXPORT_SYMBOL_NS_GPL(idio_16_get, IDIO_16); If there is not expected to be more than a single namespace, you may define it just once for all via #define DEFAULT_SYMBOL_NAMESPACE IDIO_16 And honestly, I would add also GPIO prefix to it, GPIO_IDIO_16. ... > + if (*mask & GENMASK(7, 0)) > + bitmap_set_value8(bits, ioread8(®->out0_7), 0); > + if (*mask & GENMASK(15, 8)) > + bitmap_set_value8(bits, ioread8(®->out8_15), 8); > + if (*mask & GENMASK(23, 16)) > + bitmap_set_value8(bits, ioread8(®->in0_7), 16); > + if (*mask & GENMASK(31, 24)) > + bitmap_set_value8(bits, ioread8(®->in8_15), 24); So, the addresses of the ports are not expected to be continuous? ... > +void idio_16_set(struct idio_16 __iomem *const reg, > + struct idio_16_state *const state, const unsigned long offset, > + const unsigned long value) > +{ > + unsigned long flags; > + > + /* offsets greater than 15 are input-only signals */ > + if (offset > 15) For the sake of consistency: if (offset >= 16) > + return; > + > + spin_lock_irqsave(&state->lock, flags); > + if (value) > + set_bit(offset, state->out_state); > + else > + clear_bit(offset, state->out_state); assign_bit() But I'm wondering why do you need the atomic bitops under the lock? > + if (offset < 8) > + iowrite8(bitmap_get_value8(state->out_state, 0), ®->out0_7); > + else > + iowrite8(bitmap_get_value8(state->out_state, 8), ®->out8_15); > + > + spin_unlock_irqrestore(&state->lock, flags); > +} ... > + for_each_set_clump8(offset, port_mask, mask, IDIO_16_NOUT) { > + value = bitmap_get_value8(bits, offset); > + out_state = bitmap_get_value8(state->out_state, offset); > + > + out_state = (out_state & ~port_mask) | (value & port_mask); > + bitmap_set_value8(state->out_state, out_state, offset); This looks like bitmap_replace(). It might require to redesign the flow a bit. > + if (offset < 8) > + iowrite8(out_state, ®->out0_7); > + else > + iowrite8(out_state, ®->out8_15); > + } ... > +static inline int idio_16_get_direction(const unsigned long offset) > +{ > + return (offset < IDIO_16_NOUT) ? 0 : 1; return (offset >= IDIO_16_NOUT) ? 1 : 0; ? > +} -- With Best Regards, Andy Shevchenko