From 61598093bbdd283a7edc367d900f223070ead8d2 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Fri, 10 May 2024 07:43:03 +0000
Subject: [PATCH] add ax88772C AX88772C_eeprom_tools

---
 kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c |  216 ++++++++++++++++++++---------------------------------
 1 files changed, 81 insertions(+), 135 deletions(-)

diff --git a/kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c b/kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c
index 262f4d5..a2e47b4 100644
--- a/kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c
+++ b/kernel/drivers/gpu/drm/rockchip/ebc-dev/bufmanage/buf_manage.c
@@ -28,10 +28,8 @@
 	struct buf_list_s *dsp_buf_list; /* dispplay buffer list. */
 	int dsp_buf_list_status;
 	struct ebc_buf_s *osd_buf;
-	struct buf_list_s *osd_buf_list; /* dispplay buffer list. */
-	struct mutex osd_buf_lock;
-	struct mutex dsp_buf_lock;
-	struct mutex ebc_buf_lock;
+
+	struct mutex dsp_lock;
 };
 
 static struct buf_info_s ebc_buf_info;
@@ -56,106 +54,84 @@
 	return BUF_SUCCESS;
 }
 
-static void do_dsp_buf_list(struct ebc_buf_s *dsp_buf)
+int ebc_remove_from_dsp_buf_list(struct ebc_buf_s *remove_buf)
 {
-	struct ebc_buf_s *temp_buf;
-	int temp_pos;
-
-	if (ebc_buf_info.dsp_buf_list->nb_elt > 0) {
-		temp_pos = ebc_buf_info.dsp_buf_list->nb_elt;
-		while (temp_pos) {
-			temp_pos--;
-			temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
-			if (temp_buf->needpic) {
-				continue;
-			} else {
-				buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
-				ebc_buf_release(temp_buf);
-			}
-		}
-	}
-}
-
-int ebc_drop_one_dsp_buf(void)
-{
-	struct ebc_buf_s *temp_buf;
-	int temp_pos;
-
-	mutex_lock(&ebc_buf_info.dsp_buf_lock);
+	mutex_lock(&ebc_buf_info.dsp_lock);
 	if (ebc_buf_info.dsp_buf_list) {
-		if (ebc_buf_info.dsp_buf_list->nb_elt > 0) {
-			temp_pos = ebc_buf_info.dsp_buf_list->nb_elt - 1;
-			temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
-			if (temp_buf->needpic == 2) {
-				buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
-				ebc_buf_release(temp_buf);
-				mutex_unlock(&ebc_buf_info.dsp_buf_lock);
-				return BUF_SUCCESS;
-			}
-		}
+		int pos;
+
+		pos = buf_list_get_pos(ebc_buf_info.dsp_buf_list, (int *)remove_buf);
+		buf_list_remove(ebc_buf_info.dsp_buf_list, pos);
 	}
-	mutex_unlock(&ebc_buf_info.dsp_buf_lock);
-
-	return BUF_ERROR;
-}
-
-int ebc_add_to_dsp_buf_list(struct ebc_buf_s *dsp_buf)
-{
-	mutex_lock(&ebc_buf_info.dsp_buf_lock);
-	if (ebc_buf_info.dsp_buf_list) {
-		do_dsp_buf_list(dsp_buf);
-
-		if (-1 == buf_list_add(ebc_buf_info.dsp_buf_list, (int *)dsp_buf, -1)) {
-			ebc_buf_release(dsp_buf);
-			mutex_unlock(&ebc_buf_info.dsp_buf_lock);
-			return BUF_ERROR;
-		}
-
-		if (dsp_buf->status != buf_osd)
-			dsp_buf->status = buf_dsp;
-	}
-	mutex_unlock(&ebc_buf_info.dsp_buf_lock);
+	mutex_unlock(&ebc_buf_info.dsp_lock);
 
 	return BUF_SUCCESS;
 }
 
-int ebc_add_to_osd_buf_list(struct ebc_buf_s *dsp_buf)
+int ebc_add_to_dsp_buf_list(struct ebc_buf_s *dsp_buf)
 {
-	int ret = BUF_SUCCESS;
+	struct ebc_buf_s *temp_buf;
+	int temp_pos;
+	int is_full_mode = 0;
 
-	mutex_lock(&ebc_buf_info.osd_buf_lock);
-	if (ebc_buf_info.osd_buf_list) {
-		if (-1 == buf_list_add(ebc_buf_info.osd_buf_list, (int *)dsp_buf, -1)) {
-			ebc_buf_release(dsp_buf);
-			ret = BUF_ERROR;
+	mutex_lock(&ebc_buf_info.dsp_lock);
+	if (ebc_buf_info.dsp_buf_list) {
+		switch (dsp_buf->buf_mode) {
+		case EPD_DU:
+		case EPD_SUSPEND:
+		case EPD_RESUME:
+		case EPD_POWER_OFF:
+		case EPD_OVERLAY:
+		case EPD_RESET:
+			break;
+
+		default:
+			if (ebc_buf_info.dsp_buf_list->nb_elt > 1) {
+				temp_pos = ebc_buf_info.dsp_buf_list->nb_elt;
+				while (--temp_pos) {
+					temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, temp_pos);
+					if ((temp_buf->buf_mode != EPD_FULL_GC16) &&
+					    (temp_buf->buf_mode != EPD_FULL_GL16) &&
+					    (temp_buf->buf_mode != EPD_FULL_GLR16) &&
+					    (temp_buf->buf_mode != EPD_FULL_GLD16) &&
+					    (temp_buf->buf_mode != EPD_FULL_GCC16) &&
+					    (temp_buf->buf_mode != EPD_OVERLAY) &&
+					    (temp_buf->buf_mode != EPD_DU) &&
+					    (temp_buf->buf_mode != EPD_SUSPEND) &&
+					    (temp_buf->buf_mode != EPD_RESUME) &&
+					    (temp_buf->buf_mode != EPD_POWER_OFF)) {
+						buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
+						ebc_buf_release(temp_buf);
+					} else if ((1 == is_full_mode) &&
+						   (temp_buf->buf_mode != EPD_DU) &&
+						   (temp_buf->buf_mode != EPD_OVERLAY) &&
+						   (temp_buf->buf_mode != EPD_SUSPEND) &&
+						   (temp_buf->buf_mode != EPD_RESUME) &&
+						   (temp_buf->buf_mode != EPD_POWER_OFF)) {
+						buf_list_remove(ebc_buf_info.dsp_buf_list, temp_pos);
+						ebc_buf_release(temp_buf);
+					} else {
+						is_full_mode = 1;
+					}
+				}
+			}
+			break;
+		}
+
+		dsp_buf->status = buf_dsp;
+		if (-1 == buf_list_add(ebc_buf_info.dsp_buf_list, (int *)dsp_buf, -1)) {
+			mutex_unlock(&ebc_buf_info.dsp_lock);
+			return BUF_ERROR;
 		}
 	}
-	mutex_unlock(&ebc_buf_info.osd_buf_lock);
-	return ret;
-}
+	mutex_unlock(&ebc_buf_info.dsp_lock);
 
-struct ebc_buf_s *ebc_osd_buf_get(void)
-{
-	struct ebc_buf_s *buf = NULL;
-
-	mutex_lock(&ebc_buf_info.osd_buf_lock);
-	if (ebc_buf_info.osd_buf_list && (ebc_buf_info.osd_buf_list->nb_elt > 0)) {
-		buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.osd_buf_list, 0);
-		buf_list_remove(ebc_buf_info.osd_buf_list, 0);
-	}
-	mutex_unlock(&ebc_buf_info.osd_buf_lock);
-
-	return buf;
+	return BUF_SUCCESS;
 }
 
 int ebc_get_dsp_list_enum_num(void)
 {
 	return ebc_buf_info.dsp_buf_list->nb_elt;
-}
-
-int ebc_get_osd_list_enum_num(void)
-{
-	return ebc_buf_info.osd_buf_list->nb_elt;
 }
 
 struct ebc_buf_s *ebc_find_buf_by_phy_addr(unsigned long phy_addr)
@@ -179,17 +155,15 @@
 {
 	struct ebc_buf_s *buf = NULL;
 
-	mutex_lock(&ebc_buf_info.dsp_buf_lock);
-	if (ebc_buf_info.dsp_buf_list && (ebc_buf_info.dsp_buf_list->nb_elt > 0)) {
+	mutex_lock(&ebc_buf_info.dsp_lock);
+	if (ebc_buf_info.dsp_buf_list && (ebc_buf_info.dsp_buf_list->nb_elt > 0))
 		buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.dsp_buf_list, 0);
-		buf_list_remove(ebc_buf_info.dsp_buf_list, 0);
-	}
-	mutex_unlock(&ebc_buf_info.dsp_buf_lock);
+	mutex_unlock(&ebc_buf_info.dsp_lock);
 
 	return buf;
 }
 
-struct ebc_buf_s *ebc_empty_osd_buf_get(void)
+struct ebc_buf_s *ebc_osd_buf_get(void)
 {
 	if (ebc_buf_info.osd_buf)
 		return ebc_buf_info.osd_buf;
@@ -211,13 +185,12 @@
 	return temp_buf;
 }
 
