// SPDX-License-Identifier: GPL-2.0 /* * camss-csiphy.c * * Qualcomm MSM Camera Subsystem - CSIPHY Module * * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * Copyright (C) 2016-2018 Linaro Ltd. */ #include <linux/clk.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <media/media-entity.h> #include <media/v4l2-device.h> #include <media/v4l2-subdev.h> #include "camss-csiphy.h" #include "camss.h" #define MSM_CSIPHY_NAME … static const struct csiphy_format_info formats_8x16[] = …; static const struct csiphy_format_info formats_8x96[] = …; static const struct csiphy_format_info formats_sdm845[] = …; const struct csiphy_formats csiphy_formats_8x16 = …; const struct csiphy_formats csiphy_formats_8x96 = …; const struct csiphy_formats csiphy_formats_sdm845 = …; /* * csiphy_get_bpp - map media bus format to bits per pixel * @formats: supported media bus formats array * @nformats: size of @formats array * @code: media bus format code * * Return number of bits per pixel */ static u8 csiphy_get_bpp(const struct csiphy_format_info *formats, unsigned int nformats, u32 code) { … } /* * csiphy_set_clock_rates - Calculate and set clock rates on CSIPHY module * @csiphy: CSIPHY device */ static int csiphy_set_clock_rates(struct csiphy_device *csiphy) { … } /* * csiphy_set_power - Power on/off CSIPHY module * @sd: CSIPHY V4L2 subdevice * @on: Requested power state * * Return 0 on success or a negative error code otherwise */ static int csiphy_set_power(struct v4l2_subdev *sd, int on) { … } /* * csiphy_stream_on - Enable streaming on CSIPHY module * @csiphy: CSIPHY device * * Helper function to enable streaming on CSIPHY module. * Main configuration of CSIPHY module is also done here. * * Return 0 on success or a negative error code otherwise */ static int csiphy_stream_on(struct csiphy_device *csiphy) { … } /* * csiphy_stream_off - Disable streaming on CSIPHY module * @csiphy: CSIPHY device * * Helper function to disable streaming on CSIPHY module */ static void csiphy_stream_off(struct csiphy_device *csiphy) { … } /* * csiphy_set_stream - Enable/disable streaming on CSIPHY module * @sd: CSIPHY V4L2 subdevice * @enable: Requested streaming state * * Return 0 on success or a negative error code otherwise */ static int csiphy_set_stream(struct v4l2_subdev *sd, int enable) { … } /* * __csiphy_get_format - Get pointer to format structure * @csiphy: CSIPHY device * @sd_state: V4L2 subdev state * @pad: pad from which format is requested * @which: TRY or ACTIVE format * * Return pointer to TRY or ACTIVE format structure */ static struct v4l2_mbus_framefmt * __csiphy_get_format(struct csiphy_device *csiphy, struct v4l2_subdev_state *sd_state, unsigned int pad, enum v4l2_subdev_format_whence which) { … } /* * csiphy_try_format - Handle try format by pad subdev method * @csiphy: CSIPHY device * @sd_state: V4L2 subdev state * @pad: pad on which format is requested * @fmt: pointer to v4l2 format structure * @which: wanted subdev format */ static void csiphy_try_format(struct csiphy_device *csiphy, struct v4l2_subdev_state *sd_state, unsigned int pad, struct v4l2_mbus_framefmt *fmt, enum v4l2_subdev_format_whence which) { … } /* * csiphy_enum_mbus_code - Handle pixel format enumeration * @sd: CSIPHY V4L2 subdevice * @sd_state: V4L2 subdev state * @code: pointer to v4l2_subdev_mbus_code_enum structure * return -EINVAL or zero on success */ static int csiphy_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { … } /* * csiphy_enum_frame_size - Handle frame size enumeration * @sd: CSIPHY V4L2 subdevice * @sd_state: V4L2 subdev state * @fse: pointer to v4l2_subdev_frame_size_enum structure * return -EINVAL or zero on success */ static int csiphy_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { … } /* * csiphy_get_format - Handle get format by pads subdev method * @sd: CSIPHY V4L2 subdevice * @sd_state: V4L2 subdev state * @fmt: pointer to v4l2 subdev format structure * * Return -EINVAL or zero on success */ static int csiphy_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { … } /* * csiphy_set_format - Handle set format by pads subdev method * @sd: CSIPHY V4L2 subdevice * @sd_state: V4L2 subdev state * @fmt: pointer to v4l2 subdev format structure * * Return -EINVAL or zero on success */ static int csiphy_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { … } /* * csiphy_init_formats - Initialize formats on all pads * @sd: CSIPHY V4L2 subdevice * @fh: V4L2 subdev file handle * * Initialize all pad formats with default values. * * Return 0 on success or a negative error code otherwise */ static int csiphy_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { … } static bool csiphy_match_clock_name(const char *clock_name, const char *format, int index) { … } /* * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resources * @csiphy: CSIPHY device * @res: CSIPHY module resources table * @id: CSIPHY module id * * Return 0 on success or a negative error code otherwise */ int msm_csiphy_subdev_init(struct camss *camss, struct csiphy_device *csiphy, const struct camss_subdev_resources *res, u8 id) { … } /* * csiphy_link_setup - Setup CSIPHY connections * @entity: Pointer to media entity structure * @local: Pointer to local pad * @remote: Pointer to remote pad * @flags: Link flags * * Rreturn 0 on success */ static int csiphy_link_setup(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags) { … } static const struct v4l2_subdev_core_ops csiphy_core_ops = …; static const struct v4l2_subdev_video_ops csiphy_video_ops = …; static const struct v4l2_subdev_pad_ops csiphy_pad_ops = …; static const struct v4l2_subdev_ops csiphy_v4l2_ops = …; static const struct v4l2_subdev_internal_ops csiphy_v4l2_internal_ops = …; static const struct media_entity_operations csiphy_media_ops = …; /* * msm_csiphy_register_entity - Register subdev node for CSIPHY module * @csiphy: CSIPHY device * @v4l2_dev: V4L2 device * * Return 0 on success or a negative error code otherwise */ int msm_csiphy_register_entity(struct csiphy_device *csiphy, struct v4l2_device *v4l2_dev) { … } /* * msm_csiphy_unregister_entity - Unregister CSIPHY module subdev node * @csiphy: CSIPHY device */ void msm_csiphy_unregister_entity(struct csiphy_device *csiphy) { … }