From: Parker Newman <parker@finest.io>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-serial <linux-serial@vger.kernel.org>,
Parker Newman <pnewman@connecttech.com>
Subject: Re: [PATCH v2 3/7] serial: exar: add support for config/set single MPIO
Date: Fri, 12 Apr 2024 09:36:13 -0400 [thread overview]
Message-ID: <20240412093613.0cbb4362@SWDEV2.connecttech.local> (raw)
In-Reply-To: <b057b1e2-1cf9-2f20-2453-b359a1e89f01@linux.intel.com>
On Fri, 12 Apr 2024 13:20:41 +0300 (EEST)
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> On Thu, 11 Apr 2024, parker@finest.io wrote:
>
> > From: Parker Newman <pnewman@connecttech.com>
> >
> > Adds support for configuring and setting a single MPIO
> >
> > Signed-off-by: Parker Newman <pnewman@connecttech.com>
> > ---
> > 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;
> > +}
I will fix above.
> 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.
>
The functions are used by code in other patches in this series.
I kept exar_mpio_set() and exar_mpio_config() separate because we plan on
adding support for other features in the future that require reading and
writing MPIO.
Thanks,
-Parker
next prev parent reply other threads:[~2024-04-12 13:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 20:25 [PATCH v2 0/7] serial: exar: add Connect Tech serial cards to Exar driver parker
2024-04-11 20:25 ` [PATCH v2 1/7] serial: exar: adding missing CTI and Exar PCI ids parker
2024-04-11 20:25 ` [PATCH v2 2/7] serial: exar: add support for reading from Exar EEPROM parker
2024-04-12 5:26 ` Greg Kroah-Hartman
2024-04-12 12:58 ` Parker Newman
2024-04-12 10:36 ` Ilpo Järvinen
2024-04-12 13:06 ` Parker Newman
2024-04-11 20:25 ` [PATCH v2 3/7] serial: exar: add support for config/set single MPIO parker
2024-04-12 5:29 ` Greg Kroah-Hartman
2024-04-12 13:05 ` Parker Newman
2024-04-12 10:20 ` Ilpo Järvinen
2024-04-12 13:36 ` Parker Newman [this message]
2024-04-12 13:44 ` Ilpo Järvinen
2024-04-11 20:25 ` [PATCH v2 4/7] serial: exar: add optional board_setup function parker
2024-04-12 10:08 ` Ilpo Järvinen
2024-04-12 13:50 ` Parker Newman
2024-04-11 20:25 ` [PATCH v2 5/7] serial: exar: add some CTI helper functions parker
2024-04-12 10:48 ` Ilpo Järvinen
2024-04-12 13:57 ` Parker Newman
2024-04-12 14:09 ` Ilpo Järvinen
2024-04-11 20:25 ` [PATCH v2 6/7] serial: exar: add CTI board and port setup functions parker
2024-04-12 10:57 ` Ilpo Järvinen
2024-04-12 15:19 ` Parker Newman
2024-04-12 15:28 ` Greg Kroah-Hartman
2024-04-12 15:39 ` Parker Newman
2024-04-11 20:25 ` [PATCH v2 7/7] serial: exar: fix: fix crash during shutdown if setup fails parker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240412093613.0cbb4362@SWDEV2.connecttech.local \
--to=parker@finest.io \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=pnewman@connecttech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox