display-sysfs.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * Some code and ideas taken from drivers/video/omap/ driver
  6. * by Imre Deak.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #define DSS_SUBSYS_NAME "DISPLAY"
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/jiffies.h>
  24. #include <linux/platform_device.h>
  25. #include <video/omapdss.h>
  26. #include "dss.h"
  27. #include "dss_features.h"
  28. static ssize_t display_enabled_show(struct device *dev,
  29. struct device_attribute *attr, char *buf)
  30. {
  31. struct omap_dss_device *dssdev = to_dss_device(dev);
  32. bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
  33. return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
  34. }
  35. static ssize_t display_enabled_store(struct device *dev,
  36. struct device_attribute *attr,
  37. const char *buf, size_t size)
  38. {
  39. struct omap_dss_device *dssdev = to_dss_device(dev);
  40. int r;
  41. bool enabled;
  42. r = strtobool(buf, &enabled);
  43. if (r)
  44. return r;
  45. if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
  46. if (enabled) {
  47. r = dssdev->driver->enable(dssdev);
  48. if (r)
  49. return r;
  50. } else {
  51. dssdev->driver->disable(dssdev);
  52. }
  53. }
  54. return size;
  55. }
  56. static ssize_t display_tear_show(struct device *dev,
  57. struct device_attribute *attr, char *buf)
  58. {
  59. struct omap_dss_device *dssdev = to_dss_device(dev);
  60. return snprintf(buf, PAGE_SIZE, "%d\n",
  61. dssdev->driver->get_te ?
  62. dssdev->driver->get_te(dssdev) : 0);
  63. }
  64. static ssize_t display_tear_store(struct device *dev,
  65. struct device_attribute *attr, const char *buf, size_t size)
  66. {
  67. struct omap_dss_device *dssdev = to_dss_device(dev);
  68. int r;
  69. bool te;
  70. if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
  71. return -ENOENT;
  72. r = strtobool(buf, &te);
  73. if (r)
  74. return r;
  75. r = dssdev->driver->enable_te(dssdev, te);
  76. if (r)
  77. return r;
  78. return size;
  79. }
  80. static ssize_t display_timings_show(struct device *dev,
  81. struct device_attribute *attr, char *buf)
  82. {
  83. struct omap_dss_device *dssdev = to_dss_device(dev);
  84. struct omap_video_timings t;
  85. if (!dssdev->driver->get_timings)
  86. return -ENOENT;
  87. dssdev->driver->get_timings(dssdev, &t);
  88. return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
  89. t.pixel_clock,
  90. t.x_res, t.hfp, t.hbp, t.hsw,
  91. t.y_res, t.vfp, t.vbp, t.vsw);
  92. }
  93. static ssize_t display_timings_store(struct device *dev,
  94. struct device_attribute *attr, const char *buf, size_t size)
  95. {
  96. struct omap_dss_device *dssdev = to_dss_device(dev);
  97. struct omap_video_timings t = dssdev->panel.timings;
  98. int r, found;
  99. if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
  100. return -ENOENT;
  101. found = 0;
  102. #ifdef CONFIG_OMAP2_DSS_VENC
  103. if (strncmp("pal", buf, 3) == 0) {
  104. t = omap_dss_pal_timings;
  105. found = 1;
  106. } else if (strncmp("ntsc", buf, 4) == 0) {
  107. t = omap_dss_ntsc_timings;
  108. found = 1;
  109. }
  110. #endif
  111. if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
  112. &t.pixel_clock,
  113. &t.x_res, &t.hfp, &t.hbp, &t.hsw,
  114. &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
  115. return -EINVAL;
  116. r = dssdev->driver->check_timings(dssdev, &t);
  117. if (r)
  118. return r;
  119. dssdev->driver->disable(dssdev);
  120. dssdev->driver->set_timings(dssdev, &t);
  121. r = dssdev->driver->enable(dssdev);
  122. if (r)
  123. return r;
  124. return size;
  125. }
  126. static ssize_t display_rotate_show(struct device *dev,
  127. struct device_attribute *attr, char *buf)
  128. {
  129. struct omap_dss_device *dssdev = to_dss_device(dev);
  130. int rotate;
  131. if (!dssdev->driver->get_rotate)
  132. return -ENOENT;
  133. rotate = dssdev->driver->get_rotate(dssdev);
  134. return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
  135. }
  136. static ssize_t display_rotate_store(struct device *dev,
  137. struct device_attribute *attr, const char *buf, size_t size)
  138. {
  139. struct omap_dss_device *dssdev = to_dss_device(dev);
  140. int rot, r;
  141. if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
  142. return -ENOENT;
  143. r = kstrtoint(buf, 0, &rot);
  144. if (r)
  145. return r;
  146. r = dssdev->driver->set_rotate(dssdev, rot);
  147. if (r)
  148. return r;
  149. return size;
  150. }
  151. static ssize_t display_mirror_show(struct device *dev,
  152. struct device_attribute *attr, char *buf)
  153. {
  154. struct omap_dss_device *dssdev = to_dss_device(dev);
  155. int mirror;
  156. if (!dssdev->driver->get_mirror)
  157. return -ENOENT;
  158. mirror = dssdev->driver->get_mirror(dssdev);
  159. return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
  160. }
  161. static ssize_t display_mirror_store(struct device *dev,
  162. struct device_attribute *attr, const char *buf, size_t size)
  163. {
  164. struct omap_dss_device *dssdev = to_dss_device(dev);
  165. int r;
  166. bool mirror;
  167. if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
  168. return -ENOENT;
  169. r = strtobool(buf, &mirror);
  170. if (r)
  171. return r;
  172. r = dssdev->driver->set_mirror(dssdev, mirror);
  173. if (r)
  174. return r;
  175. return size;
  176. }
  177. static ssize_t display_wss_show(struct device *dev,
  178. struct device_attribute *attr, char *buf)
  179. {
  180. struct omap_dss_device *dssdev = to_dss_device(dev);
  181. unsigned int wss;
  182. if (!dssdev->driver->get_wss)
  183. return -ENOENT;
  184. wss = dssdev->driver->get_wss(dssdev);
  185. return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
  186. }
  187. static ssize_t display_wss_store(struct device *dev,
  188. struct device_attribute *attr, const char *buf, size_t size)
  189. {
  190. struct omap_dss_device *dssdev = to_dss_device(dev);
  191. u32 wss;
  192. int r;
  193. if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
  194. return -ENOENT;
  195. r = kstrtou32(buf, 0, &wss);
  196. if (r)
  197. return r;
  198. if (wss > 0xfffff)
  199. return -EINVAL;
  200. r = dssdev->driver->set_wss(dssdev, wss);
  201. if (r)
  202. return r;
  203. return size;
  204. }
  205. static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
  206. display_enabled_show, display_enabled_store);
  207. static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
  208. display_tear_show, display_tear_store);
  209. static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
  210. display_timings_show, display_timings_store);
  211. static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
  212. display_rotate_show, display_rotate_store);
  213. static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
  214. display_mirror_show, display_mirror_store);
  215. static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
  216. display_wss_show, display_wss_store);
  217. static struct device_attribute *display_sysfs_attrs[] = {
  218. &dev_attr_enabled,
  219. &dev_attr_tear_elim,
  220. &dev_attr_timings,
  221. &dev_attr_rotate,
  222. &dev_attr_mirror,
  223. &dev_attr_wss,
  224. NULL
  225. };
  226. int display_init_sysfs(struct platform_device *pdev,
  227. struct omap_dss_device *dssdev)
  228. {
  229. struct device_attribute *attr;
  230. int i, r;
  231. /* create device sysfs files */
  232. i = 0;
  233. while ((attr = display_sysfs_attrs[i++]) != NULL) {
  234. r = device_create_file(&dssdev->dev, attr);
  235. if (r) {
  236. for (i = i - 2; i >= 0; i--) {
  237. attr = display_sysfs_attrs[i];
  238. device_remove_file(&dssdev->dev, attr);
  239. }
  240. DSSERR("failed to create sysfs file\n");
  241. return r;
  242. }
  243. }
  244. /* create display? sysfs links */
  245. r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
  246. dev_name(&dssdev->dev));
  247. if (r) {
  248. while ((attr = display_sysfs_attrs[i++]) != NULL)
  249. device_remove_file(&dssdev->dev, attr);
  250. DSSERR("failed to create sysfs display link\n");
  251. return r;
  252. }
  253. return 0;
  254. }
  255. void display_uninit_sysfs(struct platform_device *pdev,
  256. struct omap_dss_device *dssdev)
  257. {
  258. struct device_attribute *attr;
  259. int i = 0;
  260. sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
  261. while ((attr = display_sysfs_attrs[i++]) != NULL)
  262. device_remove_file(&dssdev->dev, attr);
  263. }