xref: /linux/drivers/power/sequencing/pwrseq-qcom-wcn.c (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
12f1630f4SBartosz Golaszewski // SPDX-License-Identifier: GPL-2.0-only
22f1630f4SBartosz Golaszewski /*
32f1630f4SBartosz Golaszewski  * Copyright (C) 2024 Linaro Ltd.
42f1630f4SBartosz Golaszewski  */
52f1630f4SBartosz Golaszewski 
62f1630f4SBartosz Golaszewski #include <linux/clk.h>
72f1630f4SBartosz Golaszewski #include <linux/delay.h>
82f1630f4SBartosz Golaszewski #include <linux/device.h>
92f1630f4SBartosz Golaszewski #include <linux/gpio/consumer.h>
102f1630f4SBartosz Golaszewski #include <linux/jiffies.h>
112f1630f4SBartosz Golaszewski #include <linux/mod_devicetable.h>
122f1630f4SBartosz Golaszewski #include <linux/module.h>
132f1630f4SBartosz Golaszewski #include <linux/of.h>
142f1630f4SBartosz Golaszewski #include <linux/platform_device.h>
152f1630f4SBartosz Golaszewski #include <linux/regulator/consumer.h>
162f1630f4SBartosz Golaszewski #include <linux/pwrseq/provider.h>
172f1630f4SBartosz Golaszewski #include <linux/string.h>
182f1630f4SBartosz Golaszewski #include <linux/types.h>
192f1630f4SBartosz Golaszewski 
202f1630f4SBartosz Golaszewski struct pwrseq_qcom_wcn_pdata {
212f1630f4SBartosz Golaszewski 	const char *const *vregs;
222f1630f4SBartosz Golaszewski 	size_t num_vregs;
232f1630f4SBartosz Golaszewski 	unsigned int pwup_delay_ms;
242f1630f4SBartosz Golaszewski 	unsigned int gpio_enable_delay_ms;
252f1630f4SBartosz Golaszewski };
262f1630f4SBartosz Golaszewski 
272f1630f4SBartosz Golaszewski struct pwrseq_qcom_wcn_ctx {
282f1630f4SBartosz Golaszewski 	struct pwrseq_device *pwrseq;
292f1630f4SBartosz Golaszewski 	struct device_node *of_node;
302f1630f4SBartosz Golaszewski 	const struct pwrseq_qcom_wcn_pdata *pdata;
312f1630f4SBartosz Golaszewski 	struct regulator_bulk_data *regs;
322f1630f4SBartosz Golaszewski 	struct gpio_desc *bt_gpio;
332f1630f4SBartosz Golaszewski 	struct gpio_desc *wlan_gpio;
342f1630f4SBartosz Golaszewski 	struct clk *clk;
352f1630f4SBartosz Golaszewski 	unsigned long last_gpio_enable_jf;
362f1630f4SBartosz Golaszewski };
372f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_ensure_gpio_delay(struct pwrseq_qcom_wcn_ctx * ctx)382f1630f4SBartosz Golaszewski static void pwrseq_qcom_wcn_ensure_gpio_delay(struct pwrseq_qcom_wcn_ctx *ctx)
392f1630f4SBartosz Golaszewski {
402f1630f4SBartosz Golaszewski 	unsigned long diff_jiffies;
412f1630f4SBartosz Golaszewski 	unsigned int diff_msecs;
422f1630f4SBartosz Golaszewski 
432f1630f4SBartosz Golaszewski 	if (!ctx->pdata->gpio_enable_delay_ms)
442f1630f4SBartosz Golaszewski 		return;
452f1630f4SBartosz Golaszewski 
462f1630f4SBartosz Golaszewski 	diff_jiffies = jiffies - ctx->last_gpio_enable_jf;
472f1630f4SBartosz Golaszewski 	diff_msecs = jiffies_to_msecs(diff_jiffies);
482f1630f4SBartosz Golaszewski 
492f1630f4SBartosz Golaszewski 	if (diff_msecs < ctx->pdata->gpio_enable_delay_ms)
502f1630f4SBartosz Golaszewski 		msleep(ctx->pdata->gpio_enable_delay_ms - diff_msecs);
512f1630f4SBartosz Golaszewski }
522f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_vregs_enable(struct pwrseq_device * pwrseq)532f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_vregs_enable(struct pwrseq_device *pwrseq)
542f1630f4SBartosz Golaszewski {
552f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
562f1630f4SBartosz Golaszewski 
572f1630f4SBartosz Golaszewski 	return regulator_bulk_enable(ctx->pdata->num_vregs, ctx->regs);
582f1630f4SBartosz Golaszewski }
592f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_vregs_disable(struct pwrseq_device * pwrseq)602f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_vregs_disable(struct pwrseq_device *pwrseq)
612f1630f4SBartosz Golaszewski {
622f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
632f1630f4SBartosz Golaszewski 
642f1630f4SBartosz Golaszewski 	return regulator_bulk_disable(ctx->pdata->num_vregs, ctx->regs);
652f1630f4SBartosz Golaszewski }
662f1630f4SBartosz Golaszewski 
672f1630f4SBartosz Golaszewski static const struct pwrseq_unit_data pwrseq_qcom_wcn_vregs_unit_data = {
682f1630f4SBartosz Golaszewski 	.name = "regulators-enable",
692f1630f4SBartosz Golaszewski 	.enable = pwrseq_qcom_wcn_vregs_enable,
702f1630f4SBartosz Golaszewski 	.disable = pwrseq_qcom_wcn_vregs_disable,
712f1630f4SBartosz Golaszewski };
722f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_clk_enable(struct pwrseq_device * pwrseq)732f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_clk_enable(struct pwrseq_device *pwrseq)
742f1630f4SBartosz Golaszewski {
752f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
762f1630f4SBartosz Golaszewski 
772f1630f4SBartosz Golaszewski 	return clk_prepare_enable(ctx->clk);
782f1630f4SBartosz Golaszewski }
792f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_clk_disable(struct pwrseq_device * pwrseq)802f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_clk_disable(struct pwrseq_device *pwrseq)
812f1630f4SBartosz Golaszewski {
822f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
832f1630f4SBartosz Golaszewski 
842f1630f4SBartosz Golaszewski 	clk_disable_unprepare(ctx->clk);
852f1630f4SBartosz Golaszewski 
862f1630f4SBartosz Golaszewski 	return 0;
872f1630f4SBartosz Golaszewski }
882f1630f4SBartosz Golaszewski 
892f1630f4SBartosz Golaszewski static const struct pwrseq_unit_data pwrseq_qcom_wcn_clk_unit_data = {
902f1630f4SBartosz Golaszewski 	.name = "clock-enable",
912f1630f4SBartosz Golaszewski 	.enable = pwrseq_qcom_wcn_clk_enable,
922f1630f4SBartosz Golaszewski 	.disable = pwrseq_qcom_wcn_clk_disable,
932f1630f4SBartosz Golaszewski };
942f1630f4SBartosz Golaszewski 
952f1630f4SBartosz Golaszewski static const struct pwrseq_unit_data *pwrseq_qcom_wcn_unit_deps[] = {
962f1630f4SBartosz Golaszewski 	&pwrseq_qcom_wcn_vregs_unit_data,
972f1630f4SBartosz Golaszewski 	&pwrseq_qcom_wcn_clk_unit_data,
982f1630f4SBartosz Golaszewski 	NULL
992f1630f4SBartosz Golaszewski };
1002f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_bt_enable(struct pwrseq_device * pwrseq)1012f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_bt_enable(struct pwrseq_device *pwrseq)
1022f1630f4SBartosz Golaszewski {
1032f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
1042f1630f4SBartosz Golaszewski 
1052f1630f4SBartosz Golaszewski 	pwrseq_qcom_wcn_ensure_gpio_delay(ctx);
1062f1630f4SBartosz Golaszewski 	gpiod_set_value_cansleep(ctx->bt_gpio, 1);
1072f1630f4SBartosz Golaszewski 	ctx->last_gpio_enable_jf = jiffies;
1082f1630f4SBartosz Golaszewski 
1092f1630f4SBartosz Golaszewski 	return 0;
1102f1630f4SBartosz Golaszewski }
1112f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_bt_disable(struct pwrseq_device * pwrseq)1122f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_bt_disable(struct pwrseq_device *pwrseq)
1132f1630f4SBartosz Golaszewski {
1142f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
1152f1630f4SBartosz Golaszewski 
1162f1630f4SBartosz Golaszewski 	gpiod_set_value_cansleep(ctx->bt_gpio, 0);
1172f1630f4SBartosz Golaszewski 
1182f1630f4SBartosz Golaszewski 	return 0;
1192f1630f4SBartosz Golaszewski }
1202f1630f4SBartosz Golaszewski 
1212f1630f4SBartosz Golaszewski static const struct pwrseq_unit_data pwrseq_qcom_wcn_bt_unit_data = {
1222f1630f4SBartosz Golaszewski 	.name = "bluetooth-enable",
1232f1630f4SBartosz Golaszewski 	.deps = pwrseq_qcom_wcn_unit_deps,
1242f1630f4SBartosz Golaszewski 	.enable = pwrseq_qcom_wcn_bt_enable,
1252f1630f4SBartosz Golaszewski 	.disable = pwrseq_qcom_wcn_bt_disable,
1262f1630f4SBartosz Golaszewski };
1272f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_wlan_enable(struct pwrseq_device * pwrseq)1282f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_wlan_enable(struct pwrseq_device *pwrseq)
1292f1630f4SBartosz Golaszewski {
1302f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
1312f1630f4SBartosz Golaszewski 
1322f1630f4SBartosz Golaszewski 	pwrseq_qcom_wcn_ensure_gpio_delay(ctx);
1332f1630f4SBartosz Golaszewski 	gpiod_set_value_cansleep(ctx->wlan_gpio, 1);
1342f1630f4SBartosz Golaszewski 	ctx->last_gpio_enable_jf = jiffies;
1352f1630f4SBartosz Golaszewski 
1362f1630f4SBartosz Golaszewski 	return 0;
1372f1630f4SBartosz Golaszewski }
1382f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_wlan_disable(struct pwrseq_device * pwrseq)1392f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_wlan_disable(struct pwrseq_device *pwrseq)
1402f1630f4SBartosz Golaszewski {
1412f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
1422f1630f4SBartosz Golaszewski 
1432f1630f4SBartosz Golaszewski 	gpiod_set_value_cansleep(ctx->wlan_gpio, 0);
1442f1630f4SBartosz Golaszewski 
1452f1630f4SBartosz Golaszewski 	return 0;
1462f1630f4SBartosz Golaszewski }
1472f1630f4SBartosz Golaszewski 
1482f1630f4SBartosz Golaszewski static const struct pwrseq_unit_data pwrseq_qcom_wcn_wlan_unit_data = {
1492f1630f4SBartosz Golaszewski 	.name = "wlan-enable",
1502f1630f4SBartosz Golaszewski 	.deps = pwrseq_qcom_wcn_unit_deps,
1512f1630f4SBartosz Golaszewski 	.enable = pwrseq_qcom_wcn_wlan_enable,
1522f1630f4SBartosz Golaszewski 	.disable = pwrseq_qcom_wcn_wlan_disable,
1532f1630f4SBartosz Golaszewski };
1542f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_pwup_delay(struct pwrseq_device * pwrseq)1552f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_pwup_delay(struct pwrseq_device *pwrseq)
1562f1630f4SBartosz Golaszewski {
1572f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
1582f1630f4SBartosz Golaszewski 
1592f1630f4SBartosz Golaszewski 	if (ctx->pdata->pwup_delay_ms)
1602f1630f4SBartosz Golaszewski 		msleep(ctx->pdata->pwup_delay_ms);
1612f1630f4SBartosz Golaszewski 
1622f1630f4SBartosz Golaszewski 	return 0;
1632f1630f4SBartosz Golaszewski }
1642f1630f4SBartosz Golaszewski 
1652f1630f4SBartosz Golaszewski static const struct pwrseq_target_data pwrseq_qcom_wcn_bt_target_data = {
1662f1630f4SBartosz Golaszewski 	.name = "bluetooth",
1672f1630f4SBartosz Golaszewski 	.unit = &pwrseq_qcom_wcn_bt_unit_data,
1682f1630f4SBartosz Golaszewski 	.post_enable = pwrseq_qcom_wcn_pwup_delay,
1692f1630f4SBartosz Golaszewski };
1702f1630f4SBartosz Golaszewski 
1712f1630f4SBartosz Golaszewski static const struct pwrseq_target_data pwrseq_qcom_wcn_wlan_target_data = {
1722f1630f4SBartosz Golaszewski 	.name = "wlan",
1732f1630f4SBartosz Golaszewski 	.unit = &pwrseq_qcom_wcn_wlan_unit_data,
1742f1630f4SBartosz Golaszewski 	.post_enable = pwrseq_qcom_wcn_pwup_delay,
1752f1630f4SBartosz Golaszewski };
1762f1630f4SBartosz Golaszewski 
1772f1630f4SBartosz Golaszewski static const struct pwrseq_target_data *pwrseq_qcom_wcn_targets[] = {
1782f1630f4SBartosz Golaszewski 	&pwrseq_qcom_wcn_bt_target_data,
1792f1630f4SBartosz Golaszewski 	&pwrseq_qcom_wcn_wlan_target_data,
1802f1630f4SBartosz Golaszewski 	NULL
1812f1630f4SBartosz Golaszewski };
1822f1630f4SBartosz Golaszewski 
1832f1630f4SBartosz Golaszewski static const char *const pwrseq_qca6390_vregs[] = {
1842f1630f4SBartosz Golaszewski 	"vddio",
1852f1630f4SBartosz Golaszewski 	"vddaon",
1862f1630f4SBartosz Golaszewski 	"vddpmu",
1872f1630f4SBartosz Golaszewski 	"vddrfa0p95",
1882f1630f4SBartosz Golaszewski 	"vddrfa1p3",
1892f1630f4SBartosz Golaszewski 	"vddrfa1p9",
1902f1630f4SBartosz Golaszewski 	"vddpcie1p3",
1912f1630f4SBartosz Golaszewski 	"vddpcie1p9",
1922f1630f4SBartosz Golaszewski };
1932f1630f4SBartosz Golaszewski 
1942f1630f4SBartosz Golaszewski static const struct pwrseq_qcom_wcn_pdata pwrseq_qca6390_of_data = {
1952f1630f4SBartosz Golaszewski 	.vregs = pwrseq_qca6390_vregs,
1962f1630f4SBartosz Golaszewski 	.num_vregs = ARRAY_SIZE(pwrseq_qca6390_vregs),
1972f1630f4SBartosz Golaszewski 	.pwup_delay_ms = 60,
1982f1630f4SBartosz Golaszewski 	.gpio_enable_delay_ms = 100,
1992f1630f4SBartosz Golaszewski };
2002f1630f4SBartosz Golaszewski 
2012f1630f4SBartosz Golaszewski static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn6855_of_data = {
2022f1630f4SBartosz Golaszewski 	.vregs = pwrseq_qca6390_vregs,
2032f1630f4SBartosz Golaszewski 	.num_vregs = ARRAY_SIZE(pwrseq_qca6390_vregs),
2042f1630f4SBartosz Golaszewski 	.pwup_delay_ms = 50,
2052f1630f4SBartosz Golaszewski 	.gpio_enable_delay_ms = 5,
2062f1630f4SBartosz Golaszewski };
2072f1630f4SBartosz Golaszewski 
2082f1630f4SBartosz Golaszewski static const char *const pwrseq_wcn7850_vregs[] = {
2092f1630f4SBartosz Golaszewski 	"vdd",
2102f1630f4SBartosz Golaszewski 	"vddio",
2112f1630f4SBartosz Golaszewski 	"vddio1p2",
2122f1630f4SBartosz Golaszewski 	"vddaon",
2132f1630f4SBartosz Golaszewski 	"vdddig",
2142f1630f4SBartosz Golaszewski 	"vddrfa1p2",
2152f1630f4SBartosz Golaszewski 	"vddrfa1p8",
2162f1630f4SBartosz Golaszewski };
2172f1630f4SBartosz Golaszewski 
2182f1630f4SBartosz Golaszewski static const struct pwrseq_qcom_wcn_pdata pwrseq_wcn7850_of_data = {
2192f1630f4SBartosz Golaszewski 	.vregs = pwrseq_wcn7850_vregs,
2202f1630f4SBartosz Golaszewski 	.num_vregs = ARRAY_SIZE(pwrseq_wcn7850_vregs),
2212f1630f4SBartosz Golaszewski 	.pwup_delay_ms = 50,
2222f1630f4SBartosz Golaszewski };
2232f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_match(struct pwrseq_device * pwrseq,struct device * dev)2242f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_match(struct pwrseq_device *pwrseq,
2252f1630f4SBartosz Golaszewski 				 struct device *dev)
2262f1630f4SBartosz Golaszewski {
2272f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
2282f1630f4SBartosz Golaszewski 	struct device_node *dev_node = dev->of_node;
2292f1630f4SBartosz Golaszewski 
2302f1630f4SBartosz Golaszewski 	/*
2312f1630f4SBartosz Golaszewski 	 * The PMU supplies power to the Bluetooth and WLAN modules. both
2322f1630f4SBartosz Golaszewski 	 * consume the PMU AON output so check the presence of the
2332f1630f4SBartosz Golaszewski 	 * 'vddaon-supply' property and whether it leads us to the right
2342f1630f4SBartosz Golaszewski 	 * device.
2352f1630f4SBartosz Golaszewski 	 */
2362f1630f4SBartosz Golaszewski 	if (!of_property_present(dev_node, "vddaon-supply"))
2372f1630f4SBartosz Golaszewski 		return 0;
2382f1630f4SBartosz Golaszewski 
2392f1630f4SBartosz Golaszewski 	struct device_node *reg_node __free(device_node) =
2402f1630f4SBartosz Golaszewski 			of_parse_phandle(dev_node, "vddaon-supply", 0);
2412f1630f4SBartosz Golaszewski 	if (!reg_node)
2422f1630f4SBartosz Golaszewski 		return 0;
2432f1630f4SBartosz Golaszewski 
2442f1630f4SBartosz Golaszewski 	/*
2452f1630f4SBartosz Golaszewski 	 * `reg_node` is the PMU AON regulator, its parent is the `regulators`
2462f1630f4SBartosz Golaszewski 	 * node and finally its grandparent is the PMU device node that we're
2472f1630f4SBartosz Golaszewski 	 * looking for.
2482f1630f4SBartosz Golaszewski 	 */
2492f1630f4SBartosz Golaszewski 	if (!reg_node->parent || !reg_node->parent->parent ||
2502f1630f4SBartosz Golaszewski 	    reg_node->parent->parent != ctx->of_node)
2512f1630f4SBartosz Golaszewski 		return 0;
2522f1630f4SBartosz Golaszewski 
2532f1630f4SBartosz Golaszewski 	return 1;
2542f1630f4SBartosz Golaszewski }
2552f1630f4SBartosz Golaszewski 
pwrseq_qcom_wcn_probe(struct platform_device * pdev)2562f1630f4SBartosz Golaszewski static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)
2572f1630f4SBartosz Golaszewski {
2582f1630f4SBartosz Golaszewski 	struct device *dev = &pdev->dev;
2592f1630f4SBartosz Golaszewski 	struct pwrseq_qcom_wcn_ctx *ctx;
2602f1630f4SBartosz Golaszewski 	struct pwrseq_config config;
2612f1630f4SBartosz Golaszewski 	int i, ret;
2622f1630f4SBartosz Golaszewski 
2632f1630f4SBartosz Golaszewski 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
2642f1630f4SBartosz Golaszewski 	if (!ctx)
2652f1630f4SBartosz Golaszewski 		return -ENOMEM;
2662f1630f4SBartosz Golaszewski 
2672f1630f4SBartosz Golaszewski 	ctx->of_node = dev->of_node;
2682f1630f4SBartosz Golaszewski 
2692f1630f4SBartosz Golaszewski 	ctx->pdata = of_device_get_match_data(dev);
2702f1630f4SBartosz Golaszewski 	if (!ctx->pdata)
2712f1630f4SBartosz Golaszewski 		return dev_err_probe(dev, -ENODEV,
2722f1630f4SBartosz Golaszewski 				     "Failed to obtain platform data\n");
2732f1630f4SBartosz Golaszewski 
2742f1630f4SBartosz Golaszewski 	ctx->regs = devm_kcalloc(dev, ctx->pdata->num_vregs,
2752f1630f4SBartosz Golaszewski 				 sizeof(*ctx->regs), GFP_KERNEL);
2762f1630f4SBartosz Golaszewski 	if (!ctx->regs)
2772f1630f4SBartosz Golaszewski 		return -ENOMEM;
2782f1630f4SBartosz Golaszewski 
2792f1630f4SBartosz Golaszewski 	for (i = 0; i < ctx->pdata->num_vregs; i++)
2802f1630f4SBartosz Golaszewski 		ctx->regs[i].supply = ctx->pdata->vregs[i];
2812f1630f4SBartosz Golaszewski 
2822f1630f4SBartosz Golaszewski 	ret = devm_regulator_bulk_get(dev, ctx->pdata->num_vregs, ctx->regs);
2832f1630f4SBartosz Golaszewski 	if (ret < 0)
2842f1630f4SBartosz Golaszewski 		return dev_err_probe(dev, ret,
2852f1630f4SBartosz Golaszewski 				     "Failed to get all regulators\n");
286a9aaf1ffSBartosz Golaszewski 
2872f1630f4SBartosz Golaszewski 	ctx->bt_gpio = devm_gpiod_get_optional(dev, "bt-enable", GPIOD_OUT_LOW);
2882f1630f4SBartosz Golaszewski 	if (IS_ERR(ctx->bt_gpio))
2892f1630f4SBartosz Golaszewski 		return dev_err_probe(dev, PTR_ERR(ctx->bt_gpio),
2902f1630f4SBartosz Golaszewski 				     "Failed to get the Bluetooth enable GPIO\n");
291*d8b76207SBartosz Golaszewski 
292*d8b76207SBartosz Golaszewski 	ctx->wlan_gpio = devm_gpiod_get_optional(dev, "wlan-enable",
293*d8b76207SBartosz Golaszewski 						 GPIOD_ASIS);
294*d8b76207SBartosz Golaszewski 	if (IS_ERR(ctx->wlan_gpio))
295*d8b76207SBartosz Golaszewski 		return dev_err_probe(dev, PTR_ERR(ctx->wlan_gpio),
296*d8b76207SBartosz Golaszewski 				     "Failed to get the WLAN enable GPIO\n");
297*d8b76207SBartosz Golaszewski 
2982f1630f4SBartosz Golaszewski 	/*
2992f1630f4SBartosz Golaszewski 	 * Set direction to output but keep the current value in order to not
3002f1630f4SBartosz Golaszewski 	 * disable the WLAN module accidentally if it's already powered on.
3012f1630f4SBartosz Golaszewski 	 */
3022f1630f4SBartosz Golaszewski 	gpiod_direction_output(ctx->wlan_gpio,
3032f1630f4SBartosz Golaszewski 			       gpiod_get_value_cansleep(ctx->wlan_gpio));
3042f1630f4SBartosz Golaszewski 
3052f1630f4SBartosz Golaszewski 	ctx->clk = devm_clk_get_optional(dev, NULL);
3062f1630f4SBartosz Golaszewski 	if (IS_ERR(ctx->clk))
3072f1630f4SBartosz Golaszewski 		return dev_err_probe(dev, PTR_ERR(ctx->clk),
3082f1630f4SBartosz Golaszewski 				     "Failed to get the reference clock\n");
3092f1630f4SBartosz Golaszewski 
3102f1630f4SBartosz Golaszewski 	memset(&config, 0, sizeof(config));
3112f1630f4SBartosz Golaszewski 
3122f1630f4SBartosz Golaszewski 	config.parent = dev;
3132f1630f4SBartosz Golaszewski 	config.owner = THIS_MODULE;
3142f1630f4SBartosz Golaszewski 	config.drvdata = ctx;
3152f1630f4SBartosz Golaszewski 	config.match = pwrseq_qcom_wcn_match;
3162f1630f4SBartosz Golaszewski 	config.targets = pwrseq_qcom_wcn_targets;
3172f1630f4SBartosz Golaszewski 
3182f1630f4SBartosz Golaszewski 	ctx->pwrseq = devm_pwrseq_device_register(dev, &config);
3192f1630f4SBartosz Golaszewski 	if (IS_ERR(ctx->pwrseq))
3202f1630f4SBartosz Golaszewski 		return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
3212f1630f4SBartosz Golaszewski 				     "Failed to register the power sequencer\n");
3222f1630f4SBartosz Golaszewski 
3232f1630f4SBartosz Golaszewski 	return 0;
3242f1630f4SBartosz Golaszewski }
3252f1630f4SBartosz Golaszewski 
3262f1630f4SBartosz Golaszewski static const struct of_device_id pwrseq_qcom_wcn_of_match[] = {
3272f1630f4SBartosz Golaszewski 	{
3282f1630f4SBartosz Golaszewski 		.compatible = "qcom,qca6390-pmu",
3292f1630f4SBartosz Golaszewski 		.data = &pwrseq_qca6390_of_data,
3302f1630f4SBartosz Golaszewski 	},
3312f1630f4SBartosz Golaszewski 	{
3322f1630f4SBartosz Golaszewski 		.compatible = "qcom,wcn6855-pmu",
3332f1630f4SBartosz Golaszewski 		.data = &pwrseq_wcn6855_of_data,
3342f1630f4SBartosz Golaszewski 	},
3352f1630f4SBartosz Golaszewski 	{
3362f1630f4SBartosz Golaszewski 		.compatible = "qcom,wcn7850-pmu",
3372f1630f4SBartosz Golaszewski 		.data = &pwrseq_wcn7850_of_data,
3382f1630f4SBartosz Golaszewski 	},
3392f1630f4SBartosz Golaszewski 	{ }
3402f1630f4SBartosz Golaszewski };
3412f1630f4SBartosz Golaszewski MODULE_DEVICE_TABLE(of, pwrseq_qcom_wcn_of_match);
3422f1630f4SBartosz Golaszewski 
3432f1630f4SBartosz Golaszewski static struct platform_driver pwrseq_qcom_wcn_driver = {
344 	.driver = {
345 		.name = "pwrseq-qcom_wcn",
346 		.of_match_table = pwrseq_qcom_wcn_of_match,
347 	},
348 	.probe = pwrseq_qcom_wcn_probe,
349 };
350 module_platform_driver(pwrseq_qcom_wcn_driver);
351 
352 MODULE_AUTHOR("Bartosz Golaszewski <bartosz.golaszewski@linaro.org>");
353 MODULE_DESCRIPTION("Qualcomm WCN PMU power sequencing driver");
354 MODULE_LICENSE("GPL");
355