dma-sysfs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * arch/sh/drivers/dma/dma-sysfs.c
  3. *
  4. * sysfs interface for SH DMA API
  5. *
  6. * Copyright (C) 2004 - 2006 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/sysdev.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/module.h>
  17. #include <linux/err.h>
  18. #include <linux/string.h>
  19. #include <asm/dma.h>
  20. static struct sysdev_class dma_sysclass = {
  21. set_kset_name("dma"),
  22. };
  23. EXPORT_SYMBOL(dma_sysclass);
  24. static ssize_t dma_show_devices(struct sys_device *dev, char *buf)
  25. {
  26. ssize_t len = 0;
  27. int i;
  28. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  29. struct dma_info *info = get_dma_info(i);
  30. struct dma_channel *channel = get_dma_channel(i);
  31. if (unlikely(!info) || !channel)
  32. continue;
  33. len += sprintf(buf + len, "%2d: %14s %s\n",
  34. channel->chan, info->name,
  35. channel->dev_id);
  36. }
  37. return len;
  38. }
  39. static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
  40. static int __init dma_sysclass_init(void)
  41. {
  42. int ret;
  43. ret = sysdev_class_register(&dma_sysclass);
  44. if (unlikely(ret))
  45. return ret;
  46. return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
  47. }
  48. postcore_initcall(dma_sysclass_init);
  49. static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
  50. {
  51. struct dma_channel *channel = to_dma_channel(dev);
  52. return sprintf(buf, "%s\n", channel->dev_id);
  53. }
  54. static ssize_t dma_store_dev_id(struct sys_device *dev,
  55. const char *buf, size_t count)
  56. {
  57. struct dma_channel *channel = to_dma_channel(dev);
  58. strcpy(channel->dev_id, buf);
  59. return count;
  60. }
  61. static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  62. static ssize_t dma_store_config(struct sys_device *dev,
  63. const char *buf, size_t count)
  64. {
  65. struct dma_channel *channel = to_dma_channel(dev);
  66. unsigned long config;
  67. config = simple_strtoul(buf, NULL, 0);
  68. dma_configure_channel(channel->vchan, config);
  69. return count;
  70. }
  71. static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
  72. static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
  73. {
  74. struct dma_channel *channel = to_dma_channel(dev);
  75. return sprintf(buf, "0x%08x\n", channel->mode);
  76. }
  77. static ssize_t dma_store_mode(struct sys_device *dev,
  78. const char *buf, size_t count)
  79. {
  80. struct dma_channel *channel = to_dma_channel(dev);
  81. channel->mode = simple_strtoul(buf, NULL, 0);
  82. return count;
  83. }
  84. static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  85. #define dma_ro_attr(field, fmt) \
  86. static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
  87. { \
  88. struct dma_channel *channel = to_dma_channel(dev); \
  89. return sprintf(buf, fmt, channel->field); \
  90. } \
  91. static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  92. dma_ro_attr(count, "0x%08x\n");
  93. dma_ro_attr(flags, "0x%08lx\n");
  94. int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  95. {
  96. struct sys_device *dev = &chan->dev;
  97. char name[16];
  98. int ret;
  99. dev->id = chan->vchan;
  100. dev->cls = &dma_sysclass;
  101. ret = sysdev_register(dev);
  102. if (ret)
  103. return ret;
  104. ret |= sysdev_create_file(dev, &attr_dev_id);
  105. ret |= sysdev_create_file(dev, &attr_count);
  106. ret |= sysdev_create_file(dev, &attr_mode);
  107. ret |= sysdev_create_file(dev, &attr_flags);
  108. ret |= sysdev_create_file(dev, &attr_config);
  109. if (unlikely(ret)) {
  110. dev_err(&info->pdev->dev, "Failed creating attrs\n");
  111. return ret;
  112. }
  113. snprintf(name, sizeof(name), "dma%d", chan->chan);
  114. return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
  115. }
  116. void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  117. {
  118. struct sys_device *dev = &chan->dev;
  119. char name[16];
  120. sysdev_remove_file(dev, &attr_dev_id);
  121. sysdev_remove_file(dev, &attr_count);
  122. sysdev_remove_file(dev, &attr_mode);
  123. sysdev_remove_file(dev, &attr_flags);
  124. sysdev_remove_file(dev, &attr_config);
  125. snprintf(name, sizeof(name), "dma%d", chan->chan);
  126. sysfs_remove_link(&info->pdev->dev.kobj, name);
  127. sysdev_unregister(dev);
  128. }