dma-sysfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/device.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 bus_type dma_subsys = {
  21. .name = "dma",
  22. .dev_name = "dma",
  23. };
  24. static ssize_t dma_show_devices(struct device *dev,
  25. struct device_attribute *attr, char *buf)
  26. {
  27. ssize_t len = 0;
  28. int i;
  29. for (i = 0; i < 16; i++) {
  30. struct dma_info *info = get_dma_info(i);
  31. struct dma_channel *channel = get_dma_channel(i);
  32. if (unlikely(!info) || !channel)
  33. continue;
  34. len += sprintf(buf + len, "%2d: %14s %s\n",
  35. channel->chan, info->name,
  36. channel->dev_id);
  37. }
  38. return len;
  39. }
  40. static DEVICE_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
  41. static int __init dma_subsys_init(void)
  42. {
  43. int ret;
  44. ret = subsys_system_register(&dma_subsys, NULL);
  45. if (unlikely(ret))
  46. return ret;
  47. return device_create_file(dma_subsys.dev_root, &dev_attr_devices);
  48. }
  49. postcore_initcall(dma_subsys_init);
  50. static ssize_t dma_show_dev_id(struct device *dev,
  51. struct device_attribute *attr, char *buf)
  52. {
  53. struct dma_channel *channel = to_dma_channel(dev);
  54. return sprintf(buf, "%s\n", channel->dev_id);
  55. }
  56. static ssize_t dma_store_dev_id(struct device *dev,
  57. struct device_attribute *attr,
  58. const char *buf, size_t count)
  59. {
  60. struct dma_channel *channel = to_dma_channel(dev);
  61. strcpy(channel->dev_id, buf);
  62. return count;
  63. }
  64. static DEVICE_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  65. static ssize_t dma_store_config(struct device *dev,
  66. struct device_attribute *attr,
  67. const char *buf, size_t count)
  68. {
  69. struct dma_channel *channel = to_dma_channel(dev);
  70. unsigned long config;
  71. config = simple_strtoul(buf, NULL, 0);
  72. dma_configure_channel(channel->vchan, config);
  73. return count;
  74. }
  75. static DEVICE_ATTR(config, S_IWUSR, NULL, dma_store_config);
  76. static ssize_t dma_show_mode(struct device *dev,
  77. struct device_attribute *attr, char *buf)
  78. {
  79. struct dma_channel *channel = to_dma_channel(dev);
  80. return sprintf(buf, "0x%08x\n", channel->mode);
  81. }
  82. static ssize_t dma_store_mode(struct device *dev,
  83. struct device_attribute *attr,
  84. const char *buf, size_t count)
  85. {
  86. struct dma_channel *channel = to_dma_channel(dev);
  87. channel->mode = simple_strtoul(buf, NULL, 0);
  88. return count;
  89. }
  90. static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  91. #define dma_ro_attr(field, fmt) \
  92. static ssize_t dma_show_##field(struct device *dev, \
  93. struct device_attribute *attr, char *buf)\
  94. { \
  95. struct dma_channel *channel = to_dma_channel(dev); \
  96. return sprintf(buf, fmt, channel->field); \
  97. } \
  98. static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  99. dma_ro_attr(count, "0x%08x\n");
  100. dma_ro_attr(flags, "0x%08lx\n");
  101. int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  102. {
  103. struct device *dev = &chan->dev;
  104. char name[16];
  105. int ret;
  106. dev->id = chan->vchan;
  107. dev->bus = &dma_subsys;
  108. ret = device_register(dev);
  109. if (ret)
  110. return ret;
  111. ret |= device_create_file(dev, &dev_attr_dev_id);
  112. ret |= device_create_file(dev, &dev_attr_count);
  113. ret |= device_create_file(dev, &dev_attr_mode);
  114. ret |= device_create_file(dev, &dev_attr_flags);
  115. ret |= device_create_file(dev, &dev_attr_config);
  116. if (unlikely(ret)) {
  117. dev_err(&info->pdev->dev, "Failed creating attrs\n");
  118. return ret;
  119. }
  120. snprintf(name, sizeof(name), "dma%d", chan->chan);
  121. return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
  122. }
  123. void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  124. {
  125. struct device *dev = &chan->dev;
  126. char name[16];
  127. device_remove_file(dev, &dev_attr_dev_id);
  128. device_remove_file(dev, &dev_attr_count);
  129. device_remove_file(dev, &dev_attr_mode);
  130. device_remove_file(dev, &dev_attr_flags);
  131. device_remove_file(dev, &dev_attr_config);
  132. snprintf(name, sizeof(name), "dma%d", chan->chan);
  133. sysfs_remove_link(&info->pdev->dev.kobj, name);
  134. device_unregister(dev);
  135. }