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