]> git.sur5r.net Git - u-boot/blobdiff - drivers/rtc/rx8025.c
dm: core: Add a way to bind a device by ofnode
[u-boot] / drivers / rtc / rx8025.c
index 64eafe5c3744658a3fa74a4bf66c25fc9f971b90..1c2b92fe00065c65dd61f8cbe7cd6db9c698093d 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2007
  * Matthias Fuchs, esd gmbh, matthias.fuchs@esd-electronics.com.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
  */
 
 /*
@@ -30,7 +13,7 @@
 #include <rtc.h>
 #include <i2c.h>
 
-#if defined(CONFIG_RTC_RX8025) && defined(CONFIG_CMD_DATE)
+#if defined(CONFIG_CMD_DATE)
 
 /*---------------------------------------------------------------------*/
 #undef DEBUG_RTC
@@ -42,8 +25,8 @@
 #endif
 /*---------------------------------------------------------------------*/
 
-#ifndef CFG_I2C_RTC_ADDR
-# define CFG_I2C_RTC_ADDR      0x32
+#ifndef CONFIG_SYS_I2C_RTC_ADDR
+# define CONFIG_SYS_I2C_RTC_ADDR       0x32
 #endif
 
 /*
@@ -90,8 +73,6 @@
 #define rtc_read(reg) buf[((reg) + 1) & 0xf]
 
 static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
 
 /*
  * Get the current time from the RTC
@@ -102,7 +83,7 @@ int rtc_get (struct rtc_time *tmp)
        uchar sec, min, hour, mday, wday, mon, year, ctl2;
        uchar buf[16];
 
-       if (i2c_read(CFG_I2C_RTC_ADDR, 0, 0, buf, 16))
+       if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 0, buf, 16))
                printf("Error reading from RTC\n");
 
        sec = rtc_read(RTC_SEC_REG_ADDR);
@@ -136,7 +117,11 @@ int rtc_get (struct rtc_time *tmp)
 
        tmp->tm_sec  = bcd2bin (sec & 0x7F);
        tmp->tm_min  = bcd2bin (min & 0x7F);
-       tmp->tm_hour = bcd2bin (hour & 0x3F);
+       if (rtc_read(RTC_CTL1_REG_ADDR) & RTC_CTL1_BIT_2412)
+               tmp->tm_hour = bcd2bin (hour & 0x3F);
+       else
+               tmp->tm_hour = bcd2bin (hour & 0x1F) % 12 +
+                              ((hour & 0x20) ? 12 : 0);
        tmp->tm_mday = bcd2bin (mday & 0x3F);
        tmp->tm_mon  = bcd2bin (mon & 0x1F);
        tmp->tm_year = bcd2bin (year) + ( bcd2bin (year) >= 70 ? 1900 : 2000);
@@ -154,7 +139,7 @@ int rtc_get (struct rtc_time *tmp)
 /*
  * Set the RTC
  */
-void rtc_set (struct rtc_time *tmp)
+int rtc_set (struct rtc_time *tmp)
 {
        DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
                tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
@@ -172,39 +157,25 @@ void rtc_set (struct rtc_time *tmp)
        rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
 
        rtc_write (RTC_CTL1_REG_ADDR, RTC_CTL1_BIT_2412);
+
+       return 0;
 }
 
 /*
- * Reset the RTC. We setting the date back to 1970-01-01.
+ * Reset the RTC
  */
 void rtc_reset (void)
 {
-       struct rtc_time tmp;
        uchar buf[16];
        uchar ctl2;
 
-       if (i2c_read(CFG_I2C_RTC_ADDR, 0,    0,   buf, 16))
+       if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0,    0,   buf, 16))
                printf("Error reading from RTC\n");
 
        ctl2 = rtc_read(RTC_CTL2_REG_ADDR);
        ctl2 &= ~(RTC_CTL2_BIT_PON | RTC_CTL2_BIT_VDET);
        ctl2 |= RTC_CTL2_BIT_XST | RTC_CTL2_BIT_VDSL;
        rtc_write (RTC_CTL2_REG_ADDR, ctl2);
-
-       tmp.tm_year = 1970;
-       tmp.tm_mon = 1;
-       tmp.tm_mday= 1;
-       tmp.tm_hour = 0;
-       tmp.tm_min = 0;
-       tmp.tm_sec = 0;
-
-       rtc_set(&tmp);
-
-       printf ( "RTC:   %4d-%02d-%02d %2d:%02d:%02d UTC\n",
-               tmp.tm_year, tmp.tm_mon, tmp.tm_mday,
-               tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
-
-       return;
 }
 
 /*
@@ -215,19 +186,9 @@ static void rtc_write (uchar reg, uchar val)
        uchar buf[2];
        buf[0] = reg << 4;
        buf[1] = val;
-       if (i2c_write(CFG_I2C_RTC_ADDR, 0, 0, buf, 2) != 0)
+       if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 0, buf, 2) != 0)
                printf("Error writing to RTC\n");
 
 }
 
-static unsigned bcd2bin (uchar n)
-{
-       return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
-       return (((n / 10) << 4) | (n % 10));
-}
-
 #endif /* CONFIG_RTC_RX8025 && CONFIG_CMD_DATE */