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=%u", (u32)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 spin_lock(&host->lock);
165 host->mg_do_intr = NULL;
166 del_timer(&host->timer);
168 handler = mg_unexpected_intr;
171 spin_unlock(&host->lock);
176 static int mg_get_disk_id(struct mg_host *host)
180 const u16 *id = host->id;
181 struct mg_drv_data *prv_data = host->dev->platform_data;
182 char fwrev[ATA_ID_FW_REV_LEN + 1];
183 char model[ATA_ID_PROD_LEN + 1];
184 char serial[ATA_ID_SERNO_LEN + 1];
186 if (!prv_data->use_polling)
187 outb(MG_REG_CTRL_INTR_DISABLE,
188 (unsigned long)host->dev_base +
191 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND);
192 err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_RD_DRQ);
196 for (i = 0; i < (MG_SECTOR_SIZE >> 1); i++)
197 host->id[i] = le16_to_cpu(inw((unsigned long)host->dev_base +
198 MG_BUFF_OFFSET + i * 2));
200 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
201 err = mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD);
205 if ((id[ATA_ID_FIELD_VALID] & 1) == 0)
206 return MG_ERR_TRANSLATION;
208 host->n_sectors = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
209 host->cyls = id[ATA_ID_CYLS];
210 host->heads = id[ATA_ID_HEADS];
211 host->sectors = id[ATA_ID_SECTORS];
213 if (MG_RES_SEC && host->heads && host->sectors) {
214 /* modify cyls, n_sectors */
215 host->cyls = (host->n_sectors - MG_RES_SEC) /
216 host->heads / host->sectors;
217 host->nres_sectors = host->n_sectors - host->cyls *
218 host->heads * host->sectors;
219 host->n_sectors -= host->nres_sectors;
222 ata_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev));
223 ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model));
224 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
225 printk(KERN_INFO "mg_disk: model: %s\n", model);
226 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev);
227 printk(KERN_INFO "mg_disk: serial: %s\n", serial);
228 printk(KERN_INFO "mg_disk: %d + reserved %d sectors\n",
229 host->n_sectors, host->nres_sectors);
231 if (!prv_data->use_polling)
232 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
239 static int mg_disk_init(struct mg_host *host)
241 struct mg_drv_data *prv_data = host->dev->platform_data;
246 gpio_set_value(host->rst, 0);
247 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY);
252 gpio_set_value(host->rst, 1);
253 err = mg_wait(host, MG_STAT_READY, MG_TMAX_HDRST_TO_RDY);
258 outb(MG_REG_CTRL_RESET |
259 (prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
260 MG_REG_CTRL_INTR_ENABLE),
261 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
262 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY);
267 outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
268 MG_REG_CTRL_INTR_ENABLE,
269 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
270 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY);
274 init_status = inb((unsigned long)host->dev_base + MG_REG_STATUS) & 0xf;
276 if (init_status == 0xf)
277 return MG_ERR_INIT_STAT;
282 static void mg_bad_rw_intr(struct mg_host *host)
284 struct request *req = elv_next_request(host->breq);
286 if (++req->errors >= MG_MAX_ERRORS ||
287 host->error == MG_ERR_TIMEOUT)
291 static unsigned int mg_out(struct mg_host *host,
292 unsigned int sect_num,
293 unsigned int sect_cnt,
295 void (*intr_addr)(struct mg_host *))
297 struct mg_drv_data *prv_data = host->dev->platform_data;
299 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
302 if (!prv_data->use_polling) {
303 host->mg_do_intr = intr_addr;
304 mod_timer(&host->timer, jiffies + 3 * HZ);
307 sect_num += MG_RES_SEC;
308 outb((u8)sect_cnt, (unsigned long)host->dev_base + MG_REG_SECT_CNT);
309 outb((u8)sect_num, (unsigned long)host->dev_base + MG_REG_SECT_NUM);
310 outb((u8)(sect_num >> 8), (unsigned long)host->dev_base +
312 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base +
314 outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE),
315 (unsigned long)host->dev_base + MG_REG_DRV_HEAD);
316 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND);
320 static void mg_read(struct request *req)
323 struct mg_host *host = req->rq_disk->private_data;
325 remains = req->nr_sectors;
327 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, NULL) !=
329 mg_bad_rw_intr(host);
331 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
332 remains, req->sector, req->buffer);
335 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
336 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
337 mg_bad_rw_intr(host);
340 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
341 *(u16 *)req->buffer =
342 inw((unsigned long)host->dev_base +
343 MG_BUFF_OFFSET + (j << 1));
349 remains = --req->nr_sectors;
350 --req->current_nr_sectors;
352 if (req->current_nr_sectors <= 0) {
353 MG_DBG("remain : %d sects\n", remains);
356 req = elv_next_request(host->breq);
359 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
364 static void mg_write(struct request *req)
367 struct mg_host *host = req->rq_disk->private_data;
369 remains = req->nr_sectors;
371 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, NULL) !=
373 mg_bad_rw_intr(host);
378 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
379 remains, req->sector, req->buffer);
381 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ,
382 MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
383 mg_bad_rw_intr(host);
386 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
387 outw(*(u16 *)req->buffer,
388 (unsigned long)host->dev_base +
389 MG_BUFF_OFFSET + (j << 1));
393 remains = --req->nr_sectors;
394 --req->current_nr_sectors;
396 if (req->current_nr_sectors <= 0) {
397 MG_DBG("remain : %d sects\n", remains);
400 req = elv_next_request(host->breq);
403 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
408 static void mg_read_intr(struct mg_host *host)
415 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
416 if (i & MG_REG_STATUS_BIT_BUSY)
420 if (i & MG_REG_STATUS_BIT_DATA_REQ)
423 mg_dump_status("mg_read_intr", i, host);
424 mg_bad_rw_intr(host);
425 mg_request(host->breq);
429 /* get current segment of request */
430 req = elv_next_request(host->breq);
433 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
434 *(u16 *)req->buffer =
435 inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
440 /* manipulate request */
441 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
442 req->sector, req->nr_sectors - 1, req->buffer);
446 i = --req->nr_sectors;
447 --req->current_nr_sectors;
449 /* let know if current segment done */
450 if (req->current_nr_sectors <= 0)
453 /* set handler if read remains */
455 host->mg_do_intr = mg_read_intr;
456 mod_timer(&host->timer, jiffies + 3 * HZ);
459 /* send read confirm */
460 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
462 /* goto next request */
464 mg_request(host->breq);
467 static void mg_write_intr(struct mg_host *host)
473 /* get current segment of request */
474 req = elv_next_request(host->breq);
478 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
479 if (i & MG_REG_STATUS_BIT_BUSY)
483 if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ))
486 mg_dump_status("mg_write_intr", i, host);
487 mg_bad_rw_intr(host);
488 mg_request(host->breq);
492 /* manipulate request */
494 i = --req->nr_sectors;
495 --req->current_nr_sectors;
496 req->buffer += MG_SECTOR_SIZE;
498 /* let know if current segment or all done */
499 if (!i || (req->bio && req->current_nr_sectors <= 0))
502 /* write 1 sector and set handler if remains */
504 buff = (u16 *)req->buffer;
505 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
506 outw(*buff, (unsigned long)host->dev_base +
507 MG_BUFF_OFFSET + (j << 1));
510 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
511 req->sector, req->nr_sectors, req->buffer);
512 host->mg_do_intr = mg_write_intr;
513 mod_timer(&host->timer, jiffies + 3 * HZ);
516 /* send write confirm */
517 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
520 mg_request(host->breq);
523 void mg_times_out(unsigned long data)
525 struct mg_host *host = (struct mg_host *)data;
529 spin_lock_irq(&host->lock);
531 req = elv_next_request(host->breq);
535 host->mg_do_intr = NULL;
537 name = req->rq_disk->disk_name;
538 printk(KERN_DEBUG "%s: timeout\n", name);
540 host->error = MG_ERR_TIMEOUT;
541 mg_bad_rw_intr(host);
543 mg_request(host->breq);
545 spin_unlock_irq(&host->lock);
548 static void mg_request_poll(struct request_queue *q)
551 struct mg_host *host;
553 while ((req = elv_next_request(q)) != NULL) {
554 host = req->rq_disk->private_data;
555 if (blk_fs_request(req)) {
556 switch (rq_data_dir(req)) {
564 printk(KERN_WARNING "%s:%d unknown command\n",
573 static unsigned int mg_issue_req(struct request *req,
574 struct mg_host *host,
575 unsigned int sect_num,
576 unsigned int sect_cnt)
581 switch (rq_data_dir(req)) {
583 if (mg_out(host, sect_num, sect_cnt, MG_CMD_RD, &mg_read_intr)
585 mg_bad_rw_intr(host);
591 outb(MG_REG_CTRL_INTR_DISABLE,
592 (unsigned long)host->dev_base +
594 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr)
596 mg_bad_rw_intr(host);
599 del_timer(&host->timer);
600 mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_WR_DRQ);
601 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
604 mg_bad_rw_intr(host);
607 buff = (u16 *)req->buffer;
608 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
609 outw(*buff, (unsigned long)host->dev_base +
610 MG_BUFF_OFFSET + (i << 1));
613 mod_timer(&host->timer, jiffies + 3 * HZ);
614 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
618 printk(KERN_WARNING "%s:%d unknown command\n",
626 /* This function also called from IRQ context */
627 static void mg_request(struct request_queue *q)
630 struct mg_host *host;
631 u32 sect_num, sect_cnt;
634 req = elv_next_request(q);
638 host = req->rq_disk->private_data;
640 /* check unwanted request call */
641 if (host->mg_do_intr)
644 del_timer(&host->timer);
646 sect_num = req->sector;
647 /* deal whole segments */
648 sect_cnt = req->nr_sectors;
651 if (sect_num >= get_capacity(req->rq_disk) ||
652 ((sect_num + sect_cnt) >
653 get_capacity(req->rq_disk))) {
655 "%s: bad access: sector=%d, count=%d\n",
656 req->rq_disk->disk_name,
662 if (!blk_fs_request(req))
665 if (!mg_issue_req(req, host, sect_num, sect_cnt))
670 static int mg_getgeo(struct block_device *bdev, struct hd_geometry *geo)
672 struct mg_host *host = bdev->bd_disk->private_data;
674 geo->cylinders = (unsigned short)host->cyls;
675 geo->heads = (unsigned char)host->heads;
676 geo->sectors = (unsigned char)host->sectors;
680 static struct block_device_operations mg_disk_ops = {
684 static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
686 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
687 struct mg_host *host = prv_data->host;
689 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
692 if (!prv_data->use_polling)
693 outb(MG_REG_CTRL_INTR_DISABLE,
694 (unsigned long)host->dev_base +
697 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND);
698 /* wait until mflash deep sleep */
701 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) {
702 if (!prv_data->use_polling)
703 outb(MG_REG_CTRL_INTR_ENABLE,
704 (unsigned long)host->dev_base +
712 static int mg_resume(struct platform_device *plat_dev)
714 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
715 struct mg_host *host = prv_data->host;
717 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
720 outb(MG_CMD_WAKEUP, (unsigned long)host->dev_base + MG_REG_COMMAND);
721 /* wait until mflash wakeup */
724 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
727 if (!prv_data->use_polling)
728 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base +
734 static int mg_probe(struct platform_device *plat_dev)
736 struct mg_host *host;
737 struct resource *rsc;
738 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
742 printk(KERN_ERR "%s:%d fail (no driver_data)\n",
749 host = kzalloc(sizeof(struct mg_host), GFP_KERNEL);
751 printk(KERN_ERR "%s:%d fail (no memory for mg_host)\n",
756 host->major = MG_DISK_MAJ;
758 /* link each other */
759 prv_data->host = host;
760 host->dev = &plat_dev->dev;
763 rsc = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
765 printk(KERN_ERR "%s:%d platform_get_resource fail\n",
770 host->dev_base = ioremap(rsc->start , rsc->end + 1);
771 if (!host->dev_base) {
772 printk(KERN_ERR "%s:%d ioremap fail\n",
777 MG_DBG("dev_base = 0x%x\n", (u32)host->dev_base);
780 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO,
783 printk(KERN_ERR "%s:%d get reset pin fail\n",
788 host->rst = rsc->start;
791 err = gpio_request(host->rst, MG_RST_PIN);
794 gpio_direction_output(host->rst, 1);
797 if (!(prv_data->dev_attr & MG_DEV_MASK))
800 if (prv_data->dev_attr != MG_BOOT_DEV) {
801 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO,
804 printk(KERN_ERR "%s:%d get reset-out pin fail\n",
809 host->rstout = rsc->start;
810 err = gpio_request(host->rstout, MG_RSTOUT_PIN);
813 gpio_direction_input(host->rstout);
817 if (prv_data->dev_attr == MG_STORAGE_DEV) {
818 /* If POR seq. not yet finised, wait */
819 err = mg_wait_rstout(host->rstout, MG_TMAX_RSTOUT);
822 err = mg_disk_init(host);
824 printk(KERN_ERR "%s:%d fail (err code : %d)\n",
825 __func__, __LINE__, err);
831 /* get irq resource */
832 if (!prv_data->use_polling) {
833 host->irq = platform_get_irq(plat_dev, 0);
834 if (host->irq == -ENXIO) {
838 err = request_irq(host->irq, mg_irq,
839 IRQF_DISABLED | IRQF_TRIGGER_RISING,
842 printk(KERN_ERR "%s:%d fail (request_irq err=%d)\n",
843 __func__, __LINE__, err);
850 err = mg_get_disk_id(host);
852 printk(KERN_ERR "%s:%d fail (err code : %d)\n",
853 __func__, __LINE__, err);
858 err = register_blkdev(host->major, MG_DISK_NAME);
860 printk(KERN_ERR "%s:%d register_blkdev fail (err code : %d)\n",
861 __func__, __LINE__, err);
867 spin_lock_init(&host->lock);
869 if (prv_data->use_polling)
870 host->breq = blk_init_queue(mg_request_poll, &host->lock);
872 host->breq = blk_init_queue(mg_request, &host->lock);
876 printk(KERN_ERR "%s:%d (blk_init_queue) fail\n",
881 /* mflash is random device, thanx for the noop */
882 elevator_exit(host->breq->elevator);
883 err = elevator_init(host->breq, "noop");
885 printk(KERN_ERR "%s:%d (elevator_init) fail\n",
889 blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
890 blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE);
892 init_timer(&host->timer);
893 host->timer.function = mg_times_out;
894 host->timer.data = (unsigned long)host;
896 host->gd = alloc_disk(MG_DISK_MAX_PART);
898 printk(KERN_ERR "%s:%d (alloc_disk) fail\n",
903 host->gd->major = host->major;
904 host->gd->first_minor = 0;
905 host->gd->fops = &mg_disk_ops;
906 host->gd->queue = host->breq;
907 host->gd->private_data = host;
908 sprintf(host->gd->disk_name, MG_DISK_NAME"a");
910 set_capacity(host->gd, host->n_sectors);
917 del_timer_sync(&host->timer);
919 blk_cleanup_queue(host->breq);
921 unregister_blkdev(MG_DISK_MAJ, MG_DISK_NAME);
923 if (!prv_data->use_polling)
924 free_irq(host->irq, host);
926 gpio_free(host->rstout);
928 gpio_free(host->rst);
930 iounmap(host->dev_base);
937 static int mg_remove(struct platform_device *plat_dev)
939 struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
940 struct mg_host *host = prv_data->host;
944 del_timer_sync(&host->timer);
948 del_gendisk(host->gd);
953 blk_cleanup_queue(host->breq);
955 /* unregister blk device */
956 unregister_blkdev(host->major, MG_DISK_NAME);
959 if (!prv_data->use_polling)
960 free_irq(host->irq, host);
962 /* free reset-out pin */
963 if (prv_data->dev_attr != MG_BOOT_DEV)
964 gpio_free(host->rstout);
968 gpio_free(host->rst);
972 iounmap(host->dev_base);
980 static struct platform_driver mg_disk_driver = {
983 .suspend = mg_suspend,
987 .owner = THIS_MODULE,
991 /****************************************************************************
995 ****************************************************************************/
997 static int __init mg_init(void)
999 printk(KERN_INFO "mGine mflash driver, (c) 2008 mGine Co.\n");
1000 return platform_driver_register(&mg_disk_driver);
1003 static void __exit mg_exit(void)
1005 printk(KERN_INFO "mflash driver : bye bye\n");
1006 platform_driver_unregister(&mg_disk_driver);
1009 module_init(mg_init);
1010 module_exit(mg_exit);
1012 MODULE_LICENSE("GPL");
1013 MODULE_AUTHOR("unsik Kim <donari75@gmail.com>");
1014 MODULE_DESCRIPTION("mGine m[g]flash device driver");