linux/drivers/media/platform/ti/am437x/am437x-vpfe.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * TI VPFE capture Driver
 *
 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
 *
 * Benoit Parrot <[email protected]>
 * Lad, Prabhakar <[email protected]>
 */

#include <linux/delay.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of_graph.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/videodev2.h>

#include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fwnode.h>
#include <media/v4l2-rect.h>

#include "am437x-vpfe.h"

#define VPFE_MODULE_NAME
#define VPFE_VERSION

static int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC();

#define vpfe_dbg(level, dev, fmt, arg...)
#define vpfe_info(dev, fmt, arg...)
#define vpfe_err(dev, fmt, arg...)

/* standard information */
struct vpfe_standard {};

static const struct vpfe_standard vpfe_standards[] =;

static struct vpfe_fmt formats[VPFE_NUM_FORMATS] =;

static int __subdev_get_format(struct vpfe_device *vpfe,
			       struct v4l2_mbus_framefmt *fmt);
static int vpfe_calc_format_size(struct vpfe_device *vpfe,
				 const struct vpfe_fmt *fmt,
				 struct v4l2_format *f);

static struct vpfe_fmt *find_format_by_code(struct vpfe_device *vpfe,
					    unsigned int code)
{}

static struct vpfe_fmt *find_format_by_pix(struct vpfe_device *vpfe,
					   unsigned int pixelformat)
{}

static unsigned int __get_bytesperpixel(struct vpfe_device *vpfe,
					const struct vpfe_fmt *fmt)
{}

/*  Print Four-character-code (FOURCC) */
static char *print_fourcc(u32 fmt)
{}

static inline u32 vpfe_reg_read(struct vpfe_ccdc *ccdc, u32 offset)
{}

static inline void vpfe_reg_write(struct vpfe_ccdc *ccdc, u32 val, u32 offset)
{}

static inline struct vpfe_device *to_vpfe(struct vpfe_ccdc *ccdc)
{}

static inline
struct vpfe_cap_buffer *to_vpfe_buffer(struct vb2_v4l2_buffer *vb)
{}

static inline void vpfe_pcr_enable(struct vpfe_ccdc *ccdc, int flag)
{}

static void vpfe_config_enable(struct vpfe_ccdc *ccdc, int flag)
{}

static void vpfe_ccdc_setwin(struct vpfe_ccdc *ccdc,
			     struct v4l2_rect *image_win,
			     enum ccdc_frmfmt frm_fmt,
			     int bpp)
{}

static void vpfe_reg_dump(struct vpfe_ccdc *ccdc)
{}

static int
vpfe_ccdc_validate_param(struct vpfe_ccdc *ccdc,
			 struct vpfe_ccdc_config_params_raw *ccdcparam)
{}

static void
vpfe_ccdc_update_raw_params(struct vpfe_ccdc *ccdc,
			    struct vpfe_ccdc_config_params_raw *raw_params)
{}

/*
 * vpfe_ccdc_restore_defaults()
 * This function will write defaults to all CCDC registers
 */
static void vpfe_ccdc_restore_defaults(struct vpfe_ccdc *ccdc)
{}

static int vpfe_ccdc_close(struct vpfe_ccdc *ccdc, struct device *dev)
{}

static int vpfe_ccdc_set_params(struct vpfe_ccdc *ccdc, void __user *params)
{}

/*
 * vpfe_ccdc_config_ycbcr()
 * This function will configure CCDC for YCbCr video capture
 */
static void vpfe_ccdc_config_ycbcr(struct vpfe_ccdc *ccdc)
{}

static void
vpfe_ccdc_config_black_clamp(struct vpfe_ccdc *ccdc,
			     struct vpfe_ccdc_black_clamp *bclamp)
{}

static void
vpfe_ccdc_config_black_compense(struct vpfe_ccdc *ccdc,
				struct vpfe_ccdc_black_compensation *bcomp)
{}

/*
 * vpfe_ccdc_config_raw()
 * This function will configure CCDC for Raw capture mode
 */
static void vpfe_ccdc_config_raw(struct vpfe_ccdc *ccdc)
{}

static inline int
vpfe_ccdc_set_buftype(struct vpfe_ccdc *ccdc,
		      enum ccdc_buftype buf_type)
{}

static inline enum ccdc_buftype vpfe_ccdc_get_buftype(struct vpfe_ccdc *ccdc)
{}

static int vpfe_ccdc_set_pixel_format(struct vpfe_ccdc *ccdc, u32 pixfmt)
{}

static u32 vpfe_ccdc_get_pixel_format(struct vpfe_ccdc *ccdc)
{}

static int
vpfe_ccdc_set_image_window(struct vpfe_ccdc *ccdc,
			   struct v4l2_rect *win, unsigned int bpp)
{}

static inline void
vpfe_ccdc_get_image_window(struct vpfe_ccdc *ccdc,
			   struct v4l2_rect *win)
{}

static inline unsigned int vpfe_ccdc_get_line_length(struct vpfe_ccdc *ccdc)
{}

static inline int
vpfe_ccdc_set_frame_format(struct vpfe_ccdc *ccdc,
			   enum ccdc_frmfmt frm_fmt)
{}

static inline enum ccdc_frmfmt
vpfe_ccdc_get_frame_format(struct vpfe_ccdc *ccdc)
{}

static inline int vpfe_ccdc_getfid(struct vpfe_ccdc *ccdc)
{}

static inline void vpfe_set_sdr_addr(struct vpfe_ccdc *ccdc, unsigned long addr)
{}

static int vpfe_ccdc_set_hw_if_params(struct vpfe_ccdc *ccdc,
				      struct vpfe_hw_if_param *params)
{}

static void vpfe_clear_intr(struct vpfe_ccdc *ccdc, int vdint)
{}

static void vpfe_ccdc_config_defaults(struct vpfe_ccdc *ccdc)
{}

/*
 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
 */
static int vpfe_get_ccdc_image_format(struct vpfe_device *vpfe,
				      struct v4l2_format *f)
{}

static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe)
{}

/*
 * vpfe_config_image_format()
 * For a given standard, this functions sets up the default
 * pix format & crop values in the vpfe device and ccdc.  It first
 * starts with defaults based values from the standard table.
 * It then checks if sub device supports get_fmt and then override the
 * values based on that.Sets crop values to match with scan resolution
 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
 * values in ccdc
 */
static int vpfe_config_image_format(struct vpfe_device *vpfe,
				    v4l2_std_id std_id)
{}

static int vpfe_initialize_device(struct vpfe_device *vpfe)
{}

/*
 * vpfe_release : This function is based on the vb2_fop_release
 * helper function.
 * It has been augmented to handle module power management,
 * by disabling/enabling h/w module fcntl clock when necessary.
 */
static int vpfe_release(struct file *file)
{}

/*
 * vpfe_open : This function is based on the v4l2_fh_open helper function.
 * It has been augmented to handle module power management,
 * by disabling/enabling h/w module fcntl clock when necessary.
 */
static int vpfe_open(struct file *file)
{}

/**
 * vpfe_schedule_next_buffer: set next buffer address for capture
 * @vpfe : ptr to vpfe device
 *
 * This function will get next buffer from the dma queue and
 * set the buffer address in the vpfe register for capture.
 * the buffer is marked active
 */
static void vpfe_schedule_next_buffer(struct vpfe_device *vpfe)
{}

static inline void vpfe_schedule_bottom_field(struct vpfe_device *vpfe)
{}

/*
 * vpfe_process_buffer_complete: process a completed buffer
 * @vpfe : ptr to vpfe device
 *
 * This function time stamp the buffer and mark it as DONE. It also
 * wake up any process waiting on the QUEUE and set the next buffer
 * as current
 */
static inline void vpfe_process_buffer_complete(struct vpfe_device *vpfe)
{}

static void vpfe_handle_interlaced_irq(struct vpfe_device *vpfe,
				       enum v4l2_field field)
{}

/*
 * vpfe_isr : ISR handler for vpfe capture (VINT0)
 * @irq: irq number
 * @dev_id: dev_id ptr
 *
 * It changes status of the captured buffer, takes next buffer from the queue
 * and sets its address in VPFE registers
 */
static irqreturn_t vpfe_isr(int irq, void *dev)
{}

static inline void vpfe_detach_irq(struct vpfe_device *vpfe)
{}

static inline void vpfe_attach_irq(struct vpfe_device *vpfe)
{}

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

/* get the format set at output pad of the adjacent subdev */
static int __subdev_get_format(struct vpfe_device *vpfe,
			       struct v4l2_mbus_framefmt *fmt)
{}

/* set the format at output pad of the adjacent subdev */
static int __subdev_set_format(struct vpfe_device *vpfe,
			       struct v4l2_mbus_framefmt *fmt)
{}

static int vpfe_calc_format_size(struct vpfe_device *vpfe,
				 const struct vpfe_fmt *fmt,
				 struct v4l2_format *f)
{}

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

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

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

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

static int vpfe_enum_size(struct file *file, void  *priv,
			  struct v4l2_frmsizeenum *fsize)
{}

/*
 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
 * given app input index
 */
static int
vpfe_get_subdev_input_index(struct vpfe_device *vpfe,
			    int *subdev_index,
			    int *subdev_input_index,
			    int app_input_index)
{}

