Skip to content

Commit b1751ae

Browse files
prabhakarladmchehab
authored andcommitted
media: i2c: ov5640: Separate out mipi configuration from s_power
In preparation for adding DVP configuration in s_power callback move mipi configuration into separate function Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com> Tested-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 3b987d7 commit b1751ae

File tree

1 file changed

+60
-56
lines changed

1 file changed

+60
-56
lines changed

drivers/media/i2c/ov5640.c

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,61 @@ static void ov5640_set_power_off(struct ov5640_dev *sensor)
20142014
clk_disable_unprepare(sensor->xclk);
20152015
}
20162016

2017+
static int ov5640_set_power_mipi(struct ov5640_dev *sensor, bool on)
2018+
{
2019+
int ret;
2020+
2021+
if (!on) {
2022+
/* Reset MIPI bus settings to their default values. */
2023+
ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58);
2024+
ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x04);
2025+
ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x00);
2026+
return 0;
2027+
}
2028+
2029+
/*
2030+
* Power up MIPI HS Tx and LS Rx; 2 data lanes mode
2031+
*
2032+
* 0x300e = 0x40
2033+
* [7:5] = 010 : 2 data lanes mode (see FIXME note in
2034+
* "ov5640_set_stream_mipi()")
2035+
* [4] = 0 : Power up MIPI HS Tx
2036+
* [3] = 0 : Power up MIPI LS Rx
2037+
* [2] = 0 : MIPI interface disabled
2038+
*/
2039+
ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x40);
2040+
if (ret)
2041+
return ret;
2042+
2043+
/*
2044+
* Gate clock and set LP11 in 'no packets mode' (idle)
2045+
*
2046+
* 0x4800 = 0x24
2047+
* [5] = 1 : Gate clock when 'no packets'
2048+
* [2] = 1 : MIPI bus in LP11 when 'no packets'
2049+
*/
2050+
ret = ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x24);
2051+
if (ret)
2052+
return ret;
2053+
2054+
/*
2055+
* Set data lanes and clock in LP11 when 'sleeping'
2056+
*
2057+
* 0x3019 = 0x70
2058+
* [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping'
2059+
* [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping'
2060+
* [4] = 1 : MIPI clock lane in LP11 when 'sleeping'
2061+
*/
2062+
ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x70);
2063+
if (ret)
2064+
return ret;
2065+
2066+
/* Give lanes some time to coax into LP11 state. */
2067+
usleep_range(500, 1000);
2068+
2069+
return 0;
2070+
}
2071+
20172072
static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
20182073
{
20192074
int ret = 0;
@@ -2026,67 +2081,16 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
20262081
ret = ov5640_restore_mode(sensor);
20272082
if (ret)
20282083
goto power_off;
2084+
}
20292085

2030-
/* We're done here for DVP bus, while CSI-2 needs setup. */
2031-
if (sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY)
2032-
return 0;
2033-
2034-
/*
2035-
* Power up MIPI HS Tx and LS Rx; 2 data lanes mode
2036-
*
2037-
* 0x300e = 0x40
2038-
* [7:5] = 010 : 2 data lanes mode (see FIXME note in
2039-
* "ov5640_set_stream_mipi()")
2040-
* [4] = 0 : Power up MIPI HS Tx
2041-
* [3] = 0 : Power up MIPI LS Rx
2042-
* [2] = 0 : MIPI interface disabled
2043-
*/
2044-
ret = ov5640_write_reg(sensor,
2045-
OV5640_REG_IO_MIPI_CTRL00, 0x40);
2046-
if (ret)
2047-
goto power_off;
2048-
2049-
/*
2050-
* Gate clock and set LP11 in 'no packets mode' (idle)
2051-
*
2052-
* 0x4800 = 0x24
2053-
* [5] = 1 : Gate clock when 'no packets'
2054-
* [2] = 1 : MIPI bus in LP11 when 'no packets'
2055-
*/
2056-
ret = ov5640_write_reg(sensor,
2057-
OV5640_REG_MIPI_CTRL00, 0x24);
2058-
if (ret)
2059-
goto power_off;
2060-
2061-
/*
2062-
* Set data lanes and clock in LP11 when 'sleeping'
2063-
*
2064-
* 0x3019 = 0x70
2065-
* [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping'
2066-
* [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping'
2067-
* [4] = 1 : MIPI clock lane in LP11 when 'sleeping'
2068-
*/
2069-
ret = ov5640_write_reg(sensor,
2070-
OV5640_REG_PAD_OUTPUT00, 0x70);
2086+
if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
2087+
ret = ov5640_set_power_mipi(sensor, on);
20712088
if (ret)
20722089
goto power_off;
2090+
}
20732091

2074-
/* Give lanes some time to coax into LP11 state. */
2075-
usleep_range(500, 1000);
2076-
2077-
} else {
2078-
if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
2079-
/* Reset MIPI bus settings to their default values. */
2080-
ov5640_write_reg(sensor,
2081-
OV5640_REG_IO_MIPI_CTRL00, 0x58);
2082-
ov5640_write_reg(sensor,
2083-
OV5640_REG_MIPI_CTRL00, 0x04);
2084-
ov5640_write_reg(sensor,
2085-
OV5640_REG_PAD_OUTPUT00, 0x00);
2086-
}
2087-
2092+
if (!on)
20882093
ov5640_set_power_off(sensor);
2089-
}
20902094

20912095
return 0;
20922096

0 commit comments

Comments
 (0)