Skip to content

Commit c5f5974

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250_exar: Extract cti_board_init_osc_freq() helper
Extract cti_board_init_osc_freq() helper to avoid code duplication. Signed-off-by: Andy Shevchenko <[email protected]> Tested-by: Parker Newman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1cf8520 commit c5f5974

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset)
695695
{
696696
u16 lower_word;
697697
u16 upper_word;
698-
int osc_freq;
699698

700699
lower_word = exar_ee_read(priv, eeprom_offset);
701700
// Check if EEPROM word was blank
@@ -706,10 +705,8 @@ static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset)
706705
if (upper_word == 0xFFFF)
707706
return -EIO;
708707

709-
osc_freq = FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) |
710-
FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word);
711-
712-
return osc_freq;
708+
return FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) |
709+
FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word);
713710
}
714711

715712
/**
@@ -890,6 +887,19 @@ static int cti_rs485_config_mpio_tristate(struct uart_port *port,
890887
return cti_tristate_disable(priv, port->port_id);
891888
}
892889

890+
static void cti_board_init_osc_freq(struct exar8250 *priv, struct pci_dev *pcidev, u8 eeprom_offset)
891+
{
892+
int osc_freq;
893+
894+
osc_freq = cti_read_osc_freq(priv, eeprom_offset);
895+
if (osc_freq <= 0) {
896+
dev_warn(&pcidev->dev, "failed to read OSC freq from EEPROM, using default\n");
897+
osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
898+
}
899+
900+
priv->osc_freq = osc_freq;
901+
}
902+
893903
static int cti_port_setup_common(struct exar8250 *priv,
894904
struct pci_dev *pcidev,
895905
int idx, unsigned int offset,
@@ -1095,19 +1105,9 @@ static int cti_board_init_xr17v35x(struct exar8250 *priv,
10951105
return 0;
10961106
}
10971107

1098-
static int cti_board_init_xr17v25x(struct exar8250 *priv,
1099-
struct pci_dev *pcidev)
1108+
static int cti_board_init_xr17v25x(struct exar8250 *priv, struct pci_dev *pcidev)
11001109
{
1101-
int osc_freq;
1102-
1103-
osc_freq = cti_read_osc_freq(priv, CTI_EE_OFF_XR17V25X_OSC_FREQ);
1104-
if (osc_freq < 0) {
1105-
dev_warn(&pcidev->dev,
1106-
"failed to read osc freq from EEPROM, using default\n");
1107-
osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
1108-
}
1109-
1110-
priv->osc_freq = osc_freq;
1110+
cti_board_init_osc_freq(priv, pcidev, CTI_EE_OFF_XR17V25X_OSC_FREQ);
11111111

11121112
/* enable interrupts on cards that need the "PLX fix" */
11131113
switch (pcidev->subsystem_device) {
@@ -1123,19 +1123,9 @@ static int cti_board_init_xr17v25x(struct exar8250 *priv,
11231123
return 0;
11241124
}
11251125

1126-
static int cti_board_init_xr17c15x(struct exar8250 *priv,
1127-
struct pci_dev *pcidev)
1126+
static int cti_board_init_xr17c15x(struct exar8250 *priv, struct pci_dev *pcidev)
11281127
{
1129-
int osc_freq;
1130-
1131-
osc_freq = cti_read_osc_freq(priv, CTI_EE_OFF_XR17C15X_OSC_FREQ);
1132-
if (osc_freq <= 0) {
1133-
dev_warn(&pcidev->dev,
1134-
"failed to read osc freq from EEPROM, using default\n");
1135-
osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
1136-
}
1137-
1138-
priv->osc_freq = osc_freq;
1128+
cti_board_init_osc_freq(priv, pcidev, CTI_EE_OFF_XR17C15X_OSC_FREQ);
11391129

11401130
/* enable interrupts on cards that need the "PLX fix" */
11411131
switch (pcidev->subsystem_device) {

0 commit comments

Comments
 (0)