Skip to content

Commit

Permalink
debug_cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelscholle committed Aug 31, 2024
1 parent 4f053da commit e2463fb
Show file tree
Hide file tree
Showing 5 changed files with 6,421 additions and 53 deletions.
38 changes: 23 additions & 15 deletions arch/arm64/configs/rockchip_linux_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ CONFIG_BT_HCIBTUSB=m
CONFIG_BT_HCIUART=m
CONFIG_BT_HCIUART_ATH3K=y
CONFIG_BT_HCIUART_INTEL=y
CONFIG_BT_HCIUART_BCM=y
CONFIG_BT_HCIUART_QCA=y
CONFIG_BT_HCIBFUSB=m
CONFIG_BT_HCIVHCI=m
CONFIG_BT_MRVL=m
Expand Down Expand Up @@ -618,8 +616,10 @@ CONFIG_STMMAC_ETH=y
# CONFIG_NET_VENDOR_TI is not set
# CONFIG_NET_VENDOR_VIA is not set
# CONFIG_NET_VENDOR_WIZNET is not set
CONFIG_MOTORCOMM_PHY=y
CONFIG_REALTEK_PHY=y
CONFIG_ROCKCHIP_PHY=y
CONFIG_RK630_PHY=y
CONFIG_PPP=m
CONFIG_PPP_BSDCOMP=m
CONFIG_PPP_DEFLATE=m
Expand Down Expand Up @@ -682,12 +682,11 @@ CONFIG_RTL_CARDS=m
CONFIG_RTL8723BE=m
CONFIG_RTL8192CU=m
CONFIG_RTL8XXXU=m
CONFIG_RTW89=m
CONFIG_RTW89_8852BE=m
CONFIG_USB_ZD1201=m
CONFIG_WL_ROCKCHIP=y
CONFIG_WIFI_BUILD_MODULE=y
CONFIG_AP6XXX=m
CONFIG_RTL8852BE=m
CONFIG_RTL8852BU=m
CONFIG_USB_NET_RNDIS_WLAN=y
# CONFIG_IEEE802154_DRIVERS is not set
Expand Down Expand Up @@ -813,6 +812,7 @@ CONFIG_USB_VIDEO_CLASS=y
# CONFIG_USB_GSPCA is not set
CONFIG_V4L_PLATFORM_DRIVERS=y
CONFIG_VIDEO_ROCKCHIP_CIF=y
CONFIG_ROCKCHIP_CIF_USE_NONE_DUMMY_BUF=y
CONFIG_VIDEO_ROCKCHIP_RKISP1=y
CONFIG_VIDEO_ROCKCHIP_ISP=y
CONFIG_VIDEO_ROCKCHIP_ISPP=y
Expand All @@ -830,16 +830,18 @@ CONFIG_VIDEO_GC2093=y
CONFIG_VIDEO_GC8034=y
CONFIG_VIDEO_IMX219=y
CONFIG_VIDEO_IMX415=y
CONFIG_VIDEO_ARDUCAM_PIVARIETY=m
CONFIG_VIDEO_IMX708=m
CONFIG_VIDEO_IMX462=m
CONFIG_VIDEO_ARDUCAM_IMX477P=y
CONFIG_VIDEO_ARDUCAM_PIVARIETY=y
CONFIG_VIDEO_IMX519=y
CONFIG_VIDEO_OV64A40=y
CONFIG_VIDEO_IMX464=y
CONFIG_VIDEO_OS04A10=y
CONFIG_VIDEO_OV4689=y
CONFIG_VIDEO_OV5647=y
CONFIG_VIDEO_OV5695=y
CONFIG_VIDEO_OV7251=y
CONFIG_VIDEO_OV13850=y
CONFIG_VIDEO_AK7375=y
# CONFIG_VGA_ARB is not set
CONFIG_DRM=y
CONFIG_DRM_IGNORE_IOTCL_PERMIT=y
Expand All @@ -848,12 +850,14 @@ CONFIG_DRM_LOAD_EDID_FIRMWARE=y
CONFIG_DRM_ROCKCHIP=y
CONFIG_ROCKCHIP_ANALOGIX_DP=y
CONFIG_ROCKCHIP_CDN_DP=y
CONFIG_ROCKCHIP_DRM_TVE=y
CONFIG_ROCKCHIP_DW_HDMI=y
CONFIG_ROCKCHIP_DW_MIPI_DSI=y
CONFIG_ROCKCHIP_DW_DP=y
CONFIG_ROCKCHIP_INNO_HDMI=y
CONFIG_ROCKCHIP_LVDS=y
CONFIG_ROCKCHIP_RGB=y
CONFIG_ROCKCHIP_DW_HDCP2=y
CONFIG_DRM_PANEL_SIMPLE=y
CONFIG_DRM_PANEL_JADARD_JD9365DA_H3=y
CONFIG_DRM_PANEL_RADXA_DISPLAY_8HD=y
Expand Down Expand Up @@ -911,6 +915,7 @@ CONFIG_SND_SOC=y
CONFIG_SND_SOC_ROCKCHIP=y
CONFIG_SND_SOC_ROCKCHIP_I2S_TDM=y
CONFIG_SND_SOC_ROCKCHIP_PDM=y
CONFIG_SND_SOC_ROCKCHIP_SAI=y
CONFIG_SND_SOC_ROCKCHIP_SPDIF=y
CONFIG_SND_SOC_ROCKCHIP_SPDIFRX=y
CONFIG_SND_SOC_ROCKCHIP_MAX98090=y
Expand All @@ -926,6 +931,7 @@ CONFIG_SND_SOC_ES8323=y
CONFIG_SND_SOC_ES8326=y
CONFIG_SND_SOC_RK3308=y
CONFIG_SND_SOC_RK3328=y
CONFIG_SND_SOC_RK3528=y
CONFIG_SND_SOC_RK817=y
CONFIG_SND_SOC_RK_CODEC_DIGITAL=y
CONFIG_SND_SOC_RT5616=y
Expand Down Expand Up @@ -1096,11 +1102,10 @@ CONFIG_LEDS_TRIGGER_PANIC=y
CONFIG_LEDS_TRIGGER_NETDEV=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_HYM8563=y
CONFIG_RTC_DRV_RK808=y
CONFIG_RTC_DRV_RK808=m
CONFIG_RTC_DRV_PCF85063=y
CONFIG_DMADEVICES=y
CONFIG_PL330_DMA=y
CONFIG_DMABUF_DEBUG=y
CONFIG_SW_SYNC=y
CONFIG_DMABUF_HEAPS=y
CONFIG_DMABUF_SYSFS_STATS=y
Expand All @@ -1115,12 +1120,6 @@ CONFIG_VHOST_VSOCK=m
CONFIG_VHOST_VDPA=m
CONFIG_VHOST_CROSS_ENDIAN_LEGACY=y
CONFIG_STAGING=y
CONFIG_FIQ_DEBUGGER=y
CONFIG_FIQ_DEBUGGER_NO_SLEEP=y
CONFIG_FIQ_DEBUGGER_CONSOLE=y
CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE=y
CONFIG_FIQ_DEBUGGER_TRUST_ZONE=y
CONFIG_RK_CONSOLE_THREAD=y
CONFIG_COMMON_CLK_RK808=y
CONFIG_COMMON_CLK_SCMI=y
CONFIG_COMMON_CLK_PWM=y
Expand All @@ -1133,8 +1132,11 @@ CONFIG_CPU_PX30=y
CONFIG_CPU_RK1808=y
CONFIG_CPU_RK3328=y
CONFIG_CPU_RK3399=y
CONFIG_CPU_RK3528=y
CONFIG_CPU_RK3562=y
CONFIG_CPU_RK3568=y
CONFIG_CPU_RK3588=y
CONFIG_ROCKCHIP_AMP=y
CONFIG_ROCKCHIP_CPUINFO=y
CONFIG_ROCKCHIP_GRF=y
CONFIG_ROCKCHIP_IODOMAIN=y
Expand All @@ -1146,6 +1148,12 @@ CONFIG_ROCKCHIP_SUSPEND_MODE=y
CONFIG_ROCKCHIP_SYSTEM_MONITOR=y
CONFIG_ROCKCHIP_MMC_VENDOR_STORAGE=y
CONFIG_ROCKCHIP_VENDOR_STORAGE_UPDATE_LOADER=y
CONFIG_FIQ_DEBUGGER=y
CONFIG_FIQ_DEBUGGER_NO_SLEEP=y
CONFIG_FIQ_DEBUGGER_CONSOLE=y
CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE=y
CONFIG_FIQ_DEBUGGER_TRUST_ZONE=y
CONFIG_RK_CONSOLE_THREAD=y
CONFIG_ROCKCHIP_DEBUG=y
CONFIG_PM_DEVFREQ=y
CONFIG_DEVFREQ_GOV_PERFORMANCE=y
Expand Down
182 changes: 148 additions & 34 deletions drivers/media/i2c/ak7375.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Intel Corporation

