aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/modem_if_u1/modem_link_device_mipi.h
blob: 8ca4968b870ca158bfb9acb29b72ac4b61962c11 (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
/*
 * Copyright (C) 2010 Google, Inc.
 * Copyright (C) 2010 Samsung Electronics.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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 __MODEM_LINK_DEVICE_MIPI_H__
#define __MODEM_LINK_DEVICE_MIPI_H__


#define HSI_MAX_CHANNELS	16
#define CHANNEL_MASK	0xFF

#define HSI_CHANNEL_TX_STATE_UNAVAIL	(1 << 0)
#define HSI_CHANNEL_TX_STATE_WRITING	(1 << 1)
#define HSI_CHANNEL_RX_STATE_UNAVAIL	(1 << 0)
#define HSI_CHANNEL_RX_STATE_READING	(1 << 1)

#define HSI_WRITE_DONE_TIMEOUT	(HZ)
#define HSI_READ_DONE_TIMEOUT	(HZ)
#define HSI_ACK_DONE_TIMEOUT	(HZ)
#define HSI_CLOSE_CONN_DONE_TIMEOUT	(HZ)
#define HSI_ACWAKE_DOWN_TIMEOUT	(HZ / 2)

#define HSI_CONTROL_CHANNEL	0
#define HSI_FLASHLESS_CHANNEL	0
#define HSI_CP_RAMDUMP_CHANNEL	0
#define HSI_FMT_CHANNEL	1
#define HSI_RAW_CHANNEL	2
#define HSI_RFS_CHANNEL	3
#define HSI_CMD_CHANNEL	4
#define HSI_NUM_OF_USE_CHANNELS	5

#define HSI_LL_INVALID_CHANNEL	0xFF

#define HSI_FLASHBOOT_ACK_LEN	16
#define DUMP_PACKET_SIZE	12289 /* 48K + 4 length, word unit */
#define DUMP_ERR_INFO_SIZE	39 /* 150 bytes + 4 length , word unit */

enum {
	HSI_LL_MSG_BREAK, /* 0x0 */
	HSI_LL_MSG_ECHO,
	HSI_LL_MSG_INFO_REQ,
	HSI_LL_MSG_INFO,
	HSI_LL_MSG_CONFIGURE,
	HSI_LL_MSG_ALLOCATE_CH,
	HSI_LL_MSG_RELEASE_CH,
	HSI_LL_MSG_OPEN_CONN,
	HSI_LL_MSG_CONN_READY,
	HSI_LL_MSG_CONN_CLOSED, /* 0x9 */
	HSI_LL_MSG_CANCEL_CONN,
	HSI_LL_MSG_ACK, /* 0xB */
	HSI_LL_MSG_NAK, /* 0xC */
	HSI_LL_MSG_CONF_RATE,
	HSI_LL_MSG_OPEN_CONN_OCTET, /* 0xE */
	HSI_LL_MSG_INVALID = 0xFF,
};

enum {
	STEP_UNDEF,
	STEP_CLOSED,
	STEP_NOT_READY,
	STEP_IDLE,
	STEP_ERROR,
	STEP_SEND_OPEN_CONN,
	STEP_SEND_ACK,
	STEP_WAIT_FOR_ACK,
	STEP_TO_ACK,
	STEP_SEND_NACK,
	STEP_GET_NACK,
	STEP_SEND_CONN_READY,
	STEP_WAIT_FOR_CONN_READY,
	STEP_SEND_CONF_RATE,
	STEP_WAIT_FOR_CONF_ACK,
	STEP_TX,
	STEP_RX,
	STEP_SEND_CONN_CLOSED,
	STEP_WAIT_FOR_CONN_CLOSED,
	STEP_SEND_BREAK,
};


struct if_hsi_channel {
	struct hsi_device *dev;
	unsigned int channel_id;

	u32 *tx_data;
	unsigned int tx_count;
	u32 *rx_data;
	unsigned int rx_count;
	unsigned int packet_size;

	unsigned int tx_state;
	unsigned int rx_state;
	spinlock_t tx_state_lock;
	spinlock_t rx_state_lock;

	unsigned int send_step;
	unsigned int recv_step;

	unsigned int got_nack;
	unsigned int acwake;
	spinlock_t acwake_lock;

	struct semaphore write_done_sem;
	struct semaphore ack_done_sem;
	struct semaphore close_conn_done_sem;

	unsigned int opened;
};

struct if_hsi_command {
	u32 command;
	struct list_head list;
};

struct mipi_link_device {
	struct link_device ld;

	/* mipi specific link data */
	struct if_hsi_channel hsi_channles[HSI_MAX_CHANNELS];
	struct list_head list_of_hsi_cmd;
	spinlock_t list_cmd_lock;

	struct workqueue_struct *mipi_wq;
	struct work_struct cmd_work;
	struct delayed_work start_work;

	struct wake_lock wlock;
	struct timer_list hsi_acwake_down_timer;
};
/* converts from struct link_device* to struct xxx_link_device* */
#define to_mipi_link_device(linkdev) \
			container_of(linkdev, struct mipi_link_device, ld)


enum {
	HSI_INIT_MODE_NORMAL,
	HSI_INIT_MODE_FLASHLESS_BOOT,
	HSI_INIT_MODE_CP_RAMDUMP,
};
static int hsi_init_handshake(struct mipi_link_device *mipi_ld, int mode);
static int if_hsi_write(struct if_hsi_channel *channel, u32 *data,
			unsigned int size);
static int if_hsi_protocol_send(struct mipi_link_device *mipi_ld, int ch,
			u32 *data, unsigned int len);
static int if_hsi_close_channel(struct if_hsi_channel *channel);

#endif