^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Rockchip rk1608 driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017-2018 Rockchip Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/clkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/of_graph.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <media/v4l2-ctrls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <media/v4l2-fwnode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <media/v4l2-subdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/rk-preisp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/rkisp1-config.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/rk-camera-module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "rk1608_dphy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RK1608_DPHY_NAME "RK1608-dphy"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Rk1608 is used as the Pre-ISP to link on Soc, which mainly has two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * functions. One is to download the firmware of RK1608, and the other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * is to match the extra sensor such as camera and enable sensor by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * calling sensor's s_power.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * |-----------------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * | Sensor Camera |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * |-----------------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * |-----------||----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * |-----------||----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * |-----------\/----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * | Pre-ISP RK1608 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * |-----------------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * |-----------||----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * |-----------||----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * |-----------\/----------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * | Rockchip Soc |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * |-----------------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Data Transfer As shown above. In RK1608, the data received from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * extra sensor,and it is passed to the Soc through ISP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static DEFINE_MUTEX(rk1608_dphy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline struct rk1608_dphy *to_state(struct v4l2_subdev *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return container_of(sd, struct rk1608_dphy, sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int rk1608_s_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct v4l2_ctrl *remote_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pdata->rk1608_sd->grp_id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) V4L2_CID_HBLANK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (remote_ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) v4l2_ctrl_g_ctrl(remote_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __v4l2_ctrl_modify_range(pdata->hblank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) remote_ctrl->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) remote_ctrl->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) remote_ctrl->step,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) remote_ctrl->default_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) V4L2_CID_VBLANK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (remote_ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) v4l2_ctrl_g_ctrl(remote_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __v4l2_ctrl_modify_range(pdata->vblank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) remote_ctrl->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) remote_ctrl->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) remote_ctrl->step,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) remote_ctrl->default_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int rk1608_s_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) pdata->rk1608_sd->grp_id = sd->grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int rk1608_sensor_power(struct v4l2_subdev *sd, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) pdata->rk1608_sd->grp_id = sd->grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = v4l2_subdev_call(pdata->rk1608_sd, core, s_power, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define RK1608_MAX_BITRATE (1500000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int rk1608_get_link_sensor_timing(struct rk1608_dphy *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) u32 idx = pdata->fmt_inf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct rk1608_fmt_inf *fmt_inf = &pdata->fmt_inf[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int sub_sensor_num = pdata->sub_sensor_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u32 width = 0, height = 0, out_width, out_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct v4l2_subdev_frame_interval fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int max_fps = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u64 bps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct v4l2_subdev_format fmt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .which = V4L2_SUBDEV_FORMAT_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .pad = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) link_sensor = i2c_get_clientdata(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = v4l2_subdev_call(link_sensor, pad, get_fmt, NULL, &fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dev_info(pdata->dev, "get link fmt fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) width = fmt.format.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) height = fmt.format.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev_info(pdata->dev, "phy[%d] get fmt w:%d h:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) id, width, height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) memset(&fi, 0, sizeof(fi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ret = v4l2_subdev_call(link_sensor, video, g_frame_interval, &fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dev_info(pdata->dev, "get link interval fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) max_fps = fi.interval.denominator / fi.interval.numerator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) dev_info(pdata->dev, "phy[%d] get fps:%d (%d/%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) id, max_fps, fi.interval.denominator, fi.interval.numerator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) width = fmt_inf->mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) height = fmt_inf->mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev_info(pdata->dev, "phy[%d] no link sensor\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!width || !height) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_err(pdata->dev, "phy[%d] get fmt error!\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (fmt_inf->in_ch[i].width == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) fmt_inf->in_ch[i].width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) fmt_inf->in_ch[i].height = height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) out_width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) out_height = height * (sub_sensor_num + 1); /* sub add main */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (fmt_inf->out_ch[i].width == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) fmt_inf->out_ch[i].width = out_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) fmt_inf->out_ch[i].height = out_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) fmt_inf->hactive = out_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fmt_inf->vactive = out_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) fmt_inf->htotal = out_width + (width * 1 / 3); //1.33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) fmt_inf->vtotal = out_height + (height >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* max 30 fps, raw 10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) bps = fmt_inf->htotal * fmt_inf->vtotal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) / fmt_inf->mipi_lane_out * 10 * max_fps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* add extra timing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) bps = bps * 105;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) do_div(bps, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (bps > RK1608_MAX_BITRATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bps = RK1608_MAX_BITRATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) pdata->link_freqs = (u32)(bps/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) dev_info(pdata->dev, "target mipi bps:%lld\n", bps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int rk1608_s_stream(struct v4l2_subdev *sd, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (enable && pdata->sub_sensor_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) rk1608_get_link_sensor_timing(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pdata->rk1608_sd->grp_id = sd->grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) v4l2_subdev_call(pdata->rk1608_sd, video, s_stream, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int rk1608_enum_mbus_code(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct v4l2_subdev_mbus_code_enum *code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (code->index >= pdata->fmt_inf_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) code->code = pdata->fmt_inf[code->index].mf.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int rk1608_enum_frame_sizes(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct v4l2_subdev_frame_size_enum *fse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (fse->index >= pdata->fmt_inf_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (fse->code != pdata->fmt_inf[fse->index].mf.code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) fse->min_width = pdata->fmt_inf[fse->index].mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) fse->max_width = pdata->fmt_inf[fse->index].mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) fse->max_height = pdata->fmt_inf[fse->index].mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) fse->min_height = pdata->fmt_inf[fse->index].mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int rk1608_get_fmt(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct v4l2_subdev_format *fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct v4l2_mbus_framefmt *mf = &fmt->format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) u32 idx = pdata->fmt_inf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) link_sensor = i2c_get_clientdata(pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ret = v4l2_subdev_call(link_sensor, pad, get_fmt, NULL, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) dev_info(pdata->dev, "get link fmt fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) dev_info(pdata->dev, "use link sensor fmt w:%d h:%d code:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) mf->width, mf->height, mf->code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (ret || !mf->width || !mf->height) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mf->code = pdata->fmt_inf[idx].mf.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) mf->width = pdata->fmt_inf[idx].mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mf->height = pdata->fmt_inf[idx].mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) mf->field = pdata->fmt_inf[idx].mf.field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) mf->colorspace = pdata->fmt_inf[idx].mf.colorspace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) pdata->fmt_inf[idx].mf.code = mf->code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) pdata->fmt_inf[idx].mf.width = mf->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) pdata->fmt_inf[idx].mf.height = mf->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) pdata->fmt_inf[idx].mf.field = mf->field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) pdata->fmt_inf[idx].mf.colorspace = mf->colorspace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (pdata->sub_sensor_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) rk1608_get_link_sensor_timing(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int rk1608_get_reso_dist(struct rk1608_fmt_inf *fmt_inf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct v4l2_subdev_format *fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct v4l2_mbus_framefmt *framefmt = &fmt->format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return abs(fmt_inf->mf.width - framefmt->width) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) abs(fmt_inf->mf.height - framefmt->height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int rk1608_set_fmt(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct v4l2_subdev_format *fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct v4l2_ctrl *remote_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) u32 i, idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int dist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int cur_best_fit_dist = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) for (i = 0; i < pdata->fmt_inf_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) dist = rk1608_get_reso_dist(&pdata->fmt_inf[i], fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) cur_best_fit_dist = dist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pdata->fmt_inf_idx = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pdata->rk1608_sd->grp_id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) v4l2_subdev_call(pdata->rk1608_sd, pad, set_fmt, cfg, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) V4L2_CID_HBLANK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (remote_ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) v4l2_ctrl_g_ctrl(remote_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) __v4l2_ctrl_modify_range(pdata->hblank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) remote_ctrl->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) remote_ctrl->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) remote_ctrl->step,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) remote_ctrl->default_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) V4L2_CID_VBLANK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (remote_ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) v4l2_ctrl_g_ctrl(remote_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) __v4l2_ctrl_modify_range(pdata->vblank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) remote_ctrl->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) remote_ctrl->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) remote_ctrl->step,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) remote_ctrl->default_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static int rk1608_g_frame_interval(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct v4l2_subdev_frame_interval *fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) link_sensor = i2c_get_clientdata(pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ret = v4l2_subdev_call(link_sensor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) video,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) g_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) dev_info(pdata->dev, "get link interval fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!(pdata->rk1608_sd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev_info(pdata->dev, "pdata->rk1608_sd NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) pdata->rk1608_sd->grp_id = sd->grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) v4l2_subdev_call(pdata->rk1608_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) video,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) g_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int rk1608_s_frame_interval(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct v4l2_subdev_frame_interval *fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static int rk1608_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct v4l2_mbus_config *config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) u32 val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) val = 1 << (pdata->fmt_inf[pdata->fmt_inf_idx].mipi_lane_out - 1) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) V4L2_MBUS_CSI2_CHANNEL_0 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) config->type = V4L2_MBUS_CSI2_DPHY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) config->flags = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static long rk1608_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) long ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case PREISP_CMD_SAVE_HDRAE_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ret = v4l2_subdev_call(pdata->rk1608_sd, core, ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) case PREISP_CMD_SET_HDRAE_EXP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) case RKMODULE_GET_MODULE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) case RKMODULE_AWB_CFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case PREISP_DISP_SET_FRAME_OUTPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) case PREISP_DISP_SET_FRAME_FORMAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) case PREISP_DISP_SET_FRAME_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) case PREISP_DISP_SET_PRO_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) case PREISP_DISP_SET_PRO_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) case PREISP_DISP_SET_DENOISE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) case PREISP_DISP_WRITE_EEPROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) case PREISP_DISP_READ_EEPROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) case PREISP_DISP_SET_LED_ON_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) case RKMODULE_SET_QUICK_STREAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) mutex_lock(&rk1608_dphy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) pdata->rk1608_sd->grp_id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ret = v4l2_subdev_call(pdata->rk1608_sd, core, ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) mutex_unlock(&rk1608_dphy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) case RKMODULE_GET_CSI_DPHY_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) link_sensor = i2c_get_clientdata(pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ret = v4l2_subdev_call(link_sensor, core, ioctl, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ret = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static long rk1608_compat_ioctl32(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void __user *up = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct preisp_hdrae_exp_s hdrae_exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct rkmodule_inf *inf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct rkmodule_awb_cfg *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct rkmodule_csi_dphy_param *dphy_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) u32 stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) long ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) case PREISP_CMD_SET_HDRAE_EXP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (copy_from_user(&hdrae_exp, up, sizeof(hdrae_exp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return rk1608_ioctl(sd, cmd, &hdrae_exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) case RKMODULE_GET_MODULE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) inf = kzalloc(sizeof(*inf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!inf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ret = rk1608_ioctl(sd, cmd, inf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (copy_to_user(up, inf, sizeof(*inf))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) kfree(inf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) kfree(inf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) case RKMODULE_AWB_CFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (copy_from_user(cfg, up, sizeof(*cfg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ret = rk1608_ioctl(sd, cmd, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) kfree(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) case RKMODULE_SET_QUICK_STREAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) ret = copy_from_user(&stream, up, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ret = rk1608_ioctl(sd, cmd, &stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) case RKMODULE_GET_CSI_DPHY_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) dphy_param = kzalloc(sizeof(*dphy_param), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!dphy_param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (copy_from_user(dphy_param, up, sizeof(*dphy_param)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ret = rk1608_ioctl(sd, cmd, dphy_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) kfree(dphy_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ret = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static int rk1608_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct v4l2_ctrl *remote_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct rk1608_dphy *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) container_of(ctrl->handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct rk1608_dphy, ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) pdata->rk1608_sd->grp_id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) ctrl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (remote_ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ctrl->val = v4l2_ctrl_g_ctrl(remote_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) __v4l2_ctrl_modify_range(ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) remote_ctrl->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) remote_ctrl->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) remote_ctrl->step,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) remote_ctrl->default_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static int rk1608_set_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct v4l2_ctrl *remote_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) struct rk1608_dphy *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) container_of(ctrl->handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct rk1608_dphy, ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) pdata->rk1608_sd->grp_id = pdata->sd.grp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) remote_ctrl = v4l2_ctrl_find(pdata->rk1608_sd->ctrl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ctrl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (remote_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ret = v4l2_ctrl_s_ctrl(remote_ctrl, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) #define CROP_START(SRC, DST) (((SRC) - (DST)) / 2 / 4 * 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int rk1608_get_selection(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct v4l2_subdev_selection *sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) u32 idx = pdata->fmt_inf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) u32 width = pdata->fmt_inf[idx].mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) u32 height = pdata->fmt_inf[idx].mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (sel->target != V4L2_SEL_TGT_CROP_BOUNDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) link_sensor = i2c_get_clientdata(pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ret = v4l2_subdev_call(link_sensor, pad, get_selection, NULL, sel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (pdata->fmt_inf[idx].hcrop && pdata->fmt_inf[idx].vcrop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) width = pdata->fmt_inf[idx].hcrop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) height = pdata->fmt_inf[idx].vcrop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) sel->r.left = CROP_START(pdata->fmt_inf[idx].mf.width, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) sel->r.top = CROP_START(pdata->fmt_inf[idx].mf.height, height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) sel->r.width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) sel->r.height = height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static int rk1608_enum_frame_interval(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct v4l2_subdev_pad_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) struct v4l2_subdev_frame_interval_enum *fie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct rk1608_dphy *pdata = to_state(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) u32 idx = pdata->fmt_inf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct v4l2_fract max_fps = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) .numerator = 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) .denominator = 300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct v4l2_subdev *link_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (!IS_ERR_OR_NULL(pdata->link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) link_sensor = i2c_get_clientdata(pdata->link_sensor_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (IS_ERR_OR_NULL(link_sensor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) dev_err(pdata->dev, "can not get link sensor i2c client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) ret = v4l2_subdev_call(link_sensor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) enum_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) fie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (fie->index >= pdata->fmt_inf_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) fie->code = pdata->fmt_inf[idx].mf.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) fie->width = pdata->fmt_inf[idx].mf.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) fie->height = pdata->fmt_inf[idx].mf.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) fie->interval = max_fps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static const struct v4l2_ctrl_ops rk1608_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) .g_volatile_ctrl = rk1608_g_volatile_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) .s_ctrl = rk1608_set_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static const struct v4l2_ctrl_config rk1608_priv_ctrls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .ops = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .id = CIFISP_CID_EMB_VC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .type = V4L2_CTRL_TYPE_INTEGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) .name = "Embedded visual channel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .min = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .max = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .def = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .step = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) .ops = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) .id = CIFISP_CID_EMB_DT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .type = V4L2_CTRL_TYPE_INTEGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) .name = "Embedded data type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .min = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .max = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .def = 0x30,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .step = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static int rk1608_initialize_controls(struct rk1608_dphy *dphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) u64 pixel_rate, pixel_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) u32 idx = dphy->fmt_inf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) struct v4l2_ctrl_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) unsigned long flags = V4L2_CTRL_FLAG_VOLATILE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) handler = &dphy->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ret = v4l2_ctrl_handler_init(handler, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) dphy->link_freq = v4l2_ctrl_new_int_menu(handler, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) V4L2_CID_LINK_FREQ, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 0, &dphy->link_freqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (dphy->link_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) dphy->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) switch (dphy->fmt_inf[idx].data_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) case 0x2b:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) pixel_bit = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) case 0x2c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) pixel_bit = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) pixel_bit = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) pixel_rate = dphy->link_freqs * dphy->fmt_inf[idx].mipi_lane * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) do_div(pixel_rate, pixel_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) dphy->pixel_rate = v4l2_ctrl_new_std(handler, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) V4L2_CID_PIXEL_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 0, pixel_rate, 1, pixel_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) dphy->hblank = v4l2_ctrl_new_std(handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) &rk1608_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) V4L2_CID_HBLANK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 0, 0x7FFFFFFF, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (dphy->hblank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) dphy->hblank->flags |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) dphy->vblank = v4l2_ctrl_new_std(handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) &rk1608_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) V4L2_CID_VBLANK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 0, 0x7FFFFFFF, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (dphy->vblank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) dphy->vblank->flags |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) dphy->exposure = v4l2_ctrl_new_std(handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) &rk1608_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) V4L2_CID_EXPOSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 0, 0x7FFFFFFF, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (dphy->exposure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) dphy->exposure->flags |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) dphy->gain = v4l2_ctrl_new_std(handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) &rk1608_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) V4L2_CID_ANALOGUE_GAIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 0, 0x7FFFFFFF, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (dphy->gain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) dphy->gain->flags |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) for (i = 0; i < ARRAY_SIZE(rk1608_priv_ctrls); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) v4l2_ctrl_new_custom(handler, &rk1608_priv_ctrls[i], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (handler->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ret = handler->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) dev_err(dphy->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) "Failed to init controls(%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) goto err_free_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) dphy->sd.ctrl_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) err_free_handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) v4l2_ctrl_handler_free(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static const struct v4l2_subdev_internal_ops dphy_subdev_internal_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .open = rk1608_s_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) .close = rk1608_s_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static const struct v4l2_subdev_video_ops rk1608_subdev_video_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) .s_stream = rk1608_s_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) .g_frame_interval = rk1608_g_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) .s_frame_interval = rk1608_s_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) static const struct v4l2_subdev_pad_ops rk1608_subdev_pad_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) .enum_mbus_code = rk1608_enum_mbus_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) .enum_frame_size = rk1608_enum_frame_sizes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) .get_fmt = rk1608_get_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) .set_fmt = rk1608_set_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) .get_mbus_config = rk1608_g_mbus_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) .get_selection = rk1608_get_selection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) .enum_frame_interval = rk1608_enum_frame_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) static const struct v4l2_subdev_core_ops rk1608_core_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) .s_power = rk1608_sensor_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) .ioctl = rk1608_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) .compat_ioctl32 = rk1608_compat_ioctl32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static const struct v4l2_subdev_ops dphy_subdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) .core = &rk1608_core_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) .video = &rk1608_subdev_video_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) .pad = &rk1608_subdev_pad_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static int rk1608_dphy_dt_property(struct rk1608_dphy *dphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct device_node *node = dphy->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) struct device_node *parent_node = of_node_get(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct device_node *prev_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) struct i2c_client *link_sensor_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) u32 idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) u32 sub_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ret = of_property_read_u32(node, "id", &dphy->sd.grp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) dev_warn(dphy->dev, "Can not get id!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) ret = of_property_read_u32(node, "cam_nums", &dphy->cam_nums);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) dev_warn(dphy->dev, "Can not get cam_nums!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) ret = of_property_read_u32(node, "in_mipi", &dphy->in_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) dev_warn(dphy->dev, "Can not get in_mipi!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) ret = of_property_read_u32(node, "out_mipi", &dphy->out_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) dev_warn(dphy->dev, "Can not get out_mipi!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ret = of_property_read_u64(node, "link-freqs", &dphy->link_freqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) dev_warn(dphy->dev, "Can not get link_freqs!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) ret = of_property_read_u32(node, "sensor_i2c_bus", &dphy->i2c_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) dev_warn(dphy->dev, "Can not get sensor_i2c_bus!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) ret = of_property_read_u32(node, "sensor_i2c_addr", &dphy->i2c_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) dev_warn(dphy->dev, "Can not get sensor_i2c_addr!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ret = of_property_read_string(node, "sensor-name", &dphy->sensor_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) dev_warn(dphy->dev, "Can not get sensor-name!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) while (!IS_ERR_OR_NULL(node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) of_get_next_child(parent_node, prev_node))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (!strncasecmp(node->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) "format-config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) strlen("format-config"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) ret = of_property_read_u32(node, "data_type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) &dphy->fmt_inf[idx].data_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) dev_warn(dphy->dev, "Can not get data_type!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ret = of_property_read_u32(node, "mipi_lane",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) &dphy->fmt_inf[idx].mipi_lane);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) dev_warn(dphy->dev, "Can not get mipi_lane!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) ret = of_property_read_u32(node, "mipi_lane_out",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) &dphy->fmt_inf[idx].mipi_lane_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) dev_warn(dphy->dev, "Can not get mipi_lane_out!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) ret = of_property_read_u32(node, "field",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) &dphy->fmt_inf[idx].mf.field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) dev_warn(dphy->dev, "Can not get field!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ret = of_property_read_u32(node, "colorspace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) &dphy->fmt_inf[idx].mf.colorspace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) dev_warn(dphy->dev, "Can not get colorspace!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ret = of_property_read_u32(node, "code",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) &dphy->fmt_inf[idx].mf.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) dev_warn(dphy->dev, "Can not get code!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) ret = of_property_read_u32(node, "width",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) &dphy->fmt_inf[idx].mf.width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) dev_warn(dphy->dev, "Can not get width!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) ret = of_property_read_u32(node, "height",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) &dphy->fmt_inf[idx].mf.height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) dev_warn(dphy->dev, "Can not get height!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) ret = of_property_read_u32(node, "hactive",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) &dphy->fmt_inf[idx].hactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) dev_warn(dphy->dev, "Can not get hactive!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) ret = of_property_read_u32(node, "vactive",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) &dphy->fmt_inf[idx].vactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) dev_warn(dphy->dev, "Can not get vactive!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) ret = of_property_read_u32(node, "htotal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) &dphy->fmt_inf[idx].htotal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) dev_warn(dphy->dev, "Can not get htotal!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) ret = of_property_read_u32(node, "vtotal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) &dphy->fmt_inf[idx].vtotal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) dev_warn(dphy->dev, "Can not get vtotal!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) ret = of_property_read_u32_array(node, "inch0-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) (u32 *)&dphy->fmt_inf[idx].in_ch[0], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) dev_warn(dphy->dev, "Can not get inch0-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) ret = of_property_read_u32_array(node, "inch1-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) (u32 *)&dphy->fmt_inf[idx].in_ch[1], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) dev_info(dphy->dev, "Can not get inch1-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) ret = of_property_read_u32_array(node, "inch2-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) (u32 *)&dphy->fmt_inf[idx].in_ch[2], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) dev_info(dphy->dev, "Can not get inch2-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) ret = of_property_read_u32_array(node, "inch3-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) (u32 *)&dphy->fmt_inf[idx].in_ch[3], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) dev_info(dphy->dev, "Can not get inch3-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) ret = of_property_read_u32_array(node, "outch0-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) (u32 *)&dphy->fmt_inf[idx].out_ch[0], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) dev_warn(dphy->dev, "Can not get outch0-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) ret = of_property_read_u32_array(node, "outch1-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) (u32 *)&dphy->fmt_inf[idx].out_ch[1], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) dev_info(dphy->dev, "Can not get outch1-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) ret = of_property_read_u32_array(node, "outch2-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) (u32 *)&dphy->fmt_inf[idx].out_ch[2], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) dev_info(dphy->dev, "Can not get outch2-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) ret = of_property_read_u32_array(node, "outch3-info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) (u32 *)&dphy->fmt_inf[idx].out_ch[3], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) dev_info(dphy->dev, "Can not get outch3-info!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) ret = of_property_read_u32(node, "hcrop",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) &dphy->fmt_inf[idx].hcrop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) dev_warn(dphy->dev, "Can not get hcrop!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) ret = of_property_read_u32(node, "vcrop",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) &dphy->fmt_inf[idx].vcrop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) dev_warn(dphy->dev, "Can not get vcrop!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) of_node_put(prev_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) prev_node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) dphy->fmt_inf_num = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) prev_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) /* get virtual sub sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) while (!IS_ERR_OR_NULL(node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) of_get_next_child(parent_node, prev_node))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (!strncasecmp(node->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) "virtual-sub-sensor-config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) strlen("virtual-sub-sensor-config"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (sub_idx >= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) dev_err(dphy->dev, "get too mach sub_sensor node, max 4.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) ret = of_property_read_u32(node, "id",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) &dphy->sub_sensor[sub_idx].id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) dev_warn(dphy->dev, "Can not get sub sensor id!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) dev_info(dphy->dev, "get sub sensor id:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) dphy->sub_sensor[sub_idx].id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ret = of_property_read_u32(node, "in_mipi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) &dphy->sub_sensor[sub_idx].in_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) dev_warn(dphy->dev, "Can not get sub sensor in_mipi!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) dev_info(dphy->dev, "get sub sensor in_mipi:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) dphy->sub_sensor[sub_idx].in_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ret = of_property_read_u32(node, "out_mipi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) &dphy->sub_sensor[sub_idx].out_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) dev_warn(dphy->dev, "Can not get sub sensor out_mipi!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) dev_info(dphy->dev, "get sub sensor out_mipi:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) dphy->sub_sensor[sub_idx].out_mipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) sub_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) of_node_put(prev_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) prev_node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) dphy->sub_sensor_num = sub_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) node = of_parse_phandle(parent_node, "link-sensor", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) dev_info(dphy->dev, "get link sensor node:%s\n", node->full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) link_sensor_client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) of_find_i2c_device_by_node(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (IS_ERR_OR_NULL(link_sensor_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) dev_err(dphy->dev, "can not get link sensor node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) dphy->link_sensor_client = link_sensor_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) dev_info(dphy->dev, "get link sensor client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) dev_err(dphy->dev, "can not get link-sensor node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /* get virtual sub sensor end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) of_node_put(prev_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) of_node_put(parent_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) static int rk1608_dphy_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) struct rk1608_dphy *dphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) struct v4l2_subdev *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) struct device_node *node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) char facing[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) if (!dphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) &dphy->module_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) &dphy->module_facing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) &dphy->module_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) &dphy->len_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) dev_err(dphy->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) "could not get module information!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) dphy->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) platform_set_drvdata(pdev, dphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) sd = &dphy->sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) sd->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) v4l2_subdev_init(sd, &dphy_subdev_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) rk1608_dphy_dt_property(dphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) memset(facing, 0, sizeof(facing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (strcmp(dphy->module_facing, "back") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) facing[0] = 'b';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) facing[0] = 'f';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s RK1608-dphy%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) dphy->module_index, facing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) RK1608_DPHY_NAME, sd->grp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) rk1608_initialize_controls(dphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) sd->internal_ops = &dphy_subdev_internal_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) dphy->pad.flags = MEDIA_PAD_FL_SOURCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) ret = media_entity_pads_init(&sd->entity, 1, &dphy->pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) goto handler_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) ret = v4l2_async_register_subdev_sensor_common(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) goto register_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) dev_info(dphy->dev, "RK1608-dphy(%d) probe success!\n", sd->grp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) register_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) media_entity_cleanup(&sd->entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) handler_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) v4l2_ctrl_handler_free(dphy->sd.ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) devm_kfree(&pdev->dev, dphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static int rk1608_dphy_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct rk1608_dphy *dphy = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) v4l2_async_unregister_subdev(&dphy->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) media_entity_cleanup(&dphy->sd.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) v4l2_ctrl_handler_free(&dphy->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static const struct of_device_id dphy_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) { .compatible = "rockchip,rk1608-dphy" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) { /* sentinel */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) MODULE_DEVICE_TABLE(of, dphy_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static struct platform_driver rk1608_dphy_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) .of_match_table = of_match_ptr(dphy_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) .name = RK1608_DPHY_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) .probe = rk1608_dphy_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) .remove = rk1608_dphy_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) module_platform_driver(rk1608_dphy_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) MODULE_AUTHOR("Rockchip Camera/ISP team");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) MODULE_DESCRIPTION("A DSP driver for rk1608 chip");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) MODULE_LICENSE("GPL v2");