Commit a913beae authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

[PATCH] update sa7111/7185 to new i2c

parent 72ad73df
......@@ -34,7 +34,7 @@
#include <linux/videodev.h>
#include <linux/version.h>
#include <linux/i2c-old.h>
#include <linux/i2c.h>
#include <linux/video_decoder.h>
......@@ -43,8 +43,9 @@
/* ----------------------------------------------------------------------- */
struct saa7111 {
struct i2c_bus *bus;
struct i2c_client *client;
int addr;
struct semaphore lock;
unsigned char reg[32];
int norm;
......@@ -60,74 +61,32 @@ struct saa7111 {
#define I2C_DELAY 10
/* ----------------------------------------------------------------------- */
static int saa7111_write(struct saa7111 *dev, unsigned char subaddr,
unsigned char data)
{
int ack;
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
ack = i2c_sendbyte(dev->bus, data, I2C_DELAY);
dev->reg[subaddr] = data;
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
return ack;
}
static int saa7111_write_block(struct saa7111 *dev,
unsigned const char *data, unsigned int len)
{
int ack = -1;
unsigned subaddr;
while (len > 1) {
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
ack = i2c_sendbyte(dev->bus, (subaddr = *data++), I2C_DELAY);
ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
len -= 2;
while (len > 1 && *data == ++subaddr) {
data++;
ack =
i2c_sendbyte(dev->bus,
(dev->reg[subaddr] =
*data++), I2C_DELAY);
len -= 2;
}
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
}
return ack;
}
static int saa7111_read(struct saa7111 *dev, unsigned char subaddr)
{
int data;
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr | 1, I2C_DELAY);
data = i2c_readbyte(dev->bus, 1);
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
return data;
}
static unsigned short normal_i2c[] = { 34>>1, I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
static struct i2c_client_address_data addr_data = {
.normal_i2c = normal_i2c,
.normal_i2c_range = normal_i2c_range,
.probe = probe,
.probe_range = probe_range,
.ignore = ignore,
.ignore_range = ignore_range,
.force = force
};
static struct i2c_client client_template;
/* ----------------------------------------------------------------------- */
static int saa7111_attach(struct i2c_device *device)
static int saa7111_attach(struct i2c_adapter *adap, int addr, unsigned short flags, int kind)
{
int i;
struct saa7111 *decoder;
struct i2c_client *client;
static const unsigned char init[] = {
0x00, 0x00, /* 00 - ID byte */
0x01, 0x00, /* 01 - reserved */
......@@ -158,20 +117,25 @@ static int saa7111_attach(struct i2c_device *device)
0x16, 0x00, /* 16 - VBI */
0x17, 0x00, /* 17 - VBI */
};
client = kmalloc(sizeof(*client), GFP_KERNEL);
if(client == NULL)
return -ENOMEM;
client_template.adapter = adap;
client_template.addr = addr;
memcpy(client, &client_template, sizeof(*client));
MOD_INC_USE_COUNT;
device->data = decoder = kmalloc(sizeof(struct saa7111), GFP_KERNEL);
decoder = kmalloc(sizeof(*decoder), GFP_KERNEL);
if (decoder == NULL)
{
MOD_DEC_USE_COUNT;
kfree(client);
return -ENOMEM;
}
memset(decoder, 0, sizeof(struct saa7111));
strcpy(device->name, "saa7111");
decoder->bus = device->bus;
decoder->addr = device->addr;
memset(decoder, 0, sizeof(*decoder));
strcpy(client->name, "saa7111");
decoder->client = client;
client->data = decoder;
decoder->addr = addr;
decoder->norm = VIDEO_MODE_NTSC;
decoder->input = 0;
decoder->enable = 1;
......@@ -180,29 +144,38 @@ static int saa7111_attach(struct i2c_device *device)
decoder->hue = 32768;
decoder->sat = 32768;
i = saa7111_write_block(decoder, init, sizeof(init));
i = i2c_master_send(client, init, sizeof(init));
if (i < 0) {
printk(KERN_ERR "%s_attach: init status %d\n",
device->name, i);
client->name, i);
} else {
printk(KERN_INFO "%s_attach: chip version %x\n",
device->name, saa7111_read(decoder, 0x00) >> 4);
client->name, i2c_smbus_read_byte_data(client, 0x00) >> 4);
}
init_MUTEX(&decoder->lock);
i2c_attach_client(client);
MOD_INC_USE_COUNT;
return 0;
}
static int saa7111_probe(struct i2c_adapter *adap)
{
return i2c_probe(adap, &addr_data, saa7111_attach);
}
static int saa7111_detach(struct i2c_device *device)
static int saa7111_detach(struct i2c_client *client)
{
kfree(device->data);
struct saa7111 *decoder = client->data;
i2c_detach_client(client);
kfree(decoder);
kfree(client);
MOD_DEC_USE_COUNT;
return 0;
}
static int saa7111_command(struct i2c_device *device, unsigned int cmd,
static int saa7111_command(struct i2c_client *client, unsigned int cmd,
void *arg)
{
struct saa7111 *decoder = device->data;
struct saa7111 *decoder = client->data;
switch (cmd) {
......@@ -214,11 +187,11 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
for (i = 0; i < 32; i += 16) {
int j;
printk("KERN_DEBUG %s: %03x", device->name,
printk("KERN_DEBUG %s: %03x", client->name,
i);
for (j = 0; j < 16; ++j) {
printk(" %02x",
saa7111_read(decoder,
i2c_smbus_read_byte_data(client,
i + j));
}
printk("\n");
......@@ -246,7 +219,7 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
int status;
int res;
status = saa7111_read(decoder, 0x1f);
status = i2c_smbus_read_byte_data(client, 0x1f);
res = 0;
if ((status & (1 << 6)) == 0) {
res |= DECODER_STATUS_GOOD;
......@@ -281,19 +254,19 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
switch (*iarg) {
case VIDEO_MODE_NTSC:
saa7111_write(decoder, 0x08,
i2c_smbus_write_byte_data(client, 0x08,
(decoder->
reg[0x08] & 0x3f) | 0x40);
break;
case VIDEO_MODE_PAL:
saa7111_write(decoder, 0x08,
i2c_smbus_write_byte_data(client, 0x08,
(decoder->
reg[0x08] & 0x3f) | 0x00);
break;
case VIDEO_MODE_AUTO:
saa7111_write(decoder, 0x08,
i2c_smbus_write_byte_data(client, 0x08,
(decoder->
reg[0x08] & 0x3f) | 0x80);
break;
......@@ -317,12 +290,12 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
if (decoder->input != *iarg) {
decoder->input = *iarg;
/* select mode */
saa7111_write(decoder, 0x02,
i2c_smbus_write_byte_data(client, 0x02,
(decoder->
reg[0x02] & 0xf8) |
decoder->input);
/* bypass chrominance trap for modes 4..7 */
saa7111_write(decoder, 0x09,
i2c_smbus_write_byte_data(client, 0x09,
(decoder->
reg[0x09] & 0x7f) |
((decoder->input >
......@@ -357,26 +330,26 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
// If output should be enabled, we have to reverse the above.
if (decoder->enable) {
saa7111_write(decoder, 0x02,
i2c_smbus_write_byte_data(client, 0x02,
(decoder->
reg[0x02] & 0xf8) |
decoder->input);
saa7111_write(decoder, 0x08,
i2c_smbus_write_byte_data(client, 0x08,
(decoder->
reg[0x08] & 0xfb));
saa7111_write(decoder, 0x11,
i2c_smbus_write_byte_data(client, 0x11,
(decoder->
reg[0x11] & 0xf3) |
0x0c);
} else {
saa7111_write(decoder, 0x02,
i2c_smbus_write_byte_data(client, 0x02,
(decoder->
reg[0x02] & 0xf8));
saa7111_write(decoder, 0x08,
i2c_smbus_write_byte_data(client, 0x08,
(decoder->
reg[0x08] & 0xfb) |
0x04);
saa7111_write(decoder, 0x11,
i2c_smbus_write_byte_data(client, 0x11,
(decoder->
reg[0x11] & 0xf3));
}
......@@ -391,25 +364,25 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
if (decoder->bright != pic->brightness) {
/* We want 0 to 255 we get 0-65535 */
decoder->bright = pic->brightness;
saa7111_write(decoder, 0x0a,
i2c_smbus_write_byte_data(client, 0x0a,
decoder->bright >> 8);
}
if (decoder->contrast != pic->contrast) {
/* We want 0 to 127 we get 0-65535 */
decoder->contrast = pic->contrast;
saa7111_write(decoder, 0x0b,
i2c_smbus_write_byte_data(client, 0x0b,
decoder->contrast >> 9);
}
if (decoder->sat != pic->colour) {
/* We want 0 to 127 we get 0-65535 */
decoder->sat = pic->colour;
saa7111_write(decoder, 0x0c,
i2c_smbus_write_byte_data(client, 0x0c,
decoder->sat >> 9);
}
if (decoder->hue != pic->hue) {
/* We want -128 to 127 we get 0-65535 */
decoder->hue = pic->hue;
saa7111_write(decoder, 0x0d,
i2c_smbus_write_byte_data(client, 0x0d,
(decoder->hue - 32768) >> 8);
}
}
......@@ -425,23 +398,28 @@ static int saa7111_command(struct i2c_device *device, unsigned int cmd,
/* ----------------------------------------------------------------------- */
static struct i2c_driver i2c_driver_saa7111 = {
"saa7111", /* name */
I2C_DRIVERID_VIDEODECODER, /* ID */
I2C_SAA7111, I2C_SAA7111 + 1,
.name = "saa7111", /* name */
.id = I2C_DRIVERID_SAA7111A, /* ID */
.flags = I2C_DF_NOTIFY,
.attach_adapter = saa7111_probe,
.detach_client = saa7111_detach,
.command = saa7111_command
};
saa7111_attach,
saa7111_detach,
saa7111_command
static struct i2c_client client_template = {
.name = "saa7111_client",
.id = -1,
.driver = &i2c_driver_saa7111
};
static int saa7111_init(void)
{
return i2c_register_driver(&i2c_driver_saa7111);
return i2c_add_driver(&i2c_driver_saa7111);
}
static void saa7111_exit(void)
{
i2c_unregister_driver(&i2c_driver_saa7111);
i2c_del_driver(&i2c_driver_saa7111);
}
module_init(saa7111_init);
......
......@@ -43,7 +43,7 @@
#include <linux/version.h>
#include <asm/uaccess.h>
#include <linux/i2c-old.h>
#include <linux/i2c.h>
#include <linux/video_encoder.h>
......@@ -52,9 +52,10 @@
/* ----------------------------------------------------------------------- */
struct saa7185 {
struct i2c_bus *bus;
struct i2c_client *client;
int addr;
unsigned char reg[128];
struct semaphore lock;
int norm;
int enable;
......@@ -69,66 +70,25 @@ struct saa7185 {
#define I2C_DELAY 10
/* ----------------------------------------------------------------------- */
static unsigned short normal_i2c[] = { 34>>1, I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
static unsigned short probe[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
static unsigned short probe_range[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static unsigned short ignore_range[2] = { I2C_CLIENT_END , I2C_CLIENT_END };
static unsigned short force[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
static struct i2c_client_address_data addr_data = {
.normal_i2c = normal_i2c,
.normal_i2c_range = normal_i2c_range,
.probe = probe,
.probe_range = probe_range,
.ignore = ignore,
.ignore_range = ignore_range,
.force = force
};
static int saa7185_read(struct saa7185 *dev)
{
int ack;
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr | 1, I2C_DELAY);
ack = i2c_readbyte(dev->bus, 1);
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
return ack;
}
static int saa7185_write(struct saa7185 *dev, unsigned char subaddr,
unsigned char data)
{
int ack;
DEBUG(printk
(KERN_DEBUG "SAA7185: %02x set to %02x\n", subaddr, data);
)
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
ack = i2c_sendbyte(dev->bus, data, I2C_DELAY);
dev->reg[subaddr] = data;
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
return ack;
}
static int saa7185_write_block(struct saa7185 *dev,
unsigned const char *data, unsigned int len)
{
int ack = -1;
unsigned subaddr;
while (len > 1) {
LOCK_I2C_BUS(dev->bus);
i2c_start(dev->bus);
i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
ack = i2c_sendbyte(dev->bus, (subaddr = *data++), I2C_DELAY);
ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
len -= 2;
while (len > 1 && *data == ++subaddr) {
data++;
ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
len -= 2;
}
i2c_stop(dev->bus);
UNLOCK_I2C_BUS(dev->bus);
}
return ack;
}
/* ----------------------------------------------------------------------- */
static struct i2c_client client_template;
static const unsigned char init_common[] = {
0x3a, 0x0f, /* CBENB=0, V656=0, VY2C=1, YUV2C=1, MY2C=1, MUV2C=1 */
......@@ -222,58 +182,71 @@ static const unsigned char init_ntsc[] = {
0x66, 0x21, /* FSC3 */
};
static int saa7185_attach(struct i2c_device *device)
static int saa7185_attach(struct i2c_adapter *adap, int addr, unsigned short flags, int kind)
{
int i;
struct saa7185 *encoder;
struct i2c_client client;
MOD_INC_USE_COUNT;
device->data = encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL);
client = kmalloc(sizeof(*client), GFP_KERNEL);
if (client == NULL)
return -ENOMEM;
client_template.adapter = adap;
client_template.addr = addr;
memcpy(client, &client_template, sizeof(*client));
encoder = kmalloc(sizeof(*decoder), GFP_KERNEL);
if (encoder == NULL) {
MOD_DEC_USE_COUNT;
kfree(client);
return -ENOMEM;
}
memset(encoder, 0, sizeof(struct saa7185));
strcpy(device->name, "saa7185");
encoder->bus = device->bus;
encoder->addr = device->addr;
memset(encoder, 0, sizeof(*decoder));
strcpy(client->name, "saa7185");
encoder->client = client;
client->data = encoder;
encoder->addr = addr;
encoder->norm = VIDEO_MODE_NTSC;
encoder->enable = 1;
i = saa7185_write_block(encoder, init_common, sizeof(init_common));
i = i2c_master_send(client, init_common, sizeof(init_common));
if (i >= 0) {
i = saa7185_write_block(encoder, init_ntsc,
i = i2c_master_send(client, init_ntsc,
sizeof(init_ntsc));
}
if (i < 0) {
printk(KERN_ERR "%s_attach: init error %d\n", device->name,
printk(KERN_ERR "%s_attach: init error %d\n", client->name,
i);
} else {
printk(KERN_INFO "%s_attach: chip version %d\n",
device->name, saa7185_read(encoder) >> 5);
client->name, i2c_smbus_read_byte(client) >> 5);
}
init_MUTEX(&decoder->lock);
i2c_attach_client(client);
MOD_INC_USE_COUNT;
return 0;
}
static int saa7185_probe(struct i2c_adapter *adap)
{
return i2c_probe(adap, &addr_data, saa7185_attach);
}
static int saa7185_detach(struct i2c_device *device)
static int saa7185_detach(struct i2c_client *client)
{
struct saa7185 *encoder = device->data;
saa7185_write(encoder, 0x61, (encoder->reg[0x61]) | 0x40); /* SW: output off is active */
//saa7185_write(encoder, 0x3a, (encoder->reg[0x3a]) | 0x80); /* SW: color bar */
struct saa7185 *encoder = client->data;
i2c_detach_client(client);
i2c_smbus_write_byte_data(client, 0x61, (encoder->reg[0x61]) | 0x40); /* SW: output off is active */
//i2c_smbus_write_byte_data(client, 0x3a, (encoder->reg[0x3a]) | 0x80); /* SW: color bar */
kfree(encoder);
kfree(client);
MOD_DEC_USE_COUNT;
return 0;
}
static int saa7185_command(struct i2c_device *device, unsigned int cmd,
static int saa7185_command(struct i2c_client *client, unsigned int cmd,
void *arg)
{
struct saa7185 *encoder = device->data;
struct saa7185 *encoder = client->data;
switch (cmd) {
......@@ -297,12 +270,12 @@ static int saa7185_command(struct i2c_device *device, unsigned int cmd,
switch (*iarg) {
case VIDEO_MODE_NTSC:
saa7185_write_block(encoder, init_ntsc,
i2c_master_send(client, init_ntsc,
sizeof(init_ntsc));
break;
case VIDEO_MODE_PAL:
saa7185_write_block(encoder, init_pal,
i2c_master_send(client, init_pal,
sizeof(init_pal));
break;
......@@ -326,19 +299,19 @@ static int saa7185_command(struct i2c_device *device, unsigned int cmd,
case 0:
/* Switch RTCE to 1 */
saa7185_write(encoder, 0x61,
i2c_smbus_write_byte_data(client, 0x61,
(encoder->
reg[0x61] & 0xf7) | 0x08);
saa7185_write(encoder, 0x6e, 0x01);
i2c_smbus_write_byte_data(client, 0x6e, 0x01);
break;
case 1:
/* Switch RTCE to 0 */
saa7185_write(encoder, 0x61,
i2c_smbus_write_byte_data(client, 0x61,
(encoder->
reg[0x61] & 0xf7) | 0x00);
/* SW: a slight sync problem... */
saa7185_write(encoder, 0x6e, 0x00);
i2c_smbus_write_byte_data(client, 0x6e, 0x00);
break;
default:
......@@ -364,7 +337,7 @@ static int saa7185_command(struct i2c_device *device, unsigned int cmd,
int *iarg = arg;
encoder->enable = !!*iarg;
saa7185_write(encoder, 0x61,
i2c_smbus_write_byte_data(client, 0x61,
(encoder->
reg[0x61] & 0xbf) | (encoder->
enable ? 0x00 :
......@@ -382,23 +355,28 @@ static int saa7185_command(struct i2c_device *device, unsigned int cmd,
/* ----------------------------------------------------------------------- */
static struct i2c_driver i2c_driver_saa7185 = {
"saa7185", /* name */
I2C_DRIVERID_VIDEOENCODER, /* ID */
I2C_SAA7185, I2C_SAA7185 + 1,
.name = "saa7185", /* name */
.id = I2C_DRIVERID_SAA7185B, /* ID */
.flags = I2C_DF_NOTIFY,
.attach_adapter = saa7185_probe,
.detach_client = saa7185_detach,
.command = saa7185_command
};
saa7185_attach,
saa7185_detach,
saa7185_command
static struct i2c_client client_template = {
.name = "saa7185_client",
.id = -1,
.driver = &i2c_driver_saa7185
};
static int saa7185_init(void)
{
return i2c_register_driver(&i2c_driver_saa7185);
return i2c_add_driver(&i2c_driver_saa7185);
}
static void saa7185_exit(void)
{
i2c_unregister_driver(&i2c_driver_saa7185);
i2c_del_driver(&i2c_driver_saa7185);
}
module_init(saa7185_init);
......
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