2 * Sony MemoryStick support
4 * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
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.
15 #include <linux/workqueue.h>
16 #include <linux/scatterlist.h>
17 #include <linux/device.h>
19 /*** Hardware based structures ***/
21 struct ms_status_register
{
22 unsigned char reserved
;
23 unsigned char interrupt
;
24 #define MEMSTICK_INT_CMDNAK 0x0001
25 <<<<<<< HEAD
:include
/linux
/memstick
.h
27 #define MEMSTICK_INT_IOREQ 0x0008
28 #define MEMSTICK_INT_IOBREQ 0x0010
29 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
30 #define MEMSTICK_INT_BREQ 0x0020
31 #define MEMSTICK_INT_ERR 0x0040
32 #define MEMSTICK_INT_CED 0x0080
34 unsigned char status0
;
35 #define MEMSTICK_STATUS0_WP 0x0001
36 #define MEMSTICK_STATUS0_SL 0x0002
37 #define MEMSTICK_STATUS0_BF 0x0010
38 #define MEMSTICK_STATUS0_BE 0x0020
39 #define MEMSTICK_STATUS0_FB0 0x0040
40 #define MEMSTICK_STATUS0_MB 0x0080
42 unsigned char status1
;
43 #define MEMSTICK_STATUS1_UCFG 0x0001
44 #define MEMSTICK_STATUS1_FGER 0x0002
45 #define MEMSTICK_STATUS1_UCEX 0x0004
46 #define MEMSTICK_STATUS1_EXER 0x0008
47 #define MEMSTICK_STATUS1_UCDT 0x0010
48 #define MEMSTICK_STATUS1_DTER 0x0020
49 #define MEMSTICK_STATUS1_FBI 0x0040
50 #define MEMSTICK_STATUS1_MB 0x0080
51 } __attribute__((packed
));
53 struct ms_id_register
{
55 <<<<<<< HEAD
:include
/linux
/memstick
.h
56 unsigned char reserved
;
58 unsigned char if_mode
;
59 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
60 unsigned char category
;
62 } __attribute__((packed
));
64 struct ms_param_register
{
66 <<<<<<< HEAD
:include
/linux
/memstick
.h
68 #define MEMSTICK_SYS_ATEN 0xc0
69 #define MEMSTICK_SYS_BAMD 0x80
70 #define MEMSTICK_SYS_PAM 0x08
72 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
73 unsigned char block_address_msb
;
74 unsigned short block_address
;
76 #define MEMSTICK_CP_BLOCK 0x0000
77 #define MEMSTICK_CP_PAGE 0x0020
78 #define MEMSTICK_CP_EXTRA 0x0040
79 #define MEMSTICK_CP_OVERWRITE 0x0080
81 unsigned char page_address
;
82 } __attribute__((packed
));
84 struct ms_extra_data_register
{
85 unsigned char overwrite_flag
;
86 #define MEMSTICK_OVERWRITE_UPDATA 0x0010
87 #define MEMSTICK_OVERWRITE_PAGE 0x0060
88 #define MEMSTICK_OVERWRITE_BLOCK 0x0080
90 unsigned char management_flag
;
91 #define MEMSTICK_MANAGEMENT_SYSTEM 0x0004
92 #define MEMSTICK_MANAGEMENT_TRANS_TABLE 0x0008
93 #define MEMSTICK_MANAGEMENT_COPY 0x0010
94 #define MEMSTICK_MANAGEMENT_ACCESS 0x0020
96 unsigned short logical_address
;
97 } __attribute__((packed
));
100 struct ms_status_register status
;
101 struct ms_id_register id
;
102 unsigned char reserved
[8];
103 struct ms_param_register param
;
104 struct ms_extra_data_register extra_data
;
105 } __attribute__((packed
));
107 struct mspro_param_register
{
108 unsigned char system
;
109 <<<<<<< HEAD
:include
/linux
/memstick
.h
111 #define MEMSTICK_SYS_SERIAL 0x80
112 #define MEMSTICK_SYS_PAR4 0x00
113 #define MEMSTICK_SYS_PAR8 0x40
115 unsigned short data_count
;
116 unsigned int data_address
;
117 unsigned char tpc_param
;
118 } __attribute__((packed
));
120 struct mspro_io_info_register
{
121 unsigned char version
;
122 unsigned char io_category
;
123 unsigned char current_req
;
124 unsigned char card_opt_info
;
125 unsigned char rdy_wait_time
;
126 } __attribute__((packed
));
128 struct mspro_io_func_register
{
129 unsigned char func_enable
;
130 unsigned char func_select
;
131 unsigned char func_intmask
;
132 unsigned char transfer_mode
;
133 } __attribute__((packed
));
135 struct mspro_io_cmd_register
{
136 unsigned short tpc_param
;
137 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
138 unsigned short data_count
;
139 unsigned int data_address
;
140 <<<<<<< HEAD
:include
/linux
/memstick
.h
141 unsigned char cmd_param
;
143 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
144 } __attribute__((packed
));
146 struct mspro_register
{
147 <<<<<<< HEAD
:include
/linux
/memstick
.h
148 struct ms_status_register status
;
149 struct ms_id_register id
;
150 unsigned char reserved
[8];
151 struct mspro_param_register param
;
153 struct ms_status_register status
;
154 struct ms_id_register id
;
155 unsigned char reserved0
[8];
156 struct mspro_param_register param
;
157 unsigned char reserved1
[8];
158 struct mspro_io_info_register io_info
;
159 struct mspro_io_func_register io_func
;
160 unsigned char reserved2
[7];
161 struct mspro_io_cmd_register io_cmd
;
162 unsigned char io_int
;
163 unsigned char io_int_func
;
164 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
165 } __attribute__((packed
));
167 struct ms_register_addr
{
168 unsigned char r_offset
;
169 unsigned char r_length
;
170 unsigned char w_offset
;
171 unsigned char w_length
;
172 } __attribute__((packed
));
175 <<<<<<< HEAD
:include
/linux
/memstick
.h
177 MS_TPC_READ_MG_STATUS
= 0x01,
178 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
179 MS_TPC_READ_LONG_DATA
= 0x02,
180 MS_TPC_READ_SHORT_DATA
= 0x03,
181 <<<<<<< HEAD
:include
/linux
/memstick
.h
183 MS_TPC_READ_MG_DATA
= 0x03,
184 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
185 MS_TPC_READ_REG
= 0x04,
186 <<<<<<< HEAD
:include
/linux
/memstick
.h
187 MS_TPC_READ_IO_DATA
= 0x05, /* unverified */
189 MS_TPC_READ_QUAD_DATA
= 0x05,
190 MS_TPC_READ_IO_DATA
= 0x05,
191 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
192 MS_TPC_GET_INT
= 0x07,
193 MS_TPC_SET_RW_REG_ADRS
= 0x08,
194 MS_TPC_EX_SET_CMD
= 0x09,
195 <<<<<<< HEAD
:include
/linux
/memstick
.h
196 MS_TPC_WRITE_IO_DATA
= 0x0a, /* unverified */
198 MS_TPC_WRITE_QUAD_DATA
= 0x0a,
199 MS_TPC_WRITE_IO_DATA
= 0x0a,
200 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
201 MS_TPC_WRITE_REG
= 0x0b,
202 MS_TPC_WRITE_SHORT_DATA
= 0x0c,
203 <<<<<<< HEAD
:include
/linux
/memstick
.h
205 MS_TPC_WRITE_MG_DATA
= 0x0c,
206 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
207 MS_TPC_WRITE_LONG_DATA
= 0x0d,
208 MS_TPC_SET_CMD
= 0x0e
212 <<<<<<< HEAD
:include
/linux
/memstick
.h
213 MS_CMD_BLOCK_END
= 0x33,
215 MS_CMD_BLOCK_WRITE
= 0x55,
217 MS_CMD_BLOCK_ERASE
= 0x99,
218 MS_CMD_BLOCK_READ
= 0xaa,
219 MS_CMD_CLEAR_BUF
= 0xc3,
220 MS_CMD_FLASH_STOP
= 0xcc,
221 MSPRO_CMD_FORMAT
= 0x10,
222 MSPRO_CMD_SLEEP
= 0x11,
223 MSPRO_CMD_READ_DATA
= 0x20,
224 MSPRO_CMD_WRITE_DATA
= 0x21,
225 MSPRO_CMD_READ_ATRB
= 0x24,
226 MSPRO_CMD_STOP
= 0x25,
227 MSPRO_CMD_ERASE
= 0x26,
228 MSPRO_CMD_SET_IBA
= 0x46,
229 MSPRO_CMD_SET_IBD
= 0x47
234 MSPRO_CMD_OUT_IO_DATA
235 MSPRO_CMD_READ_IO_ATRB
237 MSPRO_CMD_OUT_IO_FIFO
242 MS_CMD_BLOCK_END
= 0x33,
244 MS_CMD_BLOCK_WRITE
= 0x55,
246 MS_CMD_BLOCK_ERASE
= 0x99,
247 MS_CMD_BLOCK_READ
= 0xaa,
248 MS_CMD_CLEAR_BUF
= 0xc3,
249 MS_CMD_FLASH_STOP
= 0xcc,
250 MS_CMD_LOAD_ID
= 0x60,
251 MS_CMD_CMP_ICV
= 0x7f,
252 MSPRO_CMD_FORMAT
= 0x10,
253 MSPRO_CMD_SLEEP
= 0x11,
254 MSPRO_CMD_WAKEUP
= 0x12,
255 MSPRO_CMD_READ_DATA
= 0x20,
256 MSPRO_CMD_WRITE_DATA
= 0x21,
257 MSPRO_CMD_READ_ATRB
= 0x24,
258 MSPRO_CMD_STOP
= 0x25,
259 MSPRO_CMD_ERASE
= 0x26,
260 MSPRO_CMD_READ_QUAD
= 0x27,
261 MSPRO_CMD_WRITE_QUAD
= 0x28,
262 MSPRO_CMD_SET_IBD
= 0x46,
263 MSPRO_CMD_GET_IBD
= 0x47,
264 MSPRO_CMD_IN_IO_DATA
= 0xb0,
265 MSPRO_CMD_OUT_IO_DATA
= 0xb1,
266 MSPRO_CMD_READ_IO_ATRB
= 0xb2,
267 MSPRO_CMD_IN_IO_FIFO
= 0xb3,
268 MSPRO_CMD_OUT_IO_FIFO
= 0xb4,
269 MSPRO_CMD_IN_IOM
= 0xb5,
270 MSPRO_CMD_OUT_IOM
= 0xb6,
271 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
274 /*** Driver structures and functions ***/
276 #define MEMSTICK_PART_SHIFT 3
278 enum memstick_param
{ MEMSTICK_POWER
= 1, MEMSTICK_INTERFACE
};
280 #define MEMSTICK_POWER_OFF 0
281 #define MEMSTICK_POWER_ON 1
283 #define MEMSTICK_SERIAL 0
284 <<<<<<< HEAD
:include
/linux
/memstick
.h
285 #define MEMSTICK_PARALLEL 1
287 #define MEMSTICK_PAR4 1
288 #define MEMSTICK_PAR8 2
289 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
291 struct memstick_host
;
292 struct memstick_driver
;
294 #define MEMSTICK_MATCH_ALL 0x01
296 #define MEMSTICK_TYPE_LEGACY 0xff
297 #define MEMSTICK_TYPE_DUO 0x00
298 #define MEMSTICK_TYPE_PRO 0x01
300 #define MEMSTICK_CATEGORY_STORAGE 0xff
301 #define MEMSTICK_CATEGORY_STORAGE_DUO 0x00
303 #define MEMSTICK_CLASS_GENERIC 0xff
304 #define MEMSTICK_CLASS_GENERIC_DUO 0x00
307 struct memstick_device_id
{
308 unsigned char match_flags
;
310 unsigned char category
;
314 struct memstick_request
{
316 unsigned char data_dir
:1,
319 <<<<<<< HEAD
:include
/linux
/memstick
.h
321 #define MEMSTICK_IO_NONE 0
322 #define MEMSTICK_IO_VAL 1
323 #define MEMSTICK_IO_SG 2
327 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
328 unsigned char int_reg
;
331 struct scatterlist sg
;
333 unsigned char data_len
;
334 unsigned char data
[15];
339 struct memstick_dev
{
340 struct memstick_device_id id
;
341 struct memstick_host
*host
;
342 struct ms_register_addr reg_addr
;
343 struct completion mrq_complete
;
344 struct memstick_request current_mrq
;
346 /* Check that media driver is still willing to operate the device. */
347 int (*check
)(struct memstick_dev
*card
);
348 /* Get next request from the media driver. */
349 int (*next_request
)(struct memstick_dev
*card
,
350 struct memstick_request
**mrq
);
355 struct memstick_host
{
359 <<<<<<< HEAD
:include
/linux
/memstick
.h
360 #define MEMSTICK_CAP_PARALLEL 1
361 #define MEMSTICK_CAP_AUTO_GET_INT 2
363 #define MEMSTICK_CAP_AUTO_GET_INT 1
364 #define MEMSTICK_CAP_PAR4 2
365 #define MEMSTICK_CAP_PAR8 4
366 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
368 struct work_struct media_checker
;
369 struct class_device cdev
;
371 struct memstick_dev
*card
;
372 unsigned int retries
;
374 /* Notify the host that some requests are pending. */
375 void (*request
)(struct memstick_host
*host
);
376 /* Set host IO parameters (power, clock, etc). */
377 void (*set_param
)(struct memstick_host
*host
,
378 enum memstick_param param
,
380 unsigned long private[0] ____cacheline_aligned
;
383 struct memstick_driver
{
384 struct memstick_device_id
*id_table
;
385 int (*probe
)(struct memstick_dev
*card
);
386 void (*remove
)(struct memstick_dev
*card
);
387 int (*suspend
)(struct memstick_dev
*card
,
389 int (*resume
)(struct memstick_dev
*card
);
391 struct device_driver driver
;
394 int memstick_register_driver(struct memstick_driver
*drv
);
395 void memstick_unregister_driver(struct memstick_driver
*drv
);
397 struct memstick_host
*memstick_alloc_host(unsigned int extra
,
400 int memstick_add_host(struct memstick_host
*host
);
401 void memstick_remove_host(struct memstick_host
*host
);
402 void memstick_free_host(struct memstick_host
*host
);
403 void memstick_detect_change(struct memstick_host
*host
);
404 <<<<<<< HEAD
:include
/linux
/memstick
.h
406 void memstick_suspend_host(struct memstick_host
*host
);
407 void memstick_resume_host(struct memstick_host
*host
);
408 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/linux
/memstick
.h
410 void memstick_init_req_sg(struct memstick_request
*mrq
, unsigned char tpc
,
411 struct scatterlist
*sg
);
412 void memstick_init_req(struct memstick_request
*mrq
, unsigned char tpc
,
413 void *buf
, size_t length
);
414 int memstick_next_req(struct memstick_host
*host
,
415 struct memstick_request
**mrq
);
416 void memstick_new_req(struct memstick_host
*host
);
418 int memstick_set_rw_addr(struct memstick_dev
*card
);
420 static inline void *memstick_priv(struct memstick_host
*host
)
422 return (void *)host
->private;
425 static inline void *memstick_get_drvdata(struct memstick_dev
*card
)
427 return dev_get_drvdata(&card
->dev
);
430 static inline void memstick_set_drvdata(struct memstick_dev
*card
, void *data
)
432 dev_set_drvdata(&card
->dev
, data
);