X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fmedia%2Fvideo%2Findycam.c;h=5c2c4029ff86bd76a3872152b198b58259e73936;hb=30fbc9f77c5a77f5f7f053d29eb92e41f6043406;hp=26dd06ec89a2b6aa2b96e2b794cc7bd2e5ae5ac3;hpb=9359ede748ff1461bf0632fb4182f61da4a2f9e2;p=linux-2.6-omap-h63xx.git diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c index 26dd06ec89a..5c2c4029ff8 100644 --- a/drivers/media/video/indycam.c +++ b/drivers/media/video/indycam.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -27,15 +26,15 @@ #include "indycam.h" -//#define INDYCAM_DEBUG - -#define INDYCAM_MODULE_VERSION "0.0.3" +#define INDYCAM_MODULE_VERSION "0.0.5" MODULE_DESCRIPTION("SGI IndyCam driver"); MODULE_VERSION(INDYCAM_MODULE_VERSION); MODULE_AUTHOR("Mikael Nousiainen "); MODULE_LICENSE("GPL"); +// #define INDYCAM_DEBUG + #ifdef INDYCAM_DEBUG #define dprintk(x...) printk("IndyCam: " x); #define indycam_regdump(client) indycam_regdump_debug(client) @@ -46,14 +45,14 @@ MODULE_LICENSE("GPL"); struct indycam { struct i2c_client *client; - int version; + u8 version; }; static struct i2c_driver i2c_driver_indycam; -static const unsigned char initseq[] = { +static const u8 initseq[] = { INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */ - INDYCAM_SHUTTER_DEFAULT, /* INDYCAM_SHUTTER */ + INDYCAM_SHUTTER_60, /* INDYCAM_SHUTTER */ INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */ 0x00, /* INDYCAM_BRIGHTNESS (read-only) */ INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */ @@ -64,12 +63,11 @@ static const unsigned char initseq[] = { /* IndyCam register handling */ -static int indycam_read_reg(struct i2c_client *client, unsigned char reg, - unsigned char *value) +static int indycam_read_reg(struct i2c_client *client, u8 reg, u8 *value) { int ret; - if (reg == INDYCAM_RESET) { + if (reg == INDYCAM_REG_RESET) { dprintk("indycam_read_reg(): " "skipping write-only register %d\n", reg); *value = 0; @@ -77,24 +75,24 @@ static int indycam_read_reg(struct i2c_client *client, unsigned char reg, } ret = i2c_smbus_read_byte_data(client, reg); + if (ret < 0) { printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, " "register = 0x%02x\n", reg); return ret; } - *value = (unsigned char)ret; + *value = (u8)ret; return 0; } -static int indycam_write_reg(struct i2c_client *client, unsigned char reg, - unsigned char value) +static int indycam_write_reg(struct i2c_client *client, u8 reg, u8 value) { int err; - if ((reg == INDYCAM_BRIGHTNESS) - || (reg == INDYCAM_VERSION)) { + if ((reg == INDYCAM_REG_BRIGHTNESS) + || (reg == INDYCAM_REG_VERSION)) { dprintk("indycam_write_reg(): " "skipping read-only register %d\n", reg); return 0; @@ -102,6 +100,7 @@ static int indycam_write_reg(struct i2c_client *client, unsigned char reg, dprintk("Writing Reg %d = 0x%02x\n", reg, value); err = i2c_smbus_write_byte_data(client, reg, value); + if (err) { printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, " "register = 0x%02x, value = 0x%02x\n", reg, value); @@ -109,13 +108,12 @@ static int indycam_write_reg(struct i2c_client *client, unsigned char reg, return err; } -static int indycam_write_block(struct i2c_client *client, unsigned char reg, - unsigned char length, unsigned char *data) +static int indycam_write_block(struct i2c_client *client, u8 reg, + u8 length, u8 *data) { - unsigned char i; - int err; + int i, err; - for (i = reg; i < length; i++) { + for (i = 0; i < length; i++) { err = indycam_write_reg(client, reg + i, data[i]); if (err) return err; @@ -130,7 +128,7 @@ static int indycam_write_block(struct i2c_client *client, unsigned char reg, static void indycam_regdump_debug(struct i2c_client *client) { int i; - unsigned char val; + u8 val; for (i = 0; i < 9; i++) { indycam_read_reg(client, i, &val); @@ -139,76 +137,144 @@ static void indycam_regdump_debug(struct i2c_client *client) } #endif -static int indycam_get_controls(struct i2c_client *client, - struct indycam_control *ctrl) +static int indycam_get_control(struct i2c_client *client, + struct indycam_control *ctrl) { - unsigned char ctrl_reg; - - indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg); - ctrl->agc = (ctrl_reg & INDYCAM_CONTROL_AGCENA) - ? INDYCAM_VALUE_ENABLED - : INDYCAM_VALUE_DISABLED; - ctrl->awb = (ctrl_reg & INDYCAM_CONTROL_AWBCTL) - ? INDYCAM_VALUE_ENABLED - : INDYCAM_VALUE_DISABLED; - indycam_read_reg(client, INDYCAM_SHUTTER, - (unsigned char *)&ctrl->shutter); - indycam_read_reg(client, INDYCAM_GAIN, - (unsigned char *)&ctrl->gain); - indycam_read_reg(client, INDYCAM_RED_BALANCE, - (unsigned char *)&ctrl->red_balance); - indycam_read_reg(client, INDYCAM_BLUE_BALANCE, - (unsigned char *)&ctrl->blue_balance); - indycam_read_reg(client, INDYCAM_RED_SATURATION, - (unsigned char *)&ctrl->red_saturation); - indycam_read_reg(client, INDYCAM_BLUE_SATURATION, - (unsigned char *)&ctrl->blue_saturation); - indycam_read_reg(client, INDYCAM_GAMMA, - (unsigned char *)&ctrl->gamma); + struct indycam *camera = i2c_get_clientdata(client); + u8 reg; + int ret = 0; + + switch (ctrl->type) { + case INDYCAM_CONTROL_AGC: + case INDYCAM_CONTROL_AWB: + ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, ®); + if (ret) + return -EIO; + if (ctrl->type == INDYCAM_CONTROL_AGC) + ctrl->value = (reg & INDYCAM_CONTROL_AGCENA) + ? 1 : 0; + else + ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL) + ? 1 : 0; + break; + case INDYCAM_CONTROL_SHUTTER: + ret = indycam_read_reg(client, INDYCAM_REG_SHUTTER, ®); + if (ret) + return -EIO; + ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1); + break; + case INDYCAM_CONTROL_GAIN: + ret = indycam_read_reg(client, INDYCAM_REG_GAIN, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + break; + case INDYCAM_CONTROL_RED_BALANCE: + ret = indycam_read_reg(client, INDYCAM_REG_RED_BALANCE, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + break; + case INDYCAM_CONTROL_BLUE_BALANCE: + ret = indycam_read_reg(client, INDYCAM_REG_BLUE_BALANCE, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + break; + case INDYCAM_CONTROL_RED_SATURATION: + ret = indycam_read_reg(client, + INDYCAM_REG_RED_SATURATION, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + break; + case INDYCAM_CONTROL_BLUE_SATURATION: + ret = indycam_read_reg(client, + INDYCAM_REG_BLUE_SATURATION, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + break; + case INDYCAM_CONTROL_GAMMA: + if (camera->version == CAMERA_VERSION_MOOSE) { + ret = indycam_read_reg(client, + INDYCAM_REG_GAMMA, ®); + if (ret) + return -EIO; + ctrl->value = (s32)reg; + } else { + ctrl->value = INDYCAM_GAMMA_DEFAULT; + } + break; + default: + ret = -EINVAL; + } - return 0; + return ret; } -static int indycam_set_controls(struct i2c_client *client, - struct indycam_control *ctrl) +static int indycam_set_control(struct i2c_client *client, + struct indycam_control *ctrl) { - unsigned char ctrl_reg; + struct indycam *camera = i2c_get_clientdata(client); + u8 reg; + int ret = 0; + + switch (ctrl->type) { + case INDYCAM_CONTROL_AGC: + case INDYCAM_CONTROL_AWB: + ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, ®); + if (ret) + break; - indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg); - if (ctrl->agc != INDYCAM_VALUE_UNCHANGED) { - if (ctrl->agc) - ctrl_reg |= INDYCAM_CONTROL_AGCENA; - else - ctrl_reg &= ~INDYCAM_CONTROL_AGCENA; - } - if (ctrl->awb != INDYCAM_VALUE_UNCHANGED) { - if (ctrl->awb) - ctrl_reg |= INDYCAM_CONTROL_AWBCTL; - else - ctrl_reg &= ~INDYCAM_CONTROL_AWBCTL; + if (ctrl->type == INDYCAM_CONTROL_AGC) { + if (ctrl->value) + reg |= INDYCAM_CONTROL_AGCENA; + else + reg &= ~INDYCAM_CONTROL_AGCENA; + } else { + if (ctrl->value) + reg |= INDYCAM_CONTROL_AWBCTL; + else + reg &= ~INDYCAM_CONTROL_AWBCTL; + } + + ret = indycam_write_reg(client, INDYCAM_REG_CONTROL, reg); + break; + case INDYCAM_CONTROL_SHUTTER: + reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1); + ret = indycam_write_reg(client, INDYCAM_REG_SHUTTER, reg); + break; + case INDYCAM_CONTROL_GAIN: + ret = indycam_write_reg(client, INDYCAM_REG_GAIN, ctrl->value); + break; + case INDYCAM_CONTROL_RED_BALANCE: + ret = indycam_write_reg(client, INDYCAM_REG_RED_BALANCE, + ctrl->value); + break; + case INDYCAM_CONTROL_BLUE_BALANCE: + ret = indycam_write_reg(client, INDYCAM_REG_BLUE_BALANCE, + ctrl->value); + break; + case INDYCAM_CONTROL_RED_SATURATION: + ret = indycam_write_reg(client, INDYCAM_REG_RED_SATURATION, + ctrl->value); + break; + case INDYCAM_CONTROL_BLUE_SATURATION: + ret = indycam_write_reg(client, INDYCAM_REG_BLUE_SATURATION, + ctrl->value); + break; + case INDYCAM_CONTROL_GAMMA: + if (camera->version == CAMERA_VERSION_MOOSE) { + ret = indycam_write_reg(client, INDYCAM_REG_GAMMA, + ctrl->value); + } + break; + default: + ret = -EINVAL; } - indycam_write_reg(client, INDYCAM_CONTROL, ctrl_reg); - - if (ctrl->shutter >= 0) - indycam_write_reg(client, INDYCAM_SHUTTER, ctrl->shutter); - if (ctrl->gain >= 0) - indycam_write_reg(client, INDYCAM_GAIN, ctrl->gain); - if (ctrl->red_balance >= 0) - indycam_write_reg(client, INDYCAM_RED_BALANCE, - ctrl->red_balance); - if (ctrl->blue_balance >= 0) - indycam_write_reg(client, INDYCAM_BLUE_BALANCE, - ctrl->blue_balance); - if (ctrl->red_saturation >= 0) - indycam_write_reg(client, INDYCAM_RED_SATURATION, - ctrl->red_saturation); - if (ctrl->blue_saturation >= 0) - indycam_write_reg(client, INDYCAM_BLUE_SATURATION, - ctrl->blue_saturation); - if (ctrl->gamma >= 0) - indycam_write_reg(client, INDYCAM_GAMMA, ctrl->gamma); - return 0; + return ret; } /* I2C-interface */ @@ -222,18 +288,15 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind) printk(KERN_INFO "SGI IndyCam driver version %s\n", INDYCAM_MODULE_VERSION); - client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); + client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); if (!client) return -ENOMEM; - camera = kmalloc(sizeof(struct indycam), GFP_KERNEL); + camera = kzalloc(sizeof(struct indycam), GFP_KERNEL); if (!camera) { err = -ENOMEM; goto out_free_client; } - memset(client, 0, sizeof(struct i2c_client)); - memset(camera, 0, sizeof(struct indycam)); - client->addr = addr; client->adapter = adap; client->driver = &i2c_driver_indycam; @@ -247,7 +310,8 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind) if (err) goto out_free_camera; - camera->version = i2c_smbus_read_byte_data(client, INDYCAM_VERSION); + camera->version = i2c_smbus_read_byte_data(client, + INDYCAM_REG_VERSION); if (camera->version != CAMERA_VERSION_INDY && camera->version != CAMERA_VERSION_MOOSE) { err = -ENODEV; @@ -260,8 +324,7 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind) indycam_regdump(client); // initialize - err = indycam_write_block(client, 0, sizeof(initseq), - (unsigned char *)&initseq); + err = indycam_write_block(client, 0, sizeof(initseq), (u8 *)&initseq); if (err) { printk(KERN_ERR "IndyCam initalization failed\n"); err = -EIO; @@ -271,11 +334,10 @@ static int indycam_attach(struct i2c_adapter *adap, int addr, int kind) indycam_regdump(client); // white balance - err = indycam_write_reg(client, INDYCAM_CONTROL, + err = indycam_write_reg(client, INDYCAM_REG_CONTROL, INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL); if (err) { - printk(KERN_ERR "IndyCam white balance " - "initialization failed\n"); + printk(KERN_ERR "IndyCam: White balancing camera failed\n"); err = -EIO; goto out_detach_client; } @@ -371,13 +433,11 @@ static int indycam_command(struct i2c_client *client, unsigned int cmd, /* TODO: convert values for indycam_set_controls() */ break; } - case DECODER_INDYCAM_GET_CONTROLS: { - struct indycam_control *ctrl = arg; - indycam_get_controls(client, ctrl); + case DECODER_INDYCAM_GET_CONTROL: { + return indycam_get_control(client, arg); } - case DECODER_INDYCAM_SET_CONTROLS: { - struct indycam_control *ctrl = arg; - indycam_set_controls(client, ctrl); + case DECODER_INDYCAM_SET_CONTROL: { + return indycam_set_control(client, arg); } default: return -EINVAL; @@ -387,13 +447,13 @@ static int indycam_command(struct i2c_client *client, unsigned int cmd, } static struct i2c_driver i2c_driver_indycam = { - .owner = THIS_MODULE, - .name = "indycam", - .id = I2C_DRIVERID_INDYCAM, - .flags = I2C_DF_NOTIFY, + .driver = { + .name = "indycam", + }, + .id = I2C_DRIVERID_INDYCAM, .attach_adapter = indycam_probe, - .detach_client = indycam_detach, - .command = indycam_command, + .detach_client = indycam_detach, + .command = indycam_command, }; static int __init indycam_init(void)