#include <asm/unaligned.h>
#include <linux/acpi.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <linux/rk-camera-module.h>
#include <linux/version.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <linux/rk_vcm_head.h>

#define AK7375_MAX_FOCUS_POS 4095
/*
Expand Down Expand Up @@ -73,11 +78,14 @@ static int ak7375_i2c_write(struct ak7375_device *ak7375,
static int ak7375_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct ak7375_device *dev_vcm = to_ak7375_vcm(ctrl);


if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE){

if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE)
printk("set ctrl value: %d\r\n",ctrl->val);
return ak7375_i2c_write(dev_vcm, AK7375_REG_POSITION,
ctrl->val << 4, 2);

}
return -EINVAL;
}

Expand Down Expand Up @@ -110,7 +118,100 @@ static const struct v4l2_subdev_internal_ops ak7375_int_ops = {
.close = ak7375_close,
};

static const struct v4l2_subdev_ops ak7375_ops = { };


static long ak7375_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
//struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
struct rk_cam_vcm_tim *vcm_tim;
struct rk_cam_vcm_cfg *vcm_cfg;
int ret = 0;

if (cmd == RK_VIDIOC_VCM_TIMEINFO) {
vcm_tim = (struct rk_cam_vcm_tim *)arg;

// vcm_tim->vcm_start_t.tv_sec = ak7375_dev->start_move_tv.tv_sec;
// vcm_tim->vcm_start_t.tv_usec = ak7375_dev->start_move_tv.tv_usec;
// vcm_tim->vcm_end_t.tv_sec = ak7375_dev->end_move_tv.tv_sec;
// vcm_tim->vcm_end_t.tv_usec = ak7375_dev->end_move_tv.tv_usec;

// dev_dbg(&client->dev, "ak7375_get_move_res 0x%lx, 0x%lx, 0x%lx, 0x%lx\n",
// vcm_tim->vcm_start_t.tv_sec, vcm_tim->vcm_start_t.tv_usec,
// vcm_tim->vcm_end_t.tv_sec, vcm_tim->vcm_end_t.tv_usec);
} else if (cmd == RK_VIDIOC_GET_VCM_CFG) {
vcm_cfg = (struct rk_cam_vcm_cfg *)arg;

// vcm_cfg->start_ma = ak7375_dev->vcm_cfg.start_ma;
// vcm_cfg->rated_ma = ak7375_dev->vcm_cfg.rated_ma;
// vcm_cfg->step_mode = ak7375_dev->vcm_cfg.step_mode;
} else if (cmd == RK_VIDIOC_SET_VCM_CFG) {
vcm_cfg = (struct rk_cam_vcm_cfg *)arg;

// ak7375_dev->vcm_cfg.start_ma = vcm_cfg->start_ma;
// ak7375_dev->vcm_cfg.rated_ma = vcm_cfg->rated_ma;
// ak7375_dev->vcm_cfg.step_mode = vcm_cfg->step_mode;
//ak7375_update_vcm_cfg(ak7375_dev);
} else {
dev_err(&client->dev,
"cmd 0x%x not supported\n", cmd);
return -EINVAL;
}

return ret;
}

#ifdef CONFIG_COMPAT
static long ak7375_compat_ioctl32(struct v4l2_subdev *sd, unsigned int cmd, unsigned long arg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct rk_cam_compat_vcm_tim __user *p32 = compat_ptr(arg);
struct rk_cam_compat_vcm_tim compat_vcm_tim;
struct rk_cam_vcm_tim vcm_tim;
struct rk_cam_vcm_cfg vcm_cfg;
long ret;

if (cmd == RK_VIDIOC_COMPAT_VCM_TIMEINFO) {
ret = ak7375_ioctl(sd, RK_VIDIOC_VCM_TIMEINFO, &vcm_tim);
compat_vcm_tim.vcm_start_t.tv_sec = vcm_tim.vcm_start_t.tv_sec;
compat_vcm_tim.vcm_start_t.tv_usec = vcm_tim.vcm_start_t.tv_usec;
compat_vcm_tim.vcm_end_t.tv_sec = vcm_tim.vcm_end_t.tv_sec;
compat_vcm_tim.vcm_end_t.tv_usec = vcm_tim.vcm_end_t.tv_usec;

put_user(compat_vcm_tim.vcm_start_t.tv_sec, &p32->vcm_start_t.tv_sec);
put_user(compat_vcm_tim.vcm_start_t.tv_usec, &p32->vcm_start_t.tv_usec);
put_user(compat_vcm_tim.vcm_end_t.tv_sec, &p32->vcm_end_t.tv_sec);
put_user(compat_vcm_tim.vcm_end_t.tv_usec, &p32->vcm_end_t.tv_usec);
} else if (cmd == RK_VIDIOC_GET_VCM_CFG) {
ret = ak7375_ioctl(sd, RK_VIDIOC_GET_VCM_CFG, &vcm_cfg);
if (!ret)
ret = copy_to_user(up, &vcm_cfg, sizeof(vcm_cfg));
} else if (cmd == RK_VIDIOC_SET_VCM_CFG) {
ret = copy_from_user(&vcm_cfg, up, sizeof(vcm_cfg));
if (!ret)
ret = ak7375_ioctl(sd, cmd, &vcm_cfg);
} else {
dev_err(&client->dev,
"cmd 0x%x not supported\n", cmd);
return -EINVAL;
}

return ret;
}
#endif



static const struct v4l2_subdev_core_ops ak7375_core_ops = {
.ioctl = ak7375_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl32 = ak7375_compat_ioctl32
#endif
};

static const struct v4l2_subdev_ops ak7375_ops = {
.core = &ak7375_core_ops,
};

static void ak7375_subdev_cleanup(struct ak7375_device *ak7375_dev)
{
Expand All @@ -127,7 +228,7 @@ static int ak7375_init_controls(struct ak7375_device *dev_vcm)
v4l2_ctrl_handler_init(hdl, 1);

dev_vcm->focus = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_ABSOLUTE,
0, AK7375_MAX_FOCUS_POS, AK7375_FOCUS_STEPS, 0);
0, AK7375_MAX_FOCUS_POS, AK7375_FOCUS_STEPS, 900);

if (hdl->error)
dev_err(dev_vcm->sd.dev, "%s fail error: 0x%x\n",
Expand Down Expand Up @@ -197,30 +298,30 @@ static int ak7375_remove(struct i2c_client *client)
static int __maybe_unused ak7375_vcm_suspend(struct device *dev)
{

struct i2c_client *client = to_i2c_client(dev);
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
int ret, val;
// struct i2c_client *client = to_i2c_client(dev);
// struct v4l2_subdev *sd = i2c_get_clientdata(client);
// struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
// int ret, val;

if (!ak7375_dev->active)
return 0;
// if (!ak7375_dev->active)
// return 0;

for (val = ak7375_dev->focus->val & ~(AK7375_CTRL_STEPS - 1);
val >= 0; val -= AK7375_CTRL_STEPS) {
ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_POSITION,
val << 4, 2);
if (ret)
dev_err_once(dev, "%s I2C failure: %d\n",
__func__, ret);
usleep_range(AK7375_CTRL_DELAY_US, AK7375_CTRL_DELAY_US + 10);
}
// for (val = ak7375_dev->focus->val & ~(AK7375_CTRL_STEPS - 1);
// val >= 0; val -= AK7375_CTRL_STEPS) {
// ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_POSITION,
// val << 4, 2);
// if (ret)
// dev_err_once(dev, "%s I2C failure: %d\n",
// __func__, ret);
// usleep_range(AK7375_CTRL_DELAY_US, AK7375_CTRL_DELAY_US + 10);
// }

ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_CONT,
AK7375_MODE_STANDBY, 1);
if (ret)
dev_err(dev, "%s I2C failure: %d\n", __func__, ret);
// ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_CONT,
// AK7375_MODE_STANDBY, 1);
// if (ret)
// dev_err(dev, "%s I2C failure: %d\n", __func__, ret);

ak7375_dev->active = false;
// ak7375_dev->active = false;

return 0;
}
Expand All @@ -238,8 +339,8 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev)
struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
int ret, val;

if (ak7375_dev->active)
return 0;
// if (ak7375_dev->active)
// return 0;

ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_CONT,
AK7375_MODE_ACTIVE, 1);
Expand All @@ -248,18 +349,31 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev)
return ret;
}

for (val = ak7375_dev->focus->val % AK7375_CTRL_STEPS;
val <= ak7375_dev->focus->val;
val += AK7375_CTRL_STEPS) {
ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_POSITION,
// for (val = ak7375_dev->focus->val % AK7375_CTRL_STEPS;
// val <= ak7375_dev->focus->val;
// val += AK7375_CTRL_STEPS) {
// printk("ak7375_vcm_resume set vcm positon : %d\r\n",val);
// ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_POSITION,
// val << 4, 2);
// if (ret)
// dev_err_ratelimited(dev, "%s I2C failure: %d\n",
// __func__, ret);
// usleep_range(AK7375_CTRL_DELAY_US, AK7375_CTRL_DELAY_US + 10);
// }

//ak7375_dev->active = true;


//arducam fixed
val = ak7375_dev->focus->val;
printk("ak7375_vcm_resume set vcm positon : %d\r\n",val);
ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_POSITION,
val << 4, 2);
if (ret)
dev_err_ratelimited(dev, "%s I2C failure: %d\n",
__func__, ret);
usleep_range(AK7375_CTRL_DELAY_US, AK7375_CTRL_DELAY_US + 10);
}

ak7375_dev->active = true;


return 0;
}
Expand Down
Loading

0 comments on commit e2463fb

Please sign in to comment.