Lines Matching +full:sd +full:- +full:hs

1 // SPDX-License-Identifier: GPL-2.0
3 * max96722 GMSL2/GMSL1 to CSI-2 Deserializer driver
28 #include <linux/rk-camera-module.h>
30 #include <media/media-entity.h>
31 #include <media/v4l2-async.h>
32 #include <media/v4l2-ctrls.h>
33 #include <media/v4l2-subdev.h>
34 #include <media/v4l2-ctrls.h>
35 #include <media/v4l2-fwnode.h>
36 #include <media/v4l2-subdev.h>
59 /* max96722->link mask: link type = bit[7:4], link mask = bit[3:0] */
221 …{ I2C_DEV_DES, 2, 0x0B0F, 0x01, 0x00, 0x00 }, // Disable processing HS and DE signals(required whe…
222 …{ I2C_DEV_DES, 2, 0x0C0F, 0x01, 0x00, 0x00 }, // Disable processing HS and DE signals(required whe…
223 …{ I2C_DEV_DES, 2, 0x0D0F, 0x01, 0x00, 0x00 }, // Disable processing HS and DE signals(required whe…
224 …{ I2C_DEV_DES, 2, 0x0E0F, 0x01, 0x00, 0x00 }, // Disable processing HS and DE signals(required whe…
227 { I2C_DEV_DES, 2, 0x092D, 0x15, 0x00, 0x00 }, // SRC/DST 0/1/2 -> CSI2 Controller 1;
237 { I2C_DEV_DES, 2, 0x096D, 0x15, 0x00, 0x00 }, // SRC/DST 0/1/2 -> CSI2 Controller 1;
247 { I2C_DEV_DES, 2, 0x09AD, 0x15, 0x00, 0x00 }, // SRC/DST 0/1/2 -> CSI2 Controller 1;
257 { I2C_DEV_DES, 2, 0x09ED, 0x15, 0x00, 0x00 }, // SRC/DST 0/1/2 -> CSI2 Controller 1;
267 // Set Lane Mapping for 4-lane port A
268 { I2C_DEV_DES, 2, 0x08A3, 0xe4, 0x00, 0x00 }, // PHY1 D1->D3, D0->D2; PHY0 D1->D1, D0->D0
269 // Set 4 lane D-PHY, 2bit VC
274 // Enable software override for all pipes since GMSL1 data is parallel mode, bpp=8, dt=0x1e(yuv-8)
275 …{ I2C_DEV_DES, 2, 0x040B, 0x40, 0x00, 0x00 }, // pipe 0 bpp=0x08: Datatypes = 0x2A, 0x10-12, 0x31-
278 { I2C_DEV_DES, 2, 0x040E, 0x5e, 0x00, 0x00 }, // pipe 0 DT=0x1E: YUV422 8-bit
279 { I2C_DEV_DES, 2, 0x040F, 0x7e, 0x00, 0x00 }, // pipe 1 DT=0x1E: YUV422 8-bit
280 { I2C_DEV_DES, 2, 0x0410, 0x7a, 0x00, 0x00 }, // pipe 2 DT=0x1E, pipe 3 DT=0x1E: YUV422 8-bit
281 …{ I2C_DEV_DES, 2, 0x0411, 0x48, 0x00, 0x00 }, // pipe 1 bpp=0x08: Datatypes = 0x2A, 0x10-12, 0x31-
282 …0x0412, 0x20, 0x00, 0x00 }, // pipe 2 bpp=0x08, pipe 3 bpp=0x08: Datatypes = 0x2A, 0x10-12, 0x31-37
285 { I2C_DEV_DES, 2, 0x041A, 0xf0, 0x00, 0x00 }, // pipe 0/1/2/3: Enable YUV8-/10-bit mux mode
292 …I2C_DEV_SER, 1, 0x67, 0xc4, 0x00, 0x00 }, // Double Alignment Mode: Align at each rising edge of HS
294 { I2C_DEV_SER, 1, 0x3F, 0x08, 0x00, 0x00 }, // Crossbar HS: DIN8
368 struct i2c_client *client = max96722->client; in max96722_write_reg()
369 u16 client_addr = max96722->i2c_addr[i2c_id]; in max96722_write_reg()
375 dev_info(&client->dev, "addr(0x%02x) write reg(0x%04x, %d, 0x%02x)\n", in max96722_write_reg()
379 return -EINVAL; in max96722_write_reg()
394 val_i = 4 - val_len; in max96722_write_reg()
399 client->addr = client_addr; in max96722_write_reg()
402 dev_err(&client->dev, in max96722_write_reg()
404 __func__, reg, client->addr); in max96722_write_reg()
405 return -EIO; in max96722_write_reg()
414 struct i2c_client *client = max96722->client; in max96722_read_reg()
415 u16 client_addr = max96722->i2c_addr[i2c_id]; in max96722_read_reg()
424 return -EINVAL; in max96722_read_reg()
426 client->addr = client_addr; in max96722_read_reg()
431 msgs[0].addr = client->addr; in max96722_read_reg()
434 msgs[0].buf = &reg_be_p[2 - reg_len]; in max96722_read_reg()
437 msgs[1].addr = client->addr; in max96722_read_reg()
440 msgs[1].buf = &data_be_p[4 - val_len]; in max96722_read_reg()
442 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in max96722_read_reg()
444 dev_err(&client->dev, in max96722_read_reg()
446 __func__, reg, client->addr); in max96722_read_reg()
447 return -EIO; in max96722_read_reg()
453 dev_info(&client->dev, "addr(0x%02x) read reg(0x%04x, %d, 0x%02x)\n", in max96722_read_reg()
505 struct device *dev = &max96722->client->dev; in max96722_check_local_chipid()
514 return -ENODEV; in max96722_check_local_chipid()
524 struct device *dev = &max96722->client->dev; in max96722_check_remote_chipid()
538 return -ENODEV; in max96722_check_remote_chipid()
550 return -ENODEV; in max96722_check_remote_chipid()
562 return -ENODEV; in max96722_check_remote_chipid()
572 struct device *dev = &max96722->client->dev; in max96722_get_link_lock_state()
576 link_type = max96722->link_mask & MAXIM_GMSL_TYPE_MASK; in max96722_get_link_lock_state()
671 struct device *dev = &max96722->client->dev; in max96722_check_link_lock_state()
694 link_type = max96722->link_mask & MAXIM_GMSL_TYPE_MASK; in max96722_check_link_lock_state()
730 // Link A ~ Link D One-Shot Reset depend on link_mask in max96722_check_link_lock_state()
731 link_mask = max96722->link_mask & MAXIM_GMSL_LOCK_MASK; in max96722_check_link_lock_state()
786 return -ENODEV; in max96722_check_link_lock_state()
793 struct device *dev = &max96722->client->dev; in max96722_hot_plug_detect_irq_handler()
796 link_mask = max96722->link_mask & MAXIM_GMSL_LOCK_MASK; in max96722_hot_plug_detect_irq_handler()
797 if (max96722->streaming) { in max96722_hot_plug_detect_irq_handler()
811 struct device *dev = &max96722->client->dev; in max96722_dphy_dpll_predef_set()
916 struct device *dev = &max96722->client->dev; in max96722_auto_init_deskew()
921 // D-PHY Deskew Initial Calibration Control in max96722_auto_init_deskew()
947 struct device *dev = &max96722->client->dev; in max96722_frame_sync_period()
965 // Disable Vsync-Fsync overlap window in max96722_frame_sync_period()
975 fsync_peroid = DIV_ROUND_UP(pclk, period) - 1; in max96722_frame_sync_period()
1051 return abs(mode->width - framefmt->width) + in max96722_get_reso_dist()
1052 abs(mode->height - framefmt->height); in max96722_get_reso_dist()
1058 struct v4l2_mbus_framefmt *framefmt = &fmt->format; in max96722_find_best_fit()
1061 int cur_best_fit_dist = -1; in max96722_find_best_fit()
1064 for (i = 0; i < max96722->cfg_modes_num; i++) { in max96722_find_best_fit()
1065 dist = max96722_get_reso_dist(&max96722->supported_modes[i], framefmt); in max96722_find_best_fit()
1066 if ((cur_best_fit_dist == -1 || dist < cur_best_fit_dist) in max96722_find_best_fit()
1067 && (max96722->supported_modes[i].bus_fmt == framefmt->code)) { in max96722_find_best_fit()
1073 return &max96722->supported_modes[cur_best_fit]; in max96722_find_best_fit()
1076 static int max96722_set_fmt(struct v4l2_subdev *sd, in max96722_set_fmt() argument
1080 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_set_fmt()
1085 mutex_lock(&max96722->mutex); in max96722_set_fmt()
1089 fmt->format.code = mode->bus_fmt; in max96722_set_fmt()
1090 fmt->format.width = mode->width; in max96722_set_fmt()
1091 fmt->format.height = mode->height; in max96722_set_fmt()
1092 fmt->format.field = V4L2_FIELD_NONE; in max96722_set_fmt()
1093 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in max96722_set_fmt()
1095 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; in max96722_set_fmt()
1097 mutex_unlock(&max96722->mutex); in max96722_set_fmt()
1098 return -ENOTTY; in max96722_set_fmt()
1101 if (max96722->streaming) { in max96722_set_fmt()
1102 mutex_unlock(&max96722->mutex); in max96722_set_fmt()
1103 return -EBUSY; in max96722_set_fmt()
1106 max96722->cur_mode = mode; in max96722_set_fmt()
1108 __v4l2_ctrl_s_ctrl(max96722->link_freq, mode->link_freq_idx); in max96722_set_fmt()
1110 data_lanes = max96722->bus_cfg.bus.mipi_csi2.num_data_lanes; in max96722_set_fmt()
1111 pixel_rate = (u32)link_freq_items[mode->link_freq_idx] / mode->bpp * 2 * data_lanes; in max96722_set_fmt()
1112 __v4l2_ctrl_s_ctrl_int64(max96722->pixel_rate, pixel_rate); in max96722_set_fmt()
1114 dev_info(&max96722->client->dev, "mipi_freq_idx = %d, mipi_link_freq = %lld\n", in max96722_set_fmt()
1115 mode->link_freq_idx, link_freq_items[mode->link_freq_idx]); in max96722_set_fmt()
1116 dev_info(&max96722->client->dev, "pixel_rate = %lld, bpp = %d\n", in max96722_set_fmt()
1117 pixel_rate, mode->bpp); in max96722_set_fmt()
1120 mutex_unlock(&max96722->mutex); in max96722_set_fmt()
1125 static int max96722_get_fmt(struct v4l2_subdev *sd, in max96722_get_fmt() argument
1129 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_get_fmt()
1130 const struct max96722_mode *mode = max96722->cur_mode; in max96722_get_fmt()
1132 mutex_lock(&max96722->mutex); in max96722_get_fmt()
1133 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in max96722_get_fmt()
1135 fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad); in max96722_get_fmt()
1137 mutex_unlock(&max96722->mutex); in max96722_get_fmt()
1138 return -ENOTTY; in max96722_get_fmt()
1141 fmt->format.width = mode->width; in max96722_get_fmt()
1142 fmt->format.height = mode->height; in max96722_get_fmt()
1143 fmt->format.code = mode->bus_fmt; in max96722_get_fmt()
1144 fmt->format.field = V4L2_FIELD_NONE; in max96722_get_fmt()
1145 if (fmt->pad < PAD_MAX && fmt->pad >= PAD0) in max96722_get_fmt()
1146 fmt->reserved[0] = mode->vc[fmt->pad]; in max96722_get_fmt()
1148 fmt->reserved[0] = mode->vc[PAD0]; in max96722_get_fmt()
1150 mutex_unlock(&max96722->mutex); in max96722_get_fmt()
1155 static int max96722_enum_mbus_code(struct v4l2_subdev *sd, in max96722_enum_mbus_code() argument
1159 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_enum_mbus_code()
1160 const struct max96722_mode *mode = max96722->cur_mode; in max96722_enum_mbus_code()
1162 if (code->index != 0) in max96722_enum_mbus_code()
1163 return -EINVAL; in max96722_enum_mbus_code()
1164 code->code = mode->bus_fmt; in max96722_enum_mbus_code()
1169 static int max96722_enum_frame_sizes(struct v4l2_subdev *sd, in max96722_enum_frame_sizes() argument
1173 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_enum_frame_sizes()
1175 if (fse->index >= max96722->cfg_modes_num) in max96722_enum_frame_sizes()
1176 return -EINVAL; in max96722_enum_frame_sizes()
1178 if (fse->code != max96722->supported_modes[fse->index].bus_fmt) in max96722_enum_frame_sizes()
1179 return -EINVAL; in max96722_enum_frame_sizes()
1181 fse->min_width = max96722->supported_modes[fse->index].width; in max96722_enum_frame_sizes()
1182 fse->max_width = max96722->supported_modes[fse->index].width; in max96722_enum_frame_sizes()
1183 fse->max_height = max96722->supported_modes[fse->index].height; in max96722_enum_frame_sizes()
1184 fse->min_height = max96722->supported_modes[fse->index].height; in max96722_enum_frame_sizes()
1189 static int max96722_g_frame_interval(struct v4l2_subdev *sd, in max96722_g_frame_interval() argument
1192 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_g_frame_interval()
1193 const struct max96722_mode *mode = max96722->cur_mode; in max96722_g_frame_interval()
1195 mutex_lock(&max96722->mutex); in max96722_g_frame_interval()
1196 fi->interval = mode->max_fps; in max96722_g_frame_interval()
1197 mutex_unlock(&max96722->mutex); in max96722_g_frame_interval()
1206 strscpy(inf->base.sensor, MAX96722_NAME, sizeof(inf->base.sensor)); in max96722_get_module_inf()
1207 strscpy(inf->base.module, max96722->module_name, in max96722_get_module_inf()
1208 sizeof(inf->base.module)); in max96722_get_module_inf()
1209 strscpy(inf->base.lens, max96722->len_name, sizeof(inf->base.lens)); in max96722_get_module_inf()
1216 struct i2c_client *client = max96722->client; in max96722_get_vicap_rst_inf()
1218 rst_info->is_reset = max96722->hot_plug; in max96722_get_vicap_rst_inf()
1219 max96722->hot_plug = false; in max96722_get_vicap_rst_inf()
1220 rst_info->src = RKCIF_RESET_SRC_ERR_HOTPLUG; in max96722_get_vicap_rst_inf()
1221 dev_info(&client->dev, "%s: rst_info->is_reset:%d.\n", __func__, in max96722_get_vicap_rst_inf()
1222 rst_info->is_reset); in max96722_get_vicap_rst_inf()
1229 max96722->is_reset = rst_info.is_reset; in max96722_set_vicap_rst_inf()
1232 static long max96722_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) in max96722_ioctl() argument
1234 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_ioctl()
1263 if (dphy_param->vendor == rk3588_dcphy_param.vendor) in max96722_ioctl()
1265 dev_dbg(&max96722->client->dev, "sensor set dphy param\n"); in max96722_ioctl()
1269 if (dphy_param->vendor == rk3588_dcphy_param.vendor) in max96722_ioctl()
1271 dev_dbg(&max96722->client->dev, "sensor get dphy param\n"); in max96722_ioctl()
1274 ret = -ENOIOCTLCMD; in max96722_ioctl()
1282 static long max96722_compat_ioctl32(struct v4l2_subdev *sd, unsigned int cmd, in max96722_compat_ioctl32() argument
1298 ret = -ENOMEM; in max96722_compat_ioctl32()
1302 ret = max96722_ioctl(sd, cmd, inf); in max96722_compat_ioctl32()
1306 ret = -EFAULT; in max96722_compat_ioctl32()
1313 ret = -ENOMEM; in max96722_compat_ioctl32()
1319 ret = max96722_ioctl(sd, cmd, cfg); in max96722_compat_ioctl32()
1321 ret = -EFAULT; in max96722_compat_ioctl32()
1327 ret = -ENOMEM; in max96722_compat_ioctl32()
1331 ret = max96722_ioctl(sd, cmd, vicap_rst_inf); in max96722_compat_ioctl32()
1336 ret = -EFAULT; in max96722_compat_ioctl32()
1343 ret = -ENOMEM; in max96722_compat_ioctl32()
1349 ret = max96722_ioctl(sd, cmd, vicap_rst_inf); in max96722_compat_ioctl32()
1351 ret = -EFAULT; in max96722_compat_ioctl32()
1357 ret = -ENOMEM; in max96722_compat_ioctl32()
1361 ret = max96722_ioctl(sd, cmd, seq); in max96722_compat_ioctl32()
1365 ret = -EFAULT; in max96722_compat_ioctl32()
1372 ret = max96722_ioctl(sd, cmd, &stream); in max96722_compat_ioctl32()
1374 ret = -EFAULT; in max96722_compat_ioctl32()
1379 ret = -ENOMEM; in max96722_compat_ioctl32()
1385 ret = max96722_ioctl(sd, cmd, dphy_param); in max96722_compat_ioctl32()
1387 ret = -EFAULT; in max96722_compat_ioctl32()
1393 ret = -ENOMEM; in max96722_compat_ioctl32()
1397 ret = max96722_ioctl(sd, cmd, dphy_param); in max96722_compat_ioctl32()
1401 ret = -EFAULT; in max96722_compat_ioctl32()
1406 ret = -ENOIOCTLCMD; in max96722_compat_ioctl32()
1423 if (max96722->hot_plug_irq > 0) in __max96722_start_stream()
1424 enable_irq(max96722->hot_plug_irq); in __max96722_start_stream()
1427 max96722->cur_mode->reg_list); in __max96722_start_stream()
1431 link_freq_idx = max96722->cur_mode->link_freq_idx; in __max96722_start_stream()
1437 if (max96722->auto_init_deskew_mask != 0) { in __max96722_start_stream()
1439 max96722->auto_init_deskew_mask); in __max96722_start_stream()
1444 if (max96722->frame_sync_period != 0) { in __max96722_start_stream()
1446 max96722->frame_sync_period); in __max96722_start_stream()
1452 mutex_unlock(&max96722->mutex); in __max96722_start_stream()
1453 ret = v4l2_ctrl_handler_setup(&max96722->ctrl_handler); in __max96722_start_stream()
1454 mutex_lock(&max96722->mutex); in __max96722_start_stream()
1464 if (max96722->hot_plug_irq > 0) in __max96722_stop_stream()
1465 disable_irq(max96722->hot_plug_irq); in __max96722_stop_stream()
1470 static int max96722_s_stream(struct v4l2_subdev *sd, int on) in max96722_s_stream() argument
1472 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_s_stream()
1473 struct i2c_client *client = max96722->client; in max96722_s_stream()
1476 dev_info(&client->dev, "%s: on: %d, %dx%d@%d\n", __func__, on, in max96722_s_stream()
1477 max96722->cur_mode->width, max96722->cur_mode->height, in max96722_s_stream()
1478 DIV_ROUND_CLOSEST(max96722->cur_mode->max_fps.denominator, in max96722_s_stream()
1479 max96722->cur_mode->max_fps.numerator)); in max96722_s_stream()
1481 mutex_lock(&max96722->mutex); in max96722_s_stream()
1483 if (on == max96722->streaming) in max96722_s_stream()
1487 ret = pm_runtime_get_sync(&client->dev); in max96722_s_stream()
1489 pm_runtime_put_noidle(&client->dev); in max96722_s_stream()
1495 v4l2_err(sd, "start stream failed while write regs\n"); in max96722_s_stream()
1496 pm_runtime_put(&client->dev); in max96722_s_stream()
1501 pm_runtime_put(&client->dev); in max96722_s_stream()
1504 max96722->streaming = on; in max96722_s_stream()
1507 mutex_unlock(&max96722->mutex); in max96722_s_stream()
1512 static int max96722_s_power(struct v4l2_subdev *sd, int on) in max96722_s_power() argument
1514 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_s_power()
1515 struct i2c_client *client = max96722->client; in max96722_s_power()
1518 mutex_lock(&max96722->mutex); in max96722_s_power()
1520 /* If the power state is not modified - no work to do. */ in max96722_s_power()
1521 if (max96722->power_on == !!on) in max96722_s_power()
1525 ret = pm_runtime_get_sync(&client->dev); in max96722_s_power()
1527 pm_runtime_put_noidle(&client->dev); in max96722_s_power()
1531 max96722->power_on = true; in max96722_s_power()
1533 pm_runtime_put(&client->dev); in max96722_s_power()
1534 max96722->power_on = false; in max96722_s_power()
1538 mutex_unlock(&max96722->mutex); in max96722_s_power()
1553 struct device *dev = &max96722->client->dev; in __max96722_power_on()
1555 if (!IS_ERR(max96722->power_gpio)) { in __max96722_power_on()
1556 gpiod_set_value_cansleep(max96722->power_gpio, 1); in __max96722_power_on()
1560 if (!IS_ERR(max96722->pocen_gpio)) { in __max96722_power_on()
1561 gpiod_set_value_cansleep(max96722->pocen_gpio, 1); in __max96722_power_on()
1565 if (!IS_ERR_OR_NULL(max96722->pins_default)) { in __max96722_power_on()
1566 ret = pinctrl_select_state(max96722->pinctrl, in __max96722_power_on()
1567 max96722->pins_default); in __max96722_power_on()
1572 if (!IS_ERR(max96722->reset_gpio)) in __max96722_power_on()
1573 gpiod_set_value_cansleep(max96722->reset_gpio, 0); in __max96722_power_on()
1575 ret = regulator_bulk_enable(MAX96722_NUM_SUPPLIES, max96722->supplies); in __max96722_power_on()
1580 if (!IS_ERR(max96722->reset_gpio)) { in __max96722_power_on()
1581 gpiod_set_value_cansleep(max96722->reset_gpio, 1); in __max96722_power_on()
1585 if (!IS_ERR(max96722->pwdn_gpio)) in __max96722_power_on()
1586 gpiod_set_value_cansleep(max96722->pwdn_gpio, 1); in __max96722_power_on()
1595 clk_disable_unprepare(max96722->xvclk); in __max96722_power_on()
1603 struct device *dev = &max96722->client->dev; in __max96722_power_off()
1605 if (!IS_ERR(max96722->pwdn_gpio)) in __max96722_power_off()
1606 gpiod_set_value_cansleep(max96722->pwdn_gpio, 0); in __max96722_power_off()
1607 clk_disable_unprepare(max96722->xvclk); in __max96722_power_off()
1609 if (!IS_ERR(max96722->reset_gpio)) in __max96722_power_off()
1610 gpiod_set_value_cansleep(max96722->reset_gpio, 0); in __max96722_power_off()
1612 if (!IS_ERR_OR_NULL(max96722->pins_sleep)) { in __max96722_power_off()
1613 ret = pinctrl_select_state(max96722->pinctrl, in __max96722_power_off()
1614 max96722->pins_sleep); in __max96722_power_off()
1619 regulator_bulk_disable(MAX96722_NUM_SUPPLIES, max96722->supplies); in __max96722_power_off()
1621 if (!IS_ERR(max96722->pocen_gpio)) in __max96722_power_off()
1622 gpiod_set_value_cansleep(max96722->pocen_gpio, 0); in __max96722_power_off()
1624 if (!IS_ERR(max96722->power_gpio)) in __max96722_power_off()
1625 gpiod_set_value_cansleep(max96722->power_gpio, 0); in __max96722_power_off()
1631 struct v4l2_subdev *sd = i2c_get_clientdata(client); in max96722_runtime_resume() local
1632 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_runtime_resume()
1640 struct v4l2_subdev *sd = i2c_get_clientdata(client); in max96722_runtime_suspend() local
1641 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_runtime_suspend()
1649 static int max96722_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) in max96722_open() argument
1651 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_open()
1653 v4l2_subdev_get_try_format(sd, fh->pad, 0); in max96722_open()
1654 const struct max96722_mode *def_mode = &max96722->supported_modes[0]; in max96722_open()
1656 mutex_lock(&max96722->mutex); in max96722_open()
1658 try_fmt->width = def_mode->width; in max96722_open()
1659 try_fmt->height = def_mode->height; in max96722_open()
1660 try_fmt->code = def_mode->bus_fmt; in max96722_open()
1661 try_fmt->field = V4L2_FIELD_NONE; in max96722_open()
1663 mutex_unlock(&max96722->mutex); in max96722_open()
1671 max96722_enum_frame_interval(struct v4l2_subdev *sd, in max96722_enum_frame_interval() argument
1675 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_enum_frame_interval()
1677 if (fie->index >= max96722->cfg_modes_num) in max96722_enum_frame_interval()
1678 return -EINVAL; in max96722_enum_frame_interval()
1680 fie->code = max96722->supported_modes[fie->index].bus_fmt; in max96722_enum_frame_interval()
1681 fie->width = max96722->supported_modes[fie->index].width; in max96722_enum_frame_interval()
1682 fie->height = max96722->supported_modes[fie->index].height; in max96722_enum_frame_interval()
1683 fie->interval = max96722->supported_modes[fie->index].max_fps; in max96722_enum_frame_interval()
1688 static int max96722_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad, in max96722_g_mbus_config() argument
1691 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_g_mbus_config()
1693 u8 data_lanes = max96722->bus_cfg.bus.mipi_csi2.num_data_lanes; in max96722_g_mbus_config()
1696 val |= (1 << (data_lanes - 1)); in max96722_g_mbus_config()
1713 config->type = V4L2_MBUS_CSI2_DPHY; in max96722_g_mbus_config()
1714 config->flags = val; in max96722_g_mbus_config()
1719 static int max96722_get_selection(struct v4l2_subdev *sd, in max96722_get_selection() argument
1723 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_get_selection()
1725 if (sel->target == V4L2_SEL_TGT_CROP_BOUNDS) { in max96722_get_selection()
1726 sel->r.left = 0; in max96722_get_selection()
1727 sel->r.width = max96722->cur_mode->width; in max96722_get_selection()
1728 sel->r.top = 0; in max96722_get_selection()
1729 sel->r.height = max96722->cur_mode->height; in max96722_get_selection()
1733 return -EINVAL; in max96722_get_selection()
1782 handler = &max96722->ctrl_handler; in max96722_initialize_controls()
1784 mode = max96722->cur_mode; in max96722_initialize_controls()
1788 handler->lock = &max96722->mutex; in max96722_initialize_controls()
1790 max96722->link_freq = v4l2_ctrl_new_int_menu(handler, NULL, in max96722_initialize_controls()
1792 ARRAY_SIZE(link_freq_items) - 1, 0, in max96722_initialize_controls()
1794 __v4l2_ctrl_s_ctrl(max96722->link_freq, mode->link_freq_idx); in max96722_initialize_controls()
1795 dev_info(&max96722->client->dev, "mipi_freq_idx = %d, mipi_link_freq = %lld\n", in max96722_initialize_controls()
1796 mode->link_freq_idx, link_freq_items[mode->link_freq_idx]); in max96722_initialize_controls()
1799 data_lanes = max96722->bus_cfg.bus.mipi_csi2.num_data_lanes; in max96722_initialize_controls()
1800 pixel_rate = (u32)link_freq_items[mode->link_freq_idx] / mode->bpp * 2 * data_lanes; in max96722_initialize_controls()
1801 max96722->pixel_rate = in max96722_initialize_controls()
1804 dev_info(&max96722->client->dev, "pixel_rate = %lld, bpp = %d\n", in max96722_initialize_controls()
1805 pixel_rate, mode->bpp); in max96722_initialize_controls()
1807 if (handler->error) { in max96722_initialize_controls()
1808 ret = handler->error; in max96722_initialize_controls()
1809 dev_err(&max96722->client->dev, "Failed to init controls(%d)\n", ret); in max96722_initialize_controls()
1813 max96722->subdev.ctrl_handler = handler; in max96722_initialize_controls()
1828 max96722->supplies[i].supply = max96722_supply_names[i]; in max96722_configure_regulators()
1830 return devm_regulator_bulk_get(&max96722->client->dev, in max96722_configure_regulators()
1832 max96722->supplies); in max96722_configure_regulators()
1837 struct device *dev = &max96722->client->dev; in max96722_parse_dt()
1838 struct device_node *node = dev->of_node; in max96722_parse_dt()
1839 u8 mipi_data_lanes = max96722->bus_cfg.bus.mipi_csi2.num_data_lanes; in max96722_parse_dt()
1844 ret = of_property_read_u32(node, "ser-i2c-addr", &value); in max96722_parse_dt()
1846 max96722->i2c_addr[I2C_DEV_SER] = SER_I2C_ADDR; in max96722_parse_dt()
1848 dev_info(dev, "ser-i2c-addr property: %d\n", value); in max96722_parse_dt()
1849 max96722->i2c_addr[I2C_DEV_SER] = value; in max96722_parse_dt()
1851 dev_info(dev, "serializer i2c address: 0x%02x\n", max96722->i2c_addr[I2C_DEV_SER]); in max96722_parse_dt()
1855 * bit0 - LinkA, bit1 - LinkB, bit2 - LinkC, bit3 - LinkD in max96722_parse_dt()
1857 * bit4 - LinkA, bit5 - LinkB, bit6 - LinkC, bit7 = LinkD in max96722_parse_dt()
1859 ret = of_property_read_u32(node, "link-mask", &max96722->link_mask); in max96722_parse_dt()
1863 max96722->link_mask = 0xFF; /* Link A/B/C/D: GMSL2 and enable */ in max96722_parse_dt()
1865 max96722->link_mask = 0x33; /* Link A/B: GMSL2 and enable */ in max96722_parse_dt()
1867 dev_info(dev, "link-mask property: 0x%08x\n", max96722->link_mask); in max96722_parse_dt()
1869 dev_info(dev, "serdes link mask: 0x%02x\n", max96722->link_mask); in max96722_parse_dt()
1872 ret = of_property_read_u32(node, "auto-init-deskew-mask", in max96722_parse_dt()
1873 &max96722->auto_init_deskew_mask); in max96722_parse_dt()
1875 max96722->auto_init_deskew_mask = 0x0F; // 0x0F: default enable all in max96722_parse_dt()
1876 dev_info(dev, "auto init deskew mask: 0x%02x\n", max96722->auto_init_deskew_mask); in max96722_parse_dt()
1879 ret = of_property_read_u32(node, "frame-sync-period", in max96722_parse_dt()
1880 &max96722->frame_sync_period); in max96722_parse_dt()
1882 max96722->frame_sync_period = 0; // 0: disable (default) in max96722_parse_dt()
1883 dev_info(dev, "frame sync period: %d\n", max96722->frame_sync_period); in max96722_parse_dt()
1891 struct device *dev = &client->dev; in max96722_probe()
1892 struct device_node *node = dev->of_node; in max96722_probe()
1894 struct v4l2_subdev *sd; in max96722_probe() local
1905 return -ENOMEM; in max96722_probe()
1908 &max96722->module_index); in max96722_probe()
1910 &max96722->module_facing); in max96722_probe()
1912 &max96722->module_name); in max96722_probe()
1914 &max96722->len_name); in max96722_probe()
1917 return -EINVAL; in max96722_probe()
1920 max96722->regmap = devm_regmap_init_i2c(client, &max96722_regmap_config); in max96722_probe()
1921 if (IS_ERR(max96722->regmap)) { in max96722_probe()
1923 return PTR_ERR(max96722->regmap); in max96722_probe()
1926 max96722->client = client; in max96722_probe()
1930 max96722->i2c_addr[I2C_DEV_DES] = client->addr; in max96722_probe()
1931 max96722->i2c_addr[I2C_DEV_SER] = SER_I2C_ADDR; in max96722_probe()
1932 max96722->i2c_addr[I2C_DEV_CAM] = CAM_I2C_ADDR; in max96722_probe()
1934 endpoint = of_graph_get_next_endpoint(dev->of_node, NULL); in max96722_probe()
1937 return -EINVAL; in max96722_probe()
1941 &max96722->bus_cfg); in max96722_probe()
1944 return -EINVAL; in max96722_probe()
1946 mipi_data_lanes = max96722->bus_cfg.bus.mipi_csi2.num_data_lanes; in max96722_probe()
1950 max96722->supported_modes = supported_modes_4lane; in max96722_probe()
1951 max96722->cfg_modes_num = ARRAY_SIZE(supported_modes_4lane); in max96722_probe()
1954 return -EINVAL; in max96722_probe()
1956 max96722->cur_mode = &max96722->supported_modes[0]; in max96722_probe()
1958 max96722->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW); in max96722_probe()
1959 if (IS_ERR(max96722->power_gpio)) in max96722_probe()
1960 dev_warn(dev, "Failed to get power-gpios, maybe no use\n"); in max96722_probe()
1962 max96722->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in max96722_probe()
1963 if (IS_ERR(max96722->reset_gpio)) in max96722_probe()
1964 dev_warn(dev, "Failed to get reset-gpios\n"); in max96722_probe()
1966 max96722->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW); in max96722_probe()
1967 if (IS_ERR(max96722->pwdn_gpio)) in max96722_probe()
1968 dev_warn(dev, "Failed to get pwdn-gpios\n"); in max96722_probe()
1970 max96722->pocen_gpio = devm_gpiod_get(dev, "pocen", GPIOD_OUT_LOW); in max96722_probe()
1971 if (IS_ERR(max96722->pocen_gpio)) in max96722_probe()
1972 dev_warn(dev, "Failed to get pocen-gpios\n"); in max96722_probe()
1974 max96722->lock_gpio = devm_gpiod_get(dev, "lock", GPIOD_IN); in max96722_probe()
1975 if (IS_ERR(max96722->lock_gpio)) in max96722_probe()
1976 dev_warn(dev, "Failed to get lock-gpios\n"); in max96722_probe()
1984 max96722->pinctrl = devm_pinctrl_get(dev); in max96722_probe()
1985 if (!IS_ERR(max96722->pinctrl)) { in max96722_probe()
1986 max96722->pins_default = pinctrl_lookup_state( in max96722_probe()
1987 max96722->pinctrl, OF_CAMERA_PINCTRL_STATE_DEFAULT); in max96722_probe()
1988 if (IS_ERR(max96722->pins_default)) in max96722_probe()
1991 max96722->pins_sleep = pinctrl_lookup_state( in max96722_probe()
1992 max96722->pinctrl, OF_CAMERA_PINCTRL_STATE_SLEEP); in max96722_probe()
1993 if (IS_ERR(max96722->pins_sleep)) in max96722_probe()
1999 mutex_init(&max96722->mutex); in max96722_probe()
2001 sd = &max96722->subdev; in max96722_probe()
2002 v4l2_i2c_subdev_init(sd, client, &max96722_subdev_ops); in max96722_probe()
2016 sd->internal_ops = &max96722_internal_ops; in max96722_probe()
2017 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in max96722_probe()
2020 max96722->pad.flags = MEDIA_PAD_FL_SOURCE; in max96722_probe()
2021 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in max96722_probe()
2022 ret = media_entity_pads_init(&sd->entity, 1, &max96722->pad); in max96722_probe()
2028 if (strcmp(max96722->module_facing, "back") == 0) in max96722_probe()
2033 v4l2_set_subdevdata(sd, max96722); in max96722_probe()
2035 snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s", in max96722_probe()
2036 max96722->module_index, facing, MAX96722_NAME, in max96722_probe()
2037 dev_name(sd->dev)); in max96722_probe()
2038 ret = v4l2_async_register_subdev_sensor_common(sd); in max96722_probe()
2044 if (!IS_ERR(max96722->lock_gpio)) { in max96722_probe()
2045 max96722->hot_plug_irq = gpiod_to_irq(max96722->lock_gpio); in max96722_probe()
2046 if (max96722->hot_plug_irq < 0) { in max96722_probe()
2050 max96722->hot_plug_irq, in max96722_probe()
2058 max96722->hot_plug_irq = -1; in max96722_probe()
2060 disable_irq(max96722->hot_plug_irq); in max96722_probe()
2073 media_entity_cleanup(&sd->entity); in max96722_probe()
2078 v4l2_ctrl_handler_free(&max96722->ctrl_handler); in max96722_probe()
2080 mutex_destroy(&max96722->mutex); in max96722_probe()
2087 struct v4l2_subdev *sd = i2c_get_clientdata(client); in max96722_remove() local
2088 struct max96722 *max96722 = v4l2_get_subdevdata(sd); in max96722_remove()
2090 v4l2_async_unregister_subdev(sd); in max96722_remove()
2092 media_entity_cleanup(&sd->entity); in max96722_remove()
2094 v4l2_ctrl_handler_free(&max96722->ctrl_handler); in max96722_remove()
2095 mutex_destroy(&max96722->mutex); in max96722_remove()
2097 pm_runtime_disable(&client->dev); in max96722_remove()
2098 if (!pm_runtime_status_suspended(&client->dev)) in max96722_remove()
2100 pm_runtime_set_suspended(&client->dev); in max96722_remove()