From patchwork Fri Dec 6 14:05:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11276337 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4BD614B7 for ; Fri, 6 Dec 2019 14:05:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D2642464E for ; Fri, 6 Dec 2019 14:05:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PAW+EXgH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726272AbfLFOF0 (ORCPT ); Fri, 6 Dec 2019 09:05:26 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:42898 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbfLFOF0 (ORCPT ); Fri, 6 Dec 2019 09:05:26 -0500 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BED5E2E5; Fri, 6 Dec 2019 15:05:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1575641124; bh=6ONuODhEjMzl4kqT+4jamlywuUxfVqkfkFDu+SUHM5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAW+EXgHiGhq0+FQ9oVA4+WGG8w0j7IRksubi3QpNpOyHwExLsAQ5WiU/ugNwdf5m Cp9VaXibgGmjSJI0j1V/zcjnP30NttoPqVL+G/w3pgsyWWJYhiDRB9vSX9vlC01XRA /fT7i4o9tU+rahXx73RTKNYgv+7B3kHAf6O7VhrM= From: Kieran Bingham To: Jacopo Mondi , linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham Subject: [PATCH 1/3] media: i2c: max9286: Remove redundant max9286_i2c_mux_state Date: Fri, 6 Dec 2019 14:05:18 +0000 Message-Id: <20191206140520.10457-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116165034.39001-1-jacopo+renesas@jmondi.org> References: <20191116165034.39001-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org While simplifying the i2c-mux state, the states were stored in an enum (initially there were three). This has now simplified down to 2 states, open and closed - and can be represented easily in a bool. It 'could' also be represented within the mux_channel, but I don't want to pollute that further than the '-1' value which is already stored in there to represent no channel selected. Remove the max9286_i2c_mux_state and replace with a bool mux_open flag, and move the location within the private struct to be more appropriate. Signed-off-by: Kieran Bingham --- drivers/media/i2c/max9286.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index e5b3f78318db..6ea08fd87811 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -144,10 +144,10 @@ struct max9286_priv { struct media_pad pads[MAX9286_N_PADS]; struct regulator *regulator; bool poc_enabled; - int mux_state; struct i2c_mux_core *mux; unsigned int mux_channel; + bool mux_open; struct v4l2_ctrl_handler ctrls; @@ -221,11 +221,6 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) * I2C Multiplexer */ -enum max9286_i2c_mux_state { - MAX9286_MUX_CLOSED = 0, - MAX9286_MUX_OPEN, -}; - static void max9286_i2c_mux_configure(struct max9286_priv *priv, u8 conf) { max9286_write(priv, 0x0a, conf); @@ -242,7 +237,7 @@ static void max9286_i2c_mux_open(struct max9286_priv *priv) /* Open all channels on the MAX9286 */ max9286_i2c_mux_configure(priv, 0xff); - priv->mux_state = MAX9286_MUX_OPEN; + priv->mux_open = true; } static void max9286_i2c_mux_close(struct max9286_priv *priv) @@ -254,7 +249,7 @@ static void max9286_i2c_mux_close(struct max9286_priv *priv) */ max9286_i2c_mux_configure(priv, 0x00); - priv->mux_state = MAX9286_MUX_CLOSED; + priv->mux_open = false; priv->mux_channel = -1; } @@ -263,7 +258,7 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) struct max9286_priv *priv = i2c_mux_priv(muxc); /* Channel select is disabled when configured in the opened state. */ - if (priv->mux_state == MAX9286_MUX_OPEN) + if (priv->mux_open) return 0; if (priv->mux_channel == chan) From patchwork Fri Dec 6 14:05:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11276339 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93CF517EF for ; Fri, 6 Dec 2019 14:05:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 715FC2464E for ; Fri, 6 Dec 2019 14:05:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mjqpDLut" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726366AbfLFOF1 (ORCPT ); Fri, 6 Dec 2019 09:05:27 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:42906 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726237AbfLFOF1 (ORCPT ); Fri, 6 Dec 2019 09:05:27 -0500 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 23D6B99A; Fri, 6 Dec 2019 15:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1575641125; bh=CkF+cjiD63BZsJ7gNtqHwKT4AeGU/QVAVg8itjpe8VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mjqpDLutDk5QxISkdNPYczfzEEVX+9kyirtzYiDr3S0h9hPN7VIKpSDGs5I1yBE+r 8MEoaXE8c6mcYDxN8NL7kPKvDz/jhhcezpziGjutaO3DZmal2z2G1FezCiy7klg/TC TmgDJRpGznJnXHZYmlJvUjnEpOYg8PIe+veqpkC8= From: Kieran Bingham To: Jacopo Mondi , linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham Subject: [PATCH 2/3] media: i2c: max9286: Add GPIO chip controller Date: Fri, 6 Dec 2019 14:05:19 +0000 Message-Id: <20191206140520.10457-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191206140520.10457-1-kieran.bingham@ideasonboard.com> References: <20191116165034.39001-1-jacopo+renesas@jmondi.org> <20191206140520.10457-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Provide a GPIO chip to control the two output lines available on the MAX9286. Signed-off-by: Kieran Bingham --- drivers/media/i2c/max9286.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index 6ea08fd87811..c34e7b5c7447 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,8 @@ #define MAX9286_HVSRC_D0 (2 << 0) #define MAX9286_HVSRC_D14 (1 << 0) #define MAX9286_HVSRC_D18 (0 << 0) +/* Register 0x0f */ +#define MAX9286_0X0F_RESERVED BIT(3) /* Register 0x12 */ #define MAX9286_CSILANECNT(n) (((n) - 1) << 6) #define MAX9286_CSIDBL BIT(5) @@ -145,6 +148,9 @@ struct max9286_priv { struct regulator *regulator; bool poc_enabled; + struct gpio_chip gpio; + u8 gpio_state; + struct i2c_mux_core *mux; unsigned int mux_channel; bool mux_open; @@ -712,6 +718,60 @@ static const struct of_device_id max9286_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, max9286_dt_ids); +static void max9286_gpio_set(struct gpio_chip *chip, + unsigned int offset, int value) +{ + struct max9286_priv *priv = gpiochip_get_data(chip); + + if (value) + priv->gpio_state |= BIT(offset); + else + priv->gpio_state &= ~BIT(offset); + + max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state); +} + +static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct max9286_priv *priv = gpiochip_get_data(chip); + + return priv->gpio_state & BIT(offset); +} + +static int max9286_gpio(struct max9286_priv *priv) +{ + struct device *dev = &priv->client->dev; + struct gpio_chip *gpio = &priv->gpio; + int ret; + + static const char * const names[] = { + "GPIO0OUT", + "GPIO1OUT", + }; + + /* Configure the GPIO */ + gpio->label = dev_name(dev); + gpio->parent = dev; + gpio->owner = THIS_MODULE; + gpio->of_node = dev->of_node; + gpio->ngpio = 2; + gpio->set = max9286_gpio_set; + gpio->get = max9286_gpio_get; + gpio->can_sleep = true; + gpio->names = names; + + /* GPIO values default to high */ + priv->gpio_state = BIT(0) | BIT(1); + + ret = devm_gpiochip_add_data(dev, gpio, priv); + if (ret) + dev_err(dev, "Unable to create gpio_chip\n"); + + dev_err(dev, "Created gpio_chip for MAX9286\n"); + + return ret; +} + static int max9286_init(struct device *dev) { struct max9286_priv *priv; @@ -984,6 +1044,14 @@ static int max9286_probe(struct i2c_client *client) if (ret) return ret; + /* + * It is possible to set up the power regulator from the GPIO lines, + * so it needs to be set up early. + */ + ret = max9286_gpio(priv); + if (ret) + return ret; + priv->regulator = regulator_get(&client->dev, "poc"); if (IS_ERR(priv->regulator)) { if (PTR_ERR(priv->regulator) != -EPROBE_DEFER) From patchwork Fri Dec 6 14:05:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11276341 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9559A138D for ; Fri, 6 Dec 2019 14:05:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69B152464E for ; Fri, 6 Dec 2019 14:05:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DhPjDqoi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726237AbfLFOF2 (ORCPT ); Fri, 6 Dec 2019 09:05:28 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:42912 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbfLFOF2 (ORCPT ); Fri, 6 Dec 2019 09:05:28 -0500 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7CF2FA2E; Fri, 6 Dec 2019 15:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1575641125; bh=sHrg5QqErgwcEvTDoXZYgt8UYYVwPL4m/mdTYb9qhF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DhPjDqoiKafKGtJFG+2lMO0Xhig/BWahfsxjZ6a1xfGVq19kuP7VzNsuOudqEqger j3YL+onwcrrb9zBZLRbPmmFcH1D4uoAP5u9bdoGodMiw6fecOaPZgYZK4HwaagJH8x kz61z/X46wZCJ98w+VpuggJLpQAiv9NK0iwxQ7Zo= From: Kieran Bingham To: Jacopo Mondi , linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham Subject: [PATCH 3/3] media: i2c: max9286: Provide optional enable-gpio Date: Fri, 6 Dec 2019 14:05:20 +0000 Message-Id: <20191206140520.10457-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191206140520.10457-1-kieran.bingham@ideasonboard.com> References: <20191116165034.39001-1-jacopo+renesas@jmondi.org> <20191206140520.10457-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The MAX9286 has a negated PWDN line which must be raised to enable the device. On the Eagle-V3M this pin is connected to a GPIO on the io_expander. Provide an enable-gpio dt property to specify the link, and ensure that the line is handled in the driver accordingly. This can also provide the abiltiy to manage low power states and runtime-pm at a later date by fully powering down the chip. Signed-off-by: Kieran Bingham --- drivers/media/i2c/max9286.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c index c34e7b5c7447..67065cd99d8d 100644 --- a/drivers/media/i2c/max9286.c +++ b/drivers/media/i2c/max9286.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -143,6 +144,7 @@ struct max9286_source { struct max9286_priv { struct i2c_client *client; + struct gpio_desc *gpiod_pwdn; struct v4l2_subdev sd; struct media_pad pads[MAX9286_N_PADS]; struct regulator *regulator; @@ -1044,6 +1046,14 @@ static int max9286_probe(struct i2c_client *client) if (ret) return ret; + priv->gpiod_pwdn = devm_gpiod_get_optional(&client->dev, "enable", + GPIOD_OUT_HIGH); + if (IS_ERR(priv->gpiod_pwdn)) + return PTR_ERR(priv->gpiod_pwdn); + + gpiod_set_consumer_name(priv->gpiod_pwdn, "max9286-pwdn"); + gpiod_set_value_cansleep(priv->gpiod_pwdn, 1); + /* * It is possible to set up the power regulator from the GPIO lines, * so it needs to be set up early. @@ -1117,6 +1127,9 @@ static int max9286_remove(struct i2c_client *client) regulator_put(priv->regulator); max9286_cleanup_dt(priv); + + gpiod_set_value_cansleep(priv->gpiod_pwdn, 0); + kfree(priv); return 0;