Commit 2eb25832 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[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: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5b2e303f
...@@ -271,20 +271,16 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -271,20 +271,16 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
const char *name = NULL; const char *name = NULL;
u64 ir_type = IR_TYPE_UNKNOWN; u64 ir_type = IR_TYPE_UNKNOWN;
struct IR_i2c *ir; struct IR_i2c *ir;
struct rc_dev *rc; struct rc_dev *rc = NULL;
struct i2c_adapter *adap = client->adapter; struct i2c_adapter *adap = client->adapter;
unsigned short addr = client->addr; unsigned short addr = client->addr;
int err; int err;
ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL); ir = kzalloc(sizeof(struct IR_i2c), GFP_KERNEL);
rc = rc_allocate_device(); if (!ir)
if (!ir || !rc) { return -ENOMEM;
err = -ENOMEM;
goto err_out_free;
}
ir->c = client; ir->c = client;
ir->rc = rc;
ir->polling_interval = DEFAULT_POLLING_INTERVAL; ir->polling_interval = DEFAULT_POLLING_INTERVAL;
i2c_set_clientdata(client, ir); i2c_set_clientdata(client, ir);
...@@ -333,6 +329,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -333,6 +329,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
client->dev.platform_data; client->dev.platform_data;
ir_codes = init_data->ir_codes; ir_codes = init_data->ir_codes;
rc = init_data->rc_dev;
name = init_data->name; name = init_data->name;
if (init_data->type) if (init_data->type)
ir_type = init_data->type; ir_type = init_data->type;
...@@ -366,6 +364,19 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -366,6 +364,19 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
} }
} }
if (!rc) {
/*
* If platform_data doesn't specify rc_dev, initilize it
* internally
*/
rc = rc_allocate_device();
if (!rc) {
err = -ENOMEM;
goto err_out_free;
}
}
ir->rc = rc;
/* Make sure we are all setup before going on */ /* Make sure we are all setup before going on */
if (!name || !ir->get_key || !ir_type || !ir_codes) { if (!name || !ir->get_key || !ir_type || !ir_codes) {
dprintk(1, ": Unsupported device at address 0x%02x\n", 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,12 +393,21 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
dev_name(&adap->dev), dev_name(&adap->dev),
dev_name(&client->dev)); dev_name(&client->dev));
/* init + register input device */ /*
* Initialize input_dev fields
* It doesn't make sense to allow overriding them via platform_data
*/
rc->input_id.bustype = BUS_I2C; rc->input_id.bustype = BUS_I2C;
rc->input_name = ir->name;
rc->input_phys = ir->phys; rc->input_phys = ir->phys;
rc->map_name = ir->ir_codes; rc->input_name = ir->name;
rc->driver_name = MODULE_NAME;
/*
* Initialize the other fields of rc_dev
*/
rc->map_name = ir->ir_codes;
rc->allowed_protos = ir_type;
if (!rc->driver_name)
rc->driver_name = MODULE_NAME;
err = rc_register_device(rc); err = rc_register_device(rc);
if (err) if (err)
...@@ -403,6 +423,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -403,6 +423,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
return 0; return 0;
err_out_free: err_out_free:
/* Only frees rc if it were allocated internally */
rc_free_device(rc); rc_free_device(rc);
kfree(ir); kfree(ir);
return err; return err;
......
...@@ -46,5 +46,7 @@ struct IR_i2c_init_data { ...@@ -46,5 +46,7 @@ struct IR_i2c_init_data {
*/ */
int (*get_key)(struct IR_i2c*, u32*, u32*); int (*get_key)(struct IR_i2c*, u32*, u32*);
enum ir_kbd_get_key_fn internal_get_key_func; enum ir_kbd_get_key_fn internal_get_key_func;
struct rc_dev *rc_dev;
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment