/* All zero = no test mode */
-#define TEA5761_TESTREG_TRIGFR 0x08
-
/* MANID - Read: bytes 12 and 13 */
/* First byte - should be 0x10 */
if (params->mode == T_STANDBY) {
tuner_dbg("TEA5761 set to standby mode\n");
- buffer[4] |= TEA5761_TNCTRL_MU;
+ buffer[5] |= TEA5761_TNCTRL_MU;
} else {
- buffer[3] |= TEA5761_TNCTRL_PUPD_0;
+ buffer[4] |= TEA5761_TNCTRL_PUPD_0;
}
- buffer[5] = TEA5761_TESTREG_TRIGFR;
if (params->audmode == V4L2_TUNER_MODE_MONO) {
tuner_dbg("TEA5761 set to mono\n");
- buffer[4] |= TEA5761_TNCTRL_MST;
+ buffer[5] |= TEA5761_TNCTRL_MST;
} else {
tuner_dbg("TEA5761 set to stereo\n");
}
- div = (frq * 125 / 2 - 225000) >> 13;
+ div = (1000 * (frq * 4 / 16 + 700 + 225) ) >> 15;
buffer[1] = (div >> 8) & 0x3f;
buffer[2] = div & 0xff;
return 0;
}
-static int tea5761_init(struct dvb_frontend *fe)
-{
- struct tea5761_priv *priv = fe->tuner_priv;
- unsigned char buffer[] = {0, 0, 0, 0, 0, 0, 0 };
- int rc;
-
- tuner_dbg("Power up radio\n");
-
- buffer[3] = TEA5761_TNCTRL_PUPD_0;
-
- if (debug)
- tea5761_status_dump(buffer);
-
- rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, ARRAY_SIZE(buffer));
- if (rc != ARRAY_SIZE(buffer))
- tuner_warn("i2c i/o error: rc == %d (should be %d)\n", rc,
- ARRAY_SIZE(buffer));
-
- return 0;
-}
-
-static int tea5761_sleep(struct dvb_frontend *fe)
-{
- struct tea5761_priv *priv = fe->tuner_priv;
- unsigned char buffer[] = {0, 0, 0, 0, 0, 0, 0 };
- int rc;
-
- tuner_dbg("Power down radio\n");
-
- buffer[3] &= ~TEA5761_TNCTRL_PUPD_0;
-
- if (debug)
- tea5761_status_dump(buffer);
-
- rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, ARRAY_SIZE(buffer));
- if (rc != ARRAY_SIZE(buffer))
- tuner_warn("i2c i/o error: rc == %d (should be %d)\n", rc,
- ARRAY_SIZE(buffer));
-
- return 0;
-}
-
static int tea5761_read_status(struct dvb_frontend *fe, char *buffer)
{
struct tea5761_priv *priv = fe->tuner_priv;
.get_frequency = tea5761_get_frequency,
.get_status = tea5761_get_status,
.get_rf_strength = tea5761_get_rf_strength,
- .init = tea5761_init,
- .sleep = tea5761_sleep,
};
struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
help
Enter the I/O port of your Zoltrix radio card.
-config RADIO_TEA5761
- tristate "Philips Semiconductors TEA5761 I2C FM Radio"
- help
- Choose Y here if you have one of these AM/FM radio cards.
-
- In order to control your radio card, you will need to use programs
- that are compatible with the Video For Linux 2 API. Information on
- this API and pointers to "v4l" programs may be found at
- <file:Documentation/video4linux/API.html>.
-
- To compile this driver as a module, choose M here: the
- module will be called radio-tea5761.
-
config USB_DSBR
tristate "D-Link/GemTek USB FM radio support"
depends on USB && VIDEO_V4L2
obj-$(CONFIG_RADIO_GEMTEK_PCI) += radio-gemtek-pci.o
obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o
-obj-$(CONFIG_RADIO_TEA5761) += radio-tea5761.o
obj-$(CONFIG_USB_DSBR) += dsbr100.o
obj-$(CONFIG_USB_SI470X) += radio-si470x.o
obj-$(CONFIG_USB_MR800) += radio-mr800.o
+++ /dev/null
-/*
- * drivers/media/radio/radio-tea5761.c
- *
- * Copyright (C) 2005-2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <linux/module.h>
-#include <linux/version.h>
-#include <linux/init.h>
-#include <linux/i2c.h>
-#include <linux/delay.h>
-#include <media/v4l2-common.h>
-#include <media/v4l2-ioctl.h>
-
-#define DRIVER_NAME "tea5761"
-
-#define TEA5761_VERSION KERNEL_VERSION(0, 0, 1)
-
-#define TEA5761_I2C_ADDR 0x10
-
-#define TEA5761_MANID 0x002b
-#define TEA5761_CHIPID 0x5761
-
-#define TEA5761_INTREG_BLMSK 0x0001
-#define TEA5761_INTREG_FRRMSK 0x0002
-#define TEA5761_INTREG_LEVMSK 0x0008
-#define TEA5761_INTREG_IFMSK 0x0010
-#define TEA5761_INTREG_BLMFLAG 0x0100
-#define TEA5761_INTREG_FRRFLAG 0x0200
-#define TEA5761_INTREG_LEVFLAG 0x0800
-#define TEA5761_INTREG_IFFLAG 0x1000
-
-#define TEA5761_FRQSET_SUD 0x8000
-#define TEA5761_FRQSET_SM 0x4000
-
-#define TEA5761_TNCTRL_PUPD0 0x4000
-#define TEA5761_TNCTRL_BLIM 0x2000
-#define TEA5761_TNCTRL_SWPM 0x1000
-#define TEA5761_TNCTRL_IFCTC 0x0800
-#define TEA5761_TNCTRL_AFM 0x0400
-#define TEA5761_TNCTRL_SMUTE 0x0200
-#define TEA5761_TNCTRL_SNC 0x0100
-#define TEA5761_TNCTRL_MU 0x0080
-#define TEA5761_TNCTRL_SSL1 0x0040
-#define TEA5761_TNCTRL_SSL0 0x0020
-#define TEA5761_TNCTRL_HLSI 0x0010
-#define TEA5761_TNCTRL_MST 0x0008
-#define TEA5761_TNCTRL_SWP 0x0004
-#define TEA5761_TNCTRL_DTC 0x0002
-#define TEA5761_TNCTRL_AHLSI 0x0001
-
-#define TEA5761_TUNCHK_LEVEL(x) (((x) & 0x00F0) >> 4)
-#define TEA5761_TUNCHK_IFCNT(x) (((x) & 0xFE00) >> 9)
-#define TEA5761_TUNCHK_TUNTO 0x0100
-#define TEA5761_TUNCHK_LD 0x0008
-#define TEA5761_TUNCHK_STEREO 0x0004
-
-#define TEA5761_TESTREG_TRIGFR 0x0800
-
-#define TEA5761_FREQ_LOW 87500
-#define TEA5761_FREQ_HIGH 108000
-
-struct tea5761_regs {
- u16 intreg;
- u16 frqset;
- u16 tnctrl;
- u16 frqchk;
- u16 tunchk;
- u16 testreg;
- u16 manid;
- u16 chipid;
-} __attribute__ ((packed));
-
-struct tea5761_write_regs {
- u8 intreg;
- u16 frqset;
- u16 tnctrl;
- u16 testreg;
-} __attribute__ ((packed));
-
-struct tea5761_device {
- struct video_device *video_dev;
- struct i2c_client *i2c_dev;
- struct tea5761_regs regs;
- struct mutex mutex;
- int users;
-};
-
-static struct tea5761_device tea5761;
-
-static struct i2c_driver tea5761_driver;
-static int radio_nr = -1;
-
-static int tea5761_read_regs(struct tea5761_device *tea)
-{
- int rc, i;
- u16 *p = (u16 *) &tea->regs;
- struct i2c_client *client = tea->i2c_dev;
-
- rc = i2c_master_recv(client, (void*) &tea->regs, sizeof(tea->regs));
- for (i = 0; i < 8; i++) {
- p[i] = __be16_to_cpu(p[i]);
- }
-
- dev_dbg(&client->dev,
- "chip state: %04x %04x %04x %04x %04x %04x %04x %04x\n",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-
- if (rc < 0)
- dev_err(&client->dev, "read\n");
-
- return rc;
-}
-
-static void tea5761_write_regs(struct tea5761_device *tea)
-{
- struct tea5761_write_regs wr;
- struct tea5761_regs *r = &tea->regs;
- struct i2c_client *client = tea->i2c_dev;
- u8 *p = (u8 *) r;
-
- wr.intreg = r->intreg & 0xff;
- wr.frqset = __cpu_to_be16(r->frqset);
- wr.tnctrl = __cpu_to_be16(r->tnctrl);
- wr.testreg = __cpu_to_be16(r->testreg);
-
- dev_dbg(&client->dev,
- "writing state: %02x %02x %02x %02x %02x %02x %02x\n",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
- if (i2c_master_send(client, (void *) &wr, sizeof(wr)) < 0)
- dev_err(&client->dev, "write\n");
-}
-
-static void tea5761_power_up(struct tea5761_device *tea)
-{
- struct tea5761_regs *r = &tea->regs;
-
- if (!(r->tnctrl & TEA5761_TNCTRL_PUPD0)) {
- r->tnctrl &= ~(TEA5761_TNCTRL_AFM | TEA5761_TNCTRL_MU |
- TEA5761_TNCTRL_HLSI);
- r->testreg |= TEA5761_TESTREG_TRIGFR;
- r->tnctrl |= TEA5761_TNCTRL_PUPD0;
- return tea5761_write_regs(tea);
- }
-}
-
-static void tea5761_power_down(struct tea5761_device *tea)
-{
- struct tea5761_regs *r = &tea->regs;
-
- if (r->tnctrl & TEA5761_TNCTRL_PUPD0) {
- r->tnctrl &= ~TEA5761_TNCTRL_PUPD0;
- return tea5761_write_regs(tea);
- }
-}
-
-static void tea5761_set_freq(struct tea5761_device *tea, int freq)
-{
- struct tea5761_regs *r = &tea->regs;
-
- if (r->tnctrl & TEA5761_TNCTRL_HLSI)
- r->frqset = (freq + 225000) / 8192;
- else
- r->frqset = (freq - 225000) / 8192;
-}
-
-static int tea5761_get_freq(struct tea5761_device *tea)
-{
- struct tea5761_regs *r = &tea->regs;
-
- if (r->tnctrl & TEA5761_TNCTRL_HLSI)
- return (r->frqchk * 8192) - 225000;
- else
- return (r->frqchk * 8192) + 225000;
-}
-
-static void tea5761_tune(struct tea5761_device *tea, int freq)
-{
- tea5761_set_freq(tea, freq);
- tea5761_write_regs(tea);
-}
-
-static void tea5761_set_audout_mode(struct tea5761_device *tea, int audmode)
-{
- struct tea5761_regs *r = &tea->regs;
- int tnctrl = r->tnctrl;
-
- if (audmode == V4L2_TUNER_MODE_MONO)
- r->tnctrl |= TEA5761_TNCTRL_MST;
- else
- r->tnctrl &= ~TEA5761_TNCTRL_MST;
- if (tnctrl != r->tnctrl)
- tea5761_write_regs(tea);
-}
-
-static int tea5761_get_audout_mode(struct tea5761_device *tea)
-{
- struct tea5761_regs *r = &tea->regs;
-
- if (r->tnctrl & TEA5761_TNCTRL_MST)
- return V4L2_TUNER_MODE_MONO;
- else
- return V4L2_TUNER_MODE_STEREO;
-}
-
-static void tea5761_mute(struct tea5761_device *tea, int on)
-{
- struct tea5761_regs *r = &tea->regs;
- int tnctrl = r->tnctrl;
-
- if (on)
- r->tnctrl |= TEA5761_TNCTRL_MU;
- else
- r->tnctrl &= ~TEA5761_TNCTRL_MU;
- if (tnctrl != r->tnctrl)
- tea5761_write_regs(tea);
-}
-
-static int tea5761_is_muted(struct tea5761_device *tea)
-{
- return tea->regs.tnctrl & TEA5761_TNCTRL_MU;
-}
-
-static int tea5761_do_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, void *arg)
-{
- struct tea5761_device *tea = file->private_data;
- struct video_device *dev = tea->video_dev;
- struct i2c_client *client = tea->i2c_dev;
- struct tea5761_regs *r = &tea->regs;
-
- union {
- struct v4l2_capability c;
- struct v4l2_tuner t;
- struct v4l2_frequency f;
- struct v4l2_queryctrl qc;
- struct v4l2_control ct;
- } *u = arg;
-
- tea5761_read_regs(tea);
-
- switch (cmd) {
- case VIDIOC_QUERYCAP:
- dev_dbg(&client->dev, "VIDIOC_QUERYCAP\n");
- memset(&u->c, 0, sizeof(u->c));
- strlcpy(u->c.driver,
- dev->parent->driver->name,
- sizeof(u->c.driver));
- strlcpy(u->c.card, dev->name, sizeof(u->c.card));
- snprintf(u->c.bus_info, sizeof(u->c.bus_info), "I2C:%s",
- dev->parent->bus_id);
- u->c.version = TEA5761_VERSION;
- u->c.capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
- break;
-
- case VIDIOC_G_TUNER:
- /* Only one tuner chip */
- dev_dbg(&client->dev, "VIDIOC_G_TUNER\n");
- if (u->t.index != 0)
- return -EINVAL;
-
- memset(&u->t, 0, sizeof(u->t));
- u->t.type = V4L2_TUNER_RADIO;
- strlcpy(u->t.name, "FM", sizeof(u->t.name));
- /* Freq in 62.5Hz units */
- u->t.rangelow = TEA5761_FREQ_LOW * 16;
- u->t.rangehigh = TEA5761_FREQ_HIGH * 16;
- u->t.capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
- if (r->tunchk & TEA5761_TUNCHK_STEREO)
- u->t.rxsubchans = V4L2_TUNER_SUB_STEREO;
- u->t.audmode = tea5761_get_audout_mode(tea);
- u->t.signal = TEA5761_TUNCHK_LEVEL(r->tunchk) * 0xffff / 0xf;
- u->t.afc = TEA5761_TUNCHK_IFCNT(r->tunchk);
- break;
-
- case VIDIOC_S_TUNER:
- /* Only tuner nro 0 can be selected. */
- dev_dbg(&client->dev, "VIDIOC_S_TUNER\n");
- if (u->t.index != 0)
- return -EINVAL;
- tea5761_set_audout_mode(tea, u->t.audmode);
- break;
-
- case VIDIOC_G_FREQUENCY:
- dev_dbg(&client->dev, "VIDIOC_G_FREQUENCY\n");
- memset(&u->f, 0, sizeof(u->f));
- u->f.type = V4L2_TUNER_RADIO;
- if (r->tnctrl & TEA5761_TNCTRL_PUPD0)
- u->f.frequency = (tea5761_get_freq(tea) * 2) / 125;
- else
- u->f.frequency = 0;
- break;
-
- case VIDIOC_S_FREQUENCY:
- dev_dbg(&client->dev, "VIDIOC_S_FREQUENCY %u\n",
- u->f.frequency);
- if (u->f.tuner != 0)
- return -EINVAL;
- if (u->f.frequency == 0) {
- /* We special case this as a power down
- * control. */
- tea5761_power_down(tea);
- break;
- }
- if (u->f.frequency < 16 * TEA5761_FREQ_LOW)
- return -EINVAL;
- if (u->f.frequency > 16 * TEA5761_FREQ_HIGH)
- return -EINVAL;
-
- tea5761_power_up(tea);
- tea5761_tune(tea, (u->f.frequency * 125) / 2);
- break;
-
- case VIDIOC_QUERYCTRL:
- dev_dbg(&client->dev, "VIDIOC_QUERYCTRL %d\n", u->qc.id);
- if (u->qc.id != V4L2_CID_AUDIO_MUTE)
- return -EINVAL;
- strlcpy(u->qc.name, "Mute", sizeof(u->qc.name));
- u->qc.minimum = 0;
- u->qc.maximum = 1;
- u->qc.step = 1;
- u->qc.default_value = 0;
- u->qc.type = V4L2_CTRL_TYPE_BOOLEAN;
- break;
-
- case VIDIOC_G_CTRL:
- dev_dbg(&client->dev, "VIDIOC_G_CTRL %d\n", u->ct.id);
- if (u->ct.id != V4L2_CID_AUDIO_MUTE)
- return -EINVAL;
- if (r->tnctrl & TEA5761_TNCTRL_PUPD0)
- u->ct.value = tea5761_is_muted(tea) ? 1 : 0;
- else
- u->ct.value = 0;
- break;
-
- case VIDIOC_S_CTRL:
- dev_dbg(&client->dev, "VIDIOC_S_CTRL %d\n", u->ct.id);
- if (u->ct.id != V4L2_CID_AUDIO_MUTE)
- return -EINVAL;
- tea5761_mute(tea, u->ct.value);
- break;
-
- default:
- return -ENOIOCTLCMD;
- }
-
- return 0;
-}
-
-static int tea5761_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
-{
- return video_usercopy(inode, file, cmd, arg, tea5761_do_ioctl);
-}
-
-static int tea5761_open(struct inode *inode, struct file *file)
-{
- int minor = iminor(file->f_dentry->d_inode);
- /* Currently we support only one device */
- struct tea5761_device *tea = &tea5761;
-
- if (tea->video_dev->minor != minor)
- return -ENODEV;
-
- mutex_lock(&tea->mutex);
- /* Only exclusive access */
- if (tea->users) {
- mutex_unlock(&tea->mutex);
- return -EBUSY;
- }
- tea->users++;
- mutex_unlock(&tea->mutex);
-
- file->private_data = tea;
- return 0;
-}
-
-static int tea5761_release(struct inode *inode, struct file *file)
-{
- struct tea5761_device *tea = file->private_data;
-
- mutex_lock(&tea->mutex);
- tea->users--;
- mutex_unlock(&tea->mutex);
-
- return 0;
-}
-
-static struct file_operations tea5761_fops = {
- .owner = THIS_MODULE,
- .open = tea5761_open,
- .release = tea5761_release,
- .ioctl = tea5761_ioctl,
- .llseek = no_llseek,
-};
-
-static struct video_device tea5761_video_device = {
- .name = "TEA5761 FM-Radio",
- .vfl_type = VID_TYPE_TUNER,
- .fops = &tea5761_fops,
- .release = video_device_release
-};
-
-static int tea5761_i2c_driver_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
-{
- struct video_device *video_dev;
- int err = 0;
- struct tea5761_device *tea = &tea5761;
-
- mutex_init(&tea->mutex);
-
- tea->i2c_dev = client;
-
- /* V4L initialization */
- video_dev = video_device_alloc();
- if (video_dev == NULL) {
- dev_err(&client->dev, "couldn't allocate memory\n");
- err = -ENOMEM;
- goto exit;
- }
- tea->video_dev = video_dev;
-
- *video_dev = tea5761_video_device;
- video_dev->parent = &client->dev;
- i2c_set_clientdata(client, video_dev);
-
- /* initialize and power off the chip */
- tea5761_read_regs(tea);
- tea5761_set_audout_mode(tea, V4L2_TUNER_MODE_STEREO);
- tea5761_mute(tea, 0);
- tea5761_power_down(tea);
-
- tea5761.video_dev = video_dev;
- tea5761.i2c_dev = client;
-
- err = video_register_device(video_dev, VFL_TYPE_RADIO, radio_nr);
- if (err) {
- dev_err(&client->dev, "couldn't register video device\n");
- goto err_video_alloc;
- }
-
- dev_info(&client->dev, "tea5761 (version %d) detected\n",
- (tea->regs.manid >> 12) & 0xf);
-
- return 0;
-
-err_video_alloc:
- video_device_release(video_dev);
-exit:
- kfree(client);
- return err;
-}
-
-static int tea5761_i2c_driver_remove(struct i2c_client *client)
-{
- struct video_device *vd = i2c_get_clientdata(client);
-
- video_unregister_device(vd);
-
- return 0;
-}
-
-static const struct i2c_device_id tea5761_id[] = {
- { DRIVER_NAME, 0 },
- { },
-};
-MODULE_DEVICE_TABLE(i2c, tea5761_id);
-
-static struct i2c_driver tea5761_driver = {
- .driver = {
- .name = DRIVER_NAME,
- },
- .probe = tea5761_i2c_driver_probe,
- .remove = __devexit_p(tea5761_i2c_driver_remove),
- .id_table = tea5761_id,
-};
-
-static int __init tea5761_init(void)
-{
- int res;
-
- if ((res = i2c_add_driver(&tea5761_driver))) {
- printk(KERN_ERR DRIVER_NAME ": driver registration failed\n");
- return res;
- }
-
- return 0;
-}
-
-static void __exit tea5761_exit(void)
-{
- i2c_del_driver(&tea5761_driver);
-}
-
-MODULE_AUTHOR("Timo Teräs");
-MODULE_DESCRIPTION("I2C interface for TEA5761.");
-MODULE_LICENSE("GPL");
-
-module_param(radio_nr, int, 0);
-MODULE_PARM_DESC(nr_radio, "video4linux device number to use");
-
-module_init(tea5761_init)
-module_exit(tea5761_exit)
obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
-obj-$(CONFIG_VIDEO_OMAP_CAMERA) += omap/
obj-$(CONFIG_VIDEO_CX25840) += cx25840/
obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
-obj-$(CONFIG_VIDEO_OMAP2) += omap24xxcam.o omap24xxcam-dma.o
obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
-obj-$(CONFIG_VIDEO_OV9640) += ov9640.o
obj-$(CONFIG_USB_DABUSB) += dabusb.o
obj-$(CONFIG_USB_OV511) += ov511.o
+++ /dev/null
-config VIDEO_OMAP_CAMERA
- tristate "OMAP Camera support (EXPERIMENTAL)"
- select VIDEOBUF_GEN
- select VIDEOBUF_DMA_SG
- depends on VIDEO_DEV && (ARCH_OMAP16XX || ARCH_OMAP24XX)
- help
- V4L2 camera driver support for OMAP1/2 based boards.
+++ /dev/null
-# Makefile for OMAP1/2 camera driver
-
-obj-$(CONFIG_VIDEO_OMAP_CAMERA) += omapcamera.o
-
-objs-y$(CONFIG_ARCH_OMAP16XX) += omap16xxcam.o camera_core.o
-
-omapcamera-objs := $(objs-yy)
-
-EXTRA_CFLAGS = -I$(src)/..
+++ /dev/null
-/*
- * drivers/media/video/omap/camera_core.c
- *
- * Copyright (C) 2004 Texas Instruments, Inc.
- *
- * Video-for-Linux (Version 2) camera capture driver for
- * the OMAP H2 and H3 camera controller.
- *
- * Adapted from omap24xx driver written by Andy Lowe (source@mvista.com)
- * Copyright (C) 2003-2004 MontaVista Software, Inc.
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * History:
- * 27/03/05 Vladimir Barinov - Added support for power management
- */
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/version.h>
-#include <linux/dma-mapping.h>
-#include <linux/fb.h>
-
-#include <media/v4l2-common.h>
-
-#include <asm/io.h>
-
-#include "camera_hw_if.h"
-#include "camera_core.h"
-
-#define OMAP1CAM_VERSION KERNEL_VERSION(0, 0, 0)
-
-static struct camera_device *camera_dev;
-static void camera_core_sgdma_process(struct camera_device *cam);
-
-/* Module parameters */
-static int video_nr = -1; /* Video device minor (-1 ==> auto assign) */
-
-/* Maximum amount of memory to use for capture buffers.
- * Default is 4800KB, enough to double-buffer SXGA.
- */
-static int capture_mem = 1280 * 960 * 2 * 2;
-
-/* Size of video overlay framebuffer. This determines the maximum image size
- * that can be previewed. Default is 600KB, enough for sxga.
- */
-static int overlay_mem = 640 * 480 * 2;
-
-/* Enable the external sensor interface. Try to negotiate interface
- * parameters with the sensor and start using the new ones. The calls
- * to sensor_if_enable and sensor_if_disable do not need to be balanced.
- */
-static int camera_sensor_if_enable(struct camera_device *cam)
-{
- int rval;
- struct v4l2_ifparm p;
-
- rval = vidioc_int_g_ifparm(cam->sdev, &p);
- if (rval) {
- dev_err(cam->dev, "vidioc_int_g_ifparm failed with %d\n", rval);
- return rval;
- }
-
- cam->if_type = p.if_type;
-
- switch (p.if_type) {
- case V4L2_IF_TYPE_BT656:
- cam->if_u.bt656.xclk =
- cam->cam_hardware->set_xclk(cam->if_u.bt656.xclk,
- cam->hardware_data);
- break;
- default:
- /* FIXME: how about other interfaces? */
- dev_err(cam->dev, "interface type %d not supported\n",
- p.if_type);
- return -EINVAL;
- }
-
- return 0;
-}
-
-static void camera_sensor_if_disable(const struct camera_device *cam)
-{
- switch (cam->if_type) {
- case V4L2_IF_TYPE_BT656:
- break;
- }
-}
-
-/* Initialize the sensor hardware. */
-static int camera_sensor_init(struct camera_device *cam)
-{
- int err = 0;
- struct v4l2_int_device *sdev = cam->sdev;
-
- /* Enable the xclk output. The sensor may (and does, in the case of
- * the OV9640) require an xclk input in order for its initialization
- * routine to work.
- */
-
- /* Choose an arbitrary xclk frequency */
- cam->if_u.bt656.xclk = 21000000;
-
- cam->if_u.bt656.xclk = cam->cam_hardware->set_xclk(cam->if_u.bt656.xclk,
- cam->hardware_data);
-
- err = camera_sensor_if_enable(cam);
- if (err) {
- dev_err(cam->dev, "sensor interface could not be enabled at "
- "initialization, %d\n", err);
- cam->sdev = NULL;
- goto out;
- }
-
- /* Power up sensor during sensor initialization */
- vidioc_int_s_power(sdev, 1);
-
- err = vidioc_int_dev_init(sdev);
- if (err) {
- dev_err(cam->dev, "cannot initialize sensor, error %d\n", err);
- /* Sensor initialization failed --- it's nonexistent to us! */
- cam->sdev = NULL;
- goto out;
- }
-
- dev_info(cam->dev, "sensor is %s\n", sdev->name);
-
-out:
- camera_sensor_if_disable(cam);
-
- vidioc_int_s_power(sdev, 0);
-
- return err;
-}
-
-static void camera_sensor_exit(struct camera_device *cam)
-{
- if (cam->sdev)
- vidioc_int_dev_exit(cam->sdev);
-}
-
-/* DMA completion routine for the scatter-gather DMA fragments.
- * This function is called when a scatter DMA fragment is completed
- */
-static void camera_core_callback_sgdma(void *arg1, void *arg2)
-{
- struct camera_device *cam = (struct camera_device *)arg1;
- int sgslot = (int)arg2;
-
- struct sgdma_state *sgdma;
-
- spin_lock(&cam->sg_lock);
- sgdma = cam->sgdma + sgslot;
- if (!sgdma->queued_sglist) {
- spin_unlock(&cam->sg_lock);
- dev_err(cam->dev, "SGDMA completed when none queued\n");
- return;
- }
- if (!--sgdma->queued_sglist) {
- /* Queue for this sglist is empty so check whether transfer
- * of the frame has been completed
- */
- if (sgdma->next_sglist == sgdma->sglen) {
- dma_callback_t callback = sgdma->callback;
- void *arg = sgdma->arg;
- /* All done with this sglist */
- cam->free_sgdma++;
- if (callback) {
- spin_unlock(&cam->sg_lock);
- (*callback) (cam, arg);
- camera_core_sgdma_process(cam);
- return;
- }
- }
- }
- spin_unlock(&cam->sg_lock);
- camera_core_sgdma_process(cam);
-
- return;
-}
-
-static void camera_core_sgdma_init(struct camera_device *cam)
-{
- int sg;
-
- /* Initialize the underlying camera DMA */
- cam->cam_hardware->init_dma(cam->hardware_data);
- spin_lock_init(&cam->sg_lock);
-
- cam->free_sgdma = NUM_SG_DMA;
- cam->next_sgdma = 0;
- for (sg = 0; sg < NUM_SG_DMA; sg++) {
- cam->sgdma[sg].sglen = 0;
- cam->sgdma[sg].next_sglist = 0;
- cam->sgdma[sg].queued_sglist = 0;
- cam->sgdma[sg].csr = 0;
- cam->sgdma[sg].callback = NULL;
- cam->sgdma[sg].arg = NULL;
- }
-}
-
-/* Process the scatter-gather DMA queue by starting queued transfers
- * This function is called to program the DMA to start the transfer of an image.
- */
-static void camera_core_sgdma_process(struct camera_device *cam)
-{
- unsigned long irqflags;
- int queued_sgdma, sgslot;
- struct sgdma_state *sgdma;
- const struct scatterlist *sglist;
-
- spin_lock_irqsave(&cam->sg_lock, irqflags);
- if (1 == cam->in_use) {
- spin_unlock_irqrestore(&cam->sg_lock, irqflags);
- return;
- }
- cam->in_use = 1;
- spin_unlock_irqrestore(&cam->sg_lock, irqflags);
-
- queued_sgdma = NUM_SG_DMA - cam->free_sgdma;
- sgslot = (cam->next_sgdma + cam->free_sgdma) % (NUM_SG_DMA);
- while (queued_sgdma > 0) {
- sgdma = cam->sgdma + sgslot;
- while (sgdma->next_sglist < sgdma->sglen) {
- sglist = sgdma->sglist + sgdma->next_sglist;
- if (cam->cam_hardware->
- start_dma(sgdma, camera_core_callback_sgdma,
- (void *)cam, (void *)sgslot,
- cam->hardware_data)) {
- /* DMA start failed */
- cam->in_use = 0;
- return;
- } else {
- /* DMA start successful */
- sgdma->next_sglist++;
- sgdma->queued_sglist++;
- }
- }
- queued_sgdma--;
- sgslot = (sgslot + 1) % (NUM_SG_DMA);
- }
-
- cam->in_use = 0;
-}
-
-/* Queue a scatter-gather DMA transfer from the camera to memory.
- * Returns zero if the transfer was successfully queued, or
- * non-zero if all of the scatter-gather slots are already in use.
- */
-static int camera_core_sgdma_queue(struct camera_device *cam,
- const struct scatterlist *sglist,
- int sglen, dma_callback_t callback,
- void *arg)
-{
- unsigned long irqflags;
- struct sgdma_state *sgdma;
-
- if ((sglen < 0) || ((sglen > 0) & !sglist))
- return -EINVAL;
-
- spin_lock_irqsave(&cam->sg_lock, irqflags);
-
- if (!cam->free_sgdma) {
- spin_unlock_irqrestore(&cam->sg_lock, irqflags);
- return -EBUSY;
- }
-
- sgdma = cam->sgdma + cam->next_sgdma;
-
- sgdma->sglist = sglist;
- sgdma->sglen = sglen;
- sgdma->next_sglist = 0;
- sgdma->queued_sglist = 0;
- sgdma->csr = 0;
- sgdma->callback = callback;
- sgdma->arg = arg;
-
- cam->next_sgdma = (cam->next_sgdma + 1) % (NUM_SG_DMA);
- cam->free_sgdma--;
-
- spin_unlock_irqrestore(&cam->sg_lock, irqflags);
-
- camera_core_sgdma_process(cam);
-
- return 0;
-}
-
-/* -------------------overlay routines ------------------------------
- * Callback routine for overlay DMA completion. We just start another DMA
- * transfer unless overlay has been turned off
- */
-static void camera_core_overlay_callback(void *arg1, void *arg)
-{
- struct camera_device *cam = (struct camera_device *)arg1;
- int err;
- unsigned long irqflags;
- int i, j;
- int count, index;
- unsigned char *fb_buf =
- phys_to_virt((unsigned long)camera_dev->fbuf.base);
-
- spin_lock_irqsave(&cam->overlay_lock, irqflags);
-
- if (!cam->previewing || cam->overlay_cnt == 0) {
- spin_unlock_irqrestore(&cam->overlay_lock, irqflags);
- return;
- }
-
- --cam->overlay_cnt;
- sg_dma_address(&cam->overlay_sglist) = cam->overlay_base_phys;
- sg_dma_len(&cam->overlay_sglist) = cam->pix.sizeimage;
-
- count = 0;
- j = ((cam->pix.width - 1) * cam->fbuf.fmt.bytesperline);
- for (i = 0; i < cam->pix.sizeimage; i += cam->pix.bytesperline) {
- for (index = 0; index < cam->pix.bytesperline; index++) {
- fb_buf[j] = *(((unsigned char *)cam->overlay_base) +
- i + index);
- index++;
- fb_buf[j + 1] =
- *(((unsigned char *)cam->overlay_base) + i + index);
- j = j - cam->fbuf.fmt.bytesperline;
- }
- count += 2;
- j = ((cam->pix.width - 1) * cam->fbuf.fmt.bytesperline) + count;
- }
-
- while (cam->overlay_cnt < 2) {
- err = camera_core_sgdma_queue(cam, &cam->overlay_sglist, 1,
- camera_core_overlay_callback,
- NULL);
- if (err)
- break;
- ++cam->overlay_cnt;
- }
-
- spin_unlock_irqrestore(&cam->overlay_lock, irqflags);
-
-}
-
-static void camera_core_start_overlay(struct camera_device *cam)
-{
- int err;
- unsigned long irqflags;
-
- if (!cam->previewing)
- return;
-
- spin_lock_irqsave(&cam->overlay_lock, irqflags);
-
- sg_dma_address(&cam->overlay_sglist) = cam->overlay_base_phys;
- sg_dma_len(&cam->overlay_sglist) = cam->pix.sizeimage;
- while (cam->overlay_cnt < 2) {
- err = camera_core_sgdma_queue(cam, &cam->overlay_sglist, 1,
- camera_core_overlay_callback,
- NULL);
- if (err)
- break;
- ++cam->overlay_cnt;
- }
-
- spin_unlock_irqrestore(&cam->overlay_lock, irqflags);
-}
-
-/* ------------------ videobuf_queue_ops --------------------------------
- * This routine is called from interrupt context when a scatter-gather DMA
- * transfer of a videobuf_buffer completes.
- */
-static void camera_core_vbq_complete(void *arg1, void *arg)
-{
- struct camera_device *cam = (struct camera_device *)arg1;
- struct videobuf_buffer *vb = (struct videobuf_buffer *)arg;
-
- spin_lock(&cam->vbq_lock);
-
- do_gettimeofday(&vb->ts);
- vb->field_count = cam->field_count;
- cam->field_count += 2;
- vb->state = STATE_DONE;
-
- wake_up(&vb->done);
-
- spin_unlock(&cam->vbq_lock);
-}
-
-static void camera_core_vbq_release(struct videobuf_queue *q,
- struct videobuf_buffer *vb)
-{
- struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
- videobuf_waiton(vb, 0, 0);
- videobuf_dma_unmap(q, dma);
- videobuf_dma_free(dma);
-
- vb->state = STATE_NEEDS_INIT;
-}
-
-/* Limit the number of available kernel image capture buffers based on the
- * number requested, the currently selected image size, and the maximum
- * amount of memory permitted for kernel capture buffers.
- */
-static int camera_core_vbq_setup(struct videobuf_queue *q, unsigned int *cnt,
- unsigned int *size)
-{
- struct camera_fh *fh = q->priv_data;
- struct camera_device *cam = fh->cam;
-
- if (*cnt <= 0)
- *cnt = VIDEO_MAX_FRAME; /* Supply a default number of buffers */
-
- if (*cnt > VIDEO_MAX_FRAME)
- *cnt = VIDEO_MAX_FRAME;
-
- spin_lock(&cam->img_lock);
- *size = cam->pix.sizeimage;
- spin_unlock(&cam->img_lock);
-
- while (*size * *cnt > capture_mem)
- (*cnt)--;
-
- return 0;
-}
-
-static int camera_core_vbq_prepare(struct videobuf_queue *q,
- struct videobuf_buffer *vb,
- enum v4l2_field field)
-{
- struct camera_fh *fh = q->priv_data;
- struct camera_device *cam = fh->cam;
- int err = 0;
-
- spin_lock(&cam->img_lock);
- if (cam->pix.sizeimage > vb->bsize) {
- spin_unlock(&cam->img_lock);
- return -EINVAL;
- }
- vb->size = cam->pix.sizeimage;
- vb->width = cam->pix.width;
- vb->height = cam->pix.height;
- vb->field = field;
- spin_unlock(&cam->img_lock);
-
- if (vb->state == STATE_NEEDS_INIT)
- err = videobuf_iolock(q, vb, NULL);
-
- if (!err)
- vb->state = STATE_PREPARED;
- else
- camera_core_vbq_release(q, vb);
-
- return err;
-}
-
-static void camera_core_vbq_queue(struct videobuf_queue *q,
- struct videobuf_buffer *vb)
-{
- struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
- struct camera_fh *fh = q->priv_data;
- struct camera_device *cam = fh->cam;
- enum videobuf_state state = vb->state;
- int err;
-
- vb->state = STATE_QUEUED;
- err = camera_core_sgdma_queue(cam, dma->sglist, dma->sglen,
- camera_core_vbq_complete, vb);
- if (err) {
- /* Oops. We're not supposed to get any errors here. The only
- * way we could get an error is if we ran out of scatter-gather
- * DMA slots, but we are supposed to have at least as many
- * scatter-gather DMA slots as video buffers so that can't
- * happen.
- */
- dev_dbg(cam->dev, "Failed to queue a video buffer for SGDMA\n");
- vb->state = state;
- }
-}
-
-/* IOCTL interface. */
-static int vidioc_querycap(struct file *file, void *fh,
- struct v4l2_capability *cap)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- strlcpy(cap->driver, CAM_NAME, sizeof(cap->driver));
- strlcpy(cap->card, cam->vfd->name, sizeof(cap->card));
- cap->version = OMAP1CAM_VERSION;
- cap->capabilities =
- V4L2_CAP_VIDEO_CAPTURE |
- V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
-
- return 0;
-}
-
-static int vidioc_enum_fmt_cap(struct file *file, void *fh,
- struct v4l2_fmtdesc *f)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- return vidioc_int_enum_fmt_cap(cam->sdev, f);
-}
-
-static int vidioc_g_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- /* Get the current format */
- memset(&f->fmt.pix, 0, sizeof(f->fmt.pix));
- f->fmt.pix = cam->pix;
-
- return 0;
-}
-
-static int vidioc_s_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
- int rval = 0;
-
- vidioc_int_try_fmt_cap(cam->sdev, f);
-
- cam->pix = f->fmt.pix;
-
- rval = vidioc_int_s_fmt_cap(cam->sdev, f);
- camera_sensor_if_enable(cam);
-
- return rval;
-}
-
-static int vidioc_try_fmt_cap(struct file *file, void *fh,
- struct v4l2_format *f)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- return vidioc_int_try_fmt_cap(cam->sdev, f);
-}
-
-static int vidioc_reqbufs(struct file *file, void *fh,
- struct v4l2_requestbuffers *b)
-{
- struct camera_fh *ofh = fh;
-
- return videobuf_reqbufs(&ofh->vbq, b);
-}
-
-static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
-{
- struct camera_fh *ofh = fh;
-
- return videobuf_querybuf(&ofh->vbq, b);
-}
-
-static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
-{
- struct camera_fh *ofh = fh;
-
- return videobuf_qbuf(&ofh->vbq, b);
-}
-
-static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
-{
- struct camera_fh *ofh = fh;
-
- return videobuf_dqbuf(&ofh->vbq, b, file->f_flags & O_NONBLOCK);
-}
-
-static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- spin_lock(&cam->img_lock);
-
- if (cam->streaming || cam->reading) {
- spin_unlock(&cam->img_lock);
- return -EBUSY;
- } else
- cam->streaming = ofh;
- /* FIXME: start camera interface */
-
- spin_unlock(&cam->img_lock);
-
- return videobuf_streamon(&ofh->vbq);
-}
-
-static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
- int err;
-
- err = videobuf_streamoff(&ofh->vbq);
- if (err < 0)
- return err;
-
- spin_lock(&cam->img_lock);
- if (cam->streaming == ofh)
- cam->streaming = NULL;
- /* FIXME: stop camera interface */
-
- spin_unlock(&cam->img_lock);
- return 0;
-}
-
-static int vidioc_enum_input(struct file *file, void *fh,
- struct v4l2_input *inp)
-{
- if (inp->index > 0)
- return -EINVAL;
-
- strlcpy(inp->name, "camera", sizeof(inp->name));
- inp->type = V4L2_INPUT_TYPE_CAMERA;
-
- return 0;
-}
-
-static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
-{
- *i = 0;
-
- return 0;
-}
-
-static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
-{
- if (i > 0)
- return -EINVAL;
-
- return 0;
-}
-
-static int vidioc_queryctrl(struct file *file, void *fh,
- struct v4l2_queryctrl *a)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- return vidioc_int_queryctrl(cam->sdev, a);
-}
-
-static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *a)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- return vidioc_int_g_ctrl(cam->sdev, a);
-}
-
-static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- return vidioc_int_s_ctrl(cam->sdev, a);
-}
-
-static int vidioc_g_fbuf(struct file *file, void *fh,
- struct v4l2_framebuffer *a)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- spin_lock(&cam->img_lock);
- *a = cam->fbuf;
- spin_unlock(&cam->img_lock);
-
- return 0;
-}
-
-static int vidioc_s_fbuf(struct file *file, void *fh,
- struct v4l2_framebuffer *a)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
-
- spin_lock(&cam->img_lock);
- if (cam->previewing) {
- spin_unlock(&cam->img_lock);
- return -EBUSY;
- }
- cam->fbuf.base = a->base;
- cam->fbuf.fmt = a->fmt;
-
- spin_unlock(&cam->img_lock);
- return 0;
-}
-
-static int vidioc_overlay(struct file *file, void *fh, unsigned int i)
-{
- struct camera_fh *ofh = fh;
- struct camera_device *cam = ofh->cam;
- int enable = i;
-
- /* Check whether the capture format and
- * the display format matches
- * return failure if they are different
- */
- if (cam->pix.pixelformat != cam->fbuf.fmt.pixelformat)
- return -EINVAL;
-
- /* If the camera image size is greater
- * than LCD size return failure
- */
- if ((cam->pix.width > cam->fbuf.fmt.height) ||
- (cam->pix.height > cam->fbuf.fmt.width))
- return -EINVAL;
-
- if (!cam->previewing && enable) {
- cam->previewing = fh;
- cam->overlay_cnt = 0;
- camera_core_start_overlay(cam);
- } else if (!enable)
- cam->previewing = NULL;
-
- return 0;
-}
-
-/* File operations */
-static unsigned int camera_core_poll(struct file *file,
- struct poll_table_struct *wait)
-{
- return -EINVAL;
-}
-
-/* Callback routine for read DMA completion. We just start another DMA
- * transfer unless overlay has been turned off
- */
-static void camera_core_capture_callback(void *arg1, void *arg)
-{
- struct camera_device *cam = (struct camera_device *)arg1;
- int err;
- unsigned long irqflags;
- static int done = 0;
-
- spin_lock_irqsave(&cam->capture_lock, irqflags);
- if (!cam->reading) {
- done = 0;
- cam->capture_started = 0;
- spin_unlock_irqrestore(&cam->capture_lock, irqflags);
- return;
- }
-
- if (done < 14) {
- ++done;
- sg_dma_address(&cam->capture_sglist) = cam->capture_base_phys;
- sg_dma_len(&cam->capture_sglist) = cam->pix.sizeimage;
- err = camera_core_sgdma_queue(cam, &cam->capture_sglist, 1,
- camera_core_capture_callback,
- NULL);
- } else {
- cam->capture_completed = 1;
- if (cam->reading) {
- /* Wake up any process which are waiting for the
- * DMA to complete
- */
- wake_up_interruptible(&camera_dev->new_video_frame);
- sg_dma_address(&cam->capture_sglist) =
- cam->capture_base_phys;
- sg_dma_len(&cam->capture_sglist) = cam->pix.sizeimage;
- err =
- camera_core_sgdma_queue(cam, &cam->capture_sglist,
- 1,
- camera_core_capture_callback,
- NULL);
- }
- }
-
- spin_unlock_irqrestore(&cam->capture_lock, irqflags);
-}
-
-static ssize_t camera_core_read(struct file *file, char *data, size_t count,
- loff_t *ppos)
-{
- struct camera_fh *fh = file->private_data;
- struct camera_device *cam = fh->cam;
- int err;
- unsigned long irqflags;
- long timeout;
-#if 0 /* Use video_buf to do capture */
- int i;
- for (i = 0; i < 14; i++)
- videobuf_read_one(file, &fh->vbq, data, count, ppos);
- i = videobuf_read_one(file, &fh->vbq, data, count, ppos);
- return i;
-#endif
-
- if (!cam->capture_base) {
- cam->capture_base = (unsigned long)
- dma_alloc_coherent(NULL,
- cam->pix.sizeimage,
- (dma_addr_t *) &
- cam->capture_base_phys,
- GFP_KERNEL | GFP_DMA);
- }
- if (!cam->capture_base) {
- dev_err(cam->dev, "cannot allocate capture buffer\n");
- return 0;
- }
-
- spin_lock_irqsave(&cam->capture_lock, irqflags);
- cam->reading = fh;
- cam->capture_started = 1;
- sg_dma_address(&cam->capture_sglist) = cam->capture_base_phys;
- sg_dma_len(&cam->capture_sglist) = cam->pix.sizeimage;
- spin_unlock_irqrestore(&cam->capture_lock, irqflags);
-
- err = camera_core_sgdma_queue(cam, &cam->capture_sglist, 1,
- camera_core_capture_callback, NULL);
-
- /* Wait till DMA is completed */
- timeout = HZ * 10;
- cam->capture_completed = 0;
- while (cam->capture_completed == 0) {
- timeout = interruptible_sleep_on_timeout
- (&cam->new_video_frame, timeout);
- if (timeout == 0) {
- dev_err(cam->dev, "timeout waiting video frame\n");
- return -EIO; /* Time out */
- }
- }
- /* Copy the data to the user buffer */
- err = copy_to_user(data, (void *)cam->capture_base, cam->pix.sizeimage);
- return (cam->pix.sizeimage - err);
-
-}
-
-static int camera_core_mmap(struct file *file, struct vm_area_struct *vma)
-{
- struct camera_fh *fh = file->private_data;
-
- return videobuf_mmap_mapper(&fh->vbq, vma);
-}
-
-static int camera_core_release(struct inode *inode, struct file *file)
-{
- struct camera_fh *fh = file->private_data;
- struct camera_device *cam = fh->cam;
-
- file->private_data = NULL;
- kfree(fh);
-
- spin_lock(&cam->img_lock);
-
- if (cam->previewing == fh)
- cam->previewing = NULL;
- if (cam->streaming == fh)
- cam->streaming = NULL;
- if (cam->reading == fh)
- cam->reading = NULL;
-
- spin_unlock(&cam->img_lock);
-
- camera_dev->cam_hardware->finish_dma(cam->hardware_data);
-
- if (cam->capture_base) {
- dma_free_coherent(NULL, cam->pix.sizeimage,
- (void *)cam->capture_base,
- cam->capture_base_phys);
- cam->capture_base = 0;
- cam->capture_base_phys = 0;
- }
- if (fh->vbq.read_buf) {
- camera_core_vbq_release(&fh->vbq, fh->vbq.read_buf);
- kfree(fh->vbq.read_buf);
- }
-
- module_put(cam->sdev->module);
-
- cam->cam_hardware->close(cam->hardware_data);
- cam->active = 0;
- return 0;
-}
-
-static int camera_core_open(struct inode *inode, struct file *file)
-{
- int minor = iminor(inode);
- struct camera_device *cam = camera_dev;
- struct camera_fh *fh;
- struct v4l2_format format;
- int rval;
-
- if (!cam || !cam->vfd || (cam->vfd->minor != minor))
- return -ENODEV;
-
- /* Allocate per-filehandle data */
- fh = kmalloc(sizeof(*fh), GFP_KERNEL);
- if (NULL == fh)
- return -ENOMEM;
- file->private_data = fh;
- fh->cam = cam;
- fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- spin_lock(&cam->img_lock);
- if (cam->active == 1) {
- dev_err(cam->dev, "Camera device Active\n");
- spin_unlock(&cam->img_lock);
- rval = -EPERM;
- goto err;
- }
- cam->active = 1;
-
- if (cam->sdev == NULL || !try_module_get(cam->sdev->module)) {
- spin_unlock(&cam->img_lock);
- rval = -ENODEV;
- goto err;
- }
-
- vidioc_int_g_fmt_cap(cam->sdev, &format);
- spin_unlock(&cam->img_lock);
-
- videobuf_queue_sg_init(&fh->vbq, &cam->vbq_ops, NULL, &cam->vbq_lock,
- fh->type, V4L2_FIELD_NONE,
- sizeof(struct videobuf_buffer), fh);
-
- cam->capture_completed = 0;
- cam->capture_started = 0;
-
- if (cam->cam_hardware->open(cam->hardware_data)) {
- dev_err(cam->dev, "Camera IF configuration failed\n");
- cam->active = 0;
- rval = -ENODEV;
- goto err;
- }
- rval = vidioc_s_fmt_cap(file, fh, &format);
- if (rval) {
- dev_err(cam->dev, "Camera sensor configuration failed (%d)\n",
- rval);
- cam->cam_hardware->close(cam->hardware_data);
- cam->active = 0;
- rval = -ENODEV;
- goto err;
- }
-
- return 0;
-
-err:
- module_put(cam->sdev->module);
- kfree(fh);
- return rval;
-}
-
-#ifdef CONFIG_PM
-static int camera_core_suspend(struct platform_device *pdev, pm_message_t state)
-{
- struct camera_device *cam = platform_get_drvdata(pdev);
-
- spin_lock(&cam->img_lock);
- if (cam->active)
- cam->cam_hardware->close(cam->hardware_data);
-
- vidioc_int_s_power(cam->sdev, 0);
- spin_unlock(&cam->img_lock);
-
- return 0;
-}
-
-static int camera_core_resume(struct platform_device *pdev)
-{
- struct camera_device *cam = platform_get_drvdata(pdev);
-
- spin_lock(&cam->img_lock);
- vidioc_int_s_power(cam->sdev, 1);
- if (cam->active) {
- struct v4l2_format format;
-
- cam->capture_completed = 1;
- cam->cam_hardware->open(cam->hardware_data);
-
- vidioc_int_g_fmt_cap(cam->sdev, &format);
- vidioc_int_s_fmt_cap(cam->sdev, &format);
- camera_sensor_if_enable(cam);
-
- camera_core_sgdma_process(cam);
- }
- spin_unlock(&cam->img_lock);
-
- return 0;
-}
-#endif /* CONFIG_PM */
-
-static struct file_operations camera_core_fops = {
- .owner = THIS_MODULE,
- .llseek = no_llseek,
- .read = camera_core_read,
- .poll = camera_core_poll,
- .ioctl = video_ioctl2,
- .mmap = camera_core_mmap,
- .open = camera_core_open,
- .release = camera_core_release,
-};
-static ssize_t camera_streaming_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct camera_device *cam = dev_get_drvdata(dev);
-
- return sprintf(buf, "%s\n", cam->streaming ? "active" : "inactive");
-}
-
-static DEVICE_ATTR(streaming, S_IRUGO, camera_streaming_show, NULL);
-
-static void camera_device_unregister(struct v4l2_int_device *s)
-{
- struct camera_device *cam = s->u.slave->master->priv;
-
- camera_sensor_exit(cam);
-}
-
-static int camera_device_register(struct v4l2_int_device *s)
-{
- struct camera_device *cam = s->u.slave->master->priv;
- struct video_device *vfd;
- int rval;
-
- /* We already have a slave. */
- if (cam->sdev)
- return -EBUSY;
-
- cam->sdev = s;
-
- if (device_create_file(cam->dev, &dev_attr_streaming) != 0) {
- dev_err(cam->dev, "could not register sysfs entry\n");
- rval = -EBUSY;
- goto err;
- }
-
- /* Initialize the video_device struct */
- vfd = cam->vfd = video_device_alloc();
- if (!vfd) {
- dev_err(cam->dev, " could not allocate video device struct\n");
- rval = -ENOMEM;
- goto err;
- }
-
- vfd->release = video_device_release;
-
- strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name));
- vfd->type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY | VID_TYPE_CHROMAKEY;
-
- /* Need to register for a VID_HARDWARE_* ID in videodev.h */
- vfd->fops = &camera_core_fops;
- video_set_drvdata(vfd, cam);
- vfd->minor = -1;
-
- vfd->vidioc_querycap = vidioc_querycap;
- vfd->vidioc_enum_fmt_cap = vidioc_enum_fmt_cap;
- vfd->vidioc_g_fmt_cap = vidioc_g_fmt_cap;
- vfd->vidioc_s_fmt_cap = vidioc_s_fmt_cap;
- vfd->vidioc_try_fmt_cap = vidioc_try_fmt_cap;
- vfd->vidioc_reqbufs = vidioc_reqbufs;
- vfd->vidioc_querybuf = vidioc_querybuf;
- vfd->vidioc_qbuf = vidioc_qbuf;
- vfd->vidioc_dqbuf = vidioc_dqbuf;
- vfd->vidioc_streamon = vidioc_streamon;
- vfd->vidioc_streamoff = vidioc_streamoff;
- vfd->vidioc_enum_input = vidioc_enum_input;
- vfd->vidioc_g_input = vidioc_g_input;
- vfd->vidioc_s_input = vidioc_s_input;
- vfd->vidioc_queryctrl = vidioc_queryctrl;
- vfd->vidioc_g_ctrl = vidioc_g_ctrl;
- vfd->vidioc_s_ctrl = vidioc_s_ctrl;
- vfd->vidioc_g_fbuf = vidioc_g_fbuf;
- vfd->vidioc_s_fbuf = vidioc_s_fbuf;
- vfd->vidioc_overlay = vidioc_overlay;
-
- dev_info(cam->dev, "%s interface with %s sensor\n",
- cam->cam_hardware->name, cam->sdev->name);
-
- if (video_register_device(vfd, VFL_TYPE_GRABBER, video_nr) < 0) {
- dev_err(cam->dev,
- "could not register Video for Linux device\n");
- rval = -ENODEV;
- goto err;
- }
-
- rval = camera_sensor_init(cam);
- if (rval)
- goto err;
-
- /* Disable the Camera after detection */
- cam->cam_hardware->disable(cam->hardware_data);
-
- return 0;
-
-err:
- camera_device_unregister(s);
-
- return rval;
-}
-
-static struct v4l2_int_master camera_master = {
- .attach = camera_device_register,
- .detach = camera_device_unregister,
-};
-
-static struct v4l2_int_device camera = {
- .module = THIS_MODULE,
- .name = CAM_NAME,
- .type = v4l2_int_type_master,
- .u = {
- .master = &camera_master
- },
-};
-
-static int __init camera_core_probe(struct platform_device *pdev)
-{
- struct camera_device *cam;
- int status = 0;
-
- cam = kzalloc(sizeof(struct camera_device), GFP_KERNEL);
- if (!cam) {
- dev_err(&pdev->dev, "could not allocate memory\n");
- status = -ENOMEM;
- goto err;
- }
-
- platform_set_drvdata(pdev, cam);
-
- cam->dev = &pdev->dev;
-
- /* Initialize the camera interface */
- cam->cam_hardware = &camera_hardware_if;
- cam->hardware_data = cam->cam_hardware->init();
- if (!cam->hardware_data) {
- dev_err(cam->dev, "cannot initialize interface hardware\n");
- status = -ENODEV;
- goto err;
- }
-
- /* Save the pointer to camera device in a global variable */
- camera_dev = cam;
-
- /* Initialize the videobuf queue ops */
- cam->vbq_ops.buf_setup = camera_core_vbq_setup;
- cam->vbq_ops.buf_prepare = camera_core_vbq_prepare;
- cam->vbq_ops.buf_queue = camera_core_vbq_queue;
- cam->vbq_ops.buf_release = camera_core_vbq_release;
-
- /* Initialize the overlay interface */
- cam->overlay_size = overlay_mem;
- if (cam->overlay_size > 0) {
- cam->overlay_base = (unsigned long)
- dma_alloc_coherent(NULL,
- cam->overlay_size,
- (dma_addr_t *) &
- cam->overlay_base_phys,
- GFP_KERNEL | GFP_DMA);
- if (!cam->overlay_base) {
- dev_err(cam->dev,
- "cannot allocate overlay framebuffer\n");
- status = -ENOMEM;
- goto err;
- }
- }
- memset((void *)cam->overlay_base, 0, cam->overlay_size);
- spin_lock_init(&cam->overlay_lock);
- spin_lock_init(&cam->capture_lock);
-
- /* Initialize the spinlock used to serialize access to the image
- * parameters
- */
- spin_lock_init(&cam->img_lock);
-
- /* Initialize the wait queue */
- init_waitqueue_head(&cam->new_video_frame);
-
- /* Initialize the DMA structures */
- camera_core_sgdma_init(cam);
-
- platform_set_drvdata(pdev, cam);
-
- camera.priv = cam;
-
- if (v4l2_int_device_register(&camera))
- goto err;
-
- return 0;
-
-err:
- vidioc_int_dev_exit(cam->sdev);
- cam->overlay_base = 0;
- return status;
-}
-
-static int camera_core_remove(struct platform_device *pdev)
-{
- struct camera_device *cam = platform_get_drvdata(pdev);
- struct video_device *vfd;
-
- vfd = cam->vfd;
- if (vfd) {
- if (vfd->minor == -1) {
- /* The device never got registered, so release the
- * video_device struct directly
- */
- video_device_release(vfd);
- } else {
- /* The unregister function will release the
- * video_device struct as well as unregistering it.
- */
- video_unregister_device(vfd);
- }
- cam->vfd = NULL;
- }
- if (cam->overlay_base) {
- dma_free_coherent(NULL, cam->overlay_size,
- (void *)cam->overlay_base,
- cam->overlay_base_phys);
- cam->overlay_base = 0;
- }
- cam->overlay_base_phys = 0;
-
- vidioc_int_dev_exit(cam->sdev);
- cam->cam_hardware->cleanup(cam->hardware_data);
- kfree(cam);
- camera_dev = NULL;
-
- return 0;
-}
-
-static struct platform_driver camera_core_driver = {
- .driver = {
- .name = CAM_NAME,
- .owner = THIS_MODULE,
- },
- .probe = camera_core_probe,
- .remove = camera_core_remove,
-#ifdef CONFIG_PM
- .suspend = camera_core_suspend,
- .resume = camera_core_resume,
-#endif
-};
-
-/* FIXME register omap16xx or omap24xx camera device in arch/arm/...
- * system initialization code, with its resources and mux setup, NOT here.
- * Then MODULE_ALIAS(CAM_NAME) so it hotplugs and coldplugs; this
- * "legacy" driver style is trouble.
- */
-static struct platform_device *cam;
-
-static void __exit camera_core_cleanup(void)
-{
- platform_driver_unregister(&camera_core_driver);
- platform_device_unregister(cam);
-}
-
-static char banner[] __initdata = KERN_INFO "OMAP Camera driver initializing\n";
-
-static int __init camera_core_init(void)
-{
-
- printk(banner);
- platform_driver_register(&camera_core_driver);
-
- cam = platform_device_register_simple(CAM_NAME, -1, NULL, 0);
-
- return 0;
-}
-
-MODULE_AUTHOR("Texas Instruments.");
-MODULE_DESCRIPTION("OMAP Video for Linux camera driver");
-MODULE_LICENSE("GPL");
-
-module_param(video_nr, int, 0);
-MODULE_PARM_DESC(video_nr,
- "Minor number for video device (-1 ==> auto assign)");
-module_param(capture_mem, int, 0);
-MODULE_PARM_DESC(capture_mem,
- "Maximum amount of memory for capture buffers "
- "(default 4800KB)");
-
-module_init(camera_core_init);
-module_exit(camera_core_cleanup);
+++ /dev/null
-/*
- * drivers/media/video/omap/camera_core.h
- *
- * Copyright (C) 2004 Texas Instruments, Inc.
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifndef CAMERA_CORE__H
-#define CAMERA_CORE__H
-
-struct camera_fh;
-
-#include <asm/scatterlist.h>
-#include <media/videobuf-dma-sg.h>
-#include <media/v4l2-int-device.h>
-
-struct camera_device;
-typedef void (*dma_callback_t)(void *arg1, void *arg2);
-
-struct sgdma_state {
- const struct scatterlist *sglist;
- int sglen; /* number of sglist entries */
- int next_sglist; /* index of next sglist entry to process */
- int queued_sglist; /* number of sglist entries queued for DMA */
- unsigned long csr; /* DMA return code */
- dma_callback_t callback;
- void *arg;
-};
-
-/* NUM_SG_DMA is the number of scatter-gather DMA transfers that can be queued.
- */
-#define NUM_SG_DMA VIDEO_MAX_FRAME+2
-
-/* per-device data structure */
-struct camera_device {
- struct device *dev;
- struct video_device *vfd;
-
- spinlock_t overlay_lock; /* spinlock for overlay DMA counter */
- int overlay_cnt; /* count of queued overlay DMA xfers */
- struct scatterlist overlay_sglist;
- unsigned long overlay_base_phys;
- unsigned long overlay_base;
- unsigned long overlay_size;
-
- spinlock_t vbq_lock; /* spinlock for videobuf queues */
- struct videobuf_queue_ops vbq_ops; /* videobuf queue operations */
- unsigned long field_count; /* field counter for videobuf_buffer */
-
- /* scatter-gather DMA management */
- spinlock_t sg_lock;
- int free_sgdma; /* number of free sg dma slots */
- int next_sgdma; /* index of next sg dma slot to use */
- struct sgdma_state sgdma[NUM_SG_DMA];
- char in_use;
-
- /* The img_lock is used to serialize access to the image parameters for
- * overlay and capture. Need to use spin_lock_irq when writing to the
- * reading, streaming, and previewing parameters. A regular spin_lock
- * will suffice for all other cases.
- */
- spinlock_t img_lock;
-
- /* We allow reading from at most one filehandle at a time.
- * non-NULL means reading is in progress.
- */
- struct camera_fh *reading;
- /* We allow streaming from at most one filehandle at a time.
- * non-NULL means streaming is in progress.
- */
- struct camera_fh *streaming;
- /* We allow previewing from at most one filehandle at a time.
- * non-NULL means previewing is in progress.
- */
- struct camera_fh *previewing;
-
- /*
- * Sensor interface parameters: interface type, CC_CTRL
- * register value and interface specific data.
- */
- int if_type;
- union {
- struct parallel {
- u32 xclk;
- } bt656;
- } if_u;
- /* Pointer to the sensor interface ops */
- struct v4l2_int_device *sdev;
-
- /* Pointer to the camera interface hardware ops */
- struct camera_hardware *cam_hardware;
- void *hardware_data;
-
- /* pix defines the size and pixel format of the image captured by the
- * sensor. This also defines the size of the framebuffers. The
- * same pool of framebuffers is used for video capture and video
- * overlay. These parameters are set/queried by the
- * VIDIOC_S_FMT/VIDIOC_G_FMT ioctls with a CAPTURE buffer type.
- */
- struct v4l2_pix_format pix;
-
- /* crop defines the size and offset of the video overlay source window
- * within the framebuffer. These parameters are set/queried by the
- * VIDIOC_S_CROP/VIDIOC_G_CROP ioctls with an OVERLAY buffer type.
- * The cropping rectangle allows a subset of the captured image to be
- * previewed. It only affects the portion of the image previewed, not
- * captured; the entire camera image is always captured.
- */
- struct v4l2_rect crop;
-
- /* win defines the size and offset of the video overlay target window
- * within the video display. These parameters are set/queried by the
- * VIDIOC_S_FMT/VIDIOC_G_FMT ioctls with an OVERLAY buffer type.
- */
- struct v4l2_window win;
-
- /* fbuf reflects the size of the video display. It is queried with the
- * VIDIOC_G_FBUF ioctl. The size of the video display cannot be
- * changed with the VIDIOC_S_FBUF ioctl.
- */
- struct v4l2_framebuffer fbuf;
-
- /* end of generic stuff, the above should be common to all omaps */
-
- /* note, 2420 uses videobuf to do caprure, it is more memory efficient
- we need 1710 and 2420 do capture in the same way */
- /* Variables to store the capture state */
- /* Wait till DMA is completed */
- wait_queue_head_t new_video_frame;
- char capture_completed;
- char capture_started;
- spinlock_t capture_lock;
- struct scatterlist capture_sglist;
- unsigned long capture_base;
- unsigned long capture_base_phys;
-
- char active;
-};
-
-/* per-filehandle data structure */
-struct camera_fh {
- struct camera_device *cam;
- enum v4l2_buf_type type;
- struct videobuf_queue vbq;
-};
-
-#define CAM_NAME "omap_camera"
-
-#endif /* CAMERA_CORE__H */
+++ /dev/null
-/*
- * drivers/media/video/omap/camera_hw_if.h
- *
- * Copyright (C) 2004 Texas Instruments, Inc.
- *
- * Camera interface to OMAP camera capture drivers
- * Camera interface hardware driver should implement this interface
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifndef OMAP_CAMERA_HW_IF_H
-#define OMAP_CAMERA_HW_IF_H
-
-#define LEN_HW_IF_NAME 31
-
-struct sgdma_state;
-
-struct camera_hardware {
- unsigned int version; //version of camera driver module
- char name[LEN_HW_IF_NAME + 1];
-
- void *(*init)(void);
- int (*cleanup)(void *);
-
- int (*open)(void *); /* acquire h/w resources (irq,DMA), etc. */
- int (*close)(void *); /* free h/w resources, stop i/f */
-
- int (*enable)(void *);
- int (*disable)(void *);
-
- int (*abort)(void *);
-
- int (*set_xclk)(int, void *);
-
- int (*init_dma)(void *);
- int (*start_dma)(struct sgdma_state *, void (*)(void *arg1, void *arg2),
- void *, void *, void *);
- int (*finish_dma)(void *);
-};
-
-extern struct camera_hardware camera_hardware_if;
-
-#endif /* OMAP_CAMERA_HW_IF_H */
+++ /dev/null
-/*
- * drivers/media/video/omap/omap16xxcam.c
- *
- * Copyright (C) 2004 Texas Instruments, Inc.
- *
- * Video-for-Linux (Version 2) camera capture driver for
- * the OMAP H2 and H3 camera controller.
- *
- * leverage some code from CEE distribution
- * Copyright (C) 2003-2004 MontaVista Software, Inc.
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#include <linux/vmalloc.h>
-#include <linux/slab.h>
-#include <linux/proc_fs.h>
-#include <linux/ctype.h>
-#include <linux/delay.h>
-#include <linux/device.h>
-#include <linux/dma-mapping.h>
-#include <linux/interrupt.h>
-#include <linux/clk.h>
-
-#include <mach/irqs.h>
-#include <mach/dma.h>
-#include <mach/hardware.h>
-#include <asm/io.h>
-#include <asm/scatterlist.h>
-#include <asm/mach-types.h>
-
-#include "omap16xxcam.h"
-#include "camera_hw_if.h"
-#include "camera_core.h"
-
-#define CONF_CAMERAIF_RESET_R 5
-#define EN_PER 0
-
-/* NUM_CAMDMA_CHANNELS is the number of logical channels used for
- * DMA data transfer.
- */
-#define NUM_CAMDMA_CHANNELS 2
-
-typedef struct {
- unsigned int ctrlclock; /* 00 */
- unsigned int it_status; /* 04 */
- unsigned int mode; /* 08 */
- unsigned int status; /* 0C */
- unsigned int camdata; /* 10 */
- unsigned int gpio; /* 14 */
- unsigned int peak_counter; /* 18 */
-} camera_regs_t;
-
-struct camdma_state {
- dma_callback_t callback;
- void *arg1;
- void *arg2;
-};
-
-struct omap16xxcam {
- camera_regs_t *camera_regs;
- unsigned long iobase_phys;
-
- /* Frequency (in Hz) of camera interface functional clock (ocp_clk) */
- unsigned long ocp_clk;
-
- struct clk *func_clk;
-
- /* DMA related stuff */
- spinlock_t dma_lock;
- int free_dmach;
- int next_dmach;
- struct camdma_state camdma[NUM_CAMDMA_CHANNELS];
- int dma_channel_number1;
- int dma_channel_number2;
-
- wait_queue_head_t vsync_wait;
-
- int new;
-};
-static struct omap16xxcam hardware_data;
-
-static int omap16xxcam_set_xclk(int, void *);
-static void omap16xx_cam_dma_link_callback(int, unsigned short, void *);
-
-/* Clears the camera data FIFO by setting RAZ_FIFO bit in MODE configuration
- * register.
- */
-static void omap16xx_cam_clear_fifo(struct omap16xxcam *data)
-{
- data->camera_regs->mode |= RAZ_FIFO;
- udelay(10);
- data->camera_regs->mode &= ~RAZ_FIFO;
-}
-
-static void omap16xx_cam_reset(struct omap16xxcam *data, int yes)
-{
- if (machine_is_omap_h3())
- data->camera_regs->gpio = yes ? 0 : 1;
- else
- data->camera_regs->gpio = yes ? 1 : 0;
-}
-
-static void omap16xx_cam_init(void)
-{
- /*
- * FIXME - Use mux API's instead of directly writing in to MUX registers
- */
- omap_writel(omap_readl(FUNC_MUX_CTRL_4) & ~(0x1ff << 21),
- FUNC_MUX_CTRL_4);
- omap_writel(0, FUNC_MUX_CTRL_5);
- omap_writel(omap_readl(PULL_DWN_CTRL_0) & ~(0x1FFF << 17),
- PULL_DWN_CTRL_0);
- omap_writel(omap_readl(PU_PD_SEL_0) & ~(0x1FFF << 17), PU_PD_SEL_0);
-
- omap_writel(0xeaef, COMP_MODE_CTRL_0);
- omap_writel(omap_readl(OMAP1610_RESET_CONTROL) &
- ~(1 << CONF_CAMERAIF_RESET_R), OMAP1610_RESET_CONTROL);
- omap_writel(omap_readl(OMAP1610_RESET_CONTROL) |
- (1 << CONF_CAMERAIF_RESET_R), OMAP1610_RESET_CONTROL);
-
- /* Enable peripheral reset */
- omap_writew(omap_readw(ARM_RSTCT2) | (1 << EN_PER), ARM_RSTCT2);
-
- /* Enable peripheral clock */
- clk_enable(hardware_data.func_clk);
-}
-
-static void omap16xx_cam_waitfor_syncedge(struct omap16xxcam *data,
- u32 edge_mask)
-{
- data->camera_regs->mode =
- (FIFO_TRIGGER_LVL << THRESHOLD_BIT) | edge_mask;
- do {
- interruptible_sleep_on(&data->vsync_wait);
- } while (signal_pending(current));
-}
-
-static void omap16xx_cam_configure_dma(struct omap16xxcam *data)
-{
-
- data->camera_regs->mode = (FIFO_TRIGGER_LVL << THRESHOLD_BIT)
- | EN_DMA | EN_FIFO_FULL;
- data->camera_regs->ctrlclock |= LCLK_EN;
-}
-
-/* Acquire h/w resources DMA */
-static int omap16xx_cam_link_open(struct omap16xxcam *data)
-{
- int ret;
-
- /* Acquire first DMA channel */
- ret = omap_request_dma(OMAP_DMA_CAMERA_IF_RX,
- "camera dma 1",
- omap16xx_cam_dma_link_callback,
- (void *)data, &data->dma_channel_number1);
- if (ret)
- return ret;
-
- /* Acquire second DMA channel */
- ret = omap_request_dma(OMAP_DMA_CAMERA_IF_RX,
- "camera dma 2",
- omap16xx_cam_dma_link_callback,
- (void *)data, &data->dma_channel_number2);
- if (ret) {
- printk(KERN_ERR "No DMA available for camera\n");
- return ret;
- }
- data->next_dmach = data->dma_channel_number1;
- OMAP_DMA_CLNK_CTRL_REG(data->dma_channel_number1) =
- data->dma_channel_number2;
- OMAP_DMA_CLNK_CTRL_REG(data->dma_channel_number2) =
- data->dma_channel_number1;
-
- return 0;
-}
-
-/* Free h/w resources, stop i/f */
-static int omap16xx_cam_link_close(struct omap16xxcam *data)
-{
- /* Free DMA channels */
- omap_stop_dma(data->dma_channel_number1);
- omap_stop_dma(data->dma_channel_number2);
-
- omap_free_dma(data->dma_channel_number1);
- omap_free_dma(data->dma_channel_number2);
-
- return 0;
-}
-
-/* DMA callback routine. */
-static void omap16xx_cam_dma_link_callback(int lch, unsigned short ch_status,
- void *data)
-{
- int count;
- void *arg1, *arg2;
- struct sgdma_state *sgdma = sgdma;
- struct omap16xxcam *cam = (struct omap16xxcam *)data;
- dma_callback_t callback;
-
- spin_lock(&cam->dma_lock);
- if (cam->free_dmach == 2) {
- printk(KERN_ERR "callback all CHANNELS WERE IDLE \n");
- spin_unlock(&cam->dma_lock);
- return;
- }
- if (cam->free_dmach == 0) {
- lch = cam->next_dmach;
- } else {
- lch = cam->next_dmach == cam->dma_channel_number1 ?
- cam->dma_channel_number2 : cam->dma_channel_number1;
- }
-
- while (cam->free_dmach < 2) {
- if (OMAP_DMA_CCR_REG(lch) & (1 << 7))
- break;
-
- count = (lch == cam->dma_channel_number2) ? 1 : 0;
-
- callback = cam->camdma[count].callback;
- arg1 = cam->camdma[count].arg1;
- arg2 = cam->camdma[count].arg2;
- cam->free_dmach++;
-
- spin_unlock(&cam->dma_lock);
- callback(arg1, arg2);
- spin_lock(&cam->dma_lock);
-
- lch =
- (lch ==
- cam->dma_channel_number2) ? cam->
- dma_channel_number1 : cam->dma_channel_number2;
- }
- spin_unlock(&cam->dma_lock);
-
-}
-
-static irqreturn_t omap16xx_cam_isr(int irq, void *client_data)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)client_data;
- unsigned int itstat = data->camera_regs->it_status;
-
- /* VSYNC UP interrupt, start filling FIFO and enabling DMA */
- if (itstat & V_UP) {
- data->camera_regs->mode &= ~EN_V_UP;
- omap16xx_cam_clear_fifo(data);
- omap16xx_cam_configure_dma(data);
- omap_start_dma(data->next_dmach);
- wake_up_interruptible(&data->vsync_wait);
- }
-
- if (itstat & V_DOWN) {
- data->camera_regs->mode &= ~EN_V_DOWN;
- wake_up_interruptible(&data->vsync_wait);
- }
-
- if (itstat & H_UP)
- printk(KERN_INFO "H_UP\n");
-
- if (itstat & H_DOWN)
- printk(KERN_INFO "H_DOWN\n");
-
- if (itstat & FIFO_FULL) {
- omap16xx_cam_clear_fifo(data);
- printk(KERN_INFO "FIFO_FULL\n");
- }
-
- if (itstat & DATA_XFER)
- printk(KERN_INFO "DATA_TRANS\n");
-
- return IRQ_HANDLED;
-}
-
-/* ------------- Below are interface functions -----------------
- * ------------- These functions are named omap16xxcam_<name> --
- */
-static int omap16xxcam_init_dma(void *priv)
-{
- int ch;
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- data->free_dmach = 2;
- for (ch = 0; ch < 2; ++ch) {
- data->camdma[ch].callback = NULL;
- data->camdma[ch].arg1 = NULL;
- data->camdma[ch].arg2 = NULL;
- }
-
- return 0;
-}
-
-/* Start the DMA of chains */
-static int omap16xxcam_start_dma(struct sgdma_state *sgdma,
- dma_callback_t callback, void *arg1,
- void *arg2, void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
- struct scatterlist *sglist;
- unsigned long irqflags;
- int dmach;
- int prev_dmach;
- int count;
-
- spin_lock_irqsave(&data->dma_lock, irqflags);
- sglist = (struct scatterlist *)(sgdma->sglist + sgdma->next_sglist);
-
- if (!data->free_dmach) {
- spin_unlock_irqrestore(&data->dma_lock, irqflags);
- return -EBUSY;
- }
- dmach = data->next_dmach;
- count = (dmach == data->dma_channel_number2) ? 1 : 0;
- data->camdma[count].callback = callback;
- data->camdma[count].arg1 = arg1;
- data->camdma[count].arg2 = arg2;
-
- if (cpu_is_omap1710())
- omap_set_dma_src_params(dmach, OMAP_DMA_PORT_OCP_T1,
- OMAP_DMA_AMODE_CONSTANT,
- CAM_CAMDATA_REG, 0, 0);
- else
- omap_set_dma_src_params(dmach, OMAP_DMA_PORT_TIPB,
- OMAP_DMA_AMODE_CONSTANT,
- CAM_CAMDATA_REG, 0, 0);
-
- omap_set_dma_dest_params(dmach, OMAP_DMA_PORT_EMIFF,
- OMAP_DMA_AMODE_POST_INC,
- sg_dma_address(sglist), 0, 0);
-
- omap_set_dma_transfer_params(dmach, OMAP_DMA_DATA_TYPE_S32,
- FIFO_TRIGGER_LVL,
- sg_dma_len(sglist) / (4 *
- FIFO_TRIGGER_LVL),
- OMAP_DMA_SYNC_FRAME, 0, 0);
-
- OMAP_DMA_CLNK_CTRL_REG(dmach) &= ~(1 << 15);
-
- prev_dmach = (dmach == data->dma_channel_number2) ?
- data->dma_channel_number1 : data->dma_channel_number2;
-
- if (data->new) {
- data->new = 0;
- omap16xx_cam_waitfor_syncedge(data, EN_V_UP);
- } else {
- if (OMAP_DMA_CCR_REG(prev_dmach) & (1 << 7))
- OMAP_DMA_CLNK_CTRL_REG(prev_dmach) |= (1 << 15);
- else {
- /* No transfer is in progress */
- omap_start_dma(dmach);
- }
- }
-
- data->next_dmach = prev_dmach;
- data->free_dmach--;
- spin_unlock_irqrestore(&data->dma_lock, irqflags);
- return 0;
-}
-
-int static omap16xxcam_finish_dma(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- while (data->free_dmach < 2)
- mdelay(1);
-
- return 0;
-}
-
-/* Enables the camera. Takes camera out of reset. Enables the clocks. */
-static int omap16xxcam_enable(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- omap16xx_cam_reset(data, 1);
-
- /* Give clock to camera_module */
- data->camera_regs->mode = (FIFO_TRIGGER_LVL << THRESHOLD_BIT);
- data->camera_regs->ctrlclock = MCLK_EN | CAMEXCLK_EN;
-
- omap16xx_cam_clear_fifo(data);
-
- /* Wait for camera to settle down */
- mdelay(5);
-
- return 0;
-}
-
-/* Disables all the camera clocks. Put the camera interface in reset. */
-static int omap16xxcam_disable(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- omap16xx_cam_clear_fifo(data);
-
- data->camera_regs->ctrlclock = 0x00000000;
- data->camera_regs->mode = 0x00000000;
-
- omap16xx_cam_reset(data, 0);
-
- return 0;
-}
-
-/* Abort the data transfer */
-static int omap16xxcam_abort(void *priv)
-{
- return omap16xxcam_disable(priv);
-}
-
-static int omap16xxcam_set_xclk(int xclk, void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
- int xclk_val;
- int divisor = 1;
- divisor = data->ocp_clk / xclk;
- if (divisor * xclk < data->ocp_clk)
- ++divisor;
-
- switch (divisor) {
- case 1:
- case 2:
- xclk_val = FOSCMOD_TC2_CK2;
- break;
- case 3:
- xclk_val = FOSCMOD_TC2_CK3;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- xclk_val = FOSCMOD_TC2_CK4;
- break;
- case 8:
- case 9:
- xclk_val = FOSCMOD_TC2_CK8;
- break;
- case 10:
- case 11:
- xclk_val = FOSCMOD_TC2_CK10;
- break;
- case 12:
- case 13:
- case 14:
- case 15:
- xclk_val = FOSCMOD_TC2_CK12;
- break;
- case 16:
- xclk_val = FOSCMOD_TC2_CK16;
- break;
- default:
- xclk_val = FOSCMOD_TC2_CK16;
- }
-
- /* Follow the protocol to change the XCLK clock */
- data->camera_regs->ctrlclock &= ~CAMEXCLK_EN;
- data->camera_regs->ctrlclock |= xclk_val;
- data->camera_regs->ctrlclock |= CAMEXCLK_EN;
-
- return (data->ocp_clk / divisor);
-}
-
-static int omap16xxcam_open(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
- int ret;
-
- ret = request_irq(INT_CAMERA, omap16xx_cam_isr, IRQF_DISABLED,
- "camera", data);
- if (ret) {
- printk(KERN_ERR "FAILED to acquire IRQ\n");
- return ret;
- }
-
- data->new = 1;
- omap16xxcam_enable(data);
- omap16xxcam_init_dma(data);
-
- return omap16xx_cam_link_open(data);
-}
-
-static int omap16xxcam_close(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- omap16xxcam_disable(priv);
-
- free_irq(INT_CAMERA, data);
-
- return omap16xx_cam_link_close(data);
-}
-
-static int omap16xxcam_cleanup(void *priv)
-{
- struct omap16xxcam *data = (struct omap16xxcam *)priv;
-
- if (!data->camera_regs)
- return -EINVAL;
-
- omap16xxcam_disable(data);
- if (cpu_is_omap1710())
- iounmap((void *)data->camera_regs);
- data->camera_regs = NULL;
-
- if (data->iobase_phys) {
- release_mem_region(data->iobase_phys, CAMERA_IOSIZE);
- data->iobase_phys = 0;
- }
-
- if (hardware_data.func_clk) {
- clk_disable(hardware_data.func_clk);
- clk_put(hardware_data.func_clk);
- hardware_data.func_clk = NULL;
- }
-
- return 0;
-}
-
-/* Initialize the OMAP camera interface */
-static void *omap16xxcam_init(void)
-{
- unsigned long cam_iobase;
-
- if (!request_mem_region(CAMERA_BASE, CAMERA_IOSIZE,
- camera_hardware_if.name)) {
- pr_debug("%s is already in use\n", camera_hardware_if.name);
- return NULL;
- }
-
- if (cpu_is_omap1710()) {
- cam_iobase = (unsigned long)ioremap(CAMERA_BASE, CAMERA_IOSIZE);
- if (!cam_iobase) {
- printk(KERN_ERR "CANNOT MAP CAMERA REGISTER\n");
- return NULL;
- }
- } else
- cam_iobase = OMAP1_IO_ADDRESS(CAMERA_BASE);
-
- /* Set the base address of the camera registers */
- hardware_data.camera_regs = (camera_regs_t *) cam_iobase;
- hardware_data.iobase_phys = (unsigned long)CAMERA_BASE;
-
- /* Get the input clock value to camera interface and store it */
- if (cpu_is_omap1710())
- hardware_data.func_clk = clk_get(0, "tc2_ck");
- else
- hardware_data.func_clk = clk_get(0, "armper_ck");
- hardware_data.ocp_clk = clk_get_rate(hardware_data.func_clk);
-
- /* Initialize the camera IF */
- omap16xx_cam_init();
- /* Enable it. This is needed for sensor detection */
- omap16xxcam_enable((void *)&hardware_data);
- /* Initialize DMA data */
- spin_lock_init(&hardware_data.dma_lock);
-
- init_waitqueue_head(&hardware_data.vsync_wait);
- return (void *)&hardware_data;
-}
-
-struct camera_hardware camera_hardware_if = {
- .version = 0x01,
- .name = "OMAP16xx Parallel Camera",
- .init = omap16xxcam_init,
- .cleanup = omap16xxcam_cleanup,
- .open = omap16xxcam_open,
- .close = omap16xxcam_close,
- .enable = omap16xxcam_enable,
- .disable = omap16xxcam_disable,
- .abort = omap16xxcam_abort,
- .set_xclk = omap16xxcam_set_xclk,
- .init_dma = omap16xxcam_init_dma,
- .start_dma = omap16xxcam_start_dma,
- .finish_dma = omap16xxcam_finish_dma,
-};
+++ /dev/null
-/*
- * drivers/media/video/omap/omap16xxcam.h
- *
- * Copyright (C) 2004 Texas Instruments, Inc.
- *
- * This package is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifndef OMAP_16XX_CAM_H
-#define OMAP_16XX_CAM_H
-
-#define DMA_ELEM_SIZE 4
-#define FIFO_TRIGGER_LVL (32)
-
-/*
- * ---------------------------------------------------------------------------
- * OMAP1610 Camera Interface
- * ---------------------------------------------------------------------------
- */
-
-#ifdef CONFIG_MACH_OMAP_H3
-#define CAMERA_BASE (0x2007d800)
-#else
-#define CAMERA_BASE (IO_PHYS + 0x6800)
-#endif
-
-#define CAM_CTRLCLOCK_REG (CAMERA_BASE + 0x00)
-#define CAM_IT_STATUS_REG (CAMERA_BASE + 0x04)
-#define CAM_MODE_REG (CAMERA_BASE + 0x08)
-#define CAM_STATUS_REG (CAMERA_BASE + 0x0C)
-#define CAM_CAMDATA_REG (CAMERA_BASE + 0x10)
-#define CAM_GPIO_REG (CAMERA_BASE + 0x14)
-#define CAM_PEAK_CTR_REG (CAMERA_BASE + 0x18)
-#define CAMERA_IOSIZE 0x1C
-
-/* CTRLCLOCK bit shifts */
-#define FOSCMOD_BIT 0
-#define FOSCMOD_MASK (0x7 << FOSCMOD_BIT)
-#define FOSCMOD_12MHz 0x0
-#define FOSCMOD_6MHz 0x2
-#define FOSCMOD_9_6MHz 0x4
-#define FOSCMOD_24MHz 0x5
-#define FOSCMOD_8MHz 0x6
-#define FOSCMOD_TC2_CK2 0x3
-#define FOSCMOD_TC2_CK3 0x1
-#define FOSCMOD_TC2_CK4 0x5
-#define FOSCMOD_TC2_CK8 0x0
-#define FOSCMOD_TC2_CK10 0x4
-#define FOSCMOD_TC2_CK12 0x6
-#define FOSCMOD_TC2_CK16 0x2
-#define POLCLK (1<<3)
-#define CAMEXCLK_EN (1<<4)
-#define MCLK_EN (1<<5)
-#define DPLL_EN (1<<6)
-#define LCLK_EN (1<<7)
-
-/* IT_STATUS bit shifts */
-#define V_UP (1<<0)
-#define V_DOWN (1<<1)
-#define H_UP (1<<2)
-#define H_DOWN (1<<3)
-#define FIFO_FULL (1<<4)
-#define DATA_XFER (1<<5)
-
-/* MODE bit shifts */
-#define CAMOSC (1<<0)
-#define IMGSIZE_BIT 1
-#define IMGSIZE_MASK (0x3 << IMGSIZE_BIT)
-#define IMGSIZE_CIF (0x0 << IMGSIZE_BIT) /* 352x288 */
-#define IMGSIZE_QCIF (0x1 << IMGSIZE_BIT) /* 176x144 */
-#define IMGSIZE_VGA (0x2 << IMGSIZE_BIT) /* 640x480 */
-#define IMGSIZE_QVGA (0x3 << IMGSIZE_BIT) /* 320x240 */
-#define ORDERCAMD (1<<3)
-#define EN_V_UP (1<<4)
-#define EN_V_DOWN (1<<5)
-#define EN_H_UP (1<<6)
-#define EN_H_DOWN (1<<7)
-#define EN_DMA (1<<8)
-#define THRESHOLD (1<<9)
-#define THRESHOLD_BIT 9
-#define THRESHOLD_MASK (0x7f<<9)
-#define EN_NIRQ (1<<16)
-#define EN_FIFO_FULL (1<<17)
-#define RAZ_FIFO (1<<18)
-
-/* STATUS bit shifts */
-#define VSTATUS (1<<0)
-#define HSTATUS (1<<1)
-
-/* GPIO bit shifts */
-#define CAM_RST (1<<0)
-
-
-#define XCLK_6MHZ 6000000
-#define XCLK_8MHZ 8000000
-#define XCLK_9_6MHZ 9000000
-#define XCLK_12MHZ 12000000
-#define XCLK_24MHZ 24000000
-
-#endif /* OMAP_16XX_CAM_H */
+++ /dev/null
-/*
- * drivers/media/video/omap24xxcam-dma.c
- *
- * Copyright (C) 2004 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- * Copyright (C) 2007 Nokia Corporation.
- *
- * Contact: Sakari Ailus <sakari.ailus@nokia.com>
- *
- * Based on code from Andy Lowe <source@mvista.com> and
- * David Cohen <david.cohen@indt.org.br>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/scatterlist.h>
-
-#include "omap24xxcam.h"
-
-/*
- *
- * DMA hardware.
- *
- */
-
-/* Ack all interrupt on CSR and IRQSTATUS_L0 */
-static void omap24xxcam_dmahw_ack_all(unsigned long base)
-{
- u32 csr;
- int i;
-
- for (i = 0; i < NUM_CAMDMA_CHANNELS; ++i) {
- csr = omap24xxcam_reg_in(base, CAMDMA_CSR(i));
- /* ack interrupt in CSR */
- omap24xxcam_reg_out(base, CAMDMA_CSR(i), csr);
- }
- omap24xxcam_reg_out(base, CAMDMA_IRQSTATUS_L0, 0xf);
-}
-
-/* Ack dmach on CSR and IRQSTATUS_L0 */
-static u32 omap24xxcam_dmahw_ack_ch(unsigned long base, int dmach)
-{
- u32 csr;
-
- csr = omap24xxcam_reg_in(base, CAMDMA_CSR(dmach));
- /* ack interrupt in CSR */
- omap24xxcam_reg_out(base, CAMDMA_CSR(dmach), csr);
- /* ack interrupt in IRQSTATUS */
- omap24xxcam_reg_out(base, CAMDMA_IRQSTATUS_L0, (1 << dmach));
-
- return csr;
-}
-
-static int omap24xxcam_dmahw_running(unsigned long base, int dmach)
-{
- return omap24xxcam_reg_in(base, CAMDMA_CCR(dmach)) & CAMDMA_CCR_ENABLE;
-}
-
-static void omap24xxcam_dmahw_transfer_setup(unsigned long base, int dmach,
- dma_addr_t start, u32 len)
-{
- omap24xxcam_reg_out(base, CAMDMA_CCR(dmach),
- CAMDMA_CCR_SEL_SRC_DST_SYNC
- | CAMDMA_CCR_BS
- | CAMDMA_CCR_DST_AMODE_POST_INC
- | CAMDMA_CCR_SRC_AMODE_POST_INC
- | CAMDMA_CCR_FS
- | CAMDMA_CCR_WR_ACTIVE
- | CAMDMA_CCR_RD_ACTIVE
- | CAMDMA_CCR_SYNCHRO_CAMERA);
- omap24xxcam_reg_out(base, CAMDMA_CLNK_CTRL(dmach), 0);
- omap24xxcam_reg_out(base, CAMDMA_CEN(dmach), len);
- omap24xxcam_reg_out(base, CAMDMA_CFN(dmach), 1);
- omap24xxcam_reg_out(base, CAMDMA_CSDP(dmach),
- CAMDMA_CSDP_WRITE_MODE_POSTED
- | CAMDMA_CSDP_DST_BURST_EN_32
- | CAMDMA_CSDP_DST_PACKED
- | CAMDMA_CSDP_SRC_BURST_EN_32
- | CAMDMA_CSDP_SRC_PACKED
- | CAMDMA_CSDP_DATA_TYPE_8BITS);
- omap24xxcam_reg_out(base, CAMDMA_CSSA(dmach), 0);
- omap24xxcam_reg_out(base, CAMDMA_CDSA(dmach), start);
- omap24xxcam_reg_out(base, CAMDMA_CSEI(dmach), 0);
- omap24xxcam_reg_out(base, CAMDMA_CSFI(dmach), DMA_THRESHOLD);
- omap24xxcam_reg_out(base, CAMDMA_CDEI(dmach), 0);
- omap24xxcam_reg_out(base, CAMDMA_CDFI(dmach), 0);
- omap24xxcam_reg_out(base, CAMDMA_CSR(dmach),
- CAMDMA_CSR_MISALIGNED_ERR
- | CAMDMA_CSR_SECURE_ERR
- | CAMDMA_CSR_TRANS_ERR
- | CAMDMA_CSR_BLOCK
- | CAMDMA_CSR_DROP);
- omap24xxcam_reg_out(base, CAMDMA_CICR(dmach),
- CAMDMA_CICR_MISALIGNED_ERR_IE
- | CAMDMA_CICR_SECURE_ERR_IE
- | CAMDMA_CICR_TRANS_ERR_IE
- | CAMDMA_CICR_BLOCK_IE
- | CAMDMA_CICR_DROP_IE);
-}
-
-static void omap24xxcam_dmahw_transfer_start(unsigned long base, int dmach)
-{
- omap24xxcam_reg_out(base, CAMDMA_CCR(dmach),
- CAMDMA_CCR_SEL_SRC_DST_SYNC
- | CAMDMA_CCR_BS
- | CAMDMA_CCR_DST_AMODE_POST_INC
- | CAMDMA_CCR_SRC_AMODE_POST_INC
- | CAMDMA_CCR_ENABLE
- | CAMDMA_CCR_FS
- | CAMDMA_CCR_SYNCHRO_CAMERA);
-}
-
-static void omap24xxcam_dmahw_transfer_chain(unsigned long base, int dmach,
- int free_dmach)
-{
- int prev_dmach, ch;
-
- if (dmach == 0)
- prev_dmach = NUM_CAMDMA_CHANNELS - 1;
- else
- prev_dmach = dmach - 1;
- omap24xxcam_reg_out(base, CAMDMA_CLNK_CTRL(prev_dmach),
- CAMDMA_CLNK_CTRL_ENABLE_LNK | dmach);
- /* Did we chain the DMA transfer before the previous one
- * finished?
- */
- ch = (dmach + free_dmach) % NUM_CAMDMA_CHANNELS;
- while (!(omap24xxcam_reg_in(base, CAMDMA_CCR(ch))
- & CAMDMA_CCR_ENABLE)) {
- if (ch == dmach) {
- /* The previous transfer has ended and this one
- * hasn't started, so we must not have chained
- * to the previous one in time. We'll have to
- * start it now.
- */
- omap24xxcam_dmahw_transfer_start(base, dmach);
- break;
- } else
- ch = (ch + 1) % NUM_CAMDMA_CHANNELS;
- }
-}
-
-/* Abort all chained DMA transfers. After all transfers have been
- * aborted and the DMA controller is idle, the completion routines for
- * any aborted transfers will be called in sequence. The DMA
- * controller may not be idle after this routine completes, because
- * the completion routines might start new transfers.
- */
-static void omap24xxcam_dmahw_abort_ch(unsigned long base, int dmach)
-{
- /* mask all interrupts from this channel */
- omap24xxcam_reg_out(base, CAMDMA_CICR(dmach), 0);
- /* unlink this channel */
- omap24xxcam_reg_merge(base, CAMDMA_CLNK_CTRL(dmach), 0,
- CAMDMA_CLNK_CTRL_ENABLE_LNK);
- /* disable this channel */
- omap24xxcam_reg_merge(base, CAMDMA_CCR(dmach), 0, CAMDMA_CCR_ENABLE);
-}
-
-static void omap24xxcam_dmahw_init(unsigned long base)
-{
- omap24xxcam_reg_out(base, CAMDMA_OCP_SYSCONFIG,
- CAMDMA_OCP_SYSCONFIG_MIDLEMODE_FSTANDBY
- | CAMDMA_OCP_SYSCONFIG_SIDLEMODE_FIDLE
- | CAMDMA_OCP_SYSCONFIG_AUTOIDLE);
-
- omap24xxcam_reg_merge(base, CAMDMA_GCR, 0x10,
- CAMDMA_GCR_MAX_CHANNEL_FIFO_DEPTH);
-
- omap24xxcam_reg_out(base, CAMDMA_IRQENABLE_L0, 0xf);
-}
-
-/*
- *
- * Individual DMA channel handling.
- *
- */
-
-/* Start a DMA transfer from the camera to memory.
- * Returns zero if the transfer was successfully started, or non-zero if all
- * DMA channels are already in use or starting is currently inhibited.
- */
-static int omap24xxcam_dma_start(struct omap24xxcam_dma *dma, dma_addr_t start,
- u32 len, dma_callback_t callback, void *arg)
-{
- unsigned long flags;
- int dmach;
-
- spin_lock_irqsave(&dma->lock, flags);
-
- if (!dma->free_dmach || atomic_read(&dma->dma_stop)) {
- spin_unlock_irqrestore(&dma->lock, flags);
- return -EBUSY;
- }
-
- dmach = dma->next_dmach;
-
- dma->ch_state[dmach].callback = callback;
- dma->ch_state[dmach].arg = arg;
-
- omap24xxcam_dmahw_transfer_setup(dma->base, dmach, start, len);
-
- /* We're ready to start the DMA transfer. */
-
- if (dma->free_dmach < NUM_CAMDMA_CHANNELS) {
- /* A transfer is already in progress, so try to chain to it. */
- omap24xxcam_dmahw_transfer_chain(dma->base, dmach,
- dma->free_dmach);
- } else {
- /* No transfer is in progress, so we'll just start this one
- * now.
- */
- omap24xxcam_dmahw_transfer_start(dma->base, dmach);
- }
-
- dma->next_dmach = (dma->next_dmach + 1) % NUM_CAMDMA_CHANNELS;
- dma->free_dmach--;
-
- spin_unlock_irqrestore(&dma->lock, flags);
-
- return 0;
-}
-
-/* Abort all chained DMA transfers. After all transfers have been
- * aborted and the DMA controller is idle, the completion routines for
- * any aborted transfers will be called in sequence. The DMA
- * controller may not be idle after this routine completes, because
- * the completion routines might start new transfers.
- */
-static void omap24xxcam_dma_abort(struct omap24xxcam_dma *dma, u32 csr)
-{
- unsigned long flags;
- int dmach, i, free_dmach;
- dma_callback_t callback;
- void *arg;
-
- spin_lock_irqsave(&dma->lock, flags);
-
- /* stop any DMA transfers in progress */
- dmach = (dma->next_dmach + dma->free_dmach) % NUM_CAMDMA_CHANNELS;
- for (i = 0; i < NUM_CAMDMA_CHANNELS; i++) {
- omap24xxcam_dmahw_abort_ch(dma->base, dmach);
- dmach = (dmach + 1) % NUM_CAMDMA_CHANNELS;
- }
-
- /* We have to be careful here because the callback routine
- * might start a new DMA transfer, and we only want to abort
- * transfers that were started before this routine was called.
- */
- free_dmach = dma->free_dmach;
- while ((dma->free_dmach < NUM_CAMDMA_CHANNELS) &&
- (free_dmach < NUM_CAMDMA_CHANNELS)) {
- dmach = (dma->next_dmach + dma->free_dmach)
- % NUM_CAMDMA_CHANNELS;
- callback = dma->ch_state[dmach].callback;
- arg = dma->ch_state[dmach].arg;
- dma->free_dmach++;
- free_dmach++;
- if (callback) {
- /* leave interrupts disabled during callback */
- spin_unlock(&dma->lock);
- (*callback) (dma, csr, arg);
- spin_lock(&dma->lock);
- }
- }
-
- spin_unlock_irqrestore(&dma->lock, flags);
-}
-
-/* Abort all chained DMA transfers. After all transfers have been
- * aborted and the DMA controller is idle, the completion routines for
- * any aborted transfers will be called in sequence. If the completion
- * routines attempt to start a new DMA transfer it will fail, so the
- * DMA controller will be idle after this routine completes.
- */
-static void omap24xxcam_dma_stop(struct omap24xxcam_dma *dma, u32 csr)
-{
- atomic_inc(&dma->dma_stop);
- omap24xxcam_dma_abort(dma, csr);
- atomic_dec(&dma->dma_stop);
-}
-
-/* Camera DMA interrupt service routine. */
-void omap24xxcam_dma_isr(struct omap24xxcam_dma *dma)
-{
- int dmach;
- dma_callback_t callback;
- void *arg;
- u32 csr;
- const u32 csr_error = CAMDMA_CSR_MISALIGNED_ERR
- | CAMDMA_CSR_SUPERVISOR_ERR | CAMDMA_CSR_SECURE_ERR
- | CAMDMA_CSR_TRANS_ERR | CAMDMA_CSR_DROP;
-
- spin_lock(&dma->lock);
-
- if (dma->free_dmach == NUM_CAMDMA_CHANNELS) {
- /* A camera DMA interrupt occurred while all channels
- * are idle, so we'll acknowledge the interrupt in the
- * IRQSTATUS register and exit.
- */
- omap24xxcam_dmahw_ack_all(dma->base);
- spin_unlock(&dma->lock);
- return;
- }
-
- while (dma->free_dmach < NUM_CAMDMA_CHANNELS) {
- dmach = (dma->next_dmach + dma->free_dmach)
- % NUM_CAMDMA_CHANNELS;
- if (omap24xxcam_dmahw_running(dma->base, dmach)) {
- /* This buffer hasn't finished yet, so we're done. */
- break;
- }
- csr = omap24xxcam_dmahw_ack_ch(dma->base, dmach);
- if (csr & csr_error) {
- /* A DMA error occurred, so stop all DMA
- * transfers in progress.
- */
- spin_unlock(&dma->lock);
- omap24xxcam_dma_stop(dma, csr);
- return;
- } else {
- callback = dma->ch_state[dmach].callback;
- arg = dma->ch_state[dmach].arg;
- dma->free_dmach++;
- if (callback) {
- spin_unlock(&dma->lock);
- (*callback) (dma, csr, arg);
- spin_lock(&dma->lock);
- }
- }
- }
-
- spin_unlock(&dma->lock);
-
- omap24xxcam_sgdma_process(
- container_of(dma, struct omap24xxcam_sgdma, dma));
-}
-
-void omap24xxcam_dma_hwinit(const struct omap24xxcam_dma *dma)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&dma->lock, flags);
-
- omap24xxcam_dmahw_init(dma->base);
-
- spin_unlock_irqrestore(&dma->lock, flags);
-}
-
-static void omap24xxcam_dma_init(struct omap24xxcam_dma *dma,
- unsigned long base)
-{
- int ch;
-
- /* group all channels on DMA IRQ0 and unmask irq */
- spin_lock_init(&dma->lock);
- dma->base = base;
- dma->free_dmach = NUM_CAMDMA_CHANNELS;
- dma->next_dmach = 0;
- for (ch = 0; ch < NUM_CAMDMA_CHANNELS; ch++) {
- dma->ch_state[ch].callback = NULL;
- dma->ch_state[ch].arg = NULL;
- }
-}
-
-/*
- *
- * Scatter-gather DMA.
- *
- * High-level DMA construct for transferring whole picture frames to
- * memory that is discontinuous.
- *
- */
-
-/* DMA completion routine for the scatter-gather DMA fragments. */
-static void omap24xxcam_sgdma_callback(struct omap24xxcam_dma *dma, u32 csr,
- void *arg)
-{
- struct omap24xxcam_sgdma *sgdma =
- container_of(dma, struct omap24xxcam_sgdma, dma);
- int sgslot = (int)arg;
- struct sgdma_state *sg_state;
- const u32 csr_error = CAMDMA_CSR_MISALIGNED_ERR
- | CAMDMA_CSR_SUPERVISOR_ERR | CAMDMA_CSR_SECURE_ERR
- | CAMDMA_CSR_TRANS_ERR | CAMDMA_CSR_DROP;
-
- spin_lock(&sgdma->lock);
-
- /* We got an interrupt, we can remove the timer */
- del_timer(&sgdma->reset_timer);
-
- sg_state = sgdma->sg_state + sgslot;
- if (!sg_state->queued_sglist) {
- spin_unlock(&sgdma->lock);
- printk(KERN_ERR "%s: sgdma completed when none queued!\n",
- __FUNCTION__);
- return;
- }
-
- sg_state->csr |= csr;
- if (!--sg_state->queued_sglist) {
- /* Queue for this sglist is empty, so check to see if we're
- * done.
- */
- if ((sg_state->next_sglist == sg_state->sglen)
- || (sg_state->csr & csr_error)) {
- sgdma_callback_t callback = sg_state->callback;
- void *arg = sg_state->arg;
- u32 sg_csr = sg_state->csr;
- /* All done with this sglist */
- sgdma->free_sgdma++;
- if (callback) {
- spin_unlock(&sgdma->lock);
- (*callback) (sgdma, sg_csr, arg);
- return;
- }
- }
- }
-
- spin_unlock(&sgdma->lock);
-}
-
-/* Start queued scatter-gather DMA transfers. */
-void omap24xxcam_sgdma_process(struct omap24xxcam_sgdma *sgdma)
-{
- unsigned long flags;
- int queued_sgdma, sgslot;
- struct sgdma_state *sg_state;
- const u32 csr_error = CAMDMA_CSR_MISALIGNED_ERR
- | CAMDMA_CSR_SUPERVISOR_ERR | CAMDMA_CSR_SECURE_ERR
- | CAMDMA_CSR_TRANS_ERR | CAMDMA_CSR_DROP;
-
- spin_lock_irqsave(&sgdma->lock, flags);
-
- queued_sgdma = NUM_SG_DMA - sgdma->free_sgdma;
- sgslot = (sgdma->next_sgdma + sgdma->free_sgdma) % NUM_SG_DMA;
- while (queued_sgdma > 0) {
- sg_state = sgdma->sg_state + sgslot;
- while ((sg_state->next_sglist < sg_state->sglen) &&
- !(sg_state->csr & csr_error)) {
- const struct scatterlist *sglist;
- unsigned int len;
-
- sglist = sg_state->sglist + sg_state->next_sglist;
- /* try to start the next DMA transfer */
- if (sg_state->next_sglist + 1 == sg_state->sglen) {
- /*
- * On the last sg, we handle the case where
- * cam->img.pix.sizeimage % PAGE_ALIGN != 0
- */
- len = sg_state->len - sg_state->bytes_read;
- } else {
- len = sg_dma_len(sglist);
- }
-
- if (omap24xxcam_dma_start(&sgdma->dma,
- sg_dma_address(sglist),
- len,
- omap24xxcam_sgdma_callback,
- (void *)sgslot)) {
- /* DMA start failed */
- spin_unlock_irqrestore(&sgdma->lock, flags);
- return;
- } else {
- unsigned long expires;
- /* DMA start was successful */
- sg_state->next_sglist++;
- sg_state->bytes_read += len;
- sg_state->queued_sglist++;
-
- /* We start the reset timer */
- expires = jiffies + HZ;
- mod_timer(&sgdma->reset_timer, expires);
- }
- }
- queued_sgdma--;
- sgslot = (sgslot + 1) % NUM_SG_DMA;
- }
-
- spin_unlock_irqrestore(&sgdma->lock, flags);
-}
-
-/*
- * Queue a scatter-gather DMA transfer from the camera to memory.
- * Returns zero if the transfer was successfully queued, or non-zero
- * if all of the scatter-gather slots are already in use.
- */
-int omap24xxcam_sgdma_queue(struct omap24xxcam_sgdma *sgdma,
- const struct scatterlist *sglist, int sglen,
- int len, sgdma_callback_t callback, void *arg)
-{
- unsigned long flags;
- struct sgdma_state *sg_state;
-
- if ((sglen < 0) || ((sglen > 0) & !sglist))
- return -EINVAL;
-
- spin_lock_irqsave(&sgdma->lock, flags);
-
- if (!sgdma->free_sgdma) {
- spin_unlock_irqrestore(&sgdma->lock, flags);
- return -EBUSY;
- }
-
- sg_state = sgdma->sg_state + sgdma->next_sgdma;
-
- sg_state->sglist = sglist;
- sg_state->sglen = sglen;
- sg_state->next_sglist = 0;
- sg_state->bytes_read = 0;
- sg_state->len = len;
- sg_state->queued_sglist = 0;
- sg_state->csr = 0;
- sg_state->callback = callback;
- sg_state->arg = arg;
-
- sgdma->next_sgdma = (sgdma->next_sgdma + 1) % NUM_SG_DMA;
- sgdma->free_sgdma--;
-
- spin_unlock_irqrestore(&sgdma->lock, flags);
-
- omap24xxcam_sgdma_process(sgdma);
-
- return 0;
-}
-
-/* Sync scatter-gather DMA by aborting any DMA transfers currently in progress.
- * Any queued scatter-gather DMA transactions that have not yet been started
- * will remain queued. The DMA controller will be idle after this routine
- * completes. When the scatter-gather queue is restarted, the next
- * scatter-gather DMA transfer will begin at the start of a new transaction.
- */
-void omap24xxcam_sgdma_sync(struct omap24xxcam_sgdma *sgdma)
-{
- unsigned long flags;
- int sgslot;
- struct sgdma_state *sg_state;
- u32 csr = CAMDMA_CSR_TRANS_ERR;
-
- /* stop any DMA transfers in progress */
- omap24xxcam_dma_stop(&sgdma->dma, csr);
-
- spin_lock_irqsave(&sgdma->lock, flags);
-
- if (sgdma->free_sgdma < NUM_SG_DMA) {
- sgslot = (sgdma->next_sgdma + sgdma->free_sgdma) % NUM_SG_DMA;
- sg_state = sgdma->sg_state + sgslot;
- if (sg_state->next_sglist != 0) {
- /* This DMA transfer was in progress, so abort it. */
- sgdma_callback_t callback = sg_state->callback;
- void *arg = sg_state->arg;
- sgdma->free_sgdma++;
- if (callback) {
- /* leave interrupts masked */
- spin_unlock(&sgdma->lock);
- (*callback) (sgdma, csr, arg);
- spin_lock(&sgdma->lock);
- }
- }
- }
-
- spin_unlock_irqrestore(&sgdma->lock, flags);
-}
-
-void omap24xxcam_sgdma_init(struct omap24xxcam_sgdma *sgdma,
- unsigned long base,
- void (*reset_callback)(unsigned long data),
- unsigned long reset_callback_data)
-{
- int sg;
-
- spin_lock_init(&sgdma->lock);
- sgdma->free_sgdma = NUM_SG_DMA;
- sgdma->next_sgdma = 0;
- for (sg = 0; sg < NUM_SG_DMA; sg++) {
- sgdma->sg_state[sg].sglen = 0;
- sgdma->sg_state[sg].next_sglist = 0;
- sgdma->sg_state[sg].bytes_read = 0;
- sgdma->sg_state[sg].queued_sglist = 0;
- sgdma->sg_state[sg].csr = 0;
- sgdma->sg_state[sg].callback = NULL;
- sgdma->sg_state[sg].arg = NULL;
- }
-
- omap24xxcam_dma_init(&sgdma->dma, base);
- setup_timer(&sgdma->reset_timer, reset_callback, reset_callback_data);
-}
+++ /dev/null
-/*
- * drivers/media/video/omap24xxcam.c
- *
- * OMAP 2 camera block driver.
- *
- * Copyright (C) 2004 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- * Copyright (C) 2007-2008 Nokia Corporation.
- *
- * Contact: Sakari Ailus <sakari.ailus@nokia.com>
- *
- * Based on code from Andy Lowe <source@mvista.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/interrupt.h>
-#include <linux/videodev2.h>
-#include <linux/pci.h> /* needed for videobufs */
-#include <linux/version.h>
-#include <linux/platform_device.h>
-#include <linux/clk.h>
-#include <linux/io.h>
-
-#include <media/v4l2-common.h>
-#include <media/v4l2-ioctl.h>
-
-#include "omap24xxcam.h"
-
-#define OMAP24XXCAM_VERSION KERNEL_VERSION(0, 0, 0)
-
-#define RESET_TIMEOUT_NS 10000
-
-static void omap24xxcam_reset(struct omap24xxcam_device *cam);
-static int omap24xxcam_sensor_if_enable(struct omap24xxcam_device *cam);
-static void omap24xxcam_device_unregister(struct v4l2_int_device *s);
-static int omap24xxcam_remove(struct platform_device *pdev);
-
-/* module parameters */
-static int video_nr = -1; /* video device minor (-1 ==> auto assign) */
-/*
- * Maximum amount of memory to use for capture buffers.
- * Default is 4800KB, enough to double-buffer SXGA.
- */
-static int capture_mem = 1280 * 960 * 2 * 2;
-
-static struct v4l2_int_device omap24xxcam;
-
-/*
- *
- * Clocks.
- *
- */
-
-static void omap24xxcam_clock_put(struct omap24xxcam_device *cam)
-{
- if (cam->ick != NULL && !IS_ERR(cam->ick))
- clk_put(cam->ick);
- if (cam->fck != NULL && !IS_ERR(cam->fck))
- clk_put(cam->fck);
-
- cam->ick = cam->fck = NULL;
-}
-
-static int omap24xxcam_clock_get(struct omap24xxcam_device *cam)
-{
- int rval = 0;
-
- cam->fck = clk_get(cam->dev, "cam_fck");
- if (IS_ERR(cam->fck)) {
- dev_err(cam->dev, "can't get cam_fck");
- rval = PTR_ERR(cam->fck);
- omap24xxcam_clock_put(cam);
- return rval;
- }
-
- cam->ick = clk_get(cam->dev, "cam_ick");
- if (IS_ERR(cam->ick)) {
- dev_err(cam->dev, "can't get cam_ick");
- rval = PTR_ERR(cam->ick);
- omap24xxcam_clock_put(cam);
- }
-
- return rval;
-}
-
-static void omap24xxcam_clock_on(struct omap24xxcam_device *cam)
-{
- clk_enable(cam->fck);
- clk_enable(cam->ick);
-}
-
-static void omap24xxcam_clock_off(struct omap24xxcam_device *cam)
-{
- clk_disable(cam->fck);
- clk_disable(cam->ick);
-}
-
-/*
- *
- * Camera core
- *
- */
-
-/*
- * Set xclk.
- *
- * To disable xclk, use value zero.
- */
-static void omap24xxcam_core_xclk_set(const struct omap24xxcam_device *cam,
- u32 xclk)
-{
- if (xclk) {
- u32 divisor = CAM_MCLK / xclk;
-
- if (divisor == 1)
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET,
- CC_CTRL_XCLK,
- CC_CTRL_XCLK_DIV_BYPASS);
- else
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET,
- CC_CTRL_XCLK, divisor);
- } else
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET,
- CC_CTRL_XCLK, CC_CTRL_XCLK_DIV_STABLE_LOW);
-}
-
-static void omap24xxcam_core_hwinit(const struct omap24xxcam_device *cam)
-{
- /*
- * Setting the camera core AUTOIDLE bit causes problems with frame
- * synchronization, so we will clear the AUTOIDLE bit instead.
- */
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_SYSCONFIG,
- CC_SYSCONFIG_AUTOIDLE);
-
- /* program the camera interface DMA packet size */
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL_DMA,
- CC_CTRL_DMA_EN | (DMA_THRESHOLD / 4 - 1));
-
- /* enable camera core error interrupts */
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_IRQENABLE,
- CC_IRQENABLE_FW_ERR_IRQ
- | CC_IRQENABLE_FSC_ERR_IRQ
- | CC_IRQENABLE_SSC_ERR_IRQ
- | CC_IRQENABLE_FIFO_OF_IRQ);
-}
-
-/*
- * Enable the camera core.
- *
- * Data transfer to the camera DMA starts from next starting frame.
- */
-static void omap24xxcam_core_enable(const struct omap24xxcam_device *cam)
-{
-
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL,
- cam->cc_ctrl);
-}
-
-/*
- * Disable camera core.
- *
- * The data transfer will be stopped immediately (CC_CTRL_CC_RST). The
- * core internal state machines will be reset. Use
- * CC_CTRL_CC_FRAME_TRIG instead if you want to transfer the current
- * frame completely.
- */
-static void omap24xxcam_core_disable(const struct omap24xxcam_device *cam)
-{
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL,
- CC_CTRL_CC_RST);
-}
-
-/* Interrupt service routine for camera core interrupts. */
-static void omap24xxcam_core_isr(struct omap24xxcam_device *cam)
-{
- u32 cc_irqstatus;
- const u32 cc_irqstatus_err =
- CC_IRQSTATUS_FW_ERR_IRQ
- | CC_IRQSTATUS_FSC_ERR_IRQ
- | CC_IRQSTATUS_SSC_ERR_IRQ
- | CC_IRQSTATUS_FIFO_UF_IRQ
- | CC_IRQSTATUS_FIFO_OF_IRQ;
-
- cc_irqstatus = omap24xxcam_reg_in(cam->mmio_base + CC_REG_OFFSET,
- CC_IRQSTATUS);
- omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_IRQSTATUS,
- cc_irqstatus);
-
- if (cc_irqstatus & cc_irqstatus_err
- && !atomic_read(&cam->in_reset)) {
- dev_dbg(cam->dev, "resetting camera, cc_irqstatus 0x%x\n",
- cc_irqstatus);
- omap24xxcam_reset(cam);
- }
-}
-
-/*
- *
- * videobuf_buffer handling.
- *
- * Memory for mmapped videobuf_buffers is not allocated
- * conventionally, but by several kmalloc allocations and then
- * creating the scatterlist on our own. User-space buffers are handled
- * normally.
- *
- */
-
-/*
- * Free the memory-mapped buffer memory allocated for a
- * videobuf_buffer and the associated scatterlist.
- */
-static void omap24xxcam_vbq_free_mmap_buffer(struct videobuf_buffer *vb)
-{
- struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
- size_t alloc_size;
- struct page *page;
- int i;
-
- if (dma->sglist == NULL)
- return;
-
- i = dma->sglen;
- while (i) {
- i--;
- alloc_size = sg_dma_len(&dma->sglist[i]);
- page = sg_page(&dma->sglist[i]);
- do {
- ClearPageReserved(page++);
- } while (alloc_size -= PAGE_SIZE);
- __free_pages(sg_page(&dma->sglist[i]),
- get_order(sg_dma_len(&dma->sglist[i])));
- }
-
- kfree(dma->sglist);
- dma->sglist = NULL;
-}
-
-/* Release all memory related to the videobuf_queue. */
-static void omap24xxcam_vbq_free_mmap_buffers(struct videobuf_queue *vbq)
-{
- int i;
-
- mutex_lock(&vbq->vb_lock);
-
- for (i = 0; i < VIDEO_MAX_FRAME; i++) {
- if (NULL == vbq->bufs[i])
- continue;
- if (V4L2_MEMORY_MMAP != vbq->bufs[i]->memory)
- continue;
- vbq->ops->buf_release(vbq, vbq->bufs[i]);
- omap24xxcam_vbq_free_mmap_buffer(vbq->bufs[i]);
- kfree(vbq->bufs[i]);
- vbq->bufs[i] = NULL;
- }
-
- mutex_unlock(&vbq->vb_lock);
-
- videobuf_mmap_free(vbq);
-}
-
-/*
- * Allocate physically as contiguous as possible buffer for video
- * frame and allocate and build DMA scatter-gather list for it.
- */
-static int omap24xxcam_vbq_alloc_mmap_buffer(struct videobuf_buffer *vb)
-{
- unsigned int order;
- size_t alloc_size, size = vb->bsize; /* vb->bsize is page aligned */
- struct page *page;
- int max_pages, err = 0, i = 0;
- struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
-
- /*
- * allocate maximum size scatter-gather list. Note this is
- * overhead. We may not use as many entries as we allocate
- */
- max_pages = vb->bsize >> PAGE_SHIFT;
- dma->sglist = kcalloc(max_pages, sizeof(*dma->sglist), GFP_KERNEL);
- if (dma->sglist == NULL) {
- err = -ENOMEM;
- goto out;
- }
-
- while (size) {
- order = get_order(size);
- /*
- * do not over-allocate even if we would get larger
- * contiguous chunk that way
- */
- if ((PAGE_SIZE << order) > size)
- order--;
-
- /* try to allocate as many contiguous pages as possible */
- page = alloc_pages(GFP_KERNEL | GFP_DMA, order);
- /* if allocation fails, try to allocate smaller amount */
- while (page == NULL) {
- order--;
- page = alloc_pages(GFP_KERNEL | GFP_DMA, order);
- if (page == NULL && !order) {
- err = -ENOMEM;
- goto out;
- }
- }
- size -= (PAGE_SIZE << order);
-
- /* append allocated chunk of pages into scatter-gather list */
- sg_set_page(&dma->sglist[i], page, PAGE_SIZE << order, 0);
- dma->sglen++;
- i++;
-
- alloc_size = (PAGE_SIZE << order);
-
- /* clear pages before giving them to user space */
- memset(page_address(page), 0, alloc_size);
-
- /* mark allocated pages reserved */
- do {
- SetPageReserved(page++);
- } while (alloc_size -= PAGE_SIZE);
- }
- /*
- * REVISIT: not fully correct to assign nr_pages == sglen but
- * video-buf is passing nr_pages for e.g. unmap_sg calls
- */
- dma->nr_pages = dma->sglen;
- dma->direction = PCI_DMA_FROMDEVICE;
-
- return 0;
-
-out:
- omap24xxcam_vbq_free_mmap_buffer(vb);
- return err;
-}
-
-static int omap24xxcam_vbq_alloc_mmap_buffers(struct videobuf_queue *vbq,
- unsigned int count)
-{
- int i, err = 0;
- struct omap24xxcam_fh *fh =
- container_of(vbq, struct omap24xxcam_fh, vbq);
-
- mutex_lock(&vbq->vb_lock);
-
- for (i = 0; i < count; i++) {
- err = omap24xxcam_vbq_alloc_mmap_buffer(vbq->bufs[i]);
- if (err)
- goto out;
- dev_dbg(fh->cam->dev, "sglen is %d for buffer %d\n",
- videobuf_to_dma(vbq->bufs[i])->sglen, i);
- }
-
- mutex_unlock(&vbq->vb_lock);
-
- return 0;
-out:
- while (i) {
- i--;
- omap24xxcam_vbq_free_mmap_buffer(vbq->bufs[i]);
- }
-
- mutex_unlock(&vbq->vb_lock);
-
- return err;
-}
-
-/*
- * This routine is called from interrupt context when a scatter-gather DMA
- * transfer of a videobuf_buffer completes.
- */
-static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
- u32 csr, void *arg)
-{
- struct omap24xxcam_device *cam =
- container_of(sgdma, struct omap24xxcam_device, sgdma);
- struct omap24xxcam_fh *fh = cam->streaming->private_data;
- struct videobuf_buffer *vb = (struct videobuf_buffer *)arg;
- const u32 csr_error = CAMDMA_CSR_MISALIGNED_ERR
- | CAMDMA_CSR_SUPERVISOR_ERR | CAMDMA_CSR_SECURE_ERR
- | CAMDMA_CSR_TRANS_ERR | CAMDMA_CSR_DROP;
- unsigned long flags;
-
- spin_lock_irqsave(&cam->core_enable_disable_lock, flags);
- if (--cam->sgdma_in_queue == 0)
- omap24xxcam_core_disable(cam);
- spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
-
- do_gettimeofday(&vb->ts);
- vb->field_count = atomic_add_return(2, &fh->field_count);
- if (csr & csr_error) {
- vb->state = VIDEOBUF_ERROR;
- if (!atomic_read(&fh->cam->in_reset)) {
- dev_dbg(cam->dev, "resetting camera, csr 0x%x\n", csr);
- omap24xxcam_reset(cam);
- }
- } else
- vb->state = VIDEOBUF_DONE;
- wake_up(&vb->done);
-}
-
-static void omap24xxcam_vbq_release(struct videobuf_queue *vbq,
- struct videobuf_buffer *vb)
-{
- struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
-
- /* wait for buffer, especially to get out of the sgdma queue */
- videobuf_waiton(vb, 0, 0);
- if (vb->memory == V4L2_MEMORY_MMAP) {
- dma_unmap_sg(vbq->dev, dma->sglist, dma->sglen,
- dma->direction);
- dma->direction = DMA_NONE;
- } else {
- videobuf_dma_unmap(vbq, videobuf_to_dma(vb));
- videobuf_dma_free(videobuf_to_dma(vb));
- }
-
- vb->state = VIDEOBUF_NEEDS_INIT;
-}
-
-/*
- * Limit the number of available kernel image capture buffers based on the
- * number requested, the currently selected image size, and the maximum
- * amount of memory permitted for kernel capture buffers.
- */
-static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt,
- unsigned int *size)
-{
- struct omap24xxcam_fh *fh = vbq->priv_data;
-
- if (*cnt <= 0)
- *cnt = VIDEO_MAX_FRAME; /* supply a default number of buffers */
-
- if (*cnt > VIDEO_MAX_FRAME)
- *cnt = VIDEO_MAX_FRAME;
-
- *size = fh->pix.sizeimage;
-
- /* accessing fh->cam->capture_mem is ok, it's constant */
- while (*size * *cnt > fh->cam->capture_mem)
- (*cnt)--;
-
- return 0;
-}
-
-static int omap24xxcam_dma_iolock(struct videobuf_queue *vbq,
- struct videobuf_dmabuf *dma)
-{
- int err = 0;
-
- dma->direction = PCI_DMA_FROMDEVICE;
- if (!dma_map_sg(vbq->dev, dma->sglist, dma->sglen, dma->direction)) {
- kfree(dma->sglist);
- dma->sglist = NULL;
- dma->sglen = 0;
- err = -EIO;
- }
-
- return err;
-}
-
-static int omap24xxcam_vbq_prepare(struct videobuf_queue *vbq,
- struct videobuf_buffer *vb,
- enum v4l2_field field)
-{
- struct omap24xxcam_fh *fh = vbq->priv_data;
- int err = 0;
-
- /*
- * Accessing pix here is okay since it's constant while
- * streaming is on (and we only get called then).
- */
- if (vb->baddr) {
- /* This is a userspace buffer. */
- if (fh->pix.sizeimage > vb->bsize) {
- /* The buffer isn't big enough. */
- err = -EINVAL;
- } else
- vb->size = fh->pix.sizeimage;
- } else {
- if (vb->state != VIDEOBUF_NEEDS_INIT) {
- /*
- * We have a kernel bounce buffer that has
- * already been allocated.
- */
- if (fh->pix.sizeimage > vb->size) {
- /*
- * The image size has been changed to
- * a larger size since this buffer was
- * allocated, so we need to free and
- * reallocate it.
- */
- omap24xxcam_vbq_release(vbq, vb);
- vb->size = fh->pix.sizeimage;
- }
- } else {
- /* We need to allocate a new kernel bounce buffer. */
- vb->size = fh->pix.sizeimage;
- }
- }
-
- if (err)
- return err;
-
- vb->width = fh->pix.width;
- vb->height = fh->pix.height;
- vb->field = field;
-
- if (vb->state == VIDEOBUF_NEEDS_INIT) {
- if (vb->memory == V4L2_MEMORY_MMAP)
- /*
- * we have built the scatter-gather list by ourself so
- * do the scatter-gather mapping as well
- */
- err = omap24xxcam_dma_iolock(vbq, videobuf_to_dma(vb));
- else
- err = videobuf_iolock(vbq, vb, NULL);
- }
-
- if (!err)
- vb->state = VIDEOBUF_PREPARED;
- else
- omap24xxcam_vbq_release(vbq, vb);
-
- return err;
-}
-
-static void omap24xxcam_vbq_queue(struct videobuf_queue *vbq,
- struct videobuf_buffer *vb)
-{
- struct omap24xxcam_fh *fh = vbq->priv_data;
- struct omap24xxcam_device *cam = fh->cam;
- enum videobuf_state state = vb->state;
- unsigned long flags;
- int err;
-
- /*
- * FIXME: We're marking the buffer active since we have no
- * pretty way of marking it active exactly when the
- * scatter-gather transfer starts.
- */
- vb->state = VIDEOBUF_ACTIVE;
-
- err = omap24xxcam_sgdma_queue(&fh->cam->sgdma,
- videobuf_to_dma(vb)->sglist,
- videobuf_to_dma(vb)->sglen, vb->size,
- omap24xxcam_vbq_complete, vb);
-
- if (!err) {
- spin_lock_irqsave(&cam->core_enable_disable_lock, flags);
- if (++cam->sgdma_in_queue == 1
- && !atomic_read(&cam->in_reset))
- omap24xxcam_core_enable(cam);
- spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
- } else {
- /*
- * Oops. We're not supposed to get any errors here.
- * The only way we could get an error is if we ran out
- * of scatter-gather DMA slots, but we are supposed to
- * have at least as many scatter-gather DMA slots as
- * video buffers so that can't happen.
- */
- dev_err(cam->dev, "failed to queue a video buffer for dma!\n");
- dev_err(cam->dev, "likely a bug in the driver!\n");
- vb->state = state;
- }
-}
-
-static struct videobuf_queue_ops omap24xxcam_vbq_ops = {
- .buf_setup = omap24xxcam_vbq_setup,
- .buf_prepare = omap24xxcam_vbq_prepare,
- .buf_queue = omap24xxcam_vbq_queue,
- .buf_release = omap24xxcam_vbq_release,
-};
-
-/*
- *
- * OMAP main camera system
- *
- */
-
-/*
- * Reset camera block to power-on state.
- */
-static void omap24xxcam_poweron_reset(const struct omap24xxcam_device *cam)
-{
- int max_loop = RESET_TIMEOUT_NS;
-
- /* Reset whole camera subsystem */
- omap24xxcam_reg_out(cam->mmio_base,
- CAM_SYSCONFIG,
- CAM_SYSCONFIG_SOFTRESET);
-
- /* Wait till it's finished */
- while (!(omap24xxcam_reg_in(cam->mmio_base, CAM_SYSSTATUS)
- & CAM_SYSSTATUS_RESETDONE)
- && --max_loop) {
- ndelay(1);
- }
-
- if (!(omap24xxcam_reg_in(cam->mmio_base, CAM_SYSSTATUS)
- & CAM_SYSSTATUS_RESETDONE))
- dev_err(cam->dev, "camera soft reset timeout\n");
-}
-
-/*
- * (Re)initialise the camera block.
- */
-static void omap24xxcam_hwinit(const struct omap24xxcam_device *cam)
-{
- omap24xxcam_poweron_reset(cam);
-
- /* set the camera subsystem autoidle bit */
- omap24xxcam_reg_out(cam->mmio_base, CAM_SYSCONFIG,
- CAM_SYSCONFIG_AUTOIDLE);
-
- /* set the camera MMU autoidle bit */
- omap24xxcam_reg_out(cam->mmio_base,
- CAMMMU_REG_OFFSET + CAMMMU_SYSCONFIG,
- CAMMMU_SYSCONFIG_AUTOIDLE);
-
- omap24xxcam_core_hwinit(cam);
-
- omap24xxcam_dma_hwinit(&cam->sgdma.dma);
-}
-
-/*
- * Callback for dma transfer stalling.
- */
-static void omap24xxcam_stalled_dma_reset(unsigned long data)
-{
- struct omap24xxcam_device *cam = (struct omap24xxcam_device *)data;
-
- if (!atomic_read(&cam->in_reset)) {
- dev_dbg(cam->dev, "dma stalled, resetting camera\n");
- omap24xxcam_reset(cam);
- }
-}
-
-/*
- * Stop capture. Mark we're doing a reset, stop DMA transfers and
- * core. (No new scatter-gather transfers will be queued whilst
- * in_reset is non-zero.)
- *
- * If omap24xxcam_capture_stop is called from several places at
- * once, only the first call will have an effect. Similarly, the last
- * call omap24xxcam_streaming_cont will have effect.
- *
- * Serialisation is ensured by using cam->core_enable_disable_lock.
- */
-static void omap24xxcam_capture_stop(struct omap24xxcam_device *cam)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&cam->core_enable_disable_lock, flags);
-
- if (atomic_inc_return(&cam->in_reset) != 1) {
- spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
- return;
- }
-
- omap24xxcam_core_disable(cam);
-
- spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
-
- omap24xxcam_sgdma_sync(&cam->sgdma);
-}
-
-/*
- * Reset and continue streaming.
- *
- * Note: Resetting the camera FIFO via the CC_RST bit in the CC_CTRL
- * register is supposed to be sufficient to recover from a camera
- * interface error, but it doesn't seem to be enough. If we only do
- * that then subsequent image captures are out of sync by either one
- * or two times DMA_THRESHOLD bytes. Resetting and re-initializing the
- * entire camera subsystem prevents the problem with frame
- * synchronization.
- */
-static void omap24xxcam_capture_cont(struct omap24xxcam_device *cam)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&cam->core_enable_disable_lock, flags);
-
- if (atomic_read(&cam->in_reset) != 1)
- goto out;
-
- omap24xxcam_hwinit(cam);
-
- omap24xxcam_sensor_if_enable(cam);
-
- omap24xxcam_sgdma_process(&cam->sgdma);
-
- if (cam->sgdma_in_queue)
- omap24xxcam_core_enable(cam);
-
-out:
- atomic_dec(&cam->in_reset);
- spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
-}
-
-static ssize_t
-omap24xxcam_streaming_show(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- struct omap24xxcam_device *cam = dev_get_drvdata(dev);
-
- return sprintf(buf, "%s\n", cam->streaming ? "active" : "inactive");
-}
-static DEVICE_ATTR(streaming, S_IRUGO, omap24xxcam_streaming_show, NULL);
-
-/*
- * Stop capture and restart it. I.e. reset the camera during use.
- */
-static void omap24xxcam_reset(struct omap24xxcam_device *cam)
-{
- omap24xxcam_capture_stop(cam);
- omap24xxcam_capture_cont(cam);
-}
-
-/*
- * The main interrupt handler.
- */
-static irqreturn_t omap24xxcam_isr(int irq, void *arg)
-{
- struct omap24xxcam_device *cam = (struct omap24xxcam_device *)arg;
- u32 irqstatus;
- unsigned int irqhandled = 0;
-
- irqstatus = omap24xxcam_reg_in(cam->mmio_base, CAM_IRQSTATUS);
-
- if (irqstatus &
- (CAM_IRQSTATUS_DMA_IRQ2 | CAM_IRQSTATUS_DMA_IRQ1
- | CAM_IRQSTATUS_DMA_IRQ0)) {
- omap24xxcam_dma_isr(&cam->sgdma.dma);
- irqhandled = 1;
- }
- if (irqstatus & CAM_IRQSTATUS_CC_IRQ) {
- omap24xxcam_core_isr(cam);
- irqhandled = 1;
- }
- if (irqstatus & CAM_IRQSTATUS_MMU_IRQ)
- dev_err(cam->dev, "unhandled camera MMU interrupt!\n");
-
- return IRQ_RETVAL(irqhandled);
-}
-
-/*
- *
- * Sensor handling.
- *
- */
-
-/*
- * Enable the external sensor interface. Try to negotiate interface
- * parameters with the sensor and start using the new ones. The calls
- * to sensor_if_enable and sensor_if_disable need not to be balanced.
- */
-static int omap24xxcam_sensor_if_enable(struct omap24xxcam_device *cam)
-{
- int rval;
- struct v4l2_ifparm p;
-
- rval = vidioc_int_g_ifparm(cam->sdev, &p);
- if (rval) {
- dev_err(cam->dev, "vidioc_int_g_ifparm failed with %d\n", rval);
- return rval;
- }
-
- cam->if_type = p.if_type;
-
- cam->cc_ctrl = CC_CTRL_CC_EN;
-
- switch (p.if_type) {
- case V4L2_IF_TYPE_BT656:
- if (p.u.bt656.frame_start_on_rising_vs)
- cam->cc_ctrl |= CC_CTRL_NOBT_SYNCHRO;
- if (p.u.bt656.bt_sync_correct)
- cam->cc_ctrl |= CC_CTRL_BT_CORRECT;
- if (p.u.bt656.swap)
- cam->cc_ctrl |= CC_CTRL_PAR_ORDERCAM;
- if (p.u.bt656.latch_clk_inv)
- cam->cc_ctrl |= CC_CTRL_PAR_CLK_POL;
- if (p.u.bt656.nobt_hs_inv)
- cam->cc_ctrl |= CC_CTRL_NOBT_HS_POL;
- if (p.u.bt656.nobt_vs_inv)
- cam->cc_ctrl |= CC_CTRL_NOBT_VS_POL;
-
- switch (p.u.bt656.mode) {
- case V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT:
- cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT8;
- break;
- case V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT:
- cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT10;
- break;
- case V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT:
- cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT12;
- break;
- case V4L2_IF_TYPE_BT656_MODE_BT_8BIT:
- cam->cc_ctrl |= CC_CTRL_PAR_MODE_BT8;
- break;
- case V4L2_IF_TYPE_BT656_MODE_BT_10BIT:
- cam->cc_ctrl |= CC_CTRL_PAR_MODE_BT10;
- break;
- default:
- dev_err(cam->dev,
- "bt656 interface mode %d not supported\n",
- p.u.bt656.mode);
- return -EINVAL;
- }
- /*
- * The clock rate that the sensor wants has changed.
- * We have to adjust the xclk from OMAP 2 side to
- * match the sensor's wish as closely as possible.
- */
- if (p.u.bt656.clock_curr != cam->if_u.bt656.xclk) {
- u32 xclk = p.u.bt656.clock_curr;
- u32 divisor;
-
- if (xclk == 0)
- return -EINVAL;
-
- if (xclk > CAM_MCLK)
- xclk = CAM_MCLK;
-
- divisor = CAM_MCLK / xclk;
- if (divisor * xclk < CAM_MCLK)
- divisor++;
- if (CAM_MCLK / divisor < p.u.bt656.clock_min
- && divisor > 1)
- divisor--;
- if (divisor > 30)
- divisor = 30;
-
- xclk = CAM_MCLK / divisor;
-
- if (xclk < p.u.bt656.clock_min
- || xclk > p.u.bt656.clock_max)
- return -EINVAL;
-
- cam->if_u.bt656.xclk = xclk;
- }
- omap24xxcam_core_xclk_set(cam, cam->if_u.bt656.xclk);
- break;
- default:
- /* FIXME: how about other interfaces? */
- dev_err(cam->dev, "interface type %d not supported\n",
- p.if_type);
- return -EINVAL;
- }
-
- return 0;
-}
-
-static void omap24xxcam_sensor_if_disable(const struct omap24xxcam_device *cam)
-{
- switch (cam->if_type) {
- case V4L2_IF_TYPE_BT656:
- omap24xxcam_core_xclk_set(cam, 0);
- break;
- }
-}
-
-/*
- * Initialise the sensor hardware.
- */
-static int omap24xxcam_sensor_init(struct omap24xxcam_device *cam)
-{
- int err = 0;
- struct v4l2_int_device *sdev = cam->sdev;
-
- omap24xxcam_clock_on(cam);
- err = omap24xxcam_sensor_if_enable(cam);
- if (err) {
- dev_err(cam->dev, "sensor interface could not be enabled at "
- "initialisation, %d\n", err);
- cam->sdev = NULL;
- goto out;
- }
-
- /* power up sensor during sensor initialization */
- vidioc_int_s_power(sdev, 1);
-
- err = vidioc_int_dev_init(sdev);
- if (err) {
- dev_err(cam->dev, "cannot initialize sensor, error %d\n", err);
- /* Sensor init failed --- it's nonexistent to us! */
- cam->sdev = NULL;
- goto out;
- }
-
- dev_info(cam->dev, "sensor is %s\n", sdev->name);
-
-out:
- omap24xxcam_sensor_if_disable(cam);
- omap24xxcam_clock_off(cam);
-
- vidioc_int_s_power(sdev, 0);
-
- return err;
-}
-
-static void omap24xxcam_sensor_exit(struct omap24xxcam_device *cam)
-{
- if (cam->sdev)
- vidioc_int_dev_exit(cam->sdev);
-}
-
-static void omap24xxcam_sensor_disable(struct omap24xxcam_device *cam)
-{
- omap24xxcam_sensor_if_disable(cam);
- omap24xxcam_clock_off(cam);
- vidioc_int_s_power(cam->sdev, 0);
-}
-
-/*
- * Power-up and configure camera sensor. It's ready for capturing now.
- */
-static int omap24xxcam_sensor_enable(struct omap24xxcam_device *cam)
-{
- int rval;
-
- omap24xxcam_clock_on(cam);
-
- omap24xxcam_sensor_if_enable(cam);
-
- rval = vidioc_int_s_power(cam->sdev, 1);
- if (rval)
- goto out;
-
- rval = vidioc_int_init(cam->sdev);
- if (rval)
- goto out;
-
- return 0;
-
-out:
- omap24xxcam_sensor_disable(cam);
-
- return rval;
-}
-
-static void omap24xxcam_sensor_reset_work(struct work_struct *work)
-{
- struct omap24xxcam_device *cam =
- container_of(work, struct omap24xxcam_device,
- sensor_reset_work);
-
- if (atomic_read(&cam->reset_disable))
- return;
-
- omap24xxcam_capture_stop(cam);
-
- if (vidioc_int_reset(cam->sdev) == 0) {
- vidioc_int_init(cam->sdev);
- } else {
- /* Can't reset it by vidioc_int_reset. */
- omap24xxcam_sensor_disable(cam);
- omap24xxcam_sensor_enable(cam);
- }
-
- omap24xxcam_capture_cont(cam);
-}
-
-/*
- *
- * IOCTL interface.
- *
- */
-
-static int vidioc_querycap(struct file *file, void *fh,
- struct v4l2_capability *cap)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
-
- strlcpy(cap->driver, CAM_NAME, sizeof(cap->driver));
- strlcpy(cap->card, cam->vfd->name, sizeof(cap->card));
- cap->version = OMAP24XXCAM_VERSION;
- cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
-
- return 0;
-}
-
-static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh,
- struct v4l2_fmtdesc *f)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- rval = vidioc_int_enum_fmt_cap(cam->sdev, f);
-
- return rval;
-}
-
-static int vidioc_g_fmt_vid_cap(struct file *file, void *fh,
- struct v4l2_format *f)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- rval = vidioc_int_g_fmt_cap(cam->sdev, f);
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_s_fmt_vid_cap(struct file *file, void *fh,
- struct v4l2_format *f)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming) {
- rval = -EBUSY;
- goto out;
- }
-
- rval = vidioc_int_s_fmt_cap(cam->sdev, f);
-
-out:
- mutex_unlock(&cam->mutex);
-
- if (!rval) {
- mutex_lock(&ofh->vbq.vb_lock);
- ofh->pix = f->fmt.pix;
- mutex_unlock(&ofh->vbq.vb_lock);
- }
-
- memset(f, 0, sizeof(*f));
- vidioc_g_fmt_vid_cap(file, fh, f);
-
- return rval;
-}
-
-static int vidioc_try_fmt_vid_cap(struct file *file, void *fh,
- struct v4l2_format *f)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- rval = vidioc_int_try_fmt_cap(cam->sdev, f);
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_reqbufs(struct file *file, void *fh,
- struct v4l2_requestbuffers *b)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming) {
- mutex_unlock(&cam->mutex);
- return -EBUSY;
- }
-
- omap24xxcam_vbq_free_mmap_buffers(&ofh->vbq);
- mutex_unlock(&cam->mutex);
-
- rval = videobuf_reqbufs(&ofh->vbq, b);
-
- /*
- * Either videobuf_reqbufs failed or the buffers are not
- * memory-mapped (which would need special attention).
- */
- if (rval < 0 || b->memory != V4L2_MEMORY_MMAP)
- goto out;
-
- rval = omap24xxcam_vbq_alloc_mmap_buffers(&ofh->vbq, rval);
- if (rval)
- omap24xxcam_vbq_free_mmap_buffers(&ofh->vbq);
-
-out:
- return rval;
-}
-
-static int vidioc_querybuf(struct file *file, void *fh,
- struct v4l2_buffer *b)
-{
- struct omap24xxcam_fh *ofh = fh;
-
- return videobuf_querybuf(&ofh->vbq, b);
-}
-
-static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
-{
- struct omap24xxcam_fh *ofh = fh;
-
- return videobuf_qbuf(&ofh->vbq, b);
-}
-
-static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- struct videobuf_buffer *vb;
- int rval;
-
-videobuf_dqbuf_again:
- rval = videobuf_dqbuf(&ofh->vbq, b, file->f_flags & O_NONBLOCK);
- if (rval)
- goto out;
-
- vb = ofh->vbq.bufs[b->index];
-
- mutex_lock(&cam->mutex);
- /* _needs_reset returns -EIO if reset is required. */
- rval = vidioc_int_g_needs_reset(cam->sdev, (void *)vb->baddr);
- mutex_unlock(&cam->mutex);
- if (rval == -EIO)
- schedule_work(&cam->sensor_reset_work);
- else
- rval = 0;
-
-out:
- /*
- * This is a hack. We don't want to show -EIO to the user
- * space. Requeue the buffer and try again if we're not doing
- * this in non-blocking mode.
- */
- if (rval == -EIO) {
- videobuf_qbuf(&ofh->vbq, b);
- if (!(file->f_flags & O_NONBLOCK))
- goto videobuf_dqbuf_again;
- /*
- * We don't have a videobuf_buffer now --- maybe next
- * time...
- */
- rval = -EAGAIN;
- }
-
- return rval;
-}
-
-static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming) {
- rval = -EBUSY;
- goto out;
- }
-
- rval = omap24xxcam_sensor_if_enable(cam);
- if (rval) {
- dev_dbg(cam->dev, "vidioc_int_g_ifparm failed\n");
- goto out;
- }
-
- rval = videobuf_streamon(&ofh->vbq);
- if (!rval) {
- cam->streaming = file;
- sysfs_notify(&cam->dev->kobj, NULL, "streaming");
- }
-
-out:
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- struct videobuf_queue *q = &ofh->vbq;
- int rval;
-
- atomic_inc(&cam->reset_disable);
-
- flush_scheduled_work();
-
- rval = videobuf_streamoff(q);
- if (!rval) {
- mutex_lock(&cam->mutex);
- cam->streaming = NULL;
- mutex_unlock(&cam->mutex);
- sysfs_notify(&cam->dev->kobj, NULL, "streaming");
- }
-
- atomic_dec(&cam->reset_disable);
-
- return rval;
-}
-
-static int vidioc_enum_input(struct file *file, void *fh,
- struct v4l2_input *inp)
-{
- if (inp->index > 0)
- return -EINVAL;
-
- strlcpy(inp->name, "camera", sizeof(inp->name));
- inp->type = V4L2_INPUT_TYPE_CAMERA;
-
- return 0;
-}
-
-static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
-{
- *i = 0;
-
- return 0;
-}
-
-static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
-{
- if (i > 0)
- return -EINVAL;
-
- return 0;
-}
-
-static int vidioc_queryctrl(struct file *file, void *fh,
- struct v4l2_queryctrl *a)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- rval = vidioc_int_queryctrl(cam->sdev, a);
-
- return rval;
-}
-
-static int vidioc_g_ctrl(struct file *file, void *fh,
- struct v4l2_control *a)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- rval = vidioc_int_g_ctrl(cam->sdev, a);
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_s_ctrl(struct file *file, void *fh,
- struct v4l2_control *a)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- mutex_lock(&cam->mutex);
- rval = vidioc_int_s_ctrl(cam->sdev, a);
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_g_parm(struct file *file, void *fh,
- struct v4l2_streamparm *a) {
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- int rval;
-
- if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
- return -EINVAL;
-
- mutex_lock(&cam->mutex);
- rval = vidioc_int_g_parm(cam->sdev, a);
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-static int vidioc_s_parm(struct file *file, void *fh,
- struct v4l2_streamparm *a)
-{
- struct omap24xxcam_fh *ofh = fh;
- struct omap24xxcam_device *cam = ofh->cam;
- struct v4l2_streamparm old_streamparm;
- int rval;
-
- if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
- return -EINVAL;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming) {
- rval = -EBUSY;
- goto out;
- }
-
- old_streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- rval = vidioc_int_g_parm(cam->sdev, &old_streamparm);
- if (rval)
- goto out;
-
- rval = vidioc_int_s_parm(cam->sdev, a);
- if (rval)
- goto out;
-
- rval = omap24xxcam_sensor_if_enable(cam);
- /*
- * Revert to old streaming parameters if enabling sensor
- * interface with the new ones failed.
- */
- if (rval)
- vidioc_int_s_parm(cam->sdev, &old_streamparm);
-
-out:
- mutex_unlock(&cam->mutex);
-
- return rval;
-}
-
-/*
- *
- * File operations.
- *
- */
-
-static unsigned int omap24xxcam_poll(struct file *file,
- struct poll_table_struct *wait)
-{
- struct omap24xxcam_fh *fh = file->private_data;
- struct omap24xxcam_device *cam = fh->cam;
- struct videobuf_buffer *vb;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming != file) {
- mutex_unlock(&cam->mutex);
- return POLLERR;
- }
- mutex_unlock(&cam->mutex);
-
- mutex_lock(&fh->vbq.vb_lock);
- if (list_empty(&fh->vbq.stream)) {
- mutex_unlock(&fh->vbq.vb_lock);
- return POLLERR;
- }
- vb = list_entry(fh->vbq.stream.next, struct videobuf_buffer, stream);
- mutex_unlock(&fh->vbq.vb_lock);
-
- poll_wait(file, &vb->done, wait);
-
- if (vb->state == VIDEOBUF_DONE || vb->state == VIDEOBUF_ERROR)
- return POLLIN | POLLRDNORM;
-
- return 0;
-}
-
-static int omap24xxcam_mmap_buffers(struct file *file,
- struct vm_area_struct *vma)
-{
- struct omap24xxcam_fh *fh = file->private_data;
- struct omap24xxcam_device *cam = fh->cam;
- struct videobuf_queue *vbq = &fh->vbq;
- unsigned int first, last, size, i, j;
- int err = 0;
-
- mutex_lock(&cam->mutex);
- if (cam->streaming) {
- mutex_unlock(&cam->mutex);
- return -EBUSY;
- }
- mutex_unlock(&cam->mutex);
- mutex_lock(&vbq->vb_lock);
-
- /* look for first buffer to map */
- for (first = 0; first < VIDEO_MAX_FRAME; first++) {
- if (NULL == vbq->bufs[first])
- continue;
- if (V4L2_MEMORY_MMAP != vbq->bufs[first]->memory)
- continue;
- if (vbq->bufs[first]->boff == (vma->vm_pgoff << PAGE_SHIFT))
- break;
- }
-
- /* look for last buffer to map */
- for (size = 0, last = first; last < VIDEO_MAX_FRAME; last++) {
- if (NULL == vbq->bufs[last])
- continue;
- if (V4L2_MEMORY_MMAP != vbq->bufs[last]->memory)
- continue;
- size += vbq->bufs[last]->bsize;
- if (size == (vma->vm_end - vma->vm_start))
- break;
- }
-
- size = 0;
- for (i = first; i <= last; i++) {
- struct videobuf_dmabuf *dma = videobuf_to_dma(vbq->bufs[i]);
-
- for (j = 0; j < dma->sglen; j++) {
- err = remap_pfn_range(
- vma, vma->vm_start + size,
- page_to_pfn(sg_page(&dma->sglist[j])),
- sg_dma_len(&dma->sglist[j]), vma->vm_page_prot);
- if (err)
- goto out;
- size += sg_dma_len(&dma->sglist[j]);
- }
- }
-
-out:
- mutex_unlock(&vbq->vb_lock);
-
- return err;
-}
-
-static int omap24xxcam_mmap(struct file *file, struct vm_area_struct *vma)
-{
- struct omap24xxcam_fh *fh = file->private_data;
- int rval;
-
- /* let the video-buf mapper check arguments and set-up structures */
- rval = videobuf_mmap_mapper(&fh->vbq, vma);
- if (rval)
- return rval;
-
- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-
- /* do mapping to our allocated buffers */
- rval = omap24xxcam_mmap_buffers(file, vma);
- /*
- * In case of error, free vma->vm_private_data allocated by
- * videobuf_mmap_mapper.
- */
- if (rval)
- kfree(vma->vm_private_data);
-
- return rval;
-}
-
-static int omap24xxcam_open(struct inode *inode, struct file *file)
-{
- int minor = iminor(inode);
- struct omap24xxcam_device *cam = omap24xxcam.priv;
- struct omap24xxcam_fh *fh;
- struct v4l2_format format;
-
- if (!cam || !cam->vfd || (cam->vfd->minor != minor))
- return -ENODEV;
-
- fh = kzalloc(sizeof(*fh), GFP_KERNEL);
- if (fh == NULL)
- return -ENOMEM;
-
- mutex_lock(&cam->mutex);
- if (cam->sdev == NULL || !try_module_get(cam->sdev->module)) {
- mutex_unlock(&cam->mutex);
- goto out_try_module_get;
- }
-
- if (atomic_inc_return(&cam->users) == 1) {
- omap24xxcam_hwinit(cam);
- if (omap24xxcam_sensor_enable(cam)) {
- mutex_unlock(&cam->mutex);
- goto out_omap24xxcam_sensor_enable;
- }
- }
- mutex_unlock(&cam->mutex);
-
- fh->cam = cam;
- mutex_lock(&cam->mutex);
- vidioc_int_g_fmt_cap(cam->sdev, &format);
- mutex_unlock(&cam->mutex);
- /* FIXME: how about fh->pix when there are more users? */
- fh->pix = format.fmt.pix;
-
- file->private_data = fh;
-
- spin_lock_init(&fh->vbq_lock);
-
- videobuf_queue_sg_init(&fh->vbq, &omap24xxcam_vbq_ops, NULL,
- &fh->vbq_lock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
- V4L2_FIELD_NONE,
- sizeof(struct videobuf_buffer), fh);
-
- return 0;
-
-out_omap24xxcam_sensor_enable:
- omap24xxcam_poweron_reset(cam);
- module_put(cam->sdev->module);
-
-out_try_module_get:
- kfree(fh);
-
- return -ENODEV;
-}
-
-static int omap24xxcam_release(struct inode *inode, struct file *file)
-{
- struct omap24xxcam_fh *fh = file->private_data;
- struct omap24xxcam_device *cam = fh->cam;
-
- atomic_inc(&cam->reset_disable);
-
- flush_scheduled_work();
-
- /* stop streaming capture */
- videobuf_streamoff(&fh->vbq);
-
- mutex_lock(&cam->mutex);
- if (cam->streaming == file) {
- cam->streaming = NULL;
- mutex_unlock(&cam->mutex);
- sysfs_notify(&cam->dev->kobj, NULL, "streaming");
- } else {
- mutex_unlock(&cam->mutex);
- }
-
- atomic_dec(&cam->reset_disable);
-
- omap24xxcam_vbq_free_mmap_buffers(&fh->vbq);
-
- /*
- * Make sure the reset work we might have scheduled is not
- * pending! It may be run *only* if we have users. (And it may
- * not be scheduled anymore since streaming is already
- * disabled.)
- */
- flush_scheduled_work();
-
- mutex_lock(&cam->mutex);
- if (atomic_dec_return(&cam->users) == 0) {
- omap24xxcam_sensor_disable(cam);
- omap24xxcam_poweron_reset(cam);
- }
- mutex_unlock(&cam->mutex);
-
- file->private_data = NULL;
-
- module_put(cam->sdev->module);
- kfree(fh);
-
- return 0;
-}
-
-static struct file_operations omap24xxcam_fops = {
- .llseek = no_llseek,
- .ioctl = video_ioctl2,
- .poll = omap24xxcam_poll,
- .mmap = omap24xxcam_mmap,
- .open = omap24xxcam_open,
- .release = omap24xxcam_release,
-};
-
-/*
- *
- * Power management.
- *
- */
-
-#ifdef CONFIG_PM
-static int omap24xxcam_suspend(struct platform_device *pdev, pm_message_t state)
-{
- struct omap24xxcam_device *cam = platform_get_drvdata(pdev);
-
- if (atomic_read(&cam->users) == 0)
- return 0;
-
- if (!atomic_read(&cam->reset_disable))
- omap24xxcam_capture_stop(cam);
-
- omap24xxcam_sensor_disable(cam);
- omap24xxcam_poweron_reset(cam);
-
- return 0;
-}
-
-static int omap24xxcam_resume(struct platform_device *pdev)
-{
- struct omap24xxcam_device *cam = platform_get_drvdata(pdev);
-
- if (atomic_read(&cam->users) == 0)
- return 0;
-
- omap24xxcam_hwinit(cam);
- omap24xxcam_sensor_enable(cam);
-
- if (!atomic_read(&cam->reset_disable))
- omap24xxcam_capture_cont(cam);
-
- return 0;
-}
-#endif /* CONFIG_PM */
-
-static const struct v4l2_ioctl_ops omap24xxcam_ioctl_fops = {
- .vidioc_querycap = vidioc_querycap,
- .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
- .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
- .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
- .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
- .vidioc_reqbufs = vidioc_reqbufs,
- .vidioc_querybuf = vidioc_querybuf,
- .vidioc_qbuf = vidioc_qbuf,
- .vidioc_dqbuf = vidioc_dqbuf,
- .vidioc_streamon = vidioc_streamon,
- .vidioc_streamoff = vidioc_streamoff,
- .vidioc_enum_input = vidioc_enum_input,
- .vidioc_g_input = vidioc_g_input,
- .vidioc_s_input = vidioc_s_input,
- .vidioc_queryctrl = vidioc_queryctrl,
- .vidioc_g_ctrl = vidioc_g_ctrl,
- .vidioc_s_ctrl = vidioc_s_ctrl,
- .vidioc_g_parm = vidioc_g_parm,
- .vidioc_s_parm = vidioc_s_parm,
-};
-
-/*
- *
- * Camera device (i.e. /dev/video).
- *
- */
-
-static int omap24xxcam_device_register(struct v4l2_int_device *s)
-{
- struct omap24xxcam_device *cam = s->u.slave->master->priv;
- struct video_device *vfd;
- int rval;
-
- /* We already have a slave. */
- if (cam->sdev)
- return -EBUSY;
-
- cam->sdev = s;
-
- if (device_create_file(cam->dev, &dev_attr_streaming) != 0) {
- dev_err(cam->dev, "could not register sysfs entry\n");
- rval = -EBUSY;
- goto err;
- }
-
- /* initialize the video_device struct */
- vfd = cam->vfd = video_device_alloc();
- if (!vfd) {
- dev_err(cam->dev, "could not allocate video device struct\n");
- rval = -ENOMEM;
- goto err;
- }
- vfd->release = video_device_release;
-
- vfd->parent = cam->dev;
-
- strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name));
- vfd->vfl_type = VID_TYPE_CAPTURE | VID_TYPE_CHROMAKEY;
- vfd->fops = &omap24xxcam_fops;
- vfd->priv = cam;
- vfd->minor = -1;
- vfd->ioctl_ops = &omap24xxcam_ioctl_fops;
-
- omap24xxcam_hwinit(cam);
-
- rval = omap24xxcam_sensor_init(cam);
- if (rval)
- goto err;
-
- if (video_register_device(vfd, VFL_TYPE_GRABBER, video_nr) < 0) {
- dev_err(cam->dev, "could not register V4L device\n");
- vfd->minor = -1;
- rval = -EBUSY;
- goto err;
- }
-
- omap24xxcam_poweron_reset(cam);
-
- dev_info(cam->dev, "registered device video%d\n", vfd->minor);
-
- return 0;
-
-err:
- omap24xxcam_device_unregister(s);
-
- return rval;
-}
-
-static void omap24xxcam_device_unregister(struct v4l2_int_device *s)
-{
- struct omap24xxcam_device *cam = s->u.slave->master->priv;
-
- omap24xxcam_sensor_exit(cam);
-
- if (cam->vfd) {
- if (cam->vfd->minor == -1) {
- /*
- * The device was never registered, so release the
- * video_device struct directly.
- */
- video_device_release(cam->vfd);
- } else {
- /*
- * The unregister function will release the
- * video_device struct as well as
- * unregistering it.
- */
- video_unregister_device(cam->vfd);
- }
- cam->vfd = NULL;
- }
-
- device_remove_file(cam->dev, &dev_attr_streaming);
-
- cam->sdev = NULL;
-}
-
-static struct v4l2_int_master omap24xxcam_master = {
- .attach = omap24xxcam_device_register,
- .detach = omap24xxcam_device_unregister,
-};
-
-static struct v4l2_int_device omap24xxcam = {
- .module = THIS_MODULE,
- .name = CAM_NAME,
- .type = v4l2_int_type_master,
- .u = {
- .master = &omap24xxcam_master
- },
-};
-
-/*
- *
- * Driver initialisation and deinitialisation.
- *
- */
-
-static int __init omap24xxcam_probe(struct platform_device *pdev)
-{
- struct omap24xxcam_device *cam;
- struct resource *mem;
- int irq;
-
- cam = kzalloc(sizeof(*cam), GFP_KERNEL);
- if (!cam) {
- dev_err(&pdev->dev, "could not allocate memory\n");
- goto err;
- }
-
- platform_set_drvdata(pdev, cam);
-
- cam->dev = &pdev->dev;
-
- /*
- * Impose a lower limit on the amount of memory allocated for
- * capture. We require at least enough memory to double-buffer
- * QVGA (300KB).
- */
- if (capture_mem < 320 * 240 * 2 * 2)
- capture_mem = 320 * 240 * 2 * 2;
- cam->capture_mem = capture_mem;
-
- /* request the mem region for the camera registers */
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!mem) {
- dev_err(cam->dev, "no mem resource?\n");
- goto err;
- }
- if (!request_mem_region(mem->start, (mem->end - mem->start) + 1,
- pdev->name)) {
- dev_err(cam->dev,
- "cannot reserve camera register I/O region\n");
- goto err;
- }
- cam->mmio_base_phys = mem->start;
- cam->mmio_size = (mem->end - mem->start) + 1;
-
- /* map the region */
- cam->mmio_base = (unsigned long)
- ioremap_nocache(cam->mmio_base_phys, cam->mmio_size);
- if (!cam->mmio_base) {
- dev_err(cam->dev, "cannot map camera register I/O region\n");
- goto err;
- }
-
- irq = platform_get_irq(pdev, 0);
- if (irq <= 0) {
- dev_err(cam->dev, "no irq for camera?\n");
- goto err;
- }
-
- /* install the interrupt service routine */
- if (request_irq(irq, omap24xxcam_isr, 0, CAM_NAME, cam)) {
- dev_err(cam->dev,
- "could not install interrupt service routine\n");
- goto err;
- }
- cam->irq = irq;
-
- if (omap24xxcam_clock_get(cam))
- goto err;
-
- INIT_WORK(&cam->sensor_reset_work, omap24xxcam_sensor_reset_work);
-
- mutex_init(&cam->mutex);
- spin_lock_init(&cam->core_enable_disable_lock);
-
- omap24xxcam_sgdma_init(&cam->sgdma,
- cam->mmio_base + CAMDMA_REG_OFFSET,
- omap24xxcam_stalled_dma_reset,
- (unsigned long)cam);
-
- omap24xxcam.priv = cam;
-
- if (v4l2_int_device_register(&omap24xxcam))
- goto err;
-
- return 0;
-
-err:
- omap24xxcam_remove(pdev);
- return -ENODEV;
-}
-
-static int omap24xxcam_remove(struct platform_device *pdev)
-{
- struct omap24xxcam_device *cam = platform_get_drvdata(pdev);
-
- if (!cam)
- return 0;
-
- if (omap24xxcam.priv != NULL)
- v4l2_int_device_unregister(&omap24xxcam);
- omap24xxcam.priv = NULL;
-
- omap24xxcam_clock_put(cam);
-
- if (cam->irq) {
- free_irq(cam->irq, cam);
- cam->irq = 0;
- }
-
- if (cam->mmio_base) {
- iounmap((void *)cam->mmio_base);
- cam->mmio_base = 0;
- }
-
- if (cam->mmio_base_phys) {
- release_mem_region(cam->mmio_base_phys, cam->mmio_size);
- cam->mmio_base_phys = 0;
- }
-
- kfree(cam);
-
- return 0;
-}
-
-static struct platform_driver omap24xxcam_driver = {
- .probe = omap24xxcam_probe,
- .remove = omap24xxcam_remove,
-#ifdef CONFIG_PM
- .suspend = omap24xxcam_suspend,
- .resume = omap24xxcam_resume,
-#endif
- .driver = {
- .name = CAM_NAME,
- },
-};
-
-/*
- *
- * Module initialisation and deinitialisation
- *
- */
-
-static int __init omap24xxcam_init(void)
-{
- return platform_driver_register(&omap24xxcam_driver);
-}
-
-static void __exit omap24xxcam_cleanup(void)
-{
- platform_driver_unregister(&omap24xxcam_driver);
-}
-
-MODULE_AUTHOR("Sakari Ailus <sakari.ailus@nokia.com>");
-MODULE_DESCRIPTION("OMAP24xx Video for Linux camera driver");
-MODULE_LICENSE("GPL");
-module_param(video_nr, int, 0);
-MODULE_PARM_DESC(video_nr,
- "Minor number for video device (-1 ==> auto assign)");
-module_param(capture_mem, int, 0);
-MODULE_PARM_DESC(capture_mem, "Maximum amount of memory for capture "
- "buffers (default 4800kiB)");
-
-module_init(omap24xxcam_init);
-module_exit(omap24xxcam_cleanup);
+++ /dev/null
-/*
- * drivers/media/video/omap24xxcam.h
- *
- * Copyright (C) 2004 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- * Copyright (C) 2007 Nokia Corporation.
- *
- * Contact: Sakari Ailus <sakari.ailus@nokia.com>
- *
- * Based on code from Andy Lowe <source@mvista.com>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef OMAP24XXCAM_H
-#define OMAP24XXCAM_H
-
-#include <media/videobuf-dma-sg.h>
-#include <media/v4l2-int-device.h>
-
-/*
- *
- * General driver related definitions.
- *
- */
-
-#define CAM_NAME "omap24xxcam"
-
-#define CAM_MCLK 96000000
-
-/* number of bytes transferred per DMA request */
-#define DMA_THRESHOLD 32
-
-/*
- * NUM_CAMDMA_CHANNELS is the number of logical channels provided by
- * the camera DMA controller.
- */
-#define NUM_CAMDMA_CHANNELS 4
-
-/*
- * NUM_SG_DMA is the number of scatter-gather DMA transfers that can
- * be queued. (We don't have any overlay sglists now.)
- */
-#define NUM_SG_DMA (VIDEO_MAX_FRAME)
-
-/*
- *
- * Register definitions.
- *
- */
-
-/* subsystem register block offsets */
-#define CC_REG_OFFSET 0x00000400
-#define CAMDMA_REG_OFFSET 0x00000800
-#define CAMMMU_REG_OFFSET 0x00000C00
-
-/* define camera subsystem register offsets */
-#define CAM_REVISION 0x000
-#define CAM_SYSCONFIG 0x010
-#define CAM_SYSSTATUS 0x014
-#define CAM_IRQSTATUS 0x018
-#define CAM_GPO 0x040
-#define CAM_GPI 0x050
-
-/* define camera core register offsets */
-#define CC_REVISION 0x000
-#define CC_SYSCONFIG 0x010
-#define CC_SYSSTATUS 0x014
-#define CC_IRQSTATUS 0x018
-#define CC_IRQENABLE 0x01C
-#define CC_CTRL 0x040
-#define CC_CTRL_DMA 0x044
-#define CC_CTRL_XCLK 0x048
-#define CC_FIFODATA 0x04C
-#define CC_TEST 0x050
-#define CC_GENPAR 0x054
-#define CC_CCPFSCR 0x058
-#define CC_CCPFECR 0x05C
-#define CC_CCPLSCR 0x060
-#define CC_CCPLECR 0x064
-#define CC_CCPDFR 0x068
-
-/* define camera dma register offsets */
-#define CAMDMA_REVISION 0x000
-#define CAMDMA_IRQSTATUS_L0 0x008
-#define CAMDMA_IRQSTATUS_L1 0x00C
-#define CAMDMA_IRQSTATUS_L2 0x010
-#define CAMDMA_IRQSTATUS_L3 0x014
-#define CAMDMA_IRQENABLE_L0 0x018
-#define CAMDMA_IRQENABLE_L1 0x01C
-#define CAMDMA_IRQENABLE_L2 0x020
-#define CAMDMA_IRQENABLE_L3 0x024
-#define CAMDMA_SYSSTATUS 0x028
-#define CAMDMA_OCP_SYSCONFIG 0x02C
-#define CAMDMA_CAPS_0 0x064
-#define CAMDMA_CAPS_2 0x06C
-#define CAMDMA_CAPS_3 0x070
-#define CAMDMA_CAPS_4 0x074
-#define CAMDMA_GCR 0x078
-#define CAMDMA_CCR(n) (0x080 + (n)*0x60)
-#define CAMDMA_CLNK_CTRL(n) (0x084 + (n)*0x60)
-#define CAMDMA_CICR(n) (0x088 + (n)*0x60)
-#define CAMDMA_CSR(n) (0x08C + (n)*0x60)
-#define CAMDMA_CSDP(n) (0x090 + (n)*0x60)
-#define CAMDMA_CEN(n) (0x094 + (n)*0x60)
-#define CAMDMA_CFN(n) (0x098 + (n)*0x60)
-#define CAMDMA_CSSA(n) (0x09C + (n)*0x60)
-#define CAMDMA_CDSA(n) (0x0A0 + (n)*0x60)
-#define CAMDMA_CSEI(n) (0x0A4 + (n)*0x60)
-#define CAMDMA_CSFI(n) (0x0A8 + (n)*0x60)
-#define CAMDMA_CDEI(n) (0x0AC + (n)*0x60)
-#define CAMDMA_CDFI(n) (0x0B0 + (n)*0x60)
-#define CAMDMA_CSAC(n) (0x0B4 + (n)*0x60)
-#define CAMDMA_CDAC(n) (0x0B8 + (n)*0x60)
-#define CAMDMA_CCEN(n) (0x0BC + (n)*0x60)
-#define CAMDMA_CCFN(n) (0x0C0 + (n)*0x60)
-#define CAMDMA_COLOR(n) (0x0C4 + (n)*0x60)
-
-/* define camera mmu register offsets */
-#define CAMMMU_REVISION 0x000
-#define CAMMMU_SYSCONFIG 0x010
-#define CAMMMU_SYSSTATUS 0x014
-#define CAMMMU_IRQSTATUS 0x018
-#define CAMMMU_IRQENABLE 0x01C
-#define CAMMMU_WALKING_ST 0x040
-#define CAMMMU_CNTL 0x044
-#define CAMMMU_FAULT_AD 0x048
-#define CAMMMU_TTB 0x04C
-#define CAMMMU_LOCK 0x050
-#define CAMMMU_LD_TLB 0x054
-#define CAMMMU_CAM 0x058
-#define CAMMMU_RAM 0x05C
-#define CAMMMU_GFLUSH 0x060
-#define CAMMMU_FLUSH_ENTRY 0x064
-#define CAMMMU_READ_CAM 0x068
-#define CAMMMU_READ_RAM 0x06C
-#define CAMMMU_EMU_FAULT_AD 0x070
-
-/* Define bit fields within selected registers */
-#define CAM_REVISION_MAJOR (15 << 4)
-#define CAM_REVISION_MAJOR_SHIFT 4
-#define CAM_REVISION_MINOR (15 << 0)
-#define CAM_REVISION_MINOR_SHIFT 0
-
-#define CAM_SYSCONFIG_SOFTRESET (1 << 1)
-#define CAM_SYSCONFIG_AUTOIDLE (1 << 0)
-
-#define CAM_SYSSTATUS_RESETDONE (1 << 0)
-
-#define CAM_IRQSTATUS_CC_IRQ (1 << 4)
-#define CAM_IRQSTATUS_MMU_IRQ (1 << 3)
-#define CAM_IRQSTATUS_DMA_IRQ2 (1 << 2)
-#define CAM_IRQSTATUS_DMA_IRQ1 (1 << 1)
-#define CAM_IRQSTATUS_DMA_IRQ0 (1 << 0)
-
-#define CAM_GPO_CAM_S_P_EN (1 << 1)
-#define CAM_GPO_CAM_CCP_MODE (1 << 0)
-
-#define CAM_GPI_CC_DMA_REQ1 (1 << 24)
-#define CAP_GPI_CC_DMA_REQ0 (1 << 23)
-#define CAP_GPI_CAM_MSTANDBY (1 << 21)
-#define CAP_GPI_CAM_WAIT (1 << 20)
-#define CAP_GPI_CAM_S_DATA (1 << 17)
-#define CAP_GPI_CAM_S_CLK (1 << 16)
-#define CAP_GPI_CAM_P_DATA (0xFFF << 3)
-#define CAP_GPI_CAM_P_DATA_SHIFT 3
-#define CAP_GPI_CAM_P_VS (1 << 2)
-#define CAP_GPI_CAM_P_HS (1 << 1)
-#define CAP_GPI_CAM_P_CLK (1 << 0)
-
-#define CC_REVISION_MAJOR (15 << 4)
-#define CC_REVISION_MAJOR_SHIFT 4
-#define CC_REVISION_MINOR (15 << 0)
-#define CC_REVISION_MINOR_SHIFT 0
-
-#define CC_SYSCONFIG_SIDLEMODE (3 << 3)
-#define CC_SYSCONFIG_SIDLEMODE_FIDLE (0 << 3)
-#define CC_SYSCONFIG_SIDLEMODE_NIDLE (1 << 3)
-#define CC_SYSCONFIG_SOFTRESET (1 << 1)
-#define CC_SYSCONFIG_AUTOIDLE (1 << 0)
-
-#define CC_SYSSTATUS_RESETDONE (1 << 0)
-
-#define CC_IRQSTATUS_FS_IRQ (1 << 19)
-#define CC_IRQSTATUS_LE_IRQ (1 << 18)
-#define CC_IRQSTATUS_LS_IRQ (1 << 17)
-#define CC_IRQSTATUS_FE_IRQ (1 << 16)
-#define CC_IRQSTATUS_FW_ERR_IRQ (1 << 10)
-#define CC_IRQSTATUS_FSC_ERR_IRQ (1 << 9)
-#define CC_IRQSTATUS_SSC_ERR_IRQ (1 << 8)
-#define CC_IRQSTATUS_FIFO_NOEMPTY_IRQ (1 << 4)
-#define CC_IRQSTATUS_FIFO_FULL_IRQ (1 << 3)
-#define CC_IRQSTATUS_FIFO_THR_IRQ (1 << 2)
-#define CC_IRQSTATUS_FIFO_OF_IRQ (1 << 1)
-#define CC_IRQSTATUS_FIFO_UF_IRQ (1 << 0)
-
-#define CC_IRQENABLE_FS_IRQ (1 << 19)
-#define CC_IRQENABLE_LE_IRQ (1 << 18)
-#define CC_IRQENABLE_LS_IRQ (1 << 17)
-#define CC_IRQENABLE_FE_IRQ (1 << 16)
-#define CC_IRQENABLE_FW_ERR_IRQ (1 << 10)
-#define CC_IRQENABLE_FSC_ERR_IRQ (1 << 9)
-#define CC_IRQENABLE_SSC_ERR_IRQ (1 << 8)
-#define CC_IRQENABLE_FIFO_NOEMPTY_IRQ (1 << 4)
-#define CC_IRQENABLE_FIFO_FULL_IRQ (1 << 3)
-#define CC_IRQENABLE_FIFO_THR_IRQ (1 << 2)
-#define CC_IRQENABLE_FIFO_OF_IRQ (1 << 1)
-#define CC_IRQENABLE_FIFO_UF_IRQ (1 << 0)
-
-#define CC_CTRL_CC_ONE_SHOT (1 << 20)
-#define CC_CTRL_CC_IF_SYNCHRO (1 << 19)
-#define CC_CTRL_CC_RST (1 << 18)
-#define CC_CTRL_CC_FRAME_TRIG (1 << 17)
-#define CC_CTRL_CC_EN (1 << 16)
-#define CC_CTRL_NOBT_SYNCHRO (1 << 13)
-#define CC_CTRL_BT_CORRECT (1 << 12)
-#define CC_CTRL_PAR_ORDERCAM (1 << 11)
-#define CC_CTRL_PAR_CLK_POL (1 << 10)
-#define CC_CTRL_NOBT_HS_POL (1 << 9)
-#define CC_CTRL_NOBT_VS_POL (1 << 8)
-#define CC_CTRL_PAR_MODE (7 << 1)
-#define CC_CTRL_PAR_MODE_SHIFT 1
-#define CC_CTRL_PAR_MODE_NOBT8 (0 << 1)
-#define CC_CTRL_PAR_MODE_NOBT10 (1 << 1)
-#define CC_CTRL_PAR_MODE_NOBT12 (2 << 1)
-#define CC_CTRL_PAR_MODE_BT8 (4 << 1)
-#define CC_CTRL_PAR_MODE_BT10 (5 << 1)
-#define CC_CTRL_PAR_MODE_FIFOTEST (7 << 1)
-#define CC_CTRL_CCP_MODE (1 << 0)
-
-#define CC_CTRL_DMA_EN (1 << 8)
-#define CC_CTRL_DMA_FIFO_THRESHOLD (0x7F << 0)
-#define CC_CTRL_DMA_FIFO_THRESHOLD_SHIFT 0
-
-#define CC_CTRL_XCLK_DIV (0x1F << 0)
-#define CC_CTRL_XCLK_DIV_SHIFT 0
-#define CC_CTRL_XCLK_DIV_STABLE_LOW (0 << 0)
-#define CC_CTRL_XCLK_DIV_STABLE_HIGH (1 << 0)
-#define CC_CTRL_XCLK_DIV_BYPASS (31 << 0)
-
-#define CC_TEST_FIFO_RD_POINTER (0xFF << 24)
-#define CC_TEST_FIFO_RD_POINTER_SHIFT 24
-#define CC_TEST_FIFO_WR_POINTER (0xFF << 16)
-#define CC_TEST_FIFO_WR_POINTER_SHIFT 16
-#define CC_TEST_FIFO_LEVEL (0xFF << 8)
-#define CC_TEST_FIFO_LEVEL_SHIFT 8
-#define CC_TEST_FIFO_LEVEL_PEAK (0xFF << 0)
-#define CC_TEST_FIFO_LEVEL_PEAK_SHIFT 0
-
-#define CC_GENPAR_FIFO_DEPTH (7 << 0)
-#define CC_GENPAR_FIFO_DEPTH_SHIFT 0
-
-#define CC_CCPDFR_ALPHA (0xFF << 8)
-#define CC_CCPDFR_ALPHA_SHIFT 8
-#define CC_CCPDFR_DATAFORMAT (15 << 0)
-#define CC_CCPDFR_DATAFORMAT_SHIFT 0
-#define CC_CCPDFR_DATAFORMAT_YUV422BE ( 0 << 0)
-#define CC_CCPDFR_DATAFORMAT_YUV422 ( 1 << 0)
-#define CC_CCPDFR_DATAFORMAT_YUV420 ( 2 << 0)
-#define CC_CCPDFR_DATAFORMAT_RGB444 ( 4 << 0)
-#define CC_CCPDFR_DATAFORMAT_RGB565 ( 5 << 0)
-#define CC_CCPDFR_DATAFORMAT_RGB888NDE ( 6 << 0)
-#define CC_CCPDFR_DATAFORMAT_RGB888 ( 7 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW8NDE ( 8 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW8 ( 9 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW10NDE (10 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW10 (11 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW12NDE (12 << 0)
-#define CC_CCPDFR_DATAFORMAT_RAW12 (13 << 0)
-#define CC_CCPDFR_DATAFORMAT_JPEG8 (15 << 0)
-
-#define CAMDMA_REVISION_MAJOR (15 << 4)
-#define CAMDMA_REVISION_MAJOR_SHIFT 4
-#define CAMDMA_REVISION_MINOR (15 << 0)
-#define CAMDMA_REVISION_MINOR_SHIFT 0
-
-#define CAMDMA_OCP_SYSCONFIG_MIDLEMODE (3 << 12)
-#define CAMDMA_OCP_SYSCONFIG_MIDLEMODE_FSTANDBY (0 << 12)
-#define CAMDMA_OCP_SYSCONFIG_MIDLEMODE_NSTANDBY (1 << 12)
-#define CAMDMA_OCP_SYSCONFIG_MIDLEMODE_SSTANDBY (2 << 12)
-#define CAMDMA_OCP_SYSCONFIG_FUNC_CLOCK (1 << 9)
-#define CAMDMA_OCP_SYSCONFIG_OCP_CLOCK (1 << 8)
-#define CAMDMA_OCP_SYSCONFIG_EMUFREE (1 << 5)
-#define CAMDMA_OCP_SYSCONFIG_SIDLEMODE (3 << 3)
-#define CAMDMA_OCP_SYSCONFIG_SIDLEMODE_FIDLE (0 << 3)
-#define CAMDMA_OCP_SYSCONFIG_SIDLEMODE_NIDLE (1 << 3)
-#define CAMDMA_OCP_SYSCONFIG_SIDLEMODE_SIDLE (2 << 3)
-#define CAMDMA_OCP_SYSCONFIG_SOFTRESET (1 << 1)
-#define CAMDMA_OCP_SYSCONFIG_AUTOIDLE (1 << 0)
-
-#define CAMDMA_SYSSTATUS_RESETDONE (1 << 0)
-
-#define CAMDMA_GCR_ARBITRATION_RATE (0xFF << 16)
-#define CAMDMA_GCR_ARBITRATION_RATE_SHIFT 16
-#define CAMDMA_GCR_MAX_CHANNEL_FIFO_DEPTH (0xFF << 0)
-#define CAMDMA_GCR_MAX_CHANNEL_FIFO_DEPTH_SHIFT 0
-
-#define CAMDMA_CCR_SEL_SRC_DST_SYNC (1 << 24)
-#define CAMDMA_CCR_PREFETCH (1 << 23)
-#define CAMDMA_CCR_SUPERVISOR (1 << 22)
-#define CAMDMA_CCR_SECURE (1 << 21)
-#define CAMDMA_CCR_BS (1 << 18)
-#define CAMDMA_CCR_TRANSPARENT_COPY_ENABLE (1 << 17)
-#define CAMDMA_CCR_CONSTANT_FILL_ENABLE (1 << 16)
-#define CAMDMA_CCR_DST_AMODE (3 << 14)
-#define CAMDMA_CCR_DST_AMODE_CONST_ADDR (0 << 14)
-#define CAMDMA_CCR_DST_AMODE_POST_INC (1 << 14)
-#define CAMDMA_CCR_DST_AMODE_SGL_IDX (2 << 14)
-#define CAMDMA_CCR_DST_AMODE_DBL_IDX (3 << 14)
-#define CAMDMA_CCR_SRC_AMODE (3 << 12)
-#define CAMDMA_CCR_SRC_AMODE_CONST_ADDR (0 << 12)
-#define CAMDMA_CCR_SRC_AMODE_POST_INC (1 << 12)
-#define CAMDMA_CCR_SRC_AMODE_SGL_IDX (2 << 12)
-#define CAMDMA_CCR_SRC_AMODE_DBL_IDX (3 << 12)
-#define CAMDMA_CCR_WR_ACTIVE (1 << 10)
-#define CAMDMA_CCR_RD_ACTIVE (1 << 9)
-#define CAMDMA_CCR_SUSPEND_SENSITIVE (1 << 8)
-#define CAMDMA_CCR_ENABLE (1 << 7)
-#define CAMDMA_CCR_PRIO (1 << 6)
-#define CAMDMA_CCR_FS (1 << 5)
-#define CAMDMA_CCR_SYNCHRO ((3 << 19) | (31 << 0))
-#define CAMDMA_CCR_SYNCHRO_CAMERA 0x01
-
-#define CAMDMA_CLNK_CTRL_ENABLE_LNK (1 << 15)
-#define CAMDMA_CLNK_CTRL_NEXTLCH_ID (0x1F << 0)
-#define CAMDMA_CLNK_CTRL_NEXTLCH_ID_SHIFT 0
-
-#define CAMDMA_CICR_MISALIGNED_ERR_IE (1 << 11)
-#define CAMDMA_CICR_SUPERVISOR_ERR_IE (1 << 10)
-#define CAMDMA_CICR_SECURE_ERR_IE (1 << 9)
-#define CAMDMA_CICR_TRANS_ERR_IE (1 << 8)
-#define CAMDMA_CICR_PACKET_IE (1 << 7)
-#define CAMDMA_CICR_BLOCK_IE (1 << 5)
-#define CAMDMA_CICR_LAST_IE (1 << 4)
-#define CAMDMA_CICR_FRAME_IE (1 << 3)
-#define CAMDMA_CICR_HALF_IE (1 << 2)
-#define CAMDMA_CICR_DROP_IE (1 << 1)
-
-#define CAMDMA_CSR_MISALIGNED_ERR (1 << 11)
-#define CAMDMA_CSR_SUPERVISOR_ERR (1 << 10)
-#define CAMDMA_CSR_SECURE_ERR (1 << 9)
-#define CAMDMA_CSR_TRANS_ERR (1 << 8)
-#define CAMDMA_CSR_PACKET (1 << 7)
-#define CAMDMA_CSR_SYNC (1 << 6)
-#define CAMDMA_CSR_BLOCK (1 << 5)
-#define CAMDMA_CSR_LAST (1 << 4)
-#define CAMDMA_CSR_FRAME (1 << 3)
-#define CAMDMA_CSR_HALF (1 << 2)
-#define CAMDMA_CSR_DROP (1 << 1)
-
-#define CAMDMA_CSDP_SRC_ENDIANNESS (1 << 21)
-#define CAMDMA_CSDP_SRC_ENDIANNESS_LOCK (1 << 20)
-#define CAMDMA_CSDP_DST_ENDIANNESS (1 << 19)
-#define CAMDMA_CSDP_DST_ENDIANNESS_LOCK (1 << 18)
-#define CAMDMA_CSDP_WRITE_MODE (3 << 16)
-#define CAMDMA_CSDP_WRITE_MODE_WRNP (0 << 16)
-#define CAMDMA_CSDP_WRITE_MODE_POSTED (1 << 16)
-#define CAMDMA_CSDP_WRITE_MODE_POSTED_LAST_WRNP (2 << 16)
-#define CAMDMA_CSDP_DST_BURST_EN (3 << 14)
-#define CAMDMA_CSDP_DST_BURST_EN_1 (0 << 14)
-#define CAMDMA_CSDP_DST_BURST_EN_16 (1 << 14)
-#define CAMDMA_CSDP_DST_BURST_EN_32 (2 << 14)
-#define CAMDMA_CSDP_DST_BURST_EN_64 (3 << 14)
-#define CAMDMA_CSDP_DST_PACKED (1 << 13)
-#define CAMDMA_CSDP_WR_ADD_TRSLT (15 << 9)
-#define CAMDMA_CSDP_WR_ADD_TRSLT_ENABLE_MREQADD (3 << 9)
-#define CAMDMA_CSDP_SRC_BURST_EN (3 << 7)
-#define CAMDMA_CSDP_SRC_BURST_EN_1 (0 << 7)
-#define CAMDMA_CSDP_SRC_BURST_EN_16 (1 << 7)
-#define CAMDMA_CSDP_SRC_BURST_EN_32 (2 << 7)
-#define CAMDMA_CSDP_SRC_BURST_EN_64 (3 << 7)
-#define CAMDMA_CSDP_SRC_PACKED (1 << 6)
-#define CAMDMA_CSDP_RD_ADD_TRSLT (15 << 2)
-#define CAMDMA_CSDP_RD_ADD_TRSLT_ENABLE_MREQADD (3 << 2)
-#define CAMDMA_CSDP_DATA_TYPE (3 << 0)
-#define CAMDMA_CSDP_DATA_TYPE_8BITS (0 << 0)
-#define CAMDMA_CSDP_DATA_TYPE_16BITS (1 << 0)
-#define CAMDMA_CSDP_DATA_TYPE_32BITS (2 << 0)
-
-#define CAMMMU_SYSCONFIG_AUTOIDLE (1 << 0)
-
-/*
- *
- * Declarations.
- *
- */
-
-/* forward declarations */
-struct omap24xxcam_sgdma;
-struct omap24xxcam_dma;
-
-typedef void (*sgdma_callback_t)(struct omap24xxcam_sgdma *cam,
- u32 status, void *arg);
-typedef void (*dma_callback_t)(struct omap24xxcam_dma *cam,
- u32 status, void *arg);
-
-struct channel_state {
- dma_callback_t callback;
- void *arg;
-};
-
-/* sgdma state for each of the possible videobuf_buffers + 2 overlays */
-struct sgdma_state {
- const struct scatterlist *sglist;
- int sglen; /* number of sglist entries */
- int next_sglist; /* index of next sglist entry to process */
- unsigned int bytes_read; /* number of bytes read */
- unsigned int len; /* total length of sglist (excluding
- * bytes due to page alignment) */
- int queued_sglist; /* number of sglist entries queued for DMA */
- u32 csr; /* DMA return code */
- sgdma_callback_t callback;
- void *arg;
-};
-
-/* physical DMA channel management */
-struct omap24xxcam_dma {
- spinlock_t lock; /* Lock for the whole structure. */
-
- unsigned long base; /* base address for dma controller */
-
- /* While dma_stop!=0, an attempt to start a new DMA transfer will
- * fail.
- */
- atomic_t dma_stop;
- int free_dmach; /* number of dma channels free */
- int next_dmach; /* index of next dma channel to use */
- struct channel_state ch_state[NUM_CAMDMA_CHANNELS];
-};
-
-/* scatter-gather DMA (scatterlist stuff) management */
-struct omap24xxcam_sgdma {
- struct omap24xxcam_dma dma;
-
- spinlock_t lock; /* Lock for the fields below. */
- int free_sgdma; /* number of free sg dma slots */
- int next_sgdma; /* index of next sg dma slot to use */
- struct sgdma_state sg_state[NUM_SG_DMA];
-
- /* Reset timer data */
- struct timer_list reset_timer;
-};
-
-/* per-device data structure */
-struct omap24xxcam_device {
- /*** mutex ***/
- /*
- * mutex serialises access to this structure. Also camera
- * opening and releasing is synchronised by this.
- */
- struct mutex mutex;
-
- /*** general driver state information ***/
- atomic_t users;
- /*
- * Lock to serialise core enabling and disabling and access to
- * sgdma_in_queue.
- */
- spinlock_t core_enable_disable_lock;
- /*
- * Number or sgdma requests in scatter-gather queue, protected
- * by the lock above.
- */
- int sgdma_in_queue;
- /*
- * Sensor interface parameters: interface type, CC_CTRL
- * register value and interface specific data.
- */
- int if_type;
- union {
- struct parallel {
- u32 xclk;
- } bt656;
- } if_u;
- u32 cc_ctrl;
-
- /*** subsystem structures ***/
- struct omap24xxcam_sgdma sgdma;
-
- /*** hardware resources ***/
- unsigned int irq;
- unsigned long mmio_base;
- unsigned long mmio_base_phys;
- unsigned long mmio_size;
-
- /*** interfaces and device ***/
- struct v4l2_int_device *sdev;
- struct device *dev;
- struct video_device *vfd;
-
- /*** camera and sensor reset related stuff ***/
- struct work_struct sensor_reset_work;
- /*
- * We're in the middle of a reset. Don't enable core if this
- * is non-zero! This exists to help decisionmaking in a case
- * where videobuf_qbuf is called while we are in the middle of
- * a reset.
- */
- atomic_t in_reset;
- /*
- * Non-zero if we don't want any resets for now. Used to
- * prevent reset work to run when we're about to stop
- * streaming.
- */
- atomic_t reset_disable;
-
- /*** video device parameters ***/
- int capture_mem;
-
- /*** camera module clocks ***/
- struct clk *fck;
- struct clk *ick;
-
- /*** capture data ***/
- /* file handle, if streaming is on */
- struct file *streaming;
-};
-
-/* Per-file handle data. */
-struct omap24xxcam_fh {
- spinlock_t vbq_lock; /* spinlock for the videobuf queue */
- struct videobuf_queue vbq;
- struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
- atomic_t field_count; /* field counter for videobuf_buffer */
- /* accessing cam here doesn't need serialisation: it's constant */
- struct omap24xxcam_device *cam;
-};
-
-/*
- *
- * Register I/O functions.
- *
- */
-
-static __inline__ u32 omap24xxcam_reg_in(unsigned long base, u32 offset)
-{
- return readl(base + offset);
-}
-
-static __inline__ u32 omap24xxcam_reg_out(unsigned long base, u32 offset,
- u32 val)
-{
- writel(val, base + offset);
- return val;
-}
-
-static __inline__ u32 omap24xxcam_reg_merge(unsigned long base, u32 offset,
- u32 val, u32 mask)
-{
- u32 addr = base + offset;
- u32 new_val = (readl(addr) & ~mask) | (val & mask);
-
- writel(new_val, addr);
- return new_val;
-}
-
-/*
- *
- * Function prototypes.
- *
- */
-
-/* dma prototypes */
-
-void omap24xxcam_dma_hwinit(const struct omap24xxcam_dma *dma);
-void omap24xxcam_dma_isr(struct omap24xxcam_dma *dma);
-
-/* sgdma prototypes */
-
-void omap24xxcam_sgdma_process(struct omap24xxcam_sgdma *sgdma);
-int omap24xxcam_sgdma_queue(struct omap24xxcam_sgdma *sgdma,
- const struct scatterlist *sglist, int sglen,
- int len, sgdma_callback_t callback, void *arg);
-void omap24xxcam_sgdma_sync(struct omap24xxcam_sgdma *sgdma);
-void omap24xxcam_sgdma_init(struct omap24xxcam_sgdma *sgdma,
- unsigned long base,
- void (*reset_callback)(unsigned long data),
- unsigned long reset_callback_data);
-void omap24xxcam_sgdma_exit(struct omap24xxcam_sgdma *sgdma);
-
-#endif
+++ /dev/null
-/*
- * drivers/media/video/ov9640.c
- *
- * OV9640 sensor driver
- *
- * Author: Andy Lowe (source@mvista.com)
- * Contact: Trilok Soni <soni.trilok@gmail.com>
- *
- * Copyright (C) 2004 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- *
- * This file is licensed under the terms of the GNU General Public License
- * version 2. This program is licensed "as is" without any warranty of any
- * kind, whether express or implied.
- */
-
-#include <linux/i2c.h>
-#include <linux/delay.h>
-#include <media/v4l2-int-device.h>
-
-#include "ov9640.h"
-
-#define DRIVER_NAME "ov9640"
-
-struct ov9640_sensor {
- const struct ov9640_platform_data *pdata;
- struct v4l2_int_device *v4l2_int_device;
- struct i2c_client *i2c_client;
- struct v4l2_pix_format pix;
- struct v4l2_fract timeperframe;
- int ver; /*ov9640 chip version*/
-};
-
-static struct ov9640_sensor ov9640;
-static struct i2c_driver ov9640sensor_i2c_driver;
-
-/* list of image formats supported by OV9640 sensor */
-const static struct v4l2_fmtdesc ov9640_formats[] = {
- {
- /* Note: V4L2 defines RGB565 as:
- *
- * Byte 0 Byte 1
- * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
- *
- * We interpret RGB565 as:
- *
- * Byte 0 Byte 1
- * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
- */
- .description = "RGB565, le",
- .pixelformat = V4L2_PIX_FMT_RGB565,
- },
- {
- /* Note: V4L2 defines RGB565X as:
- *
- * Byte 0 Byte 1
- * b4 b3 b2 b1 b0 g5 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0
- *
- * We interpret RGB565X as:
- *
- * Byte 0 Byte 1
- * r4 r3 r2 r1 r0 g5 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0
- */
- .description = "RGB565, be",
- .pixelformat = V4L2_PIX_FMT_RGB565X,
- },
- {
- .description = "YUYV (YUV 4:2:2), packed",
- .pixelformat = V4L2_PIX_FMT_YUYV,
- },
- {
- .description = "UYVY, packed",
- .pixelformat = V4L2_PIX_FMT_UYVY,
- },
- {
- /* Note: V4L2 defines RGB555 as:
- *
- * Byte 0 Byte 1
- * g2 g1 g0 r4 r3 r2 r1 r0 x b4 b3 b2 b1 b0 g4 g3
- *
- * We interpret RGB555 as:
- *
- * Byte 0 Byte 1
- * g2 g1 g0 b4 b3 b2 b1 b0 x r4 r3 r2 r1 r0 g4 g3
- */
- .description = "RGB555, le",
- .pixelformat = V4L2_PIX_FMT_RGB555,
- },
- {
- /* Note: V4L2 defines RGB555X as:
- *
- * Byte 0 Byte 1
- * x b4 b3 b2 b1 b0 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0
- *
- * We interpret RGB555X as:
- *
- * Byte 0 Byte 1
- * x r4 r3 r2 r1 r0 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0
- */
- .description = "RGB555, be",
- .pixelformat = V4L2_PIX_FMT_RGB555X,
- },
-};
-
-#define NUM_CAPTURE_FORMATS ARRAY_SIZE(ov9640_formats)
-
-/*
- * OV9640 register configuration for all combinations of pixel format and
- * image size
- */
- /* YUV (YCbCr) QQCIF */
-const static struct ov9640_reg qqcif_yuv[] = {
- { 0x12, 0x08 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) QQVGA */
-const static struct ov9640_reg qqvga_yuv[] = {
- { 0x12, 0x10 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) QCIF */
-const static struct ov9640_reg qcif_yuv[] = {
- { 0x12, 0x08 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) QVGA */
-const static struct ov9640_reg qvga_yuv[] = {
- { 0x12, 0x10 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) CIF */
-const static struct ov9640_reg cif_yuv[] = {
- { 0x12, 0x20 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) VGA */
-const static struct ov9640_reg vga_yuv[] = {
- { 0x12, 0x40 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* YUV (YCbCr) SXGA */
-const static struct ov9640_reg sxga_yuv[] = {
- { 0x12, 0x00 }, { 0x3C, 0x46 }, { 0x40, 0xC0 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x50 }, { 0x50, 0x43 }, { 0x51, 0x0D }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x19 }, { 0x53, 0x4C }, { 0x54, 0x65 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x40 }, { 0x56, 0x40 }, { 0x57, 0x40 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x0F }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 QQCIF */
-const static struct ov9640_reg qqcif_565[] = {
- { 0x12, 0x0C }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 QQVGA */
-const static struct ov9640_reg qqvga_565[] = {
- { 0x12, 0x14 }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 QCIF */
-const static struct ov9640_reg qcif_565[] = {
- { 0x12, 0x0C }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 QVGA */
-const static struct ov9640_reg qvga_565[] = {
- { 0x12, 0x14 }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 CIF */
-const static struct ov9640_reg cif_565[] = {
- { 0x12, 0x24 }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 VGA */
-const static struct ov9640_reg vga_565[] = {
- { 0x12, 0x44 }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB565 SXGA */
-const static struct ov9640_reg sxga_565[] = {
- { 0x12, 0x04 }, { 0x3C, 0x40 }, { 0x40, 0x10 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 QQCIF */
-const static struct ov9640_reg qqcif_555[] = {
- { 0x12, 0x0C }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 QQVGA */
-const static struct ov9640_reg qqvga_555[] = {
- { 0x12, 0x14 }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x24 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 QCIF */
-const static struct ov9640_reg qcif_555[] = {
- { 0x12, 0x0C }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 QVGA */
-const static struct ov9640_reg qvga_555[] = {
- { 0x12, 0x14 }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 CIF */
-const static struct ov9640_reg cif_555[] = {
- { 0x12, 0x24 }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 VGA */
-const static struct ov9640_reg vga_555[] = {
- { 0x12, 0x44 }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x04 }, { 0x0D, 0xC0 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
- /* RGB555 SXGA */
-const static struct ov9640_reg sxga_555[] = {
- { 0x12, 0x04 }, { 0x3C, 0x40 }, { 0x40, 0x30 }, /* COM7, COM12, COM15 */
- { 0x04, 0x00 }, { 0x0C, 0x00 }, { 0x0D, 0x40 }, /* COM1, COM3, COM4 */
- { 0x4F, 0x71 }, { 0x50, 0x3E }, { 0x51, 0x0C }, /* MTX1, MTX2, MTX3 */
- { 0x52, 0x33 }, { 0x53, 0x72 }, { 0x54, 0x00 }, /* MTX4, MTX5, MTX6 */
- { 0x55, 0x2B }, { 0x56, 0x66 }, { 0x57, 0xD2 }, /* MTX7, MTX8, MTX9 */
- { 0x58, 0x65 }, /* MTXS */
- { OV9640_REG_TERM, OV9640_VAL_TERM }
-};
-
-
-#define DEF_GAIN 31
-#define DEF_AUTOGAIN 1
-#define DEF_EXPOSURE 154
-#define DEF_AEC 1
-#define DEF_FREEZE_AGCAEC 0
-#define DEF_BLUE 153
-#define DEF_RED (255 - DEF_BLUE)
-#define DEF_AWB 1
-#define DEF_HFLIP 0
-#define DEF_VFLIP 0
-
-/* Our own specific controls */
-#define V4L2_CID_FREEZE_AGCAEC V4L2_CID_PRIVATE_BASE
-#define V4L2_CID_AUTOEXPOSURE V4L2_CID_PRIVATE_BASE + 1
-#define V4L2_CID_LAST_PRIV V4L2_CID_AUTOEXPOSURE
-
-/* Video controls */
-static struct vcontrol {
- struct v4l2_queryctrl qc;
- int current_value;
- u8 reg;
- u8 mask;
- u8 start_bit;
-} video_control[] = {
- {
- {
- .id = V4L2_CID_GAIN,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Gain",
- .minimum = 0,
- .maximum = 63,
- .step = 1,
- .default_value = DEF_GAIN,
- },
- .current_value = 0,
- .reg = OV9640_GAIN,
- .mask = 0x3f,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_AUTOGAIN,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Auto Gain",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_AUTOGAIN,
- },
- .current_value = 0,
- .reg = OV9640_COM8,
- .mask = 0x04,
- .start_bit = 2,
- },
- {
- {
- .id = V4L2_CID_EXPOSURE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Exposure",
- .minimum = 0,
- .maximum = 255,
- .step = 1,
- .default_value = DEF_EXPOSURE,
- },
- .current_value = 0,
- .reg = OV9640_AECH,
- .mask = 0xff,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_AUTOEXPOSURE,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Auto Exposure",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_AEC,
- },
- .current_value = 0,
- .reg = OV9640_COM8,
- .mask = 0x01,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_FREEZE_AGCAEC,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Freeze AGC/AEC",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_FREEZE_AGCAEC,
- },
- .current_value = 0,
- .reg = OV9640_COM9,
- .mask = 0x01,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_RED_BALANCE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Red Balance",
- .minimum = 0,
- .maximum = 255,
- .step = 1,
- .default_value = DEF_RED,
- },
- .current_value = 0,
- .reg = OV9640_RED,
- .mask = 0xff,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_BLUE_BALANCE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Blue Balance",
- .minimum = 0,
- .maximum = 255,
- .step = 1,
- .default_value = DEF_BLUE,
- },
- .current_value = 0,
- .reg = OV9640_BLUE,
- .mask = 0xff,
- .start_bit = 0,
- },
- {
- {
- .id = V4L2_CID_AUTO_WHITE_BALANCE,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Auto White Balance",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_AWB,
- },
- .current_value = 0,
- .reg = OV9640_COM8,
- .mask = 0x02,
- .start_bit = 1,
- },
- {
- {
- .id = V4L2_CID_HFLIP,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Mirror Image",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_HFLIP,
- },
- .current_value = 0,
- .reg = OV9640_MVFP,
- .mask = 0x20,
- .start_bit = 5,
- },
- {
- {
- .id = V4L2_CID_VFLIP,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Vertical Flip",
- .minimum = 0,
- .maximum = 1,
- .step = 0,
- .default_value = DEF_VFLIP,
- },
- .current_value = 0,
- .reg = OV9640_MVFP,
- .mask = 0x10,
- .start_bit = 4,
- },
-};
-
-const static struct ov9640_reg *
- ov9640_reg_init[NUM_PIXEL_FORMATS][NUM_IMAGE_SIZES] =
-{
- { qqcif_yuv, qqvga_yuv, qcif_yuv, qvga_yuv, cif_yuv, vga_yuv, sxga_yuv },
- { qqcif_565, qqvga_565, qcif_565, qvga_565, cif_565, vga_565, sxga_565 },
- { qqcif_555, qqvga_555, qcif_555, qvga_555, cif_555, vga_555, sxga_555 },
-};
-
-
-/*
- * Read a value from a register in an OV9640 sensor device.
- * The value is returned in 'val'.
- * Returns zero if successful, or non-zero otherwise.
- */
-static int
-ov9640_read_reg(struct i2c_client *client, u8 reg, u8 *val)
-{
- int err;
- struct i2c_msg msg[1];
- unsigned char data[1];
-
- if (!client->adapter)
- return -ENODEV;
-
- msg->addr = client->addr;
- msg->flags = 0;
- msg->len = 1;
- msg->buf = data;
- *data = reg;
- err = i2c_transfer(client->adapter, msg, 1);
- if (err >= 0) {
- msg->flags = I2C_M_RD;
- err = i2c_transfer(client->adapter, msg, 1);
- }
- if (err >= 0) {
- *val = *data;
- return 0;
- }
- return err;
-}
-
-/*
- * Write a value to a register in an OV9640 sensor device.
- * Returns zero if successful, or non-zero otherwise.
- */
-static int
-ov9640_write_reg(struct i2c_client *client, u8 reg, u8 val)
-{
- int err;
- struct i2c_msg msg[1];
- unsigned char data[2];
-
- if (!client->adapter)
- return -ENODEV;
-
- msg->addr = client->addr;
- msg->flags = 0;
- msg->len = 2;
- msg->buf = data;
- data[0] = reg;
- data[1] = val;
- err = i2c_transfer(client->adapter, msg, 1);
- if (err >= 0)
- return 0;
- return err;
-}
-
-static int
-ov9640_write_reg_mask(struct i2c_client *client, u8 reg, u8 *val, u8 mask)
-{
- u8 oldval, newval;
- int rc;
-
- if (mask == 0xff)
- newval = *val;
- else {
- /* need to do read - modify - write */
- rc = ov9640_read_reg(client, reg, &oldval);
- if (rc)
- return rc;
- oldval &= (~mask); /* Clear the masked bits */
- *val &= mask; /* Enforce mask on value */
- newval = oldval | *val; /* Set the desired bits */
- }
-
- /* write the new value to the register */
- rc = ov9640_write_reg(client, reg, newval);
- if (rc)
- return rc;
-
- rc = ov9640_read_reg(client, reg, &newval);
- if (rc)
- return rc;
-
- *val = newval & mask;
- return 0;
-}
-
-static int
-ov9640_read_reg_mask(struct i2c_client *client, u8 reg, u8 *val, u8 mask)
-{
- int rc;
-
- rc = ov9640_read_reg(client, reg, val);
- if (rc)
- return rc;
- (*val) &= mask;
-
- return 0;
-}
-
-/*
- * Initialize a list of OV9640 registers.
- * The list of registers is terminated by the pair of values
- * { OV9640_REG_TERM, OV9640_VAL_TERM }.
- * Returns zero if successful, or non-zero otherwise.
- */
-static int
-ov9640_write_regs(struct i2c_client *client, const struct ov9640_reg reglist[])
-{
- int err;
- const struct ov9640_reg *next = reglist;
-
- while (!((next->reg == OV9640_REG_TERM)
- && (next->val == OV9640_VAL_TERM))) {
- err = ov9640_write_reg(client, next->reg, next->val);
- udelay(100);
- if (err)
- return err;
- next++;
- }
- return 0;
-}
-
-/* Returns the index of the requested ID from the control structure array */
-static int
-find_vctrl(int id)
-{
- int i;
-
- if (id < V4L2_CID_BASE)
- return -EDOM;
-
- for (i = (ARRAY_SIZE(video_control) - 1); i >= 0; i--)
- if (video_control[i].qc.id == id)
- break;
- if (i < 0)
- i = -EINVAL;
- return i;
-}
-
-/*
- * Calculate the internal clock divisor (value of the CLKRC register) of the
- * OV9640 given the image size, the frequency (in Hz) of its XCLK input and a
- * desired frame period (in seconds). The frame period 'fper' is expressed as
- * a fraction. The frame period is an input/output parameter.
- * Returns the value of the OV9640 CLKRC register that will yield the frame
- * period returned in 'fper' at the specified xclk frequency. The
- * returned period will be as close to the requested period as possible.
- */
-static unsigned char
-ov9640_clkrc(enum image_size isize, unsigned long xclk, struct v4l2_fract *fper)
-{
- unsigned long fpm, fpm_max; /* frames per minute */
- unsigned long divisor;
- const unsigned long divisor_max = 64;
- /* FIXME
- * clks_per_frame should come from platform data
- */
-#ifdef CONFIG_ARCH_OMAP24XX
- const static unsigned long clks_per_frame[] =
- { 200000, 400000, 200000, 400000, 400000, 800000, 3200000 };
- /* QQCIF QQVGA QCIF QVGA CIF VGA SXGA
- * 199680,400000, 199680, 400000, 399360, 800000, 3200000
- */
-#else
- const static unsigned long clks_per_frame[] =
- { 200000, 200000, 200000, 200000, 400000, 800000, 3200000 };
-#endif
-
- if (fper->numerator > 0)
- fpm = (fper->denominator*60)/fper->numerator;
- else
- fpm = 0xffffffff;
- fpm_max = (xclk*60)/clks_per_frame[isize];
- if (fpm_max == 0)
- fpm_max = 1;
- if (fpm > fpm_max)
- fpm = fpm_max;
- if (fpm == 0)
- fpm = 1;
- divisor = fpm_max/fpm;
- if (divisor > divisor_max)
- divisor = divisor_max;
- fper->numerator = divisor*60;
- fper->denominator = fpm_max;
-
- /* try to reduce the fraction */
- while (!(fper->denominator % 5) && !(fper->numerator % 5)) {
- fper->numerator /= 5;
- fper->denominator /= 5;
- }
- while (!(fper->denominator % 3) && !(fper->numerator % 3)) {
- fper->numerator /= 3;
- fper->denominator /= 3;
- }
- while (!(fper->denominator % 2) && !(fper->numerator % 2)) {
- fper->numerator /= 2;
- fper->denominator /= 2;
- }
- if (fper->numerator < fper->denominator) {
- if (!(fper->denominator % fper->numerator)) {
- fper->denominator /= fper->numerator;
- fper->numerator = 1;
- }
- } else {
- if (!(fper->numerator % fper->denominator)) {
- fper->numerator /= fper->denominator;
- fper->denominator = 1;
- }
- }
-
- /* we set bit 7 in CLKRC to enable the digital PLL */
- return (0x80 | (divisor - 1));
-}
-
-/*
- * Find the best match for a requested image capture size. The best match
- * is chosen as the nearest match that has the same number or fewer pixels
- * as the requested size, or the smallest image size if the requested size
- * has fewer pixels than the smallest image.
- */
-static enum image_size
-ov9640_find_size(unsigned int width, unsigned int height)
-{
- enum image_size isize;
- unsigned long pixels = width*height;
-
- for (isize = QQCIF; isize < SXGA; isize++) {
- if (ov9640_sizes[isize + 1].height *
- ov9640_sizes[isize + 1].width > pixels)
- return isize;
- }
- return SXGA;
-}
-
-/*
- * Given the image capture format in pix, the nominal frame period in
- * timeperframe, calculate the required xclk frequency
- */
-static unsigned long
-ov9640sensor_calc_xclk(struct i2c_client *c)
-{
- struct ov9640_sensor *sensor = i2c_get_clientdata(c);
- struct v4l2_fract *timeperframe = &sensor->timeperframe;
- struct v4l2_pix_format *pix = &sensor->pix;
-
- unsigned long tgt_xclk; /* target xclk */
- unsigned long tgt_fpm; /* target frames per minute */
- enum image_size isize;
-
- /*
- * We use arbitrary rules to select the xclk frequency. If the
- * capture size is VGA and the frame rate is greater than 900
- * frames per minute, or if the capture size is SXGA and the
- * frame rate is greater than 450 frames per minutes, then the
- * xclk frequency will be set to 48MHz. Otherwise, the xclk
- * frequency will be set to 24MHz. If the mclk frequency is such that
- * the target xclk frequency is not achievable, then xclk will be set
- * as close as to the target as possible.
- */
- tgt_fpm = (timeperframe->denominator*60)
- / timeperframe->numerator;
- tgt_xclk = OV9640_XCLK_NOM;
- isize = ov9640_find_size(pix->width, pix->height);
- switch (isize) {
- case SXGA:
- if (tgt_fpm > 450)
- tgt_xclk = OV9640_XCLK_MAX;
- break;
- case VGA:
- if (tgt_fpm > 900)
- tgt_xclk = OV9640_XCLK_MAX;
- break;
- default:
- break;
- }
- return tgt_xclk;
-}
-
-/*
- * Configure the OV9640 for a specified image size, pixel format, and frame
- * period. xclk is the frequency (in Hz) of the xclk input to the OV9640.
- * fper is the frame period (in seconds) expressed as a fraction.
- * Returns zero if successful, or non-zero otherwise.
- * The actual frame period is returned in fper.
- */
-static int ov9640_configure(struct v4l2_int_device *s)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct v4l2_pix_format *pix = &sensor->pix;
- struct v4l2_fract *fper = &sensor->timeperframe;
- struct i2c_client *client = sensor->i2c_client;
- enum image_size isize;
- unsigned long xclk;
-
- int err;
- unsigned char clkrc;
- enum pixel_format pfmt = YUV;
-
- switch (pix->pixelformat) {
- case V4L2_PIX_FMT_RGB565:
- case V4L2_PIX_FMT_RGB565X:
- pfmt = RGB565;
- break;
- case V4L2_PIX_FMT_RGB555:
- case V4L2_PIX_FMT_RGB555X:
- pfmt = RGB555;
- break;
- case V4L2_PIX_FMT_YUYV:
- case V4L2_PIX_FMT_UYVY:
- default:
- pfmt = YUV;
- }
-
- xclk = ov9640sensor_calc_xclk(client);
-
- isize = ov9640_find_size(pix->width, pix->height);
-
- /* common register initialization */
- err = ov9640_write_regs(client, sensor->pdata->default_regs);
- if (err)
- return err;
-
- /* configure image size and pixel format */
- err = ov9640_write_regs(client, ov9640_reg_init[pfmt][isize]);
- if (err)
- return err;
-
- /* configure frame rate */
- clkrc = ov9640_clkrc(isize, xclk, fper);
- err = ov9640_write_reg(client, OV9640_CLKRC, clkrc);
- if (err)
- return err;
-
- return 0;
-}
-
-/*
- * Detect if an OV9640 is present, and if so which revision.
- * A device is considered to be detected if the manufacturer ID (MIDH and MIDL)
- * and the product ID (PID) registers match the expected values.
- * Any value of the version ID (VER) register is accepted.
- * Here are the version numbers we know about:
- * 0x48 --> OV9640 Revision 1 or OV9640 Revision 2
- * 0x49 --> OV9640 Revision 3
- * Returns a negative error number if no device is detected, or the
- * non-negative value of the version ID register if a device is detected.
- */
-static int
-ov9640_detect(struct i2c_client *client)
-{
- u8 midh, midl, pid, ver;
-
- if (!client)
- return -ENODEV;
-
- if (ov9640_read_reg(client, OV9640_MIDH, &midh))
- return -ENODEV;
- if (ov9640_read_reg(client, OV9640_MIDL, &midl))
- return -ENODEV;
- if (ov9640_read_reg(client, OV9640_PID, &pid))
- return -ENODEV;
- if (ov9640_read_reg(client, OV9640_VER, &ver))
- return -ENODEV;
-
- if ((midh != OV9640_MIDH_MAGIC)
- || (midl != OV9640_MIDL_MAGIC)
- || (pid != OV9640_PID_MAGIC))
- /*
- * We didn't read the values we expected, so
- * this must not be an OV9640.
- */
- return -ENODEV;
-
- return ver;
-}
-
-/*
- * following are sensor interface functions implemented by
- * OV9640 sensor driver.
- */
-static int ioctl_queryctrl(struct v4l2_int_device *s,
- struct v4l2_queryctrl *qc)
-{
- int i;
-
- i = find_vctrl(qc->id);
- if (i == -EINVAL) {
- qc->flags = V4L2_CTRL_FLAG_DISABLED;
- return 0;
- }
- if (i < 0)
- return -EINVAL;
-
- *qc = video_control[i].qc;
- return 0;
-}
-
-static int ioctl_g_ctrl(struct v4l2_int_device *s,
- struct v4l2_control *vc)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct i2c_client *client = sensor->i2c_client;
- int i, val;
- struct vcontrol *lvc;
-
- i = find_vctrl(vc->id);
- if (i < 0)
- return -EINVAL;
-
- lvc = &video_control[i];
- if (ov9640_read_reg_mask(client, lvc->reg, (u8 *)&val, lvc->mask))
- return -EIO;
-
- val = val >> lvc->start_bit;
- if (val >= 0) {
- vc->value = lvc->current_value = val;
- return 0;
- } else
- return val;
-}
-
-static int ioctl_s_ctrl(struct v4l2_int_device *s,
- struct v4l2_control *vc)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct i2c_client *client = sensor->i2c_client;
- struct vcontrol *lvc;
- int val = vc->value;
- int i;
-
- i = find_vctrl(vc->id);
- if (i < 0)
- return -EINVAL;
-
- lvc = &video_control[i];
- val = val << lvc->start_bit;
- if (ov9640_write_reg_mask(client, lvc->reg, (u8 *)&val, (u8)lvc->mask))
- return -EIO;
-
- val = val >> lvc->start_bit;
- if (val >= 0) {
- lvc->current_value = val;
- return 0;
- } else
- return val;
-}
-
-/*
- * Implement the VIDIOC_ENUM_FMT ioctl for the CAPTURE buffer type.
- */
-static int ioctl_enum_fmt_cap(struct v4l2_int_device *s,
- struct v4l2_fmtdesc *fmt)
-{
- int index = fmt->index;
- enum v4l2_buf_type type = fmt->type;
-
- memset(fmt, 0, sizeof(*fmt));
- fmt->index = index;
- fmt->type = type;
-
- switch (fmt->type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- if (index >= NUM_CAPTURE_FORMATS)
- return -EINVAL;
- break;
- default:
- return -EINVAL;
- }
-
- fmt->flags = ov9640_formats[index].flags;
- strlcpy(fmt->description, ov9640_formats[index].description,
- sizeof(fmt->description));
- fmt->pixelformat = ov9640_formats[index].pixelformat;
-
- return 0;
-}
-
-/*
- * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
- * ioctl is used to negotiate the image capture size and pixel format
- * without actually making it take effect.
- */
-static int ioctl_try_fmt_cap(struct v4l2_int_device *s,
- struct v4l2_format *f)
-{
- enum image_size isize;
- int ifmt;
- struct v4l2_pix_format *pix = &f->fmt.pix;
-
- isize = ov9640_find_size(pix->width, pix->height);
- pix->width = ov9640_sizes[isize].width;
- pix->height = ov9640_sizes[isize].height;
- for (ifmt = 0; ifmt < NUM_CAPTURE_FORMATS; ifmt++) {
- if (pix->pixelformat == ov9640_formats[ifmt].pixelformat)
- break;
- }
- if (ifmt == NUM_CAPTURE_FORMATS)
- ifmt = 0;
- pix->pixelformat = ov9640_formats[ifmt].pixelformat;
- pix->field = V4L2_FIELD_NONE;
- pix->bytesperline = pix->width*2;
- pix->sizeimage = pix->bytesperline*pix->height;
- pix->priv = 0;
- switch (pix->pixelformat) {
- case V4L2_PIX_FMT_YUYV:
- case V4L2_PIX_FMT_UYVY:
- default:
- pix->colorspace = V4L2_COLORSPACE_JPEG;
- break;
- case V4L2_PIX_FMT_RGB565:
- case V4L2_PIX_FMT_RGB565X:
- case V4L2_PIX_FMT_RGB555:
- case V4L2_PIX_FMT_RGB555X:
- pix->colorspace = V4L2_COLORSPACE_SRGB;
- break;
- }
- return 0;
-}
-
-static int ioctl_s_fmt_cap(struct v4l2_int_device *s,
- struct v4l2_format *f)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct v4l2_pix_format *pix = &f->fmt.pix;
- int rval;
-
- rval = ioctl_try_fmt_cap(s, f);
- if (rval)
- return rval;
-
- rval = ov9640_configure(s);
-
- if (!rval)
- sensor->pix = *pix;
-
- return rval;
-}
-
-static int ioctl_g_fmt_cap(struct v4l2_int_device *s,
- struct v4l2_format *f)
-{
- struct ov9640_sensor *sensor = s->priv;
-
- f->fmt.pix = sensor->pix;
-
- return 0;
-}
-
-static int ioctl_g_parm(struct v4l2_int_device *s,
- struct v4l2_streamparm *a)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct v4l2_captureparm *cparm = &a->parm.capture;
-
- if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
- return -EINVAL;
-
- memset(a, 0, sizeof(*a));
- a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- cparm->capability = V4L2_CAP_TIMEPERFRAME;
- cparm->timeperframe = sensor->timeperframe;
-
- return 0;
-}
-
-static int ioctl_s_parm(struct v4l2_int_device *s,
- struct v4l2_streamparm *a)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct v4l2_fract *timeperframe = &a->parm.capture.timeperframe;
- struct v4l2_fract timeperframe_old;
- int rval;
-
- timeperframe_old = sensor->timeperframe;
- sensor->timeperframe = *timeperframe;
-
- rval = ov9640_configure(s);
-
- if (rval)
- sensor->timeperframe = timeperframe_old;
- else
- *timeperframe = sensor->timeperframe;
-
- return rval;
-}
-
-static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct i2c_client *client = sensor->i2c_client;
- u32 xclk; /* target xclk */
- int rval;
-
- rval = sensor->pdata->ifparm(p);
- if (rval)
- return rval;
-
- xclk = ov9640sensor_calc_xclk(client);
-
- p->u.bt656.clock_curr = xclk;
-
- return 0;
-}
-
-static int ioctl_s_power(struct v4l2_int_device *s, int on)
-{
- struct ov9640_sensor *sensor = s->priv;
-
- return sensor->pdata->power_set(on);
-}
-
-static int ioctl_init(struct v4l2_int_device *s)
-{
- return ov9640_configure(s);
-}
-
-static int ioctl_dev_exit(struct v4l2_int_device *s)
-{
- return 0;
-}
-
-static int ioctl_dev_init(struct v4l2_int_device *s)
-{
- struct ov9640_sensor *sensor = s->priv;
- struct i2c_client *c = sensor->i2c_client;
- int err;
-
- err = ov9640_detect(c);
- if (err < 0) {
- dev_err(&c->dev, "Unable to detect " DRIVER_NAME " sensor\n");
- return err;
- }
-
- sensor->ver = err;
- pr_info(DRIVER_NAME " chip version 0x%02x detected\n", sensor->ver);
-
- return 0;
-}
-
-static struct v4l2_int_ioctl_desc ov9640_ioctl_desc[] = {
- { vidioc_int_dev_init_num,
- (v4l2_int_ioctl_func *)ioctl_dev_init },
- { vidioc_int_dev_exit_num,
- (v4l2_int_ioctl_func *)ioctl_dev_exit },
- { vidioc_int_s_power_num,
- (v4l2_int_ioctl_func *)ioctl_s_power },
- { vidioc_int_g_ifparm_num,
- (v4l2_int_ioctl_func *)ioctl_g_ifparm },
- { vidioc_int_init_num,
- (v4l2_int_ioctl_func *)ioctl_init },
- { vidioc_int_enum_fmt_cap_num,
- (v4l2_int_ioctl_func *)ioctl_enum_fmt_cap },
- { vidioc_int_try_fmt_cap_num,
- (v4l2_int_ioctl_func *)ioctl_try_fmt_cap },
- { vidioc_int_g_fmt_cap_num,
- (v4l2_int_ioctl_func *)ioctl_g_fmt_cap },
- { vidioc_int_s_fmt_cap_num,
- (v4l2_int_ioctl_func *)ioctl_s_fmt_cap },
- { vidioc_int_g_parm_num,
- (v4l2_int_ioctl_func *)ioctl_g_parm },
- { vidioc_int_s_parm_num,
- (v4l2_int_ioctl_func *)ioctl_s_parm },
- { vidioc_int_queryctrl_num,
- (v4l2_int_ioctl_func *)ioctl_queryctrl },
- { vidioc_int_g_ctrl_num,
- (v4l2_int_ioctl_func *)ioctl_g_ctrl },
- { vidioc_int_s_ctrl_num,
- (v4l2_int_ioctl_func *)ioctl_s_ctrl },
-};
-
-static struct v4l2_int_slave ov9640_slave = {
- .ioctls = ov9640_ioctl_desc,
- .num_ioctls = ARRAY_SIZE(ov9640_ioctl_desc),
-};
-
-static struct v4l2_int_device ov9640_int_device = {
- .module = THIS_MODULE,
- .name = DRIVER_NAME,
- .priv = &ov9640,
- .type = v4l2_int_type_slave,
- .u = {
- .slave = &ov9640_slave,
- },
-};
-
-static int __init
-ov9640_probe(struct i2c_client *client)
-{
- struct ov9640_sensor *sensor = &ov9640;
- int err;
-
- if (i2c_get_clientdata(client))
- return -EBUSY;
-
- sensor->pdata = client->dev.platform_data;
-
- if (!sensor->pdata || !sensor->pdata->default_regs) {
- dev_err(&client->dev, "no platform data?\n");
- return -ENODEV;
- }
-
- sensor->v4l2_int_device = &ov9640_int_device;
- sensor->i2c_client = client;
-
- i2c_set_clientdata(client, sensor);
-
- /* Make the default capture format QCIF RGB565 */
- sensor->pix.width = ov9640_sizes[QCIF].width;
- sensor->pix.height = ov9640_sizes[QCIF].height;
- sensor->pix.pixelformat = V4L2_PIX_FMT_RGB565;
-
- err = v4l2_int_device_register(sensor->v4l2_int_device);
- if (err)
- i2c_set_clientdata(client, NULL);
-
- return 0;
-}
-
-static int __exit
-ov9640_remove(struct i2c_client *client)
-{
- struct ov9640_sensor *sensor = i2c_get_clientdata(client);
-
- if (!client->adapter)
- return -ENODEV; /* our client isn't attached */
-
- v4l2_int_device_unregister(sensor->v4l2_int_device);
- i2c_set_clientdata(client, NULL);
-
- return 0;
-}
-
-static struct i2c_driver ov9640sensor_i2c_driver = {
- .driver = {
- .name = DRIVER_NAME,
- },
- .probe = ov9640_probe,
- .remove = __exit_p(ov9640_remove),
-};
-
-static struct ov9640_sensor ov9640 = {
- .timeperframe = {
- .numerator = 1,
- .denominator = 15,
- },
-};
-
-static int ov9640sensor_init(void)
-{
- int err;
-
- err = i2c_add_driver(&ov9640sensor_i2c_driver);
- if (err) {
- printk(KERN_ERR "Failed to register" DRIVER_NAME ".\n");
- return err;
- }
- return 0;
-}
-module_init(ov9640sensor_init);
-
-static void __exit ov9640sensor_cleanup(void)
-{
- i2c_del_driver(&ov9640sensor_i2c_driver);
-}
-module_exit(ov9640sensor_cleanup);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("OV9640 camera sensor driver");
+++ /dev/null
-/*
- * drivers/media/video/ov9640.h
- *
- * Register definitions for the OmniVision OV9640 CameraChip.
- *
- * Author: Andy Lowe (source@mvista.com)
- *
- * Copyright (C) 2004 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- *
- * This file is licensed under the terms of the GNU General Public License
- * version 2. This program is licensed "as is" without any warranty of any
- * kind, whether express or implied.
- */
-
-#ifndef OV9640_H
-#define OV9640_H
-
-#define OV9640_I2C_ADDR 0x30
-
-/* define register offsets for the OV9640 sensor chip */
-#define OV9640_GAIN 0x00
-#define OV9640_BLUE 0x01
-#define OV9640_RED 0x02
-#define OV9640_VREF 0x03
-#define OV9640_COM1 0x04
-#define OV9640_BAVE 0x05
-#define OV9640_GEAVE 0x06
-#define OV9640_RAVE 0x08
-#define OV9640_COM2 0x09
-#define OV9640_PID 0x0A
-#define OV9640_VER 0x0B
-#define OV9640_COM3 0x0C
-#define OV9640_COM4 0x0D
-#define OV9640_COM5 0x0E
-#define OV9640_COM6 0x0F
-#define OV9640_AECH 0x10
-#define OV9640_CLKRC 0x11
-#define OV9640_COM7 0x12
-#define OV9640_COM8 0x13
-#define OV9640_COM9 0x14
-#define OV9640_COM10 0x15
-#define OV9640_HSTRT 0x17
-#define OV9640_HSTOP 0x18
-#define OV9640_VSTRT 0x19
-#define OV9640_VSTOP 0x1A
-#define OV9640_PSHFT 0x1B
-#define OV9640_MIDH 0x1C
-#define OV9640_MIDL 0x1D
-#define OV9640_MVFP 0x1E
-#define OV9640_LAEC 0x1F
-#define OV9640_BOS 0x20
-#define OV9640_GBOS 0x21
-#define OV9640_GROS 0x22
-#define OV9640_ROS 0x23
-#define OV9640_AEW 0x24
-#define OV9640_AEB 0x25
-#define OV9640_VPT 0x26
-#define OV9640_BBIAS 0x27
-#define OV9640_GBBIAS 0x28
-#define OV9640_EXHCH 0x2A
-#define OV9640_EXHCL 0x2B
-#define OV9640_RBIAS 0x2C
-#define OV9640_ADVFL 0x2D
-#define OV9640_ADVFH 0x2E
-#define OV9640_YAVE 0x2F
-#define OV9640_HSYST 0x30
-#define OV9640_HSYEN 0x31
-#define OV9640_HREF 0x32
-#define OV9640_CHLF 0x33
-#define OV9640_ARBLM 0x34
-#define OV9640_ADC 0x37
-#define OV9640_ACOM 0x38
-#define OV9640_OFON 0x39
-#define OV9640_TSLB 0x3A
-#define OV9640_COM11 0x3B
-#define OV9640_COM12 0x3C
-#define OV9640_COM13 0x3D
-#define OV9640_COM14 0x3E
-#define OV9640_EDGE 0x3F
-#define OV9640_COM15 0x40
-#define OV9640_COM16 0x41
-#define OV9640_COM17 0x42
-#define OV9640_MTX1 0x4F
-#define OV9640_MTX2 0x50
-#define OV9640_MTX3 0x51
-#define OV9640_MTX4 0x52
-#define OV9640_MTX5 0x53
-#define OV9640_MTX6 0x54
-#define OV9640_MTX7 0x55
-#define OV9640_MTX8 0x56
-#define OV9640_MTX9 0x57
-#define OV9640_MTXS 0x58
-#define OV9640_LCC1 0x62
-#define OV9640_LCC2 0x63
-#define OV9640_LCC3 0x64
-#define OV9640_LCC4 0x65
-#define OV9640_LCC5 0x66
-#define OV9640_MANU 0x67
-#define OV9640_MANV 0x68
-#define OV9640_HV 0x69
-#define OV9640_MBD 0x6A
-#define OV9640_DBLV 0x6B
-#define OV9640_GSP1 0x6C
-#define OV9640_GSP2 0x6D
-#define OV9640_GSP3 0x6E
-#define OV9640_GSP4 0x6F
-#define OV9640_GSP5 0x70
-#define OV9640_GSP6 0x71
-#define OV9640_GSP7 0x72
-#define OV9640_GSP8 0x73
-#define OV9640_GSP9 0x74
-#define OV9640_GSP10 0x75
-#define OV9640_GSP11 0x76
-#define OV9640_GSP12 0x77
-#define OV9640_GSP13 0x78
-#define OV9640_GSP14 0x79
-#define OV9640_GSP15 0x7A
-#define OV9640_GSP16 0x7B
-#define OV9640_GST1 0x7C
-#define OV9640_GST2 0x7D
-#define OV9640_GST3 0x7E
-#define OV9640_GST4 0x7F
-#define OV9640_GST5 0x80
-#define OV9640_GST6 0x81
-#define OV9640_GST7 0x82
-#define OV9640_GST8 0x83
-#define OV9640_GST9 0x84
-#define OV9640_GST10 0x85
-#define OV9640_GST11 0x86
-#define OV9640_GST12 0x87
-#define OV9640_GST13 0x88
-#define OV9640_GST14 0x89
-#define OV9640_GST15 0x8A
-
-#define OV9640_NUM_REGS (OV9640_GST15 + 1)
-
-#define OV9640_PID_MAGIC 0x96 /* high byte of product ID number */
-#define OV9640_VER_REV2 0x48 /* low byte of product ID number */
-#define OV9640_VER_REV3 0x49 /* low byte of product ID number */
-#define OV9640_MIDH_MAGIC 0x7F /* high byte of mfg ID */
-#define OV9640_MIDL_MAGIC 0xA2 /* low byte of mfg ID */
-
-#define OV9640_REG_TERM 0xFF /* terminating list entry for reg */
-#define OV9640_VAL_TERM 0xFF /* terminating list entry for val */
-
-/*
- * The nominal xclk input frequency of the OV9640 is 24MHz, maximum
- * frequency is 48MHz, and minimum frequency is 10MHz.
- */
-#define OV9640_XCLK_MIN 10000000
-#define OV9640_XCLK_MAX 48000000
-#define OV9640_XCLK_NOM 24000000
-
-/* define a structure for ov9640 register initialization values */
-struct ov9640_reg {
- unsigned char reg;
- unsigned char val;
-};
-
-enum image_size { QQCIF, QQVGA, QCIF, QVGA, CIF, VGA, SXGA };
-enum pixel_format { YUV, RGB565, RGB555 };
-
-#define NUM_IMAGE_SIZES 7
-#define NUM_PIXEL_FORMATS 3
-
-struct capture_size {
- unsigned long width;
- unsigned long height;
-};
-
-struct ov9640_platform_data {
- /* Set power state, zero is off, non-zero is on. */
- int (*power_set)(int power);
- /* Default registers written after power-on or reset. */
- const struct ov9640_reg *default_regs;
- int (*ifparm)(struct v4l2_ifparm *p);
-};
-
-/*
- * Array of image sizes supported by OV9640. These must be ordered from
- * smallest image size to largest.
- */
-const static struct capture_size ov9640_sizes[] = {
- { 88, 72 }, /* QQCIF */
- { 160, 120 }, /* QQVGA */
- { 176, 144 }, /* QCIF */
- { 320, 240 }, /* QVGA */
- { 352, 288 }, /* CIF */
- { 640, 480 }, /* VGA */
- { 1280, 960 }, /* SXGA */
-};
-
-#endif /* ifndef OV9640_H */