Skip to content
Open
50 changes: 50 additions & 0 deletions drivers/media/i2c/ov13858.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions drivers/media/i2c/ov5693.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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
Expand Down Expand Up @@ -144,6 +149,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;
Expand Down Expand Up @@ -611,6 +619,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);
Expand Down Expand Up @@ -1259,6 +1280,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);

Expand Down
94 changes: 81 additions & 13 deletions drivers/media/pci/intel/ipu-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include <linux/dmi.h>
#include <linux/i2c.h>
#include <linux/mei_cl_bus.h>
#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/property.h>
#include <linux/string.h>
#include <linux/workqueue.h>

#include <media/ipu-bridge.h>
#include <media/ipu6-pci-table.h>
#include <media/v4l2-fwnode.h>

#define ADEV_DEV(adev) ACPI_PTR(&((adev)->dev))
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -228,6 +244,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[] = {
Expand Down Expand Up @@ -498,6 +515,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;

Expand Down Expand Up @@ -555,21 +573,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,
Expand Down Expand Up @@ -899,18 +921,51 @@ 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;

for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) {
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;
Expand Down Expand Up @@ -967,6 +1022,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,
Expand Down Expand Up @@ -994,6 +1061,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);
Expand Down
Loading