dma-sysfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * arch/sh/drivers/dma/dma-sysfs.c
  3. *
  4. * sysfs interface for SH DMA API
  5. *
  6. * Copyright (C) 2004 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/module.h>
  16. #include <linux/string.h>
  17. #include <asm/dma.h>
  18. static struct sysdev_class dma_sysclass = {
  19. set_kset_name("dma"),
  20. };
  21. EXPORT_SYMBOL(dma_sysclass);
  22. static ssize_t dma_show_devices(struct sys_device *dev, char *buf)
  23. {
  24. ssize_t len = 0;
  25. int i;
  26. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  27. struct dma_info *info = get_dma_info(i);
  28. struct dma_channel *channel = &info->channels[i];
  29. len += sprintf(buf + len, "%2d: %14s %s\n",
  30. channel->chan, info->name,
  31. channel->dev_id);
  32. }
  33. return len;
  34. }
  35. static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
  36. static int __init dma_sysclass_init(void)
  37. {
  38. int ret;
  39. ret = sysdev_class_register(&dma_sysclass);
  40. if (ret == 0)
  41. sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
  42. return ret;
  43. }
  44. postcore_initcall(dma_sysclass_init);
  45. static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
  46. {
  47. struct dma_channel *channel = to_dma_channel(dev);
  48. return sprintf(buf, "%s\n", channel->dev_id);
  49. }
  50. static ssize_t dma_store_dev_id(struct sys_device *dev,
  51. const char *buf, size_t count)
  52. {
  53. struct dma_channel *channel = to_dma_channel(dev);
  54. strcpy(channel->dev_id, buf);
  55. return count;
  56. }
  57. static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
  58. static ssize_t dma_store_config(struct sys_device *dev,
  59. const char *buf, size_t count)
  60. {
  61. struct dma_channel *channel = to_dma_channel(dev);
  62. unsigned long config;
  63. config = simple_strtoul(buf, NULL, 0);
  64. dma_configure_channel(channel->chan, config);
  65. return count;
  66. }
  67. static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
  68. static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
  69. {
  70. struct dma_channel *channel = to_dma_channel(dev);
  71. return sprintf(buf, "0x%08x\n", channel->mode);
  72. }
  73. static ssize_t dma_store_mode(struct sys_device *dev,
  74. const char *buf, size_t count)
  75. {
  76. struct dma_channel *channel = to_dma_channel(dev);
  77. channel->mode = simple_strtoul(buf, NULL, 0);
  78. return count;
  79. }
  80. static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
  81. #define dma_ro_attr(field, fmt) \
  82. static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
  83. { \
  84. struct dma_channel *channel = to_dma_channel(dev); \
  85. return sprintf(buf, fmt, channel->field); \
  86. } \
  87. static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
  88. dma_ro_attr(count, "0x%08x\n");
  89. dma_ro_attr(flags, "0x%08lx\n");
  90. int __init dma_create_sysfs_files(struct dma_channel *chan)
  91. {
  92. struct sys_device *dev = &chan->dev;
  93. int ret;
  94. dev->id = chan->chan;
  95. dev->cls = &dma_sysclass;
  96. ret = sysdev_register(dev);
  97. if (ret)
  98. return ret;
  99. sysdev_create_file(dev, &attr_dev_id);
  100. sysdev_create_file(dev, &attr_count);
  101. sysdev_create_file(dev, &attr_mode);
  102. sysdev_create_file(dev, &attr_flags);
  103. sysdev_create_file(dev, &attr_config);
  104. return 0;
  105. }