manager-sysfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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 "MANAGER"
  21. #include <linux/kernel.h>
  22. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/jiffies.h>
  26. #include <video/omapdss.h>
  27. #include "dss.h"
  28. #include "dss_features.h"
  29. static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
  30. {
  31. return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
  32. }
  33. static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
  34. {
  35. struct omap_dss_device *dssdev = mgr->get_device(mgr);
  36. return snprintf(buf, PAGE_SIZE, "%s\n", dssdev ?
  37. dssdev->name : "<none>");
  38. }
  39. static int manager_display_match(struct omap_dss_device *dssdev, void *data)
  40. {
  41. const char *str = data;
  42. return sysfs_streq(dssdev->name, str);
  43. }
  44. static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
  45. const char *buf, size_t size)
  46. {
  47. int r = 0;
  48. size_t len = size;
  49. struct omap_dss_device *dssdev = NULL;
  50. struct omap_dss_device *old_dssdev;
  51. if (buf[size-1] == '\n')
  52. --len;
  53. if (len > 0)
  54. dssdev = omap_dss_find_device((void *)buf,
  55. manager_display_match);
  56. if (len > 0 && dssdev == NULL)
  57. return -EINVAL;
  58. if (dssdev) {
  59. DSSDBG("display %s found\n", dssdev->name);
  60. if (omapdss_device_is_connected(dssdev)) {
  61. DSSERR("new display is already connected\n");
  62. r = -EINVAL;
  63. goto put_device;
  64. }
  65. if (omapdss_device_is_enabled(dssdev)) {
  66. DSSERR("new display is not disabled\n");
  67. r = -EINVAL;
  68. goto put_device;
  69. }
  70. }
  71. old_dssdev = mgr->get_device(mgr);
  72. if (old_dssdev) {
  73. if (omapdss_device_is_enabled(old_dssdev)) {
  74. DSSERR("old display is not disabled\n");
  75. r = -EINVAL;
  76. goto put_device;
  77. }
  78. old_dssdev->driver->disconnect(old_dssdev);
  79. }
  80. if (dssdev) {
  81. r = dssdev->driver->connect(dssdev);
  82. if (r) {
  83. DSSERR("failed to connect new device\n");
  84. goto put_device;
  85. }
  86. old_dssdev = mgr->get_device(mgr);
  87. if (old_dssdev != dssdev) {
  88. DSSERR("failed to connect device to this manager\n");
  89. dssdev->driver->disconnect(dssdev);
  90. goto put_device;
  91. }
  92. r = mgr->apply(mgr);
  93. if (r) {
  94. DSSERR("failed to apply dispc config\n");
  95. goto put_device;
  96. }
  97. }
  98. put_device:
  99. if (dssdev)
  100. omap_dss_put_device(dssdev);
  101. return r ? r : size;
  102. }
  103. static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
  104. char *buf)
  105. {
  106. struct omap_overlay_manager_info info;
  107. mgr->get_manager_info(mgr, &info);
  108. return snprintf(buf, PAGE_SIZE, "%#x\n", info.default_color);
  109. }
  110. static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
  111. const char *buf, size_t size)
  112. {
  113. struct omap_overlay_manager_info info;
  114. u32 color;
  115. int r;
  116. r = kstrtouint(buf, 0, &color);
  117. if (r)
  118. return r;
  119. mgr->get_manager_info(mgr, &info);
  120. info.default_color = color;
  121. r = mgr->set_manager_info(mgr, &info);
  122. if (r)
  123. return r;
  124. r = mgr->apply(mgr);
  125. if (r)
  126. return r;
  127. return size;
  128. }
  129. static const char *trans_key_type_str[] = {
  130. "gfx-destination",
  131. "video-source",
  132. };
  133. static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
  134. char *buf)
  135. {
  136. enum omap_dss_trans_key_type key_type;
  137. struct omap_overlay_manager_info info;
  138. mgr->get_manager_info(mgr, &info);
  139. key_type = info.trans_key_type;
  140. BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
  141. return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
  142. }
  143. static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
  144. const char *buf, size_t size)
  145. {
  146. enum omap_dss_trans_key_type key_type;
  147. struct omap_overlay_manager_info info;
  148. int r;
  149. for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
  150. key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
  151. if (sysfs_streq(buf, trans_key_type_str[key_type]))
  152. break;
  153. }
  154. if (key_type == ARRAY_SIZE(trans_key_type_str))
  155. return -EINVAL;
  156. mgr->get_manager_info(mgr, &info);
  157. info.trans_key_type = key_type;
  158. r = mgr->set_manager_info(mgr, &info);
  159. if (r)
  160. return r;
  161. r = mgr->apply(mgr);
  162. if (r)
  163. return r;
  164. return size;
  165. }
  166. static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
  167. char *buf)
  168. {
  169. struct omap_overlay_manager_info info;
  170. mgr->get_manager_info(mgr, &info);
  171. return snprintf(buf, PAGE_SIZE, "%#x\n", info.trans_key);
  172. }
  173. static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
  174. const char *buf, size_t size)
  175. {
  176. struct omap_overlay_manager_info info;
  177. u32 key_value;
  178. int r;
  179. r = kstrtouint(buf, 0, &key_value);
  180. if (r)
  181. return r;
  182. mgr->get_manager_info(mgr, &info);
  183. info.trans_key = key_value;
  184. r = mgr->set_manager_info(mgr, &info);
  185. if (r)
  186. return r;
  187. r = mgr->apply(mgr);
  188. if (r)
  189. return r;
  190. return size;
  191. }
  192. static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
  193. char *buf)
  194. {
  195. struct omap_overlay_manager_info info;
  196. mgr->get_manager_info(mgr, &info);
  197. return snprintf(buf, PAGE_SIZE, "%d\n", info.trans_enabled);
  198. }
  199. static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
  200. const char *buf, size_t size)
  201. {
  202. struct omap_overlay_manager_info info;
  203. bool enable;
  204. int r;
  205. r = strtobool(buf, &enable);
  206. if (r)
  207. return r;
  208. mgr->get_manager_info(mgr, &info);
  209. info.trans_enabled = enable;
  210. r = mgr->set_manager_info(mgr, &info);
  211. if (r)
  212. return r;
  213. r = mgr->apply(mgr);
  214. if (r)
  215. return r;
  216. return size;
  217. }
  218. static ssize_t manager_alpha_blending_enabled_show(
  219. struct omap_overlay_manager *mgr, char *buf)
  220. {
  221. struct omap_overlay_manager_info info;
  222. if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
  223. return -ENODEV;
  224. mgr->get_manager_info(mgr, &info);
  225. return snprintf(buf, PAGE_SIZE, "%d\n",
  226. info.partial_alpha_enabled);
  227. }
  228. static ssize_t manager_alpha_blending_enabled_store(
  229. struct omap_overlay_manager *mgr,
  230. const char *buf, size_t size)
  231. {
  232. struct omap_overlay_manager_info info;
  233. bool enable;
  234. int r;
  235. if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
  236. return -ENODEV;
  237. r = strtobool(buf, &enable);
  238. if (r)
  239. return r;
  240. mgr->get_manager_info(mgr, &info);
  241. info.partial_alpha_enabled = enable;
  242. r = mgr->set_manager_info(mgr, &info);
  243. if (r)
  244. return r;
  245. r = mgr->apply(mgr);
  246. if (r)
  247. return r;
  248. return size;
  249. }
  250. static ssize_t manager_cpr_enable_show(struct omap_overlay_manager *mgr,
  251. char *buf)
  252. {
  253. struct omap_overlay_manager_info info;
  254. mgr->get_manager_info(mgr, &info);
  255. return snprintf(buf, PAGE_SIZE, "%d\n", info.cpr_enable);
  256. }
  257. static ssize_t manager_cpr_enable_store(struct omap_overlay_manager *mgr,
  258. const char *buf, size_t size)
  259. {
  260. struct omap_overlay_manager_info info;
  261. int r;
  262. bool enable;
  263. if (!dss_has_feature(FEAT_CPR))
  264. return -ENODEV;
  265. r = strtobool(buf, &enable);
  266. if (r)
  267. return r;
  268. mgr->get_manager_info(mgr, &info);
  269. if (info.cpr_enable == enable)
  270. return size;
  271. info.cpr_enable = enable;
  272. r = mgr->set_manager_info(mgr, &info);
  273. if (r)
  274. return r;
  275. r = mgr->apply(mgr);
  276. if (r)
  277. return r;
  278. return size;
  279. }
  280. static ssize_t manager_cpr_coef_show(struct omap_overlay_manager *mgr,
  281. char *buf)
  282. {
  283. struct omap_overlay_manager_info info;
  284. mgr->get_manager_info(mgr, &info);
  285. return snprintf(buf, PAGE_SIZE,
  286. "%d %d %d %d %d %d %d %d %d\n",
  287. info.cpr_coefs.rr,
  288. info.cpr_coefs.rg,
  289. info.cpr_coefs.rb,
  290. info.cpr_coefs.gr,
  291. info.cpr_coefs.gg,
  292. info.cpr_coefs.gb,
  293. info.cpr_coefs.br,
  294. info.cpr_coefs.bg,
  295. info.cpr_coefs.bb);
  296. }
  297. static ssize_t manager_cpr_coef_store(struct omap_overlay_manager *mgr,
  298. const char *buf, size_t size)
  299. {
  300. struct omap_overlay_manager_info info;
  301. struct omap_dss_cpr_coefs coefs;
  302. int r, i;
  303. s16 *arr;
  304. if (!dss_has_feature(FEAT_CPR))
  305. return -ENODEV;
  306. if (sscanf(buf, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
  307. &coefs.rr, &coefs.rg, &coefs.rb,
  308. &coefs.gr, &coefs.gg, &coefs.gb,
  309. &coefs.br, &coefs.bg, &coefs.bb) != 9)
  310. return -EINVAL;
  311. arr = (s16[]){ coefs.rr, coefs.rg, coefs.rb,
  312. coefs.gr, coefs.gg, coefs.gb,
  313. coefs.br, coefs.bg, coefs.bb };
  314. for (i = 0; i < 9; ++i) {
  315. if (arr[i] < -512 || arr[i] > 511)
  316. return -EINVAL;
  317. }
  318. mgr->get_manager_info(mgr, &info);
  319. info.cpr_coefs = coefs;
  320. r = mgr->set_manager_info(mgr, &info);
  321. if (r)
  322. return r;
  323. r = mgr->apply(mgr);
  324. if (r)
  325. return r;
  326. return size;
  327. }
  328. struct manager_attribute {
  329. struct attribute attr;
  330. ssize_t (*show)(struct omap_overlay_manager *, char *);
  331. ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
  332. };
  333. #define MANAGER_ATTR(_name, _mode, _show, _store) \
  334. struct manager_attribute manager_attr_##_name = \
  335. __ATTR(_name, _mode, _show, _store)
  336. static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
  337. static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
  338. manager_display_show, manager_display_store);
  339. static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
  340. manager_default_color_show, manager_default_color_store);
  341. static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
  342. manager_trans_key_type_show, manager_trans_key_type_store);
  343. static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
  344. manager_trans_key_value_show, manager_trans_key_value_store);
  345. static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
  346. manager_trans_key_enabled_show,
  347. manager_trans_key_enabled_store);
  348. static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
  349. manager_alpha_blending_enabled_show,
  350. manager_alpha_blending_enabled_store);
  351. static MANAGER_ATTR(cpr_enable, S_IRUGO|S_IWUSR,
  352. manager_cpr_enable_show,
  353. manager_cpr_enable_store);
  354. static MANAGER_ATTR(cpr_coef, S_IRUGO|S_IWUSR,
  355. manager_cpr_coef_show,
  356. manager_cpr_coef_store);
  357. static struct attribute *manager_sysfs_attrs[] = {
  358. &manager_attr_name.attr,
  359. &manager_attr_display.attr,
  360. &manager_attr_default_color.attr,
  361. &manager_attr_trans_key_type.attr,
  362. &manager_attr_trans_key_value.attr,
  363. &manager_attr_trans_key_enabled.attr,
  364. &manager_attr_alpha_blending_enabled.attr,
  365. &manager_attr_cpr_enable.attr,
  366. &manager_attr_cpr_coef.attr,
  367. NULL
  368. };
  369. static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
  370. char *buf)
  371. {
  372. struct omap_overlay_manager *manager;
  373. struct manager_attribute *manager_attr;
  374. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  375. manager_attr = container_of(attr, struct manager_attribute, attr);
  376. if (!manager_attr->show)
  377. return -ENOENT;
  378. return manager_attr->show(manager, buf);
  379. }
  380. static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
  381. const char *buf, size_t size)
  382. {
  383. struct omap_overlay_manager *manager;
  384. struct manager_attribute *manager_attr;
  385. manager = container_of(kobj, struct omap_overlay_manager, kobj);
  386. manager_attr = container_of(attr, struct manager_attribute, attr);
  387. if (!manager_attr->store)
  388. return -ENOENT;
  389. return manager_attr->store(manager, buf, size);
  390. }
  391. static const struct sysfs_ops manager_sysfs_ops = {
  392. .show = manager_attr_show,
  393. .store = manager_attr_store,
  394. };
  395. static struct kobj_type manager_ktype = {
  396. .sysfs_ops = &manager_sysfs_ops,
  397. .default_attrs = manager_sysfs_attrs,
  398. };
  399. int dss_manager_kobj_init(struct omap_overlay_manager *mgr,
  400. struct platform_device *pdev)
  401. {
  402. return kobject_init_and_add(&mgr->kobj, &manager_ktype,
  403. &pdev->dev.kobj, "manager%d", mgr->id);
  404. }
  405. void dss_manager_kobj_uninit(struct omap_overlay_manager *mgr)
  406. {
  407. kobject_del(&mgr->kobj);
  408. kobject_put(&mgr->kobj);
  409. memset(&mgr->kobj, 0, sizeof(mgr->kobj));
  410. }