2 * pwrseq_sd8787.c - power sequence support for Marvell SD8787 BT + Wifi chip
4 * Copyright (C) 2016 Matt Ranostay <matt@ranostay.consulting>
6 * Based on the original work pwrseq_simple.c
7 * Copyright (C) 2014 Linaro Ltd
8 * Author: Ulf Hansson <ulf.hansson@linaro.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #include <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
25 #include <linux/platform_device.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/device.h>
29 #include <linux/err.h>
30 #include <linux/gpio/consumer.h>
32 #include <linux/mmc/host.h>
36 struct mmc_pwrseq_sd8787
{
37 struct mmc_pwrseq pwrseq
;
38 struct gpio_desc
*reset_gpio
;
39 struct gpio_desc
*pwrdn_gpio
;
42 #define to_pwrseq_sd8787(p) container_of(p, struct mmc_pwrseq_sd8787, pwrseq)
44 static void mmc_pwrseq_sd8787_pre_power_on(struct mmc_host
*host
)
46 struct mmc_pwrseq_sd8787
*pwrseq
= to_pwrseq_sd8787(host
->pwrseq
);
48 gpiod_set_value_cansleep(pwrseq
->reset_gpio
, 1);
51 gpiod_set_value_cansleep(pwrseq
->pwrdn_gpio
, 1);
54 static void mmc_pwrseq_sd8787_power_off(struct mmc_host
*host
)
56 struct mmc_pwrseq_sd8787
*pwrseq
= to_pwrseq_sd8787(host
->pwrseq
);
58 gpiod_set_value_cansleep(pwrseq
->pwrdn_gpio
, 0);
59 gpiod_set_value_cansleep(pwrseq
->reset_gpio
, 0);
62 static const struct mmc_pwrseq_ops mmc_pwrseq_sd8787_ops
= {
63 .pre_power_on
= mmc_pwrseq_sd8787_pre_power_on
,
64 .power_off
= mmc_pwrseq_sd8787_power_off
,
67 static const struct of_device_id mmc_pwrseq_sd8787_of_match
[] = {
68 { .compatible
= "mmc-pwrseq-sd8787",},
71 MODULE_DEVICE_TABLE(of
, mmc_pwrseq_sd8787_of_match
);
73 static int mmc_pwrseq_sd8787_probe(struct platform_device
*pdev
)
75 struct mmc_pwrseq_sd8787
*pwrseq
;
76 struct device
*dev
= &pdev
->dev
;
78 pwrseq
= devm_kzalloc(dev
, sizeof(*pwrseq
), GFP_KERNEL
);
82 pwrseq
->pwrdn_gpio
= devm_gpiod_get(dev
, "powerdown", GPIOD_OUT_LOW
);
83 if (IS_ERR(pwrseq
->pwrdn_gpio
))
84 return PTR_ERR(pwrseq
->pwrdn_gpio
);
86 pwrseq
->reset_gpio
= devm_gpiod_get(dev
, "reset", GPIOD_OUT_LOW
);
87 if (IS_ERR(pwrseq
->reset_gpio
))
88 return PTR_ERR(pwrseq
->reset_gpio
);
90 pwrseq
->pwrseq
.dev
= dev
;
91 pwrseq
->pwrseq
.ops
= &mmc_pwrseq_sd8787_ops
;
92 pwrseq
->pwrseq
.owner
= THIS_MODULE
;
93 platform_set_drvdata(pdev
, pwrseq
);
95 return mmc_pwrseq_register(&pwrseq
->pwrseq
);
98 static int mmc_pwrseq_sd8787_remove(struct platform_device
*pdev
)
100 struct mmc_pwrseq_sd8787
*pwrseq
= platform_get_drvdata(pdev
);
102 mmc_pwrseq_unregister(&pwrseq
->pwrseq
);
107 static struct platform_driver mmc_pwrseq_sd8787_driver
= {
108 .probe
= mmc_pwrseq_sd8787_probe
,
109 .remove
= mmc_pwrseq_sd8787_remove
,
111 .name
= "pwrseq_sd8787",
112 .of_match_table
= mmc_pwrseq_sd8787_of_match
,
116 module_platform_driver(mmc_pwrseq_sd8787_driver
);
117 MODULE_LICENSE("GPL v2");