.. | .. |
---|
13 | 13 | #include <linux/module.h> |
---|
14 | 14 | #include <linux/of.h> |
---|
15 | 15 | #include <linux/of_graph.h> |
---|
| 16 | +#include <linux/of_platform.h> |
---|
16 | 17 | #include <linux/platform_device.h> |
---|
17 | 18 | #include <linux/reset.h> |
---|
18 | 19 | #include <linux/rk-camera-module.h> |
---|
19 | 20 | #include <media/v4l2-ioctl.h> |
---|
20 | 21 | #include "mipi-csi2.h" |
---|
21 | | -#include <linux/rkcif-config.h> |
---|
22 | 22 | #include <linux/regulator/consumer.h> |
---|
23 | 23 | |
---|
24 | 24 | static int csi2_debug; |
---|
.. | .. |
---|
147 | 147 | |
---|
148 | 148 | } |
---|
149 | 149 | |
---|
150 | | -static void csi2_hw_do_reset(struct csi2_dev *csi2) |
---|
| 150 | +static void csi2_hw_do_reset(struct csi2_hw *csi2_hw) |
---|
151 | 151 | { |
---|
152 | | - reset_control_assert(csi2->rsts_bulk); |
---|
| 152 | + |
---|
| 153 | + if (!csi2_hw->rsts_bulk) |
---|
| 154 | + return; |
---|
| 155 | + |
---|
| 156 | + reset_control_assert(csi2_hw->rsts_bulk); |
---|
153 | 157 | |
---|
154 | 158 | udelay(5); |
---|
155 | 159 | |
---|
156 | | - reset_control_deassert(csi2->rsts_bulk); |
---|
| 160 | + reset_control_deassert(csi2_hw->rsts_bulk); |
---|
157 | 161 | } |
---|
158 | 162 | |
---|
159 | | -static int csi2_enable_clks(struct csi2_dev *csi2) |
---|
| 163 | +static int csi2_enable_clks(struct csi2_hw *csi2_hw) |
---|
160 | 164 | { |
---|
161 | 165 | int ret = 0; |
---|
162 | 166 | |
---|
163 | | - ret = clk_bulk_prepare_enable(csi2->clks_num, csi2->clks_bulk); |
---|
| 167 | + if (!csi2_hw->clks_bulk) |
---|
| 168 | + return -EINVAL; |
---|
| 169 | + |
---|
| 170 | + ret = clk_bulk_prepare_enable(csi2_hw->clks_num, csi2_hw->clks_bulk); |
---|
164 | 171 | if (ret) |
---|
165 | | - dev_err(csi2->dev, "failed to enable clks\n"); |
---|
| 172 | + dev_err(csi2_hw->dev, "failed to enable clks\n"); |
---|
166 | 173 | |
---|
167 | 174 | return ret; |
---|
168 | 175 | } |
---|
169 | 176 | |
---|
170 | | -static void csi2_disable_clks(struct csi2_dev *csi2) |
---|
| 177 | +static void csi2_disable_clks(struct csi2_hw *csi2_hw) |
---|
171 | 178 | { |
---|
172 | | - clk_bulk_disable_unprepare(csi2->clks_num, csi2->clks_bulk); |
---|
| 179 | + if (!csi2_hw->clks_bulk) |
---|
| 180 | + return; |
---|
| 181 | + clk_bulk_disable_unprepare(csi2_hw->clks_num, csi2_hw->clks_bulk); |
---|
173 | 182 | } |
---|
174 | 183 | |
---|
175 | | -static void csi2_disable(struct csi2_dev *csi2) |
---|
| 184 | +static void csi2_disable(struct csi2_hw *csi2_hw) |
---|
176 | 185 | { |
---|
177 | | - void __iomem *base = csi2->base; |
---|
178 | | - |
---|
179 | | - write_csihost_reg(base, CSIHOST_RESETN, 0); |
---|
180 | | - write_csihost_reg(base, CSIHOST_MSK1, 0xffffffff); |
---|
181 | | - write_csihost_reg(base, CSIHOST_MSK2, 0xffffffff); |
---|
| 186 | + write_csihost_reg(csi2_hw->base, CSIHOST_RESETN, 0); |
---|
| 187 | + write_csihost_reg(csi2_hw->base, CSIHOST_MSK1, 0xffffffff); |
---|
| 188 | + write_csihost_reg(csi2_hw->base, CSIHOST_MSK2, 0xffffffff); |
---|
182 | 189 | } |
---|
183 | 190 | |
---|
184 | 191 | static int csi2_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id, |
---|
185 | 192 | struct v4l2_mbus_config *mbus); |
---|
186 | 193 | |
---|
187 | | -static void csi2_enable(struct csi2_dev *csi2, |
---|
| 194 | +static void csi2_enable(struct csi2_hw *csi2_hw, |
---|
188 | 195 | enum host_type_t host_type) |
---|
189 | 196 | { |
---|
190 | | - void __iomem *base = csi2->base; |
---|
| 197 | + void __iomem *base = csi2_hw->base; |
---|
| 198 | + struct csi2_dev *csi2 = csi2_hw->csi2; |
---|
191 | 199 | int lanes = csi2->bus.num_data_lanes; |
---|
192 | 200 | struct v4l2_mbus_config mbus; |
---|
193 | 201 | u32 val = 0; |
---|
.. | .. |
---|
225 | 233 | { |
---|
226 | 234 | enum host_type_t host_type; |
---|
227 | 235 | int ret, i; |
---|
| 236 | + int csi_idx = 0; |
---|
228 | 237 | |
---|
229 | 238 | atomic_set(&csi2->frm_sync_seq, 0); |
---|
230 | | - |
---|
231 | | - csi2_hw_do_reset(csi2); |
---|
232 | | - ret = csi2_enable_clks(csi2); |
---|
233 | | - if (ret) { |
---|
234 | | - v4l2_err(&csi2->sd, "%s: enable clks failed\n", __func__); |
---|
235 | | - return ret; |
---|
236 | | - } |
---|
237 | 239 | |
---|
238 | 240 | csi2_update_sensor_info(csi2); |
---|
239 | 241 | |
---|
.. | .. |
---|
242 | 244 | else |
---|
243 | 245 | host_type = RK_CSI_RXHOST; |
---|
244 | 246 | |
---|
245 | | - csi2_enable(csi2, host_type); |
---|
| 247 | + for (i = 0; i < csi2->csi_info.csi_num; i++) { |
---|
| 248 | + csi_idx = csi2->csi_info.csi_idx[i]; |
---|
| 249 | + csi2_hw_do_reset(csi2->csi2_hw[csi_idx]); |
---|
| 250 | + ret = csi2_enable_clks(csi2->csi2_hw[csi_idx]); |
---|
| 251 | + if (ret) { |
---|
| 252 | + v4l2_err(&csi2->sd, "%s: enable clks failed\n", __func__); |
---|
| 253 | + return ret; |
---|
| 254 | + } |
---|
| 255 | + csi2_enable(csi2->csi2_hw[csi_idx], host_type); |
---|
| 256 | + } |
---|
246 | 257 | |
---|
247 | 258 | pr_debug("stream sd: %s\n", csi2->src_sd->name); |
---|
248 | 259 | ret = v4l2_subdev_call(csi2->src_sd, video, s_stream, 1); |
---|
.. | .. |
---|
256 | 267 | return 0; |
---|
257 | 268 | |
---|
258 | 269 | err_assert_reset: |
---|
259 | | - csi2_disable(csi2); |
---|
260 | | - csi2_disable_clks(csi2); |
---|
| 270 | + for (i = 0; i < csi2->csi_info.csi_num; i++) { |
---|
| 271 | + csi_idx = csi2->csi_info.csi_idx[i]; |
---|
| 272 | + csi2_disable(csi2->csi2_hw[csi_idx]); |
---|
| 273 | + csi2_disable_clks(csi2->csi2_hw[csi_idx]); |
---|
| 274 | + } |
---|
261 | 275 | |
---|
262 | 276 | return ret; |
---|
263 | 277 | } |
---|
264 | 278 | |
---|
265 | 279 | static void csi2_stop(struct csi2_dev *csi2) |
---|
266 | 280 | { |
---|
| 281 | + int i = 0; |
---|
| 282 | + int csi_idx = 0; |
---|
| 283 | + |
---|
267 | 284 | /* stop upstream */ |
---|
268 | 285 | v4l2_subdev_call(csi2->src_sd, video, s_stream, 0); |
---|
269 | 286 | |
---|
270 | | - csi2_disable(csi2); |
---|
271 | | - csi2_hw_do_reset(csi2); |
---|
272 | | - csi2_disable_clks(csi2); |
---|
| 287 | + for (i = 0; i < csi2->csi_info.csi_num; i++) { |
---|
| 288 | + csi_idx = csi2->csi_info.csi_idx[i]; |
---|
| 289 | + csi2_disable(csi2->csi2_hw[csi_idx]); |
---|
| 290 | + csi2_hw_do_reset(csi2->csi2_hw[csi_idx]); |
---|
| 291 | + csi2_disable_clks(csi2->csi2_hw[csi_idx]); |
---|
| 292 | + } |
---|
273 | 293 | } |
---|
274 | 294 | |
---|
275 | 295 | /* |
---|
.. | .. |
---|
379 | 399 | csi2->crop.left = 0; |
---|
380 | 400 | csi2->crop.width = RKCIF_DEFAULT_WIDTH; |
---|
381 | 401 | csi2->crop.height = RKCIF_DEFAULT_HEIGHT; |
---|
382 | | - csi2->csi_idx = 0; |
---|
383 | 402 | |
---|
384 | 403 | return media_entity_pads_init(&sd->entity, num_pads, csi2->pad); |
---|
385 | 404 | } |
---|
.. | .. |
---|
567 | 586 | static long rkcif_csi2_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) |
---|
568 | 587 | { |
---|
569 | 588 | struct csi2_dev *csi2 = sd_to_dev(sd); |
---|
| 589 | + struct v4l2_subdev *sensor = get_remote_sensor(sd); |
---|
570 | 590 | long ret = 0; |
---|
| 591 | + int i = 0; |
---|
571 | 592 | |
---|
572 | 593 | switch (cmd) { |
---|
573 | 594 | case RKCIF_CMD_SET_CSI_IDX: |
---|
574 | | - csi2->csi_idx = *((u32 *)arg); |
---|
| 595 | + csi2->csi_info = *((struct rkcif_csi_info *)arg); |
---|
| 596 | + for (i = 0; i < csi2->csi_info.csi_num; i++) |
---|
| 597 | + csi2->csi2_hw[csi2->csi_info.csi_idx[i]]->csi2 = csi2; |
---|
| 598 | + if (csi2->match_data->chip_id > CHIP_RV1126_CSI2) |
---|
| 599 | + ret = v4l2_subdev_call(sensor, core, ioctl, |
---|
| 600 | + RKCIF_CMD_SET_CSI_IDX, |
---|
| 601 | + arg); |
---|
575 | 602 | break; |
---|
576 | 603 | default: |
---|
577 | 604 | ret = -ENOIOCTLCMD; |
---|
.. | .. |
---|
586 | 613 | unsigned int cmd, unsigned long arg) |
---|
587 | 614 | { |
---|
588 | 615 | void __user *up = compat_ptr(arg); |
---|
589 | | - u32 csi_idx = 0; |
---|
| 616 | + struct rkcif_csi_info csi_info; |
---|
590 | 617 | long ret; |
---|
591 | 618 | |
---|
592 | 619 | switch (cmd) { |
---|
593 | 620 | case RKCIF_CMD_SET_CSI_IDX: |
---|
594 | | - if (copy_from_user(&csi_idx, up, sizeof(u32))) |
---|
| 621 | + if (copy_from_user(&csi_info, up, sizeof(struct rkcif_csi_info))) |
---|
595 | 622 | return -EFAULT; |
---|
596 | 623 | |
---|
597 | | - ret = rkcif_csi2_ioctl(sd, cmd, &csi_idx); |
---|
| 624 | + ret = rkcif_csi2_ioctl(sd, cmd, &csi_info); |
---|
598 | 625 | break; |
---|
599 | 626 | default: |
---|
600 | 627 | ret = -ENOIOCTLCMD; |
---|
.. | .. |
---|
749 | 776 | static irqreturn_t rk_csirx_irq1_handler(int irq, void *ctx) |
---|
750 | 777 | { |
---|
751 | 778 | struct device *dev = ctx; |
---|
752 | | - struct csi2_dev *csi2 = sd_to_dev(dev_get_drvdata(dev)); |
---|
| 779 | + struct csi2_hw *csi2_hw = dev_get_drvdata(dev); |
---|
| 780 | + struct csi2_dev *csi2 = csi2_hw->csi2; |
---|
753 | 781 | struct csi2_err_stats *err_list = NULL; |
---|
754 | 782 | unsigned long err_stat = 0; |
---|
755 | 783 | u32 val; |
---|
.. | .. |
---|
758 | 786 | char vc_info[CSI_VCINFO_LEN] = {0}; |
---|
759 | 787 | bool is_add_cnt = false; |
---|
760 | 788 | |
---|
761 | | - val = read_csihost_reg(csi2->base, CSIHOST_ERR1); |
---|
| 789 | + val = read_csihost_reg(csi2_hw->base, CSIHOST_ERR1); |
---|
762 | 790 | if (val) { |
---|
763 | 791 | if (val & CSIHOST_ERR1_PHYERR_SPTSYNCHS) { |
---|
764 | 792 | err_list = &csi2->err_list[RK_CSI2_ERR_SOTSYN]; |
---|
.. | .. |
---|
767 | 795 | if (err_list->cnt > 3 && |
---|
768 | 796 | csi2->err_list[RK_CSI2_ERR_ALL].cnt <= err_list->cnt) { |
---|
769 | 797 | csi2->is_check_sot_sync = false; |
---|
770 | | - write_csihost_reg(csi2->base, CSIHOST_MSK1, 0xf); |
---|
| 798 | + write_csihost_reg(csi2_hw->base, CSIHOST_MSK1, 0xf); |
---|
771 | 799 | } |
---|
772 | 800 | if (csi2->is_check_sot_sync) { |
---|
773 | 801 | csi2_find_err_vc(val & 0xf, vc_info); |
---|
.. | .. |
---|
832 | 860 | csi2_err_strncat(err_str, cur_str); |
---|
833 | 861 | } |
---|
834 | 862 | |
---|
835 | | - pr_err("%s ERR1:0x%x %s\n", csi2->dev_name, val, err_str); |
---|
| 863 | + pr_err("%s ERR1:0x%x %s\n", csi2_hw->dev_name, val, err_str); |
---|
836 | 864 | |
---|
837 | 865 | if (is_add_cnt) { |
---|
838 | 866 | csi2->err_list[RK_CSI2_ERR_ALL].cnt++; |
---|
.. | .. |
---|
841 | 869 | |
---|
842 | 870 | atomic_notifier_call_chain(&g_csi_host_chain, |
---|
843 | 871 | err_stat, |
---|
844 | | - &csi2->csi_idx); |
---|
| 872 | + &csi2->csi_info.csi_idx[csi2->csi_info.csi_num - 1]); |
---|
845 | 873 | } |
---|
846 | 874 | |
---|
847 | 875 | } |
---|
.. | .. |
---|
852 | 880 | static irqreturn_t rk_csirx_irq2_handler(int irq, void *ctx) |
---|
853 | 881 | { |
---|
854 | 882 | struct device *dev = ctx; |
---|
855 | | - struct csi2_dev *csi2 = sd_to_dev(dev_get_drvdata(dev)); |
---|
| 883 | + struct csi2_hw *csi2_hw = dev_get_drvdata(dev); |
---|
856 | 884 | u32 val; |
---|
857 | 885 | char cur_str[CSI_ERRSTR_LEN] = {0}; |
---|
858 | 886 | char err_str[CSI_ERRSTR_LEN] = {0}; |
---|
859 | 887 | char vc_info[CSI_VCINFO_LEN] = {0}; |
---|
860 | 888 | |
---|
861 | | - val = read_csihost_reg(csi2->base, CSIHOST_ERR2); |
---|
| 889 | + val = read_csihost_reg(csi2_hw->base, CSIHOST_ERR2); |
---|
862 | 890 | if (val) { |
---|
863 | 891 | if (val & CSIHOST_ERR2_PHYERR_ESC) { |
---|
864 | 892 | csi2_find_err_vc(val & 0xf, vc_info); |
---|
.. | .. |
---|
885 | 913 | csi2_err_strncat(err_str, cur_str); |
---|
886 | 914 | } |
---|
887 | 915 | |
---|
888 | | - pr_err("%s ERR2:0x%x %s\n", csi2->dev_name, val, err_str); |
---|
| 916 | + pr_err("%s ERR2:0x%x %s\n", csi2_hw->dev_name, val, err_str); |
---|
889 | 917 | } |
---|
890 | 918 | |
---|
891 | 919 | return IRQ_HANDLED; |
---|
.. | .. |
---|
924 | 952 | static const struct csi2_match_data rk1808_csi2_match_data = { |
---|
925 | 953 | .chip_id = CHIP_RK1808_CSI2, |
---|
926 | 954 | .num_pads = CSI2_NUM_PADS, |
---|
| 955 | + .num_hw = 1, |
---|
927 | 956 | }; |
---|
928 | 957 | |
---|
929 | 958 | static const struct csi2_match_data rk3288_csi2_match_data = { |
---|
930 | 959 | .chip_id = CHIP_RK3288_CSI2, |
---|
931 | 960 | .num_pads = CSI2_NUM_PADS_SINGLE_LINK, |
---|
| 961 | + .num_hw = 1, |
---|
932 | 962 | }; |
---|
933 | 963 | |
---|
934 | 964 | static const struct csi2_match_data rv1126_csi2_match_data = { |
---|
935 | 965 | .chip_id = CHIP_RV1126_CSI2, |
---|
936 | 966 | .num_pads = CSI2_NUM_PADS, |
---|
| 967 | + .num_hw = 1, |
---|
937 | 968 | }; |
---|
938 | 969 | |
---|
939 | 970 | static const struct csi2_match_data rk3568_csi2_match_data = { |
---|
940 | 971 | .chip_id = CHIP_RK3568_CSI2, |
---|
941 | 972 | .num_pads = CSI2_NUM_PADS, |
---|
| 973 | + .num_hw = 1, |
---|
942 | 974 | }; |
---|
943 | 975 | |
---|
944 | 976 | static const struct csi2_match_data rk3588_csi2_match_data = { |
---|
945 | 977 | .chip_id = CHIP_RK3588_CSI2, |
---|
946 | 978 | .num_pads = CSI2_NUM_PADS_MAX, |
---|
| 979 | + .num_hw = 6, |
---|
| 980 | +}; |
---|
| 981 | + |
---|
| 982 | +static const struct csi2_match_data rv1106_csi2_match_data = { |
---|
| 983 | + .chip_id = CHIP_RV1106_CSI2, |
---|
| 984 | + .num_pads = CSI2_NUM_PADS_MAX, |
---|
| 985 | + .num_hw = 2, |
---|
947 | 986 | }; |
---|
948 | 987 | |
---|
949 | 988 | static const struct csi2_match_data rk3562_csi2_match_data = { |
---|
950 | 989 | .chip_id = CHIP_RK3562_CSI2, |
---|
951 | 990 | .num_pads = CSI2_NUM_PADS_MAX, |
---|
| 991 | + .num_hw = 4, |
---|
952 | 992 | }; |
---|
953 | 993 | |
---|
954 | 994 | static const struct of_device_id csi2_dt_ids[] = { |
---|
.. | .. |
---|
973 | 1013 | .data = &rk3588_csi2_match_data, |
---|
974 | 1014 | }, |
---|
975 | 1015 | { |
---|
| 1016 | + .compatible = "rockchip,rv1106-mipi-csi2", |
---|
| 1017 | + .data = &rv1106_csi2_match_data, |
---|
| 1018 | + }, |
---|
| 1019 | + { |
---|
976 | 1020 | .compatible = "rockchip,rk3562-mipi-csi2", |
---|
977 | 1021 | .data = &rk3562_csi2_match_data, |
---|
978 | 1022 | }, |
---|
.. | .. |
---|
980 | 1024 | }; |
---|
981 | 1025 | MODULE_DEVICE_TABLE(of, csi2_dt_ids); |
---|
982 | 1026 | |
---|
| 1027 | +static int csi2_attach_hw(struct csi2_dev *csi2) |
---|
| 1028 | +{ |
---|
| 1029 | + struct device_node *np; |
---|
| 1030 | + struct platform_device *pdev; |
---|
| 1031 | + struct csi2_hw *hw; |
---|
| 1032 | + int i = 0; |
---|
| 1033 | + |
---|
| 1034 | + for (i = 0; i < csi2->match_data->num_hw; i++) { |
---|
| 1035 | + np = of_parse_phandle(csi2->dev->of_node, "rockchip,hw", i); |
---|
| 1036 | + if (!np || !of_device_is_available(np)) { |
---|
| 1037 | + dev_err(csi2->dev, "failed to get csi2 hw node\n"); |
---|
| 1038 | + return -ENODEV; |
---|
| 1039 | + } |
---|
| 1040 | + |
---|
| 1041 | + pdev = of_find_device_by_node(np); |
---|
| 1042 | + of_node_put(np); |
---|
| 1043 | + if (!pdev) { |
---|
| 1044 | + dev_err(csi2->dev, "failed to get csi2 hw from node\n"); |
---|
| 1045 | + return -ENODEV; |
---|
| 1046 | + } |
---|
| 1047 | + |
---|
| 1048 | + hw = platform_get_drvdata(pdev); |
---|
| 1049 | + if (!hw) { |
---|
| 1050 | + dev_err(csi2->dev, "failed attach csi2 hw\n"); |
---|
| 1051 | + return -EINVAL; |
---|
| 1052 | + } |
---|
| 1053 | + |
---|
| 1054 | + hw->csi2 = csi2; |
---|
| 1055 | + csi2->csi2_hw[i] = hw; |
---|
| 1056 | + } |
---|
| 1057 | + dev_info(csi2->dev, "attach to csi2 hw node\n"); |
---|
| 1058 | + |
---|
| 1059 | + return 0; |
---|
| 1060 | +} |
---|
| 1061 | + |
---|
983 | 1062 | static int csi2_probe(struct platform_device *pdev) |
---|
984 | 1063 | { |
---|
985 | 1064 | const struct of_device_id *match; |
---|
986 | | - struct device *dev = &pdev->dev; |
---|
987 | 1065 | struct device_node *node = pdev->dev.of_node; |
---|
988 | 1066 | struct csi2_dev *csi2 = NULL; |
---|
989 | | - struct resource *res; |
---|
990 | 1067 | const struct csi2_match_data *data; |
---|
991 | | - int ret, irq; |
---|
| 1068 | + int ret; |
---|
992 | 1069 | |
---|
993 | 1070 | match = of_match_node(csi2_dt_ids, node); |
---|
994 | 1071 | if (IS_ERR(match)) |
---|
.. | .. |
---|
1014 | 1091 | v4l2_err(&csi2->sd, "failed to copy name\n"); |
---|
1015 | 1092 | platform_set_drvdata(pdev, &csi2->sd); |
---|
1016 | 1093 | |
---|
1017 | | - csi2->clks_num = devm_clk_bulk_get_all(dev, &csi2->clks_bulk); |
---|
1018 | | - if (csi2->clks_num < 0) { |
---|
1019 | | - csi2->clks_num = 0; |
---|
1020 | | - dev_err(dev, "failed to get csi2 clks\n"); |
---|
| 1094 | + ret = csi2_attach_hw(csi2); |
---|
| 1095 | + if (ret) { |
---|
| 1096 | + v4l2_err(&csi2->sd, "must enable all mipi csi2 hw node\n"); |
---|
| 1097 | + return -EINVAL; |
---|
1021 | 1098 | } |
---|
1022 | | - |
---|
1023 | | - csi2->rsts_bulk = devm_reset_control_array_get_optional_exclusive(dev); |
---|
1024 | | - if (IS_ERR(csi2->rsts_bulk)) { |
---|
1025 | | - if (PTR_ERR(csi2->rsts_bulk) != -EPROBE_DEFER) |
---|
1026 | | - dev_err(dev, "failed to get csi2 reset\n"); |
---|
1027 | | - csi2->rsts_bulk = NULL; |
---|
1028 | | - } |
---|
1029 | | - |
---|
1030 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1031 | | - csi2->base = devm_ioremap_resource(&pdev->dev, res); |
---|
1032 | | - if (IS_ERR(csi2->base)) { |
---|
1033 | | - resource_size_t offset = res->start; |
---|
1034 | | - resource_size_t size = resource_size(res); |
---|
1035 | | - |
---|
1036 | | - dev_warn(&pdev->dev, "avoid secondary mipi resource check!\n"); |
---|
1037 | | - |
---|
1038 | | - csi2->base = devm_ioremap(&pdev->dev, offset, size); |
---|
1039 | | - if (IS_ERR(csi2->base)) { |
---|
1040 | | - dev_err(&pdev->dev, "Failed to ioremap resource\n"); |
---|
1041 | | - |
---|
1042 | | - return PTR_ERR(csi2->base); |
---|
1043 | | - } |
---|
1044 | | - } |
---|
1045 | | - |
---|
1046 | | - irq = platform_get_irq_byname(pdev, "csi-intr1"); |
---|
1047 | | - if (irq > 0) { |
---|
1048 | | - ret = devm_request_irq(&pdev->dev, irq, |
---|
1049 | | - rk_csirx_irq1_handler, 0, |
---|
1050 | | - dev_driver_string(&pdev->dev), |
---|
1051 | | - &pdev->dev); |
---|
1052 | | - if (ret < 0) |
---|
1053 | | - v4l2_err(&csi2->sd, "request csi-intr1 irq failed: %d\n", |
---|
1054 | | - ret); |
---|
1055 | | - csi2->irq1 = irq; |
---|
1056 | | - } else { |
---|
1057 | | - v4l2_err(&csi2->sd, "No found irq csi-intr1\n"); |
---|
1058 | | - } |
---|
1059 | | - |
---|
1060 | | - irq = platform_get_irq_byname(pdev, "csi-intr2"); |
---|
1061 | | - if (irq > 0) { |
---|
1062 | | - ret = devm_request_irq(&pdev->dev, irq, |
---|
1063 | | - rk_csirx_irq2_handler, 0, |
---|
1064 | | - dev_driver_string(&pdev->dev), |
---|
1065 | | - &pdev->dev); |
---|
1066 | | - if (ret < 0) |
---|
1067 | | - v4l2_err(&csi2->sd, "request csi-intr2 failed: %d\n", |
---|
1068 | | - ret); |
---|
1069 | | - csi2->irq2 = irq; |
---|
1070 | | - } else { |
---|
1071 | | - v4l2_err(&csi2->sd, "No found irq csi-intr2\n"); |
---|
1072 | | - } |
---|
1073 | | - |
---|
1074 | 1099 | mutex_init(&csi2->lock); |
---|
1075 | 1100 | |
---|
1076 | 1101 | ret = csi2_media_init(&csi2->sd); |
---|
.. | .. |
---|
1115 | 1140 | return platform_driver_register(&csi2_driver); |
---|
1116 | 1141 | } |
---|
1117 | 1142 | |
---|
1118 | | -void __exit rkcif_csi2_plat_drv_exit(void) |
---|
| 1143 | +void rkcif_csi2_plat_drv_exit(void) |
---|
1119 | 1144 | { |
---|
1120 | 1145 | platform_driver_unregister(&csi2_driver); |
---|
1121 | 1146 | } |
---|
1122 | 1147 | |
---|
| 1148 | +static const struct csi2_hw_match_data rk1808_csi2_hw_match_data = { |
---|
| 1149 | + .chip_id = CHIP_RK1808_CSI2, |
---|
| 1150 | +}; |
---|
| 1151 | + |
---|
| 1152 | +static const struct csi2_hw_match_data rk3288_csi2_hw_match_data = { |
---|
| 1153 | + .chip_id = CHIP_RK3288_CSI2, |
---|
| 1154 | +}; |
---|
| 1155 | + |
---|
| 1156 | +static const struct csi2_hw_match_data rv1126_csi2_hw_match_data = { |
---|
| 1157 | + .chip_id = CHIP_RV1126_CSI2, |
---|
| 1158 | +}; |
---|
| 1159 | + |
---|
| 1160 | +static const struct csi2_hw_match_data rk3568_csi2_hw_match_data = { |
---|
| 1161 | + .chip_id = CHIP_RK3568_CSI2, |
---|
| 1162 | +}; |
---|
| 1163 | + |
---|
| 1164 | +static const struct csi2_hw_match_data rk3588_csi2_hw_match_data = { |
---|
| 1165 | + .chip_id = CHIP_RK3588_CSI2, |
---|
| 1166 | +}; |
---|
| 1167 | + |
---|
| 1168 | +static const struct csi2_hw_match_data rv1106_csi2_hw_match_data = { |
---|
| 1169 | + .chip_id = CHIP_RV1106_CSI2, |
---|
| 1170 | +}; |
---|
| 1171 | + |
---|
| 1172 | +static const struct csi2_hw_match_data rk3562_csi2_hw_match_data = { |
---|
| 1173 | + .chip_id = CHIP_RK3562_CSI2, |
---|
| 1174 | +}; |
---|
| 1175 | + |
---|
| 1176 | +static const struct of_device_id csi2_hw_ids[] = { |
---|
| 1177 | + { |
---|
| 1178 | + .compatible = "rockchip,rk1808-mipi-csi2-hw", |
---|
| 1179 | + .data = &rk1808_csi2_hw_match_data, |
---|
| 1180 | + }, |
---|
| 1181 | + { |
---|
| 1182 | + .compatible = "rockchip,rk3288-mipi-csi2-hw", |
---|
| 1183 | + .data = &rk3288_csi2_hw_match_data, |
---|
| 1184 | + }, |
---|
| 1185 | + { |
---|
| 1186 | + .compatible = "rockchip,rk3568-mipi-csi2-hw", |
---|
| 1187 | + .data = &rk3568_csi2_hw_match_data, |
---|
| 1188 | + }, |
---|
| 1189 | + { |
---|
| 1190 | + .compatible = "rockchip,rv1126-mipi-csi2-hw", |
---|
| 1191 | + .data = &rv1126_csi2_hw_match_data, |
---|
| 1192 | + }, |
---|
| 1193 | + { |
---|
| 1194 | + .compatible = "rockchip,rk3588-mipi-csi2-hw", |
---|
| 1195 | + .data = &rk3588_csi2_hw_match_data, |
---|
| 1196 | + }, |
---|
| 1197 | + { |
---|
| 1198 | + .compatible = "rockchip,rv1106-mipi-csi2-hw", |
---|
| 1199 | + .data = &rv1106_csi2_hw_match_data, |
---|
| 1200 | + }, |
---|
| 1201 | + { |
---|
| 1202 | + .compatible = "rockchip,rk3562-mipi-csi2-hw", |
---|
| 1203 | + .data = &rk3588_csi2_hw_match_data, |
---|
| 1204 | + }, |
---|
| 1205 | + { /* sentinel */ } |
---|
| 1206 | +}; |
---|
| 1207 | +MODULE_DEVICE_TABLE(of, csi2_hw_ids); |
---|
| 1208 | + |
---|
| 1209 | +static int csi2_hw_probe(struct platform_device *pdev) |
---|
| 1210 | +{ |
---|
| 1211 | + const struct of_device_id *match; |
---|
| 1212 | + struct device *dev = &pdev->dev; |
---|
| 1213 | + struct device_node *node = pdev->dev.of_node; |
---|
| 1214 | + struct csi2_hw *csi2_hw = NULL; |
---|
| 1215 | + struct resource *res; |
---|
| 1216 | + const struct csi2_hw_match_data *data; |
---|
| 1217 | + int ret, irq; |
---|
| 1218 | + |
---|
| 1219 | + dev_info(&pdev->dev, "enter mipi csi2 hw probe!\n"); |
---|
| 1220 | + match = of_match_node(csi2_hw_ids, node); |
---|
| 1221 | + if (IS_ERR(match)) |
---|
| 1222 | + return PTR_ERR(match); |
---|
| 1223 | + data = match->data; |
---|
| 1224 | + |
---|
| 1225 | + csi2_hw = devm_kzalloc(&pdev->dev, sizeof(*csi2_hw), GFP_KERNEL); |
---|
| 1226 | + if (!csi2_hw) |
---|
| 1227 | + return -ENOMEM; |
---|
| 1228 | + |
---|
| 1229 | + csi2_hw->dev = &pdev->dev; |
---|
| 1230 | + csi2_hw->match_data = data; |
---|
| 1231 | + |
---|
| 1232 | + csi2_hw->dev_name = node->name; |
---|
| 1233 | + |
---|
| 1234 | + csi2_hw->clks_num = devm_clk_bulk_get_all(dev, &csi2_hw->clks_bulk); |
---|
| 1235 | + if (csi2_hw->clks_num < 0) { |
---|
| 1236 | + csi2_hw->clks_num = 0; |
---|
| 1237 | + dev_err(dev, "failed to get csi2 clks\n"); |
---|
| 1238 | + } |
---|
| 1239 | + |
---|
| 1240 | + csi2_hw->rsts_bulk = devm_reset_control_array_get_optional_exclusive(dev); |
---|
| 1241 | + if (IS_ERR(csi2_hw->rsts_bulk)) { |
---|
| 1242 | + if (PTR_ERR(csi2_hw->rsts_bulk) != -EPROBE_DEFER) |
---|
| 1243 | + dev_err(dev, "failed to get csi2 reset\n"); |
---|
| 1244 | + csi2_hw->rsts_bulk = NULL; |
---|
| 1245 | + } |
---|
| 1246 | + |
---|
| 1247 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
| 1248 | + csi2_hw->base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 1249 | + if (IS_ERR(csi2_hw->base)) { |
---|
| 1250 | + resource_size_t offset = res->start; |
---|
| 1251 | + resource_size_t size = resource_size(res); |
---|
| 1252 | + |
---|
| 1253 | + dev_warn(&pdev->dev, "avoid secondary mipi resource check!\n"); |
---|
| 1254 | + |
---|
| 1255 | + csi2_hw->base = devm_ioremap(&pdev->dev, offset, size); |
---|
| 1256 | + if (IS_ERR(csi2_hw->base)) { |
---|
| 1257 | + dev_err(&pdev->dev, "Failed to ioremap resource\n"); |
---|
| 1258 | + |
---|
| 1259 | + return PTR_ERR(csi2_hw->base); |
---|
| 1260 | + } |
---|
| 1261 | + } |
---|
| 1262 | + |
---|
| 1263 | + irq = platform_get_irq_byname(pdev, "csi-intr1"); |
---|
| 1264 | + if (irq > 0) { |
---|
| 1265 | + ret = devm_request_irq(&pdev->dev, irq, |
---|
| 1266 | + rk_csirx_irq1_handler, 0, |
---|
| 1267 | + dev_driver_string(&pdev->dev), |
---|
| 1268 | + &pdev->dev); |
---|
| 1269 | + if (ret < 0) |
---|
| 1270 | + dev_err(&pdev->dev, "request csi-intr1 irq failed: %d\n", |
---|
| 1271 | + ret); |
---|
| 1272 | + csi2_hw->irq1 = irq; |
---|
| 1273 | + } else { |
---|
| 1274 | + dev_err(&pdev->dev, "No found irq csi-intr1\n"); |
---|
| 1275 | + } |
---|
| 1276 | + |
---|
| 1277 | + irq = platform_get_irq_byname(pdev, "csi-intr2"); |
---|
| 1278 | + if (irq > 0) { |
---|
| 1279 | + ret = devm_request_irq(&pdev->dev, irq, |
---|
| 1280 | + rk_csirx_irq2_handler, 0, |
---|
| 1281 | + dev_driver_string(&pdev->dev), |
---|
| 1282 | + &pdev->dev); |
---|
| 1283 | + if (ret < 0) |
---|
| 1284 | + dev_err(&pdev->dev, "request csi-intr2 failed: %d\n", |
---|
| 1285 | + ret); |
---|
| 1286 | + csi2_hw->irq2 = irq; |
---|
| 1287 | + } else { |
---|
| 1288 | + dev_err(&pdev->dev, "No found irq csi-intr2\n"); |
---|
| 1289 | + } |
---|
| 1290 | + platform_set_drvdata(pdev, csi2_hw); |
---|
| 1291 | + dev_info(&pdev->dev, "probe success, v4l2_dev:%s!\n", csi2_hw->dev_name); |
---|
| 1292 | + |
---|
| 1293 | + return 0; |
---|
| 1294 | +} |
---|
| 1295 | + |
---|
| 1296 | +static int csi2_hw_remove(struct platform_device *pdev) |
---|
| 1297 | +{ |
---|
| 1298 | + return 0; |
---|
| 1299 | +} |
---|
| 1300 | + |
---|
| 1301 | +static struct platform_driver csi2_hw_driver = { |
---|
| 1302 | + .driver = { |
---|
| 1303 | + .name = DEVICE_NAME_HW, |
---|
| 1304 | + .of_match_table = csi2_hw_ids, |
---|
| 1305 | + }, |
---|
| 1306 | + .probe = csi2_hw_probe, |
---|
| 1307 | + .remove = csi2_hw_remove, |
---|
| 1308 | +}; |
---|
| 1309 | + |
---|
| 1310 | +int rkcif_csi2_hw_plat_drv_init(void) |
---|
| 1311 | +{ |
---|
| 1312 | + return platform_driver_register(&csi2_hw_driver); |
---|
| 1313 | +} |
---|
| 1314 | + |
---|
| 1315 | +void rkcif_csi2_hw_plat_drv_exit(void) |
---|
| 1316 | +{ |
---|
| 1317 | + platform_driver_unregister(&csi2_hw_driver); |
---|
| 1318 | +} |
---|
| 1319 | + |
---|
1123 | 1320 | MODULE_DESCRIPTION("Rockchip MIPI CSI2 driver"); |
---|
1124 | 1321 | MODULE_AUTHOR("Macrofly.xu <xuhf@rock-chips.com>"); |
---|
1125 | 1322 | MODULE_LICENSE("GPL"); |
---|