media: mt9m114: Changes to make it work with atomisp devices
Subsystems (4)
cover media: mt9m114: Changes to make it work with atomisp devices
Hi All,
Here is a series of patches to make the "mainline" mt9m114 driver work on devices with an atomisp CSI2 receiver / ISP. This has been tested on an Asus T100TA.
This allows dropping the atomisp specific atomisp-mt9m114 driver from drivers/staging.
Chances are there are conflicts here with Mathis':
"[PATCH v4 0/6] MT9M114 driver bugfix and improvements" series.
I'll expect there be some review comments on this series anyways, so merging Mathis' series first is fine, then I'll rebase this series on top for v2.
Regards,
Hans
Hans de Goede (13):
media: aptina-pll: Debug log p1 min and max values
media: mt9m114: Add support for clock-frequency property
media: mt9m114: Use aptina-PLL helper to get PLL values
media: mt9m114: Lower minimum vblank value
media: mt9m114: Fix default hblank and vblank values
media: mt9m114: Tweak default hblank and vblank for more accurate fps
media: mt9m114: Update hblank and vblank defaults on pixel-array
format changes
media: mt9m114: Avoid a reset low spike during probe()
media: mt9m114: Put sensor in reset on power-down
media: mt9m114: Fix scaler bypass mode
media: mt9m114: Drop start-, stop-streaming sequence from initialize
media: mt9m114: Return -EPROBE_DEFER if no endpoint is found
media: mt9m114: Add ACPI enumeration support
drivers/media/i2c/aptina-pll.c | 2 + drivers/media/i2c/mt9m114.c | 167 ++++++++++++++++++++++++--------- 2 files changed, 125 insertions(+), 44 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/13 media: aptina-pll: Debug log p1 min and max values
Make aptina_pll_calculate() debug log the calculated p1 min and max values, this makes it easier to see how the m, n and p1 values were chosen.
--- drivers/media/i2c/aptina-pll.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/aptina-pll.c +2 -0
@@ -129,6 +129,8 @@ int aptina_pll_calculate(struct device *dev, p1_max =min (limits->p1_max, limits->out_clock_max * div / (pll->ext_clock * pll->m)); +dev_dbg (dev,"pll: p1 min %u max %u\n" , p1_min, p1_max); +for (p1 = p1_max & ~1 ; p1 >= p1_min; p1 -=2 ) {unsigned int mf_inc = p1 /gcd (div, p1);unsigned int mf_high;
Signature · 1 line
2.49.0
Re: [PATCH 01/13] media: aptina-pll: Debug log p1 min and max values
Hi Hans,
Thank you for the patch.
Quoted 4 lines · Hans de Goede
Make
aptina_pll_calculate()debug log the calculated p1 min and max values, this makes it easier to see how the m, n and p1 values were chosen.Signed-off-by Hans de Goede <[email protected]>
Quoted 17 lines
--- drivers/media/i2c/aptina-pll.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/i2c/aptina-pll.c +2
-0@@ -129,6 +129,8 @@ int aptina_pll_calculate(struct device *dev, p1_max =min (limits->p1_max, limits->out_clock_max * div / (pll->ext_clock * pll->m)); +dev_dbg (dev,"pll: p1 min %u max %u\n" , p1_min, p1_max); +for (p1 = p1_max & ~1 ; p1 >= p1_min; p1 -=2 ) {unsigned int mf_inc = p1 /gcd (div, p1);unsigned int mf_high;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/13 media: mt9m114: Add support for clock-frequency property
In reply to Hans de GoedeAdd support for platforms that do not have a clock provider, but instead specify the clock frequency by using the "clock-frequency" property.
E.g. ACPI platforms turn the clock on/off through ACPI power-resources depending on the runtime-pm state, so there is no clock provider.
--- drivers/media/i2c/mt9m114.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/media/i2c/mt9m114.c +16 -4
@@ -377,6 +377,7 @@ struct mt9m114 {struct gpio_desc *reset;struct regulator_bulk_data supplies[3 ];struct v4l2_fwnode_endpoint bus_cfg; +u32 clk_freq;struct {unsigned int m;
@@ -2122,14 +2123,13 @@ static int mt9m114_power_on(struct mt9m114 *sensor)/* Perform a hard reset if available, or a soft reset otherwise. */ if (sensor->reset) { -long freq =clk_get_rate (sensor->clk);unsigned int duration;/* * The minimum duration is 50 clock cycles, thus typically * around 2µs. Double it to be safe. */ - duration =DIV_ROUND_UP (2 *50 *1000000 , freq); + duration =DIV_ROUND_UP (2 *50 *1000000 , sensor->clk_freq);gpiod_set_value (sensor->reset,1 );fsleep (duration);
@@ -2249,7 +2249,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* for 16-bit per pixel, transmitted in DDR over a single lane. For * parallel mode, the sensor ouputs one pixel in two PIXCLK cycles. */ - sensor->pixrate =clk_get_rate (sensor->clk) * sensor->pll.m + sensor->pixrate = sensor->clk_freq * sensor->pll.m / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); link_freq = sensor->bus_cfg.bus_type ==V4L2_MBUS_CSI2_DPHY
@@ -2360,13 +2360,25 @@ static int mt9m114_probe(struct i2c_client *client)return ret;/* Acquire clocks, GPIOs and regulators. */ - sensor->clk =devm_clk_get (dev,NULL ); + sensor->clk =devm_clk_get_optional (dev,NULL );if (IS_ERR (sensor->clk)) { ret =PTR_ERR (sensor->clk);dev_err_probe (dev, ret,"Failed to get clock\n" ); goto error_ep_free; } +if (sensor->clk) { + sensor->clk_freq =clk_get_rate (sensor->clk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &sensor->clk_freq); +if (ret) { +dev_err_probe (dev, ret,"Failed to read clock-freq\n" ); + goto error_ep_free; + } + } + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW );if (IS_ERR (sensor->reset)) { ret =PTR_ERR (sensor->reset);
Signature · 1 line
2.49.0
Laurent Pinchart
maintainerRe: [PATCH 02/13] media: mt9m114: Add support for clock-frequency property
Hi Hans,
Quoted 5 lines · Hans de Goede
Add support for platforms that do not have a clock provider, but instead specify the clock frequency by using the "clock-frequency" property.
E.g. ACPI platforms turn the clock on/off through ACPI power-resources depending on the runtime-pm state, so there is no clock provider.
https://lore.kernel.org/r/[email protected]
is a solution to this problem that will scale better.
Quoted 69 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)drivers/media/i2c/mt9m114.c +16
-4@@ -377,6 +377,7 @@ struct mt9m114 {struct gpio_desc *reset;struct regulator_bulk_data supplies[3 ];struct v4l2_fwnode_endpoint bus_cfg; +u32 clk_freq;struct {unsigned int m;@@ -2122,14 +2123,13 @@ static int mt9m114_power_on(struct mt9m114 *sensor)/* Perform a hard reset if available, or a soft reset otherwise. */ if (sensor->reset) { -long freq =clk_get_rate (sensor->clk);unsigned int duration;/* * The minimum duration is 50 clock cycles, thus typically * around 2µs. Double it to be safe. */ - duration =DIV_ROUND_UP (2 *50 *1000000 , freq); + duration =DIV_ROUND_UP (2 *50 *1000000 , sensor->clk_freq);gpiod_set_value (sensor->reset,1 );fsleep (duration);@@ -2249,7 +2249,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* for 16-bit per pixel, transmitted in DDR over a single lane. For * parallel mode, the sensor ouputs one pixel in two PIXCLK cycles. */ - sensor->pixrate =clk_get_rate (sensor->clk) * sensor->pll.m + sensor->pixrate = sensor->clk_freq * sensor->pll.m / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); link_freq = sensor->bus_cfg.bus_type ==V4L2_MBUS_CSI2_DPHY @@ -2360,13 +2360,25 @@ static int mt9m114_probe(struct i2c_client *client)return ret;/* Acquire clocks, GPIOs and regulators. */ - sensor->clk =devm_clk_get (dev,NULL ); + sensor->clk =devm_clk_get_optional (dev,NULL );if (IS_ERR (sensor->clk)) { ret =PTR_ERR (sensor->clk);dev_err_probe (dev, ret,"Failed to get clock\n" ); goto error_ep_free; } +if (sensor->clk) { + sensor->clk_freq =clk_get_rate (sensor->clk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &sensor->clk_freq); +if (ret) { +dev_err_probe (dev, ret,"Failed to read clock-freq\n" ); + goto error_ep_free; + } + } + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW );if (IS_ERR (sensor->reset)) { ret =PTR_ERR (sensor->reset);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 02/13] media: mt9m114: Add support for clock-frequency property
Hi,
Quoted 11 lines · Laurent Pinchart
Hi Hans,
Quoted 5 lines · Hans de Goede
Add support for platforms that do not have a clock provider, but instead specify the clock frequency by using the "clock-frequency" property.
E.g. ACPI platforms turn the clock on/off through ACPI power-resources depending on the runtime-pm state, so there is no clock provider.
https://lore.kernel.org/r/[email protected]
is a solution to this problem that will scale better.
I agree. Depending on how the timing wrt upstreaming works out, we may still need this patch before merging 13/13 (adding of the actual ACPI hw-id table). I'll move this to be patch 12/13 for v2. So that we can at least merge 1-11 of v2 (assuming there will be no more review comments on v2).
Laurent, if the patch you linked to is not ready yet would you then be ok with temporarily taking this patch? I'm happy to commit to moving this driver over to the new helper once the helper is upstream.
Regards,
Hans
Quoted 71 lines
Quoted 70 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)drivers/media/i2c/mt9m114.c +16
-4@@ -377,6 +377,7 @@ struct mt9m114 {struct gpio_desc *reset;struct regulator_bulk_data supplies[3 ];struct v4l2_fwnode_endpoint bus_cfg; +u32 clk_freq;struct {unsigned int m;@@ -2122,14 +2123,13 @@ static int mt9m114_power_on(struct mt9m114 *sensor)/* Perform a hard reset if available, or a soft reset otherwise. */ if (sensor->reset) { -long freq =clk_get_rate (sensor->clk);unsigned int duration;/* * The minimum duration is 50 clock cycles, thus typically * around 2µs. Double it to be safe. */ - duration =DIV_ROUND_UP (2 *50 *1000000 , freq); + duration =DIV_ROUND_UP (2 *50 *1000000 , sensor->clk_freq);gpiod_set_value (sensor->reset,1 );fsleep (duration);@@ -2249,7 +2249,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* for 16-bit per pixel, transmitted in DDR over a single lane. For * parallel mode, the sensor ouputs one pixel in two PIXCLK cycles. */ - sensor->pixrate =clk_get_rate (sensor->clk) * sensor->pll.m + sensor->pixrate = sensor->clk_freq * sensor->pll.m / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); link_freq = sensor->bus_cfg.bus_type ==V4L2_MBUS_CSI2_DPHY @@ -2360,13 +2360,25 @@ static int mt9m114_probe(struct i2c_client *client)return ret;/* Acquire clocks, GPIOs and regulators. */ - sensor->clk =devm_clk_get (dev,NULL ); + sensor->clk =devm_clk_get_optional (dev,NULL );if (IS_ERR (sensor->clk)) { ret =PTR_ERR (sensor->clk);dev_err_probe (dev, ret,"Failed to get clock\n" ); goto error_ep_free; } +if (sensor->clk) { + sensor->clk_freq =clk_get_rate (sensor->clk); + }else { + ret =fwnode_property_read_u32 (dev_fwnode (dev), +"clock-frequency" , + &sensor->clk_freq); +if (ret) { +dev_err_probe (dev, ret,"Failed to read clock-freq\n" ); + goto error_ep_free; + } + } + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW );if (IS_ERR (sensor->reset)) { ret =PTR_ERR (sensor->reset);
PATCH 3/13 media: mt9m114: Use aptina-PLL helper to get PLL values
In reply to Hans de GoedeBefore this change the driver used hardcoded PLL m, n and p values to achieve a 48MHz pixclock when used with an external clock with a frequency of 24 MHz.
Use aptina_pll_calculate() to allow the driver to work with different external clock frequencies. The m, n, and p values will be unchanged with a 24 MHz extclk and this has also been tested with a 19.2 MHz clock where m gets increased from 32 to 40.
--- drivers/media/i2c/mt9m114.c | 53 +++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-)
drivers/media/i2c/mt9m114.c +39 -14
@@ -31,6 +31,8 @@#include <media/v4l2-mediabus.h> #include <media/v4l2-subdev.h> +#include "aptina-pll.h" +/* Sysctl registers */ #define MT9M114_CHIP_ID CCI_REG16(0x0000)#define MT9M114_COMMAND_REGISTER CCI_REG16(0x0080)
@@ -262,9 +264,9 @@#define MT9M114_CAM_SYSCTL_PLL_ENABLE CCI_REG8(0xc97e)#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_M_N CCI_REG16(0xc980) -#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE (m, n) (((n) << 8) | (m)) +#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE (m, n) ((((n) - 1) << 8) | (m))#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P CCI_REG16(0xc982) -#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (p) ((p) << 8) +#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (p) (((p) - 1) << 8)#define MT9M114_CAM_PORT_OUTPUT_CONTROL CCI_REG16(0xc984)#define MT9M114_CAM_PORT_PORT_SELECT_PARALLEL (0 << 0)#define MT9M114_CAM_PORT_PORT_SELECT_MIPI (1 << 0)
@@ -325,7 +327,7 @@* minimum values that have been seen in register lists are 303 and 38, use * them. * -* Set the default to achieve 1280x960 at 30fps. +* Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. */ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 38
@@ -335,6 +337,8 @@#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120 +#define MT9M114_DEF_PIXCLOCK 48000000 +#define MT9M114_PIXEL_ARRAY_WIDTH 1296U#define MT9M114_PIXEL_ARRAY_HEIGHT 976U
@@ -379,11 +383,7 @@ struct mt9m114 {struct v4l2_fwnode_endpoint bus_cfg;u32 clk_freq; -struct { -unsigned int m; -unsigned int n; -unsigned int p; - } pll; +struct aptina_pll pll;unsigned int pixrate;bool streaming;
@@ -751,7 +751,7 @@ static int mt9m114_initialize(struct mt9m114 *sensor) sensor->pll.n), &ret);cci_write (sensor->regmap,MT9M114_CAM_SYSCTL_PLL_DIVIDER_P , -MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p), &ret); +MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p1), &ret);cci_write (sensor->regmap,MT9M114_CAM_SENSOR_CFG_PIXCLK , sensor->pixrate, &ret);
@@ -2238,11 +2238,36 @@ static const struct dev_pm_ops mt9m114_pm_ops = {static int mt9m114_clk_init (struct mt9m114 *sensor) {unsigned int link_freq; +/* +* TODO these limits have been copied from mt9p031.c, with out_clock_max +* increased from 360000000 to 400000000 to get the same PLL settings as +* in the static register lists for 24 MHz and 19.2 MHz ext clock freq. +* These should be verified / adjusted by someone with access to +* the full MT9M114 datasheet. +*/ +static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =27000000 , + .int_clock_min =2000000 , + .int_clock_max =13500000 , + .out_clock_min =180000000 , + .out_clock_max =400000000 , + .pix_clock_max =96000000 , + .n_min =1 , + .n_max =64 , + .m_min =16 , + .m_max =255 , + .p1_min =1 , + .p1_max =128 , + }; +int ret; -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; + sensor->pll.ext_clock = sensor->clk_freq; + sensor->pll.pix_clock =MT9M114_DEF_PIXCLOCK ; + + ret =aptina_pll_calculate (&sensor->client->dev, &limits, &sensor->pll); +if (ret) +return ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked
@@ -2250,7 +2275,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* parallel mode, the sensor ouputs one pixel in two PIXCLK cycles. */ sensor->pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1); link_freq = sensor->bus_cfg.bus_type ==V4L2_MBUS_CSI2_DPHY ? sensor->pixrate *8 : sensor->pixrate *2 ;
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH 03/13] media: mt9m114: Use aptina-PLL helper to get PLL values
kernel test robot noticed the following build errors:
Hi Hans,
kernel test robot noticed the following build errors:
[auto build test ERROR on sailus-media-tree/master]
[also build test ERROR on linuxtv-media-pending/master linus/master media-tree/master v6.15-rc5 next-20250509] [cannot apply to sailus-media-tree/streams]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Hans-de-Goede/media-aptina-pll-Debug-log-p1-min-and-max-values/20250505-114824 base: git://linuxtv.org/sailus/media_tree.git master patch link: https://lore.kernel.org/r/20250504101336.18748-4-hdegoede%40redhat.com patch subject: [PATCH 03/13] media: mt9m114: Use aptina-PLL helper to get PLL values config: i386-randconfig-005-20250509 (https://download.01.org/0day-ci/archive/20250509/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-12) 11.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250509/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: drivers/gpu/drm/xe/xe_migrate.o: in function `pte_update_cmd_size':
drivers/gpu/drm/xe/xe_migrate.c:1561: undefined reference to `__udivdi3'
ld: drivers/media/i2c/mt9m114.o: in function `mt9m114_clk_init':
>> drivers/media/i2c/mt9m114.c:2268: undefined reference to `aptina_pll_calculate'
vim +2268 drivers/media/i2c/mt9m114.c
2233
2234 /* -----------------------------------------------------------------------------
2235 * Probe & Remove
2236 */
2237
2238 static int mt9m114_clk_init(struct mt9m114 *sensor)
2239 {
2240 unsigned int link_freq;
2241 /*
2242 * TODO these limits have been copied from mt9p031.c, with out_clock_max
2243 * increased from 360000000 to 400000000 to get the same PLL settings as
2244 * in the static register lists for 24 MHz and 19.2 MHz ext clock freq.
2245 * These should be verified / adjusted by someone with access to
2246 * the full MT9M114 datasheet.
2247 */
2248 static const struct aptina_pll_limits limits = {
2249 .ext_clock_min = 6000000,
2250 .ext_clock_max = 27000000,
2251 .int_clock_min = 2000000,
2252 .int_clock_max = 13500000,
2253 .out_clock_min = 180000000,
2254 .out_clock_max = 400000000,
2255 .pix_clock_max = 96000000,
2256 .n_min = 1,
2257 .n_max = 64,
2258 .m_min = 16,
2259 .m_max = 255,
2260 .p1_min = 1,
2261 .p1_max = 128,
2262 };
2263 int ret;
2264
2265 sensor->pll.ext_clock = sensor->clk_freq;
2266 sensor->pll.pix_clock = MT9M114_DEF_PIXCLOCK;
2267
> 2268 ret = aptina_pll_calculate(&sensor->client->dev, &limits, &sensor->pll);
2269 if (ret)
2270 return ret;
2271
2272 /*
2273 * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked
2274 * for 16-bit per pixel, transmitted in DDR over a single lane. For
2275 * parallel mode, the sensor ouputs one pixel in two PIXCLK cycles.
2276 */
2277 sensor->pixrate = sensor->clk_freq * sensor->pll.m
2278 / (sensor->pll.n * sensor->pll.p1);
2279
2280 link_freq = sensor->bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
2281 ? sensor->pixrate * 8 : sensor->pixrate * 2;
2282
2283 if (sensor->bus_cfg.nr_of_link_frequencies != 1 ||
2284 sensor->bus_cfg.link_frequencies[0] != link_freq) {
2285 dev_err(&sensor->client->dev, "Unsupported DT link-frequencies\n");
2286 return -EINVAL;
2287 }
2288
2289 return 0;
2290 }
2291
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Laurent Pinchart
maintainerRe: [PATCH 03/13] media: mt9m114: Use aptina-PLL helper to get PLL values
In reply to Hans de GoedeHi Hans,
Thank you for the patch.
Quoted 20 lines · Hans de Goede
Before this change the driver used hardcoded PLL m, n and p values to achieve a 48MHz pixclock when used with an external clock with a frequency of 24 MHz.
Use
aptina_pll_calculate()to allow the driver to work with different external clock frequencies. The m, n, and p values will be unchanged with a 24 MHz extclk and this has also been tested with a 19.2 MHz clock where m gets increased from 32 to 40.Suggested-by Laurent Pinchart <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 53 +++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-)drivers/media/i2c/mt9m114.c +0
-0
drivers/media/i2c/mt9m114.c line 34
Quoted 4 lines
drivers/media/i2c/mt9m114.c +1
-0@@ -31,6 +31,8 @@#include <media/v4l2-mediabus.h> #include <media/v4l2-subdev.h> +#include "aptina-pll.h"
You need to select CONFIG_VIDEO_APTINA_PLL.
Quoted 57 lines
drivers/media/i2c/mt9m114.c +8
-9+/* Sysctl registers */ #define MT9M114_CHIP_ID CCI_REG16(0x0000)#define MT9M114_COMMAND_REGISTER CCI_REG16(0x0080)@@ -262,9 +264,9 @@#define MT9M114_CAM_SYSCTL_PLL_ENABLE CCI_REG8(0xc97e)#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_M_N CCI_REG16(0xc980) -#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE (m, n) (((n) << 8) | (m)) +#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_VALUE (m, n) ((((n) - 1) << 8) | (m))#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P CCI_REG16(0xc982) -#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (p) ((p) << 8) +#define MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (p) (((p) - 1) << 8)#define MT9M114_CAM_PORT_OUTPUT_CONTROL CCI_REG16(0xc984)#define MT9M114_CAM_PORT_PORT_SELECT_PARALLEL (0 << 0)#define MT9M114_CAM_PORT_PORT_SELECT_MIPI (1 << 0)@@ -325,7 +327,7 @@* minimum values that have been seen in register lists are 303 and 38, use * them. * -* Set the default to achieve 1280x960 at 30fps. +* Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. */ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 38@@ -335,6 +337,8 @@#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120 +#define MT9M114_DEF_PIXCLOCK 48000000 +#define MT9M114_PIXEL_ARRAY_WIDTH 1296U#define MT9M114_PIXEL_ARRAY_HEIGHT 976U@@ -379,11 +383,7 @@ struct mt9m114 {struct v4l2_fwnode_endpoint bus_cfg;u32 clk_freq; -struct { -unsigned int m; -unsigned int n; -unsigned int p; - } pll; +struct aptina_pll pll;unsigned int pixrate;bool streaming;@@ -751,7 +751,7 @@ static int mt9m114_initialize(struct mt9m114 *sensor) sensor->pll.n), &ret);cci_write (sensor->regmap,MT9M114_CAM_SYSCTL_PLL_DIVIDER_P , -MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p), &ret); +MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p1), &ret);cci_write (sensor->regmap,MT9M114_CAM_SENSOR_CFG_PIXCLK , sensor->pixrate, &ret);
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2246
Quoted 9 lines
drivers/media/i2c/mt9m114.c +6
-0@@ -2238,11 +2238,36 @@ static const struct dev_pm_ops mt9m114_pm_ops = {static int mt9m114_clk_init (struct mt9m114 *sensor) {unsigned int link_freq; +/* +* TODO these limits have been copied from mt9p031.c, with out_clock_max +* increased from 360000000 to 400000000 to get the same PLL settings as +* in the static register lists for 24 MHz and 19.2 MHz ext clock freq. +* These should be verified / adjusted by someone with access to +* the full MT9M114 datasheet.
Not all constraints are documented, unfortunately :-(
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2250
Quoted 4 lines
drivers/media/i2c/mt9m114.c +4
-0+*/ +static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =27000000 ,
The external clock range is 6 MHz to 54 MHz.
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2252
Quoted 2 lines
drivers/media/i2c/mt9m114.c +2
-0+ .int_clock_min = 2000000, + .int_clock_max = 13500000,
There's no documented values for the internal frequency.
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2254
Quoted 2 lines
drivers/media/i2c/mt9m114.c +2
-0+ .out_clock_min = 180000000, + .out_clock_max = 400000000,
The maximum is 768 MHz. There's no documented minimum value.
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2255
Quoted 1 line
drivers/media/i2c/mt9m114.c +1
-0+ .pix_clock_max = 96000000,
I think the maximum pixel clock frequency is 48 MPix/s.
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2259
Quoted 4 lines
drivers/media/i2c/mt9m114.c +4
-0+ .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 255,
I found a screenshot that specifies the N range as 0-63 (so 1-64 after adding 1) and the M range as 16-192.
drivers/media/i2c/mt9m114.c static const struct dev_pm_ops mt9m114_pm_ops = { · line 2261
Quoted 2 lines
drivers/media/i2c/mt9m114.c +2
-0+ .p1_min = 1, + .p1_max = 128,
I don't know what the maximum value is, but the field is documented as 6 bits, so it can't be above 64.
Quoted 25 lines
drivers/media/i2c/mt9m114.c +9
-5+ }; +int ret; -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; + sensor->pll.ext_clock = sensor->clk_freq; + sensor->pll.pix_clock =MT9M114_DEF_PIXCLOCK ; + + ret =aptina_pll_calculate (&sensor->client->dev, &limits, &sensor->pll); +if (ret) +return ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2250,7 +2275,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* parallel mode, the sensor ouputs one pixel in two PIXCLK cycles. */ sensor->pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1); link_freq = sensor->bus_cfg.bus_type ==V4L2_MBUS_CSI2_DPHY ? sensor->pixrate *8 : sensor->pixrate *2 ;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 4/13 media: mt9m114: Lower minimum vblank value
In reply to Hans de GoedeAs the comment above the defines says, the minimum values are undocumented so the lowest values seen in register lists are used.
The version of the mt9m114 driver shipped together with the atomisp code uses 21 for vblank in its register lists, lower MT9M114_MIN_VBLANK accordingly.
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m114.c +2 -2
@@ -324,13 +324,13 @@/* * The minimum amount of horizontal and vertical blanking is undocumented. The -* minimum values that have been seen in register lists are 303 and 38, use +* minimum values that have been seen in register lists are 303 and 21, use * them. * * Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. */ #define MT9M114_MIN_HBLANK 303 -#define MT9M114_MIN_VBLANK 38 +#define MT9M114_MIN_VBLANK 21#define MT9M114_DEF_HBLANK 323#define MT9M114_DEF_VBLANK 39
Signature · 1 line
2.49.0
Re: [PATCH 04/13] media: mt9m114: Lower minimum vblank value
Hi Hans,
Thank you for the patch.
Quoted 8 lines · Hans de Goede
As the comment above the defines says, the minimum values are undocumented so the lowest values seen in register lists are used.
The version of the mt9m114 driver shipped together with the atomisp code uses 21 for vblank in its register lists, lower
MT9M114_MIN_VBLANKaccordingly.Signed-off-by Hans de Goede <[email protected]>
Quoted 24 lines
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/i2c/mt9m114.c +2
-2@@ -324,13 +324,13 @@/* * The minimum amount of horizontal and vertical blanking is undocumented. The -* minimum values that have been seen in register lists are 303 and 38, use +* minimum values that have been seen in register lists are 303 and 21, use * them. * * Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. */ #define MT9M114_MIN_HBLANK 303 -#define MT9M114_MIN_VBLANK 38 +#define MT9M114_MIN_VBLANK 21#define MT9M114_DEF_HBLANK 323#define MT9M114_DEF_VBLANK 39
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 5/13 media: mt9m114: Fix default hblank and vblank values
In reply to Hans de GoedeThe old default hblank and vblank values were based on reaching 30 fps with the pixel-array outputting 1280x960, but the default format for the pixel-array source pad and the isp sink pad is 1296x976, correct the default hblank and vblank values to take this into account.
--- drivers/media/i2c/mt9m114.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/mt9m114.c +3 -3
@@ -327,12 +327,12 @@* minimum values that have been seen in register lists are 303 and 21, use * them. * -* Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. +* Set the default to achieve 1296x976 at 30fps with a 48 MHz pixclock. */ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 21 -#define MT9M114_DEF_HBLANK 323 -#define MT9M114_DEF_VBLANK 39 +#define MT9M114_DEF_HBLANK 307 +#define MT9M114_DEF_VBLANK 23#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120
Signature · 1 line
2.49.0
Re: [PATCH 05/13] media: mt9m114: Fix default hblank and vblank values
Hi Hans,
Quoted 1 line · Hans de Goede
The old default hblank and vblank values were based on reaching 30 fps
s/old/current/ and s/were/are/
Quoted 14 lines
with the pixel-array outputting 1280x960, but the default format for the pixel-array source pad and the isp sink pad is 1296x976, correct the default hblank and vblank values to take this into account.
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m114.c +0
-0
drivers/media/i2c/mt9m114.c line 330
Quoted 5 lines
drivers/media/i2c/mt9m114.c +1
-1@@ -327,12 +327,12 @@* minimum values that have been seen in register lists are 303 and 21, use * them. * -* Set the default to achieve 1280x960 at 30fps with a 48 MHz pixclock. +* Set the default to achieve 1296x976 at 30fps with a 48 MHz pixclock.
1280x960 is referring to the output resolution. I agree about the new blanking values, but maybe we could be more precise in the comment:
* Set the default to achieve full resolution (1296x976 analog crop
* rectangle, 1280x960 output size) at 30fps with a 48 MHz pixclock.
Quoted 10 lines
drivers/media/i2c/mt9m114.c +2
-2*/ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 21 -#define MT9M114_DEF_HBLANK 323 -#define MT9M114_DEF_VBLANK 39 +#define MT9M114_DEF_HBLANK 307 +#define MT9M114_DEF_VBLANK 23#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 6/13 media: mt9m114: Tweak default hblank and vblank for more accurate fps
In reply to Hans de GoedeThe PLL gets programmed to achieve a 48 MHz pixelclock, with the original vblank + hblank defaults this results in a fps of:
48000000 / ((1296 + 307) * (976 + 23) = 29.974 fps
Tweak the defaults to get closer to 30 fps:
48000000 / ((1296 + 308) * (976 + 21) = 30.015 fps
This improves things from being 0.026 fps too low to 0.015 fps too high.
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m114.c +2 -2
@@ -331,8 +331,8 @@*/ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 21 -#define MT9M114_DEF_HBLANK 307 -#define MT9M114_DEF_VBLANK 23 +#define MT9M114_DEF_HBLANK 308 +#define MT9M114_DEF_VBLANK 21#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120
Signature · 1 line
2.49.0
Re: [PATCH 06/13] media: mt9m114: Tweak default hblank and vblank for more accurate fps
Hi Hans,
Thank you for the patch.
Quoted 1 line · Hans de Goede
The PLL gets programmed to achieve a 48 MHz pixelclock, with the original
s/original/current/
Quoted 11 lines
vblank + hblank defaults this results in a fps of:
48000000 / ((1296 + 307) * (976 + 23) = 29.974 fps
Tweak the defaults to get closer to 30 fps:
48000000 / ((1296 + 308) * (976 + 21) = 30.015 fps
This improves things from being 0.026 fps too low to 0.015 fps too high.
Signed-off-by Hans de Goede <[email protected]>
Quoted 19 lines
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/i2c/mt9m114.c +2
-2@@ -331,8 +331,8 @@*/ #define MT9M114_MIN_HBLANK 303#define MT9M114_MIN_VBLANK 21 -#define MT9M114_DEF_HBLANK 307 -#define MT9M114_DEF_VBLANK 23 +#define MT9M114_DEF_HBLANK 308 +#define MT9M114_DEF_VBLANK 21#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 7/13 media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
In reply to Hans de GoedeUpdate hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
--- drivers/media/i2c/mt9m114.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/media/i2c/mt9m114.c +11 -3
@@ -333,6 +333,10 @@#define MT9M114_MIN_VBLANK 21#define MT9M114_DEF_HBLANK 308#define MT9M114_DEF_VBLANK 21 +#define MT9M114_DEF_HTS \ + (MT9M114_PIXEL_ARRAY_WIDTH + MT9M114_DEF_HBLANK) +#define MT9M114_DEF_VTS \ + (MT9M114_PIXEL_ARRAY_HEIGHT + MT9M114_DEF_VBLANK)#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120
@@ -1130,18 +1134,22 @@ static void mt9m114_pa_ctrl_update_exposure(struct mt9m114 *sensor, bool manual)static void mt9m114_pa_ctrl_update_blanking (struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format) { -unsigned int max_blank; +unsigned int def_blank, max_blank;/* Update the blanking controls ranges based on the output size. */ max_blank =MT9M114_CAM_SENSOR_CFG_LINE_LENGTH_PCK_MAX - format->width; + def_blank =MT9M114_DEF_HTS - format->width;__v4l2_ctrl_modify_range (sensor->pa.hblank,MT9M114_MIN_HBLANK , - max_blank,1 ,MT9M114_DEF_HBLANK ); + max_blank,1 , def_blank); +__v4l2_ctrl_s_ctrl (sensor->pa.hblank, def_blank); max_blank =MT9M114_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_MAX - format->height; + def_blank =MT9M114_DEF_VTS - format->height;__v4l2_ctrl_modify_range (sensor->pa.vblank,MT9M114_MIN_VBLANK , - max_blank,1 ,MT9M114_DEF_VBLANK ); + max_blank,1 , def_blank); +__v4l2_ctrl_s_ctrl (sensor->pa.vblank, def_blank); }/* -----------------------------------------------------------------------------
Signature · 1 line
2.49.0
Laurent Pinchart
maintainerRe: [PATCH 07/13] media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
Hi Hans,
Thank you for the patch.
Quoted 2 lines · Hans de Goede
Update hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
I don't think this should be the kernel's responsibility to do so. Sakari, any opinion ?
Quoted 46 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m114.c +11
-3@@ -333,6 +333,10 @@#define MT9M114_MIN_VBLANK 21#define MT9M114_DEF_HBLANK 308#define MT9M114_DEF_VBLANK 21 +#define MT9M114_DEF_HTS \ + (MT9M114_PIXEL_ARRAY_WIDTH + MT9M114_DEF_HBLANK) +#define MT9M114_DEF_VTS \ + (MT9M114_PIXEL_ARRAY_HEIGHT + MT9M114_DEF_VBLANK)#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120@@ -1130,18 +1134,22 @@ static void mt9m114_pa_ctrl_update_exposure(struct mt9m114 *sensor, bool manual)static void mt9m114_pa_ctrl_update_blanking (struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format) { -unsigned int max_blank; +unsigned int def_blank, max_blank;/* Update the blanking controls ranges based on the output size. */ max_blank =MT9M114_CAM_SENSOR_CFG_LINE_LENGTH_PCK_MAX - format->width; + def_blank =MT9M114_DEF_HTS - format->width;__v4l2_ctrl_modify_range (sensor->pa.hblank,MT9M114_MIN_HBLANK , - max_blank,1 ,MT9M114_DEF_HBLANK ); + max_blank,1 , def_blank); +__v4l2_ctrl_s_ctrl (sensor->pa.hblank, def_blank); max_blank =MT9M114_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_MAX - format->height; + def_blank =MT9M114_DEF_VTS - format->height;__v4l2_ctrl_modify_range (sensor->pa.vblank,MT9M114_MIN_VBLANK , - max_blank,1 ,MT9M114_DEF_VBLANK ); + max_blank,1 , def_blank); +__v4l2_ctrl_s_ctrl (sensor->pa.vblank, def_blank); }/* -----------------------------------------------------------------------------
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH 07/13] media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
Hi Laurent,
Quoted 10 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 2 lines · Hans de Goede
Update hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
I don't think this should be the kernel's responsibility to do so. Sakari, any opinion ?
Generally drivers don't do this indeed. It's the user space's resposibility to configure the frame rate. Drivers only guarantee hardware limits are respected.
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH 07/13] media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
Hi,
Quoted 11 lines · Sakari Ailus
Hi Laurent,
Quoted 8 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 2 lines · Hans de Goede
Update hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
Quoted 6 lines
Quoted 2 lines
I don't think this should be the kernel's responsibility to do so. Sakari, any opinion ?
Generally drivers don't do this indeed. It's the user space's resposibility to configure the frame rate. Drivers only guarantee hardware limits are respected.
Ok, I'll drop this patch for v2.
Laurent, thank you for all the reviews so far. I agree with all your remarks and I'll address them for v2.
I notice that you did not review 10/13 - 12/13 yet, I guess you ran out of time ? Also I guess 10/13 is possibly a bit controversial patch, all I can say about that is that this one is necessary to make things work in raw-bayer mode with the atomisp.
Regards,
Hans
Laurent Pinchart
maintainerRe: [PATCH 07/13] media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
Quoted 21 lines · Hans de Goede
Hi,
Quoted 11 lines · Sakari Ailus
Hi Laurent,
Quoted 8 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 2 lines · Hans de Goede
Update hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
Quoted 6 lines
Quoted 2 lines
I don't think this should be the kernel's responsibility to do so. Sakari, any opinion ?
Generally drivers don't do this indeed. It's the user space's resposibility to configure the frame rate. Drivers only guarantee hardware limits are respected.
Quoted 7 lines
Ok, I'll drop this patch for v2.
Laurent, thank you for all the reviews so far. I agree with all your remarks and I'll address them for v2.
I notice that you did not review 10/13 - 12/13 yet, I guess you ran out of time ?
Yes I ran out of time, and next week will likely be busy. Feel free to send a v2 addressing the review comments so far, and I can review patchs 10/13to 12/13 from there.
Quoted 7 lines
Also I guess 10/13 is possibly a bit
controversial patch, all I can say about that is that this one is necessary to make things work in raw-bayer mode with the atomisp.Regards,
Hans
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH 07/13] media: mt9m114: Update hblank and vblank defaults on pixel-array format changes
In reply to Hans de GoedeHi Hans,
Quoted 27 lines · Hans de Goede
Update hblank and vblank defaults when the pixel-array format changes, to maintain 30 fps on format changes.
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m114.c +4
-0@@ -333,6 +333,10 @@#define MT9M114_MIN_VBLANK 21#define MT9M114_DEF_HBLANK 308#define MT9M114_DEF_VBLANK 21 +#define MT9M114_DEF_HTS \ + (MT9M114_PIXEL_ARRAY_WIDTH + MT9M114_DEF_HBLANK) +#define MT9M114_DEF_VTS \ + (MT9M114_PIXEL_ARRAY_HEIGHT + MT9M114_DEF_VBLANK)#define MT9M114_DEF_FRAME_RATE 30#define MT9M114_MAX_FRAME_RATE 120@@ -1130,18 +1134,22 @@ static void mt9m114_pa_ctrl_update_exposure(struct mt9m114 *sensor, bool manual)static void mt9m114_pa_ctrl_update_blanking (struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format) {
drivers/media/i2c/mt9m114.c static void mt9m114_pa_ctrl_update_exposure(struct mt9m114 *sensor, bool manual) · line 1144
Quoted 10 lines
drivers/media/i2c/mt9m114.c +3
-2-unsigned int max_blank; +unsigned int def_blank, max_blank;/* Update the blanking controls ranges based on the output size. */ max_blank =MT9M114_CAM_SENSOR_CFG_LINE_LENGTH_PCK_MAX - format->width; + def_blank =MT9M114_DEF_HTS - format->width;__v4l2_ctrl_modify_range (sensor->pa.hblank,MT9M114_MIN_HBLANK , - max_blank,1 ,MT9M114_DEF_HBLANK ); + max_blank,1 , def_blank);
__v4l2_ctrl_modify_range() may fail.
The problem isn't introduced by this patch but it'd be nice to fix it (separately).
Quoted 12 lines
drivers/media/i2c/mt9m114.c +4
-1+__v4l2_ctrl_s_ctrl (sensor->pa.hblank, def_blank); max_blank =MT9M114_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_MAX - format->height; + def_blank =MT9M114_DEF_VTS - format->height;__v4l2_ctrl_modify_range (sensor->pa.vblank,MT9M114_MIN_VBLANK , - max_blank,1 ,MT9M114_DEF_VBLANK ); + max_blank,1 , def_blank); +__v4l2_ctrl_s_ctrl (sensor->pa.vblank, def_blank); }/* -----------------------------------------------------------------------------
Signature · 3 lines
Regards, Sakari Ailus
PATCH 8/13 media: mt9m114: Avoid a reset low spike during probe()
In reply to Hans de Goedemt9m114_probe() requests the reset GPIO in output low state:
sensor->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
and then almost immediately afterwards calls mt9m114_power_on() which does:
gpiod_set_value(sensor->reset, 1); fsleep(duration); gpiod_set_value(sensor->reset, 0);
which means that if the reset pin was high before this code runs that it will very briefly be driven low because of passing GPIOD_OUT_LOW when requesting the GPIO only to be driven high again possibly directly after that. Such a very brief driving low of the reset pin may put the chip in a confused state.
Request the GPIO in high (reset the chip) state instead to avoid this, turning the initial gpiod_set_value() in mt9m114_power_on() into a no-op. and the fsleep() ensures that it will stay high long enough to properly reset the chip.
--- drivers/media/i2c/mt9m114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +1 -1
@@ -2412,7 +2412,7 @@ static int mt9m114_probe(struct i2c_client *client) } } - sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH );if (IS_ERR (sensor->reset)) { ret =PTR_ERR (sensor->reset);dev_err_probe (dev, ret,"Failed to get reset GPIO\n" );
Signature · 1 line
2.49.0
Re: [PATCH 08/13] media: mt9m114: Avoid a reset low spike during probe()
Hi Hans,
Thank you for the patch.
Quoted 16 lines · Hans de Goede
mt9m114_probe()requests the reset GPIO in output low state:sensor->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);and then almost immediately afterwards calls
mt9m114_power_on()which does:gpiod_set_value(sensor->reset, 1); fsleep(duration); gpiod_set_value(sensor->reset, 0);which means that if the reset pin was high before this code runs that it will very briefly be driven low because of passing
GPIOD_OUT_LOWwhen requesting the GPIO only to be driven high again possibly directly after that. Such a very brief driving low of the reset pin may put the chip in a confused state.
Quoted 6 lines
Request the GPIO in high (reset the chip) state instead to avoid this, turning the initial
gpiod_set_value()inmt9m114_power_on()into a no-op. and thefsleep()ensures that it will stay high long enough to properly reset the chip.Signed-off-by Hans de Goede <[email protected]>
Quoted 17 lines
--- drivers/media/i2c/mt9m114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/mt9m114.c +1
-1@@ -2412,7 +2412,7 @@ static int mt9m114_probe(struct i2c_client *client) } } - sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH );if (IS_ERR (sensor->reset)) { ret =PTR_ERR (sensor->reset);dev_err_probe (dev, ret,"Failed to get reset GPIO\n" );
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 9/13 media: mt9m114: Put sensor in reset on power-down
In reply to Hans de GoedePut sensor back in reset on power-down.
--- drivers/media/i2c/mt9m114.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/i2c/mt9m114.c +1 -0
@@ -2202,6 +2202,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)static void mt9m114_power_off (struct mt9m114 *sensor) { +gpiod_set_value (sensor->reset,1 );clk_disable_unprepare (sensor->clk);regulator_bulk_disable (ARRAY_SIZE (sensor->supplies), sensor->supplies); }
Signature · 1 line
2.49.0
Laurent Pinchart
maintainerRe: [PATCH 09/13] media: mt9m114: Put sensor in reset on power-down
Hi Hans,
Quoted 12 lines · Hans de Goede
Put sensor back in reset on power-down.
Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/mt9m114.c +0
-0
drivers/media/i2c/mt9m114.c static int mt9m114_power_on(struct mt9m114 *sensor) · line 2205
Quoted 4 lines
drivers/media/i2c/mt9m114.c +1
-0@@ -2202,6 +2202,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)static void mt9m114_power_off (struct mt9m114 *sensor) { +gpiod_set_value (sensor->reset,1 );
The sensor requires a delay of at least 10 EXTCLK cycles here.
Quoted 3 lines
drivers/media/i2c/mt9m114.c +0
-0clk_disable_unprepare (sensor->clk);regulator_bulk_disable (ARRAY_SIZE (sensor->supplies), sensor->supplies); }
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 10/13 media: mt9m114: Fix scaler bypass mode
In reply to Hans de GoedeAs indicated by the comment in mt9m114_ifp_set_fmt():
/* If the output format is RAW10, bypass the scaler. */ if (format->code == MEDIA_BUS_FMT_SGRBG10_1X10) ...
The intend of the driver is that the scalar is bypassed when the ISP source/output pad's pixel-format is set to MEDIA_BUS_FMT_SGRBG10_1X10.
This patch makes 2 changes which are required to get this to work properly:
1. Set the MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE bit in the MT9M114_CAM_OUTPUT_FORMAT register.
2. Disable cropping/composing by setting crop and compose selections on the ISP sink/input format to the format widthxheight @ 0x0.
--- drivers/media/i2c/mt9m114.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/media/i2c/mt9m114.c +26 -6
@@ -468,7 +468,8 @@ static const struct mt9m114_format_info mt9m114_format_infos[] = {/* Keep the format compatible with the IFP sink pad last. */ .code = MEDIA_BUS_FMT_SGRBG10_1X10, .output_format = MT9M114_CAM_OUTPUT_FORMAT_BAYER_FORMAT_RAWR10 - | MT9M114_CAM_OUTPUT_FORMAT_FORMAT_BAYER, + | MT9M114_CAM_OUTPUT_FORMAT_FORMAT_BAYER + | MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE, .flags = MT9M114_FMT_FLAG_PARALLEL | MT9M114_FMT_FLAG_CSI2, } };
@@ -796,7 +797,7 @@ static int mt9m114_configure(struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *ifp_format;const struct v4l2_rect *ifp_crop;const struct v4l2_rect *ifp_compose; -unsigned int hratio, vratio; +unsigned int border, hratio, vratio;u64 output_format;u64 read_mode;int ret =0 ;
@@ -856,10 +857,12 @@ static int mt9m114_configure(struct mt9m114 *sensor,* by demosaicing that are taken into account in the crop rectangle but * not in the hardware. */ + border = (ifp_format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) ?0 :4 ; +cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_XOFFSET , - ifp_crop->left -4 , &ret); + ifp_crop->left - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_YOFFSET , - ifp_crop->top -4 , &ret); + ifp_crop->top - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_WIDTH , ifp_crop->width, &ret); cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_HEIGHT,
@@ -898,7 +901,8 @@ static int mt9m114_configure(struct mt9m114 *sensor,MT9M114_CAM_OUTPUT_FORMAT_BAYER_FORMAT_MASK |MT9M114_CAM_OUTPUT_FORMAT_FORMAT_MASK |MT9M114_CAM_OUTPUT_FORMAT_SWAP_BYTES | - MT9M114_CAM_OUTPUT_FORMAT_SWAP_RED_BLUE); +MT9M114_CAM_OUTPUT_FORMAT_SWAP_RED_BLUE | + MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLE); output_format |= ifp_info->output_format; cci_write(sensor->regmap, MT9M114_CAM_OUTPUT_FORMAT,
@@ -1805,6 +1809,7 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, {struct mt9m114 *sensor =ifp_to_mt9m114 (sd);struct v4l2_mbus_framefmt *format; +struct v4l2_rect *crop; format =v4l2_subdev_state_get_format (state, fmt->pad);
@@ -1825,8 +1830,15 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, format->code = info->code;/* If the output format is RAW10, bypass the scaler. */ -if (format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) +if (format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) { *format = *v4l2_subdev_state_get_format (state,0 ); + crop =v4l2_subdev_state_get_crop (state,0 ); + crop->left =0 ; + crop->top =0 ; + crop->width = format->width; + crop->height = format->height; + *v4l2_subdev_state_get_compose (state,0 ) = *crop; + } } fmt->format = *format;
@@ -1846,6 +1858,10 @@ static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd,if (sel->pad !=0 )return -EINVAL ; +/* Crop and compose are not supported when bypassing the scaler */ +if (v4l2_subdev_state_get_format (state,1 )->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; +switch (sel->target) {case V4L2_SEL_TGT_CROP : sel->r = *v4l2_subdev_state_get_crop (state,0 );
@@ -1906,6 +1922,10 @@ static int mt9m114_ifp_set_selection(struct v4l2_subdev *sd,if (sel->pad !=0 )return -EINVAL ; +/* Crop and compose cannot be changed when bypassing the scaler */ +if (v4l2_subdev_state_get_format (state,1 )->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) +return -EINVAL ; + format =v4l2_subdev_state_get_format (state,0 ); crop =v4l2_subdev_state_get_crop (state,0 ); compose =v4l2_subdev_state_get_compose (state,0 );
Signature · 1 line
2.49.0
PATCH 11/13 media: mt9m114: Drop start-, stop-streaming sequence from initialize
In reply to Hans de GoedeDrop the start-, stop-streaming sequence from initialize.
When streaming is started with a runtime-suspended sensor, mt9m114_start_streaming() will runtime-resume the sensor which calls mt9m114_initialize() immediately followed by calling mt9m114_set_state(ENTER_CONFIG_CHANGE).
This results in the following state changes in quick succession:
mt9m114_set_state(ENTER_CONFIG_CHANGE) -> transitions to STREAMINGmt9m114_set_state(ENTER_SUSPEND) -> transitions to SUSPENDEDmt9m114_set_state(ENTER_CONFIG_CHANGE) -> transitions to STREAMING
these quick state changes confuses the CSI receiver on atomisp devices causing streaming to not work.
Drop the state changes from mt9m114_initialize() so that only a single mt9m114_set_state(ENTER_CONFIG_CHANGE) call is made when streaming is started with a runtime-suspend sensor.
This means that the sensor may have config changes pending when mt9m114_runtime_suspend() gets called the first time after mt9m114_probe(), when streaming was not started within the 1 second runtime-pm timeout. Keep track of this and do the ENTER_CONFIG_CHANGE + ENTER suspend from mt9m114_runtime_suspend() if necessary.
--- drivers/media/i2c/mt9m114.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/media/i2c/mt9m114.c +11 -8
@@ -391,6 +391,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;/* Pixel Array */ struct {
@@ -776,14 +777,7 @@ static int mt9m114_initialize(struct mt9m114 *sensor)if (ret <0 )return ret; - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_CONFIG_CHANGE ); -if (ret <0 ) -return ret; - - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_SUSPEND ); -if (ret <0 ) -return ret; - + sensor->config_change_pending = true;return 0 ; }
@@ -958,6 +952,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;
@@ -2251,6 +2246,14 @@ static int __maybe_unused mt9m114_runtime_suspend(struct device *dev)struct v4l2_subdev *sd =dev_get_drvdata (dev);struct mt9m114 *sensor =ifp_to_mt9m114 (sd); +if (sensor->config_change_pending) { +/* mt9m114_set_state() prints errors itself, no need to check */ +mt9m114_set_state (sensor, +MT9M114_SYS_STATE_ENTER_CONFIG_CHANGE ); +mt9m114_set_state (sensor, +MT9M114_SYS_STATE_ENTER_SUSPEND ); + } +mt9m114_power_off (sensor);return 0 ;
Signature · 1 line
2.49.0
PATCH 12/13 media: mt9m114: Return -EPROBE_DEFER if no endpoint is found
In reply to Hans de GoedeWith IPU# bridges, endpoints may only be created when the IPU bridge is initialized. This may happen after the sensor driver's first probe().
--- drivers/media/i2c/mt9m114.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/media/i2c/mt9m114.c +7 -4
@@ -2361,11 +2361,14 @@ static int mt9m114_parse_dt(struct mt9m114 *sensor)struct fwnode_handle *ep;int ret; +/* +* Sometimes the fwnode graph is initialized by the bridge driver, +* wait for this. +*/ ep =fwnode_graph_get_next_endpoint (fwnode,NULL ); -if (!ep) { -dev_err (&sensor->client->dev,"No endpoint found\n" ); -return -EINVAL ; - } +if (!ep) +return dev_err_probe (&sensor->client->dev, -EPROBE_DEFER , +"waiting for fwnode graph endpoint\n" ); sensor->bus_cfg.bus_type =V4L2_MBUS_UNKNOWN ; ret =v4l2_fwnode_endpoint_alloc_parse (ep, &sensor->bus_cfg);
Signature · 1 line
2.49.0
PATCH 13/13 media: mt9m114: Add ACPI enumeration support
In reply to Hans de GoedeAdd support for the mt9m114 sensor being enumerated through ACPI using the INT33F0 HID as found on the Asus T100TA.
--- drivers/media/i2c/mt9m114.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/media/i2c/mt9m114.c +7 -0
@@ -2556,11 +2556,18 @@ static const struct of_device_id mt9m114_of_ids[] = { };MODULE_DEVICE_TABLE (of, mt9m114_of_ids); +static const struct acpi_device_id mt9m114_acpi_ids[] = { + {"INT33F0" }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (acpi, mt9m114_acpi_ids); +static struct i2c_driver mt9m114_driver = { .driver = { .name ="mt9m114" , .pm = &mt9m114_pm_ops, .of_match_table = mt9m114_of_ids, + .acpi_match_table = mt9m114_acpi_ids, }, .probe = mt9m114_probe, .remove = mt9m114_remove,
Signature · 1 line
2.49.0
Re: [PATCH 13/13] media: mt9m114: Add ACPI enumeration support
Hi Hans,
Thank you for the patch.
Quoted 4 lines · Hans de Goede
Add support for the mt9m114 sensor being enumerated through ACPI using the INT33F0 HID as found on the Asus T100TA.
Signed-off-by Hans de Goede <[email protected]>
Quoted 27 lines
--- drivers/media/i2c/mt9m114.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/media/i2c/mt9m114.c +7
-0@@ -2556,11 +2556,18 @@ static const struct of_device_id mt9m114_of_ids[] = { };MODULE_DEVICE_TABLE (of, mt9m114_of_ids); +static const struct acpi_device_id mt9m114_acpi_ids[] = { + {"INT33F0" }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (acpi, mt9m114_acpi_ids); +static struct i2c_driver mt9m114_driver = { .driver = { .name ="mt9m114" , .pm = &mt9m114_pm_ops, .of_match_table = mt9m114_of_ids, + .acpi_match_table = mt9m114_acpi_ids, }, .probe = mt9m114_probe, .remove = mt9m114_remove,
Signature · 3 lines
Regards, Laurent Pinchart