Lines Matching +full:alvium +full:- +full:csi2

1 // SPDX-License-Identifier: GPL-2.0
3 * Allied Vision Technologies GmbH Alvium camera driver
15 #include <media/mipi-csi2.h>
16 #include <media/v4l2-async.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/v4l2-device.h>
19 #include <media/v4l2-event.h>
20 #include <media/v4l2-fwnode.h>
21 #include <media/v4l2-subdev.h>
23 #include "alvium-csi2.h"
45 .bay_fmt_regval = -1,
55 .bay_fmt_regval = -1,
65 .bay_fmt_regval = -1,
75 .bay_fmt_regval = -1,
85 .bay_fmt_regval = -1,
95 .bay_fmt_regval = -1,
105 .bay_fmt_regval = -1,
115 .bay_fmt_regval = -1,
125 .bay_fmt_regval = -1,
321 static int alvium_read(struct alvium_dev *alvium, u32 reg, u64 *val, int *err) in alvium_read() argument
325 reg += alvium->bcrm_addr; in alvium_read()
328 return cci_read(alvium->regmap, reg, val, err); in alvium_read()
331 static int alvium_write(struct alvium_dev *alvium, u32 reg, u64 val, int *err) in alvium_write() argument
335 reg += alvium->bcrm_addr; in alvium_write()
338 return cci_write(alvium->regmap, reg, val, err); in alvium_write()
341 static int alvium_write_hshake(struct alvium_dev *alvium, u32 reg, u64 val) in alvium_write_hshake() argument
343 struct device *dev = &alvium->i2c_client->dev; in alvium_write_hshake()
347 /* reset handshake bit and write alvium reg */ in alvium_write_hshake()
348 alvium_write(alvium, REG_BCRM_WRITE_HANDSHAKE_RW, 0, &ret); in alvium_write_hshake()
349 alvium_write(alvium, reg, val, &ret); in alvium_write_hshake()
359 alvium, REG_BCRM_WRITE_HANDSHAKE_RW, in alvium_write_hshake()
367 alvium_write(alvium, REG_BCRM_WRITE_HANDSHAKE_RW, 0, &ret); in alvium_write_hshake()
377 alvium, REG_BCRM_WRITE_HANDSHAKE_RW, in alvium_write_hshake()
387 static int alvium_get_bcrm_vers(struct alvium_dev *alvium) in alvium_get_bcrm_vers() argument
389 struct device *dev = &alvium->i2c_client->dev; in alvium_get_bcrm_vers()
393 ret = alvium_read(alvium, REG_BCRM_MINOR_VERSION_R, &min, &ret); in alvium_get_bcrm_vers()
394 ret = alvium_read(alvium, REG_BCRM_MAJOR_VERSION_R, &maj, &ret); in alvium_get_bcrm_vers()
403 static int alvium_get_fw_version(struct alvium_dev *alvium) in alvium_get_fw_version() argument
405 struct device *dev = &alvium->i2c_client->dev; in alvium_get_fw_version()
409 ret = alvium_read(alvium, REG_BCRM_DEVICE_FW, &val, NULL); in alvium_get_fw_version()
426 static int alvium_get_bcrm_addr(struct alvium_dev *alvium) in alvium_get_bcrm_addr() argument
431 ret = alvium_read(alvium, REG_BCRM_REG_ADDR_R, &val, NULL); in alvium_get_bcrm_addr()
435 alvium->bcrm_addr = val; in alvium_get_bcrm_addr()
440 static int alvium_is_alive(struct alvium_dev *alvium) in alvium_is_alive() argument
445 alvium_read(alvium, REG_BCRM_MINOR_VERSION_R, &bcrm, &ret); in alvium_is_alive()
446 alvium_read(alvium, REG_BCRM_HEARTBEAT_RW, &hbeat, &ret); in alvium_is_alive()
453 static void alvium_print_avail_mipi_fmt(struct alvium_dev *alvium) in alvium_print_avail_mipi_fmt() argument
455 struct device *dev = &alvium->i2c_client->dev; in alvium_print_avail_mipi_fmt()
458 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8_LEG]); in alvium_print_avail_mipi_fmt()
460 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8]); in alvium_print_avail_mipi_fmt()
462 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_10]); in alvium_print_avail_mipi_fmt()
464 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8_CSPS]); in alvium_print_avail_mipi_fmt()
466 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_10_CSPS]); in alvium_print_avail_mipi_fmt()
468 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV422_8]); in alvium_print_avail_mipi_fmt()
470 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV422_10]); in alvium_print_avail_mipi_fmt()
472 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB888]); in alvium_print_avail_mipi_fmt()
474 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB666]); in alvium_print_avail_mipi_fmt()
476 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB565]); in alvium_print_avail_mipi_fmt()
478 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB555]); in alvium_print_avail_mipi_fmt()
480 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB444]); in alvium_print_avail_mipi_fmt()
482 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW6]); in alvium_print_avail_mipi_fmt()
484 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW7]); in alvium_print_avail_mipi_fmt()
486 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW8]); in alvium_print_avail_mipi_fmt()
488 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW10]); in alvium_print_avail_mipi_fmt()
490 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW12]); in alvium_print_avail_mipi_fmt()
492 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW14]); in alvium_print_avail_mipi_fmt()
494 alvium->is_mipi_fmt_avail[ALVIUM_BIT_JPEG]); in alvium_print_avail_mipi_fmt()
497 static void alvium_print_avail_feat(struct alvium_dev *alvium) in alvium_print_avail_feat() argument
499 struct device *dev = &alvium->i2c_client->dev; in alvium_print_avail_feat()
501 dev_dbg(dev, "feature rev_x: %u\n", alvium->avail_ft.rev_x); in alvium_print_avail_feat()
502 dev_dbg(dev, "feature rev_y: %u\n", alvium->avail_ft.rev_y); in alvium_print_avail_feat()
503 dev_dbg(dev, "feature int_autop: %u\n", alvium->avail_ft.int_autop); in alvium_print_avail_feat()
504 dev_dbg(dev, "feature black_lvl: %u\n", alvium->avail_ft.black_lvl); in alvium_print_avail_feat()
505 dev_dbg(dev, "feature gain: %u\n", alvium->avail_ft.gain); in alvium_print_avail_feat()
506 dev_dbg(dev, "feature gamma: %u\n", alvium->avail_ft.gamma); in alvium_print_avail_feat()
507 dev_dbg(dev, "feature contrast: %u\n", alvium->avail_ft.contrast); in alvium_print_avail_feat()
508 dev_dbg(dev, "feature sat: %u\n", alvium->avail_ft.sat); in alvium_print_avail_feat()
509 dev_dbg(dev, "feature hue: %u\n", alvium->avail_ft.hue); in alvium_print_avail_feat()
510 dev_dbg(dev, "feature whiteb: %u\n", alvium->avail_ft.whiteb); in alvium_print_avail_feat()
511 dev_dbg(dev, "feature sharp: %u\n", alvium->avail_ft.sharp); in alvium_print_avail_feat()
512 dev_dbg(dev, "feature auto_exp: %u\n", alvium->avail_ft.auto_exp); in alvium_print_avail_feat()
513 dev_dbg(dev, "feature auto_gain: %u\n", alvium->avail_ft.auto_gain); in alvium_print_avail_feat()
514 dev_dbg(dev, "feature auto_whiteb: %u\n", alvium->avail_ft.auto_whiteb); in alvium_print_avail_feat()
515 dev_dbg(dev, "feature dev_temp: %u\n", alvium->avail_ft.dev_temp); in alvium_print_avail_feat()
516 dev_dbg(dev, "feature acq_abort: %u\n", alvium->avail_ft.acq_abort); in alvium_print_avail_feat()
517 dev_dbg(dev, "feature acq_fr: %u\n", alvium->avail_ft.acq_fr); in alvium_print_avail_feat()
518 dev_dbg(dev, "feature fr_trigger: %u\n", alvium->avail_ft.fr_trigger); in alvium_print_avail_feat()
520 alvium->avail_ft.exp_acq_line); in alvium_print_avail_feat()
523 static void alvium_print_avail_bayer(struct alvium_dev *alvium) in alvium_print_avail_bayer() argument
525 struct device *dev = &alvium->i2c_client->dev; in alvium_print_avail_bayer()
528 alvium->is_bay_avail[ALVIUM_BIT_BAY_MONO]); in alvium_print_avail_bayer()
530 alvium->is_bay_avail[ALVIUM_BIT_BAY_GR]); in alvium_print_avail_bayer()
532 alvium->is_bay_avail[ALVIUM_BIT_BAY_RG]); in alvium_print_avail_bayer()
534 alvium->is_bay_avail[ALVIUM_BIT_BAY_GB]); in alvium_print_avail_bayer()
536 alvium->is_bay_avail[ALVIUM_BIT_BAY_BG]); in alvium_print_avail_bayer()
539 static int alvium_get_feat_inq(struct alvium_dev *alvium) in alvium_get_feat_inq() argument
545 ret = alvium_read(alvium, REG_BCRM_FEATURE_INQUIRY_R, &val, NULL); in alvium_get_feat_inq()
550 alvium->avail_ft = *f; in alvium_get_feat_inq()
551 alvium_print_avail_feat(alvium); in alvium_get_feat_inq()
556 static int alvium_get_host_supp_csi_lanes(struct alvium_dev *alvium) in alvium_get_host_supp_csi_lanes() argument
561 ret = alvium_read(alvium, REG_BCRM_CSI2_LANE_COUNT_RW, &val, NULL); in alvium_get_host_supp_csi_lanes()
565 alvium->h_sup_csi_lanes = val; in alvium_get_host_supp_csi_lanes()
570 static int alvium_set_csi_lanes(struct alvium_dev *alvium) in alvium_set_csi_lanes() argument
572 struct device *dev = &alvium->i2c_client->dev; in alvium_set_csi_lanes()
576 num_lanes = alvium->ep.bus.mipi_csi2.num_data_lanes; in alvium_set_csi_lanes()
578 if (num_lanes > alvium->h_sup_csi_lanes) in alvium_set_csi_lanes()
579 return -EINVAL; in alvium_set_csi_lanes()
581 ret = alvium_write_hshake(alvium, REG_BCRM_CSI2_LANE_COUNT_RW, in alvium_set_csi_lanes()
591 static int alvium_set_lp2hs_delay(struct alvium_dev *alvium) in alvium_set_lp2hs_delay() argument
593 struct device *dev = &alvium->i2c_client->dev; in alvium_set_lp2hs_delay()
602 * Alvium forces a dphy-reset on all lanes for that period. in alvium_set_lp2hs_delay()
606 alvium_write(alvium, REG_BCRM_LP2HS_DELAY_RW, in alvium_set_lp2hs_delay()
616 static int alvium_get_csi_clk_params(struct alvium_dev *alvium) in alvium_get_csi_clk_params() argument
621 alvium_read(alvium, REG_BCRM_CSI2_CLOCK_MIN_R, &min_csi_clk, &ret); in alvium_get_csi_clk_params()
622 alvium_read(alvium, REG_BCRM_CSI2_CLOCK_MAX_R, &max_csi_clk, &ret); in alvium_get_csi_clk_params()
626 alvium->min_csi_clk = min_csi_clk; in alvium_get_csi_clk_params()
627 alvium->max_csi_clk = max_csi_clk; in alvium_get_csi_clk_params()
632 static int alvium_set_csi_clk(struct alvium_dev *alvium) in alvium_set_csi_clk() argument
634 struct device *dev = &alvium->i2c_client->dev; in alvium_set_csi_clk()
638 csi_clk = clamp(alvium->ep.link_frequencies[0], in alvium_set_csi_clk()
639 (u64)alvium->min_csi_clk, (u64)alvium->max_csi_clk); in alvium_set_csi_clk()
641 if (alvium->ep.link_frequencies[0] != (u64)csi_clk) { in alvium_set_csi_clk()
644 alvium->ep.link_frequencies[0], in alvium_set_csi_clk()
645 alvium->min_csi_clk, alvium->max_csi_clk, csi_clk); in alvium_set_csi_clk()
648 ret = alvium_write_hshake(alvium, REG_BCRM_CSI2_CLOCK_RW, csi_clk); in alvium_set_csi_clk()
654 alvium->link_freq = csi_clk; in alvium_set_csi_clk()
659 static int alvium_get_img_width_params(struct alvium_dev *alvium) in alvium_get_img_width_params() argument
664 alvium_read(alvium, REG_BCRM_IMG_WIDTH_RW, &imgw, &ret); in alvium_get_img_width_params()
665 alvium_read(alvium, REG_BCRM_IMG_WIDTH_MIN_R, &imgw_min, &ret); in alvium_get_img_width_params()
666 alvium_read(alvium, REG_BCRM_IMG_WIDTH_MAX_R, &imgw_max, &ret); in alvium_get_img_width_params()
667 alvium_read(alvium, REG_BCRM_IMG_WIDTH_INC_R, &imgw_inc, &ret); in alvium_get_img_width_params()
671 alvium->dft_img_width = imgw; in alvium_get_img_width_params()
672 alvium->img_min_width = imgw_min; in alvium_get_img_width_params()
673 alvium->img_max_width = imgw_max; in alvium_get_img_width_params()
674 alvium->img_inc_width = imgw_inc; in alvium_get_img_width_params()
679 static int alvium_get_img_height_params(struct alvium_dev *alvium) in alvium_get_img_height_params() argument
684 alvium_read(alvium, REG_BCRM_IMG_HEIGHT_RW, &imgh, &ret); in alvium_get_img_height_params()
685 alvium_read(alvium, REG_BCRM_IMG_HEIGHT_MIN_R, &imgh_min, &ret); in alvium_get_img_height_params()
686 alvium_read(alvium, REG_BCRM_IMG_HEIGHT_MAX_R, &imgh_max, &ret); in alvium_get_img_height_params()
687 alvium_read(alvium, REG_BCRM_IMG_HEIGHT_INC_R, &imgh_inc, &ret); in alvium_get_img_height_params()
691 alvium->dft_img_height = imgh; in alvium_get_img_height_params()
692 alvium->img_min_height = imgh_min; in alvium_get_img_height_params()
693 alvium->img_max_height = imgh_max; in alvium_get_img_height_params()
694 alvium->img_inc_height = imgh_inc; in alvium_get_img_height_params()
699 static int alvium_set_img_width(struct alvium_dev *alvium, u32 width) in alvium_set_img_width() argument
701 struct device *dev = &alvium->i2c_client->dev; in alvium_set_img_width()
704 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_WIDTH_RW, width); in alvium_set_img_width()
713 static int alvium_set_img_height(struct alvium_dev *alvium, u32 height) in alvium_set_img_height() argument
715 struct device *dev = &alvium->i2c_client->dev; in alvium_set_img_height()
718 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_HEIGHT_RW, height); in alvium_set_img_height()
727 static int alvium_set_img_offx(struct alvium_dev *alvium, u32 offx) in alvium_set_img_offx() argument
729 struct device *dev = &alvium->i2c_client->dev; in alvium_set_img_offx()
732 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_OFFSET_X_RW, offx); in alvium_set_img_offx()
741 static int alvium_set_img_offy(struct alvium_dev *alvium, u32 offy) in alvium_set_img_offy() argument
743 struct device *dev = &alvium->i2c_client->dev; in alvium_set_img_offy()
746 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_OFFSET_Y_RW, offy); in alvium_set_img_offy()
755 static int alvium_get_offx_params(struct alvium_dev *alvium) in alvium_get_offx_params() argument
760 alvium_read(alvium, REG_BCRM_IMG_OFFSET_X_MIN_R, &min_offx, &ret); in alvium_get_offx_params()
761 alvium_read(alvium, REG_BCRM_IMG_OFFSET_X_MAX_R, &max_offx, &ret); in alvium_get_offx_params()
762 alvium_read(alvium, REG_BCRM_IMG_OFFSET_X_INC_R, &inc_offx, &ret); in alvium_get_offx_params()
766 alvium->min_offx = min_offx; in alvium_get_offx_params()
767 alvium->max_offx = max_offx; in alvium_get_offx_params()
768 alvium->inc_offx = inc_offx; in alvium_get_offx_params()
773 static int alvium_get_offy_params(struct alvium_dev *alvium) in alvium_get_offy_params() argument
778 alvium_read(alvium, REG_BCRM_IMG_OFFSET_Y_MIN_R, &min_offy, &ret); in alvium_get_offy_params()
779 alvium_read(alvium, REG_BCRM_IMG_OFFSET_Y_MAX_R, &max_offy, &ret); in alvium_get_offy_params()
780 alvium_read(alvium, REG_BCRM_IMG_OFFSET_Y_INC_R, &inc_offy, &ret); in alvium_get_offy_params()
784 alvium->min_offy = min_offy; in alvium_get_offy_params()
785 alvium->max_offy = max_offy; in alvium_get_offy_params()
786 alvium->inc_offy = inc_offy; in alvium_get_offy_params()
791 static int alvium_get_gain_params(struct alvium_dev *alvium) in alvium_get_gain_params() argument
796 alvium_read(alvium, REG_BCRM_GAIN_RW, &dft_gain, &ret); in alvium_get_gain_params()
797 alvium_read(alvium, REG_BCRM_GAIN_MIN_R, &min_gain, &ret); in alvium_get_gain_params()
798 alvium_read(alvium, REG_BCRM_GAIN_MAX_R, &max_gain, &ret); in alvium_get_gain_params()
799 alvium_read(alvium, REG_BCRM_GAIN_INC_R, &inc_gain, &ret); in alvium_get_gain_params()
803 alvium->dft_gain = dft_gain; in alvium_get_gain_params()
804 alvium->min_gain = min_gain; in alvium_get_gain_params()
805 alvium->max_gain = max_gain; in alvium_get_gain_params()
806 alvium->inc_gain = inc_gain; in alvium_get_gain_params()
811 static int alvium_get_exposure_params(struct alvium_dev *alvium) in alvium_get_exposure_params() argument
816 alvium_read(alvium, REG_BCRM_EXPOSURE_TIME_RW, &dft_exp, &ret); in alvium_get_exposure_params()
817 alvium_read(alvium, REG_BCRM_EXPOSURE_TIME_MIN_R, &min_exp, &ret); in alvium_get_exposure_params()
818 alvium_read(alvium, REG_BCRM_EXPOSURE_TIME_MAX_R, &max_exp, &ret); in alvium_get_exposure_params()
819 alvium_read(alvium, REG_BCRM_EXPOSURE_TIME_INC_R, &inc_exp, &ret); in alvium_get_exposure_params()
823 alvium->dft_exp = dft_exp; in alvium_get_exposure_params()
824 alvium->min_exp = min_exp; in alvium_get_exposure_params()
825 alvium->max_exp = max_exp; in alvium_get_exposure_params()
826 alvium->inc_exp = inc_exp; in alvium_get_exposure_params()
831 static int alvium_get_red_balance_ratio_params(struct alvium_dev *alvium) in alvium_get_red_balance_ratio_params() argument
836 alvium_read(alvium, REG_BCRM_RED_BALANCE_RATIO_RW, &dft_rb, &ret); in alvium_get_red_balance_ratio_params()
837 alvium_read(alvium, REG_BCRM_RED_BALANCE_RATIO_MIN_R, &min_rb, &ret); in alvium_get_red_balance_ratio_params()
838 alvium_read(alvium, REG_BCRM_RED_BALANCE_RATIO_MAX_R, &max_rb, &ret); in alvium_get_red_balance_ratio_params()
839 alvium_read(alvium, REG_BCRM_RED_BALANCE_RATIO_INC_R, &inc_rb, &ret); in alvium_get_red_balance_ratio_params()
843 alvium->dft_rbalance = dft_rb; in alvium_get_red_balance_ratio_params()
844 alvium->min_rbalance = min_rb; in alvium_get_red_balance_ratio_params()
845 alvium->max_rbalance = max_rb; in alvium_get_red_balance_ratio_params()
846 alvium->inc_rbalance = inc_rb; in alvium_get_red_balance_ratio_params()
851 static int alvium_get_blue_balance_ratio_params(struct alvium_dev *alvium) in alvium_get_blue_balance_ratio_params() argument
856 alvium_read(alvium, REG_BCRM_BLUE_BALANCE_RATIO_RW, &dft_bb, &ret); in alvium_get_blue_balance_ratio_params()
857 alvium_read(alvium, REG_BCRM_BLUE_BALANCE_RATIO_MIN_R, &min_bb, &ret); in alvium_get_blue_balance_ratio_params()
858 alvium_read(alvium, REG_BCRM_BLUE_BALANCE_RATIO_MAX_R, &max_bb, &ret); in alvium_get_blue_balance_ratio_params()
859 alvium_read(alvium, REG_BCRM_BLUE_BALANCE_RATIO_INC_R, &inc_bb, &ret); in alvium_get_blue_balance_ratio_params()
863 alvium->dft_bbalance = dft_bb; in alvium_get_blue_balance_ratio_params()
864 alvium->min_bbalance = min_bb; in alvium_get_blue_balance_ratio_params()
865 alvium->max_bbalance = max_bb; in alvium_get_blue_balance_ratio_params()
866 alvium->inc_bbalance = inc_bb; in alvium_get_blue_balance_ratio_params()
871 static int alvium_get_hue_params(struct alvium_dev *alvium) in alvium_get_hue_params() argument
876 alvium_read(alvium, REG_BCRM_HUE_RW, &dft_hue, &ret); in alvium_get_hue_params()
877 alvium_read(alvium, REG_BCRM_HUE_MIN_R, &min_hue, &ret); in alvium_get_hue_params()
878 alvium_read(alvium, REG_BCRM_HUE_MAX_R, &max_hue, &ret); in alvium_get_hue_params()
879 alvium_read(alvium, REG_BCRM_HUE_INC_R, &inc_hue, &ret); in alvium_get_hue_params()
883 alvium->dft_hue = (s32)dft_hue; in alvium_get_hue_params()
884 alvium->min_hue = (s32)min_hue; in alvium_get_hue_params()
885 alvium->max_hue = (s32)max_hue; in alvium_get_hue_params()
886 alvium->inc_hue = (s32)inc_hue; in alvium_get_hue_params()
891 static int alvium_get_black_lvl_params(struct alvium_dev *alvium) in alvium_get_black_lvl_params() argument
896 alvium_read(alvium, REG_BCRM_BLACK_LEVEL_RW, &dft_blvl, &ret); in alvium_get_black_lvl_params()
897 alvium_read(alvium, REG_BCRM_BLACK_LEVEL_MIN_R, &min_blvl, &ret); in alvium_get_black_lvl_params()
898 alvium_read(alvium, REG_BCRM_BLACK_LEVEL_MAX_R, &max_blvl, &ret); in alvium_get_black_lvl_params()
899 alvium_read(alvium, REG_BCRM_BLACK_LEVEL_INC_R, &inc_blvl, &ret); in alvium_get_black_lvl_params()
903 alvium->dft_black_lvl = (s32)dft_blvl; in alvium_get_black_lvl_params()
904 alvium->min_black_lvl = (s32)min_blvl; in alvium_get_black_lvl_params()
905 alvium->max_black_lvl = (s32)max_blvl; in alvium_get_black_lvl_params()
906 alvium->inc_black_lvl = (s32)inc_blvl; in alvium_get_black_lvl_params()
911 static int alvium_get_gamma_params(struct alvium_dev *alvium) in alvium_get_gamma_params() argument
916 alvium_read(alvium, REG_BCRM_GAMMA_RW, &dft_g, &ret); in alvium_get_gamma_params()
917 alvium_read(alvium, REG_BCRM_GAMMA_MIN_R, &min_g, &ret); in alvium_get_gamma_params()
918 alvium_read(alvium, REG_BCRM_GAMMA_MAX_R, &max_g, &ret); in alvium_get_gamma_params()
919 alvium_read(alvium, REG_BCRM_GAMMA_INC_R, &inc_g, &ret); in alvium_get_gamma_params()
923 alvium->dft_gamma = dft_g; in alvium_get_gamma_params()
924 alvium->min_gamma = min_g; in alvium_get_gamma_params()
925 alvium->max_gamma = max_g; in alvium_get_gamma_params()
926 alvium->inc_gamma = inc_g; in alvium_get_gamma_params()
931 static int alvium_get_sharpness_params(struct alvium_dev *alvium) in alvium_get_sharpness_params() argument
936 alvium_read(alvium, REG_BCRM_SHARPNESS_RW, &dft_sh, &ret); in alvium_get_sharpness_params()
937 alvium_read(alvium, REG_BCRM_SHARPNESS_MIN_R, &min_sh, &ret); in alvium_get_sharpness_params()
938 alvium_read(alvium, REG_BCRM_BLACK_LEVEL_MAX_R, &max_sh, &ret); in alvium_get_sharpness_params()
939 alvium_read(alvium, REG_BCRM_SHARPNESS_INC_R, &inc_sh, &ret); in alvium_get_sharpness_params()
943 alvium->dft_sharp = (s32)dft_sh; in alvium_get_sharpness_params()
944 alvium->min_sharp = (s32)min_sh; in alvium_get_sharpness_params()
945 alvium->max_sharp = (s32)max_sh; in alvium_get_sharpness_params()
946 alvium->inc_sharp = (s32)inc_sh; in alvium_get_sharpness_params()
951 static int alvium_get_contrast_params(struct alvium_dev *alvium) in alvium_get_contrast_params() argument
956 alvium_read(alvium, REG_BCRM_CONTRAST_VALUE_RW, &dft_c, &ret); in alvium_get_contrast_params()
957 alvium_read(alvium, REG_BCRM_CONTRAST_VALUE_MIN_R, &min_c, &ret); in alvium_get_contrast_params()
958 alvium_read(alvium, REG_BCRM_CONTRAST_VALUE_MAX_R, &max_c, &ret); in alvium_get_contrast_params()
959 alvium_read(alvium, REG_BCRM_CONTRAST_VALUE_INC_R, &inc_c, &ret); in alvium_get_contrast_params()
963 alvium->dft_contrast = dft_c; in alvium_get_contrast_params()
964 alvium->min_contrast = min_c; in alvium_get_contrast_params()
965 alvium->max_contrast = max_c; in alvium_get_contrast_params()
966 alvium->inc_contrast = inc_c; in alvium_get_contrast_params()
971 static int alvium_get_saturation_params(struct alvium_dev *alvium) in alvium_get_saturation_params() argument
976 alvium_read(alvium, REG_BCRM_SATURATION_RW, &dft_sat, &ret); in alvium_get_saturation_params()
977 alvium_read(alvium, REG_BCRM_SATURATION_MIN_R, &min_sat, &ret); in alvium_get_saturation_params()
978 alvium_read(alvium, REG_BCRM_SATURATION_MAX_R, &max_sat, &ret); in alvium_get_saturation_params()
979 alvium_read(alvium, REG_BCRM_SATURATION_INC_R, &inc_sat, &ret); in alvium_get_saturation_params()
983 alvium->dft_sat = dft_sat; in alvium_get_saturation_params()
984 alvium->min_sat = min_sat; in alvium_get_saturation_params()
985 alvium->max_sat = max_sat; in alvium_get_saturation_params()
986 alvium->inc_sat = inc_sat; in alvium_get_saturation_params()
991 static int alvium_set_bcm_mode(struct alvium_dev *alvium) in alvium_set_bcm_mode() argument
995 alvium_write(alvium, REG_GENCP_CHANGEMODE_W, ALVIUM_BCM_MODE, &ret); in alvium_set_bcm_mode()
996 alvium->bcrm_mode = ALVIUM_BCM_MODE; in alvium_set_bcm_mode()
1001 static int alvium_get_mode(struct alvium_dev *alvium) in alvium_get_mode() argument
1006 ret = alvium_read(alvium, REG_GENCP_CURRENTMODE_R, &bcrm_mode, NULL); in alvium_get_mode()
1012 alvium->bcrm_mode = ALVIUM_BCM_MODE; in alvium_get_mode()
1015 alvium->bcrm_mode = ALVIUM_GENCP_MODE; in alvium_get_mode()
1022 static int alvium_get_avail_mipi_data_format(struct alvium_dev *alvium) in alvium_get_avail_mipi_data_format() argument
1028 ret = alvium_read(alvium, REG_BCRM_IMG_AVAILABLE_MIPI_DATA_FORMATS_R, in alvium_get_avail_mipi_data_format()
1035 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8_LEG] = in alvium_get_avail_mipi_data_format()
1036 avail_fmt->yuv420_8_leg; in alvium_get_avail_mipi_data_format()
1037 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8] = in alvium_get_avail_mipi_data_format()
1038 avail_fmt->yuv420_8; in alvium_get_avail_mipi_data_format()
1039 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_10] = in alvium_get_avail_mipi_data_format()
1040 avail_fmt->yuv420_10; in alvium_get_avail_mipi_data_format()
1041 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_8_CSPS] = in alvium_get_avail_mipi_data_format()
1042 avail_fmt->yuv420_8_csps; in alvium_get_avail_mipi_data_format()
1043 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV420_10_CSPS] = in alvium_get_avail_mipi_data_format()
1044 avail_fmt->yuv420_10_csps; in alvium_get_avail_mipi_data_format()
1045 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV422_8] = in alvium_get_avail_mipi_data_format()
1046 avail_fmt->yuv422_8; in alvium_get_avail_mipi_data_format()
1047 alvium->is_mipi_fmt_avail[ALVIUM_BIT_YUV422_10] = in alvium_get_avail_mipi_data_format()
1048 avail_fmt->yuv422_10; in alvium_get_avail_mipi_data_format()
1049 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB888] = in alvium_get_avail_mipi_data_format()
1050 avail_fmt->rgb888; in alvium_get_avail_mipi_data_format()
1051 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB666] = in alvium_get_avail_mipi_data_format()
1052 avail_fmt->rgb666; in alvium_get_avail_mipi_data_format()
1053 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB565] = in alvium_get_avail_mipi_data_format()
1054 avail_fmt->rgb565; in alvium_get_avail_mipi_data_format()
1055 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB555] = in alvium_get_avail_mipi_data_format()
1056 avail_fmt->rgb555; in alvium_get_avail_mipi_data_format()
1057 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RGB444] = in alvium_get_avail_mipi_data_format()
1058 avail_fmt->rgb444; in alvium_get_avail_mipi_data_format()
1059 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW6] = in alvium_get_avail_mipi_data_format()
1060 avail_fmt->raw6; in alvium_get_avail_mipi_data_format()
1061 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW7] = in alvium_get_avail_mipi_data_format()
1062 avail_fmt->raw7; in alvium_get_avail_mipi_data_format()
1063 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW8] = in alvium_get_avail_mipi_data_format()
1064 avail_fmt->raw8; in alvium_get_avail_mipi_data_format()
1065 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW10] = in alvium_get_avail_mipi_data_format()
1066 avail_fmt->raw10; in alvium_get_avail_mipi_data_format()
1067 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW12] = in alvium_get_avail_mipi_data_format()
1068 avail_fmt->raw12; in alvium_get_avail_mipi_data_format()
1069 alvium->is_mipi_fmt_avail[ALVIUM_BIT_RAW14] = in alvium_get_avail_mipi_data_format()
1070 avail_fmt->raw14; in alvium_get_avail_mipi_data_format()
1071 alvium->is_mipi_fmt_avail[ALVIUM_BIT_JPEG] = in alvium_get_avail_mipi_data_format()
1072 avail_fmt->jpeg; in alvium_get_avail_mipi_data_format()
1074 alvium_print_avail_mipi_fmt(alvium); in alvium_get_avail_mipi_data_format()
1079 static int alvium_setup_mipi_fmt(struct alvium_dev *alvium) in alvium_setup_mipi_fmt() argument
1087 if (!alvium->is_mipi_fmt_avail[alvium_csi2_fmts[fmt].fmt_av_bit]) in alvium_setup_mipi_fmt()
1091 alvium->is_bay_avail[alvium_csi2_fmts[fmt].bay_av_bit]) in alvium_setup_mipi_fmt()
1096 alvium->alvium_csi2_fmt_n = sz; in alvium_setup_mipi_fmt()
1097 alvium->alvium_csi2_fmt = in alvium_setup_mipi_fmt()
1099 if (!alvium->alvium_csi2_fmt) in alvium_setup_mipi_fmt()
1100 return -ENOMEM; in alvium_setup_mipi_fmt()
1104 if (!alvium->is_mipi_fmt_avail[alvium_csi2_fmts[fmt].fmt_av_bit]) in alvium_setup_mipi_fmt()
1108 alvium->is_bay_avail[alvium_csi2_fmts[fmt].bay_av_bit]) { in alvium_setup_mipi_fmt()
1109 alvium->alvium_csi2_fmt[avail_fmt_cnt] = in alvium_setup_mipi_fmt()
1118 static int alvium_set_mipi_fmt(struct alvium_dev *alvium, in alvium_set_mipi_fmt() argument
1121 struct device *dev = &alvium->i2c_client->dev; in alvium_set_mipi_fmt()
1124 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_MIPI_DATA_FORMAT_RW, in alvium_set_mipi_fmt()
1125 pixfmt->mipi_fmt_regval); in alvium_set_mipi_fmt()
1134 static int alvium_get_avail_bayer(struct alvium_dev *alvium) in alvium_get_avail_bayer() argument
1140 ret = alvium_read(alvium, REG_BCRM_IMG_BAYER_PATTERN_INQUIRY_R, in alvium_get_avail_bayer()
1147 alvium->is_bay_avail[ALVIUM_BIT_BAY_MONO] = avail_bay->mono; in alvium_get_avail_bayer()
1148 alvium->is_bay_avail[ALVIUM_BIT_BAY_GR] = avail_bay->gr; in alvium_get_avail_bayer()
1149 alvium->is_bay_avail[ALVIUM_BIT_BAY_RG] = avail_bay->rg; in alvium_get_avail_bayer()
1150 alvium->is_bay_avail[ALVIUM_BIT_BAY_GB] = avail_bay->gb; in alvium_get_avail_bayer()
1151 alvium->is_bay_avail[ALVIUM_BIT_BAY_BG] = avail_bay->bg; in alvium_get_avail_bayer()
1153 alvium_print_avail_bayer(alvium); in alvium_get_avail_bayer()
1158 static int alvium_set_bayer_pattern(struct alvium_dev *alvium, in alvium_set_bayer_pattern() argument
1161 struct device *dev = &alvium->i2c_client->dev; in alvium_set_bayer_pattern()
1164 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_BAYER_PATTERN_RW, in alvium_set_bayer_pattern()
1165 pixfmt->bay_fmt_regval); in alvium_set_bayer_pattern()
1174 static int alvium_get_frame_interval(struct alvium_dev *alvium, in alvium_get_frame_interval() argument
1179 alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R, in alvium_get_frame_interval()
1181 alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R, in alvium_get_frame_interval()
1187 static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr) in alvium_set_frame_rate() argument
1189 struct device *dev = &alvium->i2c_client->dev; in alvium_set_frame_rate()
1192 ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_EN_RW, in alvium_set_frame_rate()
1199 ret = alvium_write_hshake(alvium, REG_BCRM_FRAME_START_TRIGGER_MODE_RW, in alvium_set_frame_rate()
1206 ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, in alvium_set_frame_rate()
1218 static int alvium_set_stream_mipi(struct alvium_dev *alvium, bool on) in alvium_set_stream_mipi() argument
1220 struct device *dev = &alvium->i2c_client->dev; in alvium_set_stream_mipi()
1223 ret = alvium_write_hshake(alvium, on ? REG_BCRM_ACQUISITION_START_RW : in alvium_set_stream_mipi()
1233 static int alvium_get_gain(struct alvium_dev *alvium) in alvium_get_gain() argument
1239 ret = alvium_read(alvium, REG_BCRM_GAIN_RW, &gain, NULL); in alvium_get_gain()
1246 static int alvium_set_ctrl_gain(struct alvium_dev *alvium, int gain) in alvium_set_ctrl_gain() argument
1248 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_gain()
1252 ret = alvium_write_hshake(alvium, REG_BCRM_GAIN_RW, (u64)gain); in alvium_set_ctrl_gain()
1261 static int alvium_set_ctrl_auto_gain(struct alvium_dev *alvium, bool on) in alvium_set_ctrl_auto_gain() argument
1263 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_auto_gain()
1266 ret = alvium_write_hshake(alvium, REG_BCRM_GAIN_AUTO_RW, in alvium_set_ctrl_auto_gain()
1276 static int alvium_get_exposure(struct alvium_dev *alvium) in alvium_get_exposure() argument
1282 ret = alvium_read(alvium, REG_BCRM_EXPOSURE_TIME_RW, &exp, NULL); in alvium_get_exposure()
1289 static int alvium_set_ctrl_auto_exposure(struct alvium_dev *alvium, bool on) in alvium_set_ctrl_auto_exposure() argument
1291 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_auto_exposure()
1294 ret = alvium_write_hshake(alvium, REG_BCRM_WHITE_BALANCE_AUTO_RW, in alvium_set_ctrl_auto_exposure()
1304 static int alvium_set_ctrl_exposure(struct alvium_dev *alvium, int exposure_ns) in alvium_set_ctrl_exposure() argument
1306 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_exposure()
1309 ret = alvium_write_hshake(alvium, REG_BCRM_EXPOSURE_TIME_RW, in alvium_set_ctrl_exposure()
1319 static int alvium_set_ctrl_blue_balance_ratio(struct alvium_dev *alvium, in alvium_set_ctrl_blue_balance_ratio() argument
1322 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_blue_balance_ratio()
1325 ret = alvium_write_hshake(alvium, REG_BCRM_BLUE_BALANCE_RATIO_RW, in alvium_set_ctrl_blue_balance_ratio()
1335 static int alvium_set_ctrl_red_balance_ratio(struct alvium_dev *alvium, int red) in alvium_set_ctrl_red_balance_ratio() argument
1337 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_red_balance_ratio()
1340 ret = alvium_write_hshake(alvium, REG_BCRM_RED_BALANCE_RATIO_RW, in alvium_set_ctrl_red_balance_ratio()
1350 static int alvium_set_ctrl_awb(struct alvium_dev *alvium, bool on) in alvium_set_ctrl_awb() argument
1352 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_awb()
1355 ret = alvium_write_hshake(alvium, REG_BCRM_WHITE_BALANCE_AUTO_RW, in alvium_set_ctrl_awb()
1365 static int alvium_set_ctrl_hue(struct alvium_dev *alvium, int val) in alvium_set_ctrl_hue() argument
1367 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_hue()
1370 ret = alvium_write_hshake(alvium, REG_BCRM_HUE_RW, (u64)val); in alvium_set_ctrl_hue()
1379 static int alvium_set_ctrl_contrast(struct alvium_dev *alvium, int val) in alvium_set_ctrl_contrast() argument
1381 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_contrast()
1384 ret = alvium_write_hshake(alvium, REG_BCRM_CONTRAST_VALUE_RW, (u64)val); in alvium_set_ctrl_contrast()
1393 static int alvium_set_ctrl_saturation(struct alvium_dev *alvium, int val) in alvium_set_ctrl_saturation() argument
1395 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_saturation()
1398 ret = alvium_write_hshake(alvium, REG_BCRM_SATURATION_RW, (u64)val); in alvium_set_ctrl_saturation()
1407 static int alvium_set_ctrl_gamma(struct alvium_dev *alvium, int val) in alvium_set_ctrl_gamma() argument
1409 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_gamma()
1412 ret = alvium_write_hshake(alvium, REG_BCRM_GAMMA_RW, (u64)val); in alvium_set_ctrl_gamma()
1421 static int alvium_set_ctrl_sharpness(struct alvium_dev *alvium, int val) in alvium_set_ctrl_sharpness() argument
1423 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_sharpness()
1426 ret = alvium_write_hshake(alvium, REG_BCRM_SHARPNESS_RW, (u64)val); in alvium_set_ctrl_sharpness()
1435 static int alvium_set_ctrl_hflip(struct alvium_dev *alvium, int val) in alvium_set_ctrl_hflip() argument
1437 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_hflip()
1440 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_REVERSE_X_RW, (u64)val); in alvium_set_ctrl_hflip()
1449 static int alvium_set_ctrl_vflip(struct alvium_dev *alvium, int val) in alvium_set_ctrl_vflip() argument
1451 struct device *dev = &alvium->i2c_client->dev; in alvium_set_ctrl_vflip()
1454 ret = alvium_write_hshake(alvium, REG_BCRM_IMG_REVERSE_Y_RW, (u64)val); in alvium_set_ctrl_vflip()
1463 static int alvium_get_hw_features_params(struct alvium_dev *alvium) in alvium_get_hw_features_params() argument
1465 struct device *dev = &alvium->i2c_client->dev; in alvium_get_hw_features_params()
1468 ret = alvium_get_csi_clk_params(alvium); in alvium_get_hw_features_params()
1474 ret = alvium_get_img_width_params(alvium); in alvium_get_hw_features_params()
1480 ret = alvium_get_img_height_params(alvium); in alvium_get_hw_features_params()
1486 ret = alvium_get_offx_params(alvium); in alvium_get_hw_features_params()
1492 ret = alvium_get_offy_params(alvium); in alvium_get_hw_features_params()
1498 ret = alvium_get_gain_params(alvium); in alvium_get_hw_features_params()
1504 ret = alvium_get_exposure_params(alvium); in alvium_get_hw_features_params()
1510 ret = alvium_get_red_balance_ratio_params(alvium); in alvium_get_hw_features_params()
1516 ret = alvium_get_blue_balance_ratio_params(alvium); in alvium_get_hw_features_params()
1522 ret = alvium_get_hue_params(alvium); in alvium_get_hw_features_params()
1528 ret = alvium_get_contrast_params(alvium); in alvium_get_hw_features_params()
1534 ret = alvium_get_saturation_params(alvium); in alvium_get_hw_features_params()
1540 ret = alvium_get_black_lvl_params(alvium); in alvium_get_hw_features_params()
1546 ret = alvium_get_gamma_params(alvium); in alvium_get_hw_features_params()
1552 ret = alvium_get_sharpness_params(alvium); in alvium_get_hw_features_params()
1561 static int alvium_get_hw_info(struct alvium_dev *alvium) in alvium_get_hw_info() argument
1563 struct device *dev = &alvium->i2c_client->dev; in alvium_get_hw_info()
1566 ret = alvium_get_bcrm_vers(alvium); in alvium_get_hw_info()
1572 ret = alvium_get_bcrm_addr(alvium); in alvium_get_hw_info()
1578 ret = alvium_get_fw_version(alvium); in alvium_get_hw_info()
1584 ret = alvium_get_host_supp_csi_lanes(alvium); in alvium_get_hw_info()
1590 ret = alvium_get_feat_inq(alvium); in alvium_get_hw_info()
1596 ret = alvium_get_hw_features_params(alvium); in alvium_get_hw_info()
1602 ret = alvium_get_avail_mipi_data_format(alvium); in alvium_get_hw_info()
1608 ret = alvium_get_avail_bayer(alvium); in alvium_get_hw_info()
1614 ret = alvium_get_mode(alvium); in alvium_get_hw_info()
1623 static int alvium_hw_init(struct alvium_dev *alvium) in alvium_hw_init() argument
1625 struct device *dev = &alvium->i2c_client->dev; in alvium_hw_init()
1628 /* Set Alvium BCM mode*/ in alvium_hw_init()
1629 ret = alvium_set_bcm_mode(alvium); in alvium_hw_init()
1635 ret = alvium_set_csi_lanes(alvium); in alvium_hw_init()
1641 ret = alvium_set_csi_clk(alvium); in alvium_hw_init()
1647 ret = alvium_set_lp2hs_delay(alvium); in alvium_hw_init()
1656 /* --------------- Subdev Operations --------------- */
1661 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_s_frame_interval() local
1662 struct device *dev = &alvium->i2c_client->dev; in alvium_s_frame_interval()
1667 if (alvium->streaming) in alvium_s_frame_interval()
1668 return -EBUSY; in alvium_s_frame_interval()
1670 if (fi->interval.denominator == 0) in alvium_s_frame_interval()
1671 return -EINVAL; in alvium_s_frame_interval()
1673 ret = alvium_get_frame_interval(alvium, &min_fr, &max_fr); in alvium_s_frame_interval()
1679 dev_dbg(dev, "fi->interval.numerator = %d\n", in alvium_s_frame_interval()
1680 fi->interval.numerator); in alvium_s_frame_interval()
1681 dev_dbg(dev, "fi->interval.denominator = %d\n", in alvium_s_frame_interval()
1682 fi->interval.denominator); in alvium_s_frame_interval()
1684 req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / in alvium_s_frame_interval()
1685 fi->interval.numerator); in alvium_s_frame_interval()
1690 interval->numerator = fi->interval.numerator; in alvium_s_frame_interval()
1691 interval->denominator = fi->interval.denominator; in alvium_s_frame_interval()
1693 if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) in alvium_s_frame_interval()
1696 return alvium_set_frame_rate(alvium, req_fr); in alvium_s_frame_interval()
1703 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_enum_mbus_code() local
1705 if (code->index >= alvium->alvium_csi2_fmt_n) in alvium_enum_mbus_code()
1706 return -EINVAL; in alvium_enum_mbus_code()
1708 code->code = alvium->alvium_csi2_fmt[code->index].code; in alvium_enum_mbus_code()
1714 alvium_code_to_pixfmt(struct alvium_dev *alvium, u32 code) in alvium_code_to_pixfmt() argument
1718 for (i = 0; alvium->alvium_csi2_fmt[i].code; ++i) in alvium_code_to_pixfmt()
1719 if (alvium->alvium_csi2_fmt[i].code == code) in alvium_code_to_pixfmt()
1720 return &alvium->alvium_csi2_fmt[i]; in alvium_code_to_pixfmt()
1722 return &alvium->alvium_csi2_fmt[0]; in alvium_code_to_pixfmt()
1729 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_enum_frame_size() local
1732 if (fse->index) in alvium_enum_frame_size()
1733 return -EINVAL; in alvium_enum_frame_size()
1735 alvium_csi2_fmt = alvium_code_to_pixfmt(alvium, fse->code); in alvium_enum_frame_size()
1736 if (fse->code != alvium_csi2_fmt->code) in alvium_enum_frame_size()
1737 return -EINVAL; in alvium_enum_frame_size()
1739 fse->min_width = alvium->img_min_width; in alvium_enum_frame_size()
1740 fse->max_width = alvium->img_max_width; in alvium_enum_frame_size()
1741 fse->min_height = alvium->img_min_height; in alvium_enum_frame_size()
1742 fse->max_height = alvium->img_max_height; in alvium_enum_frame_size()
1746 static int alvium_set_mode(struct alvium_dev *alvium, in alvium_set_mode() argument
1756 v4l_bound_align_image(&fmt->width, alvium->img_min_width, in alvium_set_mode()
1757 alvium->img_max_width, 0, in alvium_set_mode()
1758 &fmt->height, alvium->img_min_height, in alvium_set_mode()
1759 alvium->img_max_height, 0, 0); in alvium_set_mode()
1761 /* alvium don't accept negative crop left/top */ in alvium_set_mode()
1762 crop->left = clamp((u32)max(0, crop->left), alvium->min_offx, in alvium_set_mode()
1763 (u32)(alvium->img_max_width - fmt->width)); in alvium_set_mode()
1764 crop->top = clamp((u32)max(0, crop->top), alvium->min_offy, in alvium_set_mode()
1765 (u32)(alvium->img_max_height - fmt->height)); in alvium_set_mode()
1767 ret = alvium_set_img_width(alvium, fmt->width); in alvium_set_mode()
1771 ret = alvium_set_img_height(alvium, fmt->height); in alvium_set_mode()
1775 ret = alvium_set_img_offx(alvium, crop->left); in alvium_set_mode()
1779 ret = alvium_set_img_offy(alvium, crop->top); in alvium_set_mode()
1786 static int alvium_set_framefmt(struct alvium_dev *alvium, in alvium_set_framefmt() argument
1789 struct device *dev = &alvium->i2c_client->dev; in alvium_set_framefmt()
1793 alvium_csi2_fmt = alvium_code_to_pixfmt(alvium, format->code); in alvium_set_framefmt()
1795 ret = alvium_set_mipi_fmt(alvium, alvium_csi2_fmt); in alvium_set_framefmt()
1799 if (alvium_csi2_fmt->is_raw) { in alvium_set_framefmt()
1800 ret = alvium_set_bayer_pattern(alvium, alvium_csi2_fmt); in alvium_set_framefmt()
1806 __func__, alvium_csi2_fmt->mipi_fmt_regval); in alvium_set_framefmt()
1813 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_s_stream() local
1814 struct i2c_client *client = v4l2_get_subdevdata(&alvium->sd); in alvium_s_stream()
1822 ret = pm_runtime_resume_and_get(&client->dev); in alvium_s_stream()
1826 ret = __v4l2_ctrl_handler_setup(&alvium->ctrls.handler); in alvium_s_stream()
1830 ret = alvium_set_mode(alvium, state); in alvium_s_stream()
1835 ret = alvium_set_framefmt(alvium, fmt); in alvium_s_stream()
1839 ret = alvium_set_stream_mipi(alvium, enable); in alvium_s_stream()
1844 alvium_set_stream_mipi(alvium, enable); in alvium_s_stream()
1845 pm_runtime_mark_last_busy(&client->dev); in alvium_s_stream()
1846 pm_runtime_put_autosuspend(&client->dev); in alvium_s_stream()
1849 alvium->streaming = !!enable; in alvium_s_stream()
1855 pm_runtime_put(&client->dev); in alvium_s_stream()
1863 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_init_state() local
1864 struct alvium_mode *mode = &alvium->mode; in alvium_init_state()
1873 .left = mode->crop.left, in alvium_init_state()
1874 .top = mode->crop.top, in alvium_init_state()
1875 .width = mode->crop.width, in alvium_init_state()
1876 .height = mode->crop.height, in alvium_init_state()
1885 interval->numerator = 1; in alvium_init_state()
1886 interval->denominator = ALVIUM_DEFAULT_FR_HZ; in alvium_init_state()
1895 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_set_fmt() local
1903 v4l_bound_align_image(&format->format.width, alvium->img_min_width, in alvium_set_fmt()
1904 alvium->img_max_width, 0, in alvium_set_fmt()
1905 &format->format.height, alvium->img_min_height, in alvium_set_fmt()
1906 alvium->img_max_height, 0, 0); in alvium_set_fmt()
1909 crop->left = clamp((u32)crop->left, (u32)0, in alvium_set_fmt()
1910 (alvium->img_max_width - fmt->width)); in alvium_set_fmt()
1911 crop->top = clamp((u32)crop->top, (u32)0, in alvium_set_fmt()
1912 (alvium->img_max_height - fmt->height)); in alvium_set_fmt()
1915 crop->width = fmt->width; in alvium_set_fmt()
1916 crop->height = fmt->height; in alvium_set_fmt()
1918 alvium_csi2_fmt = alvium_code_to_pixfmt(alvium, format->format.code); in alvium_set_fmt()
1919 fmt->code = alvium_csi2_fmt->code; in alvium_set_fmt()
1921 *fmt = format->format; in alvium_set_fmt()
1930 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_set_selection() local
1934 if (sel->target != V4L2_SEL_TGT_CROP) in alvium_set_selection()
1935 return -EINVAL; in alvium_set_selection()
1941 * Alvium can only shift the origin of the img in alvium_set_selection()
1944 if (sel->r.width != fmt->width) in alvium_set_selection()
1945 sel->r.width = fmt->width; in alvium_set_selection()
1947 if (sel->r.height != fmt->height) in alvium_set_selection()
1948 sel->r.height = fmt->height; in alvium_set_selection()
1950 /* alvium don't accept negative crop left/top */ in alvium_set_selection()
1951 crop->left = clamp((u32)max(0, sel->r.left), alvium->min_offx, in alvium_set_selection()
1952 alvium->img_max_width - sel->r.width); in alvium_set_selection()
1953 crop->top = clamp((u32)max(0, sel->r.top), alvium->min_offy, in alvium_set_selection()
1954 alvium->img_max_height - sel->r.height); in alvium_set_selection()
1956 sel->r = *crop; in alvium_set_selection()
1965 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_get_selection() local
1967 switch (sel->target) { in alvium_get_selection()
1970 sel->r = *v4l2_subdev_state_get_crop(sd_state, 0); in alvium_get_selection()
1974 sel->r.top = 0; in alvium_get_selection()
1975 sel->r.left = 0; in alvium_get_selection()
1976 sel->r.width = alvium->img_max_width; in alvium_get_selection()
1977 sel->r.height = alvium->img_max_height; in alvium_get_selection()
1982 sel->r.top = alvium->min_offy; in alvium_get_selection()
1983 sel->r.left = alvium->min_offx; in alvium_get_selection()
1984 sel->r.width = alvium->img_max_width; in alvium_get_selection()
1985 sel->r.height = alvium->img_max_height; in alvium_get_selection()
1988 return -EINVAL; in alvium_get_selection()
1997 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_g_volatile_ctrl() local
2000 switch (ctrl->id) { in alvium_g_volatile_ctrl()
2002 val = alvium_get_gain(alvium); in alvium_g_volatile_ctrl()
2005 alvium->ctrls.gain->val = val; in alvium_g_volatile_ctrl()
2008 val = alvium_get_exposure(alvium); in alvium_g_volatile_ctrl()
2011 alvium->ctrls.exposure->val = val; in alvium_g_volatile_ctrl()
2021 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_s_ctrl() local
2022 struct i2c_client *client = v4l2_get_subdevdata(&alvium->sd); in alvium_s_ctrl()
2029 if (!pm_runtime_get_if_in_use(&client->dev)) in alvium_s_ctrl()
2032 switch (ctrl->id) { in alvium_s_ctrl()
2034 ret = alvium_set_ctrl_gain(alvium, ctrl->val); in alvium_s_ctrl()
2037 ret = alvium_set_ctrl_auto_gain(alvium, ctrl->val); in alvium_s_ctrl()
2040 ret = alvium_set_ctrl_exposure(alvium, ctrl->val); in alvium_s_ctrl()
2043 ret = alvium_set_ctrl_auto_exposure(alvium, ctrl->val); in alvium_s_ctrl()
2046 ret = alvium_set_ctrl_red_balance_ratio(alvium, ctrl->val); in alvium_s_ctrl()
2049 ret = alvium_set_ctrl_blue_balance_ratio(alvium, ctrl->val); in alvium_s_ctrl()
2052 ret = alvium_set_ctrl_awb(alvium, ctrl->val); in alvium_s_ctrl()
2055 ret = alvium_set_ctrl_hue(alvium, ctrl->val); in alvium_s_ctrl()
2058 ret = alvium_set_ctrl_contrast(alvium, ctrl->val); in alvium_s_ctrl()
2061 ret = alvium_set_ctrl_saturation(alvium, ctrl->val); in alvium_s_ctrl()
2064 ret = alvium_set_ctrl_gamma(alvium, ctrl->val); in alvium_s_ctrl()
2067 ret = alvium_set_ctrl_sharpness(alvium, ctrl->val); in alvium_s_ctrl()
2070 ret = alvium_set_ctrl_hflip(alvium, ctrl->val); in alvium_s_ctrl()
2073 ret = alvium_set_ctrl_vflip(alvium, ctrl->val); in alvium_s_ctrl()
2076 ret = -EINVAL; in alvium_s_ctrl()
2080 pm_runtime_put(&client->dev); in alvium_s_ctrl()
2090 static int alvium_ctrl_init(struct alvium_dev *alvium) in alvium_ctrl_init() argument
2093 struct alvium_ctrls *ctrls = &alvium->ctrls; in alvium_ctrl_init()
2094 struct v4l2_ctrl_handler *hdl = &ctrls->handler; in alvium_ctrl_init()
2101 ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2105 ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; in alvium_ctrl_init()
2108 ctrls->link_freq = v4l2_ctrl_new_int_menu(hdl, ops, in alvium_ctrl_init()
2110 0, 0, &alvium->link_freq); in alvium_ctrl_init()
2111 ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in alvium_ctrl_init()
2114 if (alvium->avail_ft.auto_whiteb) { in alvium_ctrl_init()
2115 ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2118 v4l2_ctrl_auto_cluster(3, &ctrls->auto_wb, 0, false); in alvium_ctrl_init()
2121 ctrls->blue_balance = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2123 alvium->min_bbalance, in alvium_ctrl_init()
2124 alvium->max_bbalance, in alvium_ctrl_init()
2125 alvium->inc_bbalance, in alvium_ctrl_init()
2126 alvium->dft_bbalance); in alvium_ctrl_init()
2127 ctrls->red_balance = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2129 alvium->min_rbalance, in alvium_ctrl_init()
2130 alvium->max_rbalance, in alvium_ctrl_init()
2131 alvium->inc_rbalance, in alvium_ctrl_init()
2132 alvium->dft_rbalance); in alvium_ctrl_init()
2135 if (alvium->avail_ft.auto_exp) { in alvium_ctrl_init()
2136 ctrls->auto_exp = in alvium_ctrl_init()
2141 v4l2_ctrl_auto_cluster(2, &ctrls->auto_exp, 1, true); in alvium_ctrl_init()
2144 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2146 alvium->min_exp, in alvium_ctrl_init()
2147 alvium->max_exp, in alvium_ctrl_init()
2148 alvium->inc_exp, in alvium_ctrl_init()
2149 alvium->dft_exp); in alvium_ctrl_init()
2150 ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; in alvium_ctrl_init()
2153 if (alvium->avail_ft.auto_gain) { in alvium_ctrl_init()
2154 ctrls->auto_gain = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2157 v4l2_ctrl_auto_cluster(2, &ctrls->auto_gain, 0, true); in alvium_ctrl_init()
2160 if (alvium->avail_ft.gain) { in alvium_ctrl_init()
2161 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2163 alvium->min_gain, in alvium_ctrl_init()
2164 alvium->max_gain, in alvium_ctrl_init()
2165 alvium->inc_gain, in alvium_ctrl_init()
2166 alvium->dft_gain); in alvium_ctrl_init()
2167 ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; in alvium_ctrl_init()
2170 if (alvium->avail_ft.sat) in alvium_ctrl_init()
2171 ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2173 alvium->min_sat, in alvium_ctrl_init()
2174 alvium->max_sat, in alvium_ctrl_init()
2175 alvium->inc_sat, in alvium_ctrl_init()
2176 alvium->dft_sat); in alvium_ctrl_init()
2178 if (alvium->avail_ft.hue) in alvium_ctrl_init()
2179 ctrls->hue = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2181 alvium->min_hue, in alvium_ctrl_init()
2182 alvium->max_hue, in alvium_ctrl_init()
2183 alvium->inc_hue, in alvium_ctrl_init()
2184 alvium->dft_hue); in alvium_ctrl_init()
2186 if (alvium->avail_ft.contrast) in alvium_ctrl_init()
2187 ctrls->contrast = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2189 alvium->min_contrast, in alvium_ctrl_init()
2190 alvium->max_contrast, in alvium_ctrl_init()
2191 alvium->inc_contrast, in alvium_ctrl_init()
2192 alvium->dft_contrast); in alvium_ctrl_init()
2194 if (alvium->avail_ft.gamma) in alvium_ctrl_init()
2195 ctrls->gamma = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2197 alvium->min_gamma, in alvium_ctrl_init()
2198 alvium->max_gamma, in alvium_ctrl_init()
2199 alvium->inc_gamma, in alvium_ctrl_init()
2200 alvium->dft_gamma); in alvium_ctrl_init()
2202 if (alvium->avail_ft.sharp) in alvium_ctrl_init()
2203 ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2205 alvium->min_sharp, in alvium_ctrl_init()
2206 alvium->max_sharp, in alvium_ctrl_init()
2207 alvium->inc_sharp, in alvium_ctrl_init()
2208 alvium->dft_sharp); in alvium_ctrl_init()
2210 if (alvium->avail_ft.rev_x) in alvium_ctrl_init()
2211 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2215 if (alvium->avail_ft.rev_y) in alvium_ctrl_init()
2216 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, in alvium_ctrl_init()
2220 if (hdl->error) { in alvium_ctrl_init()
2221 ret = hdl->error; in alvium_ctrl_init()
2225 ret = v4l2_fwnode_device_parse(&alvium->i2c_client->dev, &props); in alvium_ctrl_init()
2233 alvium->sd.ctrl_handler = hdl; in alvium_ctrl_init()
2272 static int alvium_subdev_init(struct alvium_dev *alvium) in alvium_subdev_init() argument
2274 struct i2c_client *client = alvium->i2c_client; in alvium_subdev_init()
2275 struct device *dev = &alvium->i2c_client->dev; in alvium_subdev_init()
2276 struct v4l2_subdev *sd = &alvium->sd; in alvium_subdev_init()
2280 alvium->mode.fmt = alvium_csi2_default_fmt; in alvium_subdev_init()
2281 alvium->mode.width = alvium_csi2_default_fmt.width; in alvium_subdev_init()
2282 alvium->mode.height = alvium_csi2_default_fmt.height; in alvium_subdev_init()
2283 alvium->mode.crop.left = alvium->min_offx; in alvium_subdev_init()
2284 alvium->mode.crop.top = alvium->min_offy; in alvium_subdev_init()
2285 alvium->mode.crop.width = alvium_csi2_default_fmt.width; in alvium_subdev_init()
2286 alvium->mode.crop.height = alvium_csi2_default_fmt.height; in alvium_subdev_init()
2288 /* init alvium sd */ in alvium_subdev_init()
2291 sd->internal_ops = &alvium_internal_ops; in alvium_subdev_init()
2292 sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE; in alvium_subdev_init()
2293 alvium->pad.flags = MEDIA_PAD_FL_SOURCE; in alvium_subdev_init()
2294 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in alvium_subdev_init()
2296 ret = media_entity_pads_init(&sd->entity, 1, &alvium->pad); in alvium_subdev_init()
2302 ret = alvium_ctrl_init(alvium); in alvium_subdev_init()
2308 alvium->sd.state_lock = alvium->ctrls.handler.lock; in alvium_subdev_init()
2319 v4l2_ctrl_handler_free(&alvium->ctrls.handler); in alvium_subdev_init()
2321 media_entity_cleanup(&alvium->sd.entity); in alvium_subdev_init()
2325 static void alvium_subdev_cleanup(struct alvium_dev *alvium) in alvium_subdev_cleanup() argument
2327 v4l2_fwnode_endpoint_free(&alvium->ep); in alvium_subdev_cleanup()
2328 v4l2_subdev_cleanup(&alvium->sd); in alvium_subdev_cleanup()
2329 media_entity_cleanup(&alvium->sd.entity); in alvium_subdev_cleanup()
2330 v4l2_ctrl_handler_free(&alvium->ctrls.handler); in alvium_subdev_cleanup()
2333 static int alvium_get_dt_data(struct alvium_dev *alvium) in alvium_get_dt_data() argument
2335 struct device *dev = &alvium->i2c_client->dev; in alvium_get_dt_data()
2340 return -EINVAL; in alvium_get_dt_data()
2342 /* Only CSI2 is supported for now: */ in alvium_get_dt_data()
2343 alvium->ep.bus_type = V4L2_MBUS_CSI2_DPHY; in alvium_get_dt_data()
2348 return -EINVAL; in alvium_get_dt_data()
2351 if (v4l2_fwnode_endpoint_alloc_parse(endpoint, &alvium->ep)) { in alvium_get_dt_data()
2356 if (!alvium->ep.nr_of_link_frequencies) { in alvium_get_dt_data()
2364 v4l2_fwnode_endpoint_free(&alvium->ep); in alvium_get_dt_data()
2367 return -EINVAL; in alvium_get_dt_data()
2370 static int alvium_set_power(struct alvium_dev *alvium, bool on) in alvium_set_power() argument
2375 return regulator_disable(alvium->reg_vcc); in alvium_set_power()
2377 ret = regulator_enable(alvium->reg_vcc); in alvium_set_power()
2381 /* alvium boot time 7s */ in alvium_set_power()
2389 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_runtime_resume() local
2392 ret = alvium_set_power(alvium, true); in alvium_runtime_resume()
2396 ret = alvium_hw_init(alvium); in alvium_runtime_resume()
2398 alvium_set_power(alvium, false); in alvium_runtime_resume()
2408 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_runtime_suspend() local
2410 alvium_set_power(alvium, false); in alvium_runtime_suspend()
2421 struct device *dev = &client->dev; in alvium_probe()
2422 struct alvium_dev *alvium; in alvium_probe() local
2425 alvium = devm_kzalloc(dev, sizeof(*alvium), GFP_KERNEL); in alvium_probe()
2426 if (!alvium) in alvium_probe()
2427 return -ENOMEM; in alvium_probe()
2429 alvium->i2c_client = client; in alvium_probe()
2431 alvium->regmap = devm_cci_regmap_init_i2c(client, 16); in alvium_probe()
2432 if (IS_ERR(alvium->regmap)) in alvium_probe()
2433 return PTR_ERR(alvium->regmap); in alvium_probe()
2435 ret = alvium_get_dt_data(alvium); in alvium_probe()
2439 alvium->reg_vcc = devm_regulator_get_optional(dev, "vcc-ext-in"); in alvium_probe()
2440 if (IS_ERR(alvium->reg_vcc)) in alvium_probe()
2441 return dev_err_probe(dev, PTR_ERR(alvium->reg_vcc), in alvium_probe()
2442 "no vcc-ext-in regulator provided\n"); in alvium_probe()
2444 ret = alvium_set_power(alvium, true); in alvium_probe()
2448 if (!alvium_is_alive(alvium)) { in alvium_probe()
2449 ret = -ENODEV; in alvium_probe()
2454 ret = alvium_get_hw_info(alvium); in alvium_probe()
2460 ret = alvium_hw_init(alvium); in alvium_probe()
2466 ret = alvium_setup_mipi_fmt(alvium); in alvium_probe()
2475 * Don't use pm autosuspend (alvium have ~7s boot time). in alvium_probe()
2476 * Alvium has been powered manually: in alvium_probe()
2477 * - mark it as active in alvium_probe()
2478 * - increase the usage count without resuming the device. in alvium_probe()
2485 ret = alvium_subdev_init(alvium); in alvium_probe()
2489 ret = v4l2_async_register_subdev(&alvium->sd); in alvium_probe()
2498 alvium_subdev_cleanup(alvium); in alvium_probe()
2502 kfree(alvium->alvium_csi2_fmt); in alvium_probe()
2504 alvium_set_power(alvium, false); in alvium_probe()
2512 struct alvium_dev *alvium = sd_to_alvium(sd); in alvium_remove() local
2513 struct device *dev = &alvium->i2c_client->dev; in alvium_remove()
2516 alvium_subdev_cleanup(alvium); in alvium_remove()
2517 kfree(alvium->alvium_csi2_fmt); in alvium_remove()
2524 alvium_set_power(alvium, false); in alvium_remove()
2529 { .compatible = "alliedvision,alvium-csi2", },
2536 .name = "alvium-csi2",
2546 MODULE_DESCRIPTION("Allied Vision's Alvium Camera Driver");