diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-11-12 07:02:40 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-12-29 05:16:38 -0500 |
commit | 2eb258327722de3ed4d84ce1b9add2bad21a0ec4 (patch) | |
tree | d2f5e21d74e8b3062fc847a3af38221f1362d281 | |
parent | 5b2e303f6df1e0b1a903950c5d613a20c8c71a37 (diff) |
[media] ir-kbd-i2c: add rc_dev as a parameter to the driver
There are several fields on rc_dev that drivers can benefit. Allow drivers
to pass it as a parameter to the driver.
For now, the rc_dev parameter is optional. If drivers don't pass it, create
them internally. However, the best is to create rc_dev inside the drivers,
in order to fill other fields, like open(), close(), driver_name, etc.
So, a latter patch making it mandatory and changing the caller drivers is
welcome.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/ir-kbd-i2c.c | 45 | ||||
-rw-r--r-- | include/media/ir-kbd-i2c.h | 2 |
2 files changed, 35 insertions, 12 deletions
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c index 83b59a195230..de0060fa33f1 100644 --- a/drivers/media/video/ir-kbd-i2c.c +++ b/drivers/media/video/ir-kbd-i2c.c | |||
@@ -271,20 +271,16 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
271 | const char *name = NULL; | 271 | const char *name = NULL; |
272 | u64 ir_type = IR_TYPE_UNKNOWN; | 272 | u64 ir_type = IR_TYPE_UNKNOWN; |
273 | struct IR_i2c *ir; | 273 | struct IR_i2c *ir; |
274 | struct rc_dev *rc; | 274 | struct rc_dev *rc = NULL; |
275 | struct i2c_adapter *adap = client->adapter; | 275 | struct i2c_adapter *adap = client->adapter; |
276 | unsigned short addr = client->addr; | 276 | unsigned short addr = client->addr; |
277 | int err; | 277 | int err; |
278 | 278 | ||
279 | ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL); | 279 | ir = kzalloc(sizeof(struct IR_i2c), GFP_KERNEL); |
280 | rc = rc_allocate_device(); | 280 | if (!ir) |
281 | if (!ir || !rc) { | 281 | return -ENOMEM; |
282 | err = -ENOMEM; | ||
283 | goto err_out_free; | ||
284 | } | ||
285 | 282 | ||
286 | ir->c = client; | 283 | ir->c = client; |
287 | ir->rc = rc; | ||
288 | ir->polling_interval = DEFAULT_POLLING_INTERVAL; | 284 | ir->polling_interval = DEFAULT_POLLING_INTERVAL; |
289 | i2c_set_clientdata(client, ir); | 285 | i2c_set_clientdata(client, ir); |
290 | 286 | ||
@@ -333,6 +329,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
333 | client->dev.platform_data; | 329 | client->dev.platform_data; |
334 | 330 | ||
335 | ir_codes = init_data->ir_codes; | 331 | ir_codes = init_data->ir_codes; |
332 | rc = init_data->rc_dev; | ||
333 | |||
336 | name = init_data->name; | 334 | name = init_data->name; |
337 | if (init_data->type) | 335 | if (init_data->type) |
338 | ir_type = init_data->type; | 336 | ir_type = init_data->type; |
@@ -366,6 +364,19 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
366 | } | 364 | } |
367 | } | 365 | } |
368 | 366 | ||
367 | if (!rc) { | ||
368 | /* | ||
369 | * If platform_data doesn't specify rc_dev, initilize it | ||
370 | * internally | ||
371 | */ | ||
372 | rc = rc_allocate_device(); | ||
373 | if (!rc) { | ||
374 | err = -ENOMEM; | ||
375 | goto err_out_free; | ||
376 | } | ||
377 | } | ||
378 | ir->rc = rc; | ||
379 | |||
369 | /* Make sure we are all setup before going on */ | 380 | /* Make sure we are all setup before going on */ |
370 | if (!name || !ir->get_key || !ir_type || !ir_codes) { | 381 | if (!name || !ir->get_key || !ir_type || !ir_codes) { |
371 | dprintk(1, ": Unsupported device at address 0x%02x\n", | 382 | dprintk(1, ": Unsupported device at address 0x%02x\n", |
@@ -382,12 +393,21 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
382 | dev_name(&adap->dev), | 393 | dev_name(&adap->dev), |
383 | dev_name(&client->dev)); | 394 | dev_name(&client->dev)); |
384 | 395 | ||
385 | /* init + register input device */ | 396 | /* |
397 | * Initialize input_dev fields | ||
398 | * It doesn't make sense to allow overriding them via platform_data | ||
399 | */ | ||
386 | rc->input_id.bustype = BUS_I2C; | 400 | rc->input_id.bustype = BUS_I2C; |
387 | rc->input_name = ir->name; | ||
388 | rc->input_phys = ir->phys; | 401 | rc->input_phys = ir->phys; |
389 | rc->map_name = ir->ir_codes; | 402 | rc->input_name = ir->name; |
390 | rc->driver_name = MODULE_NAME; | 403 | |
404 | /* | ||
405 | * Initialize the other fields of rc_dev | ||
406 | */ | ||
407 | rc->map_name = ir->ir_codes; | ||
408 | rc->allowed_protos = ir_type; | ||
409 | if (!rc->driver_name) | ||
410 | rc->driver_name = MODULE_NAME; | ||
391 | 411 | ||
392 | err = rc_register_device(rc); | 412 | err = rc_register_device(rc); |
393 | if (err) | 413 | if (err) |
@@ -403,6 +423,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
403 | return 0; | 423 | return 0; |
404 | 424 | ||
405 | err_out_free: | 425 | err_out_free: |
426 | /* Only frees rc if it were allocated internally */ | ||
406 | rc_free_device(rc); | 427 | rc_free_device(rc); |
407 | kfree(ir); | 428 | kfree(ir); |
408 | return err; | 429 | return err; |
diff --git a/include/media/ir-kbd-i2c.h b/include/media/ir-kbd-i2c.h index 4ee9b42cbf72..aca015e04f17 100644 --- a/include/media/ir-kbd-i2c.h +++ b/include/media/ir-kbd-i2c.h | |||
@@ -46,5 +46,7 @@ struct IR_i2c_init_data { | |||
46 | */ | 46 | */ |
47 | int (*get_key)(struct IR_i2c*, u32*, u32*); | 47 | int (*get_key)(struct IR_i2c*, u32*, u32*); |
48 | enum ir_kbd_get_key_fn internal_get_key_func; | 48 | enum ir_kbd_get_key_fn internal_get_key_func; |
49 | |||
50 | struct rc_dev *rc_dev; | ||
49 | }; | 51 | }; |
50 | #endif | 52 | #endif |