Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  1/*
  2 * pwrseq_sd8787.c - power sequence support for Marvell SD8787 BT + Wifi chip
  3 *
  4 * Copyright (C) 2016 Matt Ranostay <matt@ranostay.consulting>
  5 *
  6 * Based on the original work pwrseq_simple.c
  7 *  Copyright (C) 2014 Linaro Ltd
  8 *  Author: Ulf Hansson <ulf.hansson@linaro.org>
  9 *
 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.
 14 *
 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.
 19 *
 20 */
 21
 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>
 31
 32#include <linux/mmc/host.h>
 33
 34#include "pwrseq.h"
 35
 36struct mmc_pwrseq_sd8787 {
 37	struct mmc_pwrseq pwrseq;
 38	struct gpio_desc *reset_gpio;
 39	struct gpio_desc *pwrdn_gpio;
 40};
 41
 42#define to_pwrseq_sd8787(p) container_of(p, struct mmc_pwrseq_sd8787, pwrseq)
 43
 44static void mmc_pwrseq_sd8787_pre_power_on(struct mmc_host *host)
 45{
 46	struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq);
 47
 48	gpiod_set_value_cansleep(pwrseq->reset_gpio, 1);
 49
 50	msleep(300);
 51	gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 1);
 52}
 53
 54static void mmc_pwrseq_sd8787_power_off(struct mmc_host *host)
 55{
 56	struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq);
 57
 58	gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 0);
 59	gpiod_set_value_cansleep(pwrseq->reset_gpio, 0);
 60}
 61
 62static 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,
 65};
 66
 67static const struct of_device_id mmc_pwrseq_sd8787_of_match[] = {
 68	{ .compatible = "mmc-pwrseq-sd8787",},
 69	{/* sentinel */},
 70};
 71MODULE_DEVICE_TABLE(of, mmc_pwrseq_sd8787_of_match);
 72
 73static int mmc_pwrseq_sd8787_probe(struct platform_device *pdev)
 74{
 75	struct mmc_pwrseq_sd8787 *pwrseq;
 76	struct device *dev = &pdev->dev;
 77
 78	pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
 79	if (!pwrseq)
 80		return -ENOMEM;
 81
 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);
 85
 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);
 89
 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);
 94
 95	return mmc_pwrseq_register(&pwrseq->pwrseq);
 96}
 97
 98static int mmc_pwrseq_sd8787_remove(struct platform_device *pdev)
 99{
100	struct mmc_pwrseq_sd8787 *pwrseq = platform_get_drvdata(pdev);
101
102	mmc_pwrseq_unregister(&pwrseq->pwrseq);
103
104	return 0;
105}
106
107static struct platform_driver mmc_pwrseq_sd8787_driver = {
108	.probe = mmc_pwrseq_sd8787_probe,
109	.remove = mmc_pwrseq_sd8787_remove,
110	.driver = {
111		.name = "pwrseq_sd8787",
112		.of_match_table = mmc_pwrseq_sd8787_of_match,
113	},
114};
115
116module_platform_driver(mmc_pwrseq_sd8787_driver);
117MODULE_LICENSE("GPL v2");