Blame view

include/linux/memstick.h 9.73 KB
baf8532a1   Alex Dubov   memstick: initial...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  /*
   *  Sony MemoryStick support
   *
   *  Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   */
  
  #ifndef _MEMSTICK_H
  #define _MEMSTICK_H
  
  #include <linux/workqueue.h>
  #include <linux/scatterlist.h>
  #include <linux/device.h>
  
  /*** Hardware based structures ***/
  
  struct ms_status_register {
  	unsigned char reserved;
  	unsigned char interrupt;
8e82f8c34   Alex Dubov   memstick: fix MSP...
24
25
26
27
28
29
  #define MEMSTICK_INT_CMDNAK 0x01
  #define MEMSTICK_INT_IOREQ  0x08
  #define MEMSTICK_INT_IOBREQ 0x10
  #define MEMSTICK_INT_BREQ   0x20
  #define MEMSTICK_INT_ERR    0x40
  #define MEMSTICK_INT_CED    0x80
baf8532a1   Alex Dubov   memstick: initial...
30
31
  
  	unsigned char status0;
8e82f8c34   Alex Dubov   memstick: fix MSP...
32
33
34
35
36
37
  #define MEMSTICK_STATUS0_WP  0x01
  #define MEMSTICK_STATUS0_SL  0x02
  #define MEMSTICK_STATUS0_BF  0x10
  #define MEMSTICK_STATUS0_BE  0x20
  #define MEMSTICK_STATUS0_FB0 0x40
  #define MEMSTICK_STATUS0_MB  0x80
baf8532a1   Alex Dubov   memstick: initial...
38
39
  
  	unsigned char status1;
8e82f8c34   Alex Dubov   memstick: fix MSP...
40
41
42
43
44
45
46
47
  #define MEMSTICK_STATUS1_UCFG 0x01
  #define MEMSTICK_STATUS1_FGER 0x02
  #define MEMSTICK_STATUS1_UCEX 0x04
  #define MEMSTICK_STATUS1_EXER 0x08
  #define MEMSTICK_STATUS1_UCDT 0x10
  #define MEMSTICK_STATUS1_DTER 0x20
  #define MEMSTICK_STATUS1_FB1  0x40
  #define MEMSTICK_STATUS1_MB   0x80
baf8532a1   Alex Dubov   memstick: initial...
48
49
50
51
  } __attribute__((packed));
  
  struct ms_id_register {
  	unsigned char type;
e1f19995f   Alex Dubov   memstick: introdu...
52
  	unsigned char if_mode;
baf8532a1   Alex Dubov   memstick: initial...
53
54
55
56
57
58
  	unsigned char category;
  	unsigned char class;
  } __attribute__((packed));
  
  struct ms_param_register {
  	unsigned char system;
e1f19995f   Alex Dubov   memstick: introdu...
59
  #define MEMSTICK_SYS_PAM  0x08
8e82f8c34   Alex Dubov   memstick: fix MSP...
60
  #define MEMSTICK_SYS_BAMD 0x80
e1f19995f   Alex Dubov   memstick: introdu...
61

baf8532a1   Alex Dubov   memstick: initial...
62
63
64
  	unsigned char block_address_msb;
  	unsigned short block_address;
  	unsigned char cp;
8e82f8c34   Alex Dubov   memstick: fix MSP...
65
66
67
68
  #define MEMSTICK_CP_BLOCK     0x00
  #define MEMSTICK_CP_PAGE      0x20
  #define MEMSTICK_CP_EXTRA     0x40
  #define MEMSTICK_CP_OVERWRITE 0x80
baf8532a1   Alex Dubov   memstick: initial...
69
70
71
72
73
74
  
  	unsigned char page_address;
  } __attribute__((packed));
  
  struct ms_extra_data_register {
  	unsigned char  overwrite_flag;
8e82f8c34   Alex Dubov   memstick: fix MSP...
75
76
77
78
  #define MEMSTICK_OVERWRITE_UDST  0x10
  #define MEMSTICK_OVERWRITE_PGST1 0x20
  #define MEMSTICK_OVERWRITE_PGST0 0x40
  #define MEMSTICK_OVERWRITE_BKST  0x80
baf8532a1   Alex Dubov   memstick: initial...
79
80
  
  	unsigned char  management_flag;
8e82f8c34   Alex Dubov   memstick: fix MSP...
81
82
83
84
  #define MEMSTICK_MANAGEMENT_SYSFLG 0x04
  #define MEMSTICK_MANAGEMENT_ATFLG  0x08
  #define MEMSTICK_MANAGEMENT_SCMS1  0x10
  #define MEMSTICK_MANAGEMENT_SCMS0  0x20
baf8532a1   Alex Dubov   memstick: initial...
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  
  	unsigned short logical_address;
  } __attribute__((packed));
  
  struct ms_register {
  	struct ms_status_register     status;
  	struct ms_id_register         id;
  	unsigned char                 reserved[8];
  	struct ms_param_register      param;
  	struct ms_extra_data_register extra_data;
  } __attribute__((packed));
  
  struct mspro_param_register {
  	unsigned char  system;
e1f19995f   Alex Dubov   memstick: introdu...
99
100
  #define MEMSTICK_SYS_PAR4   0x00
  #define MEMSTICK_SYS_PAR8   0x40
8e82f8c34   Alex Dubov   memstick: fix MSP...
101
  #define MEMSTICK_SYS_SERIAL 0x80
e1f19995f   Alex Dubov   memstick: introdu...
102

69347a236   Harvey Harrison   memstick: annotat...
103
104
  	__be16 data_count;
  	__be32 data_address;
e1f19995f   Alex Dubov   memstick: introdu...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  	unsigned char  tpc_param;
  } __attribute__((packed));
  
  struct mspro_io_info_register {
  	unsigned char version;
  	unsigned char io_category;
  	unsigned char current_req;
  	unsigned char card_opt_info;
  	unsigned char rdy_wait_time;
  } __attribute__((packed));
  
  struct mspro_io_func_register {
  	unsigned char func_enable;
  	unsigned char func_select;
  	unsigned char func_intmask;
  	unsigned char transfer_mode;
  } __attribute__((packed));
  
  struct mspro_io_cmd_register {
  	unsigned short tpc_param;
baf8532a1   Alex Dubov   memstick: initial...
125
126
  	unsigned short data_count;
  	unsigned int   data_address;
baf8532a1   Alex Dubov   memstick: initial...
127
128
129
  } __attribute__((packed));
  
  struct mspro_register {
e1f19995f   Alex Dubov   memstick: introdu...
130
131
132
133
134
135
136
137
138
139
140
  	struct ms_status_register     status;
  	struct ms_id_register         id;
  	unsigned char                 reserved0[8];
  	struct mspro_param_register   param;
  	unsigned char                 reserved1[8];
  	struct mspro_io_info_register io_info;
  	struct mspro_io_func_register io_func;
  	unsigned char                 reserved2[7];
  	struct mspro_io_cmd_register  io_cmd;
  	unsigned char                 io_int;
  	unsigned char                 io_int_func;
baf8532a1   Alex Dubov   memstick: initial...
141
142
143
144
145
146
147
148
  } __attribute__((packed));
  
  struct ms_register_addr {
  	unsigned char r_offset;
  	unsigned char r_length;
  	unsigned char w_offset;
  	unsigned char w_length;
  } __attribute__((packed));
