dma-sysfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * arch/sh/drivers/dma/dma-sysfs.c
  3. *
  4. * sysfs interface for SH DMA API
  5. *
  6. * Copyright (C) 2004, 2005 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 = &info->channels[i];
  31. len += sprintf(buf + len, "%2d: %14s %s\n",
  32. channel->chan, info->name,
  33. channel->dev_id);
  34. }
  35. return len;
  36. }
  37. static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
  38. static int __init dma_sysclass_init(void)
  39. {
  40. int ret;
  41. ret = sysdev_class_register(&dma_sysclass);
  42. if (unlikely(ret))
  43. return ret;
  44. return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
  45. }
  46. postcore_initcall(dma_sysclass_init);
  47. static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
  48. {
  49. struct dma_channel *channel = to_dma_channel(dev);
  50. return sprintf(buf, "%s\n", channel->dev_id);
  51. }
  52. static ssize_t dma_store_dev_id(struct sys_device *dev,
  53. const char *buf, size_t count)
  54. {
  55. struct dma_channel *channel = to_dma_channel(dev);
  56. strcpy(channel->dev_id, buf);
  57. return count;
  58. }
  59. static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  60. static ssize_t dma_store_config(struct sys_device *dev,
  61. const char *buf, size_t count)
  62. {
  63. struct dma_channel *channel = to_dma_channel(dev);
  64. unsigned long config;
  65. config = simple_strtoul(buf, NULL, 0);
  66. dma_configure_channel(channel->vchan, config);
  67. return count;
  68. }
  69. static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
  70. static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
  71. {
  72. struct dma_channel *channel = to_dma_channel(dev);
  73. return sprintf(buf, "0x%08x\n", channel->mode);
  74. }
  75. static ssize_t dma_store_mode(struct sys_device *dev,
  76. const char *buf, size_t count)
  77. {
  78. struct dma_channel *channel = to_dma_channel(dev);
  79. channel->mode = simple_strtoul(buf, NULL, 0);
  80. return count;
  81. }
  82. static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  83. #define dma_ro_attr(field, fmt) \
  84. static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
  85. { \
  86. struct dma_channel *channel = to_dma_channel(dev); \
  87. return sprintf(buf, fmt, channel->field); \
  88. } \
  89. static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  90. dma_ro_attr(count, "0x%08x\n");
  91. dma_ro_attr(flags, "0x%08lx\n");
  92. int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  93. {
  94. struct sys_device *dev = &chan->dev;
  95. char name[16];
  96. int ret;
  97. dev->id = chan->vchan;
  98. dev->cls = &dma_sysclass;
  99. ret = sysdev_register(dev);
  100. if (ret)
  101. return ret;
  102. sysdev_create_file(dev, &attr_dev_id);
  103. sysdev_create_file(dev, &attr_count);
  104. sysdev_create_file(dev, &attr_mode);
  105. sysdev_create_file(dev, &attr_flags);
  106. sysdev_create_file(dev, &attr_config);
  107. snprintf(name, sizeof(name), "dma%d", chan->chan);
  108. return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
  109. }
  110. void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
  111. {
  112. struct sys_device *dev = &chan->dev;
  113. char name[16];
  114. sysdev_remove_file(dev, &attr_dev_id);
  115. sysdev_remove_file(dev, &attr_count);
  116. sysdev_remove_file(dev, &attr_mode);
  117. sysdev_remove_file(dev, &attr_flags);
  118. sysdev_remove_file(dev, &attr_config);
  119. snprintf(name, sizeof(name), "dma%d", chan->chan);
  120. sysfs_remove_link(&info->pdev->dev.kobj, name);
  121. sysdev_unregister(dev);
  122. }