Unverified Commit 94112d3d authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: codec: wcd93xx: Convert to GPIO descriptors

Merge series from "Peng Fan (OSS)" <peng.fan@oss.nxp.com>:

of_gpio.h is deprecated, so update driver to use gpiod API.

The current driver use value 0 to assert reset and 1 to deassert reset.
The DTSes in tree that use the codec are using GPIO_ACTIVE_LOW.
So it is safe to use devm_gpiod_get to get GPIO descriptors and
use gpiod_set_value to configure output with value 1 means raw value
0, value 0 means raw value 1.

Note:
I not have devices to test, just my best pratice to do the convertion.
parents 1f4db3cb d5099bc1
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include <sound/soc.h>
#include <sound/pcm_params.h>
#include <sound/soc-dapm.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <sound/tlv.h>
@@ -331,7 +331,7 @@ struct wcd9335_codec {
	int comp_enabled[COMPANDER_MAX];

	int intr1;
	int reset_gpio;
	struct gpio_desc *reset_gpio;
	struct regulator_bulk_data supplies[WCD9335_MAX_SUPPLY];

	unsigned int rx_port_value[WCD9335_RX_MAX];
@@ -4975,12 +4975,11 @@ static const struct regmap_irq_chip wcd9335_regmap_irq1_chip = {
static int wcd9335_parse_dt(struct wcd9335_codec *wcd)
{
	struct device *dev = wcd->dev;
	struct device_node *np = dev->of_node;
	int ret;

	wcd->reset_gpio = of_get_named_gpio(np,	"reset-gpios", 0);
	if (wcd->reset_gpio < 0)
		return dev_err_probe(dev, wcd->reset_gpio, "Reset GPIO missing from DT\n");
	wcd->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(wcd->reset_gpio))
		return dev_err_probe(dev, PTR_ERR(wcd->reset_gpio), "Reset GPIO missing from DT\n");

	wcd->mclk = devm_clk_get(dev, "mclk");
	if (IS_ERR(wcd->mclk))
@@ -5023,9 +5022,9 @@ static int wcd9335_power_on_reset(struct wcd9335_codec *wcd)
	 */
	usleep_range(600, 650);

	gpio_direction_output(wcd->reset_gpio, 0);
	gpiod_set_value(wcd->reset_gpio, 1);
	msleep(20);
	gpio_set_value(wcd->reset_gpio, 1);
	gpiod_set_value(wcd->reset_gpio, 0);
	msleep(20);

	return 0;
+6 −7
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
#include <linux/pm_runtime.h>
#include <linux/component.h>
#include <sound/tlv.h>
#include <linux/of_gpio.h>
#include <linux/of.h>
#include <sound/jack.h>
#include <sound/pcm.h>
@@ -171,7 +170,7 @@ struct wcd938x_priv {
	int flyback_cur_det_disable;
	int ear_rx_path;
	int variant;
	int reset_gpio;
	struct gpio_desc *reset_gpio;
	struct gpio_desc *us_euro_gpio;
	u32 micb1_mv;
	u32 micb2_mv;
@@ -3251,9 +3250,9 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
	struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg;
	int ret;

	wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
	if (wcd938x->reset_gpio < 0)
		return dev_err_probe(dev, wcd938x->reset_gpio,
	wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(wcd938x->reset_gpio))
		return dev_err_probe(dev, PTR_ERR(wcd938x->reset_gpio),
				     "Failed to get reset gpio\n");

	wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro",
@@ -3297,10 +3296,10 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device

static int wcd938x_reset(struct wcd938x_priv *wcd938x)
{
	gpio_direction_output(wcd938x->reset_gpio, 0);
	gpiod_set_value(wcd938x->reset_gpio, 1);
	/* 20us sleep required after pulling the reset gpio to LOW */
	usleep_range(20, 30);
	gpio_set_value(wcd938x->reset_gpio, 1);
	gpiod_set_value(wcd938x->reset_gpio, 0);
	/* 20us sleep required after pulling the reset gpio to HIGH */
	usleep_range(20, 30);

+8 −8
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
#include <linux/pm_runtime.h>
#include <linux/component.h>
#include <sound/tlv.h>
#include <linux/of_gpio.h>
#include <linux/of_graph.h>
#include <linux/of.h>
#include <sound/jack.h>
@@ -201,7 +200,7 @@ struct wcd939x_priv {
	u32 hph_mode;
	u32 tx_mode[TX_ADC_MAX];
	int variant;
	int reset_gpio;
	struct gpio_desc *reset_gpio;
	u32 micb1_mv;
	u32 micb2_mv;
	u32 micb3_mv;
@@ -3239,10 +3238,11 @@ static int wcd939x_populate_dt_data(struct wcd939x_priv *wcd939x, struct device
#endif /* CONFIG_TYPEC */
	int ret;

	wcd939x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
	if (wcd939x->reset_gpio < 0)
		return dev_err_probe(dev, wcd939x->reset_gpio,
				     "Failed to get reset gpio\n");
	wcd939x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(wcd939x->reset_gpio)) {
		ret = PTR_ERR(wcd939x->reset_gpio);
		return dev_err_probe(dev, ret, "Failed to get reset gpio\n");
	}

	wcd939x->supplies[0].supply = "vdd-rxtx";
	wcd939x->supplies[1].supply = "vdd-io";
@@ -3290,10 +3290,10 @@ static int wcd939x_populate_dt_data(struct wcd939x_priv *wcd939x, struct device

static int wcd939x_reset(struct wcd939x_priv *wcd939x)
{
	gpio_direction_output(wcd939x->reset_gpio, 0);
	gpiod_set_value(wcd939x->reset_gpio, 1);
	/* 20us sleep required after pulling the reset gpio to LOW */
	usleep_range(20, 30);
	gpio_set_value(wcd939x->reset_gpio, 1);
	gpiod_set_value(wcd939x->reset_gpio, 0);
	/* 20us sleep required after pulling the reset gpio to HIGH */
	usleep_range(20, 30);