Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[ARM] Turn ARM RiscPC PCF8583 i2c RTC driver into a proper module

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Russell King and committed by
Russell King
1d1fd66c b4c2803c

+63 -17
+63 -17
drivers/acorn/char/pcf8583.c
··· 9 9 * 10 10 * Driver for PCF8583 RTC & RAM chip 11 11 */ 12 + #include <linux/module.h> 12 13 #include <linux/i2c.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/string.h> ··· 33 32 .forces = forces, 34 33 }; 35 34 36 - #define DAT(x) ((unsigned int)(x->dev.driver_data)) 35 + #define set_ctrl(x, v) i2c_set_clientdata(x, (void *)(unsigned int)(v)) 36 + #define get_ctrl(x) ((unsigned int)i2c_get_clientdata(x)) 37 37 38 38 static int 39 39 pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) ··· 42 40 struct i2c_client *c; 43 41 unsigned char buf[1], ad[1] = { 0 }; 44 42 struct i2c_msg msgs[2] = { 45 - { addr, 0, 1, ad }, 46 - { addr, I2C_M_RD, 1, buf } 43 + { 44 + .addr = addr, 45 + .flags = 0, 46 + .len = 1, 47 + .buf = ad, 48 + }, { 49 + .addr = addr, 50 + .flags = I2C_M_RD, 51 + .len = 1, 52 + .buf = buf, 53 + } 47 54 }; 48 55 49 56 c = kmalloc(sizeof(*c), GFP_KERNEL); ··· 65 54 c->driver = &pcf8583_driver; 66 55 67 56 if (i2c_transfer(c->adapter, msgs, 2) == 2) 68 - DAT(c) = buf[0]; 57 + set_ctrl(c, buf[0]); 69 58 70 59 return i2c_attach_client(c); 71 60 } ··· 89 78 { 90 79 unsigned char buf[8], addr[1] = { 1 }; 91 80 struct i2c_msg msgs[2] = { 92 - { client->addr, 0, 1, addr }, 93 - { client->addr, I2C_M_RD, 6, buf } 81 + { 82 + .addr = client->addr, 83 + .flags = 0, 84 + .len = 1, 85 + .buf = addr, 86 + }, { 87 + .addr = client->addr, 88 + .flags = I2C_M_RD, 89 + .len = 6, 90 + .buf = buf, 91 + } 94 92 }; 95 93 int ret = -EIO; 96 94 ··· 133 113 int ret, len = 6; 134 114 135 115 buf[0] = 0; 136 - buf[1] = DAT(client) | 0x80; 116 + buf[1] = get_ctrl(client) | 0x80; 137 117 buf[2] = BIN_TO_BCD(dt->cs); 138 118 buf[3] = BIN_TO_BCD(dt->secs); 139 119 buf[4] = BIN_TO_BCD(dt->mins); ··· 149 129 if (ret == len) 150 130 ret = 0; 151 131 152 - buf[1] = DAT(client); 132 + buf[1] = get_ctrl(client); 153 133 i2c_master_send(client, (char *)buf, 2); 154 134 155 135 return ret; ··· 158 138 static int 159 139 pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl) 160 140 { 161 - *ctrl = DAT(client); 141 + *ctrl = get_ctrl(client); 162 142 return 0; 163 143 } 164 144 ··· 169 149 170 150 buf[0] = 0; 171 151 buf[1] = *ctrl; 172 - DAT(client) = *ctrl; 152 + set_ctrl(client, *ctrl); 173 153 174 154 return i2c_master_send(client, (char *)buf, 2); 175 155 } ··· 179 159 { 180 160 unsigned char addr[1]; 181 161 struct i2c_msg msgs[2] = { 182 - { client->addr, 0, 1, addr }, 183 - { client->addr, I2C_M_RD, 0, mem->data } 162 + { 163 + .addr = client->addr, 164 + .flags = 0, 165 + .len = 1, 166 + .buf = addr, 167 + }, { 168 + .addr = client->addr, 169 + .flags = I2C_M_RD, 170 + .len = mem->nr, 171 + .buf = mem->data, 172 + } 184 173 }; 185 174 186 175 if (mem->loc < 8) 187 176 return -EINVAL; 188 177 189 178 addr[0] = mem->loc; 190 - msgs[1].len = mem->nr; 191 179 192 180 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; 193 181 } ··· 205 177 { 206 178 unsigned char addr[1]; 207 179 struct i2c_msg msgs[2] = { 208 - { client->addr, 0, 1, addr }, 209 - { client->addr, 0, 0, mem->data } 180 + { 181 + .addr = client->addr, 182 + .flags = 0, 183 + .len = 1, 184 + .buf = addr, 185 + }, { 186 + .addr = client->addr, 187 + .flags = I2C_M_NOSTART, 188 + .len = mem->nr, 189 + .buf = mem->data, 190 + } 210 191 }; 211 192 212 193 if (mem->loc < 8) 213 194 return -EINVAL; 214 195 215 196 addr[0] = mem->loc; 216 - msgs[1].len = mem->nr; 217 197 218 198 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; 219 199 } ··· 270 234 return i2c_add_driver(&pcf8583_driver); 271 235 } 272 236 273 - __initcall(pcf8583_init); 237 + static __exit void pcf8583_exit(void) 238 + { 239 + i2c_del_driver(&pcf8583_driver); 240 + } 241 + 242 + module_init(pcf8583_init); 243 + module_exit(pcf8583_exit); 244 + 245 + MODULE_AUTHOR("Russell King"); 246 + MODULE_DESCRIPTION("PCF8583 I2C RTC driver"); 247 + MODULE_LICENSE("GPL");