Lines Matching +full:slave +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-only
8 * - Rework topology
9 * - s/chip_id/chip_loc
10 * - s/cfam/chip (cfam_id -> chip_id etc...)
25 #include "fsi-master.h"
45 * FSI slave engine control register offsets
47 #define FSI_SMODE 0x0 /* R/W: Mode register */
49 #define FSI_SSTAT 0x14 /* R : Slave status */
51 #define FSI_LLMODE 0x100 /* R/W: Link layer mode register */
90 uint32_t size; /* size of slave address space */
120 * FSI endpoint-device support
137 if (addr > dev->size || size > dev->size || addr > dev->size - size) in fsi_device_read()
138 return -EINVAL; in fsi_device_read()
140 return fsi_slave_read(dev->slave, dev->addr + addr, val, size); in fsi_device_read()
147 if (addr > dev->size || size > dev->size || addr > dev->size - size) in fsi_device_write()
148 return -EINVAL; in fsi_device_write()
150 return fsi_slave_write(dev->slave, dev->addr + addr, val, size); in fsi_device_write()
156 uint32_t addr = FSI_PEEK_BASE + ((dev->unit - 2) * sizeof(uint32_t)); in fsi_device_peek()
158 return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t)); in fsi_device_peek()
165 of_node_put(device->dev.of_node); in fsi_device_release()
169 static struct fsi_device *fsi_create_device(struct fsi_slave *slave) in fsi_create_device() argument
177 dev->dev.parent = &slave->dev; in fsi_create_device()
178 dev->dev.bus = &fsi_bus_type; in fsi_create_device()
179 dev->dev.release = fsi_device_release; in fsi_create_device()
184 /* FSI slave support */
185 static int fsi_slave_calc_addr(struct fsi_slave *slave, uint32_t *addrp, in fsi_slave_calc_addr() argument
191 if (addr > slave->size) in fsi_slave_calc_addr()
192 return -EINVAL; in fsi_slave_calc_addr()
194 /* For 23 bit addressing, we encode the extra two bits in the slave in fsi_slave_calc_addr()
195 * id (and the slave's actual ID needs to be 0). in fsi_slave_calc_addr()
198 if (slave->id != 0) in fsi_slave_calc_addr()
199 return -EINVAL; in fsi_slave_calc_addr()
209 static int fsi_slave_report_and_clear_errors(struct fsi_slave *slave) in fsi_slave_report_and_clear_errors() argument
211 struct fsi_master *master = slave->master; in fsi_slave_report_and_clear_errors()
216 link = slave->link; in fsi_slave_report_and_clear_errors()
217 id = slave->id; in fsi_slave_report_and_clear_errors()
229 dev_dbg(&slave->dev, "status: 0x%08x, sisc: 0x%08x\n", in fsi_slave_report_and_clear_errors()
237 /* Encode slave local bus echo delay */
243 /* Encode slave local bus send delay */
249 /* Encode slave local bus clock rate ratio */
255 /* Encode slave ID */
265 | fsi_smode_echodly(t_echodly - 1) | fsi_smode_senddly(t_senddly - 1) in fsi_slave_smode()
269 static int fsi_slave_set_smode(struct fsi_slave *slave) in fsi_slave_set_smode() argument
274 /* set our smode register with the slave ID field to 0; this enables in fsi_slave_set_smode()
275 * extended slave addressing in fsi_slave_set_smode()
277 smode = fsi_slave_smode(slave->id, slave->t_send_delay, slave->t_echo_delay); in fsi_slave_set_smode()
280 return fsi_master_write(slave->master, slave->link, slave->id, in fsi_slave_set_smode()
285 static int fsi_slave_handle_error(struct fsi_slave *slave, bool write, in fsi_slave_handle_error() argument
288 struct fsi_master *master = slave->master; in fsi_slave_handle_error()
294 return -1; in fsi_slave_handle_error()
296 link = slave->link; in fsi_slave_handle_error()
297 id = slave->id; in fsi_slave_handle_error()
299 dev_dbg(&slave->dev, "handling error on %s to 0x%08x[%zd]", in fsi_slave_handle_error()
303 * communication with the slave in fsi_slave_handle_error()
305 rc = fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
310 if (master->term) { in fsi_slave_handle_error()
311 rc = master->term(master, link, id); in fsi_slave_handle_error()
316 rc = fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
322 send_delay = slave->t_send_delay; in fsi_slave_handle_error()
323 echo_delay = slave->t_echo_delay; in fsi_slave_handle_error()
325 /* getting serious, reset the slave via BREAK */ in fsi_slave_handle_error()
330 slave->t_send_delay = send_delay; in fsi_slave_handle_error()
331 slave->t_echo_delay = echo_delay; in fsi_slave_handle_error()
333 rc = fsi_slave_set_smode(slave); in fsi_slave_handle_error()
337 if (master->link_config) in fsi_slave_handle_error()
338 master->link_config(master, link, in fsi_slave_handle_error()
339 slave->t_send_delay, in fsi_slave_handle_error()
340 slave->t_echo_delay); in fsi_slave_handle_error()
342 return fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
345 int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, in fsi_slave_read() argument
348 uint8_t id = slave->id; in fsi_slave_read()
351 rc = fsi_slave_calc_addr(slave, &addr, &id); in fsi_slave_read()
356 rc = fsi_master_read(slave->master, slave->link, in fsi_slave_read()
361 err_rc = fsi_slave_handle_error(slave, false, addr, size); in fsi_slave_read()
370 int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, in fsi_slave_write() argument
373 uint8_t id = slave->id; in fsi_slave_write()
376 rc = fsi_slave_calc_addr(slave, &addr, &id); in fsi_slave_write()
381 rc = fsi_master_write(slave->master, slave->link, in fsi_slave_write()
386 err_rc = fsi_slave_handle_error(slave, true, addr, size); in fsi_slave_write()
395 int fsi_slave_claim_range(struct fsi_slave *slave, in fsi_slave_claim_range() argument
399 return -EINVAL; in fsi_slave_claim_range()
401 if (addr + size > slave->size) in fsi_slave_claim_range()
402 return -EINVAL; in fsi_slave_claim_range()
409 void fsi_slave_release_range(struct fsi_slave *slave, in fsi_slave_release_range() argument
445 /* Find a matching node for the slave engine at @address, using @size bytes
453 parent = dev_of_node(&dev->slave->dev); in fsi_device_find_of_node()
458 if (fsi_device_node_matches(&dev->dev, np, in fsi_device_find_of_node()
459 dev->addr, dev->size)) in fsi_device_find_of_node()
466 static int fsi_slave_scan(struct fsi_slave *slave) in fsi_slave_scan() argument
474 * We keep the peek mode and slave engines for the core; so start in fsi_slave_scan()
485 rc = fsi_slave_read(slave, (i + 1) * sizeof(data), in fsi_slave_scan()
488 dev_warn(&slave->dev, in fsi_slave_scan()
489 "error reading slave registers\n"); in fsi_slave_scan()
490 return -1; in fsi_slave_scan()
496 dev_warn(&slave->dev, in fsi_slave_scan()
497 "crc error in slave register at 0x%04x\n", in fsi_slave_scan()
499 return -1; in fsi_slave_scan()
516 dev = fsi_create_device(slave); in fsi_slave_scan()
518 return -ENOMEM; in fsi_slave_scan()
520 dev->slave = slave; in fsi_slave_scan()
521 dev->engine_type = type; in fsi_slave_scan()
522 dev->version = version; in fsi_slave_scan()
523 dev->unit = i; in fsi_slave_scan()
524 dev->addr = engine_addr; in fsi_slave_scan()
525 dev->size = slots * engine_page_size; in fsi_slave_scan()
529 dev_dbg(&slave->dev, in fsi_slave_scan()
531 dev->unit, dev->engine_type, version, in fsi_slave_scan()
532 dev->addr, dev->size); in fsi_slave_scan()
534 dev_set_name(&dev->dev, "%02x:%02x:%02x:%02x", in fsi_slave_scan()
535 slave->master->idx, slave->link, in fsi_slave_scan()
536 slave->id, i - 2); in fsi_slave_scan()
537 dev->dev.of_node = fsi_device_find_of_node(dev); in fsi_slave_scan()
539 rc = device_register(&dev->dev); in fsi_slave_scan()
541 dev_warn(&slave->dev, "add failed: %d\n", rc); in fsi_slave_scan()
542 put_device(&dev->dev); in fsi_slave_scan()
562 * width or the highest power-of-two factor of offset in aligned_access_size()
574 count_unit = BIT(8 * sizeof(unsigned long) - 1 - __builtin_clzl(count)); in aligned_access_size()
584 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj)); in fsi_slave_sysfs_raw_read() local
589 return -EINVAL; in fsi_slave_sysfs_raw_read()
592 return -EINVAL; in fsi_slave_sysfs_raw_read()
595 read_len = aligned_access_size(off, count - total_len); in fsi_slave_sysfs_raw_read()
597 rc = fsi_slave_read(slave, off, buf + total_len, read_len); in fsi_slave_sysfs_raw_read()
611 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj)); in fsi_slave_sysfs_raw_write() local
616 return -EINVAL; in fsi_slave_sysfs_raw_write()
619 return -EINVAL; in fsi_slave_sysfs_raw_write()
622 write_len = aligned_access_size(off, count - total_len); in fsi_slave_sysfs_raw_write()
624 rc = fsi_slave_write(slave, off, buf + total_len, write_len); in fsi_slave_sysfs_raw_write()
637 .mode = 0600,
646 struct fsi_slave *slave = to_fsi_slave(dev); in fsi_slave_release() local
648 fsi_free_minor(slave->dev.devt); in fsi_slave_release()
649 of_node_put(dev->of_node); in fsi_slave_release()
650 kfree(slave); in fsi_slave_release()
676 /* Find a matching node for the slave at (link, id). Returns NULL if none
684 parent = dev_of_node(&master->dev); in fsi_slave_find_of_node()
699 struct fsi_slave *slave = filep->private_data; in cfam_read() local
705 return -EINVAL; in cfam_read()
708 return -EINVAL; in cfam_read()
714 read_len -= off & 0x3; in cfam_read()
716 rc = fsi_slave_read(slave, off, &data, read_len); in cfam_read()
721 rc = -EFAULT; in cfam_read()
735 struct fsi_slave *slave = filep->private_data; in cfam_write() local
742 return -EINVAL; in cfam_write()
745 return -EINVAL; in cfam_write()
751 write_len -= off & 0x3; in cfam_write()
755 rc = -EFAULT; in cfam_write()
758 rc = fsi_slave_write(slave, off, &data, write_len); in cfam_write()
775 file->f_pos = offset; in cfam_llseek()
778 return -EINVAL; in cfam_llseek()
786 struct fsi_slave *slave = container_of(inode->i_cdev, struct fsi_slave, cdev); in cfam_open() local
788 file->private_data = slave; in cfam_open()
805 struct fsi_slave *slave = to_fsi_slave(dev); in send_term_store() local
806 struct fsi_master *master = slave->master; in send_term_store()
808 if (!master->term) in send_term_store()
809 return -ENODEV; in send_term_store()
811 master->term(master, slave->link, slave->id); in send_term_store()
821 struct fsi_slave *slave = to_fsi_slave(dev); in slave_send_echo_show() local
823 return sprintf(buf, "%u\n", slave->t_send_delay); in slave_send_echo_show()
829 struct fsi_slave *slave = to_fsi_slave(dev); in slave_send_echo_store() local
830 struct fsi_master *master = slave->master; in slave_send_echo_store()
835 return -EINVAL; in slave_send_echo_store()
838 return -EINVAL; in slave_send_echo_store()
840 if (!master->link_config) in slave_send_echo_store()
841 return -ENXIO; in slave_send_echo_store()
844 slave->t_send_delay = val; in slave_send_echo_store()
845 slave->t_echo_delay = val; in slave_send_echo_store()
847 rc = fsi_slave_set_smode(slave); in slave_send_echo_store()
850 if (master->link_config) in slave_send_echo_store()
851 master->link_config(master, slave->link, in slave_send_echo_store()
852 slave->t_send_delay, in slave_send_echo_store()
853 slave->t_echo_delay); in slave_send_echo_store()
865 struct fsi_slave *slave = to_fsi_slave(dev); in chip_id_show() local
867 return sprintf(buf, "%d\n", slave->chip_id); in chip_id_show()
876 struct fsi_slave *slave = to_fsi_slave(dev); in cfam_id_show() local
878 return sprintf(buf, "0x%x\n", slave->cfam_id); in cfam_id_show()
900 static char *cfam_devnode(struct device *dev, umode_t *mode, in cfam_devnode() argument
903 struct fsi_slave *slave = to_fsi_slave(dev); in cfam_devnode() local
906 return kasprintf(GFP_KERNEL, "fsi/cfam%d", slave->cdev_idx); in cfam_devnode()
908 return kasprintf(GFP_KERNEL, "cfam%d", slave->cdev_idx); in cfam_devnode()
918 static char *fsi_cdev_devnode(struct device *dev, umode_t *mode, in fsi_cdev_devnode() argument
929 .name = "fsi-cdev",
934 /* Backward compatible /dev/ numbering in "old style" mode */
944 static int __fsi_get_new_minor(struct fsi_slave *slave, enum fsi_dev_type type, in __fsi_get_new_minor() argument
947 int cid = slave->chip_id; in __fsi_get_new_minor()
961 if (id != -ENOSPC) in __fsi_get_new_minor()
963 /* Fallback to non-legacy allocation */ in __fsi_get_new_minor()
977 return __fsi_get_new_minor(fdev->slave, type, out_dev, out_index); in fsi_get_new_minor()
990 struct fsi_slave *slave; in fsi_slave_init() local
996 * full 23-bit address range in fsi_slave_init()
999 return -EINVAL; in fsi_slave_init()
1003 dev_dbg(&master->dev, "can't read slave %02x:%02x %d\n", in fsi_slave_init()
1005 return -ENODEV; in fsi_slave_init()
1012 dev_warn(&master->dev, "slave %02x:%02x invalid cfam id CRC!\n", in fsi_slave_init()
1014 return -EIO; in fsi_slave_init()
1017 dev_dbg(&master->dev, "fsi: found chip %08x at %02x:%02x:%02x\n", in fsi_slave_init()
1018 cfam_id, master->idx, link, id); in fsi_slave_init()
1020 /* If we're behind a master that doesn't provide a self-running bus in fsi_slave_init()
1021 * clock, put the slave into async mode in fsi_slave_init()
1023 if (master->flags & FSI_MASTER_FLAG_SWCLOCK) { in fsi_slave_init()
1029 dev_warn(&master->dev, in fsi_slave_init()
1030 "can't set llmode on slave:%02x:%02x %d\n", in fsi_slave_init()
1034 /* We can communicate with a slave; create the slave device and in fsi_slave_init()
1037 slave = kzalloc(sizeof(*slave), GFP_KERNEL); in fsi_slave_init()
1038 if (!slave) in fsi_slave_init()
1039 return -ENOMEM; in fsi_slave_init()
1041 dev_set_name(&slave->dev, "slave@%02x:%02x", link, id); in fsi_slave_init()
1042 slave->dev.type = &cfam_type; in fsi_slave_init()
1043 slave->dev.parent = &master->dev; in fsi_slave_init()
1044 slave->dev.of_node = fsi_slave_find_of_node(master, link, id); in fsi_slave_init()
1045 slave->dev.release = fsi_slave_release; in fsi_slave_init()
1046 device_initialize(&slave->dev); in fsi_slave_init()
1047 slave->cfam_id = cfam_id; in fsi_slave_init()
1048 slave->master = master; in fsi_slave_init()
1049 slave->link = link; in fsi_slave_init()
1050 slave->id = id; in fsi_slave_init()
1051 slave->size = FSI_SLAVE_SIZE_23b; in fsi_slave_init()
1052 slave->t_send_delay = 16; in fsi_slave_init()
1053 slave->t_echo_delay = 16; in fsi_slave_init()
1056 slave->chip_id = -1; in fsi_slave_init()
1057 if (slave->dev.of_node) { in fsi_slave_init()
1059 if (!of_property_read_u32(slave->dev.of_node, "chip-id", &prop)) in fsi_slave_init()
1060 slave->chip_id = prop; in fsi_slave_init()
1068 dev_warn(&master->dev, in fsi_slave_init()
1069 "can't set slbus on slave:%02x:%02x %d\n", link, id, in fsi_slave_init()
1072 rc = fsi_slave_set_smode(slave); in fsi_slave_init()
1074 dev_warn(&master->dev, in fsi_slave_init()
1075 "can't set smode on slave:%02x:%02x %d\n", in fsi_slave_init()
1081 rc = __fsi_get_new_minor(slave, fsi_dev_cfam, &slave->dev.devt, in fsi_slave_init()
1082 &slave->cdev_idx); in fsi_slave_init()
1086 trace_fsi_slave_init(slave); in fsi_slave_init()
1089 cdev_init(&slave->cdev, &cfam_fops); in fsi_slave_init()
1090 rc = cdev_device_add(&slave->cdev, &slave->dev); in fsi_slave_init()
1092 dev_err(&slave->dev, "Error %d creating slave device\n", rc); in fsi_slave_init()
1101 if (master->link_config) in fsi_slave_init()
1102 master->link_config(master, link, in fsi_slave_init()
1103 slave->t_send_delay, in fsi_slave_init()
1104 slave->t_echo_delay); in fsi_slave_init()
1106 /* Legacy raw file -> to be removed */ in fsi_slave_init()
1107 rc = device_create_bin_file(&slave->dev, &fsi_slave_raw_attr); in fsi_slave_init()
1109 dev_warn(&slave->dev, "failed to create raw attr: %d\n", rc); in fsi_slave_init()
1112 rc = fsi_slave_scan(slave); in fsi_slave_init()
1114 dev_dbg(&master->dev, "failed during slave scan with: %d\n", in fsi_slave_init()
1120 fsi_free_minor(slave->dev.devt); in fsi_slave_init()
1122 of_node_put(slave->dev.of_node); in fsi_slave_init()
1123 kfree(slave); in fsi_slave_init()
1132 return -EINVAL; in fsi_check_access()
1135 return -EINVAL; in fsi_check_access()
1137 return -EINVAL; in fsi_check_access()
1151 rc = master->read(master, link, slave_id, addr, val, size); in fsi_master_read()
1168 rc = master->write(master, link, slave_id, addr, val, size); in fsi_master_write()
1178 if (master->link_enable) in fsi_master_link_disable()
1179 return master->link_enable(master, link, false); in fsi_master_link_disable()
1186 if (master->link_enable) in fsi_master_link_enable()
1187 return master->link_enable(master, link, true); in fsi_master_link_enable()
1201 if (master->send_break) in fsi_master_break()
1202 rc = master->send_break(master, link); in fsi_master_break()
1203 if (master->link_config) in fsi_master_break()
1204 master->link_config(master, link, 16, 16); in fsi_master_break()
1213 for (link = 0; link < master->n_links; link++) { in fsi_master_scan()
1216 dev_dbg(&master->dev, in fsi_master_scan()
1223 dev_dbg(&master->dev, in fsi_master_scan()
1244 struct fsi_slave *slave = to_fsi_slave(dev); in fsi_master_remove_slave() local
1247 cdev_device_del(&slave->cdev, &slave->dev); in fsi_master_remove_slave()
1254 device_for_each_child(&master->dev, NULL, fsi_master_remove_slave); in fsi_master_unscan()
1261 mutex_lock(&master->scan_lock); in fsi_master_rescan()
1264 mutex_unlock(&master->scan_lock); in fsi_master_rescan()
1306 .name = "fsi-master",
1315 mutex_init(&master->scan_lock); in fsi_master_register()
1316 master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL); in fsi_master_register()
1317 if (master->idx < 0) in fsi_master_register()
1318 return master->idx; in fsi_master_register()
1320 dev_set_name(&master->dev, "fsi%d", master->idx); in fsi_master_register()
1321 master->dev.class = &fsi_master_class; in fsi_master_register()
1323 rc = device_register(&master->dev); in fsi_master_register()
1325 ida_simple_remove(&master_ida, master->idx); in fsi_master_register()
1329 np = dev_of_node(&master->dev); in fsi_master_register()
1330 if (!of_property_read_bool(np, "no-scan-on-init")) { in fsi_master_register()
1331 mutex_lock(&master->scan_lock); in fsi_master_register()
1333 mutex_unlock(&master->scan_lock); in fsi_master_register()
1342 if (master->idx >= 0) { in fsi_master_unregister()
1343 ida_simple_remove(&master_ida, master->idx); in fsi_master_unregister()
1344 master->idx = -1; in fsi_master_unregister()
1347 mutex_lock(&master->scan_lock); in fsi_master_unregister()
1349 mutex_unlock(&master->scan_lock); in fsi_master_unregister()
1350 device_unregister(&master->dev); in fsi_master_unregister()
1362 if (!fsi_drv->id_table) in fsi_bus_match()
1365 for (id = fsi_drv->id_table; id->engine_type; id++) { in fsi_bus_match()
1366 if (id->engine_type != fsi_dev->engine_type) in fsi_bus_match()
1368 if (id->version == FSI_VERSION_ANY || in fsi_bus_match()
1369 id->version == fsi_dev->version) in fsi_bus_match()
1379 return -EINVAL; in fsi_driver_register()
1380 if (!fsi_drv->id_table) in fsi_driver_register()
1381 return -EINVAL; in fsi_driver_register()
1383 return driver_register(&fsi_drv->drv); in fsi_driver_register()
1389 driver_unregister(&fsi_drv->drv); in fsi_driver_unregister()