Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp46943lql; Fri, 12 Apr 2024 03:20:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWPgwt3PGBs00N7g3B6b9f4wzWdUEJD2cv4ZG/eLE6ZJefUe1oZl0YfgUQS2jzOcAaa19a5rOVuoUmnhUKRLsq6ewvVBUvJ68uh6dtDSQ== X-Google-Smtp-Source: AGHT+IHNZnWs+L16J8Hg6WiJ8OBVZ19KMda0KZ64Cj/ADrfrIVizB8NIq/wpDJNZ6vyGEQTncJGg X-Received: by 2002:a05:620a:4453:b0:78e:ccf7:8946 with SMTP id w19-20020a05620a445300b0078eccf78946mr1682064qkp.7.1712917258173; Fri, 12 Apr 2024 03:20:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712917258; cv=pass; d=google.com; s=arc-20160816; b=x9HlsXWIZKz0PjzGUGncmh4DnAFDtT/C5aVMg4YFAMcSPhTwLIBmyX5aub9VpxS7z2 ed9vTAmgaHMl0VebbWuogg2QM7RUM7pi1o59x2IvnPyQMjjFimHOHTygWTHys9xW6qw3 282sW/9ok8ejjB/rnWMW0bK/nMbvGWqdfhwZULfYisR8N7x9Fsq1VOpRYPfHqMGTrCDn M+wejAr73LKgITuMJoqFnpU4TB2rDqaduKjLCRrjER8fjOwxOpxduulASTdAnMUK9ilA OV63YtCivE660r5HhU/qa0rvONQMluNhMUUvEAMIR/fESoFg7YOlwZINckU14EE+8QHl WXBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:date:from :dkim-signature; bh=dLp8FHzHhSzohdwNsSXfUAniOIgCkO7AZuKO3BtmGyo=; fh=Sh5cH3MtqkQX1D4MMJekGQxEmK2CposBTcbIxQW6vbY=; b=JhBBwts731xvXGygn9m/FJHMCkmXsw9IDmXJ5AitaxzwQXYcI7tsjjfT2KINuugpLT Nco/1I57GdBabrXYvRV3UHkmmYIOeT87ZmScdhwHknaDn2bzozEBsnVsBdeuGkbCOniF cl28VCjKuTTWSAKWutQK4UZ3mn39Z+3BM88kXtw28o0VOjm/3/fsTnoBtJexh8ZhYQMw KZ6lqP0YBSlmAbVSUuBDipsDqO+KpHQ9+bV+vZro+Eka2T5v8xMXW65vS2OWE7wYmIyI xonGWxLYK6yiRMEWzeJajMogW9jyIjHHBrBKPCNT6g+h8vTMtoRlTMog04ZKzw+43JRu q0Xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J3fqYhUm; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-142484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142484-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a19-20020a05620a103300b0078d771f764asi3281014qkk.433.2024.04.12.03.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 03:20:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J3fqYhUm; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-142484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142484-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E19891C22608 for ; Fri, 12 Apr 2024 10:20:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5055E53819; Fri, 12 Apr 2024 10:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="J3fqYhUm" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D22F535B7; Fri, 12 Apr 2024 10:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712917251; cv=none; b=g0iAylCuLvdi6Gy7jc25uTH1pwJC5kQFRzGtlZnRpFf9aRL8gxA3KxjTD+Lq97ziaXyfC2ympwRqBF0BV6sWpo6dOEwjtHe36QXoy/hMuRqjnpqFXTo4mJvHP1tYEM1NCaH6/FPkuahO7fWflRidqnhZ6mjnMWlJ4/NKWCsw4nw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712917251; c=relaxed/simple; bh=uA7PtL0L1ljtXQJKIJ2F2O2vSZgqgTCaVG40coZxt3c=; h=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=fUbJHVA+Modj/2vba/5nEuw2kW09WstALWzhipSLwh8aa3K1XUweeWjU83wWv/m0f4TW0SiTmCghiEw1Ed2ZDDx/Yg+g+gktDtD5i21FHmCAkCla5bBTKhAytTYtBv0yO6B5OF7xVHsFdIdWdbbIIUbsIZbCXhjR7zxmIgSELuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=J3fqYhUm; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712917250; x=1744453250; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=uA7PtL0L1ljtXQJKIJ2F2O2vSZgqgTCaVG40coZxt3c=; b=J3fqYhUmJ+B7bE3Yl76+gaLTMojo66u34kOYcoyenFk6DJWPS0TsWoDG jIgv5lyx1hIeDT4kUA1tv2rYqowHJi3owVtiC/haBZcbdWwbtG/nJYgvD 5pkv+gRqzHHaaNV0e4o0NrAFwucbW8i2WLavolhTZx/UaItdDMCjWIhoN /HXxM2kHx4IzaTF4oZ1864usexuUs304s9GKc1aR0oxFE7a449M5iSPgl o9fmc2GKIe1QrAlLUgyhK2Q3VKf0slkxqoHjCsmeFIgEFjDqPRy1uCwKq 3g1o0/fTtl8g4RC69ULXuN9B5PKnsrvfxUCcy5nO/gc4Vwn5IRiGEb1ji A==; X-CSE-ConnectionGUID: 3Jz2wNYfRxKRe4ZLlsuYlg== X-CSE-MsgGUID: ffrUGbGqRuGbQ4tCMFs93Q== X-IronPort-AV: E=McAfee;i="6600,9927,11041"; a="19788614" X-IronPort-AV: E=Sophos;i="6.07,195,1708416000"; d="scan'208";a="19788614" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 03:20:50 -0700 X-CSE-ConnectionGUID: n2VmyR4GTsazuyWQgg6aJw== X-CSE-MsgGUID: XieXYW+7SMur8XIPowtQ3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,195,1708416000"; d="scan'208";a="52352334" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.32]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 03:20:46 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Fri, 12 Apr 2024 13:20:41 +0300 (EEST) To: parker@finest.io cc: Greg Kroah-Hartman , Jiri Slaby , LKML , linux-serial , Parker Newman Subject: Re: [PATCH v2 3/7] serial: exar: add support for config/set single MPIO In-Reply-To: <3e671b6c0d11a2d0c292947675ed087eaaa5445e.1712863999.git.pnewman@connecttech.com> Message-ID: References: <3e671b6c0d11a2d0c292947675ed087eaaa5445e.1712863999.git.pnewman@connecttech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Thu, 11 Apr 2024, parker@finest.io wrote: > From: Parker Newman > > Adds support for configuring and setting a single MPIO > > Signed-off-by: Parker Newman > --- > drivers/tty/serial/8250/8250_exar.c | 88 +++++++++++++++++++++++++++++ > 1 file changed, 88 insertions(+) > > diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c > index 49d690344e65..9915a99cb7c6 100644 > --- a/drivers/tty/serial/8250/8250_exar.c > +++ b/drivers/tty/serial/8250/8250_exar.c > @@ -305,6 +305,94 @@ static int exar_ee_read(struct exar8250 *priv, uint8_t ee_addr) > return data; > } > > +/** > + * exar_mpio_config() - Configure an EXar MPIO as input or output > + * @priv: Device's private structure > + * @mpio_num: MPIO number/offset to configure > + * @output: Configure as output if true, inout if false > + * > + * Configure a single MPIO as an input or output and disable trisate. tristate > + * If configuring as output it is reccomended to set value with > + * exar_mpio_set prior to calling this function to ensure default state. Use () if talking about function. > + * > + * Return: 0 on success, negative error code on failure > + */ > +static int exar_mpio_config(struct exar8250 *priv, > + unsigned int mpio_num, bool output) > +{ > + uint8_t sel_reg; //MPIO Select register (input/output) > + uint8_t tri_reg; //MPIO Tristate register > + uint8_t value; > + unsigned int bit; > + > + if (mpio_num < 8) { > + sel_reg = UART_EXAR_MPIOSEL_7_0; > + tri_reg = UART_EXAR_MPIO3T_7_0; > + bit = mpio_num; > + } else if (mpio_num >= 8 && mpio_num < 16) { > + sel_reg = UART_EXAR_MPIOSEL_15_8; > + tri_reg = UART_EXAR_MPIO3T_15_8; > + bit = mpio_num - 8; > + } else { > + return -EINVAL; > + } > + > + //Disable MPIO pin tri-state > + value = exar_read_reg(priv, tri_reg); > + value &= ~(BIT(bit)); Use more meaningful variable name than "bit", it could perhaps even avoid the need to use the comment if the code is self-explanary with better variable name. > + exar_write_reg(priv, tri_reg, value); > + > + value = exar_read_reg(priv, sel_reg); > + //Set MPIO as input (1) or output (0) Unnecessary comment. > + if (output) > + value &= ~(BIT(bit)); Unnecessary parenthesis. > + else > + value |= BIT(bit); > + > + exar_write_reg(priv, sel_reg, value); Don't leave empty line into RMW sequence. > + > + return 0; > +} > +/** > + * exar_mpio_set() - Set an Exar MPIO output high or low > + * @priv: Device's private structure > + * @mpio_num: MPIO number/offset to set > + * @high: Set MPIO high if true, low if false > + * > + * Set a single MPIO high or low. exar_mpio_config must also be called > + * to configure the pin as an output. > + * > + * Return: 0 on success, negative error code on failure > + */ > +static int exar_mpio_set(struct exar8250 *priv, > + unsigned int mpio_num, bool high) > +{ > + uint8_t reg; > + uint8_t value; > + unsigned int bit; > + > + if (mpio_num < 8) { > + reg = UART_EXAR_MPIOSEL_7_0; > + bit = mpio_num; > + } else if (mpio_num >= 8 && mpio_num < 16) { > + reg = UART_EXAR_MPIOSEL_15_8; > + bit = mpio_num - 8; > + } else { > + return -EINVAL; > + } > + > + value = exar_read_reg(priv, reg); > + > + if (high) > + value |= BIT(bit); > + else > + value &= ~(BIT(bit)); Extra parenthesis. > + > + exar_write_reg(priv, reg, value); Again, I'd put this kind of simple RMW sequence without newlines. > + > + return 0; > +} There are zero users of these functions so I couldn't review if two functions are really needed, or if the difference could be simply handled using a boolean parameter. -- i.