output.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * output.c - Display Output Switch driver
  3. *
  4. * Copyright (C) 2006 Luming Yu <luming.yu@intel.com>
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. #include <linux/module.h>
  25. #include <linux/video_output.h>
  26. #include <linux/slab.h>
  27. #include <linux/err.h>
  28. #include <linux/ctype.h>
  29. MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction");
  30. MODULE_LICENSE("GPL");
  31. MODULE_AUTHOR("Luming Yu <luming.yu@intel.com>");
  32. static ssize_t video_output_show_state(struct device *dev,
  33. struct device_attribute *attr, char *buf)
  34. {
  35. ssize_t ret_size = 0;
  36. struct output_device *od = to_output_device(dev);
  37. if (od->props)
  38. ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
  39. return ret_size;
  40. }
  41. static ssize_t video_output_store_state(struct device *dev,
  42. struct device_attribute *attr,
  43. const char *buf,size_t count)
  44. {
  45. char *endp;
  46. struct output_device *od = to_output_device(dev);
  47. int request_state = simple_strtoul(buf,&endp,0);
  48. size_t size = endp - buf;
  49. if (isspace(*endp))
  50. size++;
  51. if (size != count)
  52. return -EINVAL;
  53. if (od->props) {
  54. od->request_state = request_state;
  55. od->props->set_state(od);
  56. }
  57. return count;
  58. }
  59. static void video_output_release(struct device *dev)
  60. {
  61. struct output_device *od = to_output_device(dev);
  62. kfree(od);
  63. }
  64. static struct device_attribute video_output_attributes[] = {
  65. __ATTR(state, 0644, video_output_show_state, video_output_store_state),
  66. __ATTR_NULL,
  67. };
  68. static struct class video_output_class = {
  69. .name = "video_output",
  70. .dev_release = video_output_release,
  71. .dev_attrs = video_output_attributes,
  72. };
  73. struct output_device *video_output_register(const char *name,
  74. struct device *dev,
  75. void *devdata,
  76. struct output_properties *op)
  77. {
  78. struct output_device *new_dev;
  79. int ret_code = 0;
  80. new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
  81. if (!new_dev) {
  82. ret_code = -ENOMEM;
  83. goto error_return;
  84. }
  85. new_dev->props = op;
  86. new_dev->dev.class = &video_output_class;
  87. new_dev->dev.parent = dev;
  88. dev_set_name(&new_dev->dev, name);
  89. dev_set_drvdata(&new_dev->dev, devdata);
  90. ret_code = device_register(&new_dev->dev);
  91. if (ret_code) {
  92. kfree(new_dev);
  93. goto error_return;
  94. }
  95. return new_dev;
  96. error_return:
  97. return ERR_PTR(ret_code);
  98. }
  99. EXPORT_SYMBOL(video_output_register);
  100. void video_output_unregister(struct output_device *dev)
  101. {
  102. if (!dev)
  103. return;
  104. device_unregister(&dev->dev);
  105. }
  106. EXPORT_SYMBOL(video_output_unregister);
  107. static void __exit video_output_class_exit(void)
  108. {
  109. class_unregister(&video_output_class);
  110. }
  111. static int __init video_output_class_init(void)
  112. {
  113. return class_register(&video_output_class);
  114. }
  115. postcore_initcall(video_output_class_init);
  116. module_exit(video_output_class_exit);