reset-ox820.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. */
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/reset-controller.h>
  13. #include <linux/slab.h>
  14. #include <linux/types.h>
  15. #include <mach/hardware.h>
  16. static int ox820_reset_reset(struct reset_controller_dev *rcdev,
  17. unsigned long id)
  18. {
  19. writel(BIT(id), SYS_CTRL_RST_SET_CTRL);
  20. writel(BIT(id), SYS_CTRL_RST_CLR_CTRL);
  21. return 0;
  22. }
  23. static int ox820_reset_assert(struct reset_controller_dev *rcdev,
  24. unsigned long id)
  25. {
  26. writel(BIT(id), SYS_CTRL_RST_SET_CTRL);
  27. return 0;
  28. }
  29. static int ox820_reset_deassert(struct reset_controller_dev *rcdev,
  30. unsigned long id)
  31. {
  32. writel(BIT(id), SYS_CTRL_RST_CLR_CTRL);
  33. return 0;
  34. }
  35. static struct reset_control_ops ox820_reset_ops = {
  36. .reset = ox820_reset_reset,
  37. .assert = ox820_reset_assert,
  38. .deassert = ox820_reset_deassert,
  39. };
  40. static const struct of_device_id ox820_reset_dt_ids[] = {
  41. { .compatible = "plxtech,nas782x-reset", },
  42. { /* sentinel */ },
  43. };
  44. MODULE_DEVICE_TABLE(of, ox820_reset_dt_ids);
  45. struct reset_controller_dev rcdev;
  46. static int ox820_reset_probe(struct platform_device *pdev)
  47. {
  48. struct reset_controller_dev *rcdev;
  49. rcdev = devm_kzalloc(&pdev->dev, sizeof(*rcdev), GFP_KERNEL);
  50. if (!rcdev)
  51. return -ENOMEM;
  52. /* note: reset controller is statically mapped */
  53. rcdev->owner = THIS_MODULE;
  54. rcdev->nr_resets = 32;
  55. rcdev->ops = &ox820_reset_ops;
  56. rcdev->of_node = pdev->dev.of_node;
  57. reset_controller_register(rcdev);
  58. platform_set_drvdata(pdev, rcdev);
  59. return 0;
  60. }
  61. static int ox820_reset_remove(struct platform_device *pdev)
  62. {
  63. struct reset_controller_dev *rcdev = platform_get_drvdata(pdev);
  64. reset_controller_unregister(rcdev);
  65. return 0;
  66. }
  67. static struct platform_driver ox820_reset_driver = {
  68. .probe = ox820_reset_probe,
  69. .remove = ox820_reset_remove,
  70. .driver = {
  71. .name = "ox820-reset",
  72. .owner = THIS_MODULE,
  73. .of_match_table = ox820_reset_dt_ids,
  74. },
  75. };
  76. static int __init ox820_reset_init(void)
  77. {
  78. return platform_driver_probe(&ox820_reset_driver,
  79. ox820_reset_probe);
  80. }
  81. /*
  82. * reset controller does not support probe deferral, so it has to be
  83. * initialized before any user, in particular, PCIE uses subsys_initcall.
  84. */
  85. arch_initcall(ox820_reset_init);
  86. MODULE_AUTHOR("Ma Haijun");
  87. MODULE_LICENSE("GPL");