Skip to content

Commit 85eb2e5

Browse files
pnewman-ctigregkh
authored andcommitted
serial: 8250_exar: Replace custom EEPROM read with eeprom_93cx6
Replace the custom 93cx6 EEPROM read functions with the eeprom_93cx6 driver. This removes duplicate code and improves code readability. Replace exar_ee_read() calls with eeprom_93cx6_read() or eeprom_93cx6_multiread(). Add "select EEPROM_93CX6" to config SERIAL_8250_EXAR to ensure eeprom_93cx6 driver is also compiled when 8250_exar driver is selected. Note: Old exar_ee_read() and associated functions are removed in next patch in this series. Link to mailing list discussion with Andy Shevchenko for reference. Link: https://lore.kernel.org/linux-serial/[email protected]/ Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Parker Newman <[email protected]> Link: https://lore.kernel.org/r/1bf2214ae27130ca58b9e779c4d65a0e5db06fc1.1727880931.git.pnewman@connecttech.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d45109c commit 85eb2e5

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

drivers/tty/serial/8250/8250_exar.c

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/delay.h>
1212
#include <linux/device.h>
1313
#include <linux/dmi.h>
14+
#include <linux/eeprom_93cx6.h>
1415
#include <linux/interrupt.h>
1516
#include <linux/io.h>
1617
#include <linux/math.h>
@@ -191,8 +192,7 @@
191192
#define CTI_EE_OFF_XR17V35X_PORT_FLAGS 0x14 /* 1 word */
192193

193194
#define CTI_EE_MASK_PORT_FLAGS_TYPE GENMASK(7, 0)
194-
#define CTI_EE_MASK_OSC_FREQ_LOWER GENMASK(15, 0)
195-
#define CTI_EE_MASK_OSC_FREQ_UPPER GENMASK(31, 16)
195+
#define CTI_EE_MASK_OSC_FREQ GENMASK(31, 0)
196196

197197
#define CTI_FPGA_RS485_IO_REG 0x2008
198198
#define CTI_FPGA_CFG_INT_EN_REG 0x48
@@ -254,6 +254,7 @@ struct exar8250 {
254254
unsigned int nr;
255255
unsigned int osc_freq;
256256
struct exar8250_board *board;
257+
struct eeprom_93cx6 eeprom;
257258
void __iomem *virt;
258259
int line[];
259260
};
@@ -357,6 +358,39 @@ static u16 exar_ee_read(struct exar8250 *priv, u8 ee_addr)
357358
return data;
358359
}
359360

361+
static void exar_eeprom_93cx6_reg_read(struct eeprom_93cx6 *eeprom)
362+
{
363+
struct exar8250 *priv = eeprom->data;
364+
u8 regb = exar_read_reg(priv, UART_EXAR_REGB);
365+
366+
/* EECK and EECS always read 0 from REGB so only set EEDO */
367+
eeprom->reg_data_out = regb & UART_EXAR_REGB_EEDO;
368+
}
369+
370+
static void exar_eeprom_93cx6_reg_write(struct eeprom_93cx6 *eeprom)
371+
{
372+
struct exar8250 *priv = eeprom->data;
373+
u8 regb = 0;
374+
375+
if (eeprom->reg_data_in)
376+
regb |= UART_EXAR_REGB_EEDI;
377+
if (eeprom->reg_data_clock)
378+
regb |= UART_EXAR_REGB_EECK;
379+
if (eeprom->reg_chip_select)
380+
regb |= UART_EXAR_REGB_EECS;
381+
382+
exar_write_reg(priv, UART_EXAR_REGB, regb);
383+
}
384+
385+
static void exar_eeprom_init(struct exar8250 *priv)
386+
{
387+
priv->eeprom.data = priv;
388+
priv->eeprom.register_read = exar_eeprom_93cx6_reg_read;
389+
priv->eeprom.register_write = exar_eeprom_93cx6_reg_write;
390+
priv->eeprom.width = PCI_EEPROM_WIDTH_93C46;
391+
priv->eeprom.quirks |= PCI_EEPROM_QUIRK_EXTRA_READ_CYCLE;
392+
}
393+
360394
/**
361395
* exar_mpio_config_output() - Configure an Exar MPIO as an output
362396
* @priv: Device's private structure
@@ -698,20 +732,16 @@ static int cti_plx_int_enable(struct exar8250 *priv)
698732
*/
699733
static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset)
700734
{
701-
u16 lower_word;
702-
u16 upper_word;
735+
__le16 ee_words[2];
736+
u32 osc_freq;
703737

704-
lower_word = exar_ee_read(priv, eeprom_offset);
705-
// Check if EEPROM word was blank
706-
if (lower_word == 0xFFFF)
707-
return -EIO;
738+
eeprom_93cx6_multiread(&priv->eeprom, eeprom_offset, ee_words, ARRAY_SIZE(ee_words));
708739

709-
upper_word = exar_ee_read(priv, (eeprom_offset + 1));
710-
if (upper_word == 0xFFFF)
740+
osc_freq = le16_to_cpu(ee_words[0]) | (le16_to_cpu(ee_words[1]) << 16);
741+
if (osc_freq == CTI_EE_MASK_OSC_FREQ)
711742
return -EIO;
712743

713-
return FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) |
714-
FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word);
744+
return osc_freq;
715745
}
716746

717747
/**
@@ -835,7 +865,7 @@ static enum cti_port_type cti_get_port_type_xr17v35x(struct exar8250 *priv,
835865
u8 offset;
836866

837867
offset = CTI_EE_OFF_XR17V35X_PORT_FLAGS + port_num;
838-
port_flags = exar_ee_read(priv, offset);
868+
eeprom_93cx6_read(&priv->eeprom, offset, &port_flags);
839869

840870
port_type = FIELD_GET(CTI_EE_MASK_PORT_FLAGS_TYPE, port_flags);
841871
if (CTI_PORT_TYPE_VALID(port_type))
@@ -1553,6 +1583,8 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
15531583
if (rc)
15541584
return rc;
15551585

1586+
exar_eeprom_init(priv);
1587+
15561588
for (i = 0; i < nr_ports && i < maxnr; i++) {
15571589
rc = board->setup(priv, pcidev, &uart, i);
15581590
if (rc) {

drivers/tty/serial/8250/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ config SERIAL_8250_EXAR
150150
tristate "8250/16550 Exar/Commtech PCI/PCIe device support"
151151
depends on SERIAL_8250 && PCI
152152
select SERIAL_8250_PCILIB
153+
select EEPROM_93CX6
153154
default SERIAL_8250
154155
help
155156
This builds support for XR17C1xx, XR17V3xx and some Commtech

0 commit comments

Comments
 (0)