Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
memstick.h
Go to the documentation of this file.
1 /*
2  * Sony MemoryStick support
3  *
4  * Copyright (C) 2007 Alex Dubov <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  */
11 
12 #ifndef _MEMSTICK_H
13 #define _MEMSTICK_H
14 
15 #include <linux/workqueue.h>
16 #include <linux/scatterlist.h>
17 #include <linux/device.h>
18 
19 /*** Hardware based structures ***/
20 
22  unsigned char reserved;
23  unsigned char interrupt;
24 #define MEMSTICK_INT_CMDNAK 0x01
25 #define MEMSTICK_INT_IOREQ 0x08
26 #define MEMSTICK_INT_IOBREQ 0x10
27 #define MEMSTICK_INT_BREQ 0x20
28 #define MEMSTICK_INT_ERR 0x40
29 #define MEMSTICK_INT_CED 0x80
30 
31  unsigned char status0;
32 #define MEMSTICK_STATUS0_WP 0x01
33 #define MEMSTICK_STATUS0_SL 0x02
34 #define MEMSTICK_STATUS0_BF 0x10
35 #define MEMSTICK_STATUS0_BE 0x20
36 #define MEMSTICK_STATUS0_FB0 0x40
37 #define MEMSTICK_STATUS0_MB 0x80
38 
39  unsigned char status1;
40 #define MEMSTICK_STATUS1_UCFG 0x01
41 #define MEMSTICK_STATUS1_FGER 0x02
42 #define MEMSTICK_STATUS1_UCEX 0x04
43 #define MEMSTICK_STATUS1_EXER 0x08
44 #define MEMSTICK_STATUS1_UCDT 0x10
45 #define MEMSTICK_STATUS1_DTER 0x20
46 #define MEMSTICK_STATUS1_FB1 0x40
47 #define MEMSTICK_STATUS1_MB 0x80
48 } __attribute__((packed));
49 
51  unsigned char type;
52  unsigned char if_mode;
53  unsigned char category;
54  unsigned char class;
55 } __attribute__((packed));
56 
58  unsigned char system;
59 #define MEMSTICK_SYS_PAM 0x08
60 #define MEMSTICK_SYS_BAMD 0x80
61 
62  unsigned char block_address_msb;
63  unsigned short block_address;
64  unsigned char cp;
65 #define MEMSTICK_CP_BLOCK 0x00
66 #define MEMSTICK_CP_PAGE 0x20
67 #define MEMSTICK_CP_EXTRA 0x40
68 #define MEMSTICK_CP_OVERWRITE 0x80
69 
70  unsigned char page_address;
71 } __attribute__((packed));
72 
74  unsigned char overwrite_flag;
75 #define MEMSTICK_OVERWRITE_UDST 0x10
76 #define MEMSTICK_OVERWRITE_PGST1 0x20
77 #define MEMSTICK_OVERWRITE_PGST0 0x40
78 #define MEMSTICK_OVERWRITE_BKST 0x80
79 
80  unsigned char management_flag;
81 #define MEMSTICK_MANAGEMENT_SYSFLG 0x04
82 #define MEMSTICK_MANAGEMENT_ATFLG 0x08
83 #define MEMSTICK_MANAGEMENT_SCMS1 0x10
84 #define MEMSTICK_MANAGEMENT_SCMS0 0x20
85 
86  unsigned short logical_address;
87 } __attribute__((packed));
88 
89 struct ms_register {
92  unsigned char reserved[8];
95 } __attribute__((packed));
96 
98  unsigned char system;
99 #define MEMSTICK_SYS_PAR4 0x00
100 #define MEMSTICK_SYS_PAR8 0x40
101 #define MEMSTICK_SYS_SERIAL 0x80
102 
105  unsigned char tpc_param;
106 } __attribute__((packed));
107 
109  unsigned char version;
110  unsigned char io_category;
111  unsigned char current_req;
112  unsigned char card_opt_info;
113  unsigned char rdy_wait_time;
114 } __attribute__((packed));
117  unsigned char func_enable;
118  unsigned char func_select;
119  unsigned char func_intmask;
120  unsigned char transfer_mode;
121 } __attribute__((packed));
124  unsigned short tpc_param;
125  unsigned short data_count;
126  unsigned int data_address;
127 } __attribute__((packed));
128 
132  unsigned char reserved0[8];
134  unsigned char reserved1[8];
137  unsigned char reserved2[7];
139  unsigned char io_int;
140  unsigned char io_int_func;
141 } __attribute__((packed));
142 
144  unsigned char r_offset;
145  unsigned char r_length;
146  unsigned char w_offset;
147  unsigned char w_length;
148 } __attribute__((packed));
168 };
169 
172  MS_CMD_RESET = 0x3c,
174  MS_CMD_SLEEP = 0x5a,
200 };
201 
202 /*** Driver structures and functions ***/
203 
205 
206 #define MEMSTICK_POWER_OFF 0
207 #define MEMSTICK_POWER_ON 1
208 
209 #define MEMSTICK_SERIAL 0
210 #define MEMSTICK_PAR4 1
211 #define MEMSTICK_PAR8 2
212 
213 struct memstick_host;
214 struct memstick_driver;
215 
217  unsigned char match_flags;
218 #define MEMSTICK_MATCH_ALL 0x01
219 
220  unsigned char type;
221 #define MEMSTICK_TYPE_LEGACY 0xff
222 #define MEMSTICK_TYPE_DUO 0x00
223 #define MEMSTICK_TYPE_PRO 0x01
224 
225  unsigned char category;
226 #define MEMSTICK_CATEGORY_STORAGE 0xff
227 #define MEMSTICK_CATEGORY_STORAGE_DUO 0x00
228 #define MEMSTICK_CATEGORY_IO 0x01
229 #define MEMSTICK_CATEGORY_IO_PRO 0x10
230 
231  unsigned char class;
232 #define MEMSTICK_CLASS_FLASH 0xff
233 #define MEMSTICK_CLASS_DUO 0x00
234 #define MEMSTICK_CLASS_ROM 0x01
235 #define MEMSTICK_CLASS_RO 0x02
236 #define MEMSTICK_CLASS_WP 0x03
237 };
238 
240  unsigned char tpc;
241  unsigned char data_dir:1,
242  need_card_int:1,
243  long_data:1;
244  unsigned char int_reg;
245  int error;
246  union {
247  struct scatterlist sg;
248  struct {
249  unsigned char data_len;
250  unsigned char data[15];
251  };
252  };
253 };
254 
255 struct memstick_dev {
261 
262  /* Check that media driver is still willing to operate the device. */
263  int (*check)(struct memstick_dev *card);
264  /* Get next request from the media driver. */
266  struct memstick_request **mrq);
267  /* Tell the media driver to stop doing things */
268  void (*stop)(struct memstick_dev *card);
269  /* Allow the media driver to continue */
271 
272  struct device dev;
273 };
274 
276  struct mutex lock;
277  unsigned int id;
278  unsigned int caps;
279 #define MEMSTICK_CAP_AUTO_GET_INT 1
280 #define MEMSTICK_CAP_PAR4 2
281 #define MEMSTICK_CAP_PAR8 4
282 
284  struct device dev;
285 
287  unsigned int retries;
288 
289  /* Notify the host that some requests are pending. */
291  /* Set host IO parameters (power, clock, etc). */
293  enum memstick_param param,
294  int value);
295  unsigned long private[0] ____cacheline_aligned;
296 };
297 
300  int (*probe)(struct memstick_dev *card);
301  void (*remove)(struct memstick_dev *card);
305 
307 };
308 
311 
312 struct memstick_host *memstick_alloc_host(unsigned int extra,
313  struct device *dev);
314 
321 
322 void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc,
323  const struct scatterlist *sg);
324 void memstick_init_req(struct memstick_request *mrq, unsigned char tpc,
325  const void *buf, size_t length);
327  struct memstick_request **mrq);
328 void memstick_new_req(struct memstick_host *host);
329 
331 
332 static inline void *memstick_priv(struct memstick_host *host)
333 {
334  return (void *)host->private;
335 }
336 
337 static inline void *memstick_get_drvdata(struct memstick_dev *card)
338 {
339  return dev_get_drvdata(&card->dev);
340 }
341 
342 static inline void memstick_set_drvdata(struct memstick_dev *card, void *data)
343 {
344  dev_set_drvdata(&card->dev, data);
345 }
346 
347 #endif