dma-sysfs.c 3.1 KB

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