Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
2f4c2749
Commit
2f4c2749
authored
Jan 13, 2003
by
Miles Bader
Committed by
Linus Torvalds
Jan 13, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PATCH] Update v850 nb85e_uart serial driver to set baud min/max
parent
a73f6b51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
18 deletions
+47
-18
drivers/serial/nb85e_uart.c
drivers/serial/nb85e_uart.c
+47
-18
No files found.
drivers/serial/nb85e_uart.c
View file @
2f4c2749
/*
/*
* drivers/serial/nb85e_uart.c -- Serial I/O using V850E/NB85E on-chip UART
* drivers/serial/nb85e_uart.c -- Serial I/O using V850E/NB85E on-chip UART
*
*
* Copyright (C) 2001,02 NEC Corporation
* Copyright (C) 2001,02
,03
NEC Corporation
* Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
* Copyright (C) 2001,02
,03
Miles Bader <miles@gnu.org>
*
*
* This file is subject to the terms and conditions of the GNU General
* This file is subject to the terms and conditions of the GNU General
* Public License. See the file COPYING in the main directory of this
* Public License. See the file COPYING in the main directory of this
...
@@ -31,6 +31,9 @@
...
@@ -31,6 +31,9 @@
#define NB85E_UART_INIT_CFLAGS (B115200 | CS8 | CREAD)
#define NB85E_UART_INIT_CFLAGS (B115200 | CS8 | CREAD)
#endif
#endif
/* XXX This should be in a header file. */
#define NB85E_UART_BRGC_MIN 8
/* A string used for prefixing printed descriptions; since the same UART
/* A string used for prefixing printed descriptions; since the same UART
macro is actually used on other chips than the V850E/NB85E. This must
macro is actually used on other chips than the V850E/NB85E. This must
be a constant string. */
be a constant string. */
...
@@ -38,6 +41,29 @@
...
@@ -38,6 +41,29 @@
#define NB85E_UART_CHIP_NAME "V850E/NB85E"
#define NB85E_UART_CHIP_NAME "V850E/NB85E"
#endif
#endif
/* Helper functions for doing baud-rate/frequency calculations. */
/* Calculate the minimum value for CKSR on this processor. */
static
inline
unsigned
cksr_min
(
void
)
{
int
min
=
0
;
unsigned
freq
=
NB85E_UART_BASE_FREQ
;
while
(
freq
>
NB85E_UART_CKSR_MAX_FREQ
)
{
freq
>>=
1
;
min
++
;
}
return
min
;
}
/* Minimum baud rate possible. */
#define min_baud() \
((NB85E_UART_BASE_FREQ >> NB85E_UART_CKSR_MAX) / (2 * 255) + 1)
/* Maximum baud rate possible. The error is quite high at max, though. */
#define max_baud() \
((NB85E_UART_BASE_FREQ >> cksr_min()) / (2 * NB85E_UART_BRGC_MIN))
/* Low-level UART functions. */
/* Low-level UART functions. */
...
@@ -60,7 +86,7 @@ static inline void nb85e_uart_delay (unsigned cycles)
...
@@ -60,7 +86,7 @@ static inline void nb85e_uart_delay (unsigned cycles)
modes' bits in CFLAGS, and a baud-rate of BAUD. */
modes' bits in CFLAGS, and a baud-rate of BAUD. */
void
nb85e_uart_configure
(
unsigned
chan
,
unsigned
cflags
,
unsigned
baud
)
void
nb85e_uart_configure
(
unsigned
chan
,
unsigned
cflags
,
unsigned
baud
)
{
{
int
cksr_min
,
flags
;
int
flags
;
unsigned
new_config
=
0
;
/* What we'll write to the control reg. */
unsigned
new_config
=
0
;
/* What we'll write to the control reg. */
unsigned
new_clk_divlog2
;
/* New baud-rate generate clock divider. */
unsigned
new_clk_divlog2
;
/* New baud-rate generate clock divider. */
unsigned
new_brgen_count
;
/* New counter max for baud-rate generator.*/
unsigned
new_brgen_count
;
/* New counter max for baud-rate generator.*/
...
@@ -68,14 +94,12 @@ void nb85e_uart_configure (unsigned chan, unsigned cflags, unsigned baud)
...
@@ -68,14 +94,12 @@ void nb85e_uart_configure (unsigned chan, unsigned cflags, unsigned baud)
unsigned
old_config
,
old_clk_divlog2
,
old_brgen_count
;
unsigned
old_config
,
old_clk_divlog2
,
old_brgen_count
;
/* Calculate new baud-rate generator config values. */
/* Calculate new baud-rate generator config values. */
cksr_min
=
0
;
while
((
NB85E_UART_BASE_FREQ
>>
cksr_min
)
>
NB85E_UART_CKSR_MAX_FREQ
)
cksr_min
++
;
/* Calculate the log2 clock divider and baud-rate counter values
/* Calculate the log2 clock divider and baud-rate counter values
(note that the UART divides the resulting clock by 2, so
(note that the UART divides the resulting clock by 2, so
multiply BAUD by 2 here to compensate). */
multiply BAUD by 2 here to compensate). */
calc_counter_params
(
NB85E_UART_BASE_FREQ
,
baud
*
2
,
calc_counter_params
(
NB85E_UART_BASE_FREQ
,
baud
*
2
,
cksr_min
,
NB85E_UART_CKSR_MAX
,
8
/*bits*/
,
cksr_min
()
,
NB85E_UART_CKSR_MAX
,
8
/*bits*/
,
&
new_clk_divlog2
,
&
new_brgen_count
);
&
new_clk_divlog2
,
&
new_brgen_count
);
/* Figure out new configuration of control register. */
/* Figure out new configuration of control register. */
...
@@ -443,10 +467,18 @@ static void
...
@@ -443,10 +467,18 @@ static void
nb85e_uart_set_termios
(
struct
uart_port
*
port
,
struct
termios
*
termios
,
nb85e_uart_set_termios
(
struct
uart_port
*
port
,
struct
termios
*
termios
,
struct
termios
*
old
)
struct
termios
*
old
)
{
{
/* FIXME: Which termios flags does this driver support? --rmk */
unsigned
cflags
=
termios
->
c_cflag
;
nb85e_uart_configure
(
port
->
line
,
termios
->
c_cflags
,
/* Restrict flags to legal values. */
uart_get_baud_rate
(
port
,
termios
));
if
((
cflags
&
CSIZE
)
!=
CS7
&&
(
cflags
&
CSIZE
)
!=
CS8
)
/* The new value of CSIZE is invalid, use the old value. */
cflags
=
(
cflags
&
~
CSIZE
)
|
(
old
->
c_cflag
&
CSIZE
);
termios
->
c_cflag
=
cflags
;
nb85e_uart_configure
(
port
->
line
,
cflags
,
uart_get_baud_rate
(
port
,
termios
,
old
,
min_baud
(),
max_baud
()));
}
}
static
const
char
*
nb85e_uart_type
(
struct
uart_port
*
port
)
static
const
char
*
nb85e_uart_type
(
struct
uart_port
*
port
)
...
@@ -519,7 +551,6 @@ static int __init nb85e_uart_init (void)
...
@@ -519,7 +551,6 @@ static int __init nb85e_uart_init (void)
unsigned
chan
;
unsigned
chan
;
for
(
chan
=
0
;
chan
<
NB85E_UART_NUM_CHANNELS
;
chan
++
)
{
for
(
chan
=
0
;
chan
<
NB85E_UART_NUM_CHANNELS
;
chan
++
)
{
int
cksr_min
;
struct
uart_port
*
port
=
&
nb85e_uart_ports
[
chan
];
struct
uart_port
*
port
=
&
nb85e_uart_ports
[
chan
];
memset
(
port
,
0
,
sizeof
*
port
);
memset
(
port
,
0
,
sizeof
*
port
);
...
@@ -550,15 +581,13 @@ static int __init nb85e_uart_init (void)
...
@@ -550,15 +581,13 @@ static int __init nb85e_uart_init (void)
the framework will puke during its internal
the framework will puke during its internal
calculations, and force the baud rate to be 9600.
calculations, and force the baud rate to be 9600.
To be accurate though, just repeat the calculation
To be accurate though, just repeat the calculation
we use when actually setting the speed. */
we use when actually setting the speed.
cksr_min
=
0
;
while
((
NB85E_UART_BASE_FREQ
>>
cksr_min
)
The `* 8' means `* 16 / 2': 16 to account for for
>
NB85E_UART_CKSR_MAX_FREQ
)
cksr_min
++
;
/* The `* 8' means `* 16 / 2': 16 to account for for
the serial framework's built-in bias, and 2 because
the serial framework's built-in bias, and 2 because
there's an additional / 2 in the hardware. */
there's an additional / 2 in the hardware. */
port
->
uartclk
=
(
NB85E_UART_BASE_FREQ
>>
cksr_min
)
*
8
;
port
->
uartclk
=
(
NB85E_UART_BASE_FREQ
>>
cksr_min
())
*
8
;
uart_add_one_port
(
&
nb85e_uart_driver
,
port
);
uart_add_one_port
(
&
nb85e_uart_driver
,
port
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment