linux/drivers/media/platform/via/via-camera.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Driver for the VIA Chrome integrated camera controller.
 *
 * Copyright 2009,2010 Jonathan Corbet <[email protected]>
 *
 * This work was supported by the One Laptop Per Child project
 */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/v4l2-image-sizes.h>
#include <media/i2c/ov7670.h>
#include <media/videobuf2-dma-sg.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/pm_qos.h>
#include <linux/via-core.h>
#include <linux/via_i2c.h>

#ifdef CONFIG_X86
#include <asm/olpc.h>
#else
#define machine_is_olpc
#endif

#include "via-camera.h"

MODULE_ALIAS();
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();

static bool flip_image;
module_param(flip_image, bool, 0444);
MODULE_PARM_DESC();

static bool override_serial;
module_param(override_serial, bool, 0444);
MODULE_PARM_DESC();

/*
 * The structure describing our camera.
 */
enum viacam_opstate {};

struct via_camera {};

/* buffer for one video frame */
struct via_buffer {};

/*
 * Yes, this is a hack, but there's only going to be one of these
 * on any system we know of.
 */
static struct via_camera *via_cam_info;

/*
 * Flag values, manipulated with bitops
 */
#define CF_DMA_ACTIVE
#define CF_CONFIG_NEEDED


/*
 * Nasty ugly v4l2 boilerplate.
 */
#define sensor_call(cam, optype, func, args...)

/*
 * Debugging and related.
 */
#define cam_err(cam, fmt, arg...)
#define cam_warn(cam, fmt, arg...)
#define cam_dbg(cam, fmt, arg...)

/*
 * Format handling.  This is ripped almost directly from Hans's changes
 * to cafe_ccic.c.  It's a little unfortunate; until this change, we
 * didn't need to know anything about the format except its byte depth;
 * now this information must be managed at this level too.
 */
static struct via_format {} via_formats[] =;
#define N_VIA_FMTS

static struct via_format *via_find_format(u32 pixelformat)
{}


/*--------------------------------------------------------------------------*/
/*
 * Sensor power/reset management.  This piece is OLPC-specific for
 * sure; other configurations will have things connected differently.
 */
static int via_sensor_power_setup(struct via_camera *cam)
{}

/*
 * Power up the sensor and perform the reset dance.
 */
static void via_sensor_power_up(struct via_camera *cam)
{}

static void via_sensor_power_down(struct via_camera *cam)
{}


static void via_sensor_power_release(struct via_camera *cam)
{}

/* --------------------------------------------------------------------------*/
/* Sensor ops */

/*
 * Manage the ov7670 "flip" bit, which needs special help.
 */
static int viacam_set_flip(struct via_camera *cam)
{}

/*
 * Configure the sensor.  It's up to the caller to ensure
 * that the camera is in the correct operating state.
 */
static int viacam_configure_sensor(struct via_camera *cam)
{}



/* --------------------------------------------------------------------------*/
/*
 * Some simple register accessors; they assume that the lock is held.
 *
 * Should we want to support the second capture engine, we could
 * hide the register difference by adding 0x1000 to registers in the
 * 0x300-350 range.
 */
static inline void viacam_write_reg(struct via_camera *cam,
		int reg, int value)
{}

static inline int viacam_read_reg(struct via_camera *cam, int reg)
{}

static inline void viacam_write_reg_mask(struct via_camera *cam,
		int reg, int value, int mask)
{}


/* --------------------------------------------------------------------------*/
/* Interrupt management and handling */

static irqreturn_t viacam_quick_irq(int irq, void *data)
{}

/*
 * Find the next buffer which has somebody waiting on it.
 */
static struct via_buffer *viacam_next_buffer(struct via_camera *cam)
{}

/*
 * The threaded IRQ handler.
 */
static irqreturn_t viacam_irq(int irq, void *data)
{}


/*
 * These functions must mess around with the general interrupt
 * control register, which is relevant to much more than just the
 * camera.  Nothing else uses interrupts, though, as of this writing.
 * Should that situation change, we'll have to improve support at
 * the via-core level.
 */
static void viacam_int_enable(struct via_camera *cam)
{}

static void viacam_int_disable(struct via_camera *cam)
{}



/* --------------------------------------------------------------------------*/
/* Controller operations */

/*
 * Set up our capture buffers in framebuffer memory.
 */
static int viacam_ctlr_cbufs(struct via_camera *cam)
{}

/*
 * Set the scaling register for downscaling the image.
 *
 * This register works like this...  Vertical scaling is enabled
 * by bit 26; if that bit is set, downscaling is controlled by the
 * value in bits 16:25.	 Those bits are divided by 1024 to get
 * the scaling factor; setting just bit 25 thus cuts the height
 * in half.
 *
 * Horizontal scaling works about the same, but it's enabled by
 * bit 11, with bits 0:10 giving the numerator of a fraction
 * (over 2048) for the scaling value.
 *
 * This function is naive in that, if the user departs from
 * the 3x4 VGA scaling factor, the image will distort.	We
 * could work around that if it really seemed important.
 */
