reset-oxnas.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * drivers/reset/reset-oxnas.c
  3. *
  4. * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
  5. * Copyright (C) 2014 Ma Haijun <mahaijuns@gmail.com>
  6. * Copyright (C) 2009 Oxford Semiconductor Ltd
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/module.h>
  22. #include <linux/of.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/reset-controller.h>
  25. #include <linux/slab.h>
  26. #include <linux/delay.h>
  27. #include <linux/types.h>
  28. #include <linux/regmap.h>
  29. #include <linux/mfd/syscon.h>
  30. /* Regmap offsets */
  31. #define RST_SET_REGOFFSET 0x34
  32. #define RST_CLR_REGOFFSET 0x38
  33. struct oxnas_reset {
  34. struct regmap *regmap;
  35. struct reset_controller_dev rcdev;
  36. };
  37. static int oxnas_reset_reset(struct reset_controller_dev *rcdev,
  38. unsigned long id)
  39. {
  40. struct oxnas_reset *data =
  41. container_of(rcdev, struct oxnas_reset, rcdev);
  42. regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
  43. msleep(50);
  44. regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
  45. return 0;
  46. }
  47. static int oxnas_reset_assert(struct reset_controller_dev *rcdev,
  48. unsigned long id)
  49. {
  50. struct oxnas_reset *data =
  51. container_of(rcdev, struct oxnas_reset, rcdev);
  52. regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
  53. return 0;
  54. }
  55. static int oxnas_reset_deassert(struct reset_controller_dev *rcdev,
  56. unsigned long id)
  57. {
  58. struct oxnas_reset *data =
  59. container_of(rcdev, struct oxnas_reset, rcdev);
  60. regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
  61. return 0;
  62. }
  63. static const struct reset_control_ops oxnas_reset_ops = {
  64. .reset = oxnas_reset_reset,
  65. .assert = oxnas_reset_assert,
  66. .deassert = oxnas_reset_deassert,
  67. };
  68. static const struct of_device_id oxnas_reset_dt_ids[] = {
  69. { .compatible = "oxsemi,ox810se-reset", },
  70. { /* sentinel */ },
  71. };
  72. MODULE_DEVICE_TABLE(of, oxnas_reset_dt_ids);
  73. static int oxnas_reset_probe(struct platform_device *pdev)
  74. {
  75. struct oxnas_reset *data;
  76. struct device *parent;
  77. parent = pdev->dev.parent;
  78. if (!parent) {
  79. dev_err(&pdev->dev, "no parent\n");
  80. return -ENODEV;
  81. }
  82. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  83. if (!data)
  84. return -ENOMEM;
  85. data->regmap = syscon_node_to_regmap(parent->of_node);
  86. if (IS_ERR(data->regmap)) {
  87. dev_err(&pdev->dev, "failed to get parent regmap\n");
  88. return PTR_ERR(data->regmap);
  89. }
  90. platform_set_drvdata(pdev, data);
  91. data->rcdev.owner = THIS_MODULE;
  92. data->rcdev.nr_resets = 32;
  93. data->rcdev.ops = &oxnas_reset_ops;
  94. data->rcdev.of_node = pdev->dev.of_node;
  95. return devm_reset_controller_register(&pdev->dev, &data->rcdev);
  96. }
  97. static struct platform_driver oxnas_reset_driver = {
  98. .probe = oxnas_reset_probe,
  99. .driver = {
  100. .name = "oxnas-reset",
  101. .of_match_table = oxnas_reset_dt_ids,
  102. },
  103. };
  104. module_platform_driver(oxnas_reset_driver);