summaryrefslogtreecommitdiffstats
path: root/c/src/libchip
diff options
context:
space:
mode:
authorTill Straumann <strauman@slac.stanford.edu>2007-11-21 06:23:12 +0000
committerTill Straumann <strauman@slac.stanford.edu>2007-11-21 06:23:12 +0000
commitd371a97e582d8e2beac846b946c6480b548cb277 (patch)
treea7b1b338be2af82381b899966e0e23c80cd9a9c8 /c/src/libchip
parent2007-11-17 Till Straumann <strauman@slac.stanford.edu> (diff)
downloadrtems-d371a97e582d8e2beac846b946c6480b548cb277.tar.bz2
2007-11-20 Till Straumann <strauman@slac.stanford.edu>
* libchip/rtc/ds1375.c, libchip/rtc/ds1375-rtc.h: Avoid using 'stdio' before the system is up and fully initialized.
Diffstat (limited to 'c/src/libchip')
-rw-r--r--c/src/libchip/rtc/ds1375-rtc.h7
-rw-r--r--c/src/libchip/rtc/ds1375.c23
2 files changed, 27 insertions, 3 deletions
diff --git a/c/src/libchip/rtc/ds1375-rtc.h b/c/src/libchip/rtc/ds1375-rtc.h
index d1d68a96ac..99100b8b07 100644
--- a/c/src/libchip/rtc/ds1375-rtc.h
+++ b/c/src/libchip/rtc/ds1375-rtc.h
@@ -71,6 +71,13 @@ rtc_ds1375_set_register( uint32_t port, uint8_t reg, uint32_t value );
* BSP must supply string constant argument 'i2cname' which matches
* the registered device name of the raw i2c device (created with mknod).
* E.g., "/dev/i2c.ds1375-raw"
+ *
+ * NOTE: The i2c bus driver must already be up and 'i2cname' already
+ * be available when this ENTRY is registered or initialized.
+ *
+ * If you want to allow applications to add the RTC driver to
+ * the configuration table then the i2c subsystem must be
+ * initialized by the BSP from the predriver_hook.
*/
#define DS1375_RTC_TBL_ENTRY(i2cname) \
{ \
diff --git a/c/src/libchip/rtc/ds1375.c b/c/src/libchip/rtc/ds1375.c
index 3afd966946..5859190d50 100644
--- a/c/src/libchip/rtc/ds1375.c
+++ b/c/src/libchip/rtc/ds1375.c
@@ -54,6 +54,7 @@
#include <libchip/ds1375-rtc.h>
#include <sys/fcntl.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <inttypes.h>
@@ -61,6 +62,22 @@
#define STATIC static
#undef DEBUG
+/* The RTC driver routines are possibly called during
+ * system initialization -- that would be prior to opening
+ * the console. At this point it is not safe to use stdio
+ * (printf, perror etc.).
+ * Our file descriptors may even be 0..2
+ */
+#define STDIOSAFE(fmt,args...) \
+ do { \
+ if ( _System_state_Is_up( _System_state_Get() ) ) { \
+ fprintf(stderr,fmt,args); \
+ } else { \
+ printk(fmt,args); \
+ } \
+ } while (0)
+
+
STATIC uint8_t ds1375_bcd2bin(uint8_t x)
{
uint8_t h = x & 0xf0;
@@ -399,19 +416,19 @@ rtc_ds1375_device_probe( int minor )
int fd;
if ( ( fd = getfd( minor ) ) < 0 ) {
- perror("ds1375_probe (open)");
+ STDIOSAFE( "ds1375_probe (open): %s\n", strerror( errno ) );
return FALSE;
}
/* Try to set file pointer */
if ( 0 != wr_bytes( fd, DS1375_SEC_REG, 0, 0 ) ) {
- perror( "ds1375_probe (wr_bytes)" );
+ STDIOSAFE( "ds1375_probe (wr_bytes): %s\n", strerror( errno ) );
close( fd );
return FALSE;
}
if ( close( fd ) ) {
- perror( "ds1375_probe (close)" );
+ STDIOSAFE( "ds1375_probe (close): %s\n", strerror( errno ) );
return FALSE;
}