From patchwork Tue May 21 09:54:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mugunthan V N X-Patchwork-Id: 2596641 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 41F2A3FE81 for ; Tue, 21 May 2013 09:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753167Ab3EUJzW (ORCPT ); Tue, 21 May 2013 05:55:22 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:43335 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753061Ab3EUJzT (ORCPT ); Tue, 21 May 2013 05:55:19 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id r4L9tE2B001113; Tue, 21 May 2013 04:55:14 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r4L9tEer003821; Tue, 21 May 2013 04:55:14 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.2.342.3; Tue, 21 May 2013 04:55:14 -0500 Received: from psplinux063.india.ti.com (dbdp20.itg.ti.com [172.24.170.38]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r4L9t54d005305; Tue, 21 May 2013 04:55:12 -0500 From: Mugunthan V N To: CC: , , , , , Mugunthan V N Subject: [net-next resend PATCH 2/6] net: davinci_mdio: enhance pinctrl support Date: Tue, 21 May 2013 15:24:59 +0530 Message-ID: <1369130103-743-3-git-send-email-mugunthanvnm@ti.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1369130103-743-1-git-send-email-mugunthanvnm@ti.com> References: <1369130103-743-1-git-send-email-mugunthanvnm@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Amend cpsw controller to optionally take a pin control handle and set the state of the pins to: - "default" on boot, resume - "sleep" on suspend() This should make it possible to optimize energy usage for the pins for the suspend/resume cycle. If any of the above pin states are missing in dt, a warning message about the missing state is displayed. If certain pin-states are not available, to remove this warning message pass respective state name with null phandler. Signed-off-by: Mugunthan V N --- drivers/net/ethernet/ti/davinci_mdio.c | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c index 12aec17..be81d3e 100644 --- a/drivers/net/ethernet/ti/davinci_mdio.c +++ b/drivers/net/ethernet/ti/davinci_mdio.c @@ -38,6 +38,7 @@ #include #include #include +#include /* * This timeout definition is a worst-case ultra defensive measure against @@ -94,6 +95,11 @@ struct davinci_mdio_data { struct mii_bus *bus; bool suspended; unsigned long access_time; /* jiffies */ + + /* Two optional pin states - default & sleep */ + struct pinctrl *pinctrl; + struct pinctrl_state *pins_default; + struct pinctrl_state *pins_sleep; }; static void __davinci_mdio_reset(struct davinci_mdio_data *data) @@ -347,6 +353,36 @@ static int davinci_mdio_probe(struct platform_device *pdev) data->bus->parent = dev; data->bus->priv = data; + data->pinctrl = devm_pinctrl_get(&pdev->dev); + if (!IS_ERR(data->pinctrl)) { + data->pins_default = pinctrl_lookup_state(data->pinctrl, + PINCTRL_STATE_DEFAULT); + /* enable pins to be muxed in and configured */ + if (IS_ERR(data->pins_default)) + dev_warn(&pdev->dev, "could not get default pinstate\n"); + else + if (pinctrl_select_state(data->pinctrl, + data->pins_default)) + dev_err(&pdev->dev, + "could not set default pins\n"); + + data->pins_sleep = pinctrl_lookup_state(data->pinctrl, + PINCTRL_STATE_SLEEP); + if (IS_ERR(data->pins_sleep)) + dev_warn(&pdev->dev, "could not get sleep pinstate\n"); + } else { + /* + * Since we continue even when pinctrl node is not found, + * Invalidate pins as not available. This is to make sure that + * IS_ERR(pins_xxx) results in failure when used. + */ + data->pins_default = ERR_PTR(-ENODATA); + data->pins_sleep = ERR_PTR(-ENODATA); + + dev_warn(&pdev->dev, + "pins are not configured from the driver\n"); + } + pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev); data->clk = clk_get(&pdev->dev, "fck"); @@ -454,6 +490,11 @@ static int davinci_mdio_suspend(struct device *dev) data->suspended = true; spin_unlock(&data->lock); + /* Optionally let pins go into sleep states */ + if (!IS_ERR(data->pins_sleep)) + if (pinctrl_select_state(data->pinctrl, data->pins_sleep)) + dev_err(dev, "could not set pins to sleep state\n"); + return 0; } @@ -465,6 +506,11 @@ static int davinci_mdio_resume(struct device *dev) spin_lock(&data->lock); pm_runtime_get_sync(data->dev); + /* Optionaly enable pins to be muxed in and configured */ + if (!IS_ERR(data->pins_default)) + if (pinctrl_select_state(data->pinctrl, data->pins_default)) + dev_err(dev, "could not set default pins\n"); + /* restart the scan state machine */ ctrl = __raw_readl(&data->regs->control); ctrl |= CONTROL_ENABLE;