* [PATCH 2/8] console: factorise function to get the console by name
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-06 11:24 ` Sascha Hauer
2013-10-03 7:21 ` [PATCH 3/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
rename it to console_get_by_name
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/loadxy.c | 26 ++------------------------
common/console_common.c | 17 +++++++++++++++++
include/console.h | 1 +
3 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/commands/loadxy.c b/commands/loadxy.c
index 7a91286..b90d2fd 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -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) {
diff --git a/common/console_common.c b/common/console_common.c
index c3a3053..b02f525 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -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);
diff --git a/include/console.h b/include/console.h
index 2bf791c..b8c3fc9 100644
--- a/include/console.h
+++ b/include/console.h
@@ -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
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/8] console: factorise function to get the console by name
2013-10-03 7:21 ` [PATCH 2/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-06 11:24 ` Sascha Hauer
2013-10-06 18:38 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2013-10-06 11:24 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Thu, Oct 03, 2013 at 09:21:54AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> rename it to console_get_by_name
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> +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);
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
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/8] console: factorise function to get the console by name
2013-10-06 11:24 ` Sascha Hauer
@ 2013-10-06 18:38 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-07 6:23 ` Sascha Hauer
0 siblings, 1 reply; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-06 18:38 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 13:24 Sun 06 Oct , Sascha Hauer wrote:
> On Thu, Oct 03, 2013 at 09:21:54AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > rename it to console_get_by_name
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > +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);
>
> 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.
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.
>
> Sascha
>
> --
> 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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/8] console: factorise function to get the console by name
2013-10-06 18:38 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-07 6:23 ` Sascha Hauer
0 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2013-10-07 6:23 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sun, Oct 06, 2013 at 08:38:56PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 13:24 Sun 06 Oct , Sascha Hauer wrote:
> > On Thu, Oct 03, 2013 at 09:21:54AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > rename it to console_get_by_name
> > >
> > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > > ---
> > > +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);
> >
> > 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.
>
> 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
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/8] console: introduce startup and shutdown
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 2/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 4/8] loadxy: use console_open/close Jean-Christophe PLAGNIOL-VILLARD
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
so enable the uart only if used
so linux can detect the right one enable if it want
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
common/console.c | 6 ++++++
common/console_common.c | 35 +++++++++++++++++++++++++++++++++++
common/console_simple.c | 3 +++
include/console.h | 4 ++++
4 files changed, 48 insertions(+)
diff --git a/common/console.c b/common/console.c
index 56bc864..b0a9542 100644
--- a/common/console.c
+++ b/common/console.c
@@ -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;
diff --git a/common/console_common.c b/common/console_common.c
index b02f525..05603c4 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -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);
diff --git a/common/console_simple.c b/common/console_simple.c
index 6cb72bb..0f83fa4 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -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);
diff --git a/include/console.h b/include/console.h
index b8c3fc9..8f0aac0 100644
--- a/include/console.h
+++ b/include/console.h
@@ -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
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/8] loadxy: use console_open/close
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 2/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 3/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 5/8] console: console_get_by_name pass flags Jean-Christophe PLAGNIOL-VILLARD
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
so we can use non startup console
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/loadxy.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/commands/loadxy.c b/commands/loadxy.c
index b90d2fd..7cefba4 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -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;
}
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 5/8] console: console_get_by_name pass flags
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
` (2 preceding siblings ...)
2013-10-03 7:21 ` [PATCH 4/8] loadxy: use console_open/close Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection Jean-Christophe PLAGNIOL-VILLARD
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
this 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
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/loadxy.c | 4 ++--
common/console_common.c | 10 ++++++----
include/console.h | 2 +-
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/commands/loadxy.c b/commands/loadxy.c
index 7cefba4..41181f2 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -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) {
diff --git a/common/console_common.c b/common/console_common.c
index 05603c4..6e5fb68 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -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;
}
diff --git a/include/console.h b/include/console.h
index 8f0aac0..f1bc049 100644
--- a/include/console.h
+++ b/include/console.h
@@ -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);
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
` (3 preceding siblings ...)
2013-10-03 7:21 ` [PATCH 5/8] console: console_get_by_name pass flags Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:21 ` [PATCH 7/8] serial: amba-pl011: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:22 ` [PATCH 8/8] serial: atmel: " Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
arch/arm/boards/animeo_ip/init.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boards/animeo_ip/init.c b/arch/arm/boards/animeo_ip/init.c
index 2fee1ff..e6d2745 100644
--- a/arch/arm/boards/animeo_ip/init.c
+++ b/arch/arm/boards/animeo_ip/init.c
@@ -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);
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 7/8] serial: amba-pl011: add start and shutdown support
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
` (4 preceding siblings ...)
2013-10-03 7:21 ` [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:21 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-03 7:22 ` [PATCH 8/8] serial: atmel: " Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:21 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/serial/amba-pl011.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index fc7723e..b7e01dd 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -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);
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 8/8] serial: atmel: add start and shutdown support
2013-10-03 7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
` (5 preceding siblings ...)
2013-10-03 7:21 ` [PATCH 7/8] serial: amba-pl011: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-03 7:22 ` Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-03 7:22 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/serial/atmel.c | 55 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 14 deletions(-)
diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index c2a5d33..a1eb4cb 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -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_mode
return 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);
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 13+ messages in thread