Commit Graph

134 Commits

Author SHA1 Message Date
Jiri Slaby
2fb19b9578 mxser: remove tty->driver_data NULL check
Noone sets tty->driver_data to NULL in the driver, so there is no point
to check that in mxser_close(). Remove the check.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-8-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
5c338fbf21 mxser: remove pointless xmit_buf checks
xmit_buf is supposed to exist in all these functions. I.e. from
tty_port_operations::activate() to ::shutdown(). So remove these checks.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-7-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
3b88dbff1c mxser: clean up tx handling in mxser_transmit_chars()
The port->icount.tx is handled in a too complicated manner. Instead of
remembering the original count and subtracting the new one from it,
simply increase tx for each character in the loop. No need for cnt
variable then.

Change also the "X = X & Y" assignment to simpler "X &= Y".

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-6-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
30f6027fe4 mxser: move MSR read to mxser_check_modem_status()
The MSR read is currently performed on both places where
mxser_check_modem_status() is called. So move it there to avoid code
duplication.

Rename the variable to msr while we move it, to actually see what
"status" we are testing.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-5-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
274ab58dc2 mxser: keep only !tty test in ISR
The others are superfluous with tty refcounting in place now. And they
are racy in fact:
* tty_port_initialized() reports false for a small moment after
  interrupts are enabled.
* closing is 1 while the port is still alive.

The queues are flushed later during close anyway. So there is no need
for this special handling. Actually, the ISR should not flush the
queues. It should behave as every other driver, just queue the chars
into tty buffer and go on. But this will be changed later. There is
still a lot code depending on having tty in ISR (and not only tty_port).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-4-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
568a2b9c12 mxser: rename mxser_close_port() to mxser_stop_rx()
As it is the only thing it does now. This is one of the future
serial_core hooks.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-3-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
e25ed43b4b mxser: remove wait for sent from mxser_close_port
mxser_close() behaves like this:
  -> tty_port_close_start()
    -> tty_wait_until_sent()
      -> mxser_wait_until_sent()
  -> mxser_close_port
    -> wait for TEMT

So it is already waited for TEMT through mxser_wait_until_sent() and
there is another round of waiting in mxser_close_port(). The latter one
is superfluous as nothing could be filled into the output FIFO. Remove
the call.

This helps unification among drivers (so that all behave the same) and
future use of tty_port_close().

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20211118073125.12283-2-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-25 18:33:21 +01:00
Jiri Slaby
d249e662c3 mxser: store FCR state in mxser_port::FCR
We force the FCR contents on many places in the code instead of writing
what was actually set in mxser_change_speed() (by ->activate() or
->set_serial_info()).

So introduce mxser_port::FCR to hold the proper contents and bitwise-OR
the value to what needs to be set on all those locations. That is,
clearing RX and/or TX FIFOs. Those flags are self-clearing, so no need
to set them to mxser_port::FCR.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-7-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:09 +02:00
Jiri Slaby
215fa41c2d mxser: don't read from UART_FCR
The UART_FCR register is write-only. When reading it, one gets contents
of (read-only) UART_IIR instead as they are shared. This mistake was
performed in mxser_flush_buffer() to clear FIFOs.

Actually FCR handling throughout the driver is completely broken. On
many places, it respects neither mu860 settings, nor FIFO (16450 vs
16550) setting. This patch doesn't help to fix this, it actually does
the same. We will introduce a mxser_port::FCR in the next patch to fix
this issue.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-6-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:09 +02:00
Jiri Slaby
ee7e5e66f2 mxser: move FIFO clearing to mxser_disable_and_clear_FIFO()
This code is used on two places, make a helper for disabling and
clearing FIFOs. And demangle the too complicated 'if' by using a local
variable.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-5-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:09 +02:00
Jiri Slaby
bf1434c1b7 mxser: simplify FCR computation in mxser_change_speed()
Provided FIFO is always enabled for MUST chips, move its FCR setting out
of PORT_8250/PORT_16450 special case in mxser_change_speed(). Now, we
can pre-set fcr to zero and invert the condition of the 'if'.

