]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/block/xsysace.c
Merge branch 'params' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux...
[net-next-2.6.git] / drivers / block / xsysace.c
1 /*
2  * Xilinx SystemACE device driver
3  *
4  * Copyright 2007 Secret Lab Technologies Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published
8  * by the Free Software Foundation.
9  */
10
11 /*
12  * The SystemACE chip is designed to configure FPGAs by loading an FPGA
13  * bitstream from a file on a CF card and squirting it into FPGAs connected
14  * to the SystemACE JTAG chain.  It also has the advantage of providing an
15  * MPU interface which can be used to control the FPGA configuration process
16  * and to use the attached CF card for general purpose storage.
17  *
18  * This driver is a block device driver for the SystemACE.
19  *
20  * Initialization:
21  *    The driver registers itself as a platform_device driver at module
22  *    load time.  The platform bus will take care of calling the
23  *    ace_probe() method for all SystemACE instances in the system.  Any
24  *    number of SystemACE instances are supported.  ace_probe() calls
25  *    ace_setup() which initialized all data structures, reads the CF
26  *    id structure and registers the device.
27  *
28  * Processing:
29  *    Just about all of the heavy lifting in this driver is performed by
30  *    a Finite State Machine (FSM).  The driver needs to wait on a number
31  *    of events; some raised by interrupts, some which need to be polled
32  *    for.  Describing all of the behaviour in a FSM seems to be the
33  *    easiest way to keep the complexity low and make it easy to
34  *    understand what the driver is doing.  If the block ops or the
35  *    request function need to interact with the hardware, then they
36  *    simply need to flag the request and kick of FSM processing.
37  *
38  *    The FSM itself is atomic-safe code which can be run from any
39  *    context.  The general process flow is:
40  *    1. obtain the ace->lock spinlock.
41  *    2. loop on ace_fsm_dostate() until the ace->fsm_continue flag is
42  *       cleared.
43  *    3. release the lock.
44  *
45  *    Individual states do not sleep in any way.  If a condition needs to
46  *    be waited for then the state much clear the fsm_continue flag and
47  *    either schedule the FSM to be run again at a later time, or expect
48  *    an interrupt to call the FSM when the desired condition is met.
49  *
50  *    In normal operation, the FSM is processed at interrupt context
51  *    either when the driver's tasklet is scheduled, or when an irq is
52  *    raised by the hardware.  The tasklet can be scheduled at any time.
53  *    The request method in particular schedules the tasklet when a new
54  *    request has been indicated by the block layer.  Once started, the
55  *    FSM proceeds as far as it can processing the request until it
56  *    needs on a hardware event.  At this point, it must yield execution.
57  *
58  *    A state has two options when yielding execution:
59  *    1. ace_fsm_yield()
60  *       - Call if need to poll for event.
61  *       - clears the fsm_continue flag to exit the processing loop
62  *       - reschedules the tasklet to run again as soon as possible
63  *    2. ace_fsm_yieldirq()
64  *       - Call if an irq is expected from the HW
65  *       - clears the fsm_continue flag to exit the processing loop
66  *       - does not reschedule the tasklet so the FSM will not be processed
67  *         again until an irq is received.
68  *    After calling a yield function, the state must return control back
69  *    to the FSM main loop.
70  *
71  *    Additionally, the driver maintains a kernel timer which can process
72  *    the FSM.  If the FSM gets stalled, typically due to a missed
73  *    interrupt, then the kernel timer will expire and the driver can
74  *    continue where it left off.
75  *
76  * To Do:
77  *    - Add FPGA configuration control interface.
78  *    - Request major number from lanana
79  */
80
81 #undef DEBUG
82
83 #include <linux/module.h>
84 #include <linux/ctype.h>
85 #include <linux/init.h>
86 #include <linux/interrupt.h>
87 #include <linux/errno.h>
88 #include <linux/kernel.h>
89 #include <linux/delay.h>
90 #include <linux/slab.h>
91 #include <linux/blkdev.h>
92 #include <linux/smp_lock.h>
93 #include <linux/ata.h>
94 #include <linux/hdreg.h>
95 #include <linux/platform_device.h>
96 #if defined(CONFIG_OF)
97 #include <linux/of_device.h>
98 #include <linux/of_platform.h>
99 #endif
100
101 MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
102 MODULE_DESCRIPTION("Xilinx SystemACE device driver");
103 MODULE_LICENSE("GPL");
104
105 /* SystemACE register definitions */
106 #define ACE_BUSMODE (0x00)
107
108 #define ACE_STATUS (0x04)
109 #define ACE_STATUS_CFGLOCK      (0x00000001)
110 #define ACE_STATUS_MPULOCK      (0x00000002)
111 #define ACE_STATUS_CFGERROR     (0x00000004)    /* config controller error */
112 #define ACE_STATUS_CFCERROR     (0x00000008)    /* CF controller error */
113 #define ACE_STATUS_CFDETECT     (0x00000010)
114 #define ACE_STATUS_DATABUFRDY   (0x00000020)
115 #define ACE_STATUS_DATABUFMODE  (0x00000040)
116 #define ACE_STATUS_CFGDONE      (0x00000080)
117 #define ACE_STATUS_RDYFORCFCMD  (0x00000100)
118 #define ACE_STATUS_CFGMODEPIN   (0x00000200)
119 #define ACE_STATUS_CFGADDR_MASK (0x0000e000)
120 #define ACE_STATUS_CFBSY        (0x00020000)
121 #define ACE_STATUS_CFRDY        (0x00040000)
122 #define ACE_STATUS_CFDWF        (0x00080000)
123 #define ACE_STATUS_CFDSC        (0x00100000)
124 #define ACE_STATUS_CFDRQ        (0x00200000)
125 #define ACE_STATUS_CFCORR       (0x00400000)
126 #define ACE_STATUS_CFERR        (0x00800000)
127
128 #define ACE_ERROR (0x08)
129 #define ACE_CFGLBA (0x0c)
130 #define ACE_MPULBA (0x10)
131
132 #define ACE_SECCNTCMD (0x14)
133 #define ACE_SECCNTCMD_RESET      (0x0100)
134 #define ACE_SECCNTCMD_IDENTIFY   (0x0200)
135 #define ACE_SECCNTCMD_READ_DATA  (0x0300)
136 #define ACE_SECCNTCMD_WRITE_DATA (0x0400)
137 #define ACE_SECCNTCMD_ABORT      (0x0600)
138
139 #define ACE_VERSION (0x16)
140 #define ACE_VERSION_REVISION_MASK (0x00FF)
141 #define ACE_VERSION_MINOR_MASK    (0x0F00)
142 #define ACE_VERSION_MAJOR_MASK    (0xF000)
143
144 #define ACE_CTRL (0x18)
145 #define ACE_CTRL_FORCELOCKREQ   (0x0001)
146 #define ACE_CTRL_LOCKREQ        (0x0002)
147 #define ACE_CTRL_FORCECFGADDR   (0x0004)
148 #define ACE_CTRL_FORCECFGMODE   (0x0008)
149 #define ACE_CTRL_CFGMODE        (0x0010)
150 #define ACE_CTRL_CFGSTART       (0x0020)
151 #define ACE_CTRL_CFGSEL         (0x0040)
152 #define ACE_CTRL_CFGRESET       (0x0080)
153 #define ACE_CTRL_DATABUFRDYIRQ  (0x0100)
154 #define ACE_CTRL_ERRORIRQ       (0x0200)
155 #define ACE_CTRL_CFGDONEIRQ     (0x0400)
156 #define ACE_CTRL_RESETIRQ       (0x0800)
157 #define ACE_CTRL_CFGPROG        (0x1000)
158 #define ACE_CTRL_CFGADDR_MASK   (0xe000)
159
160 #define ACE_FATSTAT (0x1c)
161
162 #define ACE_NUM_MINORS 16
163 #define ACE_SECTOR_SIZE (512)
164 #define ACE_FIFO_SIZE (32)
165 #define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE)
166
167 #define ACE_BUS_WIDTH_8  0
168 #define ACE_BUS_WIDTH_16 1
169
170 struct ace_reg_ops;
171
172 struct ace_device {
173         /* driver state data */
174         int id;
175         int media_change;
176         int users;
177         struct list_head list;
178
179         /* finite state machine data */
180         struct tasklet_struct fsm_tasklet;
181         uint fsm_task;          /* Current activity (ACE_TASK_*) */
182         uint fsm_state;         /* Current state (ACE_FSM_STATE_*) */
183         uint fsm_continue_flag; /* cleared to exit FSM mainloop */
184         uint fsm_iter_num;
185         struct timer_list stall_timer;
186
187         /* Transfer state/result, use for both id and block request */
188         struct request *req;    /* request being processed */
189         void *data_ptr;         /* pointer to I/O buffer */
190         int data_count;         /* number of buffers remaining */
191         int data_result;        /* Result of transfer; 0 := success */
192
193         int id_req_count;       /* count of id requests */
194         int id_result;
195         struct completion id_completion;        /* used when id req finishes */
196         int in_irq;
197
198         /* Details of hardware device */
199         resource_size_t physaddr;
200         void __iomem *baseaddr;
201         int irq;
202         int bus_width;          /* 0 := 8 bit; 1 := 16 bit */
203         struct ace_reg_ops *reg_ops;
204         int lock_count;
205
206         /* Block device data structures */
207         spinlock_t lock;
208         struct device *dev;
209         struct request_queue *queue;
210         struct gendisk *gd;
211
212         /* Inserted CF card parameters */
213         u16 cf_id[ATA_ID_WORDS];
214 };
215
216 static int ace_major;
217
218 /* ---------------------------------------------------------------------
219  * Low level register access
220  */
221
222 struct ace_reg_ops {
223         u16(*in) (struct ace_device * ace, int reg);
224         void (*out) (struct ace_device * ace, int reg, u16 val);
225         void (*datain) (struct ace_device * ace);
226         void (*dataout) (struct ace_device * ace);
227 };
228
229 /* 8 Bit bus width */
230 static u16 ace_in_8(struct ace_device *ace, int reg)
231 {
232         void __iomem *r = ace->baseaddr + reg;
233         return in_8(r) | (in_8(r + 1) << 8);
234 }
235
236 static void ace_out_8(struct ace_device *ace, int reg, u16 val)
237 {
238         void __iomem *r = ace->baseaddr + reg;
239         out_8(r, val);
240         out_8(r + 1, val >> 8);
241 }
242
243 static void ace_datain_8(struct ace_device *ace)
244 {
245         void __iomem *r = ace->baseaddr + 0x40;
246         u8 *dst = ace->data_ptr;
247         int i = ACE_FIFO_SIZE;
248         while (i--)
249                 *dst++ = in_8(r++);
250         ace->data_ptr = dst;
251 }
252
253 static void ace_dataout_8(struct ace_device *ace)
254 {
255         void __iomem *r = ace->baseaddr + 0x40;
256         u8 *src = ace->data_ptr;
257         int i = ACE_FIFO_SIZE;
258         while (i--)
259                 out_8(r++, *src++);
260         ace->data_ptr = src;
261 }
262
263 static struct ace_reg_ops ace_reg_8_ops = {
264         .in = ace_in_8,
265         .out = ace_out_8,
266         .datain = ace_datain_8,
267         .dataout = ace_dataout_8,
268 };
269
270 /* 16 bit big endian bus attachment */
271 static u16 ace_in_be16(struct ace_device *ace, int reg)
272 {
273         return in_be16(ace->baseaddr + reg);
274 }
275
276 static void ace_out_be16(struct ace_device *ace, int reg, u16 val)
277 {
278         out_be16(ace->baseaddr + reg, val);
279 }
280
281 static void ace_datain_be16(struct ace_device *ace)
282 {
283         int i = ACE_FIFO_SIZE / 2;
284         u16 *dst = ace->data_ptr;
285         while (i--)
286                 *dst++ = in_le16(ace->baseaddr + 0x40);
287         ace->data_ptr = dst;
288 }
289
290 static void ace_dataout_be16(struct ace_device *ace)
291 {
292         int i = ACE_FIFO_SIZE / 2;
293         u16 *src = ace->data_ptr;
294         while (i--)
295                 out_le16(ace->baseaddr + 0x40, *src++);
296         ace->data_ptr = src;
297 }
298
299 /* 16 bit little endian bus attachment */
300 static u16 ace_in_le16(struct ace_device *ace, int reg)
301 {
302         return in_le16(ace->baseaddr + reg);
303 }
304
305 static void ace_out_le16(struct ace_device *ace, int reg, u16 val)
306 {
307         out_le16(ace->baseaddr + reg, val);
308 }
309
310 static void ace_datain_le16(struct ace_device *ace)
311 {
312         int i = ACE_FIFO_SIZE / 2;
313         u16 *dst = ace->data_ptr;
314         while (i--)
315                 *dst++ = in_be16(ace->baseaddr + 0x40);
316         ace->data_ptr = dst;
317 }
318
319 static void ace_dataout_le16(struct ace_device *ace)
320 {
321         int i = ACE_FIFO_SIZE / 2;
322         u16 *src = ace->data_ptr;
323         while (i--)
324                 out_be16(ace->baseaddr + 0x40, *src++);
325         ace->data_ptr = src;
326 }
327
328 static struct ace_reg_ops ace_reg_be16_ops = {
329         .in = ace_in_be16,
330         .out = ace_out_be16,
331         .datain = ace_datain_be16,
332         .dataout = ace_dataout_be16,
333 };
334
335 static struct ace_reg_ops ace_reg_le16_ops = {
336         .in = ace_in_le16,
337         .out = ace_out_le16,
338         .datain = ace_datain_le16,
339         .dataout = ace_dataout_le16,
340 };
341
342 static inline u16 ace_in(struct ace_device *ace, int reg)
343 {
344         return ace->reg_ops->in(ace, reg);
345 }
346
347 static inline u32 ace_in32(struct ace_device *ace, int reg)
348 {
349         return ace_in(ace, reg) | (ace_in(ace, reg + 2) << 16);
350 }
351
352 static inline void ace_out(struct ace_device *ace, int reg, u16 val)
353 {
354         ace->reg_ops->out(ace, reg, val);
355 }
356
357 static inline void ace_out32(struct ace_device *ace, int reg, u32 val)
358 {
359         ace_out(ace, reg, val);
360         ace_out(ace, reg + 2, val >> 16);
361 }
362
363 /* ---------------------------------------------------------------------
364  * Debug support functions
365  */
366
367 #if defined(DEBUG)
368 static void ace_dump_mem(void *base, int len)
369 {
370         const char *ptr = base;
371         int i, j;
372
373         for (i = 0; i < len; i += 16) {
374                 printk(KERN_INFO "%.8x:", i);
375                 for (j = 0; j < 16; j++) {
376                         if (!(j % 4))
377                                 printk(" ");
378                         printk("%.2x", ptr[i + j]);
379                 }
380                 printk(" ");
381                 for (j = 0; j < 16; j++)
382                         printk("%c", isprint(ptr[i + j]) ? ptr[i + j] : '.');
383                 printk("\n");
384         }
385 }
386 #else
387 static inline void ace_dump_mem(void *base, int len)
388 {
389 }
390 #endif
391
392 static void ace_dump_regs(struct ace_device *ace)
393 {
394         dev_info(ace->dev,
395                  "    ctrl:  %.8x  seccnt/cmd: %.4x      ver:%.4x\n"
396                  "    status:%.8x  mpu_lba:%.8x  busmode:%4x\n"
397                  "    error: %.8x  cfg_lba:%.8x  fatstat:%.4x\n",
398                  ace_in32(ace, ACE_CTRL),
399                  ace_in(ace, ACE_SECCNTCMD),
400                  ace_in(ace, ACE_VERSION),
401                  ace_in32(ace, ACE_STATUS),
402                  ace_in32(ace, ACE_MPULBA),
403                  ace_in(ace, ACE_BUSMODE),
404                  ace_in32(ace, ACE_ERROR),
405                  ace_in32(ace, ACE_CFGLBA), ace_in(ace, ACE_FATSTAT));
406 }
407
408 void ace_fix_driveid(u16 *id)
409 {
410 #if defined(__BIG_ENDIAN)
411         int i;
412
413         /* All half words have wrong byte order; swap the bytes */
414         for (i = 0; i < ATA_ID_WORDS; i++, id++)
415                 *id = le16_to_cpu(*id);
416 #endif
417 }
418
419 /* ---------------------------------------------------------------------
420  * Finite State Machine (FSM) implementation
421  */
422
423 /* FSM tasks; used to direct state transitions */
424 #define ACE_TASK_IDLE      0
425 #define ACE_TASK_IDENTIFY  1
426 #define ACE_TASK_READ      2
427 #define ACE_TASK_WRITE     3
428 #define ACE_FSM_NUM_TASKS  4
429
430 /* FSM state definitions */
431 #define ACE_FSM_STATE_IDLE               0
432 #define ACE_FSM_STATE_REQ_LOCK           1
433 #define ACE_FSM_STATE_WAIT_LOCK          2
434 #define ACE_FSM_STATE_WAIT_CFREADY       3
435 #define ACE_FSM_STATE_IDENTIFY_PREPARE   4
436 #define ACE_FSM_STATE_IDENTIFY_TRANSFER  5
437 #define ACE_FSM_STATE_IDENTIFY_COMPLETE  6
438 #define ACE_FSM_STATE_REQ_PREPARE        7
439 #define ACE_FSM_STATE_REQ_TRANSFER       8
440 #define ACE_FSM_STATE_REQ_COMPLETE       9
441 #define ACE_FSM_STATE_ERROR             10
442 #define ACE_FSM_NUM_STATES              11
443
444 /* Set flag to exit FSM loop and reschedule tasklet */
445 static inline void ace_fsm_yield(struct ace_device *ace)
446 {
447         dev_dbg(ace->dev, "ace_fsm_yield()\n");
448         tasklet_schedule(&ace->fsm_tasklet);
449         ace->fsm_continue_flag = 0;
450 }
451
452 /* Set flag to exit FSM loop and wait for IRQ to reschedule tasklet */
453 static inline void ace_fsm_yieldirq(struct ace_device *ace)
454 {
455         dev_dbg(ace->dev, "ace_fsm_yieldirq()\n");
456
457         if (ace->irq == NO_IRQ)
458                 /* No IRQ assigned, so need to poll */
459                 tasklet_schedule(&ace->fsm_tasklet);
460         ace->fsm_continue_flag = 0;
461 }
462
463 /* Get the next read/write request; ending requests that we don't handle */
464 struct request *ace_get_next_request(struct request_queue * q)
465 {
466         struct request *req;
467
468         while ((req = blk_peek_request(q)) != NULL) {
469                 if (req->cmd_type == REQ_TYPE_FS)
470                         break;
471                 blk_start_request(req);
472                 __blk_end_request_all(req, -EIO);
473         }
474         return req;
475 }
476
477 static void ace_fsm_dostate(struct ace_device *ace)
478 {
479         struct request *req;
480         u32 status;
481         u16 val;
482         int count;
483
484 #if defined(DEBUG)
485         dev_dbg(ace->dev, "fsm_state=%i, id_req_count=%i\n",
486                 ace->fsm_state, ace->id_req_count);
487 #endif
488
489         /* Verify that there is actually a CF in the slot. If not, then
490          * bail out back to the idle state and wake up all the waiters */
491         status = ace_in32(ace, ACE_STATUS);
492         if ((status & ACE_STATUS_CFDETECT) == 0) {
493                 ace->fsm_state = ACE_FSM_STATE_IDLE;
494                 ace->media_change = 1;
495                 set_capacity(ace->gd, 0);
496                 dev_info(ace->dev, "No CF in slot\n");
497
498                 /* Drop all in-flight and pending requests */
499                 if (ace->req) {
500                         __blk_end_request_all(ace->req, -EIO);
501                         ace->req = NULL;
502                 }
503                 while ((req = blk_fetch_request(ace->queue)) != NULL)
504                         __blk_end_request_all(req, -EIO);
505
506                 /* Drop back to IDLE state and notify waiters */
507                 ace->fsm_state = ACE_FSM_STATE_IDLE;
508                 ace->id_result = -EIO;
509                 while (ace->id_req_count) {
510                         complete(&ace->id_completion);
511                         ace->id_req_count--;
512                 }
513         }
514
515         switch (ace->fsm_state) {
516         case ACE_FSM_STATE_IDLE:
517                 /* See if there is anything to do */
518                 if (ace->id_req_count || ace_get_next_request(ace->queue)) {
519                         ace->fsm_iter_num++;
520                         ace->fsm_state = ACE_FSM_STATE_REQ_LOCK;
521                         mod_timer(&ace->stall_timer, jiffies + HZ);
522                         if (!timer_pending(&ace->stall_timer))
523                                 add_timer(&ace->stall_timer);
524                         break;
525                 }
526                 del_timer(&ace->stall_timer);
527                 ace->fsm_continue_flag = 0;
528                 break;
529
530         case ACE_FSM_STATE_REQ_LOCK:
531                 if (ace_in(ace, ACE_STATUS) & ACE_STATUS_MPULOCK) {
532                         /* Already have the lock, jump to next state */
533                         ace->fsm_state = ACE_FSM_STATE_WAIT_CFREADY;
534                         break;
535                 }
536
537                 /* Request the lock */
538                 val = ace_in(ace, ACE_CTRL);
539                 ace_out(ace, ACE_CTRL, val | ACE_CTRL_LOCKREQ);
540                 ace->fsm_state = ACE_FSM_STATE_WAIT_LOCK;
541                 break;
542
543         case ACE_FSM_STATE_WAIT_LOCK:
544                 if (ace_in(ace, ACE_STATUS) & ACE_STATUS_MPULOCK) {
545                         /* got the lock; move to next state */
546                         ace->fsm_state = ACE_FSM_STATE_WAIT_CFREADY;
547                         break;
548                 }
549
550                 /* wait a bit for the lock */
551                 ace_fsm_yield(ace);
552                 break;
553
554         case ACE_FSM_STATE_WAIT_CFREADY:
555                 status = ace_in32(ace, ACE_STATUS);
556                 if (!(status & ACE_STATUS_RDYFORCFCMD) ||
557                     (status & ACE_STATUS_CFBSY)) {
558                         /* CF card isn't ready; it needs to be polled */
559                         ace_fsm_yield(ace);
560                         break;
561                 }
562
563                 /* Device is ready for command; determine what to do next */
564                 if (ace->id_req_count)
565                         ace->fsm_state = ACE_FSM_STATE_IDENTIFY_PREPARE;
566                 else
567                         ace->fsm_state = ACE_FSM_STATE_REQ_PREPARE;
568                 break;
569
570         case ACE_FSM_STATE_IDENTIFY_PREPARE:
571                 /* Send identify command */
572                 ace->fsm_task = ACE_TASK_IDENTIFY;
573                 ace->data_ptr = ace->cf_id;
574                 ace->data_count = ACE_BUF_PER_SECTOR;
575                 ace_out(ace, ACE_SECCNTCMD, ACE_SECCNTCMD_IDENTIFY);
576
577                 /* As per datasheet, put config controller in reset */
578                 val = ace_in(ace, ACE_CTRL);
579                 ace_out(ace, ACE_CTRL, val | ACE_CTRL_CFGRESET);
580
581                 /* irq handler takes over from this point; wait for the
582                  * transfer to complete */
583                 ace->fsm_state = ACE_FSM_STATE_IDENTIFY_TRANSFER;
584                 ace_fsm_yieldirq(ace);
585                 break;
586
587         case ACE_FSM_STATE_IDENTIFY_TRANSFER:
588                 /* Check that the sysace is ready to receive data */
589                 status = ace_in32(ace, ACE_STATUS);
590                 if (status & ACE_STATUS_CFBSY) {
591                         dev_dbg(ace->dev, "CFBSY set; t=%i iter=%i dc=%i\n",
592                                 ace->fsm_task, ace->fsm_iter_num,
593                                 ace->data_count);
594                         ace_fsm_yield(ace);
595                         break;
596                 }
597                 if (!(status & ACE_STATUS_DATABUFRDY)) {
598                         ace_fsm_yield(ace);
599                         break;
600                 }
601
602                 /* Transfer the next buffer */
603                 ace->reg_ops->datain(ace);
604                 ace->data_count--;
605
606                 /* If there are still buffers to be transfers; jump out here */
607                 if (ace->data_count != 0) {
608                         ace_fsm_yieldirq(ace);
609                         break;
610                 }
611
612                 /* transfer finished; kick state machine */
613                 dev_dbg(ace->dev, "identify finished\n");
614                 ace->fsm_state = ACE_FSM_STATE_IDENTIFY_COMPLETE;
615                 break;
616
617         case ACE_FSM_STATE_IDENTIFY_COMPLETE:
618                 ace_fix_driveid(ace->cf_id);
619                 ace_dump_mem(ace->cf_id, 512);  /* Debug: Dump out disk ID */
620
621                 if (ace->data_result) {
622                         /* Error occured, disable the disk */
623                         ace->media_change = 1;
624                         set_capacity(ace->gd, 0);
625                         dev_err(ace->dev, "error fetching CF id (%i)\n",
626                                 ace->data_result);
627                 } else {
628                         ace->media_change = 0;
629
630                         /* Record disk parameters */
631                         set_capacity(ace->gd,
632                                 ata_id_u32(ace->cf_id, ATA_ID_LBA_CAPACITY));
633                         dev_info(ace->dev, "capacity: %i sectors\n",
634                                 ata_id_u32(ace->cf_id, ATA_ID_LBA_CAPACITY));
635                 }
636
637                 /* We're done, drop to IDLE state and notify waiters */
638                 ace->fsm_state = ACE_FSM_STATE_IDLE;
639                 ace->id_result = ace->data_result;
640                 while (ace->id_req_count) {
641                         complete(&ace->id_completion);
642                         ace->id_req_count--;
643                 }
644                 break;
645
646         case ACE_FSM_STATE_REQ_PREPARE:
647                 req = ace_get_next_request(ace->queue);
648                 if (!req) {
649                         ace->fsm_state = ACE_FSM_STATE_IDLE;
650                         break;
651                 }
652                 blk_start_request(req);
653
654                 /* Okay, it's a data request, set it up for transfer */
655                 dev_dbg(ace->dev,
656                         "request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
657                         (unsigned long long)blk_rq_pos(req),
658                         blk_rq_sectors(req), blk_rq_cur_sectors(req),
659                         rq_data_dir(req));
660
661                 ace->req = req;
662                 ace->data_ptr = req->buffer;
663                 ace->data_count = blk_rq_cur_sectors(req) * ACE_BUF_PER_SECTOR;
664                 ace_out32(ace, ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
665
666                 count = blk_rq_sectors(req);
667                 if (rq_data_dir(req)) {
668                         /* Kick off write request */
669                         dev_dbg(ace->dev, "write data\n");
670                         ace->fsm_task = ACE_TASK_WRITE;
671                         ace_out(ace, ACE_SECCNTCMD,
672                                 count | ACE_SECCNTCMD_WRITE_DATA);
673                 } else {
674                         /* Kick off read request */
675                         dev_dbg(ace->dev, "read data\n");
676                         ace->fsm_task = ACE_TASK_READ;
677                         ace_out(ace, ACE_SECCNTCMD,
678                                 count | ACE_SECCNTCMD_READ_DATA);
679                 }
680
681                 /* As per datasheet, put config controller in reset */
682                 val = ace_in(ace, ACE_CTRL);
683                 ace_out(ace, ACE_CTRL, val | ACE_CTRL_CFGRESET);
684
685                 /* Move to the transfer state.  The systemace will raise
686                  * an interrupt once there is something to do
687                  */
688                 ace->fsm_state = ACE_FSM_STATE_REQ_TRANSFER;
689                 if (ace->fsm_task == ACE_TASK_READ)
690                         ace_fsm_yieldirq(ace);  /* wait for data ready */
691                 break;
692
693         case ACE_FSM_STATE_REQ_TRANSFER:
694                 /* Check that the sysace is ready to receive data */
695                 status = ace_in32(ace, ACE_STATUS);
696                 if (status & ACE_STATUS_CFBSY) {
697                         dev_dbg(ace->dev,
698                                 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
699                                 ace->fsm_task, ace->fsm_iter_num,
700                                 blk_rq_cur_sectors(ace->req) * 16,
701                                 ace->data_count, ace->in_irq);
702                         ace_fsm_yield(ace);     /* need to poll CFBSY bit */
703                         break;
704                 }
705                 if (!(status & ACE_STATUS_DATABUFRDY)) {
706                         dev_dbg(ace->dev,
707                                 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
708                                 ace->fsm_task, ace->fsm_iter_num,
709                                 blk_rq_cur_sectors(ace->req) * 16,
710                                 ace->data_count, ace->in_irq);
711                         ace_fsm_yieldirq(ace);
712                         break;
713                 }
714
715                 /* Transfer the next buffer */
716                 if (ace->fsm_task == ACE_TASK_WRITE)
717                         ace->reg_ops->dataout(ace);
718                 else
719                         ace->reg_ops->datain(ace);
720                 ace->data_count--;
721
722                 /* If there are still buffers to be transfers; jump out here */
723                 if (ace->data_count != 0) {
724                         ace_fsm_yieldirq(ace);
725                         break;
726                 }
727
728                 /* bio finished; is there another one? */
729                 if (__blk_end_request_cur(ace->req, 0)) {
730                         /* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
731                          *      blk_rq_sectors(ace->req),
732                          *      blk_rq_cur_sectors(ace->req));
733                          */
734                         ace->data_ptr = ace->req->buffer;
735                         ace->data_count = blk_rq_cur_sectors(ace->req) * 16;
736                         ace_fsm_yieldirq(ace);
737                         break;
738                 }
739
740                 ace->fsm_state = ACE_FSM_STATE_REQ_COMPLETE;
741                 break;
742
743         case ACE_FSM_STATE_REQ_COMPLETE:
744                 ace->req = NULL;
745
746                 /* Finished request; go to idle state */
747                 ace->fsm_state = ACE_FSM_STATE_IDLE;
748                 break;
749
750         default:
751                 ace->fsm_state = ACE_FSM_STATE_IDLE;
752                 break;
753         }
754 }
755
756 static void ace_fsm_tasklet(unsigned long data)
757 {
758         struct ace_device *ace = (void *)data;
759         unsigned long flags;
760
761         spin_lock_irqsave(&ace->lock, flags);
762
763         /* Loop over state machine until told to stop */
764         ace->fsm_continue_flag = 1;
765         while (ace->fsm_continue_flag)
766                 ace_fsm_dostate(ace);
767
768         spin_unlock_irqrestore(&ace->lock, flags);
769 }
770
771 static void ace_stall_timer(unsigned long data)
772 {
773         struct ace_device *ace = (void *)data;
774         unsigned long flags;
775
776         dev_warn(ace->dev,
777                  "kicking stalled fsm; state=%i task=%i iter=%i dc=%i\n",
778                  ace->fsm_state, ace->fsm_task, ace->fsm_iter_num,
779                  ace->data_count);
780         spin_lock_irqsave(&ace->lock, flags);
781
782         /* Rearm the stall timer *before* entering FSM (which may then
783          * delete the timer) */
784         mod_timer(&ace->stall_timer, jiffies + HZ);
785
786         /* Loop over state machine until told to stop */
787         ace->fsm_continue_flag = 1;
788         while (ace->fsm_continue_flag)
789                 ace_fsm_dostate(ace);
790
791         spin_unlock_irqrestore(&ace->lock, flags);
792 }
793
794 /* ---------------------------------------------------------------------
795  * Interrupt handling routines
796  */
797 static int ace_interrupt_checkstate(struct ace_device *ace)
798 {
799         u32 sreg = ace_in32(ace, ACE_STATUS);
800         u16 creg = ace_in(ace, ACE_CTRL);
801
802         /* Check for error occurance */
803         if ((sreg & (ACE_STATUS_CFGERROR | ACE_STATUS_CFCERROR)) &&
804             (creg & ACE_CTRL_ERRORIRQ)) {
805                 dev_err(ace->dev, "transfer failure\n");
806                 ace_dump_regs(ace);
807                 return -EIO;
808         }
809
810         return 0;
811 }
812
813 static irqreturn_t ace_interrupt(int irq, void *dev_id)
814 {
815         u16 creg;
816         struct ace_device *ace = dev_id;
817
818         /* be safe and get the lock */
819         spin_lock(&ace->lock);
820         ace->in_irq = 1;
821
822         /* clear the interrupt */
823         creg = ace_in(ace, ACE_CTRL);
824         ace_out(ace, ACE_CTRL, creg | ACE_CTRL_RESETIRQ);
825         ace_out(ace, ACE_CTRL, creg);
826
827         /* check for IO failures */
828         if (ace_interrupt_checkstate(ace))
829                 ace->data_result = -EIO;
830
831         if (ace->fsm_task == 0) {
832                 dev_err(ace->dev,
833                         "spurious irq; stat=%.8x ctrl=%.8x cmd=%.4x\n",
834                         ace_in32(ace, ACE_STATUS), ace_in32(ace, ACE_CTRL),
835                         ace_in(ace, ACE_SECCNTCMD));
836                 dev_err(ace->dev, "fsm_task=%i fsm_state=%i data_count=%i\n",
837                         ace->fsm_task, ace->fsm_state, ace->data_count);
838         }
839
840         /* Loop over state machine until told to stop */
841         ace->fsm_continue_flag = 1;
842         while (ace->fsm_continue_flag)
843                 ace_fsm_dostate(ace);
844
845         /* done with interrupt; drop the lock */
846         ace->in_irq = 0;
847         spin_unlock(&ace->lock);
848
849         return IRQ_HANDLED;
850 }
851
852 /* ---------------------------------------------------------------------
853  * Block ops
854  */
855 static void ace_request(struct request_queue * q)
856 {
857         struct request *req;
858         struct ace_device *ace;
859
860         req = ace_get_next_request(q);
861
862         if (req) {
863                 ace = req->rq_disk->private_data;
864                 tasklet_schedule(&ace->fsm_tasklet);
865         }
866 }
867
868 static int ace_media_changed(struct gendisk *gd)
869 {
870         struct ace_device *ace = gd->private_data;
871         dev_dbg(ace->dev, "ace_media_changed(): %i\n", ace->media_change);
872
873         return ace->media_change;
874 }
875
876 static int ace_revalidate_disk(struct gendisk *gd)
877 {
878         struct ace_device *ace = gd->private_data;
879         unsigned long flags;
880
881         dev_dbg(ace->dev, "ace_revalidate_disk()\n");
882
883         if (ace->media_change) {
884                 dev_dbg(ace->dev, "requesting cf id and scheduling tasklet\n");
885
886                 spin_lock_irqsave(&ace->lock, flags);
887                 ace->id_req_count++;
888                 spin_unlock_irqrestore(&ace->lock, flags);
889
890                 tasklet_schedule(&ace->fsm_tasklet);
891                 wait_for_completion(&ace->id_completion);
892         }
893
894         dev_dbg(ace->dev, "revalidate complete\n");
895         return ace->id_result;
896 }
897
898 static int ace_open(struct block_device *bdev, fmode_t mode)
899 {
900         struct ace_device *ace = bdev->bd_disk->private_data;
901         unsigned long flags;
902
903         dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
904
905         lock_kernel();
906         spin_lock_irqsave(&ace->lock, flags);
907         ace->users++;
908         spin_unlock_irqrestore(&ace->lock, flags);
909
910         check_disk_change(bdev);
911         unlock_kernel();
912
913         return 0;
914 }
915
916 static int ace_release(struct gendisk *disk, fmode_t mode)
917 {
918         struct ace_device *ace = disk->private_data;
919         unsigned long flags;
920         u16 val;
921
922         dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
923
924         lock_kernel();
925         spin_lock_irqsave(&ace->lock, flags);
926         ace->users--;
927         if (ace->users == 0) {
928                 val = ace_in(ace, ACE_CTRL);
929                 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
930         }
931         spin_unlock_irqrestore(&ace->lock, flags);
932         unlock_kernel();
933         return 0;
934 }
935
936 static int ace_getgeo(struct block_device *bdev, struct hd_geometry *geo)
937 {
938         struct ace_device *ace = bdev->bd_disk->private_data;
939         u16 *cf_id = ace->cf_id;
940
941         dev_dbg(ace->dev, "ace_getgeo()\n");
942
943         geo->heads      = cf_id[ATA_ID_HEADS];
944         geo->sectors    = cf_id[ATA_ID_SECTORS];
945         geo->cylinders  = cf_id[ATA_ID_CYLS];
946
947         return 0;
948 }
949
950 static const struct block_device_operations ace_fops = {
951         .owner = THIS_MODULE,
952         .open = ace_open,
953         .release = ace_release,
954         .media_changed = ace_media_changed,
955         .revalidate_disk = ace_revalidate_disk,
956         .getgeo = ace_getgeo,
957 };
958
959 /* --------------------------------------------------------------------
960  * SystemACE device setup/teardown code
961  */
962 static int __devinit ace_setup(struct ace_device *ace)
963 {
964         u16 version;
965         u16 val;
966         int rc;
967
968         dev_dbg(ace->dev, "ace_setup(ace=0x%p)\n", ace);
969         dev_dbg(ace->dev, "physaddr=0x%llx irq=%i\n",
970                 (unsigned long long)ace->physaddr, ace->irq);
971
972         spin_lock_init(&ace->lock);
973         init_completion(&ace->id_completion);
974
975         /*
976          * Map the device
977          */
978         ace->baseaddr = ioremap(ace->physaddr, 0x80);
979         if (!ace->baseaddr)
980                 goto err_ioremap;
981
982         /*
983          * Initialize the state machine tasklet and stall timer
984          */
985         tasklet_init(&ace->fsm_tasklet, ace_fsm_tasklet, (unsigned long)ace);
986         setup_timer(&ace->stall_timer, ace_stall_timer, (unsigned long)ace);
987
988         /*
989          * Initialize the request queue
990          */
991         ace->queue = blk_init_queue(ace_request, &ace->lock);
992         if (ace->queue == NULL)
993                 goto err_blk_initq;
994         blk_queue_logical_block_size(ace->queue, 512);
995
996         /*
997          * Allocate and initialize GD structure
998          */
999         ace->gd = alloc_disk(ACE_NUM_MINORS);
1000         if (!ace->gd)
1001                 goto err_alloc_disk;
1002
1003         ace->gd->major = ace_major;
1004         ace->gd->first_minor = ace->id * ACE_NUM_MINORS;
1005         ace->gd->fops = &ace_fops;
1006         ace->gd->queue = ace->queue;
1007         ace->gd->private_data = ace;
1008         snprintf(ace->gd->disk_name, 32, "xs%c", ace->id + 'a');
1009
1010         /* set bus width */
1011         if (ace->bus_width == ACE_BUS_WIDTH_16) {
1012                 /* 0x0101 should work regardless of endianess */
1013                 ace_out_le16(ace, ACE_BUSMODE, 0x0101);
1014
1015                 /* read it back to determine endianess */
1016                 if (ace_in_le16(ace, ACE_BUSMODE) == 0x0001)
1017                         ace->reg_ops = &ace_reg_le16_ops;
1018                 else
1019                         ace->reg_ops = &ace_reg_be16_ops;
1020         } else {
1021                 ace_out_8(ace, ACE_BUSMODE, 0x00);
1022                 ace->reg_ops = &ace_reg_8_ops;
1023         }
1024
1025         /* Make sure version register is sane */
1026         version = ace_in(ace, ACE_VERSION);
1027         if ((version == 0) || (version == 0xFFFF))
1028                 goto err_read;
1029
1030         /* Put sysace in a sane state by clearing most control reg bits */
1031         ace_out(ace, ACE_CTRL, ACE_CTRL_FORCECFGMODE |
1032                 ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ);
1033
1034         /* Now we can hook up the irq handler */
1035         if (ace->irq != NO_IRQ) {
1036                 rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
1037                 if (rc) {
1038                         /* Failure - fall back to polled mode */
1039                         dev_err(ace->dev, "request_irq failed\n");
1040                         ace->irq = NO_IRQ;
1041                 }
1042         }
1043
1044         /* Enable interrupts */
1045         val = ace_in(ace, ACE_CTRL);
1046         val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ;
1047         ace_out(ace, ACE_CTRL, val);
1048
1049         /* Print the identification */
1050         dev_info(ace->dev, "Xilinx SystemACE revision %i.%i.%i\n",
1051                  (version >> 12) & 0xf, (version >> 8) & 0x0f, version & 0xff);
1052         dev_dbg(ace->dev, "physaddr 0x%llx, mapped to 0x%p, irq=%i\n",
1053                 (unsigned long long) ace->physaddr, ace->baseaddr, ace->irq);
1054
1055         ace->media_change = 1;
1056         ace_revalidate_disk(ace->gd);
1057
1058         /* Make the sysace device 'live' */
1059         add_disk(ace->gd);
1060
1061         return 0;
1062
1063 err_read:
1064         put_disk(ace->gd);
1065 err_alloc_disk:
1066         blk_cleanup_queue(ace->queue);
1067 err_blk_initq:
1068         iounmap(ace->baseaddr);
1069 err_ioremap:
1070         dev_info(ace->dev, "xsysace: error initializing device at 0x%llx\n",
1071                  (unsigned long long) ace->physaddr);
1072         return -ENOMEM;
1073 }
1074
1075 static void __devexit ace_teardown(struct ace_device *ace)
1076 {
1077         if (ace->gd) {
1078                 del_gendisk(ace->gd);
1079                 put_disk(ace->gd);
1080         }
1081
1082         if (ace->queue)
1083                 blk_cleanup_queue(ace->queue);
1084
1085         tasklet_kill(&ace->fsm_tasklet);
1086
1087         if (ace->irq != NO_IRQ)
1088                 free_irq(ace->irq, ace);
1089
1090         iounmap(ace->baseaddr);
1091 }
1092
1093 static int __devinit
1094 ace_alloc(struct device *dev, int id, resource_size_t physaddr,
1095           int irq, int bus_width)
1096 {
1097         struct ace_device *ace;
1098         int rc;
1099         dev_dbg(dev, "ace_alloc(%p)\n", dev);
1100
1101         if (!physaddr) {
1102                 rc = -ENODEV;
1103                 goto err_noreg;
1104         }
1105
1106         /* Allocate and initialize the ace device structure */
1107         ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL);
1108         if (!ace) {
1109                 rc = -ENOMEM;
1110                 goto err_alloc;
1111         }
1112
1113         ace->dev = dev;
1114         ace->id = id;
1115         ace->physaddr = physaddr;
1116         ace->irq = irq;
1117         ace->bus_width = bus_width;
1118
1119         /* Call the setup code */
1120         rc = ace_setup(ace);
1121         if (rc)
1122                 goto err_setup;
1123
1124         dev_set_drvdata(dev, ace);
1125         return 0;
1126
1127 err_setup:
1128         dev_set_drvdata(dev, NULL);
1129         kfree(ace);
1130 err_alloc:
1131 err_noreg:
1132         dev_err(dev, "could not initialize device, err=%i\n", rc);
1133         return rc;
1134 }
1135
1136 static void __devexit ace_free(struct device *dev)
1137 {
1138         struct ace_device *ace = dev_get_drvdata(dev);
1139         dev_dbg(dev, "ace_free(%p)\n", dev);
1140
1141         if (ace) {
1142                 ace_teardown(ace);
1143                 dev_set_drvdata(dev, NULL);
1144                 kfree(ace);
1145         }
1146 }
1147
1148 /* ---------------------------------------------------------------------
1149  * Platform Bus Support
1150  */
1151
1152 static int __devinit ace_probe(struct platform_device *dev)
1153 {
1154         resource_size_t physaddr = 0;
1155         int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */
1156         int id = dev->id;
1157         int irq = NO_IRQ;
1158         int i;
1159
1160         dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
1161
1162         for (i = 0; i < dev->num_resources; i++) {
1163                 if (dev->resource[i].flags & IORESOURCE_MEM)
1164                         physaddr = dev->resource[i].start;
1165                 if (dev->resource[i].flags & IORESOURCE_IRQ)
1166                         irq = dev->resource[i].start;
1167         }
1168
1169         /* Call the bus-independant setup code */
1170         return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);
1171 }
1172
1173 /*
1174  * Platform bus remove() method
1175  */
1176 static int __devexit ace_remove(struct platform_device *dev)
1177 {
1178         ace_free(&dev->dev);
1179         return 0;
1180 }
1181
1182 static struct platform_driver ace_platform_driver = {
1183         .probe = ace_probe,
1184         .remove = __devexit_p(ace_remove),
1185         .driver = {
1186                 .owner = THIS_MODULE,
1187                 .name = "xsysace",
1188         },
1189 };
1190
1191 /* ---------------------------------------------------------------------
1192  * OF_Platform Bus Support
1193  */
1194
1195 #if defined(CONFIG_OF)
1196 static int __devinit
1197 ace_of_probe(struct platform_device *op, const struct of_device_id *match)
1198 {
1199         struct resource res;
1200         resource_size_t physaddr;
1201         const u32 *id;
1202         int irq, bus_width, rc;
1203
1204         dev_dbg(&op->dev, "ace_of_probe(%p, %p)\n", op, match);
1205
1206         /* device id */
1207         id = of_get_property(op->dev.of_node, "port-number", NULL);
1208
1209         /* physaddr */
1210         rc = of_address_to_resource(op->dev.of_node, 0, &res);
1211         if (rc) {
1212                 dev_err(&op->dev, "invalid address\n");
1213                 return rc;
1214         }
1215         physaddr = res.start;
1216
1217         /* irq */
1218         irq = irq_of_parse_and_map(op->dev.of_node, 0);
1219
1220         /* bus width */
1221         bus_width = ACE_BUS_WIDTH_16;
1222         if (of_find_property(op->dev.of_node, "8-bit", NULL))
1223                 bus_width = ACE_BUS_WIDTH_8;
1224
1225         /* Call the bus-independant setup code */
1226         return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width);
1227 }
1228
1229 static int __devexit ace_of_remove(struct platform_device *op)
1230 {
1231         ace_free(&op->dev);
1232         return 0;
1233 }
1234
1235 /* Match table for of_platform binding */
1236 static const struct of_device_id ace_of_match[] __devinitconst = {
1237         { .compatible = "xlnx,opb-sysace-1.00.b", },
1238         { .compatible = "xlnx,opb-sysace-1.00.c", },
1239         { .compatible = "xlnx,xps-sysace-1.00.a", },
1240         { .compatible = "xlnx,sysace", },
1241         {},
1242 };
1243 MODULE_DEVICE_TABLE(of, ace_of_match);
1244
1245 static struct of_platform_driver ace_of_driver = {
1246         .probe = ace_of_probe,
1247         .remove = __devexit_p(ace_of_remove),
1248         .driver = {
1249                 .name = "xsysace",
1250                 .owner = THIS_MODULE,
1251                 .of_match_table = ace_of_match,
1252         },
1253 };
1254
1255 /* Registration helpers to keep the number of #ifdefs to a minimum */
1256 static inline int __init ace_of_register(void)
1257 {
1258         pr_debug("xsysace: registering OF binding\n");
1259         return of_register_platform_driver(&ace_of_driver);
1260 }
1261
1262 static inline void __exit ace_of_unregister(void)
1263 {
1264         of_unregister_platform_driver(&ace_of_driver);
1265 }
1266 #else /* CONFIG_OF */
1267 /* CONFIG_OF not enabled; do nothing helpers */
1268 static inline int __init ace_of_register(void) { return 0; }
1269 static inline void __exit ace_of_unregister(void) { }
1270 #endif /* CONFIG_OF */
1271
1272 /* ---------------------------------------------------------------------
1273  * Module init/exit routines
1274  */
1275 static int __init ace_init(void)
1276 {
1277         int rc;
1278
1279         ace_major = register_blkdev(ace_major, "xsysace");
1280         if (ace_major <= 0) {
1281                 rc = -ENOMEM;
1282                 goto err_blk;
1283         }
1284
1285         rc = ace_of_register();
1286         if (rc)
1287                 goto err_of;
1288
1289         pr_debug("xsysace: registering platform binding\n");
1290         rc = platform_driver_register(&ace_platform_driver);
1291         if (rc)
1292                 goto err_plat;
1293
1294         pr_info("Xilinx SystemACE device driver, major=%i\n", ace_major);
1295         return 0;
1296
1297 err_plat:
1298         ace_of_unregister();
1299 err_of:
1300         unregister_blkdev(ace_major, "xsysace");
1301 err_blk:
1302         printk(KERN_ERR "xsysace: registration failed; err=%i\n", rc);
1303         return rc;
1304 }
1305
1306 static void __exit ace_exit(void)
1307 {
1308         pr_debug("Unregistering Xilinx SystemACE driver\n");
1309         platform_driver_unregister(&ace_platform_driver);
1310         ace_of_unregister();
1311         unregister_blkdev(ace_major, "xsysace");
1312 }
1313
1314 module_init(ace_init);
1315 module_exit(ace_exit);