2 * Sony MemoryStick Pro storage 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.
10 * Special thanks to Carlos Corbacho for providing various MemoryStick cards
11 * that made this driver possible.
15 #include <linux/blkdev.h>
16 #include <linux/idr.h>
17 #include <linux/hdreg.h>
18 #include <linux/kthread.h>
19 #include <linux/delay.h>
20 #include <linux/memstick.h>
22 #define DRIVER_NAME "mspro_block"
25 module_param(major
, int, 0644);
27 #define MSPRO_BLOCK_MAX_SEGS 32
28 #define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
30 #define MSPRO_BLOCK_SIGNATURE 0xa5c3
31 #define MSPRO_BLOCK_MAX_ATTRIBUTES 41
34 MSPRO_BLOCK_ID_SYSINFO
= 0x10,
35 MSPRO_BLOCK_ID_MODELNAME
= 0x15,
36 MSPRO_BLOCK_ID_MBR
= 0x20,
37 MSPRO_BLOCK_ID_PBR16
= 0x21,
38 MSPRO_BLOCK_ID_PBR32
= 0x22,
39 MSPRO_BLOCK_ID_SPECFILEVALUES1
= 0x25,
40 MSPRO_BLOCK_ID_SPECFILEVALUES2
= 0x26,
41 MSPRO_BLOCK_ID_DEVINFO
= 0x30
44 struct mspro_sys_attr
{
49 struct device_attribute dev_attr
;
52 struct mspro_attr_entry
{
56 unsigned char reserved
[3];
57 } __attribute__((packed
));
59 struct mspro_attribute
{
60 unsigned short signature
;
61 unsigned short version
;
63 unsigned char reserved
[11];
64 struct mspro_attr_entry entries
[];
65 } __attribute__((packed
));
67 struct mspro_sys_info
{
69 unsigned char reserved0
;
70 unsigned short block_size
;
71 unsigned short block_count
;
72 unsigned short user_block_count
;
73 unsigned short page_size
;
74 unsigned char reserved1
[2];
75 unsigned char assembly_date
[8];
76 unsigned int serial_number
;
77 unsigned char assembly_maker_code
;
78 unsigned char assembly_model_code
[3];
79 unsigned short memory_maker_code
;
80 unsigned short memory_model_code
;
81 unsigned char reserved2
[4];
84 unsigned short controller_number
;
85 unsigned short controller_function
;
86 unsigned short start_sector
;
87 unsigned short unit_size
;
88 unsigned char ms_sub_class
;
89 unsigned char reserved3
[4];
90 unsigned char interface_type
;
91 unsigned short controller_code
;
92 unsigned char format_type
;
93 unsigned char reserved4
;
94 unsigned char device_type
;
95 unsigned char reserved5
[7];
96 unsigned char mspro_id
[16];
97 unsigned char reserved6
[16];
98 } __attribute__((packed
));
101 unsigned char boot_partition
;
102 unsigned char start_head
;
103 unsigned char start_sector
;
104 unsigned char start_cylinder
;
105 unsigned char partition_type
;
106 unsigned char end_head
;
107 unsigned char end_sector
;
108 unsigned char end_cylinder
;
109 unsigned int start_sectors
;
110 unsigned int sectors_per_partition
;
111 } __attribute__((packed
));
113 struct mspro_specfile
{
117 unsigned char reserved
[10];
120 unsigned short cluster
;
122 } __attribute__((packed
));
124 struct mspro_devinfo
{
125 unsigned short cylinders
;
126 unsigned short heads
;
127 unsigned short bytes_per_track
;
128 unsigned short bytes_per_sector
;
129 unsigned short sectors_per_track
;
130 unsigned char reserved
[6];
131 } __attribute__((packed
));
133 struct mspro_block_data
{
134 struct memstick_dev
*card
;
135 unsigned int usage_count
;
137 struct gendisk
*disk
;
138 struct request_queue
*queue
;
140 wait_queue_head_t q_wait
;
141 struct task_struct
*q_thread
;
143 unsigned short page_size
;
144 unsigned short cylinders
;
145 unsigned short heads
;
146 unsigned short sectors_per_track
;
148 unsigned char system
;
149 unsigned char read_only
:1,
153 unsigned char transfer_cmd
;
155 int (*mrq_handler
)(struct memstick_dev
*card
,
156 struct memstick_request
**mrq
);
158 struct attribute_group attr_group
;
160 struct scatterlist req_sg
[MSPRO_BLOCK_MAX_SEGS
];
161 unsigned int seg_count
;
162 unsigned int current_seg
;
163 unsigned short current_page
;
166 static DEFINE_IDR(mspro_block_disk_idr
);
167 static DEFINE_MUTEX(mspro_block_disk_lock
);
169 /*** Block device ***/
171 static int mspro_block_bd_open(struct inode
*inode
, struct file
*filp
)
173 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
174 struct mspro_block_data
*msb
= disk
->private_data
;
177 mutex_lock(&mspro_block_disk_lock
);
179 if (msb
&& msb
->card
) {
181 if ((filp
->f_mode
& FMODE_WRITE
) && msb
->read_only
)
187 mutex_unlock(&mspro_block_disk_lock
);
193 static int mspro_block_disk_release(struct gendisk
*disk
)
195 struct mspro_block_data
*msb
= disk
->private_data
;
196 int disk_id
= disk
->first_minor
>> MEMSTICK_PART_SHIFT
;
198 mutex_lock(&mspro_block_disk_lock
);
200 if (msb
->usage_count
) {
202 if (!msb
->usage_count
) {
204 disk
->private_data
= NULL
;
205 idr_remove(&mspro_block_disk_idr
, disk_id
);
210 mutex_unlock(&mspro_block_disk_lock
);
215 static int mspro_block_bd_release(struct inode
*inode
, struct file
*filp
)
217 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
218 return mspro_block_disk_release(disk
);
221 static int mspro_block_bd_getgeo(struct block_device
*bdev
,
222 struct hd_geometry
*geo
)
224 struct mspro_block_data
*msb
= bdev
->bd_disk
->private_data
;
226 geo
->heads
= msb
->heads
;
227 geo
->sectors
= msb
->sectors_per_track
;
228 geo
->cylinders
= msb
->cylinders
;
233 static struct block_device_operations ms_block_bdops
= {
234 .open
= mspro_block_bd_open
,
235 .release
= mspro_block_bd_release
,
236 .getgeo
= mspro_block_bd_getgeo
,
240 /*** Information ***/
242 static struct mspro_sys_attr
*mspro_from_sysfs_attr(struct attribute
*attr
)
244 struct device_attribute
*dev_attr
245 = container_of(attr
, struct device_attribute
, attr
);
246 return container_of(dev_attr
, struct mspro_sys_attr
, dev_attr
);
249 static const char *mspro_block_attr_name(unsigned char tag
)
252 case MSPRO_BLOCK_ID_SYSINFO
:
253 return "attr_sysinfo";
254 case MSPRO_BLOCK_ID_MODELNAME
:
255 return "attr_modelname";
256 case MSPRO_BLOCK_ID_MBR
:
258 case MSPRO_BLOCK_ID_PBR16
:
260 case MSPRO_BLOCK_ID_PBR32
:
262 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
263 return "attr_specfilevalues1";
264 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
265 return "attr_specfilevalues2";
266 case MSPRO_BLOCK_ID_DEVINFO
:
267 return "attr_devinfo";
273 typedef ssize_t (*sysfs_show_t
)(struct device
*dev
,
274 struct device_attribute
*attr
,
277 static ssize_t
mspro_block_attr_show_default(struct device
*dev
,
278 struct device_attribute
*attr
,
281 struct mspro_sys_attr
*s_attr
= container_of(attr
,
282 struct mspro_sys_attr
,
287 for (cnt
= 0; cnt
< s_attr
->size
; cnt
++) {
288 if (cnt
&& !(cnt
% 16)) {
293 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "%02x ",
294 ((unsigned char *)s_attr
->data
)[cnt
]);
299 static ssize_t
mspro_block_attr_show_sysinfo(struct device
*dev
,
300 struct device_attribute
*attr
,
303 struct mspro_sys_attr
*x_attr
= container_of(attr
,
304 struct mspro_sys_attr
,
306 struct mspro_sys_info
*x_sys
= x_attr
->data
;
308 int date_tz
= 0, date_tz_f
= 0;
310 if (x_sys
->assembly_date
[0] > 0x80U
) {
311 date_tz
= (~x_sys
->assembly_date
[0]) + 1;
312 date_tz_f
= date_tz
& 3;
316 } else if (x_sys
->assembly_date
[0] < 0x80U
) {
317 date_tz
= x_sys
->assembly_date
[0];
318 date_tz_f
= date_tz
& 3;
323 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "class: %x\n",
325 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block size: %x\n",
326 be16_to_cpu(x_sys
->block_size
));
327 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block count: %x\n",
328 be16_to_cpu(x_sys
->block_count
));
329 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "user block count: %x\n",
330 be16_to_cpu(x_sys
->user_block_count
));
331 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "page size: %x\n",
332 be16_to_cpu(x_sys
->page_size
));
333 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly date: "
334 "GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
336 be16_to_cpu(*(unsigned short *)
337 &x_sys
->assembly_date
[1]),
338 x_sys
->assembly_date
[3], x_sys
->assembly_date
[4],
339 x_sys
->assembly_date
[5], x_sys
->assembly_date
[6],
340 x_sys
->assembly_date
[7]);
341 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "serial number: %x\n",
342 be32_to_cpu(x_sys
->serial_number
));
343 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
344 "assembly maker code: %x\n",
345 x_sys
->assembly_maker_code
);
346 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly model code: "
347 "%02x%02x%02x\n", x_sys
->assembly_model_code
[0],
348 x_sys
->assembly_model_code
[1],
349 x_sys
->assembly_model_code
[2]);
350 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory maker code: %x\n",
351 be16_to_cpu(x_sys
->memory_maker_code
));
352 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory model code: %x\n",
353 be16_to_cpu(x_sys
->memory_model_code
));
354 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vcc: %x\n",
356 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vpp: %x\n",
358 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller number: %x\n",
359 be16_to_cpu(x_sys
->controller_number
));
360 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
361 "controller function: %x\n",
362 be16_to_cpu(x_sys
->controller_function
));
363 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
364 be16_to_cpu(x_sys
->start_sector
));
365 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "unit size: %x\n",
366 be16_to_cpu(x_sys
->unit_size
));
367 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sub class: %x\n",
368 x_sys
->ms_sub_class
);
369 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "interface type: %x\n",
370 x_sys
->interface_type
);
371 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller code: %x\n",
372 be16_to_cpu(x_sys
->controller_code
));
373 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "format type: %x\n",
375 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "device type: %x\n",
377 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "mspro id: %s\n",
382 static ssize_t
mspro_block_attr_show_modelname(struct device
*dev
,
383 struct device_attribute
*attr
,
386 struct mspro_sys_attr
*s_attr
= container_of(attr
,
387 struct mspro_sys_attr
,
390 return scnprintf(buffer
, PAGE_SIZE
, "%s", (char *)s_attr
->data
);
393 static ssize_t
mspro_block_attr_show_mbr(struct device
*dev
,
394 struct device_attribute
*attr
,
397 struct mspro_sys_attr
*x_attr
= container_of(attr
,
398 struct mspro_sys_attr
,
400 struct mspro_mbr
*x_mbr
= x_attr
->data
;
403 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "boot partition: %x\n",
404 x_mbr
->boot_partition
);
405 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start head: %x\n",
407 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
408 x_mbr
->start_sector
);
409 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cylinder: %x\n",
410 x_mbr
->start_cylinder
);
411 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "partition type: %x\n",
412 x_mbr
->partition_type
);
413 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end head: %x\n",
415 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end sector: %x\n",
417 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end cylinder: %x\n",
418 x_mbr
->end_cylinder
);
419 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sectors: %x\n",
420 x_mbr
->start_sectors
);
421 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
422 "sectors per partition: %x\n",
423 x_mbr
->sectors_per_partition
);
427 static ssize_t
mspro_block_attr_show_specfile(struct device
*dev
,
428 struct device_attribute
*attr
,
431 struct mspro_sys_attr
*x_attr
= container_of(attr
,
432 struct mspro_sys_attr
,
434 struct mspro_specfile
*x_spfile
= x_attr
->data
;
435 char name
[9], ext
[4];
438 memcpy(name
, x_spfile
->name
, 8);
440 memcpy(ext
, x_spfile
->ext
, 3);
443 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "name: %s\n", name
);
444 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "ext: %s\n", ext
);
445 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "attribute: %x\n",
447 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "time: %d:%d:%d\n",
448 x_spfile
->time
>> 11,
449 (x_spfile
->time
>> 5) & 0x3f,
450 (x_spfile
->time
& 0x1f) * 2);
451 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "date: %d-%d-%d\n",
452 (x_spfile
->date
>> 9) + 1980,
453 (x_spfile
->date
>> 5) & 0xf,
454 x_spfile
->date
& 0x1f);
455 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cluster: %x\n",
457 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "size: %x\n",
462 static ssize_t
mspro_block_attr_show_devinfo(struct device
*dev
,
463 struct device_attribute
*attr
,
466 struct mspro_sys_attr
*x_attr
= container_of(attr
,
467 struct mspro_sys_attr
,
469 struct mspro_devinfo
*x_devinfo
= x_attr
->data
;
472 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "cylinders: %x\n",
473 be16_to_cpu(x_devinfo
->cylinders
));
474 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "heads: %x\n",
475 be16_to_cpu(x_devinfo
->heads
));
476 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per track: %x\n",
477 be16_to_cpu(x_devinfo
->bytes_per_track
));
478 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per sector: %x\n",
479 be16_to_cpu(x_devinfo
->bytes_per_sector
));
480 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sectors per track: %x\n",
481 be16_to_cpu(x_devinfo
->sectors_per_track
));
485 static sysfs_show_t
mspro_block_attr_show(unsigned char tag
)
488 case MSPRO_BLOCK_ID_SYSINFO
:
489 return mspro_block_attr_show_sysinfo
;
490 case MSPRO_BLOCK_ID_MODELNAME
:
491 return mspro_block_attr_show_modelname
;
492 case MSPRO_BLOCK_ID_MBR
:
493 return mspro_block_attr_show_mbr
;
494 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
495 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
496 return mspro_block_attr_show_specfile
;
497 case MSPRO_BLOCK_ID_DEVINFO
:
498 return mspro_block_attr_show_devinfo
;
500 return mspro_block_attr_show_default
;
504 /*** Protocol handlers ***/
507 * Functions prefixed with "h_" are protocol callbacks. They can be called from
508 * interrupt context. Return value of 0 means that request processing is still
509 * ongoing, while special error value of -EAGAIN means that current request is
510 * finished (and request processor should come back some time later).
513 static int h_mspro_block_req_init(struct memstick_dev
*card
,
514 struct memstick_request
**mrq
)
516 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
518 *mrq
= &card
->current_mrq
;
519 card
->next_request
= msb
->mrq_handler
;
523 static int h_mspro_block_default(struct memstick_dev
*card
,
524 struct memstick_request
**mrq
)
526 complete(&card
->mrq_complete
);
530 return (*mrq
)->error
;
533 static int h_mspro_block_get_ro(struct memstick_dev
*card
,
534 struct memstick_request
**mrq
)
536 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
539 complete(&card
->mrq_complete
);
540 return (*mrq
)->error
;
543 if ((*mrq
)->data
[offsetof(struct ms_status_register
, status0
)]
544 & MEMSTICK_STATUS0_WP
)
549 complete(&card
->mrq_complete
);
553 static int h_mspro_block_wait_for_ced(struct memstick_dev
*card
,
554 struct memstick_request
**mrq
)
557 complete(&card
->mrq_complete
);
558 return (*mrq
)->error
;
561 dev_dbg(&card
->dev
, "wait for ced: value %x\n", (*mrq
)->data
[0]);
563 if ((*mrq
)->data
[0] & (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
)) {
564 card
->current_mrq
.error
= -EFAULT
;
565 complete(&card
->mrq_complete
);
566 return card
->current_mrq
.error
;
569 if (!((*mrq
)->data
[0] & MEMSTICK_INT_CED
))
572 card
->current_mrq
.error
= 0;
573 complete(&card
->mrq_complete
);
578 static int h_mspro_block_transfer_data(struct memstick_dev
*card
,
579 struct memstick_request
**mrq
)
581 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
582 unsigned char t_val
= 0;
583 struct scatterlist t_sg
= { 0 };
587 complete(&card
->mrq_complete
);
588 return (*mrq
)->error
;
591 switch ((*mrq
)->tpc
) {
592 case MS_TPC_WRITE_REG
:
593 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &msb
->transfer_cmd
, 1);
594 (*mrq
)->need_card_int
= 1;
597 t_val
= (*mrq
)->int_reg
;
598 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
599 if (msb
->caps
& MEMSTICK_CAP_AUTO_GET_INT
)
603 t_val
= (*mrq
)->data
[0];
605 if (t_val
& (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
)) {
606 t_val
= MSPRO_CMD_STOP
;
607 memstick_init_req(*mrq
, MS_TPC_SET_CMD
, &t_val
, 1);
608 card
->next_request
= h_mspro_block_default
;
612 if (msb
->current_page
613 == (msb
->req_sg
[msb
->current_seg
].length
615 msb
->current_page
= 0;
618 if (msb
->current_seg
== msb
->seg_count
) {
619 if (t_val
& MEMSTICK_INT_CED
) {
620 complete(&card
->mrq_complete
);
624 = h_mspro_block_wait_for_ced
;
625 memstick_init_req(*mrq
, MS_TPC_GET_INT
,
632 if (!(t_val
& MEMSTICK_INT_BREQ
)) {
633 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
637 t_offset
= msb
->req_sg
[msb
->current_seg
].offset
;
638 t_offset
+= msb
->current_page
* msb
->page_size
;
641 nth_page(sg_page(&(msb
->req_sg
[msb
->current_seg
])),
642 t_offset
>> PAGE_SHIFT
),
643 msb
->page_size
, offset_in_page(t_offset
));
645 memstick_init_req_sg(*mrq
, msb
->data_dir
== READ
646 ? MS_TPC_READ_LONG_DATA
647 : MS_TPC_WRITE_LONG_DATA
,
649 (*mrq
)->need_card_int
= 1;
651 case MS_TPC_READ_LONG_DATA
:
652 case MS_TPC_WRITE_LONG_DATA
:
654 if (msb
->caps
& MEMSTICK_CAP_AUTO_GET_INT
) {
655 t_val
= (*mrq
)->int_reg
;
658 memstick_init_req(*mrq
, MS_TPC_GET_INT
, NULL
, 1);
667 /*** Data transfer ***/
669 static void mspro_block_process_request(struct memstick_dev
*card
,
672 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
673 struct mspro_param_register param
;
675 unsigned short page_count
;
681 msb
->current_seg
= 0;
682 msb
->seg_count
= blk_rq_map_sg(req
->q
, req
, msb
->req_sg
);
684 if (msb
->seg_count
) {
685 msb
->current_page
= 0;
686 for (rc
= 0; rc
< msb
->seg_count
; rc
++)
687 page_count
+= msb
->req_sg
[rc
].length
691 sector_div(t_sec
, msb
->page_size
>> 9);
692 param
.system
= msb
->system
;
693 param
.data_count
= cpu_to_be16(page_count
);
694 param
.data_address
= cpu_to_be32((uint32_t)t_sec
);
697 msb
->data_dir
= rq_data_dir(req
);
698 msb
->transfer_cmd
= msb
->data_dir
== READ
699 ? MSPRO_CMD_READ_DATA
700 : MSPRO_CMD_WRITE_DATA
;
702 dev_dbg(&card
->dev
, "data transfer: cmd %x, "
703 "lba %x, count %x\n", msb
->transfer_cmd
,
704 be32_to_cpu(param
.data_address
),
707 card
->next_request
= h_mspro_block_req_init
;
708 msb
->mrq_handler
= h_mspro_block_transfer_data
;
709 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
710 ¶m
, sizeof(param
));
711 memstick_new_req(card
->host
);
712 wait_for_completion(&card
->mrq_complete
);
713 rc
= card
->current_mrq
.error
;
715 if (rc
|| (card
->current_mrq
.tpc
== MSPRO_CMD_STOP
)) {
716 for (cnt
= 0; cnt
< msb
->current_seg
; cnt
++)
717 page_count
+= msb
->req_sg
[cnt
].length
720 if (msb
->current_page
)
721 page_count
+= msb
->current_page
- 1;
723 if (page_count
&& (msb
->data_dir
== READ
))
724 rc
= msb
->page_size
* page_count
;
728 rc
= msb
->page_size
* page_count
;
732 spin_lock_irqsave(&msb
->q_lock
, flags
);
734 chunk
= __blk_end_request(req
, 0, rc
);
736 chunk
= __blk_end_request(req
, rc
, 0);
738 dev_dbg(&card
->dev
, "end chunk %d, %d\n", rc
, chunk
);
739 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
743 static int mspro_block_has_request(struct mspro_block_data
*msb
)
748 spin_lock_irqsave(&msb
->q_lock
, flags
);
749 if (kthread_should_stop() || msb
->has_request
)
751 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
755 static int mspro_block_queue_thread(void *data
)
757 struct memstick_dev
*card
= data
;
758 struct memstick_host
*host
= card
->host
;
759 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
764 wait_event(msb
->q_wait
, mspro_block_has_request(msb
));
765 dev_dbg(&card
->dev
, "thread iter\n");
767 spin_lock_irqsave(&msb
->q_lock
, flags
);
768 req
= elv_next_request(msb
->queue
);
769 dev_dbg(&card
->dev
, "next req %p\n", req
);
771 msb
->has_request
= 0;
772 if (kthread_should_stop()) {
773 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
777 msb
->has_request
= 1;
778 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
781 mutex_lock(&host
->lock
);
782 mspro_block_process_request(card
, req
);
783 mutex_unlock(&host
->lock
);
786 dev_dbg(&card
->dev
, "thread finished\n");
790 static void mspro_block_request(struct request_queue
*q
)
792 struct memstick_dev
*card
= q
->queuedata
;
793 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
794 struct request
*req
= NULL
;
797 msb
->has_request
= 1;
798 wake_up_all(&msb
->q_wait
);
800 while ((req
= elv_next_request(q
)) != NULL
)
801 end_queued_request(req
, -ENODEV
);
805 /*** Initialization ***/
807 static int mspro_block_wait_for_ced(struct memstick_dev
*card
)
809 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
811 card
->next_request
= h_mspro_block_req_init
;
812 msb
->mrq_handler
= h_mspro_block_wait_for_ced
;
813 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
814 memstick_new_req(card
->host
);
815 wait_for_completion(&card
->mrq_complete
);
816 return card
->current_mrq
.error
;
819 static int mspro_block_set_interface(struct memstick_dev
*card
,
820 unsigned char sys_reg
)
822 struct memstick_host
*host
= card
->host
;
823 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
824 struct mspro_param_register param
= {
831 card
->next_request
= h_mspro_block_req_init
;
832 msb
->mrq_handler
= h_mspro_block_default
;
833 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
835 memstick_new_req(host
);
836 wait_for_completion(&card
->mrq_complete
);
837 return card
->current_mrq
.error
;
840 static int mspro_block_switch_interface(struct memstick_dev
*card
)
842 struct memstick_host
*host
= card
->host
;
843 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
846 if (msb
->caps
& MEMSTICK_CAP_PAR4
)
847 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR4
);
853 "%s: could not switch to 4-bit mode, error %d\n",
854 card
->dev
.bus_id
, rc
);
858 msb
->system
= MEMSTICK_SYS_PAR4
;
859 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_PAR4
);
860 printk(KERN_INFO
"%s: switching to 4-bit parallel mode\n",
863 if (msb
->caps
& MEMSTICK_CAP_PAR8
) {
864 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR8
);
867 msb
->system
= MEMSTICK_SYS_PAR8
;
868 host
->set_param(host
, MEMSTICK_INTERFACE
,
871 "%s: switching to 8-bit parallel mode\n",
875 "%s: could not switch to 8-bit mode, error %d\n",
876 card
->dev
.bus_id
, rc
);
879 card
->next_request
= h_mspro_block_req_init
;
880 msb
->mrq_handler
= h_mspro_block_default
;
881 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
882 memstick_new_req(card
->host
);
883 wait_for_completion(&card
->mrq_complete
);
884 rc
= card
->current_mrq
.error
;
888 "%s: interface error, trying to fall back to serial\n",
890 msb
->system
= MEMSTICK_SYS_SERIAL
;
891 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_OFF
);
893 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_ON
);
894 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_SERIAL
);
896 rc
= memstick_set_rw_addr(card
);
898 rc
= mspro_block_set_interface(card
, msb
->system
);
903 /* Memory allocated for attributes by this function should be freed by
904 * mspro_block_data_clear, no matter if the initialization process succeded
907 static int mspro_block_read_attributes(struct memstick_dev
*card
)
909 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
910 struct mspro_param_register param
= {
911 .system
= msb
->system
,
912 .data_count
= cpu_to_be16(1),
916 struct mspro_attribute
*attr
= NULL
;
917 struct mspro_sys_attr
*s_attr
= NULL
;
918 unsigned char *buffer
= NULL
;
919 int cnt
, rc
, attr_count
;
921 unsigned short page_count
;
923 attr
= kmalloc(msb
->page_size
, GFP_KERNEL
);
927 sg_init_one(&msb
->req_sg
[0], attr
, msb
->page_size
);
929 msb
->current_seg
= 0;
930 msb
->current_page
= 0;
931 msb
->data_dir
= READ
;
932 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
934 card
->next_request
= h_mspro_block_req_init
;
935 msb
->mrq_handler
= h_mspro_block_transfer_data
;
936 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
938 memstick_new_req(card
->host
);
939 wait_for_completion(&card
->mrq_complete
);
940 if (card
->current_mrq
.error
) {
941 rc
= card
->current_mrq
.error
;
945 if (be16_to_cpu(attr
->signature
) != MSPRO_BLOCK_SIGNATURE
) {
946 printk(KERN_ERR
"%s: unrecognized device signature %x\n",
947 card
->dev
.bus_id
, be16_to_cpu(attr
->signature
));
952 if (attr
->count
> MSPRO_BLOCK_MAX_ATTRIBUTES
) {
953 printk(KERN_WARNING
"%s: way too many attribute entries\n",
955 attr_count
= MSPRO_BLOCK_MAX_ATTRIBUTES
;
957 attr_count
= attr
->count
;
959 msb
->attr_group
.attrs
= kzalloc((attr_count
+ 1)
960 * sizeof(struct attribute
),
962 if (!msb
->attr_group
.attrs
) {
966 msb
->attr_group
.name
= "media_attributes";
968 buffer
= kmalloc(msb
->page_size
, GFP_KERNEL
);
973 memcpy(buffer
, (char *)attr
, msb
->page_size
);
976 for (cnt
= 0; cnt
< attr_count
; ++cnt
) {
977 s_attr
= kzalloc(sizeof(struct mspro_sys_attr
), GFP_KERNEL
);
980 goto out_free_buffer
;
983 msb
->attr_group
.attrs
[cnt
] = &s_attr
->dev_attr
.attr
;
984 addr
= be32_to_cpu(attr
->entries
[cnt
].address
);
985 rc
= be32_to_cpu(attr
->entries
[cnt
].size
);
986 dev_dbg(&card
->dev
, "adding attribute %d: id %x, address %x, "
987 "size %x\n", cnt
, attr
->entries
[cnt
].id
, addr
, rc
);
988 s_attr
->id
= attr
->entries
[cnt
].id
;
989 if (mspro_block_attr_name(s_attr
->id
))
990 snprintf(s_attr
->name
, sizeof(s_attr
->name
), "%s",
991 mspro_block_attr_name(attr
->entries
[cnt
].id
));
993 snprintf(s_attr
->name
, sizeof(s_attr
->name
),
994 "attr_x%02x", attr
->entries
[cnt
].id
);
996 s_attr
->dev_attr
.attr
.name
= s_attr
->name
;
997 s_attr
->dev_attr
.attr
.mode
= S_IRUGO
;
998 s_attr
->dev_attr
.attr
.owner
= THIS_MODULE
;
999 s_attr
->dev_attr
.show
= mspro_block_attr_show(s_attr
->id
);
1005 s_attr
->data
= kmalloc(rc
, GFP_KERNEL
);
1006 if (!s_attr
->data
) {
1008 goto out_free_buffer
;
1011 if (((addr
/ msb
->page_size
)
1012 == be32_to_cpu(param
.data_address
))
1013 && (((addr
+ rc
- 1) / msb
->page_size
)
1014 == be32_to_cpu(param
.data_address
))) {
1015 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1020 if (page_count
<= (rc
/ msb
->page_size
)) {
1022 page_count
= (rc
/ msb
->page_size
) + 1;
1023 buffer
= kmalloc(page_count
* msb
->page_size
,
1031 param
.system
= msb
->system
;
1032 param
.data_count
= cpu_to_be16((rc
/ msb
->page_size
) + 1);
1033 param
.data_address
= cpu_to_be32(addr
/ msb
->page_size
);
1034 param
.tpc_param
= 0;
1036 sg_init_one(&msb
->req_sg
[0], buffer
,
1037 be16_to_cpu(param
.data_count
) * msb
->page_size
);
1039 msb
->current_seg
= 0;
1040 msb
->current_page
= 0;
1041 msb
->data_dir
= READ
;
1042 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
1044 dev_dbg(&card
->dev
, "reading attribute pages %x, %x\n",
1045 be32_to_cpu(param
.data_address
),
1046 be16_to_cpu(param
.data_count
));
1048 card
->next_request
= h_mspro_block_req_init
;
1049 msb
->mrq_handler
= h_mspro_block_transfer_data
;
1050 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
1051 (char *)¶m
, sizeof(param
));
1052 memstick_new_req(card
->host
);
1053 wait_for_completion(&card
->mrq_complete
);
1054 if (card
->current_mrq
.error
) {
1055 rc
= card
->current_mrq
.error
;
1056 goto out_free_buffer
;
1059 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
, rc
);
1070 static int mspro_block_init_card(struct memstick_dev
*card
)
1072 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1073 struct memstick_host
*host
= card
->host
;
1076 msb
->system
= MEMSTICK_SYS_SERIAL
;
1077 card
->reg_addr
.r_offset
= offsetof(struct mspro_register
, status
);
1078 card
->reg_addr
.r_length
= sizeof(struct ms_status_register
);
1079 card
->reg_addr
.w_offset
= offsetof(struct mspro_register
, param
);
1080 card
->reg_addr
.w_length
= sizeof(struct mspro_param_register
);
1082 if (memstick_set_rw_addr(card
))
1085 msb
->caps
= host
->caps
;
1086 rc
= mspro_block_switch_interface(card
);
1091 rc
= mspro_block_wait_for_ced(card
);
1094 dev_dbg(&card
->dev
, "card activated\n");
1095 if (msb
->system
!= MEMSTICK_SYS_SERIAL
)
1096 msb
->caps
|= MEMSTICK_CAP_AUTO_GET_INT
;
1098 card
->next_request
= h_mspro_block_req_init
;
1099 msb
->mrq_handler
= h_mspro_block_get_ro
;
1100 memstick_init_req(&card
->current_mrq
, MS_TPC_READ_REG
, NULL
,
1101 sizeof(struct ms_status_register
));
1102 memstick_new_req(card
->host
);
1103 wait_for_completion(&card
->mrq_complete
);
1104 if (card
->current_mrq
.error
)
1105 return card
->current_mrq
.error
;
1107 dev_dbg(&card
->dev
, "card r/w status %d\n", msb
->read_only
? 0 : 1);
1109 msb
->page_size
= 512;
1110 rc
= mspro_block_read_attributes(card
);
1114 dev_dbg(&card
->dev
, "attributes loaded\n");
1119 static int mspro_block_init_disk(struct memstick_dev
*card
)
1121 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1122 struct memstick_host
*host
= card
->host
;
1123 struct mspro_devinfo
*dev_info
= NULL
;
1124 struct mspro_sys_info
*sys_info
= NULL
;
1125 struct mspro_sys_attr
*s_attr
= NULL
;
1127 u64 limit
= BLK_BOUNCE_HIGH
;
1128 unsigned long capacity
;
1130 if (host
->cdev
.dev
->dma_mask
&& *(host
->cdev
.dev
->dma_mask
))
1131 limit
= *(host
->cdev
.dev
->dma_mask
);
1133 for (rc
= 0; msb
->attr_group
.attrs
[rc
]; ++rc
) {
1134 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[rc
]);
1136 if (s_attr
->id
== MSPRO_BLOCK_ID_DEVINFO
)
1137 dev_info
= s_attr
->data
;
1138 else if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
)
1139 sys_info
= s_attr
->data
;
1142 if (!dev_info
|| !sys_info
)
1145 msb
->cylinders
= be16_to_cpu(dev_info
->cylinders
);
1146 msb
->heads
= be16_to_cpu(dev_info
->heads
);
1147 msb
->sectors_per_track
= be16_to_cpu(dev_info
->sectors_per_track
);
1149 msb
->page_size
= be16_to_cpu(sys_info
->unit_size
);
1151 if (!idr_pre_get(&mspro_block_disk_idr
, GFP_KERNEL
))
1154 mutex_lock(&mspro_block_disk_lock
);
1155 rc
= idr_get_new(&mspro_block_disk_idr
, card
, &disk_id
);
1156 mutex_unlock(&mspro_block_disk_lock
);
1161 if ((disk_id
<< MEMSTICK_PART_SHIFT
) > 255) {
1163 goto out_release_id
;
1166 msb
->disk
= alloc_disk(1 << MEMSTICK_PART_SHIFT
);
1169 goto out_release_id
;
1172 spin_lock_init(&msb
->q_lock
);
1173 init_waitqueue_head(&msb
->q_wait
);
1175 msb
->queue
= blk_init_queue(mspro_block_request
, &msb
->q_lock
);
1181 msb
->queue
->queuedata
= card
;
1183 blk_queue_bounce_limit(msb
->queue
, limit
);
1184 blk_queue_max_sectors(msb
->queue
, MSPRO_BLOCK_MAX_PAGES
);
1185 blk_queue_max_phys_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1186 blk_queue_max_hw_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1187 blk_queue_max_segment_size(msb
->queue
,
1188 MSPRO_BLOCK_MAX_PAGES
* msb
->page_size
);
1190 msb
->disk
->major
= major
;
1191 msb
->disk
->first_minor
= disk_id
<< MEMSTICK_PART_SHIFT
;
1192 msb
->disk
->fops
= &ms_block_bdops
;
1193 msb
->usage_count
= 1;
1194 msb
->disk
->private_data
= msb
;
1195 msb
->disk
->queue
= msb
->queue
;
1196 msb
->disk
->driverfs_dev
= &card
->dev
;
1198 sprintf(msb
->disk
->disk_name
, "mspblk%d", disk_id
);
1200 blk_queue_hardsect_size(msb
->queue
, msb
->page_size
);
1202 capacity
= be16_to_cpu(sys_info
->user_block_count
);
1203 capacity
*= be16_to_cpu(sys_info
->block_size
);
1204 capacity
*= msb
->page_size
>> 9;
1205 set_capacity(msb
->disk
, capacity
);
1206 dev_dbg(&card
->dev
, "capacity set %ld\n", capacity
);
1207 msb
->q_thread
= kthread_run(mspro_block_queue_thread
, card
,
1209 if (IS_ERR(msb
->q_thread
))
1212 mutex_unlock(&host
->lock
);
1213 add_disk(msb
->disk
);
1214 mutex_lock(&host
->lock
);
1219 put_disk(msb
->disk
);
1221 mutex_lock(&mspro_block_disk_lock
);
1222 idr_remove(&mspro_block_disk_idr
, disk_id
);
1223 mutex_unlock(&mspro_block_disk_lock
);
1227 static void mspro_block_data_clear(struct mspro_block_data
*msb
)
1230 struct mspro_sys_attr
*s_attr
;
1232 if (msb
->attr_group
.attrs
) {
1233 for (cnt
= 0; msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1234 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
1236 kfree(s_attr
->data
);
1239 kfree(msb
->attr_group
.attrs
);
1245 static int mspro_block_check_card(struct memstick_dev
*card
)
1247 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1249 return (msb
->active
== 1);
1252 static int mspro_block_probe(struct memstick_dev
*card
)
1254 struct mspro_block_data
*msb
;
1257 msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1260 memstick_set_drvdata(card
, msb
);
1263 rc
= mspro_block_init_card(card
);
1268 rc
= sysfs_create_group(&card
->dev
.kobj
, &msb
->attr_group
);
1272 rc
= mspro_block_init_disk(card
);
1274 card
->check
= mspro_block_check_card
;
1278 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1280 memstick_set_drvdata(card
, NULL
);
1281 mspro_block_data_clear(msb
);
1286 static void mspro_block_remove(struct memstick_dev
*card
)
1288 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1289 struct task_struct
*q_thread
= NULL
;
1290 unsigned long flags
;
1292 del_gendisk(msb
->disk
);
1293 dev_dbg(&card
->dev
, "mspro block remove\n");
1294 spin_lock_irqsave(&msb
->q_lock
, flags
);
1295 q_thread
= msb
->q_thread
;
1296 msb
->q_thread
= NULL
;
1298 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1301 mutex_unlock(&card
->host
->lock
);
1302 kthread_stop(q_thread
);
1303 mutex_lock(&card
->host
->lock
);
1306 dev_dbg(&card
->dev
, "queue thread stopped\n");
1308 blk_cleanup_queue(msb
->queue
);
1310 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1312 mutex_lock(&mspro_block_disk_lock
);
1313 mspro_block_data_clear(msb
);
1314 mutex_unlock(&mspro_block_disk_lock
);
1316 mspro_block_disk_release(msb
->disk
);
1317 memstick_set_drvdata(card
, NULL
);
1322 static int mspro_block_suspend(struct memstick_dev
*card
, pm_message_t state
)
1324 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1325 struct task_struct
*q_thread
= NULL
;
1326 unsigned long flags
;
1328 spin_lock_irqsave(&msb
->q_lock
, flags
);
1329 q_thread
= msb
->q_thread
;
1330 msb
->q_thread
= NULL
;
1332 blk_stop_queue(msb
->queue
);
1333 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1336 kthread_stop(q_thread
);
1341 static int mspro_block_resume(struct memstick_dev
*card
)
1343 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1344 unsigned long flags
;
1347 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
1349 struct mspro_block_data
*new_msb
;
1350 struct memstick_host
*host
= card
->host
;
1351 struct mspro_sys_attr
*s_attr
, *r_attr
;
1354 mutex_lock(&host
->lock
);
1355 new_msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1361 new_msb
->card
= card
;
1362 memstick_set_drvdata(card
, new_msb
);
1363 if (mspro_block_init_card(card
))
1366 for (cnt
= 0; new_msb
->attr_group
.attrs
[cnt
]
1367 && msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1368 s_attr
= mspro_from_sysfs_attr(new_msb
->attr_group
.attrs
[cnt
]);
1369 r_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[cnt
]);
1371 if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
1372 && r_attr
->id
== s_attr
->id
) {
1373 if (memcmp(s_attr
->data
, r_attr
->data
, s_attr
->size
))
1376 memstick_set_drvdata(card
, msb
);
1377 msb
->q_thread
= kthread_run(mspro_block_queue_thread
,
1378 card
, DRIVER_NAME
"d");
1379 if (IS_ERR(msb
->q_thread
))
1380 msb
->q_thread
= NULL
;
1389 memstick_set_drvdata(card
, msb
);
1390 mspro_block_data_clear(new_msb
);
1393 mutex_unlock(&host
->lock
);
1395 #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
1397 spin_lock_irqsave(&msb
->q_lock
, flags
);
1398 blk_start_queue(msb
->queue
);
1399 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1405 #define mspro_block_suspend NULL
1406 #define mspro_block_resume NULL
1408 #endif /* CONFIG_PM */
1410 static struct memstick_device_id mspro_block_id_tbl
[] = {
1411 {MEMSTICK_MATCH_ALL
, MEMSTICK_TYPE_PRO
, MEMSTICK_CATEGORY_STORAGE_DUO
,
1412 MEMSTICK_CLASS_GENERIC_DUO
},
1417 static struct memstick_driver mspro_block_driver
= {
1419 .name
= DRIVER_NAME
,
1420 .owner
= THIS_MODULE
1422 .id_table
= mspro_block_id_tbl
,
1423 .probe
= mspro_block_probe
,
1424 .remove
= mspro_block_remove
,
1425 .suspend
= mspro_block_suspend
,
1426 .resume
= mspro_block_resume
1429 static int __init
mspro_block_init(void)
1433 rc
= register_blkdev(major
, DRIVER_NAME
);
1435 printk(KERN_ERR DRIVER_NAME
": failed to register "
1436 "major %d, error %d\n", major
, rc
);
1442 rc
= memstick_register_driver(&mspro_block_driver
);
1444 unregister_blkdev(major
, DRIVER_NAME
);
1448 static void __exit
mspro_block_exit(void)
1450 memstick_unregister_driver(&mspro_block_driver
);
1451 unregister_blkdev(major
, DRIVER_NAME
);
1452 idr_destroy(&mspro_block_disk_idr
);
1455 module_init(mspro_block_init
);
1456 module_exit(mspro_block_exit
);
1458 MODULE_LICENSE("GPL");
1459 MODULE_AUTHOR("Alex Dubov");
1460 MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
1461 MODULE_DEVICE_TABLE(memstick
, mspro_block_id_tbl
);