This makes the code more readable (no functional change intended).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-4-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:09 +02:00
Jiri Slaby
19236287d8 mxser: make mxser_port::ldisc_stop_rx a bool
It's used only as a yes-no variable, so make it a bool and switch the
set values appropriately.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-3-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:08 +02:00
Jiri Slaby
7d5006d59d mxser: simplify condition in mxser_receive_chars_new
mxser_receive_chars_old() is used whenever MOXA_MUST_LSR_RERR is set in
status no matter the HW ID (the last 'if'). So there is no need for
another check of MOXA_MUST_LSR_RERR _with_ hwid == MOXA_MUST_MU860_HWID
(the third 'if').  Hence remove this subcase. That allows us to check
status on a single line with both UART_LSR_BRK_ERROR_BITS (from the
second 'if') and MOXA_MUST_LSR_RERR (the last 'if').

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-2-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:08 +02:00
Jiri Slaby
3fdfa165d7 mxser: restore baud rate if its setting fails
If a user tries to set a too high rate, it fails due to check in
mxser_set_baud(). But the high rate remains set in termios, so the user
might think everything went smooth. Restore the baud rate from the
old_termios if this happens, so that user knows nothing was changed in
fact.

It used to behave the correct way many years ago, but somehow the
restoration vanished with commit 1c45607ad3 (Char: mxser, remove it)
-- the commit removed mxser's older clone.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210922075938.31390-1-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-05 14:08:08 +02:00
Dan Carpenter
2285c49639 mxser: use semi-colons instead of commas
This code works, but it's cleaner to use semi-colons at the end of
a statement instead of a comma.

Acked-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20210825072435.GB13013@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-08-26 14:48:40 +02:00
Jiri Slaby
9f90a4ddef tty: drop put_tty_driver
put_tty_driver() is an alias for tty_driver_kref_put(). There is no need
for two exported identical functions, therefore switch all users of
old put_tty_driver() to new tty_driver_kref_put() and remove the former
for good.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Scott Branden <scott.branden@broadcom.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: David Sterba <dsterba@suse.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Acked-by: Alex Elder <elder@linaro.org>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Acked-by: David Sterba <dsterba@suse.com>
Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210723074317.32690-8-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-27 12:17:21 +02:00
Jiri Slaby
39b7b42be4 tty: stop using alloc_tty_driver
alloc_tty_driver was deprecated by tty_alloc_driver in commit
7f0bc6a68e (TTY: pass flags to alloc_tty_driver) in 2012.

I never got into eliminating alloc_tty_driver until now. So we still
have two functions for allocating drivers which might be confusing. So
get rid of alloc_tty_driver uses to eliminate it for good in the next
patch.

Note we need to switch return value checking as tty_alloc_driver uses
ERR_PTR. And flags are now a parameter of tty_alloc_driver.

Cc: Richard Henderson <rth@twiddle.net>(odd fixer:ALPHA PORT)
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: David Sterba <dsterba@suse.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Johan Hovold <johan@kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Acked-by: David Sterba <dsterba@suse.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210723074317.32690-5-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-27 12:17:20 +02:00
Jiri Slaby
5d1ea1ad28 mxser: introduce mxser_16550A_or_MUST helper
This check is used in the code on many places. Either in positive or
negative form. So introduce a helper called mxser_16550A_or_MUST for
this purpose. And replace all the occurrences.

This simplifies many ifs in there.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-67-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:03 +02:00
Jiri Slaby
06cc52ef82 mxser: rename flags to old_speed in mxser_set_serial_info
Local 'flags' are used to store speed in mxser_set_serial_info, not
actual flags (by doing & ASYNC_SPD_MASK). So rename 'flags' to
'old_speed' (after what it is).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-66-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:03 +02:00
Jiri Slaby
1b3086b6e6 mxser: use port variable in mxser_set_serial_info
mxser_set_serial_info already defined a local 'port' of type struct
tty_port. So use it in the code everywhere.

