From patchwork Mon Apr 15 09:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13629711 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 F12773EA96 for ; Mon, 15 Apr 2024 09:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174113; cv=none; b=dKGBHH5dQDLdtldoD8zf7uzDGeSQyJhPHGCYI3lhENxY6sa4zm4jssOkt4Veq2tLOfeDpSlj1fACAjCrplzPbO8fexWp/UkhJNqFd2NSd95evoCj9rQkAZ4OHgiPvM9GAhojew3KxJbws/M4qth82hpjsWIg405O0gW/nTWSpbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174113; c=relaxed/simple; bh=soogh2Kl4OCTxsK8RSBuV4VmMnuEw2/vj6QNAvJ3kdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bhRIDIcAyS7gN2H9djWAFWiu05IMVPLgNXzDH+xNo9Sddh/YpiI/FuoMOtx1E4D/eyMcb5e2FxbdCPmk+mZrPrt2JC+aeUCiuEFC3XX4pK48zOKau9vdJME/RmQ7PcdjEPp8RfEI/lC8VeT+FCQbG+GCQkG1JEHYXkrYSNadWmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UXVDzmbj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UXVDzmbj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713174109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0kRsVSPkQfYy3ExT7223wBLMdl5dF1rzos3a1fVd3B4=; b=UXVDzmbjGyntGRRrBPzJCDgGejKXFAjmCAMvsuug1dBaN8I7vmsgMYCR8H4Rbjt3f3fyJd q2i8Aj72o4dueXpROPY7OpuLtJm++O7PZtdOZOrjwZ84AZCWxbVu14C6T/RZai0J8hu6TV A6Orx4vyRJM1QxhLYVA1Yheac+x0EGk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-oMBqdxTzMMCtMx1nzIVkKw-1; Mon, 15 Apr 2024 05:41:48 -0400 X-MC-Unique: oMBqdxTzMMCtMx1nzIVkKw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5C0E3C025C3; Mon, 15 Apr 2024 09:41:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.195.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF402492BC9; Mon, 15 Apr 2024 09:41:46 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Rui Miguel Silva Cc: Hans de Goede , Mauro Carvalho Chehab , Kate Hsuan , Kieran Bingham , linux-media@vger.kernel.org Subject: [PATCH resend 1/4] media: hi556: Return -EPROBE_DEFER if no endpoint is found Date: Mon, 15 Apr 2024 11:41:30 +0200 Message-ID: <20240415094133.210580-2-hdegoede@redhat.com> In-Reply-To: <20240415094133.210580-1-hdegoede@redhat.com> References: <20240415094133.210580-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 With ipu bridge, endpoints may only be created when ipu bridge has initialised. This may happen after the sensor driver has first probed. Signed-off-by: Hans de Goede --- drivers/media/i2c/hi556.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c index 38c77d515786..96bae9914d52 100644 --- a/drivers/media/i2c/hi556.c +++ b/drivers/media/i2c/hi556.c @@ -1206,8 +1206,13 @@ static int hi556_check_hwcfg(struct device *dev) int ret = 0; unsigned int i, j; - if (!fwnode) - return -ENXIO; + /* + * Sometimes the fwnode graph is initialized by the bridge driver, + * wait for this. + */ + ep = fwnode_graph_get_next_endpoint(fwnode, NULL); + if (!ep) + return -EPROBE_DEFER; ret = fwnode_property_read_u32(fwnode, "clock-frequency", &mclk); if (ret) { @@ -1220,10 +1225,6 @@ static int hi556_check_hwcfg(struct device *dev) return -EINVAL; } - ep = fwnode_graph_get_next_endpoint(fwnode, NULL); - if (!ep) - return -ENXIO; - ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); fwnode_handle_put(ep); if (ret) From patchwork Mon Apr 15 09:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13629714 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 BEF3E3FBAE for ; Mon, 15 Apr 2024 09:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174117; cv=none; b=p+HQOenTcjnRuGLLyjfRrd5S6LJ/lYTjNG9KF+SpIjjk92YedV1XUjNp4xoYQB/TeL/RhxYpUgwWC16F+hiELbz+x7bMoOeiPgV5KqJc8SB5b8cOgg2xGH8D2jbF+fOyvSfOXRWrMjUDSJ9re4yC52k177Hwqx4BIEPoypqjdYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174117; c=relaxed/simple; bh=Zzn31TLG51HSpJ6iNnZdQkescJ4j01fDjqLbBfiq36k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TMxD4sjeTDAKlTVGgSj0vbyf6xJyTzJ/PS8kfogpYmW3yDnXc/DftyfEw0eFgyoOMjfBsEh5gKYEDLEGu39grRGTvEkRVTODvr1UijuEnuyNSMnolucLqzh00HIodnhxpQHnXFoJEa/xEF8vACFF/Uywh+khodTTL08+5/COhDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q74zMBw/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q74zMBw/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713174114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DUZUMZHmc3gNotXUBYhT3YTGOgxWtDjeo2rRtpwteFg=; b=Q74zMBw/coNS+3d7A6ZEA9UrhDZ5qWtJ2mf3R8akh+qEEzf5P6enWBRC5cxlMfffVf4nTv zbFRHpZ0/Wl0XzM5q6t8rr8A1jrh9n+PThjMW1ZfzytUMWsiJ+dtHkqEJGVlRrw1BgVA0C f5Au8aYtl0oVb8b3ttkXKmMnP9+kRbA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-23lONq6pOYCwdTZQtoWdCA-1; Mon, 15 Apr 2024 05:41:49 -0400 X-MC-Unique: 23lONq6pOYCwdTZQtoWdCA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DF995881E62; Mon, 15 Apr 2024 09:41:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.195.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9090492BC8; Mon, 15 Apr 2024 09:41:47 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Rui Miguel Silva Cc: Hans de Goede , Mauro Carvalho Chehab , Kate Hsuan , Kieran Bingham , linux-media@vger.kernel.org Subject: [PATCH resend 2/4] media: hi556: Add support for reset GPIO Date: Mon, 15 Apr 2024 11:41:31 +0200 Message-ID: <20240415094133.210580-3-hdegoede@redhat.com> In-Reply-To: <20240415094133.210580-1-hdegoede@redhat.com> References: <20240415094133.210580-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 On some ACPI platforms, such as Chromebooks the ACPI methods to change the power-state (_PS0 and _PS3) fully take care of powering on/off the sensor. On other ACPI platforms, such as e.g. various HP models with IPU6 + hi556 sensor, the sensor driver must control the reset GPIO itself. Add support for having the driver control an optional reset GPIO. Signed-off-by: Hans de Goede --- drivers/media/i2c/hi556.c | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c index 96bae9914d52..f5a39b83598b 100644 --- a/drivers/media/i2c/hi556.c +++ b/drivers/media/i2c/hi556.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -633,6 +634,9 @@ struct hi556 { struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; + /* GPIOs, clocks, etc. */ + struct gpio_desc *reset_gpio; + /* Current mode */ const struct hi556_mode *cur_mode; @@ -1276,6 +1280,25 @@ static void hi556_remove(struct i2c_client *client) mutex_destroy(&hi556->mutex); } +static int hi556_suspend(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct hi556 *hi556 = to_hi556(sd); + + gpiod_set_value_cansleep(hi556->reset_gpio, 1); + return 0; +} + +static int hi556_resume(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct hi556 *hi556 = to_hi556(sd); + + gpiod_set_value_cansleep(hi556->reset_gpio, 0); + usleep_range(5000, 5500); + return 0; +} + static int hi556_probe(struct i2c_client *client) { struct hi556 *hi556; @@ -1295,12 +1318,24 @@ static int hi556_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&hi556->sd, client, &hi556_subdev_ops); + hi556->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(hi556->reset_gpio)) + return dev_err_probe(&client->dev, PTR_ERR(hi556->reset_gpio), + "failed to get reset GPIO\n"); + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { + /* Ensure non ACPI managed resources are enabled */ + ret = hi556_resume(&client->dev); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to power on sensor\n"); + ret = hi556_identify_module(hi556); if (ret) { dev_err(&client->dev, "failed to find sensor: %d", ret); - return ret; + goto probe_error_power_off; } } @@ -1345,9 +1380,16 @@ static int hi556_probe(struct i2c_client *client) v4l2_ctrl_handler_free(hi556->sd.ctrl_handler); mutex_destroy(&hi556->mutex); +probe_error_power_off: + if (full_power) + hi556_suspend(&client->dev); + return ret; } +static DEFINE_RUNTIME_DEV_PM_OPS(hi556_pm_ops, hi556_suspend, hi556_resume, + NULL); + #ifdef CONFIG_ACPI static const struct acpi_device_id hi556_acpi_ids[] = { {"INT3537"}, @@ -1361,6 +1403,7 @@ static struct i2c_driver hi556_i2c_driver = { .driver = { .name = "hi556", .acpi_match_table = ACPI_PTR(hi556_acpi_ids), + .pm = pm_sleep_ptr(&hi556_pm_ops), }, .probe = hi556_probe, .remove = hi556_remove, From patchwork Mon Apr 15 09:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13629713 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 E2BAD3EA96 for ; Mon, 15 Apr 2024 09:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174116; cv=none; b=uiO26hYHmvTdGI7QxWjefiJqmLeedFPkRCsEtJwzki83FXlOXUa1Dsrb4XSq4IWockqnpQMe5AK+t9AOQO76imf0Ulze1KaVSLD8yF2Z5CrHgXApmL2MLW09GEj140u6fNeZnLYUuIx25TAr3WWJXoVNF3qgPZoGYuWvIMDOlrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174116; c=relaxed/simple; bh=15PpbWBgrXUsaMQuKnvvR4wdLsN7XoiqT2cnrYYAv/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AsAOvZc4rXUP3FFz7O68EGZciLRA5rKnz5vID7h4sWLbH0ApmAV2tG4HjKF+NSvSqpJeMhK35ZkqZ1tKoRSkX8+IvhBpoGtGb1Abs/hhRdOFYB8ac8Lj7ROyZH2f4uRyI/d8EWCEVSk38yA1RJ5p3uUAFrVGpvSw93gRB2cYzRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Yu3tsB9n; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yu3tsB9n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713174113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uJCp6rrQC844l61YbZjijrtQd4N9DxhtZyWzpwOw8WU=; b=Yu3tsB9nT6iBOUXR19Zj7pBCzV7nSeFIJ/Ky+bkVTYt6DSAAfT8LUeH3937GpeuR3NtTOR vwSInffZBRRIYFY6C8lEMB6EifjCMKMoOawuGmSLW1HEyzFIiXJ/PVuVFlaEMv64WuEWKw rSt1qWqiOnh529h5SL9B0nvAFFBZhXg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-UaFasqNdM7y5YZtwwYv7jA-1; Mon, 15 Apr 2024 05:41:50 -0400 X-MC-Unique: UaFasqNdM7y5YZtwwYv7jA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11DAF830E75; Mon, 15 Apr 2024 09:41:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.195.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BD3C492BC7; Mon, 15 Apr 2024 09:41:49 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Rui Miguel Silva Cc: Hans de Goede , Mauro Carvalho Chehab , Kate Hsuan , Kieran Bingham , linux-media@vger.kernel.org Subject: [PATCH resend 3/4] media: hi556: Add support for external clock Date: Mon, 15 Apr 2024 11:41:32 +0200 Message-ID: <20240415094133.210580-4-hdegoede@redhat.com> In-Reply-To: <20240415094133.210580-1-hdegoede@redhat.com> References: <20240415094133.210580-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 On some ACPI platforms, such as Chromebooks the ACPI methods to change the power-state (_PS0 and _PS3) fully take care of powering on/off the sensor. On other ACPI platforms, such as e.g. various HP models with IPU6 + hi556 sensor, the sensor driver must control the sensor's clock itself. Add support for having the driver control an optional clock. Signed-off-by: Hans de Goede --- drivers/media/i2c/hi556.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c index f5a39b83598b..b783e0f56687 100644 --- a/drivers/media/i2c/hi556.c +++ b/drivers/media/i2c/hi556.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -636,6 +637,7 @@ struct hi556 { /* GPIOs, clocks, etc. */ struct gpio_desc *reset_gpio; + struct clk *clk; /* Current mode */ const struct hi556_mode *cur_mode; @@ -1286,6 +1288,7 @@ static int hi556_suspend(struct device *dev) struct hi556 *hi556 = to_hi556(sd); gpiod_set_value_cansleep(hi556->reset_gpio, 1); + clk_disable_unprepare(hi556->clk); return 0; } @@ -1293,6 +1296,11 @@ static int hi556_resume(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); struct hi556 *hi556 = to_hi556(sd); + int ret; + + ret = clk_prepare_enable(hi556->clk); + if (ret) + return ret; gpiod_set_value_cansleep(hi556->reset_gpio, 0); usleep_range(5000, 5500); @@ -1324,6 +1332,11 @@ static int hi556_probe(struct i2c_client *client) return dev_err_probe(&client->dev, PTR_ERR(hi556->reset_gpio), "failed to get reset GPIO\n"); + hi556->clk = devm_clk_get_optional(&client->dev, "clk"); + if (IS_ERR(hi556->clk)) + return dev_err_probe(&client->dev, PTR_ERR(hi556->clk), + "failed to get clock\n"); + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { /* Ensure non ACPI managed resources are enabled */ From patchwork Mon Apr 15 09:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13629712 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 75BE4446AD for ; Mon, 15 Apr 2024 09:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174115; cv=none; b=oMkW9JeP5LlYnZ0qVeAqw12yOWs0Ae1VpB6cKN9NyhVMtLFiL61Iytx7cMZIqiZNt63zI2X6nboYhT250Npx9ndpsg43NiIAXKilTBsVFZqvVnol1jB4TV02lY7y6UhBn6vwa+2iWEDaFD7jAWh6XzmL0SzP2q7xN+bglz5YM2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174115; c=relaxed/simple; bh=OY+yzan0TGo1zadtOUGnX5magb/OiZZK3zpdjIOxl+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MYUccIALRV5/VVF7KFEomPCDUPwh/N3ABVvbPTzMrD65AY6dEcfwWsNZlNUzlRrDBTeyMX4XLzl1RCrcUXyn8lRZW1U1FA/KEyVAwlCGZ4nuUdT45yU1nPSMSXPqKyLLtAMQIYxMn4KdNMao1mU9ml5oQTMQeaVSgLsHB2iGlc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=C7AN0FrZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C7AN0FrZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713174113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QWWWu3C2VFCqfhP7lXz85x6U6MQsclb2hazeAcb5IlQ=; b=C7AN0FrZI6O1f6BnhE1dfKs9TWhbsk6PIfJi+p7TRv/C9FIQRCXRAG2yz4jn8Bmkzjc3DF IB+592d4vPK1ERTNaQnKf9reLh2WzMCEml4WE7NbFqP0GwoaGrcDgt/NM5+bl+EFMQUkSq nLALYK7LmZCrg70KAWwgdUGm+PpB8CQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-uEyCsP0JPYehpv7Lz-VE-Q-1; Mon, 15 Apr 2024 05:41:51 -0400 X-MC-Unique: uEyCsP0JPYehpv7Lz-VE-Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C32D29AC02F; Mon, 15 Apr 2024 09:41:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.195.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44C50492BC8; Mon, 15 Apr 2024 09:41:50 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Rui Miguel Silva Cc: Hans de Goede , Mauro Carvalho Chehab , Kate Hsuan , Kieran Bingham , linux-media@vger.kernel.org Subject: [PATCH resend 4/4] media: hi556: Add support for avdd regulator Date: Mon, 15 Apr 2024 11:41:33 +0200 Message-ID: <20240415094133.210580-5-hdegoede@redhat.com> In-Reply-To: <20240415094133.210580-1-hdegoede@redhat.com> References: <20240415094133.210580-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 On some ACPI platforms, such as Chromebooks the ACPI methods to change the power-state (_PS0 and _PS3) fully take care of powering on/off the sensor. On other ACPI platforms, such as e.g. various HP models with IPU6 + hi556 sensor, the sensor driver must control the avdd regulator itself. Add support for having the driver control the sensor's avdd regulator. Note this relies on the regulator-core providing a dummy regulator (which it does by default) on platforms where Linux is not aware of the avdd regulator. Signed-off-by: Hans de Goede --- drivers/media/i2c/hi556.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c index b783e0f56687..5641c249d4b1 100644 --- a/drivers/media/i2c/hi556.c +++ b/drivers/media/i2c/hi556.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -638,6 +639,7 @@ struct hi556 { /* GPIOs, clocks, etc. */ struct gpio_desc *reset_gpio; struct clk *clk; + struct regulator *avdd; /* Current mode */ const struct hi556_mode *cur_mode; @@ -1286,8 +1288,17 @@ static int hi556_suspend(struct device *dev) { struct v4l2_subdev *sd = dev_get_drvdata(dev); struct hi556 *hi556 = to_hi556(sd); + int ret; gpiod_set_value_cansleep(hi556->reset_gpio, 1); + + ret = regulator_disable(hi556->avdd); + if (ret) { + dev_err(dev, "failed to disable avdd: %d\n", ret); + gpiod_set_value_cansleep(hi556->reset_gpio, 0); + return ret; + } + clk_disable_unprepare(hi556->clk); return 0; } @@ -1302,6 +1313,13 @@ static int hi556_resume(struct device *dev) if (ret) return ret; + ret = regulator_enable(hi556->avdd); + if (ret) { + dev_err(dev, "failed to enable avdd: %d\n", ret); + clk_disable_unprepare(hi556->clk); + return ret; + } + gpiod_set_value_cansleep(hi556->reset_gpio, 0); usleep_range(5000, 5500); return 0; @@ -1337,6 +1355,12 @@ static int hi556_probe(struct i2c_client *client) return dev_err_probe(&client->dev, PTR_ERR(hi556->clk), "failed to get clock\n"); + /* The regulator core will provide a "dummy" regulator if necessary */ + hi556->avdd = devm_regulator_get(&client->dev, "avdd"); + if (IS_ERR(hi556->avdd)) + return dev_err_probe(&client->dev, PTR_ERR(hi556->avdd), + "failed to get avdd regulator\n"); + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { /* Ensure non ACPI managed resources are enabled */