blob: d6f8356f5df203e333ae1bd3eb753bd9498b8100 [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;
102 uint8_t devcap_state;
103 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;
140 void (*notify_usb_online)(int online);
141 struct usb_ext_notification *mhl_info;
142 bool disc_enabled;
143 struct power_supply mhl_psy;
144 bool vbus_active;
145 int current_val;
146 struct completion msc_cmd_done;
147 uint8_t devcap[16];
148 uint8_t devcap_state;
149 uint8_t path_en_state;
Manoj Raoabedad42013-02-01 21:35:01 -0800150 void *hdmi_mhl_ops;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800151 struct work_struct mhl_msc_send_work;
152 struct list_head list_cmd;
153 struct input_dev *input;
154 struct workqueue_struct *msc_send_workqueue;
155 u16 *rcp_key_code_tbl;
156 size_t rcp_key_code_tbl_len;
Manoj Rao455c8c72013-01-21 16:44:08 -0800157 struct scrpd_struct scrpd;
158 int scrpd_busy;
159 int wr_burst_pending;
Manoj Rao7708a3a2012-12-13 18:30:58 -0800160};
161
162int mhl_i2c_reg_read(struct i2c_client *client,
163 uint8_t slave_addr_index, uint8_t reg_offset);
164int mhl_i2c_reg_write(struct i2c_client *client,
165 uint8_t slave_addr_index, uint8_t reg_offset,
166 uint8_t value);
167void mhl_i2c_reg_modify(struct i2c_client *client,
168 uint8_t slave_addr_index, uint8_t reg_offset,
169 uint8_t mask, uint8_t val);
170
171#endif /* CONFIG_FB_MSM_MDSS_HDMI_MHL_SII8334 */
172
Manoj Rao14648742012-03-30 19:42:12 -0700173enum {
174 TX_PAGE_TPI = 0x00,
175 TX_PAGE_L0 = 0x01,
176 TX_PAGE_L1 = 0x02,
177 TX_PAGE_2 = 0x03,
178 TX_PAGE_3 = 0x04,
179 TX_PAGE_CBUS = 0x05,
180 TX_PAGE_DDC_EDID = 0x06,
181 TX_PAGE_DDC_SEGM = 0x07,
182};
183
184enum mhl_st_type {
185 POWER_STATE_D0_NO_MHL = 0,
186 POWER_STATE_D0_MHL = 2,
187 POWER_STATE_D3 = 3,
188};
189
190enum {
191 DEV_PAGE_TPI_0 = (0x72),
192 DEV_PAGE_TX_L0_0 = (0x72),
193 DEV_PAGE_TPI_1 = (0x76),
194 DEV_PAGE_TX_L0_1 = (0x76),
195 DEV_PAGE_TX_L1_0 = (0x7A),
196 DEV_PAGE_TX_L1_1 = (0x7E),
197 DEV_PAGE_TX_2_0 = (0x92),
198 DEV_PAGE_TX_2_1 = (0x96),
199 DEV_PAGE_TX_3_0 = (0x9A),
200 DEV_PAGE_TX_3_1 = (0x9E),
201 DEV_PAGE_CBUS = (0xC8),
202 DEV_PAGE_DDC_EDID = (0xA0),
203 DEV_PAGE_DDC_SEGM = (0x60),
204};
205
Manoj Raoe41ba162012-10-25 16:32:32 -0700206#define MHL_SII_PAGE0_RD(off) \
207 mhl_i2c_reg_read(client, TX_PAGE_L0, off)
208#define MHL_SII_PAGE0_WR(off, val) \
209 mhl_i2c_reg_write(client, TX_PAGE_L0, off, val)
210#define MHL_SII_PAGE0_MOD(off, mask, val) \
211 mhl_i2c_reg_modify(client, TX_PAGE_L0, off, mask, val)
212
213
214#define MHL_SII_PAGE1_RD(off) \
215 mhl_i2c_reg_read(client, TX_PAGE_L1, off)
216#define MHL_SII_PAGE1_WR(off, val) \
217 mhl_i2c_reg_write(client, TX_PAGE_L1, off, val)
218#define MHL_SII_PAGE1_MOD(off, mask, val) \
219 mhl_i2c_reg_modify(client, TX_PAGE_L1, off, mask, val)
220
221
222#define MHL_SII_PAGE2_RD(off) \
223 mhl_i2c_reg_read(client, TX_PAGE_2, off)
224#define MHL_SII_PAGE2_WR(off, val) \
225 mhl_i2c_reg_write(client, TX_PAGE_2, off, val)
226#define MHL_SII_PAGE2_MOD(off, mask, val) \
227 mhl_i2c_reg_modify(client, TX_PAGE_2, off, mask, val)
228
229
230#define MHL_SII_PAGE3_RD(off) \
231 mhl_i2c_reg_read(client, TX_PAGE_3, off)
232#define MHL_SII_PAGE3_WR(off, val) \
233 mhl_i2c_reg_write(client, TX_PAGE_3, off, val)
234#define MHL_SII_PAGE3_MOD(off, mask, val) \
235 mhl_i2c_reg_modify(client, TX_PAGE_3, off, mask, val)
236
237#define MHL_SII_CBUS_RD(off) \
238 mhl_i2c_reg_read(client, TX_PAGE_CBUS, off)
239#define MHL_SII_CBUS_WR(off, val) \
240 mhl_i2c_reg_write(client, TX_PAGE_CBUS, off, val)
241#define MHL_SII_CBUS_MOD(off, mask, val) \
242 mhl_i2c_reg_modify(client, TX_PAGE_CBUS, off, mask, val)
243
244#define REG_SRST ((TX_PAGE_3 << 16) | 0x0000)
245#define REG_INTR1 ((TX_PAGE_L0 << 16) | 0x0071)
246#define REG_INTR1_MASK ((TX_PAGE_L0 << 16) | 0x0075)
247#define REG_INTR2 ((TX_PAGE_L0 << 16) | 0x0072)
248#define REG_TMDS_CCTRL ((TX_PAGE_L0 << 16) | 0x0080)
249
250#define REG_DISC_CTRL1 ((TX_PAGE_3 << 16) | 0x0010)
251#define REG_DISC_CTRL2 ((TX_PAGE_3 << 16) | 0x0011)
252#define REG_DISC_CTRL3 ((TX_PAGE_3 << 16) | 0x0012)
253#define REG_DISC_CTRL4 ((TX_PAGE_3 << 16) | 0x0013)
254#define REG_DISC_CTRL5 ((TX_PAGE_3 << 16) | 0x0014)
255#define REG_DISC_CTRL6 ((TX_PAGE_3 << 16) | 0x0015)
256#define REG_DISC_CTRL7 ((TX_PAGE_3 << 16) | 0x0016)
257#define REG_DISC_CTRL8 ((TX_PAGE_3 << 16) | 0x0017)
258#define REG_DISC_CTRL9 ((TX_PAGE_3 << 16) | 0x0018)
259#define REG_DISC_CTRL10 ((TX_PAGE_3 << 16) | 0x0019)
260#define REG_DISC_CTRL11 ((TX_PAGE_3 << 16) | 0x001A)
261#define REG_DISC_STAT ((TX_PAGE_3 << 16) | 0x001B)
262#define REG_DISC_STAT2 ((TX_PAGE_3 << 16) | 0x001C)
263
264#define REG_INT_CTRL ((TX_PAGE_3 << 16) | 0x0020)
265#define REG_INTR4 ((TX_PAGE_3 << 16) | 0x0021)
266#define REG_INTR4_MASK ((TX_PAGE_3 << 16) | 0x0022)
267#define REG_INTR5 ((TX_PAGE_3 << 16) | 0x0023)
268#define REG_INTR5_MASK ((TX_PAGE_3 << 16) | 0x0024)
269
270#define REG_MHLTX_CTL1 ((TX_PAGE_3 << 16) | 0x0030)
271#define REG_MHLTX_CTL2 ((TX_PAGE_3 << 16) | 0x0031)
272#define REG_MHLTX_CTL3 ((TX_PAGE_3 << 16) | 0x0032)
273#define REG_MHLTX_CTL4 ((TX_PAGE_3 << 16) | 0x0033)
274#define REG_MHLTX_CTL5 ((TX_PAGE_3 << 16) | 0x0034)
275#define REG_MHLTX_CTL6 ((TX_PAGE_3 << 16) | 0x0035)
276#define REG_MHLTX_CTL7 ((TX_PAGE_3 << 16) | 0x0036)
277#define REG_MHLTX_CTL8 ((TX_PAGE_3 << 16) | 0x0037)
278
279#define REG_TMDS_CSTAT ((TX_PAGE_3 << 16) | 0x0040)
280
Manoj Rao7708a3a2012-12-13 18:30:58 -0800281#define REG_CBUS_INTR_STATUS ((TX_PAGE_CBUS << 16) | 0x0008)
Manoj Raoe41ba162012-10-25 16:32:32 -0700282#define REG_CBUS_INTR_ENABLE ((TX_PAGE_CBUS << 16) | 0x0009)
283
284#define REG_DDC_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000B)
285#define REG_CBUS_BUS_STATUS ((TX_PAGE_CBUS << 16) | 0x000A)
286#define REG_PRI_XFR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000D)
287#define REG_CBUS_PRI_FWR_ABORT_REASON ((TX_PAGE_CBUS << 16) | 0x000E)
288#define REG_CBUS_PRI_START ((TX_PAGE_CBUS << 16) | 0x0012)
289#define REG_CBUS_PRI_ADDR_CMD ((TX_PAGE_CBUS << 16) | 0x0013)
290#define REG_CBUS_PRI_WR_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0014)
291#define REG_CBUS_PRI_WR_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0015)
292#define REG_CBUS_PRI_RD_DATA_1ST ((TX_PAGE_CBUS << 16) | 0x0016)
293#define REG_CBUS_PRI_RD_DATA_2ND ((TX_PAGE_CBUS << 16) | 0x0017)
294#define REG_CBUS_PRI_VS_CMD ((TX_PAGE_CBUS << 16) | 0x0018)
295#define REG_CBUS_PRI_VS_DATA ((TX_PAGE_CBUS << 16) | 0x0019)
296#define REG_CBUS_MSC_RETRY_INTERVAL ((TX_PAGE_CBUS << 16) | 0x001A)
297#define REG_CBUS_DDC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001C)
298#define REG_CBUS_MSC_FAIL_LIMIT ((TX_PAGE_CBUS << 16) | 0x001D)
299#define REG_CBUS_MSC_INT2_STATUS ((TX_PAGE_CBUS << 16) | 0x001E)
300#define REG_CBUS_MSC_INT2_ENABLE ((TX_PAGE_CBUS << 16) | 0x001F)
301#define REG_MSC_WRITE_BURST_LEN ((TX_PAGE_CBUS << 16) | 0x0020)
302#define REG_MSC_HEARTBEAT_CONTROL ((TX_PAGE_CBUS << 16) | 0x0021)
303#define REG_MSC_TIMEOUT_LIMIT ((TX_PAGE_CBUS << 16) | 0x0022)
304#define REG_CBUS_LINK_CONTROL_1 ((TX_PAGE_CBUS << 16) | 0x0030)
305#define REG_CBUS_LINK_CONTROL_2 ((TX_PAGE_CBUS << 16) | 0x0031)
306#define REG_CBUS_LINK_CONTROL_3 ((TX_PAGE_CBUS << 16) | 0x0032)
307#define REG_CBUS_LINK_CONTROL_4 ((TX_PAGE_CBUS << 16) | 0x0033)
308#define REG_CBUS_LINK_CONTROL_5 ((TX_PAGE_CBUS << 16) | 0x0034)
309#define REG_CBUS_LINK_CONTROL_6 ((TX_PAGE_CBUS << 16) | 0x0035)
310#define REG_CBUS_LINK_CONTROL_7 ((TX_PAGE_CBUS << 16) | 0x0036)
311#define REG_CBUS_LINK_STATUS_1 ((TX_PAGE_CBUS << 16) | 0x0037)
312#define REG_CBUS_LINK_STATUS_2 ((TX_PAGE_CBUS << 16) | 0x0038)
313#define REG_CBUS_LINK_CONTROL_8 ((TX_PAGE_CBUS << 16) | 0x0039)
314#define REG_CBUS_LINK_CONTROL_9 ((TX_PAGE_CBUS << 16) | 0x003A)
315#define REG_CBUS_LINK_CONTROL_10 ((TX_PAGE_CBUS << 16) | 0x003B)
316#define REG_CBUS_LINK_CONTROL_11 ((TX_PAGE_CBUS << 16) | 0x003C)
317#define REG_CBUS_LINK_CONTROL_12 ((TX_PAGE_CBUS << 16) | 0x003D)
318
319
320#define REG_CBUS_LINK_CTRL9_0 ((TX_PAGE_CBUS << 16) | 0x003A)
321#define REG_CBUS_LINK_CTRL9_1 ((TX_PAGE_CBUS << 16) | 0x00BA)
322
323#define REG_CBUS_DRV_STRENGTH_0 ((TX_PAGE_CBUS << 16) | 0x0040)
324#define REG_CBUS_DRV_STRENGTH_1 ((TX_PAGE_CBUS << 16) | 0x0041)
325#define REG_CBUS_ACK_CONTROL ((TX_PAGE_CBUS << 16) | 0x0042)
326#define REG_CBUS_CAL_CONTROL ((TX_PAGE_CBUS << 16) | 0x0043)
327
328#define REG_CBUS_SCRATCHPAD_0 ((TX_PAGE_CBUS << 16) | 0x00C0)
329#define REG_CBUS_DEVICE_CAP_0 ((TX_PAGE_CBUS << 16) | 0x0080)
330#define REG_CBUS_DEVICE_CAP_1 ((TX_PAGE_CBUS << 16) | 0x0081)
331#define REG_CBUS_DEVICE_CAP_2 ((TX_PAGE_CBUS << 16) | 0x0082)
332#define REG_CBUS_DEVICE_CAP_3 ((TX_PAGE_CBUS << 16) | 0x0083)
333#define REG_CBUS_DEVICE_CAP_4 ((TX_PAGE_CBUS << 16) | 0x0084)
334#define REG_CBUS_DEVICE_CAP_5 ((TX_PAGE_CBUS << 16) | 0x0085)
335#define REG_CBUS_DEVICE_CAP_6 ((TX_PAGE_CBUS << 16) | 0x0086)
336#define REG_CBUS_DEVICE_CAP_7 ((TX_PAGE_CBUS << 16) | 0x0087)
337#define REG_CBUS_DEVICE_CAP_8 ((TX_PAGE_CBUS << 16) | 0x0088)
338#define REG_CBUS_DEVICE_CAP_9 ((TX_PAGE_CBUS << 16) | 0x0089)
339#define REG_CBUS_DEVICE_CAP_A ((TX_PAGE_CBUS << 16) | 0x008A)
340#define REG_CBUS_DEVICE_CAP_B ((TX_PAGE_CBUS << 16) | 0x008B)
341#define REG_CBUS_DEVICE_CAP_C ((TX_PAGE_CBUS << 16) | 0x008C)
342#define REG_CBUS_DEVICE_CAP_D ((TX_PAGE_CBUS << 16) | 0x008D)
343#define REG_CBUS_DEVICE_CAP_E ((TX_PAGE_CBUS << 16) | 0x008E)
344#define REG_CBUS_DEVICE_CAP_F ((TX_PAGE_CBUS << 16) | 0x008F)
345#define REG_CBUS_SET_INT_0 ((TX_PAGE_CBUS << 16) | 0x00A0)
346#define REG_CBUS_SET_INT_1 ((TX_PAGE_CBUS << 16) | 0x00A1)
347#define REG_CBUS_SET_INT_2 ((TX_PAGE_CBUS << 16) | 0x00A2)
348#define REG_CBUS_SET_INT_3 ((TX_PAGE_CBUS << 16) | 0x00A3)
349#define REG_CBUS_WRITE_STAT_0 ((TX_PAGE_CBUS << 16) | 0x00B0)
350#define REG_CBUS_WRITE_STAT_1 ((TX_PAGE_CBUS << 16) | 0x00B1)
351#define REG_CBUS_WRITE_STAT_2 ((TX_PAGE_CBUS << 16) | 0x00B2)
352#define REG_CBUS_WRITE_STAT_3 ((TX_PAGE_CBUS << 16) | 0x00B3)
353
Manoj Rao455c8c72013-01-21 16:44:08 -0800354#define GET_PAGE(x) ((x) >> 16)
355#define GET_OFF(x) ((x) & 0xffff)
Manoj Raoe41ba162012-10-25 16:32:32 -0700356
357
358#define MHL_SII_REG_NAME_RD(arg)\
359 mhl_i2c_reg_read(client, GET_PAGE(arg), GET_OFF(arg))
360#define MHL_SII_REG_NAME_WR(arg, val)\
361 mhl_i2c_reg_write(client, GET_PAGE(arg), GET_OFF(arg), val)
362#define MHL_SII_REG_NAME_MOD(arg, mask, val)\
363 mhl_i2c_reg_modify(client, GET_PAGE(arg), GET_OFF(arg), mask, val)
364
Manoj Rao14648742012-03-30 19:42:12 -0700365#endif /* __MHL_MSM_H__ */