pwrseq_sd8787.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include <linux/delay.h>
  22. #include <linux/init.h>
  23. #include <linux/kernel.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/module.h>
  26. #include <linux/slab.h>
  27. #include <linux/device.h>
  28. #include <linux/err.h>
  29. #include <linux/gpio/consumer.h>
  30. #include <linux/mmc/host.h>
  31. #include "pwrseq.h"
  32. struct mmc_pwrseq_sd8787 {
  33. struct mmc_pwrseq pwrseq;
  34. struct gpio_desc *reset_gpio;
  35. struct gpio_desc *pwrdn_gpio;
  36. };
  37. #define to_pwrseq_sd8787(p) container_of(p, struct mmc_pwrseq_sd8787, pwrseq)
  38. static void mmc_pwrseq_sd8787_pre_power_on(struct mmc_host *host)
  39. {
  40. struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq);
  41. gpiod_set_value_cansleep(pwrseq->reset_gpio, 1);
  42. msleep(300);
  43. gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 1);
  44. }
  45. static void mmc_pwrseq_sd8787_power_off(struct mmc_host *host)
  46. {
  47. 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);
  50. }
  51. static const struct mmc_pwrseq_ops mmc_pwrseq_sd8787_ops = {
  52. .pre_power_on = mmc_pwrseq_sd8787_pre_power_on,
  53. .power_off = mmc_pwrseq_sd8787_power_off,
  54. };
  55. static const struct of_device_id mmc_pwrseq_sd8787_of_match[] = {
  56. { .compatible = "mmc-pwrseq-sd8787",},
  57. {/* sentinel */},
  58. };
  59. MODULE_DEVICE_TABLE(of, mmc_pwrseq_sd8787_of_match);
  60. static int mmc_pwrseq_sd8787_probe(struct platform_device *pdev)
  61. {
  62. struct mmc_pwrseq_sd8787 *pwrseq;
  63. struct device *dev = &pdev->dev;
  64. pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
  65. if (!pwrseq)
  66. return -ENOMEM;
  67. pwrseq->pwrdn_gpio = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_LOW);
  68. if (IS_ERR(pwrseq->pwrdn_gpio))
  69. return PTR_ERR(pwrseq->pwrdn_gpio);
  70. pwrseq->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
  71. if (IS_ERR(pwrseq->reset_gpio))
  72. return PTR_ERR(pwrseq->reset_gpio);
  73. pwrseq->pwrseq.dev = dev;
  74. pwrseq->pwrseq.ops = &mmc_pwrseq_sd8787_ops;
  75. pwrseq->pwrseq.owner = THIS_MODULE;
  76. platform_set_drvdata(pdev, pwrseq);
  77. return mmc_pwrseq_register(&pwrseq->pwrseq);
  78. }
  79. static int mmc_pwrseq_sd8787_remove(struct platform_device *pdev)
  80. {
  81. struct mmc_pwrseq_sd8787 *pwrseq = platform_get_drvdata(pdev);
  82. mmc_pwrseq_unregister(&pwrseq->pwrseq);
  83. return 0;
  84. }
  85. static struct platform_driver mmc_pwrseq_sd8787_driver = {
  86. .probe = mmc_pwrseq_sd8787_probe,
  87. .remove = mmc_pwrseq_sd8787_remove,
  88. .driver = {
  89. .name = "pwrseq_sd8787",
  90. .of_match_table = mmc_pwrseq_sd8787_of_match,
  91. },
  92. };
  93. module_platform_driver(mmc_pwrseq_sd8787_driver);
  94. MODULE_LICENSE("GPL v2");