* [PATCH 2/8] console: factorise function to get the first enabled console
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 8:44 ` Sascha Hauer
2013-09-27 7:14 ` [PATCH 3/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
` (5 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 UTC (permalink / raw)
To: barebox
rename it to console_get_first_current
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
arch/ppc/mach-mpc85xx/fdt.c | 4 +---
commands/loadb.c | 22 +---------------------
commands/loadxy.c | 24 ++----------------------
common/console_common.c | 21 +++++++++++++++++++++
include/console.h | 2 ++
5 files changed, 27 insertions(+), 46 deletions(-)
diff --git a/arch/ppc/mach-mpc85xx/fdt.c b/arch/ppc/mach-mpc85xx/fdt.c
index 4feae44..ae2dc28 100644
--- a/arch/ppc/mach-mpc85xx/fdt.c
+++ b/arch/ppc/mach-mpc85xx/fdt.c
@@ -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_current();
if (cdev)
sprintf(sername, "serial%d", cdev->dev->id);
else
diff --git a/commands/loadb.c b/commands/loadb.c
index a2f3315..f66f86d 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -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_current();
if (NULL == cdev) {
printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
return -ENODEV;
diff --git a/commands/loadxy.c b/commands/loadxy.c
index 52ecdca..1def6ae 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -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_current();
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_current();
if (!cdev) {
printf("%s:No console device %s with STDIN and STDOUT\n",
argv[0], cname ? cname : "default");
diff --git a/common/console_common.c b/common/console_common.c
index 6abc6c0..b9a93db 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -154,3 +154,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_current(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_current);
diff --git a/include/console.h b/include/console.h
index 9e78f84..400ef7e 100644
--- a/include/console.h
+++ b/include/console.h
@@ -64,4 +64,6 @@ extern struct list_head console_list;
bool console_is_input_allow(void);
void console_allow_input(bool val);
+struct console_device *console_get_first_current(void);
+
#endif
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 2/8] console: factorise function to get the first enabled console
2013-09-27 7:14 ` [PATCH 2/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 8:44 ` Sascha Hauer
0 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-09-27 8:44 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Fri, Sep 27, 2013 at 09:14:12AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> +/**
> + * @brief returns current used console device
> + *
> + * @return console device which is registered with CONSOLE_STDIN and
> + * CONSOLE_STDOUT
> + */
> +struct console_device *console_get_first_current(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_current);
I find the function name misleading. Can we stick to the original name
or console_get_first_active?
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] 19+ messages in thread
* [PATCH 3/8] console: factorise function to get the console by name
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 2/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 8:50 ` Sascha Hauer
2013-09-27 7:14 ` [PATCH 4/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
` (4 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 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 1def6ae..fe1b5f5 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_current();
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_current();
if (!cdev) {
diff --git a/common/console_common.c b/common/console_common.c
index b9a93db..b18409c 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -175,3 +175,20 @@ struct console_device *console_get_first_current(void)
return NULL;
}
EXPORT_SYMBOL(console_get_first_current);
+
+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 400ef7e..7d1f5e5 100644
--- a/include/console.h
+++ b/include/console.h
@@ -65,5 +65,6 @@ bool console_is_input_allow(void);
void console_allow_input(bool val);
struct console_device *console_get_first_current(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] 19+ messages in thread
* Re: [PATCH 3/8] console: factorise function to get the console by name
2013-09-27 7:14 ` [PATCH 3/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 8:50 ` Sascha Hauer
2013-09-27 8:58 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-09-27 8:50 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Fri, Sep 27, 2013 at 09:14:13AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> rename it to console_get_by_name
>
> +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 know this patch doesn't change the current behaviour, but a common
function console_get_by_name() should return return the console by name
regardless of whether it's active or not.
For the loadx code this would be a net win aswell. I think this code
should not depend on an active console but the other way round: It
should clear the CONSOLE_STDIN/CONSOLE_STDOUT during loadx operation.
This way we could easily make sure there are no printf message garbling
the line during transfers and still we could have console messages on
other consoles.
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] 19+ messages in thread
* Re: [PATCH 3/8] console: factorise function to get the console by name
2013-09-27 8:50 ` Sascha Hauer
@ 2013-09-27 8:58 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 9:05 ` Sascha Hauer
0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 8:58 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 10:50 Fri 27 Sep , Sascha Hauer wrote:
> On Fri, Sep 27, 2013 at 09:14:13AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > rename it to console_get_by_name
> >
> > +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 know this patch doesn't change the current behaviour, but a common
> function console_get_by_name() should return return the console by name
> regardless of whether it's active or not.
I change it behaviour later as now this function will check the console
feature
as the current implemetation do it too but in the wrong way
>
> For the loadx code this would be a net win aswell. I think this code
> should not depend on an active console but the other way round: It
> should clear the CONSOLE_STDIN/CONSOLE_STDOUT during loadx operation.
> This way we could easily make sure there are no printf message garbling
> the line during transfers and still we could have console messages on
> other consoles.
patch 8 finaly clean it
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] 19+ messages in thread
* Re: [PATCH 3/8] console: factorise function to get the console by name
2013-09-27 8:58 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 9:05 ` Sascha Hauer
2013-09-27 9:07 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-09-27 9:05 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Fri, Sep 27, 2013 at 10:58:47AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:50 Fri 27 Sep , Sascha Hauer wrote:
> > On Fri, Sep 27, 2013 at 09:14:13AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > rename it to console_get_by_name
> > >
> > > +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 know this patch doesn't change the current behaviour, but a common
> > function console_get_by_name() should return return the console by name
> > regardless of whether it's active or not.
>
> I change it behaviour later as now this function will check the console
> feature
>
> as the current implemetation do it too but in the wrong way
> >
> > For the loadx code this would be a net win aswell. I think this code
> > should not depend on an active console but the other way round: It
> > should clear the CONSOLE_STDIN/CONSOLE_STDOUT during loadx operation.
> > This way we could easily make sure there are no printf message garbling
> > the line during transfers and still we could have console messages on
> > other consoles.
>
> patch 8 finaly clean it
?
patch 8/8 is an atmel serial driver specific patch that changes nothing
in this regard.
What I mean is that the loadx stuff should do a cdev->active = 0 so that
during transfers printf is still possible without corrupting the
transfers. This behaviour is not changed in this series.
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] 19+ messages in thread
* Re: [PATCH 3/8] console: factorise function to get the console by name
2013-09-27 9:05 ` Sascha Hauer
@ 2013-09-27 9:07 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 9:07 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Sep 27, 2013, at 5:05 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Fri, Sep 27, 2013 at 10:58:47AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
>> On 10:50 Fri 27 Sep , Sascha Hauer wrote:
>>> On Fri, Sep 27, 2013 at 09:14:13AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
>>>> rename it to console_get_by_name
>>>>
>>>> +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 know this patch doesn't change the current behaviour, but a common
>>> function console_get_by_name() should return return the console by name
>>> regardless of whether it's active or not.
>>
>> I change it behaviour later as now this function will check the console
>> feature
>>
>> as the current implemetation do it too but in the wrong way
>>>
>>> For the loadx code this would be a net win aswell. I think this code
>>> should not depend on an active console but the other way round: It
>>> should clear the CONSOLE_STDIN/CONSOLE_STDOUT during loadx operation.
>>> This way we could easily make sure there are no printf message garbling
>>> the line during transfers and still we could have console messages on
>>> other consoles.
>>
>> patch 8 finaly clean it
>
> ?
>
> patch 8/8 is an atmel serial driver specific patch that changes nothing
> in this regard.
>
it's patch 9 I forget to send this one
but put it on the git
> What I mean is that the loadx stuff should do a cdev->active = 0 so that
> during transfers printf is still possible without corrupting the
> transfers. This behaviour is not changed in this series.
yeah I agree
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] 19+ messages in thread
* [PATCH 4/8] console: introduce startup and shutdown
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 2/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 3/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 8:55 ` Sascha Hauer
2013-09-27 7:14 ` [PATCH 5/8] loadbxy: use console_open/close Jean-Christophe PLAGNIOL-VILLARD
` (3 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 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 | 36 ++++++++++++++++++++++++++++++++++++
common/console_simple.c | 3 +++
include/console.h | 4 ++++
4 files changed, 49 insertions(+)
diff --git a/common/console.c b/common/console.c
index 56bc864..00fd2cf 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 desactivated, shutdown it */
+ if (cdev->shutdown)
+ cdev->shutdown(cdev);
}
active[i] = 0;
diff --git a/common/console_common.c b/common/console_common.c
index b18409c..357e002 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -192,3 +192,39 @@ 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) {
+ cdev->baudrate = CONFIG_BAUDRATE;
+ 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 7d1f5e5..20d9986 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);
@@ -66,5 +68,7 @@ void console_allow_input(bool val);
struct console_device *console_get_first_current(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] 19+ messages in thread
* Re: [PATCH 4/8] console: introduce startup and shutdown
2013-09-27 7:14 ` [PATCH 4/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 8:55 ` Sascha Hauer
2013-09-27 9:03 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-09-27 8:55 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Fri, Sep 27, 2013 at 09:14:14AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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 | 36 ++++++++++++++++++++++++++++++++++++
> common/console_simple.c | 3 +++
> include/console.h | 4 ++++
> 4 files changed, 49 insertions(+)
>
> diff --git a/common/console.c b/common/console.c
> index 56bc864..00fd2cf 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 desactivated, shutdown it */
/* The device is being deactivated, shut it down */
> +
> +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) {
> + cdev->baudrate = CONFIG_BAUDRATE;
I believe cdev->baudrate should be set only once during initialization.
When I deactivate a console and activate it again I don't expect the
baudrate to be changed to it's default value.
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] 19+ messages in thread
* Re: [PATCH 4/8] console: introduce startup and shutdown
2013-09-27 8:55 ` Sascha Hauer
@ 2013-09-27 9:03 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 9:09 ` Sascha Hauer
0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 9:03 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 10:55 Fri 27 Sep , Sascha Hauer wrote:
> On Fri, Sep 27, 2013 at 09:14:14AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > 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 | 36 ++++++++++++++++++++++++++++++++++++
> > common/console_simple.c | 3 +++
> > include/console.h | 4 ++++
> > 4 files changed, 49 insertions(+)
> >
> > diff --git a/common/console.c b/common/console.c
> > index 56bc864..00fd2cf 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 desactivated, shutdown it */
>
> /* The device is being deactivated, shut it down */
>
> > +
> > +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) {
> > + cdev->baudrate = CONFIG_BAUDRATE;
>
> I believe cdev->baudrate should be set only once during initialization.
> When I deactivate a console and activate it again I don't expect the
> baudrate to be changed to it's default value.
maybe but if the device is not a console but rs485 you never set the baudrate
today same if a device is never active
as example use a non active device for loadxy
so I'm think that the console_open is more like man 2 open + ioctl to use a
cdev
later we will switch to open + ioctl API
for now on I prefer to just fix the big issues and prepare to switch easly
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] 19+ messages in thread
* Re: [PATCH 4/8] console: introduce startup and shutdown
2013-09-27 9:03 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 9:09 ` Sascha Hauer
2013-09-27 9:20 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-09-27 9:09 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Fri, Sep 27, 2013 at 11:03:57AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:55 Fri 27 Sep , Sascha Hauer wrote:
> > On Fri, Sep 27, 2013 at 09:14:14AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > so enable the uart only if used
> > > so linux can detect the right one enable if it want
> > > +{
> > > + int ret;
> > > +
> > > + if (cdev->f_active)
> > > + return 0;
> > > +
> > > + if (cdev->startup) {
> > > + ret = cdev->startup(cdev);
> > > + if (ret)
> > > + return ret;
> > > + }
> > > +
> > > + if (cdev->setbrg) {
> > > + cdev->baudrate = CONFIG_BAUDRATE;
> >
> > I believe cdev->baudrate should be set only once during initialization.
> > When I deactivate a console and activate it again I don't expect the
> > baudrate to be changed to it's default value.
>
> maybe but if the device is not a console but rs485 you never set the baudrate
> today same if a device is never active
>
> as example use a non active device for loadxy
>
> so I'm think that the console_open is more like man 2 open + ioctl to use a
> cdev
Put a cdev->baudrate = CONFIG_BAUDRATE in console_register() instead of
console_open. This doesn't affect RS485 at all but fixes the behaviour i
moaned about.
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] 19+ messages in thread
* Re: [PATCH 4/8] console: introduce startup and shutdown
2013-09-27 9:09 ` Sascha Hauer
@ 2013-09-27 9:20 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 9:20 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 11:09 Fri 27 Sep , Sascha Hauer wrote:
> On Fri, Sep 27, 2013 at 11:03:57AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 10:55 Fri 27 Sep , Sascha Hauer wrote:
> > > On Fri, Sep 27, 2013 at 09:14:14AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > so enable the uart only if used
> > > > so linux can detect the right one enable if it want
> > > > +{
> > > > + int ret;
> > > > +
> > > > + if (cdev->f_active)
> > > > + return 0;
> > > > +
> > > > + if (cdev->startup) {
> > > > + ret = cdev->startup(cdev);
> > > > + if (ret)
> > > > + return ret;
> > > > + }
> > > > +
> > > > + if (cdev->setbrg) {
> > > > + cdev->baudrate = CONFIG_BAUDRATE;
> > >
> > > I believe cdev->baudrate should be set only once during initialization.
> > > When I deactivate a console and activate it again I don't expect the
> > > baudrate to be changed to it's default value.
> >
> > maybe but if the device is not a console but rs485 you never set the baudrate
> > today same if a device is never active
> >
> > as example use a non active device for loadxy
> >
> > so I'm think that the console_open is more like man 2 open + ioctl to use a
> > cdev
>
> Put a cdev->baudrate = CONFIG_BAUDRATE in console_register() instead of
> console_open. This doesn't affect RS485 at all but fixes the behaviour i
> moaned about.
ok why not
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] 19+ messages in thread
* [PATCH 5/8] loadbxy: use console_open/close
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
` (2 preceding siblings ...)
2013-09-27 7:14 ` [PATCH 4/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [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; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 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 fe1b5f5..33f923d 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] 19+ messages in thread
* [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
` (3 preceding siblings ...)
2013-09-27 7:14 ` [PATCH 5/8] loadbxy: use console_open/close Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 7/8] serial: amba-pl011: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 8/8] serial: atmel: " Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 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] 19+ messages in thread
* [PATCH 7/8] serial: amba-pl011: add start and shutdown support
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
` (4 preceding siblings ...)
2013-09-27 7:14 ` [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-27 7:14 ` [PATCH 8/8] serial: atmel: " Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/serial/amba-pl011.c | 45 +++++++++++++++++++++++++++++++++------------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index fc7723e..5a8e633 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -147,14 +147,41 @@ 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);
+
+ 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);
+
+ /*
+ ** Finally, enable the UART
+ */
+ writel((UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE | UART011_CR_RTS),
+ uart->base + UART011_CR);
+
+ return 0;
+}
+
+static void pl011_port_init(struct console_device *cdev)
{
struct amba_uart_port *uart = to_amba_uart_port(cdev);
/*
** First, disable everything.
*/
- writel(0x0, uart->base + UART011_CR);
+ pl011_shutdown(cdev);
/*
* Try to enable the clock producer.
@@ -168,13 +195,7 @@ int pl011_init_port (struct console_device *cdev)
*/
pl011_rlcr(uart, UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN);
- /*
- ** Finally, enable the UART
- */
- writel((UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE | UART011_CR_RTS),
- uart->base + UART011_CR);
-
- return 0;
+ clk_disable(uart->clk);
}
static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
@@ -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] 19+ messages in thread
* [PATCH 8/8] serial: atmel: add start and shutdown support
2013-09-27 7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
` (5 preceding siblings ...)
2013-09-27 7:14 ` [PATCH 7/8] serial: amba-pl011: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-27 7:14 ` Jean-Christophe PLAGNIOL-VILLARD
6 siblings, 0 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-27 7:14 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/serial/atmel.c | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index c2a5d33..10eb2e7 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -388,31 +388,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);
+
+ 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);
+ | 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 +442,20 @@ 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->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] 19+ messages in thread