diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c index 015493a164309..8e2065b089609 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -77,6 +77,12 @@ #define OV13858_DGTL_GAIN_DEFAULT 1024 /* Default gain = 1 X */ #define OV13858_DGTL_GAIN_STEP 1 /* Each step = 1/1024 */ +/* Readout direction */ +#define OV13858_REG_FORMAT1 0x3820 +#define OV13858_FORMAT1_VFLIP BIT(4) +/* Horizontal flip, active low: every mode table sets this bit */ +#define OV13858_FORMAT1_HFLIP_N BIT(3) + /* Test Pattern Control */ #define OV13858_REG_TEST_PATTERN 0x4503 #define OV13858_TEST_PATTERN_ENABLE BIT(7) @@ -1051,6 +1057,8 @@ struct ov13858 { struct v4l2_ctrl *vblank; struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; /* Current mode */ const struct ov13858_mode *cur_mode; @@ -1331,6 +1339,31 @@ static int ov13858_enable_test_pattern(struct ov13858 *ov13858, u32 pattern) OV13858_REG_VALUE_08BIT, val); } +static int ov13858_update_flips(struct ov13858 *ov13858) +{ + u32 val; + int ret; + + ret = ov13858_read_reg(ov13858, OV13858_REG_FORMAT1, + OV13858_REG_VALUE_08BIT, &val); + if (ret) + return ret; + + if (ov13858->vflip->val) + val |= OV13858_FORMAT1_VFLIP; + else + val &= ~OV13858_FORMAT1_VFLIP; + + /* The mirror bit is active low, as it is on ov13b10. */ + if (ov13858->hflip->val) + val &= ~OV13858_FORMAT1_HFLIP_N; + else + val |= OV13858_FORMAT1_HFLIP_N; + + return ov13858_write_reg(ov13858, OV13858_REG_FORMAT1, + OV13858_REG_VALUE_08BIT, val); +} + static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl) { struct ov13858 *ov13858 = container_of(ctrl->handler, @@ -1377,6 +1410,10 @@ static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl) ov13858->cur_mode->height + ctrl->val); break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + ret = ov13858_update_flips(ov13858); + break; case V4L2_CID_TEST_PATTERN: ret = ov13858_enable_test_pattern(ov13858, ctrl->val); break; @@ -1603,6 +1640,13 @@ static int ov13858_set_stream(struct v4l2_subdev *sd, int enable) pm_runtime_put(ov13858->dev); } + /* + * Do not let the flips change while streaming. ov13858->mutex is the + * control handler's own lock and is held here, hence the __ form. + */ + __v4l2_ctrl_grab(ov13858->hflip, enable); + __v4l2_ctrl_grab(ov13858->vflip, enable); + mutex_unlock(&ov13858->mutex); return ret; @@ -1745,6 +1789,12 @@ static int ov13858_init_controls(struct ov13858 *ov13858) OV13858_DGTL_GAIN_MIN, OV13858_DGTL_GAIN_MAX, OV13858_DGTL_GAIN_STEP, OV13858_DGTL_GAIN_DEFAULT); + ov13858->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); + ov13858->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_cluster(2, &ov13858->hflip); + v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_TEST_PATTERN, ARRAY_SIZE(ov13858_test_pattern_menu) - 1, diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c index d90f135bc55f4..6b8282562d9e3 100644 --- a/drivers/media/i2c/ov5693.c +++ b/drivers/media/i2c/ov5693.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,11 @@ #define OV5693_STOP_STREAMING 0x00 #define OV5693_SW_RESET 0x01 +/* MIPI transmitter control */ +#define OV5693_MIPI_CTRL00_REG CCI_REG8(0x4800) +/* Gate the clock lane when there is no packet to transmit */ +#define OV5693_MIPI_CTRL00_CLOCK_LANE_GATE BIT(5) + #define OV5693_REG_CHIP_ID CCI_REG16(0x300a) /* Yes, this is right. The datasheet for the OV5693 gives its ID as 0x5690 */ #define OV5693_CHIP_ID 0x5690 @@ -82,6 +88,17 @@ #define OV5693_OFFSET_START_X_REG CCI_REG16(0x3810) #define OV5693_OFFSET_START_Y_REG CCI_REG16(0x3812) +/* + * ISP window Y offset used in the binned mode. Parity selects the Bayer + * phase of the output: 2 (even) keeps the advertised BGGR phase and is what + * libcamera's software ISP expects; 3 (odd, the Windows value) yields the + * GRBG phase that the IPU6 PSYS program groups from the Windows tuning + * expect. Switch with: modprobe ov5693 binned_y_offset=3 + */ +static int binned_y_offset = 2; +module_param(binned_y_offset, int, 0644); +MODULE_PARM_DESC(binned_y_offset, "binned-mode ISP window Y offset (2=softISP/BGGR, 3=PSYS/GRBG)"); + #define OV5693_SUB_INC_X_REG CCI_REG8(0x3814) #define OV5693_SUB_INC_Y_REG CCI_REG8(0x3815) @@ -144,6 +161,9 @@ struct ov5693_device { struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES]; struct clk *xvclk; + /* Gate the MIPI clock lane when idle (CSI-2 non-continuous clock) */ + bool clock_ncont; + struct ov5693_mode { struct v4l2_rect crop; struct v4l2_mbus_framefmt format; @@ -285,6 +305,15 @@ static const struct cci_reg_sequence ov5693_global_regs[] = { {CCI_REG8(0x3a04), 0x06}, {CCI_REG8(0x3a05), 0x14}, {CCI_REG8(0x3e07), 0x20}, + /* + * BLC: same values the Windows driver writes. The sensor keeps its + * black pedestal at ~16 LSB (10-bit) at every analogue gain (measured + * with dark captures; adding the remaining Windows BLC registers + * 0x4002/0x4005/0x400c/0x400d/0x404e/0x404f does not change that). + * Note the OEM .aiqb black-level calibration says 64.9 because it is + * expressed at the 12-bit alignment Windows' ISYS DMA delivers + * (16.2 <<2); see REPRODUCIR.md section 10. + */ {CCI_REG8(0x4000), 0x08}, {CCI_REG8(0x4001), 0x04}, {CCI_REG8(0x4004), 0x08}, @@ -293,7 +322,7 @@ static const struct cci_reg_sequence ov5693_global_regs[] = { {CCI_REG8(0x4009), 0x10}, {CCI_REG8(0x4058), 0x00}, {CCI_REG8(0x4101), 0xb2}, - {CCI_REG8(0x4307), 0x31}, + {CCI_REG8(0x4307), 0x30}, {CCI_REG8(0x4511), 0x05}, {CCI_REG8(0x4512), 0x01}, {CCI_REG8(0x481f), 0x30}, @@ -353,19 +382,126 @@ static const u8 ov5693_test_pattern_bits[] = { /* V4L2 Controls Functions */ +/* + * Which FORMAT1 bits express a vertical flip depends on the readout mode. + * + * At full resolution both the sensor-side and the ISP-side bit are used, as + * the datasheet describes. With 2x2 binning, setting both corrupts the CSI-2 + * framing: an IPU6 receiver reports "Frame sync error" on every frame and no + * data arrives at all. The ISP bit alone streams cleanly but does not + * actually flip the picture, so the sensor-side bit alone is the one that + * both streams and flips. It also inverts the vertical Bayer phase, which + * the even ISP window offset in ov5693_mode_configure() keeps in place -- + * measured on a Surface Pro 7+ against the full-resolution orientation. + */ +static u8 ov5693_flip_vert_bits(struct ov5693_device *ov5693) +{ + if (ov5693->mode.binning_y) + return OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; + + return OV5693_FORMAT1_FLIP_VERT_ISP_EN | + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; +} + +/* + * On the Surface Pro 4 and 5 and the Surface Book 2 the front OV5693 is mounted + * vertically mirrored: the upright, unmirrored image needs the sensor's + * vertical flip and no horizontal flip (the firmware reports a 180 degree + * rotation instead, which would leave the image mirrored). Invert the VFLIP + * control so that its default (0) gives the upright image; ipu-bridge reports + * 0 degrees for this sensor. + */ +static const struct dmi_system_id ov5693_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + +static bool ov5693_vflip_enabled(bool ctrl_val) +{ + return ctrl_val ^ !!dmi_check_system(ov5693_vflip_inverted_dmi_ids); +} + +/* + * In the full readout each flip (ISP + sensor bits) moves the Bayer phase by + * one column, so with exactly one of them enabled the receiver gets GBRG + * instead of BGGR; with both enabled the two shifts cancel out. The crop + * start is only honoured in steps of two, so compensate by shifting the + * output window by one column instead, and widen the crop so the window still + * fits. The binned readout keeps its phase with either flip. + */ +static bool ov5693_bayer_shift(struct ov5693_device *ov5693) +{ + const struct ov5693_mode *mode = &ov5693->mode; + bool hflip, vflip; + + if (mode->binning_x || mode->binning_y) + return false; + + hflip = ov5693->ctrls.hflip && ov5693->ctrls.hflip->val; + vflip = ov5693->ctrls.vflip && + ov5693_vflip_enabled(ov5693->ctrls.vflip->val); + + return hflip ^ vflip; +} + +static int ov5693_window_x_configure(struct ov5693_device *ov5693) +{ + const struct ov5693_mode *mode = &ov5693->mode; + bool binned = mode->binning_x || mode->binning_y; + bool shift = ov5693_bayer_shift(ov5693); + int ret = 0; + + /* Offset X */ + cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, + binned ? 8 : shift, &ret); + + /* Crop End X */ + cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, + binned ? OV5693_NATIVE_WIDTH - 1 : + mode->crop.left + mode->crop.width + + (shift ? 2 : 0), &ret); + + return ret; +} + static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable) { - u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN | + enable = ov5693_vflip_enabled(enable); + + u8 mask = OV5693_FORMAT1_FLIP_VERT_ISP_EN | OV5693_FORMAT1_FLIP_VERT_SENSOR_EN; int ret; - ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, bits, - enable ? bits : 0, NULL); + ret = cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, mask, + enable ? ov5693_flip_vert_bits(ov5693) : 0, NULL); if (ret) return ret; - return 0; + return ov5693_window_x_configure(ov5693); } static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, @@ -380,7 +516,7 @@ static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, if (ret) return ret; - return 0; + return ov5693_window_x_configure(ov5693); } static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value) @@ -549,36 +685,116 @@ static const struct v4l2_ctrl_ops ov5693_ctrl_ops = { /* System Control Functions */ +/* + * Registers the vendor (Windows) driver programs differently for the full + * resolution and the 2x2 binned readout, taken from the mode tables in + * ov5693.sys. + * + * The mainline driver writes only the full-resolution values, once, from + * ov5693_global_regs, and never revisits them. Selecting the binned mode + * therefore leaves the sensor with a MIPI PLL multiplier (0x30b3) and + * analogue readout timing meant for twice the line length. On an IPU6 the + * receiver then reports "Transfer FIFO overflow" and every frame arrives + * empty, which is why the binned mode has been unusable -- and why the + * sensor has had to be read at full resolution and downscaled, costing two + * stops of light and forcing the AGC to its maximum analogue gain. + */ +static const struct cci_reg_sequence ov5693_mode_full_regs[] = { + {CCI_REG8(0x30b3), 0x83}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3620), 0x54}, + {CCI_REG8(0x3621), 0xc7}, + {CCI_REG8(0x3622), 0x0f}, + {CCI_REG8(0x3708), 0xe2}, + {CCI_REG8(0x3709), 0xc3}, + {CCI_REG8(0x371f), 0x0c}, +}; + +static const struct cci_reg_sequence ov5693_mode_binned_regs[] = { + {CCI_REG8(0x30b3), 0x70}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3600), 0xbc}, /* analogue, vendor sets it binned-only */ + {CCI_REG8(0x3620), 0x44}, + {CCI_REG8(0x3621), 0xb5}, + {CCI_REG8(0x3622), 0x0c}, + {CCI_REG8(0x3708), 0xe6}, + {CCI_REG8(0x3709), 0xc7}, + {CCI_REG8(0x371f), 0x1f}, +}; + +/* + * Binned readout set. With the 60 fps values (0) the IPU3 CIO2 of the + * Surface Pro 5 loses several frames per stream ("frame sync error", + * short payloads); the 30 fps values (1, default) stream cleanly. + * binned_regs = 0: readout and MIPI PLL of the 60 fps binned mode + * binned_regs = 1: 30 fps binned values, MIPI PLL multiplier 0x7d + * binned_regs = 2: 30 fps binned values with the full-mode PLL (0x83) + * blc_target: black level target (0x4009); 0 leaves the default. + */ +static int binned_regs = 1; +module_param(binned_regs, int, 0644); +MODULE_PARM_DESC(binned_regs, "binned readout set (0=60fps, 1=30fps, 2=30fps+full PLL)"); + +static int blc_target; +module_param(blc_target, int, 0644); +MODULE_PARM_DESC(blc_target, "black level target 0x4009 (0=default)"); + +static const struct cci_reg_sequence ov5693_mode_binned30_regs[] = { + {CCI_REG8(0x30b3), 0x7d}, /* MIPI PLL multiplier */ + {CCI_REG8(0x3620), 0x54}, + {CCI_REG8(0x3621), 0xc7}, + {CCI_REG8(0x3622), 0x0f}, + {CCI_REG8(0x3708), 0xe6}, + {CCI_REG8(0x3709), 0xc7}, + {CCI_REG8(0x371f), 0x0c}, +}; + static int ov5693_mode_configure(struct ov5693_device *ov5693) { const struct ov5693_mode *mode = &ov5693->mode; + bool binned = mode->binning_x || mode->binning_y; int ret = 0; - /* Crop Start X */ - cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, mode->crop.left, - &ret); + /* + * Readout geometry. At full resolution this is the crop rectangle + * selected over the media API, with the sensor-ISP window offsets at + * zero. + * + * The binned mode instead copies the vendor driver: read the whole + * pixel array (0..2623 x 0..1955), bin it to 1312x978, and let the + * ISP window offsets place the 1296x972 output inside that. The + * vertical offset is 2 rather than the vendor's 3: an odd offset + * shifts the Bayer phase by one row (everything decodes magenta and + * green); the vendor ISP knows the resulting phase, a V4L2 receiver + * assumes it unchanged. The + * obvious alternative -- keeping the 2592x1944 crop so the binned + * readout exactly equals the output size with zero offset -- leaves + * the sensor ISP without spare pixels around the window, and the + * frames it emits then fail CSI-2 framing ("Frame sync error" on the + * IPU6, no frame ever completes). + */ - /* Offset X */ - cci_write(ov5693->regmap, OV5693_OFFSET_START_X_REG, 0, &ret); + /* Crop Start X */ + cci_write(ov5693->regmap, OV5693_CROP_START_X_REG, + binned ? 0 : mode->crop.left, &ret); /* Output Size X */ cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_X_REG, mode->format.width, &ret); - /* Crop End X */ - cci_write(ov5693->regmap, OV5693_CROP_END_X_REG, - mode->crop.left + mode->crop.width, &ret); + /* Offset X and Crop End X follow the flips, see ov5693_bayer_shift(). */ + if (!ret) + ret = ov5693_window_x_configure(ov5693); /* Horizontal Total Size */ cci_write(ov5693->regmap, OV5693_TIMING_HTS_REG, OV5693_FIXED_PPL, &ret); /* Crop Start Y */ - cci_write(ov5693->regmap, OV5693_CROP_START_Y_REG, mode->crop.top, - &ret); + cci_write(ov5693->regmap, OV5693_CROP_START_Y_REG, + binned ? 0 : mode->crop.top, &ret); - /* Offset Y */ - cci_write(ov5693->regmap, OV5693_OFFSET_START_Y_REG, 0, &ret); + /* Offset Y: parity picks the Bayer phase, see binned_y_offset. */ + cci_write(ov5693->regmap, OV5693_OFFSET_START_Y_REG, + binned ? binned_y_offset : 0, &ret); /* Output Size Y */ cci_write(ov5693->regmap, OV5693_OUTPUT_SIZE_Y_REG, mode->format.height, @@ -586,7 +802,8 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) /* Crop End Y */ cci_write(ov5693->regmap, OV5693_CROP_END_Y_REG, - mode->crop.top + mode->crop.height, &ret); + binned ? OV5693_NATIVE_HEIGHT - 1 : + mode->crop.top + mode->crop.height, &ret); /* Subsample X increase */ cci_write(ov5693->regmap, OV5693_SUB_INC_X_REG, @@ -604,6 +821,34 @@ static int ov5693_mode_configure(struct ov5693_device *ov5693) OV5693_FORMAT2_HBIN_EN, mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0, &ret); + /* + * The set of FORMAT1 bits that means "vertical flip" changes with the + * readout mode, so re-apply the control now that binning is known. + */ + if (ov5693->ctrls.vflip && + ov5693_vflip_enabled(ov5693->ctrls.vflip->val)) + cci_update_bits(ov5693->regmap, OV5693_FORMAT1_REG, + OV5693_FORMAT1_FLIP_VERT_ISP_EN | + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN, + ov5693_flip_vert_bits(ov5693), &ret); + + /* PLL and analogue readout timing follow the readout mode. */ + if ((mode->binning_x || mode->binning_y) && binned_regs) { + cci_multi_reg_write(ov5693->regmap, ov5693_mode_binned30_regs, + ARRAY_SIZE(ov5693_mode_binned30_regs), &ret); + if (binned_regs == 2) + cci_write(ov5693->regmap, CCI_REG8(0x30b3), 0x83, &ret); + } else if (mode->binning_x || mode->binning_y) + cci_multi_reg_write(ov5693->regmap, ov5693_mode_binned_regs, + ARRAY_SIZE(ov5693_mode_binned_regs), &ret); + else + cci_multi_reg_write(ov5693->regmap, ov5693_mode_full_regs, + ARRAY_SIZE(ov5693_mode_full_regs), &ret); + + if (blc_target) + cci_write(ov5693->regmap, CCI_REG8(0x4009), blc_target & 0xff, + &ret); + return ret; } @@ -611,6 +856,19 @@ static int ov5693_enable_streaming(struct ov5693_device *ov5693, bool enable) { int ret = 0; + /* + * Gate the MIPI clock lane while idle if the CSI-2 link is configured + * for a non-continuous clock. Only that bit is touched, and only in + * that case, so the register keeps whatever the platform left in it + * and the clock stays free-running as before everywhere else. It + * needs no counterpart at stream off: the link is down by then, and + * the register returns to its default when the sensor is powered off. + */ + if (enable && ov5693->clock_ncont) + cci_update_bits(ov5693->regmap, OV5693_MIPI_CTRL00_REG, + OV5693_MIPI_CTRL00_CLOCK_LANE_GATE, + OV5693_MIPI_CTRL00_CLOCK_LANE_GATE, &ret); + cci_write(ov5693->regmap, OV5693_SW_STREAM_REG, enable ? OV5693_START_STREAMING : OV5693_STOP_STREAMING, &ret); @@ -762,6 +1020,16 @@ static unsigned int __ov5693_calc_vts(u32 height) tgt_fps = rounddown(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / height, 30); + /* + * Cap at 30fps. Left alone this picks 60fps for the 2x2 binned mode, + * which halves VTS to 1038 -- and the binned readout runs off a slower + * MIPI PLL (0x30b3), so the link cannot carry twice the frame rate: + * the IPU6 reports "Frame sync error" and no frame ever completes. The + * vendor driver runs the same mode at VTS 1984. Staying at 30fps also + * keeps the exposure ceiling, which is VTS bound, where it was. + */ + tgt_fps = min(tgt_fps, 30U); + return ALIGN_DOWN(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / tgt_fps, 2); } @@ -976,6 +1244,19 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable) return ret; mutex_lock(&ov5693->lock); + + /* + * Same as ov8865: the mode registers are only written on + * runtime PM resume, so a format change on a sensor that stays + * powered never reaches the chip. Program the mode first, then + * the controls, so the mode registers don't clobber them. + */ + ret = ov5693_mode_configure(ov5693); + if (ret) { + mutex_unlock(&ov5693->lock); + goto err_power_down; + } + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler); if (ret) { mutex_unlock(&ov5693->lock); @@ -1259,6 +1540,9 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693) goto out_free_bus_cfg; } + ov5693->clock_ncont = bus_cfg.bus.mipi_csi2.flags & + V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK; + out_free_bus_cfg: v4l2_fwnode_endpoint_free(&bus_cfg); diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index a1a91b41eb4d6..b59a4f668b088 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -234,6 +235,90 @@ static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { [OV7251_24_MHZ] = &ov7251_pll_cfgs_24_mhz, }; +/* + * Surface IR flood illuminator. + * + * On the Surface Pro 5 and 6 and the Surface Book 2 the IR LED is driven by + * the sensor's STROBE pad, not by a GPIO or the TPS68470 LED outputs, and ACPI + * does not describe it. The mode tables leave the pad disabled (0x3005 = 0x00, + * 0x3016-0x301c = 0xf0), so the LED never lights and the IR camera (behind an + * IR-pass filter) sees black. + * + * 0x3b81 is the strobe pattern: 0xaa lights the LED on alternate frames, so + * userspace gets lit and unlit frames for ambient light subtraction. + * + * surface_ir_strobe: -1 = auto (on for the DMI matches below), 0 = off, 1 = on. + */ +static int surface_ir_strobe = -1; +module_param(surface_ir_strobe, int, 0644); +MODULE_PARM_DESC(surface_ir_strobe, + "Drive the Surface IR illuminator via STROBE (-1 auto, 0 off, 1 on)"); + +static const struct dmi_system_id ov7251_surface_ir_strobe_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, + "Surface_Pro_6_1796_Consumer"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, + {} +}; + +static const struct reg_value ov7251_surface_ir_strobe_regs[] = { + { 0x3005, 0x08 }, + { 0x3016, 0x10 }, + { 0x3017, 0x00 }, + { 0x3018, 0x00 }, + { 0x301a, 0x00 }, + { 0x301b, 0x00 }, + { 0x301c, 0x00 }, + { 0x3664, 0xf0 }, + { 0x3b81, 0xaa }, + { 0x3b8b, 0x00 }, + { 0x3b8e, 0x03 }, + { 0x3b8f, 0x08 }, + { 0x3b96, 0xc0 }, +}; + +/* + * Strobe pattern (0x3b81): 0xaa lights alternate frames, 0xff every frame. + * The strobe pulse follows the exposure time (0x3b8c-0x3b8f, in lines), + * clamped to the range the Surface uses. + */ +static int surface_ir_pattern = 0xaa; +module_param(surface_ir_pattern, int, 0644); +MODULE_PARM_DESC(surface_ir_pattern, "IR strobe pattern 0x3b81 (0xaa alternate frames, 0xff every frame)"); + +#define OV7251_STROBE_MIN_LINES 52 +#define OV7251_STROBE_MAX_LINES 776 + +static bool ov7251_use_surface_ir_strobe(void) +{ + if (surface_ir_strobe >= 0) + return surface_ir_strobe; + + return dmi_check_system(ov7251_surface_ir_strobe_dmi_ids); +} + static const struct reg_value ov7251_global_init_setting[] = { { 0x0103, 0x01 }, { 0x303b, 0x02 }, @@ -865,13 +950,28 @@ static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure) { u16 reg; u8 val[3]; + s32 strobe; + int ret; reg = OV7251_AEC_EXPO_0; val[0] = (exposure & 0xf000) >> 12; /* goes to OV7251_AEC_EXPO_0 */ val[1] = (exposure & 0x0ff0) >> 4; /* goes to OV7251_AEC_EXPO_1 */ val[2] = (exposure & 0x000f) << 4; /* goes to OV7251_AEC_EXPO_2 */ - return ov7251_write_seq_regs(ov7251, reg, val, 3); + ret = ov7251_write_seq_regs(ov7251, reg, val, 3); + if (ret < 0 || !ov7251_use_surface_ir_strobe()) + return ret; + + strobe = clamp_t(s32, exposure, OV7251_STROBE_MIN_LINES, + OV7251_STROBE_MAX_LINES); + val[0] = 0; + val[1] = 0; + val[2] = strobe >> 8; + ret = ov7251_write_seq_regs(ov7251, 0x3b8c, val, 3); + if (ret < 0) + return ret; + + return ov7251_write_reg(ov7251, 0x3b8f, strobe & 0xff); } static int ov7251_set_gain(struct ov7251 *ov7251, s32 gain) @@ -1362,6 +1462,18 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) ov7251->current_mode->height); goto err_power_down; } + if (ov7251_use_surface_ir_strobe()) { + ret = ov7251_set_register_array(ov7251, + ov7251_surface_ir_strobe_regs, + ARRAY_SIZE(ov7251_surface_ir_strobe_regs)); + if (!ret) + ret = ov7251_write_reg(ov7251, 0x3b81, + surface_ir_pattern & 0xff); + if (ret < 0) { + dev_err(ov7251->dev, "could not set IR strobe\n"); + goto err_power_down; + } + } ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls); if (ret < 0) { dev_err(ov7251->dev, "could not sync v4l2 controls\n"); diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index 289a34a3eeb17..247b66ac359f0 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -180,10 +181,10 @@ #define OV8865_HTS_L_REG 0x380d #define OV8865_HTS_L(v) ((v) & GENMASK(7, 0)) #define OV8865_VTS_H_REG 0x380e -#define OV8865_VTS_H(v) (((v) & GENMASK(11, 8)) >> 8) +#define OV8865_VTS_H(v) (((v) & GENMASK(14, 8)) >> 8) #define OV8865_VTS_L_REG 0x380f #define OV8865_VTS_L(v) ((v) & GENMASK(7, 0)) -#define OV8865_TIMING_MAX_VTS 0xffff +#define OV8865_TIMING_MAX_VTS 0x7fff #define OV8865_TIMING_MIN_VTS 0x04 #define OV8865_OFFSET_X_H_REG 0x3810 #define OV8865_OFFSET_X_H(v) (((v) & GENMASK(15, 8)) >> 8) @@ -2189,11 +2190,48 @@ static int ov8865_blue_balance_configure(struct ov8865_sensor *sensor, /* Flip */ +/* + * On the Surface Pro 4 and 5 and the Surface Book 2 the rear OV8865 is mounted + * vertically mirrored: the upright image needs the sensor's vertical flip + * enabled. Invert the VFLIP control so that the default (0) gives an upright + * image. + */ +static const struct dmi_system_id ov8865_vflip_inverted_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + static int ov8865_flip_vert_configure(struct ov8865_sensor *sensor, bool enable) { u8 bits = OV8865_FORMAT1_FLIP_VERT_ISP_EN | OV8865_FORMAT1_FLIP_VERT_SENSOR_EN; + if (dmi_check_system(ov8865_vflip_inverted_dmi_ids)) + enable = !enable; + return ov8865_update_bits(sensor, OV8865_FORMAT1_REG, bits, enable ? bits : 0); } @@ -2528,7 +2566,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor) /* Gain */ - v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 128, + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 1, 128); /* White Balance */ @@ -2701,6 +2739,43 @@ static int ov8865_get_fmt(struct v4l2_subdev *subdev, return 0; } +/* + * The Surface Pro 5 exposes the rear camera through libcamera's IPU3 + * pipeline, which does not change the frame length. In the 800x600 mode + * (90 fps) the exposure is then capped at ~11 ms and indoor images are + * black even at maximum gain, so default to 30 fps there. Higher frame + * rates stay available through VBLANK. + */ +static const struct dmi_system_id ov8865_30fps_default_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + }, + {} +}; + +/* The 800x600 mode is the only one faster than 30 fps: 90 fps at its VTS. */ +#define OV8865_SVGA_FPS_DIVIDER 3 + +static u32 ov8865_vblank_default(const struct ov8865_mode *mode) +{ + u32 vts = mode->vts; + + if (mode->output_size_x == 800 && mode->output_size_y == 600 && + dmi_check_system(ov8865_30fps_default_dmi_ids)) + vts *= OV8865_SVGA_FPS_DIVIDER; + + return vts - mode->output_size_y; +} + static int ov8865_set_fmt(struct v4l2_subdev *subdev, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) @@ -2711,6 +2786,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev, u32 mbus_code = 0; unsigned int hblank; unsigned int index; + u32 vblank_def; int exposure_max; int ret = 0; @@ -2751,15 +2827,25 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev, sensor->state.mbus_code != mbus_code) ret = ov8865_state_configure(sensor, mode, mbus_code); + vblank_def = ov8865_vblank_default(mode); __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV8865_TIMING_MIN_VTS, OV8865_TIMING_MAX_VTS - mode->output_size_y, - 1, mode->vts - mode->output_size_y); + 1, vblank_def); + + /* + * Start every mode from its default frame length: a VBLANK value left + * over from the previous mode would keep that mode's timing (e.g. the + * full-size mode's 22 lines make the 800x600 mode run at ~93 fps). + */ + if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) + __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, vblank_def); hblank = mode->hts - mode->output_size_x; __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1, hblank); - exposure_max = mode->vts - OV8865_INTEGRATION_TIME_MARGIN; + exposure_max = mode->output_size_y + vblank_def - + OV8865_INTEGRATION_TIME_MARGIN; __v4l2_ctrl_modify_range(sensor->ctrls.exposure, sensor->ctrls.exposure->minimum, exposure_max, sensor->ctrls.exposure->step, diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c index 271b987660c5c..c9b9dcbc355a6 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include +#include #include #define ADEV_DEV(adev) ACPI_PTR(&((adev)->dev)) @@ -48,6 +50,14 @@ * * Please keep the list sorted by ACPI HID. */ +/* IPU6 variants whose CSI-2 receiver needs the ov5693 clock lane gated */ +static const u16 ipu6_ov5693_ncont_clk[] = { + PCI_DEVICE_ID_INTEL_IPU6, /* Tiger Lake */ + PCI_DEVICE_ID_INTEL_IPU6EP_ADLP, /* Alder Lake-P */ + PCI_DEVICE_ID_INTEL_IPU6EP_ADLN, /* Alder Lake-N */ + 0 +}; + static const struct ipu_sensor_config ipu_supported_sensors[] = { /* Himax HM1092 */ IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000), @@ -60,10 +70,16 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = { /* GalaxyCore GC0310 */ IPU_SENSOR_CONFIG("INT0310", 1, 55692000), /* Omnivision OV5693 */ + IPU_SENSOR_CONFIG_MATCH_FL("INT33BE", ipu6_ov5693_ncont_clk, + IPU_BR_FL_CSI2_CLK_NONCONTINUOUS, + 1, 419200000), IPU_SENSOR_CONFIG("INT33BE", 1, 419200000), /* Onsemi MT9M114 */ IPU_SENSOR_CONFIG("INT33F0", 1, 384000000), /* Omnivision OV5693 - Surface Pro 9 */ + IPU_SENSOR_CONFIG_MATCH_FL("OVTI5693", ipu6_ov5693_ncont_clk, + IPU_BR_FL_CSI2_CLK_NONCONTINUOUS, + 1, 419200000), IPU_SENSOR_CONFIG("OVTI5693", 1, 419200000), /* Omnivision OV13858 - Surface Pro 9 */ IPU_SENSOR_CONFIG("OVTID858", 4, 540000000), @@ -220,6 +236,74 @@ static const struct dmi_system_id upside_down_sensor_dmi_ids[] = { {} /* Terminating entry */ }; +/* + * DMI matches for devices whose SSDB reports a 180° rotation for sensors that + * are not actually rotated. On the Surface Pro 4 and 5 and the Surface Book 2 + * the firmware reports 180° for both the front (OV5693) and the rear (OV8865) + * camera. Measured on the devices, both need a vertical flip only and no + * mirroring, which is not a rotation: report 0 degrees and let the sensor + * drivers apply the flip. + */ +static const struct dmi_system_id not_rotated_sensor_dmi_ids[] = { + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_4"), + }, + .driver_data = "INT347A", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Book_1793"), + }, + .driver_data = "INT347A", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1796"), + }, + .driver_data = "INT347A", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + .driver_data = "INT33BE", + }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "Surface_Pro_1807"), + }, + .driver_data = "INT347A", + }, + {} /* Terminating entry */ +}; + static const struct ipu_property_names prop_names = { .clock_frequency = "clock-frequency", .rotation = "rotation", @@ -228,6 +312,7 @@ static const struct ipu_property_names prop_names = { .data_lanes = "data-lanes", .remote_endpoint = "remote-endpoint", .link_frequencies = "link-frequencies", + .clock_noncontinuous = "clock-noncontinuous", }; static const char * const ipu_vcm_types[] = { @@ -412,6 +497,11 @@ static u32 ipu_bridge_parse_rotation(struct acpi_device *adev, if (acpi_dev_hid_match(adev, dmi_id->driver_data)) return 180; + for (dmi_id = dmi_first_match(not_rotated_sensor_dmi_ids); dmi_id; + dmi_id = dmi_first_match(dmi_id + 1)) + if (acpi_dev_hid_match(adev, dmi_id->driver_data)) + return 0; + switch (ssdb->degree) { case IPU_SENSOR_ROTATION_NORMAL: return 0; @@ -498,6 +588,7 @@ static void ipu_bridge_create_fwnode_properties( { struct ipu_property_names *names = &sensor->prop_names; struct software_node *nodes = sensor->swnodes; + unsigned int i = 0; sensor->prop_names = prop_names; @@ -555,21 +646,25 @@ static void ipu_bridge_create_fwnode_properties( PROPERTY_ENTRY_REF_ARRAY("lens-focus", sensor->vcm_ref); } - sensor->ep_properties[0] = PROPERTY_ENTRY_U32( - sensor->prop_names.bus_type, - V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); - sensor->ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN( - sensor->prop_names.data_lanes, - bridge->data_lanes, sensor->lanes); - sensor->ep_properties[2] = PROPERTY_ENTRY_REF_ARRAY( - sensor->prop_names.remote_endpoint, - sensor->local_ref); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_BUS_TYPE)] = + PROPERTY_ENTRY_U32(names->bus_type, + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_DATA_LANES)] = + PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes, + bridge->data_lanes, sensor->lanes); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_REMOTE_EP)] = + PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint, + sensor->local_ref); if (cfg->nr_link_freqs > 0) - sensor->ep_properties[3] = PROPERTY_ENTRY_U64_ARRAY_LEN( - sensor->prop_names.link_frequencies, - cfg->link_freqs, - cfg->nr_link_freqs); + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_LINK_FREQUENCIES)] = + PROPERTY_ENTRY_U64_ARRAY_LEN(names->link_frequencies, + cfg->link_freqs, + cfg->nr_link_freqs); + + if (cfg->flags & IPU_BR_FL_CSI2_CLK_NONCONTINUOUS) + sensor->ep_properties[IPU_BRIDGE_NEXT_PROPERTY(i, EP_CLOCK_NONCONTINUOUS)] = + PROPERTY_ENTRY_BOOL(names->clock_noncontinuous); sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( sensor->prop_names.data_lanes, @@ -899,8 +994,28 @@ static int ipu_bridge_connect_sensor(const struct ipu_sensor_config *cfg, return ret; } +/* + * Whether a sensor config applies to the IPU this bridge sits on. A config + * listing PCI product IDs only applies to those IPUs. + */ +static bool ipu_bridge_config_matches(const struct ipu_sensor_config *cfg, + struct ipu_bridge *bridge) +{ + const u16 *id; + + if (!cfg->pci_ids) + return true; + + for (id = cfg->pci_ids; *id; id++) + if (*id == bridge->pci_id) + return true; + + return false; +} + static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge) { + const char *done_hid = NULL; unsigned int i; int ret; @@ -908,9 +1023,22 @@ static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge) const struct ipu_sensor_config *cfg = &ipu_supported_sensors[i]; + /* + * Entries for one HID are adjacent, IPU-specific ones first, + * so the generic entry is skipped once a specific one has + * matched and the sensor is not connected twice. + */ + if (done_hid && !strcmp(cfg->hid, done_hid)) + continue; + + if (!ipu_bridge_config_matches(cfg, bridge)) + continue; + ret = ipu_bridge_connect_sensor(cfg, bridge); if (ret) goto err_unregister_sensors; + + done_hid = cfg->hid; } return 0; @@ -967,6 +1095,18 @@ static int ipu_bridge_check_fwnode_graph(struct fwnode_handle *fwnode) return ipu_bridge_check_fwnode_graph(fwnode->secondary); } +struct pci_dev *ipu_bridge_get_ipu6(void) +{ + struct pci_dev *ipu = NULL; + + for (unsigned int i = 0; !ipu && ipu6_pci_tbl[i].vendor; i++) + ipu = pci_get_device(ipu6_pci_tbl[i].vendor, + ipu6_pci_tbl[i].device, NULL); + + return ipu; +} +EXPORT_SYMBOL_NS_GPL(ipu_bridge_get_ipu6, "INTEL_IPU_BRIDGE"); + static DEFINE_MUTEX(ipu_bridge_mutex); int ipu_bridge_init(struct device *dev, @@ -994,6 +1134,7 @@ int ipu_bridge_init(struct device *dev, sizeof(bridge->ipu_node_name)); bridge->ipu_hid_node.name = bridge->ipu_node_name; bridge->dev = dev; + bridge->pci_id = dev_is_pci(dev) ? to_pci_dev(dev)->device : 0; bridge->parse_sensor_fwnode = parse_sensor_fwnode; ret = software_node_register(&bridge->ipu_hid_node); diff --git a/include/media/ipu-bridge.h b/include/media/ipu-bridge.h index 16fac765456e8..3ef94c2b76789 100644 --- a/include/media/ipu-bridge.h +++ b/include/media/ipu-bridge.h @@ -17,13 +17,28 @@ #define IPU_SENSOR_ROTATION_NORMAL 0 #define IPU_SENSOR_ROTATION_INVERTED 1 -#define IPU_SENSOR_CONFIG(_HID, _NR, ...) \ - (const struct ipu_sensor_config) { \ - .hid = _HID, \ - .nr_link_freqs = _NR, \ - .link_freqs = { __VA_ARGS__ } \ +/* Flags for struct ipu_sensor_config */ +/* The sensor's CSI-2 transmitter needs a non-continuous clock */ +#define IPU_BR_FL_CSI2_CLK_NONCONTINUOUS BIT(0) + +/* + * Sensor config specific to one or more IPUs, identified by their PCI product + * IDs, with flags describing what the sensor needs there. Entries for one HID + * must be adjacent in ipu_supported_sensors[], with the IPU-specific ones + * before the generic one. + */ +#define IPU_SENSOR_CONFIG_MATCH_FL(_HID, _IDS, _FLAGS, _NR, ...) \ + (const struct ipu_sensor_config) { \ + .hid = _HID, \ + .pci_ids = _IDS, \ + .flags = _FLAGS, \ + .nr_link_freqs = _NR, \ + .link_freqs = { __VA_ARGS__ } \ } +#define IPU_SENSOR_CONFIG(_HID, _NR, ...) \ + IPU_SENSOR_CONFIG_MATCH_FL(_HID, NULL, 0, _NR, __VA_ARGS__) + #define NODE_SENSOR(_HID, _PROPS) \ (const struct software_node) { \ .name = _HID, \ @@ -64,6 +79,24 @@ enum ipu_sensor_swnodes { SWNODE_COUNT }; +enum ipu_bridge_ep_props { + IPU_BRIDGE_EP_BUS_TYPE, + IPU_BRIDGE_EP_DATA_LANES, + IPU_BRIDGE_EP_REMOTE_EP, + IPU_BRIDGE_EP_LINK_FREQUENCIES, + IPU_BRIDGE_EP_CLOCK_NONCONTINUOUS, + IPU_BRIDGE_EP_NUM_OF, + IPU_BRIDGE_EP_NUM_ENTRIES +}; + +/* + * Get the index of the next property in a property array, with a given maximum + * value. + */ +#define IPU_BRIDGE_NEXT_PROPERTY(index, max) \ + (WARN_ON((index) > IPU_BRIDGE_##max) ? \ + IPU_BRIDGE_##max : (index)++) + /* Data representation as it is in ACPI SSDB buffer */ struct ipu_sensor_ssdb { u8 version; @@ -102,6 +135,7 @@ struct ipu_property_names { char data_lanes[11]; char remote_endpoint[16]; char link_frequencies[17]; + char clock_noncontinuous[20]; }; struct ipu_node_names { @@ -115,6 +149,9 @@ struct ipu_node_names { struct ipu_sensor_config { const char *hid; + /* Zero-terminated list of IPU PCI product IDs, NULL for any IPU */ + const u16 *pci_ids; + const u32 flags; const u8 nr_link_freqs; const u64 link_freqs[MAX_NUM_LINK_FREQS]; }; @@ -141,7 +178,7 @@ struct ipu_sensor { const char *vcm_type; struct ipu_property_names prop_names; - struct property_entry ep_properties[5]; + struct property_entry ep_properties[IPU_BRIDGE_EP_NUM_ENTRIES]; struct property_entry dev_properties[5]; struct property_entry ipu_properties[3]; struct property_entry ivsc_properties[1]; @@ -160,6 +197,8 @@ typedef int (*ipu_parse_sensor_fwnode_t)(struct acpi_device *adev, struct ipu_bridge { struct device *dev; + /* PCI product ID of the IPU, 0 if it is not a PCI device */ + u16 pci_id; ipu_parse_sensor_fwnode_t parse_sensor_fwnode; char ipu_node_name[ACPI_ID_LEN]; struct software_node ipu_hid_node; @@ -169,11 +208,13 @@ struct ipu_bridge { }; #if IS_ENABLED(CONFIG_IPU_BRIDGE) +struct pci_dev *ipu_bridge_get_ipu6(void); int ipu_bridge_init(struct device *dev, ipu_parse_sensor_fwnode_t parse_sensor_fwnode); int ipu_bridge_parse_ssdb(struct acpi_device *adev, struct ipu_sensor *sensor); int ipu_bridge_instantiate_vcm(struct device *sensor); #else +static inline struct pci_dev *ipu_bridge_get_ipu6(void) { return NULL; } /* Use a define to avoid the @parse_sensor_fwnode argument getting evaluated */ #define ipu_bridge_init(dev, parse_sensor_fwnode) (0) static inline int ipu_bridge_instantiate_vcm(struct device *s) { return 0; }