linux/drivers/media/platform/renesas/renesas-ceu.c

// SPDX-License-Identifier: GPL-2.0
/*
 * V4L2 Driver for Renesas Capture Engine Unit (CEU) interface
 * Copyright (C) 2017-2018 Jacopo Mondi <[email protected]>
 *
 * Based on soc-camera driver "soc_camera/sh_mobile_ceu_camera.c"
 * Copyright (C) 2008 Magnus Damm
 *
 * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
 * Copyright (C) 2006, Sascha Hauer, Pengutronix
 * Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
 */

#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/videodev2.h>

#include <media/v4l2-async.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-device.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fwnode.h>
#include <media/v4l2-image-sizes.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-mediabus.h>
#include <media/videobuf2-dma-contig.h>

#include <media/drv-intf/renesas-ceu.h>

#define DRIVER_NAME

/* CEU registers offsets and masks. */
#define CEU_CAPSR
#define CEU_CAPCR
#define CEU_CAMCR
#define CEU_CAMOR
#define CEU_CAPWR
#define CEU_CAIFR
#define CEU_CRCNTR
#define CEU_CRCMPR
#define CEU_CFLCR
#define CEU_CFSZR
#define CEU_CDWDR
#define CEU_CDAYR
#define CEU_CDACR
#define CEU_CFWCR
#define CEU_CDOCR
#define CEU_CEIER
#define CEU_CETCR
#define CEU_CSTSR
#define CEU_CSRTR

/* Data synchronous fetch mode. */
#define CEU_CAMCR_JPEG

/* Input components ordering: CEU_CAMCR.DTARY field. */
#define CEU_CAMCR_DTARY_8_UYVY
#define CEU_CAMCR_DTARY_8_VYUY
#define CEU_CAMCR_DTARY_8_YUYV
#define CEU_CAMCR_DTARY_8_YVYU
/* TODO: input components ordering for 16 bits input. */

/* Bus transfer MTU. */
#define CEU_CAPCR_BUS_WIDTH256

/* Bus width configuration. */
#define CEU_CAMCR_DTIF_16BITS

/* No downsampling to planar YUV420 in image fetch mode. */
#define CEU_CDOCR_NO_DOWSAMPLE

/* Swap all input data in 8-bit, 16-bits and 32-bits units (Figure 46.45). */
#define CEU_CDOCR_SWAP_ENDIANNESS

/* Capture reset and enable bits. */
#define CEU_CAPSR_CPKIL
#define CEU_CAPSR_CE

/* CEU operating flag bit. */
#define CEU_CAPCR_CTNCP
#define CEU_CSTRST_CPTON

/* Platform specific IRQ source flags. */
#define CEU_CETCR_ALL_IRQS_RZ
#define CEU_CETCR_ALL_IRQS_SH4

/* Prohibited register access interrupt bit. */
#define CEU_CETCR_IGRW
/* One-frame capture end interrupt. */
#define CEU_CEIER_CPE
/* VBP error. */
#define CEU_CEIER_VBP
#define CEU_CEIER_MASK

#define CEU_MAX_WIDTH
#define CEU_MAX_HEIGHT
#define CEU_MAX_BPL
#define CEU_W_MAX(w)
#define CEU_H_MAX(h)

/*
 * ceu_bus_fmt - describe a 8-bits yuyv format the sensor can produce
 *
 * @mbus_code: bus format code
 * @fmt_order: CEU_CAMCR.DTARY ordering of input components (Y, Cb, Cr)
 * @fmt_order_swap: swapped CEU_CAMCR.DTARY ordering of input components
 *		    (Y, Cr, Cb)
 * @swapped: does Cr appear before Cb?
 * @bps: number of bits sent over bus for each sample
 * @bpp: number of bits per pixels unit
 */
struct ceu_mbus_fmt {};

/*
 * ceu_buffer - Link vb2 buffer to the list of available buffers.
 */
struct ceu_buffer {};

static inline struct ceu_buffer *vb2_to_ceu(struct vb2_v4l2_buffer *vbuf)
{}

/*
 * ceu_subdev - Wraps v4l2 sub-device and provides async subdevice.
 */
struct ceu_subdev {};

static struct ceu_subdev *to_ceu_subdev(struct v4l2_async_connection *asd)
{}

/*
 * ceu_device - CEU device instance
 */
struct ceu_device {};

static inline struct ceu_device *v4l2_to_ceu(struct v4l2_device *v4l2_dev)
{}

/* --- CEU memory output formats --- */

/*
 * ceu_fmt - describe a memory output format supported by CEU interface.
 *
 * @fourcc: memory layout fourcc format code
 * @bpp: number of bits for each pixel stored in memory
 */
struct ceu_fmt {};

/*
 * ceu_format_list - List of supported memory output formats
 *
 * If sensor provides any YUYV bus format, all the following planar memory
 * formats are available thanks to CEU re-ordering and sub-sampling
 * capabilities.
 */
static const struct ceu_fmt ceu_fmt_list[] =;

static const struct ceu_fmt *get_ceu_fmt_from_fourcc(unsigned int fourcc)
{}

static bool ceu_fmt_mplane(struct v4l2_pix_format_mplane *pix)
{}

/* --- CEU HW operations --- */

static void ceu_write(struct ceu_device *priv, unsigned int reg_offs, u32 data)
{}

static u32 ceu_read(struct ceu_device *priv, unsigned int reg_offs)
{}

/*
 * ceu_soft_reset() - Software reset the CEU interface.
 * @ceu_device: CEU device.
 *
 * Returns 0 for success, -EIO for error.
 */
static int ceu_soft_reset(struct ceu_device *ceudev)
{}

/* --- CEU Capture Operations --- */

/*
 * ceu_hw_config() - Configure CEU interface registers.
 */
static int ceu_hw_config(struct ceu_device *ceudev)
{}

/*
 * ceu_capture() - Trigger start of a capture sequence.
 *
 * Program the CEU DMA registers with addresses where to transfer image data.
 */
static int ceu_capture(struct ceu_device *ceudev)
{}

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

/* --- CEU Videobuf2 operations --- */

static void ceu_update_plane_sizes(struct v4l2_plane_pix_format *plane,
				   unsigned int bpl, unsigned int szimage)
{}

/*
 * ceu_calc_plane_sizes() - Fill per-plane 'struct v4l2_plane_pix_format'
 *			    information according to the currently configured
 *			    pixel format.
 * @ceu_device: CEU device.
 * @ceu_fmt: Active image format.
 * @pix: Pixel format information (store line width and image sizes)
 */
static void ceu_calc_plane_sizes(struct ceu_device *ceudev,
				 const struct ceu_fmt *ceu_fmt,
				 struct v4l2_pix_format_mplane *pix)
{}

/*
 * ceu_vb2_setup() - is called to check whether the driver can accept the
 *		     requested number of buffers and to fill in plane sizes
 *		     for the current frame format, if required.
 */
static int ceu_vb2_setup(struct vb2_queue *vq, unsigned int *count,
			 unsigned int *num_planes, unsigned int sizes[],
			 struct device *alloc_devs[])
{}

static void ceu_vb2_queue(struct vb2_buffer *vb)
{}

static int ceu_vb2_prepare(struct vb2_buffer *vb)
{}

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

static void ceu_stop_streaming(struct vb2_queue *vq)
{}

static const struct vb2_ops ceu_vb2_ops =;

/* --- CEU image formats handling --- */

/*
 * __ceu_try_fmt() - test format on CEU and sensor
 * @ceudev: The CEU device.
 * @v4l2_fmt: format to test.
 * @sd_mbus_code: the media bus code accepted by the subdevice; output param.
 *
 * Returns 0 for success, < 0 for errors.
 */
static int __ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt,
			 u32 *sd_mbus_code)
{}

/*
 * ceu_try_fmt() - Wrapper for __ceu_try_fmt; discard configured mbus_fmt
 */
static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)
{}

/*
 * ceu_set_fmt() - Apply the supplied format to both sensor and CEU
 */
static int ceu_set_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)
{}

/*
 * ceu_set_default_fmt() - Apply default NV16 memory output format with VGA
 *			   sizes.
 */
static int ceu_set_default_fmt(struct ceu_device *ceudev)
{}

