xsysace.c 33 KB

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