* [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
@ 2007-07-17 0:49 Vitaly Bordug
2007-07-17 16:36 ` Scott Wood
0 siblings, 1 reply; 6+ messages in thread
From: Vitaly Bordug @ 2007-07-17 0:49 UTC (permalink / raw)
To: Paul Mackerras; +Cc: linuxppc-dev
This enables DS1337 embedded RTC and uses "clock-frequency"
property to configure loops_per_jiffy. Fixed spaces vs tabs issue
in couple of places.
Signed-off-by: Vitaly Bordug <vitb@kernel.crashing.org>
---
arch/powerpc/platforms/83xx/mpc8313_rdb.c | 52 ++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/83xx/mpc8313_rdb.c b/arch/powerpc/platforms/83xx/mpc8313_rdb.c
index 3edfe17..b410e67 100644
--- a/arch/powerpc/platforms/83xx/mpc8313_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc8313_rdb.c
@@ -14,6 +14,8 @@
*/
#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/rtc.h>
#include <asm/time.h>
#include <asm/ipic.h>
@@ -42,6 +44,17 @@ static void __init mpc8313_rdb_setup_arch(void)
if (ppc_md.progress)
ppc_md.progress("mpc8313_rdb_setup_arch()", 0);
+ np = of_find_node_by_type(NULL, "cpu");
+ if (np != 0) {
+ const unsigned int *fp =
+ get_property(np, "clock-frequency", NULL);
+ if (fp != 0)
+ loops_per_jiffy = *fp / HZ;
+ else
+ loops_per_jiffy = 50000000 / HZ;
+ of_node_put(np);
+ }
+
#ifdef CONFIG_PCI
for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
mpc83xx_add_bridge(np);
@@ -67,14 +80,49 @@ void __init mpc8313_rdb_init_IRQ(void)
ipic_set_default_priority();
}
+#if defined (CONFIG_SENSORS_DS1337) && defined (CONFIG_I2C)
+
+extern int ds1337_do_command(int id, int cmd, void *arg);
+extern spinlock_t rtc_lock;
+#define DS1337_GET_DATE 0
+#define DS1337_SET_DATE 1
+
+static void mpc8313rdb_get_rtc_time(struct rtc_time *tm)
+{
+ int result;
+
+ result = ds1337_do_command(0, DS1337_GET_DATE, tm);
+
+ if (result == 0)
+ result = mktime(tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+}
+
+static int mpc8313rdb_set_rtc_time(struct rtc_time *tm)
+{
+ int result;
+
+ result = ds1337_do_command(0, DS1337_SET_DATE, tm);
+
+ return result;
+}
+
+static int __init rtc_hookup(void)
+{
+ ppc_md.get_rtc_time = mpc8313rdb_get_rtc_time;
+ ppc_md.set_rtc_time = mpc8313rdb_set_rtc_time;
+ return 0;
+}
+late_initcall(rtc_hookup);
+#endif
+
/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init mpc8313_rdb_probe(void)
{
- unsigned long root = of_get_flat_dt_root();
+ unsigned long root = of_get_flat_dt_root();
- return of_flat_dt_is_compatible(root, "MPC8313ERDB");
+ return of_flat_dt_is_compatible(root, "MPC8313ERDB");
}
define_machine(mpc8313_rdb) {
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
2007-07-17 0:49 [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency" Vitaly Bordug
@ 2007-07-17 16:36 ` Scott Wood
2007-07-17 17:48 ` Vitaly Bordug
0 siblings, 1 reply; 6+ messages in thread
From: Scott Wood @ 2007-07-17 16:36 UTC (permalink / raw)
To: Vitaly Bordug; +Cc: linuxppc-dev, Paul Mackerras
On Tue, Jul 17, 2007 at 04:49:13AM +0400, Vitaly Bordug wrote:
> + np = of_find_node_by_type(NULL, "cpu");
> + if (np != 0) {
> + const unsigned int *fp =
> + get_property(np, "clock-frequency", NULL);
> + if (fp != 0)
> + loops_per_jiffy = *fp / HZ;
> + else
> + loops_per_jiffy = 50000000 / HZ;
> + of_node_put(np);
> + }
This is not necessary. It's only used for /proc/cpuinfo (delays are done
using tb_ticks_per_usec), and it'll be overwritten by the generic
calibrate_delay() anyway.
We should be removing this from board files that have it, not adding it
to ones that don't.
> +#if defined (CONFIG_SENSORS_DS1337) && defined (CONFIG_I2C)
> +
> +extern int ds1337_do_command(int id, int cmd, void *arg);
> +extern spinlock_t rtc_lock;
> +#define DS1337_GET_DATE 0
> +#define DS1337_SET_DATE 1
> +
> +static void mpc8313rdb_get_rtc_time(struct rtc_time *tm)
> +{
> + int result;
> +
> + result = ds1337_do_command(0, DS1337_GET_DATE, tm);
> +
> + if (result == 0)
> + result = mktime(tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
> +}
> +
> +static int mpc8313rdb_set_rtc_time(struct rtc_time *tm)
> +{
> + int result;
> +
> + result = ds1337_do_command(0, DS1337_SET_DATE, tm);
> +
> + return result;
> +}
> +
> +static int __init rtc_hookup(void)
> +{
> + ppc_md.get_rtc_time = mpc8313rdb_get_rtc_time;
> + ppc_md.set_rtc_time = mpc8313rdb_set_rtc_time;
> + return 0;
> +}
> +late_initcall(rtc_hookup);
> +#endif
Please don't do this; drivers/i2c/chips/ds1337.c is deprecated. You
should be using the RTC-class driver in drivers/rtc/rtc-ds1307.c, which
has a non-device-specific API that can be used.
The ppc_md RTC functions should really just go away, though -- setting
the clock on bootup can be done by generic code, and periodically
updating the RTC when using NTP can be done from userspace.
-Scott
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
2007-07-17 16:36 ` Scott Wood
@ 2007-07-17 17:48 ` Vitaly Bordug
2007-07-17 17:53 ` Scott Wood
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Vitaly Bordug @ 2007-07-17 17:48 UTC (permalink / raw)
To: Scott Wood; +Cc: linuxppc-dev, Paul Mackerras
On Tue, 17 Jul 2007 11:36:45 -0500
Scott Wood <scottwood@freescale.com> wrote:
> On Tue, Jul 17, 2007 at 04:49:13AM +0400, Vitaly Bordug wrote:
> > + np = of_find_node_by_type(NULL, "cpu");
> > + if (np != 0) {
> > + const unsigned int *fp =
> > + get_property(np, "clock-frequency", NULL);
> > + if (fp != 0)
> > + loops_per_jiffy = *fp / HZ;
> > + else
> > + loops_per_jiffy = 50000000 / HZ;
> > + of_node_put(np);
> > + }
>
> This is not necessary. It's only used for /proc/cpuinfo (delays are done
> using tb_ticks_per_usec), and it'll be overwritten by the generic
> calibrate_delay() anyway.
>
> We should be removing this from board files that have it, not adding it
> to ones that don't.
>
Yet many boards still have this stuff (like pretty recent 86xx) - should
we at least add some comments or clean that up?
> > +#if defined (CONFIG_SENSORS_DS1337) && defined (CONFIG_I2C)
> > +
> > +extern int ds1337_do_command(int id, int cmd, void *arg);
> > +extern spinlock_t rtc_lock;
> > +#define DS1337_GET_DATE 0
> > +#define DS1337_SET_DATE 1
> > +
> > +static void mpc8313rdb_get_rtc_time(struct rtc_time *tm)
> > +{
> > + int result;
> > +
> > + result = ds1337_do_command(0, DS1337_GET_DATE, tm);
> > +
> > + if (result == 0)
> > + result = mktime(tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
> > +}
> > +
> > +static int mpc8313rdb_set_rtc_time(struct rtc_time *tm)
> > +{
> > + int result;
> > +
> > + result = ds1337_do_command(0, DS1337_SET_DATE, tm);
> > +
> > + return result;
> > +}
> > +
> > +static int __init rtc_hookup(void)
> > +{
> > + ppc_md.get_rtc_time = mpc8313rdb_get_rtc_time;
> > + ppc_md.set_rtc_time = mpc8313rdb_set_rtc_time;
> > + return 0;
> > +}
> > +late_initcall(rtc_hookup);
> > +#endif
>
> Please don't do this; drivers/i2c/chips/ds1337.c is deprecated. You
> should be using the RTC-class driver in drivers/rtc/rtc-ds1307.c, which
> has a non-device-specific API that can be used.
>
> The ppc_md RTC functions should really just go away, though -- setting
> the clock on bootup can be done by generic code, and periodically
> updating the RTC when using NTP can be done from userspace.
>
If those ppc_md hookups would be declared deprecated, there's no much sense in the upper,
apparently. But I am not sure they will be... I'm inclined to let this patch floating since
interacting with rtc class from within BSP code just does not worth it.
--
Sincerely,
Vitaly
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
2007-07-17 17:48 ` Vitaly Bordug
@ 2007-07-17 17:53 ` Scott Wood
2007-07-17 18:12 ` Jon Loeliger
2007-07-17 19:58 ` Guennadi Liakhovetski
2 siblings, 0 replies; 6+ messages in thread
From: Scott Wood @ 2007-07-17 17:53 UTC (permalink / raw)
To: Vitaly Bordug; +Cc: linuxppc-dev, Paul Mackerras
Vitaly Bordug wrote:
> On Tue, 17 Jul 2007 11:36:45 -0500
> Scott Wood <scottwood@freescale.com> wrote:
>>We should be removing this from board files that have it, not adding it
>>to ones that don't.
>
> Yet many boards still have this stuff (like pretty recent 86xx) - should
> we at least add some comments or clean that up?
See above. :-)
AFAICT, it's just copied from board to board without thought. It should
be removed.
>>The ppc_md RTC functions should really just go away, though -- setting
>>the clock on bootup can be done by generic code, and periodically
>>updating the RTC when using NTP can be done from userspace.
>
> If those ppc_md hookups would be declared deprecated, there's no much sense in the upper,
> apparently. But I am not sure they will be... I'm inclined to let this patch floating since
> interacting with rtc class from within BSP code just does not worth it.
I'm not sure they will either; I just wish they would be. :-)
In the meantime, some sort of workqueue-based hookup to the RTC class
API should be used. I believe there have been patches along those lines
posted in the past.
-Scott
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
2007-07-17 17:48 ` Vitaly Bordug
2007-07-17 17:53 ` Scott Wood
@ 2007-07-17 18:12 ` Jon Loeliger
2007-07-17 19:58 ` Guennadi Liakhovetski
2 siblings, 0 replies; 6+ messages in thread
From: Jon Loeliger @ 2007-07-17 18:12 UTC (permalink / raw)
To: Vitaly Bordug; +Cc: linuxppc-dev, Paul Mackerras
On Tue, 2007-07-17 at 12:48, Vitaly Bordug wrote:
> 't.
> >
> Yet many boards still have this stuff (like pretty recent 86xx) - should
> we at least add some comments or clean that up?
Hrm. Alright. I'm on deck for a patch here, I see... :-)
But you might notice that the most recent board port
that I added, mpc8544_ds.c, does NOT have it:
static void __init mpc8544_ds_setup_arch(void)
{
if (ppc_md.progress)
ppc_md.progress("mpc8544_ds_setup_arch()", 0);
printk("MPC8544 DS board from Freescale Semiconductor\n");
}
Thanks,
jdl
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency"
2007-07-17 17:48 ` Vitaly Bordug
2007-07-17 17:53 ` Scott Wood
2007-07-17 18:12 ` Jon Loeliger
@ 2007-07-17 19:58 ` Guennadi Liakhovetski
2 siblings, 0 replies; 6+ messages in thread
From: Guennadi Liakhovetski @ 2007-07-17 19:58 UTC (permalink / raw)
To: Vitaly Bordug; +Cc: linuxppc-dev, Paul Mackerras
On Tue, 17 Jul 2007, Vitaly Bordug wrote:
> > Please don't do this; drivers/i2c/chips/ds1337.c is deprecated. You
> > should be using the RTC-class driver in drivers/rtc/rtc-ds1307.c, which
> > has a non-device-specific API that can be used.
> >
> > The ppc_md RTC functions should really just go away, though -- setting
> > the clock on bootup can be done by generic code, and periodically
> > updating the RTC when using NTP can be done from userspace.
>
> If those ppc_md hookups would be declared deprecated, there's no much sense in the upper,
> apparently. But I am not sure they will be... I'm inclined to let this patch floating since
> interacting with rtc class from within BSP code just does not worth it.
Exactly! Don't interact with it. Just leave it alone. No need to re-write
[sg]et_rtc_time, bother with setting system time on bootup... Just let the
rtc driver and framework do it for you.
Thanks
Guennadi
---
Guennadi Liakhovetski
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-07-17 19:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-17 0:49 [PATCH] POWERPC: Added RTC support for mpc8313RDB and utilize "clock-frequency" Vitaly Bordug
2007-07-17 16:36 ` Scott Wood
2007-07-17 17:48 ` Vitaly Bordug
2007-07-17 17:53 ` Scott Wood
2007-07-17 18:12 ` Jon Loeliger
2007-07-17 19:58 ` Guennadi Liakhovetski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).