-struct ebc_buf_s *ebc_empty_buf_get(const char *tid_name)
+struct ebc_buf_s *ebc_empty_buf_get(void)
 {
-	struct ebc_buf_s *temp_buf = NULL;
+	struct ebc_buf_s *temp_buf;
 	int temp_pos;
 
-	mutex_lock(&ebc_buf_info.ebc_buf_lock);
-	while (ebc_buf_info.buf_list) {
+	if (ebc_buf_info.buf_list) {
 		temp_pos = 0;
 
 		while (temp_pos < ebc_buf_info.buf_list->nb_elt) {
@@ -225,23 +198,23 @@
 			if (temp_buf) {
 				if (temp_buf->status == buf_idle) {
 					temp_buf->status = buf_user;
-					memcpy(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1); //store user thread name
-					goto OUT;
+					memcpy(temp_buf->tid_name, current->comm, TASK_COMM_LEN); //store user thread name
+					return temp_buf;
 				}
 				// one tid only can get one buf at one time
-				else if ((temp_buf->status == buf_user) && (!strncmp(temp_buf->tid_name, tid_name, TASK_COMM_LEN - 1))) {
-					printk("[%s]: one tid only can get one buf at one time\n", tid_name);
-					goto OUT;
+				else if ((temp_buf->status == buf_user) && (!strncmp(temp_buf->tid_name, current->comm, TASK_COMM_LEN - 7))) {
+					return temp_buf;
 				}
 			}
 		}
 		ebc_buf_info.use_buf_is_empty = 1;
+
 		wait_event_interruptible(ebc_buf_wq, ebc_buf_info.use_buf_is_empty != 1);
+
+		return ebc_empty_buf_get();
 	}
 
-OUT:
-	mutex_unlock(&ebc_buf_info.ebc_buf_lock);
-	return temp_buf;
+	return NULL;
 }
 
 unsigned long ebc_phy_buf_base_get(void)
@@ -252,23 +225,6 @@
 char *ebc_virt_buf_base_get(void)
 {
 	return ebc_buf_info.virt_mem_base;
-}
-
-int ebc_buf_state_show(char *buf)
-{
-	int i;
-	int ret = 0;
-	struct ebc_buf_s *temp_buf;
-
-	ret += sprintf(buf, "dsp_buf num = %d\n", ebc_buf_info.dsp_buf_list->nb_elt);
-	if (ebc_buf_info.buf_list) {
-		for (i = 0; i < ebc_buf_info.buf_list->nb_elt; i++) {
-			temp_buf = (struct ebc_buf_s *)buf_list_get(ebc_buf_info.buf_list, i);
-			ret += sprintf(buf + ret, "ebc_buf[%d]: s = %d, m = %d, tid = %s\n", i, temp_buf->status, temp_buf->buf_mode, temp_buf->tid_name);
-		}
-	}
-
-	return ret;
 }
 
 int ebc_buf_uninit(void)
@@ -304,21 +260,14 @@
 	if (NULL == mem_start)
 		return BUF_ERROR;
 
-	mutex_init(&ebc_buf_info.dsp_buf_lock);
-	mutex_init(&ebc_buf_info.ebc_buf_lock);
-	mutex_init(&ebc_buf_info.osd_buf_lock);
+	mutex_init(&ebc_buf_info.dsp_lock);
 
 	if (buf_list_init(&ebc_buf_info.buf_list, BUF_LIST_MAX_NUMBER))
 		return BUF_ERROR;
 
 	if (buf_list_init(&ebc_buf_info.dsp_buf_list, BUF_LIST_MAX_NUMBER)) {
 		res = BUF_ERROR;
-		goto dsp_list_err;
-	}
-
-	if (buf_list_init(&ebc_buf_info.osd_buf_list, BUF_LIST_MAX_NUMBER)) {
-		res = BUF_ERROR;
-		goto osd_list_err;
+		goto buf_list_err;
 	}
 
 	ebc_buf_info.buf_total_num = 0;
@@ -368,13 +317,10 @@
 	}
 
 	return BUF_SUCCESS;
-
 exit:
 	ebc_buf_uninit();
-	buf_list_uninit(ebc_buf_info.osd_buf_list);
-osd_list_err:
 	buf_list_uninit(ebc_buf_info.dsp_buf_list);
-dsp_list_err:
+buf_list_err:
 	buf_list_uninit(ebc_buf_info.buf_list);
 
 	return res;

--
Gitblit v1.6.2