output.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 device *dev,
  32. struct device_attribute *attr, char *buf)
  33. {
  34. ssize_t ret_size = 0;
  35. struct output_device *od = to_output_device(dev);
  36. if (od->props)
  37. ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
  38. return ret_size;
  39. }
  40. static ssize_t video_output_store_state(struct device *dev,
  41. struct device_attribute *attr,
  42. const char *buf,size_t count)
  43. {
  44. char *endp;
  45. struct output_device *od = to_output_device(dev);
  46. int request_state = simple_strtoul(buf,&endp,0);
  47. size_t size = endp - buf;
  48. if (*endp && isspace(*endp))
  49. size++;
  50. if (size != count)
  51. return -EINVAL;
  52. if (od->props) {
  53. od->request_state = request_state;
  54. od->props->set_state(od);
  55. }
  56. return count;
  57. }
  58. static void video_output_release(struct device *dev)
  59. {
  60. struct output_device *od = to_output_device(dev);
  61. kfree(od);
  62. }
  63. static struct device_attribute video_output_attributes[] = {
  64. __ATTR(state, 0644, video_output_show_state, video_output_store_state),
  65. __ATTR_NULL,
  66. };
  67. static struct class video_output_class = {
  68. .name = "video_output",
  69. .dev_release = video_output_release,
  70. .dev_attrs = video_output_attributes,
  71. };
  72. struct output_device *video_output_register(const char *name,
  73. struct device *dev,
  74. void *devdata,
  75. struct output_properties *op)
  76. {
  77. struct output_device *new_dev;
  78. int ret_code = 0;
  79. new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
  80. if (!new_dev) {
  81. ret_code = -ENOMEM;
  82. goto error_return;
  83. }
  84. new_dev->props = op;
  85. new_dev->dev.class = &video_output_class;
  86. new_dev->dev.parent = dev;
  87. strlcpy(new_dev->dev.bus_id,name, BUS_ID_SIZE);
  88. dev_set_drvdata(&new_dev->dev, devdata);
  89. ret_code = device_register(&new_dev->dev);
  90. if (ret_code) {
  91. kfree(new_dev);
  92. goto error_return;
  93. }
  94. return new_dev;
  95. error_return:
  96. return ERR_PTR(ret_code);
  97. }
  98. EXPORT_SYMBOL(video_output_register);
  99. void video_output_unregister(struct output_device *dev)
  100. {
  101. if (!dev)
  102. return;
  103. device_unregister(&dev->dev);
  104. }
  105. EXPORT_SYMBOL(video_output_unregister);
  106. static void __exit video_output_class_exit(void)
  107. {
  108. class_unregister(&video_output_class);
  109. }
  110. static int __init video_output_class_init(void)
  111. {
  112. return class_register(&video_output_class);
  113. }
  114. postcore_initcall(video_output_class_init);
  115. module_exit(video_output_class_exit);