Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1097635rda; Mon, 23 Oct 2023 02:21:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCHElz/qNaCEmMkkdldlRgwxZVBSzm7dPZWbSClgrOPsqMtzyN9aNbZnoGvF1b1ekePLhq X-Received: by 2002:a05:6870:a105:b0:1ea:d8bb:411a with SMTP id m5-20020a056870a10500b001ead8bb411amr10939153oae.6.1698052899662; Mon, 23 Oct 2023 02:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698052899; cv=none; d=google.com; s=arc-20160816; b=iIc2tSamGXJdTC4hUB55kiUoOODbs0DKkGpI4B1f4ZrcC67IrmdQAfCmueXU7D2okN N1GGK3Pbh0VpV704croDcgCvGEQKAYk20mNiduFK4JMpUUQRiCalBVS38NfWYRuO99in ZaKjPPr4aTt1hSKMzjJLEDz2GF1+j+4xVVX5Yf0yYJxMcF1Qqo/DupEdGP0eC5ZKtDKD u5xV4JrHLlHbWLf0G3UBYsFONDg/VQubCmHbXDKMCODdMKt99bOwov1Z16q43CG4hq6+ A/dm1QJ53e7YtltVgHqSafg9K+Y8lmVCvhDLZMr19wetiqwMD1KBlKeGZSPwTW3cGU+m DxEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=ncwZ+54TAmoWMAgT2A7XJrAOAp3ix/gvc4035tpMKU8=; fh=rBGpfrN+Ux4s/4k925snBQH9A7rBZKwyK2FpFhqHb/4=; b=Pej5SvmsJc6d+wF1gcnunB+4cMErqOJEBjkzb7pTcik8R52mnRSZl9Lxum9voONQCJ d6gZJPAm5gsi+B5TycVi09hTxNwoGuDFVXAb+aKVcKJEfY0Yn+FgW4nNAYShg32jxV04 coaqXDL14opCJ7WNRww2FtA+kM2XbsSNgrk8HHRGNiZQdbTvzmmlnQ7b08zqWAoRZxoG 8a82Mo4sXAtucsr8BKhl0EBW0/yJ6v6RH4oQOIgHgI6kcmsFOpx2eunqrlUcfL97VVqI s2q0mW+OM2XcuXi7763q3UY9V4YIYrMRkpt83pS9HD6GM5xUA0mMsW92hhsmZL+IOrIA BCOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hcrlfluX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id j69-20020a638048000000b0058974d3c292si5932536pgd.191.2023.10.23.02.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 02:21:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hcrlfluX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 85940805936E; Mon, 23 Oct 2023 02:21:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbjJWJVP (ORCPT + 99 others); Mon, 23 Oct 2023 05:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjJWJVM (ORCPT ); Mon, 23 Oct 2023 05:21:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33338F5; Mon, 23 Oct 2023 02:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698052870; x=1729588870; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=p1SAne+x2Vqn1d6KCvK50Z1tyZPw11rQLG9JPCmxBzc=; b=hcrlfluXJjwzz25dpO1hf1++djIm+WBKaCWBfTkITLBFwwBOBEACXY9x gsRdKAoj3xbbMXDlk4ZAko0kIA6KPy/GUcXBSw4WdfiXIWV0T7W5dAs2K kEp6ga8/8NgioM8ODCQ5ba3pO25yOJVnmtm4bDEUA+EsnaFRyUHSItAd+ wOXMLrLFlGQGsRjhZmRSlRxJj7k+vOqBsBWAHBukoVBYH/oU3vBeIWBMh GuqeaNhRZXrXiKA0vO6Sl9V3LG17crEt0wlJLFqKYSyL9CEgEBGf76KtX mPvtvSyLJv3J19rxrg5DLouwUOyaOphkOH0AmIxYAWvUVddI6iV3IQXzr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10871"; a="453270585" X-IronPort-AV: E=Sophos;i="6.03,244,1694761200"; d="scan'208";a="453270585" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 02:21:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10871"; a="848737994" X-IronPort-AV: E=Sophos;i="6.03,244,1694761200"; d="scan'208";a="848737994" Received: from foliveix-mobl5.amr.corp.intel.com ([10.251.211.194]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2023 02:21:07 -0700 Date: Mon, 23 Oct 2023 12:21:01 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Crescent CY Hsieh cc: Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default In-Reply-To: <20231018091739.10125-6-crescentcy.hsieh@moxa.com> Message-ID: References: <20231018091739.10125-1-crescentcy.hsieh@moxa.com> <20231018091739.10125-6-crescentcy.hsieh@moxa.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 23 Oct 2023 02:21:35 -0700 (PDT) On Wed, 18 Oct 2023, Crescent CY Hsieh wrote: > MOXA PCIe RS422/RS485 boards will not function by default because of the > initial default serial interface of all MOXA PCIe boards is set to RS232. > > This patch fixes the problem above by setting the initial default serial > interface to RS422 for those MOXA RS422/RS485 PCIe boards. > > Signed-off-by: Crescent CY Hsieh > --- > drivers/tty/serial/8250/8250_pci.c | 52 ++++++++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) > > diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c > index b2be3783f..29a28e72b 100644 > --- a/drivers/tty/serial/8250/8250_pci.c > +++ b/drivers/tty/serial/8250/8250_pci.c > @@ -1968,6 +1968,12 @@ pci_sunix_setup(struct serial_private *priv, > > #define MOXA_GPIO_PIN2 BIT(2) > > +#define MOXA_RS232 0x00 > +#define MOXA_RS422 0x01 > +#define MOXA_RS485_4W 0x0B > +#define MOXA_RS485_2W 0x0F > +#define MOXA_UIR_OFFSET 0x04 > + > static bool pci_moxa_is_mini_pcie(unsigned short device) > { > if (device == PCI_DEVICE_ID_MOXA_CP102N || > @@ -1981,13 +1987,59 @@ static bool pci_moxa_is_mini_pcie(unsigned short device) > return false; > } > > +/* > + * The second digit of the MOXA PCIe device ID in hexadecimal indicates > + * which serial interface modes this board supports: > + * > + * 0x*0** - RS232 > + * 0x*1** - RS232/RS422/RS485 > + * 0x*3** - RS422/RS485 > + * 0x*6** - RS232 > + */ > +static bool pci_moxa_match_second_digit(unsigned short device, > + unsigned short pattern) > +{ > + return (device & 0x0F00) == pattern; Define a named field, not literal. IMO, the function name is not good because it tells what code does, not why it does. I think the name should be based on . > +} > + > +static int pci_moxa_set_interface(const struct pci_dev *dev, > + unsigned int port_idx, > + u8 mode) > +{ > + resource_size_t iobar_addr = pci_resource_start(dev, 2); > + resource_size_t UIR_addr = iobar_addr + MOXA_UIR_OFFSET + port_idx / 2; > + u8 val; > + > + val = inb(UIR_addr); > + > + if (port_idx % 2) { > + val &= 0x0F; > + val |= mode << 4; > + } else { > + val &= 0xF0; > + val |= mode; These should use the typical pattern instead: val &= ~NAMED_DEFINE; val |= FIELD_PREP(NAMED_DEFINE, mode); Also, don't forget to add bitfield.h if it's not there yet among the includes. -- i. > + } > + outb(val, UIR_addr); > + > + return 0; > +} > + > static int pci_moxa_init(struct pci_dev *dev) > { > unsigned short device = dev->device; > resource_size_t iobar_addr = pci_resource_start(dev, 2); > + unsigned int i; > unsigned int num_ports = (device & 0x00F0) >> 4; Put declaration of i after num_ports. > u8 val; > > + /* > + * For the device IDs of MOXA PCIe boards match the pattern 0x*3**, > + * the initial default serial interface mode should be set to RS422. > + */ > + if (pci_moxa_match_second_digit(device, 0x0300)) { Name the literal with define, once you have better name for the function and no literal, the comment is no longer necessary at all because the code will document itself much better! > + for (i = 0; i < num_ports; ++i) > + pci_moxa_set_interface(dev, i, MOXA_RS422); > + } > /* > * Enable hardware buffer to prevent break signal output when system boots up. > * This hardware buffer is only supported on Mini PCIe series. >