treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / mmc / core / pwrseq_sd8787.c
blob68a826f1c0a10fccb6c97ecfce2e184b02798f2e
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * pwrseq_sd8787.c - power sequence support for Marvell SD8787 BT + Wifi chip
5 * Copyright (C) 2016 Matt Ranostay <matt@ranostay.consulting>
7 * Based on the original work pwrseq_simple.c
8 * Copyright (C) 2014 Linaro Ltd
9 * Author: Ulf Hansson <ulf.hansson@linaro.org>
12 #include <linux/delay.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/platform_device.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
19 #include <linux/err.h>
20 #include <linux/gpio/consumer.h>
22 #include <linux/mmc/host.h>
24 #include "pwrseq.h"
26 struct mmc_pwrseq_sd8787 {
27 struct mmc_pwrseq pwrseq;
28 struct gpio_desc *reset_gpio;
29 struct gpio_desc *pwrdn_gpio;
32 #define to_pwrseq_sd8787(p) container_of(p, struct mmc_pwrseq_sd8787, pwrseq)
34 static void mmc_pwrseq_sd8787_pre_power_on(struct mmc_host *host)
36 struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq);
38 gpiod_set_value_cansleep(pwrseq->reset_gpio, 1);
40 msleep(300);
41 gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 1);
44 static void mmc_pwrseq_sd8787_power_off(struct mmc_host *host)
46 struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq);
48 gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 0);
49 gpiod_set_value_cansleep(pwrseq->reset_gpio, 0);
52 static const struct mmc_pwrseq_ops mmc_pwrseq_sd8787_ops = {
53 .pre_power_on = mmc_pwrseq_sd8787_pre_power_on,
54 .power_off = mmc_pwrseq_sd8787_power_off,
57 static const struct of_device_id mmc_pwrseq_sd8787_of_match[] = {
58 { .compatible = "mmc-pwrseq-sd8787",},
59 {/* sentinel */},
61 MODULE_DEVICE_TABLE(of, mmc_pwrseq_sd8787_of_match);
63 static int mmc_pwrseq_sd8787_probe(struct platform_device *pdev)
65 struct mmc_pwrseq_sd8787 *pwrseq;
66 struct device *dev = &pdev->dev;
68 pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
69 if (!pwrseq)
70 return -ENOMEM;
72 pwrseq->pwrdn_gpio = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_LOW);
73 if (IS_ERR(pwrseq->pwrdn_gpio))
74 return PTR_ERR(pwrseq->pwrdn_gpio);
76 pwrseq->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
77 if (IS_ERR(pwrseq->reset_gpio))
78 return PTR_ERR(pwrseq->reset_gpio);
80 pwrseq->pwrseq.dev = dev;
81 pwrseq->pwrseq.ops = &mmc_pwrseq_sd8787_ops;
82 pwrseq->pwrseq.owner = THIS_MODULE;
83 platform_set_drvdata(pdev, pwrseq);
85 return mmc_pwrseq_register(&pwrseq->pwrseq);
88 static int mmc_pwrseq_sd8787_remove(struct platform_device *pdev)
90 struct mmc_pwrseq_sd8787 *pwrseq = platform_get_drvdata(pdev);
92 mmc_pwrseq_unregister(&pwrseq->pwrseq);
94 return 0;
97 static struct platform_driver mmc_pwrseq_sd8787_driver = {
98 .probe = mmc_pwrseq_sd8787_probe,
99 .remove = mmc_pwrseq_sd8787_remove,
100 .driver = {
101 .name = "pwrseq_sd8787",
102 .of_match_table = mmc_pwrseq_sd8787_of_match,
106 module_platform_driver(mmc_pwrseq_sd8787_driver);
107 MODULE_LICENSE("GPL v2");