diff options
| author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2005-10-30 14:07:59 -0500 |
|---|---|---|
| committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2005-10-30 14:07:59 -0500 |
| commit | 1d1fd66c45fa78c6fed61612e14dad0e24c815c2 (patch) | |
| tree | f78f5370f45eaa17d6eea0b8378f20d99ccff8f2 /drivers/acorn/char | |
| parent | b4c2803ca8ad7bb1aad215d89532e24488e9e68e (diff) | |
[ARM] Turn ARM RiscPC PCF8583 i2c RTC driver into a proper module
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/acorn/char')
| -rw-r--r-- | drivers/acorn/char/pcf8583.c | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/drivers/acorn/char/pcf8583.c b/drivers/acorn/char/pcf8583.c index 2b850e5860a0..e26f007a1417 100644 --- a/drivers/acorn/char/pcf8583.c +++ b/drivers/acorn/char/pcf8583.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | * | 9 | * |
| 10 | * Driver for PCF8583 RTC & RAM chip | 10 | * Driver for PCF8583 RTC & RAM chip |
| 11 | */ | 11 | */ |
| 12 | #include <linux/module.h> | ||
| 12 | #include <linux/i2c.h> | 13 | #include <linux/i2c.h> |
| 13 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
| 14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
| @@ -32,7 +33,8 @@ static struct i2c_client_address_data addr_data = { | |||
| 32 | .forces = forces, | 33 | .forces = forces, |
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | #define DAT(x) ((unsigned int)(x->dev.driver_data)) | 36 | #define set_ctrl(x, v) i2c_set_clientdata(x, (void *)(unsigned int)(v)) |
| 37 | #define get_ctrl(x) ((unsigned int)i2c_get_clientdata(x)) | ||
| 36 | 38 | ||
| 37 | static int | 39 | static int |
| 38 | pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) | 40 | pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) |
| @@ -40,8 +42,17 @@ pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) | |||
| 40 | struct i2c_client *c; | 42 | struct i2c_client *c; |
| 41 | unsigned char buf[1], ad[1] = { 0 }; | 43 | unsigned char buf[1], ad[1] = { 0 }; |
| 42 | struct i2c_msg msgs[2] = { | 44 | struct i2c_msg msgs[2] = { |
| 43 | { addr, 0, 1, ad }, | 45 | { |
| 44 | { addr, I2C_M_RD, 1, buf } | 46 | .addr = addr, |
| 47 | .flags = 0, | ||
| 48 | .len = 1, | ||
| 49 | .buf = ad, | ||
| 50 | }, { | ||
| 51 | .addr = addr, | ||
| 52 | .flags = I2C_M_RD, | ||
| 53 | .len = 1, | ||
| 54 | .buf = buf, | ||
| 55 | } | ||
| 45 | }; | 56 | }; |
| 46 | 57 | ||
| 47 | c = kmalloc(sizeof(*c), GFP_KERNEL); | 58 | c = kmalloc(sizeof(*c), GFP_KERNEL); |
| @@ -54,7 +65,7 @@ pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) | |||
| 54 | c->driver = &pcf8583_driver; | 65 | c->driver = &pcf8583_driver; |
| 55 | 66 | ||
| 56 | if (i2c_transfer(c->adapter, msgs, 2) == 2) | 67 | if (i2c_transfer(c->adapter, msgs, 2) == 2) |
| 57 | DAT(c) = buf[0]; | 68 | set_ctrl(c, buf[0]); |
| 58 | 69 | ||
| 59 | return i2c_attach_client(c); | 70 | return i2c_attach_client(c); |
| 60 | } | 71 | } |
| @@ -78,8 +89,17 @@ pcf8583_get_datetime(struct i2c_client *client, struct rtc_tm *dt) | |||
| 78 | { | 89 | { |
| 79 | unsigned char buf[8], addr[1] = { 1 }; | 90 | unsigned char buf[8], addr[1] = { 1 }; |
| 80 | struct i2c_msg msgs[2] = { | 91 | struct i2c_msg msgs[2] = { |
| 81 | { client->addr, 0, 1, addr }, | 92 | { |
| 82 | { client->addr, I2C_M_RD, 6, buf } | 93 | .addr = client->addr, |
| 94 | .flags = 0, | ||
| 95 | .len = 1, | ||
| 96 | .buf = addr, | ||
| 97 | }, { | ||
| 98 | .addr = client->addr, | ||
| 99 | .flags = I2C_M_RD, | ||
| 100 | .len = 6, | ||
| 101 | .buf = buf, | ||
| 102 | } | ||
| 83 | }; | 103 | }; |
| 84 | int ret = -EIO; | 104 | int ret = -EIO; |
| 85 | 105 | ||
| @@ -113,7 +133,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo) | |||
| 113 | int ret, len = 6; | 133 | int ret, len = 6; |
| 114 | 134 | ||
| 115 | buf[0] = 0; | 135 | buf[0] = 0; |
| 116 | buf[1] = DAT(client) | 0x80; | 136 | buf[1] = get_ctrl(client) | 0x80; |
| 117 | buf[2] = BIN_TO_BCD(dt->cs); | 137 | buf[2] = BIN_TO_BCD(dt->cs); |
| 118 | buf[3] = BIN_TO_BCD(dt->secs); | 138 | buf[3] = BIN_TO_BCD(dt->secs); |
| 119 | buf[4] = BIN_TO_BCD(dt->mins); | 139 | buf[4] = BIN_TO_BCD(dt->mins); |
| @@ -129,7 +149,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo) | |||
| 129 | if (ret == len) | 149 | if (ret == len) |
| 130 | ret = 0; | 150 | ret = 0; |
| 131 | 151 | ||
| 132 | buf[1] = DAT(client); | 152 | buf[1] = get_ctrl(client); |
| 133 | i2c_master_send(client, (char *)buf, 2); | 153 | i2c_master_send(client, (char *)buf, 2); |
| 134 | 154 | ||
| 135 | return ret; | 155 | return ret; |
| @@ -138,7 +158,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo) | |||
| 138 | static int | 158 | static int |
| 139 | pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl) | 159 | pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl) |
| 140 | { | 160 | { |
| 141 | *ctrl = DAT(client); | 161 | *ctrl = get_ctrl(client); |
| 142 | return 0; | 162 | return 0; |
| 143 | } | 163 | } |
| 144 | 164 | ||
| @@ -149,7 +169,7 @@ pcf8583_set_ctrl(struct i2c_client *client, unsigned char *ctrl) | |||
| 149 | 169 | ||
| 150 | buf[0] = 0; | 170 | buf[0] = 0; |
| 151 | buf[1] = *ctrl; | 171 | buf[1] = *ctrl; |
| 152 | DAT(client) = *ctrl; | 172 | set_ctrl(client, *ctrl); |
| 153 | 173 | ||
| 154 | return i2c_master_send(client, (char *)buf, 2); | 174 | return i2c_master_send(client, (char *)buf, 2); |
| 155 | } | 175 | } |
| @@ -159,15 +179,23 @@ pcf8583_read_mem(struct i2c_client *client, struct mem *mem) | |||
| 159 | { | 179 | { |
| 160 | unsigned char addr[1]; | 180 | unsigned char addr[1]; |
| 161 | struct i2c_msg msgs[2] = { | 181 | struct i2c_msg msgs[2] = { |
| 162 | { client->addr, 0, 1, addr }, | 182 | { |
| 163 | { client->addr, I2C_M_RD, 0, mem->data } | 183 | .addr = client->addr, |
| 184 | .flags = 0, | ||
| 185 | .len = 1, | ||
| 186 | .buf = addr, | ||
| 187 | }, { | ||
| 188 | .addr = client->addr, | ||
| 189 | .flags = I2C_M_RD, | ||
| 190 | .len = mem->nr, | ||
| 191 | .buf = mem->data, | ||
| 192 | } | ||
| 164 | }; | 193 | }; |
| 165 | 194 | ||
| 166 | if (mem->loc < 8) | 195 | if (mem->loc < 8) |
| 167 | return -EINVAL; | 196 | return -EINVAL; |
| 168 | 197 | ||
| 169 | addr[0] = mem->loc; | 198 | addr[0] = mem->loc; |
| 170 | msgs[1].len = mem->nr; | ||
| 171 | 199 | ||
| 172 | return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; | 200 | return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; |
| 173 | } | 201 | } |
| @@ -177,15 +205,23 @@ pcf8583_write_mem(struct i2c_client *client, struct mem *mem) | |||
| 177 | { | 205 | { |
| 178 | unsigned char addr[1]; | 206 | unsigned char addr[1]; |
| 179 | struct i2c_msg msgs[2] = { | 207 | struct i2c_msg msgs[2] = { |
| 180 | { client->addr, 0, 1, addr }, | 208 | { |
| 181 | { client->addr, 0, 0, mem->data } | 209 | .addr = client->addr, |
| 210 | .flags = 0, | ||
| 211 | .len = 1, | ||
| 212 | .buf = addr, | ||
| 213 | }, { | ||
| 214 | .addr = client->addr, | ||
| 215 | .flags = I2C_M_NOSTART, | ||
| 216 | .len = mem->nr, | ||
| 217 | .buf = mem->data, | ||
| 218 | } | ||
| 182 | }; | 219 | }; |
| 183 | 220 | ||
| 184 | if (mem->loc < 8) | 221 | if (mem->loc < 8) |
| 185 | return -EINVAL; | 222 | return -EINVAL; |
| 186 | 223 | ||
| 187 | addr[0] = mem->loc; | 224 | addr[0] = mem->loc; |
| 188 | msgs[1].len = mem->nr; | ||
| 189 | 225 | ||
| 190 | return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; | 226 | return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; |
| 191 | } | 227 | } |
| @@ -234,4 +270,14 @@ static __init int pcf8583_init(void) | |||
| 234 | return i2c_add_driver(&pcf8583_driver); | 270 | return i2c_add_driver(&pcf8583_driver); |
| 235 | } | 271 | } |
| 236 | 272 | ||
| 237 | __initcall(pcf8583_init); | 273 | static __exit void pcf8583_exit(void) |
| 274 | { | ||
| 275 | i2c_del_driver(&pcf8583_driver); | ||
| 276 | } | ||
| 277 | |||
| 278 | module_init(pcf8583_init); | ||
| 279 | module_exit(pcf8583_exit); | ||
| 280 | |||
| 281 | MODULE_AUTHOR("Russell King"); | ||
| 282 | MODULE_DESCRIPTION("PCF8583 I2C RTC driver"); | ||
| 283 | MODULE_LICENSE("GPL"); | ||
