reset-light.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017, Impinj, Inc.
  4. *
  5. * i.MX7 System Reset Controller (SRC) driver
  6. *
  7. * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
  8. */
  9. #include <linux/mfd/syscon.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/reset-controller.h>
  14. #include <linux/regmap.h>
  15. #include <dt-bindings/reset/light-reset.h>
  16. struct light_src_signal {
  17. unsigned int offset, bit;
  18. };
  19. struct light_src_variant {
  20. const struct light_src_signal *signals;
  21. unsigned int signals_num;
  22. struct reset_control_ops ops;
  23. };
  24. struct light_src {
  25. struct reset_controller_dev rcdev;
  26. struct regmap *regmap;
  27. const struct light_src_signal *signals;
  28. };
  29. enum light_src_registers {
  30. SRC_WDT0 = 0x0034,
  31. SRC_WDT1 = 0x0038,
  32. };
  33. static int light_reset_update(struct light_src *lightsrc,
  34. unsigned long id, unsigned int value)
  35. {
  36. const struct light_src_signal *signal = &lightsrc->signals[id];
  37. return regmap_update_bits(lightsrc->regmap,
  38. signal->offset, signal->bit, value);
  39. }
  40. static const struct light_src_signal light_src_signals[] = {
  41. [LIGHT_RESET_WDT0] = { SRC_WDT0, BIT(0) },
  42. [LIGHT_RESET_WDT1] = { SRC_WDT1, BIT(0) },
  43. };
  44. static struct light_src *to_light_src(struct reset_controller_dev *rcdev)
  45. {
  46. return container_of(rcdev, struct light_src, rcdev);
  47. }
  48. static int light_reset_set(struct reset_controller_dev *rcdev,
  49. unsigned long id, bool assert)
  50. {
  51. struct light_src *lightsrc = to_light_src(rcdev);
  52. const unsigned int bit = lightsrc->signals[id].bit;
  53. unsigned int value = assert ? bit : 0;
  54. switch (id) {
  55. /*add special dispatch*/
  56. default:
  57. break;
  58. }
  59. return light_reset_update(lightsrc, id, value);
  60. }
  61. static int light_reset_assert(struct reset_controller_dev *rcdev,
  62. unsigned long id)
  63. {
  64. pr_info("%s id:%u\n",__func__,id);
  65. return light_reset_set(rcdev, id, false);
  66. }
  67. static int light_reset_deassert(struct reset_controller_dev *rcdev,
  68. unsigned long id)
  69. {
  70. pr_info("%s id:%u\n",__func__,id);
  71. return light_reset_set(rcdev, id, true);
  72. }
  73. static const struct light_src_variant variant_light = {
  74. .signals = light_src_signals,
  75. .signals_num = ARRAY_SIZE(light_src_signals),
  76. .ops = {
  77. .assert = light_reset_assert,
  78. .deassert = light_reset_deassert,
  79. },
  80. };
  81. static int light_reset_probe(struct platform_device *pdev)
  82. {
  83. struct light_src *lightsrc;
  84. struct device *dev = &pdev->dev;
  85. struct regmap_config config = { .name = "src" };
  86. const struct light_src_variant *variant = of_device_get_match_data(dev);
  87. lightsrc = devm_kzalloc(dev, sizeof(*lightsrc), GFP_KERNEL);
  88. if (!lightsrc)
  89. return -ENOMEM;
  90. lightsrc->signals = variant->signals;
  91. lightsrc->regmap = syscon_node_to_regmap(dev->of_node);
  92. if (IS_ERR(lightsrc->regmap)) {
  93. dev_err(dev, "Unable to get light-src regmap");
  94. return PTR_ERR(lightsrc->regmap);
  95. }
  96. regmap_attach_dev(dev, lightsrc->regmap, &config);
  97. lightsrc->rcdev.owner = THIS_MODULE;
  98. lightsrc->rcdev.nr_resets = variant->signals_num;
  99. lightsrc->rcdev.ops = &variant->ops;
  100. lightsrc->rcdev.of_node = dev->of_node;
  101. return devm_reset_controller_register(dev, &lightsrc->rcdev);
  102. }
  103. static const struct of_device_id light_reset_dt_ids[] = {
  104. { .compatible = "thead,light-reset-src", .data = &variant_light },
  105. };
  106. MODULE_DEVICE_TABLE(of, light_reset_dt_ids);
  107. static struct platform_driver light_reset_driver = {
  108. .probe = light_reset_probe,
  109. .driver = {
  110. .name = KBUILD_MODNAME,
  111. .of_match_table = light_reset_dt_ids,
  112. },
  113. };
  114. module_platform_driver(light_reset_driver);
  115. MODULE_AUTHOR("zenglinghui.zlh <zenglinghui.zlh@linux.alibaba.com>");
  116. MODULE_DESCRIPTION("Thead light reset driver");
  117. MODULE_LICENSE("GPL v2");