media: i2c: imx219: fix msr access command sequence
PATCH 1/1 media: i2c: imx219: fix msr access command sequence
From: Conor Dooley <[email protected]>
It was reported to me that the imx219 didn't work on one of our development kits partly because the access sequence is incorrect. The datasheet I could find [1] for this camera has the access sequence:
Seq. No. Address (Hex) data
1 30EB 05 2 30EB 0C 3 300A FF 4 300B FF 5 30EB 05 6 30EB 09
but the driver swaps the first two elements. Laurent pointed out on IRC that the original code used the correct sequence for 1920x1080 but the current sequence for 3280x2464 and 1640x1232. During refactoring of the init sequence the current order was used for all formats.
Switch to using the documented sequence.
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.
--- drivers/media/i2c/imx219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx219.c +1 -1
@@ -162,8 +162,8 @@ static const struct cci_reg_sequence imx219_common_regs[] = { { IMX219_REG_MODE_SELECT, 0x00 }, /* Mode Select *//* To Access Addresses 3000-5fff, send the following commands */ - { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x30eb), 0x05 }, + { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x300a), 0xff }, { CCI_REG8(0x300b), 0xff }, { CCI_REG8(0x30eb), 0x05 },
Signature · 1 line
2.43.0
Hi Conor,
Thank you for the patch.
Quoted 18 lines · Conor Dooley
From: Conor Dooley <[email protected]>
It was reported to me that the imx219 didn't work on one of our development kits partly because the access sequence is incorrect. The datasheet I could find [1] for this camera has the access sequence:
Seq. No. Address (Hex) data1 30EB 05 2 30EB 0C 3 300A FF 4 300B FF 5 30EB 05 6 30EB 09but the driver swaps the first two elements. Laurent pointed out on IRC that the original code used the correct sequence for 1920x1080 but the current sequence for 3280x2464 and 1640x1232. During refactoring of the init sequence the current order was used for all formats.
Quoted 6 lines
Switch to using the documented sequence.
Fixes 8508455961d5 ("media: i2c: imx219: Split common registers from mode tables")Fixes 1283b3b8f82b ("media: i2c: Add driver for Sony IMX219 sensor")Signed-off-by Conor Dooley <[email protected]>
This looks reasonable, based on the above link.
Dave, could you check the impact on the Raspberry Pi kernel ? It seems to be shipping the incorrect sequence unconditionally.
Any information about what the 12 undocumented MSRs that are programmed by the driver do would be appreciated too ;-)
Quoted 35 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.CC Dave Stevenson <[email protected]>CC Sakari Ailus <[email protected]>CC Mauro Carvalho Chehab <[email protected]>CC Adam Ford <[email protected]>CC Laurent Pinchart <[email protected]>CC Andrey Konovalov <[email protected]>--- drivers/media/i2c/imx219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/imx219.c +1
-1@@ -162,8 +162,8 @@ static const struct cci_reg_sequence imx219_common_regs[] = { { IMX219_REG_MODE_SELECT, 0x00 }, /* Mode Select *//* To Access Addresses 3000-5fff, send the following commands */ - { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x30eb), 0x05 }, + { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x300a), 0xff }, { CCI_REG8(0x300b), 0xff }, { CCI_REG8(0x30eb), 0x05 },
Signature · 3 lines
Regards, Laurent Pinchart
Dave Stevenson
maintainerHi Conor and Laurent
Quoted 31 lines · Laurent Pinchart
Hi Conor,
Thank you for the patch.
Quoted 18 lines · Conor Dooley
From: Conor Dooley <[email protected]>
It was reported to me that the imx219 didn't work on one of our development kits partly because the access sequence is incorrect. The datasheet I could find [1] for this camera has the access sequence:
Seq. No. Address (Hex) data1 30EB 05 2 30EB 0C 3 300A FF 4 300B FF 5 30EB 05 6 30EB 09but the driver swaps the first two elements. Laurent pointed out on IRC that the original code used the correct sequence for 1920x1080 but the current sequence for 3280x2464 and 1640x1232. During refactoring of the init sequence the current order was used for all formats.
Quoted 6 lines
Switch to using the documented sequence.
Fixes 8508455961d5 ("media: i2c: imx219: Split common registers from mode tables")Fixes 1283b3b8f82b ("media: i2c: Add driver for Sony IMX219 sensor")Signed-off-by Conor Dooley <[email protected]>
Quoted 6 lines
This looks reasonable, based on the above link.
Reviewed-by Laurent Pinchart <[email protected]>Dave, could you check the impact on the Raspberry Pi kernel ? It seems to be shipping the incorrect sequence unconditionally.
I've compared the values against the old firmware driver. There we have the cropped 1080p and VGA high framerate modes had 0x05 0x0c, and the full res 3280x2464 and 2x2 binned 1640x1232 modes had 0x0c 0x05, so the same as the original kernel driver. Not totally unsurprising as the kernel driver register sets were copied from the firmware. So the Pi has used imx219 in this manner since launch of the sensor in 2014! Whether that was a transcription typo or an error in the register sets from Sony I couldn't say (Naush may still have the original register set information).
I don't have an imx219 to hand right now to test with, but will check it out on Monday. I'll agree that the patch looks valid based on the datasheet.
Quoted 2 lines
Any information about what the 12 undocumented MSRs that are programmed by the driver do would be appreciated too ;-)
Sadly I have no extra information on those.
Quoted 8 lines
Quoted 8 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.
Did the change fix it for the reporter? We're using the driver with no changes to the register settings cf mainline.
Why it works on the Pi but not on a Microchip board is likely to be something quite subtle.
Dave
Quoted 31 lines
Quoted 17 lines
CC Dave Stevenson <[email protected]>CC Sakari Ailus <[email protected]>CC Mauro Carvalho Chehab <[email protected]>CC Adam Ford <[email protected]>CC Laurent Pinchart <[email protected]>CC Andrey Konovalov <[email protected]>--- drivers/media/i2c/imx219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/imx219.c +0
-0drivers/media/i2c/imx219.c static const struct cci_reg_sequence imx219_common_regs[] = { · line 169
Quoted 9 lines
drivers/media/i2c/imx219.c +1
-1@@ -162,8 +162,8 @@ static const struct cci_reg_sequence imx219_common_regs[] = { { IMX219_REG_MODE_SELECT, 0x00 }, /* Mode Select *//* To Access Addresses 3000-5fff, send the following commands */ - { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x30eb), 0x05 }, + { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x300a), 0xff }, { CCI_REG8(0x300b), 0xff }, { CCI_REG8(0x30eb), 0x05 },--
Regards,Laurent Pinchart
Quoted 9 lines · Dave Stevenson
Quoted 8 lines
Quoted 8 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.
Quoted 4 lines
Did the change fix it for the reporter? We're using the driver with no changes to the register settings cf mainline.
Why it works on the Pi but not on a Microchip board is likely to be something quite subtle.
I've asked, maybe it turns out to just be the first of my suggestions, and they noticed it was not matching in passing. They did introduce two additional MSR accesses, both outside of the range documented in the datasheets I could find online. They did have explanations for what those undocumented MSRs did (0x5040 and 0x5041) in the mail I got, but given it's third hand info to me, I dunno if we have the datasheet etc. I'll try to find out some more next week.
Thanks,
Conor.
Quoted 12 lines · Conor Dooley
Quoted 9 lines · Dave Stevenson
Quoted 8 lines
Quoted 8 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.
Quoted 4 lines
Quoted 4 lines
Did the change fix it for the reporter? We're using the driver with no changes to the register settings cf mainline.
Why it works on the Pi but not on a Microchip board is likely to be something quite subtle.
I have two different platforms which can use this sensor. I can try to test it this weekend and I'll report back my findings.
adam
Quoted 11 lines
I've asked, maybe it turns out to just be the first of my suggestions, and they noticed it was not matching in passing. They did introduce two additional MSR accesses, both outside of the range documented in the datasheets I could find online. They did have explanations for what those undocumented MSRs did (
0x5040and0x5041) in the mail I got, but given it's third hand info to me, I dunno if we have the datasheet etc. I'll try to find out some more next week.Thanks,
Conor.
Quoted 11 lines · Conor Dooley
Quoted 9 lines · Dave Stevenson
Quoted 8 lines
Quoted 8 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.
Quoted 7 lines
Quoted 4 lines
Did the change fix it for the reporter? We're using the driver with no changes to the register settings cf mainline.
Why it works on the Pi but not on a Microchip board is likely to be something quite subtle.I've asked, maybe it turns out to just be the first of my suggestions, and they noticed it was not matching in passing.
Apparently it was the latter & they did need to fix the sequence to be able to write the MSRs.
Quoted 6 lines
They did introduce two
additional MSR accesses, both outside of the range documented in the datasheets I could find online. They did have explanations for what those undocumented MSRs did (0x5040and0x5041) in the mail I got, but given it's third hand info to me, I dunno if we have the datasheet etc. I'll try to find out some more next week.
Seemingly what those two additional MSRs do is under NDA so I would have no way of justifying a patch to add them or the devicetree property required to know whether or not the additional MSR writes is needed. :)
Hi Conor
Quoted 18 lines · Conor Dooley
Quoted 16 lines · Conor Dooley
Quoted 13 lines · Dave Stevenson
Quoted 8 lines
Quoted 8 lines
---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.Did the change fix it for the reporter? We're using the driver with no changes to the register settings cf mainline.
Why it works on the Pi but not on a Microchip board is likely to be something quite subtle.
Quoted 5 lines
Quoted 2 lines
I've asked, maybe it turns out to just be the first of my suggestions, and they noticed it was not matching in passing.
Apparently it was the latter & they did need to fix the sequence to be able to write the MSRs.
Fair enough.
Quoted 10 lines
Quoted 6 lines
They did introduce two
additional MSR accesses, both outside of the range documented in the datasheets I could find online. They did have explanations for what those undocumented MSRs did (0x5040and0x5041) in the mail I got, but given it's third hand info to me, I dunno if we have the datasheet etc. I'll try to find out some more next week.Seemingly what those two additional MSRs do is under NDA so I would have no way of justifying a patch to add them or the devicetree property required to know whether or not the additional MSR writes is needed. :)
NDAs can be a real pain sometimes.
I'm happy with the patch though, and it doesn't stop anything else working on the Pi.
Quoted 14 lines · Conor Dooley
From: Conor Dooley <[email protected]>
It was reported to me that the imx219 didn't work on one of our development kits partly because the access sequence is incorrect. The datasheet I could find [1] for this camera has the access sequence:
Seq. No. Address (Hex) data1 30EB 05 2 30EB 0C 3 300A FF 4 300B FF 5 30EB 05 6 30EB 09
Quoted 7 lines
but the driver swaps the first two elements. Laurent pointed out on IRC that the original code used the correct sequence for 1920x1080 but the current sequence for 3280x2464 and 1640x1232. During refactoring of the init sequence the current order was used for all formats.
Switch to using the documented sequence.
adam
Quoted 42 lines
Fixes 8508455961d5 ("media: i2c: imx219: Split common registers from mode tables")Fixes 1283b3b8f82b ("media: i2c: Add driver for Sony IMX219 sensor")Signed-off-by Conor Dooley <[email protected]>---
I got the report of this third hand, I don't have a device and can't test this. I do wonder why the RPis get away with the sequence that seemingly doesn't work for the guy that reported this to me. My theory is either that they noticed the sequence was wrong while adding some other MSR access that is needed on this board while either cross checking the values written or because the other MSR accesses didn't take effect.CC Dave Stevenson <[email protected]>CC Sakari Ailus <[email protected]>CC Mauro Carvalho Chehab <[email protected]>CC Adam Ford <[email protected]>CC Laurent Pinchart <[email protected]>CC Andrey Konovalov <[email protected]>--- drivers/media/i2c/imx219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/imx219.c +1
-2@@ -162,8 +162,8 @@ static const struct cci_reg_sequence imx219_common_regs[] = { { IMX219_REG_MODE_SELECT, 0x00 }, /* Mode Select *//* To Access Addresses 3000-5fff, send the following commands */ - { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x30eb), 0x05 }, + { CCI_REG8(0x30eb), 0x0c }, { CCI_REG8(0x300a), 0xff }, { CCI_REG8(0x300b), 0xff }, { CCI_REG8(0x30eb), 0x05 }, --2.43.0