output.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 state_show(struct device *dev, struct device_attribute *attr,
  33. 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 state_store(struct device *dev, 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 (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 DEVICE_ATTR_RW(state);
  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 attribute *video_output_attrs[] = {
  65. &dev_attr_state.attr,
  66. NULL,
  67. };
  68. ATTRIBUTE_GROUPS(video_output);
  69. static struct class video_output_class = {
  70. .name = "video_output",
  71. .dev_release = video_output_release,
  72. .dev_groups = video_output_groups,
  73. };
  74. struct output_device *video_output_register(const char *name,
  75. struct device *dev,
  76. void *devdata,
  77. struct output_properties *op)
  78. {
  79. struct output_device *new_dev;
  80. int ret_code = 0;
  81. new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
  82. if (!new_dev) {
  83. ret_code = -ENOMEM;
  84. goto error_return;
  85. }
  86. new_dev->props = op;
  87. new_dev->dev.class = &video_output_class;
  88. new_dev->dev.parent = dev;
  89. dev_set_name(&new_dev->dev, "%s", name);
  90. dev_set_drvdata(&new_dev->dev, devdata);
  91. ret_code = device_register(&new_dev->dev);
  92. if (ret_code) {
  93. kfree(new_dev);
  94. goto error_return;
  95. }
  96. return new_dev;
  97. error_return:
  98. return ERR_PTR(ret_code);
  99. }
  100. EXPORT_SYMBOL(video_output_register);
  101. void video_output_unregister(struct output_device *dev)
  102. {
  103. if (!dev)
  104. return;
  105. device_unregister(&dev->dev);
  106. }
  107. EXPORT_SYMBOL(video_output_unregister);
  108. static void __exit video_output_class_exit(void)
  109. {
  110. class_unregister(&video_output_class);
  111. }
  112. static int __init video_output_class_init(void)
  113. {
  114. return class_register(&video_output_class);
  115. }
  116. postcore_initcall(video_output_class_init);
  117. module_exit(video_output_class_exit);