blob: 75e654685bd8c49073853d5ce564aeb8af22ece4 [file] [log] [blame]
Manoj Rao7708a3a2012-12-13 18:30:58 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Manoj Rao14648742012-03-30 19:42:12 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef __MHL_MSM_H__
15#define __MHL_MSM_H__
16
17#include <linux/types.h>
18#include <linux/platform_device.h>
19#include <mach/board.h>
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070020#include <linux/mhl_devcap.h>
Manoj Rao7708a3a2012-12-13 18:30:58 -080021#include <linux/power_supply.h>
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070022#include <linux/mhl_defs.h>
Manoj Rao14648742012-03-30 19:42:12 -070023
Manoj Rao14648742012-03-30 19:42:12 -070024#define MHL_DEVICE_NAME "sii8334"
25#define MHL_DRIVER_NAME "sii8334"
26
27#define HPD_UP 1
28#define HPD_DOWN 0
29
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070030enum discovery_result_enum {
31 MHL_DISCOVERY_RESULT_USB = 0,
32 MHL_DISCOVERY_RESULT_MHL,
33};
34
Manoj Raof7110b82012-07-29 22:29:02 -070035struct msc_command_struct {
36 u8 command;
37 u8 offset;
38 u8 length;
Manoj Rao455c8c72013-01-21 16:44:08 -080039 u8 retry;
Manoj Raof7110b82012-07-29 22:29:02 -070040 union {
41 u8 data[16];
42 u8 *burst_data;
43 } payload;
44 u8 retval;
45};
46
Manoj Rao455c8c72013-01-21 16:44:08 -080047struct scrpd_struct {
48 u8 offset;
49 u8 length;
50 u8 data[MHL_SCRATCHPAD_SIZE];
51};
52
53
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070054/* USB driver interface */
55
Manoj Raob554cf62012-11-27 21:27:38 -080056#if defined(CONFIG_FB_MSM_HDMI_MHL_8334)
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070057 /* mhl_device_discovery */
58extern int mhl_device_discovery(const char *name, int *result);
59
60/* - register|unregister MHL cable plug callback. */
61extern int mhl_register_callback
62 (const char *name, void (*callback)(int online));
63extern int mhl_unregister_callback(const char *name);
64#else
65static inline int mhl_device_discovery(const char *name, int *result)
66{
67 return -ENODEV;
68}
69
70static inline int
71 mhl_register_callback(const char *name, void (*callback)(int online))
72{
73 return -ENODEV;
74}
75
76static inline int mhl_unregister_callback(const char *name)
77{
78 return -ENODEV;
79}
80#endif
81
Manoj Rao907b7e02012-08-08 18:47:12 -070082struct msc_cmd_envelope {
83 /*
84 * this list head is for list APIs
85 */
86 struct list_head msc_queue_envelope;
87 struct msc_command_struct msc_cmd_msg;
88};
89
Manoj Rao14648742012-03-30 19:42:12 -070090struct mhl_msm_state_t {
91 struct i2c_client *i2c_client;
92 struct i2c_driver *i2c_driver;
93 uint8_t cur_state;
94 uint8_t chip_rev_id;
95 struct msm_mhl_platform_data *mhl_data;
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070096 /* Device Discovery stuff */
97 int mhl_mode;
98 struct completion rgnd_done;
Manoj Raof7110b82012-07-29 22:29:02 -070099 struct completion msc_cmd_done;
100 uint8_t devcap_state;
101 uint8_t path_en_state;
Manoj Rao907b7e02012-08-08 18:47:12 -0700102 struct work_struct mhl_msc_send_work;
103 struct list_head list_cmd;
104 void (*msc_command_put_work) (struct msc_command_struct *);
105 struct msc_command_struct* (*msc_command_get_work) (void);
Manoj Rao14648742012-03-30 19:42:12 -0700106};
107
Manoj Rao7708a3a2012-12-13 18:30:58 -0800108#ifdef CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334
109enum mhl_gpio_type {
110 MHL_TX_RESET_GPIO,
111 MHL_TX_INTR_GPIO,
112 MHL_TX_PMIC_PWR_GPIO,
113 MHL_TX_MAX_GPIO,
114};
115
116enum mhl_vreg_type {
117 MHL_TX_3V_VREG,
118 MHL_TX_MAX_VREG,
119};
120
121
122struct mhl_tx_platform_data {
123 /* Data filled from device tree nodes */
124 struct dss_gpio *gpios[MHL_TX_MAX_GPIO];
125 struct dss_vreg *vregs[MHL_TX_MAX_VREG];
126 int irq;
127};
128
129struct mhl_tx_ctrl {
130 struct platform_device *pdev;
131 struct mhl_tx_platform_data *pdata;
132 struct i2c_client *i2c_handle;
133 uint8_t cur_state;
134 uint8_t chip_rev_id;
135 int mhl_mode;
136 struct completion rgnd_done;
137 void (*notify_usb_online)(int online);
138 struct usb_ext_notification *mhl_info;
139 bool disc_enabled;
140 struct power_supply mhl_psy;
141 bool vbus_active;
142 int current_val;
143 struct completion msc_cmd_done;
144 uint8_t devcap[16];
145 uint8_t devcap_state;
146 uint8_t path_en_state;
147 uint8_t (*tmds_enabled)(void);
148 struct work_struct mhl_msc_send_work;
149 struct list_head list_cmd;
150 struct input_dev *input;
151 struct workqueue_struct *msc_send_workqueue;
152 u16 *rcp_key_code_tbl;
153 size_t rcp_key_code_tbl_len;
Manoj Rao455c8c72013-01-21 16:44:08 -0800154 struct scrpd_struct scrpd;
155 int scrpd_busy;
156 int wr_burst_pending;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800157};
158
159int mhl_i2c_reg_read(struct i2c_client *client,
160 uint8_t slave_addr_index, uint8_t reg_offset);
161int mhl_i2c_reg_write(struct i2c_client *client,
162 uint8_t slave_addr_index, uint8_t reg_offset,
163 uint8_t value);
164void mhl_i2c_reg_modify(struct i2c_client *client,
165 uint8_t slave_addr_index, uint8_t reg_offset,
166 uint8_t mask, uint8_t val);
167
168#endif /* CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334 */
169
Manoj Rao14648742012-03-30 19:42:12 -0700170enum {
171 TX_PAGE_TPI = 0x00,
172 TX_PAGE_L0 = 0x01,
173 TX_PAGE_L1 = 0x02,
174 TX_PAGE_2 = 0x03,
175 TX_PAGE_3 = 0x04,
176 TX_PAGE_CBUS = 0x05,
177 TX_PAGE_DDC_EDID = 0x06,
178 TX_PAGE_DDC_SEGM = 0x07,
179};
180
181enum mhl_st_type {
182 POWER_STATE_D0_NO_MHL = 0,
183 POWER_STATE_D0_MHL = 2,
184 POWER_STATE_D3 = 3,
185};
186
187enum {
188 DEV_PAGE_TPI_0 = (0x72),
189 DEV_PAGE_TX_L0_0 = (0x72),
190 DEV_PAGE_TPI_1 = (0x76),
191 DEV_PAGE_TX_L0_1 = (0x76),
192 DEV_PAGE_TX_L1_0 = (0x7A),
193 DEV_PAGE_TX_L1_1 = (0x7E),
194 DEV_PAGE_TX_2_0 = (0x92),
195 DEV_PAGE_TX_2_1 = (0x96),
196 DEV_PAGE_TX_3_0 = (0x9A),
197 DEV_PAGE_TX_3_1 = (0x9E),
198 DEV_PAGE_CBUS = (0xC8),
199 DEV_PAGE_DDC_EDID = (0xA0),
200 DEV_PAGE_DDC_SEGM = (0x60),
201};
202
Manoj Raoe41ba162012-10-25 16:32:32 -0700203#define MHL_SII_PAGE0_RD(off) \
204 mhl_i2c_reg_read(client, TX_PAGE_L0, off)
205#define MHL_SII_PAGE0_WR(off, val) \
206 mhl_i2c_reg_write(client, TX_PAGE_L0, off, val)
207#define MHL_SII_PAGE0_MOD(off, mask, val) \
208 mhl_i2c_reg_modify(client, TX_PAGE_L0, off, mask, val)
209
210
211#define MHL_SII_PAGE1_RD(off) \
212 mhl_i2c_reg_read(client, TX_PAGE_L1, off)
213#define MHL_SII_PAGE1_WR(off, val) \
214 mhl_i2c_reg_write(client, TX_PAGE_L1, off, val)
215#define MHL_SII_PAGE1_MOD(off, mask, val) \
216 mhl_i2c_reg_modify(client, TX_PAGE_L1, off, mask, val)
217
218
219#define MHL_SII_PAGE2_RD(off) \
220 mhl_i2c_reg_read(client, TX_PAGE_2, off)
221#define MHL_SII_PAGE2_WR(off, val) \
222 mhl_i2c_reg_write(client, TX_PAGE_2, off, val)
223#define MHL_SII_PAGE2_MOD(off, mask, val) \
224 mhl_i2c_reg_modify(client, TX_PAGE_2, off, mask, val)
225
226
227#define MHL_SII_PAGE3_RD(off) \
228 mhl_i2c_reg_read(client, TX_PAGE_3, off)
229#define MHL_SII_PAGE3_WR(off, val) \
230 mhl_i2c_reg_write(client, TX_PAGE_3, off, val)
231#define MHL_SII_PAGE3_MOD(off, mask, val) \
232 mhl_i2c_reg_modify(client, TX_PAGE_3, off, mask, val)
233
234#define MHL_SII_CBUS_RD(off) \
235 mhl_i2c_reg_read(client, TX_PAGE_CBUS, off)
236#define MHL_SII_CBUS_WR(off, val) \
237 mhl_i2c_reg_write(client, TX_PAGE_CBUS, off, val)
238#define MHL_SII_CBUS_MOD(off, mask, val) \
239 mhl_i2c_reg_modify(client, TX_PAGE_CBUS, off, mask, val)
240
241#define REG_SRST ((TX_PAGE_3 << 16) | 0x0000)
242#define REG_INTR1 ((TX_PAGE_L0 << 16) | 0x0071)
243#define REG_INTR1_MASK ((TX_PAGE_L0 << 16) | 0x0075)
244#define REG_INTR2 ((TX_PAGE_L0 << 16) | 0x0072)
245#define REG_TMDS_CCTRL ((TX_PAGE_L0 << 16) | 0x0080)
246
247#define REG_DISC_CTRL1 ((TX_PAGE_3 << 16) | 0x0010)
248#define REG_DISC_CTRL2 ((TX_PAGE_3 << 16) | 0x0011)
249#define REG_DISC_CTRL3 ((TX_PAGE_3 << 16) | 0x0012)
250#define REG_DISC_CTRL4 ((TX_PAGE_3 << 16) | 0x0013)
251#define REG_DISC_CTRL5 ((TX_PAGE_3 << 16) | 0x0014)
252#define REG_DISC_CTRL6 ((TX_PAGE_3 << 16) | 0x0015)
253#define REG_DISC_CTRL7 ((TX_PAGE_3 << 16) | 0x0016)
254#define REG_DISC_CTRL8 ((TX_PAGE_3 << 16) | 0x0017)
255#define REG_DISC_CTRL9 ((TX_PAGE_3 << 16) | 0x0018)
256#define REG_DISC_CTRL10 ((TX_PAGE_3 << 16) | 0x0019)
257#define REG_DISC_CTRL11 ((TX_PAGE_3 << 16) | 0x001A)
258#define REG_DISC_STAT ((TX_PAGE_3 << 16) | 0x001B)
259#define REG_DISC_STAT2 ((TX_PAGE_3 << 16) | 0x001C)
260
261#define REG_INT_CTRL ((TX_PAGE_3 << 16) | 0x0020)
262#define REG_INTR4 ((TX_PAGE_3 << 16) | 0x0021)
263#define REG_INTR4_MASK ((TX_PAGE_3 << 16) | 0x0022)
264#define REG_INTR5 ((TX_PAGE_3 << 16) | 0x0023)
265#define REG_INTR5_MASK ((TX_PAGE_3 << 16) | 0x0024)
266
267#define REG_MHLTX_CTL1 ((TX_PAGE_3 << 16) | 0x0030)
268#define REG_MHLTX_CTL2 ((TX_PAGE_3 << 16) | 0x0031)
269#define REG_MHLTX_CTL3 ((TX_PAGE_3 << 16) | 0x0032)
270#define REG_MHLTX_CTL4 ((TX_PAGE_3 << 16) | 0x0033)
271#define REG_MHLTX_CTL5 ((TX_PAGE_3 << 16) | 0x0034)
272#define REG_MHLTX_CTL6 ((TX_PAGE_3 << 16) | 0x0035)
273#define REG_MHLTX_CTL7 ((TX_PAGE_3 << 16) | 0x0036)
274#define REG_MHLTX_CTL8 ((TX_PAGE_3 << 16) | 0x0037)
275
276#define REG_TMDS_CSTAT ((TX_PAGE_3 << 16) | 0x0040)
277
Manoj Rao7708a3a2012-12-13 18:30:58 -0800278#define REG_CBUS_INTR_STATUS ((TX_PAGE_CBUS << 16) | 0x0008)
Manoj Raoe41ba162012-10-25 16:32:32 -0700279#define REG_CBUS_INTR_ENABLE ((TX_PAGE_CBUS << 16) | 0x0009)
280
281#define REG_DDC_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000B)
282#define REG_CBUS_BUS_STATUS ((TX_PAGE_CBUS << 16) | 0x000A)
283#define REG_PRI_XFR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000D)
284#define REG_CBUS_PRI_FWR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000E)
285#define REG_CBUS_PRI_START ((TX_PAGE_CBUS << 16) | 0x0012)
286#define REG_CBUS_PRI_ADDR_CMD ((TX_PAGE_CBUS << 16) | 0x0013)
287#define REG_CBUS_PRI_WR_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0014)
288#define REG_CBUS_PRI_WR_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0015)
289#define REG_CBUS_PRI_RD_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0016)
290#define REG_CBUS_PRI_RD_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0017)
291#define REG_CBUS_PRI_VS_CMD ((TX_PAGE_CBUS << 16) | 0x0018)
292#define REG_CBUS_PRI_VS_DATA ((TX_PAGE_CBUS << 16) | 0x0019)
293#define REG_CBUS_MSC_RETRY_INTERVAL ((TX_PAGE_CBUS << 16) | 0x001A)
294#define REG_CBUS_DDC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001C)
295#define REG_CBUS_MSC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001D)
296#define REG_CBUS_MSC_INT2_STATUS ((TX_PAGE_CBUS << 16) | 0x001E)
297#define REG_CBUS_MSC_INT2_ENABLE ((TX_PAGE_CBUS << 16) | 0x001F)
298#define REG_MSC_WRITE_BURST_LEN ((TX_PAGE_CBUS << 16) | 0x0020)
299#define REG_MSC_HEARTBEAT_CONTROL ((TX_PAGE_CBUS << 16) | 0x0021)
300#define REG_MSC_TIMEOUT_LIMIT ((TX_PAGE_CBUS << 16) | 0x0022)
301#define REG_CBUS_LINK_CONTROL_1 ((TX_PAGE_CBUS << 16) | 0x0030)
302#define REG_CBUS_LINK_CONTROL_2 ((TX_PAGE_CBUS << 16) | 0x0031)
303#define REG_CBUS_LINK_CONTROL_3 ((TX_PAGE_CBUS << 16) | 0x0032)
304#define REG_CBUS_LINK_CONTROL_4 ((TX_PAGE_CBUS << 16) | 0x0033)
305#define REG_CBUS_LINK_CONTROL_5 ((TX_PAGE_CBUS << 16) | 0x0034)
306#define REG_CBUS_LINK_CONTROL_6 ((TX_PAGE_CBUS << 16) | 0x0035)
307#define REG_CBUS_LINK_CONTROL_7 ((TX_PAGE_CBUS << 16) | 0x0036)
308#define REG_CBUS_LINK_STATUS_1 ((TX_PAGE_CBUS << 16) | 0x0037)
309#define REG_CBUS_LINK_STATUS_2 ((TX_PAGE_CBUS << 16) | 0x0038)
310#define REG_CBUS_LINK_CONTROL_8 ((TX_PAGE_CBUS << 16) | 0x0039)
311#define REG_CBUS_LINK_CONTROL_9 ((TX_PAGE_CBUS << 16) | 0x003A)
312#define REG_CBUS_LINK_CONTROL_10 ((TX_PAGE_CBUS << 16) | 0x003B)
313#define REG_CBUS_LINK_CONTROL_11 ((TX_PAGE_CBUS << 16) | 0x003C)
314#define REG_CBUS_LINK_CONTROL_12 ((TX_PAGE_CBUS << 16) | 0x003D)
315
316
317#define REG_CBUS_LINK_CTRL9_0 ((TX_PAGE_CBUS << 16) | 0x003A)
318#define REG_CBUS_LINK_CTRL9_1 ((TX_PAGE_CBUS << 16) | 0x00BA)
319
320#define REG_CBUS_DRV_STRENGTH_0 ((TX_PAGE_CBUS << 16) | 0x0040)
321#define REG_CBUS_DRV_STRENGTH_1 ((TX_PAGE_CBUS << 16) | 0x0041)
322#define REG_CBUS_ACK_CONTROL ((TX_PAGE_CBUS << 16) | 0x0042)
323#define REG_CBUS_CAL_CONTROL ((TX_PAGE_CBUS << 16) | 0x0043)
324
325#define REG_CBUS_SCRATCHPAD_0 ((TX_PAGE_CBUS << 16) | 0x00C0)
326#define REG_CBUS_DEVICE_CAP_0 ((TX_PAGE_CBUS << 16) | 0x0080)
327#define REG_CBUS_DEVICE_CAP_1 ((TX_PAGE_CBUS << 16) | 0x0081)
328#define REG_CBUS_DEVICE_CAP_2 ((TX_PAGE_CBUS << 16) | 0x0082)
329#define REG_CBUS_DEVICE_CAP_3 ((TX_PAGE_CBUS << 16) | 0x0083)
330#define REG_CBUS_DEVICE_CAP_4 ((TX_PAGE_CBUS << 16) | 0x0084)
331#define REG_CBUS_DEVICE_CAP_5 ((TX_PAGE_CBUS << 16) | 0x0085)
332#define REG_CBUS_DEVICE_CAP_6 ((TX_PAGE_CBUS << 16) | 0x0086)
333#define REG_CBUS_DEVICE_CAP_7 ((TX_PAGE_CBUS << 16) | 0x0087)
334#define REG_CBUS_DEVICE_CAP_8 ((TX_PAGE_CBUS << 16) | 0x0088)
335#define REG_CBUS_DEVICE_CAP_9 ((TX_PAGE_CBUS << 16) | 0x0089)
336#define REG_CBUS_DEVICE_CAP_A ((TX_PAGE_CBUS << 16) | 0x008A)
337#define REG_CBUS_DEVICE_CAP_B ((TX_PAGE_CBUS << 16) | 0x008B)
338#define REG_CBUS_DEVICE_CAP_C ((TX_PAGE_CBUS << 16) | 0x008C)
339#define REG_CBUS_DEVICE_CAP_D ((TX_PAGE_CBUS << 16) | 0x008D)
340#define REG_CBUS_DEVICE_CAP_E ((TX_PAGE_CBUS << 16) | 0x008E)
341#define REG_CBUS_DEVICE_CAP_F ((TX_PAGE_CBUS << 16) | 0x008F)
342#define REG_CBUS_SET_INT_0 ((TX_PAGE_CBUS << 16) | 0x00A0)
343#define REG_CBUS_SET_INT_1 ((TX_PAGE_CBUS << 16) | 0x00A1)
344#define REG_CBUS_SET_INT_2 ((TX_PAGE_CBUS << 16) | 0x00A2)
345#define REG_CBUS_SET_INT_3 ((TX_PAGE_CBUS << 16) | 0x00A3)
346#define REG_CBUS_WRITE_STAT_0 ((TX_PAGE_CBUS << 16) | 0x00B0)
347#define REG_CBUS_WRITE_STAT_1 ((TX_PAGE_CBUS << 16) | 0x00B1)
348#define REG_CBUS_WRITE_STAT_2 ((TX_PAGE_CBUS << 16) | 0x00B2)
349#define REG_CBUS_WRITE_STAT_3 ((TX_PAGE_CBUS << 16) | 0x00B3)
350
Manoj Rao455c8c72013-01-21 16:44:08 -0800351#define GET_PAGE(x) ((x) >> 16)
352#define GET_OFF(x) ((x) & 0xffff)
Manoj Raoe41ba162012-10-25 16:32:32 -0700353
354
355#define MHL_SII_REG_NAME_RD(arg)\
356 mhl_i2c_reg_read(client, GET_PAGE(arg), GET_OFF(arg))
357#define MHL_SII_REG_NAME_WR(arg, val)\
358 mhl_i2c_reg_write(client, GET_PAGE(arg), GET_OFF(arg), val)
359#define MHL_SII_REG_NAME_MOD(arg, mask, val)\
360 mhl_i2c_reg_modify(client, GET_PAGE(arg), GET_OFF(arg), mask, val)
361
Manoj Rao14648742012-03-30 19:42:12 -0700362#endif /* __MHL_MSM_H__ */