reset-oxnas.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. { .compatible = "oxsemi,ox820-reset", },
  71. { /* sentinel */ },
  72. };
  73. MODULE_DEVICE_TABLE(of, oxnas_reset_dt_ids);
  74. static int oxnas_reset_probe(struct platform_device *pdev)
  75. {
  76. struct oxnas_reset *data;
  77. struct device *parent;
  78. parent = pdev->dev.parent;
  79. if (!parent) {
  80. dev_err(&pdev->dev, "no parent\n");
  81. return -ENODEV;
  82. }
  83. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  84. if (!data)
  85. return -ENOMEM;
  86. data->regmap = syscon_node_to_regmap(parent->of_node);
  87. if (IS_ERR(data->regmap)) {
  88. dev_err(&pdev->dev, "failed to get parent regmap\n");
  89. return PTR_ERR(data->regmap);
  90. }
  91. platform_set_drvdata(pdev, data);
  92. data->rcdev.owner = THIS_MODULE;
  93. data->rcdev.nr_resets = 32;
  94. data->rcdev.ops = &oxnas_reset_ops;
  95. data->rcdev.of_node = pdev->dev.of_node;
  96. return devm_reset_controller_register(&pdev->dev, &data->rcdev);
  97. }
  98. static struct platform_driver oxnas_reset_driver = {
  99. .probe = oxnas_reset_probe,
  100. .driver = {
  101. .name = "oxnas-reset",
  102. .of_match_table = oxnas_reset_dt_ids,
  103. },
  104. };
  105. module_platform_driver(oxnas_reset_driver);