Lines Matching full:sensor
480 static inline bool ov5640_is_csi2(const struct ov5640_dev *sensor) in ov5640_is_csi2() argument
482 return sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY; in ov5640_is_csi2()
486 ov5640_formats(struct ov5640_dev *sensor) in ov5640_formats() argument
488 return ov5640_is_csi2(sensor) ? ov5640_csi2_formats in ov5640_formats()
493 ov5640_code_to_pixfmt(struct ov5640_dev *sensor, u32 code) in ov5640_code_to_pixfmt() argument
495 const struct ov5640_pixfmt *formats = ov5640_formats(sensor); in ov5640_code_to_pixfmt()
506 static u32 ov5640_code_to_bpp(struct ov5640_dev *sensor, u32 code) in ov5640_code_to_bpp() argument
508 const struct ov5640_pixfmt *format = ov5640_code_to_pixfmt(sensor, in ov5640_code_to_bpp()
1130 ov5640_timings(const struct ov5640_dev *sensor, in ov5640_timings() argument
1133 if (ov5640_is_csi2(sensor)) in ov5640_timings()
1139 static int ov5640_init_slave_id(struct ov5640_dev *sensor) in ov5640_init_slave_id() argument
1141 struct i2c_client *client = sensor->i2c_client; in ov5640_init_slave_id()
1167 static int ov5640_write_reg(struct ov5640_dev *sensor, u16 reg, u8 val) in ov5640_write_reg() argument
1169 struct i2c_client *client = sensor->i2c_client; in ov5640_write_reg()
1193 static int ov5640_read_reg(struct ov5640_dev *sensor, u16 reg, u8 *val) in ov5640_read_reg() argument
1195 struct i2c_client *client = sensor->i2c_client; in ov5640_read_reg()
1224 static int ov5640_read_reg16(struct ov5640_dev *sensor, u16 reg, u16 *val) in ov5640_read_reg16() argument
1229 ret = ov5640_read_reg(sensor, reg, &hi); in ov5640_read_reg16()
1232 ret = ov5640_read_reg(sensor, reg + 1, &lo); in ov5640_read_reg16()
1240 static int ov5640_write_reg16(struct ov5640_dev *sensor, u16 reg, u16 val) in ov5640_write_reg16() argument
1244 ret = ov5640_write_reg(sensor, reg, val >> 8); in ov5640_write_reg16()
1248 return ov5640_write_reg(sensor, reg + 1, val & 0xff); in ov5640_write_reg16()
1251 static int ov5640_mod_reg(struct ov5640_dev *sensor, u16 reg, in ov5640_mod_reg() argument
1257 ret = ov5640_read_reg(sensor, reg, &readval); in ov5640_mod_reg()
1265 return ov5640_write_reg(sensor, reg, val); in ov5640_mod_reg()
1365 static unsigned long ov5640_compute_sys_clk(struct ov5640_dev *sensor, in ov5640_compute_sys_clk() argument
1369 unsigned long sysclk = sensor->xclk_freq / pll_prediv * pll_mult; in ov5640_compute_sys_clk()
1378 static unsigned long ov5640_calc_sys_clk(struct ov5640_dev *sensor, in ov5640_calc_sys_clk() argument
1402 _rate = ov5640_compute_sys_clk(sensor, in ov5640_calc_sys_clk()
1443 static int ov5640_set_mipi_pclk(struct ov5640_dev *sensor) in ov5640_set_mipi_pclk() argument
1455 link_freq = sensor->current_link_freq; in ov5640_set_mipi_pclk()
1469 ov5640_calc_sys_clk(sensor, sysclk, &prediv, &mult, &sysdiv); in ov5640_set_mipi_pclk()
1508 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_set_mipi_pclk()
1513 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, 0x0f, bit_div); in ov5640_set_mipi_pclk()
1517 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, 0xff, in ov5640_set_mipi_pclk()
1522 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, 0xff, mult); in ov5640_set_mipi_pclk()
1526 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, 0x1f, in ov5640_set_mipi_pclk()
1531 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, in ov5640_set_mipi_pclk()
1536 return ov5640_write_reg(sensor, OV5640_REG_PCLK_PERIOD, pclk_period); in ov5640_set_mipi_pclk()
1539 static u32 ov5640_calc_pixel_rate(struct ov5640_dev *sensor) in ov5640_calc_pixel_rate() argument
1541 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_calc_pixel_rate()
1546 rate *= ov5640_framerates[sensor->current_fr]; in ov5640_calc_pixel_rate()
1551 static unsigned long ov5640_calc_pclk(struct ov5640_dev *sensor, in ov5640_calc_pclk() argument
1559 _rate = ov5640_calc_sys_clk(sensor, _rate, pll_prediv, pll_mult, in ov5640_calc_pclk()
1568 static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor) in ov5640_set_dvp_pclk() argument
1574 rate = ov5640_calc_pixel_rate(sensor); in ov5640_set_dvp_pclk()
1575 rate *= ov5640_code_to_bpp(sensor, sensor->fmt.code); in ov5640_set_dvp_pclk()
1576 rate /= sensor->ep.bus.parallel.bus_width; in ov5640_set_dvp_pclk()
1578 ov5640_calc_pclk(sensor, rate, &prediv, &mult, &sysdiv, &pll_rdiv, in ov5640_set_dvp_pclk()
1584 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, in ov5640_set_dvp_pclk()
1593 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, in ov5640_set_dvp_pclk()
1598 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, in ov5640_set_dvp_pclk()
1603 ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, in ov5640_set_dvp_pclk()
1608 return ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x30, in ov5640_set_dvp_pclk()
1613 static int ov5640_set_jpeg_timings(struct ov5640_dev *sensor, in ov5640_set_jpeg_timings() argument
1625 ret = ov5640_mod_reg(sensor, OV5640_REG_JPG_MODE_SELECT, 0x7, 0x3); in ov5640_set_jpeg_timings()
1629 ret = ov5640_write_reg16(sensor, OV5640_REG_VFIFO_HSIZE, mode->width); in ov5640_set_jpeg_timings()
1633 return ov5640_write_reg16(sensor, OV5640_REG_VFIFO_VSIZE, mode->height); in ov5640_set_jpeg_timings()
1636 /* download ov5640 settings to sensor through i2c */
1637 static int ov5640_set_timings(struct ov5640_dev *sensor, in ov5640_set_timings() argument
1645 if (sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8) { in ov5640_set_timings()
1646 ret = ov5640_set_jpeg_timings(sensor, mode); in ov5640_set_timings()
1651 timings = ov5640_timings(sensor, mode); in ov5640_set_timings()
1655 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HS, in ov5640_set_timings()
1660 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VS, in ov5640_set_timings()
1665 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HW, in ov5640_set_timings()
1670 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VH, in ov5640_set_timings()
1675 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HOFFS, crop->left); in ov5640_set_timings()
1679 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VOFFS, crop->top); in ov5640_set_timings()
1683 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->width); in ov5640_set_timings()
1687 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPVO, mode->height); in ov5640_set_timings()
1691 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HTS, timings->htot); in ov5640_set_timings()
1695 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, in ov5640_set_timings()
1703 static void ov5640_load_regs(struct ov5640_dev *sensor, in ov5640_load_regs() argument
1721 !ov5640_is_csi2(sensor)) in ov5640_load_regs()
1725 ret = ov5640_mod_reg(sensor, reg_addr, mask, val); in ov5640_load_regs()
1727 ret = ov5640_write_reg(sensor, reg_addr, val); in ov5640_load_regs()
1736 static int ov5640_set_autoexposure(struct ov5640_dev *sensor, bool on) in ov5640_set_autoexposure() argument
1738 return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, in ov5640_set_autoexposure()
1743 static int ov5640_get_exposure(struct ov5640_dev *sensor) in ov5640_get_exposure() argument
1748 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_HI, &temp); in ov5640_get_exposure()
1752 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_MED, &temp); in ov5640_get_exposure()
1756 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_LO, &temp); in ov5640_get_exposure()
1765 static int ov5640_set_exposure(struct ov5640_dev *sensor, u32 exposure) in ov5640_set_exposure() argument
1771 ret = ov5640_write_reg(sensor, in ov5640_set_exposure()
1776 ret = ov5640_write_reg(sensor, in ov5640_set_exposure()
1781 return ov5640_write_reg(sensor, in ov5640_set_exposure()
1786 static int ov5640_get_gain(struct ov5640_dev *sensor) in ov5640_get_gain() argument
1791 ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, &gain); in ov5640_get_gain()
1798 static int ov5640_set_gain(struct ov5640_dev *sensor, int gain) in ov5640_set_gain() argument
1800 return ov5640_write_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, in ov5640_set_gain()
1804 static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) in ov5640_set_autogain() argument
1806 return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, in ov5640_set_autogain()
1810 static int ov5640_set_stream_dvp(struct ov5640_dev *sensor, bool on) in ov5640_set_stream_dvp() argument
1812 return ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ? in ov5640_set_stream_dvp()
1817 static int ov5640_set_stream_mipi(struct ov5640_dev *sensor, bool on) in ov5640_set_stream_mipi() argument
1826 * FIXME: the sensor manual (version 2.03) reports in ov5640_set_stream_mipi()
1838 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, in ov5640_set_stream_mipi()
1843 return ov5640_write_reg(sensor, OV5640_REG_FRAME_CTRL01, in ov5640_set_stream_mipi()
1847 static int ov5640_get_sysclk(struct ov5640_dev *sensor) in ov5640_get_sysclk() argument
1850 u32 xvclk = sensor->xclk_freq / 10000; in ov5640_get_sysclk()
1857 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL0, &temp1); in ov5640_get_sysclk()
1864 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL1, &temp1); in ov5640_get_sysclk()
1871 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL2, &temp1); in ov5640_get_sysclk()
1876 ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL3, &temp1); in ov5640_get_sysclk()
1882 ret = ov5640_read_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, &temp1); in ov5640_get_sysclk()
1898 static int ov5640_set_night_mode(struct ov5640_dev *sensor) in ov5640_set_night_mode() argument
1904 ret = ov5640_read_reg(sensor, OV5640_REG_AEC_CTRL00, &mode); in ov5640_set_night_mode()
1908 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL00, mode); in ov5640_set_night_mode()
1911 static int ov5640_get_hts(struct ov5640_dev *sensor) in ov5640_get_hts() argument
1917 ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_HTS, &hts); in ov5640_get_hts()
1923 static int ov5640_get_vts(struct ov5640_dev *sensor) in ov5640_get_vts() argument
1928 ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_VTS, &vts); in ov5640_get_vts()
1934 static int ov5640_set_vts(struct ov5640_dev *sensor, int vts) in ov5640_set_vts() argument
1936 return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, vts); in ov5640_set_vts()
1939 static int ov5640_get_light_freq(struct ov5640_dev *sensor) in ov5640_get_light_freq() argument
1945 ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL01, &temp); in ov5640_get_light_freq()
1951 ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL00, in ov5640_get_light_freq()
1964 ret = ov5640_read_reg(sensor, OV5640_REG_SIGMADELTA_CTRL0C, in ov5640_get_light_freq()
1980 static int ov5640_set_bandingfilter(struct ov5640_dev *sensor) in ov5640_set_bandingfilter() argument
1986 ret = ov5640_get_sysclk(sensor); in ov5640_set_bandingfilter()
1991 sensor->prev_sysclk = ret; in ov5640_set_bandingfilter()
1993 ret = ov5640_get_hts(sensor); in ov5640_set_bandingfilter()
1998 sensor->prev_hts = ret; in ov5640_set_bandingfilter()
2001 ret = ov5640_get_vts(sensor); in ov5640_set_bandingfilter()
2008 band_step60 = sensor->prev_sysclk * 100 / sensor->prev_hts * 100 / 120; in ov5640_set_bandingfilter()
2009 ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B60_STEP, band_step60); in ov5640_set_bandingfilter()
2015 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0D, max_band60); in ov5640_set_bandingfilter()
2020 band_step50 = sensor->prev_sysclk * 100 / sensor->prev_hts; in ov5640_set_bandingfilter()
2021 ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B50_STEP, band_step50); in ov5640_set_bandingfilter()
2027 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0E, max_band50); in ov5640_set_bandingfilter()
2030 static int ov5640_set_ae_target(struct ov5640_dev *sensor, int target) in ov5640_set_ae_target() argument
2036 sensor->ae_low = target * 23 / 25; /* 0.92 */ in ov5640_set_ae_target()
2037 sensor->ae_high = target * 27 / 25; /* 1.08 */ in ov5640_set_ae_target()
2039 fast_high = sensor->ae_high << 1; in ov5640_set_ae_target()
2043 fast_low = sensor->ae_low >> 1; in ov5640_set_ae_target()
2045 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0F, sensor->ae_high); in ov5640_set_ae_target()
2048 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL10, sensor->ae_low); in ov5640_set_ae_target()
2051 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1B, sensor->ae_high); in ov5640_set_ae_target()
2054 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1E, sensor->ae_low); in ov5640_set_ae_target()
2057 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL11, fast_high); in ov5640_set_ae_target()
2060 return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1F, fast_low); in ov5640_set_ae_target()
2063 static int ov5640_get_binning(struct ov5640_dev *sensor) in ov5640_get_binning() argument
2068 ret = ov5640_read_reg(sensor, OV5640_REG_TIMING_TC_REG21, &temp); in ov5640_get_binning()
2075 static int ov5640_set_binning(struct ov5640_dev *sensor, bool enable) in ov5640_set_binning() argument
2083 ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_binning()
2092 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, in ov5640_set_binning()
2096 static int ov5640_set_virtual_channel(struct ov5640_dev *sensor) in ov5640_set_virtual_channel() argument
2098 struct i2c_client *client = sensor->i2c_client; in ov5640_set_virtual_channel()
2109 ret = ov5640_read_reg(sensor, OV5640_REG_DEBUG_MODE, &temp); in ov5640_set_virtual_channel()
2114 return ov5640_write_reg(sensor, OV5640_REG_DEBUG_MODE, temp); in ov5640_set_virtual_channel()
2118 ov5640_find_mode(struct ov5640_dev *sensor, int width, int height, bool nearest) in ov5640_find_mode() argument
2135 * sensor changes between scaling and subsampling, go through
2138 static int ov5640_set_mode_exposure_calc(struct ov5640_dev *sensor, in ov5640_set_mode_exposure_calc() argument
2153 ret = ov5640_get_exposure(sensor); in ov5640_set_mode_exposure_calc()
2157 ret = ov5640_get_binning(sensor); in ov5640_set_mode_exposure_calc()
2165 ret = ov5640_get_gain(sensor); in ov5640_set_mode_exposure_calc()
2171 ret = ov5640_read_reg(sensor, OV5640_REG_AVG_READOUT, &average); in ov5640_set_mode_exposure_calc()
2176 ret = ov5640_set_night_mode(sensor); in ov5640_set_mode_exposure_calc()
2181 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_exposure_calc()
2182 ret = ov5640_set_timings(sensor, mode); in ov5640_set_mode_exposure_calc()
2187 ret = ov5640_get_vts(sensor); in ov5640_set_mode_exposure_calc()
2191 ret = ov5640_get_hts(sensor); in ov5640_set_mode_exposure_calc()
2198 ret = ov5640_get_sysclk(sensor); in ov5640_set_mode_exposure_calc()
2206 ret = ov5640_get_light_freq(sensor); in ov5640_set_mode_exposure_calc()
2219 if (!sensor->prev_sysclk) { in ov5640_set_mode_exposure_calc()
2220 ret = ov5640_get_sysclk(sensor); in ov5640_set_mode_exposure_calc()
2225 sensor->prev_sysclk = ret; in ov5640_set_mode_exposure_calc()
2234 if (average > sensor->ae_low && average < sensor->ae_high) { in ov5640_set_mode_exposure_calc()
2238 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2239 sensor->prev_hts / cap_hts * in ov5640_set_mode_exposure_calc()
2240 sensor->ae_target / average; in ov5640_set_mode_exposure_calc()
2244 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2245 sensor->prev_hts / cap_hts; in ov5640_set_mode_exposure_calc()
2279 ret = ov5640_set_gain(sensor, cap_gain16); in ov5640_set_mode_exposure_calc()
2286 ret = ov5640_set_vts(sensor, cap_vts); in ov5640_set_mode_exposure_calc()
2292 return ov5640_set_exposure(sensor, cap_shutter); in ov5640_set_mode_exposure_calc()
2296 * if sensor changes inside scaling or subsampling
2299 static int ov5640_set_mode_direct(struct ov5640_dev *sensor, in ov5640_set_mode_direct() argument
2306 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_direct()
2307 return ov5640_set_timings(sensor, mode); in ov5640_set_mode_direct()
2310 static int ov5640_set_mode(struct ov5640_dev *sensor) in ov5640_set_mode() argument
2312 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_mode()
2313 const struct ov5640_mode_info *orig_mode = sensor->last_mode; in ov5640_set_mode()
2315 bool auto_gain = sensor->ctrls.auto_gain->val == 1; in ov5640_set_mode()
2316 bool auto_exp = sensor->ctrls.auto_exp->val == V4L2_EXPOSURE_AUTO; in ov5640_set_mode()
2324 ret = ov5640_set_autogain(sensor, false); in ov5640_set_mode()
2330 ret = ov5640_set_autoexposure(sensor, false); in ov5640_set_mode()
2335 if (ov5640_is_csi2(sensor)) in ov5640_set_mode()
2336 ret = ov5640_set_mipi_pclk(sensor); in ov5640_set_mode()
2338 ret = ov5640_set_dvp_pclk(sensor); in ov5640_set_mode()
2348 ret = ov5640_set_mode_exposure_calc(sensor, mode); in ov5640_set_mode()
2354 ret = ov5640_set_mode_direct(sensor, mode); in ov5640_set_mode()
2361 ov5640_set_autogain(sensor, true); in ov5640_set_mode()
2363 ov5640_set_autoexposure(sensor, true); in ov5640_set_mode()
2365 ret = ov5640_set_binning(sensor, dn_mode != SCALING); in ov5640_set_mode()
2368 ret = ov5640_set_ae_target(sensor, sensor->ae_target); in ov5640_set_mode()
2371 ret = ov5640_get_light_freq(sensor); in ov5640_set_mode()
2374 ret = ov5640_set_bandingfilter(sensor); in ov5640_set_mode()
2377 ret = ov5640_set_virtual_channel(sensor); in ov5640_set_mode()
2381 sensor->pending_mode_change = false; in ov5640_set_mode()
2382 sensor->last_mode = mode; in ov5640_set_mode()
2388 ov5640_set_autoexposure(sensor, true); in ov5640_set_mode()
2391 ov5640_set_autogain(sensor, true); in ov5640_set_mode()
2396 static int ov5640_set_framefmt(struct ov5640_dev *sensor,
2400 static int ov5640_restore_mode(struct ov5640_dev *sensor) in ov5640_restore_mode() argument
2405 ov5640_load_regs(sensor, ov5640_init_setting, in ov5640_restore_mode()
2408 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, in ov5640_restore_mode()
2415 ret = ov5640_set_mode(sensor); in ov5640_restore_mode()
2419 return ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_restore_mode()
2422 static void ov5640_power(struct ov5640_dev *sensor, bool enable) in ov5640_power() argument
2424 gpiod_set_value_cansleep(sensor->pwdn_gpio, enable ? 0 : 1); in ov5640_power()
2427 static void ov5640_reset(struct ov5640_dev *sensor) in ov5640_reset() argument
2429 if (!sensor->reset_gpio) in ov5640_reset()
2432 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in ov5640_reset()
2435 ov5640_power(sensor, false); in ov5640_reset()
2437 ov5640_power(sensor, true); in ov5640_reset()
2440 gpiod_set_value_cansleep(sensor->reset_gpio, 1); in ov5640_reset()
2443 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in ov5640_reset()
2447 static int ov5640_set_power_on(struct ov5640_dev *sensor) in ov5640_set_power_on() argument
2449 struct i2c_client *client = sensor->i2c_client; in ov5640_set_power_on()
2452 ret = clk_prepare_enable(sensor->xclk); in ov5640_set_power_on()
2460 sensor->supplies); in ov5640_set_power_on()
2467 ov5640_reset(sensor); in ov5640_set_power_on()
2468 ov5640_power(sensor, true); in ov5640_set_power_on()
2470 ret = ov5640_init_slave_id(sensor); in ov5640_set_power_on()
2477 ov5640_power(sensor, false); in ov5640_set_power_on()
2478 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_on()
2480 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_on()
2484 static void ov5640_set_power_off(struct ov5640_dev *sensor) in ov5640_set_power_off() argument
2486 ov5640_power(sensor, false); in ov5640_set_power_off()
2487 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_off()
2488 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_off()
2491 static int ov5640_set_power_mipi(struct ov5640_dev *sensor, bool on) in ov5640_set_power_mipi() argument
2497 ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); in ov5640_set_power_mipi()
2498 ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x04); in ov5640_set_power_mipi()
2499 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x00); in ov5640_set_power_mipi()
2513 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x40); in ov5640_set_power_mipi()
2524 ret = ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x24); in ov5640_set_power_mipi()
2536 ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x70); in ov5640_set_power_mipi()
2546 static int ov5640_set_power_dvp(struct ov5640_dev *sensor, bool on) in ov5640_set_power_dvp() argument
2548 unsigned int flags = sensor->ep.bus.parallel.flags; in ov5640_set_power_dvp()
2549 bool bt656 = sensor->ep.bus_type == V4L2_MBUS_BT656; in ov5640_set_power_dvp()
2555 ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, 0x00); in ov5640_set_power_dvp()
2556 ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); in ov5640_set_power_dvp()
2557 ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, 0x20); in ov5640_set_power_dvp()
2558 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, 0x00); in ov5640_set_power_dvp()
2559 ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0x00); in ov5640_set_power_dvp()
2603 ret = ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, in ov5640_set_power_dvp()
2627 ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, polarities); in ov5640_set_power_dvp()
2639 ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x18); in ov5640_set_power_dvp()
2653 ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, in ov5640_set_power_dvp()
2664 return ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0xfc); in ov5640_set_power_dvp()
2667 static int ov5640_set_power(struct ov5640_dev *sensor, bool on) in ov5640_set_power() argument
2672 ret = ov5640_set_power_on(sensor); in ov5640_set_power()
2676 ret = ov5640_restore_mode(sensor); in ov5640_set_power()
2681 if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) in ov5640_set_power()
2682 ret = ov5640_set_power_mipi(sensor, on); in ov5640_set_power()
2684 ret = ov5640_set_power_dvp(sensor, on); in ov5640_set_power()
2689 ov5640_set_power_off(sensor); in ov5640_set_power()
2694 ov5640_set_power_off(sensor); in ov5640_set_power()
2716 static int ov5640_try_frame_interval(struct ov5640_dev *sensor, in ov5640_try_frame_interval() argument
2752 mode = ov5640_find_mode(sensor, width, height, false); in ov5640_try_frame_interval()
2760 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_get_fmt() local
2766 mutex_lock(&sensor->lock); in ov5640_get_fmt()
2769 fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state, in ov5640_get_fmt()
2772 fmt = &sensor->fmt; in ov5640_get_fmt()
2776 mutex_unlock(&sensor->lock); in ov5640_get_fmt()
2786 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_try_fmt_internal() local
2791 mode = ov5640_find_mode(sensor, fmt->width, fmt->height, true); in ov5640_try_fmt_internal()
2795 pixfmt = ov5640_code_to_pixfmt(sensor, fmt->code); in ov5640_try_fmt_internal()
2823 static int ov5640_update_pixel_rate(struct ov5640_dev *sensor) in ov5640_update_pixel_rate() argument
2825 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_update_pixel_rate()
2827 struct v4l2_mbus_framefmt *fmt = &sensor->fmt; in ov5640_update_pixel_rate()
2843 if (!ov5640_is_csi2(sensor)) { in ov5640_update_pixel_rate()
2844 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, in ov5640_update_pixel_rate()
2845 ov5640_calc_pixel_rate(sensor)); in ov5640_update_pixel_rate()
2857 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_update_pixel_rate()
2858 bpp = ov5640_code_to_bpp(sensor, fmt->code); in ov5640_update_pixel_rate()
2865 sensor->current_link_freq = link_freq; in ov5640_update_pixel_rate()
2886 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, pixel_rate); in ov5640_update_pixel_rate()
2887 __v4l2_ctrl_s_ctrl(sensor->ctrls.link_freq, i); in ov5640_update_pixel_rate()
2889 timings = ov5640_timings(sensor, mode); in ov5640_update_pixel_rate()
2891 __v4l2_ctrl_modify_range(sensor->ctrls.hblank, in ov5640_update_pixel_rate()
2896 if (sensor->current_fr != mode->def_fps) { in ov5640_update_pixel_rate()
2901 int fie_num = sensor->frame_interval.numerator; in ov5640_update_pixel_rate()
2902 int fie_denom = sensor->frame_interval.denominator; in ov5640_update_pixel_rate()
2908 __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV5640_MIN_VBLANK, in ov5640_update_pixel_rate()
2910 __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, vblank); in ov5640_update_pixel_rate()
2913 exposure_val = clamp_t(s32, sensor->ctrls.exposure->val, in ov5640_update_pixel_rate()
2914 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2917 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_update_pixel_rate()
2918 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2928 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_set_fmt() local
2936 mutex_lock(&sensor->lock); in ov5640_set_fmt()
2938 if (sensor->streaming) { in ov5640_set_fmt()
2944 sensor->current_fr, &new_mode); in ov5640_set_fmt()
2953 if (new_mode != sensor->current_mode) { in ov5640_set_fmt()
2954 sensor->current_fr = new_mode->def_fps; in ov5640_set_fmt()
2955 sensor->current_mode = new_mode; in ov5640_set_fmt()
2956 sensor->pending_mode_change = true; in ov5640_set_fmt()
2958 if (mbus_fmt->code != sensor->fmt.code) in ov5640_set_fmt()
2959 sensor->pending_fmt_change = true; in ov5640_set_fmt()
2962 sensor->fmt = *mbus_fmt; in ov5640_set_fmt()
2964 ov5640_update_pixel_rate(sensor); in ov5640_set_fmt()
2967 mutex_unlock(&sensor->lock); in ov5640_set_fmt()
2975 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_get_selection() local
2976 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_get_selection()
2981 mutex_lock(&sensor->lock); in ov5640_get_selection()
2982 timings = ov5640_timings(sensor, mode); in ov5640_get_selection()
2984 mutex_unlock(&sensor->lock); in ov5640_get_selection()
3010 static int ov5640_set_framefmt(struct ov5640_dev *sensor, in ov5640_set_framefmt() argument
3017 pixfmt = ov5640_code_to_pixfmt(sensor, format->code); in ov5640_set_framefmt()
3020 ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, in ov5640_set_framefmt()
3026 ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, in ov5640_set_framefmt()
3035 ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_framefmt()
3046 ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_RESET02, in ov5640_set_framefmt()
3057 return ov5640_mod_reg(sensor, OV5640_REG_SYS_CLOCK_ENABLE02, in ov5640_set_framefmt()
3063 * Sensor Controls.
3066 static int ov5640_set_ctrl_hue(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_hue() argument
3071 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_hue()
3075 ret = ov5640_write_reg16(sensor, OV5640_REG_SDE_CTRL1, value); in ov5640_set_ctrl_hue()
3077 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(0), 0); in ov5640_set_ctrl_hue()
3083 static int ov5640_set_ctrl_contrast(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_contrast() argument
3088 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_contrast()
3092 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL5, in ov5640_set_ctrl_contrast()
3095 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(2), 0); in ov5640_set_ctrl_contrast()
3101 static int ov5640_set_ctrl_saturation(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_saturation() argument
3106 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, in ov5640_set_ctrl_saturation()
3110 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL3, in ov5640_set_ctrl_saturation()
3114 ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL4, in ov5640_set_ctrl_saturation()
3117 ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(1), 0); in ov5640_set_ctrl_saturation()
3123 static int ov5640_set_ctrl_white_balance(struct ov5640_dev *sensor, int awb) in ov5640_set_ctrl_white_balance() argument
3127 ret = ov5640_mod_reg(sensor, OV5640_REG_AWB_MANUAL_CTRL, in ov5640_set_ctrl_white_balance()
3133 u16 red = (u16)sensor->ctrls.red_balance->val; in ov5640_set_ctrl_white_balance()
3134 u16 blue = (u16)sensor->ctrls.blue_balance->val; in ov5640_set_ctrl_white_balance()
3136 ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_R_GAIN, red); in ov5640_set_ctrl_white_balance()
3139 ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_B_GAIN, blue); in ov5640_set_ctrl_white_balance()
3145 static int ov5640_set_ctrl_exposure(struct ov5640_dev *sensor, in ov5640_set_ctrl_exposure() argument
3148 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_exposure()
3153 ret = ov5640_set_autoexposure(sensor, auto_exp); in ov5640_set_ctrl_exposure()
3161 ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_VTS, in ov5640_set_ctrl_exposure()
3165 ret = ov5640_get_vts(sensor); in ov5640_set_ctrl_exposure()
3172 ret = ov5640_set_exposure(sensor, ctrls->exposure->val); in ov5640_set_ctrl_exposure()
3178 static int ov5640_set_ctrl_gain(struct ov5640_dev *sensor, bool auto_gain) in ov5640_set_ctrl_gain() argument
3180 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_gain()
3184 ret = ov5640_set_autogain(sensor, auto_gain); in ov5640_set_ctrl_gain()
3190 ret = ov5640_set_gain(sensor, ctrls->gain->val); in ov5640_set_ctrl_gain()
3226 static int ov5640_set_ctrl_test_pattern(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_test_pattern() argument
3228 return ov5640_write_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, in ov5640_set_ctrl_test_pattern()
3232 static int ov5640_set_ctrl_light_freq(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_light_freq() argument
3236 ret = ov5640_mod_reg(sensor, OV5640_REG_HZ5060_CTRL01, BIT(7), in ov5640_set_ctrl_light_freq()
3242 return ov5640_mod_reg(sensor, OV5640_REG_HZ5060_CTRL00, BIT(2), in ov5640_set_ctrl_light_freq()
3247 static int ov5640_set_ctrl_hflip(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_hflip() argument
3250 * If sensor is mounted upside down, mirror logic is inversed. in ov5640_set_ctrl_hflip()
3252 * Sensor is a BSI (Back Side Illuminated) one, in ov5640_set_ctrl_hflip()
3261 * - [1]: Sensor mirror in ov5640_set_ctrl_hflip()
3263 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, in ov5640_set_ctrl_hflip()
3265 (!(value ^ sensor->upside_down)) ? in ov5640_set_ctrl_hflip()
3269 static int ov5640_set_ctrl_vflip(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_vflip() argument
3271 /* If sensor is mounted upside down, flip logic is inversed */ in ov5640_set_ctrl_vflip()
3276 * - [1]: Sensor vflip in ov5640_set_ctrl_vflip()
3278 return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, in ov5640_set_ctrl_vflip()
3280 (value ^ sensor->upside_down) ? in ov5640_set_ctrl_vflip()
3284 static int ov5640_set_ctrl_vblank(struct ov5640_dev *sensor, int value) in ov5640_set_ctrl_vblank() argument
3286 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_ctrl_vblank()
3289 return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, in ov5640_set_ctrl_vblank()
3296 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_g_volatile_ctrl() local
3301 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_g_volatile_ctrl()
3306 val = ov5640_get_gain(sensor); in ov5640_g_volatile_ctrl()
3309 sensor->ctrls.gain->val = val; in ov5640_g_volatile_ctrl()
3312 val = ov5640_get_exposure(sensor); in ov5640_g_volatile_ctrl()
3315 sensor->ctrls.exposure->val = val; in ov5640_g_volatile_ctrl()
3319 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_g_volatile_ctrl()
3327 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_s_ctrl() local
3328 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_s_ctrl()
3338 timings = ov5640_timings(sensor, mode); in ov5640_s_ctrl()
3340 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_s_ctrl()
3341 sensor->ctrls.exposure->minimum, in ov5640_s_ctrl()
3342 exp_max, sensor->ctrls.exposure->step, in ov5640_s_ctrl()
3352 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_s_ctrl()
3357 ret = ov5640_set_ctrl_gain(sensor, ctrl->val); in ov5640_s_ctrl()
3360 ret = ov5640_set_ctrl_exposure(sensor, ctrl->val); in ov5640_s_ctrl()
3363 ret = ov5640_set_ctrl_white_balance(sensor, ctrl->val); in ov5640_s_ctrl()
3366 ret = ov5640_set_ctrl_hue(sensor, ctrl->val); in ov5640_s_ctrl()
3369 ret = ov5640_set_ctrl_contrast(sensor, ctrl->val); in ov5640_s_ctrl()
3372 ret = ov5640_set_ctrl_saturation(sensor, ctrl->val); in ov5640_s_ctrl()
3375 ret = ov5640_set_ctrl_test_pattern(sensor, ctrl->val); in ov5640_s_ctrl()
3378 ret = ov5640_set_ctrl_light_freq(sensor, ctrl->val); in ov5640_s_ctrl()
3381 ret = ov5640_set_ctrl_hflip(sensor, ctrl->val); in ov5640_s_ctrl()
3384 ret = ov5640_set_ctrl_vflip(sensor, ctrl->val); in ov5640_s_ctrl()
3387 ret = ov5640_set_ctrl_vblank(sensor, ctrl->val); in ov5640_s_ctrl()
3394 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_ctrl()
3404 static int ov5640_init_controls(struct ov5640_dev *sensor) in ov5640_init_controls() argument
3406 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_init_controls()
3408 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_init_controls()
3419 hdl->lock = &sensor->lock; in ov5640_init_controls()
3433 timings = ov5640_timings(sensor, mode); in ov5640_init_controls()
3490 ret = v4l2_fwnode_device_parse(&sensor->i2c_client->dev, &props); in ov5640_init_controls()
3495 sensor->upside_down = true; in ov5640_init_controls()
3511 sensor->sd.ctrl_handler = hdl; in ov5640_init_controls()
3523 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_frame_size() local
3524 u32 bpp = ov5640_code_to_bpp(sensor, fse->code); in ov5640_enum_frame_size()
3556 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_frame_interval() local
3568 ret = ov5640_try_frame_interval(sensor, &tpf, in ov5640_enum_frame_interval()
3580 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_g_frame_interval() local
3582 mutex_lock(&sensor->lock); in ov5640_g_frame_interval()
3583 fi->interval = sensor->frame_interval; in ov5640_g_frame_interval()
3584 mutex_unlock(&sensor->lock); in ov5640_g_frame_interval()
3592 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_s_frame_interval() local
3599 mutex_lock(&sensor->lock); in ov5640_s_frame_interval()
3601 if (sensor->streaming) { in ov5640_s_frame_interval()
3606 mode = sensor->current_mode; in ov5640_s_frame_interval()
3608 frame_rate = ov5640_try_frame_interval(sensor, &fi->interval, in ov5640_s_frame_interval()
3613 fi->interval = sensor->frame_interval; in ov5640_s_frame_interval()
3617 mode = ov5640_find_mode(sensor, mode->width, mode->height, true); in ov5640_s_frame_interval()
3628 if (mode != sensor->current_mode || in ov5640_s_frame_interval()
3629 frame_rate != sensor->current_fr) { in ov5640_s_frame_interval()
3630 sensor->current_fr = frame_rate; in ov5640_s_frame_interval()
3631 sensor->frame_interval = fi->interval; in ov5640_s_frame_interval()
3632 sensor->current_mode = mode; in ov5640_s_frame_interval()
3633 sensor->pending_mode_change = true; in ov5640_s_frame_interval()
3635 ov5640_update_pixel_rate(sensor); in ov5640_s_frame_interval()
3638 mutex_unlock(&sensor->lock); in ov5640_s_frame_interval()
3646 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_enum_mbus_code() local
3650 if (ov5640_is_csi2(sensor)) { in ov5640_enum_mbus_code()
3668 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_s_stream() local
3672 ret = pm_runtime_resume_and_get(&sensor->i2c_client->dev); in ov5640_s_stream()
3676 ret = v4l2_ctrl_handler_setup(&sensor->ctrls.handler); in ov5640_s_stream()
3678 pm_runtime_put(&sensor->i2c_client->dev); in ov5640_s_stream()
3683 mutex_lock(&sensor->lock); in ov5640_s_stream()
3685 if (sensor->streaming == !enable) { in ov5640_s_stream()
3686 if (enable && sensor->pending_mode_change) { in ov5640_s_stream()
3687 ret = ov5640_set_mode(sensor); in ov5640_s_stream()
3692 if (enable && sensor->pending_fmt_change) { in ov5640_s_stream()
3693 ret = ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_s_stream()
3696 sensor->pending_fmt_change = false; in ov5640_s_stream()
3699 if (ov5640_is_csi2(sensor)) in ov5640_s_stream()
3700 ret = ov5640_set_stream_mipi(sensor, enable); in ov5640_s_stream()
3702 ret = ov5640_set_stream_dvp(sensor, enable); in ov5640_s_stream()
3705 sensor->streaming = enable; in ov5640_s_stream()
3709 mutex_unlock(&sensor->lock); in ov5640_s_stream()
3712 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_stream()
3762 static int ov5640_get_regulators(struct ov5640_dev *sensor) in ov5640_get_regulators() argument
3767 sensor->supplies[i].supply = ov5640_supply_name[i]; in ov5640_get_regulators()
3769 return devm_regulator_bulk_get(&sensor->i2c_client->dev, in ov5640_get_regulators()
3771 sensor->supplies); in ov5640_get_regulators()
3774 static int ov5640_check_chip_id(struct ov5640_dev *sensor) in ov5640_check_chip_id() argument
3776 struct i2c_client *client = sensor->i2c_client; in ov5640_check_chip_id()
3780 ret = ov5640_read_reg16(sensor, OV5640_REG_CHIP_ID, &chip_id); in ov5640_check_chip_id()
3800 struct ov5640_dev *sensor; in ov5640_probe() local
3803 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); in ov5640_probe()
3804 if (!sensor) in ov5640_probe()
3807 sensor->i2c_client = client; in ov5640_probe()
3810 * default init sequence initialize sensor to in ov5640_probe()
3813 sensor->fmt = ov5640_default_fmt; in ov5640_probe()
3814 sensor->frame_interval.numerator = 1; in ov5640_probe()
3815 sensor->frame_interval.denominator = ov5640_framerates[OV5640_30_FPS]; in ov5640_probe()
3816 sensor->current_fr = OV5640_30_FPS; in ov5640_probe()
3817 sensor->current_mode = in ov5640_probe()
3819 sensor->last_mode = sensor->current_mode; in ov5640_probe()
3820 sensor->current_link_freq = OV5640_DEFAULT_LINK_FREQ; in ov5640_probe()
3822 sensor->ae_target = 52; in ov5640_probe()
3831 ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep); in ov5640_probe()
3838 if (sensor->ep.bus_type != V4L2_MBUS_PARALLEL && in ov5640_probe()
3839 sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY && in ov5640_probe()
3840 sensor->ep.bus_type != V4L2_MBUS_BT656) { in ov5640_probe()
3841 dev_err(dev, "Unsupported bus type %d\n", sensor->ep.bus_type); in ov5640_probe()
3846 sensor->xclk = devm_clk_get(dev, "xclk"); in ov5640_probe()
3847 if (IS_ERR(sensor->xclk)) { in ov5640_probe()
3849 return PTR_ERR(sensor->xclk); in ov5640_probe()
3852 sensor->xclk_freq = clk_get_rate(sensor->xclk); in ov5640_probe()
3853 if (sensor->xclk_freq < OV5640_XCLK_MIN || in ov5640_probe()
3854 sensor->xclk_freq > OV5640_XCLK_MAX) { in ov5640_probe()
3856 sensor->xclk_freq); in ov5640_probe()
3861 sensor->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown", in ov5640_probe()
3863 if (IS_ERR(sensor->pwdn_gpio)) in ov5640_probe()
3864 return PTR_ERR(sensor->pwdn_gpio); in ov5640_probe()
3867 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov5640_probe()
3869 if (IS_ERR(sensor->reset_gpio)) in ov5640_probe()
3870 return PTR_ERR(sensor->reset_gpio); in ov5640_probe()
3872 v4l2_i2c_subdev_init(&sensor->sd, client, &ov5640_subdev_ops); in ov5640_probe()
3874 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov5640_probe()
3876 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5640_probe()
3877 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5640_probe()
3878 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in ov5640_probe()
3882 ret = ov5640_get_regulators(sensor); in ov5640_probe()
3886 mutex_init(&sensor->lock); in ov5640_probe()
3888 ret = ov5640_init_controls(sensor); in ov5640_probe()
3902 ret = ov5640_check_chip_id(sensor); in ov5640_probe()
3906 ret = v4l2_async_register_subdev_sensor(&sensor->sd); in ov5640_probe()
3919 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_probe()
3922 media_entity_cleanup(&sensor->sd.entity); in ov5640_probe()
3923 mutex_destroy(&sensor->lock); in ov5640_probe()
3930 struct ov5640_dev *sensor = to_ov5640_dev(sd); in ov5640_remove() local
3938 v4l2_async_unregister_subdev(&sensor->sd); in ov5640_remove()
3939 media_entity_cleanup(&sensor->sd.entity); in ov5640_remove()
3940 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_remove()
3941 mutex_destroy(&sensor->lock); in ov5640_remove()