2 * drivers/block/mg_disk.c
4 * Support for the mGine m[g]flash IO mode.
7 * (c) 2008 mGine Co.,LTD
8 * (c) 2008 unsik Kim <donari75@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
18 #include <linux/blkdev.h>
19 #include <linux/hdreg.h>
20 #include <linux/libata.h>
21 #include <linux/interrupt.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/mg_disk.h>
27 #define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
29 static void mg_request(struct request_queue *);
31 static void mg_dump_status(const char *msg, unsigned int stat,
34 char *name = MG_DISK_NAME;
38 req = elv_next_request(host->breq);
40 name = req->rq_disk->disk_name;
43 printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
44 if (stat & MG_REG_STATUS_BIT_BUSY)
46 if (stat & MG_REG_STATUS_BIT_READY)
47 printk("DriveReady ");
48 if (stat & MG_REG_STATUS_BIT_WRITE_FAULT)
49 printk("WriteFault ");
50 if (stat & MG_REG_STATUS_BIT_SEEK_DONE)
51 printk("SeekComplete ");
52 if (stat & MG_REG_STATUS_BIT_DATA_REQ)
53 printk("DataRequest ");
54 if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR)
55 printk("CorrectedError ");
56 if (stat & MG_REG_STATUS_BIT_ERROR)
59 if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) {
62 host->error = inb((unsigned long)host->dev_base + MG_REG_ERROR);
63 printk(KERN_ERR "%s: %s: error=0x%02x { ", name, msg,
65 if (host->error & MG_REG_ERR_BBK)
67 if (host->error & MG_REG_ERR_UNC)
68 printk("UncorrectableError ");
69 if (host->error & MG_REG_ERR_IDNF)
70 printk("SectorIdNotFound ");
71 if (host->error & MG_REG_ERR_ABRT)
72 printk("DriveStatusError ");
73 if (host->error & MG_REG_ERR_AMNF)
74 printk("AddrMarkNotFound ");
77 (MG_REG_ERR_BBK | MG_REG_ERR_UNC |
78 MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) {
80 req = elv_next_request(host->breq);
82 printk(", sector=%ld", req->sector);
90 static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
93 unsigned long expire, cur_jiffies;
94 struct mg_drv_data *prv_data = host->dev->platform_data;
96 host->error = MG_ERR_NONE;
97 expire = jiffies + msecs_to_jiffies(msec);
99 status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
102 cur_jiffies = jiffies;
103 if (status & MG_REG_STATUS_BIT_BUSY) {
104 if (expect == MG_REG_STATUS_BIT_BUSY)
107 /* Check the error condition! */
108 if (status & MG_REG_STATUS_BIT_ERROR) {
109 mg_dump_status("mg_wait", status, host);
113 if (expect == MG_STAT_READY)
114 if (MG_READY_OK(status))
117 if (expect == MG_REG_STATUS_BIT_DATA_REQ)
118 if (status & MG_REG_STATUS_BIT_DATA_REQ)
122 mg_dump_status("not ready", status, host);
123 return MG_ERR_INV_STAT;
125 if (prv_data->use_polling)
128 status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
129 } while (time_before(cur_jiffies, expire));
131 if (time_after_eq(cur_jiffies, expire) && msec)
132 host->error = MG_ERR_TIMEOUT;
137 static unsigned int mg_wait_rstout(u32 rstout, u32 msec)
139 unsigned long expire;
141 expire = jiffies + msecs_to_jiffies(msec);
142 while (time_before(jiffies, expire)) {
143 if (gpio_get_value(rstout) == 1)
148 return MG_ERR_RSTOUT;
151 static void mg_unexpected_intr(struct mg_host *host)
153 u32 status = inb((unsigned long)host->dev_base + MG_REG_STATUS);
155 mg_dump_status("mg_unexpected_intr", status, host);
158 static irqreturn_t mg_irq(int irq, void *dev_id)
160 struct mg_host *host = dev_id;
161 void (*handler)(struct mg_host *) = host->mg_do_intr;
163 host->mg_do_intr = 0;
164 del_timer(&host->timer);
166 handler = mg_unexpected_intr;
171 static int mg_get_disk_id(struct mg_host *host)
175 const u16 *id = host->id;
176 struct mg_drv_data *prv_data = host->dev->platform_data;
177 char fwrev[ATA_ID_FW_REV_LEN + 1];
178 char model[ATA_ID_PROD_LEN + 1];
179 char serial[ATA_ID_SERNO_LEN + 1];
181 if (!prv_data->use_polling)
182 outb(MG_REG_CTRL_INTR_DISABLE,
183 (unsigned long)host->dev_base +
186 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND);
187 err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_RD_DRQ);
191 for (i = 0; i < (MG_SECTOR_SIZE >> 1); i++)
192 host->id[i] = le16_to_cpu(inw((unsigned long)host->dev_base +
193 MG_BUFF_OFFSET + i * 2));
195 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
196 err = mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD);
200 if ((id[ATA_ID_FIELD_VALID] & 1) == 0)
201 return MG_ERR_TRANSLATION;
203 host->n_sectors = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
204 host->cyls = id[ATA_ID_CYLS];
205 host->heads = id[ATA_ID_HEADS];
206 host->sectors = id[ATA_ID_SECTORS];
208 if (MG_RES_SEC && host->heads && host->sectors) {
209 /* modify cyls, n_sectors */
210 host->cyls = (host->n_sectors - MG_RES_SEC) /
211 host->heads / host->sectors;
212 host->nres_sectors = host->n_sectors - host->cyls *
213 host->heads * host->sectors;
214 host->n_sectors -= host->nres_sectors;
217 ata_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev));
218 ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model));
219 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
220 printk(KERN_INFO "mg_disk: model: %s\n", model);
221 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev);
222 printk(KERN_INFO "mg_disk: serial: %s\n", serial);
223 printk(KERN_INFO "mg_disk: %d + reserved %d sectors\n",
224 host->n_sectors, host->nres_sectors);
226 if (!prv_data->use_polling)
227 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
234 static int mg_disk_init(struct mg_host *host)
236 struct mg_drv_data *prv_data = host->dev->platform_data;
241 gpio_set_value(host->rst, 0);
242 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY);
247 gpio_set_value(host->rst, 1);
248 err = mg_wait(host, MG_STAT_READY, MG_TMAX_HDRST_TO_RDY);
253 outb(MG_REG_CTRL_RESET |
254 (prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
255 MG_REG_CTRL_INTR_ENABLE),
256 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
257 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY);
262 outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
263 MG_REG_CTRL_INTR_ENABLE,
264 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
265 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY);
269 init_status = inb((unsigned long)host->dev_base + MG_REG_STATUS) & 0xf;
271 if (init_status == 0xf)
272 return MG_ERR_INIT_STAT;
277 static void mg_bad_rw_intr(struct mg_host *host)
279 struct request *req = elv_next_request(host->breq);
281 if (++req->errors >= MG_MAX_ERRORS ||
282 host->error == MG_ERR_TIMEOUT)
286 static unsigned int mg_out(struct mg_host *host,
287 unsigned int sect_num,
288 unsigned int sect_cnt,
290 void (*intr_addr)(struct mg_host *))
292 struct mg_drv_data *prv_data = host->dev->platform_data;
294 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
297 if (!prv_data->use_polling) {
298 host->mg_do_intr = intr_addr;
299 mod_timer(&host->timer, jiffies + 3 * HZ);
302 sect_num += MG_RES_SEC;
303 outb((u8)sect_cnt, (unsigned long)host->dev_base + MG_REG_SECT_CNT);
304 outb((u8)sect_num, (unsigned long)host->dev_base + MG_REG_SECT_NUM);
305 outb((u8)(sect_num >> 8), (unsigned long)host->dev_base +
307 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base +
309 outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE),
310 (unsigned long)host->dev_base + MG_REG_DRV_HEAD);
311 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND);
315 static void mg_read(struct request *req)
318 struct mg_host *host = req->rq_disk->private_data;
320 remains = req->nr_sectors;
322 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, 0) !=
324 mg_bad_rw_intr(host);
326 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
327 remains, req->sector, req->buffer);
330 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
331 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
332 mg_bad_rw_intr(host);
335 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
336 *(u16 *)req->buffer =
337 inw((unsigned long)host->dev_base +
338 MG_BUFF_OFFSET + (j << 1));
344 remains = --req->nr_sectors;
345 --req->current_nr_sectors;
347 if (req->current_nr_sectors <= 0) {
348 MG_DBG("remain : %d sects\n", remains);
351 req = elv_next_request(host->breq);
354 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
359 static void mg_write(struct request *req)
362 struct mg_host *host = req->rq_disk->private_data;
364 remains = req->nr_sectors;
366 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, 0) !=
368 mg_bad_rw_intr(host);
373 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
374 remains, req->sector, req->buffer);
376 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
377 MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
378 mg_bad_rw_intr(host);
381 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
382 outw(*(u16 *)req->buffer,
383 (unsigned long)host->dev_base +
384 MG_BUFF_OFFSET + (j << 1));
388 remains = --req->nr_sectors;
389 --req->current_nr_sectors;
391 if (req->current_nr_sectors <= 0) {
392 MG_DBG("remain : %d sects\n", remains);
395 req = elv_next_request(host->breq);
398 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
403 static void mg_read_intr(struct mg_host *host)
410 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
411 if (i & MG_REG_STATUS_BIT_BUSY)
415 if (i & MG_REG_STATUS_BIT_DATA_REQ)
418 mg_dump_status("mg_read_intr", i, host);
419 mg_bad_rw_intr(host);
420 mg_request(host->breq);
424 /* get current segment of request */
425 req = elv_next_request(host->breq);
428 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
429 *(u16 *)req->buffer =
430 inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
435 /* manipulate request */
436 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
437 req->sector, req->nr_sectors - 1, req->buffer);
441 i = --req->nr_sectors;
442 --req->current_nr_sectors;
444 /* let know if current segment done */
445 if (req->current_nr_sectors <= 0)
448 /* set handler if read remains */
450 host->mg_do_intr = mg_read_intr;
451 mod_timer(&host->timer, jiffies + 3 * HZ);
454 /* send read confirm */
455 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
457 /* goto next request */
459 mg_request(host->breq);
462 static void mg_write_intr(struct mg_host *host)
468 /* get current segment of request */
469 req = elv_next_request(host->breq);
473 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
474 if (i & MG_REG_STATUS_BIT_BUSY)
478 if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ))
481 mg_dump_status("mg_write_intr", i, host);
482 mg_bad_rw_intr(host);
483 mg_request(host->breq);
487 /* manipulate request */
489 i = --req->nr_sectors;
490 --req->current_nr_sectors;
491 req->buffer += MG_SECTOR_SIZE;
493 /* let know if current segment or all done */
494 if (!i || (req->bio && req->current_nr_sectors <= 0))
497 /* write 1 sector and set handler if remains */
499 buff = (u16 *)req->buffer;
500 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
501 outw(*buff, (unsigned long)host->dev_base +
502 MG_BUFF_OFFSET + (j << 1));
505 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
506 req->sector, req->nr_sectors, req->buffer);
507 host->mg_do_intr = mg_write_intr;
508 mod_timer(&host->timer, jiffies + 3 * HZ);
511 /* send write confirm */
512 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
515 mg_request(host->breq);
518 void mg_times_out(unsigned long data)
520 struct mg_host *host = (struct mg_host *)data;
524 req = elv_next_request(host->breq);
528 host->mg_do_intr = NULL;
530 name = req->rq_disk->disk_name;
531 printk(KERN_DEBUG "%s: timeout\n", name);
533 host->error = MG_ERR_TIMEOUT;
534 mg_bad_rw_intr(host);
536 mg_request(host->breq);
539 static void mg_request_poll(struct request_queue *q)
542 struct mg_host *host;
544 while ((req = elv_next_request(q)) != NULL) {
545 host = req->rq_disk->private_data;
546 if (blk_fs_request(req)) {
547 switch (rq_data_dir(req)) {
555 printk(KERN_WARNING "%s:%d unknown command\n",
564 static unsigned int mg_issue_req(struct request *req,
565 struct mg_host *host,
566 unsigned int sect_num,
567 unsigned int sect_cnt)
572 switch (rq_data_dir(req)) {
574 if (mg_out(host, sect_num, sect_cnt, MG_CMD_RD, &mg_read_intr)
576 mg_bad_rw_intr(host);
582 outb(MG_REG_CTRL_INTR_DISABLE,
583 (unsigned long)host->dev_base +
585 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr)
587 mg_bad_rw_intr(host);
590 del_timer(&host->timer);
591 mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_WR_DRQ);
592 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
595 mg_bad_rw_intr(host);
598 buff = (u16 *)req->buffer;
599 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
600 outw(*buff, (unsigned long)host->dev_base +
601 MG_BUFF_OFFSET + (i << 1));
604 mod_timer(&host->timer, jiffies + 3 * HZ);
605 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
609 printk(KERN_WARNING "%s:%d unknown command\n",
617 /* This function also called from IRQ context */
618 static void mg_request(struct request_queue *q)
621 struct mg_host *host;
622 u32 sect_num, sect_cnt;
625 req = elv_next_request(q);
629 host = req->rq_disk->private_data;
631 /* check unwanted request call */
632 if (host->mg_do_intr)
635 del_timer(&host->timer);
637 sect_num = req->sector;
638 /* deal whole segments */
639 sect_cnt = req->nr_sectors;
642 if (sect_num >= get_capacity(req->rq_disk) ||
643 ((sect_num + sect_cnt) >
644 get_capacity(req->rq_disk))) {
646 "%s: bad access: sector=%d, count=%d\n",
647 req->rq_disk->disk_name,
653 if (!blk_fs_request(req))
656 if (!mg_issue_req(req, host, sect_num, sect_cnt))
661 static int mg_getgeo(struct block_device *bdev, struct hd_geometry *geo)
663 struct mg_host *host = bdev->bd_disk->private_data;
665 geo->cylinders = (unsigned short)host->cyls;
666 geo->heads = (unsigned char)host->heads;
667 geo->sectors = (unsigned char)host->sectors;
671 static struct block_device_operations mg_disk_ops = {
675 static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
677 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
678 struct mg_host *host = prv_data->host;
680 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
683 if (!prv_data->use_polling)
684 outb(MG_REG_CTRL_INTR_DISABLE,
685 (unsigned long)host->dev_base +
688 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND);
689 /* wait until mflash deep sleep */
692 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) {
693 if (!prv_data->use_polling)
694 outb(MG_REG_CTRL_INTR_ENABLE,
695 (unsigned long)host->dev_base +
703 static int mg_resume(struct platform_device *plat_dev)
705 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
706 struct mg_host *host = prv_data->host;
708 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
711 outb(MG_CMD_WAKEUP, (unsigned long)host->dev_base + MG_REG_COMMAND);
712 /* wait until mflash wakeup */
715 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
718 if (!prv_data->use_polling)
719 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
725 static int mg_probe(struct platform_device *plat_dev)
727 struct mg_host *host;
728 struct resource *rsc;
729 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
733 printk(KERN_ERR "%s:%d fail (no driver_data)\n",
740 host = kzalloc(sizeof(struct mg_host), GFP_KERNEL);
742 printk(KERN_ERR "%s:%d fail (no memory for mg_host)\n",
747 host->major = MG_DISK_MAJ;
749 /* link each other */
750 prv_data->host = host;
751 host->dev = &plat_dev->dev;
754 rsc = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
756 printk(KERN_ERR "%s:%d platform_get_resource fail\n",
761 host->dev_base = ioremap(rsc->start , rsc->end + 1);
762 if (!host->dev_base) {
763 printk(KERN_ERR "%s:%d ioremap fail\n",
768 MG_DBG("dev_base = 0x%x\n", (u32)host->dev_base);
771 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO,
774 printk(KERN_ERR "%s:%d get reset pin fail\n",
779 host->rst = rsc->start;
782 err = gpio_request(host->rst, MG_RST_PIN);
785 gpio_direction_output(host->rst, 1);
788 if (!(prv_data->dev_attr & MG_DEV_MASK))
791 if (prv_data->dev_attr != MG_BOOT_DEV) {
792 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO,
795 printk(KERN_ERR "%s:%d get reset-out pin fail\n",
800 host->rstout = rsc->start;
801 err = gpio_request(host->rstout, MG_RSTOUT_PIN);
804 gpio_direction_input(host->rstout);
808 if (prv_data->dev_attr == MG_STORAGE_DEV) {
809 /* If POR seq. not yet finised, wait */
810 err = mg_wait_rstout(host->rstout, MG_TMAX_RSTOUT);
813 err = mg_disk_init(host);
815 printk(KERN_ERR "%s:%d fail (err code : %d)\n",
816 __func__, __LINE__, err);
822 /* get irq resource */
823 if (!prv_data->use_polling) {
824 host->irq = platform_get_irq(plat_dev, 0);
825 if (host->irq == -ENXIO) {
829 err = request_irq(host->irq, mg_irq,
830 IRQF_DISABLED | IRQF_TRIGGER_RISING,
833 printk(KERN_ERR "%s:%d fail (request_irq err=%d)\n",
834 __func__, __LINE__, err);
841 err = mg_get_disk_id(host);
843 printk(KERN_ERR "%s:%d fail (err code : %d)\n",
844 __func__, __LINE__, err);
849 err = register_blkdev(host->major, MG_DISK_NAME);
851 printk(KERN_ERR "%s:%d register_blkdev fail (err code : %d)\n",
852 __func__, __LINE__, err);
858 spin_lock_init(&host->lock);
860 if (prv_data->use_polling)
861 host->breq = blk_init_queue(mg_request_poll, &host->lock);
863 host->breq = blk_init_queue(mg_request, &host->lock);
867 printk(KERN_ERR "%s:%d (blk_init_queue) fail\n",
872 /* mflash is random device, thanx for the noop */
873 elevator_exit(host->breq->elevator);
874 err = elevator_init(host->breq, "noop");
876 printk(KERN_ERR "%s:%d (elevator_init) fail\n",
880 blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
881 blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE);
883 init_timer(&host->timer);
884 host->timer.function = mg_times_out;
885 host->timer.data = (unsigned long)host;
887 host->gd = alloc_disk(MG_DISK_MAX_PART);
889 printk(KERN_ERR "%s:%d (alloc_disk) fail\n",
894 host->gd->major = host->major;
895 host->gd->first_minor = 0;
896 host->gd->fops = &mg_disk_ops;
897 host->gd->queue = host->breq;
898 host->gd->private_data = host;
899 sprintf(host->gd->disk_name, MG_DISK_NAME"a");
901 set_capacity(host->gd, host->n_sectors);
908 del_timer_sync(&host->timer);
910 blk_cleanup_queue(host->breq);
912 unregister_blkdev(MG_DISK_MAJ, MG_DISK_NAME);
914 if (!prv_data->use_polling)
915 free_irq(host->irq, host);
917 gpio_free(host->rstout);
919 gpio_free(host->rst);
921 iounmap(host->dev_base);
928 static int mg_remove(struct platform_device *plat_dev)
930 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
931 struct mg_host *host = prv_data->host;
935 del_timer_sync(&host->timer);
939 del_gendisk(host->gd);
944 blk_cleanup_queue(host->breq);
946 /* unregister blk device */
947 unregister_blkdev(host->major, MG_DISK_NAME);
950 if (!prv_data->use_polling)
951 free_irq(host->irq, host);
953 /* free reset-out pin */
954 if (prv_data->dev_attr != MG_BOOT_DEV)
955 gpio_free(host->rstout);
959 gpio_free(host->rst);
963 iounmap(host->dev_base);
971 static struct platform_driver mg_disk_driver = {
974 .suspend = mg_suspend,
978 .owner = THIS_MODULE,
982 /****************************************************************************
986 ****************************************************************************/
988 static int __init mg_init(void)
990 printk(KERN_INFO "mGine mflash driver, (c) 2008 mGine Co.\n");
991 return platform_driver_register(&mg_disk_driver);
994 static void __exit mg_exit(void)
996 printk(KERN_INFO "mflash driver : bye bye\n");
997 platform_driver_unregister(&mg_disk_driver);
1000 module_init(mg_init);
1001 module_exit(mg_exit);
1003 MODULE_LICENSE("GPL");
1004 MODULE_AUTHOR("unsik Kim <donari75@gmail.com>");
1005 MODULE_DESCRIPTION("mGine m[g]flash device driver");