Lines Matching full:sensor
481 static inline bool ov5640_is_csi2(const struct ov5640_dev *sensor) in ov5640_is_csi2() argument
483 return sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY; in ov5640_is_csi2()
487 ov5640_formats(struct ov5640_dev *sensor) in ov5640_formats() argument
489 return ov5640_is_csi2(sensor) ? ov5640_csi2_formats in ov5640_formats()
494 ov5640_code_to_pixfmt(struct ov5640_dev *sensor, u32 code) in ov5640_code_to_pixfmt() argument
496 const struct ov5640_pixfmt *formats = ov5640_formats(sensor); in ov5640_code_to_pixfmt()
507 static u32 ov5640_code_to_bpp(struct ov5640_dev *sensor, u32 code) in ov5640_code_to_bpp() argument
509 const struct ov5640_pixfmt *format = ov5640_code_to_pixfmt(sensor, in ov5640_code_to_bpp()
1141 ov5640_timings(const struct ov5640_dev *sensor, in ov5640_timings() argument
1144 if (ov5640_is_csi2(sensor)) in ov5640_timings()
1150 static int ov5640_init_slave_id(struct ov5640_dev *sensor) in ov5640_init_slave_id() argument
1152 struct i2c_client *client = sensor->i2c_client; in ov5640_init_slave_id()
1178 static int ov5640_write_reg(struct ov5640_dev *sensor, u16 reg, u8 val) in ov5640_write_reg() argument
1180 struct i2c_client *client = sensor->i2c_client; in ov5640_write_reg()
1204 static int ov5640_read_reg(struct ov5640_dev *sensor, u16 reg, u8 *val) in ov5640_read_reg() argument
1206 struct i2c_client *client = sensor->i2c_client; in ov5640_read_reg()
1235 static int ov5640_read_reg16(struct ov5640_dev *sensor, u16 reg, u16 *val) in ov5640_read_reg16() argument
1240 ret = ov5640_read_reg(sensor, reg, &hi); in ov5640_read_reg16()
1243 ret = ov5640_read_reg(sensor, reg + 1, &lo); in ov5640_read_reg16()
1251 static int ov5640_write_reg16(struct ov5640_dev *sensor, u16 reg, u16 val) in ov5640_write_reg16() argument
1255 ret = ov5640_write_reg(sensor, reg, val >> 8); in ov5640_write_reg16()
1259 return ov5640_write_reg(sensor, reg + 1, val & 0xff); in ov5640_write_reg16()
1262 static int ov5640_mod_reg(struct ov5640_dev *sensor, u16 reg, in ov5640_mod_reg() argument
1268 ret = ov5640_read_reg(sensor, reg, &readval); in ov5640_mod_reg()
1276 return ov5640_write_reg(sensor, reg, val); in ov5640_mod_reg()
1376 static unsigned long ov5640_compute_sys_clk(struct ov5640_dev *sensor, in ov5640_compute_sys_clk() argument
1380 unsigned long sysclk = sensor->xclk_freq / pll_prediv * pll_mult; in ov5640_compute_sys_clk()
1389 static unsigned long ov5640_calc_sys_clk(struct ov5640_dev *sensor, in ov5640_calc_sys_clk() argument
1413 _rate = ov5640_compute_sys_clk(sensor, in ov5640_calc_sys_clk()
1454 static int ov5640_set_mipi_pclk(struct ov5640_dev *sensor) in ov5640_set_mipi_pclk() argument
1466 link_freq = sensor->current_link_freq; in ov5640_set_mipi_pclk()
1480 ov5640_calc_sys_clk(sensor, sysclk, &prediv, &mult, &sysdiv); in ov5640_set_mipi_pclk()
1519 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_set_mipi_pclk()
1524 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, 0x0f, bit_div); in ov5640_set_mipi_pclk()
1528 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, 0xff, in ov5640_set_mipi_pclk()
1533 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, 0xff, mult); in ov5640_set_mipi_pclk()
1537 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, 0x1f, in ov5640_set_mipi_pclk()
1542 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, in ov5640_set_mipi_pclk()
1547 return ov5640_write_reg(sensor, OV5640_REG_PCLK_PERIOD, pclk_period); in ov5640_set_mipi_pclk()
1550 static u32 ov5640_calc_pixel_rate(struct ov5640_dev *sensor) in ov5640_calc_pixel_rate() argument
1552 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_calc_pixel_rate()
1557 rate *= ov5640_framerates[sensor->current_fr]; in ov5640_calc_pixel_rate()
1562 static unsigned long ov5640_calc_pclk(struct ov5640_dev *sensor, in ov5640_calc_pclk() argument
1570 _rate = ov5640_calc_sys_clk(sensor, _rate, pll_prediv, pll_mult, in ov5640_calc_pclk()
1579 static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor) in ov5640_set_dvp_pclk() argument
1585 rate = ov5640_calc_pixel_rate(sensor); in ov5640_set_dvp_pclk()
1586 rate *= ov5640_code_to_bpp(sensor, sensor->fmt.code); in ov5640_set_dvp_pclk()
1587 rate /= sensor->ep.bus.parallel.bus_width; in ov5640_set_dvp_pclk()
1589 ov5640_calc_pclk(sensor, rate, &prediv, &mult, &sysdiv, &pll_rdiv, in ov5640_set_dvp_pclk()
1595 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, in ov5640_set_dvp_pclk()
1604 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, in ov5640_set_dvp_pclk()
1609 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, in ov5640_set_dvp_pclk()
1614 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, in ov5640_set_dvp_pclk()
1619 return ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x30, in ov5640_set_dvp_pclk()
1624 static int ov5640_set_jpeg_timings(struct ov5640_dev *sensor, in ov5640_set_jpeg_timings() argument
1636 ret = ov5640_mod_reg(sensor, OV5640_REG_JPG_MODE_SELECT, 0x7, 0x3); in ov5640_set_jpeg_timings()
1640 ret = ov5640_write_reg16(sensor, OV5640_REG_VFIFO_HSIZE, mode->width); in ov5640_set_jpeg_timings()
1644 return ov5640_write_reg16(sensor, OV5640_REG_VFIFO_VSIZE, mode->height); in ov5640_set_jpeg_timings()
1647 /* download ov5640 settings to sensor through i2c */
1648 static int ov5640_set_timings(struct ov5640_dev *sensor, in ov5640_set_timings() argument
1656 if (sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8) { in ov5640_set_timings()
1657 ret = ov5640_set_jpeg_timings(sensor, mode); in ov5640_set_timings()
1662 timings = ov5640_timings(sensor, mode); in ov5640_set_timings()
1666 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HS, in ov5640_set_timings()
1671 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VS, in ov5640_set_timings()
1676 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HW, in ov5640_set_timings()
1681 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VH, in ov5640_set_timings()
1686 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HOFFS, crop->left); in ov5640_set_timings()
1690 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VOFFS, crop->top); in ov5640_set_timings()
1694 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->width); in ov5640_set_timings()
1698 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPVO, mode->height); in ov5640_set_timings()
1702 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HTS, timings->htot); in ov5640_set_timings()
1706 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, in ov5640_set_timings()
1714 static void ov5640_load_regs(struct ov5640_dev *sensor, in ov5640_load_regs() argument
1732 !ov5640_is_csi2(sensor)) in ov5640_load_regs()
1736 ret = ov5640_mod_reg(sensor, reg_addr, mask, val); in ov5640_load_regs()
1738 ret = ov5640_write_reg(sensor, reg_addr, val); in ov5640_load_regs()
1747 static int ov5640_set_autoexposure(struct ov5640_dev *sensor, bool on) in ov5640_set_autoexposure() argument
1749 return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, in ov5640_set_autoexposure()
1754 static int ov5640_get_exposure(struct ov5640_dev *sensor) in ov5640_get_exposure() argument
1759 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_HI, &temp); in ov5640_get_exposure()
1763 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_MED, &temp); in ov5640_get_exposure()
1767 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_LO, &temp); in ov5640_get_exposure()
1776 static int ov5640_set_exposure(struct ov5640_dev *sensor, u32 exposure) in ov5640_set_exposure() argument
1782 ret = ov5640_write_reg(sensor, in ov5640_set_exposure()
1787 ret = ov5640_write_reg(sensor, in ov5640_set_exposure()
1792 return ov5640_write_reg(sensor, in ov5640_set_exposure()
1797 static int ov5640_get_gain(struct ov5640_dev *sensor) in ov5640_get_gain() argument
1802 ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, &gain); in ov5640_get_gain()
1809 static int ov5640_set_gain(struct ov5640_dev *sensor, int gain) in ov5640_set_gain() argument
1811 return ov5640_write_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, in ov5640_set_gain()
1815 static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) in ov5640_set_autogain() argument
1817 return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, in ov5640_set_autogain()
1821 static int ov5640_set_stream_dvp(struct ov5640_dev *sensor, bool on) in ov5640_set_stream_dvp() argument
1823 return ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ? in ov5640_set_stream_dvp()
1828 static int ov5640_set_stream_mipi(struct ov5640_dev *sensor, bool on) in ov5640_set_stream_mipi() argument
1837 * FIXME: the sensor manual (version 2.03) reports in ov5640_set_stream_mipi()
1849 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, in ov5640_set_stream_mipi()
1854 return ov5640_write_reg(sensor, OV5640_REG_FRAME_CTRL01, in ov5640_set_stream_mipi()
1858 static int ov5640_get_sysclk(struct ov5640_dev *sensor) in ov5640_get_sysclk() argument
1861 u32 xvclk = sensor->xclk_freq / 10000; in ov5640_get_sysclk()
1868 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL0, &temp1); in ov5640_get_sysclk()
1875 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL1, &temp1); in ov5640_get_sysclk()
1882 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL2, &temp1); in ov5640_get_sysclk()
1887 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL3, &temp1); in ov5640_get_sysclk()
1893 ret = ov5640_read_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, &temp1); in ov5640_get_sysclk()
1909 static int ov5640_set_night_mode(struct ov5640_dev *sensor) in ov5640_set_night_mode() argument
1915 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_CTRL00, &mode); in ov5640_set_night_mode()
1919 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL00, mode); in ov5640_set_night_mode()
1922 static int ov5640_get_hts(struct ov5640_dev *sensor) in ov5640_get_hts() argument
1928 ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_HTS, &hts); in ov5640_get_hts()
1934 static int ov5640_get_vts(struct ov5640_dev *sensor) in ov5640_get_vts() argument
1939 ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_VTS, &vts); in ov5640_get_vts()
1945 static int ov5640_set_vts(struct ov5640_dev *sensor, int vts) in ov5640_set_vts() argument
1947 return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, vts); in ov5640_set_vts()
1950 static int ov5640_get_light_freq(struct ov5640_dev *sensor) in ov5640_get_light_freq() argument
1956 ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL01, &temp); in ov5640_get_light_freq()
1962 ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL00, in ov5640_get_light_freq()
1975 ret = ov5640_read_reg(sensor, OV5640_REG_SIGMADELTA_CTRL0C, in ov5640_get_light_freq()
1991 static int ov5640_set_bandingfilter(struct ov5640_dev *sensor) in ov5640_set_bandingfilter() argument
1997 ret = ov5640_get_sysclk(sensor); in ov5640_set_bandingfilter()
2002 sensor->prev_sysclk = ret; in ov5640_set_bandingfilter()
2004 ret = ov5640_get_hts(sensor); in ov5640_set_bandingfilter()
2009 sensor->prev_hts = ret; in ov5640_set_bandingfilter()
2012 ret = ov5640_get_vts(sensor); in ov5640_set_bandingfilter()
2019 band_step60 = sensor->prev_sysclk * 100 / sensor->prev_hts * 100 / 120; in ov5640_set_bandingfilter()
2020 ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B60_STEP, band_step60); in ov5640_set_bandingfilter()
2026 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0D, max_band60); in ov5640_set_bandingfilter()
2031 band_step50 = sensor->prev_sysclk * 100 / sensor->prev_hts; in ov5640_set_bandingfilter()
2032 ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B50_STEP, band_step50); in ov5640_set_bandingfilter()
2038 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0E, max_band50); in ov5640_set_bandingfilter()
2041 static int ov5640_set_ae_target(struct ov5640_dev *sensor, int target) in ov5640_set_ae_target() argument
2047 sensor->ae_low = target * 23 / 25; /* 0.92 */ in ov5640_set_ae_target()
2048 sensor->ae_high = target * 27 / 25; /* 1.08 */ in ov5640_set_ae_target()
2050 fast_high = sensor->ae_high << 1; in ov5640_set_ae_target()
2054 fast_low = sensor->ae_low >> 1; in ov5640_set_ae_target()
2056 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0F, sensor->ae_high); in ov5640_set_ae_target()
2059 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL10, sensor->ae_low); in ov5640_set_ae_target()
2062 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1B, sensor->ae_high); in ov5640_set_ae_target()
2065 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1E, sensor->ae_low); in ov5640_set_ae_target()
2068 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL11, fast_high); in ov5640_set_ae_target()
2071 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1F, fast_low); in ov5640_set_ae_target()
2074 static int ov5640_get_binning(struct ov5640_dev *sensor) in ov5640_get_binning() argument
2079 ret = ov5640_read_reg(sensor, OV5640_REG_TIMING_TC_REG21, &temp); in ov5640_get_binning()
2086 static int ov5640_set_binning(struct ov5640_dev *sensor, bool enable) in ov5640_set_binning() argument
2094 ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_binning()
2103 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, in ov5640_set_binning()
2107 static int ov5640_set_virtual_channel(struct ov5640_dev *sensor) in ov5640_set_virtual_channel() argument
2109 struct i2c_client *client = sensor->i2c_client; in ov5640_set_virtual_channel()
2120 ret = ov5640_read_reg(sensor, OV5640_REG_DEBUG_MODE, &temp); in ov5640_set_virtual_channel()
2125 return ov5640_write_reg(sensor, OV5640_REG_DEBUG_MODE, temp); in ov5640_set_virtual_channel()
2129 ov5640_find_mode(struct ov5640_dev *sensor, int width, int height, bool nearest) in ov5640_find_mode() argument
2146 * sensor changes between scaling and subsampling, go through
2149 static int ov5640_set_mode_exposure_calc(struct ov5640_dev *sensor, in ov5640_set_mode_exposure_calc() argument
2164 ret = ov5640_get_exposure(sensor); in ov5640_set_mode_exposure_calc()
2168 ret = ov5640_get_binning(sensor); in ov5640_set_mode_exposure_calc()
2176 ret = ov5640_get_gain(sensor); in ov5640_set_mode_exposure_calc()
2182 ret = ov5640_read_reg(sensor, OV5640_REG_AVG_READOUT, &average); in ov5640_set_mode_exposure_calc()
2187 ret = ov5640_set_night_mode(sensor); in ov5640_set_mode_exposure_calc()
2192 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_exposure_calc()
2193 ret = ov5640_set_timings(sensor, mode); in ov5640_set_mode_exposure_calc()
2198 ret = ov5640_get_vts(sensor); in ov5640_set_mode_exposure_calc()
2202 ret = ov5640_get_hts(sensor); in ov5640_set_mode_exposure_calc()
2209 ret = ov5640_get_sysclk(sensor); in ov5640_set_mode_exposure_calc()
2217 ret = ov5640_get_light_freq(sensor); in ov5640_set_mode_exposure_calc()
2230 if (!sensor->prev_sysclk) { in ov5640_set_mode_exposure_calc()
2231 ret = ov5640_get_sysclk(sensor); in ov5640_set_mode_exposure_calc()
2236 sensor->prev_sysclk = ret; in ov5640_set_mode_exposure_calc()
2245 if (average > sensor->ae_low && average < sensor->ae_high) { in ov5640_set_mode_exposure_calc()
2249 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2250 sensor->prev_hts / cap_hts * in ov5640_set_mode_exposure_calc()
2251 sensor->ae_target / average; in ov5640_set_mode_exposure_calc()
2255 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2256 sensor->prev_hts / cap_hts; in ov5640_set_mode_exposure_calc()
2290 ret = ov5640_set_gain(sensor, cap_gain16); in ov5640_set_mode_exposure_calc()
2297 ret = ov5640_set_vts(sensor, cap_vts); in ov5640_set_mode_exposure_calc()
2303 return ov5640_set_exposure(sensor, cap_shutter); in ov5640_set_mode_exposure_calc()
2307 * if sensor changes inside scaling or subsampling
2310 static int ov5640_set_mode_direct(struct ov5640_dev *sensor, in ov5640_set_mode_direct() argument
2317 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_direct()
2318 return ov5640_set_timings(sensor, mode); in ov5640_set_mode_direct()
2321 static int ov5640_set_mode(struct ov5640_dev *sensor) in ov5640_set_mode() argument
2323 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_mode()
2324 const struct ov5640_mode_info *orig_mode = sensor->last_mode; in ov5640_set_mode()
2326 bool auto_gain = sensor->ctrls.auto_gain->val == 1; in ov5640_set_mode()
2327 bool auto_exp = sensor->ctrls.auto_exp->val == V4L2_EXPOSURE_AUTO; in ov5640_set_mode()
2335 ret = ov5640_set_autogain(sensor, false); in ov5640_set_mode()
2341 ret = ov5640_set_autoexposure(sensor, false); in ov5640_set_mode()
2346 if (ov5640_is_csi2(sensor)) in ov5640_set_mode()
2347 ret = ov5640_set_mipi_pclk(sensor); in ov5640_set_mode()
2349 ret = ov5640_set_dvp_pclk(sensor); in ov5640_set_mode()
2359 ret = ov5640_set_mode_exposure_calc(sensor, mode); in ov5640_set_mode()
2365 ret = ov5640_set_mode_direct(sensor, mode); in ov5640_set_mode()
2372 ov5640_set_autogain(sensor, true); in ov5640_set_mode()
2374 ov5640_set_autoexposure(sensor, true); in ov5640_set_mode()
2376 ret = ov5640_set_binning(sensor, dn_mode != SCALING); in ov5640_set_mode()
2379 ret = ov5640_set_ae_target(sensor, sensor->ae_target); in ov5640_set_mode()
2382 ret = ov5640_get_light_freq(sensor); in ov5640_set_mode()
2385 ret = ov5640_set_bandingfilter(sensor); in ov5640_set_mode()
2388 ret = ov5640_set_virtual_channel(sensor); in ov5640_set_mode()
2392 sensor->pending_mode_change = false; in ov5640_set_mode()
2393 sensor->last_mode = mode; in ov5640_set_mode()
2399 ov5640_set_autoexposure(sensor, true); in ov5640_set_mode()
2402 ov5640_set_autogain(sensor, true); in ov5640_set_mode()
2407 static int ov5640_set_framefmt(struct ov5640_dev *sensor,
2411 static int ov5640_restore_mode(struct ov5640_dev *sensor) in ov5640_restore_mode() argument
2416 ov5640_load_regs(sensor, ov5640_init_setting, in ov5640_restore_mode()
2419 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, in ov5640_restore_mode()
2426 ret = ov5640_set_mode(sensor); in ov5640_restore_mode()
2430 return ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_restore_mode()
2433 static void ov5640_power(struct ov5640_dev *sensor, bool enable) in ov5640_power() argument
2435 gpiod_set_value_cansleep(sensor->pwdn_gpio, enable ? 0 : 1); in ov5640_power()
2452 static void ov5640_powerup_sequence(struct ov5640_dev *sensor) in ov5640_powerup_sequence() argument
2454 if (sensor->pwdn_gpio) { in ov5640_powerup_sequence()
2455 gpiod_set_value_cansleep(sensor->reset_gpio, 1); in ov5640_powerup_sequence()
2458 ov5640_power(sensor, false); in ov5640_powerup_sequence()
2460 ov5640_power(sensor, true); in ov5640_powerup_sequence()
2463 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in ov5640_powerup_sequence()
2466 ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, in ov5640_powerup_sequence()
2475 ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, in ov5640_powerup_sequence()
2479 static int ov5640_set_power_on(struct ov5640_dev *sensor) in ov5640_set_power_on() argument
2481 struct i2c_client *client = sensor->i2c_client; in ov5640_set_power_on()
2484 ret = clk_prepare_enable(sensor->xclk); in ov5640_set_power_on()
2492 sensor->supplies); in ov5640_set_power_on()
2499 ov5640_powerup_sequence(sensor); in ov5640_set_power_on()
2501 ret = ov5640_init_slave_id(sensor); in ov5640_set_power_on()
2508 ov5640_power(sensor, false); in ov5640_set_power_on()
2509 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_on()
2511 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_on()
2515 static void ov5640_set_power_off(struct ov5640_dev *sensor) in ov5640_set_power_off() argument
2517 ov5640_power(sensor, false); in ov5640_set_power_off()
2518 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_off()
2519 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_off()
2522 static int ov5640_set_power_mipi(struct ov5640_dev *sensor, bool on) in ov5640_set_power_mipi() argument
2528 ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); in ov5640_set_power_mipi()
2529 ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x04); in ov5640_set_power_mipi()
2530 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x00); in ov5640_set_power_mipi()
2544 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x44); in ov5640_set_power_mipi()
2555 ret = ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x24); in ov5640_set_power_mipi()
2567 ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x70); in ov5640_set_power_mipi()
2577 static int ov5640_set_power_dvp(struct ov5640_dev *sensor, bool on) in ov5640_set_power_dvp() argument
2579 unsigned int flags = sensor->ep.bus.parallel.flags; in ov5640_set_power_dvp()
2580 bool bt656 = sensor->ep.bus_type == V4L2_MBUS_BT656; in ov5640_set_power_dvp()
2586 ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, 0x00); in ov5640_set_power_dvp()
2587 ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); in ov5640_set_power_dvp()
2588 ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, 0x20); in ov5640_set_power_dvp()
2589 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, 0x00); in ov5640_set_power_dvp()
2590 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0x00); in ov5640_set_power_dvp()
2634 ret = ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, in ov5640_set_power_dvp()
2658 ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, polarities); in ov5640_set_power_dvp()
2670 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x18); in ov5640_set_power_dvp()
2684 ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, in ov5640_set_power_dvp()
2695 return ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0xfc); in ov5640_set_power_dvp()
2698 static int ov5640_set_power(struct ov5640_dev *sensor, bool on) in ov5640_set_power() argument
2703 ret = ov5640_set_power_on(sensor); in ov5640_set_power()
2707 ret = ov5640_restore_mode(sensor); in ov5640_set_power()
2712 if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) in ov5640_set_power()
2713 ret = ov5640_set_power_mipi(sensor, on); in ov5640_set_power()
2715 ret = ov5640_set_power_dvp(sensor, on); in ov5640_set_power()
2720 ov5640_set_power_off(sensor); in ov5640_set_power()
2725 ov5640_set_power_off(sensor); in ov5640_set_power()
2747 static int ov5640_try_frame_interval(struct ov5640_dev *sensor, in ov5640_try_frame_interval() argument
2783 mode = ov5640_find_mode(sensor, mode->width, mode->height, false); in ov5640_try_frame_interval()
2791 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_get_fmt() local
2797 mutex_lock(&sensor->lock); in ov5640_get_fmt()
2802 fmt = &sensor->fmt; in ov5640_get_fmt()
2806 mutex_unlock(&sensor->lock); in ov5640_get_fmt()
2815 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_try_fmt_internal() local
2820 mode = ov5640_find_mode(sensor, fmt->width, fmt->height, true); in ov5640_try_fmt_internal()
2824 pixfmt = ov5640_code_to_pixfmt(sensor, fmt->code); in ov5640_try_fmt_internal()
2852 static void __v4l2_ctrl_vblank_update(struct ov5640_dev *sensor, u32 vblank) in __v4l2_ctrl_vblank_update() argument
2854 const struct ov5640_mode_info *mode = sensor->current_mode; in __v4l2_ctrl_vblank_update()
2856 __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV5640_MIN_VBLANK, in __v4l2_ctrl_vblank_update()
2859 __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, vblank); in __v4l2_ctrl_vblank_update()
2862 static int ov5640_update_pixel_rate(struct ov5640_dev *sensor) in ov5640_update_pixel_rate() argument
2864 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_update_pixel_rate()
2866 struct v4l2_mbus_framefmt *fmt = &sensor->fmt; in ov5640_update_pixel_rate()
2867 const struct ov5640_timings *timings = ov5640_timings(sensor, mode); in ov5640_update_pixel_rate()
2882 if (!ov5640_is_csi2(sensor)) { in ov5640_update_pixel_rate()
2883 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, in ov5640_update_pixel_rate()
2884 ov5640_calc_pixel_rate(sensor)); in ov5640_update_pixel_rate()
2886 __v4l2_ctrl_vblank_update(sensor, timings->vblank_def); in ov5640_update_pixel_rate()
2898 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_update_pixel_rate()
2899 bpp = ov5640_code_to_bpp(sensor, fmt->code); in ov5640_update_pixel_rate()
2906 sensor->current_link_freq = link_freq; in ov5640_update_pixel_rate()
2927 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, pixel_rate); in ov5640_update_pixel_rate()
2928 __v4l2_ctrl_s_ctrl(sensor->ctrls.link_freq, i); in ov5640_update_pixel_rate()
2931 __v4l2_ctrl_modify_range(sensor->ctrls.hblank, in ov5640_update_pixel_rate()
2935 __v4l2_ctrl_vblank_update(sensor, vblank); in ov5640_update_pixel_rate()
2938 exposure_val = clamp_t(s32, sensor->ctrls.exposure->val, in ov5640_update_pixel_rate()
2939 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2942 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_update_pixel_rate()
2943 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2953 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_set_fmt() local
2961 mutex_lock(&sensor->lock); in ov5640_set_fmt()
2963 if (sensor->streaming) { in ov5640_set_fmt()
2977 if (new_mode != sensor->current_mode) { in ov5640_set_fmt()
2978 sensor->current_fr = new_mode->def_fps; in ov5640_set_fmt()
2979 sensor->current_mode = new_mode; in ov5640_set_fmt()
2980 sensor->pending_mode_change = true; in ov5640_set_fmt()
2982 if (mbus_fmt->code != sensor->fmt.code) in ov5640_set_fmt()
2983 sensor->pending_fmt_change = true; in ov5640_set_fmt()
2986 sensor->fmt = *mbus_fmt; in ov5640_set_fmt()
2988 ov5640_update_pixel_rate(sensor); in ov5640_set_fmt()
2991 mutex_unlock(&sensor->lock); in ov5640_set_fmt()
2999 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_get_selection() local
3000 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_get_selection()
3005 mutex_lock(&sensor->lock); in ov5640_get_selection()
3006 timings = ov5640_timings(sensor, mode); in ov5640_get_selection()
3008 mutex_unlock(&sensor->lock); in ov5640_get_selection()
3034 static int ov5640_set_framefmt(struct ov5640_dev *sensor, in ov5640_set_framefmt() argument
3041 pixfmt = ov5640_code_to_pixfmt(sensor, format->code); in ov5640_set_framefmt()
3044 ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, in ov5640_set_framefmt()
3050 ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, in ov5640_set_framefmt()
3059 ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_framefmt()
3070 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_RESET02, in ov5640_set_framefmt()
3081 return ov5640_mod_reg(sensor, OV5640_REG_SYS_CLOCK_ENABLE02, in ov5640_set_framefmt()
3087 * Sensor Controls.
3090 static int ov5640_set_ctrl_hue(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_hue() argument
3095 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_hue()
3099 ret = ov5640_write_reg16(sensor, OV5640_REG_SDE_CTRL1, value); in ov5640_set_ctrl_hue()
3101 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(0), 0); in ov5640_set_ctrl_hue()
3107 static int ov5640_set_ctrl_contrast(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_contrast() argument
3112 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_contrast()
3116 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL5, in ov5640_set_ctrl_contrast()
3119 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(2), 0); in ov5640_set_ctrl_contrast()
3125 static int ov5640_set_ctrl_saturation(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_saturation() argument
3130 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_saturation()
3134 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL3, in ov5640_set_ctrl_saturation()
3138 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL4, in ov5640_set_ctrl_saturation()
3141 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(1), 0); in ov5640_set_ctrl_saturation()
3147 static int ov5640_set_ctrl_white_balance(struct ov5640_dev *sensor, int awb) in ov5640_set_ctrl_white_balance() argument
3151 ret = ov5640_mod_reg(sensor, OV5640_REG_AWB_MANUAL_CTRL, in ov5640_set_ctrl_white_balance()
3157 u16 red = (u16)sensor->ctrls.red_balance->val; in ov5640_set_ctrl_white_balance()
3158 u16 blue = (u16)sensor->ctrls.blue_balance->val; in ov5640_set_ctrl_white_balance()
3160 ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_R_GAIN, red); in ov5640_set_ctrl_white_balance()
3163 ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_B_GAIN, blue); in ov5640_set_ctrl_white_balance()
3169 static int ov5640_set_ctrl_exposure(struct ov5640_dev *sensor, in ov5640_set_ctrl_exposure() argument
3172 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_exposure()
3177 ret = ov5640_set_autoexposure(sensor, auto_exp); in ov5640_set_ctrl_exposure()
3185 ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_VTS, in ov5640_set_ctrl_exposure()
3189 ret = ov5640_get_vts(sensor); in ov5640_set_ctrl_exposure()
3196 ret = ov5640_set_exposure(sensor, ctrls->exposure->val); in ov5640_set_ctrl_exposure()
3202 static int ov5640_set_ctrl_gain(struct ov5640_dev *sensor, bool auto_gain) in ov5640_set_ctrl_gain() argument
3204 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_gain()
3208 ret = ov5640_set_autogain(sensor, auto_gain); in ov5640_set_ctrl_gain()
3214 ret = ov5640_set_gain(sensor, ctrls->gain->val); in ov5640_set_ctrl_gain()
3250 static int ov5640_set_ctrl_test_pattern(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_test_pattern() argument
3252 return ov5640_write_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, in ov5640_set_ctrl_test_pattern()
3256 static int ov5640_set_ctrl_light_freq(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_light_freq() argument
3260 ret = ov5640_mod_reg(sensor, OV5640_REG_HZ5060_CTRL01, BIT(7), in ov5640_set_ctrl_light_freq()
3266 return ov5640_mod_reg(sensor, OV5640_REG_HZ5060_CTRL00, BIT(2), in ov5640_set_ctrl_light_freq()
3271 static int ov5640_set_ctrl_hflip(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_hflip() argument
3274 * If sensor is mounted upside down, mirror logic is inversed. in ov5640_set_ctrl_hflip()
3276 * Sensor is a BSI (Back Side Illuminated) one, in ov5640_set_ctrl_hflip()
3285 * - [1]: Sensor mirror in ov5640_set_ctrl_hflip()
3287 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_ctrl_hflip()
3289 (!(value ^ sensor->upside_down)) ? in ov5640_set_ctrl_hflip()
3293 static int ov5640_set_ctrl_vflip(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_vflip() argument
3295 /* If sensor is mounted upside down, flip logic is inversed */ in ov5640_set_ctrl_vflip()
3300 * - [1]: Sensor vflip in ov5640_set_ctrl_vflip()
3302 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, in ov5640_set_ctrl_vflip()
3304 (value ^ sensor->upside_down) ? in ov5640_set_ctrl_vflip()
3308 static int ov5640_set_ctrl_vblank(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_vblank() argument
3310 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_ctrl_vblank()
3313 return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, in ov5640_set_ctrl_vblank()
3320 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_g_volatile_ctrl() local
3325 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_g_volatile_ctrl()
3330 val = ov5640_get_gain(sensor); in ov5640_g_volatile_ctrl()
3333 sensor->ctrls.gain->val = val; in ov5640_g_volatile_ctrl()
3336 val = ov5640_get_exposure(sensor); in ov5640_g_volatile_ctrl()
3339 sensor->ctrls.exposure->val = val; in ov5640_g_volatile_ctrl()
3343 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_g_volatile_ctrl()
3344 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_g_volatile_ctrl()
3352 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_s_ctrl() local
3353 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_s_ctrl()
3363 timings = ov5640_timings(sensor, mode); in ov5640_s_ctrl()
3365 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_s_ctrl()
3366 sensor->ctrls.exposure->minimum, in ov5640_s_ctrl()
3367 exp_max, sensor->ctrls.exposure->step, in ov5640_s_ctrl()
3377 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_s_ctrl()
3382 ret = ov5640_set_ctrl_gain(sensor, ctrl->val); in ov5640_s_ctrl()
3385 ret = ov5640_set_ctrl_exposure(sensor, ctrl->val); in ov5640_s_ctrl()
3388 ret = ov5640_set_ctrl_white_balance(sensor, ctrl->val); in ov5640_s_ctrl()
3391 ret = ov5640_set_ctrl_hue(sensor, ctrl->val); in ov5640_s_ctrl()
3394 ret = ov5640_set_ctrl_contrast(sensor, ctrl->val); in ov5640_s_ctrl()
3397 ret = ov5640_set_ctrl_saturation(sensor, ctrl->val); in ov5640_s_ctrl()
3400 ret = ov5640_set_ctrl_test_pattern(sensor, ctrl->val); in ov5640_s_ctrl()
3403 ret = ov5640_set_ctrl_light_freq(sensor, ctrl->val); in ov5640_s_ctrl()
3406 ret = ov5640_set_ctrl_hflip(sensor, ctrl->val); in ov5640_s_ctrl()
3409 ret = ov5640_set_ctrl_vflip(sensor, ctrl->val); in ov5640_s_ctrl()
3412 ret = ov5640_set_ctrl_vblank(sensor, ctrl->val); in ov5640_s_ctrl()
3419 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_s_ctrl()
3420 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_ctrl()
3430 static int ov5640_init_controls(struct ov5640_dev *sensor) in ov5640_init_controls() argument
3432 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_init_controls()
3434 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_init_controls()
3445 hdl->lock = &sensor->lock; in ov5640_init_controls()
3459 timings = ov5640_timings(sensor, mode); in ov5640_init_controls()
3516 ret = v4l2_fwnode_device_parse(&sensor->i2c_client->dev, &props); in ov5640_init_controls()
3521 sensor->upside_down = true; in ov5640_init_controls()
3537 sensor->sd.ctrl_handler = hdl; in ov5640_init_controls()
3549 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_frame_size() local
3550 u32 bpp = ov5640_code_to_bpp(sensor, fse->code); in ov5640_enum_frame_size()
3582 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_frame_interval() local
3592 mode = ov5640_find_mode(sensor, fie->width, fie->height, false); in ov5640_enum_frame_interval()
3599 ret = ov5640_try_frame_interval(sensor, &tpf, mode); in ov5640_enum_frame_interval()
3611 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_get_frame_interval() local
3620 mutex_lock(&sensor->lock); in ov5640_get_frame_interval()
3621 fi->interval = sensor->frame_interval; in ov5640_get_frame_interval()
3622 mutex_unlock(&sensor->lock); in ov5640_get_frame_interval()
3631 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_set_frame_interval() local
3645 mutex_lock(&sensor->lock); in ov5640_set_frame_interval()
3647 if (sensor->streaming) { in ov5640_set_frame_interval()
3652 mode = sensor->current_mode; in ov5640_set_frame_interval()
3654 frame_rate = ov5640_try_frame_interval(sensor, &fi->interval, mode); in ov5640_set_frame_interval()
3657 fi->interval = sensor->frame_interval; in ov5640_set_frame_interval()
3661 mode = ov5640_find_mode(sensor, mode->width, mode->height, true); in ov5640_set_frame_interval()
3672 if (mode != sensor->current_mode || in ov5640_set_frame_interval()
3673 frame_rate != sensor->current_fr) { in ov5640_set_frame_interval()
3674 sensor->current_fr = frame_rate; in ov5640_set_frame_interval()
3675 sensor->frame_interval = fi->interval; in ov5640_set_frame_interval()
3676 sensor->current_mode = mode; in ov5640_set_frame_interval()
3677 sensor->pending_mode_change = true; in ov5640_set_frame_interval()
3679 ov5640_update_pixel_rate(sensor); in ov5640_set_frame_interval()
3682 mutex_unlock(&sensor->lock); in ov5640_set_frame_interval()
3690 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_mbus_code() local
3694 if (ov5640_is_csi2(sensor)) { in ov5640_enum_mbus_code()
3712 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_s_stream() local
3716 ret = pm_runtime_resume_and_get(&sensor->i2c_client->dev); in ov5640_s_stream()
3720 ret = v4l2_ctrl_handler_setup(&sensor->ctrls.handler); in ov5640_s_stream()
3722 pm_runtime_put(&sensor->i2c_client->dev); in ov5640_s_stream()
3727 mutex_lock(&sensor->lock); in ov5640_s_stream()
3729 if (sensor->streaming == !enable) { in ov5640_s_stream()
3730 if (enable && sensor->pending_mode_change) { in ov5640_s_stream()
3731 ret = ov5640_set_mode(sensor); in ov5640_s_stream()
3736 if (enable && sensor->pending_fmt_change) { in ov5640_s_stream()
3737 ret = ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_s_stream()
3740 sensor->pending_fmt_change = false; in ov5640_s_stream()
3743 if (ov5640_is_csi2(sensor)) in ov5640_s_stream()
3744 ret = ov5640_set_stream_mipi(sensor, enable); in ov5640_s_stream()
3746 ret = ov5640_set_stream_dvp(sensor, enable); in ov5640_s_stream()
3749 sensor->streaming = enable; in ov5640_s_stream()
3753 mutex_unlock(&sensor->lock); in ov5640_s_stream()
3756 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_s_stream()
3757 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_stream()
3766 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_init_state() local
3771 *fmt = ov5640_is_csi2(sensor) ? ov5640_csi2_default_fmt : in ov5640_init_state()
3813 static int ov5640_get_regulators(struct ov5640_dev *sensor) in ov5640_get_regulators() argument
3818 sensor->supplies[i].supply = ov5640_supply_name[i]; in ov5640_get_regulators()
3820 return devm_regulator_bulk_get(&sensor->i2c_client->dev, in ov5640_get_regulators()
3822 sensor->supplies); in ov5640_get_regulators()
3825 static int ov5640_check_chip_id(struct ov5640_dev *sensor) in ov5640_check_chip_id() argument
3827 struct i2c_client *client = sensor->i2c_client; in ov5640_check_chip_id()
3831 ret = ov5640_read_reg16(sensor, OV5640_REG_CHIP_ID, &chip_id); in ov5640_check_chip_id()
3851 struct ov5640_dev *sensor; in ov5640_probe() local
3854 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); in ov5640_probe()
3855 if (!sensor) in ov5640_probe()
3858 sensor->i2c_client = client; in ov5640_probe()
3861 * default init sequence initialize sensor to in ov5640_probe()
3864 sensor->frame_interval.numerator = 1; in ov5640_probe()
3865 sensor->frame_interval.denominator = ov5640_framerates[OV5640_30_FPS]; in ov5640_probe()
3866 sensor->current_fr = OV5640_30_FPS; in ov5640_probe()
3867 sensor->current_mode = in ov5640_probe()
3869 sensor->last_mode = sensor->current_mode; in ov5640_probe()
3870 sensor->current_link_freq = in ov5640_probe()
3873 sensor->ae_target = 52; in ov5640_probe()
3882 ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep); in ov5640_probe()
3889 if (sensor->ep.bus_type != V4L2_MBUS_PARALLEL && in ov5640_probe()
3890 sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY && in ov5640_probe()
3891 sensor->ep.bus_type != V4L2_MBUS_BT656) { in ov5640_probe()
3892 dev_err(dev, "Unsupported bus type %d\n", sensor->ep.bus_type); in ov5640_probe()
3896 sensor->fmt = ov5640_is_csi2(sensor) ? ov5640_csi2_default_fmt : in ov5640_probe()
3900 sensor->xclk = devm_clk_get(dev, "xclk"); in ov5640_probe()
3901 if (IS_ERR(sensor->xclk)) { in ov5640_probe()
3903 return PTR_ERR(sensor->xclk); in ov5640_probe()
3906 sensor->xclk_freq = clk_get_rate(sensor->xclk); in ov5640_probe()
3907 if (sensor->xclk_freq < OV5640_XCLK_MIN || in ov5640_probe()
3908 sensor->xclk_freq > OV5640_XCLK_MAX) { in ov5640_probe()
3910 sensor->xclk_freq); in ov5640_probe()
3915 sensor->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown", in ov5640_probe()
3917 if (IS_ERR(sensor->pwdn_gpio)) in ov5640_probe()
3918 return PTR_ERR(sensor->pwdn_gpio); in ov5640_probe()
3921 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov5640_probe()
3923 if (IS_ERR(sensor->reset_gpio)) in ov5640_probe()
3924 return PTR_ERR(sensor->reset_gpio); in ov5640_probe()
3926 v4l2_i2c_subdev_init(&sensor->sd, client, &ov5640_subdev_ops); in ov5640_probe()
3927 sensor->sd.internal_ops = &ov5640_internal_ops; in ov5640_probe()
3929 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov5640_probe()
3931 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5640_probe()
3932 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5640_probe()
3933 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in ov5640_probe()
3937 ret = ov5640_get_regulators(sensor); in ov5640_probe()
3941 mutex_init(&sensor->lock); in ov5640_probe()
3943 ret = ov5640_init_controls(sensor); in ov5640_probe()
3957 ret = ov5640_check_chip_id(sensor); in ov5640_probe()
3961 ret = v4l2_async_register_subdev_sensor(&sensor->sd); in ov5640_probe()
3977 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_probe()
3979 media_entity_cleanup(&sensor->sd.entity); in ov5640_probe()
3980 mutex_destroy(&sensor->lock); in ov5640_probe()
3987 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_remove() local
3995 v4l2_async_unregister_subdev(&sensor->sd); in ov5640_remove()
3996 media_entity_cleanup(&sensor->sd.entity); in ov5640_remove()
3997 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_remove()
3998 mutex_destroy(&sensor->lock); in ov5640_remove()