rtc-rs5c372.c (e2bfe3424b368e977002fc58f81536d5d8ea9449) | rtc-rs5c372.c (2a4e2b8780c6df42b19c053243dada7fa4d311ee) |
---|---|
1/* 2 * An I2C driver for Ricoh RS5C372 and RV5C38[67] RTCs 3 * 4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net> 5 * Copyright (C) 2006 Tower Technologies 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 152 unchanged lines hidden (view full) --- 161 /* tm->tm_mon is zero-based */ 162 tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; 163 164 /* year is 1900 + tm->tm_year */ 165 tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100; 166 167 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 168 "mday=%d, mon=%d, year=%d, wday=%d\n", | 1/* 2 * An I2C driver for Ricoh RS5C372 and RV5C38[67] RTCs 3 * 4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net> 5 * Copyright (C) 2006 Tower Technologies 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 152 unchanged lines hidden (view full) --- 161 /* tm->tm_mon is zero-based */ 162 tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; 163 164 /* year is 1900 + tm->tm_year */ 165 tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100; 166 167 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 168 "mday=%d, mon=%d, year=%d, wday=%d\n", |
169 __FUNCTION__, | 169 __func__, |
170 tm->tm_sec, tm->tm_min, tm->tm_hour, 171 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 172 173 /* rtc might need initialization */ 174 return rtc_valid_tm(tm); 175} 176 177static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) 178{ 179 struct rs5c372 *rs5c = i2c_get_clientdata(client); 180 unsigned char buf[8]; 181 182 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 183 "mday=%d, mon=%d, year=%d, wday=%d\n", | 170 tm->tm_sec, tm->tm_min, tm->tm_hour, 171 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 172 173 /* rtc might need initialization */ 174 return rtc_valid_tm(tm); 175} 176 177static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) 178{ 179 struct rs5c372 *rs5c = i2c_get_clientdata(client); 180 unsigned char buf[8]; 181 182 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 183 "mday=%d, mon=%d, year=%d, wday=%d\n", |
184 __FUNCTION__, | 184 __func__, |
185 tm->tm_sec, tm->tm_min, tm->tm_hour, 186 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 187 188 buf[0] = RS5C_ADDR(RS5C372_REG_SECS); 189 buf[1] = BIN2BCD(tm->tm_sec); 190 buf[2] = BIN2BCD(tm->tm_min); 191 buf[3] = rs5c_hr2reg(rs5c, tm->tm_hour); 192 buf[4] = BIN2BCD(tm->tm_wday); 193 buf[5] = BIN2BCD(tm->tm_mday); 194 buf[6] = BIN2BCD(tm->tm_mon + 1); 195 buf[7] = BIN2BCD(tm->tm_year - 100); 196 197 if ((i2c_master_send(client, buf, 8)) != 8) { | 185 tm->tm_sec, tm->tm_min, tm->tm_hour, 186 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 187 188 buf[0] = RS5C_ADDR(RS5C372_REG_SECS); 189 buf[1] = BIN2BCD(tm->tm_sec); 190 buf[2] = BIN2BCD(tm->tm_min); 191 buf[3] = rs5c_hr2reg(rs5c, tm->tm_hour); 192 buf[4] = BIN2BCD(tm->tm_wday); 193 buf[5] = BIN2BCD(tm->tm_mday); 194 buf[6] = BIN2BCD(tm->tm_mon + 1); 195 buf[7] = BIN2BCD(tm->tm_year - 100); 196 197 if ((i2c_master_send(client, buf, 8)) != 8) { |
198 dev_err(&client->dev, "%s: write error\n", __FUNCTION__); | 198 dev_err(&client->dev, "%s: write error\n", __func__); |
199 return -EIO; 200 } 201 202 return 0; 203} 204 205#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 206#define NEED_TRIM --- 8 unchanged lines hidden (view full) --- 215{ 216 struct rs5c372 *rs5c372 = i2c_get_clientdata(client); 217 u8 tmp = rs5c372->regs[RS5C372_REG_TRIM]; 218 219 if (osc) 220 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; 221 222 if (trim) { | 199 return -EIO; 200 } 201 202 return 0; 203} 204 205#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 206#define NEED_TRIM --- 8 unchanged lines hidden (view full) --- 215{ 216 struct rs5c372 *rs5c372 = i2c_get_clientdata(client); 217 u8 tmp = rs5c372->regs[RS5C372_REG_TRIM]; 218 219 if (osc) 220 *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; 221 222 if (trim) { |
223 dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, tmp); | 223 dev_dbg(&client->dev, "%s: raw trim=%x\n", __func__, tmp); |
224 tmp &= RS5C372_TRIM_MASK; 225 if (tmp & 0x3e) { 226 int t = tmp & 0x3f; 227 228 if (tmp & 0x40) 229 t = (~t | (s8)0xc0) + 1; 230 else 231 t = t - 1; --- 263 unchanged lines hidden (view full) --- 495static struct i2c_driver rs5c372_driver; 496 497static int rs5c372_probe(struct i2c_client *client) 498{ 499 int err = 0; 500 struct rs5c372 *rs5c372; 501 struct rtc_time tm; 502 | 224 tmp &= RS5C372_TRIM_MASK; 225 if (tmp & 0x3e) { 226 int t = tmp & 0x3f; 227 228 if (tmp & 0x40) 229 t = (~t | (s8)0xc0) + 1; 230 else 231 t = t - 1; --- 263 unchanged lines hidden (view full) --- 495static struct i2c_driver rs5c372_driver; 496 497static int rs5c372_probe(struct i2c_client *client) 498{ 499 int err = 0; 500 struct rs5c372 *rs5c372; 501 struct rtc_time tm; 502 |
503 dev_dbg(&client->dev, "%s\n", __FUNCTION__); | 503 dev_dbg(&client->dev, "%s\n", __func__); |
504 505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 506 err = -ENODEV; 507 goto exit; 508 } 509 510 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 511 err = -ENOMEM; --- 163 unchanged lines hidden --- | 504 505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 506 err = -ENODEV; 507 goto exit; 508 } 509 510 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 511 err = -ENOMEM; --- 163 unchanged lines hidden --- |