.. | .. |
---|
27 | 27 | #include <media/v4l2-subdev.h> |
---|
28 | 28 | #include <linux/pinctrl/consumer.h> |
---|
29 | 29 | #include "../platform/rockchip/isp/rkisp_tb_helper.h" |
---|
| 30 | +#include "cam-sleep-wakeup.h" |
---|
30 | 31 | |
---|
31 | 32 | #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x01) |
---|
32 | 33 | |
---|
.. | .. |
---|
158 | 159 | bool is_thunderboot; |
---|
159 | 160 | bool is_first_streamoff; |
---|
160 | 161 | struct preisp_hdrae_exp_s init_hdrae_exp; |
---|
| 162 | + struct cam_sw_info *cam_sw_inf; |
---|
161 | 163 | }; |
---|
162 | 164 | |
---|
163 | 165 | #define to_sc3338(sd) container_of(sd, struct sc3338, subdev) |
---|
.. | .. |
---|
722 | 724 | } |
---|
723 | 725 | break; |
---|
724 | 726 | case PREISP_CMD_SET_HDRAE_EXP: |
---|
| 727 | + if (sc3338->cam_sw_inf) |
---|
| 728 | + memcpy(&sc3338->cam_sw_inf->hdr_ae, (struct preisp_hdrae_exp_s *)(arg), |
---|
| 729 | + sizeof(struct preisp_hdrae_exp_s)); |
---|
725 | 730 | break; |
---|
726 | 731 | case RKMODULE_SET_QUICK_STREAM: |
---|
727 | 732 | |
---|
.. | .. |
---|
970 | 975 | return ret; |
---|
971 | 976 | } |
---|
972 | 977 | |
---|
| 978 | + cam_sw_regulator_bulk_init(sc3338->cam_sw_inf, SC3338_NUM_SUPPLIES, sc3338->supplies); |
---|
| 979 | + |
---|
973 | 980 | if (sc3338->is_thunderboot) |
---|
974 | 981 | return 0; |
---|
975 | 982 | |
---|
.. | .. |
---|
1036 | 1043 | regulator_bulk_disable(SC3338_NUM_SUPPLIES, sc3338->supplies); |
---|
1037 | 1044 | } |
---|
1038 | 1045 | |
---|
| 1046 | +#if IS_REACHABLE(CONFIG_VIDEO_CAM_SLEEP_WAKEUP) |
---|
| 1047 | +static int sc3338_resume(struct device *dev) |
---|
| 1048 | +{ |
---|
| 1049 | + int ret; |
---|
| 1050 | + struct i2c_client *client = to_i2c_client(dev); |
---|
| 1051 | + struct v4l2_subdev *sd = i2c_get_clientdata(client); |
---|
| 1052 | + struct sc3338 *sc3338 = to_sc3338(sd); |
---|
| 1053 | + |
---|
| 1054 | + cam_sw_prepare_wakeup(sc3338->cam_sw_inf, dev); |
---|
| 1055 | + |
---|
| 1056 | + usleep_range(6000, 8000); |
---|
| 1057 | + cam_sw_write_array(sc3338->cam_sw_inf); |
---|
| 1058 | + |
---|
| 1059 | + if (__v4l2_ctrl_handler_setup(&sc3338->ctrl_handler)) |
---|
| 1060 | + dev_err(dev, "__v4l2_ctrl_handler_setup fail!"); |
---|
| 1061 | + |
---|
| 1062 | + if (sc3338->has_init_exp && sc3338->cur_mode != NO_HDR) { // hdr mode |
---|
| 1063 | + ret = sc3338_ioctl(&sc3338->subdev, PREISP_CMD_SET_HDRAE_EXP, |
---|
| 1064 | + &sc3338->cam_sw_inf->hdr_ae); |
---|
| 1065 | + if (ret) { |
---|
| 1066 | + dev_err(&sc3338->client->dev, "set exp fail in hdr mode\n"); |
---|
| 1067 | + return ret; |
---|
| 1068 | + } |
---|
| 1069 | + } |
---|
| 1070 | + return 0; |
---|
| 1071 | +} |
---|
| 1072 | + |
---|
| 1073 | +static int sc3338_suspend(struct device *dev) |
---|
| 1074 | +{ |
---|
| 1075 | + struct i2c_client *client = to_i2c_client(dev); |
---|
| 1076 | + struct v4l2_subdev *sd = i2c_get_clientdata(client); |
---|
| 1077 | + struct sc3338 *sc3338 = to_sc3338(sd); |
---|
| 1078 | + |
---|
| 1079 | + cam_sw_write_array_cb_init(sc3338->cam_sw_inf, client, |
---|
| 1080 | + (void *)sc3338->cur_mode->reg_list, (sensor_write_array)sc3338_write_array); |
---|
| 1081 | + cam_sw_prepare_sleep(sc3338->cam_sw_inf); |
---|
| 1082 | + |
---|
| 1083 | + return 0; |
---|
| 1084 | +} |
---|
| 1085 | +#endif |
---|
| 1086 | + |
---|
1039 | 1087 | static int sc3338_runtime_resume(struct device *dev) |
---|
1040 | 1088 | { |
---|
1041 | 1089 | struct i2c_client *client = to_i2c_client(dev); |
---|
.. | .. |
---|
1094 | 1142 | } |
---|
1095 | 1143 | |
---|
1096 | 1144 | static const struct dev_pm_ops sc3338_pm_ops = { |
---|
1097 | | - SET_RUNTIME_PM_OPS(sc3338_runtime_suspend, |
---|
1098 | | - sc3338_runtime_resume, NULL) |
---|
| 1145 | + SET_RUNTIME_PM_OPS(sc3338_runtime_suspend, sc3338_runtime_resume, NULL) |
---|
| 1146 | +#if IS_REACHABLE(CONFIG_VIDEO_CAM_SLEEP_WAKEUP) |
---|
| 1147 | + SET_LATE_SYSTEM_SLEEP_PM_OPS(sc3338_suspend, sc3338_resume) |
---|
| 1148 | +#endif |
---|
1099 | 1149 | }; |
---|
1100 | 1150 | |
---|
1101 | 1151 | #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API |
---|
.. | .. |
---|
1454 | 1504 | goto err_power_off; |
---|
1455 | 1505 | #endif |
---|
1456 | 1506 | |
---|
| 1507 | + if (!sc3338->cam_sw_inf) { |
---|
| 1508 | + sc3338->cam_sw_inf = cam_sw_init(); |
---|
| 1509 | + cam_sw_clk_init(sc3338->cam_sw_inf, sc3338->xvclk, SC3338_XVCLK_FREQ); |
---|
| 1510 | + cam_sw_reset_pin_init(sc3338->cam_sw_inf, sc3338->reset_gpio, 0); |
---|
| 1511 | + cam_sw_pwdn_pin_init(sc3338->cam_sw_inf, sc3338->pwdn_gpio, 1); |
---|
| 1512 | + } |
---|
| 1513 | + |
---|
1457 | 1514 | memset(facing, 0, sizeof(facing)); |
---|
1458 | 1515 | if (strcmp(sc3338->module_facing, "back") == 0) |
---|
1459 | 1516 | facing[0] = 'b'; |
---|
.. | .. |
---|
1504 | 1561 | v4l2_ctrl_handler_free(&sc3338->ctrl_handler); |
---|
1505 | 1562 | mutex_destroy(&sc3338->mutex); |
---|
1506 | 1563 | |
---|
| 1564 | + cam_sw_deinit(sc3338->cam_sw_inf); |
---|
| 1565 | + |
---|
1507 | 1566 | pm_runtime_disable(&client->dev); |
---|
1508 | 1567 | if (!pm_runtime_status_suspended(&client->dev)) |
---|
1509 | 1568 | __sc3338_power_off(sc3338); |
---|