From nobody Fri Dec 19 20:13:21 2025 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 C7FA21D95AA for ; Sun, 2 Feb 2025 12:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738498055; cv=none; b=u4kwW7ymR+Jsq8zY6DROFjpwl6uOzFv5wdc6BIO75RODYhL5yv0DlYRRVk8l+M4AA2bGtGE5XYWRf8onIHYnLSVdr0MN08sMSr9Paisl65pXtM2lQmHhix2qpv/OeVr9Bgf35zOy1e3HE/8wzhjyzxqme3XI6ERjjukAT3fLjr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738498055; c=relaxed/simple; bh=gLQhAOItk1SGD5tjqJAAptsrV//vN4Xt/at5DjS5YR4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YJ/GizX5zn9VRo4aFGzB07W+aM4f1Fr3PaN3n5g3Ta+lG3IOthcQ/OA1Pl2MOkg5pJkOImwkbqfZJp8xs8/DkKbtB7oetSFjRl/3k8mTHr676t6f48Ud6g0lbfWMoELbVSxAAKz9jFURkocX3s7l3o3O55DQVXIE3RfHEEP5Fng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=hxPocEf7; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hxPocEf7" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-540201cfedbso3069945e87.3 for ; Sun, 02 Feb 2025 04:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738498051; x=1739102851; 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=QQncvRRAuoLjn6XHpoivkjOodkjhTrikHPuhN7/HYX0=; b=hxPocEf7X5mcRfLwAT9+RtClcASYd8vzmaJA1uErXUDns718Z6j8NCmUV6vhH6m0is tGNPxcAFyAm3DbkbIjPcPvUWViil/O6BE5bm/imt5NwM4DJnQwg2jFxUFaa2uI/EuoRC mSCRtA9ixmKRpQ9X+Lki6/i1tctMmD2pq1nAPZq6lvQSF+W3X+LZnJ9MfWzKOCpuP67y wbVwVDvdJG90B1Ox02ZktuV6Vkr4CxMK8luM//PpmHKjscxRadNs6PJY97TE7637TZeu vx1E7M0+AJgNglRY6THtsQPqXjWjcEKrLcI9WmmFctgikfwG19iXlvaCwcxjxoQSUiNI pnRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738498051; x=1739102851; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QQncvRRAuoLjn6XHpoivkjOodkjhTrikHPuhN7/HYX0=; b=l4vSrn5hgcemQJ1PWQEpmpA6fBT3YfNAO4sV+GFY/HUANKXn5I0swue1nm64g1PWaC O+0Na2unaFFtAThHJmEMGJXAN/OoqIS3Fphh0fKyja03FPZ3kIi3fI6UBHqh6Po3x3ED eNHnFm0RbV+aHWvqox2aOkUsTIloy/WZN44nfJbaLfuIoctj/HjYjeL61Cd1+Sc49iuH dPMbguZ3GvnTGvnocw8ryIS4j+EdQ1z/dyrsGWM+B7cDUypeUrp1iXZ9UCLTgvvXJBJC XW1yakhLl/4T3V/eox4ioSz+G27TdrkrpBT8SND45kD/kzJgIkrHpsUYhmAjHYY355j2 CbFQ== X-Forwarded-Encrypted: i=1; AJvYcCUzq4fjX6NRgUXPW0AZlctjO0ie8/mNRScvEtgXIzqn9bKYGSOAgqb9d8qKvxjqp4EJAsBpy6MM+svFVh4=@vger.kernel.org X-Gm-Message-State: AOJu0YwGeJr53yvLw9MKMm5uNM4f7qfDbnOaeRoP0ivU0ljltJp0nsly L2nVVMjkRKc5Q+AGzs4Lr6/OGLTnzxuQIYdgacQSesOuSUZIt1jZ0w+Ztc32mkg= X-Gm-Gg: ASbGncuiAXbaoL9ksvdCMmUyUem9lGX60eZK+fA1AP45dgDaQiOqcYZAWs6m0PvYJ05 e4IBDbTMAilP9XeG9J1Q+myAIwVYQpoTiBMzDBs0KD/tf+rx6kJ9lGDp4IugkdP/Htqc4FI/Kgi hgw4Hot8JqAfM/0ZNrEoH3Aol55iND1FjNfNoKXmjIkrqTxQI4c4qpV2sMIqWlg4v8QFxKdF8DS hnHK+wK/Sv/JrTJqX2v782n/mXutMT+qfnI+ripWsxVl9YDd/nDwCu1/8+yGrecM3D3uKqdsIuY p1GGBqxE7Tn63hzn3kAbeuE= X-Google-Smtp-Source: AGHT+IFnGr8L+9iP3OQdkPVM5s571J/KyHyeV1CN/jrYqKSaEHG0644NFlegLXXwgJhE4erLTqfaFQ== X-Received: by 2002:a05:6512:2389:b0:542:8cf5:a384 with SMTP id 2adb3069b0e04-543e4be006fmr5936742e87.8.1738498050727; Sun, 02 Feb 2025 04:07:30 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-543ebe10678sm960695e87.101.2025.02.02.04.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2025 04:07:29 -0800 (PST) From: Dmitry Baryshkov Date: Sun, 02 Feb 2025 14:07:13 +0200 Subject: [PATCH v4 06/12] drm/vc4: hdmi: switch to generic CEC helpers 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: <20250202-drm-hdmi-connector-cec-v4-6-a71620a54d50@linaro.org> References: <20250202-drm-hdmi-connector-cec-v4-0-a71620a54d50@linaro.org> In-Reply-To: <20250202-drm-hdmi-connector-cec-v4-0-a71620a54d50@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10666; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=gLQhAOItk1SGD5tjqJAAptsrV//vN4Xt/at5DjS5YR4=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnn1/vWvLDojKsF20g4/2KT80ycY54icfhIVjGo 0lIfb6t9JWJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ59f7wAKCRCLPIo+Aiko 1YFTCACDcgTgFBV6ofWn3W5jkEq3MDrqHCvhJuZXeqtTJQ7z6k9C5qd2Ki8/A75YFhnRz3+Vpci zZ0a7yWlVgZbhVZUqfNmnBuzll2ZlE3WLvuVi702mTb6gTxsYkjZqhh4P+25FgmLEll9ijSj7Bz HOIrhz/bpZKIhXWiH7VJLzeQWWXglpPuZgOplHbhW89Eh4cTzwM43OjFKFlIdifA2NJ57T+kEph y1mZLk0mq8DksYOz8bIlkDNLtYsRk648AzTf+IF3ybFuIEgceulxMF40we6tjh02RU6DHgwIFFj KJqj5Expl4p5CR7bOkz/leXX+2rnjG8isTWw2OCIob6pKYdU X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A Switch VC4 driver to using CEC helpers code, simplifying hotplug and registration / cleanup. The existing vc4_hdmi_cec_release() is kept for now. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_hdmi.c | 138 ++++++++++++++++---------------------= ---- drivers/gpu/drm/vc4/vc4_hdmi.h | 1 - 3 files changed, 56 insertions(+), 84 deletions(-) diff --git a/drivers/gpu/drm/vc4/Kconfig b/drivers/gpu/drm/vc4/Kconfig index 123ab0ce178157c3b39466f87c7ac39c8470f329..bb8c40be325033632d3e94db87a= 16b03554ad3af 100644 --- a/drivers/gpu/drm/vc4/Kconfig +++ b/drivers/gpu/drm/vc4/Kconfig @@ -35,6 +35,7 @@ config DRM_VC4_HDMI_CEC bool "Broadcom VC4 HDMI CEC Support" depends on DRM_VC4 select CEC_CORE + select DRM_DISPLAY_HDMI_CEC_HELPER help Choose this option if you have a Broadcom VC4 GPU and want to use CEC. diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 47d9ada98430634cfd8c1e21c2a4d00d501bab7e..1108983c44858382cb9f09b6869= 56903645ebe0a 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -32,6 +32,7 @@ */ =20 #include +#include #include #include #include @@ -400,16 +401,8 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *v= c4_hdmi, * the lock for now. */ =20 - if (status =3D=3D connector_status_disconnected) { - cec_phys_addr_invalidate(vc4_hdmi->cec_adap); - return; - } - drm_atomic_helper_connector_hdmi_hotplug(connector, status); =20 - cec_s_phys_addr(vc4_hdmi->cec_adap, - connector->display_info.source_physical_address, false); - if (status !=3D connector_status_connected) return; =20 @@ -2388,8 +2381,8 @@ static irqreturn_t vc4_cec_irq_handler_rx_thread(int = irq, void *priv) struct vc4_hdmi *vc4_hdmi =3D priv; =20 if (vc4_hdmi->cec_rx_msg.len) - cec_received_msg(vc4_hdmi->cec_adap, - &vc4_hdmi->cec_rx_msg); + drm_connector_hdmi_cec_received_msg(&vc4_hdmi->connector, + &vc4_hdmi->cec_rx_msg); =20 return IRQ_HANDLED; } @@ -2399,15 +2392,17 @@ static irqreturn_t vc4_cec_irq_handler_tx_thread(in= t irq, void *priv) struct vc4_hdmi *vc4_hdmi =3D priv; =20 if (vc4_hdmi->cec_tx_ok) { - cec_transmit_done(vc4_hdmi->cec_adap, CEC_TX_STATUS_OK, - 0, 0, 0, 0); + drm_connector_hdmi_cec_transmit_done(&vc4_hdmi->connector, + CEC_TX_STATUS_OK, + 0, 0, 0, 0); } else { /* * This CEC implementation makes 1 retry, so if we * get a NACK, then that means it made 2 attempts. */ - cec_transmit_done(vc4_hdmi->cec_adap, CEC_TX_STATUS_NACK, - 0, 2, 0, 0); + drm_connector_hdmi_cec_transmit_done(&vc4_hdmi->connector, + CEC_TX_STATUS_NACK, + 0, 2, 0, 0); } return IRQ_HANDLED; } @@ -2564,9 +2559,9 @@ static irqreturn_t vc4_cec_irq_handler(int irq, void = *priv) return ret; } =20 -static int vc4_hdmi_cec_enable(struct cec_adapter *adap) +static int vc4_hdmi_cec_enable(struct drm_connector *connector) { - struct vc4_hdmi *vc4_hdmi =3D cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi =3D connector_to_vc4_hdmi(connector); struct drm_device *drm =3D vc4_hdmi->connector.dev; /* clock period in microseconds */ const u32 usecs =3D 1000000 / CEC_CLOCK_FREQ; @@ -2631,9 +2626,9 @@ static int vc4_hdmi_cec_enable(struct cec_adapter *ad= ap) return 0; } =20 -static int vc4_hdmi_cec_disable(struct cec_adapter *adap) +static int vc4_hdmi_cec_disable(struct drm_connector *connector) { - struct vc4_hdmi *vc4_hdmi =3D cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi =3D connector_to_vc4_hdmi(connector); struct drm_device *drm =3D vc4_hdmi->connector.dev; unsigned long flags; int idx; @@ -2667,17 +2662,17 @@ static int vc4_hdmi_cec_disable(struct cec_adapter = *adap) return 0; } =20 -static int vc4_hdmi_cec_adap_enable(struct cec_adapter *adap, bool enable) +static int vc4_hdmi_cec_adap_enable(struct drm_connector *connector, bool = enable) { if (enable) - return vc4_hdmi_cec_enable(adap); + return vc4_hdmi_cec_enable(connector); else - return vc4_hdmi_cec_disable(adap); + return vc4_hdmi_cec_disable(connector); } =20 -static int vc4_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 log_add= r) +static int vc4_hdmi_cec_adap_log_addr(struct drm_connector *connector, u8 = log_addr) { - struct vc4_hdmi *vc4_hdmi =3D cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi =3D connector_to_vc4_hdmi(connector); struct drm_device *drm =3D vc4_hdmi->connector.dev; unsigned long flags; int idx; @@ -2703,10 +2698,10 @@ static int vc4_hdmi_cec_adap_log_addr(struct cec_ad= apter *adap, u8 log_addr) return 0; } =20 -static int vc4_hdmi_cec_adap_transmit(struct cec_adapter *adap, u8 attempt= s, +static int vc4_hdmi_cec_adap_transmit(struct drm_connector *connector, u8 = attempts, u32 signal_free_time, struct cec_msg *msg) { - struct vc4_hdmi *vc4_hdmi =3D cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi =3D connector_to_vc4_hdmi(connector); struct drm_device *dev =3D vc4_hdmi->connector.dev; unsigned long flags; u32 val; @@ -2749,84 +2744,66 @@ static int vc4_hdmi_cec_adap_transmit(struct cec_ad= apter *adap, u8 attempts, return 0; } =20 -static const struct cec_adap_ops vc4_hdmi_cec_adap_ops =3D { - .adap_enable =3D vc4_hdmi_cec_adap_enable, - .adap_log_addr =3D vc4_hdmi_cec_adap_log_addr, - .adap_transmit =3D vc4_hdmi_cec_adap_transmit, -}; - -static void vc4_hdmi_cec_release(void *ptr) -{ - struct vc4_hdmi *vc4_hdmi =3D ptr; - - cec_unregister_adapter(vc4_hdmi->cec_adap); - vc4_hdmi->cec_adap =3D NULL; -} - -static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) +static int vc4_hdmi_cec_init(struct drm_connector *connector) { - struct cec_connector_info conn_info; + struct vc4_hdmi *vc4_hdmi =3D connector_to_vc4_hdmi(connector); struct platform_device *pdev =3D vc4_hdmi->pdev; struct device *dev =3D &pdev->dev; int ret; =20 - if (!of_property_present(dev->of_node, "interrupts")) { - dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); - return 0; - } - - vc4_hdmi->cec_adap =3D cec_allocate_adapter(&vc4_hdmi_cec_adap_ops, - vc4_hdmi, - vc4_hdmi->variant->card_name, - CEC_CAP_DEFAULTS | - CEC_CAP_CONNECTOR_INFO, 1); - ret =3D PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap); - if (ret < 0) - return ret; - - cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector); - cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info); - if (vc4_hdmi->variant->external_irq_controller) { ret =3D devm_request_threaded_irq(dev, platform_get_irq_byname(pdev, "ce= c-rx"), vc4_cec_irq_handler_rx_bare, vc4_cec_irq_handler_rx_thread, 0, "vc4 hdmi cec rx", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; =20 ret =3D devm_request_threaded_irq(dev, platform_get_irq_byname(pdev, "ce= c-tx"), vc4_cec_irq_handler_tx_bare, vc4_cec_irq_handler_tx_thread, 0, "vc4 hdmi cec tx", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; } else { ret =3D devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), vc4_cec_irq_handler, vc4_cec_irq_handler_thread, 0, "vc4 hdmi cec", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; } =20 - ret =3D cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev); - if (ret < 0) - goto err_delete_cec_adap; + return 0; +} + +static const struct drm_connector_hdmi_cec_adapter_ops vc4_hdmi_cec_adap_o= ps =3D { + .base.unregister =3D drm_connector_hdmi_cec_unregister, + .init =3D vc4_hdmi_cec_init, + .enable =3D vc4_hdmi_cec_adap_enable, + .log_addr =3D vc4_hdmi_cec_adap_log_addr, + .transmit =3D vc4_hdmi_cec_adap_transmit, +}; + +static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) +{ + struct platform_device *pdev =3D vc4_hdmi->pdev; + struct device *dev =3D &pdev->dev; + + if (!of_property_present(dev->of_node, "interrupts")) { + dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); + return 0; + } =20 /* - * NOTE: Strictly speaking, we should probably use a DRM-managed - * registration there to avoid removing the CEC adapter by the - * time the DRM driver doesn't have any user anymore. + * NOTE: the CEC adapter will be unregistered from + * drm_connector_cleanup(), which is called from drm_dev_unplug() + * during device unbind. * * However, the CEC framework already cleans up the CEC adapter * only when the last user has closed its file descriptor, so we * don't need to handle it in DRM. * - * By the time the device-managed hook is executed, we will give - * up our reference to the CEC adapter and therefore don't - * really care when it's actually freed. - * * There's still a problematic sequence: if we unregister our * CEC adapter, but the userspace keeps a handle on the CEC * adapter but not the DRM device for some reason. In such a @@ -2837,19 +2814,14 @@ static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_h= dmi) * the CEC framework already handles this too, by calling * cec_is_registered() in cec_ioctl() and cec_poll(). */ - ret =3D devm_add_action_or_reset(dev, vc4_hdmi_cec_release, vc4_hdmi); - if (ret) - return ret; - - return 0; - -err_delete_cec_adap: - cec_delete_adapter(vc4_hdmi->cec_adap); - - return ret; + return drm_connector_hdmi_cec_register(&vc4_hdmi->connector, + &vc4_hdmi_cec_adap_ops, + vc4_hdmi->variant->card_name, + 1, + &pdev->dev); } #else -static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) +static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) { return 0; } @@ -3271,7 +3243,7 @@ static int vc4_hdmi_bind(struct device *dev, struct d= evice *master, void *data) if (ret) goto err_put_runtime_pm; =20 - ret =3D vc4_hdmi_cec_init(vc4_hdmi); + ret =3D vc4_hdmi_cec_register(vc4_hdmi); if (ret) goto err_put_runtime_pm; =20 diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index e3d989ca302b72533c374dfa3fd0d5bd7fe64a82..5acbe27fb57659d02f32ca571dd= 3ded4a1a0d9dc 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -146,7 +146,6 @@ struct vc4_hdmi { */ bool disable_wifi_frequencies; =20 - struct cec_adapter *cec_adap; struct cec_msg cec_rx_msg; bool cec_tx_ok; bool cec_irq_was_rx; --=20 2.39.5