@@ -35,6 +35,7 @@
#include <linux/if_vlan.h>
#include <linux/platform_data/cpsw.h>
+#include <linux/pinctrl/consumer.h>
#include "cpsw_ale.h"
#include "cpts.h"
@@ -351,6 +352,11 @@ struct cpsw_priv {
bool irq_enabled;
struct cpts *cpts;
u32 emac_port;
+
+ /* Two optional pin states - default & sleep */
+ struct pinctrl *pinctrl;
+ struct pinctrl_state *pins_default;
+ struct pinctrl_state *pins_sleep;
};
#define napi_to_priv(napi) container_of(napi, struct cpsw_priv, napi)
@@ -1689,6 +1695,36 @@ static int cpsw_probe(struct platform_device *pdev)
*/
pm_runtime_enable(&pdev->dev);
+ priv->pinctrl = devm_pinctrl_get(&pdev->dev);
+ if (!IS_ERR(priv->pinctrl)) {
+ priv->pins_default = pinctrl_lookup_state(priv->pinctrl,
+ PINCTRL_STATE_DEFAULT);
+ /* enable pins to be muxed in and configured */
+ if (IS_ERR(priv->pins_default))
+ dev_warn(&pdev->dev, "could not get default pinstate\n");
+ else
+ if (pinctrl_select_state(priv->pinctrl,
+ priv->pins_default))
+ dev_err(&pdev->dev,
+ "could not set default pins\n");
+
+ priv->pins_sleep = pinctrl_lookup_state(priv->pinctrl,
+ PINCTRL_STATE_SLEEP);
+ if (IS_ERR(priv->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.
+ */
+ priv->pins_default = ERR_PTR(-ENODATA);
+ priv->pins_sleep = ERR_PTR(-ENODATA);
+
+ dev_warn(&pdev->dev,
+ "pins are not configured from the driver\n");
+ }
+
if (cpsw_probe_dt(&priv->data, pdev)) {
pr_err("cpsw: platform data missing\n");
ret = -ENODEV;
@@ -1973,11 +2009,17 @@ static int cpsw_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
+ struct cpsw_priv *priv = netdev_priv(ndev);
if (netif_running(ndev))
cpsw_ndo_stop(ndev);
pm_runtime_put_sync(&pdev->dev);
+ /* Optionally let pins go into sleep states */
+ if (!IS_ERR(priv->pins_sleep))
+ if (pinctrl_select_state(priv->pinctrl, priv->pins_sleep))
+ dev_err(dev, "could not set pins to sleep state\n");
+
return 0;
}
@@ -1985,8 +2027,15 @@ static int cpsw_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev);
+ struct cpsw_priv *priv = netdev_priv(ndev);
pm_runtime_get_sync(&pdev->dev);
+
+ /* Optionaly enable pins to be muxed in and configured */
+ if (!IS_ERR(priv->pins_default))
+ if (pinctrl_select_state(priv->pinctrl, priv->pins_default))
+ dev_err(dev, "could not set default pins\n");
+
if (netif_running(ndev))
cpsw_ndo_open(ndev);
return 0;