dma-sysfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/stat.h>
  15. #include <linux/sysdev.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/err.h>
  18. #include <linux/string.h>
  19. #include <asm/dma.h>
  20. static struct sysdev_class dma_sysclass = {
  21. .name = "dma",
  22. };
  23. static ssize_t dma_show_devices(struct sys_device *dev,
  24. struct sysdev_attribute *attr, 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,
  50. struct sysdev_attribute *attr, char *buf)
  51. {
  52. struct dma_channel *channel = to_dma_channel(dev);
  53. return sprintf(buf, "%s\n", channel->dev_id);
  54. }
  55. static ssize_t dma_store_dev_id(struct sys_device *dev,
  56. struct sysdev_attribute *attr,
  57. const char *buf, size_t count)
  58. {
  59. struct dma_channel *channel = to_dma_channel(dev);
  60. strcpy(channel->dev_id, buf);
  61. return count;
  62. }
  63. static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  64. static ssize_t dma_store_config(struct sys_device *dev,
  65. struct sysdev_attribute *attr,
  66. const char *buf, size_t count)
  67. {
  68. struct dma_channel *channel = to_dma_channel(dev);
  69. unsigned long config;
  70. config = simple_strtoul(buf, NULL, 0);
  71. dma_configure_channel(channel->vchan, config);
  72. return count;
  73. }
  74. static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
  75. static ssize_t dma_show_mode(struct sys_device *dev,
  76. struct sysdev_attribute *attr, char *buf)
  77. {
  78. struct dma_channel *channel = to_dma_channel(dev);
  79. return sprintf(buf, "0x%08x\n", channel->mode);
  80. }
  81. static ssize_t dma_store_mode(struct sys_device *dev,
  82. struct sysdev_attribute *attr,
  83. const char *buf, size_t count)
  84. {
  85. struct dma_channel *channel = to_dma_channel(dev);
  86. channel->mode = simple_strtoul(buf, NULL, 0);
  87. return count;
  88. }
  89. static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  90. #define dma_ro_attr(field, fmt) \
  91. static ssize_t dma_show_##field(struct sys_device *dev, \
  92. struct sysdev_attribute *attr, char *buf)\
  93. { \
  94. struct dma_channel *channel = to_dma_channel(dev); \
  95. return sprintf(buf, fmt, channel->field); \
  96. } \
  97. static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  98. dma_ro_attr(count, "0x%08x\n");
  99. dma_ro_attr(flags, "0x%08lx\n");
  100. int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  101. {
  102. struct sys_device *dev = &chan->dev;
  103. char name[16];
  104. int ret;
  105. dev->id = chan->vchan;
  106. dev->cls = &dma_sysclass;
  107. ret = sysdev_register(dev);
  108. if (ret)
  109. return ret;
  110. ret |= sysdev_create_file(dev, &attr_dev_id);
  111. ret |= sysdev_create_file(dev, &attr_count);
  112. ret |= sysdev_create_file(dev, &attr_mode);
  113. ret |= sysdev_create_file(dev, &attr_flags);
  114. ret |= sysdev_create_file(dev, &attr_config);
  115. if (unlikely(ret)) {
  116. dev_err(&info->pdev->dev, "Failed creating attrs\n");
  117. return ret;
  118. }
  119. snprintf(name, sizeof(name), "dma%d", chan->chan);
  120. return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
  121. }
  122. void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  123. {
  124. struct sys_device *dev = &chan->dev;
  125. char name[16];
  126. sysdev_remove_file(dev, &attr_dev_id);
  127. sysdev_remove_file(dev, &attr_count);
  128. sysdev_remove_file(dev, &attr_mode);
  129. sysdev_remove_file(dev, &attr_flags);
  130. sysdev_remove_file(dev, &attr_config);
  131. snprintf(name, sizeof(name), "dma%d", chan->chan);
  132. sysfs_remove_link(&info->pdev->dev.kobj, name);
  133. sysdev_unregister(dev);
  134. }