Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * FSI core driver
0004  *
0005  * Copyright (C) IBM Corporation 2016
0006  *
0007  * TODO:
0008  *  - Rework topology
0009  *  - s/chip_id/chip_loc
0010  *  - s/cfam/chip (cfam_id -> chip_id etc...)
0011  */
0012 
0013 #include <linux/crc4.h>
0014 #include <linux/device.h>
0015 #include <linux/fsi.h>
0016 #include <linux/idr.h>
0017 #include <linux/module.h>
0018 #include <linux/of.h>
0019 #include <linux/slab.h>
0020 #include <linux/bitops.h>
0021 #include <linux/cdev.h>
0022 #include <linux/fs.h>
0023 #include <linux/uaccess.h>
0024 
0025 #include "fsi-master.h"
0026 
0027 #define FSI_SLAVE_CONF_NEXT_MASK    GENMASK(31, 31)
0028 #define FSI_SLAVE_CONF_SLOTS_MASK   GENMASK(23, 16)
0029 #define FSI_SLAVE_CONF_SLOTS_SHIFT  16
0030 #define FSI_SLAVE_CONF_VERSION_MASK GENMASK(15, 12)
0031 #define FSI_SLAVE_CONF_VERSION_SHIFT    12
0032 #define FSI_SLAVE_CONF_TYPE_MASK    GENMASK(11, 4)
0033 #define FSI_SLAVE_CONF_TYPE_SHIFT   4
0034 #define FSI_SLAVE_CONF_CRC_SHIFT    4
0035 #define FSI_SLAVE_CONF_CRC_MASK     GENMASK(3, 0)
0036 #define FSI_SLAVE_CONF_DATA_BITS    28
0037 
0038 #define FSI_PEEK_BASE           0x410
0039 
0040 static const int engine_page_size = 0x400;
0041 
0042 #define FSI_SLAVE_BASE          0x800
0043 
0044 /*
0045  * FSI slave engine control register offsets
0046  */
0047 #define FSI_SMODE       0x0 /* R/W: Mode register */
0048 #define FSI_SISC        0x8 /* R/W: Interrupt condition */
0049 #define FSI_SSTAT       0x14    /* R  : Slave status */
0050 #define FSI_SLBUS       0x30    /* W  : LBUS Ownership */
0051 #define FSI_LLMODE      0x100   /* R/W: Link layer mode register */
0052 
0053 /*
0054  * SMODE fields
0055  */
0056 #define FSI_SMODE_WSC       0x80000000  /* Warm start done */
0057 #define FSI_SMODE_ECRC      0x20000000  /* Hw CRC check */
0058 #define FSI_SMODE_SID_SHIFT 24      /* ID shift */
0059 #define FSI_SMODE_SID_MASK  3       /* ID Mask */
0060 #define FSI_SMODE_ED_SHIFT  20      /* Echo delay shift */
0061 #define FSI_SMODE_ED_MASK   0xf     /* Echo delay mask */
0062 #define FSI_SMODE_SD_SHIFT  16      /* Send delay shift */
0063 #define FSI_SMODE_SD_MASK   0xf     /* Send delay mask */
0064 #define FSI_SMODE_LBCRR_SHIFT   8       /* Clk ratio shift */
0065 #define FSI_SMODE_LBCRR_MASK    0xf     /* Clk ratio mask */
0066 
0067 /*
0068  * SLBUS fields
0069  */
0070 #define FSI_SLBUS_FORCE     0x80000000  /* Force LBUS ownership */
0071 
0072 /*
0073  * LLMODE fields
0074  */
0075 #define FSI_LLMODE_ASYNC    0x1
0076 
0077 #define FSI_SLAVE_SIZE_23b      0x800000
0078 
0079 static DEFINE_IDA(master_ida);
0080 
0081 struct fsi_slave {
0082     struct device       dev;
0083     struct fsi_master   *master;
0084     struct cdev     cdev;
0085     int         cdev_idx;
0086     int         id; /* FSI address */
0087     int         link;   /* FSI link# */
0088     u32         cfam_id;
0089     int         chip_id;
0090     uint32_t        size;   /* size of slave address space */
0091     u8          t_send_delay;
0092     u8          t_echo_delay;
0093 };
0094 
0095 #define CREATE_TRACE_POINTS
0096 #include <trace/events/fsi.h>
0097 
0098 #define to_fsi_master(d) container_of(d, struct fsi_master, dev)
0099 #define to_fsi_slave(d) container_of(d, struct fsi_slave, dev)
0100 
0101 static const int slave_retries = 2;
0102 static int discard_errors;
0103 
0104 static dev_t fsi_base_dev;
0105 static DEFINE_IDA(fsi_minor_ida);
0106 #define FSI_CHAR_MAX_DEVICES    0x1000
0107 
0108 /* Legacy /dev numbering: 4 devices per chip, 16 chips */
0109 #define FSI_CHAR_LEGACY_TOP 64
0110 
0111 static int fsi_master_read(struct fsi_master *master, int link,
0112         uint8_t slave_id, uint32_t addr, void *val, size_t size);
0113 static int fsi_master_write(struct fsi_master *master, int link,
0114         uint8_t slave_id, uint32_t addr, const void *val, size_t size);
0115 static int fsi_master_break(struct fsi_master *master, int link);
0116 
0117 /*
0118  * fsi_device_read() / fsi_device_write() / fsi_device_peek()
0119  *
0120  * FSI endpoint-device support
0121  *
0122  * Read / write / peek accessors for a client
0123  *
0124  * Parameters:
0125  * dev:  Structure passed to FSI client device drivers on probe().
0126  * addr: FSI address of given device.  Client should pass in its base address
0127  *       plus desired offset to access its register space.
0128  * val:  For read/peek this is the value read at the specified address. For
0129  *       write this is value to write to the specified address.
0130  *       The data in val must be FSI bus endian (big endian).
0131  * size: Size in bytes of the operation.  Sizes supported are 1, 2 and 4 bytes.
0132  *       Addresses must be aligned on size boundaries or an error will result.
0133  */
0134 int fsi_device_read(struct fsi_device *dev, uint32_t addr, void *val,
0135         size_t size)
0136 {
0137     if (addr > dev->size || size > dev->size || addr > dev->size - size)
0138         return -EINVAL;
0139 
0140     return fsi_slave_read(dev->slave, dev->addr + addr, val, size);
0141 }
0142 EXPORT_SYMBOL_GPL(fsi_device_read);
0143 
0144 int fsi_device_write(struct fsi_device *dev, uint32_t addr, const void *val,
0145         size_t size)
0146 {
0147     if (addr > dev->size || size > dev->size || addr > dev->size - size)
0148         return -EINVAL;
0149 
0150     return fsi_slave_write(dev->slave, dev->addr + addr, val, size);
0151 }
0152 EXPORT_SYMBOL_GPL(fsi_device_write);
0153 
0154 int fsi_device_peek(struct fsi_device *dev, void *val)
0155 {
0156     uint32_t addr = FSI_PEEK_BASE + ((dev->unit - 2) * sizeof(uint32_t));
0157 
0158     return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t));
0159 }
0160 
0161 static void fsi_device_release(struct device *_device)
0162 {
0163     struct fsi_device *device = to_fsi_dev(_device);
0164 
0165     of_node_put(device->dev.of_node);
0166     kfree(device);
0167 }
0168 
0169 static struct fsi_device *fsi_create_device(struct fsi_slave *slave)
0170 {
0171     struct fsi_device *dev;
0172 
0173     dev = kzalloc(sizeof(*dev), GFP_KERNEL);
0174     if (!dev)
0175         return NULL;
0176 
0177     dev->dev.parent = &slave->dev;
0178     dev->dev.bus = &fsi_bus_type;
0179     dev->dev.release = fsi_device_release;
0180 
0181     return dev;
0182 }
0183 
0184 /* FSI slave support */
0185 static int fsi_slave_calc_addr(struct fsi_slave *slave, uint32_t *addrp,
0186         uint8_t *idp)
0187 {
0188     uint32_t addr = *addrp;
0189     uint8_t id = *idp;
0190 
0191     if (addr > slave->size)
0192         return -EINVAL;
0193 
0194     /* For 23 bit addressing, we encode the extra two bits in the slave
0195      * id (and the slave's actual ID needs to be 0).
0196      */
0197     if (addr > 0x1fffff) {
0198         if (slave->id != 0)
0199             return -EINVAL;
0200         id = (addr >> 21) & 0x3;
0201         addr &= 0x1fffff;
0202     }
0203 
0204     *addrp = addr;
0205     *idp = id;
0206     return 0;
0207 }
0208 
0209 static int fsi_slave_report_and_clear_errors(struct fsi_slave *slave)
0210 {
0211     struct fsi_master *master = slave->master;
0212     __be32 irq, stat;
0213     int rc, link;
0214     uint8_t id;
0215 
0216     link = slave->link;
0217     id = slave->id;
0218 
0219     rc = fsi_master_read(master, link, id, FSI_SLAVE_BASE + FSI_SISC,
0220             &irq, sizeof(irq));
0221     if (rc)
0222         return rc;
0223 
0224     rc =  fsi_master_read(master, link, id, FSI_SLAVE_BASE + FSI_SSTAT,
0225             &stat, sizeof(stat));
0226     if (rc)
0227         return rc;
0228 
0229     dev_dbg(&slave->dev, "status: 0x%08x, sisc: 0x%08x\n",
0230             be32_to_cpu(stat), be32_to_cpu(irq));
0231 
0232     /* clear interrupts */
0233     return fsi_master_write(master, link, id, FSI_SLAVE_BASE + FSI_SISC,
0234             &irq, sizeof(irq));
0235 }
0236 
0237 /* Encode slave local bus echo delay */
0238 static inline uint32_t fsi_smode_echodly(int x)
0239 {
0240     return (x & FSI_SMODE_ED_MASK) << FSI_SMODE_ED_SHIFT;
0241 }
0242 
0243 /* Encode slave local bus send delay */
0244 static inline uint32_t fsi_smode_senddly(int x)
0245 {
0246     return (x & FSI_SMODE_SD_MASK) << FSI_SMODE_SD_SHIFT;
0247 }
0248 
0249 /* Encode slave local bus clock rate ratio */
0250 static inline uint32_t fsi_smode_lbcrr(int x)
0251 {
0252     return (x & FSI_SMODE_LBCRR_MASK) << FSI_SMODE_LBCRR_SHIFT;
0253 }
0254 
0255 /* Encode slave ID */
0256 static inline uint32_t fsi_smode_sid(int x)
0257 {
0258     return (x & FSI_SMODE_SID_MASK) << FSI_SMODE_SID_SHIFT;
0259 }
0260 
0261 static uint32_t fsi_slave_smode(int id, u8 t_senddly, u8 t_echodly)
0262 {
0263     return FSI_SMODE_WSC | FSI_SMODE_ECRC
0264         | fsi_smode_sid(id)
0265         | fsi_smode_echodly(t_echodly - 1) | fsi_smode_senddly(t_senddly - 1)
0266         | fsi_smode_lbcrr(0x8);
0267 }
0268 
0269 static int fsi_slave_set_smode(struct fsi_slave *slave)
0270 {
0271     uint32_t smode;
0272     __be32 data;
0273 
0274     /* set our smode register with the slave ID field to 0; this enables
0275      * extended slave addressing
0276      */
0277     smode = fsi_slave_smode(slave->id, slave->t_send_delay, slave->t_echo_delay);
0278     data = cpu_to_be32(smode);
0279 
0280     return fsi_master_write(slave->master, slave->link, slave->id,
0281                 FSI_SLAVE_BASE + FSI_SMODE,
0282                 &data, sizeof(data));
0283 }
0284 
0285 static int fsi_slave_handle_error(struct fsi_slave *slave, bool write,
0286                   uint32_t addr, size_t size)
0287 {
0288     struct fsi_master *master = slave->master;
0289     int rc, link;
0290     uint32_t reg;
0291     uint8_t id, send_delay, echo_delay;
0292 
0293     if (discard_errors)
0294         return -1;
0295 
0296     link = slave->link;
0297     id = slave->id;
0298 
0299     dev_dbg(&slave->dev, "handling error on %s to 0x%08x[%zd]",
0300             write ? "write" : "read", addr, size);
0301 
0302     /* try a simple clear of error conditions, which may fail if we've lost
0303      * communication with the slave
0304      */
0305     rc = fsi_slave_report_and_clear_errors(slave);
0306     if (!rc)
0307         return 0;
0308 
0309     /* send a TERM and retry */
0310     if (master->term) {
0311         rc = master->term(master, link, id);
0312         if (!rc) {
0313             rc = fsi_master_read(master, link, id, 0,
0314                     &reg, sizeof(reg));
0315             if (!rc)
0316                 rc = fsi_slave_report_and_clear_errors(slave);
0317             if (!rc)
0318                 return 0;
0319         }
0320     }
0321 
0322     send_delay = slave->t_send_delay;
0323     echo_delay = slave->t_echo_delay;
0324 
0325     /* getting serious, reset the slave via BREAK */
0326     rc = fsi_master_break(master, link);
0327     if (rc)
0328         return rc;
0329 
0330     slave->t_send_delay = send_delay;
0331     slave->t_echo_delay = echo_delay;
0332 
0333     rc = fsi_slave_set_smode(slave);
0334     if (rc)
0335         return rc;
0336 
0337     if (master->link_config)
0338         master->link_config(master, link,
0339                     slave->t_send_delay,
0340                     slave->t_echo_delay);
0341 
0342     return fsi_slave_report_and_clear_errors(slave);
0343 }
0344 
0345 int fsi_slave_read(struct fsi_slave *slave, uint32_t addr,
0346             void *val, size_t size)
0347 {
0348     uint8_t id = slave->id;
0349     int rc, err_rc, i;
0350 
0351     rc = fsi_slave_calc_addr(slave, &addr, &id);
0352     if (rc)
0353         return rc;
0354 
0355     for (i = 0; i < slave_retries; i++) {
0356         rc = fsi_master_read(slave->master, slave->link,
0357                 id, addr, val, size);
0358         if (!rc)
0359             break;
0360 
0361         err_rc = fsi_slave_handle_error(slave, false, addr, size);
0362         if (err_rc)
0363             break;
0364     }
0365 
0366     return rc;
0367 }
0368 EXPORT_SYMBOL_GPL(fsi_slave_read);
0369 
0370 int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,
0371             const void *val, size_t size)
0372 {
0373     uint8_t id = slave->id;
0374     int rc, err_rc, i;
0375 
0376     rc = fsi_slave_calc_addr(slave, &addr, &id);
0377     if (rc)
0378         return rc;
0379 
0380     for (i = 0; i < slave_retries; i++) {
0381         rc = fsi_master_write(slave->master, slave->link,
0382                 id, addr, val, size);
0383         if (!rc)
0384             break;
0385 
0386         err_rc = fsi_slave_handle_error(slave, true, addr, size);
0387         if (err_rc)
0388             break;
0389     }
0390 
0391     return rc;
0392 }
0393 EXPORT_SYMBOL_GPL(fsi_slave_write);
0394 
0395 extern int fsi_slave_claim_range(struct fsi_slave *slave,
0396         uint32_t addr, uint32_t size)
0397 {
0398     if (addr + size < addr)
0399         return -EINVAL;
0400 
0401     if (addr + size > slave->size)
0402         return -EINVAL;
0403 
0404     /* todo: check for overlapping claims */
0405     return 0;
0406 }
0407 EXPORT_SYMBOL_GPL(fsi_slave_claim_range);
0408 
0409 extern void fsi_slave_release_range(struct fsi_slave *slave,
0410         uint32_t addr, uint32_t size)
0411 {
0412 }
0413 EXPORT_SYMBOL_GPL(fsi_slave_release_range);
0414 
0415 static bool fsi_device_node_matches(struct device *dev, struct device_node *np,
0416         uint32_t addr, uint32_t size)
0417 {
0418     unsigned int len, na, ns;
0419     const __be32 *prop;
0420     uint32_t psize;
0421 
0422     na = of_n_addr_cells(np);
0423     ns = of_n_size_cells(np);
0424 
0425     if (na != 1 || ns != 1)
0426         return false;
0427 
0428     prop = of_get_property(np, "reg", &len);
0429     if (!prop || len != 8)
0430         return false;
0431 
0432     if (of_read_number(prop, 1) != addr)
0433         return false;
0434 
0435     psize = of_read_number(prop + 1, 1);
0436     if (psize != size) {
0437         dev_warn(dev,
0438             "node %s matches probed address, but not size (got 0x%x, expected 0x%x)",
0439             of_node_full_name(np), psize, size);
0440     }
0441 
0442     return true;
0443 }
0444 
0445 /* Find a matching node for the slave engine at @address, using @size bytes
0446  * of space. Returns NULL if not found, or a matching node with refcount
0447  * already incremented.
0448  */
0449 static struct device_node *fsi_device_find_of_node(struct fsi_device *dev)
0450 {
0451     struct device_node *parent, *np;
0452 
0453     parent = dev_of_node(&dev->slave->dev);
0454     if (!parent)
0455         return NULL;
0456 
0457     for_each_child_of_node(parent, np) {
0458         if (fsi_device_node_matches(&dev->dev, np,
0459                     dev->addr, dev->size))
0460             return np;
0461     }
0462 
0463     return NULL;
0464 }
0465 
0466 static int fsi_slave_scan(struct fsi_slave *slave)
0467 {
0468     uint32_t engine_addr;
0469     int rc, i;
0470 
0471     /*
0472      * scan engines
0473      *
0474      * We keep the peek mode and slave engines for the core; so start
0475      * at the third slot in the configuration table. We also need to
0476      * skip the chip ID entry at the start of the address space.
0477      */
0478     engine_addr = engine_page_size * 3;
0479     for (i = 2; i < engine_page_size / sizeof(uint32_t); i++) {
0480         uint8_t slots, version, type, crc;
0481         struct fsi_device *dev;
0482         uint32_t conf;
0483         __be32 data;
0484 
0485         rc = fsi_slave_read(slave, (i + 1) * sizeof(data),
0486                 &data, sizeof(data));
0487         if (rc) {
0488             dev_warn(&slave->dev,
0489                 "error reading slave registers\n");
0490             return -1;
0491         }
0492         conf = be32_to_cpu(data);
0493 
0494         crc = crc4(0, conf, 32);
0495         if (crc) {
0496             dev_warn(&slave->dev,
0497                 "crc error in slave register at 0x%04x\n",
0498                 i);
0499             return -1;
0500         }
0501 
0502         slots = (conf & FSI_SLAVE_CONF_SLOTS_MASK)
0503             >> FSI_SLAVE_CONF_SLOTS_SHIFT;
0504         version = (conf & FSI_SLAVE_CONF_VERSION_MASK)
0505             >> FSI_SLAVE_CONF_VERSION_SHIFT;
0506         type = (conf & FSI_SLAVE_CONF_TYPE_MASK)
0507             >> FSI_SLAVE_CONF_TYPE_SHIFT;
0508 
0509         /*
0510          * Unused address areas are marked by a zero type value; this
0511          * skips the defined address areas
0512          */
0513         if (type != 0 && slots != 0) {
0514 
0515             /* create device */
0516             dev = fsi_create_device(slave);
0517             if (!dev)
0518                 return -ENOMEM;
0519 
0520             dev->slave = slave;
0521             dev->engine_type = type;
0522             dev->version = version;
0523             dev->unit = i;
0524             dev->addr = engine_addr;
0525             dev->size = slots * engine_page_size;
0526 
0527             trace_fsi_dev_init(dev);
0528 
0529             dev_dbg(&slave->dev,
0530             "engine[%i]: type %x, version %x, addr %x size %x\n",
0531                     dev->unit, dev->engine_type, version,
0532                     dev->addr, dev->size);
0533 
0534             dev_set_name(&dev->dev, "%02x:%02x:%02x:%02x",
0535                     slave->master->idx, slave->link,
0536                     slave->id, i - 2);
0537             dev->dev.of_node = fsi_device_find_of_node(dev);
0538 
0539             rc = device_register(&dev->dev);
0540             if (rc) {
0541                 dev_warn(&slave->dev, "add failed: %d\n", rc);
0542                 put_device(&dev->dev);
0543             }
0544         }
0545 
0546         engine_addr += slots * engine_page_size;
0547 
0548         if (!(conf & FSI_SLAVE_CONF_NEXT_MASK))
0549             break;
0550     }
0551 
0552     return 0;
0553 }
0554 
0555 static unsigned long aligned_access_size(size_t offset, size_t count)
0556 {
0557     unsigned long offset_unit, count_unit;
0558 
0559     /* Criteria:
0560      *
0561      * 1. Access size must be less than or equal to the maximum access
0562      *    width or the highest power-of-two factor of offset
0563      * 2. Access size must be less than or equal to the amount specified by
0564      *    count
0565      *
0566      * The access width is optimal if we can calculate 1 to be strictly
0567      * equal while still satisfying 2.
0568      */
0569 
0570     /* Find 1 by the bottom bit of offset (with a 4 byte access cap) */
0571     offset_unit = BIT(__builtin_ctzl(offset | 4));
0572 
0573     /* Find 2 by the top bit of count */
0574     count_unit = BIT(8 * sizeof(unsigned long) - 1 - __builtin_clzl(count));
0575 
0576     /* Constrain the maximum access width to the minimum of both criteria */
0577     return BIT(__builtin_ctzl(offset_unit | count_unit));
0578 }
0579 
0580 static ssize_t fsi_slave_sysfs_raw_read(struct file *file,
0581         struct kobject *kobj, struct bin_attribute *attr, char *buf,
0582         loff_t off, size_t count)
0583 {
0584     struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj));
0585     size_t total_len, read_len;
0586     int rc;
0587 
0588     if (off < 0)
0589         return -EINVAL;
0590 
0591     if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
0592         return -EINVAL;
0593 
0594     for (total_len = 0; total_len < count; total_len += read_len) {
0595         read_len = aligned_access_size(off, count - total_len);
0596 
0597         rc = fsi_slave_read(slave, off, buf + total_len, read_len);
0598         if (rc)
0599             return rc;
0600 
0601         off += read_len;
0602     }
0603 
0604     return count;
0605 }
0606 
0607 static ssize_t fsi_slave_sysfs_raw_write(struct file *file,
0608         struct kobject *kobj, struct bin_attribute *attr,
0609         char *buf, loff_t off, size_t count)
0610 {
0611     struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj));
0612     size_t total_len, write_len;
0613     int rc;
0614 
0615     if (off < 0)
0616         return -EINVAL;
0617 
0618     if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
0619         return -EINVAL;
0620 
0621     for (total_len = 0; total_len < count; total_len += write_len) {
0622         write_len = aligned_access_size(off, count - total_len);
0623 
0624         rc = fsi_slave_write(slave, off, buf + total_len, write_len);
0625         if (rc)
0626             return rc;
0627 
0628         off += write_len;
0629     }
0630 
0631     return count;
0632 }
0633 
0634 static const struct bin_attribute fsi_slave_raw_attr = {
0635     .attr = {
0636         .name = "raw",
0637         .mode = 0600,
0638     },
0639     .size = 0,
0640     .read = fsi_slave_sysfs_raw_read,
0641     .write = fsi_slave_sysfs_raw_write,
0642 };
0643 
0644 static void fsi_slave_release(struct device *dev)
0645 {
0646     struct fsi_slave *slave = to_fsi_slave(dev);
0647 
0648     fsi_free_minor(slave->dev.devt);
0649     of_node_put(dev->of_node);
0650     kfree(slave);
0651 }
0652 
0653 static bool fsi_slave_node_matches(struct device_node *np,
0654         int link, uint8_t id)
0655 {
0656     unsigned int len, na, ns;
0657     const __be32 *prop;
0658 
0659     na = of_n_addr_cells(np);
0660     ns = of_n_size_cells(np);
0661 
0662     /* Ensure we have the correct format for addresses and sizes in
0663      * reg properties
0664      */
0665     if (na != 2 || ns != 0)
0666         return false;
0667 
0668     prop = of_get_property(np, "reg", &len);
0669     if (!prop || len != 8)
0670         return false;
0671 
0672     return (of_read_number(prop, 1) == link) &&
0673         (of_read_number(prop + 1, 1) == id);
0674 }
0675 
0676 /* Find a matching node for the slave at (link, id). Returns NULL if none
0677  * found, or a matching node with refcount already incremented.
0678  */
0679 static struct device_node *fsi_slave_find_of_node(struct fsi_master *master,
0680         int link, uint8_t id)
0681 {
0682     struct device_node *parent, *np;
0683 
0684     parent = dev_of_node(&master->dev);
0685     if (!parent)
0686         return NULL;
0687 
0688     for_each_child_of_node(parent, np) {
0689         if (fsi_slave_node_matches(np, link, id))
0690             return np;
0691     }
0692 
0693     return NULL;
0694 }
0695 
0696 static ssize_t cfam_read(struct file *filep, char __user *buf, size_t count,
0697              loff_t *offset)
0698 {
0699     struct fsi_slave *slave = filep->private_data;
0700     size_t total_len, read_len;
0701     loff_t off = *offset;
0702     ssize_t rc;
0703 
0704     if (off < 0)
0705         return -EINVAL;
0706 
0707     if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
0708         return -EINVAL;
0709 
0710     for (total_len = 0; total_len < count; total_len += read_len) {
0711         __be32 data;
0712 
0713         read_len = min_t(size_t, count, 4);
0714         read_len -= off & 0x3;
0715 
0716         rc = fsi_slave_read(slave, off, &data, read_len);
0717         if (rc)
0718             goto fail;
0719         rc = copy_to_user(buf + total_len, &data, read_len);
0720         if (rc) {
0721             rc = -EFAULT;
0722             goto fail;
0723         }
0724         off += read_len;
0725     }
0726     rc = count;
0727  fail:
0728     *offset = off;
0729     return rc;
0730 }
0731 
0732 static ssize_t cfam_write(struct file *filep, const char __user *buf,
0733               size_t count, loff_t *offset)
0734 {
0735     struct fsi_slave *slave = filep->private_data;
0736     size_t total_len, write_len;
0737     loff_t off = *offset;
0738     ssize_t rc;
0739 
0740 
0741     if (off < 0)
0742         return -EINVAL;
0743 
0744     if (off > 0xffffffff || count > 0xffffffff || off + count > 0xffffffff)
0745         return -EINVAL;
0746 
0747     for (total_len = 0; total_len < count; total_len += write_len) {
0748         __be32 data;
0749 
0750         write_len = min_t(size_t, count, 4);
0751         write_len -= off & 0x3;
0752 
0753         rc = copy_from_user(&data, buf + total_len, write_len);
0754         if (rc) {
0755             rc = -EFAULT;
0756             goto fail;
0757         }
0758         rc = fsi_slave_write(slave, off, &data, write_len);
0759         if (rc)
0760             goto fail;
0761         off += write_len;
0762     }
0763     rc = count;
0764  fail:
0765     *offset = off;
0766     return rc;
0767 }
0768 
0769 static loff_t cfam_llseek(struct file *file, loff_t offset, int whence)
0770 {
0771     switch (whence) {
0772     case SEEK_CUR:
0773         break;
0774     case SEEK_SET:
0775         file->f_pos = offset;
0776         break;
0777     default:
0778         return -EINVAL;
0779     }
0780 
0781     return offset;
0782 }
0783 
0784 static int cfam_open(struct inode *inode, struct file *file)
0785 {
0786     struct fsi_slave *slave = container_of(inode->i_cdev, struct fsi_slave, cdev);
0787 
0788     file->private_data = slave;
0789 
0790     return 0;
0791 }
0792 
0793 static const struct file_operations cfam_fops = {
0794     .owner      = THIS_MODULE,
0795     .open       = cfam_open,
0796     .llseek     = cfam_llseek,
0797     .read       = cfam_read,
0798     .write      = cfam_write,
0799 };
0800 
0801 static ssize_t send_term_store(struct device *dev,
0802                    struct device_attribute *attr,
0803                    const char *buf, size_t count)
0804 {
0805     struct fsi_slave *slave = to_fsi_slave(dev);
0806     struct fsi_master *master = slave->master;
0807 
0808     if (!master->term)
0809         return -ENODEV;
0810 
0811     master->term(master, slave->link, slave->id);
0812     return count;
0813 }
0814 
0815 static DEVICE_ATTR_WO(send_term);
0816 
0817 static ssize_t slave_send_echo_show(struct device *dev,
0818                     struct device_attribute *attr,
0819                     char *buf)
0820 {
0821     struct fsi_slave *slave = to_fsi_slave(dev);
0822 
0823     return sprintf(buf, "%u\n", slave->t_send_delay);
0824 }
0825 
0826 static ssize_t slave_send_echo_store(struct device *dev,
0827         struct device_attribute *attr, const char *buf, size_t count)
0828 {
0829     struct fsi_slave *slave = to_fsi_slave(dev);
0830     struct fsi_master *master = slave->master;
0831     unsigned long val;
0832     int rc;
0833 
0834     if (kstrtoul(buf, 0, &val) < 0)
0835         return -EINVAL;
0836 
0837     if (val < 1 || val > 16)
0838         return -EINVAL;
0839 
0840     if (!master->link_config)
0841         return -ENXIO;
0842 
0843     /* Current HW mandates that send and echo delay are identical */
0844     slave->t_send_delay = val;
0845     slave->t_echo_delay = val;
0846 
0847     rc = fsi_slave_set_smode(slave);
0848     if (rc < 0)
0849         return rc;
0850     if (master->link_config)
0851         master->link_config(master, slave->link,
0852                     slave->t_send_delay,
0853                     slave->t_echo_delay);
0854 
0855     return count;
0856 }
0857 
0858 static DEVICE_ATTR(send_echo_delays, 0600,
0859            slave_send_echo_show, slave_send_echo_store);
0860 
0861 static ssize_t chip_id_show(struct device *dev,
0862                 struct device_attribute *attr,
0863                 char *buf)
0864 {
0865     struct fsi_slave *slave = to_fsi_slave(dev);
0866 
0867     return sprintf(buf, "%d\n", slave->chip_id);
0868 }
0869 
0870 static DEVICE_ATTR_RO(chip_id);
0871 
0872 static ssize_t cfam_id_show(struct device *dev,
0873                 struct device_attribute *attr,
0874                 char *buf)
0875 {
0876     struct fsi_slave *slave = to_fsi_slave(dev);
0877 
0878     return sprintf(buf, "0x%x\n", slave->cfam_id);
0879 }
0880 
0881 static DEVICE_ATTR_RO(cfam_id);
0882 
0883 static struct attribute *cfam_attr[] = {
0884     &dev_attr_send_echo_delays.attr,
0885     &dev_attr_chip_id.attr,
0886     &dev_attr_cfam_id.attr,
0887     &dev_attr_send_term.attr,
0888     NULL,
0889 };
0890 
0891 static const struct attribute_group cfam_attr_group = {
0892     .attrs = cfam_attr,
0893 };
0894 
0895 static const struct attribute_group *cfam_attr_groups[] = {
0896     &cfam_attr_group,
0897     NULL,
0898 };
0899 
0900 static char *cfam_devnode(struct device *dev, umode_t *mode,
0901               kuid_t *uid, kgid_t *gid)
0902 {
0903     struct fsi_slave *slave = to_fsi_slave(dev);
0904 
0905 #ifdef CONFIG_FSI_NEW_DEV_NODE
0906     return kasprintf(GFP_KERNEL, "fsi/cfam%d", slave->cdev_idx);
0907 #else
0908     return kasprintf(GFP_KERNEL, "cfam%d", slave->cdev_idx);
0909 #endif
0910 }
0911 
0912 static const struct device_type cfam_type = {
0913     .name = "cfam",
0914     .devnode = cfam_devnode,
0915     .groups = cfam_attr_groups
0916 };
0917 
0918 static char *fsi_cdev_devnode(struct device *dev, umode_t *mode,
0919                   kuid_t *uid, kgid_t *gid)
0920 {
0921 #ifdef CONFIG_FSI_NEW_DEV_NODE
0922     return kasprintf(GFP_KERNEL, "fsi/%s", dev_name(dev));
0923 #else
0924     return kasprintf(GFP_KERNEL, "%s", dev_name(dev));
0925 #endif
0926 }
0927 
0928 const struct device_type fsi_cdev_type = {
0929     .name = "fsi-cdev",
0930     .devnode = fsi_cdev_devnode,
0931 };
0932 EXPORT_SYMBOL_GPL(fsi_cdev_type);
0933 
0934 /* Backward compatible /dev/ numbering in "old style" mode */
0935 static int fsi_adjust_index(int index)
0936 {
0937 #ifdef CONFIG_FSI_NEW_DEV_NODE
0938     return index;
0939 #else
0940     return index + 1;
0941 #endif
0942 }
0943 
0944 static int __fsi_get_new_minor(struct fsi_slave *slave, enum fsi_dev_type type,
0945                    dev_t *out_dev, int *out_index)
0946 {
0947     int cid = slave->chip_id;
0948     int id;
0949 
0950     /* Check if we qualify for legacy numbering */
0951     if (cid >= 0 && cid < 16 && type < 4) {
0952         /* Try reserving the legacy number */
0953         id = (cid << 4) | type;
0954         id = ida_simple_get(&fsi_minor_ida, id, id + 1, GFP_KERNEL);
0955         if (id >= 0) {
0956             *out_index = fsi_adjust_index(cid);
0957             *out_dev = fsi_base_dev + id;
0958             return 0;
0959         }
0960         /* Other failure */
0961         if (id != -ENOSPC)
0962             return id;
0963         /* Fallback to non-legacy allocation */
0964     }
0965     id = ida_simple_get(&fsi_minor_ida, FSI_CHAR_LEGACY_TOP,
0966                 FSI_CHAR_MAX_DEVICES, GFP_KERNEL);
0967     if (id < 0)
0968         return id;
0969     *out_index = fsi_adjust_index(id);
0970     *out_dev = fsi_base_dev + id;
0971     return 0;
0972 }
0973 
0974 int fsi_get_new_minor(struct fsi_device *fdev, enum fsi_dev_type type,
0975               dev_t *out_dev, int *out_index)
0976 {
0977     return __fsi_get_new_minor(fdev->slave, type, out_dev, out_index);
0978 }
0979 EXPORT_SYMBOL_GPL(fsi_get_new_minor);
0980 
0981 void fsi_free_minor(dev_t dev)
0982 {
0983     ida_simple_remove(&fsi_minor_ida, MINOR(dev));
0984 }
0985 EXPORT_SYMBOL_GPL(fsi_free_minor);
0986 
0987 static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
0988 {
0989     uint32_t cfam_id;
0990     struct fsi_slave *slave;
0991     uint8_t crc;
0992     __be32 data, llmode, slbus;
0993     int rc;
0994 
0995     /* Currently, we only support single slaves on a link, and use the
0996      * full 23-bit address range
0997      */
0998     if (id != 0)
0999         return -EINVAL;
1000 
1001     rc = fsi_master_read(master, link, id, 0, &data, sizeof(data));
1002     if (rc) {
1003         dev_dbg(&master->dev, "can't read slave %02x:%02x %d\n",
1004                 link, id, rc);
1005         return -ENODEV;
1006     }
1007     cfam_id = be32_to_cpu(data);
1008 
1009     crc = crc4(0, cfam_id, 32);
1010     if (crc) {
1011         trace_fsi_slave_invalid_cfam(master, link, cfam_id);
1012         dev_warn(&master->dev, "slave %02x:%02x invalid cfam id CRC!\n",
1013                 link, id);
1014         return -EIO;
1015     }
1016 
1017     dev_dbg(&master->dev, "fsi: found chip %08x at %02x:%02x:%02x\n",
1018             cfam_id, master->idx, link, id);
1019 
1020     /* If we're behind a master that doesn't provide a self-running bus
1021      * clock, put the slave into async mode
1022      */
1023     if (master->flags & FSI_MASTER_FLAG_SWCLOCK) {
1024         llmode = cpu_to_be32(FSI_LLMODE_ASYNC);
1025         rc = fsi_master_write(master, link, id,
1026                 FSI_SLAVE_BASE + FSI_LLMODE,
1027                 &llmode, sizeof(llmode));
1028         if (rc)
1029             dev_warn(&master->dev,
1030                 "can't set llmode on slave:%02x:%02x %d\n",
1031                 link, id, rc);
1032     }
1033 
1034     /* We can communicate with a slave; create the slave device and
1035      * register.
1036      */
1037     slave = kzalloc(sizeof(*slave), GFP_KERNEL);
1038     if (!slave)
1039         return -ENOMEM;
1040 
1041     dev_set_name(&slave->dev, "slave@%02x:%02x", link, id);
1042     slave->dev.type = &cfam_type;
1043     slave->dev.parent = &master->dev;
1044     slave->dev.of_node = fsi_slave_find_of_node(master, link, id);
1045     slave->dev.release = fsi_slave_release;
1046     device_initialize(&slave->dev);
1047     slave->cfam_id = cfam_id;
1048     slave->master = master;
1049     slave->link = link;
1050     slave->id = id;
1051     slave->size = FSI_SLAVE_SIZE_23b;
1052     slave->t_send_delay = 16;
1053     slave->t_echo_delay = 16;
1054 
1055     /* Get chip ID if any */
1056     slave->chip_id = -1;
1057     if (slave->dev.of_node) {
1058         uint32_t prop;
1059         if (!of_property_read_u32(slave->dev.of_node, "chip-id", &prop))
1060             slave->chip_id = prop;
1061 
1062     }
1063 
1064     slbus = cpu_to_be32(FSI_SLBUS_FORCE);
1065     rc = fsi_master_write(master, link, id, FSI_SLAVE_BASE + FSI_SLBUS,
1066                   &slbus, sizeof(slbus));
1067     if (rc)
1068         dev_warn(&master->dev,
1069              "can't set slbus on slave:%02x:%02x %d\n", link, id,
1070              rc);
1071 
1072     rc = fsi_slave_set_smode(slave);
1073     if (rc) {
1074         dev_warn(&master->dev,
1075                 "can't set smode on slave:%02x:%02x %d\n",
1076                 link, id, rc);
1077         goto err_free;
1078     }
1079 
1080     /* Allocate a minor in the FSI space */
1081     rc = __fsi_get_new_minor(slave, fsi_dev_cfam, &slave->dev.devt,
1082                  &slave->cdev_idx);
1083     if (rc)
1084         goto err_free;
1085 
1086     trace_fsi_slave_init(slave);
1087 
1088     /* Create chardev for userspace access */
1089     cdev_init(&slave->cdev, &cfam_fops);
1090     rc = cdev_device_add(&slave->cdev, &slave->dev);
1091     if (rc) {
1092         dev_err(&slave->dev, "Error %d creating slave device\n", rc);
1093         goto err_free_ida;
1094     }
1095 
1096     /* Now that we have the cdev registered with the core, any fatal
1097      * failures beyond this point will need to clean up through
1098      * cdev_device_del(). Fortunately though, nothing past here is fatal.
1099      */
1100 
1101     if (master->link_config)
1102         master->link_config(master, link,
1103                     slave->t_send_delay,
1104                     slave->t_echo_delay);
1105 
1106     /* Legacy raw file -> to be removed */
1107     rc = device_create_bin_file(&slave->dev, &fsi_slave_raw_attr);
1108     if (rc)
1109         dev_warn(&slave->dev, "failed to create raw attr: %d\n", rc);
1110 
1111 
1112     rc = fsi_slave_scan(slave);
1113     if (rc)
1114         dev_dbg(&master->dev, "failed during slave scan with: %d\n",
1115                 rc);
1116 
1117     return 0;
1118 
1119 err_free_ida:
1120     fsi_free_minor(slave->dev.devt);
1121 err_free:
1122     of_node_put(slave->dev.of_node);
1123     kfree(slave);
1124     return rc;
1125 }
1126 
1127 /* FSI master support */
1128 static int fsi_check_access(uint32_t addr, size_t size)
1129 {
1130     if (size == 4) {
1131         if (addr & 0x3)
1132             return -EINVAL;
1133     } else if (size == 2) {
1134         if (addr & 0x1)
1135             return -EINVAL;
1136     } else if (size != 1)
1137         return -EINVAL;
1138 
1139     return 0;
1140 }
1141 
1142 static int fsi_master_read(struct fsi_master *master, int link,
1143         uint8_t slave_id, uint32_t addr, void *val, size_t size)
1144 {
1145     int rc;
1146 
1147     trace_fsi_master_read(master, link, slave_id, addr, size);
1148 
1149     rc = fsi_check_access(addr, size);
1150     if (!rc)
1151         rc = master->read(master, link, slave_id, addr, val, size);
1152 
1153     trace_fsi_master_rw_result(master, link, slave_id, addr, size,
1154             false, val, rc);
1155 
1156     return rc;
1157 }
1158 
1159 static int fsi_master_write(struct fsi_master *master, int link,
1160         uint8_t slave_id, uint32_t addr, const void *val, size_t size)
1161 {
1162     int rc;
1163 
1164     trace_fsi_master_write(master, link, slave_id, addr, size, val);
1165 
1166     rc = fsi_check_access(addr, size);
1167     if (!rc)
1168         rc = master->write(master, link, slave_id, addr, val, size);
1169 
1170     trace_fsi_master_rw_result(master, link, slave_id, addr, size,
1171             true, val, rc);
1172 
1173     return rc;
1174 }
1175 
1176 static int fsi_master_link_disable(struct fsi_master *master, int link)
1177 {
1178     if (master->link_enable)
1179         return master->link_enable(master, link, false);
1180 
1181     return 0;
1182 }
1183 
1184 static int fsi_master_link_enable(struct fsi_master *master, int link)
1185 {
1186     if (master->link_enable)
1187         return master->link_enable(master, link, true);
1188 
1189     return 0;
1190 }
1191 
1192 /*
1193  * Issue a break command on this link
1194  */
1195 static int fsi_master_break(struct fsi_master *master, int link)
1196 {
1197     int rc = 0;
1198 
1199     trace_fsi_master_break(master, link);
1200 
1201     if (master->send_break)
1202         rc = master->send_break(master, link);
1203     if (master->link_config)
1204         master->link_config(master, link, 16, 16);
1205 
1206     return rc;
1207 }
1208 
1209 static int fsi_master_scan(struct fsi_master *master)
1210 {
1211     int link, rc;
1212 
1213     for (link = 0; link < master->n_links; link++) {
1214         rc = fsi_master_link_enable(master, link);
1215         if (rc) {
1216             dev_dbg(&master->dev,
1217                 "enable link %d failed: %d\n", link, rc);
1218             continue;
1219         }
1220         rc = fsi_master_break(master, link);
1221         if (rc) {
1222             fsi_master_link_disable(master, link);
1223             dev_dbg(&master->dev,
1224                 "break to link %d failed: %d\n", link, rc);
1225             continue;
1226         }
1227 
1228         rc = fsi_slave_init(master, link, 0);
1229         if (rc)
1230             fsi_master_link_disable(master, link);
1231     }
1232 
1233     return 0;
1234 }
1235 
1236 static int fsi_slave_remove_device(struct device *dev, void *arg)
1237 {
1238     device_unregister(dev);
1239     return 0;
1240 }
1241 
1242 static int fsi_master_remove_slave(struct device *dev, void *arg)
1243 {
1244     struct fsi_slave *slave = to_fsi_slave(dev);
1245 
1246     device_for_each_child(dev, NULL, fsi_slave_remove_device);
1247     cdev_device_del(&slave->cdev, &slave->dev);
1248     put_device(dev);
1249     return 0;
1250 }
1251 
1252 static void fsi_master_unscan(struct fsi_master *master)
1253 {
1254     device_for_each_child(&master->dev, NULL, fsi_master_remove_slave);
1255 }
1256 
1257 int fsi_master_rescan(struct fsi_master *master)
1258 {
1259     int rc;
1260 
1261     mutex_lock(&master->scan_lock);
1262     fsi_master_unscan(master);
1263     rc = fsi_master_scan(master);
1264     mutex_unlock(&master->scan_lock);
1265 
1266     return rc;
1267 }
1268 EXPORT_SYMBOL_GPL(fsi_master_rescan);
1269 
1270 static ssize_t master_rescan_store(struct device *dev,
1271         struct device_attribute *attr, const char *buf, size_t count)
1272 {
1273     struct fsi_master *master = to_fsi_master(dev);
1274     int rc;
1275 
1276     rc = fsi_master_rescan(master);
1277     if (rc < 0)
1278         return rc;
1279 
1280     return count;
1281 }
1282 
1283 static DEVICE_ATTR(rescan, 0200, NULL, master_rescan_store);
1284 
1285 static ssize_t master_break_store(struct device *dev,
1286         struct device_attribute *attr, const char *buf, size_t count)
1287 {
1288     struct fsi_master *master = to_fsi_master(dev);
1289 
1290     fsi_master_break(master, 0);
1291 
1292     return count;
1293 }
1294 
1295 static DEVICE_ATTR(break, 0200, NULL, master_break_store);
1296 
1297 static struct attribute *master_attrs[] = {
1298     &dev_attr_break.attr,
1299     &dev_attr_rescan.attr,
1300     NULL
1301 };
1302 
1303 ATTRIBUTE_GROUPS(master);
1304 
1305 static struct class fsi_master_class = {
1306     .name = "fsi-master",
1307     .dev_groups = master_groups,
1308 };
1309 
1310 int fsi_master_register(struct fsi_master *master)
1311 {
1312     int rc;
1313     struct device_node *np;
1314 
1315     mutex_init(&master->scan_lock);
1316     master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
1317     dev_set_name(&master->dev, "fsi%d", master->idx);
1318     master->dev.class = &fsi_master_class;
1319 
1320     rc = device_register(&master->dev);
1321     if (rc) {
1322         ida_simple_remove(&master_ida, master->idx);
1323         return rc;
1324     }
1325 
1326     np = dev_of_node(&master->dev);
1327     if (!of_property_read_bool(np, "no-scan-on-init")) {
1328         mutex_lock(&master->scan_lock);
1329         fsi_master_scan(master);
1330         mutex_unlock(&master->scan_lock);
1331     }
1332 
1333     return 0;
1334 }
1335 EXPORT_SYMBOL_GPL(fsi_master_register);
1336 
1337 void fsi_master_unregister(struct fsi_master *master)
1338 {
1339     if (master->idx >= 0) {
1340         ida_simple_remove(&master_ida, master->idx);
1341         master->idx = -1;
1342     }
1343 
1344     mutex_lock(&master->scan_lock);
1345     fsi_master_unscan(master);
1346     mutex_unlock(&master->scan_lock);
1347     device_unregister(&master->dev);
1348 }
1349 EXPORT_SYMBOL_GPL(fsi_master_unregister);
1350 
1351 /* FSI core & Linux bus type definitions */
1352 
1353 static int fsi_bus_match(struct device *dev, struct device_driver *drv)
1354 {
1355     struct fsi_device *fsi_dev = to_fsi_dev(dev);
1356     struct fsi_driver *fsi_drv = to_fsi_drv(drv);
1357     const struct fsi_device_id *id;
1358 
1359     if (!fsi_drv->id_table)
1360         return 0;
1361 
1362     for (id = fsi_drv->id_table; id->engine_type; id++) {
1363         if (id->engine_type != fsi_dev->engine_type)
1364             continue;
1365         if (id->version == FSI_VERSION_ANY ||
1366                 id->version == fsi_dev->version)
1367             return 1;
1368     }
1369 
1370     return 0;
1371 }
1372 
1373 int fsi_driver_register(struct fsi_driver *fsi_drv)
1374 {
1375     if (!fsi_drv)
1376         return -EINVAL;
1377     if (!fsi_drv->id_table)
1378         return -EINVAL;
1379 
1380     return driver_register(&fsi_drv->drv);
1381 }
1382 EXPORT_SYMBOL_GPL(fsi_driver_register);
1383 
1384 void fsi_driver_unregister(struct fsi_driver *fsi_drv)
1385 {
1386     driver_unregister(&fsi_drv->drv);
1387 }
1388 EXPORT_SYMBOL_GPL(fsi_driver_unregister);
1389 
1390 struct bus_type fsi_bus_type = {
1391     .name       = "fsi",
1392     .match      = fsi_bus_match,
1393 };
1394 EXPORT_SYMBOL_GPL(fsi_bus_type);
1395 
1396 static int __init fsi_init(void)
1397 {
1398     int rc;
1399 
1400     rc = alloc_chrdev_region(&fsi_base_dev, 0, FSI_CHAR_MAX_DEVICES, "fsi");
1401     if (rc)
1402         return rc;
1403     rc = bus_register(&fsi_bus_type);
1404     if (rc)
1405         goto fail_bus;
1406 
1407     rc = class_register(&fsi_master_class);
1408     if (rc)
1409         goto fail_class;
1410 
1411     return 0;
1412 
1413  fail_class:
1414     bus_unregister(&fsi_bus_type);
1415  fail_bus:
1416     unregister_chrdev_region(fsi_base_dev, FSI_CHAR_MAX_DEVICES);
1417     return rc;
1418 }
1419 postcore_initcall(fsi_init);
1420 
1421 static void fsi_exit(void)
1422 {
1423     class_unregister(&fsi_master_class);
1424     bus_unregister(&fsi_bus_type);
1425     unregister_chrdev_region(fsi_base_dev, FSI_CHAR_MAX_DEVICES);
1426     ida_destroy(&fsi_minor_ida);
1427 }
1428 module_exit(fsi_exit);
1429 module_param(discard_errors, int, 0664);
1430 MODULE_LICENSE("GPL");
1431 MODULE_PARM_DESC(discard_errors, "Don't invoke error handling on bus accesses");