@@ -2000,6 +2000,61 @@ static void ov5640_set_power_off(struct ov5640_dev *sensor)
20002000 clk_disable_unprepare (sensor -> xclk );
20012001}
20022002
2003+ static int ov5640_set_power_mipi (struct ov5640_dev * sensor , bool on )
2004+ {
2005+ int ret ;
2006+
2007+ if (!on ) {
2008+ /* Reset MIPI bus settings to their default values. */
2009+ ov5640_write_reg (sensor , OV5640_REG_IO_MIPI_CTRL00 , 0x58 );
2010+ ov5640_write_reg (sensor , OV5640_REG_MIPI_CTRL00 , 0x04 );
2011+ ov5640_write_reg (sensor , OV5640_REG_PAD_OUTPUT00 , 0x00 );
2012+ return 0 ;
2013+ }
2014+
2015+ /*
2016+ * Power up MIPI HS Tx and LS Rx; 2 data lanes mode
2017+ *
2018+ * 0x300e = 0x40
2019+ * [7:5] = 010 : 2 data lanes mode (see FIXME note in
2020+ * "ov5640_set_stream_mipi()")
2021+ * [4] = 0 : Power up MIPI HS Tx
2022+ * [3] = 0 : Power up MIPI LS Rx
2023+ * [2] = 0 : MIPI interface disabled
2024+ */
2025+ ret = ov5640_write_reg (sensor , OV5640_REG_IO_MIPI_CTRL00 , 0x40 );
2026+ if (ret )
2027+ return ret ;
2028+
2029+ /*
2030+ * Gate clock and set LP11 in 'no packets mode' (idle)
2031+ *
2032+ * 0x4800 = 0x24
2033+ * [5] = 1 : Gate clock when 'no packets'
2034+ * [2] = 1 : MIPI bus in LP11 when 'no packets'
2035+ */
2036+ ret = ov5640_write_reg (sensor , OV5640_REG_MIPI_CTRL00 , 0x24 );
2037+ if (ret )
2038+ return ret ;
2039+
2040+ /*
2041+ * Set data lanes and clock in LP11 when 'sleeping'
2042+ *
2043+ * 0x3019 = 0x70
2044+ * [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping'
2045+ * [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping'
2046+ * [4] = 1 : MIPI clock lane in LP11 when 'sleeping'
2047+ */
2048+ ret = ov5640_write_reg (sensor , OV5640_REG_PAD_OUTPUT00 , 0x70 );
2049+ if (ret )
2050+ return ret ;
2051+
2052+ /* Give lanes some time to coax into LP11 state. */
2053+ usleep_range (500 , 1000 );
2054+
2055+ return 0 ;
2056+ }
2057+
20032058static int ov5640_set_power (struct ov5640_dev * sensor , bool on )
20042059{
20052060 int ret = 0 ;
@@ -2012,67 +2067,16 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on)
20122067 ret = ov5640_restore_mode (sensor );
20132068 if (ret )
20142069 goto power_off ;
2070+ }
20152071
2016- /* We're done here for DVP bus, while CSI-2 needs setup. */
2017- if (sensor -> ep .bus_type != V4L2_MBUS_CSI2_DPHY )
2018- return 0 ;
2019-
2020- /*
2021- * Power up MIPI HS Tx and LS Rx; 2 data lanes mode
2022- *
2023- * 0x300e = 0x40
2024- * [7:5] = 010 : 2 data lanes mode (see FIXME note in
2025- * "ov5640_set_stream_mipi()")
2026- * [4] = 0 : Power up MIPI HS Tx
2027- * [3] = 0 : Power up MIPI LS Rx
2028- * [2] = 0 : MIPI interface disabled
2029- */
2030- ret = ov5640_write_reg (sensor ,
2031- OV5640_REG_IO_MIPI_CTRL00 , 0x40 );
2032- if (ret )
2033- goto power_off ;
2034-
2035- /*
2036- * Gate clock and set LP11 in 'no packets mode' (idle)
2037- *
2038- * 0x4800 = 0x24
2039- * [5] = 1 : Gate clock when 'no packets'
2040- * [2] = 1 : MIPI bus in LP11 when 'no packets'
2041- */
2042- ret = ov5640_write_reg (sensor ,
2043- OV5640_REG_MIPI_CTRL00 , 0x24 );
2044- if (ret )
2045- goto power_off ;
2046-
2047- /*
2048- * Set data lanes and clock in LP11 when 'sleeping'
2049- *
2050- * 0x3019 = 0x70
2051- * [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping'
2052- * [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping'
2053- * [4] = 1 : MIPI clock lane in LP11 when 'sleeping'
2054- */
2055- ret = ov5640_write_reg (sensor ,
2056- OV5640_REG_PAD_OUTPUT00 , 0x70 );
2072+ if (sensor -> ep .bus_type == V4L2_MBUS_CSI2_DPHY ) {
2073+ ret = ov5640_set_power_mipi (sensor , on );
20572074 if (ret )
20582075 goto power_off ;
2076+ }
20592077
2060- /* Give lanes some time to coax into LP11 state. */
2061- usleep_range (500 , 1000 );
2062-
2063- } else {
2064- if (sensor -> ep .bus_type == V4L2_MBUS_CSI2_DPHY ) {
2065- /* Reset MIPI bus settings to their default values. */
2066- ov5640_write_reg (sensor ,
2067- OV5640_REG_IO_MIPI_CTRL00 , 0x58 );
2068- ov5640_write_reg (sensor ,
2069- OV5640_REG_MIPI_CTRL00 , 0x04 );
2070- ov5640_write_reg (sensor ,
2071- OV5640_REG_PAD_OUTPUT00 , 0x00 );
2072- }
2073-
2078+ if (!on )
20742079 ov5640_set_power_off (sensor );
2075- }
20762080
20772081 return 0 ;
20782082
0 commit comments