Commit abfa3df3 authored by Jonathan Corbet's avatar Jonathan Corbet Committed by Mauro Carvalho Chehab

[media] marvell-cam: Separate out the Marvell camera core

There will eventually be multiple users of the core camera controller, so
separate it from the bus/platform/i2c stuff.  I've tried to do the minimal
set of changes to get the driver functioning in this configuration; I did
clean up a bunch of old checkpatch gripes in the process.  This driver
works like the old one did on OLPC XO 1 systems.

Cc: Daniel Drake <dsd@laptop.org>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent f8fc7298
obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
cafe_ccic-y := cafe-driver.o mcam-core.o
/*
* A driver for the CMOS camera controller in the Marvell 88ALP01 "cafe"
* multifunction chip. Currently works with the Omnivision OV7670
* sensor.
*
* The data sheet for this device can be found at:
* http://www.marvell.com/products/pc_connectivity/88alp01/
*
* Copyright 2006-11 One Laptop Per Child Association, Inc.
* Copyright 2006-11 Jonathan Corbet <corbet@lwn.net>
*
* Written by Jonathan Corbet, corbet@lwn.net.
*
* v4l2_device/v4l2_subdev conversion by:
* Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
*
* Note: this conversion is untested! Please contact the linux-media
* mailinglist if you can test this, together with the test results.
*
* This file may be distributed under the terms of the GNU General
* Public License, version 2.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-chip-ident.h>
#include <linux/device.h>
#include <linux/wait.h>
#include <linux/delay.h>
#include <linux/io.h>
#include "mcam-core.h"
#define CAFE_VERSION 0x000002
/*
* Parameters.
*/
MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
MODULE_DESCRIPTION("Marvell 88ALP01 CMOS Camera Controller driver");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("Video");
struct cafe_camera {
int registered; /* Fully initialized? */
struct mcam_camera mcam;
struct pci_dev *pdev;
wait_queue_head_t smbus_wait; /* Waiting on i2c events */
};
/*
* Debugging and related.
*/
#define cam_err(cam, fmt, arg...) \
dev_err(&(cam)->pdev->dev, fmt, ##arg);
#define cam_warn(cam, fmt, arg...) \
dev_warn(&(cam)->pdev->dev, fmt, ##arg);
/* -------------------------------------------------------------------- */
/*
* The I2C/SMBUS interface to the camera itself starts here. The
* controller handles SMBUS itself, presenting a relatively simple register
* interface; all we have to do is to tell it where to route the data.
*/
#define CAFE_SMBUS_TIMEOUT (HZ) /* generous */
static inline struct cafe_camera *to_cam(struct v4l2_device *dev)
{
struct mcam_camera *m = container_of(dev, struct mcam_camera, v4l2_dev);
return container_of(m, struct cafe_camera, mcam);
}
static int cafe_smbus_write_done(struct mcam_camera *mcam)
{
unsigned long flags;
int c1;
/*
* We must delay after the interrupt, or the controller gets confused
* and never does give us good status. Fortunately, we don't do this
* often.
*/
udelay(20);
spin_lock_irqsave(&mcam->dev_lock, flags);
c1 = mcam_reg_read(mcam, REG_TWSIC1);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
return (c1 & (TWSIC1_WSTAT|TWSIC1_ERROR)) != TWSIC1_WSTAT;
}
static int cafe_smbus_write_data(struct cafe_camera *cam,
u16 addr, u8 command, u8 value)
{
unsigned int rval;
unsigned long flags;
struct mcam_camera *mcam = &cam->mcam;
spin_lock_irqsave(&mcam->dev_lock, flags);
rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
/*
* Marvell sez set clkdiv to all 1's for now.
*/
rval |= TWSIC0_CLKDIV;
mcam_reg_write(mcam, REG_TWSIC0, rval);
(void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */
rval = value | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
mcam_reg_write(mcam, REG_TWSIC1, rval);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
/* Unfortunately, reading TWSIC1 too soon after sending a command
* causes the device to die.
* Use a busy-wait because we often send a large quantity of small
* commands at-once; using msleep() would cause a lot of context
* switches which take longer than 2ms, resulting in a noticeable
* boot-time and capture-start delays.
*/
mdelay(2);
/*
* Another sad fact is that sometimes, commands silently complete but
* cafe_smbus_write_done() never becomes aware of this.
* This happens at random and appears to possible occur with any
* command.
* We don't understand why this is. We work around this issue
* with the timeout in the wait below, assuming that all commands
* complete within the timeout.
*/
wait_event_timeout(cam->smbus_wait, cafe_smbus_write_done(mcam),
CAFE_SMBUS_TIMEOUT);
spin_lock_irqsave(&mcam->dev_lock, flags);
rval = mcam_reg_read(mcam, REG_TWSIC1);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
if (rval & TWSIC1_WSTAT) {
cam_err(cam, "SMBUS write (%02x/%02x/%02x) timed out\n", addr,
command, value);
return -EIO;
}
if (rval & TWSIC1_ERROR) {
cam_err(cam, "SMBUS write (%02x/%02x/%02x) error\n", addr,
command, value);
return -EIO;
}
return 0;
}
static int cafe_smbus_read_done(struct mcam_camera *mcam)
{
unsigned long flags;
int c1;
/*
* We must delay after the interrupt, or the controller gets confused
* and never does give us good status. Fortunately, we don't do this
* often.
*/
udelay(20);
spin_lock_irqsave(&mcam->dev_lock, flags);
c1 = mcam_reg_read(mcam, REG_TWSIC1);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
return c1 & (TWSIC1_RVALID|TWSIC1_ERROR);
}
static int cafe_smbus_read_data(struct cafe_camera *cam,
u16 addr, u8 command, u8 *value)
{
unsigned int rval;
unsigned long flags;
struct mcam_camera *mcam = &cam->mcam;
spin_lock_irqsave(&mcam->dev_lock, flags);
rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
/*
* Marvel sez set clkdiv to all 1's for now.
*/
rval |= TWSIC0_CLKDIV;
mcam_reg_write(mcam, REG_TWSIC0, rval);
(void) mcam_reg_read(mcam, REG_TWSIC1); /* force write */
rval = TWSIC1_READ | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
mcam_reg_write(mcam, REG_TWSIC1, rval);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
wait_event_timeout(cam->smbus_wait,
cafe_smbus_read_done(mcam), CAFE_SMBUS_TIMEOUT);
spin_lock_irqsave(&mcam->dev_lock, flags);
rval = mcam_reg_read(mcam, REG_TWSIC1);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
if (rval & TWSIC1_ERROR) {
cam_err(cam, "SMBUS read (%02x/%02x) error\n", addr, command);
return -EIO;
}
if (!(rval & TWSIC1_RVALID)) {
cam_err(cam, "SMBUS read (%02x/%02x) timed out\n", addr,
command);
return -EIO;
}
*value = rval & 0xff;
return 0;
}
/*
* Perform a transfer over SMBUS. This thing is called under
* the i2c bus lock, so we shouldn't race with ourselves...
*/
static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
unsigned short flags, char rw, u8 command,
int size, union i2c_smbus_data *data)
{
struct cafe_camera *cam = i2c_get_adapdata(adapter);
int ret = -EINVAL;
/*
* This interface would appear to only do byte data ops. OK
* it can do word too, but the cam chip has no use for that.
*/
if (size != I2C_SMBUS_BYTE_DATA) {
cam_err(cam, "funky xfer size %d\n", size);
return -EINVAL;
}
if (rw == I2C_SMBUS_WRITE)
ret = cafe_smbus_write_data(cam, addr, command, data->byte);
else if (rw == I2C_SMBUS_READ)
ret = cafe_smbus_read_data(cam, addr, command, &data->byte);
return ret;
}
static void cafe_smbus_enable_irq(struct cafe_camera *cam)
{
unsigned long flags;
spin_lock_irqsave(&cam->mcam.dev_lock, flags);
mcam_reg_set_bit(&cam->mcam, REG_IRQMASK, TWSIIRQS);
spin_unlock_irqrestore(&cam->mcam.dev_lock, flags);
}
static u32 cafe_smbus_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_READ_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
}
static struct i2c_algorithm cafe_smbus_algo = {
.smbus_xfer = cafe_smbus_xfer,
.functionality = cafe_smbus_func
};
static int cafe_smbus_setup(struct cafe_camera *cam)
{
struct i2c_adapter *adap = &cam->mcam.i2c_adapter;
int ret;
cafe_smbus_enable_irq(cam);
adap->owner = THIS_MODULE;
adap->algo = &cafe_smbus_algo;
strcpy(adap->name, "cafe_ccic");
adap->dev.parent = &cam->pdev->dev;
i2c_set_adapdata(adap, cam);
ret = i2c_add_adapter(adap);
if (ret)
printk(KERN_ERR "Unable to register cafe i2c adapter\n");
return ret;
}
static void cafe_smbus_shutdown(struct cafe_camera *cam)
{
i2c_del_adapter(&cam->mcam.i2c_adapter);
}
/*
* Controller-level stuff
*/
static void cafe_ctlr_init(struct mcam_camera *mcam)
{
unsigned long flags;
spin_lock_irqsave(&mcam->dev_lock, flags);
/*
* Added magic to bring up the hardware on the B-Test board
*/
mcam_reg_write(mcam, 0x3038, 0x8);
mcam_reg_write(mcam, 0x315c, 0x80008);
/*
* Go through the dance needed to wake the device up.
* Note that these registers are global and shared
* with the NAND and SD devices. Interaction between the
* three still needs to be examined.
*/
mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */
mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRC);
mcam_reg_write(mcam, REG_GL_CSR, GCSR_SRC|GCSR_MRS);
/*
* Here we must wait a bit for the controller to come around.
*/
spin_unlock_irqrestore(&mcam->dev_lock, flags);
msleep(5);
spin_lock_irqsave(&mcam->dev_lock, flags);
mcam_reg_write(mcam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC);
mcam_reg_set_bit(mcam, REG_GL_IMASK, GIMSK_CCIC_EN);
/*
* Mask all interrupts.
*/
mcam_reg_write(mcam, REG_IRQMASK, 0);
spin_unlock_irqrestore(&mcam->dev_lock, flags);
}
static void cafe_ctlr_power_up(struct mcam_camera *mcam)
{
/*
* Part one of the sensor dance: turn the global
* GPIO signal on.
*/
mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON);
mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT|GGPIO_VAL);
/*
* Put the sensor into operational mode (assumes OLPC-style
* wiring). Control 0 is reset - set to 1 to operate.
* Control 1 is power down, set to 0 to operate.
*/
mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
}
static void cafe_ctlr_power_down(struct mcam_camera *mcam)
{
mcam_reg_write(mcam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1);
mcam_reg_write(mcam, REG_GL_FCR, GFCR_GPIO_ON);
mcam_reg_write(mcam, REG_GL_GPIOR, GGPIO_OUT);
}
/*
* The platform interrupt handler.
*/
static irqreturn_t cafe_irq(int irq, void *data)
{
struct cafe_camera *cam = data;
struct mcam_camera *mcam = &cam->mcam;
unsigned int irqs, handled;
spin_lock(&mcam->dev_lock);
irqs = mcam_reg_read(mcam, REG_IRQSTAT);
handled = cam->registered && mccic_irq(mcam, irqs);
if (irqs & TWSIIRQS) {
mcam_reg_write(mcam, REG_IRQSTAT, TWSIIRQS);
wake_up(&cam->smbus_wait);
handled = 1;
}
spin_unlock(&mcam->dev_lock);
return IRQ_RETVAL(handled);
}
/* -------------------------------------------------------------------------- */
/*
* PCI interface stuff.
*/
static int cafe_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
int ret;
struct cafe_camera *cam;
struct mcam_camera *mcam;
/*
* Start putting together one of our big camera structures.
*/
ret = -ENOMEM;
cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL);
if (cam == NULL)
goto out;
cam->pdev = pdev;
mcam = &cam->mcam;
mcam->chip_id = V4L2_IDENT_CAFE;
spin_lock_init(&mcam->dev_lock);
init_waitqueue_head(&cam->smbus_wait);
mcam->plat_power_up = cafe_ctlr_power_up;
mcam->plat_power_down = cafe_ctlr_power_down;
mcam->dev = &pdev->dev;
/*
* Get set up on the PCI bus.
*/
ret = pci_enable_device(pdev);
if (ret)
goto out_free;
pci_set_master(pdev);
ret = -EIO;
mcam->regs = pci_iomap(pdev, 0, 0);
if (!mcam->regs) {
printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
goto out_disable;
}
ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
if (ret)
goto out_iounmap;
/*
* Initialize the controller and leave it powered up. It will
* stay that way until the sensor driver shows up.
*/
cafe_ctlr_init(mcam);
cafe_ctlr_power_up(mcam);
/*
* Set up I2C/SMBUS communications. We have to drop the mutex here
* because the sensor could attach in this call chain, leading to
* unsightly deadlocks.
*/
ret = cafe_smbus_setup(cam);
if (ret)
goto out_pdown;
ret = mccic_register(mcam);
if (ret == 0) {
cam->registered = 1;
return 0;
}
cafe_smbus_shutdown(cam);
out_pdown:
cafe_ctlr_power_down(mcam);
free_irq(pdev->irq, cam);
out_iounmap:
pci_iounmap(pdev, mcam->regs);
out_disable:
pci_disable_device(pdev);
out_free:
kfree(cam);
out:
return ret;
}
/*
* Shut down an initialized device
*/
static void cafe_shutdown(struct cafe_camera *cam)
{
mccic_shutdown(&cam->mcam);
cafe_smbus_shutdown(cam);
free_irq(cam->pdev->irq, cam);
pci_iounmap(cam->pdev, cam->mcam.regs);
}
static void cafe_pci_remove(struct pci_dev *pdev)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
struct cafe_camera *cam = to_cam(v4l2_dev);
if (cam == NULL) {
printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
return;
}
cafe_shutdown(cam);
kfree(cam);
}
#ifdef CONFIG_PM
/*
* Basic power management.
*/
static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
struct cafe_camera *cam = to_cam(v4l2_dev);
int ret;
ret = pci_save_state(pdev);
if (ret)
return ret;
mccic_suspend(&cam->mcam);
pci_disable_device(pdev);
return 0;
}
static int cafe_pci_resume(struct pci_dev *pdev)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
struct cafe_camera *cam = to_cam(v4l2_dev);
int ret = 0;
pci_restore_state(pdev);
ret = pci_enable_device(pdev);
if (ret) {
cam_warn(cam, "Unable to re-enable device on resume!\n");
return ret;
}
cafe_ctlr_init(&cam->mcam);
return mccic_resume(&cam->mcam);
}
#endif /* CONFIG_PM */
static struct pci_device_id cafe_ids[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL,
PCI_DEVICE_ID_MARVELL_88ALP01_CCIC) },
{ 0, }
};
MODULE_DEVICE_TABLE(pci, cafe_ids);
static struct pci_driver cafe_pci_driver = {
.name = "cafe1000-ccic",
.id_table = cafe_ids,
.probe = cafe_pci_probe,
.remove = cafe_pci_remove,
#ifdef CONFIG_PM
.suspend = cafe_pci_suspend,
.resume = cafe_pci_resume,
#endif
};
static int __init cafe_init(void)
{
int ret;
printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
CAFE_VERSION);
ret = pci_register_driver(&cafe_pci_driver);
if (ret) {
printk(KERN_ERR "Unable to register cafe_ccic driver\n");
goto out;
}
ret = 0;
out:
return ret;
}
static void __exit cafe_exit(void)
{
pci_unregister_driver(&cafe_pci_driver);
}
module_init(cafe_init);
module_exit(cafe_exit);
/* /*
* A driver for the CMOS camera controller in the Marvell 88ALP01 "cafe" * The Marvell camera core. This device appears in a number of settings,
* multifunction chip. Currently works with the Omnivision OV7670 * so it needs platform-specific support outside of the core.
* sensor.
* *
* The data sheet for this device can be found at: * Copyright 2011 Jonathan Corbet corbet@lwn.net
* http://www.marvell.com/products/pc_connectivity/88alp01/
*
* Copyright 2006 One Laptop Per Child Association, Inc.
* Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
*
* Written by Jonathan Corbet, corbet@lwn.net.
*
* v4l2_device/v4l2_subdev conversion by:
* Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
*
* Note: this conversion is untested! Please contact the linux-media
* mailinglist if you can test this, together with the test results.
*
* This file may be distributed under the terms of the GNU General
* Public License, version 2.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/pci.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -44,22 +25,11 @@ ...@@ -44,22 +25,11 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <asm/uaccess.h> #include "mcam-core.h"
#include <asm/io.h>
#include "cafe_ccic-regs.h"
#define CAFE_VERSION 0x000002
/*
* Parameters.
*/
MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
MODULE_DESCRIPTION("Marvell 88ALP01 CMOS Camera Controller driver");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("Video");
/* /*
* Internal DMA buffer management. Since the controller cannot do S/G I/O, * Internal DMA buffer management. Since the controller cannot do S/G I/O,
...@@ -74,7 +44,6 @@ MODULE_SUPPORTED_DEVICE("Video"); ...@@ -74,7 +44,6 @@ MODULE_SUPPORTED_DEVICE("Video");
* sense. * sense.
*/ */
#define MAX_DMA_BUFS 3
static int alloc_bufs_at_read; static int alloc_bufs_at_read;
module_param(alloc_bufs_at_read, bool, 0444); module_param(alloc_bufs_at_read, bool, 0444);
MODULE_PARM_DESC(alloc_bufs_at_read, MODULE_PARM_DESC(alloc_bufs_at_read,
...@@ -115,84 +84,6 @@ MODULE_PARM_DESC(flip, ...@@ -115,84 +84,6 @@ MODULE_PARM_DESC(flip,
"If set, the sensor will be instructed to flip the image " "If set, the sensor will be instructed to flip the image "
"vertically."); "vertically.");
enum cafe_state {
S_NOTREADY, /* Not yet initialized */
S_IDLE, /* Just hanging around */
S_FLAKED, /* Some sort of problem */
S_SINGLEREAD, /* In read() */
S_SPECREAD, /* Speculative read (for future read()) */
S_STREAMING /* Streaming data */
};
/*
* Tracking of streaming I/O buffers.
*/
struct cafe_sio_buffer {
struct list_head list;
struct v4l2_buffer v4lbuf;
char *buffer; /* Where it lives in kernel space */
int mapcount;
struct cafe_camera *cam;
};
/*
* A description of one of our devices.
* Locking: controlled by s_mutex. Certain fields, however, require
* the dev_lock spinlock; they are marked as such by comments.
* dev_lock is also required for access to device registers.
*/
struct cafe_camera
{
struct v4l2_device v4l2_dev;
enum cafe_state state;
unsigned long flags; /* Buffer status, mainly (dev_lock) */
int users; /* How many open FDs */
struct file *owner; /* Who has data access (v4l2) */
/*
* Subsystem structures.
*/
struct pci_dev *pdev;
struct video_device vdev;
struct i2c_adapter i2c_adapter;
struct v4l2_subdev *sensor;
unsigned short sensor_addr;
unsigned char __iomem *regs;
struct list_head dev_list; /* link to other devices */
/* DMA buffers */
unsigned int nbufs; /* How many are alloc'd */
int next_buf; /* Next to consume (dev_lock) */
unsigned int dma_buf_size; /* allocated size */
void *dma_bufs[MAX_DMA_BUFS]; /* Internal buffer addresses */
dma_addr_t dma_handles[MAX_DMA_BUFS]; /* Buffer bus addresses */
unsigned int specframes; /* Unconsumed spec frames (dev_lock) */
unsigned int sequence; /* Frame sequence number */
unsigned int buf_seq[MAX_DMA_BUFS]; /* Sequence for individual buffers */
/* Streaming buffers */
unsigned int n_sbufs; /* How many we have */
struct cafe_sio_buffer *sb_bufs; /* The array of housekeeping structs */
struct list_head sb_avail; /* Available for data (we own) (dev_lock) */
struct list_head sb_full; /* With data (user space owns) (dev_lock) */
struct tasklet_struct s_tasklet;
/* Current operating parameters */
u32 sensor_type; /* Currently ov7670 only */
struct v4l2_pix_format pix_format;
enum v4l2_mbus_pixelcode mbus_code;
/* Locks */
struct mutex s_mutex; /* Access to this structure */
spinlock_t dev_lock; /* Access to device */
/* Misc */
wait_queue_head_t smbus_wait; /* Waiting on i2c events */
wait_queue_head_t iowait; /* Waiting on frame data */
};
/* /*
* Status flags. Always manipulated with bit operations. * Status flags. Always manipulated with bit operations.
*/ */
...@@ -205,17 +96,12 @@ struct cafe_camera ...@@ -205,17 +96,12 @@ struct cafe_camera
#define sensor_call(cam, o, f, args...) \ #define sensor_call(cam, o, f, args...) \
v4l2_subdev_call(cam->sensor, o, f, ##args) v4l2_subdev_call(cam->sensor, o, f, ##args)
static inline struct cafe_camera *to_cam(struct v4l2_device *dev) static struct mcam_format_struct {
{
return container_of(dev, struct cafe_camera, v4l2_dev);
}
static struct cafe_format_struct {
__u8 *desc; __u8 *desc;
__u32 pixelformat; __u32 pixelformat;
int bpp; /* Bytes per pixel */ int bpp; /* Bytes per pixel */
enum v4l2_mbus_pixelcode mbus_code; enum v4l2_mbus_pixelcode mbus_code;
} cafe_formats[] = { } mcam_formats[] = {
{ {
.desc = "YUYV 4:2:2", .desc = "YUYV 4:2:2",
.pixelformat = V4L2_PIX_FMT_YUYV, .pixelformat = V4L2_PIX_FMT_YUYV,
...@@ -241,23 +127,23 @@ static struct cafe_format_struct { ...@@ -241,23 +127,23 @@ static struct cafe_format_struct {
.bpp = 1 .bpp = 1
}, },
}; };
#define N_CAFE_FMTS ARRAY_SIZE(cafe_formats) #define N_MCAM_FMTS ARRAY_SIZE(mcam_formats)
static struct cafe_format_struct *cafe_find_format(u32 pixelformat) static struct mcam_format_struct *mcam_find_format(u32 pixelformat)
{ {
unsigned i; unsigned i;
for (i = 0; i < N_CAFE_FMTS; i++) for (i = 0; i < N_MCAM_FMTS; i++)
if (cafe_formats[i].pixelformat == pixelformat) if (mcam_formats[i].pixelformat == pixelformat)
return cafe_formats + i; return mcam_formats + i;
/* Not found? Then return the first format. */ /* Not found? Then return the first format. */
return cafe_formats; return mcam_formats;
} }
/* /*
* Start over with DMA buffers - dev_lock needed. * Start over with DMA buffers - dev_lock needed.
*/ */
static void cafe_reset_buffers(struct cafe_camera *cam) static void mcam_reset_buffers(struct mcam_camera *cam)
{ {
int i; int i;
...@@ -267,12 +153,12 @@ static void cafe_reset_buffers(struct cafe_camera *cam) ...@@ -267,12 +153,12 @@ static void cafe_reset_buffers(struct cafe_camera *cam)
cam->specframes = 0; cam->specframes = 0;
} }
static inline int cafe_needs_config(struct cafe_camera *cam) static inline int mcam_needs_config(struct mcam_camera *cam)
{ {
return test_bit(CF_CONFIG_NEEDED, &cam->flags); return test_bit(CF_CONFIG_NEEDED, &cam->flags);
} }
static void cafe_set_config_needed(struct cafe_camera *cam, int needed) static void mcam_set_config_needed(struct mcam_camera *cam, int needed)
{ {
if (needed) if (needed)
set_bit(CF_CONFIG_NEEDED, &cam->flags); set_bit(CF_CONFIG_NEEDED, &cam->flags);
...@@ -281,275 +167,16 @@ static void cafe_set_config_needed(struct cafe_camera *cam, int needed) ...@@ -281,275 +167,16 @@ static void cafe_set_config_needed(struct cafe_camera *cam, int needed)
} }
/* /*
* Debugging and related. * Debugging and related. FIXME these are broken
*/ */
#define cam_err(cam, fmt, arg...) \ #define cam_err(cam, fmt, arg...) \
dev_err(&(cam)->pdev->dev, fmt, ##arg); dev_err((cam)->dev, fmt, ##arg);
#define cam_warn(cam, fmt, arg...) \ #define cam_warn(cam, fmt, arg...) \
dev_warn(&(cam)->pdev->dev, fmt, ##arg); dev_warn((cam)->dev, fmt, ##arg);
#define cam_dbg(cam, fmt, arg...) \ #define cam_dbg(cam, fmt, arg...) \
dev_dbg(&(cam)->pdev->dev, fmt, ##arg); dev_dbg((cam)->dev, fmt, ##arg);
/* ---------------------------------------------------------------------*/
/*
* Device register I/O
*/
static inline void cafe_reg_write(struct cafe_camera *cam, unsigned int reg,
unsigned int val)
{
iowrite32(val, cam->regs + reg);
}
static inline unsigned int cafe_reg_read(struct cafe_camera *cam,
unsigned int reg)
{
return ioread32(cam->regs + reg);
}
static inline void cafe_reg_write_mask(struct cafe_camera *cam, unsigned int reg,
unsigned int val, unsigned int mask)
{
unsigned int v = cafe_reg_read(cam, reg);
v = (v & ~mask) | (val & mask);
cafe_reg_write(cam, reg, v);
}
static inline void cafe_reg_clear_bit(struct cafe_camera *cam,
unsigned int reg, unsigned int val)
{
cafe_reg_write_mask(cam, reg, 0, val);
}
static inline void cafe_reg_set_bit(struct cafe_camera *cam,
unsigned int reg, unsigned int val)
{
cafe_reg_write_mask(cam, reg, val, val);
}
/* -------------------------------------------------------------------- */
/*
* The I2C/SMBUS interface to the camera itself starts here. The
* controller handles SMBUS itself, presenting a relatively simple register
* interface; all we have to do is to tell it where to route the data.
*/
#define CAFE_SMBUS_TIMEOUT (HZ) /* generous */
static int cafe_smbus_write_done(struct cafe_camera *cam)
{
unsigned long flags;
int c1;
/*
* We must delay after the interrupt, or the controller gets confused
* and never does give us good status. Fortunately, we don't do this
* often.
*/
udelay(20);
spin_lock_irqsave(&cam->dev_lock, flags);
c1 = cafe_reg_read(cam, REG_TWSIC1);
spin_unlock_irqrestore(&cam->dev_lock, flags);
return (c1 & (TWSIC1_WSTAT|TWSIC1_ERROR)) != TWSIC1_WSTAT;
}
static int cafe_smbus_write_data(struct cafe_camera *cam,
u16 addr, u8 command, u8 value)
{
unsigned int rval;
unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags);
rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
/*
* Marvell sez set clkdiv to all 1's for now.
*/
rval |= TWSIC0_CLKDIV;
cafe_reg_write(cam, REG_TWSIC0, rval);
(void) cafe_reg_read(cam, REG_TWSIC1); /* force write */
rval = value | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
cafe_reg_write(cam, REG_TWSIC1, rval);
spin_unlock_irqrestore(&cam->dev_lock, flags);
/* Unfortunately, reading TWSIC1 too soon after sending a command
* causes the device to die.
* Use a busy-wait because we often send a large quantity of small
* commands at-once; using msleep() would cause a lot of context
* switches which take longer than 2ms, resulting in a noticeable
* boot-time and capture-start delays.
*/
mdelay(2);
/*
* Another sad fact is that sometimes, commands silently complete but
* cafe_smbus_write_done() never becomes aware of this.
* This happens at random and appears to possible occur with any
* command.
* We don't understand why this is. We work around this issue
* with the timeout in the wait below, assuming that all commands
* complete within the timeout.
*/
wait_event_timeout(cam->smbus_wait, cafe_smbus_write_done(cam),
CAFE_SMBUS_TIMEOUT);
spin_lock_irqsave(&cam->dev_lock, flags);
rval = cafe_reg_read(cam, REG_TWSIC1);
spin_unlock_irqrestore(&cam->dev_lock, flags);
if (rval & TWSIC1_WSTAT) {
cam_err(cam, "SMBUS write (%02x/%02x/%02x) timed out\n", addr,
command, value);
return -EIO;
}
if (rval & TWSIC1_ERROR) {
cam_err(cam, "SMBUS write (%02x/%02x/%02x) error\n", addr,
command, value);
return -EIO;
}
return 0;
}
static int cafe_smbus_read_done(struct cafe_camera *cam)
{
unsigned long flags;
int c1;
/*
* We must delay after the interrupt, or the controller gets confused
* and never does give us good status. Fortunately, we don't do this
* often.
*/
udelay(20);
spin_lock_irqsave(&cam->dev_lock, flags);
c1 = cafe_reg_read(cam, REG_TWSIC1);
spin_unlock_irqrestore(&cam->dev_lock, flags);
return c1 & (TWSIC1_RVALID|TWSIC1_ERROR);
}
static int cafe_smbus_read_data(struct cafe_camera *cam,
u16 addr, u8 command, u8 *value)
{
unsigned int rval;
unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags);
rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
/*
* Marvel sez set clkdiv to all 1's for now.
*/
rval |= TWSIC0_CLKDIV;
cafe_reg_write(cam, REG_TWSIC0, rval);
(void) cafe_reg_read(cam, REG_TWSIC1); /* force write */
rval = TWSIC1_READ | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
cafe_reg_write(cam, REG_TWSIC1, rval);
spin_unlock_irqrestore(&cam->dev_lock, flags);
wait_event_timeout(cam->smbus_wait,
cafe_smbus_read_done(cam), CAFE_SMBUS_TIMEOUT);
spin_lock_irqsave(&cam->dev_lock, flags);
rval = cafe_reg_read(cam, REG_TWSIC1);
spin_unlock_irqrestore(&cam->dev_lock, flags);
if (rval & TWSIC1_ERROR) {
cam_err(cam, "SMBUS read (%02x/%02x) error\n", addr, command);
return -EIO;
}
if (! (rval & TWSIC1_RVALID)) {
cam_err(cam, "SMBUS read (%02x/%02x) timed out\n", addr,
command);
return -EIO;
}
*value = rval & 0xff;
return 0;
}
/*
* Perform a transfer over SMBUS. This thing is called under
* the i2c bus lock, so we shouldn't race with ourselves...
*/
static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
unsigned short flags, char rw, u8 command,
int size, union i2c_smbus_data *data)
{
struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
struct cafe_camera *cam = to_cam(v4l2_dev);
int ret = -EINVAL;
/*
* This interface would appear to only do byte data ops. OK
* it can do word too, but the cam chip has no use for that.
*/
if (size != I2C_SMBUS_BYTE_DATA) {
cam_err(cam, "funky xfer size %d\n", size);
return -EINVAL;
}
if (rw == I2C_SMBUS_WRITE)
ret = cafe_smbus_write_data(cam, addr, command, data->byte);
else if (rw == I2C_SMBUS_READ)
ret = cafe_smbus_read_data(cam, addr, command, &data->byte);
return ret;
}
static void cafe_smbus_enable_irq(struct cafe_camera *cam)
{
unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags);
cafe_reg_set_bit(cam, REG_IRQMASK, TWSIIRQS);
spin_unlock_irqrestore(&cam->dev_lock, flags);
}
static u32 cafe_smbus_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_READ_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
}
static struct i2c_algorithm cafe_smbus_algo = {
.smbus_xfer = cafe_smbus_xfer,
.functionality = cafe_smbus_func
};
/* Somebody is on the bus */
static void cafe_ctlr_stop_dma(struct cafe_camera *cam);
static void cafe_ctlr_power_down(struct cafe_camera *cam);
static int cafe_smbus_setup(struct cafe_camera *cam)
{
struct i2c_adapter *adap = &cam->i2c_adapter;
int ret;
cafe_smbus_enable_irq(cam);
adap->owner = THIS_MODULE;
adap->algo = &cafe_smbus_algo;
strcpy(adap->name, "cafe_ccic");
adap->dev.parent = &cam->pdev->dev;
i2c_set_adapdata(adap, &cam->v4l2_dev);
ret = i2c_add_adapter(adap);
if (ret)
printk(KERN_ERR "Unable to register cafe i2c adapter\n");
return ret;
}
static void cafe_smbus_shutdown(struct cafe_camera *cam)
{
i2c_del_adapter(&cam->i2c_adapter);
}
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
...@@ -561,7 +188,7 @@ static void cafe_smbus_shutdown(struct cafe_camera *cam) ...@@ -561,7 +188,7 @@ static void cafe_smbus_shutdown(struct cafe_camera *cam)
* Do everything we think we need to have the interface operating * Do everything we think we need to have the interface operating
* according to the desired format. * according to the desired format.
*/ */
static void cafe_ctlr_dma(struct cafe_camera *cam) static void mcam_ctlr_dma(struct mcam_camera *cam)
{ {
/* /*
* Store the first two Y buffers (we aren't supporting * Store the first two Y buffers (we aren't supporting
...@@ -569,48 +196,47 @@ static void cafe_ctlr_dma(struct cafe_camera *cam) ...@@ -569,48 +196,47 @@ static void cafe_ctlr_dma(struct cafe_camera *cam)
* set the third if it exists, or tell the controller * set the third if it exists, or tell the controller
* to just use two. * to just use two.
*/ */
cafe_reg_write(cam, REG_Y0BAR, cam->dma_handles[0]); mcam_reg_write(cam, REG_Y0BAR, cam->dma_handles[0]);
cafe_reg_write(cam, REG_Y1BAR, cam->dma_handles[1]); mcam_reg_write(cam, REG_Y1BAR, cam->dma_handles[1]);
if (cam->nbufs > 2) { if (cam->nbufs > 2) {
cafe_reg_write(cam, REG_Y2BAR, cam->dma_handles[2]); mcam_reg_write(cam, REG_Y2BAR, cam->dma_handles[2]);
cafe_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS); mcam_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS);
} } else
else mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
cafe_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS); mcam_reg_write(cam, REG_UBAR, 0); /* 32 bits only for now */
cafe_reg_write(cam, REG_UBAR, 0); /* 32 bits only for now */
} }
static void cafe_ctlr_image(struct cafe_camera *cam) static void mcam_ctlr_image(struct mcam_camera *cam)
{ {
int imgsz; int imgsz;
struct v4l2_pix_format *fmt = &cam->pix_format; struct v4l2_pix_format *fmt = &cam->pix_format;
imgsz = ((fmt->height << IMGSZ_V_SHIFT) & IMGSZ_V_MASK) | imgsz = ((fmt->height << IMGSZ_V_SHIFT) & IMGSZ_V_MASK) |
(fmt->bytesperline & IMGSZ_H_MASK); (fmt->bytesperline & IMGSZ_H_MASK);
cafe_reg_write(cam, REG_IMGSIZE, imgsz); mcam_reg_write(cam, REG_IMGSIZE, imgsz);
cafe_reg_write(cam, REG_IMGOFFSET, 0); mcam_reg_write(cam, REG_IMGOFFSET, 0);
/* YPITCH just drops the last two bits */ /* YPITCH just drops the last two bits */
cafe_reg_write_mask(cam, REG_IMGPITCH, fmt->bytesperline, mcam_reg_write_mask(cam, REG_IMGPITCH, fmt->bytesperline,
IMGP_YP_MASK); IMGP_YP_MASK);
/* /*
* Tell the controller about the image format we are using. * Tell the controller about the image format we are using.
*/ */
switch (cam->pix_format.pixelformat) { switch (cam->pix_format.pixelformat) {
case V4L2_PIX_FMT_YUYV: case V4L2_PIX_FMT_YUYV:
cafe_reg_write_mask(cam, REG_CTRL0, mcam_reg_write_mask(cam, REG_CTRL0,
C0_DF_YUV|C0_YUV_PACKED|C0_YUVE_YUYV, C0_DF_YUV|C0_YUV_PACKED|C0_YUVE_YUYV,
C0_DF_MASK); C0_DF_MASK);
break; break;
case V4L2_PIX_FMT_RGB444: case V4L2_PIX_FMT_RGB444:
cafe_reg_write_mask(cam, REG_CTRL0, mcam_reg_write_mask(cam, REG_CTRL0,
C0_DF_RGB|C0_RGBF_444|C0_RGB4_XRGB, C0_DF_RGB|C0_RGBF_444|C0_RGB4_XRGB,
C0_DF_MASK); C0_DF_MASK);
/* Alpha value? */ /* Alpha value? */
break; break;
case V4L2_PIX_FMT_RGB565: case V4L2_PIX_FMT_RGB565:
cafe_reg_write_mask(cam, REG_CTRL0, mcam_reg_write_mask(cam, REG_CTRL0,
C0_DF_RGB|C0_RGBF_565|C0_RGB5_BGGR, C0_DF_RGB|C0_RGBF_565|C0_RGB5_BGGR,
C0_DF_MASK); C0_DF_MASK);
break; break;
...@@ -622,7 +248,7 @@ static void cafe_ctlr_image(struct cafe_camera *cam) ...@@ -622,7 +248,7 @@ static void cafe_ctlr_image(struct cafe_camera *cam)
/* /*
* Make sure it knows we want to use hsync/vsync. * Make sure it knows we want to use hsync/vsync.
*/ */
cafe_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC, mcam_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
C0_SIFM_MASK); C0_SIFM_MASK);
} }
...@@ -631,95 +257,68 @@ static void cafe_ctlr_image(struct cafe_camera *cam) ...@@ -631,95 +257,68 @@ static void cafe_ctlr_image(struct cafe_camera *cam)
* Configure the controller for operation; caller holds the * Configure the controller for operation; caller holds the
* device mutex. * device mutex.
*/ */
static int cafe_ctlr_configure(struct cafe_camera *cam) static int mcam_ctlr_configure(struct mcam_camera *cam)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cafe_ctlr_dma(cam); mcam_ctlr_dma(cam);
cafe_ctlr_image(cam); mcam_ctlr_image(cam);
cafe_set_config_needed(cam, 0); mcam_set_config_needed(cam, 0);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
return 0; return 0;
} }
static void cafe_ctlr_irq_enable(struct cafe_camera *cam) static void mcam_ctlr_irq_enable(struct mcam_camera *cam)
{ {
/* /*
* Clear any pending interrupts, since we do not * Clear any pending interrupts, since we do not
* expect to have I/O active prior to enabling. * expect to have I/O active prior to enabling.
*/ */
cafe_reg_write(cam, REG_IRQSTAT, FRAMEIRQS); mcam_reg_write(cam, REG_IRQSTAT, FRAMEIRQS);
cafe_reg_set_bit(cam, REG_IRQMASK, FRAMEIRQS); mcam_reg_set_bit(cam, REG_IRQMASK, FRAMEIRQS);
} }
static void cafe_ctlr_irq_disable(struct cafe_camera *cam) static void mcam_ctlr_irq_disable(struct mcam_camera *cam)
{ {
cafe_reg_clear_bit(cam, REG_IRQMASK, FRAMEIRQS); mcam_reg_clear_bit(cam, REG_IRQMASK, FRAMEIRQS);
} }
/* /*
* Make the controller start grabbing images. Everything must * Make the controller start grabbing images. Everything must
* be set up before doing this. * be set up before doing this.
*/ */
static void cafe_ctlr_start(struct cafe_camera *cam) static void mcam_ctlr_start(struct mcam_camera *cam)
{ {
/* set_bit performs a read, so no other barrier should be /* set_bit performs a read, so no other barrier should be
needed here */ needed here */
cafe_reg_set_bit(cam, REG_CTRL0, C0_ENABLE); mcam_reg_set_bit(cam, REG_CTRL0, C0_ENABLE);
} }
static void cafe_ctlr_stop(struct cafe_camera *cam) static void mcam_ctlr_stop(struct mcam_camera *cam)
{ {
cafe_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE); mcam_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
} }
static void cafe_ctlr_init(struct cafe_camera *cam) static void mcam_ctlr_init(struct mcam_camera *cam)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
/*
* Added magic to bring up the hardware on the B-Test board
*/
cafe_reg_write(cam, 0x3038, 0x8);
cafe_reg_write(cam, 0x315c, 0x80008);
/*
* Go through the dance needed to wake the device up.
* Note that these registers are global and shared
* with the NAND and SD devices. Interaction between the
* three still needs to be examined.
*/
cafe_reg_write(cam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */
cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRC);
cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRS);
/*
* Here we must wait a bit for the controller to come around.
*/
spin_unlock_irqrestore(&cam->dev_lock, flags);
msleep(5);
spin_lock_irqsave(&cam->dev_lock, flags);
cafe_reg_write(cam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC);
cafe_reg_set_bit(cam, REG_GL_IMASK, GIMSK_CCIC_EN);
/* /*
* Make sure it's not powered down. * Make sure it's not powered down.
*/ */
cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN); mcam_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN);
/* /*
* Turn off the enable bit. It sure should be off anyway, * Turn off the enable bit. It sure should be off anyway,
* but it's good to be sure. * but it's good to be sure.
*/ */
cafe_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE); mcam_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
/*
* Mask all interrupts.
*/
cafe_reg_write(cam, REG_IRQMASK, 0);
/* /*
* Clock the sensor appropriately. Controller clock should * Clock the sensor appropriately. Controller clock should
* be 48MHz, sensor "typical" value is half that. * be 48MHz, sensor "typical" value is half that.
*/ */
cafe_reg_write_mask(cam, REG_CLKCTRL, 2, CLK_DIV_MASK); mcam_reg_write_mask(cam, REG_CLKCTRL, 2, CLK_DIV_MASK);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
} }
...@@ -728,7 +327,7 @@ static void cafe_ctlr_init(struct cafe_camera *cam) ...@@ -728,7 +327,7 @@ static void cafe_ctlr_init(struct cafe_camera *cam)
* Stop the controller, and don't return until we're really sure that no * Stop the controller, and don't return until we're really sure that no
* further DMA is going on. * further DMA is going on.
*/ */
static void cafe_ctlr_stop_dma(struct cafe_camera *cam) static void mcam_ctlr_stop_dma(struct mcam_camera *cam)
{ {
unsigned long flags; unsigned long flags;
...@@ -738,7 +337,7 @@ static void cafe_ctlr_stop_dma(struct cafe_camera *cam) ...@@ -738,7 +337,7 @@ static void cafe_ctlr_stop_dma(struct cafe_camera *cam)
* interrupt, then wait until no DMA is active. * interrupt, then wait until no DMA is active.
*/ */
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cafe_ctlr_stop(cam); mcam_ctlr_stop(cam);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
mdelay(1); mdelay(1);
wait_event_timeout(cam->iowait, wait_event_timeout(cam->iowait,
...@@ -748,47 +347,31 @@ static void cafe_ctlr_stop_dma(struct cafe_camera *cam) ...@@ -748,47 +347,31 @@ static void cafe_ctlr_stop_dma(struct cafe_camera *cam)
/* This would be bad news - what now? */ /* This would be bad news - what now? */
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cam->state = S_IDLE; cam->state = S_IDLE;
cafe_ctlr_irq_disable(cam); mcam_ctlr_irq_disable(cam);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
} }
/* /*
* Power up and down. * Power up and down.
*/ */
static void cafe_ctlr_power_up(struct cafe_camera *cam) static void mcam_ctlr_power_up(struct mcam_camera *cam)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN); mcam_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN);
/* cam->plat_power_up(cam);
* Part one of the sensor dance: turn the global
* GPIO signal on.
*/
cafe_reg_write(cam, REG_GL_FCR, GFCR_GPIO_ON);
cafe_reg_write(cam, REG_GL_GPIOR, GGPIO_OUT|GGPIO_VAL);
/*
* Put the sensor into operational mode (assumes OLPC-style
* wiring). Control 0 is reset - set to 1 to operate.
* Control 1 is power down, set to 0 to operate.
*/
cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
/* mdelay(1); */ /* Marvell says 1ms will do it */
cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
/* mdelay(1); */ /* Enough? */
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
msleep(5); /* Just to be sure */ msleep(5); /* Just to be sure */
} }
static void cafe_ctlr_power_down(struct cafe_camera *cam) static void mcam_ctlr_power_down(struct mcam_camera *cam)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1); cam->plat_power_down(cam);
cafe_reg_write(cam, REG_GL_FCR, GFCR_GPIO_ON); mcam_reg_set_bit(cam, REG_CTRL1, C1_PWRDWN);
cafe_reg_write(cam, REG_GL_GPIOR, GGPIO_OUT);
cafe_reg_set_bit(cam, REG_CTRL1, C1_PWRDWN);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
} }
...@@ -797,7 +380,7 @@ static void cafe_ctlr_power_down(struct cafe_camera *cam) ...@@ -797,7 +380,7 @@ static void cafe_ctlr_power_down(struct cafe_camera *cam)
* Communications with the sensor. * Communications with the sensor.
*/ */
static int __cafe_cam_reset(struct cafe_camera *cam) static int __mcam_cam_reset(struct mcam_camera *cam)
{ {
return sensor_call(cam, core, reset, 0); return sensor_call(cam, core, reset, 0);
} }
...@@ -806,7 +389,7 @@ static int __cafe_cam_reset(struct cafe_camera *cam) ...@@ -806,7 +389,7 @@ static int __cafe_cam_reset(struct cafe_camera *cam)
* We have found the sensor on the i2c. Let's try to have a * We have found the sensor on the i2c. Let's try to have a
* conversation. * conversation.
*/ */
static int cafe_cam_init(struct cafe_camera *cam) static int mcam_cam_init(struct mcam_camera *cam)
{ {
struct v4l2_dbg_chip_ident chip; struct v4l2_dbg_chip_ident chip;
int ret; int ret;
...@@ -815,7 +398,7 @@ static int cafe_cam_init(struct cafe_camera *cam) ...@@ -815,7 +398,7 @@ static int cafe_cam_init(struct cafe_camera *cam)
if (cam->state != S_NOTREADY) if (cam->state != S_NOTREADY)
cam_warn(cam, "Cam init with device in funky state %d", cam_warn(cam, "Cam init with device in funky state %d",
cam->state); cam->state);
ret = __cafe_cam_reset(cam); ret = __mcam_cam_reset(cam);
if (ret) if (ret)
goto out; goto out;
chip.ident = V4L2_IDENT_NONE; chip.ident = V4L2_IDENT_NONE;
...@@ -833,8 +416,8 @@ static int cafe_cam_init(struct cafe_camera *cam) ...@@ -833,8 +416,8 @@ static int cafe_cam_init(struct cafe_camera *cam)
/* Get/set parameters? */ /* Get/set parameters? */
ret = 0; ret = 0;
cam->state = S_IDLE; cam->state = S_IDLE;
out: out:
cafe_ctlr_power_down(cam); mcam_ctlr_power_down(cam);
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
...@@ -843,7 +426,7 @@ static int cafe_cam_init(struct cafe_camera *cam) ...@@ -843,7 +426,7 @@ static int cafe_cam_init(struct cafe_camera *cam)
* Configure the sensor to match the parameters we have. Caller should * Configure the sensor to match the parameters we have. Caller should
* hold s_mutex * hold s_mutex
*/ */
static int cafe_cam_set_flip(struct cafe_camera *cam) static int mcam_cam_set_flip(struct mcam_camera *cam)
{ {
struct v4l2_control ctrl; struct v4l2_control ctrl;
...@@ -854,7 +437,7 @@ static int cafe_cam_set_flip(struct cafe_camera *cam) ...@@ -854,7 +437,7 @@ static int cafe_cam_set_flip(struct cafe_camera *cam)
} }
static int cafe_cam_configure(struct cafe_camera *cam) static int mcam_cam_configure(struct mcam_camera *cam)
{ {
struct v4l2_mbus_framefmt mbus_fmt; struct v4l2_mbus_framefmt mbus_fmt;
int ret; int ret;
...@@ -866,7 +449,7 @@ static int cafe_cam_configure(struct cafe_camera *cam) ...@@ -866,7 +449,7 @@ static int cafe_cam_configure(struct cafe_camera *cam)
/* /*
* OV7670 does weird things if flip is set *before* format... * OV7670 does weird things if flip is set *before* format...
*/ */
ret += cafe_cam_set_flip(cam); ret += mcam_cam_set_flip(cam);
return ret; return ret;
} }
...@@ -879,11 +462,11 @@ static int cafe_cam_configure(struct cafe_camera *cam) ...@@ -879,11 +462,11 @@ static int cafe_cam_configure(struct cafe_camera *cam)
* does a get_free_pages() call, and we waste a good chunk of an orderN * does a get_free_pages() call, and we waste a good chunk of an orderN
* allocation. Should try to allocate the whole set in one chunk. * allocation. Should try to allocate the whole set in one chunk.
*/ */
static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime) static int mcam_alloc_dma_bufs(struct mcam_camera *cam, int loadtime)
{ {
int i; int i;
cafe_set_config_needed(cam, 1); mcam_set_config_needed(cam, 1);
if (loadtime) if (loadtime)
cam->dma_buf_size = dma_buf_size; cam->dma_buf_size = dma_buf_size;
else else
...@@ -893,7 +476,7 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime) ...@@ -893,7 +476,7 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime)
cam->nbufs = 0; cam->nbufs = 0;
for (i = 0; i < n_dma_bufs; i++) { for (i = 0; i < n_dma_bufs; i++) {
cam->dma_bufs[i] = dma_alloc_coherent(&cam->pdev->dev, cam->dma_bufs[i] = dma_alloc_coherent(cam->dev,
cam->dma_buf_size, cam->dma_handles + i, cam->dma_buf_size, cam->dma_handles + i,
GFP_KERNEL); GFP_KERNEL);
if (cam->dma_bufs[i] == NULL) { if (cam->dma_bufs[i] == NULL) {
...@@ -907,7 +490,7 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime) ...@@ -907,7 +490,7 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime)
switch (cam->nbufs) { switch (cam->nbufs) {
case 1: case 1:
dma_free_coherent(&cam->pdev->dev, cam->dma_buf_size, dma_free_coherent(cam->dev, cam->dma_buf_size,
cam->dma_bufs[0], cam->dma_handles[0]); cam->dma_bufs[0], cam->dma_handles[0]);
cam->nbufs = 0; cam->nbufs = 0;
case 0: case 0:
...@@ -922,12 +505,12 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime) ...@@ -922,12 +505,12 @@ static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime)
return 0; return 0;
} }
static void cafe_free_dma_bufs(struct cafe_camera *cam) static void mcam_free_dma_bufs(struct mcam_camera *cam)
{ {
int i; int i;
for (i = 0; i < cam->nbufs; i++) { for (i = 0; i < cam->nbufs; i++) {
dma_free_coherent(&cam->pdev->dev, cam->dma_buf_size, dma_free_coherent(cam->dev, cam->dma_buf_size,
cam->dma_bufs[i], cam->dma_handles[i]); cam->dma_bufs[i], cam->dma_handles[i]);
cam->dma_bufs[i] = NULL; cam->dma_bufs[i] = NULL;
} }
...@@ -946,7 +529,7 @@ static void cafe_free_dma_bufs(struct cafe_camera *cam) ...@@ -946,7 +529,7 @@ static void cafe_free_dma_bufs(struct cafe_camera *cam)
/* /*
* Read an image from the device. * Read an image from the device.
*/ */
static ssize_t cafe_deliver_buffer(struct cafe_camera *cam, static ssize_t mcam_deliver_buffer(struct mcam_camera *cam,
char __user *buffer, size_t len, loff_t *pos) char __user *buffer, size_t len, loff_t *pos)
{ {
int bufno; int bufno;
...@@ -962,7 +545,7 @@ static ssize_t cafe_deliver_buffer(struct cafe_camera *cam, ...@@ -962,7 +545,7 @@ static ssize_t cafe_deliver_buffer(struct cafe_camera *cam,
clear_bit(bufno, &cam->flags); clear_bit(bufno, &cam->flags);
if (++(cam->next_buf) >= cam->nbufs) if (++(cam->next_buf) >= cam->nbufs)
cam->next_buf = 0; cam->next_buf = 0;
if (! test_bit(cam->next_buf, &cam->flags)) if (!test_bit(cam->next_buf, &cam->flags))
cam->next_buf = -1; cam->next_buf = -1;
cam->specframes = 0; cam->specframes = 0;
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
...@@ -978,7 +561,7 @@ static ssize_t cafe_deliver_buffer(struct cafe_camera *cam, ...@@ -978,7 +561,7 @@ static ssize_t cafe_deliver_buffer(struct cafe_camera *cam,
/* /*
* Get everything ready, and start grabbing frames. * Get everything ready, and start grabbing frames.
*/ */
static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state) static int mcam_read_setup(struct mcam_camera *cam, enum mcam_state state)
{ {
int ret; int ret;
unsigned long flags; unsigned long flags;
...@@ -988,12 +571,12 @@ static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state) ...@@ -988,12 +571,12 @@ static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state)
* make one last, desperate attempt. * make one last, desperate attempt.
*/ */
if (cam->nbufs == 0) if (cam->nbufs == 0)
if (cafe_alloc_dma_bufs(cam, 0)) if (mcam_alloc_dma_bufs(cam, 0))
return -ENOMEM; return -ENOMEM;
if (cafe_needs_config(cam)) { if (mcam_needs_config(cam)) {
cafe_cam_configure(cam); mcam_cam_configure(cam);
ret = cafe_ctlr_configure(cam); ret = mcam_ctlr_configure(cam);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -1002,19 +585,19 @@ static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state) ...@@ -1002,19 +585,19 @@ static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state)
* Turn it loose. * Turn it loose.
*/ */
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
cafe_reset_buffers(cam); mcam_reset_buffers(cam);
cafe_ctlr_irq_enable(cam); mcam_ctlr_irq_enable(cam);
cam->state = state; cam->state = state;
cafe_ctlr_start(cam); mcam_ctlr_start(cam);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
return 0; return 0;
} }
static ssize_t cafe_v4l_read(struct file *filp, static ssize_t mcam_v4l_read(struct file *filp,
char __user *buffer, size_t len, loff_t *pos) char __user *buffer, size_t len, loff_t *pos)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
int ret = 0; int ret = 0;
/* /*
...@@ -1024,7 +607,7 @@ static ssize_t cafe_v4l_read(struct file *filp, ...@@ -1024,7 +607,7 @@ static ssize_t cafe_v4l_read(struct file *filp,
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
if (cam->state == S_SPECREAD) { if (cam->state == S_SPECREAD) {
if (cam->next_buf >= 0) { if (cam->next_buf >= 0) {
ret = cafe_deliver_buffer(cam, buffer, len, pos); ret = mcam_deliver_buffer(cam, buffer, len, pos);
if (ret != 0) if (ret != 0)
goto out_unlock; goto out_unlock;
} }
...@@ -1050,7 +633,7 @@ static ssize_t cafe_v4l_read(struct file *filp, ...@@ -1050,7 +633,7 @@ static ssize_t cafe_v4l_read(struct file *filp,
* Do setup if need be. * Do setup if need be.
*/ */
if (cam->state != S_SPECREAD) { if (cam->state != S_SPECREAD) {
ret = cafe_read_setup(cam, S_SINGLEREAD); ret = mcam_read_setup(cam, S_SINGLEREAD);
if (ret) if (ret)
goto out_unlock; goto out_unlock;
} }
...@@ -1061,16 +644,16 @@ static ssize_t cafe_v4l_read(struct file *filp, ...@@ -1061,16 +644,16 @@ static ssize_t cafe_v4l_read(struct file *filp,
wait_event_timeout(cam->iowait, cam->next_buf >= 0, HZ); wait_event_timeout(cam->iowait, cam->next_buf >= 0, HZ);
if (cam->next_buf < 0) { if (cam->next_buf < 0) {
cam_err(cam, "read() operation timed out\n"); cam_err(cam, "read() operation timed out\n");
cafe_ctlr_stop_dma(cam); mcam_ctlr_stop_dma(cam);
ret = -EIO; ret = -EIO;
goto out_unlock; goto out_unlock;
} }
/* /*
* Give them their data and we should be done. * Give them their data and we should be done.
*/ */
ret = cafe_deliver_buffer(cam, buffer, len, pos); ret = mcam_deliver_buffer(cam, buffer, len, pos);
out_unlock: out_unlock:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
...@@ -1088,10 +671,10 @@ static ssize_t cafe_v4l_read(struct file *filp, ...@@ -1088,10 +671,10 @@ static ssize_t cafe_v4l_read(struct file *filp,
static int cafe_vidioc_streamon(struct file *filp, void *priv, static int mcam_vidioc_streamon(struct file *filp, void *priv,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
int ret = -EINVAL; int ret = -EINVAL;
if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
...@@ -1101,19 +684,19 @@ static int cafe_vidioc_streamon(struct file *filp, void *priv, ...@@ -1101,19 +684,19 @@ static int cafe_vidioc_streamon(struct file *filp, void *priv,
goto out_unlock; goto out_unlock;
cam->sequence = 0; cam->sequence = 0;
ret = cafe_read_setup(cam, S_STREAMING); ret = mcam_read_setup(cam, S_STREAMING);
out_unlock: out_unlock:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
out: out:
return ret; return ret;
} }
static int cafe_vidioc_streamoff(struct file *filp, void *priv, static int mcam_vidioc_streamoff(struct file *filp, void *priv,
enum v4l2_buf_type type) enum v4l2_buf_type type)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
int ret = -EINVAL; int ret = -EINVAL;
if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
...@@ -1122,20 +705,20 @@ static int cafe_vidioc_streamoff(struct file *filp, void *priv, ...@@ -1122,20 +705,20 @@ static int cafe_vidioc_streamoff(struct file *filp, void *priv,
if (cam->state != S_STREAMING) if (cam->state != S_STREAMING)
goto out_unlock; goto out_unlock;
cafe_ctlr_stop_dma(cam); mcam_ctlr_stop_dma(cam);
ret = 0; ret = 0;
out_unlock: out_unlock:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
out: out:
return ret; return ret;
} }
static int cafe_setup_siobuf(struct cafe_camera *cam, int index) static int mcam_setup_siobuf(struct mcam_camera *cam, int index)
{ {
struct cafe_sio_buffer *buf = cam->sb_bufs + index; struct mcam_sio_buffer *buf = cam->sb_bufs + index;
INIT_LIST_HEAD(&buf->list); INIT_LIST_HEAD(&buf->list);
buf->v4lbuf.length = PAGE_ALIGN(cam->pix_format.sizeimage); buf->v4lbuf.length = PAGE_ALIGN(cam->pix_format.sizeimage);
...@@ -1159,7 +742,7 @@ static int cafe_setup_siobuf(struct cafe_camera *cam, int index) ...@@ -1159,7 +742,7 @@ static int cafe_setup_siobuf(struct cafe_camera *cam, int index)
return 0; return 0;
} }
static int cafe_free_sio_buffers(struct cafe_camera *cam) static int mcam_free_sio_buffers(struct mcam_camera *cam)
{ {
int i; int i;
...@@ -1184,10 +767,10 @@ static int cafe_free_sio_buffers(struct cafe_camera *cam) ...@@ -1184,10 +767,10 @@ static int cafe_free_sio_buffers(struct cafe_camera *cam)
static int cafe_vidioc_reqbufs(struct file *filp, void *priv, static int mcam_vidioc_reqbufs(struct file *filp, void *priv,
struct v4l2_requestbuffers *req) struct v4l2_requestbuffers *req)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
int ret = 0; /* Silence warning */ int ret = 0; /* Silence warning */
/* /*
...@@ -1203,8 +786,8 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv, ...@@ -1203,8 +786,8 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
if (req->count == 0) { if (req->count == 0) {
if (cam->state == S_STREAMING) if (cam->state == S_STREAMING)
cafe_ctlr_stop_dma(cam); mcam_ctlr_stop_dma(cam);
ret = cafe_free_sio_buffers (cam); ret = mcam_free_sio_buffers(cam);
goto out; goto out;
} }
/* /*
...@@ -1223,19 +806,19 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv, ...@@ -1223,19 +806,19 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
else if (req->count > max_buffers) else if (req->count > max_buffers)
req->count = max_buffers; req->count = max_buffers;
if (cam->n_sbufs > 0) { if (cam->n_sbufs > 0) {
ret = cafe_free_sio_buffers(cam); ret = mcam_free_sio_buffers(cam);
if (ret) if (ret)
goto out; goto out;
} }
cam->sb_bufs = kzalloc(req->count*sizeof(struct cafe_sio_buffer), cam->sb_bufs = kzalloc(req->count*sizeof(struct mcam_sio_buffer),
GFP_KERNEL); GFP_KERNEL);
if (cam->sb_bufs == NULL) { if (cam->sb_bufs == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
for (cam->n_sbufs = 0; cam->n_sbufs < req->count; (cam->n_sbufs++)) { for (cam->n_sbufs = 0; cam->n_sbufs < req->count; (cam->n_sbufs++)) {
ret = cafe_setup_siobuf(cam, cam->n_sbufs); ret = mcam_setup_siobuf(cam, cam->n_sbufs);
if (ret) if (ret)
break; break;
} }
...@@ -1244,16 +827,16 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv, ...@@ -1244,16 +827,16 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
kfree(cam->sb_bufs); kfree(cam->sb_bufs);
req->count = cam->n_sbufs; /* In case of partial success */ req->count = cam->n_sbufs; /* In case of partial success */
out: out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
static int cafe_vidioc_querybuf(struct file *filp, void *priv, static int mcam_vidioc_querybuf(struct file *filp, void *priv,
struct v4l2_buffer *buf) struct v4l2_buffer *buf)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
int ret = -EINVAL; int ret = -EINVAL;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1261,16 +844,16 @@ static int cafe_vidioc_querybuf(struct file *filp, void *priv, ...@@ -1261,16 +844,16 @@ static int cafe_vidioc_querybuf(struct file *filp, void *priv,
goto out; goto out;
*buf = cam->sb_bufs[buf->index].v4lbuf; *buf = cam->sb_bufs[buf->index].v4lbuf;
ret = 0; ret = 0;
out: out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
static int cafe_vidioc_qbuf(struct file *filp, void *priv, static int mcam_vidioc_qbuf(struct file *filp, void *priv,
struct v4l2_buffer *buf) struct v4l2_buffer *buf)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
struct cafe_sio_buffer *sbuf; struct mcam_sio_buffer *sbuf;
int ret = -EINVAL; int ret = -EINVAL;
unsigned long flags; unsigned long flags;
...@@ -1292,16 +875,16 @@ static int cafe_vidioc_qbuf(struct file *filp, void *priv, ...@@ -1292,16 +875,16 @@ static int cafe_vidioc_qbuf(struct file *filp, void *priv,
list_add(&sbuf->list, &cam->sb_avail); list_add(&sbuf->list, &cam->sb_avail);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
ret = 0; ret = 0;
out: out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
static int cafe_vidioc_dqbuf(struct file *filp, void *priv, static int mcam_vidioc_dqbuf(struct file *filp, void *priv,
struct v4l2_buffer *buf) struct v4l2_buffer *buf)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
struct cafe_sio_buffer *sbuf; struct mcam_sio_buffer *sbuf;
int ret = -EINVAL; int ret = -EINVAL;
unsigned long flags; unsigned long flags;
...@@ -1329,7 +912,7 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv, ...@@ -1329,7 +912,7 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv,
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
/* Should probably recheck !list_empty() here */ /* Should probably recheck !list_empty() here */
sbuf = list_entry(cam->sb_full.next, sbuf = list_entry(cam->sb_full.next,
struct cafe_sio_buffer, list); struct mcam_sio_buffer, list);
list_del_init(&sbuf->list); list_del_init(&sbuf->list);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_DONE; sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_DONE;
...@@ -1337,17 +920,17 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv, ...@@ -1337,17 +920,17 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv,
ret = 0; ret = 0;
} }
out_unlock: out_unlock:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
out: out:
return ret; return ret;
} }
static void cafe_v4l_vm_open(struct vm_area_struct *vma) static void mcam_v4l_vm_open(struct vm_area_struct *vma)
{ {
struct cafe_sio_buffer *sbuf = vma->vm_private_data; struct mcam_sio_buffer *sbuf = vma->vm_private_data;
/* /*
* Locking: done under mmap_sem, so we don't need to * Locking: done under mmap_sem, so we don't need to
* go back to the camera lock here. * go back to the camera lock here.
...@@ -1356,9 +939,9 @@ static void cafe_v4l_vm_open(struct vm_area_struct *vma) ...@@ -1356,9 +939,9 @@ static void cafe_v4l_vm_open(struct vm_area_struct *vma)
} }
static void cafe_v4l_vm_close(struct vm_area_struct *vma) static void mcam_v4l_vm_close(struct vm_area_struct *vma)
{ {
struct cafe_sio_buffer *sbuf = vma->vm_private_data; struct mcam_sio_buffer *sbuf = vma->vm_private_data;
mutex_lock(&sbuf->cam->s_mutex); mutex_lock(&sbuf->cam->s_mutex);
sbuf->mapcount--; sbuf->mapcount--;
...@@ -1368,21 +951,21 @@ static void cafe_v4l_vm_close(struct vm_area_struct *vma) ...@@ -1368,21 +951,21 @@ static void cafe_v4l_vm_close(struct vm_area_struct *vma)
mutex_unlock(&sbuf->cam->s_mutex); mutex_unlock(&sbuf->cam->s_mutex);
} }
static const struct vm_operations_struct cafe_v4l_vm_ops = { static const struct vm_operations_struct mcam_v4l_vm_ops = {
.open = cafe_v4l_vm_open, .open = mcam_v4l_vm_open,
.close = cafe_v4l_vm_close .close = mcam_v4l_vm_close
}; };
static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma) static int mcam_v4l_mmap(struct file *filp, struct vm_area_struct *vma)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
int ret = -EINVAL; int ret = -EINVAL;
int i; int i;
struct cafe_sio_buffer *sbuf = NULL; struct mcam_sio_buffer *sbuf = NULL;
if (! (vma->vm_flags & VM_WRITE) || ! (vma->vm_flags & VM_SHARED)) if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
return -EINVAL; return -EINVAL;
/* /*
* Find the buffer they are looking for. * Find the buffer they are looking for.
...@@ -1401,28 +984,28 @@ static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -1401,28 +984,28 @@ static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma)
goto out; goto out;
vma->vm_flags |= VM_DONTEXPAND; vma->vm_flags |= VM_DONTEXPAND;
vma->vm_private_data = sbuf; vma->vm_private_data = sbuf;
vma->vm_ops = &cafe_v4l_vm_ops; vma->vm_ops = &mcam_v4l_vm_ops;
sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_MAPPED; sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_MAPPED;
cafe_v4l_vm_open(vma); mcam_v4l_vm_open(vma);
ret = 0; ret = 0;
out: out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
static int cafe_v4l_open(struct file *filp) static int mcam_v4l_open(struct file *filp)
{ {
struct cafe_camera *cam = video_drvdata(filp); struct mcam_camera *cam = video_drvdata(filp);
filp->private_data = cam; filp->private_data = cam;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
if (cam->users == 0) { if (cam->users == 0) {
cafe_ctlr_power_up(cam); mcam_ctlr_power_up(cam);
__cafe_cam_reset(cam); __mcam_cam_reset(cam);
cafe_set_config_needed(cam, 1); mcam_set_config_needed(cam, 1);
/* FIXME make sure this is complete */ /* FIXME make sure this is complete */
} }
(cam->users)++; (cam->users)++;
...@@ -1431,21 +1014,21 @@ static int cafe_v4l_open(struct file *filp) ...@@ -1431,21 +1014,21 @@ static int cafe_v4l_open(struct file *filp)
} }
static int cafe_v4l_release(struct file *filp) static int mcam_v4l_release(struct file *filp)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
(cam->users)--; (cam->users)--;
if (filp == cam->owner) { if (filp == cam->owner) {
cafe_ctlr_stop_dma(cam); mcam_ctlr_stop_dma(cam);
cafe_free_sio_buffers(cam); mcam_free_sio_buffers(cam);
cam->owner = NULL; cam->owner = NULL;
} }
if (cam->users == 0) { if (cam->users == 0) {
cafe_ctlr_power_down(cam); mcam_ctlr_power_down(cam);
if (alloc_bufs_at_read) if (alloc_bufs_at_read)
cafe_free_dma_bufs(cam); mcam_free_dma_bufs(cam);
} }
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return 0; return 0;
...@@ -1453,10 +1036,10 @@ static int cafe_v4l_release(struct file *filp) ...@@ -1453,10 +1036,10 @@ static int cafe_v4l_release(struct file *filp)
static unsigned int cafe_v4l_poll(struct file *filp, static unsigned int mcam_v4l_poll(struct file *filp,
struct poll_table_struct *pt) struct poll_table_struct *pt)
{ {
struct cafe_camera *cam = filp->private_data; struct mcam_camera *cam = filp->private_data;
poll_wait(filp, &cam->iowait, pt); poll_wait(filp, &cam->iowait, pt);
if (cam->next_buf >= 0) if (cam->next_buf >= 0)
...@@ -1466,10 +1049,10 @@ static unsigned int cafe_v4l_poll(struct file *filp, ...@@ -1466,10 +1049,10 @@ static unsigned int cafe_v4l_poll(struct file *filp,
static int cafe_vidioc_queryctrl(struct file *filp, void *priv, static int mcam_vidioc_queryctrl(struct file *filp, void *priv,
struct v4l2_queryctrl *qc) struct v4l2_queryctrl *qc)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1479,10 +1062,10 @@ static int cafe_vidioc_queryctrl(struct file *filp, void *priv, ...@@ -1479,10 +1062,10 @@ static int cafe_vidioc_queryctrl(struct file *filp, void *priv,
} }
static int cafe_vidioc_g_ctrl(struct file *filp, void *priv, static int mcam_vidioc_g_ctrl(struct file *filp, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1492,10 +1075,10 @@ static int cafe_vidioc_g_ctrl(struct file *filp, void *priv, ...@@ -1492,10 +1075,10 @@ static int cafe_vidioc_g_ctrl(struct file *filp, void *priv,
} }
static int cafe_vidioc_s_ctrl(struct file *filp, void *priv, static int mcam_vidioc_s_ctrl(struct file *filp, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1508,12 +1091,12 @@ static int cafe_vidioc_s_ctrl(struct file *filp, void *priv, ...@@ -1508,12 +1091,12 @@ static int cafe_vidioc_s_ctrl(struct file *filp, void *priv,
static int cafe_vidioc_querycap(struct file *file, void *priv, static int mcam_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *cap) struct v4l2_capability *cap)
{ {
strcpy(cap->driver, "cafe_ccic"); strcpy(cap->driver, "marvell_ccic");
strcpy(cap->card, "cafe_ccic"); strcpy(cap->card, "marvell_ccic");
cap->version = CAFE_VERSION; cap->version = 1;
cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
return 0; return 0;
...@@ -1523,7 +1106,7 @@ static int cafe_vidioc_querycap(struct file *file, void *priv, ...@@ -1523,7 +1106,7 @@ static int cafe_vidioc_querycap(struct file *file, void *priv,
/* /*
* The default format we use until somebody says otherwise. * The default format we use until somebody says otherwise.
*/ */
static const struct v4l2_pix_format cafe_def_pix_format = { static const struct v4l2_pix_format mcam_def_pix_format = {
.width = VGA_WIDTH, .width = VGA_WIDTH,
.height = VGA_HEIGHT, .height = VGA_HEIGHT,
.pixelformat = V4L2_PIX_FMT_YUYV, .pixelformat = V4L2_PIX_FMT_YUYV,
...@@ -1532,30 +1115,30 @@ static const struct v4l2_pix_format cafe_def_pix_format = { ...@@ -1532,30 +1115,30 @@ static const struct v4l2_pix_format cafe_def_pix_format = {
.sizeimage = VGA_WIDTH*VGA_HEIGHT*2, .sizeimage = VGA_WIDTH*VGA_HEIGHT*2,
}; };
static const enum v4l2_mbus_pixelcode cafe_def_mbus_code = static const enum v4l2_mbus_pixelcode mcam_def_mbus_code =
V4L2_MBUS_FMT_YUYV8_2X8; V4L2_MBUS_FMT_YUYV8_2X8;
static int cafe_vidioc_enum_fmt_vid_cap(struct file *filp, static int mcam_vidioc_enum_fmt_vid_cap(struct file *filp,
void *priv, struct v4l2_fmtdesc *fmt) void *priv, struct v4l2_fmtdesc *fmt)
{ {
if (fmt->index >= N_CAFE_FMTS) if (fmt->index >= N_MCAM_FMTS)
return -EINVAL; return -EINVAL;
strlcpy(fmt->description, cafe_formats[fmt->index].desc, strlcpy(fmt->description, mcam_formats[fmt->index].desc,
sizeof(fmt->description)); sizeof(fmt->description));
fmt->pixelformat = cafe_formats[fmt->index].pixelformat; fmt->pixelformat = mcam_formats[fmt->index].pixelformat;
return 0; return 0;
} }
static int cafe_vidioc_try_fmt_vid_cap(struct file *filp, void *priv, static int mcam_vidioc_try_fmt_vid_cap(struct file *filp, void *priv,
struct v4l2_format *fmt) struct v4l2_format *fmt)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
struct cafe_format_struct *f; struct mcam_format_struct *f;
struct v4l2_pix_format *pix = &fmt->fmt.pix; struct v4l2_pix_format *pix = &fmt->fmt.pix;
struct v4l2_mbus_framefmt mbus_fmt; struct v4l2_mbus_framefmt mbus_fmt;
int ret; int ret;
f = cafe_find_format(pix->pixelformat); f = mcam_find_format(pix->pixelformat);
pix->pixelformat = f->pixelformat; pix->pixelformat = f->pixelformat;
v4l2_fill_mbus_format(&mbus_fmt, pix, f->mbus_code); v4l2_fill_mbus_format(&mbus_fmt, pix, f->mbus_code);
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1567,11 +1150,11 @@ static int cafe_vidioc_try_fmt_vid_cap(struct file *filp, void *priv, ...@@ -1567,11 +1150,11 @@ static int cafe_vidioc_try_fmt_vid_cap(struct file *filp, void *priv,
return ret; return ret;
} }
static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv, static int mcam_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
struct v4l2_format *fmt) struct v4l2_format *fmt)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
struct cafe_format_struct *f; struct mcam_format_struct *f;
int ret; int ret;
/* /*
...@@ -1581,12 +1164,12 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv, ...@@ -1581,12 +1164,12 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
if (cam->state != S_IDLE || cam->n_sbufs > 0) if (cam->state != S_IDLE || cam->n_sbufs > 0)
return -EBUSY; return -EBUSY;
f = cafe_find_format(fmt->fmt.pix.pixelformat); f = mcam_find_format(fmt->fmt.pix.pixelformat);
/* /*
* See if the formatting works in principle. * See if the formatting works in principle.
*/ */
ret = cafe_vidioc_try_fmt_vid_cap(filp, priv, fmt); ret = mcam_vidioc_try_fmt_vid_cap(filp, priv, fmt);
if (ret) if (ret)
return ret; return ret;
/* /*
...@@ -1602,18 +1185,18 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv, ...@@ -1602,18 +1185,18 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
*/ */
ret = -ENOMEM; ret = -ENOMEM;
if (cam->nbufs > 0 && cam->dma_buf_size < cam->pix_format.sizeimage) if (cam->nbufs > 0 && cam->dma_buf_size < cam->pix_format.sizeimage)
cafe_free_dma_bufs(cam); mcam_free_dma_bufs(cam);
if (cam->nbufs == 0) { if (cam->nbufs == 0) {
if (cafe_alloc_dma_bufs(cam, 0)) if (mcam_alloc_dma_bufs(cam, 0))
goto out; goto out;
} }
/* /*
* It looks like this might work, so let's program the sensor. * It looks like this might work, so let's program the sensor.
*/ */
ret = cafe_cam_configure(cam); ret = mcam_cam_configure(cam);
if (! ret) if (!ret)
ret = cafe_ctlr_configure(cam); ret = mcam_ctlr_configure(cam);
out: out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return ret; return ret;
} }
...@@ -1623,10 +1206,10 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv, ...@@ -1623,10 +1206,10 @@ static int cafe_vidioc_s_fmt_vid_cap(struct file *filp, void *priv,
* The V4l2 spec wants us to be smarter, and actually get this from * The V4l2 spec wants us to be smarter, and actually get this from
* the camera (and not mess with it at open time). Someday. * the camera (and not mess with it at open time). Someday.
*/ */
static int cafe_vidioc_g_fmt_vid_cap(struct file *filp, void *priv, static int mcam_vidioc_g_fmt_vid_cap(struct file *filp, void *priv,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
f->fmt.pix = cam->pix_format; f->fmt.pix = cam->pix_format;
return 0; return 0;
...@@ -1635,7 +1218,7 @@ static int cafe_vidioc_g_fmt_vid_cap(struct file *filp, void *priv, ...@@ -1635,7 +1218,7 @@ static int cafe_vidioc_g_fmt_vid_cap(struct file *filp, void *priv,
/* /*
* We only have one input - the sensor - so minimize the nonsense here. * We only have one input - the sensor - so minimize the nonsense here.
*/ */
static int cafe_vidioc_enum_input(struct file *filp, void *priv, static int mcam_vidioc_enum_input(struct file *filp, void *priv,
struct v4l2_input *input) struct v4l2_input *input)
{ {
if (input->index != 0) if (input->index != 0)
...@@ -1647,13 +1230,13 @@ static int cafe_vidioc_enum_input(struct file *filp, void *priv, ...@@ -1647,13 +1230,13 @@ static int cafe_vidioc_enum_input(struct file *filp, void *priv,
return 0; return 0;
} }
static int cafe_vidioc_g_input(struct file *filp, void *priv, unsigned int *i) static int mcam_vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
{ {
*i = 0; *i = 0;
return 0; return 0;
} }
static int cafe_vidioc_s_input(struct file *filp, void *priv, unsigned int i) static int mcam_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
{ {
if (i != 0) if (i != 0)
return -EINVAL; return -EINVAL;
...@@ -1661,7 +1244,7 @@ static int cafe_vidioc_s_input(struct file *filp, void *priv, unsigned int i) ...@@ -1661,7 +1244,7 @@ static int cafe_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
} }
/* from vivi.c */ /* from vivi.c */
static int cafe_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a) static int mcam_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a)
{ {
return 0; return 0;
} }
...@@ -1670,10 +1253,10 @@ static int cafe_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a) ...@@ -1670,10 +1253,10 @@ static int cafe_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a)
* G/S_PARM. Most of this is done by the sensor, but we are * G/S_PARM. Most of this is done by the sensor, but we are
* the level which controls the number of read buffers. * the level which controls the number of read buffers.
*/ */
static int cafe_vidioc_g_parm(struct file *filp, void *priv, static int mcam_vidioc_g_parm(struct file *filp, void *priv,
struct v4l2_streamparm *parms) struct v4l2_streamparm *parms)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1683,10 +1266,10 @@ static int cafe_vidioc_g_parm(struct file *filp, void *priv, ...@@ -1683,10 +1266,10 @@ static int cafe_vidioc_g_parm(struct file *filp, void *priv,
return ret; return ret;
} }
static int cafe_vidioc_s_parm(struct file *filp, void *priv, static int mcam_vidioc_s_parm(struct file *filp, void *priv,
struct v4l2_streamparm *parms) struct v4l2_streamparm *parms)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1696,24 +1279,24 @@ static int cafe_vidioc_s_parm(struct file *filp, void *priv, ...@@ -1696,24 +1279,24 @@ static int cafe_vidioc_s_parm(struct file *filp, void *priv,
return ret; return ret;
} }
static int cafe_vidioc_g_chip_ident(struct file *file, void *priv, static int mcam_vidioc_g_chip_ident(struct file *file, void *priv,
struct v4l2_dbg_chip_ident *chip) struct v4l2_dbg_chip_ident *chip)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
chip->ident = V4L2_IDENT_NONE; chip->ident = V4L2_IDENT_NONE;
chip->revision = 0; chip->revision = 0;
if (v4l2_chip_match_host(&chip->match)) { if (v4l2_chip_match_host(&chip->match)) {
chip->ident = V4L2_IDENT_CAFE; chip->ident = cam->chip_id;
return 0; return 0;
} }
return sensor_call(cam, core, g_chip_ident, chip); return sensor_call(cam, core, g_chip_ident, chip);
} }
static int cafe_vidioc_enum_framesizes(struct file *filp, void *priv, static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv,
struct v4l2_frmsizeenum *sizes) struct v4l2_frmsizeenum *sizes)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1722,10 +1305,10 @@ static int cafe_vidioc_enum_framesizes(struct file *filp, void *priv, ...@@ -1722,10 +1305,10 @@ static int cafe_vidioc_enum_framesizes(struct file *filp, void *priv,
return ret; return ret;
} }
static int cafe_vidioc_enum_frameintervals(struct file *filp, void *priv, static int mcam_vidioc_enum_frameintervals(struct file *filp, void *priv,
struct v4l2_frmivalenum *interval) struct v4l2_frmivalenum *interval)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
int ret; int ret;
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
...@@ -1735,26 +1318,26 @@ static int cafe_vidioc_enum_frameintervals(struct file *filp, void *priv, ...@@ -1735,26 +1318,26 @@ static int cafe_vidioc_enum_frameintervals(struct file *filp, void *priv,
} }
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
static int cafe_vidioc_g_register(struct file *file, void *priv, static int mcam_vidioc_g_register(struct file *file, void *priv,
struct v4l2_dbg_register *reg) struct v4l2_dbg_register *reg)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
if (v4l2_chip_match_host(&reg->match)) { if (v4l2_chip_match_host(&reg->match)) {
reg->val = cafe_reg_read(cam, reg->reg); reg->val = mcam_reg_read(cam, reg->reg);
reg->size = 4; reg->size = 4;
return 0; return 0;
} }
return sensor_call(cam, core, g_register, reg); return sensor_call(cam, core, g_register, reg);
} }
static int cafe_vidioc_s_register(struct file *file, void *priv, static int mcam_vidioc_s_register(struct file *file, void *priv,
struct v4l2_dbg_register *reg) struct v4l2_dbg_register *reg)
{ {
struct cafe_camera *cam = priv; struct mcam_camera *cam = priv;
if (v4l2_chip_match_host(&reg->match)) { if (v4l2_chip_match_host(&reg->match)) {
cafe_reg_write(cam, reg->reg, reg->val); mcam_reg_write(cam, reg->reg, reg->val);
return 0; return 0;
} }
return sensor_call(cam, core, s_register, reg); return sensor_call(cam, core, s_register, reg);
...@@ -1766,57 +1349,56 @@ static int cafe_vidioc_s_register(struct file *file, void *priv, ...@@ -1766,57 +1349,56 @@ static int cafe_vidioc_s_register(struct file *file, void *priv,
* clone it for specific real devices. * clone it for specific real devices.
*/ */
static const struct v4l2_file_operations cafe_v4l_fops = { static const struct v4l2_file_operations mcam_v4l_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = cafe_v4l_open, .open = mcam_v4l_open,
.release = cafe_v4l_release, .release = mcam_v4l_release,
.read = cafe_v4l_read, .read = mcam_v4l_read,
.poll = cafe_v4l_poll, .poll = mcam_v4l_poll,
.mmap = cafe_v4l_mmap, .mmap = mcam_v4l_mmap,
.unlocked_ioctl = video_ioctl2, .unlocked_ioctl = video_ioctl2,
}; };
static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = { static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
.vidioc_querycap = cafe_vidioc_querycap, .vidioc_querycap = mcam_vidioc_querycap,
.vidioc_enum_fmt_vid_cap = cafe_vidioc_enum_fmt_vid_cap, .vidioc_enum_fmt_vid_cap = mcam_vidioc_enum_fmt_vid_cap,
.vidioc_try_fmt_vid_cap = cafe_vidioc_try_fmt_vid_cap, .vidioc_try_fmt_vid_cap = mcam_vidioc_try_fmt_vid_cap,
.vidioc_s_fmt_vid_cap = cafe_vidioc_s_fmt_vid_cap, .vidioc_s_fmt_vid_cap = mcam_vidioc_s_fmt_vid_cap,
.vidioc_g_fmt_vid_cap = cafe_vidioc_g_fmt_vid_cap, .vidioc_g_fmt_vid_cap = mcam_vidioc_g_fmt_vid_cap,
.vidioc_enum_input = cafe_vidioc_enum_input, .vidioc_enum_input = mcam_vidioc_enum_input,
.vidioc_g_input = cafe_vidioc_g_input, .vidioc_g_input = mcam_vidioc_g_input,
.vidioc_s_input = cafe_vidioc_s_input, .vidioc_s_input = mcam_vidioc_s_input,
.vidioc_s_std = cafe_vidioc_s_std, .vidioc_s_std = mcam_vidioc_s_std,
.vidioc_reqbufs = cafe_vidioc_reqbufs, .vidioc_reqbufs = mcam_vidioc_reqbufs,
.vidioc_querybuf = cafe_vidioc_querybuf, .vidioc_querybuf = mcam_vidioc_querybuf,
.vidioc_qbuf = cafe_vidioc_qbuf, .vidioc_qbuf = mcam_vidioc_qbuf,
.vidioc_dqbuf = cafe_vidioc_dqbuf, .vidioc_dqbuf = mcam_vidioc_dqbuf,
.vidioc_streamon = cafe_vidioc_streamon, .vidioc_streamon = mcam_vidioc_streamon,
.vidioc_streamoff = cafe_vidioc_streamoff, .vidioc_streamoff = mcam_vidioc_streamoff,
.vidioc_queryctrl = cafe_vidioc_queryctrl, .vidioc_queryctrl = mcam_vidioc_queryctrl,
.vidioc_g_ctrl = cafe_vidioc_g_ctrl, .vidioc_g_ctrl = mcam_vidioc_g_ctrl,
.vidioc_s_ctrl = cafe_vidioc_s_ctrl, .vidioc_s_ctrl = mcam_vidioc_s_ctrl,
.vidioc_g_parm = cafe_vidioc_g_parm, .vidioc_g_parm = mcam_vidioc_g_parm,
.vidioc_s_parm = cafe_vidioc_s_parm, .vidioc_s_parm = mcam_vidioc_s_parm,
.vidioc_enum_framesizes = cafe_vidioc_enum_framesizes, .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes,
.vidioc_enum_frameintervals = cafe_vidioc_enum_frameintervals, .vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals,
.vidioc_g_chip_ident = cafe_vidioc_g_chip_ident, .vidioc_g_chip_ident = mcam_vidioc_g_chip_ident,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
.vidioc_g_register = cafe_vidioc_g_register, .vidioc_g_register = mcam_vidioc_g_register,
.vidioc_s_register = cafe_vidioc_s_register, .vidioc_s_register = mcam_vidioc_s_register,
#endif #endif
}; };
static struct video_device cafe_v4l_template = { static struct video_device mcam_v4l_template = {
.name = "cafe", .name = "mcam",
.tvnorms = V4L2_STD_NTSC_M, .tvnorms = V4L2_STD_NTSC_M,
.current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */ .current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */
.fops = &cafe_v4l_fops, .fops = &mcam_v4l_fops,
.ioctl_ops = &cafe_v4l_ioctl_ops, .ioctl_ops = &mcam_v4l_ioctl_ops,
.release = video_device_release_empty, .release = video_device_release_empty,
}; };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* /*
* Interrupt handler stuff * Interrupt handler stuff
...@@ -1824,12 +1406,12 @@ static struct video_device cafe_v4l_template = { ...@@ -1824,12 +1406,12 @@ static struct video_device cafe_v4l_template = {
static void cafe_frame_tasklet(unsigned long data) static void mcam_frame_tasklet(unsigned long data)
{ {
struct cafe_camera *cam = (struct cafe_camera *) data; struct mcam_camera *cam = (struct mcam_camera *) data;
int i; int i;
unsigned long flags; unsigned long flags;
struct cafe_sio_buffer *sbuf; struct mcam_sio_buffer *sbuf;
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
for (i = 0; i < cam->nbufs; i++) { for (i = 0; i < cam->nbufs; i++) {
...@@ -1840,13 +1422,13 @@ static void cafe_frame_tasklet(unsigned long data) ...@@ -1840,13 +1422,13 @@ static void cafe_frame_tasklet(unsigned long data)
} }
if (++(cam->next_buf) >= cam->nbufs) if (++(cam->next_buf) >= cam->nbufs)
cam->next_buf = 0; cam->next_buf = 0;
if (! test_bit(bufno, &cam->flags)) if (!test_bit(bufno, &cam->flags))
continue; continue;
if (list_empty(&cam->sb_avail)) if (list_empty(&cam->sb_avail))
break; /* Leave it valid, hope for better later */ break; /* Leave it valid, hope for better later */
clear_bit(bufno, &cam->flags); clear_bit(bufno, &cam->flags);
sbuf = list_entry(cam->sb_avail.next, sbuf = list_entry(cam->sb_avail.next,
struct cafe_sio_buffer, list); struct mcam_sio_buffer, list);
/* /*
* Drop the lock during the big copy. This *should* be safe... * Drop the lock during the big copy. This *should* be safe...
*/ */
...@@ -1860,14 +1442,14 @@ static void cafe_frame_tasklet(unsigned long data) ...@@ -1860,14 +1442,14 @@ static void cafe_frame_tasklet(unsigned long data)
spin_lock_irqsave(&cam->dev_lock, flags); spin_lock_irqsave(&cam->dev_lock, flags);
list_move_tail(&sbuf->list, &cam->sb_full); list_move_tail(&sbuf->list, &cam->sb_full);
} }
if (! list_empty(&cam->sb_full)) if (!list_empty(&cam->sb_full))
wake_up(&cam->iowait); wake_up(&cam->iowait);
spin_unlock_irqrestore(&cam->dev_lock, flags); spin_unlock_irqrestore(&cam->dev_lock, flags);
} }
static void cafe_frame_complete(struct cafe_camera *cam, int frame) static void mcam_frame_complete(struct mcam_camera *cam, int frame)
{ {
/* /*
* Basic frame housekeeping. * Basic frame housekeeping.
...@@ -1896,8 +1478,8 @@ static void cafe_frame_complete(struct cafe_camera *cam, int frame) ...@@ -1896,8 +1478,8 @@ static void cafe_frame_complete(struct cafe_camera *cam, int frame)
*/ */
case S_SPECREAD: case S_SPECREAD:
if (++(cam->specframes) >= cam->nbufs) { if (++(cam->specframes) >= cam->nbufs) {
cafe_ctlr_stop(cam); mcam_ctlr_stop(cam);
cafe_ctlr_irq_disable(cam); mcam_ctlr_irq_disable(cam);
cam->state = S_IDLE; cam->state = S_IDLE;
} }
wake_up(&cam->iowait); wake_up(&cam->iowait);
...@@ -1923,57 +1505,38 @@ static void cafe_frame_complete(struct cafe_camera *cam, int frame) ...@@ -1923,57 +1505,38 @@ static void cafe_frame_complete(struct cafe_camera *cam, int frame)
static void cafe_frame_irq(struct cafe_camera *cam, unsigned int irqs) int mccic_irq(struct mcam_camera *cam, unsigned int irqs)
{ {
unsigned int frame; unsigned int frame, handled = 0;
cafe_reg_write(cam, REG_IRQSTAT, FRAMEIRQS); /* Clear'em all */ mcam_reg_write(cam, REG_IRQSTAT, FRAMEIRQS); /* Clear'em all */
/* /*
* Handle any frame completions. There really should * Handle any frame completions. There really should
* not be more than one of these, or we have fallen * not be more than one of these, or we have fallen
* far behind. * far behind.
*/ */
for (frame = 0; frame < cam->nbufs; frame++) for (frame = 0; frame < cam->nbufs; frame++)
if (irqs & (IRQ_EOF0 << frame)) if (irqs & (IRQ_EOF0 << frame)) {
cafe_frame_complete(cam, frame); mcam_frame_complete(cam, frame);
handled = 1;
}
/* /*
* If a frame starts, note that we have DMA active. This * If a frame starts, note that we have DMA active. This
* code assumes that we won't get multiple frame interrupts * code assumes that we won't get multiple frame interrupts
* at once; may want to rethink that. * at once; may want to rethink that.
*/ */
if (irqs & (IRQ_SOF0 | IRQ_SOF1 | IRQ_SOF2)) if (irqs & (IRQ_SOF0 | IRQ_SOF1 | IRQ_SOF2)) {
set_bit(CF_DMA_ACTIVE, &cam->flags); set_bit(CF_DMA_ACTIVE, &cam->flags);
} handled = 1;
static irqreturn_t cafe_irq(int irq, void *data)
{
struct cafe_camera *cam = data;
unsigned int irqs;
spin_lock(&cam->dev_lock);
irqs = cafe_reg_read(cam, REG_IRQSTAT);
if ((irqs & ALLIRQS) == 0) {
spin_unlock(&cam->dev_lock);
return IRQ_NONE;
} }
if (irqs & FRAMEIRQS) return handled;
cafe_frame_irq(cam, irqs);
if (irqs & TWSIIRQS) {
cafe_reg_write(cam, REG_IRQSTAT, TWSIIRQS);
wake_up(&cam->smbus_wait);
}
spin_unlock(&cam->dev_lock);
return IRQ_HANDLED;
} }
/* -------------------------------------------------------------------------- */
/* /*
* PCI interface stuff. * Registration and such.
*/ */
/* FIXME this is really platform stuff */
static const struct dmi_system_id olpc_xo1_dmi[] = { static const struct dmi_system_id olpc_xo1_dmi[] = {
{ {
.matches = { .matches = {
...@@ -1985,12 +1548,7 @@ static const struct dmi_system_id olpc_xo1_dmi[] = { ...@@ -1985,12 +1548,7 @@ static const struct dmi_system_id olpc_xo1_dmi[] = {
{ } { }
}; };
static int cafe_pci_probe(struct pci_dev *pdev, static struct ov7670_config sensor_cfg = {
const struct pci_device_id *id)
{
int ret;
struct cafe_camera *cam;
struct ov7670_config sensor_cfg = {
/* This controller only does SMBUS */ /* This controller only does SMBUS */
.use_smbus = true, .use_smbus = true,
...@@ -2000,210 +1558,124 @@ static int cafe_pci_probe(struct pci_dev *pdev, ...@@ -2000,210 +1558,124 @@ static int cafe_pci_probe(struct pci_dev *pdev,
*/ */
.min_width = 320, .min_width = 320,
.min_height = 240, .min_height = 240,
}; };
int mccic_register(struct mcam_camera *cam)
{
struct i2c_board_info ov7670_info = { struct i2c_board_info ov7670_info = {
.type = "ov7670", .type = "ov7670",
.addr = 0x42, .addr = 0x42,
.platform_data = &sensor_cfg, .platform_data = &sensor_cfg,
}; };
int ret;
/* /*
* Start putting together one of our big camera structures. * Register with V4L
*/ */
ret = -ENOMEM; ret = v4l2_device_register(cam->dev, &cam->v4l2_dev);
cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL);
if (cam == NULL)
goto out;
ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev);
if (ret) if (ret)
goto out_free; return ret;
mutex_init(&cam->s_mutex); mutex_init(&cam->s_mutex);
spin_lock_init(&cam->dev_lock);
cam->state = S_NOTREADY; cam->state = S_NOTREADY;
cafe_set_config_needed(cam, 1); mcam_set_config_needed(cam, 1);
init_waitqueue_head(&cam->smbus_wait);
init_waitqueue_head(&cam->iowait); init_waitqueue_head(&cam->iowait);
cam->pdev = pdev; cam->pix_format = mcam_def_pix_format;
cam->pix_format = cafe_def_pix_format; cam->mbus_code = mcam_def_mbus_code;
cam->mbus_code = cafe_def_mbus_code;
INIT_LIST_HEAD(&cam->dev_list); INIT_LIST_HEAD(&cam->dev_list);
INIT_LIST_HEAD(&cam->sb_avail); INIT_LIST_HEAD(&cam->sb_avail);
INIT_LIST_HEAD(&cam->sb_full); INIT_LIST_HEAD(&cam->sb_full);
tasklet_init(&cam->s_tasklet, cafe_frame_tasklet, (unsigned long) cam); tasklet_init(&cam->s_tasklet, mcam_frame_tasklet, (unsigned long) cam);
/*
* Get set up on the PCI bus.
*/
ret = pci_enable_device(pdev);
if (ret)
goto out_unreg;
pci_set_master(pdev);
ret = -EIO; mcam_ctlr_init(cam);
cam->regs = pci_iomap(pdev, 0, 0);
if (! cam->regs) {
printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
goto out_unreg;
}
ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
if (ret)
goto out_iounmap;
/*
* Initialize the controller and leave it powered up. It will
* stay that way until the sensor driver shows up.
*/
cafe_ctlr_init(cam);
cafe_ctlr_power_up(cam);
/*
* Set up I2C/SMBUS communications. We have to drop the mutex here
* because the sensor could attach in this call chain, leading to
* unsightly deadlocks.
*/
ret = cafe_smbus_setup(cam);
if (ret)
goto out_freeirq;
/* Apply XO-1 clock speed */ /* Apply XO-1 clock speed */
if (dmi_check_system(olpc_xo1_dmi)) if (dmi_check_system(olpc_xo1_dmi))
sensor_cfg.clock_speed = 45; sensor_cfg.clock_speed = 45;
/*
* Try to find the sensor.
*/
cam->sensor_addr = ov7670_info.addr; cam->sensor_addr = ov7670_info.addr;
cam->sensor = v4l2_i2c_new_subdev_board(&cam->v4l2_dev, &cam->i2c_adapter, cam->sensor = v4l2_i2c_new_subdev_board(&cam->v4l2_dev,
&ov7670_info, NULL); &cam->i2c_adapter, &ov7670_info, NULL);
if (cam->sensor == NULL) { if (cam->sensor == NULL) {
ret = -ENODEV; ret = -ENODEV;
goto out_smbus; goto out_unregister;
} }
ret = cafe_cam_init(cam); ret = mcam_cam_init(cam);
if (ret) if (ret)
goto out_smbus; goto out_unregister;
/* /*
* Get the v4l2 setup done. * Get the v4l2 setup done.
*/ */
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
cam->vdev = cafe_v4l_template; cam->vdev = mcam_v4l_template;
cam->vdev.debug = 0; cam->vdev.debug = 0;
/* cam->vdev.debug = V4L2_DEBUG_IOCTL_ARG;*/
cam->vdev.v4l2_dev = &cam->v4l2_dev; cam->vdev.v4l2_dev = &cam->v4l2_dev;
ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
if (ret) if (ret)
goto out_unlock; goto out;
video_set_drvdata(&cam->vdev, cam); video_set_drvdata(&cam->vdev, cam);
/* /*
* If so requested, try to get our DMA buffers now. * If so requested, try to get our DMA buffers now.
*/ */
if (!alloc_bufs_at_read) { if (!alloc_bufs_at_read) {
if (cafe_alloc_dma_bufs(cam, 1)) if (mcam_alloc_dma_bufs(cam, 1))
cam_warn(cam, "Unable to alloc DMA buffers at load" cam_warn(cam, "Unable to alloc DMA buffers at load"
" will try again later."); " will try again later.");
} }
out:
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
return 0; return ret;
out_unregister:
out_unlock:
mutex_unlock(&cam->s_mutex);
out_smbus:
cafe_smbus_shutdown(cam);
out_freeirq:
cafe_ctlr_power_down(cam);
free_irq(pdev->irq, cam);
out_iounmap:
pci_iounmap(pdev, cam->regs);
out_free:
v4l2_device_unregister(&cam->v4l2_dev); v4l2_device_unregister(&cam->v4l2_dev);
out_unreg:
kfree(cam);
out:
return ret; return ret;
} }
/* void mccic_shutdown(struct mcam_camera *cam)
* Shut down an initialized device
*/
static void cafe_shutdown(struct cafe_camera *cam)
{ {
/* FIXME: Make sure we take care of everything here */ if (cam->users > 0)
cam_warn(cam, "Removing a device with users!\n");
if (cam->n_sbufs > 0) if (cam->n_sbufs > 0)
/* What if they are still mapped? Shouldn't be, but... */ /* What if they are still mapped? Shouldn't be, but... */
cafe_free_sio_buffers(cam); mcam_free_sio_buffers(cam);
cafe_ctlr_stop_dma(cam); mcam_ctlr_stop_dma(cam);
cafe_ctlr_power_down(cam); mcam_ctlr_power_down(cam);
cafe_smbus_shutdown(cam); mcam_free_dma_bufs(cam);
cafe_free_dma_bufs(cam);
free_irq(cam->pdev->irq, cam);
pci_iounmap(cam->pdev, cam->regs);
video_unregister_device(&cam->vdev); video_unregister_device(&cam->vdev);
}
static void cafe_pci_remove(struct pci_dev *pdev)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
struct cafe_camera *cam = to_cam(v4l2_dev);
if (cam == NULL) {
printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
return;
}
mutex_lock(&cam->s_mutex);
if (cam->users > 0)
cam_warn(cam, "Removing a device with users!\n");
cafe_shutdown(cam);
v4l2_device_unregister(&cam->v4l2_dev); v4l2_device_unregister(&cam->v4l2_dev);
kfree(cam);
/* No unlock - it no longer exists */
} }
#ifdef CONFIG_PM
/* /*
* Basic power management. * Power management
*/ */
static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state) #ifdef CONFIG_PM
void mccic_suspend(struct mcam_camera *cam)
{ {
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); enum mcam_state cstate = cam->state;
struct cafe_camera *cam = to_cam(v4l2_dev);
int ret;
enum cafe_state cstate;
ret = pci_save_state(pdev); mcam_ctlr_stop_dma(cam);
if (ret) mcam_ctlr_power_down(cam);
return ret;
cstate = cam->state; /* HACK - stop_dma sets to idle */
cafe_ctlr_stop_dma(cam);
cafe_ctlr_power_down(cam);
pci_disable_device(pdev);
cam->state = cstate; cam->state = cstate;
return 0;
} }
int mccic_resume(struct mcam_camera *cam)
static int cafe_pci_resume(struct pci_dev *pdev)
{ {
struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
struct cafe_camera *cam = to_cam(v4l2_dev);
int ret = 0; int ret = 0;
pci_restore_state(pdev);
ret = pci_enable_device(pdev);
if (ret) {
cam_warn(cam, "Unable to re-enable device on resume!\n");
return ret;
}
cafe_ctlr_init(cam);
mutex_lock(&cam->s_mutex); mutex_lock(&cam->s_mutex);
if (cam->users > 0) { if (cam->users > 0) {
cafe_ctlr_power_up(cam); mcam_ctlr_power_up(cam);
__cafe_cam_reset(cam); __mcam_cam_reset(cam);
} else { } else {
cafe_ctlr_power_down(cam); mcam_ctlr_power_down(cam);
} }
mutex_unlock(&cam->s_mutex); mutex_unlock(&cam->s_mutex);
...@@ -2211,57 +1683,7 @@ static int cafe_pci_resume(struct pci_dev *pdev) ...@@ -2211,57 +1683,7 @@ static int cafe_pci_resume(struct pci_dev *pdev)
if (cam->state == S_SPECREAD) if (cam->state == S_SPECREAD)
cam->state = S_IDLE; /* Don't bother restarting */ cam->state = S_IDLE; /* Don't bother restarting */
else if (cam->state == S_SINGLEREAD || cam->state == S_STREAMING) else if (cam->state == S_SINGLEREAD || cam->state == S_STREAMING)
ret = cafe_read_setup(cam, cam->state); ret = mcam_read_setup(cam, cam->state);
return ret; return ret;
} }
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
static struct pci_device_id cafe_ids[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL,
PCI_DEVICE_ID_MARVELL_88ALP01_CCIC) },
{ 0, }
};
MODULE_DEVICE_TABLE(pci, cafe_ids);
static struct pci_driver cafe_pci_driver = {
.name = "cafe1000-ccic",
.id_table = cafe_ids,
.probe = cafe_pci_probe,
.remove = cafe_pci_remove,
#ifdef CONFIG_PM
.suspend = cafe_pci_suspend,
.resume = cafe_pci_resume,
#endif
};
static int __init cafe_init(void)
{
int ret;
printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
CAFE_VERSION);
ret = pci_register_driver(&cafe_pci_driver);
if (ret) {
printk(KERN_ERR "Unable to register cafe_ccic driver\n");
goto out;
}
ret = 0;
out:
return ret;
}
static void __exit cafe_exit(void)
{
pci_unregister_driver(&cafe_pci_driver);
}
module_init(cafe_init);
module_exit(cafe_exit);
/*
* Marvell camera core structures.
*
* Copyright 2011 Jonathan Corbet corbet@lwn.net
*/
/*
* Tracking of streaming I/O buffers.
* FIXME doesn't belong in this file
*/
struct mcam_sio_buffer {
struct list_head list;
struct v4l2_buffer v4lbuf;
char *buffer; /* Where it lives in kernel space */
int mapcount;
struct mcam_camera *cam;
};
enum mcam_state {
S_NOTREADY, /* Not yet initialized */
S_IDLE, /* Just hanging around */
S_FLAKED, /* Some sort of problem */
S_SINGLEREAD, /* In read() */
S_SPECREAD, /* Speculative read (for future read()) */
S_STREAMING /* Streaming data */
};
#define MAX_DMA_BUFS 3
/*
* A description of one of our devices.
* Locking: controlled by s_mutex. Certain fields, however, require
* the dev_lock spinlock; they are marked as such by comments.
* dev_lock is also required for access to device registers.
*/
struct mcam_camera {
/*
* These fields should be set by the platform code prior to
* calling mcam_register().
*/
struct i2c_adapter i2c_adapter;
unsigned char __iomem *regs;
spinlock_t dev_lock;
struct device *dev; /* For messages, dma alloc */
unsigned int chip_id;
/*
* Callbacks from the core to the platform code.
*/
void (*plat_power_up) (struct mcam_camera *cam);
void (*plat_power_down) (struct mcam_camera *cam);
/*
* Everything below here is private to the mcam core and
* should not be touched by the platform code.
*/
struct v4l2_device v4l2_dev;
enum mcam_state state;
unsigned long flags; /* Buffer status, mainly (dev_lock) */
int users; /* How many open FDs */
struct file *owner; /* Who has data access (v4l2) */
/*
* Subsystem structures.
*/
struct video_device vdev;
struct v4l2_subdev *sensor;
unsigned short sensor_addr;
struct list_head dev_list; /* link to other devices */
/* DMA buffers */
unsigned int nbufs; /* How many are alloc'd */
int next_buf; /* Next to consume (dev_lock) */
unsigned int dma_buf_size; /* allocated size */
void *dma_bufs[MAX_DMA_BUFS]; /* Internal buffer addresses */
dma_addr_t dma_handles[MAX_DMA_BUFS]; /* Buffer bus addresses */
unsigned int specframes; /* Unconsumed spec frames (dev_lock) */
unsigned int sequence; /* Frame sequence number */
unsigned int buf_seq[MAX_DMA_BUFS]; /* Sequence for individual buffers */
/* Streaming buffers */
unsigned int n_sbufs; /* How many we have */
struct mcam_sio_buffer *sb_bufs; /* The array of housekeeping structs */
struct list_head sb_avail; /* Available for data (we own) (dev_lock) */
struct list_head sb_full; /* With data (user space owns) (dev_lock) */
struct tasklet_struct s_tasklet;
/* Current operating parameters */
u32 sensor_type; /* Currently ov7670 only */
struct v4l2_pix_format pix_format;
enum v4l2_mbus_pixelcode mbus_code;
/* Locks */
struct mutex s_mutex; /* Access to this structure */
/* Misc */
wait_queue_head_t iowait; /* Waiting on frame data */
};
/*
* Register I/O functions. These are here because the platform code
* may legitimately need to mess with the register space.
*/
/*
* Device register I/O
*/
static inline void mcam_reg_write(struct mcam_camera *cam, unsigned int reg,
unsigned int val)
{
iowrite32(val, cam->regs + reg);
}
static inline unsigned int mcam_reg_read(struct mcam_camera *cam,
unsigned int reg)
{
return ioread32(cam->regs + reg);
}
static inline void mcam_reg_write_mask(struct mcam_camera *cam, unsigned int reg,
unsigned int val, unsigned int mask)
{
unsigned int v = mcam_reg_read(cam, reg);
v = (v & ~mask) | (val & mask);
mcam_reg_write(cam, reg, v);
}
static inline void mcam_reg_clear_bit(struct mcam_camera *cam,
unsigned int reg, unsigned int val)
{
mcam_reg_write_mask(cam, reg, 0, val);
}
static inline void mcam_reg_set_bit(struct mcam_camera *cam,
unsigned int reg, unsigned int val)
{
mcam_reg_write_mask(cam, reg, val, val);
}
/*
* Functions for use by platform code.
*/
int mccic_register(struct mcam_camera *cam);
int mccic_irq(struct mcam_camera *cam, unsigned int irqs);
void mccic_shutdown(struct mcam_camera *cam);
#ifdef CONFIG_PM
void mccic_suspend(struct mcam_camera *cam);
int mccic_resume(struct mcam_camera *cam);
#endif
/* /*
* Register definitions for the m88alp01 camera interface. Offsets in bytes * Register definitions for the m88alp01 camera interface. Offsets in bytes
* as given in the spec. * as given in the spec.
*
* Copyright 2006 One Laptop Per Child Association, Inc.
*
* Written by Jonathan Corbet, corbet@lwn.net.
*
* This file may be distributed under the terms of the GNU General
* Public License, version 2.
*/ */
#define REG_Y0BAR 0x00 #define REG_Y0BAR 0x00
#define REG_Y1BAR 0x04 #define REG_Y1BAR 0x04
...@@ -156,7 +301,7 @@ ...@@ -156,7 +301,7 @@
#define GGPIO_OUT 0x80000 /* GPIO output */ #define GGPIO_OUT 0x80000 /* GPIO output */
#define GGPIO_VAL 0x00008 /* Output pin value */ #define GGPIO_VAL 0x00008 /* Output pin value */
#define REG_LEN REG_GL_IMASK + 4 #define REG_LEN (REG_GL_IMASK + 4)
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment