Skip to content

Commit 1a9d3e4

Browse files
ashinlinalex3788
authored andcommitted
[DISPLAY] Move the muc driver to drivers/misc/ to fix the issue of "DSI is not workable"
Change-Id: I211bffcc3362f7d9f88830ce43a5c0f1b539e4f9 Reviewed-on: https://tp-biosrd-v02/gerrit/80215 Reviewed-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com> Tested-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com>
1 parent 7c5c265 commit 1a9d3e4

4 files changed

Lines changed: 249 additions & 2 deletions

File tree

drivers/miniarm/dsi/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-$(CONFIG_DRM_PANEL_TOSHIBA_TC358762) += panel-toshiba-tc358762.o
2-
obj-$(CONFIG_ASUS_RPI_MCU) += asus_mcu.o
2+
#obj-$(CONFIG_ASUS_RPI_MCU) += asus_mcu.o
33
obj-$(CONFIG_ROCKCHIP_DW_MIPI_DSI2) += dw-mipi-dsi.o
4-
obj-$(CONFIG_TINKER_MCU) += tinker_mcu.o
4+
#obj-$(CONFIG_TINKER_MCU) += tinker_mcu.o
55
obj-$(CONFIG_TOUCHSCREEN_TINKER_FT5406) += tinker_ft5406.o

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ obj-$(CONFIG_ROCKCHIP_SCR) += rk_scr.o
6262
obj-$(CONFIG_UID_SYS_STATS) += uid_sys_stats.o
6363
obj-$(CONFIG_MEMORY_STATE_TIME) += memory_state_time.o
6464
obj-$(CONFIG_USB_CAM_GPIO) += usb_cam_gpio.o
65+
obj-$(CONFIG_TINKER_MCU) += tinker_mcu.o

