From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BB523B5319 for ; Fri, 17 Apr 2026 10:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776420977; cv=none; b=d/SziiRha1WrUc8Xgb3J06FGnOWCjPpFfMu2W1lLzdJNpI7kx1w6J8+JQBjoEV50XG+NeHz1rKg2GnBLkpi2L9YVBIb5oTjlAF1SHnAxn7K1MYiHo4lvMFDVZNBcLCiG+taXv2DUwhgQny4u6zq5QRANJSwRhsKjD6n8DaJyr38= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776420977; c=relaxed/simple; bh=FbRccAlNnTxvIjKHLYcaGVLSPfh9iyD9P+CWG72bXZ8=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=mz7RmoJlIRvu17p/+l97UTeZ8GQbqGqZ7n+dkHA5SHRYGmYAEL+0Qvs3uAKJALIkCPfH4WHIFcCbNcJqCfBOlib0OnUiJwNw8kwkalUfjzrtZVxZkv331eqIE43e2q38FrHrfPpAwzQkRxVF+5xxAqnWmnOBOydZxDPzQ7M3Glk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=EGX3yQEE; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ENgl1ln1; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="EGX3yQEE"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ENgl1ln1" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63H8BvH0667583 for ; Fri, 17 Apr 2026 10:16:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 4jB5s7u6k9Zzlr7X3W5qKaFiB0WFBTWxPhCDheBItAY=; b=EGX3yQEE6nHTovvN ot/bzxxsb95qZj3MVBh6pZkAStRXMi1WKAkU27PYIaCs73LRhJdVHLUfErbUTSOh 3pgQG+SX8zOxEb+EoccWQDkDS/xb6jWC7xebUXpeoaH2iZJZDhYzWfJg1tunEsr/ jxN1V5uKXyAaD6S/OAKl6LlZyIBz2I4bwuI0mQchfJSLo7JR6ihwRWyOAky91jMg M5HDt3kDvdqoNOy5T6JzzlRV6FM1lqG//WGOSomJSl6APoRgNcnFWFS3/UA/qMNF 9yPwp76gcbSkH4LdS9EBsyZFsKexin9HX6AKfXk+1FVnuCp3eb5AW1iOohpm0Me4 e7NgMg== Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dkaxcstfx-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 17 Apr 2026 10:16:15 +0000 (GMT) Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-50d8e4c29caso13341581cf.0 for ; Fri, 17 Apr 2026 03:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1776420974; x=1777025774; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=4jB5s7u6k9Zzlr7X3W5qKaFiB0WFBTWxPhCDheBItAY=; b=ENgl1ln1XNFD8R7HIbxrGiUPqZ1JSfsTzrPs1dIJtHxuvgWer1ADYtjwz+VcrcEBoL 9oW0ZQ5+T2TwJsPpYE8KjdI9HjRD1AoqR9FM3SQYMp/DD+HJtN2oWdbDUxnk8sjunQvI 4YvtD5tZhWjRxtSYQefV6U4KXZ0iz7+uuf0VvH/7LUV7KqVbA3iXIznCJgTktmsR6duo clWfBj7d5hIVMw6M5U+Wr/3wcUe36uQOcS7uABySx04bze8CZISrXGfBHlDBVEXW/965 oGwYXkjeRua4omHGxUQqzjqPUnWM8PjTO7o1wQvjPOE3WDEvtYTkyr74wv9i5CCl50yG J57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776420974; x=1777025774; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4jB5s7u6k9Zzlr7X3W5qKaFiB0WFBTWxPhCDheBItAY=; b=qLzlE/xh01HCO1GbLyfmrh0WFo/0NLA6non+YCCsl/oTQuGQIOzO2JdMNbw0FwBVwX siA7UdJ0uiHz8hsyaQnsSuZqE9HSFHZRtGoPaPS6ip3tAJHl0k384GNopSAS6pJvvmyN Dmwwr6h7XW4isGYkcHOWRBwO1xSA/6XjUPRnYnmns2TOSlqCHDq5iSAYFHcTK7Oe3JkA uX4M8gI/RGZHg8cu+huLHZuuX3yjKtskp1Em8kEm7C3dLm1z2EJFOpY5gL+wstPljazZ LHQXxiW0mVfbXTHBYHHQupL5Dn6TIa6kHzJTloiC48UTxZ7lU7gLGLXBkzSaPiAKPNHj PMjA== X-Forwarded-Encrypted: i=1; AFNElJ9A9fTs/lp1XSJaInL4dRuCvQ9rmK4jls4R/9/zUGswv6WAxxW+0V+nDsF3CseUaueW2fRVuwPxT+3dAls=@vger.kernel.org X-Gm-Message-State: AOJu0YwVEdgitZK0tHkrnGGP+S5Jl9N1P42jlkQ6jjkTEeUnXxCmGvZo ZK7AXLJRO3N+mJool4CTmYvV/ZK//m3gFmX9x5hc2mjmI5qsg9Rnp8gqxUKdF/8kWwkzJhONjms RkCE4tt7ycpj8O+zYGaSp/1DAC9RZuJXDVb/ezi1vpq5WrEBspkI0tiC5Ec+YlAoO8M8= X-Gm-Gg: AeBDieuUN3PIc6pzPbCKoT8EeXMrT7/wC7wmYM5LYkD5HT7JxBIx7Kw0gdkbl7Ki3ha E1FKBNpP9TKzEkqyHHiUKIpQsFZhDx16jhQOqLwWcZfIXVtEgMm6a47faeGHeDpu+G/618uLFvz P+DKTlhCLNctJIi+57duXHJYhHc33Vl1zE82K3F3gwiqCH/hR8d/QFiGWxBEOrJNiKKzeLgB56t tyAW29RrAMAZ/JqY9GLy6ifrX0aPhNSlkzC/0yo8NOnUJ/MWIi7ppbYkUFVX+J7GL3oEOGKMmDF AOosZzSogsLnCA7/Sw7HRH4sytckNHjQ682jhwN/iWfp3nE06WYx895l03f9wy7sizCrnbjo/8/ gkuOuqNC2OqvZsVHKfIwq7R68+9J3xA0nZH0gDsvkqx+O+9KzQsA1tHI7UOBa0eTh+cXqPPfsGI o6HfagnFBV9DZBBGVQoqZSPPuTzqa7kuVT5EvbAGimwgMXp45oAeB08FnxI1vaLxhzItwQzfhWj Xt/3E/Q4AXP2QShLpsKlhFCnsQ= X-Received: by 2002:a05:622a:2b07:b0:50d:6ab3:1acb with SMTP id d75a77b69052e-50e36ecedccmr28082251cf.41.1776420974405; Fri, 17 Apr 2026 03:16:14 -0700 (PDT) X-Received: by 2002:a05:622a:2b07:b0:50d:6ab3:1acb with SMTP id d75a77b69052e-50e36ecedccmr28081771cf.41.1776420973888; Fri, 17 Apr 2026 03:16:13 -0700 (PDT) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ba455539817sm39424466b.56.2026.04.17.03.16.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Apr 2026 03:16:12 -0700 (PDT) Message-ID: Date: Fri, 17 Apr 2026 12:16:11 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Hans de Goede Subject: Re: [PATCH 2/2] media: i2c: imx471: Add Sony IMX471 image sensor driver To: Kate Hsuan , Mauro Carvalho Chehab , Hans Verkuil , Sakari Ailus , Serin Yeh Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260417083214.222189-1-hpa@redhat.com> <20260417083214.222189-3-hpa@redhat.com> Content-Language: en-US, nl In-Reply-To: <20260417083214.222189-3-hpa@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=JcqMa0KV c=1 sm=1 tr=0 ts=69e2086f cx=c_pps a=mPf7EqFMSY9/WdsSgAYMbA==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=NEAV23lmAAAA:8 a=vlGuhjqhAAAA:20 a=20KFwNOVAAAA:8 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=MCOcW4g6KZAOg600A84A:9 a=QEXdDO2ut3YA:10 a=dawVfQjAaf238kedN5IG:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDE3MDEwMSBTYWx0ZWRfXy1S9J+rrgAQP VeMRpho1J4o3yljfhL0PKhdV/t7vjNghKCYJ4QuKX5u2NudLr0FpDyfG5W5iHKpmsb6j7nwaXjq p60Arg86DX1a/2unDqxg37zQYrAwWktGl7CaLoNzHODeFkfPvwZraNjt7r4N/pv8E0VQNCo7Rdz vOibK+XxuohnD+56ZKx5rWcsesiBqkS7kFvS0keNs9gWHHrtqOl3/xmHJ/miqUQh0IJLTmUqkW8 8oaPLmhDL8RPIAuve8yJLw80H5twha1szcL3YrUIAQzT0pZW6qu60Xf3ytK+UiA5vH5fTXW1GmA ZrYeJla1OHa1E4R6m5kk+qJH+iJ0pxS10jlV8TIoVbizi/OmKk2BNSRPSC1tkDS7RMMyPRbFQsF FJtxd7azqPO0CdYqYO+XVk81D1jTxW2dQd+aP+t+9aUnDrGF1jMBAKLr7fAUqFKNyMzVGzWBvJh wJl6rCwh58L4P8LZNqQ== X-Proofpoint-GUID: XaOdJE7iM_fujSPvS2hTr0WcLSYLl4j7 X-Proofpoint-ORIG-GUID: XaOdJE7iM_fujSPvS2hTr0WcLSYLl4j7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-16_04,2026-04-16_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1015 malwarescore=0 phishscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604170101 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 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/imx471.c > Link: https://bugzilla.redhat.com/show_bug.cgi?id=2454119 > Signed-off-by: Kate Hsuan > 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 @@ > +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