18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2009 Nokia Corporation
48c2ecf20Sopenharmony_ci * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Some code and ideas taken from drivers/video/omap/ driver
78c2ecf20Sopenharmony_ci * by Imre Deak.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define DSS_SUBSYS_NAME "OVERLAY"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/module.h>
138c2ecf20Sopenharmony_ci#include <linux/err.h>
148c2ecf20Sopenharmony_ci#include <linux/sysfs.h>
158c2ecf20Sopenharmony_ci#include <linux/kobject.h>
168c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <video/omapfb_dss.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "dss.h"
218c2ecf20Sopenharmony_ci#include "dss_features.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name);
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%s\n",
318c2ecf20Sopenharmony_ci			ovl->manager ? ovl->manager->name : "<none>");
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf,
358c2ecf20Sopenharmony_ci		size_t size)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	int i, r;
388c2ecf20Sopenharmony_ci	struct omap_overlay_manager *mgr = NULL;
398c2ecf20Sopenharmony_ci	struct omap_overlay_manager *old_mgr;
408c2ecf20Sopenharmony_ci	int len = size;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	if (buf[size-1] == '\n')
438c2ecf20Sopenharmony_ci		--len;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	if (len > 0) {
468c2ecf20Sopenharmony_ci		for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
478c2ecf20Sopenharmony_ci			mgr = omap_dss_get_overlay_manager(i);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci			if (sysfs_streq(buf, mgr->name))
508c2ecf20Sopenharmony_ci				break;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci			mgr = NULL;
538c2ecf20Sopenharmony_ci		}
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	if (len > 0 && mgr == NULL)
578c2ecf20Sopenharmony_ci		return -EINVAL;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	if (mgr)
608c2ecf20Sopenharmony_ci		DSSDBG("manager %s found\n", mgr->name);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	if (mgr == ovl->manager)
638c2ecf20Sopenharmony_ci		return size;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	old_mgr = ovl->manager;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	r = dispc_runtime_get();
688c2ecf20Sopenharmony_ci	if (r)
698c2ecf20Sopenharmony_ci		return r;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	/* detach old manager */
728c2ecf20Sopenharmony_ci	if (old_mgr) {
738c2ecf20Sopenharmony_ci		r = ovl->unset_manager(ovl);
748c2ecf20Sopenharmony_ci		if (r) {
758c2ecf20Sopenharmony_ci			DSSERR("detach failed\n");
768c2ecf20Sopenharmony_ci			goto err;
778c2ecf20Sopenharmony_ci		}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci		r = old_mgr->apply(old_mgr);
808c2ecf20Sopenharmony_ci		if (r)
818c2ecf20Sopenharmony_ci			goto err;
828c2ecf20Sopenharmony_ci	}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	if (mgr) {
858c2ecf20Sopenharmony_ci		r = ovl->set_manager(ovl, mgr);
868c2ecf20Sopenharmony_ci		if (r) {
878c2ecf20Sopenharmony_ci			DSSERR("Failed to attach overlay\n");
888c2ecf20Sopenharmony_ci			goto err;
898c2ecf20Sopenharmony_ci		}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci		r = mgr->apply(mgr);
928c2ecf20Sopenharmony_ci		if (r)
938c2ecf20Sopenharmony_ci			goto err;
948c2ecf20Sopenharmony_ci	}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	dispc_runtime_put();
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	return size;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cierr:
1018c2ecf20Sopenharmony_ci	dispc_runtime_put();
1028c2ecf20Sopenharmony_ci	return r;
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d,%d\n",
1128c2ecf20Sopenharmony_ci			info.width, info.height);
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d\n", info.screen_width);
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d,%d\n",
1318c2ecf20Sopenharmony_ci			info.pos_x, info.pos_y);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic ssize_t overlay_position_store(struct omap_overlay *ovl,
1358c2ecf20Sopenharmony_ci		const char *buf, size_t size)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	int r;
1388c2ecf20Sopenharmony_ci	char *last;
1398c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	info.pos_x = simple_strtoul(buf, &last, 10);
1448c2ecf20Sopenharmony_ci	++last;
1458c2ecf20Sopenharmony_ci	if (last - buf >= size)
1468c2ecf20Sopenharmony_ci		return -EINVAL;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	info.pos_y = simple_strtoul(last, &last, 10);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	r = ovl->set_overlay_info(ovl, &info);
1518c2ecf20Sopenharmony_ci	if (r)
1528c2ecf20Sopenharmony_ci		return r;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	if (ovl->manager) {
1558c2ecf20Sopenharmony_ci		r = ovl->manager->apply(ovl->manager);
1568c2ecf20Sopenharmony_ci		if (r)
1578c2ecf20Sopenharmony_ci			return r;
1588c2ecf20Sopenharmony_ci	}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	return size;
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d,%d\n",
1708c2ecf20Sopenharmony_ci			info.out_width, info.out_height);
1718c2ecf20Sopenharmony_ci}
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic ssize_t overlay_output_size_store(struct omap_overlay *ovl,
1748c2ecf20Sopenharmony_ci		const char *buf, size_t size)
1758c2ecf20Sopenharmony_ci{
1768c2ecf20Sopenharmony_ci	int r;
1778c2ecf20Sopenharmony_ci	char *last;
1788c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	info.out_width = simple_strtoul(buf, &last, 10);
1838c2ecf20Sopenharmony_ci	++last;
1848c2ecf20Sopenharmony_ci	if (last - buf >= size)
1858c2ecf20Sopenharmony_ci		return -EINVAL;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	info.out_height = simple_strtoul(last, &last, 10);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	r = ovl->set_overlay_info(ovl, &info);
1908c2ecf20Sopenharmony_ci	if (r)
1918c2ecf20Sopenharmony_ci		return r;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	if (ovl->manager) {
1948c2ecf20Sopenharmony_ci		r = ovl->manager->apply(ovl->manager);
1958c2ecf20Sopenharmony_ci		if (r)
1968c2ecf20Sopenharmony_ci			return r;
1978c2ecf20Sopenharmony_ci	}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	return size;
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d\n", ovl->is_enabled(ovl));
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf,
2088c2ecf20Sopenharmony_ci		size_t size)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	int r;
2118c2ecf20Sopenharmony_ci	bool enable;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	r = strtobool(buf, &enable);
2148c2ecf20Sopenharmony_ci	if (r)
2158c2ecf20Sopenharmony_ci		return r;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	if (enable)
2188c2ecf20Sopenharmony_ci		r = ovl->enable(ovl);
2198c2ecf20Sopenharmony_ci	else
2208c2ecf20Sopenharmony_ci		r = ovl->disable(ovl);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	if (r)
2238c2ecf20Sopenharmony_ci		return r;
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	return size;
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d\n",
2358c2ecf20Sopenharmony_ci			info.global_alpha);
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
2398c2ecf20Sopenharmony_ci		const char *buf, size_t size)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	int r;
2428c2ecf20Sopenharmony_ci	u8 alpha;
2438c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
2468c2ecf20Sopenharmony_ci		return -ENODEV;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	r = kstrtou8(buf, 0, &alpha);
2498c2ecf20Sopenharmony_ci	if (r)
2508c2ecf20Sopenharmony_ci		return r;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	info.global_alpha = alpha;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	r = ovl->set_overlay_info(ovl, &info);
2578c2ecf20Sopenharmony_ci	if (r)
2588c2ecf20Sopenharmony_ci		return r;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	if (ovl->manager) {
2618c2ecf20Sopenharmony_ci		r = ovl->manager->apply(ovl->manager);
2628c2ecf20Sopenharmony_ci		if (r)
2638c2ecf20Sopenharmony_ci			return r;
2648c2ecf20Sopenharmony_ci	}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	return size;
2678c2ecf20Sopenharmony_ci}
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistatic ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl,
2708c2ecf20Sopenharmony_ci		char *buf)
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d\n",
2778c2ecf20Sopenharmony_ci			info.pre_mult_alpha);
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistatic ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl,
2818c2ecf20Sopenharmony_ci		const char *buf, size_t size)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	int r;
2848c2ecf20Sopenharmony_ci	u8 alpha;
2858c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
2888c2ecf20Sopenharmony_ci		return -ENODEV;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	r = kstrtou8(buf, 0, &alpha);
2918c2ecf20Sopenharmony_ci	if (r)
2928c2ecf20Sopenharmony_ci		return r;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	info.pre_mult_alpha = alpha;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	r = ovl->set_overlay_info(ovl, &info);
2998c2ecf20Sopenharmony_ci	if (r)
3008c2ecf20Sopenharmony_ci		return r;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	if (ovl->manager) {
3038c2ecf20Sopenharmony_ci		r = ovl->manager->apply(ovl->manager);
3048c2ecf20Sopenharmony_ci		if (r)
3058c2ecf20Sopenharmony_ci			return r;
3068c2ecf20Sopenharmony_ci	}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	return size;
3098c2ecf20Sopenharmony_ci}
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistatic ssize_t overlay_zorder_show(struct omap_overlay *ovl, char *buf)
3128c2ecf20Sopenharmony_ci{
3138c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "%d\n", info.zorder);
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic ssize_t overlay_zorder_store(struct omap_overlay *ovl,
3218c2ecf20Sopenharmony_ci		const char *buf, size_t size)
3228c2ecf20Sopenharmony_ci{
3238c2ecf20Sopenharmony_ci	int r;
3248c2ecf20Sopenharmony_ci	u8 zorder;
3258c2ecf20Sopenharmony_ci	struct omap_overlay_info info;
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
3288c2ecf20Sopenharmony_ci		return -ENODEV;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	r = kstrtou8(buf, 0, &zorder);
3318c2ecf20Sopenharmony_ci	if (r)
3328c2ecf20Sopenharmony_ci		return r;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	ovl->get_overlay_info(ovl, &info);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	info.zorder = zorder;
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	r = ovl->set_overlay_info(ovl, &info);
3398c2ecf20Sopenharmony_ci	if (r)
3408c2ecf20Sopenharmony_ci		return r;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	if (ovl->manager) {
3438c2ecf20Sopenharmony_ci		r = ovl->manager->apply(ovl->manager);
3448c2ecf20Sopenharmony_ci		if (r)
3458c2ecf20Sopenharmony_ci			return r;
3468c2ecf20Sopenharmony_ci	}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	return size;
3498c2ecf20Sopenharmony_ci}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistruct overlay_attribute {
3528c2ecf20Sopenharmony_ci	struct attribute attr;
3538c2ecf20Sopenharmony_ci	ssize_t (*show)(struct omap_overlay *, char *);
3548c2ecf20Sopenharmony_ci	ssize_t	(*store)(struct omap_overlay *, const char *, size_t);
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci#define OVERLAY_ATTR(_name, _mode, _show, _store) \
3588c2ecf20Sopenharmony_ci	struct overlay_attribute overlay_attr_##_name = \
3598c2ecf20Sopenharmony_ci	__ATTR(_name, _mode, _show, _store)
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(name, S_IRUGO, overlay_name_show, NULL);
3628c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(manager, S_IRUGO|S_IWUSR,
3638c2ecf20Sopenharmony_ci		overlay_manager_show, overlay_manager_store);
3648c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(input_size, S_IRUGO, overlay_input_size_show, NULL);
3658c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(screen_width, S_IRUGO, overlay_screen_width_show, NULL);
3668c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(position, S_IRUGO|S_IWUSR,
3678c2ecf20Sopenharmony_ci		overlay_position_show, overlay_position_store);
3688c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(output_size, S_IRUGO|S_IWUSR,
3698c2ecf20Sopenharmony_ci		overlay_output_size_show, overlay_output_size_store);
3708c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR,
3718c2ecf20Sopenharmony_ci		overlay_enabled_show, overlay_enabled_store);
3728c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR,
3738c2ecf20Sopenharmony_ci		overlay_global_alpha_show, overlay_global_alpha_store);
3748c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR,
3758c2ecf20Sopenharmony_ci		overlay_pre_mult_alpha_show,
3768c2ecf20Sopenharmony_ci		overlay_pre_mult_alpha_store);
3778c2ecf20Sopenharmony_cistatic OVERLAY_ATTR(zorder, S_IRUGO|S_IWUSR,
3788c2ecf20Sopenharmony_ci		overlay_zorder_show, overlay_zorder_store);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic struct attribute *overlay_sysfs_attrs[] = {
3818c2ecf20Sopenharmony_ci	&overlay_attr_name.attr,
3828c2ecf20Sopenharmony_ci	&overlay_attr_manager.attr,
3838c2ecf20Sopenharmony_ci	&overlay_attr_input_size.attr,
3848c2ecf20Sopenharmony_ci	&overlay_attr_screen_width.attr,
3858c2ecf20Sopenharmony_ci	&overlay_attr_position.attr,
3868c2ecf20Sopenharmony_ci	&overlay_attr_output_size.attr,
3878c2ecf20Sopenharmony_ci	&overlay_attr_enabled.attr,
3888c2ecf20Sopenharmony_ci	&overlay_attr_global_alpha.attr,
3898c2ecf20Sopenharmony_ci	&overlay_attr_pre_mult_alpha.attr,
3908c2ecf20Sopenharmony_ci	&overlay_attr_zorder.attr,
3918c2ecf20Sopenharmony_ci	NULL
3928c2ecf20Sopenharmony_ci};
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cistatic ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr,
3958c2ecf20Sopenharmony_ci		char *buf)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	struct omap_overlay *overlay;
3988c2ecf20Sopenharmony_ci	struct overlay_attribute *overlay_attr;
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	overlay = container_of(kobj, struct omap_overlay, kobj);
4018c2ecf20Sopenharmony_ci	overlay_attr = container_of(attr, struct overlay_attribute, attr);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	if (!overlay_attr->show)
4048c2ecf20Sopenharmony_ci		return -ENOENT;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	return overlay_attr->show(overlay, buf);
4078c2ecf20Sopenharmony_ci}
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_cistatic ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr,
4108c2ecf20Sopenharmony_ci		const char *buf, size_t size)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	struct omap_overlay *overlay;
4138c2ecf20Sopenharmony_ci	struct overlay_attribute *overlay_attr;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	overlay = container_of(kobj, struct omap_overlay, kobj);
4168c2ecf20Sopenharmony_ci	overlay_attr = container_of(attr, struct overlay_attribute, attr);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	if (!overlay_attr->store)
4198c2ecf20Sopenharmony_ci		return -ENOENT;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	return overlay_attr->store(overlay, buf, size);
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_cistatic const struct sysfs_ops overlay_sysfs_ops = {
4258c2ecf20Sopenharmony_ci	.show = overlay_attr_show,
4268c2ecf20Sopenharmony_ci	.store = overlay_attr_store,
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_cistatic struct kobj_type overlay_ktype = {
4308c2ecf20Sopenharmony_ci	.sysfs_ops = &overlay_sysfs_ops,
4318c2ecf20Sopenharmony_ci	.default_attrs = overlay_sysfs_attrs,
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ciint dss_overlay_kobj_init(struct omap_overlay *ovl,
4358c2ecf20Sopenharmony_ci		struct platform_device *pdev)
4368c2ecf20Sopenharmony_ci{
4378c2ecf20Sopenharmony_ci	return kobject_init_and_add(&ovl->kobj, &overlay_ktype,
4388c2ecf20Sopenharmony_ci			&pdev->dev.kobj, "overlay%d", ovl->id);
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_civoid dss_overlay_kobj_uninit(struct omap_overlay *ovl)
4428c2ecf20Sopenharmony_ci{
4438c2ecf20Sopenharmony_ci	kobject_del(&ovl->kobj);
4448c2ecf20Sopenharmony_ci	kobject_put(&ovl->kobj);
4458c2ecf20Sopenharmony_ci}
446