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

staging: greybus: arche-apb-ctrl.c: 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
functions "deassert_reset()" and "assert_reset()" 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 e28dd69e
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
#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/interrupt.h> #include <linux/interrupt.h>
#include <linux/of_gpio.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pinctrl/consumer.h> #include <linux/pinctrl/consumer.h>
...@@ -24,12 +23,12 @@ static void apb_bootret_deassert(struct device *dev); ...@@ -24,12 +23,12 @@ static void apb_bootret_deassert(struct device *dev);
struct arche_apb_ctrl_drvdata { struct arche_apb_ctrl_drvdata {
/* Control GPIO signals to and from AP <=> AP Bridges */ /* Control GPIO signals to and from AP <=> AP Bridges */
int resetn_gpio; struct gpio_desc *resetn;
int boot_ret_gpio; struct gpio_desc *boot_ret;
int pwroff_gpio; struct gpio_desc *pwroff;
int wake_in_gpio; struct gpio_desc *wake_in;
int wake_out_gpio; struct gpio_desc *wake_out;
int pwrdn_gpio; struct gpio_desc *pwrdn;
enum arche_platform_state state; enum arche_platform_state state;
bool init_disabled; bool init_disabled;
...@@ -37,28 +36,28 @@ struct arche_apb_ctrl_drvdata { ...@@ -37,28 +36,28 @@ struct arche_apb_ctrl_drvdata {
struct regulator *vcore; struct regulator *vcore;
struct regulator *vio; struct regulator *vio;
int clk_en_gpio; struct gpio_desc *clk_en;
struct clk *clk; struct clk *clk;
struct pinctrl *pinctrl; struct pinctrl *pinctrl;
struct pinctrl_state *pin_default; struct pinctrl_state *pin_default;
/* V2: SPI Bus control */ /* V2: SPI Bus control */
int spi_en_gpio; struct gpio_desc *spi_en;
bool spi_en_polarity_high; bool spi_en_polarity_high;
}; };
/* /*
* Note that these low level api's are active high * Note that these low level api's are active high
*/ */
static inline void deassert_reset(unsigned int gpio) static inline void deassert_reset(struct gpio_desc *gpio)
{ {
gpio_set_value(gpio, 1); gpiod_set_raw_value(gpio, 1);
} }
static inline void assert_reset(unsigned int gpio) static inline void assert_reset(struct gpio_desc *gpio)
{ {
gpio_set_value(gpio, 0); gpiod_set_raw_value(gpio, 0);
} }
/* /*
...@@ -75,11 +74,10 @@ static int coldboot_seq(struct platform_device *pdev) ...@@ -75,11 +74,10 @@ static int coldboot_seq(struct platform_device *pdev)
return 0; return 0;
/* Hold APB in reset state */ /* Hold APB in reset state */
assert_reset(apb->resetn_gpio); assert_reset(apb->resetn);
if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en)
gpio_is_valid(apb->spi_en_gpio)) devm_gpiod_put(dev, apb->spi_en);
devm_gpio_free(dev, apb->spi_en_gpio);
/* Enable power to APB */ /* Enable power to APB */
if (!IS_ERR(apb->vcore)) { if (!IS_ERR(apb->vcore)) {
...@@ -101,13 +99,13 @@ static int coldboot_seq(struct platform_device *pdev) ...@@ -101,13 +99,13 @@ static int coldboot_seq(struct platform_device *pdev)
apb_bootret_deassert(dev); apb_bootret_deassert(dev);
/* On DB3 clock was not mandatory */ /* On DB3 clock was not mandatory */
if (gpio_is_valid(apb->clk_en_gpio)) if (apb->clk_en)
gpio_set_value(apb->clk_en_gpio, 1); gpiod_set_value(apb->clk_en, 1);
usleep_range(100, 200); usleep_range(100, 200);
/* deassert reset to APB : Active-low signal */ /* deassert reset to APB : Active-low signal */
deassert_reset(apb->resetn_gpio); deassert_reset(apb->resetn);
apb->state = ARCHE_PLATFORM_STATE_ACTIVE; apb->state = ARCHE_PLATFORM_STATE_ACTIVE;
...@@ -136,25 +134,25 @@ static int fw_flashing_seq(struct platform_device *pdev) ...@@ -136,25 +134,25 @@ static int fw_flashing_seq(struct platform_device *pdev)
return ret; return ret;
} }
if (gpio_is_valid(apb->spi_en_gpio)) { if (apb->spi_en) {
unsigned long flags; unsigned long flags;
if (apb->spi_en_polarity_high) if (apb->spi_en_polarity_high)
flags = GPIOF_OUT_INIT_HIGH; flags = GPIOD_OUT_HIGH;
else else
flags = GPIOF_OUT_INIT_LOW; flags = GPIOD_OUT_LOW;
ret = devm_gpio_request_one(dev, apb->spi_en_gpio, apb->spi_en = devm_gpiod_get(dev, "spi-en", flags);
flags, "apb_spi_en"); if (IS_ERR(apb->spi_en)) {
if (ret) { ret = PTR_ERR(apb->spi_en);
dev_err(dev, "Failed requesting SPI bus en gpio %d\n", dev_err(dev, "Failed requesting SPI bus en GPIO: %d\n",
apb->spi_en_gpio); ret);
return ret; return ret;
} }
} }
/* for flashing device should be in reset state */ /* for flashing device should be in reset state */
assert_reset(apb->resetn_gpio); assert_reset(apb->resetn);
apb->state = ARCHE_PLATFORM_STATE_FW_FLASHING; apb->state = ARCHE_PLATFORM_STATE_FW_FLASHING;
return 0; return 0;
...@@ -176,9 +174,8 @@ static int standby_boot_seq(struct platform_device *pdev) ...@@ -176,9 +174,8 @@ static int standby_boot_seq(struct platform_device *pdev)
apb->state == ARCHE_PLATFORM_STATE_OFF) apb->state == ARCHE_PLATFORM_STATE_OFF)
return 0; return 0;
if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en)
gpio_is_valid(apb->spi_en_gpio)) devm_gpiod_put(dev, apb->spi_en);
devm_gpio_free(dev, apb->spi_en_gpio);
/* /*
* As per WDM spec, do nothing * As per WDM spec, do nothing
...@@ -201,13 +198,12 @@ static void poweroff_seq(struct platform_device *pdev) ...@@ -201,13 +198,12 @@ static void poweroff_seq(struct platform_device *pdev)
if (apb->init_disabled || apb->state == ARCHE_PLATFORM_STATE_OFF) if (apb->init_disabled || apb->state == ARCHE_PLATFORM_STATE_OFF)
return; return;
if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en)
gpio_is_valid(apb->spi_en_gpio)) devm_gpiod_put(dev, apb->spi_en);
devm_gpio_free(dev, apb->spi_en_gpio);
/* disable the clock */ /* disable the clock */
if (gpio_is_valid(apb->clk_en_gpio)) if (apb->clk_en)
gpio_set_value(apb->clk_en_gpio, 0); gpiod_set_value(apb->clk_en, 0);
if (!IS_ERR(apb->vcore) && regulator_is_enabled(apb->vcore) > 0) if (!IS_ERR(apb->vcore) && regulator_is_enabled(apb->vcore) > 0)
regulator_disable(apb->vcore); regulator_disable(apb->vcore);
...@@ -216,7 +212,7 @@ static void poweroff_seq(struct platform_device *pdev) ...@@ -216,7 +212,7 @@ static void poweroff_seq(struct platform_device *pdev)
regulator_disable(apb->vio); regulator_disable(apb->vio);
/* As part of exit, put APB back in reset state */ /* As part of exit, put APB back in reset state */
assert_reset(apb->resetn_gpio); assert_reset(apb->resetn);
apb->state = ARCHE_PLATFORM_STATE_OFF; apb->state = ARCHE_PLATFORM_STATE_OFF;
/* TODO: May have to send an event to SVC about this exit */ /* TODO: May have to send an event to SVC about this exit */
...@@ -226,7 +222,7 @@ static void apb_bootret_deassert(struct device *dev) ...@@ -226,7 +222,7 @@ static void apb_bootret_deassert(struct device *dev)
{ {
struct arche_apb_ctrl_drvdata *apb = dev_get_drvdata(dev); struct arche_apb_ctrl_drvdata *apb = dev_get_drvdata(dev);
gpio_set_value(apb->boot_ret_gpio, 0); gpiod_set_value(apb->boot_ret, 0);
} }
int apb_ctrl_coldboot(struct device *dev) int apb_ctrl_coldboot(struct device *dev)
...@@ -322,66 +318,44 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev, ...@@ -322,66 +318,44 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
struct arche_apb_ctrl_drvdata *apb) struct arche_apb_ctrl_drvdata *apb)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
int ret; int ret;
apb->resetn_gpio = of_get_named_gpio(np, "reset-gpios", 0); apb->resetn = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
if (apb->resetn_gpio < 0) { if (IS_ERR(apb->resetn)) {
dev_err(dev, "failed to get reset gpio\n"); ret = PTR_ERR(apb->resetn);
return apb->resetn_gpio; dev_err(dev, "Failed requesting reset GPIO: %d\n", ret);
}
ret = devm_gpio_request_one(dev, apb->resetn_gpio,
GPIOF_OUT_INIT_LOW, "apb-reset");
if (ret) {
dev_err(dev, "Failed requesting reset gpio %d\n",
apb->resetn_gpio);
return ret; return ret;
} }
apb->boot_ret_gpio = of_get_named_gpio(np, "boot-ret-gpios", 0); apb->boot_ret = devm_gpiod_get(dev, "boot-ret", GPIOD_OUT_LOW);
if (apb->boot_ret_gpio < 0) { if (IS_ERR(apb->boot_ret)) {
dev_err(dev, "failed to get boot retention gpio\n"); ret = PTR_ERR(apb->boot_ret);
return apb->boot_ret_gpio; dev_err(dev, "Failed requesting bootret GPIO: %d\n", ret);
}
ret = devm_gpio_request_one(dev, apb->boot_ret_gpio,
GPIOF_OUT_INIT_LOW, "boot retention");
if (ret) {
dev_err(dev, "Failed requesting bootret gpio %d\n",
apb->boot_ret_gpio);
return ret; return ret;
} }
/* It's not mandatory to support power management interface */ /* It's not mandatory to support power management interface */
apb->pwroff_gpio = of_get_named_gpio(np, "pwr-off-gpios", 0); apb->pwroff = devm_gpiod_get_optional(dev, "pwr-off", GPIOD_IN);
if (apb->pwroff_gpio < 0) { if (IS_ERR(apb->pwroff)) {
dev_err(dev, "failed to get power off gpio\n"); ret = PTR_ERR(apb->pwroff);
return apb->pwroff_gpio; dev_err(dev, "Failed requesting pwroff_n GPIO: %d\n", ret);
}
ret = devm_gpio_request_one(dev, apb->pwroff_gpio,
GPIOF_IN, "pwroff_n");
if (ret) {
dev_err(dev, "Failed requesting pwroff_n gpio %d\n",
apb->pwroff_gpio);
return ret; return ret;
} }
/* Do not make clock mandatory as of now (for DB3) */ /* Do not make clock mandatory as of now (for DB3) */
apb->clk_en_gpio = of_get_named_gpio(np, "clock-en-gpio", 0); apb->clk_en = devm_gpiod_get_optional(dev, "clock-en", GPIOD_OUT_LOW);
if (apb->clk_en_gpio < 0) { if (IS_ERR(apb->clk_en)) {
dev_warn(dev, "failed to get clock en gpio\n"); ret = PTR_ERR(apb->clk_en);
} else if (gpio_is_valid(apb->clk_en_gpio)) { dev_err(dev, "Failed requesting APB clock en GPIO: %d\n", ret);
ret = devm_gpio_request_one(dev, apb->clk_en_gpio, return ret;
GPIOF_OUT_INIT_LOW, "apb_clk_en");
if (ret) {
dev_warn(dev, "Failed requesting APB clock en gpio %d\n",
apb->clk_en_gpio);
return ret;
}
} }
apb->pwrdn_gpio = of_get_named_gpio(np, "pwr-down-gpios", 0); apb->pwrdn = devm_gpiod_get(dev, "pwr-down", GPIOD_OUT_LOW);
if (apb->pwrdn_gpio < 0) if (IS_ERR(apb->pwrdn)) {
dev_warn(dev, "failed to get power down gpio\n"); ret = PTR_ERR(apb->pwrdn);
dev_warn(dev, "Failed requesting power down GPIO: %d\n", ret);
return ret;
}
/* Regulators are optional, as we may have fixed supply coming in */ /* Regulators are optional, as we may have fixed supply coming in */
apb->vcore = devm_regulator_get(dev, "vcore"); apb->vcore = devm_regulator_get(dev, "vcore");
...@@ -404,12 +378,8 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev, ...@@ -404,12 +378,8 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
} }
/* Only applicable for platform >= V2 */ /* Only applicable for platform >= V2 */
apb->spi_en_gpio = of_get_named_gpio(np, "spi-en-gpio", 0); if (of_property_read_bool(pdev->dev.of_node, "gb,spi-en-active-high"))
if (apb->spi_en_gpio >= 0) { apb->spi_en_polarity_high = true;
if (of_property_read_bool(pdev->dev.of_node,
"spi-en-active-high"))
apb->spi_en_polarity_high = true;
}
return 0; return 0;
} }
......
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