Lines Matching +full:clkout +full:- +full:fmt

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/clk-provider.h>
16 #include <linux/i2c-atr.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-mediabus.h>
30 #include <media/v4l2-subdev.h>
121 /* FPD-Link III CSI-2 synchronous mode */
123 /* FPD-Link III CSI-2 non-synchronous mode, external ref clock */
125 /* FPD-Link III CSI-2 non-synchronous mode, internal ref clock */
127 /* FPD-Link III DVP mode */
191 mutex_lock(&priv->reg_lock); in ub953_read()
193 ret = regmap_read(priv->regmap, reg, &v); in ub953_read()
195 dev_err(&priv->client->dev, "Cannot read register 0x%02x: %d\n", in ub953_read()
203 mutex_unlock(&priv->reg_lock); in ub953_read()
212 mutex_lock(&priv->reg_lock); in ub953_write()
214 ret = regmap_write(priv->regmap, reg, val); in ub953_write()
216 dev_err(&priv->client->dev, in ub953_write()
219 mutex_unlock(&priv->reg_lock); in ub953_write()
226 struct device *dev = &priv->client->dev; in ub953_select_ind_reg_block()
229 if (priv->current_indirect_target == block) in ub953_select_ind_reg_block()
232 ret = regmap_write(priv->regmap, UB953_REG_IND_ACC_CTL, block << 2); in ub953_select_ind_reg_block()
239 priv->current_indirect_target = block; in ub953_select_ind_reg_block()
250 mutex_lock(&priv->reg_lock); in ub953_read_ind()
256 ret = regmap_write(priv->regmap, UB953_REG_IND_ACC_ADDR, reg); in ub953_read_ind()
258 dev_err(&priv->client->dev, in ub953_read_ind()
264 ret = regmap_read(priv->regmap, UB953_REG_IND_ACC_DATA, &v); in ub953_read_ind()
266 dev_err(&priv->client->dev, in ub953_read_ind()
275 mutex_unlock(&priv->reg_lock); in ub953_read_ind()
285 mutex_lock(&priv->reg_lock); in ub953_write_ind()
291 ret = regmap_write(priv->regmap, UB953_REG_IND_ACC_ADDR, reg); in ub953_write_ind()
293 dev_err(&priv->client->dev, in ub953_write_ind()
299 ret = regmap_write(priv->regmap, UB953_REG_IND_ACC_DATA, val); in ub953_write_ind()
301 dev_err(&priv->client->dev, in ub953_write_ind()
307 mutex_unlock(&priv->reg_lock); in ub953_write_ind()
335 return regmap_update_bits(priv->regmap, UB953_REG_GPIO_INPUT_CTRL, in ub953_gpio_direction_in()
347 ret = regmap_update_bits(priv->regmap, UB953_REG_LOCAL_GPIO_DATA, in ub953_gpio_direction_out()
355 return regmap_update_bits(priv->regmap, UB953_REG_GPIO_INPUT_CTRL, in ub953_gpio_direction_out()
378 regmap_update_bits(priv->regmap, UB953_REG_LOCAL_GPIO_DATA, in ub953_gpio_set()
389 *flags = gpiospec->args[1]; in ub953_gpio_of_xlate()
391 return gpiospec->args[0]; in ub953_gpio_of_xlate()
396 struct device *dev = &priv->client->dev; in ub953_gpiochip_probe()
397 struct gpio_chip *gc = &priv->gpio_chip; in ub953_gpiochip_probe()
404 gc->label = dev_name(dev); in ub953_gpiochip_probe()
405 gc->parent = dev; in ub953_gpiochip_probe()
406 gc->owner = THIS_MODULE; in ub953_gpiochip_probe()
407 gc->base = -1; in ub953_gpiochip_probe()
408 gc->can_sleep = true; in ub953_gpiochip_probe()
409 gc->ngpio = UB953_NUM_GPIOS; in ub953_gpiochip_probe()
410 gc->get_direction = ub953_gpio_get_direction; in ub953_gpiochip_probe()
411 gc->direction_input = ub953_gpio_direction_in; in ub953_gpiochip_probe()
412 gc->direction_output = ub953_gpio_direction_out; in ub953_gpiochip_probe()
413 gc->get = ub953_gpio_get; in ub953_gpiochip_probe()
414 gc->set = ub953_gpio_set; in ub953_gpiochip_probe()
415 gc->of_xlate = ub953_gpio_of_xlate; in ub953_gpiochip_probe()
416 gc->of_gpio_n_cells = 2; in ub953_gpiochip_probe()
429 gpiochip_remove(&priv->gpio_chip); in ub953_gpiochip_remove()
457 if (routing->num_routes > V4L2_FRAME_DESC_ENTRY_MAX) in _ub953_set_routing()
458 return -EINVAL; in _ub953_set_routing()
479 if (which == V4L2_SUBDEV_FORMAT_ACTIVE && priv->enabled_source_streams) in ub953_set_routing()
480 return -EBUSY; in ub953_set_routing()
495 return -EINVAL; in ub953_get_frame_desc()
497 ret = v4l2_subdev_call(priv->source_sd, pad, get_frame_desc, in ub953_get_frame_desc()
498 priv->source_sd_pad, &source_fd); in ub953_get_frame_desc()
502 fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2; in ub953_get_frame_desc()
506 for_each_active_route(&state->routing, route) { in ub953_get_frame_desc()
510 if (route->source_pad != pad) in ub953_get_frame_desc()
514 if (source_fd.entry[i].stream == route->sink_stream) { in ub953_get_frame_desc()
521 dev_err(&priv->client->dev, in ub953_get_frame_desc()
523 ret = -EPIPE; in ub953_get_frame_desc()
527 fd->entry[fd->num_entries].stream = route->source_stream; in ub953_get_frame_desc()
528 fd->entry[fd->num_entries].flags = source_entry->flags; in ub953_get_frame_desc()
529 fd->entry[fd->num_entries].length = source_entry->length; in ub953_get_frame_desc()
530 fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode; in ub953_get_frame_desc()
531 fd->entry[fd->num_entries].bus.csi2.vc = in ub953_get_frame_desc()
532 source_entry->bus.csi2.vc; in ub953_get_frame_desc()
533 fd->entry[fd->num_entries].bus.csi2.dt = in ub953_get_frame_desc()
534 source_entry->bus.csi2.dt; in ub953_get_frame_desc()
536 fd->num_entries++; in ub953_get_frame_desc()
550 struct v4l2_mbus_framefmt *fmt; in ub953_set_fmt() local
552 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE && in ub953_set_fmt()
553 priv->enabled_source_streams) in ub953_set_fmt()
554 return -EBUSY; in ub953_set_fmt()
557 if (format->pad == UB953_PAD_SOURCE) in ub953_set_fmt()
561 fmt = v4l2_subdev_state_get_format(state, format->pad, format->stream); in ub953_set_fmt()
562 if (!fmt) in ub953_set_fmt()
563 return -EINVAL; in ub953_set_fmt()
565 *fmt = format->format; in ub953_set_fmt()
568 fmt = v4l2_subdev_state_get_opposite_stream_format(state, format->pad, in ub953_set_fmt()
569 format->stream); in ub953_set_fmt()
570 if (!fmt) in ub953_set_fmt()
571 return -EINVAL; in ub953_set_fmt()
573 *fmt = format->format; in ub953_set_fmt()
602 struct device *dev = &priv->client->dev; in ub953_log_status()
677 ret = v4l2_subdev_enable_streams(priv->source_sd, priv->source_sd_pad, in ub953_enable_streams()
682 priv->enabled_source_streams |= streams_mask; in ub953_enable_streams()
699 ret = v4l2_subdev_disable_streams(priv->source_sd, priv->source_sd_pad, in ub953_disable_streams()
704 priv->enabled_source_streams &= ~streams_mask; in ub953_disable_streams()
741 struct ub953_data *priv = sd_to_ub953(notifier->sd); in ub953_notify_bound()
742 struct device *dev = &priv->client->dev; in ub953_notify_bound()
745 ret = media_entity_get_fwnode_pad(&source_subdev->entity, in ub953_notify_bound()
746 source_subdev->fwnode, in ub953_notify_bound()
750 source_subdev->name); in ub953_notify_bound()
754 priv->source_sd = source_subdev; in ub953_notify_bound()
755 priv->source_sd_pad = ret; in ub953_notify_bound()
757 ret = media_create_pad_link(&source_subdev->entity, priv->source_sd_pad, in ub953_notify_bound()
758 &priv->sd.entity, 0, in ub953_notify_bound()
762 dev_err(dev, "Unable to link %s:%u -> %s:0\n", in ub953_notify_bound()
763 source_subdev->name, priv->source_sd_pad, in ub953_notify_bound()
764 priv->sd.name); in ub953_notify_bound()
777 struct device *dev = &priv->client->dev; in ub953_v4l2_notifier_register()
786 return -ENODEV; in ub953_v4l2_notifier_register()
789 v4l2_async_subdev_nf_init(&priv->notifier, &priv->sd); in ub953_v4l2_notifier_register()
791 asd = v4l2_async_nf_add_fwnode_remote(&priv->notifier, ep_fwnode, in ub953_v4l2_notifier_register()
798 v4l2_async_nf_cleanup(&priv->notifier); in ub953_v4l2_notifier_register()
802 priv->notifier.ops = &ub953_notify_ops; in ub953_v4l2_notifier_register()
804 ret = v4l2_async_nf_register(&priv->notifier); in ub953_v4l2_notifier_register()
807 v4l2_async_nf_cleanup(&priv->notifier); in ub953_v4l2_notifier_register()
816 v4l2_async_nf_unregister(&priv->notifier); in ub953_v4l2_notifier_unregister()
817 v4l2_async_nf_cleanup(&priv->notifier); in ub953_v4l2_notifier_unregister()
832 scl_high = div64_u64((u64)scl_high * ref, 1000000000) - 5; in ub953_i2c_master_init()
833 scl_low = div64_u64((u64)scl_low * ref, 1000000000) - 5; in ub953_i2c_master_init()
848 switch (priv->mode) { in ub953_get_fc_rate()
850 if (priv->hw_data->is_ub971) in ub953_get_fc_rate()
851 return priv->plat_data->bc_rate * 160ull; in ub953_get_fc_rate()
853 return priv->plat_data->bc_rate / 2 * 160ull; in ub953_get_fc_rate()
857 return clk_get_rate(priv->clkin) * 80ull; in ub953_get_fc_rate()
870 * We always use 4 as a pre-divider (HS_CLK_DIV = 2). in ub953_calc_clkout_ub953()
873 * - "HS_CLK_DIV typically should be set to either 16, 8, or 4 (default)." in ub953_calc_clkout_ub953()
874 * - "if it is not possible to have an integer ratio of N/M, it is best to in ub953_calc_clkout_ub953()
886 /* clkout = fc / hs_clk_div * m / n */ in ub953_calc_clkout_ub953()
890 rational_best_approximation(target, fc_divided, (1 << 5) - 1, in ub953_calc_clkout_ub953()
891 (1 << 8) - 1, &mul, &div); in ub953_calc_clkout_ub953()
910 /* clkout = fc * m / (8 * n) */ in ub953_calc_clkout_ub971()
914 rational_best_approximation(target, fc_divided, (1 << 5) - 1, in ub953_calc_clkout_ub971()
915 (1 << 8) - 1, &mul, &div); in ub953_calc_clkout_ub971()
929 struct device *dev = &priv->client->dev; in ub953_calc_clkout_params()
935 if (priv->hw_data->is_ub971) { in ub953_calc_clkout_params()
941 clkout_data->m = m; in ub953_calc_clkout_params()
942 clkout_data->n = n; in ub953_calc_clkout_params()
952 clkout_data->hs_div = hs_div; in ub953_calc_clkout_params()
953 clkout_data->m = m; in ub953_calc_clkout_params()
954 clkout_data->n = n; in ub953_calc_clkout_params()
961 clkout_data->rate = clkout_rate; in ub953_calc_clkout_params()
969 if (priv->hw_data->is_ub971) in ub953_write_clkout_regs()
970 clkout_ctrl0 = clkout_data->m; in ub953_write_clkout_regs()
972 clkout_ctrl0 = (__ffs(clkout_data->hs_div) << 5) | in ub953_write_clkout_regs()
973 clkout_data->m; in ub953_write_clkout_regs()
975 clkout_ctrl1 = clkout_data->n; in ub953_write_clkout_regs()
985 struct device *dev = &priv->client->dev; in ub953_clkout_recalc_rate()
1007 if (priv->hw_data->is_ub971) { in ub953_clkout_recalc_rate()
1016 dev_dbg(dev, "clkout: fc rate %llu, mul %u, div %u = %llu\n", in ub953_clkout_recalc_rate()
1029 "clkout: fc rate %llu, hs_clk_div %u, mul %u, div %u = %llu\n", in ub953_clkout_recalc_rate()
1055 dev_dbg(&priv->client->dev, "%s %lu (requested %lu)\n", __func__, in ub953_clkout_set_rate()
1071 struct device *dev = &priv->client->dev; in ub953_register_clkout()
1074 priv->hw_data->model, dev_name(dev)), in ub953_register_clkout()
1081 return -ENOMEM; in ub953_register_clkout()
1083 /* Initialize clkout to 25MHz by default */ in ub953_register_clkout()
1087 priv->clkout_clk_hw.init = &init; in ub953_register_clkout()
1089 ret = devm_clk_hw_register(dev, &priv->clkout_clk_hw); in ub953_register_clkout()
1095 &priv->clkout_clk_hw); in ub953_register_clkout()
1105 struct device *dev = &priv->client->dev; in ub953_add_i2c_adapter()
1113 ret = i2c_atr_add_adapter(priv->plat_data->atr, priv->plat_data->port, in ub953_add_i2c_adapter()
1134 struct device *dev = &priv->client->dev; in ub953_parse_dt()
1145 return dev_err_probe(dev, -ENOENT, "no endpoint found\n"); in ub953_parse_dt()
1157 return dev_err_probe(dev, -EINVAL, in ub953_parse_dt()
1158 "bad number of data-lanes: %u\n", nlanes); in ub953_parse_dt()
1160 priv->num_data_lanes = nlanes; in ub953_parse_dt()
1162 priv->non_continous_clk = vep.bus.mipi_csi2.flags & in ub953_parse_dt()
1170 struct device *dev = &priv->client->dev; in ub953_hw_init()
1180 return dev_err_probe(dev, -EIO, "Mode value not stabilized\n"); in ub953_hw_init()
1186 priv->mode = UB953_MODE_SYNC; in ub953_hw_init()
1189 priv->mode = UB953_MODE_NONSYNC_EXT; in ub953_hw_init()
1192 priv->mode = UB953_MODE_NONSYNC_INT; in ub953_hw_init()
1195 priv->mode = UB953_MODE_DVP; in ub953_hw_init()
1198 return dev_err_probe(dev, -EIO, in ub953_hw_init()
1203 priv->mode); in ub953_hw_init()
1205 if (priv->mode != UB953_MODE_SYNC && in ub953_hw_init()
1206 priv->mode != UB953_MODE_NONSYNC_EXT) in ub953_hw_init()
1207 return dev_err_probe(dev, -ENODEV, in ub953_hw_init()
1209 priv->mode); in ub953_hw_init()
1211 if (priv->mode == UB953_MODE_NONSYNC_EXT && !priv->clkin) in ub953_hw_init()
1212 return dev_err_probe(dev, -EINVAL, in ub953_hw_init()
1213 "clkin required for non-sync ext mode\n"); in ub953_hw_init()
1219 dev_info(dev, "Found %s rev/mask %#04x\n", priv->hw_data->model, v); in ub953_hw_init()
1233 (priv->non_continous_clk ? 0 : UB953_REG_GENERAL_CFG_CONT_CLK) | in ub953_hw_init()
1234 ((priv->num_data_lanes - 1) << UB953_REG_GENERAL_CFG_CSI_LANE_SEL_SHIFT) | in ub953_hw_init()
1242 struct device *dev = &priv->client->dev; in ub953_subdev_init()
1245 v4l2_i2c_subdev_init(&priv->sd, priv->client, &ub953_subdev_ops); in ub953_subdev_init()
1246 priv->sd.internal_ops = &ub953_internal_ops; in ub953_subdev_init()
1248 priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ub953_subdev_init()
1250 priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in ub953_subdev_init()
1251 priv->sd.entity.ops = &ub953_entity_ops; in ub953_subdev_init()
1253 priv->pads[0].flags = MEDIA_PAD_FL_SINK; in ub953_subdev_init()
1254 priv->pads[1].flags = MEDIA_PAD_FL_SOURCE; in ub953_subdev_init()
1256 ret = media_entity_pads_init(&priv->sd.entity, 2, priv->pads); in ub953_subdev_init()
1260 ret = v4l2_subdev_init_finalize(&priv->sd); in ub953_subdev_init()
1271 ret = v4l2_async_register_subdev(&priv->sd); in ub953_subdev_init()
1282 v4l2_subdev_cleanup(&priv->sd); in ub953_subdev_init()
1284 media_entity_cleanup(&priv->sd.entity); in ub953_subdev_init()
1291 v4l2_async_unregister_subdev(&priv->sd); in ub953_subdev_uninit()
1293 v4l2_subdev_cleanup(&priv->sd); in ub953_subdev_uninit()
1294 fwnode_handle_put(priv->sd.fwnode); in ub953_subdev_uninit()
1295 media_entity_cleanup(&priv->sd.entity); in ub953_subdev_uninit()
1300 struct device *dev = &client->dev; in ub953_probe()
1306 return -ENOMEM; in ub953_probe()
1308 priv->client = client; in ub953_probe()
1310 priv->hw_data = device_get_match_data(dev); in ub953_probe()
1312 priv->plat_data = dev_get_platdata(&client->dev); in ub953_probe()
1313 if (!priv->plat_data) in ub953_probe()
1314 return dev_err_probe(dev, -ENODEV, "Platform data missing\n"); in ub953_probe()
1316 mutex_init(&priv->reg_lock); in ub953_probe()
1322 priv->current_indirect_target = 0xff; in ub953_probe()
1324 priv->regmap = devm_regmap_init_i2c(client, &ub953_regmap_config); in ub953_probe()
1325 if (IS_ERR(priv->regmap)) { in ub953_probe()
1326 ret = PTR_ERR(priv->regmap); in ub953_probe()
1331 priv->clkin = devm_clk_get_optional(dev, "clkin"); in ub953_probe()
1332 if (IS_ERR(priv->clkin)) { in ub953_probe()
1333 ret = PTR_ERR(priv->clkin); in ub953_probe()
1354 dev_err_probe(dev, ret, "Failed to register clkout\n"); in ub953_probe()
1375 mutex_destroy(&priv->reg_lock); in ub953_probe()
1385 i2c_atr_del_adapter(priv->plat_data->atr, priv->plat_data->port); in ub953_remove()
1390 mutex_destroy(&priv->reg_lock); in ub953_remove()
1403 { "ds90ub953-q1", (kernel_ulong_t)&ds90ub953_hw },
1404 { "ds90ub971-q1", (kernel_ulong_t)&ds90ub971_hw },
1410 { .compatible = "ti,ds90ub953-q1", .data = &ds90ub953_hw },
1411 { .compatible = "ti,ds90ub971-q1", .data = &ds90ub971_hw },
1428 MODULE_DESCRIPTION("Texas Instruments FPD-Link III/IV CSI-2 Serializers Driver");