From nobody Tue Dec 16 06:37:31 2025 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA175314D3D for ; Mon, 15 Dec 2025 09:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765792073; cv=none; b=WjRqFAZ5suCFS5siwctY17vi8JqhGB8NgRyFghqor1n+iP75OFzAefJg8x73uXuEFbhqwJIxn8WAUzA/k0vYuZTVXWihlT7woFyhRJOvWKxuiVNX4AADFWpTC8lB7lJutQ3KfILuHIEFZJcX+/CWXwsvQ6PY18VW+0M3qCYUaHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765792073; c=relaxed/simple; bh=Lms6/stTSeqardwm+RyauEeBz1C1uDEVLzFEIXT2v3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mW3mGj5gJ9zswptZlRGfWjTFOL2dUI8U27KA1Ro0qofWYfy2YLiZWGZtU3lMsn9o6h/Edl9i85zaKiU7+ygB+fXfuw9Ue/Vv9aGzMavMTYgMD4auQpDm0npCboGKAd5eSQFo27B2Idh5i5nuxpHjrMnLpi1Pb9NoerfQOSPOrVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LGF4mjWu; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LGF4mjWu" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-594285c6509so3779776e87.0 for ; Mon, 15 Dec 2025 01:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765792070; x=1766396870; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=V6iN4UOpzzHKEEieW0jj8euz+beVA0D1U8Y9G9L7tjI=; b=LGF4mjWuNAy+vylRY6Pj3tkJw+ZGNDe+2XetucWBr3cTgnUfEGHeLbYNrFBEQMclrx 2mflglkJKBOx2kA7t9HFvw5vh9noZEVim3mgYJ5QV5rH+UuUlW7hjlXpEWAmKrdyKNFD MEB2s2iX5yrAotsESdmLjwecGXGsB3Uz/pQOyIEDkVRkwD3LyBvTLMX1Uu497/5RmMFX HOKK56lVRPI9/1wrld5BlYF4odASWmBVL4SOBz1ZNwrl5TKDc3cCaILb4LDncwz3U/B7 QMDA7O69PeHVSLN8vwua3vItVj4QK55BIG/Q8Ke6vMjDliGErTXGftAupb/wiliFkUPW AwRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765792070; x=1766396870; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=V6iN4UOpzzHKEEieW0jj8euz+beVA0D1U8Y9G9L7tjI=; b=rluVSvq7fZlQ2dlrwSkwNzAI25gWDQP/J1FyO+DRsyHeLx3yAOdNYSShPkPXgR7DXV b6OwyqrURjPzTJb/mdzR4R+94RElp1K0RNO3gBeb7MZ36HljUHm7iMgru7HYITBaHHGV xlmhhiIMlSkfocYxWDagJVX8+yauv2HggkiNW1+qbd6Recn2vMh7Nt9uEAr8RDsv1jyk 6Dmj3gF64nsuDWaPwt6OmDijv3qBLZJ+BRK0Dme8sN8N6kfiglPNhBqywP/853SfUvXY T74CYq33ciUatoKyhQv23OgLShMx/G5AbFMh5SClllNCxO1GaU9Kil/7ovkRsq+BctRE 1ncg== X-Forwarded-Encrypted: i=1; AJvYcCXILviifA6xan9cU0VhlkI7/LRJxIx3EJcjlxG4sR8iWZmY5R7h/4vaYe7mdcuOBNb1reLUjwxDT4HguVU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8oqAfiNYh1KnZCKxH/S0/X5UgeTKpzS8tjxFBBnoEmDvt9iwM a34XVcM1fQL+0ws3EU9lEqvSKeq2XdxPhGlbkSw01RfRKr3PEbpmYaJb X-Gm-Gg: AY/fxX4j+fgBZDsPGIjIYYFsYLkzy1ugKqTjMWgHQVhzX9jiaRcKuhpGpFG2zRbIREa r/wCaqBwuPSGJfv50IgG8jIZs5IriuLqZL2dws8i6vFCTd35mVmNeBCLgtAfICHlSRHs4so3yDk m9Nr48oHm2PIqf5tSldU2RXMoyASNMEi186vs6/KlbfNKxjNXbddKGjS7AxGfSo/6b/nd3CUl7/ ZWlVoNe2sT+Ym/gQlqrNak0T3jIto/hXp4T6MGLkx3ovdqsNZN2Nxf5JqMwYJJsG5gIHi0DvwiO HK1v9NjIFjRPlId9JNgMiz8NKM2Wdl38a0SyGIclxilAMVFcbxsVKkWa+0YgRIs0GA4P5b2SI5c DVThIUt5hw9ovR6HMGdn4dreueQ07dntZvibM9kP3diChjtkwDHzrO9zbUOrzR6h1P3ArE79bVn yyn3bJ2zfBcKJMEdwv3y4aWcFKkC/0SeTD/JogNRkb4Sshapf0Feo/61q1QfKJdiYVcB8= X-Google-Smtp-Source: AGHT+IGNGdkYxDu4RNnvhaDwVvl/Rq0J8YhGbOK3oIot8sr5UOeyNDMUIHvZMbDWb9lbSF2aIj/0Cw== X-Received: by 2002:a05:6512:131a:b0:592:f72f:c1d8 with SMTP id 2adb3069b0e04-598faa1db17mr3424469e87.16.1765792069526; Mon, 15 Dec 2025 01:47:49 -0800 (PST) Received: from [192.168.1.168] (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-598f2f37ae8sm5397546e87.15.2025.12.15.01.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Dec 2025 01:47:48 -0800 (PST) From: Marcus Folkesson Date: Mon, 15 Dec 2025 10:46:46 +0100 Subject: [PATCH v3 4/7] drm/sitronix/st7571-i2c: make probe independent of hw interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251215-st7571-split-v3-4-d5f3205c3138@gmail.com> References: <20251215-st7571-split-v3-0-d5f3205c3138@gmail.com> In-Reply-To: <20251215-st7571-split-v3-0-d5f3205c3138@gmail.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Javier Martinez Canillas , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Marcus Folkesson X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10532; i=marcus.folkesson@gmail.com; h=from:subject:message-id; bh=Lms6/stTSeqardwm+RyauEeBz1C1uDEVLzFEIXT2v3s=; b=kA0DAAoBiIBOb1ldUjIByyZiAGk/2SqhW0zkq9G9T7nRMX8T3pCfTnzLFPTk7PS5gEHBgvIg4 YkCMwQAAQoAHRYhBAVRoui2bLVNZMEsZYiATm9ZXVIyBQJpP9kqAAoJEIiATm9ZXVIyKZwQAKfA 60KnqyoyZjfGEwXc33feUsH2BCH8JLNG8fXrDrhj7KAbSUIqY5D5AsF8MlSGtff/E0NhTMzMxh/ co+DQM3WxOmjSCmsia1vXN4VRidN0oUec+rgpmlCWeKNiLDfuoP+cguyj44vXiwl2BRcMZLjypS Tdu/hN6MgLEVwtnSF2cymvcHfB2gqOSSPY0J36jf66DlXiAY//AdFJO35MsDuWai+8iL4gxhCsa f71i/Bwe/FD3lVSkCp38Y5Dw+1MoJp4ayldJIxjSlm739swCJ7+SGkbYZrNprhhu8ljjjGN08gv 2bhaCK2TaJHAaRJFHvZN/OFy/4czBfeYQhA9jv4HU0Y5eWCODDhbRKzO8V9cv9XzHEZCNjKKNeq VgbF3ym+WmyMawjo7qm/z+WU/zfQH0CiqtG3vtxo52z3PhIKY99CA0zflhCT77wbA/B90kgj+kH dLeyqLHOFQARWBGHRZB3oTvHQ6qlsCss7TIWZGz7t0HObtK/9F+FSCi+fsdyYnPSA1Wq1Ng2uP0 NkOCfE7gwApJqYgw+PfQyexHcq/p/5knvHlGwqWVt0Swq4q0IyDq0MhTzbTBIT0Yswq9MtXSqRv UltAvYVaRkGcx47skN/EUcJbBTsKURmVgu+g2gJiLmaU7Ye2647vJxHWwifJYbh3khA8ktmM8Is tld/4 X-Developer-Key: i=marcus.folkesson@gmail.com; a=openpgp; fpr=AB91D46C7E0F6E6FB2AB640EC0FE25D598F6C127 Create an interface independent layer for the probe function. This is to make it possible to add support for other interfaces. Reviewed-by: Javier Martinez Canillas Signed-off-by: Marcus Folkesson --- drivers/gpu/drm/sitronix/st7571-i2c.c | 165 +++++++++++++++++++++++-------= ---- drivers/gpu/drm/sitronix/st7571.h | 25 +----- 2 files changed, 113 insertions(+), 77 deletions(-) diff --git a/drivers/gpu/drm/sitronix/st7571-i2c.c b/drivers/gpu/drm/sitron= ix/st7571-i2c.c index af27658a5e15..f994ace40739 100644 --- a/drivers/gpu/drm/sitronix/st7571-i2c.c +++ b/drivers/gpu/drm/sitronix/st7571-i2c.c @@ -80,6 +80,33 @@ #define DRIVER_MAJOR 1 #define DRIVER_MINOR 0 =20 +struct st7571_i2c_transport { + struct i2c_client *client; + + /* + * Depending on the hardware design, the acknowledge signal may be hard to + * recognize as a valid logic "0" level. + * Therefor, ignore NAK if possible to stay compatible with most hardware= designs + * and off-the-shelf panels out there. + * + * From section 6.4 MICROPOCESSOR INTERFACE section in the datasheet: + * + * "By connecting SDA_OUT to SDA_IN externally, the SDA line becomes fully + * I2C interface compatible. + * Separating acknowledge-output from serial data + * input is advantageous for chip-on-glass (COG) applications. In COG + * applications, the ITO resistance and the pull-up resistor will form a + * voltage divider, which affects acknowledge-signal level. Larger ITO + * resistance will raise the acknowledged-signal level and system cannot + * recognize this level as a valid logic =E2=80=9C0=E2=80=9D level. By se= parating SDA_IN from + * SDA_OUT, the IC can be used in a mode that ignores the acknowledge-bit. + * For applications which check acknowledge-bit, it is necessary to minim= ize + * the ITO resistance of the SDA_OUT trace to guarantee a valid low level= ." + * + */ + bool ignore_nak; +}; + static inline struct st7571_device *drm_to_st7571(struct drm_device *drm) { return container_of(drm, struct st7571_device, drm); @@ -87,18 +114,17 @@ static inline struct st7571_device *drm_to_st7571(stru= ct drm_device *drm) =20 static int st7571_regmap_write(void *context, const void *data, size_t cou= nt) { - struct i2c_client *client =3D context; - struct st7571_device *st7571 =3D i2c_get_clientdata(client); + struct st7571_i2c_transport *t =3D context; int ret; =20 struct i2c_msg msg =3D { - .addr =3D st7571->client->addr, - .flags =3D st7571->ignore_nak ? I2C_M_IGNORE_NAK : 0, + .addr =3D t->client->addr, + .flags =3D t->ignore_nak ? I2C_M_IGNORE_NAK : 0, .len =3D count, .buf =3D (u8 *)data }; =20 - ret =3D i2c_transfer(st7571->client->adapter, &msg, 1); + ret =3D i2c_transfer(t->client->adapter, &msg, 1); =20 /* * Unfortunately, there is no way to check if the transfer failed because= of @@ -106,7 +132,7 @@ static int st7571_regmap_write(void *context, const voi= d *data, size_t count) * * However, if the transfer fails and ignore_nak is set, we know it is an= error. */ - if (ret < 0 && st7571->ignore_nak) + if (ret < 0 && t->ignore_nak) return ret; =20 return 0; @@ -845,102 +871,135 @@ static int st7571_lcd_init(struct st7571_device *st= 7571) return st7571_send_command_list(st7571, commands, ARRAY_SIZE(commands)); } =20 -static int st7571_probe(struct i2c_client *client) +static struct st7571_device *st7571_probe(struct device *dev, + struct regmap *regmap) { struct st7571_device *st7571; struct drm_device *drm; int ret; =20 - st7571 =3D devm_drm_dev_alloc(&client->dev, &st7571_driver, + st7571 =3D devm_drm_dev_alloc(dev, &st7571_driver, struct st7571_device, drm); if (IS_ERR(st7571)) - return PTR_ERR(st7571); + return st7571; =20 drm =3D &st7571->drm; - st7571->dev =3D &client->dev; - st7571->client =3D client; - i2c_set_clientdata(client, st7571); + st7571->dev =3D dev; st7571->pdata =3D device_get_match_data(st7571->dev); =20 ret =3D st7571->pdata->parse_dt(st7571); if (ret) - return ret; + return ERR_PTR(ret); =20 ret =3D st7571_validate_parameters(st7571); if (ret) - return ret; + return ERR_PTR(ret); =20 st7571->mode =3D st7571_mode(st7571); + st7571->regmap =3D regmap; =20 - /* - * The hardware design could make it hard to detect a NAK on the I2C bus. - * If the adapter does not support protocol mangling do - * not set the I2C_M_IGNORE_NAK flag at the expense * of possible - * cruft in the logs. - */ - if (i2c_check_functionality(client->adapter, I2C_FUNC_PROTOCOL_MANGLING)) - st7571->ignore_nak =3D true; - - st7571->regmap =3D devm_regmap_init(st7571->dev, &st7571_regmap_bus, - client, &st7571_regmap_config); - if (IS_ERR(st7571->regmap)) { - return dev_err_probe(st7571->dev, PTR_ERR(st7571->regmap), - "Failed to initialize regmap\n"); - } =20 st7571->hwbuf =3D devm_kzalloc(st7571->dev, (st7571->nlines * st7571->ncols * st7571->bpp) / 8, GFP_KERNEL); if (!st7571->hwbuf) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 st7571->row =3D devm_kzalloc(st7571->dev, (st7571->ncols * st7571->bpp), GFP_KERNEL); if (!st7571->row) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 ret =3D st7571_mode_config_init(st7571); - if (ret) - return dev_err_probe(st7571->dev, ret, - "Failed to initialize mode config\n"); + if (ret) { + dev_err(st7571->dev, "Failed to initialize mode config\n"); + return ERR_PTR(ret); + } =20 ret =3D st7571_plane_init(st7571, st7571->pformat); - if (ret) - return dev_err_probe(st7571->dev, ret, - "Failed to initialize primary plane\n"); + if (ret) { + dev_err(st7571->dev, "Failed to initialize primary plane\n"); + return ERR_PTR(ret); + } =20 ret =3D st7571_crtc_init(st7571); - if (ret < 0) - return dev_err_probe(st7571->dev, ret, - "Failed to initialize CRTC\n"); + if (ret < 0) { + dev_err(st7571->dev, "Failed to initialize CRTC\n"); + return ERR_PTR(ret); + } =20 ret =3D st7571_encoder_init(st7571); - if (ret < 0) - return dev_err_probe(st7571->dev, ret, - "Failed to initialize encoder\n"); + if (ret < 0) { + dev_err(st7571->dev, "Failed to initialize encoder\n"); + return ERR_PTR(ret); + } =20 ret =3D st7571_connector_init(st7571); - if (ret < 0) - return dev_err_probe(st7571->dev, ret, - "Failed to initialize connector\n"); + if (ret < 0) { + dev_err(st7571->dev, "Failed to initialize connector\n"); + return ERR_PTR(ret); + } =20 drm_mode_config_reset(drm); =20 ret =3D drm_dev_register(drm, 0); - if (ret) - return dev_err_probe(st7571->dev, ret, - "Failed to register DRM device\n"); + if (ret) { + dev_err(st7571->dev, "Failed to register DRM device\n"); + return ERR_PTR(ret); + } =20 drm_client_setup(drm, NULL); + return st7571; +} + +static void st7571_remove(struct st7571_device *st7571) +{ + drm_dev_unplug(&st7571->drm); +} + +static int st7571_i2c_probe(struct i2c_client *client) +{ + struct st7571_device *st7571; + struct st7571_i2c_transport *t; + struct regmap *regmap; + + t =3D devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL); + if (!t) + return -ENOMEM; + + t->client =3D client; + + /* + * The hardware design could make it hard to detect a NAK on the I2C bus. + * If the adapter does not support protocol mangling do + * not set the I2C_M_IGNORE_NAK flag at the expense * of possible + * cruft in the logs. + */ + if (i2c_check_functionality(client->adapter, I2C_FUNC_PROTOCOL_MANGLING)) + t->ignore_nak =3D true; + + regmap =3D devm_regmap_init(&client->dev, &st7571_regmap_bus, + t, &st7571_regmap_config); + if (IS_ERR(regmap)) { + return dev_err_probe(&client->dev, PTR_ERR(regmap), + "Failed to initialize regmap\n"); + } + + st7571 =3D st7571_probe(&client->dev, regmap); + if (IS_ERR(st7571)) + return dev_err_probe(&client->dev, PTR_ERR(st7571), + "Failed to initialize regmap\n"); + + i2c_set_clientdata(client, st7571); return 0; } =20 -static void st7571_remove(struct i2c_client *client) +static void st7571_i2c_remove(struct i2c_client *client) { struct st7571_device *st7571 =3D i2c_get_clientdata(client); =20 - drm_dev_unplug(&st7571->drm); + st7571_remove(st7571); } =20 static const struct st7571_panel_data st7567_config =3D { @@ -986,8 +1045,8 @@ static struct i2c_driver st7571_i2c_driver =3D { .name =3D "st7571", .of_match_table =3D st7571_of_match, }, - .probe =3D st7571_probe, - .remove =3D st7571_remove, + .probe =3D st7571_i2c_probe, + .remove =3D st7571_i2c_remove, .id_table =3D st7571_id, }; =20 diff --git a/drivers/gpu/drm/sitronix/st7571.h b/drivers/gpu/drm/sitronix/s= t7571.h index c6fd6f1d3aa3..f62c57ddb99e 100644 --- a/drivers/gpu/drm/sitronix/st7571.h +++ b/drivers/gpu/drm/sitronix/st7571.h @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include =20 @@ -62,33 +63,9 @@ struct st7571_device { =20 const struct st7571_panel_format *pformat; const struct st7571_panel_data *pdata; - struct i2c_client *client; struct gpio_desc *reset; struct regmap *regmap; =20 - /* - * Depending on the hardware design, the acknowledge signal may be hard to - * recognize as a valid logic "0" level. - * Therefor, ignore NAK if possible to stay compatible with most hardware= designs - * and off-the-shelf panels out there. - * - * From section 6.4 MICROPOCESSOR INTERFACE section in the datasheet: - * - * "By connecting SDA_OUT to SDA_IN externally, the SDA line becomes fully - * I2C interface compatible. - * Separating acknowledge-output from serial data - * input is advantageous for chip-on-glass (COG) applications. In COG - * applications, the ITO resistance and the pull-up resistor will form a - * voltage divider, which affects acknowledge-signal level. Larger ITO - * resistance will raise the acknowledged-signal level and system cannot - * recognize this level as a valid logic =E2=80=9C0=E2=80=9D level. By se= parating SDA_IN from - * SDA_OUT, the IC can be used in a mode that ignores the acknowledge-bit. - * For applications which check acknowledge-bit, it is necessary to minim= ize - * the ITO resistance of the SDA_OUT trace to guarantee a valid low level= ." - * - */ - bool ignore_nak; - bool grayscale; bool inverted; u32 height_mm; --=20 2.51.2