public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Parker Newman <pnewman@connecttech.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Subject: [PATCH v1 06/13] serial: 8250_exar: Extract cti_board_init_osc_freq() helper
Date: Thu,  2 May 2024 17:44:00 +0300	[thread overview]
Message-ID: <20240502144626.2716994-7-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240502144626.2716994-1-andriy.shevchenko@linux.intel.com>

Extract cti_board_init_osc_freq() helper to avoid code duplication.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/8250/8250_exar.c | 48 ++++++++++++-----------------
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
index ac373cde7e39..956323e2de4a 100644
--- a/drivers/tty/serial/8250/8250_exar.c
+++ b/drivers/tty/serial/8250/8250_exar.c
@@ -695,7 +695,6 @@ static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset)
 {
 	u16 lower_word;
 	u16 upper_word;
-	int osc_freq;
 
 	lower_word = exar_ee_read(priv, eeprom_offset);
 	// Check if EEPROM word was blank
@@ -706,10 +705,8 @@ static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset)
 	if (upper_word == 0xFFFF)
 		return -EIO;
 
-	osc_freq = FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) |
-		FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word);
-
-	return osc_freq;
+	return FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) |
+	       FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word);
 }
 
 /**
@@ -890,6 +887,19 @@ static int cti_rs485_config_mpio_tristate(struct uart_port *port,
 	return cti_tristate_disable(priv, port->port_id);
 }
 
+static void cti_board_init_osc_freq(struct exar8250 *priv, struct pci_dev *pcidev, u8 eeprom_offset)
+{
+	int osc_freq;
+
+	osc_freq = cti_read_osc_freq(priv, eeprom_offset);
+	if (osc_freq <= 0) {
+		dev_warn(&pcidev->dev, "failed to read OSC freq from EEPROM, using default\n");
+		osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
+	}
+
+	priv->osc_freq = osc_freq;
+}
+
 static int cti_port_setup_common(struct exar8250 *priv,
 				struct pci_dev *pcidev,
 				int idx, unsigned int offset,
@@ -1095,19 +1105,9 @@ static int cti_board_init_xr17v35x(struct exar8250 *priv,
 	return 0;
 }
 
-static int cti_board_init_xr17v25x(struct exar8250 *priv,
-				struct pci_dev *pcidev)
+static int cti_board_init_xr17v25x(struct exar8250 *priv, struct pci_dev *pcidev)
 {
-	int osc_freq;
-
-	osc_freq = cti_read_osc_freq(priv, CTI_EE_OFF_XR17V25X_OSC_FREQ);
-	if (osc_freq < 0) {
-		dev_warn(&pcidev->dev,
-			"failed to read osc freq from EEPROM, using default\n");
-		osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
-	}
-
-	priv->osc_freq = osc_freq;
+	cti_board_init_osc_freq(priv, pcidev, CTI_EE_OFF_XR17V25X_OSC_FREQ);
 
 	/* enable interrupts on cards that need the "PLX fix" */
 	switch (pcidev->subsystem_device) {
@@ -1123,19 +1123,9 @@ static int cti_board_init_xr17v25x(struct exar8250 *priv,
 	return 0;
 }
 
-static int cti_board_init_xr17c15x(struct exar8250 *priv,
-				struct pci_dev *pcidev)
+static int cti_board_init_xr17c15x(struct exar8250 *priv, struct pci_dev *pcidev)
 {
-	int osc_freq;
-
-	osc_freq = cti_read_osc_freq(priv, CTI_EE_OFF_XR17C15X_OSC_FREQ);
-	if (osc_freq <= 0) {
-		dev_warn(&pcidev->dev,
-			"failed to read osc freq from EEPROM, using default\n");
-		osc_freq = CTI_DEFAULT_PCI_OSC_FREQ;
-	}
-
-	priv->osc_freq = osc_freq;
+	cti_board_init_osc_freq(priv, pcidev, CTI_EE_OFF_XR17C15X_OSC_FREQ);
 
 	/* enable interrupts on cards that need the "PLX fix" */
 	switch (pcidev->subsystem_device) {
-- 
2.43.0.rc1.1336.g36b5255a03ac


  parent reply	other threads:[~2024-05-02 14:46 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 14:43 [PATCH v1 00/13] serial: 8250_exar: Clean up the driver Andy Shevchenko
2024-05-02 14:43 ` [PATCH v1 01/13] serial: 8250_exar: Don't return positive values as error codes Andy Shevchenko
2024-05-02 14:43 ` [PATCH v1 02/13] serial: 8250_exar: Describe all parameters in kernel doc Andy Shevchenko
2024-05-02 14:43 ` [PATCH v1 03/13] serial: 8250_exar: Kill CTI_PCI_DEVICE() Andy Shevchenko
2024-05-02 15:13   ` Parker Newman
2024-05-02 15:29     ` Andy Shevchenko
2024-05-02 15:36       ` Parker Newman
2024-05-02 15:43         ` Andy Shevchenko
2024-05-02 15:54           ` Parker Newman
2024-05-02 15:59             ` Andy Shevchenko
2024-05-02 14:43 ` [PATCH v1 04/13] serial: 8250_exar: Use PCI_SUBVENDOR_ID_IBM for subvendor ID Andy Shevchenko
2024-05-02 14:43 ` [PATCH v1 05/13] serial: 8250_exar: Trivia typo fixes Andy Shevchenko
2024-05-02 14:44 ` Andy Shevchenko [this message]
2024-05-02 14:44 ` [PATCH v1 07/13] serial: 8250_exar: Kill unneeded ->board_init() Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 08/13] serial: 8250_exar: Decrease indentation level Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 09/13] serial: 8250_exar: Return directly from switch-cases Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 10/13] serial: 8250_exar: Switch to use dev_err_probe() Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 11/13] serial: 8250_exar: Use BIT() in exar_ee_read() Andy Shevchenko
2024-05-02 16:08   ` Ilpo Järvinen
2024-05-02 17:20     ` Andy Shevchenko
2024-05-03 14:26       ` Parker Newman
2024-05-03 15:35         ` Andy Shevchenko
2024-05-03 18:56           ` Parker Newman
2024-05-06  8:37             ` Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 12/13] serial: 8250_exar: Make type of bit the same in exar_ee_*_bit() Andy Shevchenko
2024-05-02 14:44 ` [PATCH v1 13/13] serial: 8250_exar: Keep the includes sorted Andy Shevchenko
2024-05-02 15:46 ` [PATCH v1 00/13] serial: 8250_exar: Clean up the driver Parker Newman
2024-05-02 16:01   ` Andy Shevchenko
2024-05-02 16:08     ` Parker Newman
2024-05-02 17:22       ` Andy Shevchenko
2024-05-02 17:49         ` Parker Newman
2024-05-02 18:01           ` Andy Shevchenko
2024-05-03 12:36             ` Parker Newman
2024-05-03 14:47               ` Parker Newman
2024-05-03 15:33                 ` Andy Shevchenko

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=20240502144626.2716994-7-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --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