This eliminates some text from the code there.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-65-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:03 +02:00
Jiri Slaby
202acdaa14 mxser: access info->MCR under info->slock
info->MCR is protected by info->slock all over the code. Extend the lock
in mxser_tiocmget around the info->MCR fetch too.

It likely doesn't change anything, but it's always good to be consistent.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-64-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:03 +02:00
Jiri Slaby
464fbf6c4f mxser: fix typos around enhanced mode
Fix spelling of "enhanced" in macros and comments around them.

While "enchance" comes from the original Moxa's driver, I don't think it
was meant to be that. From the context, they obviously mean "enhanced".

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-63-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:03 +02:00
Jiri Slaby
aaa28e9f25 mxser: decrypt FCR values
Currently, some of the values written to FCR are magic constants. But
they are composed of well-defined bits. Use these named macros in place
of the constants.

No changes in objdump -d.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-62-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
265ceff7ae mxser: remove xmit_cnt < 0 tests
mxser_port::xmit_cnt is unsigned, it cannot be negative. Therefore
remove all the xmit_cnt < 0 tests.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-61-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
740165f7ac mxser: introduce and use start/stop_tx helpers
Starting and stopping TX is performed on many places in the driver. It
is repeated outb and info->IER modification.  Create few helpers
(__mxser_start_tx, mxser_start_tx, __mxser_stop_tx) and use them in the
code instead of open coding.

This should be a base for an uart driver for this device in the future.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-60-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
be4866671f mxser: extract and dedup CTS handling
CTS is handled on two locations in mxser. Extract the code into
separation function mxser_handle_cts. And call it from the two
locations.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-59-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
8aff64e00f mxser: don't start TX from tty_operations::put_char
TX is not supposed to be started from tty_operations::put_char. Line
disciplines ought to call tty_operations::put_char several times and
then do a single tty_operations::flush_chars to start TX.

Fix this in mxser by removing TX startup from mxser_put_char.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-58-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
007bbdc875 mxser: cleanup mxser_dtr_rts
mxser_dtr_rts now does all inb, outb, & or | in a single statement.  The
code is hard to follow, so make it more readable by doing one-line =
one-statement.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-57-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
5990843328 mxser: cleanup mxser_rs_break
mxser_rs_break now does all inb, outb, & or | in a single statement. The
code is hard to follow, so make it more readable by doing one-line =
one-statement.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-56-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
987a4cfee5 mxser: remove pointless ioaddr checks
struct mxser_port::ioaddr can never be NULL once set in ->probe. Hence
the checks for it are pointless. Remove them.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-55-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
ad1c92ff6e mxser: alloc only needed # of ports
Many boards have only 2 ports. But we always allocate 8 ports (struct
mxser_port) in each struct mxser_board.

Switch this to an empty/variable sized array ([]) and allocate the
needed number of ports using struct_size helper in ->probe.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-54-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
f8b6b327aa mxser: alloc struct mxser_board dynamically
There is no need to preallocate an array of four struct mxser_board's.
In most cases a single board or two will be present in a machine. So
allocate struct mxser_board as needed in ->probe.

This makes mxser_boards a bit array. There we store which indexes are
free (unallocated).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-53-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
13d4aba8a9 mxser: make mxser_board::idx really an index
mxser_board::idx is named as index, but actually contain a base. So
assign index there. And for base, introduce a local variable.

This is needed for the next patch (use index as a bit index).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-52-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
42ad25fc46 mxser: rework and simplify mxser_open
In mxser_open, tty->port is already set thanks to
tty_port_register_device in ->probe. So we can simply use container_of
to deduce the struct mxser_port's pointer. Thus avoiding divisions and
complex computations.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-51-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
c3db20c3b7 mxser: cleanup mxser_process_txrx_fifo
Rename process_txrx_fifo to mxser_process_txrx_fifo and:
* remove useless parentheses
* return from the 'if's true branch and process the rest in normal code
  flow (shift the code one level left)

