提交 8f66650c 编写于 作者: D Dave Stevenson 提交者: Zheng Zengkai

media: i2c: ov9281: Fixup for recent kernel releases, and remove custom code

raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------

The Rockchip driver was based on a 4.4 kernel, and had several custom
Rockchip parts.

Update to 5.4 kernel APIs, with the relevant controls required by
libcamera, and remove custom Rockchip parts.
Signed-off-by: NDave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 2b899025
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* /*
* ov9281 driver * Omnivision OV9281 1280x800 global shutter image sensor driver
*
* This driver has been taken from
* https://github.com/rockchip-linux/kernel/blob/develop-4.4/drivers/media/i2c/ov9281.c
* cleaned up, made to compile against mainline kernels instead of the Rockchip
* vendor kernel, and the relevant controls added to work with libcamera.
* *
* Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
* V0.0X01.0X02 fix mclk issue when probe multiple camera. * V0.0X01.0X02 fix mclk issue when probe multiple camera.
...@@ -17,22 +22,18 @@ ...@@ -17,22 +22,18 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/rk-camera-module.h>
#include <media/media-entity.h> #include <media/media-entity.h>
#include <media/v4l2-async.h> #include <media/v4l2-async.h>
#include <media/v4l2-ctrls.h> #include <media/v4l2-ctrls.h>
#include <media/v4l2-subdev.h> #include <media/v4l2-subdev.h>
#include <linux/pinctrl/consumer.h>
#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x3)
#ifndef V4L2_CID_DIGITAL_GAIN
#define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
#endif
#define OV9281_LINK_FREQ_400MHZ 400000000 #define OV9281_LINK_FREQ_400MHZ 400000000
#define OV9281_LANES 2
#define OV9281_BITS_PER_SAMPLE 10
/* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */ /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
#define OV9281_PIXEL_RATE (OV9281_LINK_FREQ_400MHZ * 2 * 2 / 10) #define OV9281_PIXEL_RATE (OV9281_LINK_FREQ_400MHZ * 2 * \
OV9281_LANES / OV9281_BITS_PER_SAMPLE)
#define OV9281_XVCLK_FREQ 24000000 #define OV9281_XVCLK_FREQ 24000000
#define CHIP_ID 0x9281 #define CHIP_ID 0x9281
...@@ -63,18 +64,24 @@ ...@@ -63,18 +64,24 @@
#define OV9281_REG_VTS 0x380e #define OV9281_REG_VTS 0x380e
/*
* OV9281 native and active pixel array size.
* Datasheet not available to confirm these values, so assume there are no
* border pixels.
*/
#define OV9281_NATIVE_WIDTH 1280U
#define OV9281_NATIVE_HEIGHT 800U
#define OV9281_PIXEL_ARRAY_LEFT 0U
#define OV9281_PIXEL_ARRAY_TOP 0U
#define OV9281_PIXEL_ARRAY_WIDTH 1280U
#define OV9281_PIXEL_ARRAY_HEIGHT 800U
#define REG_NULL 0xFFFF #define REG_NULL 0xFFFF
#define OV9281_REG_VALUE_08BIT 1 #define OV9281_REG_VALUE_08BIT 1
#define OV9281_REG_VALUE_16BIT 2 #define OV9281_REG_VALUE_16BIT 2
#define OV9281_REG_VALUE_24BIT 3 #define OV9281_REG_VALUE_24BIT 3
#define OV9281_LANES 2
#define OV9281_BITS_PER_SAMPLE 10
#define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
#define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
#define OV9281_NAME "ov9281" #define OV9281_NAME "ov9281"
static const char * const ov9281_supply_names[] = { static const char * const ov9281_supply_names[] = {
...@@ -93,10 +100,10 @@ struct regval { ...@@ -93,10 +100,10 @@ struct regval {
struct ov9281_mode { struct ov9281_mode {
u32 width; u32 width;
u32 height; u32 height;
struct v4l2_fract max_fps;
u32 hts_def; u32 hts_def;
u32 vts_def; u32 vts_def;
u32 exp_def; u32 exp_def;
struct v4l2_rect crop;
const struct regval *reg_list; const struct regval *reg_list;
}; };
...@@ -107,10 +114,6 @@ struct ov9281 { ...@@ -107,10 +114,6 @@ struct ov9281 {
struct gpio_desc *pwdn_gpio; struct gpio_desc *pwdn_gpio;
struct regulator_bulk_data supplies[OV9281_NUM_SUPPLIES]; struct regulator_bulk_data supplies[OV9281_NUM_SUPPLIES];
struct pinctrl *pinctrl;
struct pinctrl_state *pins_default;
struct pinctrl_state *pins_sleep;
struct v4l2_subdev subdev; struct v4l2_subdev subdev;
struct media_pad pad; struct media_pad pad;
struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl_handler ctrl_handler;
...@@ -124,21 +127,10 @@ struct ov9281 { ...@@ -124,21 +127,10 @@ struct ov9281 {
bool streaming; bool streaming;
bool power_on; bool power_on;
const struct ov9281_mode *cur_mode; const struct ov9281_mode *cur_mode;
u32 module_index;
const char *module_facing;
const char *module_name;
const char *len_name;
}; };
#define to_ov9281(sd) container_of(sd, struct ov9281, subdev) #define to_ov9281(sd) container_of(sd, struct ov9281, subdev)
/*
* Xclk 24Mhz
*/
static const struct regval ov9281_global_regs[] = {
{REG_NULL, 0x00},
};
/* /*
* Xclk 24Mhz * Xclk 24Mhz
* max_framerate 120fps * max_framerate 120fps
...@@ -247,13 +239,15 @@ static const struct ov9281_mode supported_modes[] = { ...@@ -247,13 +239,15 @@ static const struct ov9281_mode supported_modes[] = {
{ {
.width = 1280, .width = 1280,
.height = 800, .height = 800,
.max_fps = {
.numerator = 10000,
.denominator = 1200000,
},
.exp_def = 0x0320, .exp_def = 0x0320,
.hts_def = 0x0b60,//0x2d8*4 .hts_def = 0x05b0, /* 0x2d8*2 */
.vts_def = 0x038e, .vts_def = 0x038e,
.crop = {
.left = 0,
.top = 0,
.width = 1280,
.height = 800
},
.reg_list = ov9281_1280x800_regs, .reg_list = ov9281_1280x800_regs,
}, },
}; };
...@@ -389,22 +383,28 @@ static int ov9281_set_fmt(struct v4l2_subdev *sd, ...@@ -389,22 +383,28 @@ static int ov9281_set_fmt(struct v4l2_subdev *sd,
fmt->format.width = mode->width; fmt->format.width = mode->width;
fmt->format.height = mode->height; fmt->format.height = mode->height;
fmt->format.field = V4L2_FIELD_NONE; fmt->format.field = V4L2_FIELD_NONE;
fmt->format.colorspace = V4L2_COLORSPACE_SRGB;
fmt->format.ycbcr_enc =
V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace);
fmt->format.quantization =
V4L2_MAP_QUANTIZATION_DEFAULT(true, fmt->format.colorspace,
fmt->format.ycbcr_enc);
fmt->format.xfer_func =
V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace);
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
*v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
#else
mutex_unlock(&ov9281->mutex);
return -ENOTTY;
#endif
} else { } else {
ov9281->cur_mode = mode; ov9281->cur_mode = mode;
h_blank = mode->hts_def - mode->width; h_blank = mode->hts_def - mode->width;
__v4l2_ctrl_modify_range(ov9281->hblank, h_blank, __v4l2_ctrl_modify_range(ov9281->hblank, h_blank,
h_blank, 1, h_blank); h_blank, 1, h_blank);
__v4l2_ctrl_s_ctrl(ov9281->hblank, h_blank);
vblank_def = mode->vts_def - mode->height; vblank_def = mode->vts_def - mode->height;
__v4l2_ctrl_modify_range(ov9281->vblank, vblank_def, __v4l2_ctrl_modify_range(ov9281->vblank, vblank_def,
OV9281_VTS_MAX - mode->height, OV9281_VTS_MAX - mode->height,
1, vblank_def); 1, vblank_def);
__v4l2_ctrl_s_ctrl(ov9281->vblank, vblank_def);
} }
mutex_unlock(&ov9281->mutex); mutex_unlock(&ov9281->mutex);
...@@ -421,17 +421,21 @@ static int ov9281_get_fmt(struct v4l2_subdev *sd, ...@@ -421,17 +421,21 @@ static int ov9281_get_fmt(struct v4l2_subdev *sd,
mutex_lock(&ov9281->mutex); mutex_lock(&ov9281->mutex);
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
#else
mutex_unlock(&ov9281->mutex);
return -ENOTTY;
#endif
} else { } else {
fmt->format.width = mode->width; fmt->format.width = mode->width;
fmt->format.height = mode->height; fmt->format.height = mode->height;
fmt->format.code = MEDIA_BUS_FMT_Y10_1X10; fmt->format.code = MEDIA_BUS_FMT_Y10_1X10;
fmt->format.field = V4L2_FIELD_NONE; fmt->format.field = V4L2_FIELD_NONE;
fmt->format.colorspace = V4L2_COLORSPACE_SRGB;
fmt->format.ycbcr_enc =
V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace);
fmt->format.quantization =
V4L2_MAP_QUANTIZATION_DEFAULT(true,
fmt->format.colorspace,
fmt->format.ycbcr_enc);
fmt->format.xfer_func =
V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace);
} }
mutex_unlock(&ov9281->mutex); mutex_unlock(&ov9281->mutex);
...@@ -442,7 +446,7 @@ static int ov9281_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -442,7 +446,7 @@ static int ov9281_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_mbus_code_enum *code) struct v4l2_subdev_mbus_code_enum *code)
{ {
if (code->index != 0) if (code->index)
return -EINVAL; return -EINVAL;
code->code = MEDIA_BUS_FMT_Y10_1X10; code->code = MEDIA_BUS_FMT_Y10_1X10;
...@@ -480,88 +484,56 @@ static int ov9281_enable_test_pattern(struct ov9281 *ov9281, u32 pattern) ...@@ -480,88 +484,56 @@ static int ov9281_enable_test_pattern(struct ov9281 *ov9281, u32 pattern)
OV9281_REG_VALUE_08BIT, val); OV9281_REG_VALUE_08BIT, val);
} }
static int OV9281_g_frame_interval(struct v4l2_subdev *sd, static const struct v4l2_rect *
struct v4l2_subdev_frame_interval *fi) __ov9281_get_pad_crop(struct ov9281 *ov9281, struct v4l2_subdev_pad_config *cfg,
unsigned int pad, enum v4l2_subdev_format_whence which)
{ {
struct ov9281 *ov9281 = to_ov9281(sd); switch (which) {
const struct ov9281_mode *mode = ov9281->cur_mode; case V4L2_SUBDEV_FORMAT_TRY:
return v4l2_subdev_get_try_crop(&ov9281->subdev, cfg, pad);
mutex_lock(&ov9281->mutex); case V4L2_SUBDEV_FORMAT_ACTIVE:
fi->interval = mode->max_fps; return &ov9281->cur_mode->crop;
mutex_unlock(&ov9281->mutex); }
return 0; return NULL;
} }
static void ov9281_get_module_inf(struct ov9281 *ov9281, static int ov9281_get_selection(struct v4l2_subdev *sd,
struct rkmodule_inf *inf) struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_selection *sel)
{ {
memset(inf, 0, sizeof(*inf)); switch (sel->target) {
strlcpy(inf->base.sensor, OV9281_NAME, sizeof(inf->base.sensor)); case V4L2_SEL_TGT_CROP: {
strlcpy(inf->base.module, ov9281->module_name, struct ov9281 *ov9281 = to_ov9281(sd);
sizeof(inf->base.module));
strlcpy(inf->base.lens, ov9281->len_name, sizeof(inf->base.lens));
}
static long ov9281_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) mutex_lock(&ov9281->mutex);
{ sel->r = *__ov9281_get_pad_crop(ov9281, cfg, sel->pad,
struct ov9281 *ov9281 = to_ov9281(sd); sel->which);
long ret = 0; mutex_unlock(&ov9281->mutex);
switch (cmd) { return 0;
case RKMODULE_GET_MODULE_INFO:
ov9281_get_module_inf(ov9281, (struct rkmodule_inf *)arg);
break;
default:
ret = -ENOIOCTLCMD;
break;
} }
return ret; case V4L2_SEL_TGT_NATIVE_SIZE:
} sel->r.top = 0;
sel->r.left = 0;
sel->r.width = OV9281_NATIVE_WIDTH;
sel->r.height = OV9281_NATIVE_HEIGHT;
#ifdef CONFIG_COMPAT return 0;
static long ov9281_compat_ioctl32(struct v4l2_subdev *sd,
unsigned int cmd, unsigned long arg)
{
void __user *up = compat_ptr(arg);
struct rkmodule_inf *inf;
struct rkmodule_awb_cfg *cfg;
long ret;
switch (cmd) {
case RKMODULE_GET_MODULE_INFO:
inf = kzalloc(sizeof(*inf), GFP_KERNEL);
if (!inf) {
ret = -ENOMEM;
return ret;
}
ret = ov9281_ioctl(sd, cmd, inf); case V4L2_SEL_TGT_CROP_DEFAULT:
if (!ret) case V4L2_SEL_TGT_CROP_BOUNDS:
ret = copy_to_user(up, inf, sizeof(*inf)); sel->r.top = OV9281_PIXEL_ARRAY_TOP;
kfree(inf); sel->r.left = OV9281_PIXEL_ARRAY_LEFT;
break; sel->r.width = OV9281_PIXEL_ARRAY_WIDTH;
case RKMODULE_AWB_CFG: sel->r.height = OV9281_PIXEL_ARRAY_HEIGHT;
cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
if (!cfg) {
ret = -ENOMEM;
return ret;
}
ret = copy_from_user(cfg, up, sizeof(*cfg)); return 0;
if (!ret)
ret = ov9281_ioctl(sd, cmd, cfg);
kfree(cfg);
break;
default:
ret = -ENOIOCTLCMD;
break;
} }
return ret; return -EINVAL;
} }
#endif
static int __ov9281_start_stream(struct ov9281 *ov9281) static int __ov9281_start_stream(struct ov9281 *ov9281)
{ {
...@@ -643,12 +615,6 @@ static int ov9281_s_power(struct v4l2_subdev *sd, int on) ...@@ -643,12 +615,6 @@ static int ov9281_s_power(struct v4l2_subdev *sd, int on)
pm_runtime_put_noidle(&client->dev); pm_runtime_put_noidle(&client->dev);
goto unlock_and_return; goto unlock_and_return;
} }
ret = ov9281_write_array(ov9281->client, ov9281_global_regs);
if (ret) {
v4l2_err(sd, "could not set init registers\n");
pm_runtime_put_noidle(&client->dev);
goto unlock_and_return;
}
ov9281->power_on = true; ov9281->power_on = true;
} else { } else {
pm_runtime_put(&client->dev); pm_runtime_put(&client->dev);
...@@ -673,18 +639,12 @@ static int __ov9281_power_on(struct ov9281 *ov9281) ...@@ -673,18 +639,12 @@ static int __ov9281_power_on(struct ov9281 *ov9281)
u32 delay_us; u32 delay_us;
struct device *dev = &ov9281->client->dev; struct device *dev = &ov9281->client->dev;
if (!IS_ERR_OR_NULL(ov9281->pins_default)) {
ret = pinctrl_select_state(ov9281->pinctrl,
ov9281->pins_default);
if (ret < 0)
dev_err(dev, "could not set pins\n");
}
ret = clk_set_rate(ov9281->xvclk, OV9281_XVCLK_FREQ); ret = clk_set_rate(ov9281->xvclk, OV9281_XVCLK_FREQ);
if (ret < 0) if (ret < 0)
dev_warn(dev, "Failed to set xvclk rate (24MHz)\n"); dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
if (clk_get_rate(ov9281->xvclk) != OV9281_XVCLK_FREQ) if (clk_get_rate(ov9281->xvclk) != OV9281_XVCLK_FREQ)
dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n"); dev_warn(dev, "xvclk mismatched, modes are based on 24MHz - rate is %lu\n",
clk_get_rate(ov9281->xvclk));
ret = clk_prepare_enable(ov9281->xvclk); ret = clk_prepare_enable(ov9281->xvclk);
if (ret < 0) { if (ret < 0) {
...@@ -722,20 +682,11 @@ static int __ov9281_power_on(struct ov9281 *ov9281) ...@@ -722,20 +682,11 @@ static int __ov9281_power_on(struct ov9281 *ov9281)
static void __ov9281_power_off(struct ov9281 *ov9281) static void __ov9281_power_off(struct ov9281 *ov9281)
{ {
int ret;
struct device *dev = &ov9281->client->dev;
if (!IS_ERR(ov9281->pwdn_gpio)) if (!IS_ERR(ov9281->pwdn_gpio))
gpiod_set_value_cansleep(ov9281->pwdn_gpio, 0); gpiod_set_value_cansleep(ov9281->pwdn_gpio, 0);
clk_disable_unprepare(ov9281->xvclk); clk_disable_unprepare(ov9281->xvclk);
if (!IS_ERR(ov9281->reset_gpio)) if (!IS_ERR(ov9281->reset_gpio))
gpiod_set_value_cansleep(ov9281->reset_gpio, 0); gpiod_set_value_cansleep(ov9281->reset_gpio, 0);
if (!IS_ERR_OR_NULL(ov9281->pins_sleep)) {
ret = pinctrl_select_state(ov9281->pinctrl,
ov9281->pins_sleep);
if (ret < 0)
dev_dbg(dev, "could not set pins\n");
}
regulator_bulk_disable(OV9281_NUM_SUPPLIES, ov9281->supplies); regulator_bulk_disable(OV9281_NUM_SUPPLIES, ov9281->supplies);
} }
...@@ -759,7 +710,6 @@ static int ov9281_runtime_suspend(struct device *dev) ...@@ -759,7 +710,6 @@ static int ov9281_runtime_suspend(struct device *dev)
return 0; return 0;
} }
#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
{ {
struct ov9281 *ov9281 = to_ov9281(sd); struct ov9281 *ov9281 = to_ov9281(sd);
...@@ -773,61 +723,42 @@ static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) ...@@ -773,61 +723,42 @@ static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
try_fmt->height = def_mode->height; try_fmt->height = def_mode->height;
try_fmt->code = MEDIA_BUS_FMT_Y10_1X10; try_fmt->code = MEDIA_BUS_FMT_Y10_1X10;
try_fmt->field = V4L2_FIELD_NONE; try_fmt->field = V4L2_FIELD_NONE;
try_fmt->colorspace = V4L2_COLORSPACE_SRGB;
try_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(try_fmt->colorspace);
try_fmt->quantization =
V4L2_MAP_QUANTIZATION_DEFAULT(true, try_fmt->colorspace,
try_fmt->ycbcr_enc);
try_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(try_fmt->colorspace);
mutex_unlock(&ov9281->mutex); mutex_unlock(&ov9281->mutex);
/* No crop or compose */ /* No crop or compose */
return 0; return 0;
} }
#endif
static int
ov9281_enum_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_frame_interval_enum *fie)
{
if (fie->index >= ARRAY_SIZE(supported_modes))
return -EINVAL;
if (fie->code != MEDIA_BUS_FMT_Y10_1X10)
return -EINVAL;
fie->width = supported_modes[fie->index].width;
fie->height = supported_modes[fie->index].height;
fie->interval = supported_modes[fie->index].max_fps;
return 0;
}
static const struct dev_pm_ops ov9281_pm_ops = { static const struct dev_pm_ops ov9281_pm_ops = {
SET_RUNTIME_PM_OPS(ov9281_runtime_suspend, SET_RUNTIME_PM_OPS(ov9281_runtime_suspend,
ov9281_runtime_resume, NULL) ov9281_runtime_resume, NULL)
}; };
#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
static const struct v4l2_subdev_internal_ops ov9281_internal_ops = { static const struct v4l2_subdev_internal_ops ov9281_internal_ops = {
.open = ov9281_open, .open = ov9281_open,
}; };
#endif
static const struct v4l2_subdev_core_ops ov9281_core_ops = { static const struct v4l2_subdev_core_ops ov9281_core_ops = {
.s_power = ov9281_s_power, .s_power = ov9281_s_power,
.ioctl = ov9281_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl32 = ov9281_compat_ioctl32,
#endif
}; };
static const struct v4l2_subdev_video_ops ov9281_video_ops = { static const struct v4l2_subdev_video_ops ov9281_video_ops = {
.s_stream = ov9281_s_stream, .s_stream = ov9281_s_stream,
.g_frame_interval = OV9281_g_frame_interval,
}; };
static const struct v4l2_subdev_pad_ops ov9281_pad_ops = { static const struct v4l2_subdev_pad_ops ov9281_pad_ops = {
.enum_mbus_code = ov9281_enum_mbus_code, .enum_mbus_code = ov9281_enum_mbus_code,
.enum_frame_size = ov9281_enum_frame_sizes, .enum_frame_size = ov9281_enum_frame_sizes,
.enum_frame_interval = ov9281_enum_frame_interval,
.get_fmt = ov9281_get_fmt, .get_fmt = ov9281_get_fmt,
.set_fmt = ov9281_set_fmt, .set_fmt = ov9281_set_fmt,
.get_selection = ov9281_get_selection,
}; };
static const struct v4l2_subdev_ops ov9281_subdev_ops = { static const struct v4l2_subdev_ops ov9281_subdev_ops = {
...@@ -868,7 +799,8 @@ static int ov9281_set_ctrl(struct v4l2_ctrl *ctrl) ...@@ -868,7 +799,8 @@ static int ov9281_set_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_ANALOGUE_GAIN: case V4L2_CID_ANALOGUE_GAIN:
ret = ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_H, ret = ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_H,
OV9281_REG_VALUE_08BIT, OV9281_REG_VALUE_08BIT,
(ctrl->val >> OV9281_GAIN_H_SHIFT) & OV9281_GAIN_H_MASK); (ctrl->val >> OV9281_GAIN_H_SHIFT) &
OV9281_GAIN_H_MASK);
ret |= ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_L, ret |= ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_L,
OV9281_REG_VALUE_08BIT, OV9281_REG_VALUE_08BIT,
ctrl->val & OV9281_GAIN_L_MASK); ctrl->val & OV9281_GAIN_L_MASK);
...@@ -922,31 +854,34 @@ static int ov9281_initialize_controls(struct ov9281 *ov9281) ...@@ -922,31 +854,34 @@ static int ov9281_initialize_controls(struct ov9281 *ov9281)
h_blank = mode->hts_def - mode->width; h_blank = mode->hts_def - mode->width;
ov9281->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, ov9281->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
h_blank, h_blank, 1, h_blank); h_blank, h_blank, 1, h_blank);
if (ov9281->hblank) if (ov9281->hblank)
ov9281->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; ov9281->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
vblank_def = mode->vts_def - mode->height; vblank_def = mode->vts_def - mode->height;
ov9281->vblank = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops, ov9281->vblank = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
V4L2_CID_VBLANK, vblank_def, V4L2_CID_VBLANK, vblank_def,
OV9281_VTS_MAX - mode->height, OV9281_VTS_MAX - mode->height, 1,
1, vblank_def); vblank_def);
exposure_max = mode->vts_def - 4; exposure_max = mode->vts_def - 4;
ov9281->exposure = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops, ov9281->exposure = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
V4L2_CID_EXPOSURE, OV9281_EXPOSURE_MIN, V4L2_CID_EXPOSURE,
exposure_max, OV9281_EXPOSURE_STEP, OV9281_EXPOSURE_MIN, exposure_max,
mode->exp_def); OV9281_EXPOSURE_STEP,
mode->exp_def);
ov9281->anal_gain = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops, ov9281->anal_gain = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
V4L2_CID_ANALOGUE_GAIN, OV9281_GAIN_MIN, V4L2_CID_ANALOGUE_GAIN,
OV9281_GAIN_MAX, OV9281_GAIN_STEP, OV9281_GAIN_MIN, OV9281_GAIN_MAX,
OV9281_GAIN_DEFAULT); OV9281_GAIN_STEP,
OV9281_GAIN_DEFAULT);
ov9281->test_pattern = v4l2_ctrl_new_std_menu_items(handler, ov9281->test_pattern =
&ov9281_ctrl_ops, V4L2_CID_TEST_PATTERN, v4l2_ctrl_new_std_menu_items(handler, &ov9281_ctrl_ops,
ARRAY_SIZE(ov9281_test_pattern_menu) - 1, V4L2_CID_TEST_PATTERN,
0, 0, ov9281_test_pattern_menu); ARRAY_SIZE(ov9281_test_pattern_menu) - 1,
0, 0, ov9281_test_pattern_menu);
if (handler->error) { if (handler->error) {
ret = handler->error; ret = handler->error;
...@@ -1000,34 +935,14 @@ static int ov9281_probe(struct i2c_client *client, ...@@ -1000,34 +935,14 @@ static int ov9281_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct device_node *node = dev->of_node;
struct ov9281 *ov9281; struct ov9281 *ov9281;
struct v4l2_subdev *sd; struct v4l2_subdev *sd;
char facing[2];
int ret; int ret;
dev_info(dev, "driver version: %02x.%02x.%02x",
DRIVER_VERSION >> 16,
(DRIVER_VERSION & 0xff00) >> 8,
DRIVER_VERSION & 0x00ff);
ov9281 = devm_kzalloc(dev, sizeof(*ov9281), GFP_KERNEL); ov9281 = devm_kzalloc(dev, sizeof(*ov9281), GFP_KERNEL);
if (!ov9281) if (!ov9281)
return -ENOMEM; return -ENOMEM;
ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
&ov9281->module_index);
ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
&ov9281->module_facing);
ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
&ov9281->module_name);
ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
&ov9281->len_name);
if (ret) {
dev_err(dev, "could not get module information!\n");
return -EINVAL;
}
ov9281->client = client; ov9281->client = client;
ov9281->cur_mode = &supported_modes[0]; ov9281->cur_mode = &supported_modes[0];
...@@ -1037,31 +952,15 @@ static int ov9281_probe(struct i2c_client *client, ...@@ -1037,31 +952,15 @@ static int ov9281_probe(struct i2c_client *client,
return -EINVAL; return -EINVAL;
} }
ov9281->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); ov9281->reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_LOW);
if (IS_ERR(ov9281->reset_gpio)) if (IS_ERR(ov9281->reset_gpio))
dev_warn(dev, "Failed to get reset-gpios\n"); dev_warn(dev, "Failed to get reset-gpios\n");
ov9281->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); ov9281->pwdn_gpio = devm_gpiod_get_optional(dev, "pwdn", GPIOD_OUT_LOW);
if (IS_ERR(ov9281->pwdn_gpio)) if (IS_ERR(ov9281->pwdn_gpio))
dev_warn(dev, "Failed to get pwdn-gpios\n"); dev_warn(dev, "Failed to get pwdn-gpios\n");
ov9281->pinctrl = devm_pinctrl_get(dev);
if (!IS_ERR(ov9281->pinctrl)) {
ov9281->pins_default =
pinctrl_lookup_state(ov9281->pinctrl,
OF_CAMERA_PINCTRL_STATE_DEFAULT);
if (IS_ERR(ov9281->pins_default))
dev_err(dev, "could not get default pinstate\n");
ov9281->pins_sleep =
pinctrl_lookup_state(ov9281->pinctrl,
OF_CAMERA_PINCTRL_STATE_SLEEP);
if (IS_ERR(ov9281->pins_sleep))
dev_err(dev, "could not get sleep pinstate\n");
} else {
dev_err(dev, "no pinctrl\n");
}
ret = ov9281_configure_regulators(ov9281); ret = ov9281_configure_regulators(ov9281);
if (ret) { if (ret) {
dev_err(dev, "Failed to get power regulators\n"); dev_err(dev, "Failed to get power regulators\n");
...@@ -1084,26 +983,16 @@ static int ov9281_probe(struct i2c_client *client, ...@@ -1084,26 +983,16 @@ static int ov9281_probe(struct i2c_client *client,
if (ret) if (ret)
goto err_power_off; goto err_power_off;
#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
sd->internal_ops = &ov9281_internal_ops; sd->internal_ops = &ov9281_internal_ops;
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
#endif
#if defined(CONFIG_MEDIA_CONTROLLER)
ov9281->pad.flags = MEDIA_PAD_FL_SOURCE; ov9281->pad.flags = MEDIA_PAD_FL_SOURCE;
sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR; sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
ret = media_entity_init(&sd->entity, 1, &ov9281->pad, 0); ret = media_entity_pads_init(&sd->entity, 1, &ov9281->pad);
if (ret < 0) if (ret < 0)
goto err_power_off; goto err_power_off;
#endif
memset(facing, 0, sizeof(facing));
if (strcmp(ov9281->module_facing, "back") == 0)
facing[0] = 'b';
else
facing[0] = 'f';
snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s", snprintf(sd->name, sizeof(sd->name), "m%s %s",
ov9281->module_index, facing,
OV9281_NAME, dev_name(sd->dev)); OV9281_NAME, dev_name(sd->dev));
ret = v4l2_async_register_subdev_sensor_common(sd); ret = v4l2_async_register_subdev_sensor_common(sd);
if (ret) { if (ret) {
...@@ -1118,9 +1007,7 @@ static int ov9281_probe(struct i2c_client *client, ...@@ -1118,9 +1007,7 @@ static int ov9281_probe(struct i2c_client *client,
return 0; return 0;
err_clean_entity: err_clean_entity:
#if defined(CONFIG_MEDIA_CONTROLLER)
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
#endif
err_power_off: err_power_off:
__ov9281_power_off(ov9281); __ov9281_power_off(ov9281);
err_free_handler: err_free_handler:
...@@ -1137,9 +1024,7 @@ static int ov9281_remove(struct i2c_client *client) ...@@ -1137,9 +1024,7 @@ static int ov9281_remove(struct i2c_client *client)
struct ov9281 *ov9281 = to_ov9281(sd); struct ov9281 *ov9281 = to_ov9281(sd);
v4l2_async_unregister_subdev(sd); v4l2_async_unregister_subdev(sd);
#if defined(CONFIG_MEDIA_CONTROLLER)
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
#endif
v4l2_ctrl_handler_free(&ov9281->ctrl_handler); v4l2_ctrl_handler_free(&ov9281->ctrl_handler);
mutex_destroy(&ov9281->mutex); mutex_destroy(&ov9281->mutex);
...@@ -1151,13 +1036,11 @@ static int ov9281_remove(struct i2c_client *client) ...@@ -1151,13 +1036,11 @@ static int ov9281_remove(struct i2c_client *client)
return 0; return 0;
} }
#if IS_ENABLED(CONFIG_OF)
static const struct of_device_id ov9281_of_match[] = { static const struct of_device_id ov9281_of_match[] = {
{ .compatible = "ovti,ov9281" }, { .compatible = "ovti,ov9281" },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, ov9281_of_match); MODULE_DEVICE_TABLE(of, ov9281_of_match);
#endif
static const struct i2c_device_id ov9281_match_id[] = { static const struct i2c_device_id ov9281_match_id[] = {
{ "ovti,ov9281", 0 }, { "ovti,ov9281", 0 },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册