/arch/sh/drivers/dma/dma-sysfs.c

https://bitbucket.org/cresqo/cm7-p500-kernel · C · 165 lines · 122 code · 32 blank · 11 comment · 6 complexity · 3c0f38f038106305206d63d8697c812c MD5 · raw file

  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/err.h>
  17. #include <linux/string.h>
  18. #include <asm/dma.h>
  19. static struct sysdev_class dma_sysclass = {
  20. .name = "dma",
  21. };
  22. static ssize_t dma_show_devices(struct sys_device *dev,
  23. struct sysdev_attribute *attr, char *buf)
  24. {
  25. ssize_t len = 0;
  26. int i;
  27. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  28. struct dma_info *info = get_dma_info(i);
  29. struct dma_channel *channel = get_dma_channel(i);
  30. if (unlikely(!info) || !channel)
  31. continue;
  32. len += sprintf(buf + len, "%2d: %14s %s\n",
  33. channel->chan, info->name,
  34. channel->dev_id);
  35. }
  36. return len;
  37. }
  38. static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
  39. static int __init dma_sysclass_init(void)
  40. {
  41. int ret;
  42. ret = sysdev_class_register(&dma_sysclass);
  43. if (unlikely(ret))
  44. return ret;
  45. return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
  46. }
  47. postcore_initcall(dma_sysclass_init);
  48. static ssize_t dma_show_dev_id(struct sys_device *dev,
  49. struct sysdev_attribute *attr, 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. struct sysdev_attribute *attr,
  56. const char *buf, size_t count)
  57. {
  58. struct dma_channel *channel = to_dma_channel(dev);
  59. strcpy(channel->dev_id, buf);
  60. return count;
  61. }
  62. static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  63. static ssize_t dma_store_config(struct sys_device *dev,
  64. struct sysdev_attribute *attr,
  65. const char *buf, size_t count)
  66. {
  67. struct dma_channel *channel = to_dma_channel(dev);
  68. unsigned long config;
  69. config = simple_strtoul(buf, NULL, 0);
  70. dma_configure_channel(channel->vchan, config);
  71. return count;
  72. }
  73. static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
  74. static ssize_t dma_show_mode(struct sys_device *dev,
  75. struct sysdev_attribute *attr, char *buf)
  76. {
  77. struct dma_channel *channel = to_dma_channel(dev);
  78. return sprintf(buf, "0x%08x\n", channel->mode);
  79. }
  80. static ssize_t dma_store_mode(struct sys_device *dev,
  81. struct sysdev_attribute *attr,
  82. const char *buf, size_t count)
  83. {
  84. struct dma_channel *channel = to_dma_channel(dev);
  85. channel->mode = simple_strtoul(buf, NULL, 0);
  86. return count;
  87. }
  88. static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  89. #define dma_ro_attr(field, fmt) \
  90. static ssize_t dma_show_##field(struct sys_device *dev, \
  91. struct sysdev_attribute *attr, char *buf)\
  92. { \
  93. struct dma_channel *channel = to_dma_channel(dev); \
  94. return sprintf(buf, fmt, channel->field); \
  95. } \
  96. static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  97. dma_ro_attr(count, "0x%08x\n");
  98. dma_ro_attr(flags, "0x%08lx\n");
  99. int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  100. {
  101. struct sys_device *dev = &chan->dev;
  102. char name[16];
  103. int ret;
  104. dev->id = chan->vchan;
  105. dev->cls = &dma_sysclass;
  106. ret = sysdev_register(dev);
  107. if (ret)
  108. return ret;
  109. ret |= sysdev_create_file(dev, &attr_dev_id);
  110. ret |= sysdev_create_file(dev, &attr_count);
  111. ret |= sysdev_create_file(dev, &attr_mode);
  112. ret |= sysdev_create_file(dev, &attr_flags);
  113. ret |= sysdev_create_file(dev, &attr_config);
  114. if (unlikely(ret)) {
  115. dev_err(&info->pdev->dev, "Failed creating attrs\n");
  116. return ret;
  117. }
  118. snprintf(name, sizeof(name), "dma%d", chan->chan);
  119. return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
  120. }
  121. void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  122. {
  123. struct sys_device *dev = &chan->dev;
  124. char name[16];
  125. sysdev_remove_file(dev, &attr_dev_id);
  126. sysdev_remove_file(dev, &attr_count);
  127. sysdev_remove_file(dev, &attr_mode);
  128. sysdev_remove_file(dev, &attr_flags);
  129. sysdev_remove_file(dev, &attr_config);
  130. snprintf(name, sizeof(name), "dma%d", chan->chan);
  131. sysfs_remove_link(&info->pdev->dev.kobj, name);
  132. sysdev_unregister(dev);
  133. }