From patchwork Mon Nov 28 21:44:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 629083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0055C4321E for ; Mon, 28 Nov 2022 21:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233977AbiK1VqG (ORCPT ); Mon, 28 Nov 2022 16:46:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233396AbiK1VqF (ORCPT ); Mon, 28 Nov 2022 16:46:05 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B15062ED6F for ; Mon, 28 Nov 2022 13:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669671860; 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=HYgpL2606mVfO+98npo7eaosHXY5I8deinLTWhiViEE=; b=BcHcgx/1YvkblQqc7QnXEX4eW7cFsprZsOPjZhWId9ioOQVpW0EPSwVLbCZ3xv4p/nuOiW +c1739FGfZlKFRPKqWr+0Ak+Zorv1+lSDiYnq5TZQVnTQa2ICHuMLmmXr0gRnyACp754jy aVFDyHrZYCJFJ3OpOOS8H9Y/W44Grg8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-197-XIfB4YCLNIye0mUOA4KgEA-1; Mon, 28 Nov 2022 16:44:15 -0500 X-MC-Unique: XIfB4YCLNIye0mUOA4KgEA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD33286C177; Mon, 28 Nov 2022 21:44:14 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23AFD40C6EC2; Mon, 28 Nov 2022 21:44:13 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Bartosz Golaszewski , Linus Walleij , Daniel Scally , Laurent Pinchart Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, linux-gpio@vger.kernel.org, Sakari Ailus , Kate Hsuan , linux-media@vger.kernel.org Subject: [PATCH 1/5] gpio: tps68470: Fix tps68470_gpio_get() reading from the wrong register Date: Mon, 28 Nov 2022 22:44:04 +0100 Message-Id: <20221128214408.165726-2-hdegoede@redhat.com> In-Reply-To: <20221128214408.165726-1-hdegoede@redhat.com> References: <20221128214408.165726-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org For the regular GPIO pins the value should be read from TPS68470_REG_GPDI, so that the actual value of the pin is read, rather then the value the pin would output when put in output mode. Signed-off-by: Hans de Goede --- drivers/gpio/gpio-tps68470.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-tps68470.c b/drivers/gpio/gpio-tps68470.c index aaddcabe9b35..778a72cf800c 100644 --- a/drivers/gpio/gpio-tps68470.c +++ b/drivers/gpio/gpio-tps68470.c @@ -30,7 +30,7 @@ static int tps68470_gpio_get(struct gpio_chip *gc, unsigned int offset) { struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); struct regmap *regmap = tps68470_gpio->tps68470_regmap; - unsigned int reg = TPS68470_REG_GPDO; + unsigned int reg = TPS68470_REG_GPDI; int val, ret; if (offset >= TPS68470_N_REGULAR_GPIO) { From patchwork Mon Nov 28 21:44:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 629082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4084C433FE for ; Mon, 28 Nov 2022 21:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233778AbiK1VqK (ORCPT ); Mon, 28 Nov 2022 16:46:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233403AbiK1VqI (ORCPT ); Mon, 28 Nov 2022 16:46:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE5EA2FC16 for ; Mon, 28 Nov 2022 13:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669671863; 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=JMnrRho9OQOGXDAMjv1JNg9wZ8w7tYaVKUwPtg4BbDc=; b=Z9ibAxllGgVVVJh+BFCtXNadWi9Re2gHd+sLi4DY05Z8I7N0v7p+FFn/aZwh4bao3WShG/ o1nb4H6XC4RpGdtIb8LXyLPkYhTjscTLPcfAERHDJfV0Q5wtzhS6Bq832PqYfePH4GoxCe e1r4YLe16pPLH31ThKjM6XBVTuIa7SI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-nT4qwJbyOy-dhu4ed9nbAA-1; Mon, 28 Nov 2022 16:44:18 -0500 X-MC-Unique: nT4qwJbyOy-dhu4ed9nbAA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44D8C1C0512C; Mon, 28 Nov 2022 21:44:18 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF8B340C6EC2; Mon, 28 Nov 2022 21:44:16 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Bartosz Golaszewski , Linus Walleij , Daniel Scally , Laurent Pinchart Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, linux-gpio@vger.kernel.org, Sakari Ailus , Kate Hsuan , linux-media@vger.kernel.org Subject: [PATCH 3/5] gpio: tps68470: Add support for the indicator LED outputs Date: Mon, 28 Nov 2022 22:44:06 +0100 Message-Id: <20221128214408.165726-4-hdegoede@redhat.com> In-Reply-To: <20221128214408.165726-1-hdegoede@redhat.com> References: <20221128214408.165726-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The tps68470 has support for 2 indicator LED outputs called ileda and iledb, at support for these as GPIO pins 10 + 11. Signed-off-by: Hans de Goede --- drivers/gpio/gpio-tps68470.c | 46 +++++++++++++++++++++++++----------- include/linux/mfd/tps68470.h | 4 ++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-tps68470.c b/drivers/gpio/gpio-tps68470.c index 2ca86fbe1d84..33febd96c001 100644 --- a/drivers/gpio/gpio-tps68470.c +++ b/drivers/gpio/gpio-tps68470.c @@ -19,24 +19,43 @@ #define TPS68470_N_LOGIC_OUTPUT 3 #define TPS68470_N_REGULAR_GPIO 7 -#define TPS68470_N_GPIO (TPS68470_N_LOGIC_OUTPUT + TPS68470_N_REGULAR_GPIO) +#define TPS68470_N_ILEDS 2 +#define TPS68470_N_GPIO (TPS68470_N_LOGIC_OUTPUT + TPS68470_N_REGULAR_GPIO + TPS68470_N_ILEDS) struct tps68470_gpio_data { struct regmap *tps68470_regmap; struct gpio_chip gc; }; +static void tps68470_gpio_get_reg_and_mask(bool get, unsigned int offset, + unsigned int *reg, int *mask) +{ + if (offset < TPS68470_N_REGULAR_GPIO) { + if (get) + *reg = TPS68470_REG_GPDI; + else + *reg = TPS68470_REG_GPDO; + *mask = BIT(offset); + } else if (offset < (TPS68470_N_REGULAR_GPIO + TPS68470_N_LOGIC_OUTPUT)) { + *reg = TPS68470_REG_SGPO; + *mask = BIT(offset - TPS68470_N_REGULAR_GPIO); + } else { + *reg = TPS68470_REG_ILEDCTL; + if (offset == (TPS68470_N_REGULAR_GPIO + TPS68470_N_LOGIC_OUTPUT)) + *mask = TPS68470_ILEDCTL_ENA; + else + *mask = TPS68470_ILEDCTL_ENB; + } +} + static int tps68470_gpio_get(struct gpio_chip *gc, unsigned int offset) { struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); struct regmap *regmap = tps68470_gpio->tps68470_regmap; - unsigned int reg = TPS68470_REG_GPDI; - int val, ret; + int val, mask, ret; + unsigned int reg; - if (offset >= TPS68470_N_REGULAR_GPIO) { - offset -= TPS68470_N_REGULAR_GPIO; - reg = TPS68470_REG_SGPO; - } + tps68470_gpio_get_reg_and_mask(true, offset, ®, &mask); ret = regmap_read(regmap, reg, &val); if (ret) { @@ -44,7 +63,7 @@ static int tps68470_gpio_get(struct gpio_chip *gc, unsigned int offset) TPS68470_REG_SGPO); return ret; } - return !!(val & BIT(offset)); + return !!(val & mask); } static int tps68470_gpio_get_direction(struct gpio_chip *gc, @@ -75,14 +94,12 @@ static void tps68470_gpio_set(struct gpio_chip *gc, unsigned int offset, { struct tps68470_gpio_data *tps68470_gpio = gpiochip_get_data(gc); struct regmap *regmap = tps68470_gpio->tps68470_regmap; - unsigned int reg = TPS68470_REG_GPDO; + unsigned int reg; + int mask; - if (offset >= TPS68470_N_REGULAR_GPIO) { - reg = TPS68470_REG_SGPO; - offset -= TPS68470_N_REGULAR_GPIO; - } + tps68470_gpio_get_reg_and_mask(false, offset, ®, &mask); - regmap_update_bits(regmap, reg, BIT(offset), value ? BIT(offset) : 0); + regmap_update_bits(regmap, reg, mask, value ? mask : 0); } static int tps68470_gpio_output(struct gpio_chip *gc, unsigned int offset, @@ -120,6 +137,7 @@ static const char *tps68470_names[TPS68470_N_GPIO] = { "gpio.0", "gpio.1", "gpio.2", "gpio.3", "gpio.4", "gpio.5", "gpio.6", "s_enable", "s_idle", "s_resetn", + "ileda", "iledb", }; static int tps68470_gpio_probe(struct platform_device *pdev) diff --git a/include/linux/mfd/tps68470.h b/include/linux/mfd/tps68470.h index 7807fa329db0..2a1b6de65540 100644 --- a/include/linux/mfd/tps68470.h +++ b/include/linux/mfd/tps68470.h @@ -34,6 +34,7 @@ #define TPS68470_REG_SGPO 0x22 #define TPS68470_REG_GPDI 0x26 #define TPS68470_REG_GPDO 0x27 +#define TPS68470_REG_ILEDCTL 0x28 #define TPS68470_REG_VCMVAL 0x3C #define TPS68470_REG_VAUX1VAL 0x3D #define TPS68470_REG_VAUX2VAL 0x3E @@ -94,4 +95,7 @@ #define TPS68470_GPIO_MODE_OUT_CMOS 2 #define TPS68470_GPIO_MODE_OUT_ODRAIN 3 +#define TPS68470_ILEDCTL_ENA BIT(2) +#define TPS68470_ILEDCTL_ENB BIT(6) + #endif /* __LINUX_MFD_TPS68470_H */ From patchwork Mon Nov 28 21:44:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 629081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79A0EC433FE for ; Mon, 28 Nov 2022 21:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233972AbiK1VrH (ORCPT ); Mon, 28 Nov 2022 16:47:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiK1VrE (ORCPT ); Mon, 28 Nov 2022 16:47:04 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F083D2FFF9 for ; Mon, 28 Nov 2022 13:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669671866; 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=ijZvrHfxzqLtf9v5WhrCliu1xtsXettjChSs9tCIBZo=; b=ao0V4dA/GiKuky9D6YcmTq+gR3buqqSCJcXlGymGhrYvIBgxNafzil/A93KccW/bGjvShl m5d5sSSXYq0Ny1PQB8iLbL+NIQWXbvIf0TcN94Xp99ZY33CCIVc/1v0oqCz11Y/+clzz6Y ZaJkPAE7Y6s/avlSbiMcc09vAEnwHNc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-108-wfWKXQ0gMViXqONqWAwVAA-1; Mon, 28 Nov 2022 16:44:20 -0500 X-MC-Unique: wfWKXQ0gMViXqONqWAwVAA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 142E3886463; Mon, 28 Nov 2022 21:44:20 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7911F40C6EC2; Mon, 28 Nov 2022 21:44:18 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Bartosz Golaszewski , Linus Walleij , Daniel Scally , Laurent Pinchart Cc: Hans de Goede , platform-driver-x86@vger.kernel.org, linux-gpio@vger.kernel.org, Sakari Ailus , Kate Hsuan , linux-media@vger.kernel.org Subject: [PATCH 4/5] media: ov8865: Add support for a privacy-led GPIO Date: Mon, 28 Nov 2022 22:44:07 +0100 Message-Id: <20221128214408.165726-5-hdegoede@redhat.com> In-Reply-To: <20221128214408.165726-1-hdegoede@redhat.com> References: <20221128214408.165726-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for a privacy-led GPIO. Making the privacy LED to controlable from userspace, as using the LED class subsystem would do, would make it too easy for spy-ware to disable the LED. To avoid this have the sensor driver directly control the LED. Signed-off-by: Hans de Goede --- Note an additional advantage of directly controlling the GPIO is that GPIOs are tied directly to consumer devices. Where as with a LED class device, there would need to be some mechanism to tie the right LED (e.g front or back) to the right sensor. --- drivers/media/i2c/ov8865.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c index cae1866134a0..fe86b166b28b 100644 --- a/drivers/media/i2c/ov8865.c +++ b/drivers/media/i2c/ov8865.c @@ -688,6 +688,7 @@ struct ov8865_sensor { struct i2c_client *i2c_client; struct gpio_desc *reset; struct gpio_desc *powerdown; + struct gpio_desc *privacy_led; struct regulator *avdd; struct regulator *dvdd; struct regulator *dovdd; @@ -2432,10 +2433,12 @@ static int ov8865_sensor_power(struct ov8865_sensor *sensor, bool on) gpiod_set_value_cansleep(sensor->reset, 0); gpiod_set_value_cansleep(sensor->powerdown, 0); + gpiod_set_value_cansleep(sensor->privacy_led, 1); /* Time to enter streaming mode according to power timings. */ usleep_range(10000, 12000); } else { + gpiod_set_value_cansleep(sensor->privacy_led, 0); gpiod_set_value_cansleep(sensor->powerdown, 1); gpiod_set_value_cansleep(sensor->reset, 1); @@ -3009,6 +3012,12 @@ static int ov8865_probe(struct i2c_client *client) goto error_endpoint; } + sensor->privacy_led = devm_gpiod_get_optional(dev, "privacy-led", GPIOD_OUT_LOW); + if (IS_ERR(sensor->privacy_led)) { + ret = PTR_ERR(sensor->privacy_led); + goto error_endpoint; + } + /* External Clock */ sensor->extclk = devm_clk_get(dev, NULL);