From: Hans de Goede <johannes.goede@oss.qualcomm.com>
To: "Yeh, Serin" <serin.yeh@intel.com>, Kate Hsuan <hpa@redhat.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil+cisco@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: "linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] media: i2c: imx471: Add Sony IMX471 image sensor driver
Date: Mon, 20 Apr 2026 10:59:16 +0200 [thread overview]
Message-ID: <2bed7c05-7a5d-4808-990f-9d2ab9fd8005@oss.qualcomm.com> (raw)
In-Reply-To: <DS0PR11MB7971EF4F2B0759AF0CD738D0F62F2@DS0PR11MB7971.namprd11.prod.outlook.com>
Hi Serin,
On 20-Apr-26 9:23 AM, Yeh, Serin wrote:
> Hi Kate,
>
> Please ignore my previous mail.
>
> There are some reasons that the upside-down mirror/flip functions can't be submitted in the driver for upstream.
Can you explain this in a bit more detail.
> The version that I submitted for upstream is not included upside-down because the sensor has design limitations of mirror/flip.
>
> Your version will occur incorrect bayer older on different platform.
This should be fixed by only setting the voffset when enabling v-flipping
and only setting the hoffset when enabling h-flipping, as mentioned in
my review.
It looks like the sensor is mounted upside down on some laptops, so we
are going to need flipping support to fix things up.
Regards,
Hans
> -----Original Message-----
> From: Hans de Goede <johannes.goede@oss.qualcomm.com>
> Sent: Friday, April 17, 2026 6:16 PM
> To: Kate Hsuan <hpa@redhat.com>; Mauro Carvalho Chehab <mchehab@kernel.org>; Hans Verkuil <hverkuil+cisco@kernel.org>; Sakari Ailus <sakari.ailus@linux.intel.com>; Yeh, Serin <serin.yeh@intel.com>
> Cc: linux-media@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 2/2] media: i2c: imx471: Add Sony IMX471 image sensor driver
>
> Hi Kate,
>
> On 17-Apr-26 10:32, Kate Hsuan wrote:
>> Add a new driver for Sony imx471 camera sensor. It is based on Jimmy
>> Su <jimmy.su@intel.com> implementation and the driver can be found in
>> the following URL.
>> https://github.com/intel/ipu6-drivers/commits/master/drivers/media/i2c
>> /imx471.c
>>
>> This sensor can be found on Lenovo X9-14 and X9-15 laptop and it is a
>> part of IPU7 solution. The driver was tested on Lenovo X9-14 and X9-15 laptops.
>>
>> Link:
>> https://github.com/intel/ipu6-drivers/blob/master/drivers/media/i2c/im
>> x471.c
>> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2454119
>> Signed-off-by: Kate Hsuan <hpa@redhat.com>
> <snip>
>
>> diff --git a/drivers/media/i2c/imx471.c b/drivers/media/i2c/imx471.c
>> new file mode 100644 index 000000000000..32a105a60731
>> --- /dev/null
>> +++ b/drivers/media/i2c/imx471.c
>> @@ -0,0 +1,1047 @@
>
> <snip>
>
>> +static int imx471_update_flip(struct imx471_data *sensor, u32 value,
>> + u8 flip_bit)
>> +{
>> + int ret;
>> + u64 val = value ? flip_bit : 0;
>> +
>> + if (sensor->streaming)
>> + return -EBUSY;
>
> I see no reason why this could not be updated while streaming, since the h/y offsets get adjusted the bayer pattern stays the same so changing while streaming should be fine.
>
>> +
>> + /* hflip */
>> + /*
>> + * Some manufacturers mount the sensor upside-down (rotation == 180).
>> + * V4L2 sets both h/vflip to 1 for 180-degree rotation, but only the
>> + * vflip should actually be applied. Skip the initial hflip write to
>> + * preserve correct orientation.
>> + */
>
> I was answering your off-list email about this, but now I see that you've added this workaround here. I believe that this workaround is wrong, so let me move answer things here instead of off-list:
>
>> I filled in the DMI information in the table and I found v4l2 sets up
>> both hflip=1 and vflip=1 when the rotation is 180.
>
> Yes that is correct, note this is actually done by libcamera, in response to the rotation property reporting 180 degrees rotation after adding the laptop to the DMI table.
>
>> In my case, I only
>> need to set vflip then I can get a correct image.
>
> First of all are you sure that you only need to set vflip? A camera is not a mirror! If you say raise your right hand in front of the camera then on the screen you should be seen raising the hand which is on the left for "the you" looking at the screen because if you were to look at you from the pov of the camera your right hand is on the left.
>
> The easiest way to check this is to have something with some written text on it. In a mirror you cannot (easily) read e.g. the text printed on a T-shirt but with a camera you should be able to read this without problems.
>
> Also make sure you use qcam to test because qcam does not mirror/hflip.
> Some apps hflip the image for you (esp. things like google meet) because people are so used to seeing themselves in a mirror that they adjust the view for you. Note e.g. google meet only mirrors your own preview it sends out an unmirrored image to the people on the call (IIRC).
>
> If after this long mansplaining (sorry) writeup about the difference between a mirror and a camera you still think you only need vflip, then that means that either the hflip ot the vflip control of the sensor is inverted and the driver needs to invert it.
>
> Are we sure the camera module is upside down? Maybe vflip is the one which we need to invert and the module is not upside-down at all ?
>
> Hmm, looking at other imx sensor drivers, unlike ov sensors where sometimes hflip is inverted it seems the 2 flip controls are sofar always straight forward on imx. Although some drivers only implement vflip and have no hflip at all.
>
> As you mention in the cover letter this is a cleaned up version of:
> https://github.com/intel/ipu6-drivers/tree/master/drivers/media/i2c/imx471.c
>
> Note that we've seen issues with mirroring / flipping from various other drivers originating from Intel, they have not always got this correct, especially when it comes to mirroring by default (when the hflip control's value is 0) but also with vflipping by default when the driver was developed on a laptop which had the module upside-down, see e.g. :
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/drivers/media/i2c/ov02c10.c
>
> where we needed to do quite a few flipping related fixes.
>
>> + if (flip_bit == IMX471_HFLIP_BIT) {
>> + if (sensor->rotation == 180 && !sensor->hflip_initialized) {
>> + sensor->hflip_initialized = true;
>> + return 0;
>> + }
>
> This looks like you skip writing the hflip on the first start stream, but what about subsequent streams ?
>
> Also see my next comment below, I think this skipping only once does point us in the right direction.
>
>> +
>> + cci_update_bits(sensor->regmap, IMX471_REG_ORIENTATION,
>> + flip_bit, val, &ret);
>> +
>> + return ret;
>> + }
>> +
>> + /* vflip */
>> + cci_update_bits(sensor->regmap, IMX471_REG_ORIENTATION,
>> + flip_bit, val, &ret);
>> + if (ret)
>> + return ret;
>
> Hmm, I wonder if the problem here is you doing 2 subsequent cci_update_bits(). If the flip control registered is double-buffered and the new value is latched as the actual value on the start of the next frame; and this is combined with reading back reading the active value, not the last written value then the first time you do this the setting of the hflip bit will be overwritten by the second cci_update_bits.
>
> I think it would be better to do something similar to what imx219.c and replace these 2 cci_update_bits() calls with:
>
> cci_write(imx471->regmap, IMX471_REG_ORIENTATION,
> imx471->hflip->val | imx471->vflip->val << 1, &ret);
>
> I believe this should work here too.
>
>
>> +
>> + cci_write(sensor->regmap, IMX471_REG_V_WIN_OFFSET,
>> + value ? 0xe0 : 0xeb, &ret);
>> + if (ret)
>> + return ret;
>> +
>> + cci_update_bits(sensor->regmap, IMX471_REG_H_WIN_OFFSET, 1,
>> + value ? 0x01 : 0x00, &ret);
>
> No need for cci_update_bits() here, the register is always initialized to 0xc8 so this can just use hardcoded values like the V_WIN_OFFSET path:
>
> cci_write(sensor->regmap, IMX471_REG_H_WIN_OFFSET,
> value ? 0xc9 : 0xc8, &ret);
>
>> + return ret;
>
> Updating both offsets here is wrong when hflip != vflip, you should only update V_WIN_OFFSET when changing vflip and H_WIN_OFFSET when changing hflip.
>
> I suggest dropping this function and instead in set_ctrl() do this:
>
> case V4L2_CID_HFLIP:
> cci_write(imx471->regmap, IMX471_REG_ORIENTATION,
> imx471->hflip->val | imx471->vflip->val << 1, &ret);
> cci_write(sensor->regmap, IMX471_REG_H_WIN_OFFSET,
> value ? 0xc9 : 0xc8, &ret);
> break;
> case V4L2_CID_VFLIP:
> cci_write(imx471->regmap, IMX471_REG_ORIENTATION,
> imx471->hflip->val | imx471->vflip->val << 1, &ret);
> cci_write(sensor->regmap, IMX471_REG_V_WIN_OFFSET,
> value ? 0xe0 : 0xeb, &ret);
> break;
>
> Regards,
>
> Hans
>
next prev parent reply other threads:[~2026-04-20 8:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 8:32 [PATCH 0/2] Add Sony IMX471 camera sensor driver Kate Hsuan
2026-04-17 8:32 ` [PATCH 1/2] media: ipu-bridge: Add DMI information of Lenovo X9 to the image upside-down list Kate Hsuan
2026-04-17 10:37 ` Hans de Goede
2026-04-20 7:40 ` Kate Hsuan
2026-04-17 8:32 ` [PATCH 2/2] media: i2c: imx471: Add Sony IMX471 image sensor driver Kate Hsuan
2026-04-17 10:16 ` Hans de Goede
2026-04-20 4:05 ` Kate Hsuan
2026-04-20 6:48 ` Yeh, Serin
2026-04-20 7:23 ` Yeh, Serin
2026-04-20 8:59 ` Hans de Goede [this message]
2026-04-21 9:26 ` Sakari Ailus
2026-04-21 9:02 ` Sakari Ailus
2026-04-21 9:47 ` Hans de Goede
2026-04-21 20:05 ` Sakari Ailus
2026-04-28 3:08 ` Kate Hsuan
2026-04-28 8:49 ` Sakari Ailus
2026-04-21 9:23 ` Sakari Ailus
2026-04-28 4:05 ` Kate Hsuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2bed7c05-7a5d-4808-990f-9d2ab9fd8005@oss.qualcomm.com \
--to=johannes.goede@oss.qualcomm.com \
--cc=hpa@redhat.com \
--cc=hverkuil+cisco@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=serin.yeh@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox