Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] ov9640: convert to the control framework

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
839b48df d34bfcd2

+38 -85
+37 -82
drivers/media/video/ov9640.c
··· 30 30 #include <media/soc_mediabus.h> 31 31 #include <media/v4l2-chip-ident.h> 32 32 #include <media/v4l2-common.h> 33 + #include <media/v4l2-ctrls.h> 33 34 34 35 #include "ov9640.h" 35 36 ··· 165 164 V4L2_MBUS_FMT_RGB565_2X8_LE, 166 165 }; 167 166 168 - static const struct v4l2_queryctrl ov9640_controls[] = { 169 - { 170 - .id = V4L2_CID_VFLIP, 171 - .type = V4L2_CTRL_TYPE_BOOLEAN, 172 - .name = "Flip Vertically", 173 - .minimum = 0, 174 - .maximum = 1, 175 - .step = 1, 176 - .default_value = 0, 177 - }, 178 - { 179 - .id = V4L2_CID_HFLIP, 180 - .type = V4L2_CTRL_TYPE_BOOLEAN, 181 - .name = "Flip Horizontally", 182 - .minimum = 0, 183 - .maximum = 1, 184 - .step = 1, 185 - .default_value = 0, 186 - }, 187 - }; 188 - 189 167 /* read a register */ 190 168 static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val) 191 169 { ··· 266 286 return 0; 267 287 } 268 288 269 - /* Get status of additional camera capabilities */ 270 - static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 271 - { 272 - struct ov9640_priv *priv = to_ov9640_sensor(sd); 273 - 274 - switch (ctrl->id) { 275 - case V4L2_CID_VFLIP: 276 - ctrl->value = priv->flag_vflip; 277 - break; 278 - case V4L2_CID_HFLIP: 279 - ctrl->value = priv->flag_hflip; 280 - break; 281 - } 282 - return 0; 283 - } 284 - 285 289 /* Set status of additional camera capabilities */ 286 - static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 290 + static int ov9640_s_ctrl(struct v4l2_ctrl *ctrl) 287 291 { 288 - struct i2c_client *client = v4l2_get_subdevdata(sd); 289 - struct ov9640_priv *priv = to_ov9640_sensor(sd); 290 - 291 - int ret = 0; 292 + struct ov9640_priv *priv = container_of(ctrl->handler, struct ov9640_priv, hdl); 293 + struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); 292 294 293 295 switch (ctrl->id) { 294 296 case V4L2_CID_VFLIP: 295 - priv->flag_vflip = ctrl->value; 296 - if (ctrl->value) 297 - ret = ov9640_reg_rmw(client, OV9640_MVFP, 297 + if (ctrl->val) 298 + return ov9640_reg_rmw(client, OV9640_MVFP, 298 299 OV9640_MVFP_V, 0); 299 - else 300 - ret = ov9640_reg_rmw(client, OV9640_MVFP, 301 - 0, OV9640_MVFP_V); 302 - break; 300 + return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_V); 303 301 case V4L2_CID_HFLIP: 304 - priv->flag_hflip = ctrl->value; 305 - if (ctrl->value) 306 - ret = ov9640_reg_rmw(client, OV9640_MVFP, 302 + if (ctrl->val) 303 + return ov9640_reg_rmw(client, OV9640_MVFP, 307 304 OV9640_MVFP_H, 0); 308 - else 309 - ret = ov9640_reg_rmw(client, OV9640_MVFP, 310 - 0, OV9640_MVFP_H); 311 - break; 305 + return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_H); 312 306 } 313 - 314 - return ret; 307 + return -EINVAL; 315 308 } 316 309 317 310 /* Get chip identification */ ··· 596 643 */ 597 644 598 645 ret = ov9640_reg_read(client, OV9640_PID, &pid); 646 + if (!ret) 647 + ret = ov9640_reg_read(client, OV9640_VER, &ver); 648 + if (!ret) 649 + ret = ov9640_reg_read(client, OV9640_MIDH, &midh); 650 + if (!ret) 651 + ret = ov9640_reg_read(client, OV9640_MIDL, &midl); 599 652 if (ret) 600 - goto err; 601 - 602 - ret = ov9640_reg_read(client, OV9640_VER, &ver); 603 - if (ret) 604 - goto err; 605 - 606 - ret = ov9640_reg_read(client, OV9640_MIDH, &midh); 607 - if (ret) 608 - goto err; 609 - 610 - ret = ov9640_reg_read(client, OV9640_MIDL, &midl); 611 - if (ret) 612 - goto err; 653 + return ret; 613 654 614 655 switch (VERSION(pid, ver)) { 615 656 case OV9640_V2: ··· 617 670 break; 618 671 default: 619 672 dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver); 620 - ret = -ENODEV; 621 - goto err; 673 + return -ENODEV; 622 674 } 623 675 624 676 dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", 625 677 devname, pid, ver, midh, midl); 626 678 627 - err: 628 - return ret; 679 + return v4l2_ctrl_handler_setup(&priv->hdl); 629 680 } 630 681 631 - static struct soc_camera_ops ov9640_ops = { 632 - .controls = ov9640_controls, 633 - .num_controls = ARRAY_SIZE(ov9640_controls), 682 + static const struct v4l2_ctrl_ops ov9640_ctrl_ops = { 683 + .s_ctrl = ov9640_s_ctrl, 634 684 }; 635 685 636 686 static struct v4l2_subdev_core_ops ov9640_core_ops = { 637 - .g_ctrl = ov9640_g_ctrl, 638 - .s_ctrl = ov9640_s_ctrl, 639 687 .g_chip_ident = ov9640_g_chip_ident, 640 688 #ifdef CONFIG_VIDEO_ADV_DEBUG 641 689 .g_register = ov9640_get_register, ··· 702 760 703 761 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops); 704 762 705 - icd->ops = &ov9640_ops; 763 + v4l2_ctrl_handler_init(&priv->hdl, 2); 764 + v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops, 765 + V4L2_CID_VFLIP, 0, 1, 1, 0); 766 + v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops, 767 + V4L2_CID_HFLIP, 0, 1, 1, 0); 768 + priv->subdev.ctrl_handler = &priv->hdl; 769 + if (priv->hdl.error) { 770 + int err = priv->hdl.error; 771 + 772 + kfree(priv); 773 + return err; 774 + } 706 775 707 776 ret = ov9640_video_probe(icd, client); 708 777 709 778 if (ret) { 710 - icd->ops = NULL; 779 + v4l2_ctrl_handler_free(&priv->hdl); 711 780 kfree(priv); 712 781 } 713 782 ··· 730 777 struct v4l2_subdev *sd = i2c_get_clientdata(client); 731 778 struct ov9640_priv *priv = to_ov9640_sensor(sd); 732 779 780 + v4l2_device_unregister_subdev(&priv->subdev); 781 + v4l2_ctrl_handler_free(&priv->hdl); 733 782 kfree(priv); 734 783 return 0; 735 784 }
+1 -3
drivers/media/video/ov9640.h
··· 198 198 199 199 struct ov9640_priv { 200 200 struct v4l2_subdev subdev; 201 + struct v4l2_ctrl_handler hdl; 201 202 202 203 int model; 203 204 int revision; 204 - 205 - bool flag_vflip; 206 - bool flag_hflip; 207 205 }; 208 206 209 207 #endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */