aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Walls <awalls@md.metrocast.net>2011-01-14 19:11:22 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-01-19 08:46:05 -0500
commite9b351f64f5c02acf6552d2109bc213bfa133388 (patch)
treef44b3ebc4ab3a1529193deb23231727a97bc31f7
parent06da95a3ec831dee23f6af58934944a8eb9c3a56 (diff)
[media] lirc_zilog: Don't make private copies of i2c clients
Don't make private copies of the i2c clients provided by the I2C subsystem, don't change the client address field, and don't probe the client addresses - the bridge driver already did that. This moves us to the proper I2C and binding model. Signed-off-by: Andy Walls <awalls@md.metrocast.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/staging/lirc/lirc_zilog.c87
1 files changed, 28 insertions, 59 deletions
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index 85e312f33513..00f2e7d3b3e5 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -62,7 +62,7 @@
62 62
63struct IR_rx { 63struct IR_rx {
64 /* RX device */ 64 /* RX device */
65 struct i2c_client c_rx; 65 struct i2c_client *c;
66 66
67 /* RX device buffer & lock */ 67 /* RX device buffer & lock */
68 struct lirc_buffer buf; 68 struct lirc_buffer buf;
@@ -81,7 +81,7 @@ struct IR_rx {
81 81
82struct IR_tx { 82struct IR_tx {
83 /* TX device */ 83 /* TX device */
84 struct i2c_client c_tx; 84 struct i2c_client *c;
85 85
86 /* TX additional actions needed */ 86 /* TX additional actions needed */
87 int need_boot; 87 int need_boot;
@@ -132,9 +132,6 @@ static struct mutex tx_data_lock;
132 ## args) 132 ## args)
133#define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) 133#define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
134 134
135#define ZILOG_HAUPPAUGE_IR_RX_NAME "Zilog/Hauppauge IR RX"
136#define ZILOG_HAUPPAUGE_IR_TX_NAME "Zilog/Hauppauge IR TX"
137
138/* module parameters */ 135/* module parameters */
139static int debug; /* debug output */ 136static int debug; /* debug output */
140static int disable_rx; /* disable RX device */ 137static int disable_rx; /* disable RX device */
@@ -181,7 +178,7 @@ static int add_to_buf(struct IR *ir)
181 * Send random "poll command" (?) Windows driver does this 178 * Send random "poll command" (?) Windows driver does this
182 * and it is a good point to detect chip failure. 179 * and it is a good point to detect chip failure.
183 */ 180 */
184 ret = i2c_master_send(&rx->c_rx, sendbuf, 1); 181 ret = i2c_master_send(rx->c, sendbuf, 1);
185 if (ret != 1) { 182 if (ret != 1) {
186 zilog_error("i2c_master_send failed with %d\n", ret); 183 zilog_error("i2c_master_send failed with %d\n", ret);
187 if (failures >= 3) { 184 if (failures >= 3) {
@@ -205,7 +202,7 @@ static int add_to_buf(struct IR *ir)
205 continue; 202 continue;
206 } 203 }
207 204
208 ret = i2c_master_recv(&rx->c_rx, keybuf, sizeof(keybuf)); 205 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf));
209 mutex_unlock(&ir->ir_lock); 206 mutex_unlock(&ir->ir_lock);
210 if (ret != sizeof(keybuf)) { 207 if (ret != sizeof(keybuf)) {
211 zilog_error("i2c_master_recv failed with %d -- " 208 zilog_error("i2c_master_recv failed with %d -- "
@@ -315,9 +312,9 @@ static int set_use_inc(void *data)
315 * must be possible even when the device is open 312 * must be possible even when the device is open
316 */ 313 */
317 if (ir->rx != NULL) 314 if (ir->rx != NULL)
318 i2c_use_client(&ir->rx->c_rx); 315 i2c_use_client(ir->rx->c);
319 if (ir->tx != NULL) 316 if (ir->tx != NULL)
320 i2c_use_client(&ir->tx->c_tx); 317 i2c_use_client(ir->tx->c);
321 318
322 return 0; 319 return 0;
323} 320}
@@ -327,9 +324,9 @@ static void set_use_dec(void *data)
327 struct IR *ir = data; 324 struct IR *ir = data;
328 325
329 if (ir->rx) 326 if (ir->rx)
330 i2c_release_client(&ir->rx->c_rx); 327 i2c_release_client(ir->rx->c);
331 if (ir->tx) 328 if (ir->tx)
332 i2c_release_client(&ir->tx->c_tx); 329 i2c_release_client(ir->tx->c);
333 if (ir->l.owner != NULL) 330 if (ir->l.owner != NULL)
334 module_put(ir->l.owner); 331 module_put(ir->l.owner);
335} 332}
@@ -482,7 +479,7 @@ static int send_data_block(struct IR_tx *tx, unsigned char *data_block)
482 buf[1 + j] = data_block[i + j]; 479 buf[1 + j] = data_block[i + j];
483 dprintk("%02x %02x %02x %02x %02x", 480 dprintk("%02x %02x %02x %02x %02x",
484 buf[0], buf[1], buf[2], buf[3], buf[4]); 481 buf[0], buf[1], buf[2], buf[3], buf[4]);
485 ret = i2c_master_send(&tx->c_tx, buf, tosend + 1); 482 ret = i2c_master_send(tx->c, buf, tosend + 1);
486 if (ret != tosend + 1) { 483 if (ret != tosend + 1) {
487 zilog_error("i2c_master_send failed with %d\n", ret); 484 zilog_error("i2c_master_send failed with %d\n", ret);
488 return ret < 0 ? ret : -EFAULT; 485 return ret < 0 ? ret : -EFAULT;
@@ -506,19 +503,19 @@ static int send_boot_data(struct IR_tx *tx)
506 /* kick it off? */ 503 /* kick it off? */
507 buf[0] = 0x00; 504 buf[0] = 0x00;
508 buf[1] = 0x20; 505 buf[1] = 0x20;
509 ret = i2c_master_send(&tx->c_tx, buf, 2); 506 ret = i2c_master_send(tx->c, buf, 2);
510 if (ret != 2) { 507 if (ret != 2) {
511 zilog_error("i2c_master_send failed with %d\n", ret); 508 zilog_error("i2c_master_send failed with %d\n", ret);
512 return ret < 0 ? ret : -EFAULT; 509 return ret < 0 ? ret : -EFAULT;
513 } 510 }
514 ret = i2c_master_send(&tx->c_tx, buf, 1); 511 ret = i2c_master_send(tx->c, buf, 1);
515 if (ret != 1) { 512 if (ret != 1) {
516 zilog_error("i2c_master_send failed with %d\n", ret); 513 zilog_error("i2c_master_send failed with %d\n", ret);
517 return ret < 0 ? ret : -EFAULT; 514 return ret < 0 ? ret : -EFAULT;
518 } 515 }
519 516
520 /* Here comes the firmware version... (hopefully) */ 517 /* Here comes the firmware version... (hopefully) */
521 ret = i2c_master_recv(&tx->c_tx, buf, 4); 518 ret = i2c_master_recv(tx->c, buf, 4);
522 if (ret != 4) { 519 if (ret != 4) {
523 zilog_error("i2c_master_recv failed with %d\n", ret); 520 zilog_error("i2c_master_recv failed with %d\n", ret);
524 return 0; 521 return 0;
@@ -573,7 +570,7 @@ static int fw_load(struct IR_tx *tx)
573 } 570 }
574 571
575 /* Request codeset data file */ 572 /* Request codeset data file */
576 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &tx->c_tx.dev); 573 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &tx->c->dev);
577 if (ret != 0) { 574 if (ret != 0) {
578 zilog_error("firmware haup-ir-blaster.bin not available " 575 zilog_error("firmware haup-ir-blaster.bin not available "
579 "(%d)\n", ret); 576 "(%d)\n", ret);
@@ -822,19 +819,19 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
822 /* Send data block length? */ 819 /* Send data block length? */
823 buf[0] = 0x00; 820 buf[0] = 0x00;
824 buf[1] = 0x40; 821 buf[1] = 0x40;
825 ret = i2c_master_send(&tx->c_tx, buf, 2); 822 ret = i2c_master_send(tx->c, buf, 2);
826 if (ret != 2) { 823 if (ret != 2) {
827 zilog_error("i2c_master_send failed with %d\n", ret); 824 zilog_error("i2c_master_send failed with %d\n", ret);
828 return ret < 0 ? ret : -EFAULT; 825 return ret < 0 ? ret : -EFAULT;
829 } 826 }
830 ret = i2c_master_send(&tx->c_tx, buf, 1); 827 ret = i2c_master_send(tx->c, buf, 1);
831 if (ret != 1) { 828 if (ret != 1) {
832 zilog_error("i2c_master_send failed with %d\n", ret); 829 zilog_error("i2c_master_send failed with %d\n", ret);
833 return ret < 0 ? ret : -EFAULT; 830 return ret < 0 ? ret : -EFAULT;
834 } 831 }
835 832
836 /* Send finished download? */ 833 /* Send finished download? */
837 ret = i2c_master_recv(&tx->c_tx, buf, 1); 834 ret = i2c_master_recv(tx->c, buf, 1);
838 if (ret != 1) { 835 if (ret != 1) {
839 zilog_error("i2c_master_recv failed with %d\n", ret); 836 zilog_error("i2c_master_recv failed with %d\n", ret);
840 return ret < 0 ? ret : -EFAULT; 837 return ret < 0 ? ret : -EFAULT;
@@ -848,7 +845,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
848 /* Send prepare command? */ 845 /* Send prepare command? */
849 buf[0] = 0x00; 846 buf[0] = 0x00;
850 buf[1] = 0x80; 847 buf[1] = 0x80;
851 ret = i2c_master_send(&tx->c_tx, buf, 2); 848 ret = i2c_master_send(tx->c, buf, 2);
852 if (ret != 2) { 849 if (ret != 2) {
853 zilog_error("i2c_master_send failed with %d\n", ret); 850 zilog_error("i2c_master_send failed with %d\n", ret);
854 return ret < 0 ? ret : -EFAULT; 851 return ret < 0 ? ret : -EFAULT;
@@ -873,7 +870,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
873 for (i = 0; i < 20; ++i) { 870 for (i = 0; i < 20; ++i) {
874 set_current_state(TASK_UNINTERRUPTIBLE); 871 set_current_state(TASK_UNINTERRUPTIBLE);
875 schedule_timeout((50 * HZ + 999) / 1000); 872 schedule_timeout((50 * HZ + 999) / 1000);
876 ret = i2c_master_send(&tx->c_tx, buf, 1); 873 ret = i2c_master_send(tx->c, buf, 1);
877 if (ret == 1) 874 if (ret == 1)
878 break; 875 break;
879 dprintk("NAK expected: i2c_master_send " 876 dprintk("NAK expected: i2c_master_send "
@@ -886,7 +883,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
886 } 883 }
887 884
888 /* Seems to be an 'ok' response */ 885 /* Seems to be an 'ok' response */
889 i = i2c_master_recv(&tx->c_tx, buf, 1); 886 i = i2c_master_recv(tx->c, buf, 1);
890 if (i != 1) { 887 if (i != 1) {
891 zilog_error("i2c_master_recv failed with %d\n", ret); 888 zilog_error("i2c_master_recv failed with %d\n", ret);
892 return -EFAULT; 889 return -EFAULT;
@@ -1214,7 +1211,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1214{ 1211{
1215 struct IR *ir = NULL; 1212 struct IR *ir = NULL;
1216 struct i2c_adapter *adap = client->adapter; 1213 struct i2c_adapter *adap = client->adapter;
1217 char buf;
1218 int ret; 1214 int ret;
1219 int have_rx = 0, have_tx = 0; 1215 int have_rx = 0, have_tx = 0;
1220 1216
@@ -1239,24 +1235,13 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1239 * The external IR receiver is at i2c address 0x71. 1235 * The external IR receiver is at i2c address 0x71.
1240 * The IR transmitter is at 0x70. 1236 * The IR transmitter is at 0x70.
1241 */ 1237 */
1242 client->addr = 0x70;
1243 1238
1244 if (i2c_master_recv(client, &buf, 1) == 1) 1239 if (id->driver_data & ID_FLAG_TX) {
1245 have_tx = 1; 1240 have_tx = 1;
1246 dprintk("probe 0x70 @ %s: %s\n", 1241 } else if (!disable_rx) {
1247 adap->name, have_tx ? "success" : "failed"); 1242 have_rx = 1;
1248 1243 } else {
1249 if (!disable_rx) { 1244 return -ENXIO;
1250 client->addr = 0x71;
1251 if (i2c_master_recv(client, &buf, 1) == 1)
1252 have_rx = 1;
1253 dprintk("probe 0x71 @ %s: %s\n",
1254 adap->name, have_rx ? "success" : "failed");
1255 }
1256
1257 if (!(have_rx || have_tx)) {
1258 zilog_error("%s: no devices found\n", adap->name);
1259 goto out_nodev;
1260 } 1245 }
1261 1246
1262 printk(KERN_INFO "lirc_zilog: chip found with %s\n", 1247 printk(KERN_INFO "lirc_zilog: chip found with %s\n",
@@ -1270,6 +1255,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1270 if (have_tx) { 1255 if (have_tx) {
1271 ir->tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL); 1256 ir->tx = kzalloc(sizeof(struct IR_tx), GFP_KERNEL);
1272 if (ir->tx != NULL) { 1257 if (ir->tx != NULL) {
1258 ir->tx->c = client;
1273 ir->tx->need_boot = 1; 1259 ir->tx->need_boot = 1;
1274 ir->tx->post_tx_ready_poll = 1260 ir->tx->post_tx_ready_poll =
1275 (id->driver_data & ID_FLAG_HDPVR) ? false : true; 1261 (id->driver_data & ID_FLAG_HDPVR) ? false : true;
@@ -1282,6 +1268,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1282 if (ir->rx == NULL) { 1268 if (ir->rx == NULL) {
1283 ret = -ENOMEM; 1269 ret = -ENOMEM;
1284 } else { 1270 } else {
1271 ir->rx->c = client;
1285 ir->rx->hdpvr_data_fmt = 1272 ir->rx->hdpvr_data_fmt =
1286 (id->driver_data & ID_FLAG_HDPVR) ? true : false; 1273 (id->driver_data & ID_FLAG_HDPVR) ? true : false;
1287 mutex_init(&ir->rx->buf_lock); 1274 mutex_init(&ir->rx->buf_lock);
@@ -1305,11 +1292,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1305 /* initialise RX device */ 1292 /* initialise RX device */
1306 if (ir->rx != NULL) { 1293 if (ir->rx != NULL) {
1307 DECLARE_COMPLETION(tn); 1294 DECLARE_COMPLETION(tn);
1308 memcpy(&ir->rx->c_rx, client, sizeof(struct i2c_client));
1309
1310 ir->rx->c_rx.addr = 0x71;
1311 strlcpy(ir->rx->c_rx.name, ZILOG_HAUPPAUGE_IR_RX_NAME,
1312 I2C_NAME_SIZE);
1313 1295
1314 /* try to fire up polling thread */ 1296 /* try to fire up polling thread */
1315 ir->rx->t_notify = &tn; 1297 ir->rx->t_notify = &tn;
@@ -1324,14 +1306,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1324 ir->rx->t_notify = NULL; 1306 ir->rx->t_notify = NULL;
1325 } 1307 }
1326 1308
1327 /* initialise TX device */
1328 if (ir->tx) {
1329 memcpy(&ir->tx->c_tx, client, sizeof(struct i2c_client));
1330 ir->tx->c_tx.addr = 0x70;
1331 strlcpy(ir->tx->c_tx.name, ZILOG_HAUPPAUGE_IR_TX_NAME,
1332 I2C_NAME_SIZE);
1333 }
1334
1335 /* set lirc_dev stuff */ 1309 /* set lirc_dev stuff */
1336 ir->l.code_length = 13; 1310 ir->l.code_length = 13;
1337 ir->l.rbuf = (ir->rx == NULL) ? NULL : &ir->rx->buf; 1311 ir->l.rbuf = (ir->rx == NULL) ? NULL : &ir->rx->buf;
@@ -1371,16 +1345,11 @@ err:
1371 /* FIXME - memory deallocation for all error cases needs work */ 1345 /* FIXME - memory deallocation for all error cases needs work */
1372 /* undo everything, hopefully... */ 1346 /* undo everything, hopefully... */
1373 if (ir->rx != NULL) 1347 if (ir->rx != NULL)
1374 ir_remove(&ir->rx->c_rx); 1348 ir_remove(ir->rx->c);
1375 if (ir->tx != NULL) 1349 if (ir->tx != NULL)
1376 ir_remove(&ir->tx->c_tx); 1350 ir_remove(ir->tx->c);
1377 return ret; 1351 return ret;
1378 1352
1379out_nodev:
1380 /* FIXME - memory deallocation for all error cases needs work */
1381 zilog_error("no device found\n");
1382 return -ENODEV;
1383
1384out_nomem: 1353out_nomem:
1385 /* FIXME - memory deallocation for all error cases needs work */ 1354 /* FIXME - memory deallocation for all error cases needs work */
1386 zilog_error("memory allocation failure\n"); 1355 zilog_error("memory allocation failure\n");