more serial cleanup
Subsystems (2)
v2 cover more serial cleanup
Hi,
v2: function rename and rebase over next
Today we have a wired implemntation of the console which mix serial and others. Today on serial we init and start the port at probe time.
Which is wrong as we need to start the port only if used by barebox. So linux (on at91 as example) may use for uncompress or debug ll the wrong usart.
This patch series fix it by introducing startup and shutdown callback to the console_device.
This also drop the exposition of for_each_console and the list outside of the console implemetaiton
This is an other step to the full rework of the console API to split tty implementation form console.
The following changes since commit 705dbd7c795bbdfb448e1d0ace89d98cbceaaec1:
Merge branch 'for-next/tegra' into next (2013-10-02 11:07:14 +0200)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/serial_more_cleanup
for you to fetch changes up to ded7b8f151d0fc204f46c6ea070eaa8f51858eb3:
serial: atmel: add start and shutdown support (2013-10-03 15:12:55 +0800)
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (8):
console: factorise function to get the first enabled console
console: factorise function to get the console by name
console: introduce startup and shutdown
loadxy: use console_open/close
console: console_get_by_name pass flags
animeo_ip: update to use console_open/close for rs485 crossed detection
serial: amba-pl011: add start and shutdown support
serial: atmel: add start and shutdown support
arch/arm/boards/animeo_ip/init.c | 7 +++++-- arch/ppc/mach-mpc85xx/fdt.c | 4 +--- commands/loadb.c | 22 +--------------------- commands/loadxy.c | 75 +++++++++++++++++++++++++++------------------------------------------------ common/console.c | 6 ++++++ common/console_common.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/console_simple.c | 3 +++ drivers/serial/amba-pl011.c | 39 ++++++++++++++++++++++++++++++--------- drivers/serial/atmel.c | 55 +++++++++++++++++++++++++++++++++++++++++-------------- include/console.h | 6 ++++++ 10 files changed, 195 insertions(+), 97 deletions(-)
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/8 console: factorise function to get the first enabled console
rename it to console_get_first_active
--- arch/ppc/mach-mpc85xx/fdt.c | 4 +--- commands/loadb.c | 22 +--------------------- commands/loadxy.c | 24 ++---------------------- common/console_common.c | 21 +++++++++++++++++++++ include/console.h | 1 + 5 files changed, 26 insertions(+), 46 deletions(-)
arch/ppc/mach-mpc85xx/fdt.c +1 -3
@@ -70,9 +70,7 @@ static int fdt_stdout_setup(struct device_node *blob) goto error; } -for_each_console (cdev) -if ((cdev->f_active & (CONSOLE_STDIN |CONSOLE_STDOUT ))) -break ; + cdev =console_get_first_active ();if (cdev)sprintf (sername,"serial%d" , cdev->dev->id);else
commands/loadb.c +1 -21
@@ -591,26 +591,6 @@ err_quit: }/** -* @brief returns current used console device -* -* @return console device which is registered with CONSOLE_STDIN and -* CONSOLE_STDOUT -*/ -static struct console_device *get_current_console (void ) -{ -struct console_device *cdev; -/* -* Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the -* same output console -*/ -for_each_console (cdev) { -if ((cdev->f_active & (CONSOLE_STDIN |CONSOLE_STDOUT ))) -return cdev; - } -return NULL ; -} - -/** * @brief provide the loadb(Kermit) or loadY mode support * * @param cmdtp
@@ -650,7 +630,7 @@ static int do_load_serial_bin(int argc, char *argv[]) } } - cdev =get_current_console (); + cdev =console_get_first_active ();if (NULL == cdev) {printf ("%s:No console device with STDIN and STDOUT\n" , argv[0 ]);return -ENODEV ;
commands/loadxy.c +2 -22
@@ -40,26 +40,6 @@#define DEF_FILE "image.bin" -/** -* @brief returns current used console device -* -* @return console device which is registered with CONSOLE_STDIN and -* CONSOLE_STDOUT -*/ -static struct console_device *get_current_console (void ) -{ -struct console_device *cdev; -/* -* Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the -* same output console -*/ -for_each_console (cdev) { -if ((cdev->f_active & (CONSOLE_STDIN |CONSOLE_STDOUT ))) -return cdev; - } -return NULL ; -} -static int console_change_speed (struct console_device *cdev,int baudrate) {int current_baudrate;
@@ -134,7 +114,7 @@ static int do_loady(int argc, char *argv[])if (cname) cdev =get_named_console (cname);else - cdev =get_current_console (); + cdev =console_get_first_active ();if (!cdev) {printf ("%s:No console device %s with STDIN and STDOUT\n" , argv[0 ], cname ? cname :"default" );
@@ -202,7 +182,7 @@ static int do_loadx(int argc, char *argv[])if (cname) cdev =get_named_console (cname);else - cdev =get_current_console (); + cdev =console_get_first_active ();if (!cdev) {printf ("%s:No console device %s with STDIN and STDOUT\n" , argv[0 ], cname ? cname :"default" );
common/console_common.c +21 -0
@@ -181,3 +181,24 @@ struct console_device *console_get_by_dev(struct device_d *dev)return NULL ; }EXPORT_SYMBOL (console_get_by_dev); + +/** +* @brief returns current used console device +* +* @return console device which is registered with CONSOLE_STDIN and +* CONSOLE_STDOUT +*/ +struct console_device *console_get_first_active (void ) +{ +struct console_device *cdev; +/* +* Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the +* same output console +*/ +for_each_console (cdev) { +if ((cdev->f_active & (CONSOLE_STDIN |CONSOLE_STDOUT ))) +return cdev; + } +return NULL ; +} +EXPORT_SYMBOL (console_get_first_active);
include/console.h +1 -0
@@ -65,5 +65,6 @@ bool console_is_input_allow(void);void console_allow_input (bool val);extern int barebox_loglevel; +struct console_device *console_get_first_active (void );#endif
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/8 console: factorise function to get the console by name
rename it to console_get_by_name
--- commands/loadxy.c | 26 ++------------------------ common/console_common.c | 17 +++++++++++++++++ include/console.h | 1 + 3 files changed, 20 insertions(+), 24 deletions(-)
commands/loadxy.c +2 -24
@@ -57,28 +57,6 @@ static int console_change_speed(struct console_device *cdev, int baudrate)return current_baudrate; } -static struct console_device *get_named_console (const char *cname) -{ -struct console_device *cdev; -const char *target; - -/* -* Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the -* same output console -*/ -for_each_console (cdev) { - target =dev_id (&cdev->class_dev); -if (strlen (target) !=strlen (cname)) -continue ; -printf ("RJK: looking for %s in console name %s\n" , - cname, target); -if ((cdev->f_active & (CONSOLE_STDIN |CONSOLE_STDOUT )) - && !strcmp (cname, target)) -return cdev; - } -return NULL ; -} -/** * @brief provide the loady(Y-Modem or Y-Modem/G) support *
@@ -112,7 +90,7 @@ static int do_loady(int argc, char *argv[]) }if (cname) - cdev =get_named_console (cname); + cdev =console_get_by_name (cname);else cdev =console_get_first_active ();if (!cdev) {
@@ -180,7 +158,7 @@ static int do_loadx(int argc, char *argv[]) }if (cname) - cdev =get_named_console (cname); + cdev =console_get_by_name (cname);else cdev =console_get_first_active ();if (!cdev) {
common/console_common.c +17 -0
@@ -202,3 +202,20 @@ struct console_device *console_get_first_active(void)return NULL ; }EXPORT_SYMBOL (console_get_first_active); + +struct console_device *console_get_by_name (const char *cname) +{ +struct console_device *cdev; +const char *target; + +for_each_console (cdev) { + target =dev_id (&cdev->class_dev); +if (strcmp (cname, target)) +continue ; + if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) +return cdev; +return NULL ; + } +return NULL ; +} +EXPORT_SYMBOL (console_get_by_name);
include/console.h +1 -0
@@ -66,5 +66,6 @@ void console_allow_input(bool val);extern int barebox_loglevel;struct console_device *console_get_first_active (void ); +struct console_device *console_get_by_name (const char *cname);#endif
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/8] console: factorise function to get the console by name
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
rename it to
console_get_by_nameSigned-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
common/console_common.c +6
-0+struct console_device *console_get_by_name (const char *cname) +{ +struct console_device *cdev; +const char *target; + +for_each_console (cdev) {
common/console_common.c struct console_device *console_get_first_active(void) · line 221
Quoted 10 lines
common/console_common.c +10
-0+ target =dev_id (&cdev->class_dev); +if (strcmp (cname, target)) +continue ; + if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) +return cdev; +return NULL ; + } +return NULL ; +} +EXPORT_SYMBOL (console_get_by_name);
I think this function should return the console regardless of whether it's active or not. This makes the console_get_by_name_flags you introduce later unnecessary. Also the loadxyz code shouldn't care if it's activated but instead just activate the console if necessary.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/8] console: factorise function to get the console by name
Quoted 18 lines · Sascha Hauer
Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
rename it to
console_get_by_nameSigned-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
common/console_common.c +13
-0+struct console_device *console_get_by_name (const char *cname) +{ +struct console_device *cdev; +const char *target; + +for_each_console (cdev) { + target =dev_id (&cdev->class_dev); +if (strcmp (cname, target)) +continue ; + if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) +return cdev; +return NULL ; + }
Quoted 8 lines
common/console_common.c struct console_device *console_get_first_active(void) · line 221
Quoted 3 lines
common/console_common.c +3
-0+return NULL ; +} +EXPORT_SYMBOL (console_get_by_name);I think this function should return the console regardless of whether it's active or not. This makes the
console_get_by_name_flagsyou introduce later unnecessary. Also the loadxyz code shouldn't care if it's activated but instead just activate the console if necessary.
agreed that's why I change this in patch 5
as now the loadxyz just check if the cdev support input and output and not if active or not
but first I factorise it in this patch to do not 2 stuff at a time I hate doing 2 stuff in the same patch impossible to bisect
Best Regards,
J.
Quoted 8 lines
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/8] console: factorise function to get the console by name
Quoted 28 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 18 lines · Sascha Hauer
Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
rename it to
console_get_by_nameSigned-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
common/console_common.c +13
-0+struct console_device *console_get_by_name (const char *cname) +{ +struct console_device *cdev; +const char *target; + +for_each_console (cdev) { + target =dev_id (&cdev->class_dev); +if (strcmp (cname, target)) +continue ; + if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) +return cdev; +return NULL ; + }Quoted 8 lines
common/console_common.c struct console_device *console_get_first_active(void) · line 221
Quoted 3 lines
common/console_common.c +3
-0+return NULL ; +} +EXPORT_SYMBOL (console_get_by_name);I think this function should return the console regardless of whether it's active or not. This makes the
console_get_by_name_flagsyou introduce later unnecessary. Also the loadxyz code shouldn't care if it's activated but instead just activate the console if necessary.
Quoted 3 lines
agreed that's why I change this in patch 5
as now the loadxyz just check if the cdev support input and output and not if active or not
Ok, I somewhat misread the patch. I still think though that a function
struct console_device *console_get_by_name(const char *cname, int flags);
is a bit unclear. This function should either return the cdev by name *or* check the flags, but not both,
The loadxy code now ends up with:
if (cname) cdev = console_get_by_name(cname, CONSOLE_STDIN & CONSOLE_STDOUT); else cdev = console_get_first_active();
So if cname is given you explicitly ask for a console capable of input *and* output. If not, you ask for the first actve console, that is the first console which has input *or* output activated.
The loadxy code should rather look like:
if (cname) cdev = console_get_by_name(cname); else cdev = console_get_first_active(); if (!cdev) barf_and_bail_out; if (!console_can_do_input(cdev) || !console_can_do_output()) barf_and_bail_out;
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 3/8 console: introduce startup and shutdown
In reply to Jean-Christophe PLAGNIOL-VILLARDso enable the uart only if used
so linux can detect the right one enable if it want
--- common/console.c | 6 ++++++ common/console_common.c | 35 +++++++++++++++++++++++++++++++++++ common/console_simple.c | 3 +++ include/console.h | 4 ++++ 4 files changed, 48 insertions(+)
common/console.c +6 -0
@@ -83,8 +83,14 @@ static int console_std_set(struct device_d *dev, struct param_d *param,if (flag && !cdev->f_active) {/* The device is being activated, set its baudrate */ +if (cdev->startup) + cdev->startup (cdev);if (cdev->setbrg) cdev->setbrg (cdev, cdev->baudrate); + }else if (!flag && cdev->f_active) { +/* The device is being deactivated, shutdown it */ +if (cdev->shutdown) + cdev->shutdown (cdev); } active[i] =0 ;
common/console_common.c +35 -0
@@ -219,3 +219,38 @@ struct console_device *console_get_by_name(const char *cname)return NULL ; }EXPORT_SYMBOL (console_get_by_name); + +int console_open (struct console_device *cdev) +{ +int ret; + +if (cdev->f_active) +return 0 ; + +if (cdev->startup) { + ret = cdev->startup (cdev); +if (ret) +return ret; + } + +if (cdev->setbrg) { + ret = cdev->setbrg (cdev, cdev->baudrate); +if (ret) { +console_close (cdev); +return ret; + } + } + +return 0 ; +} +EXPORT_SYMBOL (console_open); + +void console_close (struct console_device *cdev) +{ +if (!cdev->f_active) +return ; + +if (cdev->shutdown) + cdev->shutdown (cdev); +} +EXPORT_SYMBOL (console_close);
common/console_simple.c +3 -0
@@ -89,6 +89,9 @@ int console_register(struct console_device *newcdev) console_list.prev = console_list.next = &newcdev->list; newcdev->list.prev = newcdev->list.next = &console_list; +if (newcdev->startup) + newcdev->startup (newcdev); +if (newcdev->setbrg) { newcdev->baudrate =CONFIG_BAUDRATE ; newcdev->setbrg (newcdev, newcdev->baudrate);
include/console.h +4 -0
@@ -37,6 +37,8 @@ struct console_device {struct device_d *dev;struct device_d class_dev; +int (*startup)(struct console_device *cdev); +void (*shutdown)(struct console_device *cdev);int (*tstc)(struct console_device *cdev);void (*putc)(struct console_device *cdev,char c);int (*getc)(struct console_device *cdev);
@@ -67,5 +69,7 @@ void console_allow_input(bool val);extern int barebox_loglevel;struct console_device *console_get_first_active (void );struct console_device *console_get_by_name (const char *cname); +int console_open (struct console_device *cdev); +void console_close (struct console_device *cdev);#endif
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 4/8 loadxy: use console_open/close
In reply to Jean-Christophe PLAGNIOL-VILLARDso we can use non startup console
--- commands/loadxy.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
commands/loadxy.c +23 -2
@@ -99,6 +99,13 @@ static int do_loady(int argc, char *argv[])return -ENODEV ; } + rcode =console_open (cdev); +if (rcode) { +printf ("%s: can not open console %s\n" , + argv[0 ], cname ? cname :"default" ); +return rcode; + } + current_baudrate =console_change_speed (cdev, load_baudrate);printf ("## Ready for binary (ymodem) download at %d bps...\n" , load_baudrate ? load_baudrate : current_baudrate);
@@ -115,6 +122,8 @@ static int do_loady(int argc, char *argv[])console_change_speed (cdev, current_baudrate); +console_close (cdev); +return rcode; }
@@ -167,6 +176,13 @@ static int do_loadx(int argc, char *argv[])return -ENODEV ; } + rcode =console_open (cdev); +if (rcode) { +printf ("%s: can not open console %s\n" , + argv[0 ], cname ? cname :"default" ); +return rcode; + } +/* Load Defaults */ if (!output_file) output_file =DEF_FILE ;
@@ -175,7 +191,8 @@ static int do_loadx(int argc, char *argv[]) ofd =open (output_file, open_mode);if (ofd <0 ) {perror (argv[0 ]); -return 3 ; + rcode =3 ; + goto err; }/* Seek to the right offset */ if (offset) {
@@ -184,7 +201,8 @@ static int do_loadx(int argc, char *argv[])close (ofd); ofd =0 ;perror (argv[0 ]); -return 4 ; + rcode =4 ; + goto err; } }
@@ -199,6 +217,9 @@ static int do_loadx(int argc, char *argv[]) }console_change_speed (cdev, current_baudrate); +err: +console_close (cdev); +return rcode; }
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 5/8 console: console_get_by_name pass flags
In reply to Jean-Christophe PLAGNIOL-VILLARDthis will allow to get console by name and specific feature we use CONSOLE_STDIN to check input support and CONSOLE_STDOUT for output support at driver level
this will also allow to use non active console for loadxy as example
--- commands/loadxy.c | 4 ++-- common/console_common.c | 10 ++++++---- include/console.h | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-)
commands/loadxy.c +2 -2
@@ -90,7 +90,7 @@ static int do_loady(int argc, char *argv[]) }if (cname) - cdev =console_get_by_name (cname); + cdev =console_get_by_name (cname,CONSOLE_STDIN &CONSOLE_STDOUT );else cdev =console_get_first_active ();if (!cdev) {
@@ -167,7 +167,7 @@ static int do_loadx(int argc, char *argv[]) }if (cname) - cdev =console_get_by_name (cname); + cdev =console_get_by_name (cname,CONSOLE_STDIN &CONSOLE_STDOUT );else cdev =console_get_first_active ();if (!cdev) {
common/console_common.c +6 -4
@@ -203,7 +203,7 @@ struct console_device *console_get_first_active(void) }EXPORT_SYMBOL (console_get_first_active); -struct console_device *console_get_by_name (const char *cname) +struct console_device *console_get_by_name (const char *cname,int flags) {struct console_device *cdev;const char *target;
@@ -212,9 +212,11 @@ struct console_device *console_get_by_name(const char *cname) target =dev_id (&cdev->class_dev);if (strcmp (cname, target))continue ; - if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT)) -return cdev; -return NULL ; +if ((flags &CONSOLE_STDIN ) && !(cdev->tstc && cdev->getc)) +return NULL ; +if ((flags &CONSOLE_STDOUT ) && !cdev->putc) +return NULL ; +return cdev; }return NULL ; }
include/console.h +1 -1
@@ -68,7 +68,7 @@ void console_allow_input(bool val);extern int barebox_loglevel;struct console_device *console_get_first_active (void ); -struct console_device *console_get_by_name (const char *cname); +struct console_device *console_get_by_name (const char *cname,int flags);int console_open (struct console_device *cdev);void console_close (struct console_device *cdev);
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 6/8 animeo_ip: update to use console_open/close for rs485 crossed detection
In reply to Jean-Christophe PLAGNIOL-VILLARD--- arch/arm/boards/animeo_ip/init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/boards/animeo_ip/init.c +5 -2
@@ -343,8 +343,6 @@ static void animeo_ip_shutdown(void)* and use it for decompress */ animeo_ip_shutdown_uart (IOMEM (AT91_DBGU +AT91_BASE_SYS )); -animeo_ip_shutdown_uart (IOMEM (AT91SAM9260_BASE_US0 )); -animeo_ip_shutdown_uart (IOMEM (AT91SAM9260_BASE_US1 )); }static int animeo_ip_console_init (void )
@@ -397,8 +395,10 @@ static int animeo_ip_cross_detect_init(void)return -EINVAL ;at91_set_gpio_input (AT91_PIN_PC16 ,0 ); +console_open (cs0); cs0->set_mode (cs0,CONSOLE_MODE_RS485 ); cs0->setbrg (cs0,38400 ); +console_open (cs1); cs1->set_mode (cs1,CONSOLE_MODE_RS485 ); cs1->setbrg (cs1,38400 );
@@ -426,6 +426,9 @@ err:pr_info ("rs485 ports %scrossed\n" , crossed ?"" :"not " ); +console_close (cs0); +console_close (cs1); +return 0 ; }late_initcall (animeo_ip_cross_detect_init);
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 7/8 serial: amba-pl011: add start and shutdown support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- drivers/serial/amba-pl011.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
drivers/serial/amba-pl011.c +30 -9
@@ -147,22 +147,24 @@ static void pl011_rlcr(struct amba_uart_port *uart, u32 lcr) } } -int pl011_init_port (struct console_device *cdev) +static void pl011_shutdown (struct console_device *cdev) {struct amba_uart_port *uart =to_amba_uart_port (cdev); -/* -** First, disable everything. -*/ writel (0x0 , uart->base +UART011_CR ); +clk_disable (uart->clk); +} + +static int pl011_startup (struct console_device *cdev) +{ +struct amba_uart_port *uart =to_amba_uart_port (cdev); +/* * Try to enable the clock producer. */ clk_enable (uart->clk); - uart->uartclk =clk_get_rate (uart->clk); -/* ** Set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled. */
@@ -177,6 +179,25 @@ int pl011_init_port (struct console_device *cdev)return 0 ; } +static void pl011_port_init (struct console_device *cdev) +{ +struct amba_uart_port *uart =to_amba_uart_port (cdev); + +/* +** First, disable everything. +*/ +pl011_shutdown (cdev); + +/* +* Try to enable the clock producer. +*/ +clk_enable (uart->clk); + + uart->uartclk =clk_get_rate (uart->clk); + +clk_disable (uart->clk); +} +static int pl011_probe (struct amba_device *dev,const struct amba_id *id) {struct amba_uart_port *uart;
@@ -192,14 +213,14 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id) cdev = &uart->uart; cdev->dev = &dev->dev; + cdev->startup = pl011_startup; + cdev->shutdown = pl011_shutdown; cdev->tstc = pl011_tstc; cdev->putc = pl011_putc; cdev->getc = pl011_getc; cdev->setbrg = pl011_setbaudrate; -pl011_init_port (cdev); - -/* Enable UART */ +pl011_port_init (cdev);console_register (cdev);
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 8/8 serial: atmel: add start and shutdown support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- drivers/serial/atmel.c | 55 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 14 deletions(-)
drivers/serial/atmel.c +41 -14
@@ -20,6 +20,7 @@#include <malloc.h> #include <io.h> #include <linux/clk.h> +#include <linux/err.h> /* USART3 register offsets */ #define USART3_CR 0x0000
@@ -388,31 +389,50 @@ static int atmel_serial_set_mode(struct console_device *cdev, enum console_modereturn 0 ; } +static void atmel_serial_shutdown (struct console_device *cdev) +{ +struct atmel_uart_port *uart =to_atmel_uart_port (cdev); + +writel (USART3_BIT (RXDIS ) |USART3_BIT (TXDIS ), uart->base +USART3_CR ); +writel (0 , uart->base +USART3_BRGR ); + +clk_disable (uart->clk); +} + +static int atmel_serial_startup (struct console_device *cdev) +{ +struct atmel_uart_port *uart =to_atmel_uart_port (cdev); + +clk_enable (uart->clk); + +writel (USART3_BIT (RXEN ) |USART3_BIT (TXEN ), uart->base +USART3_CR ); + +writel ((USART3_BF (USART_MODE ,USART3_USART_MODE_NORMAL ) + |USART3_BF (USCLKS ,USART3_USCLKS_MCK ) + |USART3_BF (CHRL ,USART3_CHRL_8 ) + |USART3_BF (PAR ,USART3_PAR_NONE ) + |USART3_BF (NBSTOP ,USART3_NBSTOP_1 )), + uart->base +USART3_MR ); + +return 0 ; +} +/* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. * */ -static int atmel_serial_init_port (struct console_device *cdev) +static void atmel_serial_init (struct console_device *cdev) { -struct device_d *dev = cdev->dev;struct atmel_uart_port *uart =to_atmel_uart_port (cdev); - uart->base =dev_request_mem_region (dev,0 ); - uart->clk =clk_get (dev,"usart" );clk_enable (uart->clk); + uart->uartclk =clk_get_rate (uart->clk);writel (USART3_BIT (RSTRX ) |USART3_BIT (RSTTX ), uart->base +USART3_CR ); -writel (USART3_BIT (RXEN ) |USART3_BIT (TXEN ), uart->base +USART3_CR ); -writel ((USART3_BF (USART_MODE ,USART3_USART_MODE_NORMAL ) - |USART3_BF (USCLKS ,USART3_USCLKS_MCK ) - |USART3_BF (CHRL ,USART3_CHRL_8 ) - |USART3_BF (PAR ,USART3_PAR_NONE ) - |USART3_BF (NBSTOP ,USART3_NBSTOP_1 )), uart->base +USART3_MR ); - -return 0 ; +clk_disable (uart->clk); }static int atmel_serial_probe (struct device_d *dev)
@@ -423,15 +443,22 @@ static int atmel_serial_probe(struct device_d *dev) uart =xzalloc (sizeof (struct atmel_uart_port )); cdev = &uart->uart; cdev->dev = dev; + cdev->startup = atmel_serial_startup; + cdev->shutdown = atmel_serial_shutdown; cdev->tstc = atmel_serial_tstc; cdev->putc = atmel_serial_putc; cdev->getc = atmel_serial_getc; cdev->setbrg = atmel_serial_setbaudrate; cdev->set_mode = atmel_serial_set_mode; -atmel_serial_init_port (cdev); + uart->base =dev_request_mem_region (dev,0 ); + + uart->clk =clk_get (dev,"usart" ); + +if (IS_ERR (uart->clk)) +return PTR_ERR (uart->clk); -/* Enable UART */ +atmel_serial_init (cdev);console_register (cdev);
Signature · 7 lines
1.8.4.rc3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox