Linux-MIPS Archive mirror
 help / color / mirror / Atom feed
From: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Aleksandar Rikalo <arikalo@gmail.com>,
	Chao-ying Fu <cfu@wavecomp.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Greg Ungerer <gerg@kernel.org>, Hauke Mehrtens <hauke@hauke-m.de>,
	Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org,
	Marc Zyngier <maz@kernel.org>,
	Paul Burton <paulburton@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tiezhu Yang <yangtiezhu@loongson.cn>
Subject: [PATCH v4 14/14] mips: FDC driver refactor
Date: Sat, 11 May 2024 12:43:41 +0200	[thread overview]
Message-ID: <20240511104341.151550-15-aleksandar.rikalo@syrmia.com> (raw)
In-Reply-To: <20240511104341.151550-1-aleksandar.rikalo@syrmia.com>

Separate the FDC driver code into two parts, common and
mips-specific.

No functional impact.

Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>
Signed-off-by: Djordje Todorovic <djordje.todorovic@syrmia.com>
---
 drivers/tty/mips_fdc/Makefile         |  2 +
 drivers/tty/mips_fdc/ejtag-fdc-mips.c | 29 ++++++++++++
 drivers/tty/mips_fdc/ejtag-fdc.c      | 66 +++------------------------
 drivers/tty/mips_fdc/ejtag-fdc.h      | 55 ++++++++++++++++++++++
 4 files changed, 93 insertions(+), 59 deletions(-)
 create mode 100644 drivers/tty/mips_fdc/ejtag-fdc-mips.c
 create mode 100644 drivers/tty/mips_fdc/ejtag-fdc.h

diff --git a/drivers/tty/mips_fdc/Makefile b/drivers/tty/mips_fdc/Makefile
index 03b2781e1090..9e0894a8b342 100644
--- a/drivers/tty/mips_fdc/Makefile
+++ b/drivers/tty/mips_fdc/Makefile
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += ejtag-fdc.o
+
+obj-$(CONFIG_MIPS) += ejtag-fdc-mips.o
diff --git a/drivers/tty/mips_fdc/ejtag-fdc-mips.c b/drivers/tty/mips_fdc/ejtag-fdc-mips.c
new file mode 100644
index 000000000000..3942ee818f0b
--- /dev/null
+++ b/drivers/tty/mips_fdc/ejtag-fdc-mips.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "ejtag-fdc.h"
+
+void __iomem *get_fdc_regs(void)
+{
+	return mips_cdmm_early_probe(0xfd);
+}
+
+int is_fdc_interrupt(void)
+{
+	return read_c0_cause() & CAUSEF_FDCI;
+}
+
+static const struct mips_cdmm_device_id mips_ejtag_fdc_tty_ids[] = {
+	{ .type = 0xfd },
+	{ }
+};
+
+static struct mips_cdmm_driver mips_ejtag_fdc_tty_driver = {
+	.drv		= {
+		.name	= "mips_ejtag_fdc",
+	},
+	.probe		= mips_ejtag_fdc_tty_probe,
+	.cpu_down	= mips_ejtag_fdc_tty_cpu_down,
+	.cpu_up		= mips_ejtag_fdc_tty_cpu_up,
+	.id_table	= mips_ejtag_fdc_tty_ids,
+};
+builtin_mips_cdmm_driver(mips_ejtag_fdc_tty_driver);
diff --git a/drivers/tty/mips_fdc/ejtag-fdc.c b/drivers/tty/mips_fdc/ejtag-fdc.c
index afbf7738c7c4..fecd96118019 100644
--- a/drivers/tty/mips_fdc/ejtag-fdc.c
+++ b/drivers/tty/mips_fdc/ejtag-fdc.c
@@ -28,45 +28,9 @@
 #include <linux/tty_flip.h>
 #include <linux/uaccess.h>
 
-#include <asm/cdmm.h>
 #include <asm/irq.h>
 
-/* Register offsets */
-#define REG_FDACSR	0x00	/* FDC Access Control and Status Register */
-#define REG_FDCFG	0x08	/* FDC Configuration Register */
-#define REG_FDSTAT	0x10	/* FDC Status Register */
-#define REG_FDRX	0x18	/* FDC Receive Register */
-#define REG_FDTX(N)	(0x20+0x8*(N))	/* FDC Transmit Register n (0..15) */
-
-/* Register fields */
-
-#define REG_FDCFG_TXINTTHRES_SHIFT	18
-#define REG_FDCFG_TXINTTHRES		(0x3 << REG_FDCFG_TXINTTHRES_SHIFT)
-#define REG_FDCFG_TXINTTHRES_DISABLED	(0x0 << REG_FDCFG_TXINTTHRES_SHIFT)
-#define REG_FDCFG_TXINTTHRES_EMPTY	(0x1 << REG_FDCFG_TXINTTHRES_SHIFT)
-#define REG_FDCFG_TXINTTHRES_NOTFULL	(0x2 << REG_FDCFG_TXINTTHRES_SHIFT)
-#define REG_FDCFG_TXINTTHRES_NEAREMPTY	(0x3 << REG_FDCFG_TXINTTHRES_SHIFT)
-#define REG_FDCFG_RXINTTHRES_SHIFT	16
-#define REG_FDCFG_RXINTTHRES		(0x3 << REG_FDCFG_RXINTTHRES_SHIFT)
-#define REG_FDCFG_RXINTTHRES_DISABLED	(0x0 << REG_FDCFG_RXINTTHRES_SHIFT)
-#define REG_FDCFG_RXINTTHRES_FULL	(0x1 << REG_FDCFG_RXINTTHRES_SHIFT)
-#define REG_FDCFG_RXINTTHRES_NOTEMPTY	(0x2 << REG_FDCFG_RXINTTHRES_SHIFT)
-#define REG_FDCFG_RXINTTHRES_NEARFULL	(0x3 << REG_FDCFG_RXINTTHRES_SHIFT)
-#define REG_FDCFG_TXFIFOSIZE_SHIFT	8
-#define REG_FDCFG_TXFIFOSIZE		(0xff << REG_FDCFG_TXFIFOSIZE_SHIFT)
-#define REG_FDCFG_RXFIFOSIZE_SHIFT	0
-#define REG_FDCFG_RXFIFOSIZE		(0xff << REG_FDCFG_RXFIFOSIZE_SHIFT)
-
-#define REG_FDSTAT_TXCOUNT_SHIFT	24
-#define REG_FDSTAT_TXCOUNT		(0xff << REG_FDSTAT_TXCOUNT_SHIFT)
-#define REG_FDSTAT_RXCOUNT_SHIFT	16
-#define REG_FDSTAT_RXCOUNT		(0xff << REG_FDSTAT_RXCOUNT_SHIFT)
-#define REG_FDSTAT_RXCHAN_SHIFT		4
-#define REG_FDSTAT_RXCHAN		(0xf << REG_FDSTAT_RXCHAN_SHIFT)
-#define REG_FDSTAT_RXE			BIT(3)	/* Rx Empty */
-#define REG_FDSTAT_RXF			BIT(2)	/* Rx Full */
-#define REG_FDSTAT_TXE			BIT(1)	/* Tx Empty */
-#define REG_FDSTAT_TXF			BIT(0)	/* Tx Full */
+#include "ejtag-fdc.h"
 
 /* Default channel for the early console */
 #define CONSOLE_CHANNEL      1
@@ -375,7 +339,7 @@ static int __init mips_ejtag_fdc_console_init(struct mips_ejtag_fdc_console *c)
 	if (c->initialised)
 		goto out;
 	/* Look for the FDC device */
-	regs = mips_cdmm_early_probe(0xfd);
+	regs = get_fdc_regs();
 	if (IS_ERR(regs)) {
 		ret = PTR_ERR(regs);
 		goto out;
@@ -664,7 +628,7 @@ static irqreturn_t mips_ejtag_fdc_isr(int irq, void *dev_id)
 		return IRQ_NONE;
 
 	/* If no FDC interrupt pending, it wasn't for us */
-	if (!(read_c0_cause() & CAUSEF_FDCI))
+	if (!is_fdc_interrupt())
 		return IRQ_NONE;
 
 	mips_ejtag_fdc_handle(priv);
@@ -882,7 +846,7 @@ int __weak get_c0_fdc_int(void)
 	return -1;
 }
 
-static int mips_ejtag_fdc_tty_probe(struct mips_cdmm_device *dev)
+int mips_ejtag_fdc_tty_probe(struct mips_cdmm_device *dev)
 {
 	int ret, nport;
 	struct mips_ejtag_fdc_tty_port *dport;
@@ -1045,7 +1009,7 @@ static int mips_ejtag_fdc_tty_probe(struct mips_cdmm_device *dev)
 	return ret;
 }
 