8e82f8c34   Alex Dubov   memstick: fix MSP...
149
  enum memstick_tpc {
e1f19995f   Alex Dubov   memstick: introdu...
150
  	MS_TPC_READ_MG_STATUS   = 0x01,
baf8532a1   Alex Dubov   memstick: initial...
151
152
  	MS_TPC_READ_LONG_DATA   = 0x02,
  	MS_TPC_READ_SHORT_DATA  = 0x03,
e1f19995f   Alex Dubov   memstick: introdu...
153
  	MS_TPC_READ_MG_DATA     = 0x03,
baf8532a1   Alex Dubov   memstick: initial...
154
  	MS_TPC_READ_REG         = 0x04,
e1f19995f   Alex Dubov   memstick: introdu...
155
156
  	MS_TPC_READ_QUAD_DATA   = 0x05,
  	MS_TPC_READ_IO_DATA     = 0x05,
baf8532a1   Alex Dubov   memstick: initial...
157
158
159
  	MS_TPC_GET_INT          = 0x07,
  	MS_TPC_SET_RW_REG_ADRS  = 0x08,
  	MS_TPC_EX_SET_CMD       = 0x09,
e1f19995f   Alex Dubov   memstick: introdu...
160
161
  	MS_TPC_WRITE_QUAD_DATA  = 0x0a,
  	MS_TPC_WRITE_IO_DATA    = 0x0a,
baf8532a1   Alex Dubov   memstick: initial...
162
163
  	MS_TPC_WRITE_REG        = 0x0b,
  	MS_TPC_WRITE_SHORT_DATA = 0x0c,
e1f19995f   Alex Dubov   memstick: introdu...
164
  	MS_TPC_WRITE_MG_DATA    = 0x0c,
baf8532a1   Alex Dubov   memstick: initial...
165
166
167
  	MS_TPC_WRITE_LONG_DATA  = 0x0d,
  	MS_TPC_SET_CMD          = 0x0e
  };
8e82f8c34   Alex Dubov   memstick: fix MSP...
168
  enum memstick_command {
e1f19995f   Alex Dubov   memstick: introdu...
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
  	MS_CMD_BLOCK_END       = 0x33,
  	MS_CMD_RESET           = 0x3c,
  	MS_CMD_BLOCK_WRITE     = 0x55,
  	MS_CMD_SLEEP           = 0x5a,
  	MS_CMD_BLOCK_ERASE     = 0x99,
  	MS_CMD_BLOCK_READ      = 0xaa,
  	MS_CMD_CLEAR_BUF       = 0xc3,
  	MS_CMD_FLASH_STOP      = 0xcc,
  	MS_CMD_LOAD_ID         = 0x60,
  	MS_CMD_CMP_ICV         = 0x7f,
  	MSPRO_CMD_FORMAT       = 0x10,
  	MSPRO_CMD_SLEEP        = 0x11,
  	MSPRO_CMD_WAKEUP       = 0x12,
  	MSPRO_CMD_READ_DATA    = 0x20,
  	MSPRO_CMD_WRITE_DATA   = 0x21,
  	MSPRO_CMD_READ_ATRB    = 0x24,
  	MSPRO_CMD_STOP         = 0x25,
  	MSPRO_CMD_ERASE        = 0x26,
  	MSPRO_CMD_READ_QUAD    = 0x27,
  	MSPRO_CMD_WRITE_QUAD   = 0x28,
  	MSPRO_CMD_SET_IBD      = 0x46,
  	MSPRO_CMD_GET_IBD      = 0x47,
  	MSPRO_CMD_IN_IO_DATA   = 0xb0,
  	MSPRO_CMD_OUT_IO_DATA  = 0xb1,
  	MSPRO_CMD_READ_IO_ATRB = 0xb2,
  	MSPRO_CMD_IN_IO_FIFO   = 0xb3,
  	MSPRO_CMD_OUT_IO_FIFO  = 0xb4,
  	MSPRO_CMD_IN_IOM       = 0xb5,
  	MSPRO_CMD_OUT_IOM      = 0xb6,
baf8532a1   Alex Dubov   memstick: initial...
198
199
200
  };
  
  /*** Driver structures and functions ***/
baf8532a1   Alex Dubov   memstick: initial...
201
202
203
204
205
206
  enum memstick_param { MEMSTICK_POWER = 1, MEMSTICK_INTERFACE };
  
  #define MEMSTICK_POWER_OFF 0
  #define MEMSTICK_POWER_ON  1
  
  #define MEMSTICK_SERIAL   0
e1f19995f   Alex Dubov   memstick: introdu...
207
208
  #define MEMSTICK_PAR4     1
  #define MEMSTICK_PAR8     2
baf8532a1   Alex Dubov   memstick: initial...
209
210
211
  
  struct memstick_host;
  struct memstick_driver;
8e82f8c34   Alex Dubov   memstick: fix MSP...
212
213
  struct memstick_device_id {
  	unsigned char match_flags;
baf8532a1   Alex Dubov   memstick: initial...
214
  #define MEMSTICK_MATCH_ALL            0x01
8e82f8c34   Alex Dubov   memstick: fix MSP...
215
  	unsigned char type;
baf8532a1   Alex Dubov   memstick: initial...
216
217
218
  #define MEMSTICK_TYPE_LEGACY          0xff
  #define MEMSTICK_TYPE_DUO             0x00
  #define MEMSTICK_TYPE_PRO             0x01
8e82f8c34   Alex Dubov   memstick: fix MSP...
219
  	unsigned char category;
baf8532a1   Alex Dubov   memstick: initial...
220
221
  #define MEMSTICK_CATEGORY_STORAGE     0xff
  #define MEMSTICK_CATEGORY_STORAGE_DUO 0x00
8e82f8c34   Alex Dubov   memstick: fix MSP...
222
223
  #define MEMSTICK_CATEGORY_IO          0x01
  #define MEMSTICK_CATEGORY_IO_PRO      0x10
baf8532a1   Alex Dubov   memstick: initial...
224

baf8532a1   Alex Dubov   memstick: initial...
225
  	unsigned char class;
8e82f8c34   Alex Dubov   memstick: fix MSP...
226
227
228
229
230
  #define MEMSTICK_CLASS_FLASH          0xff
  #define MEMSTICK_CLASS_DUO            0x00
  #define MEMSTICK_CLASS_ROM            0x01
  #define MEMSTICK_CLASS_RO             0x02
  #define MEMSTICK_CLASS_WP             0x03
baf8532a1   Alex Dubov   memstick: initial...
231
232
233
234
235
236
  };
  
  struct memstick_request {
  	unsigned char tpc;
  	unsigned char data_dir:1,
  		      need_card_int:1,
e1f19995f   Alex Dubov   memstick: introdu...
237
  		      long_data:1;
baf8532a1   Alex Dubov   memstick: initial...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
  	unsigned char int_reg;
  	int           error;
  	union {
  		struct scatterlist sg;
  		struct {
  			unsigned char data_len;
  			unsigned char data[15];
  		};
  	};
  };
  
  struct memstick_dev {
  	struct memstick_device_id id;
  	struct memstick_host     *host;
  	struct ms_register_addr  reg_addr;
  	struct completion        mrq_complete;
  	struct memstick_request  current_mrq;
  
  	/* Check that media driver is still willing to operate the device. */
  	int                      (*check)(struct memstick_dev *card);
  	/* Get next request from the media driver.                         */
  	int                      (*next_request)(struct memstick_dev *card,
  						 struct memstick_request **mrq);
17017d8d2   Alex Dubov   memstick: add "st...
261
262
263
264
  	/* Tell the media driver to stop doing things                      */
  	void                     (*stop)(struct memstick_dev *card);
  	/* Allow the media driver to continue                              */
  	void                     (*start)(struct memstick_dev *card);
baf8532a1   Alex Dubov   memstick: initial...
265
266
267
268
269
270
271
272
  
  	struct device            dev;
  };
  
  struct memstick_host {
  	struct mutex        lock;
  	unsigned int        id;
  	unsigned int        caps;
e1f19995f   Alex Dubov   memstick: introdu...
273
274
275
  #define MEMSTICK_CAP_AUTO_GET_INT  1
  #define MEMSTICK_CAP_PAR4          2
  #define MEMSTICK_CAP_PAR8          4
baf8532a1   Alex Dubov   memstick: initial...
276
277
  
  	struct work_struct  media_checker;
c4c66cf17   Greg Kroah-Hartman   memstick: convert...
278
  	struct device       dev;
baf8532a1   Alex Dubov   memstick: initial...
279
280
281
282
283
284
285
  
  	struct memstick_dev *card;
  	unsigned int        retries;
  
  	/* Notify the host that some requests are pending. */
  	void                (*request)(struct memstick_host *host);
  	/* Set host IO parameters (power, clock, etc).     */
b77899985   Alex Dubov   memstick: allow "...
286
  	int                 (*set_param)(struct memstick_host *host,
baf8532a1   Alex Dubov   memstick: initial...
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
  					 enum memstick_param param,
  					 int value);
  	unsigned long       private[0] ____cacheline_aligned;
  };
  
  struct memstick_driver {
  	struct memstick_device_id *id_table;
  	int                       (*probe)(struct memstick_dev *card);
  	void                      (*remove)(struct memstick_dev *card);
  	int                       (*suspend)(struct memstick_dev *card,
  					     pm_message_t state);
  	int                       (*resume)(struct memstick_dev *card);
  
  	struct device_driver      driver;
  };
  
  int memstick_register_driver(struct memstick_driver *drv);
  void memstick_unregister_driver(struct memstick_driver *drv);
  
  struct memstick_host *memstick_alloc_host(unsigned int extra,
  					  struct device *dev);
  
  int memstick_add_host(struct memstick_host *host);
  void memstick_remove_host(struct memstick_host *host);
  void memstick_free_host(struct memstick_host *host);
  void memstick_detect_change(struct memstick_host *host);
d114ad54f   Alex Dubov   memstick: add mem...
313
314
  void memstick_suspend_host(struct memstick_host *host);
  void memstick_resume_host(struct memstick_host *host);
baf8532a1   Alex Dubov   memstick: initial...
315
316
  
  void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc,
8e82f8c34   Alex Dubov   memstick: fix MSP...
317
  			  const struct scatterlist *sg);
baf8532a1   Alex Dubov   memstick: initial...
318
  void memstick_init_req(struct memstick_request *mrq, unsigned char tpc,
8e82f8c34   Alex Dubov   memstick: fix MSP...
319
  		       const void *buf, size_t length);
baf8532a1   Alex Dubov   memstick: initial...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
  int memstick_next_req(struct memstick_host *host,
  		      struct memstick_request **mrq);
  void memstick_new_req(struct memstick_host *host);
  
  int memstick_set_rw_addr(struct memstick_dev *card);
  
  static inline void *memstick_priv(struct memstick_host *host)
  {
  	return (void *)host->private;
  }
  
  static inline void *memstick_get_drvdata(struct memstick_dev *card)
  {
  	return dev_get_drvdata(&card->dev);
  }
  
  static inline void memstick_set_drvdata(struct memstick_dev *card, void *data)
  {
  	dev_set_drvdata(&card->dev, data);
  }
  
  #endif