blob: f0a54ebd7a6a7dddfb8d4021eeacba43379a31b8 [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
Manoj Raoabedad42013-02-01 21:35:01 -080053/* MHL 8334 supports a max HD pixel clk of 75 MHz */
54#define MAX_MHL_PCLK 75000
Manoj Rao455c8c72013-01-21 16:44:08 -080055
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070056/* USB driver interface */
57
Manoj Raob554cf62012-11-27 21:27:38 -080058#if defined(CONFIG_FB_MSM_HDMI_MHL_8334)
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070059 /* mhl_device_discovery */
60extern int mhl_device_discovery(const char *name, int *result);
61
62/* - register|unregister MHL cable plug callback. */
63extern int mhl_register_callback
64 (const char *name, void (*callback)(int online));
65extern int mhl_unregister_callback(const char *name);
66#else
67static inline int mhl_device_discovery(const char *name, int *result)
68{
69 return -ENODEV;
70}
71
72static inline int
73 mhl_register_callback(const char *name, void (*callback)(int online))
74{
75 return -ENODEV;
76}
77
78static inline int mhl_unregister_callback(const char *name)
79{
80 return -ENODEV;
81}
82#endif
83
Manoj Rao907b7e02012-08-08 18:47:12 -070084struct msc_cmd_envelope {
85 /*
86 * this list head is for list APIs
87 */
88 struct list_head msc_queue_envelope;
89 struct msc_command_struct msc_cmd_msg;
90};
91
Manoj Rao14648742012-03-30 19:42:12 -070092struct mhl_msm_state_t {
93 struct i2c_client *i2c_client;
94 struct i2c_driver *i2c_driver;
95 uint8_t cur_state;
96 uint8_t chip_rev_id;
97 struct msm_mhl_platform_data *mhl_data;
Abhishek Kharbanda16c8ae22012-05-21 11:31:15 -070098 /* Device Discovery stuff */
99 int mhl_mode;
100 struct completion rgnd_done;
Manoj Raof7110b82012-07-29 22:29:02 -0700101 struct completion msc_cmd_done;
Abhishek Kharbanda569288f2013-07-01 11:52:08 -0700102 uint16_t devcap_state;
Manoj Raof7110b82012-07-29 22:29:02 -0700103 uint8_t path_en_state;
Manoj Rao907b7e02012-08-08 18:47:12 -0700104 struct work_struct mhl_msc_send_work;
105 struct list_head list_cmd;
106 void (*msc_command_put_work) (struct msc_command_struct *);
107 struct msc_command_struct* (*msc_command_get_work) (void);
Manoj Rao14648742012-03-30 19:42:12 -0700108};
109
Manoj Rao7708a3a2012-12-13 18:30:58 -0800110#ifdef CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334
111enum mhl_gpio_type {
112 MHL_TX_RESET_GPIO,
113 MHL_TX_INTR_GPIO,
114 MHL_TX_PMIC_PWR_GPIO,
115 MHL_TX_MAX_GPIO,
116};
117
118enum mhl_vreg_type {
119 MHL_TX_3V_VREG,
120 MHL_TX_MAX_VREG,
121};
122
123
124struct mhl_tx_platform_data {
125 /* Data filled from device tree nodes */
126 struct dss_gpio *gpios[MHL_TX_MAX_GPIO];
127 struct dss_vreg *vregs[MHL_TX_MAX_VREG];
128 int irq;
Manoj Raoabedad42013-02-01 21:35:01 -0800129 struct platform_device *hdmi_pdev;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800130};
131
132struct mhl_tx_ctrl {
133 struct platform_device *pdev;
134 struct mhl_tx_platform_data *pdata;
135 struct i2c_client *i2c_handle;
136 uint8_t cur_state;
137 uint8_t chip_rev_id;
138 int mhl_mode;
139 struct completion rgnd_done;
Jack Phamb7209152013-07-03 17:04:53 -0700140 void (*notify_usb_online)(void *ctx, int online);
141 void *notify_ctx;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800142 struct usb_ext_notification *mhl_info;
143 bool disc_enabled;
144 struct power_supply mhl_psy;
145 bool vbus_active;
146 int current_val;
147 struct completion msc_cmd_done;
148 uint8_t devcap[16];
Abhishek Kharbanda569288f2013-07-01 11:52:08 -0700149 uint16_t devcap_state;
Mukesh Jhac6a6f3b2013-05-13 08:48:33 -0700150 uint8_t status[2];
Manoj Rao7708a3a2012-12-13 18:30:58 -0800151 uint8_t path_en_state;
Manoj Raoabedad42013-02-01 21:35:01 -0800152 void *hdmi_mhl_ops;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800153 struct work_struct mhl_msc_send_work;
154 struct list_head list_cmd;
155 struct input_dev *input;
156 struct workqueue_struct *msc_send_workqueue;
157 u16 *rcp_key_code_tbl;
158 size_t rcp_key_code_tbl_len;
Manoj Rao455c8c72013-01-21 16:44:08 -0800159 struct scrpd_struct scrpd;
160 int scrpd_busy;
161 int wr_burst_pending;
Manoj Raof5b974a2013-03-08 18:42:52 -0800162 struct completion req_write_done;
Manoj Rao945e7522013-04-23 15:02:57 -0700163 spinlock_t lock;
164 bool tx_powered_off;
165 uint8_t dwnstream_hpd;
Manoj Rao68d47dd2013-05-21 21:05:57 -0700166 bool mhl_det_discon;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800167};
168
169int mhl_i2c_reg_read(struct i2c_client *client,
170 uint8_t slave_addr_index, uint8_t reg_offset);
171int mhl_i2c_reg_write(struct i2c_client *client,
172 uint8_t slave_addr_index, uint8_t reg_offset,
173 uint8_t value);
174void mhl_i2c_reg_modify(struct i2c_client *client,
175 uint8_t slave_addr_index, uint8_t reg_offset,
176 uint8_t mask, uint8_t val);
177
178#endif /* CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334 */
179
Manoj Rao14648742012-03-30 19:42:12 -0700180enum {
181 TX_PAGE_TPI = 0x00,
182 TX_PAGE_L0 = 0x01,
183 TX_PAGE_L1 = 0x02,
184 TX_PAGE_2 = 0x03,
185 TX_PAGE_3 = 0x04,
186 TX_PAGE_CBUS = 0x05,
187 TX_PAGE_DDC_EDID = 0x06,
188 TX_PAGE_DDC_SEGM = 0x07,
189};
190
191enum mhl_st_type {
192 POWER_STATE_D0_NO_MHL = 0,
193 POWER_STATE_D0_MHL = 2,
194 POWER_STATE_D3 = 3,
195};
196
197enum {
198 DEV_PAGE_TPI_0 = (0x72),
199 DEV_PAGE_TX_L0_0 = (0x72),
200 DEV_PAGE_TPI_1 = (0x76),
201 DEV_PAGE_TX_L0_1 = (0x76),
202 DEV_PAGE_TX_L1_0 = (0x7A),
203 DEV_PAGE_TX_L1_1 = (0x7E),
204 DEV_PAGE_TX_2_0 = (0x92),
205 DEV_PAGE_TX_2_1 = (0x96),
206 DEV_PAGE_TX_3_0 = (0x9A),
207 DEV_PAGE_TX_3_1 = (0x9E),
208 DEV_PAGE_CBUS = (0xC8),
209 DEV_PAGE_DDC_EDID = (0xA0),
210 DEV_PAGE_DDC_SEGM = (0x60),
211};
212
Manoj Raoe41ba162012-10-25 16:32:32 -0700213#define MHL_SII_PAGE0_RD(off) \
214 mhl_i2c_reg_read(client, TX_PAGE_L0, off)
215#define MHL_SII_PAGE0_WR(off, val) \
216 mhl_i2c_reg_write(client, TX_PAGE_L0, off, val)
217#define MHL_SII_PAGE0_MOD(off, mask, val) \
218 mhl_i2c_reg_modify(client, TX_PAGE_L0, off, mask, val)
219
220
221#define MHL_SII_PAGE1_RD(off) \
222 mhl_i2c_reg_read(client, TX_PAGE_L1, off)
223#define MHL_SII_PAGE1_WR(off, val) \
224 mhl_i2c_reg_write(client, TX_PAGE_L1, off, val)
225#define MHL_SII_PAGE1_MOD(off, mask, val) \
226 mhl_i2c_reg_modify(client, TX_PAGE_L1, off, mask, val)
227
228
229#define MHL_SII_PAGE2_RD(off) \
230 mhl_i2c_reg_read(client, TX_PAGE_2, off)
231#define MHL_SII_PAGE2_WR(off, val) \
232 mhl_i2c_reg_write(client, TX_PAGE_2, off, val)
233#define MHL_SII_PAGE2_MOD(off, mask, val) \
234 mhl_i2c_reg_modify(client, TX_PAGE_2, off, mask, val)
235
236
237#define MHL_SII_PAGE3_RD(off) \
238 mhl_i2c_reg_read(client, TX_PAGE_3, off)
239#define MHL_SII_PAGE3_WR(off, val) \
240 mhl_i2c_reg_write(client, TX_PAGE_3, off, val)
241#define MHL_SII_PAGE3_MOD(off, mask, val) \
242 mhl_i2c_reg_modify(client, TX_PAGE_3, off, mask, val)
243
244#define MHL_SII_CBUS_RD(off) \
245 mhl_i2c_reg_read(client, TX_PAGE_CBUS, off)
246#define MHL_SII_CBUS_WR(off, val) \
247 mhl_i2c_reg_write(client, TX_PAGE_CBUS, off, val)
248#define MHL_SII_CBUS_MOD(off, mask, val) \
249 mhl_i2c_reg_modify(client, TX_PAGE_CBUS, off, mask, val)
250
251#define REG_SRST ((TX_PAGE_3 << 16) | 0x0000)
252#define REG_INTR1 ((TX_PAGE_L0 << 16) | 0x0071)
253#define REG_INTR1_MASK ((TX_PAGE_L0 << 16) | 0x0075)
254#define REG_INTR2 ((TX_PAGE_L0 << 16) | 0x0072)
255#define REG_TMDS_CCTRL ((TX_PAGE_L0 << 16) | 0x0080)
256
257#define REG_DISC_CTRL1 ((TX_PAGE_3 << 16) | 0x0010)
258#define REG_DISC_CTRL2 ((TX_PAGE_3 << 16) | 0x0011)
259#define REG_DISC_CTRL3 ((TX_PAGE_3 << 16) | 0x0012)
260#define REG_DISC_CTRL4 ((TX_PAGE_3 << 16) | 0x0013)
261#define REG_DISC_CTRL5 ((TX_PAGE_3 << 16) | 0x0014)
262#define REG_DISC_CTRL6 ((TX_PAGE_3 << 16) | 0x0015)
263#define REG_DISC_CTRL7 ((TX_PAGE_3 << 16) | 0x0016)
264#define REG_DISC_CTRL8 ((TX_PAGE_3 << 16) | 0x0017)
265#define REG_DISC_CTRL9 ((TX_PAGE_3 << 16) | 0x0018)
266#define REG_DISC_CTRL10 ((TX_PAGE_3 << 16) | 0x0019)
267#define REG_DISC_CTRL11 ((TX_PAGE_3 << 16) | 0x001A)
268#define REG_DISC_STAT ((TX_PAGE_3 << 16) | 0x001B)
269#define REG_DISC_STAT2 ((TX_PAGE_3 << 16) | 0x001C)
270
271#define REG_INT_CTRL ((TX_PAGE_3 << 16) | 0x0020)
272#define REG_INTR4 ((TX_PAGE_3 << 16) | 0x0021)
273#define REG_INTR4_MASK ((TX_PAGE_3 << 16) | 0x0022)
274#define REG_INTR5 ((TX_PAGE_3 << 16) | 0x0023)
275#define REG_INTR5_MASK ((TX_PAGE_3 << 16) | 0x0024)
276
277#define REG_MHLTX_CTL1 ((TX_PAGE_3 << 16) | 0x0030)
278#define REG_MHLTX_CTL2 ((TX_PAGE_3 << 16) | 0x0031)
279#define REG_MHLTX_CTL3 ((TX_PAGE_3 << 16) | 0x0032)
280#define REG_MHLTX_CTL4 ((TX_PAGE_3 << 16) | 0x0033)
281#define REG_MHLTX_CTL5 ((TX_PAGE_3 << 16) | 0x0034)
282#define REG_MHLTX_CTL6 ((TX_PAGE_3 << 16) | 0x0035)
283#define REG_MHLTX_CTL7 ((TX_PAGE_3 << 16) | 0x0036)
284#define REG_MHLTX_CTL8 ((TX_PAGE_3 << 16) | 0x0037)
285
286#define REG_TMDS_CSTAT ((TX_PAGE_3 << 16) | 0x0040)
287
Manoj Rao7708a3a2012-12-13 18:30:58 -0800288#define REG_CBUS_INTR_STATUS ((TX_PAGE_CBUS << 16) | 0x0008)
Manoj Raoe41ba162012-10-25 16:32:32 -0700289#define REG_CBUS_INTR_ENABLE ((TX_PAGE_CBUS << 16) | 0x0009)
290
291#define REG_DDC_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000B)
292#define REG_CBUS_BUS_STATUS ((TX_PAGE_CBUS << 16) | 0x000A)
293#define REG_PRI_XFR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000D)
294#define REG_CBUS_PRI_FWR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000E)
295#define REG_CBUS_PRI_START ((TX_PAGE_CBUS << 16) | 0x0012)
296#define REG_CBUS_PRI_ADDR_CMD ((TX_PAGE_CBUS << 16) | 0x0013)
297#define REG_CBUS_PRI_WR_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0014)
298#define REG_CBUS_PRI_WR_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0015)
299#define REG_CBUS_PRI_RD_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0016)
300#define REG_CBUS_PRI_RD_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0017)
301#define REG_CBUS_PRI_VS_CMD ((TX_PAGE_CBUS << 16) | 0x0018)
302#define REG_CBUS_PRI_VS_DATA ((TX_PAGE_CBUS << 16) | 0x0019)
303#define REG_CBUS_MSC_RETRY_INTERVAL ((TX_PAGE_CBUS << 16) | 0x001A)
304#define REG_CBUS_DDC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001C)
305#define REG_CBUS_MSC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001D)
306#define REG_CBUS_MSC_INT2_STATUS ((TX_PAGE_CBUS << 16) | 0x001E)
307#define REG_CBUS_MSC_INT2_ENABLE ((TX_PAGE_CBUS << 16) | 0x001F)
308#define REG_MSC_WRITE_BURST_LEN ((TX_PAGE_CBUS << 16) | 0x0020)
309#define REG_MSC_HEARTBEAT_CONTROL ((TX_PAGE_CBUS << 16) | 0x0021)
310#define REG_MSC_TIMEOUT_LIMIT ((TX_PAGE_CBUS << 16) | 0x0022)
311#define REG_CBUS_LINK_CONTROL_1 ((TX_PAGE_CBUS << 16) | 0x0030)
312#define REG_CBUS_LINK_CONTROL_2 ((TX_PAGE_CBUS << 16) | 0x0031)
313#define REG_CBUS_LINK_CONTROL_3 ((TX_PAGE_CBUS << 16) | 0x0032)
314#define REG_CBUS_LINK_CONTROL_4 ((TX_PAGE_CBUS << 16) | 0x0033)
315#define REG_CBUS_LINK_CONTROL_5 ((TX_PAGE_CBUS << 16) | 0x0034)
316#define REG_CBUS_LINK_CONTROL_6 ((TX_PAGE_CBUS << 16) | 0x0035)
317#define REG_CBUS_LINK_CONTROL_7 ((TX_PAGE_CBUS << 16) | 0x0036)
318#define REG_CBUS_LINK_STATUS_1 ((TX_PAGE_CBUS << 16) | 0x0037)
319#define REG_CBUS_LINK_STATUS_2 ((TX_PAGE_CBUS << 16) | 0x0038)
320#define REG_CBUS_LINK_CONTROL_8 ((TX_PAGE_CBUS << 16) | 0x0039)
321#define REG_CBUS_LINK_CONTROL_9 ((TX_PAGE_CBUS << 16) | 0x003A)
322#define REG_CBUS_LINK_CONTROL_10 ((TX_PAGE_CBUS << 16) | 0x003B)
323#define REG_CBUS_LINK_CONTROL_11 ((TX_PAGE_CBUS << 16) | 0x003C)
324#define REG_CBUS_LINK_CONTROL_12 ((TX_PAGE_CBUS << 16) | 0x003D)
325
326
327#define REG_CBUS_LINK_CTRL9_0 ((TX_PAGE_CBUS << 16) | 0x003A)
328#define REG_CBUS_LINK_CTRL9_1 ((TX_PAGE_CBUS << 16) | 0x00BA)
329
330#define REG_CBUS_DRV_STRENGTH_0 ((TX_PAGE_CBUS << 16) | 0x0040)
331#define REG_CBUS_DRV_STRENGTH_1 ((TX_PAGE_CBUS << 16) | 0x0041)
332#define REG_CBUS_ACK_CONTROL ((TX_PAGE_CBUS << 16) | 0x0042)
333#define REG_CBUS_CAL_CONTROL ((TX_PAGE_CBUS << 16) | 0x0043)
334
335#define REG_CBUS_SCRATCHPAD_0 ((TX_PAGE_CBUS << 16) | 0x00C0)
336#define REG_CBUS_DEVICE_CAP_0 ((TX_PAGE_CBUS << 16) | 0x0080)
337#define REG_CBUS_DEVICE_CAP_1 ((TX_PAGE_CBUS << 16) | 0x0081)
338#define REG_CBUS_DEVICE_CAP_2 ((TX_PAGE_CBUS << 16) | 0x0082)
339#define REG_CBUS_DEVICE_CAP_3 ((TX_PAGE_CBUS << 16) | 0x0083)
340#define REG_CBUS_DEVICE_CAP_4 ((TX_PAGE_CBUS << 16) | 0x0084)
341#define REG_CBUS_DEVICE_CAP_5 ((TX_PAGE_CBUS << 16) | 0x0085)
342#define REG_CBUS_DEVICE_CAP_6 ((TX_PAGE_CBUS << 16) | 0x0086)
343#define REG_CBUS_DEVICE_CAP_7 ((TX_PAGE_CBUS << 16) | 0x0087)
344#define REG_CBUS_DEVICE_CAP_8 ((TX_PAGE_CBUS << 16) | 0x0088)
345#define REG_CBUS_DEVICE_CAP_9 ((TX_PAGE_CBUS << 16) | 0x0089)
346#define REG_CBUS_DEVICE_CAP_A ((TX_PAGE_CBUS << 16) | 0x008A)
347#define REG_CBUS_DEVICE_CAP_B ((TX_PAGE_CBUS << 16) | 0x008B)
348#define REG_CBUS_DEVICE_CAP_C ((TX_PAGE_CBUS << 16) | 0x008C)
349#define REG_CBUS_DEVICE_CAP_D ((TX_PAGE_CBUS << 16) | 0x008D)
350#define REG_CBUS_DEVICE_CAP_E ((TX_PAGE_CBUS << 16) | 0x008E)
351#define REG_CBUS_DEVICE_CAP_F ((TX_PAGE_CBUS << 16) | 0x008F)
352#define REG_CBUS_SET_INT_0 ((TX_PAGE_CBUS << 16) | 0x00A0)
353#define REG_CBUS_SET_INT_1 ((TX_PAGE_CBUS << 16) | 0x00A1)
354#define REG_CBUS_SET_INT_2 ((TX_PAGE_CBUS << 16) | 0x00A2)
355#define REG_CBUS_SET_INT_3 ((TX_PAGE_CBUS << 16) | 0x00A3)
356#define REG_CBUS_WRITE_STAT_0 ((TX_PAGE_CBUS << 16) | 0x00B0)
357#define REG_CBUS_WRITE_STAT_1 ((TX_PAGE_CBUS << 16) | 0x00B1)
358#define REG_CBUS_WRITE_STAT_2 ((TX_PAGE_CBUS << 16) | 0x00B2)
359#define REG_CBUS_WRITE_STAT_3 ((TX_PAGE_CBUS << 16) | 0x00B3)
360
Manoj Rao455c8c72013-01-21 16:44:08 -0800361#define GET_PAGE(x) ((x) >> 16)
362#define GET_OFF(x) ((x) & 0xffff)
Manoj Raoe41ba162012-10-25 16:32:32 -0700363
364
365#define MHL_SII_REG_NAME_RD(arg)\
366 mhl_i2c_reg_read(client, GET_PAGE(arg), GET_OFF(arg))
367#define MHL_SII_REG_NAME_WR(arg, val)\
368 mhl_i2c_reg_write(client, GET_PAGE(arg), GET_OFF(arg), val)
369#define MHL_SII_REG_NAME_MOD(arg, mask, val)\
370 mhl_i2c_reg_modify(client, GET_PAGE(arg), GET_OFF(arg), mask, val)
371
Manoj Rao14648742012-03-30 19:42:12 -0700372#endif /* __MHL_MSM_H__ */