All this to make the code more readable.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-50-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:02 +02:00
Jiri Slaby
c24c31ff4a mxser: remove mxser_cardinfo
Now that mxser_cards array (of struct mxser_cardinfo) contains only port
count and a quirk, we can encode these two directly into
pci_device_id::driver_data. And we can remove this struct completely.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-49-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
1e37f7333c mxser: remove info message from probe
There is a dev_info in ->probe which prints device's name, bus and slot
numbers. All these can be fetched from the lspci output. So remove this
useless print.

This eliminates the whole mxser_cardinfo::name field.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-48-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
7f0e79dc09 mxser: move request irq to probe and switch to managed
Move request_irq from mxser_initbrd to mxser_probe so that we can switch
it to managed request. It simplifies the cleanup code.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-47-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
dcb04e21bb mxser: pci, switch to managed resources
Switch to managed resources for PCI using pcim_enable_device.
Regions and device disabling is now taken care of by the core and we
need not unwind. Neither in ->probe, nor in ->remove. That simplifies
the code.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-46-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
d450f0852f mxser: inline mxser_board_remove into mxser_remove
The only user of mxser_board_remove is mxser_remove. Move there those
few lines.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-45-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
57faa7d614 mxser: move board init into mxser_initbrd
What's done in ->probe for board is actually its initialization. So move
it to mxser_initbrd where it belongs.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-44-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
b441eb0f69 mxser: clean up the rest of MUST helpers
Clean up the rest of MUST helpers. They all can use the newly added
mxser_must_set_EFR. And passing a bool instead of having two functions
(_enable+_disable) simplifies the code a lot too.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-43-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
b286484b3b mxser: introduce mxser_must_select_bank and use it
Again, selecting a bank in the EFR register is duplicated many times.
Extract it to a separate function (mxser_must_select_bank) and use it on
all the places.

This cleans up most of the helpers. And mxser_get_must_hardware_id now
returns the HW ID directly, not via a by-reference parameter.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-42-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
edb7d27cd1 mxser: dedup mxser_must_set_enhance_mode
There are multiple copies of setting the EFR register. Separate it to a
new universal function called __mxser_must_set_EFR. And use it in the
code by introducing mxser_must_set_enhance_mode instead of
mxser_disable_must_enchance_mode and mxser_enable_must_enchance_mode.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-41-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
238d117d17 mxser: simplify mxser_ioctl_op_mode
* ModeMask local array is just inverted OP_MODE_MASK shifted by shiftbit.
  Drop this array and use the value directly.
* return from the if's true branch and drop 'else' branch by moving the
  code completely outside the if.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-40-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
9fae5f857e mxser: extract mxser_ioctl_op_mode
This ioctl code sets RS232, RS422 or RS485 mode. Move the code to a
separate function (mxser_ioctl_op_mode) with a note that these
mxser-special ioctls should be likely replaced eventually by TIOCGRS485
and TIOCSRS485.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-39-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
2c21832b55 mxser: cleanup mxser_change_speed
* use UART macros instead of magic constants
* let the default case reuse already existing code (CS5 case)

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-38-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
d811b26ba3 mxser: drop mxser_port::custom_divisor
It's an once-set constant, so define a macro for the constant
(MXSER_CUSTOM_DIVISOR) and use it in the code instead.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-37-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:01 +02:00
Jiri Slaby
a6970c39c3 mxser: drop mxser_port::baud_base
It's an once-set constant, so define a macro for the constant
(MXSER_BAUD_BASE) and use it in the code instead.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-36-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:00 +02:00
Jiri Slaby
01c3de9a10 mxser: remove unused mxser_port::stop_rx
It's been a long time since mxser_port::stop_rx was abandoned. Remove it.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210618061516.662-35-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-18 13:10:00 +02:00