Linux 4.16.11
[linux/fpc-iii.git] / drivers / fsi / fsi-core.c
blobe318bf8c623c66e33201d1592dba5a9b86f762c7
1 /*
2 * FSI core driver
4 * Copyright (C) IBM Corporation 2016
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/crc4.h>
17 #include <linux/device.h>
18 #include <linux/fsi.h>
19 #include <linux/idr.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
22 #include <linux/bitops.h>
24 #include "fsi-master.h"
26 #define CREATE_TRACE_POINTS
27 #include <trace/events/fsi.h>
29 #define FSI_SLAVE_CONF_NEXT_MASK GENMASK(31, 31)
30 #define FSI_SLAVE_CONF_SLOTS_MASK GENMASK(23, 16)
31 #define FSI_SLAVE_CONF_SLOTS_SHIFT 16
32 #define FSI_SLAVE_CONF_VERSION_MASK GENMASK(15, 12)
33 #define FSI_SLAVE_CONF_VERSION_SHIFT 12
34 #define FSI_SLAVE_CONF_TYPE_MASK GENMASK(11, 4)
35 #define FSI_SLAVE_CONF_TYPE_SHIFT 4
36 #define FSI_SLAVE_CONF_CRC_SHIFT 4
37 #define FSI_SLAVE_CONF_CRC_MASK GENMASK(3, 0)
38 #define FSI_SLAVE_CONF_DATA_BITS 28
40 #define FSI_PEEK_BASE 0x410
42 static const int engine_page_size = 0x400;
44 #define FSI_SLAVE_BASE 0x800
47 * FSI slave engine control register offsets
49 #define FSI_SMODE 0x0 /* R/W: Mode register */
50 #define FSI_SISC 0x8 /* R/W: Interrupt condition */
51 #define FSI_SSTAT 0x14 /* R : Slave status */
52 #define FSI_LLMODE 0x100 /* R/W: Link layer mode register */
55 * SMODE fields
57 #define FSI_SMODE_WSC 0x80000000 /* Warm start done */
58 #define FSI_SMODE_ECRC 0x20000000 /* Hw CRC check */
59 #define FSI_SMODE_SID_SHIFT 24 /* ID shift */
60 #define FSI_SMODE_SID_MASK 3 /* ID Mask */
61 #define FSI_SMODE_ED_SHIFT 20 /* Echo delay shift */
62 #define FSI_SMODE_ED_MASK 0xf /* Echo delay mask */
63 #define FSI_SMODE_SD_SHIFT 16 /* Send delay shift */
64 #define FSI_SMODE_SD_MASK 0xf /* Send delay mask */
65 #define FSI_SMODE_LBCRR_SHIFT 8 /* Clk ratio shift */
66 #define FSI_SMODE_LBCRR_MASK 0xf /* Clk ratio mask */
69 * LLMODE fields
71 #define FSI_LLMODE_ASYNC 0x1
73 #define FSI_SLAVE_SIZE_23b 0x800000
75 static DEFINE_IDA(master_ida);
77 struct fsi_slave {
78 struct device dev;
79 struct fsi_master *master;
80 int id;
81 int link;
82 uint32_t size; /* size of slave address space */
85 #define to_fsi_master(d) container_of(d, struct fsi_master, dev)
86 #define to_fsi_slave(d) container_of(d, struct fsi_slave, dev)
88 static const int slave_retries = 2;
89 static int discard_errors;
91 static int fsi_master_read(struct fsi_master *master, int link,
92 uint8_t slave_id, uint32_t addr, void *val, size_t size);
93 static int fsi_master_write(struct fsi_master *master, int link,
94 uint8_t slave_id, uint32_t addr, const void *val, size_t size);
95 static int fsi_master_break(struct fsi_master *master, int link);
98 * fsi_device_read() / fsi_device_write() / fsi_device_peek()
100 * FSI endpoint-device support
102 * Read / write / peek accessors for a client
104 * Parameters:
105 * dev: Structure passed to FSI client device drivers on probe().
106 * addr: FSI address of given device. Client should pass in its base address
107 * plus desired offset to access its register space.
108 * val: For read/peek this is the value read at the specified address. For
109 * write this is value to write to the specified address.
110 * The data in val must be FSI bus endian (big endian).
111 * size: Size in bytes of the operation. Sizes supported are 1, 2 and 4 bytes.
112 * Addresses must be aligned on size boundaries or an error will result.
114 int fsi_device_read(struct fsi_device *dev, uint32_t addr, void *val,
115 size_t size)
117 if (addr > dev->size || size > dev->size || addr > dev->size - size)
118 return -EINVAL;
120 return fsi_slave_read(dev->slave, dev->addr + addr, val, size);
122 EXPORT_SYMBOL_GPL(fsi_device_read);
124 int fsi_device_write(struct fsi_device *dev, uint32_t addr, const void *val,
125 size_t size)
127 if (addr > dev->size || size > dev->size || addr > dev->size - size)
128 return -EINVAL;
130 return fsi_slave_write(dev->slave, dev->addr + addr, val, size);
132 EXPORT_SYMBOL_GPL(fsi_device_write);
134 int fsi_device_peek(struct fsi_device *dev, void *val)
136 uint32_t addr = FSI_PEEK_BASE + ((dev->unit - 2) * sizeof(uint32_t));
138 return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t));
141 static void fsi_device_release(struct device *_device)
143 struct fsi_device *device = to_fsi_dev(_device);
145 kfree(device);
148 static struct fsi_device *fsi_create_device(struct fsi_slave *slave)
150 struct fsi_device *dev;
152 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
153 if (!dev)
154 return NULL;
156 dev->dev.parent = &slave->dev;
157 dev->dev.bus = &fsi_bus_type;
158 dev->dev.release = fsi_device_release;
160 return dev;
163 /* FSI slave support */
164 static int fsi_slave_calc_addr(struct fsi_slave *slave, uint32_t *addrp,
165 uint8_t *idp)
167 uint32_t addr = *addrp;
168 uint8_t id = *idp;
170 if (addr > slave->size)
171 return -EINVAL;
173 /* For 23 bit addressing, we encode the extra two bits in the slave
174 * id (and the slave's actual ID needs to be 0).
176 if (addr > 0x1fffff) {
177 if (slave->id != 0)
178 return -EINVAL;
179 id = (addr >> 21) & 0x3;
180 addr &= 0x1fffff;
183 *addrp = addr;
184 *idp = id;
185 return 0;
188 static int fsi_slave_report_and_clear_errors(struct fsi_slave *slave)
190 struct fsi_master *master = slave->master;
191 uint32_t irq, stat;
192 int rc, link;
193 uint8_t id;
195 link = slave->link;
196 id = slave->id;
198 rc = fsi_master_read(master, link, id, FSI_SLAVE_BASE + FSI_SISC,
199 &irq, sizeof(irq));
200 if (rc)
201 return rc;
203 rc = fsi_master_read(master, link, id, FSI_SLAVE_BASE + FSI_SSTAT,
204 &stat, sizeof(stat));
205 if (rc)
206 return rc;
208 dev_info(&slave->dev, "status: 0x%08x, sisc: 0x%08x\n",
209 be32_to_cpu(stat), be32_to_cpu(irq));
211 /* clear interrupts */
212 return fsi_master_write(master, link, id, FSI_SLAVE_BASE + FSI_SISC,
213 &irq, sizeof(irq));
216 static int fsi_slave_set_smode(struct fsi_master *master, int link, int id);
218 static int fsi_slave_handle_error(struct fsi_slave *slave, bool write,
219 uint32_t addr, size_t size)
221 struct fsi_master *master = slave->master;
222 int rc, link;
223 uint32_t reg;
224 uint8_t id;
226 if (discard_errors)
227 return -1;
229 link = slave->link;
230 id = slave->id;
232 dev_dbg(&slave->dev, "handling error on %s to 0x%08x[%zd]",
233 write ? "write" : "read", addr, size);
235 /* try a simple clear of error conditions, which may fail if we've lost
236 * communication with the slave
238 rc = fsi_slave_report_and_clear_errors(slave);
239 if (!rc)
240 return 0;
242 /* send a TERM and retry */
243 if (master->term) {
244 rc = master->term(master, link, id);
245 if (!rc) {
246 rc = fsi_master_read(master, link, id, 0,
247 &reg, sizeof(reg));
248 if (!rc)
249 rc = fsi_slave_report_and_clear_errors(slave);
250 if (!rc)
251 return 0;
255 /* getting serious, reset the slave via BREAK */
256 rc = fsi_master_break(master, link);
257 if (rc)
258 return rc;
260 rc = fsi_slave_set_smode(master, link, id);
261 if (rc)
262 return rc;
264 return fsi_slave_report_and_clear_errors(slave);
267 int fsi_slave_read(struct fsi_slave *slave, uint32_t addr,
268 void *val, size_t size)
270 uint8_t id = slave->id;
271 int rc, err_rc, i;
273 rc = fsi_slave_calc_addr(slave, &addr, &id);
274 if (rc)
275 return rc;
277 for (i = 0; i < slave_retries; i++) {
278 rc = fsi_master_read(slave->master, slave->link,
279 id, addr, val, size);
280 if (!rc)
281 break;
283 err_rc = fsi_slave_handle_error(slave, false, addr, size);
284 if (err_rc)
285 break;
288 return rc;
290 EXPORT_SYMBOL_GPL(fsi_slave_read);
292 int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,
293 const void *val, size_t size)
295 uint8_t id = slave->id;
296 int rc, err_rc, i;
298 rc = fsi_slave_calc_addr(slave, &addr, &id);
299 if (rc)
300 return rc;
302 for (i = 0; i < slave_retries; i++) {
303 rc = fsi_master_write(slave->master, slave->link,
304 id, addr, val, size);
305 if (!rc)
306 break;
308 err_rc = fsi_slave_handle_error(slave, true, addr, size);
309 if (err_rc)
310 break;
313 return rc;
315 EXPORT_SYMBOL_GPL(fsi_slave_write);
317 extern int fsi_slave_claim_range(struct fsi_slave *slave,
318 uint32_t addr, uint32_t size)
320 if (addr + size < addr)
321 return -EINVAL;
323 if (addr + size > slave->size)
324 return -EINVAL;
326 /* todo: check for overlapping claims */
327 return 0;
329 EXPORT_SYMBOL_GPL(fsi_slave_claim_range);
331 extern void fsi_slave_release_range(struct fsi_slave *slave,
332 uint32_t addr, uint32_t size)
335 EXPORT_SYMBOL_GPL(fsi_slave_release_range);
337 static int fsi_slave_scan(struct fsi_slave *slave)
339 uint32_t engine_addr;
340 uint32_t conf;
341 int rc, i;
344 * scan engines
346 * We keep the peek mode and slave engines for the core; so start
347 * at the third slot in the configuration table. We also need to
348 * skip the chip ID entry at the start of the address space.
350 engine_addr = engine_page_size * 3;
351 for (i = 2; i < engine_page_size / sizeof(uint32_t); i++) {
352 uint8_t slots, version, type, crc;
353 struct fsi_device *dev;
355 rc = fsi_slave_read(slave, (i + 1) * sizeof(conf),
356 &conf, sizeof(conf));
357 if (rc) {
358 dev_warn(&slave->dev,
359 "error reading slave registers\n");
360 return -1;
362 conf = be32_to_cpu(conf);
364 crc = crc4(0, conf, 32);
365 if (crc) {
366 dev_warn(&slave->dev,
367 "crc error in slave register at 0x%04x\n",
369 return -1;
372 slots = (conf & FSI_SLAVE_CONF_SLOTS_MASK)
373 >> FSI_SLAVE_CONF_SLOTS_SHIFT;
374 version = (conf & FSI_SLAVE_CONF_VERSION_MASK)
375 >> FSI_SLAVE_CONF_VERSION_SHIFT;
376 type = (conf & FSI_SLAVE_CONF_TYPE_MASK)
377 >> FSI_SLAVE_CONF_TYPE_SHIFT;
380 * Unused address areas are marked by a zero type value; this
381 * skips the defined address areas
383 if (type != 0 && slots != 0) {
385 /* create device */
386 dev = fsi_create_device(slave);
387 if (!dev)
388 return -ENOMEM;
390 dev->slave = slave;
391 dev->engine_type = type;
392 dev->version = version;
393 dev->unit = i;
394 dev->addr = engine_addr;
395 dev->size = slots * engine_page_size;
397 dev_dbg(&slave->dev,
398 "engine[%i]: type %x, version %x, addr %x size %x\n",
399 dev->unit, dev->engine_type, version,
400 dev->addr, dev->size);
402 dev_set_name(&dev->dev, "%02x:%02x:%02x:%02x",
403 slave->master->idx, slave->link,
404 slave->id, i - 2);
406 rc = device_register(&dev->dev);
407 if (rc) {
408 dev_warn(&slave->dev, "add failed: %d\n", rc);
409 put_device(&dev->dev);
413 engine_addr += slots * engine_page_size;
415 if (!(conf & FSI_SLAVE_CONF_NEXT_MASK))
416 break;
419 return 0;
422 static ssize_t fsi_slave_sysfs_raw_read(struct file *file,
423 struct kobject *kobj, struct bin_attribute *attr, char *buf,
424 loff_t off, size_t count)
426 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj));
427 size_t total_len, read_len;
428 int rc;
430 if (off < 0)
431 return -EINVAL;
433 if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
434 return -EINVAL;
436 for (total_len = 0; total_len < count; total_len += read_len) {
437 read_len = min_t(size_t, count, 4);
438 read_len -= off & 0x3;
440 rc = fsi_slave_read(slave, off, buf + total_len, read_len);
441 if (rc)
442 return rc;
444 off += read_len;
447 return count;
450 static ssize_t fsi_slave_sysfs_raw_write(struct file *file,
451 struct kobject *kobj, struct bin_attribute *attr,
452 char *buf, loff_t off, size_t count)
454 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj));
455 size_t total_len, write_len;
456 int rc;
458 if (off < 0)
459 return -EINVAL;
461 if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
462 return -EINVAL;
464 for (total_len = 0; total_len < count; total_len += write_len) {
465 write_len = min_t(size_t, count, 4);
466 write_len -= off & 0x3;
468 rc = fsi_slave_write(slave, off, buf + total_len, write_len);
469 if (rc)
470 return rc;
472 off += write_len;
475 return count;
478 static const struct bin_attribute fsi_slave_raw_attr = {
479 .attr = {
480 .name = "raw",
481 .mode = 0600,
483 .size = 0,
484 .read = fsi_slave_sysfs_raw_read,
485 .write = fsi_slave_sysfs_raw_write,
488 static ssize_t fsi_slave_sysfs_term_write(struct file *file,
489 struct kobject *kobj, struct bin_attribute *attr,
490 char *buf, loff_t off, size_t count)
492 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj));
493 struct fsi_master *master = slave->master;
495 if (!master->term)
496 return -ENODEV;
498 master->term(master, slave->link, slave->id);
499 return count;
502 static const struct bin_attribute fsi_slave_term_attr = {
503 .attr = {
504 .name = "term",
505 .mode = 0200,
507 .size = 0,
508 .write = fsi_slave_sysfs_term_write,
511 /* Encode slave local bus echo delay */
512 static inline uint32_t fsi_smode_echodly(int x)
514 return (x & FSI_SMODE_ED_MASK) << FSI_SMODE_ED_SHIFT;
517 /* Encode slave local bus send delay */
518 static inline uint32_t fsi_smode_senddly(int x)
520 return (x & FSI_SMODE_SD_MASK) << FSI_SMODE_SD_SHIFT;
523 /* Encode slave local bus clock rate ratio */
524 static inline uint32_t fsi_smode_lbcrr(int x)
526 return (x & FSI_SMODE_LBCRR_MASK) << FSI_SMODE_LBCRR_SHIFT;
529 /* Encode slave ID */
530 static inline uint32_t fsi_smode_sid(int x)
532 return (x & FSI_SMODE_SID_MASK) << FSI_SMODE_SID_SHIFT;
535 static uint32_t fsi_slave_smode(int id)
537 return FSI_SMODE_WSC | FSI_SMODE_ECRC
538 | fsi_smode_sid(id)
539 | fsi_smode_echodly(0xf) | fsi_smode_senddly(0xf)
540 | fsi_smode_lbcrr(0x8);
543 static int fsi_slave_set_smode(struct fsi_master *master, int link, int id)
545 uint32_t smode;
547 /* set our smode register with the slave ID field to 0; this enables
548 * extended slave addressing
550 smode = fsi_slave_smode(id);
551 smode = cpu_to_be32(smode);
553 return fsi_master_write(master, link, id, FSI_SLAVE_BASE + FSI_SMODE,
554 &smode, sizeof(smode));
557 static void fsi_slave_release(struct device *dev)
559 struct fsi_slave *slave = to_fsi_slave(dev);
561 kfree(slave);
564 static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
566 uint32_t chip_id, llmode;
567 struct fsi_slave *slave;
568 uint8_t crc;
569 int rc;
571 /* Currently, we only support single slaves on a link, and use the
572 * full 23-bit address range
574 if (id != 0)
575 return -EINVAL;
577 rc = fsi_master_read(master, link, id, 0, &chip_id, sizeof(chip_id));
578 if (rc) {
579 dev_dbg(&master->dev, "can't read slave %02x:%02x %d\n",
580 link, id, rc);
581 return -ENODEV;
583 chip_id = be32_to_cpu(chip_id);
585 crc = crc4(0, chip_id, 32);
586 if (crc) {
587 dev_warn(&master->dev, "slave %02x:%02x invalid chip id CRC!\n",
588 link, id);
589 return -EIO;
592 dev_info(&master->dev, "fsi: found chip %08x at %02x:%02x:%02x\n",
593 chip_id, master->idx, link, id);
595 rc = fsi_slave_set_smode(master, link, id);
596 if (rc) {
597 dev_warn(&master->dev,
598 "can't set smode on slave:%02x:%02x %d\n",
599 link, id, rc);
600 return -ENODEV;
603 /* If we're behind a master that doesn't provide a self-running bus
604 * clock, put the slave into async mode
606 if (master->flags & FSI_MASTER_FLAG_SWCLOCK) {
607 llmode = cpu_to_be32(FSI_LLMODE_ASYNC);
608 rc = fsi_master_write(master, link, id,
609 FSI_SLAVE_BASE + FSI_LLMODE,
610 &llmode, sizeof(llmode));
611 if (rc)
612 dev_warn(&master->dev,
613 "can't set llmode on slave:%02x:%02x %d\n",
614 link, id, rc);
617 /* We can communicate with a slave; create the slave device and
618 * register.
620 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
621 if (!slave)
622 return -ENOMEM;
624 slave->master = master;
625 slave->dev.parent = &master->dev;
626 slave->dev.release = fsi_slave_release;
627 slave->link = link;
628 slave->id = id;
629 slave->size = FSI_SLAVE_SIZE_23b;
631 dev_set_name(&slave->dev, "slave@%02x:%02x", link, id);
632 rc = device_register(&slave->dev);
633 if (rc < 0) {
634 dev_warn(&master->dev, "failed to create slave device: %d\n",
635 rc);
636 put_device(&slave->dev);
637 return rc;
640 rc = device_create_bin_file(&slave->dev, &fsi_slave_raw_attr);
641 if (rc)
642 dev_warn(&slave->dev, "failed to create raw attr: %d\n", rc);
644 rc = device_create_bin_file(&slave->dev, &fsi_slave_term_attr);
645 if (rc)
646 dev_warn(&slave->dev, "failed to create term attr: %d\n", rc);
648 rc = fsi_slave_scan(slave);
649 if (rc)
650 dev_dbg(&master->dev, "failed during slave scan with: %d\n",
651 rc);
653 return rc;
656 /* FSI master support */
657 static int fsi_check_access(uint32_t addr, size_t size)
659 if (size != 1 && size != 2 && size != 4)
660 return -EINVAL;
662 if ((addr & 0x3) != (size & 0x3))
663 return -EINVAL;
665 return 0;
668 static int fsi_master_read(struct fsi_master *master, int link,
669 uint8_t slave_id, uint32_t addr, void *val, size_t size)
671 int rc;
673 trace_fsi_master_read(master, link, slave_id, addr, size);
675 rc = fsi_check_access(addr, size);
676 if (!rc)
677 rc = master->read(master, link, slave_id, addr, val, size);
679 trace_fsi_master_rw_result(master, link, slave_id, addr, size,
680 false, val, rc);
682 return rc;
685 static int fsi_master_write(struct fsi_master *master, int link,
686 uint8_t slave_id, uint32_t addr, const void *val, size_t size)
688 int rc;
690 trace_fsi_master_write(master, link, slave_id, addr, size, val);
692 rc = fsi_check_access(addr, size);
693 if (!rc)
694 rc = master->write(master, link, slave_id, addr, val, size);
696 trace_fsi_master_rw_result(master, link, slave_id, addr, size,
697 true, val, rc);
699 return rc;
702 static int fsi_master_link_enable(struct fsi_master *master, int link)
704 if (master->link_enable)
705 return master->link_enable(master, link);
707 return 0;
711 * Issue a break command on this link
713 static int fsi_master_break(struct fsi_master *master, int link)
715 trace_fsi_master_break(master, link);
717 if (master->send_break)
718 return master->send_break(master, link);
720 return 0;
723 static int fsi_master_scan(struct fsi_master *master)
725 int link, rc;
727 for (link = 0; link < master->n_links; link++) {
728 rc = fsi_master_link_enable(master, link);
729 if (rc) {
730 dev_dbg(&master->dev,
731 "enable link %d failed: %d\n", link, rc);
732 continue;
734 rc = fsi_master_break(master, link);
735 if (rc) {
736 dev_dbg(&master->dev,
737 "break to link %d failed: %d\n", link, rc);
738 continue;
741 fsi_slave_init(master, link, 0);
744 return 0;
747 static int fsi_slave_remove_device(struct device *dev, void *arg)
749 device_unregister(dev);
750 return 0;
753 static int fsi_master_remove_slave(struct device *dev, void *arg)
755 device_for_each_child(dev, NULL, fsi_slave_remove_device);
756 device_unregister(dev);
757 return 0;
760 static void fsi_master_unscan(struct fsi_master *master)
762 device_for_each_child(&master->dev, NULL, fsi_master_remove_slave);
765 static ssize_t master_rescan_store(struct device *dev,
766 struct device_attribute *attr, const char *buf, size_t count)
768 struct fsi_master *master = to_fsi_master(dev);
769 int rc;
771 fsi_master_unscan(master);
772 rc = fsi_master_scan(master);
773 if (rc < 0)
774 return rc;
776 return count;
779 static DEVICE_ATTR(rescan, 0200, NULL, master_rescan_store);
781 static ssize_t master_break_store(struct device *dev,
782 struct device_attribute *attr, const char *buf, size_t count)
784 struct fsi_master *master = to_fsi_master(dev);
786 fsi_master_break(master, 0);
788 return count;
791 static DEVICE_ATTR(break, 0200, NULL, master_break_store);
793 int fsi_master_register(struct fsi_master *master)
795 int rc;
797 if (!master)
798 return -EINVAL;
800 master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
801 dev_set_name(&master->dev, "fsi%d", master->idx);
803 rc = device_register(&master->dev);
804 if (rc) {
805 ida_simple_remove(&master_ida, master->idx);
806 return rc;
809 rc = device_create_file(&master->dev, &dev_attr_rescan);
810 if (rc) {
811 device_unregister(&master->dev);
812 ida_simple_remove(&master_ida, master->idx);
813 return rc;
816 rc = device_create_file(&master->dev, &dev_attr_break);
817 if (rc) {
818 device_unregister(&master->dev);
819 ida_simple_remove(&master_ida, master->idx);
820 return rc;
823 fsi_master_scan(master);
825 return 0;
827 EXPORT_SYMBOL_GPL(fsi_master_register);
829 void fsi_master_unregister(struct fsi_master *master)
831 if (master->idx >= 0) {
832 ida_simple_remove(&master_ida, master->idx);
833 master->idx = -1;
836 fsi_master_unscan(master);
837 device_unregister(&master->dev);
839 EXPORT_SYMBOL_GPL(fsi_master_unregister);
841 /* FSI core & Linux bus type definitions */
843 static int fsi_bus_match(struct device *dev, struct device_driver *drv)
845 struct fsi_device *fsi_dev = to_fsi_dev(dev);
846 struct fsi_driver *fsi_drv = to_fsi_drv(drv);
847 const struct fsi_device_id *id;
849 if (!fsi_drv->id_table)
850 return 0;
852 for (id = fsi_drv->id_table; id->engine_type; id++) {
853 if (id->engine_type != fsi_dev->engine_type)
854 continue;
855 if (id->version == FSI_VERSION_ANY ||
856 id->version == fsi_dev->version)
857 return 1;
860 return 0;
863 int fsi_driver_register(struct fsi_driver *fsi_drv)
865 if (!fsi_drv)
866 return -EINVAL;
867 if (!fsi_drv->id_table)
868 return -EINVAL;
870 return driver_register(&fsi_drv->drv);
872 EXPORT_SYMBOL_GPL(fsi_driver_register);
874 void fsi_driver_unregister(struct fsi_driver *fsi_drv)
876 driver_unregister(&fsi_drv->drv);
878 EXPORT_SYMBOL_GPL(fsi_driver_unregister);
880 struct bus_type fsi_bus_type = {
881 .name = "fsi",
882 .match = fsi_bus_match,
884 EXPORT_SYMBOL_GPL(fsi_bus_type);
886 static int __init fsi_init(void)
888 return bus_register(&fsi_bus_type);
890 postcore_initcall(fsi_init);
892 static void fsi_exit(void)
894 bus_unregister(&fsi_bus_type);
896 module_exit(fsi_exit);
897 module_param(discard_errors, int, 0664);
898 MODULE_LICENSE("GPL");
899 MODULE_PARM_DESC(discard_errors, "Don't invoke error handling on bus accesses");