Received: by 10.192.165.156 with SMTP id m28csp1489050imm; Wed, 11 Apr 2018 21:02:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx48FAEzZQeYdywmJEuPuk8wa5V8KgOnVZg2X64j6Dk7vvkgWVLib+hZo7WtttaZwGUR08qz8 X-Received: by 2002:a17:902:9a81:: with SMTP id w1-v6mr7880228plp.148.1523505742735; Wed, 11 Apr 2018 21:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523505742; cv=none; d=google.com; s=arc-20160816; b=Fx8SBvNmqZ7Woo+/RjDy/uo5xJHL5TXrmzWW0+V9NgNhLJ8uHiq69+pCyakLOE6/sq cI96FcgP4zKCH9juQEw7Psxaa9QWPTrk2dg4I0M2I0C6UEyONieQfpQUJxqWXjDdfxUN xxv218/H/XK7AF2PBJY2hQGSllnj0FbB1yvo2CXCr0T5u8/zEjt3zLuhNEf/8PW9Dkf8 kiyveJio7gu7/wLJ52bkpqvEhEXPL42EtJUrd/kmUvR0BS8kW4sMySEF5qv6IiLXV5kv PjDtHBzs06xqPD0hxekE0z0+pSp4piCXNu1a6JJIxBGpmVZyl5iR2xJNPeWFA9RrzOsj sVLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=xVybOMTvI1wTfNtvplY0Eqyic6sp+4lSvQy5Ovf/ISs=; b=hysuvuQYlRMfkBW9N0XiVo5WflJHoEyJqVYWyn9Ulsg94FAU0kocwmvqqgJ0ADHvTC Ox7f5pJQj3tT1LAB2kQZiZdNo4zjF+O1gjaobYdBZRURes144MjQcuICQ13UKkE4Kd5g wZ5K+ws2nU0O8+AjxJ15WiFBMCsYpq1g+pTGUl9pJ2Vwjn9CNMDaZo/M0sr+YNs0kby3 UuPNKT1X1lXbwHsRSAkXpt9SOyBRneGTmOI78U3EjfEJmOHHBwEhqt4pbIqUpbYwDDLt HCP8upDS2TCLxFppx+kbjAahA0bRKAjffJ/sLqtEcQPsqVPHX9tD3GbvWI5wi60Gpxpd +rMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=iWgJs+ZF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k191si1696865pgc.295.2018.04.11.21.01.45; Wed, 11 Apr 2018 21:02:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=iWgJs+ZF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752777AbeDLDzR (ORCPT + 99 others); Wed, 11 Apr 2018 23:55:17 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:32701 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752656AbeDLDzP (ORCPT ); Wed, 11 Apr 2018 23:55:15 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3C3t0Ue017597; Wed, 11 Apr 2018 22:55:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1523505300; bh=AOaaDoe5SM6ZKpposFzVCP+iUZVLkj3pA0XhktE1mJ4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=iWgJs+ZFKkzB46caEWeVsJ/1nIgvFK9AKchfR+sS8t0/ixA3XHUzH0LBsJupWeRSa MvoL8FopUyJg2+o3cqI+Wf84F4odDpUzRei5F+KnjaGkuEEorQ8t7ByCmlZGCAF4js YVLJdMPX9SHox+Z8gAZ3//w3jHnKMArXzR/Pwfvk= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3C3t0sS026366; Wed, 11 Apr 2018 22:55:00 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Wed, 11 Apr 2018 22:55:00 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Wed, 11 Apr 2018 22:55:00 -0500 Received: from ula0393675.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3C3sQpp010150; Wed, 11 Apr 2018 22:54:56 -0500 From: Keerthy To: , , CC: , , , , , , , , , Russ Dill Subject: [PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context. Date: Thu, 12 Apr 2018 09:23:53 +0530 Message-ID: <1523505239-16229-9-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523505239-16229-1-git-send-email-j-keerthy@ti.com> References: <1523505239-16229-1-git-send-email-j-keerthy@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russ Dill This adds a pair of context save/restore functions to save/restore the state of a set of pinctrl registers. This simplifies some of the AM33XX PM code as some of the pinctrl registers are lost when the per power domain loses power. The pincrtl code can perform the necessary save/restore. This will also be necessary for hibernation and RTC only sleep, as all pinctrl registers all lost. Signed-off-by: Russ Dill Signed-off-by: Keerthy --- drivers/pinctrl/core.c | 1 + drivers/pinctrl/core.h | 1 - drivers/pinctrl/pinctrl-single.c | 50 ++++++++++++++++++++++++++++++++++++++++ drivers/pinctrl/pinmux.c | 22 ++++++++++++++++++ include/linux/pinctrl/pinctrl.h | 7 ++++++ include/linux/pinctrl/pinmux.h | 16 +++++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index e5a3030..1a9ae64 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -119,6 +119,7 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname) return NULL; } +EXPORT_SYMBOL_GPL(get_pinctrl_dev_from_devname); struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np) { diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 8cf2eba..e587c29 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -226,7 +226,6 @@ int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev, #endif /* CONFIG_GENERIC_PINCTRL_GROUPS */ -struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np); int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index a7c5eb3..2fc3317 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -144,6 +144,7 @@ struct pcs_soc_data { * struct pcs_device - pinctrl device instance * @res: resources * @base: virtual address of the controller + * @saved_vals: saved values for the controller * @size: size of the ioremapped area * @dev: device entry * @np: device tree node @@ -172,6 +173,7 @@ struct pcs_soc_data { struct pcs_device { struct resource *res; void __iomem *base; + void *saved_vals; unsigned size; struct device *dev; struct device_node *np; @@ -372,6 +374,52 @@ static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector, return 0; } +static int pcs_save_context(struct pinctrl_dev *pctldev) +{ + struct pcs_device *pcs; + int i; + + pcs = pinctrl_dev_get_drvdata(pctldev); + + if (!pcs->saved_vals) + pcs->saved_vals = devm_kzalloc(pcs->dev, pcs->size, GFP_ATOMIC); + + switch (pcs->width) { + case 32: + for (i = 0; i < pcs->size; i += 4) + *(u32 *)(pcs->saved_vals + i) = + pcs->read(pcs->base + i); + break; + case 16: + for (i = 0; i < pcs->size; i += 2) + *(u16 *)(pcs->saved_vals + i) = + pcs->read(pcs->base + i); + break; + } + return 0; +} + +static void pcs_restore_context(struct pinctrl_dev *pctldev) +{ + struct pcs_device *pcs; + int i; + + pcs = pinctrl_dev_get_drvdata(pctldev); + + switch (pcs->width) { + case 32: + for (i = 0; i < pcs->size; i += 4) + pcs->write(*(u32 *)(pcs->saved_vals + i), + pcs->base + i); + break; + case 16: + for (i = 0; i < pcs->size; i += 2) + pcs->write(*(u16 *)(pcs->saved_vals + i), + pcs->base + i); + break; + } +} + static int pcs_request_gpio(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned pin) { @@ -420,6 +468,8 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev, .get_function_name = pinmux_generic_get_function_name, .get_function_groups = pinmux_generic_get_function_groups, .set_mux = pcs_set_mux, + .save_context = pcs_save_context, + .restore_context = pcs_restore_context, .gpio_request_enable = pcs_request_gpio, }; diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index b8e9bda..b144e0d 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -312,6 +312,28 @@ static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev, return -EINVAL; } +int pinmux_save_context(struct pinctrl_dev *pctldev, const char *function) +{ + const struct pinmux_ops *pmxops = pctldev->desc->pmxops; + + if (!pmxops || !pmxops->save_context) + return -EINVAL; + + return pmxops->save_context(pctldev); +} +EXPORT_SYMBOL(pinmux_save_context); + +void pinmux_restore_context(struct pinctrl_dev *pctldev, const char *function) +{ + const struct pinmux_ops *pmxops = pctldev->desc->pmxops; + + if (!pmxops || !pmxops->restore_context) + return; + + pmxops->restore_context(pctldev); +} +EXPORT_SYMBOL(pinmux_restore_context); + int pinmux_map_to_setting(const struct pinctrl_map *map, struct pinctrl_setting *setting) { diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h index 8f5dbb8..c523593 100644 --- a/include/linux/pinctrl/pinctrl.h +++ b/include/linux/pinctrl/pinctrl.h @@ -198,6 +198,7 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np) extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev); extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev); extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev); +extern struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); #else struct pinctrl_dev; @@ -208,6 +209,12 @@ static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin) return pin >= 0; } +static inline struct pinctrl_dev *get_pinctrl_dev_from_devname( + const char *dev_name) +{ + return NULL; +} + #endif /* !CONFIG_PINCTRL */ #endif /* __LINUX_PINCTRL_PINCTRL_H */ diff --git a/include/linux/pinctrl/pinmux.h b/include/linux/pinctrl/pinmux.h index ace60d7..f837b8f 100644 --- a/include/linux/pinctrl/pinmux.h +++ b/include/linux/pinctrl/pinmux.h @@ -75,6 +75,8 @@ struct pinmux_ops { int (*gpio_request_enable) (struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset); + int (*save_context)(struct pinctrl_dev *pctldev); + void (*restore_context)(struct pinctrl_dev *pctldev); void (*gpio_disable_free) (struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned offset); @@ -85,6 +87,20 @@ struct pinmux_ops { bool strict; }; +int pinmux_save_context(struct pinctrl_dev *pctldev, const char *function); +void pinmux_restore_context(struct pinctrl_dev *pctldev, const char *function); + +#else /* !CONFIG_PINMUX */ + +static inline int pinmux_save_context(struct pinctrl_dev *pctldev, + const char *function) +{ + return 0; +} + +static inline void pinmux_restore_context(struct pinctrl_dev *pctldev, + const char *function) {} + #endif /* CONFIG_PINMUX */ #endif /* __LINUX_PINCTRL_PINMUX_H */ -- 1.9.1