static void viacam_set_scale(struct via_camera *cam)
{}


/*
 * Configure image-related information into the capture engine.
 */
static void viacam_ctlr_image(struct via_camera *cam)
{}


static int viacam_config_controller(struct via_camera *cam)
{}

/*
 * Make it start grabbing data.
 */
static void viacam_start_engine(struct via_camera *cam)
{}


static void viacam_stop_engine(struct via_camera *cam)
{}


/* --------------------------------------------------------------------------*/
/* vb2 callback ops */

static struct via_buffer *vb2_to_via_buffer(struct vb2_buffer *vb)
{}

static void viacam_vb2_queue(struct vb2_buffer *vb)
{}

static int viacam_vb2_prepare(struct vb2_buffer *vb)
{}

static int viacam_vb2_queue_setup(struct vb2_queue *vq,
				  unsigned int *nbufs,
				  unsigned int *num_planes, unsigned int sizes[],
				  struct device *alloc_devs[])
{}

static int viacam_vb2_start_streaming(struct vb2_queue *vq, unsigned int count)
{}

static void viacam_vb2_stop_streaming(struct vb2_queue *vq)
{}

static const struct vb2_ops viacam_vb2_ops =;

/* --------------------------------------------------------------------------*/
/* File operations */

static int viacam_open(struct file *filp)
{}

static int viacam_release(struct file *filp)
{}

static const struct v4l2_file_operations viacam_fops =;

/*----------------------------------------------------------------------------*/
/*
 * The long list of v4l2 ioctl ops
 */

/*
 * Only one input.
 */
static int viacam_enum_input(struct file *filp, void *priv,
		struct v4l2_input *input)
{}

static int viacam_g_input(struct file *filp, void *priv, unsigned int *i)
{}

static int viacam_s_input(struct file *filp, void *priv, unsigned int i)
{}

/*
 * Video format stuff.	Here is our default format until
 * user space messes with things.
 */
static const struct v4l2_pix_format viacam_def_pix_format =;

static const u32 via_def_mbus_code =;

static int viacam_enum_fmt_vid_cap(struct file *filp, void *priv,
		struct v4l2_fmtdesc *fmt)
{}

/*
 * Figure out proper image dimensions, but always force the
 * sensor to VGA.
 */
static void viacam_fmt_pre(struct v4l2_pix_format *userfmt,
		struct v4l2_pix_format *sensorfmt)
{}

static void viacam_fmt_post(struct v4l2_pix_format *userfmt,
		struct v4l2_pix_format *sensorfmt)
{}


/*
 * The real work of figuring out a workable format.
 */
static int viacam_do_try_fmt(struct via_camera *cam,
		struct v4l2_pix_format *upix, struct v4l2_pix_format *spix)
{}



static int viacam_try_fmt_vid_cap(struct file *filp, void *priv,
		struct v4l2_format *fmt)
{}


static int viacam_g_fmt_vid_cap(struct file *filp, void *priv,
		struct v4l2_format *fmt)
{}

static int viacam_s_fmt_vid_cap(struct file *filp, void *priv,
		struct v4l2_format *fmt)
{}

static int viacam_querycap(struct file *filp, void *priv,
		struct v4l2_capability *cap)
{}

/* G/S_PARM */

static int viacam_g_parm(struct file *filp, void *priv,
		struct v4l2_streamparm *parm)
{}

static int viacam_s_parm(struct file *filp, void *priv,
		struct v4l2_streamparm *parm)
{}

static int viacam_enum_framesizes(struct file *filp, void *priv,
		struct v4l2_frmsizeenum *sizes)
{}

static int viacam_enum_frameintervals(struct file *filp, void *priv,
		struct v4l2_frmivalenum *interval)
{}

static const struct v4l2_ioctl_ops viacam_ioctl_ops =;

/*----------------------------------------------------------------------------*/

/*
 * Power management.
 */
#ifdef CONFIG_PM

static int viacam_suspend(void *priv)
{}

static int viacam_resume(void *priv)
{}

static struct viafb_pm_hooks viacam_pm_hooks =;

#endif /* CONFIG_PM */

/*
 * Setup stuff.
 */

static const struct video_device viacam_v4l_template =;

/*
 * The OLPC folks put the serial port on the same pin as
 * the camera.	They also get grumpy if we break the
 * serial port and keep them from using it.  So we have
 * to check the serial enable bit and not step on it.
 */
#define VIACAM_SERIAL_DEVFN
#define VIACAM_SERIAL_CREG
#define VIACAM_SERIAL_BIT

static bool viacam_serial_is_enabled(void)
{}

static struct ov7670_config sensor_cfg =;

static int viacam_probe(struct platform_device *pdev)
{}

static void viacam_remove(struct platform_device *pdev)
{}

static struct platform_driver viacam_driver =;

module_platform_driver();