Re: [PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-13 Thread Keerthy


On Thursday 12 April 2018 07:46 PM, Tony Lindgren wrote:
> Hi,
> 
> * Keerthy  [180412 03:56]:
>> 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.
> 
> So where's the patch adding callers to this code?

This series was to get all the additional save/restores needed for the
rtc+ddr mode. Caller patch is in the main patch that implements that
mode that i will be posting once the ground is set.

Based on enable_off_mode being set this function was called only for
rtc+ddr mode.

> 
> If this cannot be done from regular driver suspend/resume calls,
> this probably should be done from cpu_pm notifiers CPU_PM_ENTER and
> CPU_PM_EXIT. We should also do the same for GPIO BTW.

I will look into that. Thanks for suggestion.

> 
> BTW, the subject line is wrong here, it should be "pinctrl" :)

Oops yes that should be pinctrl.

> 
> Regards,
> 
> Tony
> 


Re: [PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-13 Thread Keerthy


On Thursday 12 April 2018 07:46 PM, Tony Lindgren wrote:
> Hi,
> 
> * Keerthy  [180412 03:56]:
>> 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.
> 
> So where's the patch adding callers to this code?

This series was to get all the additional save/restores needed for the
rtc+ddr mode. Caller patch is in the main patch that implements that
mode that i will be posting once the ground is set.

Based on enable_off_mode being set this function was called only for
rtc+ddr mode.

> 
> If this cannot be done from regular driver suspend/resume calls,
> this probably should be done from cpu_pm notifiers CPU_PM_ENTER and
> CPU_PM_EXIT. We should also do the same for GPIO BTW.

I will look into that. Thanks for suggestion.

> 
> BTW, the subject line is wrong here, it should be "pinctrl" :)

Oops yes that should be pinctrl.

> 
> Regards,
> 
> Tony
> 


Re: [PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-12 Thread Tony Lindgren
Hi,

* Keerthy  [180412 03:56]:
> 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.

So where's the patch adding callers to this code?

If this cannot be done from regular driver suspend/resume calls,
this probably should be done from cpu_pm notifiers CPU_PM_ENTER and
CPU_PM_EXIT. We should also do the same for GPIO BTW.

BTW, the subject line is wrong here, it should be "pinctrl" :)

Regards,

Tony


Re: [PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-12 Thread Tony Lindgren
Hi,

* Keerthy  [180412 03:56]:
> 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.

So where's the patch adding callers to this code?

If this cannot be done from regular driver suspend/resume calls,
this probably should be done from cpu_pm notifiers CPU_PM_ENTER and
CPU_PM_EXIT. We should also do the same for GPIO BTW.

BTW, the subject line is wrong here, it should be "pinctrl" :)

Regards,

Tony


[PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-11 Thread Keerthy
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 

[PATCH 08/14] ARM: OMAP2: Add functions to save and restore pinctrl context.

2018-04-11 Thread Keerthy
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 ||