From: Jean Delvare <khali@linux-fr.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>,
Linux Media Mailing List <linux-media@vger.kernel.org>,
Old Video ML <video4linux-list@redhat.com>,
Douglas Landgraf <dougsland@gmail.com>
Subject: Re: Conversion of vino driver for SGI to not use the legacy decoder API
Date: Fri, 27 Feb 2009 14:59:19 +0100 [thread overview]
Message-ID: <20090227145919.19e298b1@hyperion.delvare> (raw)
In-Reply-To: <200902271312.10467.hverkuil@xs4all.nl>
Hi Hans,
On Fri, 27 Feb 2009 13:12:10 +0100, Hans Verkuil wrote:
> Jean, if you are interested in doing this, then use my v4l-dvb-vino2 tree as
> the starting point. It would be nice to get it all done in one go.
Here you go. The patch below adds the i2c-algo-sgi code to vino. Then
we can delete i2c-algo-sgi altogether, but as this driver isn't part of
the v4l-dvb tree, this has to go through another route (likely my i2c
tree.)
==========
Merge i2c-algo-sgi into its only user, vino. This is a very simple
copy-and-paste approach, although a number of further cleanups are
possible.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
---
Note: totally untested!
linux/drivers/media/video/Kconfig | 1
linux/drivers/media/video/vino.c | 169 ++++++++++++++++++++++++++++++++++---
2 files changed, 156 insertions(+), 14 deletions(-)
--- v4l-dvb-vino2.orig/linux/drivers/media/video/Kconfig 2009-02-27 13:21:39.000000000 +0100
+++ v4l-dvb-vino2/linux/drivers/media/video/Kconfig 2009-02-27 13:46:55.000000000 +0100
@@ -582,7 +582,6 @@ config VIDEO_SAA5249
config VIDEO_VINO
tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
- select I2C_ALGO_SGI
select VIDEO_SAA7191 if VIDEO_HELPER_CHIPS_AUTO
help
Say Y here to build in support for the Vino video input system found
--- v4l-dvb-vino2.orig/linux/drivers/media/video/vino.c 2009-02-27 13:21:40.000000000 +0100
+++ v4l-dvb-vino2/linux/drivers/media/video/vino.c 2009-02-27 14:56:52.000000000 +0100
@@ -33,7 +33,6 @@
#include <linux/kmod.h>
#include <linux/i2c.h>
-#include <linux/i2c-algo-sgi.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
@@ -141,6 +140,20 @@ MODULE_LICENSE("GPL");
#define VINO_DATA_NORM_COUNT 4
+/* I2C controller flags */
+#define SGI_I2C_FORCE_IDLE (0 << 0)
+#define SGI_I2C_NOT_IDLE (1 << 0)
+#define SGI_I2C_WRITE (0 << 1)
+#define SGI_I2C_READ (1 << 1)
+#define SGI_I2C_RELEASE_BUS (0 << 2)
+#define SGI_I2C_HOLD_BUS (1 << 2)
+#define SGI_I2C_XFER_DONE (0 << 4)
+#define SGI_I2C_XFER_BUSY (1 << 4)
+#define SGI_I2C_ACK (0 << 5)
+#define SGI_I2C_NACK (1 << 5)
+#define SGI_I2C_BUS_OK (0 << 7)
+#define SGI_I2C_BUS_ERR (1 << 7)
+
/* Internal data structure definitions */
struct vino_input {
@@ -640,6 +653,17 @@ struct v4l2_queryctrl vino_saa7191_v4l2_
/* VINO I2C bus functions */
+struct i2c_algo_sgi_data {
+ void *data; /* private data for lowlevel routines */
+ unsigned (*getctrl)(void *data);
+ void (*setctrl)(void *data, unsigned val);
+ unsigned (*rdata)(void *data);
+ void (*wdata)(void *data, unsigned val);
+
+ int xfer_timeout;
+ int ack_timeout;
+};
+
unsigned i2c_vino_getctrl(void *data)
{
return vino->i2c_control;
@@ -670,6 +694,134 @@ static struct i2c_algo_sgi_data i2c_sgi_
.ack_timeout = 1000,
};
+static int wait_xfer_done(struct i2c_algo_sgi_data *adap)
+{
+ int i;
+
+ for (i = 0; i < adap->xfer_timeout; i++) {
+ if ((adap->getctrl(adap->data) & SGI_I2C_XFER_BUSY) == 0)
+ return 0;
+ udelay(1);
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int wait_ack(struct i2c_algo_sgi_data *adap)
+{
+ int i;
+
+ if (wait_xfer_done(adap))
+ return -ETIMEDOUT;
+ for (i = 0; i < adap->ack_timeout; i++) {
+ if ((adap->getctrl(adap->data) & SGI_I2C_NACK) == 0)
+ return 0;
+ udelay(1);
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int force_idle(struct i2c_algo_sgi_data *adap)
+{
+ int i;
+
+ adap->setctrl(adap->data, SGI_I2C_FORCE_IDLE);
+ for (i = 0; i < adap->xfer_timeout; i++) {
+ if ((adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE) == 0)
+ goto out;
+ udelay(1);
+ }
+ return -ETIMEDOUT;
+out:
+ if (adap->getctrl(adap->data) & SGI_I2C_BUS_ERR)
+ return -EIO;
+ return 0;
+}
+
+static int do_address(struct i2c_algo_sgi_data *adap, unsigned int addr,
+ int rd)
+{
+ if (rd)
+ adap->setctrl(adap->data, SGI_I2C_NOT_IDLE);
+ /* Check if bus is idle, eventually force it to do so */
+ if (adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE)
+ if (force_idle(adap))
+ return -EIO;
+ /* Write out the i2c chip address and specify operation */
+ adap->setctrl(adap->data,
+ SGI_I2C_HOLD_BUS | SGI_I2C_WRITE | SGI_I2C_NOT_IDLE);
+ if (rd)
+ addr |= 1;
+ adap->wdata(adap->data, addr);
+ if (wait_ack(adap))
+ return -EIO;
+ return 0;
+}
+
+static int i2c_read(struct i2c_algo_sgi_data *adap, unsigned char *buf,
+ unsigned int len)
+{
+ int i;
+
+ adap->setctrl(adap->data,
+ SGI_I2C_HOLD_BUS | SGI_I2C_READ | SGI_I2C_NOT_IDLE);
+ for (i = 0; i < len; i++) {
+ if (wait_xfer_done(adap))
+ return -EIO;
+ buf[i] = adap->rdata(adap->data);
+ }
+ adap->setctrl(adap->data, SGI_I2C_RELEASE_BUS | SGI_I2C_FORCE_IDLE);
+
+ return 0;
+
+}
+
+static int i2c_write(struct i2c_algo_sgi_data *adap, unsigned char *buf,
+ unsigned int len)
+{
+ int i;
+
+ /* We are already in write state */
+ for (i = 0; i < len; i++) {
+ adap->wdata(adap->data, buf[i]);
+ if (wait_ack(adap))
+ return -EIO;
+ }
+ return 0;
+}
+
+static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
+ int num)
+{
+ struct i2c_algo_sgi_data *adap = i2c_adap->algo_data;
+ struct i2c_msg *p;
+ int i, err = 0;
+
+ for (i = 0; !err && i < num; i++) {
+ p = &msgs[i];
+ err = do_address(adap, p->addr, p->flags & I2C_M_RD);
+ if (err || !p->len)
+ continue;
+ if (p->flags & I2C_M_RD)
+ err = i2c_read(adap, p->buf, p->len);
+ else
+ err = i2c_write(adap, p->buf, p->len);
+ }
+
+ return (err < 0) ? err : i;
+}
+
+static u32 sgi_func(struct i2c_adapter *adap)
+{
+ return I2C_FUNC_SMBUS_EMUL;
+}
+
+static const struct i2c_algorithm sgi_algo = {
+ .master_xfer = sgi_xfer,
+ .functionality = sgi_func,
+};
+
/*
* There are two possible clients on VINO I2C bus, so we limit usage only
* to them.
@@ -727,21 +879,12 @@ static struct i2c_adapter vino_i2c_adapt
{
.name = "VINO I2C bus",
.id = I2C_HW_SGI_VINO,
+ .algo = &sgi_algo,
.algo_data = &i2c_sgi_vino_data,
.client_register = &i2c_vino_client_reg,
.client_unregister = &i2c_vino_client_unreg,
};
-static int vino_i2c_add_bus(void)
-{
- return i2c_sgi_add_bus(&vino_i2c_adapter);
-}
-
-static int vino_i2c_del_bus(void)
-{
- return i2c_del_adapter(&vino_i2c_adapter);
-}
-
static int i2c_camera_command(unsigned int cmd, void *arg)
{
return vino_drvdata->camera.driver->
@@ -4079,7 +4222,7 @@ static void vino_module_cleanup(int stag
video_unregister_device(vino_drvdata->a.vdev);
vino_drvdata->a.vdev = NULL;
case 9:
- vino_i2c_del_bus();
+ i2c_del_adapter(&vino_i2c_adapter);
case 8:
free_irq(SGI_VINO_IRQ, NULL);
case 7:
@@ -4301,7 +4444,7 @@ static int __init vino_module_init(void)
}
vino_init_stage++;
- ret = vino_i2c_add_bus();
+ ret = i2c_add_adapter(&vino_i2c_adapter);
if (ret) {
printk(KERN_ERR "VINO I2C bus registration failed\n");
vino_module_cleanup(vino_init_stage);
--
Jean Delvare
next prev parent reply other threads:[~2009-02-27 13:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-27 0:47 Conversion of vino driver for SGI to not use the legacy decoder API Mauro Carvalho Chehab
2009-02-27 7:19 ` Hans Verkuil
2009-02-27 9:09 ` Jean Delvare
2009-02-27 11:22 ` Mauro Carvalho Chehab
2009-02-27 11:53 ` Hans Verkuil
2009-02-27 12:12 ` Hans Verkuil
2009-02-27 13:59 ` Jean Delvare [this message]
2009-02-27 13:50 ` Douglas Schilling Landgraf
2009-02-27 15:37 ` Mauro Carvalho Chehab
2009-02-27 16:33 ` Douglas Schilling Landgraf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090227145919.19e298b1@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=dougsland@gmail.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=video4linux-list@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox