xhci-mtk-attrs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <linux/kobject.h>
  2. #include <linux/string.h>
  3. #include <linux/sysfs.h>
  4. #include <xhci.h>
  5. #include "xhci-mtk-driver.h"
  6. /* ///////////////////////////////////////////////////////////////////////// */
  7. /* interrupt moderation */
  8. /* ///////////////////////////////////////////////////////////////////////// */
  9. static unsigned int imod; /* attribute for Interrupt moderation register */
  10. /*
  11. * show the value of imod.
  12. */
  13. static ssize_t imod_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
  14. {
  15. imod = readl((void __iomem *)&mtk_xhci->ir_set->irq_control);
  16. imod &= ~0xFFFF0000;
  17. return sprintf(buf, "0x%x\n", imod);
  18. }
  19. /*
  20. * write the value to imod and config hardware.
  21. */
  22. static ssize_t imod_store(struct kobject *kobj, struct kobj_attribute *attr,
  23. const char *buf, size_t count)
  24. {
  25. u32 temp;
  26. if (sscanf(buf, "%xu", &imod) != 1)
  27. return 0;
  28. temp = readl((void __iomem *)&mtk_xhci->ir_set->irq_control);
  29. temp &= ~0xFFFF;
  30. temp |= imod;
  31. writel(temp, (void __iomem *)&mtk_xhci->ir_set->irq_control);
  32. return count;
  33. }
  34. static struct kobj_attribute imod_attribute = __ATTR(imod, 0660, imod_show, imod_store);
  35. /* ///////////////////////////////////////////////////////////////////////// */
  36. /* DMA burst */
  37. /* ///////////////////////////////////////////////////////////////////////// */
  38. static unsigned int dburst; /* attribute for Interrupt moderation register */
  39. /*
  40. * show the value of dburst.
  41. */
  42. static ssize_t dburst_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
  43. {
  44. dburst = readl((void __iomem *)_SSUSB_XHCI_HDMA_CFG(mtk_xhci->base_regs));
  45. return sprintf(buf, "0x%x\n", dburst);
  46. }
  47. /*
  48. * write the value to dburst and config hardware.
  49. */
  50. static ssize_t dburst_store(struct kobject *kobj, struct kobj_attribute *attr,
  51. const char *buf, size_t count)
  52. {
  53. u32 temp;
  54. if (sscanf(buf, "%xu", &dburst) != 1)
  55. return 0;
  56. /* This register configures the maximum burst size per DMA request to DRAM bus. */
  57. temp = readl((void __iomem *)_SSUSB_XHCI_HDMA_CFG(mtk_xhci->base_regs));
  58. /* clear dma r/w fields */
  59. temp &= ~0x0C0C;
  60. /* set r/w burst size */
  61. temp |= (dburst << 2 | dburst << 10);
  62. writel(temp, (void __iomem *)_SSUSB_XHCI_HDMA_CFG(mtk_xhci->base_regs));
  63. return count;
  64. }
  65. static struct kobj_attribute dburst_attribute = __ATTR(dburst, 0660, dburst_show, dburst_store);
  66. /*
  67. * Create a group of attributes so that we can create and destroy them all
  68. * at once.
  69. */
  70. static struct attribute *attrs[] = {
  71. &imod_attribute.attr,
  72. &dburst_attribute.attr,
  73. NULL, /* need to NULL terminate the list of attributes */
  74. };
  75. /*
  76. * An unnamed attribute group will put all of the attributes directly in
  77. * the kobject directory. If we specify a name, a subdirectory will be
  78. * created for the attributes with the directory being the name of the
  79. * attribute group.
  80. */
  81. static struct attribute_group attr_group = {
  82. .attrs = attrs,
  83. };
  84. static struct kobject *xhci_attrs_kobj;
  85. int xhci_attrs_init(void)
  86. {
  87. int retval;
  88. /*
  89. * Create a simple kobject with the name of "xhci",
  90. * located under /sys/kernel/
  91. *
  92. */
  93. xhci_attrs_kobj = kobject_create_and_add("xhci", kernel_kobj);
  94. if (!xhci_attrs_kobj)
  95. return -ENOMEM;
  96. /* Create the files associated with this kobject */
  97. retval = sysfs_create_group(xhci_attrs_kobj, &attr_group);
  98. if (retval)
  99. kobject_put(xhci_attrs_kobj);
  100. return retval;
  101. }
  102. void xhci_attrs_exit(void)
  103. {
  104. kobject_put(xhci_attrs_kobj);
  105. }