aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/mg_disk.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2009-04-28 00:06:14 -0400
committerJens Axboe <jens.axboe@oracle.com>2009-04-28 02:14:51 -0400
commiteec9462088a26c046d4db3100796a340a50890b8 (patch)
tree7038abaee44acf1498ede878257ea30f7ebb3c40 /drivers/block/mg_disk.c
parente138b4e08ef65771000fbe6d93d67e3960ff862b (diff)
mg_disk: fold mg_disk.h into mg_disk.c
include/linux/mg_disk.h is used only by drivers/block/mg_disk.c. No reason to put it in a separate header. Fold it into mg_disk.c. [ Impact: cleanup ] Signed-off-by: Tejun Heo <tj@kernel.org> Cc: unsik Kim <donari75@gmail.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/block/mg_disk.c')
-rw-r--r--drivers/block/mg_disk.c186
1 files changed, 185 insertions, 1 deletions
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 2c00ad90cd6..2c6127ee834 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -22,10 +22,194 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/mg_disk.h>
26 25
27#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1) 26#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
28 27
28/* name for block device */
29#define MG_DISK_NAME "mgd"
30/* name for platform device */
31#define MG_DEV_NAME "mg_disk"
32
33#define MG_DISK_MAJ 0
34#define MG_DISK_MAX_PART 16
35#define MG_SECTOR_SIZE 512
36#define MG_MAX_SECTS 256
37
38/* Register offsets */
39#define MG_BUFF_OFFSET 0x8000
40#define MG_STORAGE_BUFFER_SIZE 0x200
41#define MG_REG_OFFSET 0xC000
42#define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
43#define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
44#define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
45#define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
46#define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
47#define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
48#define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
49#define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
50#define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
51#define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
52#define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
53
54/* "Drive Select/Head Register" bit values */
55#define MG_REG_HEAD_MUST_BE_ON 0xA0 /* These 2 bits are always on */
56#define MG_REG_HEAD_DRIVE_MASTER (0x00 | MG_REG_HEAD_MUST_BE_ON)
57#define MG_REG_HEAD_DRIVE_SLAVE (0x10 | MG_REG_HEAD_MUST_BE_ON)
58#define MG_REG_HEAD_LBA_MODE (0x40 | MG_REG_HEAD_MUST_BE_ON)
59
60
61/* "Device Control Register" bit values */
62#define MG_REG_CTRL_INTR_ENABLE 0x0
63#define MG_REG_CTRL_INTR_DISABLE (0x1<<1)
64#define MG_REG_CTRL_RESET (0x1<<2)
65#define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH 0x0
66#define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW (0x1<<4)
67#define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW 0x0
68#define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH (0x1<<5)
69#define MG_REG_CTRL_DPD_DISABLE 0x0
70#define MG_REG_CTRL_DPD_ENABLE (0x1<<6)
71
72/* Status register bit */
73/* error bit in status register */
74#define MG_REG_STATUS_BIT_ERROR 0x01
75/* corrected error in status register */
76#define MG_REG_STATUS_BIT_CORRECTED_ERROR 0x04
77/* data request bit in status register */
78#define MG_REG_STATUS_BIT_DATA_REQ 0x08
79/* DSC - Drive Seek Complete */
80#define MG_REG_STATUS_BIT_SEEK_DONE 0x10
81/* DWF - Drive Write Fault */
82#define MG_REG_STATUS_BIT_WRITE_FAULT 0x20
83#define MG_REG_STATUS_BIT_READY 0x40
84#define MG_REG_STATUS_BIT_BUSY 0x80
85
86/* handy status */
87#define MG_STAT_READY (MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
88#define MG_READY_OK(s) (((s) & (MG_STAT_READY | \
89 (MG_REG_STATUS_BIT_BUSY | \
90 MG_REG_STATUS_BIT_WRITE_FAULT | \
91 MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY)
92
93/* Error register */
94#define MG_REG_ERR_AMNF 0x01
95#define MG_REG_ERR_ABRT 0x04
96#define MG_REG_ERR_IDNF 0x10
97#define MG_REG_ERR_UNC 0x40
98#define MG_REG_ERR_BBK 0x80
99
100/* error code for others */
101#define MG_ERR_NONE 0
102#define MG_ERR_TIMEOUT 0x100
103#define MG_ERR_INIT_STAT 0x101
104#define MG_ERR_TRANSLATION 0x102
105#define MG_ERR_CTRL_RST 0x103
106#define MG_ERR_INV_STAT 0x104
107#define MG_ERR_RSTOUT 0x105
108
109#define MG_MAX_ERRORS 6 /* Max read/write errors */
110
111/* command */
112#define MG_CMD_RD 0x20
113#define MG_CMD_WR 0x30
114#define MG_CMD_SLEEP 0x99
115#define MG_CMD_WAKEUP 0xC3
116#define MG_CMD_ID 0xEC
117#define MG_CMD_WR_CONF 0x3C
118#define MG_CMD_RD_CONF 0x40
119
120/* operation mode */
121#define MG_OP_CASCADE (1 << 0)
122#define MG_OP_CASCADE_SYNC_RD (1 << 1)
123#define MG_OP_CASCADE_SYNC_WR (1 << 2)
124#define MG_OP_INTERLEAVE (1 << 3)
125
126/* synchronous */
127#define MG_BURST_LAT_4 (3 << 4)
128#define MG_BURST_LAT_5 (4 << 4)
129#define MG_BURST_LAT_6 (5 << 4)
130#define MG_BURST_LAT_7 (6 << 4)
131#define MG_BURST_LAT_8 (7 << 4)
132#define MG_BURST_LEN_4 (1 << 1)
133#define MG_BURST_LEN_8 (2 << 1)
134#define MG_BURST_LEN_16 (3 << 1)
135#define MG_BURST_LEN_32 (4 << 1)
136#define MG_BURST_LEN_CONT (0 << 1)
137
138/* timeout value (unit: ms) */
139#define MG_TMAX_CONF_TO_CMD 1
140#define MG_TMAX_WAIT_RD_DRQ 10
141#define MG_TMAX_WAIT_WR_DRQ 500
142#define MG_TMAX_RST_TO_BUSY 10
143#define MG_TMAX_HDRST_TO_RDY 500
144#define MG_TMAX_SWRST_TO_RDY 500
145#define MG_TMAX_RSTOUT 3000
146
147/* device attribution */
148/* use mflash as boot device */
149#define MG_BOOT_DEV (1 << 0)
150/* use mflash as storage device */
151#define MG_STORAGE_DEV (1 << 1)
152/* same as MG_STORAGE_DEV, but bootloader already done reset sequence */
153#define MG_STORAGE_DEV_SKIP_RST (1 << 2)
154
155#define MG_DEV_MASK (MG_BOOT_DEV | MG_STORAGE_DEV | MG_STORAGE_DEV_SKIP_RST)
156
157/* names of GPIO resource */
158#define MG_RST_PIN "mg_rst"
159/* except MG_BOOT_DEV, reset-out pin should be assigned */
160#define MG_RSTOUT_PIN "mg_rstout"
161
162/* private driver data */
163struct mg_drv_data {
164 /* disk resource */
165 u32 use_polling;
166
167 /* device attribution */
168 u32 dev_attr;
169
170 /* internally used */
171 struct mg_host *host;
172};
173
174/* main structure for mflash driver */
175struct mg_host {
176 struct device *dev;
177
178 struct request_queue *breq;
179 spinlock_t lock;
180 struct gendisk *gd;
181
182 struct timer_list timer;
183 void (*mg_do_intr) (struct mg_host *);
184
185 u16 id[ATA_ID_WORDS];
186
187 u16 cyls;
188 u16 heads;
189 u16 sectors;
190 u32 n_sectors;
191 u32 nres_sectors;
192
193 void __iomem *dev_base;
194 unsigned int irq;
195 unsigned int rst;
196 unsigned int rstout;
197
198 u32 major;
199 u32 error;
200};
201
202/*
203 * Debugging macro and defines
204 */
205#undef DO_MG_DEBUG
206#ifdef DO_MG_DEBUG
207# define MG_DBG(fmt, args...) \
208 printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
209#else /* CONFIG_MG_DEBUG */
210# define MG_DBG(fmt, args...) do { } while (0)
211#endif /* CONFIG_MG_DEBUG */
212
29static void mg_request(struct request_queue *); 213static void mg_request(struct request_queue *);
30 214
31static void mg_dump_status(const char *msg, unsigned int stat, 215static void mg_dump_status(const char *msg, unsigned int stat,