media: mt9m114: Changes to make it work with atomisp devices
Subsystems (4)
v2 cover media: mt9m114: Changes to make it work with atomisp devices
Hi All,
Here is v2 of my series to make the "mainline" mt9m114 driver work on devices with an atomisp CSI2 receiver / ISP. This has been tested on an Asus T100TA.
Changes in v2:
- Rebase on top of sailus/media_tree.git/fixes which now has 4 of the patches from Mathis': "MT9M114 driver bugfix and improvements" series, this avoids most of the conlicts between the 2 series
- Add Laurent's Reviewed-by to some of the patches
- Add select VIDEO_APTINA_PLL to Kconfig
- Use correct aptina_pll_limits
- After setting reset high wait 20 clk cycles before disabling the clk and regulators
- When bypassing the scalar make ifp_get_selection() / ifp_set_selection() fill sel->r with a rectangle of (0,0)/wxh and return 0 instead of returning -EINVAL
Regards,
Hans
Hans de Goede (12):
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: 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/Kconfig | 1 + drivers/media/i2c/aptina-pll.c | 2 + drivers/media/i2c/mt9m114.c | 166 ++++++++++++++++++++++++--------- 3 files changed, 127 insertions(+), 42 deletions(-)
base-commit: 2a8e220f6a2bcd5828ab67c7cf194874590ede24
Signature · 1 line
2.49.0
PATCH v2 1/12 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
PATCH v2 2/12 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.
---
Note as discussed during review of v1, this needs to be moved over to the solution from:
https://lore.kernel.org/r/[email protected]
once that has landed upstream. I'll submit a follow-up patch to move to that solution once it has landed upstream.
--- drivers/media/i2c/mt9m114.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/media/i2c/mt9m114.c +17 -5
@@ -388,6 +388,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +u32 clk_freq;/* Pixel Array */ struct {
@@ -2134,14 +2135,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);
@@ -2279,7 +2279,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor)* Check if EXTCLK fits the configured link frequency. Bypass the PLL * in this case. */ - pixrate =clk_get_rate (sensor->clk) /2 ; + pixrate = sensor->clk_freq /2 ;if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = true;
@@ -2287,7 +2287,7 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ - pixrate =clk_get_rate (sensor->clk) * sensor->pll.m + pixrate = sensor->clk_freq * sensor->pll.m / ((sensor->pll.n +1 ) * (sensor->pll.p +1 ));if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate;
@@ -2395,13 +2395,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
PATCH v2 3/12 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.
---
Changes in v2:
- Add select VIDEO_APTINA_PLL to Kconfig
- Use correct aptina_pll_limits
--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/media/i2c/Kconfig +1 -0
@@ -285,6 +285,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" select V4L2_CCI_I2C + select VIDEO_APTINA_PLL help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114 camera.
drivers/media/i2c/mt9m114.c +39 -15
105 lines not on this page · raw message
Signature · 1 line
2.49.0
Laurent Pinchart
maintainerRe: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Hans,
Thank you for the patch.
Quoted 101 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)drivers/media/i2c/Kconfig +1
-0@@ -285,6 +285,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" select V4L2_CCI_I2C + select VIDEO_APTINA_PLL help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114 camera.drivers/media/i2c/mt9m114.c +9
-9@@ -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)@@ -263,9 +265,9 @@#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)#define MT9M114_CAM_SYSCTL_PLL_DISABLE_VALUE 0x00#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)@@ -326,7 +328,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@@ -336,6 +338,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@@ -380,11 +384,7 @@ struct mt9m114 {struct v4l2_fwnode_endpoint bus_cfg;bool bypass_pll; -struct { -unsigned int m; -unsigned int n; -unsigned int p; - } pll; +struct aptina_pll pll;unsigned int pixrate;bool streaming;@@ -757,7 +757,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), +MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p1), &ret); }@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {
drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers.
s/then/than/
Is that an issue though ? Does it prevent the sensor from working ?
Quoted 38 lines
drivers/media/i2c/mt9m114.c +20
-6+*/ + .out_clock_min = 180000000, + .out_clock_max = 400000000, + .pix_clock_max = 48000000, + .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 192, + .p1_min = 1, + .p1_max = 64, + };unsigned int pixrate; - -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; +int ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2287,8 +2304,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ + 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; + pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1);if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = false;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Laurent,
Quoted 119 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 101 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)drivers/media/i2c/Kconfig +1
-0@@ -285,6 +285,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" select V4L2_CCI_I2C + select VIDEO_APTINA_PLL help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114 camera.drivers/media/i2c/mt9m114.c +9
-9@@ -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)@@ -263,9 +265,9 @@#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)#define MT9M114_CAM_SYSCTL_PLL_DISABLE_VALUE 0x00#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)@@ -326,7 +328,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@@ -336,6 +338,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@@ -380,11 +384,7 @@ struct mt9m114 {struct v4l2_fwnode_endpoint bus_cfg;bool bypass_pll; -struct { -unsigned int m; -unsigned int n; -unsigned int p; - } pll; +struct aptina_pll pll;unsigned int pixrate;bool streaming;@@ -757,7 +757,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), +MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p1), &ret); }@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers. s/then/than/
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
Regards,
Hans
Quoted 39 lines
Quoted 38 lines
drivers/media/i2c/mt9m114.c +20
-6+*/ + .out_clock_min = 180000000, + .out_clock_max = 400000000, + .pix_clock_max = 48000000, + .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 192, + .p1_min = 1, + .p1_max = 64, + };unsigned int pixrate; - -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; +int ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2287,8 +2304,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ + 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; + pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1);if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = false;
Laurent Pinchart
maintainerRe: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Quoted 116 lines · Hans de Goede
Quoted 115 lines · Laurent Pinchart
Quoted 101 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)drivers/media/i2c/Kconfig +1
-0@@ -285,6 +285,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" select V4L2_CCI_I2C + select VIDEO_APTINA_PLL help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114 camera.drivers/media/i2c/mt9m114.c +9
-9@@ -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)@@ -263,9 +265,9 @@#define MT9M114_CAM_SYSCTL_PLL_ENABLE_VALUE BIT(0)#define MT9M114_CAM_SYSCTL_PLL_DISABLE_VALUE 0x00#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)@@ -326,7 +328,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@@ -336,6 +338,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@@ -380,11 +384,7 @@ struct mt9m114 {struct v4l2_fwnode_endpoint bus_cfg;bool bypass_pll; -struct { -unsigned int m; -unsigned int n; -unsigned int p; - } pll; +struct aptina_pll pll;unsigned int pixrate;bool streaming;@@ -757,7 +757,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), +MT9M114_CAM_SYSCTL_PLL_DIVIDER_P_VALUE (sensor->pll.p1), &ret); }@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers. s/then/than/
Quoted 4 lines
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Sometimes there are multiple options without any practical differences. I wouldn't necessarily assume we have to follow the hardcoded register values. Can you share the two PLL configurations ?
Quoted 2 lines
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
This sensor is rather old and not widely used. If using the correct limits doesn't cause issues on platforms we can test, that's good enough for me. We can always address problems later if any arise.
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
drivers/media/i2c/mt9m114.c +20
-6+*/ + .out_clock_min = 180000000, + .out_clock_max = 400000000, + .pix_clock_max = 48000000, + .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 192, + .p1_min = 1, + .p1_max = 64, + };unsigned int pixrate; - -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; +int ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2287,8 +2304,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ + 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; + pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1);if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = false;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Laurent,
Quoted 22 lines · Laurent Pinchart
Quoted 21 lines · Hans de Goede
Quoted 20 lines · Laurent Pinchart
Quoted 19 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)
...
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/media/i2c/mt9m114.c +2
-0@@ -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)
...
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-0@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers. s/then/than/
Quoted 4 lines
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Sometimes there are multiple options without any practical differences. I wouldn't necessarily assume we have to follow the hardcoded register values. Can you share the two PLL configurations ?
Quoted 6 lines
Quoted 2 lines
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
This sensor is rather old and not widely used. If using the correct limits doesn't cause issues on platforms we can test, that's good enough for me. We can always address problems later if any arise.
Ok, so I've tried setting out_clock_max to 768MHz, but that results in PLL setting which cause the sensor to fail to stream.
So this should be kept at 400, I'll update the comment to reflect that the datasheet says 768 but that that does not work.
Regards,
Hans
Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
drivers/media/i2c/mt9m114.c +20
-6+*/ + .out_clock_min = 180000000, + .out_clock_max = 400000000, + .pix_clock_max = 48000000, + .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 192, + .p1_min = 1, + .p1_max = 64, + };unsigned int pixrate; - -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; +int ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2287,8 +2304,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ + 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; + pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1);if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = false;
Laurent Pinchart
maintainerRe: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Hans,
Quoted 71 lines · Hans de Goede
Quoted 22 lines · Laurent Pinchart
Quoted 21 lines · Hans de Goede
Quoted 20 lines · Laurent Pinchart
Quoted 19 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)...
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/media/i2c/mt9m114.c +2
-0@@ -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)...
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-0@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers. s/then/than/
Quoted 4 lines
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Sometimes there are multiple options without any practical differences. I wouldn't necessarily assume we have to follow the hardcoded register values. Can you share the two PLL configurations ?
Quoted 2 lines
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
Quoted 6 lines
Quoted 3 lines
This sensor is rather old and not widely used. If using the correct limits doesn't cause issues on platforms we can test, that's good enough for me. We can always address problems later if any arise.
Ok, so I've tried setting
out_clock_maxto 768MHz, but that results in PLL setting which cause the sensor to fail to stream.
Thank you for testing.
Could you share the PLL configuration you obtain with the 400 MHz and 768 MHz limits ?
Quoted 41 lines
So this should be kept at 400, I'll update the comment to reflect that the datasheet says 768 but that that does not work.
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
drivers/media/i2c/mt9m114.c +20
-6+*/ + .out_clock_min = 180000000, + .out_clock_max = 400000000, + .pix_clock_max = 48000000, + .n_min = 1, + .n_max = 64, + .m_min = 16, + .m_max = 192, + .p1_min = 1, + .p1_max = 64, + };unsigned int pixrate; - -/* Hardcode the PLL multiplier and dividers to default settings. */ - sensor->pll.m =32 ; - sensor->pll.n =1 ; - sensor->pll.p =7 ; +int ret;/* * Calculate the pixel rate and link frequency. The CSI-2 bus is clocked @@ -2287,8 +2304,15 @@ static int mt9m114_clk_init(struct mt9m114 *sensor) }/* Check if the PLL configuration fits the configured link frequency. */ + 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; + pixrate = sensor->clk_freq * sensor->pll.m - / ((sensor->pll.n +1 ) * (sensor->pll.p +1 )); + / (sensor->pll.n * sensor->pll.p1);if (mt9m114_verify_link_frequency (sensor, pixrate) ==0 ) { sensor->pixrate = pixrate; sensor->bypass_pll = false;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Laurent,
Quoted 26 lines · Laurent Pinchart
Hi Hans,
Quoted 23 lines · Hans de Goede
Quoted 22 lines · Laurent Pinchart
Quoted 21 lines · Hans de Goede
Quoted 20 lines · Laurent Pinchart
Quoted 19 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)
...
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-0@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor,static int mt9m114_clk_init (struct mt9m114 *sensor) {drivers/media/i2c/mt9m114.c static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
drivers/media/i2c/mt9m114.c +10
-0+static const struct aptina_pll_limits limits = { + .ext_clock_min =6000000 , + .ext_clock_max =54000000 , +/* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min =2000000 , + .int_clock_max =13500000 , +/* +* out_clock_min is not documented, taken from mt9p031.c. +* out_clock_max is documented as 768MHz, but this leads to +* different PLL settings then used by the vendor's drivers. s/then/than/
Quoted 4 lines
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Sometimes there are multiple options without any practical differences. I wouldn't necessarily assume we have to follow the hardcoded register values. Can you share the two PLL configurations ?
Quoted 2 lines
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
This sensor is rather old and not widely used. If using the correct limits doesn't cause issues on platforms we can test, that's good enough for me. We can always address problems later if any arise.
Quoted 7 lines
Quoted 2 lines
Ok, so I've tried setting
out_clock_maxto 768MHz, but that results in PLL setting which cause the sensor to fail to stream.Thank you for testing.
Could you share the PLL configuration you obtain with the 400 MHz and 768 MHz limits ?
400 MHz out_clock_max, working setup:
[ 40.136435] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 40.136453] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 40.136463] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 8 [ 40.136473] mt9m114 i2c-INT33F0:00: PLL: N 2 M 40 P1 8
768 MHz non working setup:
[ 28.388940] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 28.388955] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 28.388966] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 16 [ 28.388976] mt9m114 i2c-INT33F0:00: PLL: N 2 M 80 P1 16
Regards,
Hans
Laurent Pinchart
maintainerRe: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Quoted 76 lines · Hans de Goede
Quoted 24 lines · Laurent Pinchart
Quoted 23 lines · Hans de Goede
Quoted 22 lines · Laurent Pinchart
Quoted 21 lines · Hans de Goede
Quoted 20 lines · Laurent Pinchart
Quoted 19 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]>---
Changes in v2:
- Add selectVIDEO_APTINA_PLLtoKconfig
- Use correctaptina_pll_limits--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/mt9m114.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-)...
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -2262,12 +2262,29 @@ static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, static int mt9m114_clk_init(struct mt9m114 *sensor) {Review static int mt9m114_verify_link_frequency(struct mt9m114 *sensor, · line 2274
Quoted 10 lines
(quoted diff) +10
-0+ static const struct aptina_pll_limits limits = { + .ext_clock_min = 6000000, + .ext_clock_max = 54000000, + /* int_clock_* limits are not documented taken from mt9p031.c */ + .int_clock_min = 2000000, + .int_clock_max = 13500000, + /* + * out_clock_min is not documented, taken from mt9p031.c. + * out_clock_max is documented as 768MHz, but this leads to + * different PLL settings then used by the vendor's drivers.s/then/than/
Quoted 4 lines
Quoted 1 line
Is that an issue though ? Does it prevent the sensor from working ?
I did not try. It seems safer to just stick with the tested / proven values from the older register-list based drivers?
Sometimes there are multiple options without any practical differences. I wouldn't necessarily assume we have to follow the hardcoded register values. Can you share the two PLL configurations ?
Quoted 2 lines
Even if it does work on my single mt9m114 sensor, that hardly constitutes testing on a representative sample.
This sensor is rather old and not widely used. If using the correct limits doesn't cause issues on platforms we can test, that's good enough for me. We can always address problems later if any arise.
Quoted 7 lines
Quoted 2 lines
Ok, so I've tried setting
out_clock_maxto 768MHz, but that results in PLL setting which cause the sensor to fail to stream.Thank you for testing.
Could you share the PLL configuration you obtain with the 400 MHz and 768 MHz limits ?
400 MHz
out_clock_max, working setup:[ 40.136435] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 40.136453] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 40.136463] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 8 [ 40.136473] mt9m114 i2c-INT33F0:00: PLL: N 2 M 40 P1 8
Quoted 6 lines
768 MHz non working setup:
[ 28.388940] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 28.388955] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 28.388966] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 16 [ 28.388976] mt9m114 i2c-INT33F0:00: PLL: N 2 M 80 P1 16
Hmmm...
Re-reading the documentation, I wonder if I had misunderstood the PLL.
There is no single clear description of the PLL (it would be too easy), but there's informatio scattered in multiple places. One of them states that
Fout = (Fin*2*m)/((n+1)*(p+1)).
Note the *2 multiplier. In another location, multiple frequencies are defined:
fSensor = (M x fin) / ((N + 1) x (P + 1)) (max 48 MHz) fWord = fSensor x 2 (max 96 MHz)
fBit = fWord * 8 (max 763 MHz)
The '+1' for N and P are understood, they relate to the values programmed in the registers. From the point of view of the PLL calculator, we should reason with that offset, with
Fout = (Fin*2*m)/(n*p).
and
fSensor = (M x fin) / (N x P)
This leads me to believe that the PLL is organized as follows:
+-----+ +-----+ +-----+ +-----+ +-----+
Fin --> | / N | --> | x M | --> | x 2 | --> | / P | --> | / 2 | -->
+-----+ +-----+ +-----+ +-----+ +-----+
fBit fWord fSensor
ext_clock int_clock out_clock pix_clockSeen this way, the maximum limit for out_clock should be 384 MHz, and the P factor should be hardcoded to 8 for CSI-2 output.
Does that make sense to you ?
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Laurent,
First of all sorry for dropping the ball on this series.
I'm preparing a v4 of this series now.
Quoted 1 line · Laurent Pinchart
On Sat, Jun 28, 2025 at 11:27:23AM +0200, Hans de Goede wrote:
...
Quoted 52 lines
Quoted 10 lines
Quoted 2 lines
Could you share the PLL configuration you obtain with the 400 MHz and 768 MHz limits ?
400 MHz
out_clock_max, working setup:[ 40.136435] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 40.136453] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 40.136463] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 8 [ 40.136473] mt9m114 i2c-INT33F0:00: PLL: N 2 M 40 P1 8Quoted 6 lines
768 MHz non working setup:
[ 28.388940] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 28.388955] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 28.388966] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 16 [ 28.388976] mt9m114 i2c-INT33F0:00: PLL: N 2 M 80 P1 16Hmmm...
Re-reading the documentation, I wonder if I had misunderstood the PLL.
There is no single clear description of the PLL (it would be too easy), but there's informatio scattered in multiple places. One of them states that
Fout = (Fin*2*m)/((n+1)*(p+1)).
Note the *2 multiplier. In another location, multiple frequencies are defined:
fSensor = (M x fin) / ((N + 1) x (P + 1)) (max 48 MHz) fWord = fSensor x 2 (max 96 MHz)
fBit = fWord * 8 (max 763 MHz)The '+1' for N and P are understood, they relate to the values programmed in the registers. From the point of view of the PLL calculator, we should reason with that offset, with
Fout = (Fin*2*m)/(n*p).
and
fSensor = (M x fin) / (N x P)
This leads me to believe that the PLL is organized as follows:
+-----+ +-----+ +-----+ +-----+ +-----+ Fin --> | / N | --> | x M | --> | x 2 | --> | / P | --> | / 2 | --> +-----+ +-----+ +-----+ +-----+ +-----+ fBit fWord fSensor ext_clock int_clock out_clock pix_clock
Quoted 4 lines
Seen this way, the maximum limit for
out_clockshould be 384 MHz, and the P factor should be hardcoded to 8 for CSI-2 output.Does that make sense to you ?
Yes that sounds right and setting out_clock_max to 384MHz works.
I've set out_clock_max to 384MH and limited P to min = max = 8 for the upcoming v4 of this series.
Regards,
Hans
Laurent Pinchart
maintainerRe: [PATCH v2 03/12] media: mt9m114: Use aptina-PLL helper to get PLL values
Hi Hans,
Quoted 3 lines · Hans de Goede
Hi Laurent,
First of all sorry for dropping the ball on this series.
I won't blame you, it happens to me way too often too.
Quoted 58 lines
I'm preparing a v4 of this series now.
Quoted 1 line · Laurent Pinchart
On Sat, Jun 28, 2025 at 11:27:23AM +0200, Hans de Goede wrote:
...
Quoted 51 lines
Quoted 10 lines
Quoted 2 lines
Could you share the PLL configuration you obtain with the 400 MHz and 768 MHz limits ?
400 MHz
out_clock_max, working setup:[ 40.136435] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 40.136453] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 40.136463] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 8 [ 40.136473] mt9m114 i2c-INT33F0:00: PLL: N 2 M 40 P1 8Quoted 6 lines
768 MHz non working setup:
[ 28.388940] mt9m114 i2c-INT33F0:00: PLL: ext clock 19200000 pix clock 48000000 [ 28.388955] mt9m114 i2c-INT33F0:00: pll: mf min 4 max 38 [ 28.388966] mt9m114 i2c-INT33F0:00: pll: p1 min 4 max 16 [ 28.388976] mt9m114 i2c-INT33F0:00: PLL: N 2 M 80 P1 16Hmmm...
Re-reading the documentation, I wonder if I had misunderstood the PLL.
There is no single clear description of the PLL (it would be too easy), but there's informatio scattered in multiple places. One of them states that
Fout = (Fin*2*m)/((n+1)*(p+1)).
Note the *2 multiplier. In another location, multiple frequencies are defined:
fSensor = (M x fin) / ((N + 1) x (P + 1)) (max 48 MHz) fWord = fSensor x 2 (max 96 MHz)
fBit = fWord * 8 (max 763 MHz)The '+1' for N and P are understood, they relate to the values programmed in the registers. From the point of view of the PLL calculator, we should reason with that offset, with
Fout = (Fin*2*m)/(n*p).
and
fSensor = (M x fin) / (N x P)
This leads me to believe that the PLL is organized as follows:
+-----+ +-----+ +-----+ +-----+ +-----+ Fin --> | / N | --> | x M | --> | x 2 | --> | / P | --> | / 2 | --> +-----+ +-----+ +-----+ +-----+ +-----+ fBit fWord fSensor ext_clock int_clock out_clock pix_clock
Could you capture this in a comment in v4 ?
Quoted 9 lines
Quoted 4 lines
Seen this way, the maximum limit for
out_clockshould be 384 MHz, and the P factor should be hardcoded to 8 for CSI-2 output.Does that make sense to you ?
Yes that sounds right and setting
out_clock_maxto 384MHz works.I've set
out_clock_maxto 384MH and limited P to min = max = 8 for the upcoming v4 of this series.
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v2 4/12 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
@@ -325,13 +325,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
PATCH v2 5/12 media: mt9m114: Fix default hblank and vblank values
In reply to Hans de GoedeThe current default hblank and vblank values are 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.
---
Changes in v2:
- Update comment about resolution / pixrate / FPS to:
* Set the default to achieve full resolution (1296x976 analog crop
* rectangle, 1280x960 output size) at 30fps with a 48 MHz pixclock.
--- drivers/media/i2c/mt9m114.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/mt9m114.c +4 -3
@@ -328,12 +328,13 @@* 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 full resolution (1296x976 analog crop +* rectangle, 1280x960 output size) 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
PATCH v2 6/12 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 current 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
@@ -333,8 +333,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
PATCH v2 7/12 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
@@ -2439,7 +2439,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
PATCH v2 8/12 media: mt9m114: Put sensor in reset on power-down
In reply to Hans de GoedePut sensor back in reset on power-down.
---
Changes in v2
- After setting reset high wait 20 clk cycles before disabling the clk and regulators
--- drivers/media/i2c/mt9m114.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/media/i2c/mt9m114.c +7 -0
@@ -2207,6 +2207,13 @@ static int mt9m114_power_on(struct mt9m114 *sensor)static void mt9m114_power_off (struct mt9m114 *sensor) { +unsigned int duration; + +gpiod_set_value (sensor->reset,1 ); +/* Power off takes 10 clock cycles. Double it to be safe. */ + duration =DIV_ROUND_UP (2 *10 *1000000 , sensor->clk_freq); +fsleep (duration); +clk_disable_unprepare (sensor->clk);regulator_bulk_disable (ARRAY_SIZE (sensor->supplies), sensor->supplies); }
Signature · 1 line
2.49.0
Re: [PATCH v2 08/12] media: mt9m114: Put sensor in reset on power-down
Hi Hans,
Thank you for the patch.
Quoted 1 line · Hans de Goede
Put sensor back in reset on power-down.
The commit message should explain why. With that,
Quoted 27 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2
- After setting reset high wait 20 clk cycles before disabling the clk and regulators--- drivers/media/i2c/mt9m114.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/media/i2c/mt9m114.c +7
-0@@ -2207,6 +2207,13 @@ static int mt9m114_power_on(struct mt9m114 *sensor)static void mt9m114_power_off (struct mt9m114 *sensor) { +unsigned int duration; + +gpiod_set_value (sensor->reset,1 ); +/* Power off takes 10 clock cycles. Double it to be safe. */ + duration =DIV_ROUND_UP (2 *10 *1000000 , sensor->clk_freq); +fsleep (duration); +clk_disable_unprepare (sensor->clk);regulator_bulk_disable (ARRAY_SIZE (sensor->supplies), sensor->supplies); }
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v2 9/12 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.
---
Changes in v2:
- When bypassing the scalar make ifp_get_selection() / ifp_set_selection() fill sel->r with a rectangle of (0,0)/wxh and return 0 instead of returning -EINVAL
--- drivers/media/i2c/mt9m114.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)
drivers/media/i2c/mt9m114.c +30 -5
@@ -467,7 +467,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, } };
@@ -850,6 +851,7 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format;const struct v4l2_rect *crop;const struct v4l2_rect *compose; +unsigned int border;u64 output_format;int ret =0 ;
@@ -869,10 +871,12 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,* by demosaicing that are taken into account in the crop rectangle but * not in the hardware. */ + border = (format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) ?0 :4 ; +cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_XOFFSET , - crop->left -4 , &ret); + crop->left - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_YOFFSET , - crop->top -4 , &ret); + crop->top - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_WIDTH , crop->width, &ret); cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_HEIGHT,
@@ -911,7 +915,8 @@ static int mt9m114_configure_ifp(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 |= info->output_format; cci_write(sensor->regmap, MT9M114_CAM_OUTPUT_FORMAT,
@@ -1810,6 +1815,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);
@@ -1830,8 +1836,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;
@@ -1851,6 +1864,12 @@ static int mt9m114_ifp_get_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 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + } +switch (sel->target) {case V4L2_SEL_TGT_CROP : sel->r = *v4l2_subdev_state_get_crop (state,0 );
@@ -1911,6 +1930,12 @@ 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 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + } + 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
Laurent Pinchart
maintainerRe: [PATCH v2 09/12] media: mt9m114: Fix scaler bypass mode
Hi Hans,
Thank you for the patch.
Quoted 6 lines · Hans de Goede
As 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) ...
Quoted 7 lines
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_DISABLEbit in theMT9M114_CAM_OUTPUT_FORMATregister.
Does that bit actually make a difference ? It's documented as only being effective when MT9M114_CAM_OUTPUT_FORMAT_BT656_ENABLE is also set, and the driver never sets that.
Quoted 37 lines
2. Disable cropping/composing by setting crop and compose selections on the ISP sink/input format to the format widthxheight @
0x0.Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- When bypassing the scalar makeifp_get_selection()/ifp_set_selection()fillsel->rwith a rectangle of (0,0)/wxh and return 0 instead of returning-EINVAL--- drivers/media/i2c/mt9m114.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)drivers/media/i2c/mt9m114.c +3
-1@@ -467,7 +467,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, } };@@ -850,6 +851,7 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format;const struct v4l2_rect *crop;const struct v4l2_rect *compose; +unsigned int border;u64 output_format;int ret =0 ;
drivers/media/i2c/mt9m114.c static int mt9m114_configure_ifp(struct mt9m114 *sensor, · line 873
Quoted 3 lines
drivers/media/i2c/mt9m114.c +0
-0@@ -869,10 +871,12 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,* by demosaicing that are taken into account in the crop rectangle but * not in the hardware. */
The comment should be updated.
drivers/media/i2c/mt9m114.c static int mt9m114_configure_ifp(struct mt9m114 *sensor, · line 874
Quoted 1 line
drivers/media/i2c/mt9m114.c +1
-0+ border = (format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) ?0 :4 ;
No need for parentheses.
Quoted 32 lines
drivers/media/i2c/mt9m114.c +6
-3+cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_XOFFSET , - crop->left -4 , &ret); + crop->left - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_YOFFSET , - crop->top -4 , &ret); + crop->top - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_WIDTH , crop->width, &ret); cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_HEIGHT,@@ -911,7 +915,8 @@ static int mt9m114_configure_ifp(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 |= info->output_format; cci_write(sensor->regmap, MT9M114_CAM_OUTPUT_FORMAT,@@ -1810,6 +1815,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);@@ -1830,8 +1836,15 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, format->code = info->code;/* If the output format is RAW10, bypass the scaler. */
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, · line 1847
Quoted 10 lines
drivers/media/i2c/mt9m114.c +8
-1-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; + }
This one is annoying. Normally changing a format or selection rectangle in a subdev should only propagate the configuration downstream. Here you're modiying selection rectangles upstream of the source pad. I think we'll need to live with it, I don't really see a way around that. It's a non-standard behaviour though, and would require sensor-specific userspace to handle this right.
There's however one issue. When switching back from a raw output to a processed output, the crop and compose rectangles will remain the same, and will have values that are not valid for processed output as they won't have the 4 pixels border subtracted. I think you'll need to update them, but only when the source format actually changes. Setting the source format without modifying the media bus code should not result in the selection rectangles being reset.
All this needs to be explained in a comment in the code.
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd, · line 1867
Quoted 8 lines
drivers/media/i2c/mt9m114.c +1
-0} fmt->format = *format;@@ -1851,6 +1864,12 @@ static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd,if (sel->pad !=0 )return -EINVAL ; +/* Crop and compose cannot be changed when bypassing the scaler */
s/scaler/scaler./
Same below.
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd, · line 1871
Quoted 4 lines
drivers/media/i2c/mt9m114.c +4
-0+if (v4l2_subdev_state_get_format (state,1 )->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + }
Instead of special-casing this, can you use a similar approach as in mt9m114_configure_ifp() and replace the 4 and 8 below with border and boarder * 2 (with an update to the comment too) ?
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_set_selection(struct v4l2_subdev *sd, · line 1937
Quoted 13 lines
drivers/media/i2c/mt9m114.c +6
-0+switch (sel->target) {case V4L2_SEL_TGT_CROP : sel->r = *v4l2_subdev_state_get_crop (state,0 );@@ -1911,6 +1930,12 @@ 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 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + }
Let's add a source_format variable to avoid duplicating the v4l2_subdev_state_get_format(), call, as we use the source format at the end of the function.
Quoted 4 lines
drivers/media/i2c/mt9m114.c +1
-0+ 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 · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 09/12] media: mt9m114: Fix scaler bypass mode
Quoted 14 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 9 lines · Hans de Goede
As 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.
Quoted 8 lines
Quoted 4 lines
This patch makes 2 changes which are required to get this to work properly:
1. Set the
MT9M114_CAM_OUTPUT_FORMAT_BT656_CROP_SCALE_DISABLEbit in theMT9M114_CAM_OUTPUT_FORMATregister.Does that bit actually make a difference ? It's documented as only being effective when
MT9M114_CAM_OUTPUT_FORMAT_BT656_ENABLEis also set, and the driver never sets that.
I've just given not setting the bit a try and indeed setting the bit is not necessary. I'll drop this for the next version.
Quoted 35 lines
Quoted 35 lines
2. Disable cropping/composing by setting crop and compose selections on the ISP sink/input format to the format widthxheight @
0x0.Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- When bypassing the scalar makeifp_get_selection()/ifp_set_selection()fillsel->rwith a rectangle of (0,0)/wxh and return 0 instead of returning-EINVAL--- drivers/media/i2c/mt9m114.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)drivers/media/i2c/mt9m114.c +3
-1@@ -467,7 +467,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, } };@@ -850,6 +851,7 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,const struct v4l2_mbus_framefmt *format;const struct v4l2_rect *crop;const struct v4l2_rect *compose; +unsigned int border;u64 output_format;int ret =0 ;
Quoted 6 lines
drivers/media/i2c/mt9m114.c static int mt9m114_configure_ifp(struct mt9m114 *sensor, · line 873
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-0@@ -869,10 +871,12 @@ static int mt9m114_configure_ifp(struct mt9m114 *sensor,* by demosaicing that are taken into account in the crop rectangle but * not in the hardware. */ The comment should be updated.
Ack.
Quoted 3 lines
drivers/media/i2c/mt9m114.c static int mt9m114_configure_ifp(struct mt9m114 *sensor, · line 874
Quoted 1 line
drivers/media/i2c/mt9m114.c +1
-0+ border = (format->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) ?0 :4 ;No need for parentheses.
Ack.
Quoted 58 lines
Quoted 32 lines
drivers/media/i2c/mt9m114.c +6
-3+cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_XOFFSET , - crop->left -4 , &ret); + crop->left - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_YOFFSET , - crop->top -4 , &ret); + crop->top - border, &ret);cci_write (sensor->regmap,MT9M114_CAM_CROP_WINDOW_WIDTH , crop->width, &ret); cci_write(sensor->regmap, MT9M114_CAM_CROP_WINDOW_HEIGHT,@@ -911,7 +915,8 @@ static int mt9m114_configure_ifp(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 |= info->output_format; cci_write(sensor->regmap, MT9M114_CAM_OUTPUT_FORMAT,@@ -1810,6 +1815,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);@@ -1830,8 +1836,15 @@ static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, format->code = info->code;/* If the output format is RAW10, bypass the scaler. */ drivers/media/i2c/mt9m114.c static int mt9m114_ifp_set_fmt(struct v4l2_subdev *sd, · line 1847
Quoted 10 lines
drivers/media/i2c/mt9m114.c +8
-1-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; + }This one is annoying. Normally changing a format or selection rectangle in a subdev should only propagate the configuration downstream. Here you're modiying selection rectangles upstream of the source pad. I think we'll need to live with it, I don't really see a way around that. It's a non-standard behaviour though, and would require sensor-specific userspace to handle this right.
There's however one issue. When switching back from a raw output to a processed output, the crop and compose rectangles will remain the same, and will have values that are not valid for processed output as they won't have the 4 pixels border subtracted. I think you'll need to update them, but only when the source format actually changes. Setting the source format without modifying the media bus code should not result in the selection rectangles being reset.
Quoted 1 line
All this needs to be explained in a comment in the code.
Ok, I'll modify the code to fixup the rectangles when the output-format changes from MEDIA_BUS_FMT_SGRBG10_1X10 -> not MEDIA_BUS_FMT_SGRBG10_1X10.
And I'll add a comment explaining this.
Actually given the above comment it is best to split this change into multiple patches, so for v3 I'm going to do as you request but it will be split out a bit more.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/mt9m114.c +0
-0} fmt->format = *format;@@ -1851,6 +1864,12 @@ static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd,if (sel->pad !=0 )return -EINVAL ;
Quoted 5 lines
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd, · line 1867
Quoted 1 line
drivers/media/i2c/mt9m114.c +1
-0+/* Crop and compose cannot be changed when bypassing the scaler */ s/scaler/scaler./
Same below.
Ack.
Quoted 8 lines
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd, · line 1871
Quoted 4 lines
drivers/media/i2c/mt9m114.c +4
-0+if (v4l2_subdev_state_get_format (state,1 )->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + }Instead of special-casing this, can you use a similar approach as in
mt9m114_configure_ifp()and replace the 4 and 8 below with border and boarder * 2 (with an update to the comment too) ?
Ack, this is part of the splitting of this patch mentioned above.
Quoted 9 lines
Quoted 9 lines
drivers/media/i2c/mt9m114.c +1
-0+switch (sel->target) {case V4L2_SEL_TGT_CROP : sel->r = *v4l2_subdev_state_get_crop (state,0 );@@ -1911,6 +1930,12 @@ static int mt9m114_ifp_set_selection(struct v4l2_subdev *sd,if (sel->pad !=0 )return -EINVAL ;
Quoted 9 lines
drivers/media/i2c/mt9m114.c static int mt9m114_ifp_get_selection(struct v4l2_subdev *sd, · line 1871
Quoted 5 lines
drivers/media/i2c/mt9m114.c +5
-0+/* Crop and compose cannot be changed when bypassing the scaler */ +if (v4l2_subdev_state_get_format (state,1 )->code ==MEDIA_BUS_FMT_SGRBG10_1X10 ) { + sel->r = *v4l2_subdev_state_get_crop (state,0 ); +return 0 ; + }Let's add a
source_formatvariable to avoid duplicating thev4l2_subdev_state_get_format(), call, as we use the source format at the end of the function.
Ack.
Regards,
Hans
Quoted 6 lines
Quoted 5 lines
drivers/media/i2c/mt9m114.c +1
-0+ format =v4l2_subdev_state_get_format (state,0 ); crop =v4l2_subdev_state_get_crop (state,0 ); compose =v4l2_subdev_state_get_compose (state,0 );
PATCH v2 10/12 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
@@ -389,6 +389,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;u32 clk_freq;/* Pixel Array */
@@ -782,14 +783,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 ; }
@@ -976,6 +970,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;
@@ -2267,6 +2262,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
Laurent Pinchart
maintainerRe: [PATCH v2 10/12] media: mt9m114: Drop start-, stop-streaming sequence from initialize
Hi Hans,
Thank you for the patch.
Quoted 44 lines · Hans de Goede
Drop 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 callsmt9m114_initialize()immediately followed by callingmt9m114_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 STREAMINGthese 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 singlemt9m114_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 aftermt9m114_probe(), when streaming was not started within the 1 second runtime-pm timeout. Keep track of this and do theENTER_CONFIG_CHANGE+ ENTER suspend frommt9m114_runtime_suspend()if necessary.Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/media/i2c/mt9m114.c +1
-0@@ -389,6 +389,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;u32 clk_freq;/* Pixel Array */
drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 787
Quoted 6 lines
drivers/media/i2c/mt9m114.c +0
-3@@ -782,14 +783,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;
Entering Config-Change here was meant to ensure the PLL and output mode settings get applied. The PLL settings can probably wait until we start streaming. For the output mode, I'm slightly concerned that incorrect settings could lead to hardware issues, as the sensor starts in parallel output mode. I suppose it shouldn't cause any hardware damage, so I think we could try to just delay Config-Change until we start streaming.
drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 791
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-4- - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_SUSPEND ); -if (ret <0 ) -return ret;
This bothers me a bit more. As far as I understand, the sensor starts streaming right after power on reset, so I'd like to disable streaming as quickly as possible.
Quoted 28 lines
drivers/media/i2c/mt9m114.c +10
-1- + sensor->config_change_pending = true;return 0 ; }@@ -976,6 +970,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;@@ -2267,6 +2262,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 · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 10/12] media: mt9m114: Drop start-, stop-streaming sequence from initialize
Hi Laurent,
Quoted 63 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 44 lines · Hans de Goede
Drop 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 callsmt9m114_initialize()immediately followed by callingmt9m114_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 STREAMINGthese 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 singlemt9m114_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 aftermt9m114_probe(), when streaming was not started within the 1 second runtime-pm timeout. Keep track of this and do theENTER_CONFIG_CHANGE+ ENTER suspend frommt9m114_runtime_suspend()if necessary.Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/media/i2c/mt9m114.c +1
-0@@ -389,6 +389,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;u32 clk_freq;/* Pixel Array */ drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 787
Quoted 6 lines
drivers/media/i2c/mt9m114.c +0
-3@@ -782,14 +783,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;Entering Config-Change here was meant to ensure the PLL and output mode settings get applied. The PLL settings can probably wait until we start streaming. For the output mode, I'm slightly concerned that incorrect settings could lead to hardware issues, as the sensor starts in parallel output mode. I suppose it shouldn't cause any hardware damage, so I think we could try to just delay Config-Change until we start streaming.
Quoted 8 lines
drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 791
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-4- - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_SUSPEND ); -if (ret <0 ) -return ret;This bothers me a bit more. As far as I understand, the sensor starts streaming right after power on reset, so I'd like to disable streaming as quickly as possible.
I tried doing the MT9M114_SYS_STATE_ENTER_SUSPEND without a prior MT9M114_SYS_STATE_ENTER_CONFIG_CHANGE but that does not work, then mt9m114_poll_command() times out.
Also I believe that the start/stop/start streaming vs just a single start streaming is actually causing the issues on atomisp devices.
Normally we only come out of runtime-suspend from mt9m114_start_streaming() so in this case there is no issue with not disabling streaming from mt9m114_initialize().
The only case where the sensor would be streaming when we do not want it would be after the power-up + mt9m114_initialize() from probe().
And we can get the desired "disable streaming as quickly as possible." by forcing a runtime-suspend from probe() directly after mt9m114_initialize() instead of waiting for the auto runtimesuspend.
I'll make probe() immediately runtime-suspend the sensor after mt9m114_initialize() in the next version.
Regards,
Hans
Quoted 30 lines
Quoted 29 lines
drivers/media/i2c/mt9m114.c +10
-1- + sensor->config_change_pending = true;return 0 ; }@@ -976,6 +970,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;@@ -2267,6 +2262,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 ;
Re: [PATCH v2 10/12] media: mt9m114: Drop start-, stop-streaming sequence from initialize
In reply to Laurent PinchartHi Laurent,
Quoted 63 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 44 lines · Hans de Goede
Drop 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 callsmt9m114_initialize()immediately followed by callingmt9m114_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 STREAMINGthese 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 singlemt9m114_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 aftermt9m114_probe(), when streaming was not started within the 1 second runtime-pm timeout. Keep track of this and do theENTER_CONFIG_CHANGE+ ENTER suspend frommt9m114_runtime_suspend()if necessary.Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/media/i2c/mt9m114.c +1
-0@@ -389,6 +389,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;u32 clk_freq;/* Pixel Array */ drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 787
Quoted 6 lines
drivers/media/i2c/mt9m114.c +0
-3@@ -782,14 +783,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;Entering Config-Change here was meant to ensure the PLL and output mode settings get applied. The PLL settings can probably wait until we start streaming. For the output mode, I'm slightly concerned that incorrect settings could lead to hardware issues, as the sensor starts in parallel output mode. I suppose it shouldn't cause any hardware damage, so I think we could try to just delay Config-Change until we start streaming.
Quoted 8 lines
drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 791
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-4- - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_SUSPEND ); -if (ret <0 ) -return ret;This bothers me a bit more. As far as I understand, the sensor starts streaming right after power on reset, so I'd like to disable streaming as quickly as possible.
Actually while working on immediately putting the sensor back in suspend from probe() I noticed that mt9m114_power_on() puts the sensor in standby at the end even checks for this:
/*
* Before issuing any Set-State command, we must ensure that the sensor
* reaches the standby mode (either initiated manually above in
* parallel mode, or automatically after reset in MIPI mode).
*/
ret = mt9m114_poll_state(sensor, MT9M114_SYS_STATE_STANDBY);
if (ret < 0)
goto error_clock;
return 0;Which means should not be streaming after power-on. So I believe that this patch is fine as is and I'm going to keep this version for v3 of the patch-set.
Regards,
Hans
Quoted 30 lines
Quoted 29 lines
drivers/media/i2c/mt9m114.c +10
-1- + sensor->config_change_pending = true;return 0 ; }@@ -976,6 +970,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;@@ -2267,6 +2262,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 ;
Laurent Pinchart
maintainerRe: [PATCH v2 10/12] media: mt9m114: Drop start-, stop-streaming sequence from initialize
Quoted 84 lines · Hans de Goede
Quoted 59 lines · Laurent Pinchart
Quoted 44 lines · Hans de Goede
Drop 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 callsmt9m114_initialize()immediately followed by callingmt9m114_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 STREAMINGthese 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 singlemt9m114_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 aftermt9m114_probe(), when streaming was not started within the 1 second runtime-pm timeout. Keep track of this and do theENTER_CONFIG_CHANGE+ ENTER suspend frommt9m114_runtime_suspend()if necessary.Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/media/i2c/mt9m114.c +1
-0@@ -389,6 +389,7 @@ struct mt9m114 {unsigned int pixrate;bool streaming; +bool config_change_pending;u32 clk_freq;/* Pixel Array */ drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 787
Quoted 6 lines
drivers/media/i2c/mt9m114.c +0
-3@@ -782,14 +783,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;Entering Config-Change here was meant to ensure the PLL and output mode settings get applied. The PLL settings can probably wait until we start streaming. For the output mode, I'm slightly concerned that incorrect settings could lead to hardware issues, as the sensor starts in parallel output mode. I suppose it shouldn't cause any hardware damage, so I think we could try to just delay Config-Change until we start streaming.
Quoted 8 lines
drivers/media/i2c/mt9m114.c static int mt9m114_initialize(struct mt9m114 *sensor) · line 791
Quoted 4 lines
drivers/media/i2c/mt9m114.c +0
-4- - ret =mt9m114_set_state (sensor,MT9M114_SYS_STATE_ENTER_SUSPEND ); -if (ret <0 ) -return ret;This bothers me a bit more. As far as I understand, the sensor starts streaming right after power on reset, so I'd like to disable streaming as quickly as possible.
Actually while working on immediately putting the sensor back in suspend from
probe()I noticed thatmt9m114_power_on()puts the sensor in standby at the end even checks for this:/* * Before issuing any Set-State command, we must ensure that the sensor * reaches the standby mode (either initiated manually above in * parallel mode, or automatically after reset in MIPI mode). */ ret = mt9m114_poll_state(sensor, MT9M114_SYS_STATE_STANDBY); if (ret < 0) goto error_clock; return 0;
Quoted 3 lines
Which means should not be streaming after power-on. So I believe that this patch is fine as is and I'm going to keep this version for v3 of the patch-set.
I just realized that this is governed by the external CONFIG pin. When the pin if pulled up (or left floating, as there's an internal pull-up resistor), the PLL is automatically configured and the sensor starts streaming at power up time. When the pin is pulled low, the sensor will go to the standby state.
I think we can assume that CONFIG will be pulled low when the sensor is used with the CSI-2 output. For the parallel output, either configuration is possible. mt9m114_power_on() issues a MT9M114_SYS_STATE_ENTER_STANDBY in that case.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
drivers/media/i2c/mt9m114.c +10
-1- + sensor->config_change_pending = true;return 0 ; }@@ -976,6 +970,7 @@ static int mt9m114_start_streaming(struct mt9m114 *sensor,if (ret) goto error; + sensor->config_change_pending = false; sensor->streaming = true;return 0 ;@@ -2267,6 +2262,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 · 3 lines
Regards, Laurent Pinchart
PATCH v2 11/12 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
@@ -2399,11 +2399,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
Laurent Pinchart
maintainerRe: [PATCH v2 11/12] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found
Hi Hans,
Thank you for the patch.
Quoted 18 lines · Hans de Goede
With IPU# bridges, endpoints may only be created when the IPU bridge is initialized. This may happen after the sensor driver's first
probe().Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/media/i2c/mt9m114.c +2
-0@@ -2399,11 +2399,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,
drivers/media/i2c/mt9m114.c static int mt9m114_parse_dt(struct mt9m114 *sensor) · line 2409
Quoted 10 lines
drivers/media/i2c/mt9m114.c +5
-4+* 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" );
That's a bit annoying, as in non-ACPI systems we'll then get probe deferral, making the issue more difficult to debug.
Is there a way, on IPU-based systems, to delay probing the sensor until the bridge has been initialized ? I suppose this is a question for Sakari too.
Quoted 3 lines
drivers/media/i2c/mt9m114.c +0
-0sensor->bus_cfg.bus_type =V4L2_MBUS_UNKNOWN ; ret =v4l2_fwnode_endpoint_alloc_parse (ep, &sensor->bus_cfg);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 11/12] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found
Hi Laurent,
Thank you for your reviews. I agree with most of your comments and I'll address them when I can make some time.
Quoted 21 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 16 lines · Hans de Goede
With IPU# bridges, endpoints may only be created when the IPU bridge is initialized. This may happen after the sensor driver's first
probe().Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/media/i2c/mt9m114.c +0
-0@@ -2399,11 +2399,14 @@ static int mt9m114_parse_dt(struct mt9m114 *sensor)struct fwnode_handle *ep;int ret;
Quoted 15 lines
drivers/media/i2c/mt9m114.c static int mt9m114_parse_dt(struct mt9m114 *sensor) · line 2409
Quoted 12 lines
drivers/media/i2c/mt9m114.c +7
-4+/* +* 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" );That's a bit annoying, as in non-ACPI systems we'll then get probe deferral, making the issue more difficult to debug.
With "then" I assume you mean when the fwnode graph endpoint is missing on DT systems ?
Quoted 2 lines
Is there a way, on IPU-based systems, to delay probing the sensor until the bridge has been initialized ?
Waiting for the fwnode graph endpoint to show up is the way to wait for bridge init we (Sakari and me) have agreed upon, this is done on all drivers used on x86/ACPI platforms.
Note that by using dev_err_probe() here and not just "return -EPROBE_DEFER" the kernel will log a message during boot some time (1 minute?) after the last probe has succeeded about devices with a deferred probe pending logging the reason passed to dev_err_probe(), so debugging this is should not be that much of an issue. There will still be a log message, it is just that it will be logged a bit later rather then directly at probe time.
Regards,
Hans
I suppose this is a question for
Quoted 6 lines
Sakari too.
Quoted 3 lines
drivers/media/i2c/mt9m114.c +0
-0sensor->bus_cfg.bus_type =V4L2_MBUS_UNKNOWN ; ret =v4l2_fwnode_endpoint_alloc_parse (ep, &sensor->bus_cfg);
Sakari Ailus
maintainerRe: [PATCH v2 11/12] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found
Hi Hans, Laurent,
Quoted 46 lines · Hans de Goede
Hi Laurent,
Thank you for your reviews. I agree with most of your comments and I'll address them when I can make some time.
Quoted 21 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 16 lines · Hans de Goede
With IPU# bridges, endpoints may only be created when the IPU bridge is initialized. This may happen after the sensor driver's first
probe().Signed-off-by Hans de Goede <[email protected]>--- drivers/media/i2c/mt9m114.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/media/i2c/mt9m114.c +0
-0@@ -2399,11 +2399,14 @@ static int mt9m114_parse_dt(struct mt9m114 *sensor)struct fwnode_handle *ep;int ret;Quoted 15 lines
drivers/media/i2c/mt9m114.c static int mt9m114_parse_dt(struct mt9m114 *sensor) · line 2409
Quoted 12 lines
drivers/media/i2c/mt9m114.c +7
-4+/* +* 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" );That's a bit annoying, as in non-ACPI systems we'll then get probe deferral, making the issue more difficult to debug.
With "then" I assume you mean when the fwnode graph endpoint is missing on DT systems ?
Quoted 6 lines
Quoted 2 lines
Is there a way, on IPU-based systems, to delay probing the sensor until the bridge has been initialized ?
Waiting for the fwnode graph endpoint to show up is the way to wait for bridge init we (Sakari and me) have agreed upon, this is done on all drivers used on x86/ACPI platforms.
In the long run it'd be nice to move the code from the IPU bridge to the ACPI framework. That way we could remove this check as we could guarantee the endpoints would be where they're needed in time.
But I don't expect this to happen any time soon: reworking the fwnode infrastructure to accommodate more flexible node/property insertion should probably be done first. Still, IPU bridge doesn't conflict with DisCo for Imaging doing largely similar things under the hood as the two are effectively mutually exclusive (and should remain so).
Signature · 3 lines
Kind regards, Sakari Ailus
PATCH v2 12/12 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
@@ -2594,11 +2594,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