drivers/misc/tinker_mcu.c

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
/*
2+
*
3+
* Tinker board Touchscreen MCU driver.
4+
*
5+
* Copyright (c) 2016 ASUSTek Computer Inc.
6+
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
7+
*
8+
* This software is licensed under the terms of the GNU General Public
9+
* License version 2, as published by the Free Software Foundation, and
10+
* may be copied, distributed, and modified under those terms.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
*/
18+
19+
#include <linux/module.h>
20+
#include <linux/slab.h>
21+
#include <linux/delay.h>
22+
#include <linux/i2c.h>
23+
#include <linux/module.h>
24+
#include <linux/workqueue.h>
25+
#include "tinker_mcu.h"
26+
27+
static struct tinker_mcu_data *g_mcu_data;
28+
static int connected = 0;
29+
30+
static int is_hex(char num)
31+
{
32+
//0-9, a-f, A-F
33+
if ((47 < num && num < 58) || (64 < num && num < 71) || (96 < num && num < 103))
34+
return 1;
35+
return 0;
36+
}
37+
38+
static int string_to_byte(const char *source, unsigned char *destination, int size)
39+
{
40+
int i = 0, counter = 0;
41+
char c[3] = {0};
42+
unsigned char bytes;
43+
44+
if (size%2 == 1)
45+
return -EINVAL;
46+
47+
for(i = 0; i < size; i++){
48+
if(!is_hex(source[i])) {
49+
return -EINVAL;
50+
}
51+
if(0 == i%2){
52+
c[0] = source[i];
53+
c[1] = source[i+1];
54+
sscanf(c, "%hhx", &bytes);
55+
destination[counter] = bytes;
56+
counter++;
57+
}
58+
}
59+
return 0;
60+
}
61+
62+
static int send_cmds(struct i2c_client *client, const char *buf)
63+
{
64+
int ret, size = strlen(buf);
65+
unsigned char byte_cmd[size/2];
66+
67+
if ((size%2) != 0) {
68+
LOG_ERR("size should be even\n");
69+
return -EINVAL;
70+
}
71+
72+
LOG_INFO("%s\n", buf);
73+
74+
string_to_byte(buf, byte_cmd, size);
75+
76+
ret = i2c_master_send(client, byte_cmd, size/2);
77+
if (ret <= 0) {
78+
LOG_ERR("send command failed, ret = %d\n", ret);
79+
return ret!=0 ? ret : -ECOMM;
80+
}
81+
msleep(20);
82+
return 0;
83+
}
84+
85+
static int recv_cmds(struct i2c_client *client, char *buf, int size)
86+
{
87+
int ret;
88+
89+
ret = i2c_master_recv(client, buf, size);
90+
if (ret <= 0) {
91+
LOG_ERR("receive commands failed, %d\n", ret);
92+
return ret!=0 ? ret : -ECOMM;
93+
}
94+
msleep(20);
95+
return 0;
96+
}
97+
98+
static int init_cmd_check(struct tinker_mcu_data *mcu_data)
99+
{
100+
int ret;
101+
char recv_buf[1] = {0};
102+
103+
ret = send_cmds(mcu_data->client, "80");
104+
if (ret < 0)
105+
goto error;
106+
107+
recv_cmds(mcu_data->client, recv_buf, 1);
108+
if (ret < 0)
109+
goto error;
110+
111+
LOG_INFO("recv_cmds: 0x%X\n", recv_buf[0]);
112+
if (recv_buf[0] != 0xC3) {
113+
LOG_ERR("read wrong info\n");
114+
ret = -EINVAL;
115+
goto error;
116+
117+
}
118+
return 0;
119+
120+
error:
121+
return ret;
122+
}
123+
124+
int tinker_mcu_screen_power_up(void)
125+
{
126+
if (!connected)
127+
return -ENODEV;
128+
129+
LOG_INFO("\n");
130+
send_cmds(g_mcu_data->client, "8500");
131+
msleep(800);
132+
send_cmds(g_mcu_data->client, "8501");
133+
send_cmds(g_mcu_data->client, "8104");
134+
135+
return 0;
136+
}
137+
EXPORT_SYMBOL_GPL(tinker_mcu_screen_power_up);
138+
139+
int tinker_mcu_set_bright(int bright)
140+
{
141+
unsigned char cmd[2];
142+
int ret;
143+
144+
if (!connected)
145+
return -ENODEV;
146+
147+
if (bright > 0xff || bright < 0)
148+
return -EINVAL;
149+
150+
LOG_INFO("bright = 0x%x\n", bright);
151+
152+
cmd[0] = 0x86;
153+
cmd[1] = bright;
154+
155+
ret = i2c_master_send(g_mcu_data->client, cmd, 2);
156+
if (ret <= 0) {
157+
LOG_ERR("send command failed, ret = %d\n", ret);
158+
return ret != 0 ? ret : -ECOMM;
159+
}
160+
161+
return 0;
162+
}
163+
EXPORT_SYMBOL_GPL(tinker_mcu_set_bright);
164+
165+
int tinker_mcu_is_connected(void)
166+
{
167+
return connected;
168+
}
169+
EXPORT_SYMBOL_GPL(tinker_mcu_is_connected);
170+
171+
static int tinker_mcu_probe(struct i2c_client *client,
172+
const struct i2c_device_id *id)
173+
{
174+
struct tinker_mcu_data *mcu_data;
175+
int ret;
176+
177+
LOG_INFO("address = 0x%x\n", client->addr);
178+
179+
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
180+
LOG_ERR("I2C check functionality failed\n");
181+
return -ENODEV;
182+
}
183+
184+
mcu_data = kzalloc(sizeof(struct tinker_mcu_data), GFP_KERNEL);
185+
if (mcu_data == NULL) {
186+
LOG_ERR("no memory for device\n");
187+
return -ENOMEM;
188+
}
189+
190+
mcu_data->client = client;
191+
i2c_set_clientdata(client, mcu_data);
192+
g_mcu_data = mcu_data;
193+
194+
ret = init_cmd_check(mcu_data);
195+
if (ret < 0) {
196+
LOG_ERR("init_cmd_check failed, %d\n", ret);
197+
goto error;
198+
}
199+
connected = 1;
200+
201+
return 0;
202+
203+
error:
204+
kfree(mcu_data);
205+
return ret;
206+
}
207+
208+
static int tinker_mcu_remove(struct i2c_client *client)
209+
{
210+
struct tinker_mcu_data *mcu_data = i2c_get_clientdata(client);
211+
connected = 0;
212+
kfree(mcu_data);
213+
return 0;
214+
}
215+
216+
static const struct i2c_device_id tinker_mcu_id[] = {
217+
{"tinker_mcu", 0},
218+
{},
219+
};
220+
221+
static struct i2c_driver tinker_mcu_driver = {
222+
.driver = {
223+
.name = "tinker_mcu",
224+
},
225+
.probe = tinker_mcu_probe,
226+
.remove = tinker_mcu_remove,
227+
.id_table = tinker_mcu_id,
228+
};
229+
module_i2c_driver(tinker_mcu_driver);
230+
231+
MODULE_DESCRIPTION("Tinker Board TouchScreen MCU driver");
232+
MODULE_LICENSE("GPL v2");

drivers/misc/tinker_mcu.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _TINKER_MCU_H_
2+
#define _TINKER_MCU_H_
3+
4+
#define LOG_INFO(fmt,arg...) pr_info("tinker-mcu: %s: "fmt, __func__, ##arg);
5+
#define LOG_ERR(fmt,arg...) pr_err("tinker-mcu: %s: "fmt, __func__, ##arg);
6+
7+
#define MAX_I2C_LEN 255
8+
9+
struct tinker_mcu_data {
10+
struct device *dev;
11+
struct i2c_client *client;
12+
};
13+
14+
#endif

0 commit comments

Comments
 (0)