/*
 * vpfe_get_app_input - Get app input index for a given subdev input index
 * driver stores the input index of the current sub device and translate it
 * when application request the current input
 */
static int vpfe_get_app_input_index(struct vpfe_device *vpfe,
				    int *app_input_index)
{}

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

static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
{}

/* Assumes caller is holding vpfe_dev->lock */
static int vpfe_set_input(struct vpfe_device *vpfe, unsigned int index)
{}

static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
{}

static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
{}

static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id std_id)
{}

static int vpfe_g_std(struct file *file, void *priv, v4l2_std_id *std_id)
{}

/*
 * vpfe_calculate_offsets : This function calculates buffers offset
 * for top and bottom field
 */
static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
{}

/*
 * vpfe_queue_setup - Callback function for buffer setup.
 * @vq: vb2_queue ptr
 * @nbuffers: ptr to number of buffers requested by application
 * @nplanes:: contains number of distinct video planes needed to hold a frame
 * @sizes[]: contains the size (in bytes) of each plane.
 * @alloc_devs: ptr to allocation context
 *
 * This callback function is called when reqbuf() is called to adjust
 * the buffer count and buffer size
 */
static int vpfe_queue_setup(struct vb2_queue *vq,
			    unsigned int *nbuffers, unsigned int *nplanes,
			    unsigned int sizes[], struct device *alloc_devs[])
{}

/*
 * vpfe_buffer_prepare :  callback function for buffer prepare
 * @vb: ptr to vb2_buffer
 *
 * This is the callback function for buffer prepare when vb2_qbuf()
 * function is called. The buffer is prepared and user space virtual address
 * or user address is converted into  physical address
 */
static int vpfe_buffer_prepare(struct vb2_buffer *vb)
{}

/*
 * vpfe_buffer_queue : Callback function to add buffer to DMA queue
 * @vb: ptr to vb2_buffer
 */
static void vpfe_buffer_queue(struct vb2_buffer *vb)
{}

static void vpfe_return_all_buffers(struct vpfe_device *vpfe,
				    enum vb2_buffer_state state)
{}

/*
 * vpfe_start_streaming : Starts the DMA engine for streaming
 * @vb: ptr to vb2_buffer
 * @count: number of buffers
 */
static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
{}

/*
 * vpfe_stop_streaming : Stop the DMA engine
 * @vq: ptr to vb2_queue
 *
 * This callback stops the DMA engine and any remaining buffers
 * in the DMA queue are released.
 */
static void vpfe_stop_streaming(struct vb2_queue *vq)
{}

static int vpfe_g_pixelaspect(struct file *file, void *priv,
			      int type, struct v4l2_fract *f)
{}

static int
vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s)
{}

static int
vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
{}

static long vpfe_ioctl_default(struct file *file, void *priv,
			       bool valid_prio, unsigned int cmd, void *param)
{}

static const struct vb2_ops vpfe_video_qops =;

/* vpfe capture driver file operations */
static const struct v4l2_file_operations vpfe_fops =;

/* vpfe capture ioctl operations */
static const struct v4l2_ioctl_ops vpfe_ioctl_ops =;

static int
vpfe_async_bound(struct v4l2_async_notifier *notifier,
		 struct v4l2_subdev *subdev,
		 struct v4l2_async_connection *asd)
{}

static int vpfe_probe_complete(struct vpfe_device *vpfe)
{}

static int vpfe_async_complete(struct v4l2_async_notifier *notifier)
{}

static const struct v4l2_async_notifier_operations vpfe_async_ops =;

static struct vpfe_config *
vpfe_get_pdata(struct vpfe_device *vpfe)
{}

/*
 * vpfe_probe : This function creates device entries by register
 * itself to the V4L2 driver and initializes fields of each
 * device objects
 */
static int vpfe_probe(struct platform_device *pdev)
{}

/*
 * vpfe_remove : It un-register device from V4L2 driver
 */
static void vpfe_remove(struct platform_device *pdev)
{}

#ifdef CONFIG_PM_SLEEP

static void vpfe_save_context(struct vpfe_ccdc *ccdc)
{}

static int vpfe_suspend(struct device *dev)
{}

static void vpfe_restore_context(struct vpfe_ccdc *ccdc)
{}

static int vpfe_resume(struct device *dev)
{}

#endif

static SIMPLE_DEV_PM_OPS(vpfe_pm_ops, vpfe_suspend, vpfe_resume);

static const struct of_device_id vpfe_of_match[] =;
MODULE_DEVICE_TABLE(of, vpfe_of_match);

static struct platform_driver vpfe_driver =;

module_platform_driver();

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