rtc-max6900 new style driver
New style conversion and reformatting as per indent --linux-style Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Cc: Dale Farnsworth <dale@farnsworth.org> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
fb0d4ec4d3
Коммит
6fd5c03f82
|
@ -17,8 +17,7 @@
|
||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
|
|
||||||
#define DRV_NAME "max6900"
|
#define DRV_VERSION "0.2"
|
||||||
#define DRV_VERSION "0.1"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* register indices
|
* register indices
|
||||||
|
@ -39,7 +38,6 @@
|
||||||
|
|
||||||
#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
|
#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* register read/write commands
|
* register read/write commands
|
||||||
*/
|
*/
|
||||||
|
@ -52,16 +50,7 @@
|
||||||
|
|
||||||
#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
|
#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
|
||||||
|
|
||||||
#define MAX6900_I2C_ADDR 0xa0
|
static struct i2c_driver max6900_driver;
|
||||||
|
|
||||||
static const unsigned short normal_i2c[] = {
|
|
||||||
MAX6900_I2C_ADDR >> 1,
|
|
||||||
I2C_CLIENT_END
|
|
||||||
};
|
|
||||||
|
|
||||||
I2C_CLIENT_INSMOD; /* defines addr_data */
|
|
||||||
|
|
||||||
static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind);
|
|
||||||
|
|
||||||
static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
|
static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
|
||||||
{
|
{
|
||||||
|
@ -72,20 +61,20 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = 0, /* write */
|
.flags = 0, /* write */
|
||||||
.len = sizeof(reg_burst_read),
|
.len = sizeof(reg_burst_read),
|
||||||
.buf = reg_burst_read
|
.buf = reg_burst_read}
|
||||||
},
|
,
|
||||||
{
|
{
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = I2C_M_RD,
|
.flags = I2C_M_RD,
|
||||||
.len = MAX6900_BURST_LEN,
|
.len = MAX6900_BURST_LEN,
|
||||||
.buf = buf
|
.buf = buf}
|
||||||
},
|
,
|
||||||
{
|
{
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = 0, /* write */
|
.flags = 0, /* write */
|
||||||
.len = sizeof(reg_century_read),
|
.len = sizeof(reg_century_read),
|
||||||
.buf = reg_century_read
|
.buf = reg_century_read}
|
||||||
},
|
,
|
||||||
{
|
{
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = I2C_M_RD,
|
.flags = I2C_M_RD,
|
||||||
|
@ -97,8 +86,7 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
|
||||||
|
|
||||||
rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
|
rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
|
||||||
if (rc != ARRAY_SIZE(msgs)) {
|
if (rc != ARRAY_SIZE(msgs)) {
|
||||||
dev_err(&client->dev, "%s: register read failed\n",
|
dev_err(&client->dev, "%s: register read failed\n", __func__);
|
||||||
__func__);
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -112,8 +100,7 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = 0, /* write */
|
.flags = 0, /* write */
|
||||||
.len = sizeof(i2c_century_buf),
|
.len = sizeof(i2c_century_buf),
|
||||||
.buf = i2c_century_buf
|
.buf = i2c_century_buf}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
|
u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
|
||||||
struct i2c_msg burst_msgs[1] = {
|
struct i2c_msg burst_msgs[1] = {
|
||||||
|
@ -121,8 +108,7 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
|
||||||
.addr = client->addr,
|
.addr = client->addr,
|
||||||
.flags = 0, /* write */
|
.flags = 0, /* write */
|
||||||
.len = sizeof(i2c_burst_buf),
|
.len = sizeof(i2c_burst_buf),
|
||||||
.buf = i2c_burst_buf
|
.buf = i2c_burst_buf}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -133,10 +119,12 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
|
||||||
* bit as part of the burst write.
|
* bit as part of the burst write.
|
||||||
*/
|
*/
|
||||||
i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
|
i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
|
||||||
|
|
||||||
rc = i2c_transfer(client->adapter, century_msgs,
|
rc = i2c_transfer(client->adapter, century_msgs,
|
||||||
ARRAY_SIZE(century_msgs));
|
ARRAY_SIZE(century_msgs));
|
||||||
if (rc != ARRAY_SIZE(century_msgs))
|
if (rc != ARRAY_SIZE(century_msgs))
|
||||||
goto write_failed;
|
goto write_failed;
|
||||||
|
|
||||||
msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
|
msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
|
||||||
|
|
||||||
memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
|
memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
|
||||||
|
@ -149,44 +137,10 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
write_failed:
|
write_failed:
|
||||||
dev_err(&client->dev, "%s: register write failed\n",
|
dev_err(&client->dev, "%s: register write failed\n", __func__);
|
||||||
__func__);
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max6900_i2c_validate_client(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
u8 regs[MAX6900_REG_LEN];
|
|
||||||
u8 zero_mask[] = {
|
|
||||||
0x80, /* seconds */
|
|
||||||
0x80, /* minutes */
|
|
||||||
0x40, /* hours */
|
|
||||||
0xc0, /* day of month */
|
|
||||||
0xe0, /* month */
|
|
||||||
0xf8, /* day of week */
|
|
||||||
0x00, /* year */
|
|
||||||
0x7f, /* control */
|
|
||||||
};
|
|
||||||
int i;
|
|
||||||
int rc;
|
|
||||||
int reserved;
|
|
||||||
|
|
||||||
reserved = i2c_smbus_read_byte_data(client, MAX6900_REG_RESERVED_READ);
|
|
||||||
if (reserved != 0x07)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
rc = max6900_i2c_read_regs(client, regs);
|
|
||||||
if (rc < 0)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(zero_mask); ++i) {
|
|
||||||
if (regs[i] & zero_mask[i])
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
|
static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -220,8 +174,8 @@ static int max6900_i2c_clear_write_protect(struct i2c_client *client)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max6900_i2c_set_time(struct i2c_client *client,
|
static int
|
||||||
struct rtc_time const *tm)
|
max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
|
||||||
{
|
{
|
||||||
u8 regs[MAX6900_REG_LEN];
|
u8 regs[MAX6900_REG_LEN];
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -258,89 +212,49 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
||||||
return max6900_i2c_set_time(to_i2c_client(dev), tm);
|
return max6900_i2c_set_time(to_i2c_client(dev), tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max6900_attach_adapter(struct i2c_adapter *adapter)
|
static int max6900_remove(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
return i2c_probe(adapter, &addr_data, max6900_probe);
|
struct rtc_device *rtc = i2c_get_clientdata(client);
|
||||||
}
|
|
||||||
|
|
||||||
static int max6900_detach_client(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct rtc_device *const rtc = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
if (rtc)
|
if (rtc)
|
||||||
rtc_device_unregister(rtc);
|
rtc_device_unregister(rtc);
|
||||||
|
|
||||||
return i2c_detach_client(client);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct i2c_driver max6900_driver = {
|
|
||||||
.driver = {
|
|
||||||
.name = DRV_NAME,
|
|
||||||
},
|
|
||||||
.id = I2C_DRIVERID_MAX6900,
|
|
||||||
.attach_adapter = max6900_attach_adapter,
|
|
||||||
.detach_client = max6900_detach_client,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct rtc_class_ops max6900_rtc_ops = {
|
static const struct rtc_class_ops max6900_rtc_ops = {
|
||||||
.read_time = max6900_rtc_read_time,
|
.read_time = max6900_rtc_read_time,
|
||||||
.set_time = max6900_rtc_set_time,
|
.set_time = max6900_rtc_set_time,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind)
|
static int
|
||||||
|
max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
struct rtc_device *rtc;
|
||||||
struct i2c_client *client = NULL;
|
|
||||||
struct rtc_device *rtc = NULL;
|
|
||||||
|
|
||||||
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
|
||||||
rc = -ENODEV;
|
return -ENODEV;
|
||||||
goto failout;
|
|
||||||
}
|
|
||||||
|
|
||||||
client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
|
||||||
if (client == NULL) {
|
|
||||||
rc = -ENOMEM;
|
|
||||||
goto failout;
|
|
||||||
}
|
|
||||||
|
|
||||||
client->addr = addr;
|
|
||||||
client->adapter = adapter;
|
|
||||||
client->driver = &max6900_driver;
|
|
||||||
strlcpy(client->name, DRV_NAME, I2C_NAME_SIZE);
|
|
||||||
|
|
||||||
if (kind < 0) {
|
|
||||||
rc = max6900_i2c_validate_client(client);
|
|
||||||
if (rc < 0)
|
|
||||||
goto failout;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = i2c_attach_client(client);
|
|
||||||
if (rc < 0)
|
|
||||||
goto failout;
|
|
||||||
|
|
||||||
dev_info(&client->dev,
|
|
||||||
"chip found, driver version " DRV_VERSION "\n");
|
|
||||||
|
|
||||||
rtc = rtc_device_register(max6900_driver.driver.name,
|
rtc = rtc_device_register(max6900_driver.driver.name,
|
||||||
&client->dev,
|
&client->dev, &max6900_rtc_ops, THIS_MODULE);
|
||||||
&max6900_rtc_ops, THIS_MODULE);
|
if (IS_ERR(rtc))
|
||||||
if (IS_ERR(rtc)) {
|
return PTR_ERR(rtc);
|
||||||
rc = PTR_ERR(rtc);
|
|
||||||
goto failout_detach;
|
|
||||||
}
|
|
||||||
|
|
||||||
i2c_set_clientdata(client, rtc);
|
i2c_set_clientdata(client, rtc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
failout_detach:
|
|
||||||
i2c_detach_client(client);
|
|
||||||
failout:
|
|
||||||
kfree(client);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct i2c_driver max6900_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "rtc-max6900",
|
||||||
|
},
|
||||||
|
.probe = max6900_probe,
|
||||||
|
.remove = max6900_remove,
|
||||||
|
};
|
||||||
|
|
||||||
static int __init max6900_init(void)
|
static int __init max6900_init(void)
|
||||||
{
|
{
|
||||||
return i2c_add_driver(&max6900_driver);
|
return i2c_add_driver(&max6900_driver);
|
||||||
|
@ -352,6 +266,7 @@ static void __exit max6900_exit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
|
MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
|
||||||
|
MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_VERSION(DRV_VERSION);
|
MODULE_VERSION(DRV_VERSION);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче