aboutsummaryrefslogtreecommitdiff
path: root/include/linux/mhl_8334.h
blob: 1f9f58374c1c55da0ab86754f5592757f3f39e92 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __MHL_MSM_H__
#define __MHL_MSM_H__

#include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/mhl_devcap.h>
#include <linux/power_supply.h>
#include <linux/mhl_defs.h>

#define MHL_DEVICE_NAME "sii8334"
#define MHL_DRIVER_NAME "sii8334"

#define HPD_UP               1
#define HPD_DOWN             0

enum discovery_result_enum {
	MHL_DISCOVERY_RESULT_USB = 0,
	MHL_DISCOVERY_RESULT_MHL,
};

struct msc_command_struct {
	u8 command;
	u8 offset;
	u8 length;
	u8 retry;
	union {
		u8 data[16];
		u8 *burst_data;
	} payload;
	u8 retval;
};

struct scrpd_struct {
	u8 offset;
	u8 length;
	u8 data[MHL_SCRATCHPAD_SIZE];
};

/* MHL 8334 supports a max HD pixel clk of 75 MHz */
#define MAX_MHL_PCLK 75000

/* USB driver interface  */

#if defined(CONFIG_FB_MSM_HDMI_MHL_8334)
 /*  mhl_device_discovery */
extern int mhl_device_discovery(const char *name, int *result);

/* - register|unregister MHL cable plug callback. */
extern int mhl_register_callback
	(const char *name, void (*callback)(int online));
extern int mhl_unregister_callback(const char *name);
#else
static inline int mhl_device_discovery(const char *name, int *result)
{
	return -ENODEV;
}

static inline int
	mhl_register_callback(const char *name, void (*callback)(int online))
{
	return -ENODEV;
}

static inline int mhl_unregister_callback(const char *name)
{
	return -ENODEV;
}
#endif

struct msc_cmd_envelope {
	/*
	 * this list head is for list APIs
	 */
	struct list_head msc_queue_envelope;
	struct msc_command_struct msc_cmd_msg;
};

struct mhl_msm_state_t {
	struct i2c_client *i2c_client;
	struct i2c_driver *i2c_driver;
	uint8_t      cur_state;
	uint8_t chip_rev_id;
	struct msm_mhl_platform_data *mhl_data;
	/* Device Discovery stuff */
	int mhl_mode;
	struct completion rgnd_done;
	struct completion msc_cmd_done;
	uint16_t devcap_state;
	uint8_t path_en_state;
	struct work_struct mhl_msc_send_work;
	struct list_head list_cmd;
	void (*msc_command_put_work) (struct msc_command_struct *);
	struct msc_command_struct* (*msc_command_get_work) (void);
};

#ifdef CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334
enum mhl_gpio_type {
	MHL_TX_RESET_GPIO,
	MHL_TX_INTR_GPIO,
	MHL_TX_PMIC_PWR_GPIO,
	MHL_TX_MAX_GPIO,
};

enum mhl_vreg_type {
	MHL_TX_3V_VREG,
	MHL_TX_MAX_VREG,
};


struct mhl_tx_platform_data {
	/* Data filled from device tree nodes */
	struct dss_gpio *gpios[MHL_TX_MAX_GPIO];
	struct dss_vreg *vregs[MHL_TX_MAX_VREG];
	int irq;
	struct platform_device *hdmi_pdev;
};

struct mhl_tx_ctrl {
	struct platform_device *pdev;
	struct mhl_tx_platform_data *pdata;
	struct i2c_client *i2c_handle;
	uint8_t cur_state;
	uint8_t chip_rev_id;
	int mhl_mode;
	struct completion rgnd_done;
	void (*notify_usb_online)(void *ctx, int online);
	void *notify_ctx;
	struct usb_ext_notification *mhl_info;
	bool disc_enabled;
	struct power_supply mhl_psy;
	bool vbus_active;
	int current_val;
	struct completion msc_cmd_done;
	uint8_t devcap[16];
	uint16_t devcap_state;
	uint8_t status[2];
	uint8_t path_en_state;
	uint8_t tmds_en_state;
	void *hdmi_mhl_ops;
	struct work_struct mhl_msc_send_work;
	struct list_head list_cmd;
	struct input_dev *input;
	struct workqueue_struct *msc_send_workqueue;
	struct workqueue_struct *mhl_workq;
	struct work_struct mhl_intr_work;
	u16 *rcp_key_code_tbl;
	size_t rcp_key_code_tbl_len;
	struct scrpd_struct scrpd;
	int scrpd_busy;
	int wr_burst_pending;
	struct completion req_write_done;
	spinlock_t lock;
	/*
	 * Lock between mhl_sii_config and
	 * mhl_sii_device_discovery functions
	*/
	struct mutex sii_config_lock;
	bool tx_powered_off;
	uint8_t dwnstream_hpd;
	bool mhl_det_discon;
	bool irq_req_done;
};

int mhl_i2c_reg_read(struct i2c_client *client,
		     uint8_t slave_addr_index, uint8_t reg_offset);
int mhl_i2c_reg_write(struct i2c_client *client,
		      uint8_t slave_addr_index, uint8_t reg_offset,
		      uint8_t value);
void mhl_i2c_reg_modify(struct i2c_client *client,
			uint8_t slave_addr_index, uint8_t reg_offset,
			uint8_t mask, uint8_t val);

#endif /* CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334 */

enum {
	TX_PAGE_TPI          = 0x00,
	TX_PAGE_L0           = 0x01,
	TX_PAGE_L1           = 0x02,
	TX_PAGE_2            = 0x03,
	TX_PAGE_3            = 0x04,
	TX_PAGE_CBUS         = 0x05,
	TX_PAGE_DDC_EDID     = 0x06,
	TX_PAGE_DDC_SEGM     = 0x07,
};

enum mhl_st_type {
	POWER_STATE_D0_NO_MHL = 0,
	POWER_STATE_D0_MHL    = 2,
	POWER_STATE_D3        = 3,
};

enum {
	DEV_PAGE_TPI_0      = (0x72),
	DEV_PAGE_TX_L0_0    = (0x72),
	DEV_PAGE_TPI_1      = (0x76),
	DEV_PAGE_TX_L0_1    = (0x76),
	DEV_PAGE_TX_L1_0    = (0x7A),
	DEV_PAGE_TX_L1_1    = (0x7E),
	DEV_PAGE_TX_2_0     = (0x92),
	DEV_PAGE_TX_2_1     = (0x96),
	DEV_PAGE_TX_3_0	    = (0x9A),
	DEV_PAGE_TX_3_1	    = (0x9E),
	DEV_PAGE_CBUS       = (0xC8),
	DEV_PAGE_DDC_EDID   = (0xA0),
	DEV_PAGE_DDC_SEGM   = (0x60),
};

#define MHL_SII_PAGE0_RD(off) \
	mhl_i2c_reg_read(client, TX_PAGE_L0, off)
#define MHL_SII_PAGE0_WR(off, val) \
	mhl_i2c_reg_write(client, TX_PAGE_L0, off, val)
#define MHL_SII_PAGE0_MOD(off, mask, val)		\
	mhl_i2c_reg_modify(client, TX_PAGE_L0, off, mask, val)


#define MHL_SII_PAGE1_RD(off) \
	mhl_i2c_reg_read(client, TX_PAGE_L1, off)
#define MHL_SII_PAGE1_WR(off, val) \
	mhl_i2c_reg_write(client, TX_PAGE_L1, off, val)
#define MHL_SII_PAGE1_MOD(off, mask, val) \
	mhl_i2c_reg_modify(client, TX_PAGE_L1, off, mask, val)


#define MHL_SII_PAGE2_RD(off) \
	mhl_i2c_reg_read(client, TX_PAGE_2, off)
#define MHL_SII_PAGE2_WR(off, val) \
	mhl_i2c_reg_write(client, TX_PAGE_2, off, val)
#define MHL_SII_PAGE2_MOD(off, mask, val) \
	mhl_i2c_reg_modify(client, TX_PAGE_2, off, mask, val)


#define MHL_SII_PAGE3_RD(off) \
	mhl_i2c_reg_read(client, TX_PAGE_3, off)
#define MHL_SII_PAGE3_WR(off, val) \
	mhl_i2c_reg_write(client, TX_PAGE_3, off, val)
#define MHL_SII_PAGE3_MOD(off, mask, val)		\
	mhl_i2c_reg_modify(client, TX_PAGE_3, off, mask, val)

#define MHL_SII_CBUS_RD(off) \
	mhl_i2c_reg_read(client, TX_PAGE_CBUS, off)
#define MHL_SII_CBUS_WR(off, val) \
	mhl_i2c_reg_write(client, TX_PAGE_CBUS, off, val)
#define MHL_SII_CBUS_MOD(off, mask, val) \
	mhl_i2c_reg_modify(client, TX_PAGE_CBUS, off, mask, val)

#define REG_SRST        ((TX_PAGE_3 << 16) | 0x0000)
#define REG_INTR1       ((TX_PAGE_L0 << 16) | 0x0071)
#define REG_INTR1_MASK  ((TX_PAGE_L0 << 16) | 0x0075)
#define REG_INTR2       ((TX_PAGE_L0 << 16) | 0x0072)
#define REG_TMDS_CCTRL  ((TX_PAGE_L0 << 16) | 0x0080)

#define REG_DISC_CTRL1	((TX_PAGE_3 << 16) | 0x0010)
#define REG_DISC_CTRL2	((TX_PAGE_3 << 16) | 0x0011)
#define REG_DISC_CTRL3	((TX_PAGE_3 << 16) | 0x0012)
#define REG_DISC_CTRL4	((TX_PAGE_3 << 16) | 0x0013)
#define REG_DISC_CTRL5	((TX_PAGE_3 << 16) | 0x0014)
#define REG_DISC_CTRL6	((TX_PAGE_3 << 16) | 0x0015)
#define REG_DISC_CTRL7	((TX_PAGE_3 << 16) | 0x0016)
#define REG_DISC_CTRL8	((TX_PAGE_3 << 16) | 0x0017)
#define REG_DISC_CTRL9	((TX_PAGE_3 << 16) | 0x0018)
#define REG_DISC_CTRL10	((TX_PAGE_3 << 16) | 0x0019)
#define REG_DISC_CTRL11	((TX_PAGE_3 << 16) | 0x001A)
#define REG_DISC_STAT	((TX_PAGE_3 << 16) | 0x001B)
#define REG_DISC_STAT2	((TX_PAGE_3 << 16) | 0x001C)

#define REG_INT_CTRL	((TX_PAGE_3 << 16) | 0x0020)
#define REG_INTR4		((TX_PAGE_3 << 16) | 0x0021)
#define REG_INTR4_MASK	((TX_PAGE_3 << 16) | 0x0022)
#define REG_INTR5		((TX_PAGE_3 << 16) | 0x0023)
#define REG_INTR5_MASK	((TX_PAGE_3 << 16) | 0x0024)

#define REG_MHLTX_CTL1	((TX_PAGE_3 << 16) | 0x0030)
#define REG_MHLTX_CTL2	((TX_PAGE_3 << 16) | 0x0031)
#define REG_MHLTX_CTL3	((TX_PAGE_3 << 16) | 0x0032)
#define REG_MHLTX_CTL4	((TX_PAGE_3 << 16) | 0x0033)
#define REG_MHLTX_CTL5	((TX_PAGE_3 << 16) | 0x0034)
#define REG_MHLTX_CTL6	((TX_PAGE_3 << 16) | 0x0035)
#define REG_MHLTX_CTL7	((TX_PAGE_3 << 16) | 0x0036)
#define REG_MHLTX_CTL8	((TX_PAGE_3 << 16) | 0x0037)

#define REG_TMDS_CSTAT	((TX_PAGE_3 << 16) | 0x0040)

#define REG_CBUS_INTR_STATUS            ((TX_PAGE_CBUS << 16) | 0x0008)
#define REG_CBUS_INTR_ENABLE            ((TX_PAGE_CBUS << 16) | 0x0009)

#define REG_DDC_ABORT_REASON            ((TX_PAGE_CBUS << 16) | 0x000B)
#define REG_CBUS_BUS_STATUS             ((TX_PAGE_CBUS << 16) | 0x000A)
#define REG_PRI_XFR_ABORT_REASON        ((TX_PAGE_CBUS << 16) | 0x000D)
#define REG_CBUS_PRI_FWR_ABORT_REASON   ((TX_PAGE_CBUS << 16) | 0x000E)
#define REG_CBUS_PRI_START              ((TX_PAGE_CBUS << 16) | 0x0012)
#define REG_CBUS_PRI_ADDR_CMD           ((TX_PAGE_CBUS << 16) | 0x0013)
#define REG_CBUS_PRI_WR_DATA_1ST        ((TX_PAGE_CBUS << 16) | 0x0014)
#define REG_CBUS_PRI_WR_DATA_2ND        ((TX_PAGE_CBUS << 16) | 0x0015)
#define REG_CBUS_PRI_RD_DATA_1ST        ((TX_PAGE_CBUS << 16) | 0x0016)
#define REG_CBUS_PRI_RD_DATA_2ND        ((TX_PAGE_CBUS << 16) | 0x0017)
#define REG_CBUS_PRI_VS_CMD             ((TX_PAGE_CBUS << 16) | 0x0018)
#define REG_CBUS_PRI_VS_DATA            ((TX_PAGE_CBUS << 16) | 0x0019)
#define	REG_CBUS_MSC_RETRY_INTERVAL		((TX_PAGE_CBUS << 16) | 0x001A)
#define	REG_CBUS_DDC_FAIL_LIMIT			((TX_PAGE_CBUS << 16) | 0x001C)
#define	REG_CBUS_MSC_FAIL_LIMIT			((TX_PAGE_CBUS << 16) | 0x001D)
#define	REG_CBUS_MSC_INT2_STATUS        ((TX_PAGE_CBUS << 16) | 0x001E)
#define REG_CBUS_MSC_INT2_ENABLE        ((TX_PAGE_CBUS << 16) | 0x001F)
#define	REG_MSC_WRITE_BURST_LEN         ((TX_PAGE_CBUS << 16) | 0x0020)
#define	REG_MSC_HEARTBEAT_CONTROL       ((TX_PAGE_CBUS << 16) | 0x0021)
#define REG_MSC_TIMEOUT_LIMIT           ((TX_PAGE_CBUS << 16) | 0x0022)
#define	REG_CBUS_LINK_CONTROL_1			((TX_PAGE_CBUS << 16) | 0x0030)
#define	REG_CBUS_LINK_CONTROL_2			((TX_PAGE_CBUS << 16) | 0x0031)
#define	REG_CBUS_LINK_CONTROL_3			((TX_PAGE_CBUS << 16) | 0x0032)
#define	REG_CBUS_LINK_CONTROL_4			((TX_PAGE_CBUS << 16) | 0x0033)
#define	REG_CBUS_LINK_CONTROL_5			((TX_PAGE_CBUS << 16) | 0x0034)
#define	REG_CBUS_LINK_CONTROL_6			((TX_PAGE_CBUS << 16) | 0x0035)
#define	REG_CBUS_LINK_CONTROL_7			((TX_PAGE_CBUS << 16) | 0x0036)
#define REG_CBUS_LINK_STATUS_1          ((TX_PAGE_CBUS << 16) | 0x0037)
#define REG_CBUS_LINK_STATUS_2          ((TX_PAGE_CBUS << 16) | 0x0038)
#define	REG_CBUS_LINK_CONTROL_8			((TX_PAGE_CBUS << 16) | 0x0039)
#define	REG_CBUS_LINK_CONTROL_9			((TX_PAGE_CBUS << 16) | 0x003A)
#define	REG_CBUS_LINK_CONTROL_10		((TX_PAGE_CBUS << 16) | 0x003B)
#define	REG_CBUS_LINK_CONTROL_11		((TX_PAGE_CBUS << 16) | 0x003C)
#define	REG_CBUS_LINK_CONTROL_12		((TX_PAGE_CBUS << 16) | 0x003D)


#define REG_CBUS_LINK_CTRL9_0			((TX_PAGE_CBUS << 16) | 0x003A)
#define REG_CBUS_LINK_CTRL9_1           ((TX_PAGE_CBUS << 16) | 0x00BA)

#define	REG_CBUS_DRV_STRENGTH_0			((TX_PAGE_CBUS << 16) | 0x0040)
#define	REG_CBUS_DRV_STRENGTH_1			((TX_PAGE_CBUS << 16) | 0x0041)
#define	REG_CBUS_ACK_CONTROL			((TX_PAGE_CBUS << 16) | 0x0042)
#define	REG_CBUS_CAL_CONTROL			((TX_PAGE_CBUS << 16) | 0x0043)

#define REG_CBUS_SCRATCHPAD_0           ((TX_PAGE_CBUS << 16) | 0x00C0)
#define REG_CBUS_DEVICE_CAP_0           ((TX_PAGE_CBUS << 16) | 0x0080)
#define REG_CBUS_DEVICE_CAP_1           ((TX_PAGE_CBUS << 16) | 0x0081)
#define REG_CBUS_DEVICE_CAP_2           ((TX_PAGE_CBUS << 16) | 0x0082)
#define REG_CBUS_DEVICE_CAP_3           ((TX_PAGE_CBUS << 16) | 0x0083)
#define REG_CBUS_DEVICE_CAP_4           ((TX_PAGE_CBUS << 16) | 0x0084)
#define REG_CBUS_DEVICE_CAP_5           ((TX_PAGE_CBUS << 16) | 0x0085)
#define REG_CBUS_DEVICE_CAP_6           ((TX_PAGE_CBUS << 16) | 0x0086)
#define REG_CBUS_DEVICE_CAP_7           ((TX_PAGE_CBUS << 16) | 0x0087)
#define REG_CBUS_DEVICE_CAP_8           ((TX_PAGE_CBUS << 16) | 0x0088)
#define REG_CBUS_DEVICE_CAP_9           ((TX_PAGE_CBUS << 16) | 0x0089)
#define REG_CBUS_DEVICE_CAP_A           ((TX_PAGE_CBUS << 16) | 0x008A)
#define REG_CBUS_DEVICE_CAP_B           ((TX_PAGE_CBUS << 16) | 0x008B)
#define REG_CBUS_DEVICE_CAP_C           ((TX_PAGE_CBUS << 16) | 0x008C)
#define REG_CBUS_DEVICE_CAP_D           ((TX_PAGE_CBUS << 16) | 0x008D)
#define REG_CBUS_DEVICE_CAP_E           ((TX_PAGE_CBUS << 16) | 0x008E)
#define REG_CBUS_DEVICE_CAP_F           ((TX_PAGE_CBUS << 16) | 0x008F)
#define REG_CBUS_SET_INT_0              ((TX_PAGE_CBUS << 16) | 0x00A0)
#define REG_CBUS_SET_INT_1		((TX_PAGE_CBUS << 16) | 0x00A1)
#define REG_CBUS_SET_INT_2		((TX_PAGE_CBUS << 16) | 0x00A2)
#define REG_CBUS_SET_INT_3		((TX_PAGE_CBUS << 16) | 0x00A3)
#define REG_CBUS_WRITE_STAT_0           ((TX_PAGE_CBUS << 16) | 0x00B0)
#define REG_CBUS_WRITE_STAT_1           ((TX_PAGE_CBUS << 16) | 0x00B1)
#define REG_CBUS_WRITE_STAT_2           ((TX_PAGE_CBUS << 16) | 0x00B2)
#define REG_CBUS_WRITE_STAT_3           ((TX_PAGE_CBUS << 16) | 0x00B3)

#define GET_PAGE(x) ((x) >> 16)
#define GET_OFF(x) ((x) & 0xffff)


#define MHL_SII_REG_NAME_RD(arg)\
	mhl_i2c_reg_read(client, GET_PAGE(arg), GET_OFF(arg))
#define MHL_SII_REG_NAME_WR(arg, val)\
	mhl_i2c_reg_write(client, GET_PAGE(arg), GET_OFF(arg), val)
#define MHL_SII_REG_NAME_MOD(arg, mask, val)\
	mhl_i2c_reg_modify(client, GET_PAGE(arg), GET_OFF(arg), mask, val)

#endif /* __MHL_MSM_H__ */