-static int mips_ejtag_fdc_tty_cpu_down(struct mips_cdmm_device *dev)
+int mips_ejtag_fdc_tty_cpu_down(struct mips_cdmm_device *dev)
 {
 	struct mips_ejtag_fdc_tty *priv = mips_cdmm_get_drvdata(dev);
 	unsigned int cfg;
@@ -1068,7 +1032,7 @@ static int mips_ejtag_fdc_tty_cpu_down(struct mips_cdmm_device *dev)
 	return 0;
 }
 
-static int mips_ejtag_fdc_tty_cpu_up(struct mips_cdmm_device *dev)
+int mips_ejtag_fdc_tty_cpu_up(struct mips_cdmm_device *dev)
 {
 	struct mips_ejtag_fdc_tty *priv = mips_cdmm_get_drvdata(dev);
 	unsigned int cfg;
@@ -1106,22 +1070,6 @@ static int mips_ejtag_fdc_tty_cpu_up(struct mips_cdmm_device *dev)
 	return ret;
 }
 
-static const struct mips_cdmm_device_id mips_ejtag_fdc_tty_ids[] = {
-	{ .type = 0xfd },
-	{ }
-};
-
-static struct mips_cdmm_driver mips_ejtag_fdc_tty_driver = {
-	.drv		= {
-		.name	= "mips_ejtag_fdc",
-	},
-	.probe		= mips_ejtag_fdc_tty_probe,
-	.cpu_down	= mips_ejtag_fdc_tty_cpu_down,
-	.cpu_up		= mips_ejtag_fdc_tty_cpu_up,
-	.id_table	= mips_ejtag_fdc_tty_ids,
-};
-builtin_mips_cdmm_driver(mips_ejtag_fdc_tty_driver);
-
 static int __init mips_ejtag_fdc_init_console(void)
 {
 	return mips_ejtag_fdc_console_init(&mips_ejtag_fdc_con);
@@ -1166,7 +1114,7 @@ static void __iomem *kgdbfdc_setup(void)
 	regs = mips_ejtag_fdc_con.regs[cpu];
 	/* First console output on this CPU? */
 	if (!regs) {
-		regs = mips_cdmm_early_probe(0xfd);
+		regs = get_fdc_regs();
 		mips_ejtag_fdc_con.regs[cpu] = regs;
 	}
 	/* Already tried and failed to find FDC on this CPU? */
diff --git a/drivers/tty/mips_fdc/ejtag-fdc.h b/drivers/tty/mips_fdc/ejtag-fdc.h
new file mode 100644
index 000000000000..62e8fbe1b614
--- /dev/null
+++ b/drivers/tty/mips_fdc/ejtag-fdc.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * TTY driver for MIPS EJTAG Fast Debug Channels.
+ *
+ * Copyright (C) 2007-2015 Imagination Technologies Ltd
+ */
+
+#ifndef __EJTAG_FDC_H
+#define __EJTAG_FDC_H
+
+#include <asm/cdmm.h>
+
+/* Register offsets */
+#define REG_FDACSR	0x00	/* FDC Access Control and Status Register */
+#define REG_FDCFG	0x08	/* FDC Configuration Register */
+#define REG_FDSTAT	0x10	/* FDC Status Register */
+#define REG_FDRX	0x18	/* FDC Receive Register */
+#define REG_FDTX(N)	(0x20+0x8*(N))	/* FDC Transmit Register n (0..15) */
+
+/* Register fields */
+#define REG_FDCFG_TXINTTHRES_SHIFT	18
+#define REG_FDCFG_TXINTTHRES		(0x3 << REG_FDCFG_TXINTTHRES_SHIFT)
+#define REG_FDCFG_TXINTTHRES_DISABLED	(0x0 << REG_FDCFG_TXINTTHRES_SHIFT)
+#define REG_FDCFG_TXINTTHRES_EMPTY	(0x1 << REG_FDCFG_TXINTTHRES_SHIFT)
+#define REG_FDCFG_TXINTTHRES_NOTFULL	(0x2 << REG_FDCFG_TXINTTHRES_SHIFT)
+#define REG_FDCFG_TXINTTHRES_NEAREMPTY	(0x3 << REG_FDCFG_TXINTTHRES_SHIFT)
+#define REG_FDCFG_RXINTTHRES_SHIFT	16
+#define REG_FDCFG_RXINTTHRES		(0x3 << REG_FDCFG_RXINTTHRES_SHIFT)
+#define REG_FDCFG_RXINTTHRES_DISABLED	(0x0 << REG_FDCFG_RXINTTHRES_SHIFT)
+#define REG_FDCFG_RXINTTHRES_FULL	(0x1 << REG_FDCFG_RXINTTHRES_SHIFT)
+#define REG_FDCFG_RXINTTHRES_NOTEMPTY	(0x2 << REG_FDCFG_RXINTTHRES_SHIFT)
+#define REG_FDCFG_RXINTTHRES_NEARFULL	(0x3 << REG_FDCFG_RXINTTHRES_SHIFT)
+#define REG_FDCFG_TXFIFOSIZE_SHIFT	8
+#define REG_FDCFG_TXFIFOSIZE		(0xff << REG_FDCFG_TXFIFOSIZE_SHIFT)
+#define REG_FDCFG_RXFIFOSIZE_SHIFT	0
+#define REG_FDCFG_RXFIFOSIZE		(0xff << REG_FDCFG_RXFIFOSIZE_SHIFT)
+
+#define REG_FDSTAT_TXCOUNT_SHIFT	24
+#define REG_FDSTAT_TXCOUNT		(0xff << REG_FDSTAT_TXCOUNT_SHIFT)
+#define REG_FDSTAT_RXCOUNT_SHIFT	16
+#define REG_FDSTAT_RXCOUNT		(0xff << REG_FDSTAT_RXCOUNT_SHIFT)
+#define REG_FDSTAT_RXCHAN_SHIFT		4
+#define REG_FDSTAT_RXCHAN		(0xf << REG_FDSTAT_RXCHAN_SHIFT)
+#define REG_FDSTAT_RXE			BIT(3)	/* Rx Empty */
+#define REG_FDSTAT_RXF			BIT(2)	/* Rx Full */
+#define REG_FDSTAT_TXE			BIT(1)	/* Tx Empty */
+#define REG_FDSTAT_TXF			BIT(0)	/* Tx Full */
+
+void __iomem *get_fdc_regs(void);
+int is_fdc_interrupt(void);
+int mips_ejtag_fdc_tty_probe(struct mips_cdmm_device *dev);
+int mips_ejtag_fdc_tty_cpu_down(struct mips_cdmm_device *dev);
+int mips_ejtag_fdc_tty_cpu_up(struct mips_cdmm_device *dev);
+
+#endif /* __EJTAG_FDC_H */
-- 
2.25.1


      parent reply	other threads:[~2024-05-11 10:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11 10:43 [PATCH v4 00/14] MIPS: Support I6500 multi-cluster configuration Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 01/14] MIPS: CPS: Add a couple of multi-cluster utility functions Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 02/14] MIPS: GIC: Generate redirect block accessors Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 03/14] irqchip: mips-gic: Introduce for_each_online_cpu_gic() Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 04/14] irqchip: mips-gic: Support multi-cluster in for_each_online_cpu_gic() Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 05/14] irqchip: mips-gic: Setup defaults in each cluster Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 06/14] irqchip: mips-gic: Multi-cluster support Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 07/14] clocksource: mips-gic-timer: Always use cluster 0 counter as clocksource Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 08/14] clocksource: mips-gic-timer: Enable counter when CPUs start Aleksandar Rikalo
2024-05-27 12:31   ` Philippe Mathieu-Daudé
2024-05-11 10:43 ` [PATCH v4 09/14] MIPS: pm-cps: Use per-CPU variables as per-CPU, not per-core Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 10/14] MIPS: CPS: Introduce struct cluster_boot_config Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 11/14] MIPS: CPS: Boot CPUs in secondary clusters Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 12/14] mips: Enable FDC on MIPS R6 platforms Aleksandar Rikalo
2024-05-11 10:43 ` [PATCH v4 13/14] mips: Move FDC driver to a separate directory Aleksandar Rikalo
2024-05-11 10:43 ` Aleksandar Rikalo [this message]

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=20240511104341.151550-15-aleksandar.rikalo@syrmia.com \
    --to=aleksandar.rikalo@syrmia.com \
    --cc=arikalo@gmail.com \
    --cc=cfu@wavecomp.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=fancer.lancer@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=gerg@kernel.org \
    --cc=hauke@hauke-m.de \
    --cc=ilya.lipnitskiy@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=paulburton@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=yangtiezhu@loongson.cn \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).