diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_api.h b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_api.h index e7ef7ec02b02..b9d2ca535644 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_api.h +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_api.h @@ -13,6 +13,7 @@ #include #include +#include "maxim2c_compact.h" #include "maxim2c_i2c.h" #include "maxim2c_link.h" #include "maxim2c_video_pipe.h" diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_compact.h b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_compact.h new file mode 100644 index 000000000000..45a9e272c31b --- /dev/null +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_compact.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Rockchip Electronics Co., Ltd. + * + */ +#ifndef __MAXIM2C_COMPACT_H__ +#define __MAXIM2C_COMPACT_H__ + +#include + +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE +enum rkmodule_pad_type { + PAD0, + PAD1, + PAD2, + PAD3, + PAD_MAX, +}; + +#ifndef fallthrough +#define fallthrough +#endif + +#ifndef read_poll_timeout +#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, \ + sleep_before_read, args...) \ +{ \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + might_sleep_if((__sleep_us) != 0); \ + if (sleep_before_read && __sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + for (;;) { \ + (val) = op(args); \ + if (cond) \ + break; \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ + (val) = op(args); \ + break; \ + } \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + cpu_relax(); \ + } \ + (cond) ? 0 : -ETIMEDOUT; \ +} +#endif /* read_poll_timeout */ +#endif /* LINUX_VERSION_CODE */ + +#endif /* __MAXIM2C_COMPACT_H__ */ diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.c b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.c index 1a86997423db..fa35f8915abd 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.c +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_drv.c @@ -24,6 +24,10 @@ * 2. remote serializer is abstracted as v4l2 subdev * 3. remote camera is bound to remote serializer * + * V3.01.00 + * 1. fixed remote camera s_stream and s_power api return error. + * 2. compatible with kernel v4.19/v5.10/v6.1 + * */ #include #include @@ -51,7 +55,7 @@ #include "maxim2c_api.h" -#define DRIVER_VERSION KERNEL_VERSION(3, 0x00, 0x00) +#define DRIVER_VERSION KERNEL_VERSION(3, 0x01, 0x00) #define MAXIM2C_XVCLK_FREQ 25000000 @@ -725,7 +729,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int maxim2c_remove(struct i2c_client *client) +#else +static void maxim2c_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); @@ -742,8 +750,9 @@ static int maxim2c_remove(struct i2c_client *client) if (!pm_runtime_status_suspended(&client->dev)) maxim2c_device_power_off(maxim2c); pm_runtime_set_suspended(&client->dev); - +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id maxim2c_of_match[] = { diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c index 22cabb854475..8bbf1ae8cee6 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_pattern.c @@ -36,7 +36,11 @@ static const struct maxim2c_mode maxim2c_pattern_mode = { .link_freq_idx = 24, .bus_fmt = MEDIA_BUS_FMT_RGB888_1X24, .bpp = 24, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + .vc[PAD0] = 0, +#else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, +#endif }; int maxim2c_pattern_enable(maxim2c_t *maxim2c, bool enable) diff --git a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c index 45797000fd06..49c499453eaf 100644 --- a/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c +++ b/drivers/media/i2c/maxim/local/maxim2c/maxim2c_v4l2.c @@ -66,10 +66,17 @@ static const struct maxim2c_mode maxim2c_def_mode = { .link_freq_idx = 15, .bus_fmt = MEDIA_BUS_FMT_UYVY8_2X8, .bpp = 16, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + .vc[PAD0] = 0, + .vc[PAD1] = 1, + .vc[PAD2] = 2, + .vc[PAD3] = 3, +#else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_1, .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_2, .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_3, +#endif /* LINUX_VERSION_CODE */ }; static struct rkmodule_csi_dphy_param rk3588_dcphy_param = { @@ -212,8 +219,13 @@ static int maxim2c_support_mode_init(maxim2c_t *maxim2c) static int maxim2c_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct maxim2c_mode *def_mode = &maxim2c->supported_mode; mutex_lock(&maxim2c->mutex); @@ -598,7 +610,11 @@ static int maxim2c_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; if (on) { +#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE ret = pm_runtime_resume_and_get(&client->dev); +#else + ret = pm_runtime_get_sync(&client->dev); +#endif if (ret < 0) goto unlock_and_return; @@ -635,9 +651,15 @@ static int maxim2c_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int maxim2c_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); const struct maxim2c_mode *mode = maxim2c->cur_mode; @@ -649,9 +671,15 @@ static int maxim2c_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int maxim2c_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); @@ -669,10 +697,15 @@ static int maxim2c_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } -static int -maxim2c_enum_frame_interval(struct v4l2_subdev *sd, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else +static int maxim2c_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); @@ -687,9 +720,15 @@ maxim2c_enum_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int maxim2c_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); const struct maxim2c_mode *mode = maxim2c->cur_mode; @@ -697,7 +736,11 @@ static int maxim2c_get_fmt(struct v4l2_subdev *sd, mutex_lock(&maxim2c->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&maxim2c->mutex); return -ENOTTY; @@ -717,9 +760,15 @@ static int maxim2c_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int maxim2c_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); struct device *dev = &maxim2c->client->dev; @@ -737,7 +786,11 @@ static int maxim2c_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&maxim2c->mutex); return -ENOTTY; @@ -769,9 +822,15 @@ static int maxim2c_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int maxim2c_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); @@ -786,6 +845,18 @@ static int maxim2c_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim2c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct maxim2c *maxim2c = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = maxim2c->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int maxim2c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -804,6 +875,26 @@ static int maxim2c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int maxim2c_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + maxim2c_t *maxim2c = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = maxim2c->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops maxim2c_internal_ops = { @@ -822,6 +913,9 @@ static const struct v4l2_subdev_core_ops maxim2c_core_ops = { static const struct v4l2_subdev_video_ops maxim2c_video_ops = { .s_stream = maxim2c_s_stream, .g_frame_interval = maxim2c_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = maxim2c_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops maxim2c_pad_ops = { @@ -831,7 +925,9 @@ static const struct v4l2_subdev_pad_ops maxim2c_pad_ops = { .get_fmt = maxim2c_get_fmt, .set_fmt = maxim2c_set_fmt, .get_selection = maxim2c_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = maxim2c_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops maxim2c_subdev_ops = { @@ -960,7 +1056,11 @@ int maxim2c_v4l2_subdev_init(maxim2c_t *maxim2c) maxim2c->module_index, facing, MAXIM2C_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_api.h b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_api.h index 8d7505449b6a..31a1fc6b20c6 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_api.h +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_api.h @@ -13,6 +13,7 @@ #include #include +#include "maxim4c_compact.h" #include "maxim4c_i2c.h" #include "maxim4c_link.h" #include "maxim4c_video_pipe.h" diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_compact.h b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_compact.h new file mode 100644 index 000000000000..18654290518b --- /dev/null +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_compact.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Rockchip Electronics Co., Ltd. + * + */ +#ifndef __MAXIM4C_COMPACT_H__ +#define __MAXIM4C_COMPACT_H__ + +#include + +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE +enum rkmodule_pad_type { + PAD0, + PAD1, + PAD2, + PAD3, + PAD_MAX, +}; + +#ifndef fallthrough +#define fallthrough +#endif + +#ifndef read_poll_timeout +#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, \ + sleep_before_read, args...) \ +({ \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + might_sleep_if((__sleep_us) != 0); \ + if (sleep_before_read && __sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + for (;;) { \ + (val) = op(args); \ + if (cond) \ + break; \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ + (val) = op(args); \ + break; \ + } \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_us); \ + cpu_relax(); \ + } \ + (cond) ? 0 : -ETIMEDOUT; \ +}) +#endif /* read_poll_timeout */ +#endif /* LINUX_VERSION_CODE */ + +#endif /* __MAXIM4C_COMPACT_H__ */ diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.c b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.c index ca8ee9a1366c..fceea4605700 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.c +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_drv.c @@ -47,6 +47,10 @@ * 2. remote serializer is abstracted as v4l2 subdev * 3. remote camera is bound to remote serializer * + * V3.01.00 + * 1. fixed remote camera s_stream and s_power api return error. + * 2. compatible with kernel v4.19/v5.10/v6.1 + * */ #include #include @@ -74,7 +78,7 @@ #include "maxim4c_api.h" -#define DRIVER_VERSION KERNEL_VERSION(3, 0x00, 0x00) +#define DRIVER_VERSION KERNEL_VERSION(3, 0x01, 0x00) #define MAXIM4C_XVCLK_FREQ 25000000 @@ -799,7 +803,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int maxim4c_remove(struct i2c_client *client) +#else +static void maxim4c_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); @@ -818,8 +826,9 @@ static int maxim4c_remove(struct i2c_client *client) if (!pm_runtime_status_suspended(&client->dev)) maxim4c_device_power_off(maxim4c); pm_runtime_set_suspended(&client->dev); - +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id maxim4c_of_match[] = { diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c index d59e077efa3b..25400b074245 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_pattern.c @@ -42,7 +42,11 @@ static const struct maxim4c_mode maxim4c_pattern_mode = { .link_freq_idx = 15, .bus_fmt = MEDIA_BUS_FMT_RGB888_1X24, .bpp = 24, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + .vc[PAD0] = 0, +#else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, +#endif }; /* VPG0 or VPG1 register */ diff --git a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c index f9c797829dc7..20f755e0e241 100644 --- a/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c +++ b/drivers/media/i2c/maxim/local/maxim4c/maxim4c_v4l2.c @@ -66,10 +66,17 @@ static const struct maxim4c_mode maxim4c_def_mode = { .link_freq_idx = 15, .bus_fmt = MEDIA_BUS_FMT_UYVY8_2X8, .bpp = 16, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + .vc[PAD0] = 0, + .vc[PAD1] = 1, + .vc[PAD2] = 2, + .vc[PAD3] = 3, +#else .vc[PAD0] = V4L2_MBUS_CSI2_CHANNEL_0, .vc[PAD1] = V4L2_MBUS_CSI2_CHANNEL_1, .vc[PAD2] = V4L2_MBUS_CSI2_CHANNEL_2, .vc[PAD3] = V4L2_MBUS_CSI2_CHANNEL_3, +#endif /* LINUX_VERSION_CODE */ }; static struct rkmodule_csi_dphy_param rk3588_dcphy_param = { @@ -212,8 +219,13 @@ static int maxim4c_support_mode_init(maxim4c_t *maxim4c) static int maxim4c_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct maxim4c_mode *def_mode = &maxim4c->supported_mode; mutex_lock(&maxim4c->mutex); @@ -598,7 +610,11 @@ static int maxim4c_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; if (on) { +#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE ret = pm_runtime_resume_and_get(&client->dev); +#else + ret = pm_runtime_get_sync(&client->dev); +#endif if (ret < 0) goto unlock_and_return; @@ -635,9 +651,15 @@ static int maxim4c_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int maxim4c_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); const struct maxim4c_mode *mode = maxim4c->cur_mode; @@ -649,9 +671,15 @@ static int maxim4c_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int maxim4c_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); @@ -669,10 +697,15 @@ static int maxim4c_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } -static int -maxim4c_enum_frame_interval(struct v4l2_subdev *sd, +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else +static int maxim4c_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); @@ -687,9 +720,15 @@ maxim4c_enum_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int maxim4c_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); const struct maxim4c_mode *mode = maxim4c->cur_mode; @@ -697,7 +736,11 @@ static int maxim4c_get_fmt(struct v4l2_subdev *sd, mutex_lock(&maxim4c->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&maxim4c->mutex); return -ENOTTY; @@ -717,9 +760,15 @@ static int maxim4c_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int maxim4c_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); struct device *dev = &maxim4c->client->dev; @@ -737,7 +786,11 @@ static int maxim4c_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&maxim4c->mutex); return -ENOTTY; @@ -769,9 +822,15 @@ static int maxim4c_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int maxim4c_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); @@ -786,6 +845,18 @@ static int maxim4c_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int maxim4c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct maxim4c *maxim4c = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = maxim4c->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int maxim4c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -804,6 +875,26 @@ static int maxim4c_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int maxim4c_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + maxim4c_t *maxim4c = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = maxim4c->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops maxim4c_internal_ops = { @@ -822,6 +913,9 @@ static const struct v4l2_subdev_core_ops maxim4c_core_ops = { static const struct v4l2_subdev_video_ops maxim4c_video_ops = { .s_stream = maxim4c_s_stream, .g_frame_interval = maxim4c_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = maxim4c_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops maxim4c_pad_ops = { @@ -831,7 +925,9 @@ static const struct v4l2_subdev_pad_ops maxim4c_pad_ops = { .get_fmt = maxim4c_get_fmt, .set_fmt = maxim4c_set_fmt, .get_selection = maxim4c_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = maxim4c_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops maxim4c_subdev_ops = { @@ -960,7 +1056,11 @@ int maxim4c_v4l2_subdev_init(maxim4c_t *maxim4c) maxim4c->module_index, facing, MAXIM4C_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; diff --git a/drivers/media/i2c/maxim/remote/max9295.c b/drivers/media/i2c/maxim/remote/max9295.c index f688ddbd29a3..9501dfc88d5d 100644 --- a/drivers/media/i2c/maxim/remote/max9295.c +++ b/drivers/media/i2c/maxim/remote/max9295.c @@ -16,7 +16,7 @@ #include "maxim_remote.h" -#define DRIVER_VERSION KERNEL_VERSION(3, 0x00, 0x00) +#define DRIVER_VERSION KERNEL_VERSION(3, 0x01, 0x00) #define MAX9295_NAME "max9295" @@ -527,13 +527,19 @@ static int max9295_probe(struct i2c_client *client, return 0; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int max9295_remove(struct i2c_client *client) +#else +static void max9295_remove(struct i2c_client *client) +#endif { maxim_remote_ser_t *max9295 = i2c_get_clientdata(client); mutex_destroy(&max9295->mutex); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id max9295_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/max96715.c b/drivers/media/i2c/maxim/remote/max96715.c index d468d2947983..fc6a6cf0ddbf 100644 --- a/drivers/media/i2c/maxim/remote/max96715.c +++ b/drivers/media/i2c/maxim/remote/max96715.c @@ -16,7 +16,7 @@ #include "maxim_remote.h" -#define DRIVER_VERSION KERNEL_VERSION(3, 0x00, 0x00) +#define DRIVER_VERSION KERNEL_VERSION(3, 0x01, 0x00) #define MAX96715_NAME "max96715" @@ -528,13 +528,19 @@ static int max96715_probe(struct i2c_client *client, return 0; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int max96715_remove(struct i2c_client *client) +#else +static void max96715_remove(struct i2c_client *client) +#endif { maxim_remote_ser_t *max96715 = i2c_get_clientdata(client); mutex_destroy(&max96715->mutex); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id max96715_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/max96717.c b/drivers/media/i2c/maxim/remote/max96717.c index d45e2b0acbc9..c2a19887ea37 100644 --- a/drivers/media/i2c/maxim/remote/max96717.c +++ b/drivers/media/i2c/maxim/remote/max96717.c @@ -16,7 +16,7 @@ #include "maxim_remote.h" -#define DRIVER_VERSION KERNEL_VERSION(3, 0x00, 0x00) +#define DRIVER_VERSION KERNEL_VERSION(3, 0x01, 0x00) #define MAX96717_NAME "maxim-max96717" @@ -477,13 +477,19 @@ static int max96717_probe(struct i2c_client *client, return 0; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int max96717_remove(struct i2c_client *client) +#else +static void max96717_remove(struct i2c_client *client) +#endif { maxim_remote_ser_t *max96717 = i2c_get_clientdata(client); mutex_destroy(&max96717->mutex); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id max96717_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/maxim_remote.h b/drivers/media/i2c/maxim/remote/maxim_remote.h index 0fa29acf9f00..8a79df354ed1 100644 --- a/drivers/media/i2c/maxim/remote/maxim_remote.h +++ b/drivers/media/i2c/maxim/remote/maxim_remote.h @@ -9,6 +9,21 @@ #include #include +#include + +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE +enum rkmodule_pad_type { + PAD0, + PAD1, + PAD2, + PAD3, + PAD_MAX, +}; + +#ifndef fallthrough +#define fallthrough +#endif +#endif /* LINUX_VERSION_CODE */ /* I2C Device ID */ enum { diff --git a/drivers/media/i2c/maxim/remote/ov231x.c b/drivers/media/i2c/maxim/remote/ov231x.c index 2e28c9cd8061..9309be42ebc0 100644 --- a/drivers/media/i2c/maxim/remote/ov231x.c +++ b/drivers/media/i2c/maxim/remote/ov231x.c @@ -291,8 +291,13 @@ static const struct dev_pm_ops ov231x_pm_ops = { static int ov231x_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct ov231x *ov231x = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct ov231x_mode *def_mode = &ov231x->supported_modes[0]; mutex_lock(&ov231x->mutex); @@ -582,9 +587,15 @@ static int ov231x_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int ov231x_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); @@ -595,9 +606,15 @@ static int ov231x_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int ov231x_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); @@ -615,9 +632,15 @@ static int ov231x_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else static int ov231x_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); @@ -660,9 +683,15 @@ ov231x_find_best_fit(struct ov231x *ov231x, struct v4l2_subdev_format *fmt) return &ov231x->supported_modes[cur_best_fit]; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE static int ov231x_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else +static int ov231x_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); struct device *dev = &ov231x->client->dev; @@ -679,7 +708,11 @@ static int ov231x_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&ov231x->mutex); return -ENOTTY; @@ -705,9 +738,15 @@ static int ov231x_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int ov231x_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); const struct ov231x_mode *mode = ov231x->cur_mode; @@ -715,7 +754,11 @@ static int ov231x_get_fmt(struct v4l2_subdev *sd, mutex_lock(&ov231x->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&ov231x->mutex); return -ENOTTY; @@ -731,9 +774,15 @@ static int ov231x_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int ov231x_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { struct ov231x *ov231x = v4l2_get_subdevdata(sd); @@ -748,6 +797,18 @@ static int ov231x_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ov231x_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct ov231x *ov231x = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = ov231x->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int ov231x_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -766,6 +827,26 @@ static int ov231x_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int ov231x_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + struct ov231x *ov231x = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = ov231x->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops ov231x_internal_ops = { @@ -784,6 +865,9 @@ static const struct v4l2_subdev_core_ops ov231x_core_ops = { static const struct v4l2_subdev_video_ops ov231x_video_ops = { .s_stream = ov231x_s_stream, .g_frame_interval = ov231x_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = ov231x_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops ov231x_pad_ops = { @@ -793,7 +877,9 @@ static const struct v4l2_subdev_pad_ops ov231x_pad_ops = { .get_fmt = ov231x_get_fmt, .set_fmt = ov231x_set_fmt, .get_selection = ov231x_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = ov231x_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops ov231x_subdev_ops = { @@ -998,7 +1084,11 @@ static int ov231x_probe(struct i2c_client *client, ov231x->module_index, facing, OV231X_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; @@ -1046,7 +1136,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int ov231x_remove(struct i2c_client *client) +#else +static void ov231x_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ov231x *ov231x = v4l2_get_subdevdata(sd); @@ -1065,7 +1159,9 @@ static int ov231x_remove(struct i2c_client *client) __ov231x_power_off(ov231x); pm_runtime_set_suspended(&client->dev); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id ov231x_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/ox01f10.c b/drivers/media/i2c/maxim/remote/ox01f10.c index 74c0a7a69d36..01fe29f20665 100644 --- a/drivers/media/i2c/maxim/remote/ox01f10.c +++ b/drivers/media/i2c/maxim/remote/ox01f10.c @@ -291,8 +291,13 @@ static const struct dev_pm_ops ox01f10_pm_ops = { static int ox01f10_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct ox01f10_mode *def_mode = &ox01f10->supported_modes[0]; mutex_lock(&ox01f10->mutex); @@ -582,9 +587,15 @@ static int ox01f10_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int ox01f10_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); @@ -595,9 +606,15 @@ static int ox01f10_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int ox01f10_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); @@ -615,9 +632,15 @@ static int ox01f10_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else static int ox01f10_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); @@ -660,9 +683,15 @@ ox01f10_find_best_fit(struct ox01f10 *ox01f10, struct v4l2_subdev_format *fmt) return &ox01f10->supported_modes[cur_best_fit]; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE static int ox01f10_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else +static int ox01f10_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); struct device *dev = &ox01f10->client->dev; @@ -679,7 +708,11 @@ static int ox01f10_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&ox01f10->mutex); return -ENOTTY; @@ -705,9 +738,15 @@ static int ox01f10_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int ox01f10_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); const struct ox01f10_mode *mode = ox01f10->cur_mode; @@ -715,7 +754,11 @@ static int ox01f10_get_fmt(struct v4l2_subdev *sd, mutex_lock(&ox01f10->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&ox01f10->mutex); return -ENOTTY; @@ -731,9 +774,15 @@ static int ox01f10_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int ox01f10_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); @@ -748,6 +797,18 @@ static int ox01f10_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox01f10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = ox01f10->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int ox01f10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -766,6 +827,26 @@ static int ox01f10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int ox01f10_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = ox01f10->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops ox01f10_internal_ops = { @@ -784,6 +865,9 @@ static const struct v4l2_subdev_core_ops ox01f10_core_ops = { static const struct v4l2_subdev_video_ops ox01f10_video_ops = { .s_stream = ox01f10_s_stream, .g_frame_interval = ox01f10_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = ox01f10_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops ox01f10_pad_ops = { @@ -793,7 +877,9 @@ static const struct v4l2_subdev_pad_ops ox01f10_pad_ops = { .get_fmt = ox01f10_get_fmt, .set_fmt = ox01f10_set_fmt, .get_selection = ox01f10_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = ox01f10_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops ox01f10_subdev_ops = { @@ -998,7 +1084,11 @@ static int ox01f10_probe(struct i2c_client *client, ox01f10->module_index, facing, OX01F10_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; @@ -1046,7 +1136,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int ox01f10_remove(struct i2c_client *client) +#else +static void ox01f10_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ox01f10 *ox01f10 = v4l2_get_subdevdata(sd); @@ -1065,7 +1159,9 @@ static int ox01f10_remove(struct i2c_client *client) __ox01f10_power_off(ox01f10); pm_runtime_set_suspended(&client->dev); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id ox01f10_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/ox03j10.c b/drivers/media/i2c/maxim/remote/ox03j10.c index 750e691029cf..7f5a742c3fda 100644 --- a/drivers/media/i2c/maxim/remote/ox03j10.c +++ b/drivers/media/i2c/maxim/remote/ox03j10.c @@ -291,8 +291,13 @@ static const struct dev_pm_ops ox03j10_pm_ops = { static int ox03j10_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct ox03j10_mode *def_mode = &ox03j10->supported_modes[0]; mutex_lock(&ox03j10->mutex); @@ -582,9 +587,15 @@ static int ox03j10_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int ox03j10_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); @@ -595,9 +606,15 @@ static int ox03j10_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int ox03j10_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); @@ -615,9 +632,15 @@ static int ox03j10_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else static int ox03j10_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); @@ -660,9 +683,15 @@ ox03j10_find_best_fit(struct ox03j10 *ox03j10, struct v4l2_subdev_format *fmt) return &ox03j10->supported_modes[cur_best_fit]; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE static int ox03j10_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else +static int ox03j10_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); struct device *dev = &ox03j10->client->dev; @@ -679,7 +708,11 @@ static int ox03j10_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&ox03j10->mutex); return -ENOTTY; @@ -705,9 +738,15 @@ static int ox03j10_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int ox03j10_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); const struct ox03j10_mode *mode = ox03j10->cur_mode; @@ -715,7 +754,11 @@ static int ox03j10_get_fmt(struct v4l2_subdev *sd, mutex_lock(&ox03j10->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&ox03j10->mutex); return -ENOTTY; @@ -731,9 +774,15 @@ static int ox03j10_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int ox03j10_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); @@ -748,6 +797,18 @@ static int ox03j10_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int ox03j10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = ox03j10->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int ox03j10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -766,6 +827,26 @@ static int ox03j10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int ox03j10_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = ox03j10->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops ox03j10_internal_ops = { @@ -784,6 +865,9 @@ static const struct v4l2_subdev_core_ops ox03j10_core_ops = { static const struct v4l2_subdev_video_ops ox03j10_video_ops = { .s_stream = ox03j10_s_stream, .g_frame_interval = ox03j10_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = ox03j10_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops ox03j10_pad_ops = { @@ -793,7 +877,9 @@ static const struct v4l2_subdev_pad_ops ox03j10_pad_ops = { .get_fmt = ox03j10_get_fmt, .set_fmt = ox03j10_set_fmt, .get_selection = ox03j10_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = ox03j10_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops ox03j10_subdev_ops = { @@ -998,7 +1084,11 @@ static int ox03j10_probe(struct i2c_client *client, ox03j10->module_index, facing, OX03J10_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; @@ -1046,7 +1136,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int ox03j10_remove(struct i2c_client *client) +#else +static void ox03j10_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ox03j10 *ox03j10 = v4l2_get_subdevdata(sd); @@ -1065,7 +1159,9 @@ static int ox03j10_remove(struct i2c_client *client) __ox03j10_power_off(ox03j10); pm_runtime_set_suspended(&client->dev); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id ox03j10_of_match[] = { diff --git a/drivers/media/i2c/maxim/remote/sc320at.c b/drivers/media/i2c/maxim/remote/sc320at.c index 2247d27454e6..0d051278647c 100644 --- a/drivers/media/i2c/maxim/remote/sc320at.c +++ b/drivers/media/i2c/maxim/remote/sc320at.c @@ -291,8 +291,13 @@ static const struct dev_pm_ops sc320at_pm_ops = { static int sc320at_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct sc320at *sc320at = v4l2_get_subdevdata(sd); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->state, 0); +#else struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd, fh->pad, 0); +#endif const struct sc320at_mode *def_mode = &sc320at->supported_modes[0]; mutex_lock(&sc320at->mutex); @@ -582,9 +587,15 @@ static int sc320at_g_frame_interval(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +#else static int sc320at_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); @@ -595,9 +606,15 @@ static int sc320at_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_enum_frame_sizes(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_size_enum *fse) +#else static int sc320at_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); @@ -615,9 +632,15 @@ static int sc320at_enum_frame_sizes(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +#else static int sc320at_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_interval_enum *fie) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); @@ -660,9 +683,15 @@ sc320at_find_best_fit(struct sc320at *sc320at, struct v4l2_subdev_format *fmt) return &sc320at->supported_modes[cur_best_fit]; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE static int sc320at_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else +static int sc320at_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); struct device *dev = &sc320at->client->dev; @@ -679,7 +708,11 @@ static int sc320at_set_fmt(struct v4l2_subdev *sd, fmt->format.field = V4L2_FIELD_NONE; if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format; + #else *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; + #endif #else mutex_unlock(&sc320at->mutex); return -ENOTTY; @@ -705,9 +738,15 @@ static int sc320at_set_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +#else static int sc320at_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); const struct sc320at_mode *mode = sc320at->cur_mode; @@ -715,7 +754,11 @@ static int sc320at_get_fmt(struct v4l2_subdev *sd, mutex_lock(&sc320at->mutex); if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + fmt->format = *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); + #else fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); + #endif #else mutex_unlock(&sc320at->mutex); return -ENOTTY; @@ -731,9 +774,15 @@ static int sc320at_get_fmt(struct v4l2_subdev *sd, return 0; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +#else static int sc320at_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) +#endif { struct sc320at *sc320at = v4l2_get_subdevdata(sd); @@ -748,6 +797,18 @@ static int sc320at_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +static int sc320at_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, + struct v4l2_mbus_config *config) +{ + struct sc320at *sc320at = v4l2_get_subdevdata(sd); + + config->type = V4L2_MBUS_CSI2_DPHY; + config->bus.mipi_csi2 = sc320at->bus_cfg.bus.mipi_csi2; + + return 0; +} +#elif KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE static int sc320at_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, struct v4l2_mbus_config *config) { @@ -766,6 +827,26 @@ static int sc320at_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, return 0; } +#else +static int sc320at_g_mbus_config(struct v4l2_subdev *sd, + struct v4l2_mbus_config *config) +{ + struct sc320at *sc320at = v4l2_get_subdevdata(sd); + u32 val = 0; + u8 data_lanes = sc320at->bus_cfg.bus.mipi_csi2.num_data_lanes; + + val |= V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; + val |= (1 << (data_lanes - 1)); + + val |= V4L2_MBUS_CSI2_CHANNEL_3 | V4L2_MBUS_CSI2_CHANNEL_2 | + V4L2_MBUS_CSI2_CHANNEL_1 | V4L2_MBUS_CSI2_CHANNEL_0; + + config->type = V4L2_MBUS_CSI2; + config->flags = val; + + return 0; +} +#endif /* LINUX_VERSION_CODE */ #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API static const struct v4l2_subdev_internal_ops sc320at_internal_ops = { @@ -784,6 +865,9 @@ static const struct v4l2_subdev_core_ops sc320at_core_ops = { static const struct v4l2_subdev_video_ops sc320at_video_ops = { .s_stream = sc320at_s_stream, .g_frame_interval = sc320at_g_frame_interval, +#if KERNEL_VERSION(5, 10, 0) > LINUX_VERSION_CODE + .g_mbus_config = sc320at_g_mbus_config, +#endif }; static const struct v4l2_subdev_pad_ops sc320at_pad_ops = { @@ -793,7 +877,9 @@ static const struct v4l2_subdev_pad_ops sc320at_pad_ops = { .get_fmt = sc320at_get_fmt, .set_fmt = sc320at_set_fmt, .get_selection = sc320at_get_selection, +#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE .get_mbus_config = sc320at_g_mbus_config, +#endif }; static const struct v4l2_subdev_ops sc320at_subdev_ops = { @@ -998,7 +1084,11 @@ static int sc320at_probe(struct i2c_client *client, sc320at->module_index, facing, SC320AT_NAME, dev_name(sd->dev)); +#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE + ret = v4l2_async_register_subdev_sensor(sd); +#else ret = v4l2_async_register_subdev_sensor_common(sd); +#endif if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_entity; @@ -1046,7 +1136,11 @@ err_destroy_mutex: return ret; } +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE static int sc320at_remove(struct i2c_client *client) +#else +static void sc320at_remove(struct i2c_client *client) +#endif { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct sc320at *sc320at = v4l2_get_subdevdata(sd); @@ -1065,7 +1159,9 @@ static int sc320at_remove(struct i2c_client *client) __sc320at_power_off(sc320at); pm_runtime_set_suspended(&client->dev); +#if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE return 0; +#endif } static const struct of_device_id sc320at_of_match[] = {