// SPDX-License-Identifier: GPL-2.0+ /* * TI OMAP4 ISS V4L2 Driver - CSI PHY module * * Copyright (C) 2012 Texas Instruments, Inc. * * Author: Sergio Aguirre <[email protected]> */ #include <linux/delay.h> #include <media/v4l2-common.h> #include <linux/v4l2-mediabus.h> #include <linux/mm.h> #include "iss.h" #include "iss_regs.h" #include "iss_csi2.h" /* * csi2_if_enable - Enable CSI2 Receiver interface. * @enable: enable flag * */ static void csi2_if_enable(struct iss_csi2_device *csi2, u8 enable) { … } /* * csi2_recv_config - CSI2 receiver module configuration. * @currctrl: iss_csi2_ctrl_cfg structure * */ static void csi2_recv_config(struct iss_csi2_device *csi2, struct iss_csi2_ctrl_cfg *currctrl) { … } static const unsigned int csi2_input_fmts[] = …; /* To set the format on the CSI2 requires a mapping function that takes * the following inputs: * - 3 different formats (at this time) * - 2 destinations (mem, vp+mem) (vp only handled separately) * - 2 decompression options (on, off) * Output should be CSI2 frame format code * Array indices as follows: [format][dest][decompr] * Not all combinations are valid. 0 means invalid. */ static const u16 __csi2_fmt_map[][2][2] = …; /* * csi2_ctx_map_format - Map CSI2 sink media bus format to CSI2 format ID * @csi2: ISS CSI2 device * * Returns CSI2 physical format id */ static u16 csi2_ctx_map_format(struct iss_csi2_device *csi2) { … } /* * csi2_set_outaddr - Set memory address to save output image * @csi2: Pointer to ISS CSI2a device. * @addr: 32-bit memory address aligned on 32 byte boundary. * * Sets the memory address where the output will be saved. * * Returns 0 if successful, or -EINVAL if the address is not in the 32 byte * boundary. */ static void csi2_set_outaddr(struct iss_csi2_device *csi2, u32 addr) { … } /* * is_usr_def_mapping - Checks whether USER_DEF_MAPPING should * be enabled by CSI2. * @format_id: mapped format id * */ static inline int is_usr_def_mapping(u32 format_id) { … } /* * csi2_ctx_enable - Enable specified CSI2 context * @ctxnum: Context number, valid between 0 and 7 values. * @enable: enable * */ static void csi2_ctx_enable(struct iss_csi2_device *csi2, u8 ctxnum, u8 enable) { … } /* * csi2_ctx_config - CSI2 context configuration. * @ctx: context configuration * */ static void csi2_ctx_config(struct iss_csi2_device *csi2, struct iss_csi2_ctx_cfg *ctx) { … } /* * csi2_timing_config - CSI2 timing configuration. * @timing: csi2_timing_cfg structure */ static void csi2_timing_config(struct iss_csi2_device *csi2, struct iss_csi2_timing_cfg *timing) { … } /* * csi2_irq_ctx_set - Enables CSI2 Context IRQs. * @enable: Enable/disable CSI2 Context interrupts */ static void csi2_irq_ctx_set(struct iss_csi2_device *csi2, int enable) { … } /* * csi2_irq_complexio1_set - Enables CSI2 ComplexIO IRQs. * @enable: Enable/disable CSI2 ComplexIO #1 interrupts */ static void csi2_irq_complexio1_set(struct iss_csi2_device *csi2, int enable) { … } /* * csi2_irq_status_set - Enables CSI2 Status IRQs. * @enable: Enable/disable CSI2 Status interrupts */ static void csi2_irq_status_set(struct iss_csi2_device *csi2, int enable) { … } /* * omap4iss_csi2_reset - Resets the CSI2 module. * * Must be called with the phy lock held. * * Returns 0 if successful, or -EBUSY if power command didn't respond. */ int omap4iss_csi2_reset(struct iss_csi2_device *csi2) { … } static int csi2_configure(struct iss_csi2_device *csi2) { … } /* * csi2_print_status - Prints CSI2 debug information. */ #define CSI2_PRINT_REGISTER(iss, regs, name) … static void csi2_print_status(struct iss_csi2_device *csi2) { … } /* ----------------------------------------------------------------------------- * Interrupt handling */ /* * csi2_isr_buffer - Does buffer handling at end-of-frame * when writing to memory. */ static void csi2_isr_buffer(struct iss_csi2_device *csi2) { … } static void csi2_isr_ctx(struct iss_csi2_device *csi2, struct iss_csi2_ctx_cfg *ctx) { … } /* * omap4iss_csi2_isr - CSI2 interrupt handling. */ void omap4iss_csi2_isr(struct iss_csi2_device *csi2) { … } /* ----------------------------------------------------------------------------- * ISS video operations */ /* * csi2_queue - Queues the first buffer when using memory output * @video: The video node * @buffer: buffer to queue */ static int csi2_queue(struct iss_video *video, struct iss_buffer *buffer) { … } static const struct iss_video_operations csi2_issvideo_ops = …; /* ----------------------------------------------------------------------------- * V4L2 subdev operations */ static struct v4l2_mbus_framefmt * __csi2_get_format(struct iss_csi2_device *csi2, struct v4l2_subdev_state *sd_state, unsigned int pad, enum v4l2_subdev_format_whence which) { … } static void csi2_try_format(struct iss_csi2_device *csi2, struct v4l2_subdev_state *sd_state, unsigned int pad, struct v4l2_mbus_framefmt *fmt, enum v4l2_subdev_format_whence which) { … } /* * csi2_enum_mbus_code - Handle pixel format enumeration * @sd : pointer to v4l2 subdev structure * @sd_state: V4L2 subdev state * @code : pointer to v4l2_subdev_mbus_code_enum structure * return -EINVAL or zero on success */ static int csi2_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { … } static int csi2_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { … } /* * csi2_get_format - Handle get format by pads subdev method * @sd : pointer to v4l2 subdev structure * @sd_state: V4L2 subdev state * @fmt: pointer to v4l2 subdev format structure * return -EINVAL or zero on success */ static int csi2_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { … } /* * csi2_set_format - Handle set format by pads subdev method * @sd : pointer to v4l2 subdev structure * @sd_state: V4L2 subdev state * @fmt: pointer to v4l2 subdev format structure * return -EINVAL or zero on success */ static int csi2_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { … } static int csi2_link_validate(struct v4l2_subdev *sd, struct media_link *link, struct v4l2_subdev_format *source_fmt, struct v4l2_subdev_format *sink_fmt) { … } /* * csi2_init_formats - Initialize formats on all pads * @sd: ISS CSI2 V4L2 subdevice * @fh: V4L2 subdev file handle * * Initialize all pad formats with default values. If fh is not NULL, try * formats are initialized on the file handle. Otherwise active formats are * initialized on the device. */ static int csi2_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { … } /* * csi2_set_stream - Enable/Disable streaming on the CSI2 module * @sd: ISS CSI2 V4L2 subdevice * @enable: ISS pipeline stream state * * Return 0 on success or a negative error code otherwise. */ static int csi2_set_stream(struct v4l2_subdev *sd, int enable) { … } /* subdev video operations */ static const struct v4l2_subdev_video_ops csi2_video_ops = …; /* subdev pad operations */ static const struct v4l2_subdev_pad_ops csi2_pad_ops = …; /* subdev operations */ static const struct v4l2_subdev_ops csi2_ops = …; /* subdev internal operations */ static const struct v4l2_subdev_internal_ops csi2_internal_ops = …; /* ----------------------------------------------------------------------------- * Media entity operations */ /* * csi2_link_setup - Setup CSI2 connections. * @entity : Pointer to media entity structure * @local : Pointer to local pad array * @remote : Pointer to remote pad array * @flags : Link flags * return -EINVAL or zero on success */ static int csi2_link_setup(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags) { … } /* media operations */ static const struct media_entity_operations csi2_media_ops = …; void omap4iss_csi2_unregister_entities(struct iss_csi2_device *csi2) { … } int omap4iss_csi2_register_entities(struct iss_csi2_device *csi2, struct v4l2_device *vdev) { … } /* ----------------------------------------------------------------------------- * ISS CSI2 initialisation and cleanup */ /* * csi2_init_entities - Initialize subdev and media entity. * @csi2: Pointer to csi2 structure. * return -ENOMEM or zero on success */ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname) { … } /* * omap4iss_csi2_init - Routine for module driver init */ int omap4iss_csi2_init(struct iss_device *iss) { … } /* * omap4iss_csi2_create_links() - CSI2 pads links creation * @iss: Pointer to ISS device * * return negative error code or zero on success */ int omap4iss_csi2_create_links(struct iss_device *iss) { … } /* * omap4iss_csi2_cleanup - Routine for module driver cleanup */ void omap4iss_csi2_cleanup(struct iss_device *iss) { … }