Commit 4207b587 authored by Nishad Kamdar's avatar Nishad Kamdar Committed by Greg Kroah-Hartman

staging: greybus: arche-platform: Switch to the gpio descriptor interface

Use the gpiod interface instead of the deprecated old non-descriptor
interface while continuing to ignore gpio flags from device tree in
"svc_reset_onoff()" for now.
Reviewed-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarNishad Kamdar <nishadkamdar@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fbacec8f
...@@ -8,10 +8,9 @@ ...@@ -8,10 +8,9 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_gpio.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/pinctrl/consumer.h> #include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -45,14 +44,14 @@ enum svc_wakedetect_state { ...@@ -45,14 +44,14 @@ enum svc_wakedetect_state {
struct arche_platform_drvdata { struct arche_platform_drvdata {
/* Control GPIO signals to and from AP <=> SVC */ /* Control GPIO signals to and from AP <=> SVC */
int svc_reset_gpio; struct gpio_desc *svc_reset;
bool is_reset_act_hi; bool is_reset_act_hi;
int svc_sysboot_gpio; struct gpio_desc *svc_sysboot;
int wake_detect_gpio; /* bi-dir,maps to WAKE_MOD & WAKE_FRAME signals */ struct gpio_desc *wake_detect; /* bi-dir,maps to WAKE_MOD & WAKE_FRAME signals */
enum arche_platform_state state; enum arche_platform_state state;
int svc_refclk_req; struct gpio_desc *svc_refclk_req;
struct clk *svc_ref_clk; struct clk *svc_ref_clk;
struct pinctrl *pinctrl; struct pinctrl *pinctrl;
...@@ -85,9 +84,9 @@ static void arche_platform_set_wake_detect_state( ...@@ -85,9 +84,9 @@ static void arche_platform_set_wake_detect_state(
arche_pdata->wake_detect_state = state; arche_pdata->wake_detect_state = state;
} }
static inline void svc_reset_onoff(unsigned int gpio, bool onoff) static inline void svc_reset_onoff(struct gpio_desc *gpio, bool onoff)
{ {
gpio_set_value(gpio, onoff); gpiod_set_raw_value(gpio, onoff);
} }
static int apb_cold_boot(struct device *dev, void *data) static int apb_cold_boot(struct device *dev, void *data)
...@@ -116,7 +115,6 @@ static int apb_poweroff(struct device *dev, void *data) ...@@ -116,7 +115,6 @@ static int apb_poweroff(struct device *dev, void *data)
static void arche_platform_wd_irq_en(struct arche_platform_drvdata *arche_pdata) static void arche_platform_wd_irq_en(struct arche_platform_drvdata *arche_pdata)
{ {
/* Enable interrupt here, to read event back from SVC */ /* Enable interrupt here, to read event back from SVC */
gpio_direction_input(arche_pdata->wake_detect_gpio);
enable_irq(arche_pdata->wake_detect_irq); enable_irq(arche_pdata->wake_detect_irq);
} }
...@@ -160,7 +158,7 @@ static irqreturn_t arche_platform_wd_irq(int irq, void *devid) ...@@ -160,7 +158,7 @@ static irqreturn_t arche_platform_wd_irq(int irq, void *devid)
spin_lock_irqsave(&arche_pdata->wake_lock, flags); spin_lock_irqsave(&arche_pdata->wake_lock, flags);
if (gpio_get_value(arche_pdata->wake_detect_gpio)) { if (gpiod_get_value(arche_pdata->wake_detect)) {
/* wake/detect rising */ /* wake/detect rising */
/* /*
...@@ -224,10 +222,9 @@ arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata) ...@@ -224,10 +222,9 @@ arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
dev_info(arche_pdata->dev, "Booting from cold boot state\n"); dev_info(arche_pdata->dev, "Booting from cold boot state\n");
svc_reset_onoff(arche_pdata->svc_reset_gpio, svc_reset_onoff(arche_pdata->svc_reset, arche_pdata->is_reset_act_hi);
arche_pdata->is_reset_act_hi);
gpio_set_value(arche_pdata->svc_sysboot_gpio, 0); gpiod_set_value(arche_pdata->svc_sysboot, 0);
usleep_range(100, 200); usleep_range(100, 200);
ret = clk_prepare_enable(arche_pdata->svc_ref_clk); ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
...@@ -238,8 +235,7 @@ arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata) ...@@ -238,8 +235,7 @@ arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
} }
/* bring SVC out of reset */ /* bring SVC out of reset */
svc_reset_onoff(arche_pdata->svc_reset_gpio, svc_reset_onoff(arche_pdata->svc_reset, !arche_pdata->is_reset_act_hi);
!arche_pdata->is_reset_act_hi);
arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_ACTIVE); arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_ACTIVE);
...@@ -259,10 +255,9 @@ arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata) ...@@ -259,10 +255,9 @@ arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
dev_info(arche_pdata->dev, "Switching to FW flashing state\n"); dev_info(arche_pdata->dev, "Switching to FW flashing state\n");
svc_reset_onoff(arche_pdata->svc_reset_gpio, svc_reset_onoff(arche_pdata->svc_reset, arche_pdata->is_reset_act_hi);
arche_pdata->is_reset_act_hi);
gpio_set_value(arche_pdata->svc_sysboot_gpio, 1); gpiod_set_value(arche_pdata->svc_sysboot, 1);
usleep_range(100, 200); usleep_range(100, 200);
...@@ -273,8 +268,7 @@ arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata) ...@@ -273,8 +268,7 @@ arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
return ret; return ret;
} }
svc_reset_onoff(arche_pdata->svc_reset_gpio, svc_reset_onoff(arche_pdata->svc_reset, !arche_pdata->is_reset_act_hi);
!arche_pdata->is_reset_act_hi);
arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_FW_FLASHING); arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_FW_FLASHING);
...@@ -305,8 +299,7 @@ arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata) ...@@ -305,8 +299,7 @@ arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata)
clk_disable_unprepare(arche_pdata->svc_ref_clk); clk_disable_unprepare(arche_pdata->svc_ref_clk);
/* As part of exit, put APB back in reset state */ /* As part of exit, put APB back in reset state */
svc_reset_onoff(arche_pdata->svc_reset_gpio, svc_reset_onoff(arche_pdata->svc_reset, arche_pdata->is_reset_act_hi);
arche_pdata->is_reset_act_hi);
arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF); arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
} }
...@@ -435,6 +428,7 @@ static int arche_platform_probe(struct platform_device *pdev) ...@@ -435,6 +428,7 @@ static int arche_platform_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
int ret; int ret;
unsigned int flags;
arche_pdata = devm_kzalloc(&pdev->dev, sizeof(*arche_pdata), arche_pdata = devm_kzalloc(&pdev->dev, sizeof(*arche_pdata),
GFP_KERNEL); GFP_KERNEL);
...@@ -444,61 +438,33 @@ static int arche_platform_probe(struct platform_device *pdev) ...@@ -444,61 +438,33 @@ static int arche_platform_probe(struct platform_device *pdev)
/* setup svc reset gpio */ /* setup svc reset gpio */
arche_pdata->is_reset_act_hi = of_property_read_bool(np, arche_pdata->is_reset_act_hi = of_property_read_bool(np,
"svc,reset-active-high"); "svc,reset-active-high");
arche_pdata->svc_reset_gpio = of_get_named_gpio(np, if (arche_pdata->is_reset_act_hi)
"svc,reset-gpio", flags = GPIOD_OUT_HIGH;
0); else
if (!gpio_is_valid(arche_pdata->svc_reset_gpio)) { flags = GPIOD_OUT_LOW;
dev_err(dev, "failed to get reset-gpio\n");
return arche_pdata->svc_reset_gpio; arche_pdata->svc_reset = devm_gpiod_get(dev, "svc,reset", flags);
} if (IS_ERR(arche_pdata->svc_reset)) {
ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset"); ret = PTR_ERR(arche_pdata->svc_reset);
if (ret) { dev_err(dev, "failed to request svc-reset GPIO: %d\n", ret);
dev_err(dev, "failed to request svc-reset gpio:%d\n", ret);
return ret;
}
ret = gpio_direction_output(arche_pdata->svc_reset_gpio,
arche_pdata->is_reset_act_hi);
if (ret) {
dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
return ret; return ret;
} }
arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF); arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np, arche_pdata->svc_sysboot = devm_gpiod_get(dev, "svc,sysboot",
"svc,sysboot-gpio", GPIOD_OUT_LOW);
0); if (IS_ERR(arche_pdata->svc_sysboot)) {
if (!gpio_is_valid(arche_pdata->svc_sysboot_gpio)) { ret = PTR_ERR(arche_pdata->svc_sysboot);
dev_err(dev, "failed to get sysboot gpio\n"); dev_err(dev, "failed to request sysboot0 GPIO: %d\n", ret);
return arche_pdata->svc_sysboot_gpio;
}
ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
if (ret) {
dev_err(dev, "failed to request sysboot0 gpio:%d\n", ret);
return ret;
}
ret = gpio_direction_output(arche_pdata->svc_sysboot_gpio, 0);
if (ret) {
dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
return ret; return ret;
} }
/* setup the clock request gpio first */ /* setup the clock request gpio first */
arche_pdata->svc_refclk_req = of_get_named_gpio(np, arche_pdata->svc_refclk_req = devm_gpiod_get(dev, "svc,refclk-req",
"svc,refclk-req-gpio", GPIOD_IN);
0); if (IS_ERR(arche_pdata->svc_refclk_req)) {
if (!gpio_is_valid(arche_pdata->svc_refclk_req)) { ret = PTR_ERR(arche_pdata->svc_refclk_req);
dev_err(dev, "failed to get svc clock-req gpio\n"); dev_err(dev, "failed to request svc-clk-req GPIO: %d\n", ret);
return arche_pdata->svc_refclk_req;
}
ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
"svc-clk-req");
if (ret) {
dev_err(dev, "failed to request svc-clk-req gpio: %d\n", ret);
return ret;
}
ret = gpio_direction_input(arche_pdata->svc_refclk_req);
if (ret) {
dev_err(dev, "failed to set svc-clk-req gpio dir :%d\n", ret);
return ret; return ret;
} }
...@@ -515,19 +481,11 @@ static int arche_platform_probe(struct platform_device *pdev) ...@@ -515,19 +481,11 @@ static int arche_platform_probe(struct platform_device *pdev)
arche_pdata->num_apbs = of_get_child_count(np); arche_pdata->num_apbs = of_get_child_count(np);
dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs); dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs);
arche_pdata->wake_detect_gpio = of_get_named_gpio(np, arche_pdata->wake_detect = devm_gpiod_get(dev, "svc,wake-detect",
"svc,wake-detect-gpio", GPIOD_IN);
0); if (IS_ERR(arche_pdata->wake_detect)) {
if (arche_pdata->wake_detect_gpio < 0) { ret = PTR_ERR(arche_pdata->wake_detect);
dev_err(dev, "failed to get wake detect gpio\n"); dev_err(dev, "Failed requesting wake_detect GPIO: %d\n", ret);
return arche_pdata->wake_detect_gpio;
}
ret = devm_gpio_request(dev, arche_pdata->wake_detect_gpio,
"wake detect");
if (ret) {
dev_err(dev, "Failed requesting wake_detect gpio %d\n",
arche_pdata->wake_detect_gpio);
return ret; return ret;
} }
...@@ -538,7 +496,7 @@ static int arche_platform_probe(struct platform_device *pdev) ...@@ -538,7 +496,7 @@ static int arche_platform_probe(struct platform_device *pdev)
spin_lock_init(&arche_pdata->wake_lock); spin_lock_init(&arche_pdata->wake_lock);
mutex_init(&arche_pdata->platform_state_mutex); mutex_init(&arche_pdata->platform_state_mutex);
arche_pdata->wake_detect_irq = arche_pdata->wake_detect_irq =
gpio_to_irq(arche_pdata->wake_detect_gpio); gpiod_to_irq(arche_pdata->wake_detect);
ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq, ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq,
arche_platform_wd_irq, arche_platform_wd_irq,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment