20 #include <linux/slab.h>
23 #include <linux/module.h>
25 #define DRIVER_NAME "mspro_block"
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
187 struct gendisk *disk = bdev->
bd_disk;
193 if (msb && msb->
card) {
207 static int mspro_block_disk_release(
struct gendisk *disk)
220 disk->private_data =
NULL;
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,
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,
264 static const char *mspro_block_attr_name(
unsigned char tag)
268 return "attr_sysinfo";
270 return "attr_modelname";
278 return "attr_specfilevalues1";
280 return "attr_specfilevalues2";
282 return "attr_devinfo";
292 static ssize_t mspro_block_attr_show_default(
struct device *dev,
302 for (cnt = 0; cnt < s_attr->
size; cnt++) {
303 if (cnt && !(cnt % 16)) {
309 ((
unsigned char *)s_attr->
data)[cnt]);
314 static ssize_t mspro_block_attr_show_sysinfo(
struct device *dev,
323 int date_tz = 0, date_tz_f = 0;
327 date_tz_f = date_tz & 3;
333 date_tz_f = date_tz & 3;
349 "GMT%+d:%d %04u-%02u-%02u %02u:%02u:%02u\n",
358 "assembly maker code: %x\n",
375 "controller function: %x\n",
396 static ssize_t mspro_block_attr_show_modelname(
struct device *dev,
436 "sectors per partition: %x\n",
441 static ssize_t mspro_block_attr_show_specfile(
struct device *dev,
462 x_spfile->
time >> 11,
463 (x_spfile->
time >> 5) & 0x3f,
464 (x_spfile->
time & 0x1f) * 2);
466 (x_spfile->
date >> 9) + 1980,
467 (x_spfile->
date >> 5) & 0xf,
468 x_spfile->
date & 0x1f);
476 static ssize_t mspro_block_attr_show_devinfo(
struct device *dev,
499 static sysfs_show_t mspro_block_attr_show(
unsigned char tag)
503 return mspro_block_attr_show_sysinfo;
505 return mspro_block_attr_show_modelname;
507 return mspro_block_attr_show_mbr;
510 return mspro_block_attr_show_specfile;
512 return mspro_block_attr_show_devinfo;
514 return mspro_block_attr_show_default;
540 return mspro_block_complete_req(card, (*mrq)->error);
554 if (!(*mrq)->error) {
562 return mspro_block_complete_req(card, (*mrq)->error);
565 static int h_mspro_block_wait_for_ced(
struct memstick_dev *card,
568 dev_dbg(&card->
dev,
"wait for ced: value %x\n", (*mrq)->data[0]);
570 if (!(*mrq)->error) {
577 return mspro_block_complete_req(card, (*mrq)->error);
580 static int h_mspro_block_transfer_data(
struct memstick_dev *card,
584 unsigned char t_val = 0;
589 return mspro_block_complete_req(card, (*mrq)->error);
591 switch ((*mrq)->tpc) {
594 (*mrq)->need_card_int = 1;
597 t_val = (*mrq)->int_reg;
603 t_val = (*mrq)->data[0];
620 return mspro_block_complete_req(card,
624 = h_mspro_block_wait_for_ced;
649 (*mrq)->need_card_int = 1;
655 t_val = (*mrq)->int_reg;
694 ¶m,
sizeof(param));
749 unsigned int t_len = 0;
764 t_len += msb->
req_sg[cnt].length
775 dev_dbg(&card->
dev,
"transferred %x (%d)\n", t_len, error);
778 t_len = blk_rq_cur_bytes(msb->
block_req);
782 error = mspro_block_issue_req(card, chunk);
796 spin_unlock_irqrestore(&msb->
q_lock, flags);
812 spin_unlock_irqrestore(&msb->
q_lock, flags);
821 static void mspro_block_start(
struct memstick_dev *card)
828 spin_unlock_irqrestore(&msb->
q_lock, flags);
833 if (req->cmd_type != REQ_TYPE_FS &&
834 req->cmd_type != REQ_TYPE_BLOCK_PC) {
861 if (mspro_block_issue_req(card, 0))
867 static int mspro_block_wait_for_ced(
struct memstick_dev *card)
879 static int mspro_block_set_interface(
struct memstick_dev *card,
880 unsigned char sys_reg)
900 static int mspro_block_switch_interface(
struct memstick_dev *card)
914 "%s: could not switch to 4-bit mode, error %d\n",
915 dev_name(&card->
dev), rc);
922 dev_name(&card->
dev));
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);
949 "%s: interface error, trying to fall back to serial\n",
950 dev_name(&card->
dev));
959 rc = mspro_block_set_interface(card, msb->
system);
963 rc = mspro_block_wait_for_ced(card);
980 static int mspro_block_read_attributes(
struct memstick_dev *card)
985 unsigned char *buffer =
NULL;
986 int cnt,
rc, attr_count;
1023 dev_name(&card->
dev));
1026 attr_count = attr->
count;
1028 msb->
attr_group.attrs = kzalloc((attr_count + 1)
1042 memcpy(buffer, (
char *)attr, attr_len);
1044 for (cnt = 0; cnt < attr_count; ++
cnt) {
1048 goto out_free_buffer;
1054 dev_dbg(&card->
dev,
"adding attribute %d: id %x, address %x, "
1055 "size %zx\n", cnt, attr->
entries[cnt].id, addr,
1058 if (mspro_block_attr_name(s_attr->
id))
1060 mspro_block_attr_name(attr->
entries[cnt].id));
1063 "attr_x%02x", attr->
entries[cnt].id);
1068 s_attr->
dev_attr.show = mspro_block_attr_show(s_attr->
id);
1074 if (!s_attr->
data) {
1076 goto out_free_buffer;
1089 if ((attr_offset + attr_len) < (addr + s_attr->
size)) {
1107 dev_dbg(&card->
dev,
"reading attribute range %x, %x\n",
1108 attr_offset, attr_len);
1115 goto out_free_buffer;
1130 static int mspro_block_init_card(
struct memstick_dev *card)
1150 rc = mspro_block_wait_for_ced(card);
1154 rc = mspro_block_switch_interface(card);
1174 rc = mspro_block_read_attributes(card);
1183 static int mspro_block_init_disk(
struct memstick_dev *card)
1194 if (host->
dev.dma_mask && *(host->
dev.dma_mask))
1195 limit = *(host->
dev.dma_mask);
1198 s_attr = mspro_from_sysfs_attr(msb->
attr_group.attrs[rc]);
1201 dev_info = s_attr->
data;
1203 sys_info = s_attr->
data;
1206 if (!dev_info || !sys_info)
1221 rc =
idr_get_new(&mspro_block_disk_idr, card, &disk_id);
1229 goto out_release_id;
1235 goto out_release_id;
1255 msb->
disk->fops = &ms_block_bdops;
1257 msb->
disk->private_data =
msb;
1259 msb->
disk->driverfs_dev = &card->
dev;
1261 sprintf(msb->
disk->disk_name,
"mspblk%d", disk_id);
1268 set_capacity(msb->
disk, capacity);
1269 dev_dbg(&card->
dev,
"capacity set %ld\n", capacity);
1291 s_attr = mspro_from_sysfs_attr(msb->
attr_group
1302 static int mspro_block_check_card(
struct memstick_dev *card)
1306 return (msb->
active == 1);
1309 static int mspro_block_probe(
struct memstick_dev *card)
1317 memstick_set_drvdata(card, msb);
1321 rc = mspro_block_init_card(card);
1330 rc = mspro_block_init_disk(card);
1332 card->
check = mspro_block_check_card;
1333 card->
stop = mspro_block_stop;
1334 card->
start = mspro_block_start;
1340 memstick_set_drvdata(card,
NULL);
1341 mspro_block_data_clear(msb);
1346 static void mspro_block_remove(
struct memstick_dev *card)
1349 unsigned long flags;
1354 spin_unlock_irqrestore(&msb->
q_lock, flags);
1365 mspro_block_data_clear(msb);
1368 mspro_block_disk_release(msb->
disk);
1369 memstick_set_drvdata(card,
NULL);
1377 unsigned long flags;
1382 spin_unlock_irqrestore(&msb->
q_lock, flags);
1390 unsigned long flags;
1393 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
1408 memstick_set_drvdata(card, new_msb);
1409 if (mspro_block_init_card(card))
1414 s_attr = mspro_from_sysfs_attr(new_msb->
attr_group.attrs[cnt]);
1415 r_attr = mspro_from_sysfs_attr(msb->
attr_group.attrs[cnt]);
1418 && r_attr->
id == s_attr->
id) {
1428 memstick_set_drvdata(card, msb);
1429 mspro_block_data_clear(new_msb);
1438 spin_unlock_irqrestore(&msb->
q_lock, flags);
1444 #define mspro_block_suspend NULL
1445 #define mspro_block_resume NULL
1461 .id_table = mspro_block_id_tbl,
1462 .probe = mspro_block_probe,
1463 .remove = mspro_block_remove,
1468 static int __init mspro_block_init(
void)
1475 "major %d, error %d\n", major, rc);
1487 static void __exit mspro_block_exit(
void)