]> git.sur5r.net Git - u-boot/blobdiff - drivers/rtc/pcf8563.c
dm: core: Add a way to bind a device by ofnode
[u-boot] / drivers / rtc / pcf8563.c
index c384975f3559970897c9fd7451b28eeceb2d9ce5..e2fa6b6aab6c9c2d766ecab4c41822c75a1aeb29 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2001
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * 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
  */
 
 /*
 #include <rtc.h>
 #include <i2c.h>
 
-#if defined(CONFIG_RTC_PCF8563) && defined(CONFIG_CMD_DATE)
+#if defined(CONFIG_CMD_DATE)
 
 static uchar rtc_read  (uchar reg);
 static void  rtc_write (uchar reg, uchar val);
-static uchar bin2bcd   (unsigned int n);
-static unsigned bcd2bin(uchar c);
 
 /* ------------------------------------------------------------------------- */
 
@@ -74,7 +55,7 @@ int rtc_get (struct rtc_time *tmp)
        tmp->tm_hour = bcd2bin (hour & 0x3F);
        tmp->tm_mday = bcd2bin (mday & 0x3F);
        tmp->tm_mon  = bcd2bin (mon_cent & 0x1F);
-       tmp->tm_year = bcd2bin (year) + ((mon_cent & 0x80) ? 2000 : 1900);
+       tmp->tm_year = bcd2bin (year) + ((mon_cent & 0x80) ? 1900 : 2000);
        tmp->tm_wday = bcd2bin (wday & 0x07);
        tmp->tm_yday = 0;
        tmp->tm_isdst= 0;
@@ -86,7 +67,7 @@ int rtc_get (struct rtc_time *tmp)
        return rel;
 }
 
-void rtc_set (struct rtc_time *tmp)
+int rtc_set (struct rtc_time *tmp)
 {
        uchar century;
 
@@ -96,7 +77,7 @@ void rtc_set (struct rtc_time *tmp)
 
        rtc_write (0x08, bin2bcd(tmp->tm_year % 100));
 
-       century = (tmp->tm_year >= 2000) ? 0x80 : 0;
+       century = (tmp->tm_year >= 2000) ? 0 : 0x80;
        rtc_write (0x07, bin2bcd(tmp->tm_mon) | century);
 
        rtc_write (0x06, bin2bcd(tmp->tm_wday));
@@ -104,6 +85,8 @@ void rtc_set (struct rtc_time *tmp)
        rtc_write (0x04, bin2bcd(tmp->tm_hour));
        rtc_write (0x03, bin2bcd(tmp->tm_min ));
        rtc_write (0x02, bin2bcd(tmp->tm_sec ));
+
+       return 0;
 }
 
 void rtc_reset (void)
@@ -127,22 +110,12 @@ void rtc_reset (void)
 
 static uchar rtc_read (uchar reg)
 {
-       return (i2c_reg_read (CFG_I2C_RTC_ADDR, reg));
+       return (i2c_reg_read (CONFIG_SYS_I2C_RTC_ADDR, reg));
 }
 
 static void rtc_write (uchar reg, uchar val)
 {
-       i2c_reg_write (CFG_I2C_RTC_ADDR, reg, val);
-}
-
-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));
+       i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
 }
 
 #endif