Lines Matching full:slave
28 #include "fsi-slave.h"
51 * FSI slave engine control register offsets
55 #define FSI_SSTAT 0x14 /* R : Slave status */
126 return fsi_slave_read(dev->slave, dev->addr + addr, val, size); in fsi_device_read()
136 return fsi_slave_write(dev->slave, dev->addr + addr, val, size); in fsi_device_write()
144 return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t)); in fsi_device_peek()
155 static struct fsi_device *fsi_create_device(struct fsi_slave *slave) in fsi_create_device() argument
163 dev->dev.parent = &slave->dev; in fsi_create_device()
170 /* FSI slave support */
171 static int fsi_slave_calc_addr(struct fsi_slave *slave, uint32_t *addrp, in fsi_slave_calc_addr() argument
177 if (addr > slave->size) in fsi_slave_calc_addr()
180 /* For 23 bit addressing, we encode the extra two bits in the slave in fsi_slave_calc_addr()
181 * id (and the slave's actual ID needs to be 0). in fsi_slave_calc_addr()
184 if (slave->id != 0) in fsi_slave_calc_addr()
195 static int fsi_slave_report_and_clear_errors(struct fsi_slave *slave) in fsi_slave_report_and_clear_errors() argument
197 struct fsi_master *master = slave->master; in fsi_slave_report_and_clear_errors()
202 link = slave->link; in fsi_slave_report_and_clear_errors()
203 id = slave->id; in fsi_slave_report_and_clear_errors()
215 dev_dbg(&slave->dev, "status: 0x%08x, sisc: 0x%08x\n", in fsi_slave_report_and_clear_errors()
223 /* Encode slave local bus echo delay */
229 /* Encode slave local bus send delay */
235 /* Encode slave local bus clock rate ratio */
241 /* Encode slave ID */
255 static int fsi_slave_set_smode(struct fsi_slave *slave) in fsi_slave_set_smode() argument
260 /* set our smode register with the slave ID field to 0; this enables in fsi_slave_set_smode()
261 * extended slave addressing in fsi_slave_set_smode()
263 smode = fsi_slave_smode(slave->id, slave->t_send_delay, slave->t_echo_delay); in fsi_slave_set_smode()
266 return fsi_master_write(slave->master, slave->link, slave->id, in fsi_slave_set_smode()
271 static int fsi_slave_handle_error(struct fsi_slave *slave, bool write, in fsi_slave_handle_error() argument
274 struct fsi_master *master = slave->master; in fsi_slave_handle_error()
282 link = slave->link; in fsi_slave_handle_error()
283 id = slave->id; in fsi_slave_handle_error()
285 dev_dbg(&slave->dev, "handling error on %s to 0x%08x[%zd]", in fsi_slave_handle_error()
289 * communication with the slave in fsi_slave_handle_error()
291 rc = fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
302 rc = fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
308 send_delay = slave->t_send_delay; in fsi_slave_handle_error()
309 echo_delay = slave->t_echo_delay; in fsi_slave_handle_error()
311 /* getting serious, reset the slave via BREAK */ in fsi_slave_handle_error()
316 slave->t_send_delay = send_delay; in fsi_slave_handle_error()
317 slave->t_echo_delay = echo_delay; in fsi_slave_handle_error()
319 rc = fsi_slave_set_smode(slave); in fsi_slave_handle_error()
325 slave->t_send_delay, in fsi_slave_handle_error()
326 slave->t_echo_delay); in fsi_slave_handle_error()
328 return fsi_slave_report_and_clear_errors(slave); in fsi_slave_handle_error()
331 int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, in fsi_slave_read() argument
334 uint8_t id = slave->id; in fsi_slave_read()
337 rc = fsi_slave_calc_addr(slave, &addr, &id); in fsi_slave_read()
342 rc = fsi_master_read(slave->master, slave->link, in fsi_slave_read()
347 err_rc = fsi_slave_handle_error(slave, false, addr, size); in fsi_slave_read()
356 int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, in fsi_slave_write() argument
359 uint8_t id = slave->id; in fsi_slave_write()
362 rc = fsi_slave_calc_addr(slave, &addr, &id); in fsi_slave_write()
367 rc = fsi_master_write(slave->master, slave->link, in fsi_slave_write()
372 err_rc = fsi_slave_handle_error(slave, true, addr, size); in fsi_slave_write()
381 int fsi_slave_claim_range(struct fsi_slave *slave, in fsi_slave_claim_range() argument
387 if (addr + size > slave->size) in fsi_slave_claim_range()
395 void fsi_slave_release_range(struct fsi_slave *slave, in fsi_slave_release_range() argument
421 /* Find a matching node for the slave engine at @address, using @size bytes
429 parent = dev_of_node(&dev->slave->dev); in fsi_device_find_of_node()
442 static int fsi_slave_scan(struct fsi_slave *slave) in fsi_slave_scan() argument
450 * We keep the peek mode and slave engines for the core; so start in fsi_slave_scan()
461 rc = fsi_slave_read(slave, (i + 1) * sizeof(data), in fsi_slave_scan()
464 dev_warn(&slave->dev, in fsi_slave_scan()
465 "error reading slave registers\n"); in fsi_slave_scan()
472 dev_warn(&slave->dev, in fsi_slave_scan()
473 "crc error in slave register at 0x%04x\n", in fsi_slave_scan()
492 dev = fsi_create_device(slave); in fsi_slave_scan()
496 dev->slave = slave; in fsi_slave_scan()
505 dev_dbg(&slave->dev, in fsi_slave_scan()
511 slave->master->idx, slave->link, in fsi_slave_scan()
512 slave->id, i - 2); in fsi_slave_scan()
517 dev_warn(&slave->dev, "add failed: %d\n", rc); in fsi_slave_scan()
560 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj)); in fsi_slave_sysfs_raw_read() local
573 rc = fsi_slave_read(slave, off, buf + total_len, read_len); in fsi_slave_sysfs_raw_read()
587 struct fsi_slave *slave = to_fsi_slave(kobj_to_dev(kobj)); in fsi_slave_sysfs_raw_write() local
600 rc = fsi_slave_write(slave, off, buf + total_len, write_len); in fsi_slave_sysfs_raw_write()
622 struct fsi_slave *slave = to_fsi_slave(dev); in fsi_slave_release() local
624 fsi_free_minor(slave->dev.devt); in fsi_slave_release()
626 kfree(slave); in fsi_slave_release()
640 /* Find a matching node for the slave at (link, id). Returns NULL if none
663 struct fsi_slave *slave = filep->private_data; in cfam_read() local
680 rc = fsi_slave_read(slave, off, &data, read_len); in cfam_read()
699 struct fsi_slave *slave = filep->private_data; in cfam_write() local
722 rc = fsi_slave_write(slave, off, &data, write_len); in cfam_write()
750 struct fsi_slave *slave = container_of(inode->i_cdev, struct fsi_slave, cdev); in cfam_open() local
752 file->private_data = slave; in cfam_open()
769 struct fsi_slave *slave = to_fsi_slave(dev); in send_term_store() local
770 struct fsi_master *master = slave->master; in send_term_store()
775 master->term(master, slave->link, slave->id); in send_term_store()
785 struct fsi_slave *slave = to_fsi_slave(dev); in slave_send_echo_show() local
787 return sprintf(buf, "%u\n", slave->t_send_delay); in slave_send_echo_show()
793 struct fsi_slave *slave = to_fsi_slave(dev); in slave_send_echo_store() local
794 struct fsi_master *master = slave->master; in slave_send_echo_store()
808 slave->t_send_delay = val; in slave_send_echo_store()
809 slave->t_echo_delay = val; in slave_send_echo_store()
811 rc = fsi_slave_set_smode(slave); in slave_send_echo_store()
815 master->link_config(master, slave->link, in slave_send_echo_store()
816 slave->t_send_delay, in slave_send_echo_store()
817 slave->t_echo_delay); in slave_send_echo_store()
829 struct fsi_slave *slave = to_fsi_slave(dev); in chip_id_show() local
831 return sprintf(buf, "%d\n", slave->chip_id); in chip_id_show()
840 struct fsi_slave *slave = to_fsi_slave(dev); in cfam_id_show() local
842 return sprintf(buf, "0x%x\n", slave->cfam_id); in cfam_id_show()
867 const struct fsi_slave *slave = to_fsi_slave(dev); in cfam_devnode() local
870 return kasprintf(GFP_KERNEL, "fsi/cfam%d", slave->cdev_idx); in cfam_devnode()
872 return kasprintf(GFP_KERNEL, "cfam%d", slave->cdev_idx); in cfam_devnode()
908 static int __fsi_get_new_minor(struct fsi_slave *slave, enum fsi_dev_type type, in __fsi_get_new_minor() argument
911 int cid = slave->chip_id; in __fsi_get_new_minor()
971 return __fsi_get_new_minor(fdev->slave, type, out_dev, out_index); in fsi_get_new_minor()
984 struct fsi_slave *slave; in fsi_slave_init() local
997 dev_dbg(&master->dev, "can't read slave %02x:%02x %d\n", in fsi_slave_init()
1006 dev_warn(&master->dev, "slave %02x:%02x invalid cfam id CRC!\n", in fsi_slave_init()
1015 * clock, put the slave into async mode in fsi_slave_init()
1024 "can't set llmode on slave:%02x:%02x %d\n", in fsi_slave_init()
1028 /* We can communicate with a slave; create the slave device and in fsi_slave_init()
1031 slave = kzalloc(sizeof(*slave), GFP_KERNEL); in fsi_slave_init()
1032 if (!slave) in fsi_slave_init()
1035 dev_set_name(&slave->dev, "slave@%02x:%02x", link, id); in fsi_slave_init()
1036 slave->dev.type = &cfam_type; in fsi_slave_init()
1037 slave->dev.parent = &master->dev; in fsi_slave_init()
1038 slave->dev.of_node = fsi_slave_find_of_node(master, link, id); in fsi_slave_init()
1039 slave->dev.release = fsi_slave_release; in fsi_slave_init()
1040 device_initialize(&slave->dev); in fsi_slave_init()
1041 slave->cfam_id = cfam_id; in fsi_slave_init()
1042 slave->master = master; in fsi_slave_init()
1043 slave->link = link; in fsi_slave_init()
1044 slave->id = id; in fsi_slave_init()
1045 slave->size = FSI_SLAVE_SIZE_23b; in fsi_slave_init()
1046 slave->t_send_delay = 16; in fsi_slave_init()
1047 slave->t_echo_delay = 16; in fsi_slave_init()
1050 slave->chip_id = -1; in fsi_slave_init()
1051 if (slave->dev.of_node) { in fsi_slave_init()
1053 if (!of_property_read_u32(slave->dev.of_node, "chip-id", &prop)) in fsi_slave_init()
1054 slave->chip_id = prop; in fsi_slave_init()
1063 "can't set slbus on slave:%02x:%02x %d\n", link, id, in fsi_slave_init()
1066 rc = fsi_slave_set_smode(slave); in fsi_slave_init()
1069 "can't set smode on slave:%02x:%02x %d\n", in fsi_slave_init()
1075 rc = __fsi_get_new_minor(slave, fsi_dev_cfam, &slave->dev.devt, in fsi_slave_init()
1076 &slave->cdev_idx); in fsi_slave_init()
1080 trace_fsi_slave_init(slave); in fsi_slave_init()
1083 cdev_init(&slave->cdev, &cfam_fops); in fsi_slave_init()
1084 rc = cdev_device_add(&slave->cdev, &slave->dev); in fsi_slave_init()
1086 dev_err(&slave->dev, "Error %d creating slave device\n", rc); in fsi_slave_init()
1097 slave->t_send_delay, in fsi_slave_init()
1098 slave->t_echo_delay); in fsi_slave_init()
1101 rc = device_create_bin_file(&slave->dev, &fsi_slave_raw_attr); in fsi_slave_init()
1103 dev_warn(&slave->dev, "failed to create raw attr: %d\n", rc); in fsi_slave_init()
1106 rc = fsi_slave_scan(slave); in fsi_slave_init()
1108 dev_dbg(&master->dev, "failed during slave scan with: %d\n", in fsi_slave_init()
1114 fsi_free_minor(slave->dev.devt); in fsi_slave_init()
1116 of_node_put(slave->dev.of_node); in fsi_slave_init()
1117 kfree(slave); in fsi_slave_init()
1239 struct fsi_slave *slave = to_fsi_slave(dev); in fsi_master_remove_slave() local
1242 cdev_device_del(&slave->cdev, &slave->dev); in fsi_master_remove_slave()