output.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/err.h>
  27. #include <linux/ctype.h>
  28. MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction");
  29. MODULE_LICENSE("GPL");
  30. MODULE_AUTHOR("Luming Yu <luming.yu@intel.com>");
  31. static ssize_t video_output_show_state(struct class_device *dev,char *buf)
  32. {
  33. ssize_t ret_size = 0;
  34. struct output_device *od = to_output_device(dev);
  35. if (od->props)
  36. ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
  37. return ret_size;
  38. }
  39. static ssize_t video_output_store_state(struct class_device *dev,
  40. const char *buf,size_t count)
  41. {
  42. char *endp;
  43. struct output_device *od = to_output_device(dev);
  44. int request_state = simple_strtoul(buf,&endp,0);
  45. size_t size = endp - buf;
  46. if (*endp && isspace(*endp))
  47. size++;
  48. if (size != count)
  49. return -EINVAL;
  50. if (od->props) {
  51. od->request_state = request_state;
  52. od->props->set_state(od);
  53. }
  54. return count;
  55. }
  56. static void video_output_class_release(struct class_device *dev)
  57. {
  58. struct output_device *od = to_output_device(dev);
  59. kfree(od);
  60. }
  61. static struct class_device_attribute video_output_attributes[] = {
  62. __ATTR(state, 0644, video_output_show_state, video_output_store_state),
  63. __ATTR_NULL,
  64. };
  65. static struct class video_output_class = {
  66. .name = "video_output",
  67. .release = video_output_class_release,
  68. .class_dev_attrs = video_output_attributes,
  69. };
  70. struct output_device *video_output_register(const char *name,
  71. struct device *dev,
  72. void *devdata,
  73. struct output_properties *op)
  74. {
  75. struct output_device *new_dev;
  76. int ret_code = 0;
  77. new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
  78. if (!new_dev) {
  79. ret_code = -ENOMEM;
  80. goto error_return;
  81. }
  82. new_dev->props = op;
  83. new_dev->class_dev.class = &video_output_class;
  84. new_dev->class_dev.dev = dev;
  85. strlcpy(new_dev->class_dev.class_id,name,KOBJ_NAME_LEN);
  86. class_set_devdata(&new_dev->class_dev,devdata);
  87. ret_code = class_device_register(&new_dev->class_dev);
  88. if (ret_code) {
  89. kfree(new_dev);
  90. goto error_return;
  91. }
  92. return new_dev;
  93. error_return:
  94. return ERR_PTR(ret_code);
  95. }
  96. EXPORT_SYMBOL(video_output_register);
  97. void video_output_unregister(struct output_device *dev)
  98. {
  99. if (!dev)
  100. return;
  101. class_device_unregister(&dev->class_dev);
  102. }
  103. EXPORT_SYMBOL(video_output_unregister);
  104. static void __exit video_output_class_exit(void)
  105. {
  106. class_unregister(&video_output_class);
  107. }
  108. static int __init video_output_class_init(void)
  109. {
  110. return class_register(&video_output_class);
  111. }
  112. postcore_initcall(video_output_class_init);
  113. module_exit(video_output_class_exit);