ptp_qoriq_debugfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Copyright 2019 NXP
  3. */
  4. #include <linux/device.h>
  5. #include <linux/debugfs.h>
  6. #include <linux/fsl/ptp_qoriq.h>
  7. static int ptp_qoriq_fiper1_lpbk_get(void *data, u64 *val)
  8. {
  9. struct ptp_qoriq *ptp_qoriq = data;
  10. struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
  11. u32 ctrl;
  12. ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
  13. *val = ctrl & PP1L ? 1 : 0;
  14. return 0;
  15. }
  16. static int ptp_qoriq_fiper1_lpbk_set(void *data, u64 val)
  17. {
  18. struct ptp_qoriq *ptp_qoriq = data;
  19. struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
  20. u32 ctrl;
  21. ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
  22. if (val == 0)
  23. ctrl &= ~PP1L;
  24. else
  25. ctrl |= PP1L;
  26. ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
  27. return 0;
  28. }
  29. DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper1_fops, ptp_qoriq_fiper1_lpbk_get,
  30. ptp_qoriq_fiper1_lpbk_set, "%llu\n");
  31. static int ptp_qoriq_fiper2_lpbk_get(void *data, u64 *val)
  32. {
  33. struct ptp_qoriq *ptp_qoriq = data;
  34. struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
  35. u32 ctrl;
  36. ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
  37. *val = ctrl & PP2L ? 1 : 0;
  38. return 0;
  39. }
  40. static int ptp_qoriq_fiper2_lpbk_set(void *data, u64 val)
  41. {
  42. struct ptp_qoriq *ptp_qoriq = data;
  43. struct ptp_qoriq_registers *regs = &ptp_qoriq->regs;
  44. u32 ctrl;
  45. ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl);
  46. if (val == 0)
  47. ctrl &= ~PP2L;
  48. else
  49. ctrl |= PP2L;
  50. ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl);
  51. return 0;
  52. }
  53. DEFINE_DEBUGFS_ATTRIBUTE(ptp_qoriq_fiper2_fops, ptp_qoriq_fiper2_lpbk_get,
  54. ptp_qoriq_fiper2_lpbk_set, "%llu\n");
  55. void ptp_qoriq_create_debugfs(struct ptp_qoriq *ptp_qoriq)
  56. {
  57. struct dentry *root;
  58. root = debugfs_create_dir(dev_name(ptp_qoriq->dev), NULL);
  59. if (IS_ERR(root))
  60. return;
  61. if (!root)
  62. goto err_root;
  63. ptp_qoriq->debugfs_root = root;
  64. if (!debugfs_create_file_unsafe("fiper1-loopback", 0600, root,
  65. ptp_qoriq, &ptp_qoriq_fiper1_fops))
  66. goto err_node;
  67. if (!debugfs_create_file_unsafe("fiper2-loopback", 0600, root,
  68. ptp_qoriq, &ptp_qoriq_fiper2_fops))
  69. goto err_node;
  70. return;
  71. err_node:
  72. debugfs_remove_recursive(root);
  73. ptp_qoriq->debugfs_root = NULL;
  74. err_root:
  75. dev_err(ptp_qoriq->dev, "failed to initialize debugfs\n");
  76. }
  77. void ptp_qoriq_remove_debugfs(struct ptp_qoriq *ptp_qoriq)
  78. {
  79. debugfs_remove_recursive(ptp_qoriq->debugfs_root);
  80. ptp_qoriq->debugfs_root = NULL;
  81. }