From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: parker@finest.io
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
Parker Newman <pnewman@connecttech.com>
Subject: Re: [PATCH v2 2/7] serial: exar: add support for reading from Exar EEPROM
Date: Fri, 12 Apr 2024 13:36:42 +0300 (EEST) [thread overview]
Message-ID: <2b817d47-52f6-bc9b-cb24-4f540101ea50@linux.intel.com> (raw)
In-Reply-To: <d16cb88f916914278e125023c856bbf85d0908c1.1712863999.git.pnewman@connecttech.com>
On Thu, 11 Apr 2024, parker@finest.io wrote:
> From: Parker Newman <pnewman@connecttech.com>
>
> - Adds support for reading a word from the Exar EEPROM.
> - Adds exar_write_reg/exar_read_reg for reading and writing to the UART's
> config registers.
>
> Signed-off-by: Parker Newman <pnewman@connecttech.com>
> ---
> drivers/tty/serial/8250/8250_exar.c | 110 ++++++++++++++++++++++++++++
> 1 file changed, 110 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
> index 4d1e07343d0b..49d690344e65 100644
> --- a/drivers/tty/serial/8250/8250_exar.c
> +++ b/drivers/tty/serial/8250/8250_exar.c
> @@ -128,6 +128,16 @@
> #define UART_EXAR_DLD 0x02 /* Divisor Fractional */
> #define UART_EXAR_DLD_485_POLARITY 0x80 /* RS-485 Enable Signal Polarity */
>
> +/* EEPROM registers */
> +#define UART_EXAR_REGB 0x8e
> +#define UART_EXAR_REGB_EECK BIT(4)
> +#define UART_EXAR_REGB_EECS BIT(5)
> +#define UART_EXAR_REGB_EEDI BIT(6)
> +#define UART_EXAR_REGB_EEDO BIT(7)
> +#define UART_EXAR_REGB_EE_ADDR_SIZE 6
> +#define UART_EXAR_REGB_EE_DATA_SIZE 16
> +
> +
Extra new line.
> /*
> * IOT2040 MPIO wiring semantics:
> *
> @@ -195,6 +205,106 @@ struct exar8250 {
> int line[];
> };
>
> +static inline void exar_write_reg(struct exar8250 *priv,
> + unsigned int reg, uint8_t value)
> +{
> + if (!priv || !priv->virt)
> + return;
> +
> + writeb(value, priv->virt + reg);
> +}
> +
> +static inline uint8_t exar_read_reg(struct exar8250 *priv, unsigned int reg)
> +{
> + if (!priv || !priv->virt)
> + return 0;
> +
> + return readb(priv->virt + reg);
> +}
> +
> +static inline void exar_ee_select(struct exar8250 *priv, bool enable)
> +{
> + uint8_t value = 0x00;
> +
> + if (enable)
> + value |= UART_EXAR_REGB_EECS;
You could just do:
u8 value;
value = enable ? UART_EXAR_REGB_EECS : 0;
Or even:
exar_write_reg(priv, UART_EXAR_REGB, enable ? UART_EXAR_REGB_EECS : 0);
> +
> + exar_write_reg(priv, UART_EXAR_REGB, value);
> + udelay(2);
> +}
> +
> +static inline void exar_ee_write_bit(struct exar8250 *priv, int bit)
> +{
> + uint8_t value = UART_EXAR_REGB_EECS;
> +
> + if (bit)
> + value |= UART_EXAR_REGB_EEDI;
> +
> + //Clock out the bit on the i2c interface
> + exar_write_reg(priv, UART_EXAR_REGB, value);
> + udelay(2);
> +
> + value |= UART_EXAR_REGB_EECK;
> +
> + exar_write_reg(priv, UART_EXAR_REGB, value);
> + udelay(2);
> +}
> +
> +static inline uint8_t exar_ee_read_bit(struct exar8250 *priv)
> +{
> + uint8_t regb;
> + uint8_t value = UART_EXAR_REGB_EECS;
> +
> + //Clock in the bit on the i2c interface
> + exar_write_reg(priv, UART_EXAR_REGB, value);
> + udelay(2);
> +
> + value |= UART_EXAR_REGB_EECK;
> +
> + exar_write_reg(priv, UART_EXAR_REGB, value);
> + udelay(2);
> +
> + regb = exar_read_reg(priv, UART_EXAR_REGB);
> +
> + return (regb & UART_EXAR_REGB_EEDO ? 1 : 0);
> +}
> +
> +/**
> + * exar_ee_read() - Read a word from the EEPROM
> + * @priv: Device's private structure
> + * @ee_addr: Offset of EEPROM to read word from
> + *
> + * Read a single 16bit word from an Exar UART's EEPROM
Add missing .
> + *
> + * Return: EEPROM word on success, negative error code on failure
This function does not return any -Exx code as far as I can see??
> + */
> +static int exar_ee_read(struct exar8250 *priv, uint8_t ee_addr)
> +{
> + int i;
> + int data = 0;
> +
> + exar_ee_select(priv, true);
> +
> + //Send read command (opcode 110)
> + exar_ee_write_bit(priv, 1);
> + exar_ee_write_bit(priv, 1);
> + exar_ee_write_bit(priv, 0);
> +
> + //Send address to read from
> + for (i = 1 << (UART_EXAR_REGB_EE_ADDR_SIZE - 1); i; i >>= 1)
> + exar_ee_write_bit(priv, (ee_addr & i));
> +
> + //Read data 1 bit at a time
> + for (i = 0; i <= UART_EXAR_REGB_EE_DATA_SIZE; i++) {
> + data <<= 1;
> + data |= exar_ee_read_bit(priv);
> + }
> +
> + exar_ee_select(priv, false);
> +
> + return data;
> +}
--
i.
next prev parent reply other threads:[~2024-04-12 10: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 [this message]
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
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=2b817d47-52f6-bc9b-cb24-4f540101ea50@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=parker@finest.io \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.