summaryrefstree
path: root/kernel/drivers/video/fbdev/exynos/panel/panel_spi.h
blob: dc2d1782fbbe32f89845edd6ef77fd72dda38d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Samsung Electronics Co., Ltd.
 * Kimyung Lee <kernel.lee@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __PANEL_SPI_DEVICE_H__
#define __PANEL_SPI_DEVICE_H__

#include <linux/kernel.h>
#include <linux/miscdevice.h>
#include <linux/bitops.h>
#include "panel.h"

#define DRIVER_NAME "panel_spi"
#define PANEL_SPI_DRIVER_NAME "panel_spi_driver"
#define MAX_PANEL_SPI_RX_BUF	(2048)
#define MAX_PANEL_SPI_RX_DATA	(MAX_PANEL_SPI_RX_BUF)
#define MAX_PANEL_SPI_TX_BUF	(260)
#define MAX_PANEL_SPI_TX_DATA	(256)
#define MAX_ADDRESSING_BYTE		(4)

#define MAX_CMD_RETRY			(5)
#define MAX_STATUS_RETRY		(10)
#define MAX_BUSY_RETRY			(50)

enum {
	PANEL_SPI_CTRL_DATA_RX = 0,
	PANEL_SPI_CTRL_DATA_TX = 1,
	PANEL_SPI_CTRL_RESET = 2,
	PANEL_SPI_CTRL_CMD = 3,
	PANEL_SPI_STATUS_1 = 4,
	PANEL_SPI_STATUS_2 = 5,
	PANEL_SPI_UNLOCK = 6,
	PANEL_SPI_LOCK = 7,
	PANEL_SPI_WRITE_ENABLE = 8,
};

enum {
	PANEL_SPI_CMD_OPTION_NONE = BIT(0),
	PANEL_SPI_CMD_OPTION_READ_COMPARE = BIT(1),
	PANEL_SPI_CMD_OPTION_ADDR_3BYTE = BIT(2),
	PANEL_SPI_CMD_OPTION_ADDR_4BYTE = BIT(3),
	PANEL_SPI_CMD_OPTION_ONLY_DELAY = BIT(4),
};

enum {
	PANEL_SPI_CMD_NONE,
	PANEL_SPI_CMD_FLASH_INIT1,
	PANEL_SPI_CMD_FLASH_INIT1_DONE,
	PANEL_SPI_CMD_FLASH_INIT2,
	PANEL_SPI_CMD_FLASH_INIT2_DONE,
	PANEL_SPI_CMD_FLASH_EXIT1,
	PANEL_SPI_CMD_FLASH_EXIT1_DONE,
	PANEL_SPI_CMD_FLASH_EXIT2,
	PANEL_SPI_CMD_FLASH_EXIT2_DONE,
	PANEL_SPI_CMD_FLASH_BUSY_CLEAR,
	PANEL_SPI_CMD_FLASH_READ,
	PANEL_SPI_CMD_FLASH_WRITE_ENABLE,
	PANEL_SPI_CMD_FLASH_WRITE_DISABLE,
	PANEL_SPI_CMD_FLASH_WRITE,
	PANEL_SPI_CMD_FLASH_WRITE_DONE,
	PANEL_SPI_CMD_FLASH_ERASE_4K,
	PANEL_SPI_CMD_FLASH_ERASE_4K_DONE,
	PANEL_SPI_CMD_FLASH_ERASE_32K,
	PANEL_SPI_CMD_FLASH_ERASE_32K_DONE,
	PANEL_SPI_CMD_FLASH_ERASE_64K,
	PANEL_SPI_CMD_FLASH_ERASE_64K_DONE,
	PANEL_SPI_CMD_FLASH_ERASE_256K,
	PANEL_SPI_CMD_FLASH_ERASE_256K_DONE,
	PANEL_SPI_CMD_FLASH_ERASE_CHIP,
	PANEL_SPI_CMD_FLASH_ERASE_CHIP_DONE,
	MAX_PANEL_SPI_CMD,
};

enum {
	PANEL_SPI_ERASE_TYPE_BLOCK,
	PANEL_SPI_ERASE_TYPE_CHIP,
	MAX_PANEL_SPI_ERASE,
};

enum {
	PANEL_SPI_CTRL_NONE,
	PANEL_SPI_CTRL_INIT,
	PANEL_SPI_CTRL_EXIT,
	PANEL_SPI_CTRL_ID_READ,
	PANEL_SPI_CTRL_BUSY_CHECK,
	PANEL_SPI_CTRL_GET_READ_SIZE,
	PANEL_SPI_CTRL_GET_WRITE_SIZE,
	MAX_PANEL_SPI_CTRL,
};

enum {
	PANEL_SPI_GET_READ_SIZE,
	PANEL_SPI_GET_WRITE_SIZE,
};

enum {
	PANEL_SPI_PACKET_TYPE_ERASE_NONBLOCK = 0x1,
};

struct panel_spi_dev;

struct spi_cmd {
	int reg;
	int opt;
	int addr;
	int wlen;
	u8 *wval;
	int rlen;
	u8 *rval;
	u8 *rmask;
	u32 delay_before_usecs;
	u32 delay_after_usecs;
	u32 delay_retry_usecs;
	int wait_response_bytes;
};

// spi_data_packet : for read/write/erase func
struct spi_data_packet {
	int type;
	u32 addr;
	u32 size;
	u8 *buf;
};

struct spi_drv_ops {
	int (*ctl)(struct panel_spi_dev *spi_dev, int msg, void *data);
	int (*cmd)(struct panel_spi_dev *spi_dev, const u8 *wbuf, int wsize, u8 *rbuf, int rsize);
	int (*erase)(struct panel_spi_dev *spi_dev, struct spi_data_packet *data_buf);
	int (*read)(struct panel_spi_dev *spi_dev, struct spi_data_packet *data_buf);
	int (*write)(struct panel_spi_dev *spi_dev, struct spi_data_packet *data_buf);
	int (*init)(struct panel_spi_dev *spi_dev);
	int (*exit)(struct panel_spi_dev *spi_dev);
	int (*get_buf_size)(struct panel_spi_dev *spi_dev, int type);
};

//deprecated: accessing via common_panel_driver
struct spi_drv_pdrv_ops {
	int (*pdrv_read)(struct panel_spi_dev *spi_dev, const u8 cmd, u8 *buf, int size);
	int (*pdrv_cmd)(struct panel_spi_dev *spi_dev, const u8 *wbuf, int wsize, u8 *rbuf, int rsize);
	int (*pdrv_read_param)(struct panel_spi_dev *spi_dev, const u8 *wbuf, int wsize);
};

struct spi_dev_info {
	bool ready;
	u32 id;
	u32 size;
	u32 speed_hz;
	int erase_type;
	int byte_per_write;
	int byte_per_read;
	char *vendor;
	char *model;
	struct spi_cmd **cmd_list;
};

struct spi_data {
	int spi_addr;
	u32 size;
	u32 speed_hz;
	u32 compat_mask;
	u32 compat_id;
	int erase_type;
	int byte_per_write;
	int byte_per_read;
	char *vendor;
	char *model;
	struct spi_cmd **cmd_list;
};

struct panel_spi_dev {
	struct miscdevice dev;
	struct spi_drv_ops *ops;
	struct spi_drv_pdrv_ops *pdrv_ops;		//accessing via common_panel_driver
	struct spi_device *spi;
	struct spi_dev_info spi_info;
	u8 *setparam_buffer;
	u32 setparam_buffer_size;
	u8 *read_buf_data;
	u8 read_buf_cmd;
	u32 read_buf_size;

	//for file ops
	struct mutex f_lock;
	bool fopened;
	bool auto_erase;
};

struct ioc_erase_info {
	u32 offset;
	u32 length;
};

#define PANEL_SPI_IOCTL_MAGIC	'S'

#define IOCTL_AUTO_ERASE_ENABLE		_IO(PANEL_SPI_IOCTL_MAGIC, 1)
#define IOCTL_AUTO_ERASE_DISABLE	_IO(PANEL_SPI_IOCTL_MAGIC, 2)
#define IOCTL_CHECK_STATE			_IOR(PANEL_SPI_IOCTL_MAGIC, 3, int)
#define IOCTL_ERASE			_IOW(PANEL_SPI_IOCTL_MAGIC, 4, struct ioc_erase_info)

int panel_spi_drv_probe(struct panel_device *panel, struct spi_data **spi_data_tbl, int nr_spi_data_tbl);
static inline bool SPI_IS_READY(struct panel_spi_dev *dev)
{
	return dev->spi_info.ready;
}

#endif