Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * TP  suspend Control Abstraction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) RK Company
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifndef _RK_TP_SUSPEND_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define _RK_TP_SUSPEND_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "../../gpu/drm/rockchip/ebc-dev/ebc_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct  tp_device{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct notifier_block fb_notif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct notifier_block ebc_notif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	int(*tp_suspend)(struct  tp_device*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int(*tp_resume)(struct  tp_device*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct mutex ops_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static inline int fb_notifier_callback(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 				unsigned long action, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct tp_device *tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct fb_event *event = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int blank_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	tp = container_of(self, struct tp_device, fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (action != FB_EVENT_BLANK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	mutex_lock(&tp->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	blank_mode = *((int *)event->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	//printk("%s.....lin=%d tp->status=%x,blank_mode=%x\n",__func__,__LINE__,tp->status,blank_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	switch (blank_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	case FB_BLANK_UNBLANK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (tp->status != FB_BLANK_UNBLANK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			tp->status = blank_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			tp->tp_resume(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (tp->status == FB_BLANK_UNBLANK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			tp->status = blank_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			ret = tp->tp_suspend(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	mutex_unlock(&tp->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		printk("TP_notifier_callback error action=%x,blank_mode=%x\n",(int)action,blank_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int ebc_notifier_callback(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		unsigned long action, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct tp_device *tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	tp = container_of(self, struct tp_device, ebc_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	mutex_lock(&tp->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (action == EBC_FB_BLANK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		tp->tp_suspend(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	else if (action == EBC_FB_UNBLANK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		tp->tp_resume(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	mutex_unlock(&tp->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static inline int tp_register_fb(struct tp_device *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	memset(&tp->fb_notif, 0, sizeof(tp->fb_notif));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	tp->fb_notif.notifier_call = fb_notifier_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	tp->ebc_notif.notifier_call = ebc_notifier_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	mutex_init(&tp->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	tp->status = FB_BLANK_UNBLANK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ebc_register_notifier(&tp->ebc_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	fb_register_client(&tp->fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline void tp_unregister_fb(struct tp_device *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ebc_unregister_notifier(&tp->ebc_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	fb_unregister_client(&tp->fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif