From patchwork Fri Dec 20 11:43:14 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: 13916655 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 DD2901C07FE for ; Fri, 20 Dec 2024 11:43:34 +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=1734695016; cv=none; b=HsCfRE0DFuDwjVYARJ+JKb4ed8ghoD+Og9Wwz+Q8yg9q7pjADFtGTD8BwEbZQ8BfF5RGZDtv8YQznKnHGI84wYwQFtBsKMSeO3aGnAoUq5GQtqIc0FBMUo8lYaFeiD/NIRPG4uNq1Y7maxa93uR5OggWOtiWwe92ABM4GUv0bXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734695016; c=relaxed/simple; bh=aao10dzqt96yU5beZA4/KFree79dGQBrHsMADMFYh50=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CHHU3bncHvNtdYSeDUKDhqK6+38gXB5wb3SOxGpN5bb6he+uIA+jL8YtufVw3Vu29mrcgfKztdneI6LpQAxG2esHJO/m76L7Fr8xu3i7R7REZozk8WrvMHT+yST34ZEaMmgH3e1wqClyF51WyBUhWryZIgSpcADr/ns2DM1SfOs= 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=IzaD4k96; 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="IzaD4k96" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734695013; 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; bh=Fyr4JezP/PHWB46kPYzXFpV8G10d/iivBgujoHfVZEs=; b=IzaD4k96rNNitTxAyk1iEet4Yutbaj+fwg8Uu7KwjcVylOE9wQFm9nfAiQ/BD9Cs+SnCVA 2/7zxim2O7F6ygtJZRcsTZd6lDBkpSdCB3mi4wrbjIdJy04irFBHa2NqSFjHoYbqZCjGRL e2Yn0RdY0Y42VAZ9FSPzHgM9MdueEA4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-VJd3mi5mMp2y0-E8umO3mA-1; Fri, 20 Dec 2024 06:43:28 -0500 X-MC-Unique: VJd3mi5mMp2y0-E8umO3mA-1 X-Mimecast-MFC-AGG-ID: VJd3mi5mMp2y0-E8umO3mA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0675719560AA; Fri, 20 Dec 2024 11:43:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.74]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DAE7195609D; Fri, 20 Dec 2024 11:43:23 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Tianshu Qiu , Bingbu Cao Cc: Hans de Goede , Mauro Carvalho Chehab , Ricardo Ribalda , linux-media@vger.kernel.org, Stanislaw Gruszka Subject: [PATCH v2 1/4] media: ov2740: Debug log chip ID Date: Fri, 20 Dec 2024 12:43:14 +0100 Message-ID: <20241220114317.21219-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.0 on 10.30.177.15 Calling the identify function may get delayed till the first stream-on, add a dev_dbg() to it so that we know when it has run. This is useful to debug bring-up problems related to regulators / clks / GPIOs. Reviewed-by: Ricardo Ribalda Tested-by: Stanislaw Gruszka Signed-off-by: Hans de Goede --- Changes in v2: - Prefix chip-id with "0x" when logging it as it is logged in hex --- drivers/media/i2c/ov2740.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index c484b753a718..a79e478342dd 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -644,6 +644,8 @@ static int ov2740_identify_module(struct ov2740 *ov2740) return -ENXIO; } + dev_dbg(&client->dev, "chip id: 0x%x\n", val); + ov2740->identified = true; return 0; From patchwork Fri Dec 20 11:43:15 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: 13916656 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 45BC91C07CD for ; Fri, 20 Dec 2024 11:43:35 +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=1734695018; cv=none; b=Hmzp6QgnTd0VmaVZxN0S9CYSY4E5QS5GQnF/tYB3emzXTrPeHWuNQOhWNjmBsp81GQQZO0r+nWDL67g+dyWNxU4m0+mhRxgjTmTD+l5k9RahSAg1GDd6jeIKUrG/GpRx6OZLWhMYiz5lMnqaeTdfP2tHpqnddLcovHgmC+TNmYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734695018; c=relaxed/simple; bh=ldfR3xb/ut09rqX6lTdfeOyz8/A5w+uOLKEWgSXGrSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ogn/TQOsWJAIQ7cnASd3BUjL/4VrL0NKsrJ8EWW4z8DGxPpgKPmY/Ae/MjQOvljgdoIyuyFVhESCktfmhwSP7XerDi46xMChHpYKSoVCLj/xlvF3sLt6RQeBxivJvgJGAH1ssjW2IV3jgmH4N5AjN5N+ryBrtARljbSvDkpbu0I= 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=QOwqMwdd; 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="QOwqMwdd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734695014; 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=ze+ZgzfkRj3DNrpGfsdmyoEAPQoL1RY7NC2bvvVgYu4=; b=QOwqMwddmtaRDMMFm1pKDskKZNNQugSUOMoZmoIvEMovAEauePMbpOmdPOieXLxbQnoFPF qML2M3kfIRjRuhBjLK3AY3UIz7gIeihSFJQNNpEVvkW6KvS1x2W9jQilnZAKUHHg0X2S0h zGEO6g5zIPXD2xreiRGlTWGzwkOkyMo= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-kIAT7G1GPBaWggb8N2BRtg-1; Fri, 20 Dec 2024 06:43:31 -0500 X-MC-Unique: kIAT7G1GPBaWggb8N2BRtg-1 X-Mimecast-MFC-AGG-ID: kIAT7G1GPBaWggb8N2BRtg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D877719560A2; Fri, 20 Dec 2024 11:43:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.74]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4ECDE195608A; Fri, 20 Dec 2024 11:43:27 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Tianshu Qiu , Bingbu Cao Cc: Hans de Goede , Mauro Carvalho Chehab , Ricardo Ribalda , linux-media@vger.kernel.org, Stanislaw Gruszka Subject: [PATCH v2 2/4] media: ov2740: Add camera orientation and sensor rotation controls Date: Fri, 20 Dec 2024 12:43:15 +0100 Message-ID: <20241220114317.21219-2-hdegoede@redhat.com> In-Reply-To: <20241220114317.21219-1-hdegoede@redhat.com> References: <20241220114317.21219-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.0 on 10.30.177.15 Add camera orientation and sensor rotation controls using the v4l2_fwnode_device_parse() and v4l2_ctrl_new_fwnode_properties() helpers. Tested-by: Stanislaw Gruszka Signed-off-by: Hans de Goede Reviewed-by: Ricardo Ribalda --- Changes in v2: - Call v4l2_ctrl_handler_free() on v4l2_fwnode_device_parse() errors --- drivers/media/i2c/ov2740.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index a79e478342dd..bd7475c337e2 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -755,15 +755,17 @@ static const struct v4l2_ctrl_ops ov2740_ctrl_ops = { static int ov2740_init_controls(struct ov2740 *ov2740) { + struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); struct v4l2_ctrl_handler *ctrl_hdlr; const struct ov2740_mode *cur_mode; s64 exposure_max, h_blank, pixel_rate; u32 vblank_min, vblank_max, vblank_default; + struct v4l2_fwnode_device_properties props; int size; int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10); if (ret) return ret; @@ -813,6 +815,15 @@ static int ov2740_init_controls(struct ov2740 *ov2740) V4L2_CID_TEST_PATTERN, ARRAY_SIZE(ov2740_test_pattern_menu) - 1, 0, 0, ov2740_test_pattern_menu); + + ret = v4l2_fwnode_device_parse(&client->dev, &props); + if (ret) { + v4l2_ctrl_handler_free(ctrl_hdlr); + return ret; + } + + v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &ov2740_ctrl_ops, &props); + if (ctrl_hdlr->error) { v4l2_ctrl_handler_free(ctrl_hdlr); return ctrl_hdlr->error; From patchwork Fri Dec 20 11:43:16 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: 13916657 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 E63981C07FE for ; Fri, 20 Dec 2024 11:43:37 +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=1734695019; cv=none; b=SDFsrqzYSLYU9sLwfWlTNpGB2xAc5XhJZG00vLpp2swT1iv9StBpRpjW6ZHsZ47Ew5XHtB51F6WRZGOs+DWnPGSZFD5H5B5eL/xSDUZULAYgS6Lv0gkE3N6BCzuhrXWUqjH3auFhmT769enwSbMb912AD/OvLEphc0BZMnn+sQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734695019; c=relaxed/simple; bh=hsPz69MzjmcIoDAhid+LhdCnlCLmEUA0S18ARdxlDA4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BzAX8Tv4Daj1Rj9ercUUCPn+lZwIv+JdBX/A1hyBfQtOjn0UVEaDPQTIcaNpnbD+7cCDkGszdT/8Uwx5MAOvKDHmxiAIJR+MbaNC95QE27pJTTX+7ncbn2P9rdQxjdJGaCJ0C1xELWVPRI20jHCuoqP8OCBqJcXjG8NFzgWve5k= 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=iDwRsN4U; 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="iDwRsN4U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734695016; 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=AYsw5oU1PQaf1eTERqYuhMXTCvUl+XagFLUha6auHIw=; b=iDwRsN4U7s7m1M7w/ekrrxAjgD3cAukSLIZG+jkco7kSf7phLFJcNBbPmD5KXgRq0ZnYGc blRaU1zNTdHs8UhaB/b900CpgNwE+wO24UbbsXV+ksZy0lHtoT0/wJ7O+mCz/+M8l1AJa3 3psPjRn9D2sbIWKX1w4IIv1HQMCrWRA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-KsO67oYcMoGw2sXAfWjT0A-1; Fri, 20 Dec 2024 06:43:34 -0500 X-MC-Unique: KsO67oYcMoGw2sXAfWjT0A-1 X-Mimecast-MFC-AGG-ID: KsO67oYcMoGw2sXAfWjT0A Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C059E19560AB; Fri, 20 Dec 2024 11:43:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.74]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50725195608A; Fri, 20 Dec 2024 11:43:30 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Tianshu Qiu , Bingbu Cao Cc: Hans de Goede , Mauro Carvalho Chehab , Ricardo Ribalda , linux-media@vger.kernel.org, Stanislaw Gruszka Subject: [PATCH v2 3/4] media: ov2740: Add powerdown GPIO support Date: Fri, 20 Dec 2024 12:43:16 +0100 Message-ID: <20241220114317.21219-3-hdegoede@redhat.com> In-Reply-To: <20241220114317.21219-1-hdegoede@redhat.com> References: <20241220114317.21219-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.0 on 10.30.177.15 The ov2740 sensor has both reset and power_down inputs according to the datasheet one or the other should always be tied to DOVDD but on some designs both are attached to GPIOs. Add support for controlling both a reset and a powerdown GPIO. Acked-by: Ricardo Ribalda Tested-by: Stanislaw Gruszka Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2740.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index bd7475c337e2..0ee83e2680eb 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -525,6 +525,7 @@ struct ov2740 { /* GPIOs, clocks */ struct gpio_desc *reset_gpio; + struct gpio_desc *powerdown_gpio; struct clk *clk; /* Current mode */ @@ -1308,6 +1309,7 @@ static int ov2740_suspend(struct device *dev) struct ov2740 *ov2740 = to_ov2740(sd); gpiod_set_value_cansleep(ov2740->reset_gpio, 1); + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 1); clk_disable_unprepare(ov2740->clk); return 0; } @@ -1322,6 +1324,7 @@ static int ov2740_resume(struct device *dev) if (ret) return ret; + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 0); gpiod_set_value_cansleep(ov2740->reset_gpio, 0); msleep(20); @@ -1350,9 +1353,17 @@ static int ov2740_probe(struct i2c_client *client) if (IS_ERR(ov2740->reset_gpio)) { return dev_err_probe(dev, PTR_ERR(ov2740->reset_gpio), "failed to get reset GPIO\n"); - } else if (ov2740->reset_gpio) { + } + + ov2740->powerdown_gpio = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); + if (IS_ERR(ov2740->powerdown_gpio)) { + return dev_err_probe(dev, PTR_ERR(ov2740->powerdown_gpio), + "failed to get powerdown GPIO\n"); + } + + if (ov2740->reset_gpio || ov2740->powerdown_gpio) { /* - * Ensure reset is asserted for at least 20 ms before + * Ensure reset/powerdown is asserted for at least 20 ms before * ov2740_resume() deasserts it. */ msleep(20); From patchwork Fri Dec 20 11:43:17 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: 13916658 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 A0F6D1C07FE for ; Fri, 20 Dec 2024 11:43:40 +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=1734695022; cv=none; b=nfaFX21OWqh9bm1ktDQwsEIOgIR1lIX37WUJ8MY2KrV6goMJQKlQtWCO+xkjxktTLOiLd8FJoOWM8eOlAcJFDw8NzT5nwNnb3WguHD8eCk6qYpkv4xJDTXnq5yxsYbs+lFJcQ5lqfnrkJXlj830cELC9+9YKrqn/YXmo5fGTfF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734695022; c=relaxed/simple; bh=1Q4r/2vnj4uHxSoaDJQaKLSjXx8RPbWgH9Xd9zP3oGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fPCLgTtBpS6oR5jf7Ub7cFMmpxu2sTAi4IPVQO1HUlE6x8Gg21GwLTDHurGb1i1nenopUjgQe0l2MpeHc3D33I4SHW27CFgSFq9usI9gVFp4Ae4y6ZY1NrL0uQxbrSOvc2/CNUNtz1bbz6+14HzQxAMA98GOkp0uyjI64VPfE4k= 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=HtiEnGiC; 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="HtiEnGiC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734695019; 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=gyqeW1ucNsufnmm4yh81pi2UUfJhZQ3+Y92Tk5SVFas=; b=HtiEnGiCnXcmnjKIHetFR4+2VTTGihC8CuC11IdA28KHS9G9JL5B90ymHsvDZA4m+HjPrc t54VyBM0/EQMleB9i9N4gsHAYtoiXNCaTiJrEwxaL6bWruHWhL9t45fDZH9Wm7+mosM90x ZOgsmjM+dbEkHvH1u5TKvS1gdcmcv+w= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-ypUx_1lrO4WAGEp8aIkAJg-1; Fri, 20 Dec 2024 06:43:36 -0500 X-MC-Unique: ypUx_1lrO4WAGEp8aIkAJg-1 X-Mimecast-MFC-AGG-ID: ypUx_1lrO4WAGEp8aIkAJg Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5CFFD19560B1; Fri, 20 Dec 2024 11:43:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.74]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2EEE8195608A; Fri, 20 Dec 2024 11:43:32 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Tianshu Qiu , Bingbu Cao Cc: Hans de Goede , Mauro Carvalho Chehab , Ricardo Ribalda , linux-media@vger.kernel.org, Stanislaw Gruszka Subject: [PATCH v2 4/4] media: ov2740: Add regulator support Date: Fri, 20 Dec 2024 12:43:17 +0100 Message-ID: <20241220114317.21219-4-hdegoede@redhat.com> In-Reply-To: <20241220114317.21219-1-hdegoede@redhat.com> References: <20241220114317.21219-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.0 on 10.30.177.15 On some designs the regulators for the AVDD / DOVDD / DVDD power rails are controlled by Linux. Add support to the driver for getting regulators for these 3 rails and for enabling these regulators when necessary. The datasheet specifies a delay of 0ns between enabling the regulators, IOW they can all 3 be enabled at the same time. This allows using the bulk regulator API. The regulator core will provide dummy regulators for the 3 power-rails when necessary. Acked-by: Ricardo Ribalda Tested-by: Stanislaw Gruszka Signed-off-by: Hans de Goede --- Changes in v2: - Directly use ARRAY_SIZE(ov2740_supply_name), drop OV2740_NUM_SUPPLIES define - Make i in probe() unsigned --- drivers/media/i2c/ov2740.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index 0ee83e2680eb..80d151e8ae29 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,12 @@ /* OTP registers from sensor */ #define OV2740_REG_OTP_CUSTOMER 0x7010 +static const char * const ov2740_supply_name[] = { + "AVDD", + "DOVDD", + "DVDD", +}; + struct nvm_data { struct nvmem_device *nvmem; struct regmap *regmap; @@ -523,10 +530,11 @@ struct ov2740 { struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; - /* GPIOs, clocks */ + /* GPIOs, clocks, regulators */ struct gpio_desc *reset_gpio; struct gpio_desc *powerdown_gpio; struct clk *clk; + struct regulator_bulk_data supplies[ARRAY_SIZE(ov2740_supply_name)]; /* Current mode */ const struct ov2740_mode *cur_mode; @@ -1311,6 +1319,8 @@ static int ov2740_suspend(struct device *dev) gpiod_set_value_cansleep(ov2740->reset_gpio, 1); gpiod_set_value_cansleep(ov2740->powerdown_gpio, 1); clk_disable_unprepare(ov2740->clk); + regulator_bulk_disable(ARRAY_SIZE(ov2740_supply_name), + ov2740->supplies); return 0; } @@ -1320,10 +1330,18 @@ static int ov2740_resume(struct device *dev) struct ov2740 *ov2740 = to_ov2740(sd); int ret; - ret = clk_prepare_enable(ov2740->clk); + ret = regulator_bulk_enable(ARRAY_SIZE(ov2740_supply_name), + ov2740->supplies); if (ret) return ret; + ret = clk_prepare_enable(ov2740->clk); + if (ret) { + regulator_bulk_disable(ARRAY_SIZE(ov2740_supply_name), + ov2740->supplies); + return ret; + } + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 0); gpiod_set_value_cansleep(ov2740->reset_gpio, 0); msleep(20); @@ -1336,6 +1354,7 @@ static int ov2740_probe(struct i2c_client *client) struct device *dev = &client->dev; struct ov2740 *ov2740; bool full_power; + unsigned int i; int ret; ov2740 = devm_kzalloc(&client->dev, sizeof(*ov2740), GFP_KERNEL); @@ -1374,6 +1393,14 @@ static int ov2740_probe(struct i2c_client *client) return dev_err_probe(dev, PTR_ERR(ov2740->clk), "failed to get clock\n"); + for (i = 0; i < ARRAY_SIZE(ov2740_supply_name); i++) + ov2740->supplies[i].supply = ov2740_supply_name[i]; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ov2740_supply_name), + ov2740->supplies); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { /* ACPI does not always clear the reset GPIO / enable the clock */