/*
 * ceu_init_mbus_fmt() - Query sensor for supported formats and initialize
 *			 CEU media bus format used to produce memory formats.
 *
 * Find out if sensor can produce a permutation of 8-bits YUYV bus format.
 * From a single 8-bits YUYV bus format the CEU can produce several memory
 * output formats:
 * - NV[12|21|16|61] through image fetch mode;
 * - YUYV422 if sensor provides YUYV422
 *
 * TODO: Other YUYV422 permutations through data fetch sync mode and DTARY
 * TODO: Binary data (eg. JPEG) and raw formats through data fetch sync mode
 */
static int ceu_init_mbus_fmt(struct ceu_device *ceudev)
{}

/* --- Runtime PM Handlers --- */

/*
 * ceu_runtime_resume() - soft-reset the interface and turn sensor power on.
 */
static int __maybe_unused ceu_runtime_resume(struct device *dev)
{}

/*
 * ceu_runtime_suspend() - disable capture and interrupts and soft-reset.
 *			   Turn sensor power off.
 */
static int __maybe_unused ceu_runtime_suspend(struct device *dev)
{}

/* --- File Operations --- */

static int ceu_open(struct file *file)
{}

static int ceu_release(struct file *file)
{}

static const struct v4l2_file_operations ceu_fops =;

/* --- Video Device IOCTLs --- */

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

static int ceu_enum_fmt_vid_cap(struct file *file, void *priv,
				struct v4l2_fmtdesc *f)
{}

static int ceu_try_fmt_vid_cap(struct file *file, void *priv,
			       struct v4l2_format *f)
{}

static int ceu_s_fmt_vid_cap(struct file *file, void *priv,
			     struct v4l2_format *f)
{}

static int ceu_g_fmt_vid_cap(struct file *file, void *priv,
			     struct v4l2_format *f)
{}

static int ceu_enum_input(struct file *file, void *priv,
			  struct v4l2_input *inp)
{}

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

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

static int ceu_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
{}

static int ceu_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
{}

static int ceu_enum_framesizes(struct file *file, void *fh,
			       struct v4l2_frmsizeenum *fsize)
{}

static int ceu_enum_frameintervals(struct file *file, void *fh,
				   struct v4l2_frmivalenum *fival)
{}

static const struct v4l2_ioctl_ops ceu_ioctl_ops =;

/*
 * ceu_vdev_release() - release CEU video device memory when last reference
 *			to this driver is closed
 */
static void ceu_vdev_release(struct video_device *vdev)
{}

static int ceu_notify_bound(struct v4l2_async_notifier *notifier,
			    struct v4l2_subdev *v4l2_sd,
			    struct v4l2_async_connection *asd)
{}

static int ceu_notify_complete(struct v4l2_async_notifier *notifier)
{}

static const struct v4l2_async_notifier_operations ceu_notify_ops =;

/*
 * ceu_init_async_subdevs() - Initialize CEU subdevices and async_subdevs in
 *                           ceu device. Both DT and platform data parsing use
 *                           this routine.
 *
 * Returns 0 for success, -ENOMEM for failure.
 */
static int ceu_init_async_subdevs(struct ceu_device *ceudev, unsigned int n_sd)
{}

/*
 * ceu_parse_platform_data() - Initialize async_subdevices using platform
 *			       device provided data.
 */
static int ceu_parse_platform_data(struct ceu_device *ceudev,
				   const struct ceu_platform_data *pdata)
{}

/*
 * ceu_parse_dt() - Initialize async_subdevs parsing device tree graph.
 */
static int ceu_parse_dt(struct ceu_device *ceudev)
{}

/*
 * struct ceu_data - Platform specific CEU data
 * @irq_mask: CETCR mask with all interrupt sources enabled. The mask differs
 *	      between SH4 and RZ platforms.
 */
struct ceu_data {};

static const struct ceu_data ceu_data_sh4 =;

#if IS_ENABLED(CONFIG_OF)
static const struct ceu_data ceu_data_rz =;

static const struct of_device_id ceu_of_match[] =;
MODULE_DEVICE_TABLE(of, ceu_of_match);
#endif

static int ceu_probe(struct platform_device *pdev)
{}

static void ceu_remove(struct platform_device *pdev)
{}

static const struct dev_pm_ops ceu_pm_ops =;

static struct platform_driver ceu_driver =;

module_platform_driver();

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