| .. | .. |
|---|
| 21 | 21 | #include <linux/init.h> |
|---|
| 22 | 22 | #include <linux/kernel.h> |
|---|
| 23 | 23 | #include <linux/module.h> |
|---|
| 24 | +#include <linux/regmap.h> |
|---|
| 24 | 25 | #include <linux/slab.h> |
|---|
| 25 | 26 | #include <linux/v4l2-mediabus.h> |
|---|
| 26 | 27 | #include <linux/videodev2.h> |
|---|
| .. | .. |
|---|
| 29 | 30 | |
|---|
| 30 | 31 | #include <media/v4l2-ctrls.h> |
|---|
| 31 | 32 | #include <media/v4l2-device.h> |
|---|
| 33 | +#include <media/v4l2-event.h> |
|---|
| 32 | 34 | #include <media/v4l2-image-sizes.h> |
|---|
| 33 | 35 | #include <media/v4l2-subdev.h> |
|---|
| 34 | 36 | |
|---|
| .. | .. |
|---|
| 414 | 416 | struct v4l2_subdev subdev; |
|---|
| 415 | 417 | struct v4l2_ctrl_handler hdl; |
|---|
| 416 | 418 | struct clk *clk; |
|---|
| 419 | + struct regmap *regmap; |
|---|
| 417 | 420 | struct ov772x_camera_info *info; |
|---|
| 418 | 421 | struct gpio_desc *pwdn_gpio; |
|---|
| 419 | 422 | struct gpio_desc *rstb_gpio; |
|---|
| .. | .. |
|---|
| 549 | 552 | return container_of(sd, struct ov772x_priv, subdev); |
|---|
| 550 | 553 | } |
|---|
| 551 | 554 | |
|---|
| 552 | | -static int ov772x_read(struct i2c_client *client, u8 addr) |
|---|
| 553 | | -{ |
|---|
| 554 | | - int ret; |
|---|
| 555 | | - u8 val; |
|---|
| 556 | | - |
|---|
| 557 | | - ret = i2c_master_send(client, &addr, 1); |
|---|
| 558 | | - if (ret < 0) |
|---|
| 559 | | - return ret; |
|---|
| 560 | | - ret = i2c_master_recv(client, &val, 1); |
|---|
| 561 | | - if (ret < 0) |
|---|
| 562 | | - return ret; |
|---|
| 563 | | - |
|---|
| 564 | | - return val; |
|---|
| 565 | | -} |
|---|
| 566 | | - |
|---|
| 567 | | -static inline int ov772x_write(struct i2c_client *client, u8 addr, u8 value) |
|---|
| 568 | | -{ |
|---|
| 569 | | - return i2c_smbus_write_byte_data(client, addr, value); |
|---|
| 570 | | -} |
|---|
| 571 | | - |
|---|
| 572 | | -static int ov772x_mask_set(struct i2c_client *client, u8 command, u8 mask, |
|---|
| 573 | | - u8 set) |
|---|
| 574 | | -{ |
|---|
| 575 | | - s32 val = ov772x_read(client, command); |
|---|
| 576 | | - |
|---|
| 577 | | - if (val < 0) |
|---|
| 578 | | - return val; |
|---|
| 579 | | - |
|---|
| 580 | | - val &= ~mask; |
|---|
| 581 | | - val |= set & mask; |
|---|
| 582 | | - |
|---|
| 583 | | - return ov772x_write(client, command, val); |
|---|
| 584 | | -} |
|---|
| 585 | | - |
|---|
| 586 | | -static int ov772x_reset(struct i2c_client *client) |
|---|
| 555 | +static int ov772x_reset(struct ov772x_priv *priv) |
|---|
| 587 | 556 | { |
|---|
| 588 | 557 | int ret; |
|---|
| 589 | 558 | |
|---|
| 590 | | - ret = ov772x_write(client, COM7, SCCB_RESET); |
|---|
| 559 | + ret = regmap_write(priv->regmap, COM7, SCCB_RESET); |
|---|
| 591 | 560 | if (ret < 0) |
|---|
| 592 | 561 | return ret; |
|---|
| 593 | 562 | |
|---|
| 594 | 563 | usleep_range(1000, 5000); |
|---|
| 595 | 564 | |
|---|
| 596 | | - return ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE); |
|---|
| 565 | + return regmap_update_bits(priv->regmap, COM2, SOFT_SLEEP_MODE, |
|---|
| 566 | + SOFT_SLEEP_MODE); |
|---|
| 597 | 567 | } |
|---|
| 598 | 568 | |
|---|
| 599 | 569 | /* |
|---|
| .. | .. |
|---|
| 611 | 581 | if (priv->streaming == enable) |
|---|
| 612 | 582 | goto done; |
|---|
| 613 | 583 | |
|---|
| 614 | | - ret = ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, |
|---|
| 615 | | - enable ? 0 : SOFT_SLEEP_MODE); |
|---|
| 584 | + ret = regmap_update_bits(priv->regmap, COM2, SOFT_SLEEP_MODE, |
|---|
| 585 | + enable ? 0 : SOFT_SLEEP_MODE); |
|---|
| 616 | 586 | if (ret) |
|---|
| 617 | 587 | goto done; |
|---|
| 618 | 588 | |
|---|
| .. | .. |
|---|
| 657 | 627 | const struct ov772x_color_format *cfmt, |
|---|
| 658 | 628 | const struct ov772x_win_size *win) |
|---|
| 659 | 629 | { |
|---|
| 660 | | - struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); |
|---|
| 661 | 630 | unsigned long fin = clk_get_rate(priv->clk); |
|---|
| 662 | 631 | unsigned int best_diff; |
|---|
| 663 | 632 | unsigned int fsize; |
|---|
| .. | .. |
|---|
| 723 | 692 | } |
|---|
| 724 | 693 | } |
|---|
| 725 | 694 | |
|---|
| 726 | | - ret = ov772x_write(client, COM4, com4 | COM4_RESERVED); |
|---|
| 695 | + ret = regmap_write(priv->regmap, COM4, com4 | COM4_RESERVED); |
|---|
| 727 | 696 | if (ret < 0) |
|---|
| 728 | 697 | return ret; |
|---|
| 729 | 698 | |
|---|
| 730 | | - ret = ov772x_write(client, CLKRC, clkrc | CLKRC_RESERVED); |
|---|
| 699 | + ret = regmap_write(priv->regmap, CLKRC, clkrc | CLKRC_RESERVED); |
|---|
| 731 | 700 | if (ret < 0) |
|---|
| 732 | 701 | return ret; |
|---|
| 733 | 702 | |
|---|
| .. | .. |
|---|
| 788 | 757 | { |
|---|
| 789 | 758 | struct ov772x_priv *priv = container_of(ctrl->handler, |
|---|
| 790 | 759 | struct ov772x_priv, hdl); |
|---|
| 791 | | - struct v4l2_subdev *sd = &priv->subdev; |
|---|
| 792 | | - struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| 760 | + struct regmap *regmap = priv->regmap; |
|---|
| 793 | 761 | int ret = 0; |
|---|
| 794 | 762 | u8 val; |
|---|
| 795 | 763 | |
|---|
| .. | .. |
|---|
| 808 | 776 | val = ctrl->val ? VFLIP_IMG : 0x00; |
|---|
| 809 | 777 | if (priv->info && (priv->info->flags & OV772X_FLAG_VFLIP)) |
|---|
| 810 | 778 | val ^= VFLIP_IMG; |
|---|
| 811 | | - return ov772x_mask_set(client, COM3, VFLIP_IMG, val); |
|---|
| 779 | + return regmap_update_bits(regmap, COM3, VFLIP_IMG, val); |
|---|
| 812 | 780 | case V4L2_CID_HFLIP: |
|---|
| 813 | 781 | val = ctrl->val ? HFLIP_IMG : 0x00; |
|---|
| 814 | 782 | if (priv->info && (priv->info->flags & OV772X_FLAG_HFLIP)) |
|---|
| 815 | 783 | val ^= HFLIP_IMG; |
|---|
| 816 | | - return ov772x_mask_set(client, COM3, HFLIP_IMG, val); |
|---|
| 784 | + return regmap_update_bits(regmap, COM3, HFLIP_IMG, val); |
|---|
| 817 | 785 | case V4L2_CID_BAND_STOP_FILTER: |
|---|
| 818 | 786 | if (!ctrl->val) { |
|---|
| 819 | 787 | /* Switch the filter off, it is on now */ |
|---|
| 820 | | - ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff); |
|---|
| 788 | + ret = regmap_update_bits(regmap, BDBASE, 0xff, 0xff); |
|---|
| 821 | 789 | if (!ret) |
|---|
| 822 | | - ret = ov772x_mask_set(client, COM8, |
|---|
| 823 | | - BNDF_ON_OFF, 0); |
|---|
| 790 | + ret = regmap_update_bits(regmap, COM8, |
|---|
| 791 | + BNDF_ON_OFF, 0); |
|---|
| 824 | 792 | } else { |
|---|
| 825 | 793 | /* Switch the filter on, set AEC low limit */ |
|---|
| 826 | 794 | val = 256 - ctrl->val; |
|---|
| 827 | | - ret = ov772x_mask_set(client, COM8, |
|---|
| 828 | | - BNDF_ON_OFF, BNDF_ON_OFF); |
|---|
| 795 | + ret = regmap_update_bits(regmap, COM8, |
|---|
| 796 | + BNDF_ON_OFF, BNDF_ON_OFF); |
|---|
| 829 | 797 | if (!ret) |
|---|
| 830 | | - ret = ov772x_mask_set(client, BDBASE, |
|---|
| 831 | | - 0xff, val); |
|---|
| 798 | + ret = regmap_update_bits(regmap, BDBASE, |
|---|
| 799 | + 0xff, val); |
|---|
| 832 | 800 | } |
|---|
| 833 | 801 | |
|---|
| 834 | 802 | return ret; |
|---|
| .. | .. |
|---|
| 841 | 809 | static int ov772x_g_register(struct v4l2_subdev *sd, |
|---|
| 842 | 810 | struct v4l2_dbg_register *reg) |
|---|
| 843 | 811 | { |
|---|
| 844 | | - struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| 812 | + struct ov772x_priv *priv = to_ov772x(sd); |
|---|
| 845 | 813 | int ret; |
|---|
| 814 | + unsigned int val; |
|---|
| 846 | 815 | |
|---|
| 847 | 816 | reg->size = 1; |
|---|
| 848 | 817 | if (reg->reg > 0xff) |
|---|
| 849 | 818 | return -EINVAL; |
|---|
| 850 | 819 | |
|---|
| 851 | | - ret = ov772x_read(client, reg->reg); |
|---|
| 820 | + ret = regmap_read(priv->regmap, reg->reg, &val); |
|---|
| 852 | 821 | if (ret < 0) |
|---|
| 853 | 822 | return ret; |
|---|
| 854 | 823 | |
|---|
| 855 | | - reg->val = (__u64)ret; |
|---|
| 824 | + reg->val = (__u64)val; |
|---|
| 856 | 825 | |
|---|
| 857 | 826 | return 0; |
|---|
| 858 | 827 | } |
|---|
| .. | .. |
|---|
| 860 | 829 | static int ov772x_s_register(struct v4l2_subdev *sd, |
|---|
| 861 | 830 | const struct v4l2_dbg_register *reg) |
|---|
| 862 | 831 | { |
|---|
| 863 | | - struct i2c_client *client = v4l2_get_subdevdata(sd); |
|---|
| 832 | + struct ov772x_priv *priv = to_ov772x(sd); |
|---|
| 864 | 833 | |
|---|
| 865 | 834 | if (reg->reg > 0xff || |
|---|
| 866 | 835 | reg->val > 0xff) |
|---|
| 867 | 836 | return -EINVAL; |
|---|
| 868 | 837 | |
|---|
| 869 | | - return ov772x_write(client, reg->reg, reg->val); |
|---|
| 838 | + return regmap_write(priv->regmap, reg->reg, reg->val); |
|---|
| 870 | 839 | } |
|---|
| 871 | 840 | #endif |
|---|
| 872 | 841 | |
|---|
| .. | .. |
|---|
| 1005 | 974 | |
|---|
| 1006 | 975 | static int ov772x_edgectrl(struct ov772x_priv *priv) |
|---|
| 1007 | 976 | { |
|---|
| 1008 | | - struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); |
|---|
| 977 | + struct regmap *regmap = priv->regmap; |
|---|
| 1009 | 978 | int ret; |
|---|
| 1010 | 979 | |
|---|
| 1011 | 980 | if (!priv->info) |
|---|
| .. | .. |
|---|
| 1019 | 988 | * Remove it when manual mode. |
|---|
| 1020 | 989 | */ |
|---|
| 1021 | 990 | |
|---|
| 1022 | | - ret = ov772x_mask_set(client, DSPAUTO, EDGE_ACTRL, 0x00); |
|---|
| 991 | + ret = regmap_update_bits(regmap, DSPAUTO, EDGE_ACTRL, 0x00); |
|---|
| 1023 | 992 | if (ret < 0) |
|---|
| 1024 | 993 | return ret; |
|---|
| 1025 | 994 | |
|---|
| 1026 | | - ret = ov772x_mask_set(client, |
|---|
| 1027 | | - EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK, |
|---|
| 1028 | | - priv->info->edgectrl.threshold); |
|---|
| 995 | + ret = regmap_update_bits(regmap, EDGE_TRSHLD, |
|---|
| 996 | + OV772X_EDGE_THRESHOLD_MASK, |
|---|
| 997 | + priv->info->edgectrl.threshold); |
|---|
| 1029 | 998 | if (ret < 0) |
|---|
| 1030 | 999 | return ret; |
|---|
| 1031 | 1000 | |
|---|
| 1032 | | - ret = ov772x_mask_set(client, |
|---|
| 1033 | | - EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK, |
|---|
| 1034 | | - priv->info->edgectrl.strength); |
|---|
| 1001 | + ret = regmap_update_bits(regmap, EDGE_STRNGT, |
|---|
| 1002 | + OV772X_EDGE_STRENGTH_MASK, |
|---|
| 1003 | + priv->info->edgectrl.strength); |
|---|
| 1035 | 1004 | if (ret < 0) |
|---|
| 1036 | 1005 | return ret; |
|---|
| 1037 | 1006 | |
|---|
| .. | .. |
|---|
| 1041 | 1010 | * |
|---|
| 1042 | 1011 | * Set upper and lower limit. |
|---|
| 1043 | 1012 | */ |
|---|
| 1044 | | - ret = ov772x_mask_set(client, |
|---|
| 1045 | | - EDGE_UPPER, OV772X_EDGE_UPPER_MASK, |
|---|
| 1046 | | - priv->info->edgectrl.upper); |
|---|
| 1013 | + ret = regmap_update_bits(regmap, EDGE_UPPER, |
|---|
| 1014 | + OV772X_EDGE_UPPER_MASK, |
|---|
| 1015 | + priv->info->edgectrl.upper); |
|---|
| 1047 | 1016 | if (ret < 0) |
|---|
| 1048 | 1017 | return ret; |
|---|
| 1049 | 1018 | |
|---|
| 1050 | | - ret = ov772x_mask_set(client, |
|---|
| 1051 | | - EDGE_LOWER, OV772X_EDGE_LOWER_MASK, |
|---|
| 1052 | | - priv->info->edgectrl.lower); |
|---|
| 1019 | + ret = regmap_update_bits(regmap, EDGE_LOWER, |
|---|
| 1020 | + OV772X_EDGE_LOWER_MASK, |
|---|
| 1021 | + priv->info->edgectrl.lower); |
|---|
| 1053 | 1022 | if (ret < 0) |
|---|
| 1054 | 1023 | return ret; |
|---|
| 1055 | 1024 | } |
|---|
| .. | .. |
|---|
| 1061 | 1030 | const struct ov772x_color_format *cfmt, |
|---|
| 1062 | 1031 | const struct ov772x_win_size *win) |
|---|
| 1063 | 1032 | { |
|---|
| 1064 | | - struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); |
|---|
| 1065 | 1033 | int ret; |
|---|
| 1066 | 1034 | u8 val; |
|---|
| 1067 | 1035 | |
|---|
| 1068 | 1036 | /* Reset hardware. */ |
|---|
| 1069 | | - ov772x_reset(client); |
|---|
| 1037 | + ov772x_reset(priv); |
|---|
| 1070 | 1038 | |
|---|
| 1071 | 1039 | /* Edge Ctrl. */ |
|---|
| 1072 | 1040 | ret = ov772x_edgectrl(priv); |
|---|
| .. | .. |
|---|
| 1074 | 1042 | return ret; |
|---|
| 1075 | 1043 | |
|---|
| 1076 | 1044 | /* Format and window size. */ |
|---|
| 1077 | | - ret = ov772x_write(client, HSTART, win->rect.left >> 2); |
|---|
| 1045 | + ret = regmap_write(priv->regmap, HSTART, win->rect.left >> 2); |
|---|
| 1078 | 1046 | if (ret < 0) |
|---|
| 1079 | 1047 | goto ov772x_set_fmt_error; |
|---|
| 1080 | | - ret = ov772x_write(client, HSIZE, win->rect.width >> 2); |
|---|
| 1048 | + ret = regmap_write(priv->regmap, HSIZE, win->rect.width >> 2); |
|---|
| 1081 | 1049 | if (ret < 0) |
|---|
| 1082 | 1050 | goto ov772x_set_fmt_error; |
|---|
| 1083 | | - ret = ov772x_write(client, VSTART, win->rect.top >> 1); |
|---|
| 1051 | + ret = regmap_write(priv->regmap, VSTART, win->rect.top >> 1); |
|---|
| 1084 | 1052 | if (ret < 0) |
|---|
| 1085 | 1053 | goto ov772x_set_fmt_error; |
|---|
| 1086 | | - ret = ov772x_write(client, VSIZE, win->rect.height >> 1); |
|---|
| 1054 | + ret = regmap_write(priv->regmap, VSIZE, win->rect.height >> 1); |
|---|
| 1087 | 1055 | if (ret < 0) |
|---|
| 1088 | 1056 | goto ov772x_set_fmt_error; |
|---|
| 1089 | | - ret = ov772x_write(client, HOUTSIZE, win->rect.width >> 2); |
|---|
| 1057 | + ret = regmap_write(priv->regmap, HOUTSIZE, win->rect.width >> 2); |
|---|
| 1090 | 1058 | if (ret < 0) |
|---|
| 1091 | 1059 | goto ov772x_set_fmt_error; |
|---|
| 1092 | | - ret = ov772x_write(client, VOUTSIZE, win->rect.height >> 1); |
|---|
| 1060 | + ret = regmap_write(priv->regmap, VOUTSIZE, win->rect.height >> 1); |
|---|
| 1093 | 1061 | if (ret < 0) |
|---|
| 1094 | 1062 | goto ov772x_set_fmt_error; |
|---|
| 1095 | | - ret = ov772x_write(client, HREF, |
|---|
| 1063 | + ret = regmap_write(priv->regmap, HREF, |
|---|
| 1096 | 1064 | ((win->rect.top & 1) << HREF_VSTART_SHIFT) | |
|---|
| 1097 | 1065 | ((win->rect.left & 3) << HREF_HSTART_SHIFT) | |
|---|
| 1098 | 1066 | ((win->rect.height & 1) << HREF_VSIZE_SHIFT) | |
|---|
| 1099 | 1067 | ((win->rect.width & 3) << HREF_HSIZE_SHIFT)); |
|---|
| 1100 | 1068 | if (ret < 0) |
|---|
| 1101 | 1069 | goto ov772x_set_fmt_error; |
|---|
| 1102 | | - ret = ov772x_write(client, EXHCH, |
|---|
| 1070 | + ret = regmap_write(priv->regmap, EXHCH, |
|---|
| 1103 | 1071 | ((win->rect.height & 1) << EXHCH_VSIZE_SHIFT) | |
|---|
| 1104 | 1072 | ((win->rect.width & 3) << EXHCH_HSIZE_SHIFT)); |
|---|
| 1105 | 1073 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 1108 | 1076 | /* Set DSP_CTRL3. */ |
|---|
| 1109 | 1077 | val = cfmt->dsp3; |
|---|
| 1110 | 1078 | if (val) { |
|---|
| 1111 | | - ret = ov772x_mask_set(client, |
|---|
| 1112 | | - DSP_CTRL3, UV_MASK, val); |
|---|
| 1079 | + ret = regmap_update_bits(priv->regmap, DSP_CTRL3, UV_MASK, val); |
|---|
| 1113 | 1080 | if (ret < 0) |
|---|
| 1114 | 1081 | goto ov772x_set_fmt_error; |
|---|
| 1115 | 1082 | } |
|---|
| 1116 | 1083 | |
|---|
| 1117 | 1084 | /* DSP_CTRL4: AEC reference point and DSP output format. */ |
|---|
| 1118 | 1085 | if (cfmt->dsp4) { |
|---|
| 1119 | | - ret = ov772x_write(client, DSP_CTRL4, cfmt->dsp4); |
|---|
| 1086 | + ret = regmap_write(priv->regmap, DSP_CTRL4, cfmt->dsp4); |
|---|
| 1120 | 1087 | if (ret < 0) |
|---|
| 1121 | 1088 | goto ov772x_set_fmt_error; |
|---|
| 1122 | 1089 | } |
|---|
| .. | .. |
|---|
| 1132 | 1099 | if (priv->hflip_ctrl->val) |
|---|
| 1133 | 1100 | val ^= HFLIP_IMG; |
|---|
| 1134 | 1101 | |
|---|
| 1135 | | - ret = ov772x_mask_set(client, |
|---|
| 1136 | | - COM3, SWAP_MASK | IMG_MASK, val); |
|---|
| 1102 | + ret = regmap_update_bits(priv->regmap, COM3, SWAP_MASK | IMG_MASK, val); |
|---|
| 1137 | 1103 | if (ret < 0) |
|---|
| 1138 | 1104 | goto ov772x_set_fmt_error; |
|---|
| 1139 | 1105 | |
|---|
| 1140 | 1106 | /* COM7: Sensor resolution and output format control. */ |
|---|
| 1141 | | - ret = ov772x_write(client, COM7, win->com7_bit | cfmt->com7); |
|---|
| 1107 | + ret = regmap_write(priv->regmap, COM7, win->com7_bit | cfmt->com7); |
|---|
| 1142 | 1108 | if (ret < 0) |
|---|
| 1143 | 1109 | goto ov772x_set_fmt_error; |
|---|
| 1144 | 1110 | |
|---|
| .. | .. |
|---|
| 1151 | 1117 | if (priv->band_filter_ctrl->val) { |
|---|
| 1152 | 1118 | unsigned short band_filter = priv->band_filter_ctrl->val; |
|---|
| 1153 | 1119 | |
|---|
| 1154 | | - ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, BNDF_ON_OFF); |
|---|
| 1120 | + ret = regmap_update_bits(priv->regmap, COM8, |
|---|
| 1121 | + BNDF_ON_OFF, BNDF_ON_OFF); |
|---|
| 1155 | 1122 | if (!ret) |
|---|
| 1156 | | - ret = ov772x_mask_set(client, BDBASE, |
|---|
| 1157 | | - 0xff, 256 - band_filter); |
|---|
| 1123 | + ret = regmap_update_bits(priv->regmap, BDBASE, |
|---|
| 1124 | + 0xff, 256 - band_filter); |
|---|
| 1158 | 1125 | if (ret < 0) |
|---|
| 1159 | 1126 | goto ov772x_set_fmt_error; |
|---|
| 1160 | 1127 | } |
|---|
| .. | .. |
|---|
| 1163 | 1130 | |
|---|
| 1164 | 1131 | ov772x_set_fmt_error: |
|---|
| 1165 | 1132 | |
|---|
| 1166 | | - ov772x_reset(client); |
|---|
| 1133 | + ov772x_reset(priv); |
|---|
| 1167 | 1134 | |
|---|
| 1168 | 1135 | return ret; |
|---|
| 1169 | 1136 | } |
|---|
| .. | .. |
|---|
| 1181 | 1148 | sel->r.top = 0; |
|---|
| 1182 | 1149 | switch (sel->target) { |
|---|
| 1183 | 1150 | case V4L2_SEL_TGT_CROP_BOUNDS: |
|---|
| 1184 | | - case V4L2_SEL_TGT_CROP_DEFAULT: |
|---|
| 1185 | 1151 | case V4L2_SEL_TGT_CROP: |
|---|
| 1186 | 1152 | sel->r.width = priv->win->rect.width; |
|---|
| 1187 | 1153 | sel->r.height = priv->win->rect.height; |
|---|
| .. | .. |
|---|
| 1277 | 1243 | return ret; |
|---|
| 1278 | 1244 | |
|---|
| 1279 | 1245 | /* Check and show product ID and manufacturer ID. */ |
|---|
| 1280 | | - pid = ov772x_read(client, PID); |
|---|
| 1281 | | - if (pid < 0) |
|---|
| 1282 | | - return pid; |
|---|
| 1283 | | - ver = ov772x_read(client, VER); |
|---|
| 1284 | | - if (ver < 0) |
|---|
| 1285 | | - return ver; |
|---|
| 1246 | + ret = regmap_read(priv->regmap, PID, &pid); |
|---|
| 1247 | + if (ret < 0) |
|---|
| 1248 | + return ret; |
|---|
| 1249 | + ret = regmap_read(priv->regmap, VER, &ver); |
|---|
| 1250 | + if (ret < 0) |
|---|
| 1251 | + return ret; |
|---|
| 1286 | 1252 | |
|---|
| 1287 | 1253 | switch (VERSION(pid, ver)) { |
|---|
| 1288 | 1254 | case OV7720: |
|---|
| .. | .. |
|---|
| 1298 | 1264 | goto done; |
|---|
| 1299 | 1265 | } |
|---|
| 1300 | 1266 | |
|---|
| 1301 | | - midh = ov772x_read(client, MIDH); |
|---|
| 1302 | | - if (midh < 0) |
|---|
| 1303 | | - return midh; |
|---|
| 1304 | | - midl = ov772x_read(client, MIDL); |
|---|
| 1305 | | - if (midl < 0) |
|---|
| 1306 | | - return midl; |
|---|
| 1267 | + ret = regmap_read(priv->regmap, MIDH, &midh); |
|---|
| 1268 | + if (ret < 0) |
|---|
| 1269 | + return ret; |
|---|
| 1270 | + ret = regmap_read(priv->regmap, MIDL, &midl); |
|---|
| 1271 | + if (ret < 0) |
|---|
| 1272 | + return ret; |
|---|
| 1307 | 1273 | |
|---|
| 1308 | 1274 | dev_info(&client->dev, |
|---|
| 1309 | 1275 | "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", |
|---|
| .. | .. |
|---|
| 1322 | 1288 | }; |
|---|
| 1323 | 1289 | |
|---|
| 1324 | 1290 | static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = { |
|---|
| 1291 | + .log_status = v4l2_ctrl_subdev_log_status, |
|---|
| 1292 | + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, |
|---|
| 1293 | + .unsubscribe_event = v4l2_event_subdev_unsubscribe, |
|---|
| 1325 | 1294 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
|---|
| 1326 | 1295 | .g_register = ov772x_g_register, |
|---|
| 1327 | 1296 | .s_register = ov772x_s_register, |
|---|
| .. | .. |
|---|
| 1383 | 1352 | * i2c_driver function |
|---|
| 1384 | 1353 | */ |
|---|
| 1385 | 1354 | |
|---|
| 1386 | | -static int ov772x_probe(struct i2c_client *client, |
|---|
| 1387 | | - const struct i2c_device_id *did) |
|---|
| 1355 | +static int ov772x_probe(struct i2c_client *client) |
|---|
| 1388 | 1356 | { |
|---|
| 1389 | 1357 | struct ov772x_priv *priv; |
|---|
| 1390 | | - struct i2c_adapter *adapter = client->adapter; |
|---|
| 1391 | 1358 | int ret; |
|---|
| 1359 | + static const struct regmap_config ov772x_regmap_config = { |
|---|
| 1360 | + .reg_bits = 8, |
|---|
| 1361 | + .val_bits = 8, |
|---|
| 1362 | + .max_register = DSPAUTO, |
|---|
| 1363 | + }; |
|---|
| 1392 | 1364 | |
|---|
| 1393 | 1365 | if (!client->dev.of_node && !client->dev.platform_data) { |
|---|
| 1394 | 1366 | dev_err(&client->dev, |
|---|
| .. | .. |
|---|
| 1396 | 1368 | return -EINVAL; |
|---|
| 1397 | 1369 | } |
|---|
| 1398 | 1370 | |
|---|
| 1399 | | - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
|---|
| 1400 | | - dev_err(&adapter->dev, |
|---|
| 1401 | | - "I2C-Adapter doesn't support SMBUS_BYTE_DATA\n"); |
|---|
| 1402 | | - return -EIO; |
|---|
| 1403 | | - } |
|---|
| 1404 | | - |
|---|
| 1405 | 1371 | priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 1406 | 1372 | if (!priv) |
|---|
| 1407 | 1373 | return -ENOMEM; |
|---|
| 1374 | + |
|---|
| 1375 | + priv->regmap = devm_regmap_init_sccb(client, &ov772x_regmap_config); |
|---|
| 1376 | + if (IS_ERR(priv->regmap)) { |
|---|
| 1377 | + dev_err(&client->dev, "Failed to allocate register map\n"); |
|---|
| 1378 | + return PTR_ERR(priv->regmap); |
|---|
| 1379 | + } |
|---|
| 1408 | 1380 | |
|---|
| 1409 | 1381 | priv->info = client->dev.platform_data; |
|---|
| 1410 | 1382 | mutex_init(&priv->lock); |
|---|
| 1411 | 1383 | |
|---|
| 1412 | 1384 | v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops); |
|---|
| 1413 | | - priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
|---|
| 1385 | + priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | |
|---|
| 1386 | + V4L2_SUBDEV_FL_HAS_EVENTS; |
|---|
| 1414 | 1387 | v4l2_ctrl_handler_init(&priv->hdl, 3); |
|---|
| 1415 | 1388 | /* Use our mutex for the controls */ |
|---|
| 1416 | 1389 | priv->hdl.lock = &priv->lock; |
|---|
| .. | .. |
|---|
| 1424 | 1397 | priv->subdev.ctrl_handler = &priv->hdl; |
|---|
| 1425 | 1398 | if (priv->hdl.error) { |
|---|
| 1426 | 1399 | ret = priv->hdl.error; |
|---|
| 1427 | | - goto error_mutex_destroy; |
|---|
| 1400 | + goto error_ctrl_free; |
|---|
| 1428 | 1401 | } |
|---|
| 1429 | 1402 | |
|---|
| 1430 | 1403 | priv->clk = clk_get(&client->dev, NULL); |
|---|
| .. | .. |
|---|
| 1473 | 1446 | clk_put(priv->clk); |
|---|
| 1474 | 1447 | error_ctrl_free: |
|---|
| 1475 | 1448 | v4l2_ctrl_handler_free(&priv->hdl); |
|---|
| 1476 | | -error_mutex_destroy: |
|---|
| 1477 | 1449 | mutex_destroy(&priv->lock); |
|---|
| 1478 | 1450 | |
|---|
| 1479 | 1451 | return ret; |
|---|
| .. | .. |
|---|
| 1512 | 1484 | .name = "ov772x", |
|---|
| 1513 | 1485 | .of_match_table = ov772x_of_match, |
|---|
| 1514 | 1486 | }, |
|---|
| 1515 | | - .probe = ov772x_probe, |
|---|
| 1487 | + .probe_new = ov772x_probe, |
|---|
| 1516 | 1488 | .remove = ov772x_remove, |
|---|
| 1517 | 1489 | .id_table = ov772x_id, |
|---|
| 1518 | 1490 | }; |
|---|