ov7740
ov7740->subdev.ctrl_handler = ctrl_hdlr;
mutex_destroy(&ov7740->mutex);
static void ov7740_free_controls(struct ov7740 *ov7740)
v4l2_ctrl_handler_free(ov7740->subdev.ctrl_handler);
mutex_destroy(&ov7740->mutex);
struct ov7740 *ov7740;
ov7740 = devm_kzalloc(&client->dev, sizeof(*ov7740), GFP_KERNEL);
if (!ov7740)
ov7740->xvclk = devm_v4l2_sensor_clk_get(&client->dev, "xvclk");
if (IS_ERR(ov7740->xvclk))
return dev_err_probe(&client->dev, PTR_ERR(ov7740->xvclk),
ret = ov7740_probe_dt(client, ov7740);
ov7740->regmap = devm_regmap_init_sccb(client, &ov7740_regmap_config);
if (IS_ERR(ov7740->regmap)) {
ret = PTR_ERR(ov7740->regmap);
sd = &ov7740->subdev;
ov7740->pad.flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(&sd->entity, 1, &ov7740->pad);
ret = ov7740_set_power(ov7740, 1);
ret = ov7740_detect(ov7740);
mutex_init(&ov7740->mutex);
ret = ov7740_init_controls(ov7740);
ov7740->fmt = &ov7740_formats[0];
ov7740->frmsize = &ov7740_framesizes[0];
ov7740_get_default_format(sd, &ov7740->format);
v4l2_ctrl_handler_free(ov7740->subdev.ctrl_handler);
ov7740_free_controls(ov7740);
ov7740_set_power(ov7740, 0);
media_entity_cleanup(&ov7740->subdev.entity);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
mutex_destroy(&ov7740->mutex);
v4l2_ctrl_handler_free(ov7740->subdev.ctrl_handler);
media_entity_cleanup(&ov7740->subdev.entity);
ov7740_free_controls(ov7740);
ov7740_set_power(ov7740, 0);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
ov7740_set_power(ov7740, 0);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
return ov7740_set_power(ov7740, 1);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
struct regmap *regmap = ov7740->regmap;
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
struct regmap *regmap = ov7740->regmap;
static int ov7740_set_power(struct ov7740 *ov7740, int on)
ret = clk_prepare_enable(ov7740->xvclk);
if (ov7740->pwdn_gpio)
gpiod_direction_output(ov7740->pwdn_gpio, 0);
if (ov7740->resetb_gpio) {
gpiod_set_value(ov7740->resetb_gpio, 1);
gpiod_set_value(ov7740->resetb_gpio, 0);
clk_disable_unprepare(ov7740->xvclk);
if (ov7740->pwdn_gpio)
gpiod_direction_output(ov7740->pwdn_gpio, 0);
static int ov7740_set_white_balance(struct ov7740 *ov7740, int awb)
struct regmap *regmap = ov7740->regmap;
ov7740->blue_balance->val);
ret = regmap_write(regmap, REG_RGAIN, ov7740->red_balance->val);
static int ov7740_get_gain(struct ov7740 *ov7740, struct v4l2_ctrl *ctrl)
struct regmap *regmap = ov7740->regmap;
ov7740->gain->val = (value1 << 8) | (value0 & 0xff);
static int ov7740_get_exp(struct ov7740 *ov7740, struct v4l2_ctrl *ctrl)
struct regmap *regmap = ov7740->regmap;
ov7740->exposure->val = (value1 << 8) | (value0 & 0xff);
struct ov7740 *ov7740 = container_of(ctrl->handler,
struct ov7740, ctrl_handler);
ret = ov7740_get_gain(ov7740, ctrl);
ret = ov7740_get_exp(ov7740, ctrl);
struct ov7740 *ov7740 = container_of(ctrl->handler,
struct ov7740, ctrl_handler);
struct i2c_client *client = v4l2_get_subdevdata(&ov7740->subdev);
struct regmap *regmap = ov7740->regmap;
ret = ov7740_set_white_balance(ov7740, ctrl->val);
ret = ov7740_set_gain(regmap, ov7740->gain->val);
ret = ov7740_set_exp(regmap, ov7740->exposure->val);
static int ov7740_start_streaming(struct ov7740 *ov7740)
if (ov7740->fmt) {
ret = regmap_multi_reg_write(ov7740->regmap,
ov7740->fmt->regs,
ov7740->fmt->reg_num);
if (ov7740->frmsize) {
ret = regmap_multi_reg_write(ov7740->regmap,
ov7740->frmsize->regs,
ov7740->frmsize->reg_num);
return __v4l2_ctrl_handler_setup(ov7740->subdev.ctrl_handler);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
mutex_lock(&ov7740->mutex);
ret = ov7740_start_streaming(ov7740);
mutex_unlock(&ov7740->mutex);
mutex_unlock(&ov7740->mutex);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
ov7740->format = *fmt;
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
mutex_lock(&ov7740->mutex);
mutex_unlock(&ov7740->mutex);
ov7740->fmt = ovfmt;
ov7740->frmsize = fsize;
mutex_unlock(&ov7740->mutex);
mutex_unlock(&ov7740->mutex);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
mutex_lock(&ov7740->mutex);
format->format = ov7740->format;
mutex_unlock(&ov7740->mutex);
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
format->width = ov7740->frmsize->width;
format->height = ov7740->frmsize->height;
format->colorspace = ov7740->fmt->colorspace;
format->code = ov7740->fmt->mbus_code;
struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
mutex_lock(&ov7740->mutex);
mutex_unlock(&ov7740->mutex);
struct ov7740 *ov7740)
ov7740->resetb_gpio = devm_gpiod_get_optional(&client->dev, "reset",
if (IS_ERR(ov7740->resetb_gpio)) {
return PTR_ERR(ov7740->resetb_gpio);
ov7740->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
if (IS_ERR(ov7740->pwdn_gpio)) {
return PTR_ERR(ov7740->pwdn_gpio);
static int ov7740_detect(struct ov7740 *ov7740)
struct regmap *regmap = ov7740->regmap;
static int ov7740_init_controls(struct ov7740 *ov7740)
struct i2c_client *client = v4l2_get_subdevdata(&ov7740->subdev);
struct v4l2_ctrl_handler *ctrl_hdlr = &ov7740->ctrl_handler;
ctrl_hdlr->lock = &ov7740->mutex;
ov7740->auto_wb = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->blue_balance = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->red_balance = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->brightness = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->contrast = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->saturation = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->auto_gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
ov7740->auto_exposure = v4l2_ctrl_new_std_menu(ctrl_hdlr,
v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false);
v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true);
v4l2_ctrl_auto_cluster(2, &ov7740->auto_exposure,