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/slab.h>
21 #include <linux/mutex.h>
22 #include <linux/memstick.h>
23 #include <linux/module.h>
25 #define DRIVER_NAME "mspro_block"
28 module_param(major
, int, 0644);
30 #define MSPRO_BLOCK_MAX_SEGS 32
31 #define MSPRO_BLOCK_MAX_PAGES ((2 << 16) - 1)
33 #define MSPRO_BLOCK_SIGNATURE 0xa5c3
34 #define MSPRO_BLOCK_MAX_ATTRIBUTES 41
36 #define MSPRO_BLOCK_PART_SHIFT 3
39 MSPRO_BLOCK_ID_SYSINFO
= 0x10,
40 MSPRO_BLOCK_ID_MODELNAME
= 0x15,
41 MSPRO_BLOCK_ID_MBR
= 0x20,
42 MSPRO_BLOCK_ID_PBR16
= 0x21,
43 MSPRO_BLOCK_ID_PBR32
= 0x22,
44 MSPRO_BLOCK_ID_SPECFILEVALUES1
= 0x25,
45 MSPRO_BLOCK_ID_SPECFILEVALUES2
= 0x26,
46 MSPRO_BLOCK_ID_DEVINFO
= 0x30
49 struct mspro_sys_attr
{
54 struct device_attribute dev_attr
;
57 struct mspro_attr_entry
{
61 unsigned char reserved
[3];
62 } __attribute__((packed
));
64 struct mspro_attribute
{
66 unsigned short version
;
68 unsigned char reserved
[11];
69 struct mspro_attr_entry entries
[];
70 } __attribute__((packed
));
72 struct mspro_sys_info
{
74 unsigned char reserved0
;
77 __be16 user_block_count
;
79 unsigned char reserved1
[2];
80 unsigned char assembly_date
[8];
82 unsigned char assembly_maker_code
;
83 unsigned char assembly_model_code
[3];
84 __be16 memory_maker_code
;
85 __be16 memory_model_code
;
86 unsigned char reserved2
[4];
89 __be16 controller_number
;
90 __be16 controller_function
;
93 unsigned char ms_sub_class
;
94 unsigned char reserved3
[4];
95 unsigned char interface_type
;
96 __be16 controller_code
;
97 unsigned char format_type
;
98 unsigned char reserved4
;
99 unsigned char device_type
;
100 unsigned char reserved5
[7];
101 unsigned char mspro_id
[16];
102 unsigned char reserved6
[16];
103 } __attribute__((packed
));
106 unsigned char boot_partition
;
107 unsigned char start_head
;
108 unsigned char start_sector
;
109 unsigned char start_cylinder
;
110 unsigned char partition_type
;
111 unsigned char end_head
;
112 unsigned char end_sector
;
113 unsigned char end_cylinder
;
114 unsigned int start_sectors
;
115 unsigned int sectors_per_partition
;
116 } __attribute__((packed
));
118 struct mspro_specfile
{
122 unsigned char reserved
[10];
125 unsigned short cluster
;
127 } __attribute__((packed
));
129 struct mspro_devinfo
{
132 __be16 bytes_per_track
;
133 __be16 bytes_per_sector
;
134 __be16 sectors_per_track
;
135 unsigned char reserved
[6];
136 } __attribute__((packed
));
138 struct mspro_block_data
{
139 struct memstick_dev
*card
;
140 unsigned int usage_count
;
142 struct gendisk
*disk
;
143 struct request_queue
*queue
;
144 struct request
*block_req
;
147 unsigned short page_size
;
148 unsigned short cylinders
;
149 unsigned short heads
;
150 unsigned short sectors_per_track
;
152 unsigned char system
;
153 unsigned char read_only
:1,
158 unsigned char transfer_cmd
;
160 int (*mrq_handler
)(struct memstick_dev
*card
,
161 struct memstick_request
**mrq
);
164 /* Default request setup function for data access method preferred by
165 * this host instance.
167 void (*setup_transfer
)(struct memstick_dev
*card
,
168 u64 offset
, size_t length
);
170 struct attribute_group attr_group
;
172 struct scatterlist req_sg
[MSPRO_BLOCK_MAX_SEGS
];
173 unsigned int seg_count
;
174 unsigned int current_seg
;
175 unsigned int current_page
;
178 static DEFINE_IDR(mspro_block_disk_idr
);
179 static DEFINE_MUTEX(mspro_block_disk_lock
);
181 static int mspro_block_complete_req(struct memstick_dev
*card
, int error
);
183 /*** Block device ***/
185 static int mspro_block_bd_open(struct block_device
*bdev
, fmode_t mode
)
187 struct gendisk
*disk
= bdev
->bd_disk
;
188 struct mspro_block_data
*msb
= disk
->private_data
;
191 mutex_lock(&mspro_block_disk_lock
);
193 if (msb
&& msb
->card
) {
195 if ((mode
& FMODE_WRITE
) && msb
->read_only
)
201 mutex_unlock(&mspro_block_disk_lock
);
207 static int mspro_block_disk_release(struct gendisk
*disk
)
209 struct mspro_block_data
*msb
= disk
->private_data
;
210 int disk_id
= MINOR(disk_devt(disk
)) >> MSPRO_BLOCK_PART_SHIFT
;
212 mutex_lock(&mspro_block_disk_lock
);
215 if (msb
->usage_count
)
218 if (!msb
->usage_count
) {
220 disk
->private_data
= NULL
;
221 idr_remove(&mspro_block_disk_idr
, disk_id
);
226 mutex_unlock(&mspro_block_disk_lock
);
231 static int mspro_block_bd_release(struct gendisk
*disk
, fmode_t mode
)
233 return mspro_block_disk_release(disk
);
236 static int mspro_block_bd_getgeo(struct block_device
*bdev
,
237 struct hd_geometry
*geo
)
239 struct mspro_block_data
*msb
= bdev
->bd_disk
->private_data
;
241 geo
->heads
= msb
->heads
;
242 geo
->sectors
= msb
->sectors_per_track
;
243 geo
->cylinders
= msb
->cylinders
;
248 static const struct block_device_operations ms_block_bdops
= {
249 .open
= mspro_block_bd_open
,
250 .release
= mspro_block_bd_release
,
251 .getgeo
= mspro_block_bd_getgeo
,
255 /*** Information ***/
257 static struct mspro_sys_attr
*mspro_from_sysfs_attr(struct attribute
*attr
)
259 struct device_attribute
*dev_attr
260 = container_of(attr
, struct device_attribute
, attr
);
261 return container_of(dev_attr
, struct mspro_sys_attr
, dev_attr
);
264 static const char *mspro_block_attr_name(unsigned char tag
)
267 case MSPRO_BLOCK_ID_SYSINFO
:
268 return "attr_sysinfo";
269 case MSPRO_BLOCK_ID_MODELNAME
:
270 return "attr_modelname";
271 case MSPRO_BLOCK_ID_MBR
:
273 case MSPRO_BLOCK_ID_PBR16
:
275 case MSPRO_BLOCK_ID_PBR32
:
277 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
278 return "attr_specfilevalues1";
279 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
280 return "attr_specfilevalues2";
281 case MSPRO_BLOCK_ID_DEVINFO
:
282 return "attr_devinfo";
288 typedef ssize_t (*sysfs_show_t
)(struct device
*dev
,
289 struct device_attribute
*attr
,
292 static ssize_t
mspro_block_attr_show_default(struct device
*dev
,
293 struct device_attribute
*attr
,
296 struct mspro_sys_attr
*s_attr
= container_of(attr
,
297 struct mspro_sys_attr
,
302 for (cnt
= 0; cnt
< s_attr
->size
; cnt
++) {
303 if (cnt
&& !(cnt
% 16)) {
308 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "%02x ",
309 ((unsigned char *)s_attr
->data
)[cnt
]);
314 static ssize_t
mspro_block_attr_show_sysinfo(struct device
*dev
,
315 struct device_attribute
*attr
,
318 struct mspro_sys_attr
*x_attr
= container_of(attr
,
319 struct mspro_sys_attr
,
321 struct mspro_sys_info
*x_sys
= x_attr
->data
;
323 int date_tz
= 0, date_tz_f
= 0;
325 if (x_sys
->assembly_date
[0] > 0x80U
) {
326 date_tz
= (~x_sys
->assembly_date
[0]) + 1;
327 date_tz_f
= date_tz
& 3;
331 } else if (x_sys
->assembly_date
[0] < 0x80U
) {
332 date_tz
= x_sys
->assembly_date
[0];
333 date_tz_f
= date_tz
& 3;
338 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "class: %x\n",
340 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block size: %x\n",
341 be16_to_cpu(x_sys
->block_size
));
342 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "block count: %x\n",
343 be16_to_cpu(x_sys
->block_count
));
344 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "user block count: %x\n",
345 be16_to_cpu(x_sys
->user_block_count
));
346 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "page size: %x\n",
347 be16_to_cpu(x_sys
->page_size
));
348 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly date: "
349 "GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
351 be16_to_cpup((__be16
*)&x_sys
->assembly_date
[1]),
352 x_sys
->assembly_date
[3], x_sys
->assembly_date
[4],
353 x_sys
->assembly_date
[5], x_sys
->assembly_date
[6],
354 x_sys
->assembly_date
[7]);
355 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "serial number: %x\n",
356 be32_to_cpu(x_sys
->serial_number
));
357 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
358 "assembly maker code: %x\n",
359 x_sys
->assembly_maker_code
);
360 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "assembly model code: "
361 "%02x%02x%02x\n", x_sys
->assembly_model_code
[0],
362 x_sys
->assembly_model_code
[1],
363 x_sys
->assembly_model_code
[2]);
364 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory maker code: %x\n",
365 be16_to_cpu(x_sys
->memory_maker_code
));
366 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "memory model code: %x\n",
367 be16_to_cpu(x_sys
->memory_model_code
));
368 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vcc: %x\n",
370 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "vpp: %x\n",
372 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller number: %x\n",
373 be16_to_cpu(x_sys
->controller_number
));
374 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
375 "controller function: %x\n",
376 be16_to_cpu(x_sys
->controller_function
));
377 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
378 be16_to_cpu(x_sys
->start_sector
));
379 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "unit size: %x\n",
380 be16_to_cpu(x_sys
->unit_size
));
381 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sub class: %x\n",
382 x_sys
->ms_sub_class
);
383 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "interface type: %x\n",
384 x_sys
->interface_type
);
385 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "controller code: %x\n",
386 be16_to_cpu(x_sys
->controller_code
));
387 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "format type: %x\n",
389 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "device type: %x\n",
391 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "mspro id: %s\n",
396 static ssize_t
mspro_block_attr_show_modelname(struct device
*dev
,
397 struct device_attribute
*attr
,
400 struct mspro_sys_attr
*s_attr
= container_of(attr
,
401 struct mspro_sys_attr
,
404 return scnprintf(buffer
, PAGE_SIZE
, "%s", (char *)s_attr
->data
);
407 static ssize_t
mspro_block_attr_show_mbr(struct device
*dev
,
408 struct device_attribute
*attr
,
411 struct mspro_sys_attr
*x_attr
= container_of(attr
,
412 struct mspro_sys_attr
,
414 struct mspro_mbr
*x_mbr
= x_attr
->data
;
417 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "boot partition: %x\n",
418 x_mbr
->boot_partition
);
419 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start head: %x\n",
421 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sector: %x\n",
422 x_mbr
->start_sector
);
423 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cylinder: %x\n",
424 x_mbr
->start_cylinder
);
425 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "partition type: %x\n",
426 x_mbr
->partition_type
);
427 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end head: %x\n",
429 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end sector: %x\n",
431 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "end cylinder: %x\n",
432 x_mbr
->end_cylinder
);
433 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start sectors: %x\n",
434 x_mbr
->start_sectors
);
435 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
,
436 "sectors per partition: %x\n",
437 x_mbr
->sectors_per_partition
);
441 static ssize_t
mspro_block_attr_show_specfile(struct device
*dev
,
442 struct device_attribute
*attr
,
445 struct mspro_sys_attr
*x_attr
= container_of(attr
,
446 struct mspro_sys_attr
,
448 struct mspro_specfile
*x_spfile
= x_attr
->data
;
449 char name
[9], ext
[4];
452 memcpy(name
, x_spfile
->name
, 8);
454 memcpy(ext
, x_spfile
->ext
, 3);
457 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "name: %s\n", name
);
458 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "ext: %s\n", ext
);
459 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "attribute: %x\n",
461 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "time: %d:%d:%d\n",
462 x_spfile
->time
>> 11,
463 (x_spfile
->time
>> 5) & 0x3f,
464 (x_spfile
->time
& 0x1f) * 2);
465 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "date: %d-%d-%d\n",
466 (x_spfile
->date
>> 9) + 1980,
467 (x_spfile
->date
>> 5) & 0xf,
468 x_spfile
->date
& 0x1f);
469 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "start cluster: %x\n",
471 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "size: %x\n",
476 static ssize_t
mspro_block_attr_show_devinfo(struct device
*dev
,
477 struct device_attribute
*attr
,
480 struct mspro_sys_attr
*x_attr
= container_of(attr
,
481 struct mspro_sys_attr
,
483 struct mspro_devinfo
*x_devinfo
= x_attr
->data
;
486 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "cylinders: %x\n",
487 be16_to_cpu(x_devinfo
->cylinders
));
488 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "heads: %x\n",
489 be16_to_cpu(x_devinfo
->heads
));
490 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per track: %x\n",
491 be16_to_cpu(x_devinfo
->bytes_per_track
));
492 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "bytes per sector: %x\n",
493 be16_to_cpu(x_devinfo
->bytes_per_sector
));
494 rc
+= scnprintf(buffer
+ rc
, PAGE_SIZE
- rc
, "sectors per track: %x\n",
495 be16_to_cpu(x_devinfo
->sectors_per_track
));
499 static sysfs_show_t
mspro_block_attr_show(unsigned char tag
)
502 case MSPRO_BLOCK_ID_SYSINFO
:
503 return mspro_block_attr_show_sysinfo
;
504 case MSPRO_BLOCK_ID_MODELNAME
:
505 return mspro_block_attr_show_modelname
;
506 case MSPRO_BLOCK_ID_MBR
:
507 return mspro_block_attr_show_mbr
;
508 case MSPRO_BLOCK_ID_SPECFILEVALUES1
:
509 case MSPRO_BLOCK_ID_SPECFILEVALUES2
:
510 return mspro_block_attr_show_specfile
;
511 case MSPRO_BLOCK_ID_DEVINFO
:
512 return mspro_block_attr_show_devinfo
;
514 return mspro_block_attr_show_default
;
518 /*** Protocol handlers ***/
521 * Functions prefixed with "h_" are protocol callbacks. They can be called from
522 * interrupt context. Return value of 0 means that request processing is still
523 * ongoing, while special error value of -EAGAIN means that current request is
524 * finished (and request processor should come back some time later).
527 static int h_mspro_block_req_init(struct memstick_dev
*card
,
528 struct memstick_request
**mrq
)
530 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
532 *mrq
= &card
->current_mrq
;
533 card
->next_request
= msb
->mrq_handler
;
537 static int h_mspro_block_default(struct memstick_dev
*card
,
538 struct memstick_request
**mrq
)
540 return mspro_block_complete_req(card
, (*mrq
)->error
);
543 static int h_mspro_block_default_bad(struct memstick_dev
*card
,
544 struct memstick_request
**mrq
)
549 static int h_mspro_block_get_ro(struct memstick_dev
*card
,
550 struct memstick_request
**mrq
)
552 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
554 if (!(*mrq
)->error
) {
555 if ((*mrq
)->data
[offsetof(struct ms_status_register
, status0
)]
556 & MEMSTICK_STATUS0_WP
)
562 return mspro_block_complete_req(card
, (*mrq
)->error
);
565 static int h_mspro_block_wait_for_ced(struct memstick_dev
*card
,
566 struct memstick_request
**mrq
)
568 dev_dbg(&card
->dev
, "wait for ced: value %x\n", (*mrq
)->data
[0]);
570 if (!(*mrq
)->error
) {
571 if ((*mrq
)->data
[0] & (MEMSTICK_INT_CMDNAK
| MEMSTICK_INT_ERR
))
572 (*mrq
)->error
= -EFAULT
;
573 else if (!((*mrq
)->data
[0] & MEMSTICK_INT_CED
))
577 return mspro_block_complete_req(card
, (*mrq
)->error
);
580 static int h_mspro_block_transfer_data(struct memstick_dev
*card
,
581 struct memstick_request
**mrq
)
583 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
584 unsigned char t_val
= 0;
585 struct scatterlist t_sg
= { 0 };
589 return mspro_block_complete_req(card
, (*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 return mspro_block_complete_req(card
,
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 /*** Transfer setup functions for different access methods. ***/
669 /** Setup data transfer request for SET_CMD TPC with arguments in card
672 * @card Current media instance
673 * @offset Target data offset in bytes
674 * @length Required transfer length in bytes.
676 static void h_mspro_block_setup_cmd(struct memstick_dev
*card
, u64 offset
,
679 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
680 struct mspro_param_register param
= {
681 .system
= msb
->system
,
682 .data_count
= cpu_to_be16((uint16_t)(length
/ msb
->page_size
)),
683 /* ISO C90 warning precludes direct initialization for now. */
688 do_div(offset
, msb
->page_size
);
689 param
.data_address
= cpu_to_be32((uint32_t)offset
);
691 card
->next_request
= h_mspro_block_req_init
;
692 msb
->mrq_handler
= h_mspro_block_transfer_data
;
693 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
,
694 ¶m
, sizeof(param
));
697 /*** Data transfer ***/
699 static int mspro_block_issue_req(struct memstick_dev
*card
, int chunk
)
701 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
707 msb
->current_page
= 0;
708 msb
->current_seg
= 0;
709 msb
->seg_count
= blk_rq_map_sg(msb
->block_req
->q
,
713 if (!msb
->seg_count
) {
714 chunk
= __blk_end_request_cur(msb
->block_req
, -ENOMEM
);
718 t_off
= blk_rq_pos(msb
->block_req
);
720 count
= blk_rq_bytes(msb
->block_req
);
722 msb
->setup_transfer(card
, t_off
, count
);
724 msb
->data_dir
= rq_data_dir(msb
->block_req
);
725 msb
->transfer_cmd
= msb
->data_dir
== READ
726 ? MSPRO_CMD_READ_DATA
727 : MSPRO_CMD_WRITE_DATA
;
729 memstick_new_req(card
->host
);
733 dev_dbg(&card
->dev
, "blk_fetch\n");
734 msb
->block_req
= blk_fetch_request(msb
->queue
);
735 if (!msb
->block_req
) {
736 dev_dbg(&card
->dev
, "issue end\n");
740 dev_dbg(&card
->dev
, "trying again\n");
745 static int mspro_block_complete_req(struct memstick_dev
*card
, int error
)
747 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
749 unsigned int t_len
= 0;
752 spin_lock_irqsave(&msb
->q_lock
, flags
);
753 dev_dbg(&card
->dev
, "complete %d, %d\n", msb
->has_request
? 1 : 0,
756 if (msb
->has_request
) {
757 /* Nothing to do - not really an error */
758 if (error
== -EAGAIN
)
761 if (error
|| (card
->current_mrq
.tpc
== MSPRO_CMD_STOP
)) {
762 if (msb
->data_dir
== READ
) {
763 for (cnt
= 0; cnt
< msb
->current_seg
; cnt
++)
764 t_len
+= msb
->req_sg
[cnt
].length
767 if (msb
->current_page
)
768 t_len
+= msb
->current_page
- 1;
770 t_len
*= msb
->page_size
;
773 t_len
= blk_rq_bytes(msb
->block_req
);
775 dev_dbg(&card
->dev
, "transferred %x (%d)\n", t_len
, error
);
778 t_len
= blk_rq_cur_bytes(msb
->block_req
);
780 chunk
= __blk_end_request(msb
->block_req
, error
, t_len
);
782 error
= mspro_block_issue_req(card
, chunk
);
787 msb
->has_request
= 0;
793 card
->next_request
= h_mspro_block_default_bad
;
794 complete_all(&card
->mrq_complete
);
796 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
800 static void mspro_block_stop(struct memstick_dev
*card
)
802 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
807 spin_lock_irqsave(&msb
->q_lock
, flags
);
808 if (!msb
->has_request
) {
809 blk_stop_queue(msb
->queue
);
812 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
817 wait_for_completion(&card
->mrq_complete
);
821 static void mspro_block_start(struct memstick_dev
*card
)
823 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
826 spin_lock_irqsave(&msb
->q_lock
, flags
);
827 blk_start_queue(msb
->queue
);
828 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
831 static int mspro_block_prepare_req(struct request_queue
*q
, struct request
*req
)
833 if (req
->cmd_type
!= REQ_TYPE_FS
&&
834 req
->cmd_type
!= REQ_TYPE_BLOCK_PC
) {
835 blk_dump_rq_flags(req
, "MSPro unsupported request");
839 req
->cmd_flags
|= REQ_DONTPREP
;
844 static void mspro_block_submit_req(struct request_queue
*q
)
846 struct memstick_dev
*card
= q
->queuedata
;
847 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
848 struct request
*req
= NULL
;
850 if (msb
->has_request
)
854 while ((req
= blk_fetch_request(q
)) != NULL
)
855 __blk_end_request_all(req
, -ENODEV
);
860 msb
->has_request
= 1;
861 if (mspro_block_issue_req(card
, 0))
862 msb
->has_request
= 0;
865 /*** Initialization ***/
867 static int mspro_block_wait_for_ced(struct memstick_dev
*card
)
869 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
871 card
->next_request
= h_mspro_block_req_init
;
872 msb
->mrq_handler
= h_mspro_block_wait_for_ced
;
873 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
874 memstick_new_req(card
->host
);
875 wait_for_completion(&card
->mrq_complete
);
876 return card
->current_mrq
.error
;
879 static int mspro_block_set_interface(struct memstick_dev
*card
,
880 unsigned char sys_reg
)
882 struct memstick_host
*host
= card
->host
;
883 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
884 struct mspro_param_register param
= {
891 card
->next_request
= h_mspro_block_req_init
;
892 msb
->mrq_handler
= h_mspro_block_default
;
893 memstick_init_req(&card
->current_mrq
, MS_TPC_WRITE_REG
, ¶m
,
895 memstick_new_req(host
);
896 wait_for_completion(&card
->mrq_complete
);
897 return card
->current_mrq
.error
;
900 static int mspro_block_switch_interface(struct memstick_dev
*card
)
902 struct memstick_host
*host
= card
->host
;
903 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
907 if (msb
->caps
& MEMSTICK_CAP_PAR4
)
908 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR4
);
914 "%s: could not switch to 4-bit mode, error %d\n",
915 dev_name(&card
->dev
), rc
);
919 msb
->system
= MEMSTICK_SYS_PAR4
;
920 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_PAR4
);
921 printk(KERN_INFO
"%s: switching to 4-bit parallel mode\n",
922 dev_name(&card
->dev
));
924 if (msb
->caps
& MEMSTICK_CAP_PAR8
) {
925 rc
= mspro_block_set_interface(card
, MEMSTICK_SYS_PAR8
);
928 msb
->system
= MEMSTICK_SYS_PAR8
;
929 host
->set_param(host
, MEMSTICK_INTERFACE
,
932 "%s: switching to 8-bit parallel mode\n",
933 dev_name(&card
->dev
));
936 "%s: could not switch to 8-bit mode, error %d\n",
937 dev_name(&card
->dev
), rc
);
940 card
->next_request
= h_mspro_block_req_init
;
941 msb
->mrq_handler
= h_mspro_block_default
;
942 memstick_init_req(&card
->current_mrq
, MS_TPC_GET_INT
, NULL
, 1);
943 memstick_new_req(card
->host
);
944 wait_for_completion(&card
->mrq_complete
);
945 rc
= card
->current_mrq
.error
;
949 "%s: interface error, trying to fall back to serial\n",
950 dev_name(&card
->dev
));
951 msb
->system
= MEMSTICK_SYS_SERIAL
;
952 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_OFF
);
954 host
->set_param(host
, MEMSTICK_POWER
, MEMSTICK_POWER_ON
);
955 host
->set_param(host
, MEMSTICK_INTERFACE
, MEMSTICK_SERIAL
);
957 rc
= memstick_set_rw_addr(card
);
959 rc
= mspro_block_set_interface(card
, msb
->system
);
963 rc
= mspro_block_wait_for_ced(card
);
967 if (msb
->caps
& MEMSTICK_CAP_PAR8
) {
968 msb
->caps
&= ~MEMSTICK_CAP_PAR8
;
976 /* Memory allocated for attributes by this function should be freed by
977 * mspro_block_data_clear, no matter if the initialization process succeeded
980 static int mspro_block_read_attributes(struct memstick_dev
*card
)
982 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
983 struct mspro_attribute
*attr
= NULL
;
984 struct mspro_sys_attr
*s_attr
= NULL
;
985 unsigned char *buffer
= NULL
;
986 int cnt
, rc
, attr_count
;
987 /* While normally physical device offsets, represented here by
988 * attr_offset and attr_len will be of large numeric types, we can be
989 * sure, that attributes are close enough to the beginning of the
990 * device, to save ourselves some trouble.
992 unsigned int addr
, attr_offset
= 0, attr_len
= msb
->page_size
;
994 attr
= kmalloc(msb
->page_size
, GFP_KERNEL
);
998 sg_init_one(&msb
->req_sg
[0], attr
, msb
->page_size
);
1000 msb
->current_seg
= 0;
1001 msb
->current_page
= 0;
1002 msb
->data_dir
= READ
;
1003 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
1005 msb
->setup_transfer(card
, attr_offset
, attr_len
);
1007 memstick_new_req(card
->host
);
1008 wait_for_completion(&card
->mrq_complete
);
1009 if (card
->current_mrq
.error
) {
1010 rc
= card
->current_mrq
.error
;
1014 if (be16_to_cpu(attr
->signature
) != MSPRO_BLOCK_SIGNATURE
) {
1015 printk(KERN_ERR
"%s: unrecognized device signature %x\n",
1016 dev_name(&card
->dev
), be16_to_cpu(attr
->signature
));
1021 if (attr
->count
> MSPRO_BLOCK_MAX_ATTRIBUTES
) {
1022 printk(KERN_WARNING
"%s: way too many attribute entries\n",
1023 dev_name(&card
->dev
));
1024 attr_count
= MSPRO_BLOCK_MAX_ATTRIBUTES
;
1026 attr_count
= attr
->count
;
1028 msb
->attr_group
.attrs
= kzalloc((attr_count
+ 1)
1029 * sizeof(struct attribute
),
1031 if (!msb
->attr_group
.attrs
) {
1035 msb
->attr_group
.name
= "media_attributes";
1037 buffer
= kmalloc(attr_len
, GFP_KERNEL
);
1042 memcpy(buffer
, (char *)attr
, attr_len
);
1044 for (cnt
= 0; cnt
< attr_count
; ++cnt
) {
1045 s_attr
= kzalloc(sizeof(struct mspro_sys_attr
), GFP_KERNEL
);
1048 goto out_free_buffer
;
1051 msb
->attr_group
.attrs
[cnt
] = &s_attr
->dev_attr
.attr
;
1052 addr
= be32_to_cpu(attr
->entries
[cnt
].address
);
1053 s_attr
->size
= be32_to_cpu(attr
->entries
[cnt
].size
);
1054 dev_dbg(&card
->dev
, "adding attribute %d: id %x, address %x, "
1055 "size %zx\n", cnt
, attr
->entries
[cnt
].id
, addr
,
1057 s_attr
->id
= attr
->entries
[cnt
].id
;
1058 if (mspro_block_attr_name(s_attr
->id
))
1059 snprintf(s_attr
->name
, sizeof(s_attr
->name
), "%s",
1060 mspro_block_attr_name(attr
->entries
[cnt
].id
));
1062 snprintf(s_attr
->name
, sizeof(s_attr
->name
),
1063 "attr_x%02x", attr
->entries
[cnt
].id
);
1065 sysfs_attr_init(&s_attr
->dev_attr
.attr
);
1066 s_attr
->dev_attr
.attr
.name
= s_attr
->name
;
1067 s_attr
->dev_attr
.attr
.mode
= S_IRUGO
;
1068 s_attr
->dev_attr
.show
= mspro_block_attr_show(s_attr
->id
);
1073 s_attr
->data
= kmalloc(s_attr
->size
, GFP_KERNEL
);
1074 if (!s_attr
->data
) {
1076 goto out_free_buffer
;
1079 if (((addr
/ msb
->page_size
) == (attr_offset
/ msb
->page_size
))
1080 && (((addr
+ s_attr
->size
- 1) / msb
->page_size
)
1081 == (attr_offset
/ msb
->page_size
))) {
1082 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1087 attr_offset
= (addr
/ msb
->page_size
) * msb
->page_size
;
1089 if ((attr_offset
+ attr_len
) < (addr
+ s_attr
->size
)) {
1091 attr_len
= (((addr
+ s_attr
->size
) / msb
->page_size
)
1092 + 1 ) * msb
->page_size
- attr_offset
;
1093 buffer
= kmalloc(attr_len
, GFP_KERNEL
);
1100 sg_init_one(&msb
->req_sg
[0], buffer
, attr_len
);
1102 msb
->current_seg
= 0;
1103 msb
->current_page
= 0;
1104 msb
->data_dir
= READ
;
1105 msb
->transfer_cmd
= MSPRO_CMD_READ_ATRB
;
1107 dev_dbg(&card
->dev
, "reading attribute range %x, %x\n",
1108 attr_offset
, attr_len
);
1110 msb
->setup_transfer(card
, attr_offset
, attr_len
);
1111 memstick_new_req(card
->host
);
1112 wait_for_completion(&card
->mrq_complete
);
1113 if (card
->current_mrq
.error
) {
1114 rc
= card
->current_mrq
.error
;
1115 goto out_free_buffer
;
1118 memcpy(s_attr
->data
, buffer
+ addr
% msb
->page_size
,
1130 static int mspro_block_init_card(struct memstick_dev
*card
)
1132 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1133 struct memstick_host
*host
= card
->host
;
1136 msb
->system
= MEMSTICK_SYS_SERIAL
;
1137 msb
->setup_transfer
= h_mspro_block_setup_cmd
;
1139 card
->reg_addr
.r_offset
= offsetof(struct mspro_register
, status
);
1140 card
->reg_addr
.r_length
= sizeof(struct ms_status_register
);
1141 card
->reg_addr
.w_offset
= offsetof(struct mspro_register
, param
);
1142 card
->reg_addr
.w_length
= sizeof(struct mspro_param_register
);
1144 if (memstick_set_rw_addr(card
))
1147 msb
->caps
= host
->caps
;
1150 rc
= mspro_block_wait_for_ced(card
);
1154 rc
= mspro_block_switch_interface(card
);
1158 dev_dbg(&card
->dev
, "card activated\n");
1159 if (msb
->system
!= MEMSTICK_SYS_SERIAL
)
1160 msb
->caps
|= MEMSTICK_CAP_AUTO_GET_INT
;
1162 card
->next_request
= h_mspro_block_req_init
;
1163 msb
->mrq_handler
= h_mspro_block_get_ro
;
1164 memstick_init_req(&card
->current_mrq
, MS_TPC_READ_REG
, NULL
,
1165 sizeof(struct ms_status_register
));
1166 memstick_new_req(card
->host
);
1167 wait_for_completion(&card
->mrq_complete
);
1168 if (card
->current_mrq
.error
)
1169 return card
->current_mrq
.error
;
1171 dev_dbg(&card
->dev
, "card r/w status %d\n", msb
->read_only
? 0 : 1);
1173 msb
->page_size
= 512;
1174 rc
= mspro_block_read_attributes(card
);
1178 dev_dbg(&card
->dev
, "attributes loaded\n");
1183 static int mspro_block_init_disk(struct memstick_dev
*card
)
1185 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1186 struct memstick_host
*host
= card
->host
;
1187 struct mspro_devinfo
*dev_info
= NULL
;
1188 struct mspro_sys_info
*sys_info
= NULL
;
1189 struct mspro_sys_attr
*s_attr
= NULL
;
1191 u64 limit
= BLK_BOUNCE_HIGH
;
1192 unsigned long capacity
;
1194 if (host
->dev
.dma_mask
&& *(host
->dev
.dma_mask
))
1195 limit
= *(host
->dev
.dma_mask
);
1197 for (rc
= 0; msb
->attr_group
.attrs
[rc
]; ++rc
) {
1198 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[rc
]);
1200 if (s_attr
->id
== MSPRO_BLOCK_ID_DEVINFO
)
1201 dev_info
= s_attr
->data
;
1202 else if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
)
1203 sys_info
= s_attr
->data
;
1206 if (!dev_info
|| !sys_info
)
1209 msb
->cylinders
= be16_to_cpu(dev_info
->cylinders
);
1210 msb
->heads
= be16_to_cpu(dev_info
->heads
);
1211 msb
->sectors_per_track
= be16_to_cpu(dev_info
->sectors_per_track
);
1213 msb
->page_size
= be16_to_cpu(sys_info
->unit_size
);
1215 mutex_lock(&mspro_block_disk_lock
);
1216 disk_id
= idr_alloc(&mspro_block_disk_idr
, card
, 0, 256, GFP_KERNEL
);
1217 mutex_unlock(&mspro_block_disk_lock
);
1221 msb
->disk
= alloc_disk(1 << MSPRO_BLOCK_PART_SHIFT
);
1224 goto out_release_id
;
1227 msb
->queue
= blk_init_queue(mspro_block_submit_req
, &msb
->q_lock
);
1233 msb
->queue
->queuedata
= card
;
1234 blk_queue_prep_rq(msb
->queue
, mspro_block_prepare_req
);
1236 blk_queue_bounce_limit(msb
->queue
, limit
);
1237 blk_queue_max_hw_sectors(msb
->queue
, MSPRO_BLOCK_MAX_PAGES
);
1238 blk_queue_max_segments(msb
->queue
, MSPRO_BLOCK_MAX_SEGS
);
1239 blk_queue_max_segment_size(msb
->queue
,
1240 MSPRO_BLOCK_MAX_PAGES
* msb
->page_size
);
1242 msb
->disk
->major
= major
;
1243 msb
->disk
->first_minor
= disk_id
<< MSPRO_BLOCK_PART_SHIFT
;
1244 msb
->disk
->fops
= &ms_block_bdops
;
1245 msb
->usage_count
= 1;
1246 msb
->disk
->private_data
= msb
;
1247 msb
->disk
->queue
= msb
->queue
;
1248 msb
->disk
->driverfs_dev
= &card
->dev
;
1250 sprintf(msb
->disk
->disk_name
, "mspblk%d", disk_id
);
1252 blk_queue_logical_block_size(msb
->queue
, msb
->page_size
);
1254 capacity
= be16_to_cpu(sys_info
->user_block_count
);
1255 capacity
*= be16_to_cpu(sys_info
->block_size
);
1256 capacity
*= msb
->page_size
>> 9;
1257 set_capacity(msb
->disk
, capacity
);
1258 dev_dbg(&card
->dev
, "capacity set %ld\n", capacity
);
1260 add_disk(msb
->disk
);
1265 put_disk(msb
->disk
);
1267 mutex_lock(&mspro_block_disk_lock
);
1268 idr_remove(&mspro_block_disk_idr
, disk_id
);
1269 mutex_unlock(&mspro_block_disk_lock
);
1273 static void mspro_block_data_clear(struct mspro_block_data
*msb
)
1276 struct mspro_sys_attr
*s_attr
;
1278 if (msb
->attr_group
.attrs
) {
1279 for (cnt
= 0; msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1280 s_attr
= mspro_from_sysfs_attr(msb
->attr_group
1282 kfree(s_attr
->data
);
1285 kfree(msb
->attr_group
.attrs
);
1291 static int mspro_block_check_card(struct memstick_dev
*card
)
1293 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1295 return (msb
->active
== 1);
1298 static int mspro_block_probe(struct memstick_dev
*card
)
1300 struct mspro_block_data
*msb
;
1303 msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1306 memstick_set_drvdata(card
, msb
);
1308 spin_lock_init(&msb
->q_lock
);
1310 rc
= mspro_block_init_card(card
);
1315 rc
= sysfs_create_group(&card
->dev
.kobj
, &msb
->attr_group
);
1319 rc
= mspro_block_init_disk(card
);
1321 card
->check
= mspro_block_check_card
;
1322 card
->stop
= mspro_block_stop
;
1323 card
->start
= mspro_block_start
;
1327 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1329 memstick_set_drvdata(card
, NULL
);
1330 mspro_block_data_clear(msb
);
1335 static void mspro_block_remove(struct memstick_dev
*card
)
1337 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1338 unsigned long flags
;
1340 spin_lock_irqsave(&msb
->q_lock
, flags
);
1342 blk_start_queue(msb
->queue
);
1343 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1345 del_gendisk(msb
->disk
);
1346 dev_dbg(&card
->dev
, "mspro block remove\n");
1348 blk_cleanup_queue(msb
->queue
);
1351 sysfs_remove_group(&card
->dev
.kobj
, &msb
->attr_group
);
1353 mutex_lock(&mspro_block_disk_lock
);
1354 mspro_block_data_clear(msb
);
1355 mutex_unlock(&mspro_block_disk_lock
);
1357 mspro_block_disk_release(msb
->disk
);
1358 memstick_set_drvdata(card
, NULL
);
1363 static int mspro_block_suspend(struct memstick_dev
*card
, pm_message_t state
)
1365 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1366 unsigned long flags
;
1368 spin_lock_irqsave(&msb
->q_lock
, flags
);
1369 blk_stop_queue(msb
->queue
);
1371 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1376 static int mspro_block_resume(struct memstick_dev
*card
)
1378 struct mspro_block_data
*msb
= memstick_get_drvdata(card
);
1379 unsigned long flags
;
1382 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
1384 struct mspro_block_data
*new_msb
;
1385 struct memstick_host
*host
= card
->host
;
1386 struct mspro_sys_attr
*s_attr
, *r_attr
;
1389 mutex_lock(&host
->lock
);
1390 new_msb
= kzalloc(sizeof(struct mspro_block_data
), GFP_KERNEL
);
1396 new_msb
->card
= card
;
1397 memstick_set_drvdata(card
, new_msb
);
1398 if (mspro_block_init_card(card
))
1401 for (cnt
= 0; new_msb
->attr_group
.attrs
[cnt
]
1402 && msb
->attr_group
.attrs
[cnt
]; ++cnt
) {
1403 s_attr
= mspro_from_sysfs_attr(new_msb
->attr_group
.attrs
[cnt
]);
1404 r_attr
= mspro_from_sysfs_attr(msb
->attr_group
.attrs
[cnt
]);
1406 if (s_attr
->id
== MSPRO_BLOCK_ID_SYSINFO
1407 && r_attr
->id
== s_attr
->id
) {
1408 if (memcmp(s_attr
->data
, r_attr
->data
, s_attr
->size
))
1417 memstick_set_drvdata(card
, msb
);
1418 mspro_block_data_clear(new_msb
);
1421 mutex_unlock(&host
->lock
);
1423 #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
1425 spin_lock_irqsave(&msb
->q_lock
, flags
);
1426 blk_start_queue(msb
->queue
);
1427 spin_unlock_irqrestore(&msb
->q_lock
, flags
);
1433 #define mspro_block_suspend NULL
1434 #define mspro_block_resume NULL
1436 #endif /* CONFIG_PM */
1438 static struct memstick_device_id mspro_block_id_tbl
[] = {
1439 {MEMSTICK_MATCH_ALL
, MEMSTICK_TYPE_PRO
, MEMSTICK_CATEGORY_STORAGE_DUO
,
1440 MEMSTICK_CLASS_DUO
},
1445 static struct memstick_driver mspro_block_driver
= {
1447 .name
= DRIVER_NAME
,
1448 .owner
= THIS_MODULE
1450 .id_table
= mspro_block_id_tbl
,
1451 .probe
= mspro_block_probe
,
1452 .remove
= mspro_block_remove
,
1453 .suspend
= mspro_block_suspend
,
1454 .resume
= mspro_block_resume
1457 static int __init
mspro_block_init(void)
1461 rc
= register_blkdev(major
, DRIVER_NAME
);
1463 printk(KERN_ERR DRIVER_NAME
": failed to register "
1464 "major %d, error %d\n", major
, rc
);
1470 rc
= memstick_register_driver(&mspro_block_driver
);
1472 unregister_blkdev(major
, DRIVER_NAME
);
1476 static void __exit
mspro_block_exit(void)
1478 memstick_unregister_driver(&mspro_block_driver
);
1479 unregister_blkdev(major
, DRIVER_NAME
);
1480 idr_destroy(&mspro_block_disk_idr
);
1483 module_init(mspro_block_init
);
1484 module_exit(mspro_block_exit
);
1486 MODULE_LICENSE("GPL");
1487 MODULE_AUTHOR("Alex Dubov");
1488 MODULE_DESCRIPTION("Sony MemoryStickPro block device driver");
1489 MODULE_DEVICE_TABLE(memstick
, mspro_block_id_tbl
);