Lines Matching refs:smaster
41 static void siox_master_lock(struct siox_master *smaster) in siox_master_lock() argument
43 mutex_lock(&smaster->lock); in siox_master_lock()
46 static void siox_master_unlock(struct siox_master *smaster) in siox_master_unlock() argument
48 mutex_unlock(&smaster->lock); in siox_master_unlock()
128 static void siox_poll(struct siox_master *smaster) in siox_poll() argument
131 size_t i = smaster->setbuf_len; in siox_poll()
135 smaster->last_poll = jiffies; in siox_poll()
147 if (++smaster->status > 0x0d) in siox_poll()
148 smaster->status = 0; in siox_poll()
150 memset(smaster->buf, 0, smaster->setbuf_len); in siox_poll()
153 list_for_each_entry(sdevice, &smaster->devices, node) { in siox_poll()
156 sdevice->status_written = smaster->status; in siox_poll()
170 &smaster->buf[i + 1]); in siox_poll()
178 smaster->buf[i] = sdevice->status_written; in siox_poll()
180 trace_siox_set_data(smaster, sdevice, devno, i); in siox_poll()
185 smaster->pushpull(smaster, smaster->setbuf_len, smaster->buf, in siox_poll()
186 smaster->getbuf_len, in siox_poll()
187 smaster->buf + smaster->setbuf_len); in siox_poll()
193 i = smaster->setbuf_len; in siox_poll()
194 list_for_each_entry(sdevice, &smaster->devices, node) { in siox_poll()
197 u8 status = smaster->buf[i + sdevice->outbytes - 1]; in siox_poll()
267 trace_siox_get_data(smaster, sdevice, devno, status_clean, i); in siox_poll()
271 sdriver->get_data(sdevice, &smaster->buf[i]); in siox_poll()
280 struct siox_master *smaster = data; in siox_poll_thread() local
283 get_device(&smaster->dev); in siox_poll_thread()
287 put_device(&smaster->dev); in siox_poll_thread()
291 siox_master_lock(smaster); in siox_poll_thread()
293 if (smaster->active) { in siox_poll_thread()
295 smaster->last_poll + smaster->poll_interval; in siox_poll_thread()
297 siox_poll(smaster); in siox_poll_thread()
299 timeout = smaster->poll_interval - in siox_poll_thread()
300 (jiffies - smaster->last_poll); in siox_poll_thread()
313 siox_master_unlock(smaster); in siox_poll_thread()
327 static int __siox_start(struct siox_master *smaster) in __siox_start() argument
329 if (!(smaster->setbuf_len + smaster->getbuf_len)) in __siox_start()
332 if (!smaster->buf) in __siox_start()
335 if (smaster->active) in __siox_start()
338 smaster->active = 1; in __siox_start()
339 wake_up_process(smaster->poll_thread); in __siox_start()
344 static int siox_start(struct siox_master *smaster) in siox_start() argument
348 siox_master_lock(smaster); in siox_start()
349 ret = __siox_start(smaster); in siox_start()
350 siox_master_unlock(smaster); in siox_start()
355 static int __siox_stop(struct siox_master *smaster) in __siox_stop() argument
357 if (smaster->active) { in __siox_stop()
360 smaster->active = 0; in __siox_stop()
362 list_for_each_entry(sdevice, &smaster->devices, node) { in __siox_stop()
373 static int siox_stop(struct siox_master *smaster) in siox_stop() argument
377 siox_master_lock(smaster); in siox_stop()
378 ret = __siox_stop(smaster); in siox_stop()
379 siox_master_unlock(smaster); in siox_stop()
420 siox_master_lock(sdev->smaster); in status_errors_show()
424 siox_master_unlock(sdev->smaster); in status_errors_show()
437 siox_master_lock(sdev->smaster); in connected_show()
441 siox_master_unlock(sdev->smaster); in connected_show()
454 siox_master_lock(sdev->smaster); in watchdog_show()
458 siox_master_unlock(sdev->smaster); in watchdog_show()
471 siox_master_lock(sdev->smaster); in watchdog_errors_show()
475 siox_master_unlock(sdev->smaster); in watchdog_errors_show()
553 struct siox_master *smaster = to_siox_master(dev); in active_show() local
555 return sprintf(buf, "%d\n", smaster->active); in active_show()
562 struct siox_master *smaster = to_siox_master(dev); in active_store() local
571 ret = siox_start(smaster); in active_store()
573 ret = siox_stop(smaster); in active_store()
583 static struct siox_device *siox_device_add(struct siox_master *smaster,
591 struct siox_master *smaster = to_siox_master(dev); in device_add_store() local
605 siox_device_add(smaster, "siox-12x8", inbytes, outbytes, statustype); in device_add_store()
612 static void siox_device_remove(struct siox_master *smaster);
618 struct siox_master *smaster = to_siox_master(dev); in device_remove_store() local
621 siox_device_remove(smaster); in device_remove_store()
631 struct siox_master *smaster = to_siox_master(dev); in poll_interval_ns_show() local
633 return sprintf(buf, "%lld\n", jiffies_to_nsecs(smaster->poll_interval)); in poll_interval_ns_show()
640 struct siox_master *smaster = to_siox_master(dev); in poll_interval_ns_store() local
648 siox_master_lock(smaster); in poll_interval_ns_store()
650 smaster->poll_interval = nsecs_to_jiffies(val); in poll_interval_ns_store()
652 siox_master_unlock(smaster); in poll_interval_ns_store()
670 struct siox_master *smaster = to_siox_master(dev); in siox_master_release() local
672 kfree(smaster); in siox_master_release()
683 struct siox_master *smaster; in siox_master_alloc() local
688 smaster = kzalloc(sizeof(*smaster) + size, GFP_KERNEL); in siox_master_alloc()
689 if (!smaster) in siox_master_alloc()
692 device_initialize(&smaster->dev); in siox_master_alloc()
694 smaster->busno = -1; in siox_master_alloc()
695 smaster->dev.bus = &siox_bus_type; in siox_master_alloc()
696 smaster->dev.type = &siox_master_type; in siox_master_alloc()
697 smaster->dev.parent = dev; in siox_master_alloc()
698 smaster->poll_interval = DIV_ROUND_UP(HZ, 40); in siox_master_alloc()
700 dev_set_drvdata(&smaster->dev, &smaster[1]); in siox_master_alloc()
702 return smaster; in siox_master_alloc()
706 int siox_master_register(struct siox_master *smaster) in siox_master_register() argument
713 if (!smaster->pushpull) in siox_master_register()
716 dev_set_name(&smaster->dev, "siox-%d", smaster->busno); in siox_master_register()
718 mutex_init(&smaster->lock); in siox_master_register()
719 INIT_LIST_HEAD(&smaster->devices); in siox_master_register()
721 smaster->last_poll = jiffies; in siox_master_register()
722 smaster->poll_thread = kthread_run(siox_poll_thread, smaster, in siox_master_register()
723 "siox-%d", smaster->busno); in siox_master_register()
724 if (IS_ERR(smaster->poll_thread)) { in siox_master_register()
725 smaster->active = 0; in siox_master_register()
726 return PTR_ERR(smaster->poll_thread); in siox_master_register()
729 ret = device_add(&smaster->dev); in siox_master_register()
731 kthread_stop(smaster->poll_thread); in siox_master_register()
737 void siox_master_unregister(struct siox_master *smaster) in siox_master_unregister() argument
740 device_del(&smaster->dev); in siox_master_unregister()
742 siox_master_lock(smaster); in siox_master_unregister()
744 __siox_stop(smaster); in siox_master_unregister()
746 while (smaster->num_devices) { in siox_master_unregister()
749 sdevice = container_of(smaster->devices.prev, in siox_master_unregister()
752 smaster->num_devices--; in siox_master_unregister()
754 siox_master_unlock(smaster); in siox_master_unregister()
758 siox_master_lock(smaster); in siox_master_unregister()
761 siox_master_unlock(smaster); in siox_master_unregister()
763 put_device(&smaster->dev); in siox_master_unregister()
767 static struct siox_device *siox_device_add(struct siox_master *smaster, in siox_device_add() argument
784 sdevice->smaster = smaster; in siox_device_add()
785 sdevice->dev.parent = &smaster->dev; in siox_device_add()
789 siox_master_lock(smaster); in siox_device_add()
792 smaster->busno, smaster->num_devices); in siox_device_add()
794 buf_len = smaster->setbuf_len + inbytes + in siox_device_add()
795 smaster->getbuf_len + outbytes; in siox_device_add()
796 if (smaster->buf_len < buf_len) { in siox_device_add()
797 u8 *buf = krealloc(smaster->buf, buf_len, GFP_KERNEL); in siox_device_add()
800 dev_err(&smaster->dev, in siox_device_add()
806 smaster->buf_len = buf_len; in siox_device_add()
807 smaster->buf = buf; in siox_device_add()
812 dev_err(&smaster->dev, "failed to register device: %d\n", ret); in siox_device_add()
817 smaster->num_devices++; in siox_device_add()
818 list_add_tail(&sdevice->node, &smaster->devices); in siox_device_add()
820 smaster->setbuf_len += sdevice->inbytes; in siox_device_add()
821 smaster->getbuf_len += sdevice->outbytes; in siox_device_add()
832 siox_master_unlock(smaster); in siox_device_add()
840 siox_master_unlock(smaster); in siox_device_add()
847 static void siox_device_remove(struct siox_master *smaster) in siox_device_remove() argument
851 siox_master_lock(smaster); in siox_device_remove()
853 if (!smaster->num_devices) { in siox_device_remove()
854 siox_master_unlock(smaster); in siox_device_remove()
858 sdevice = container_of(smaster->devices.prev, struct siox_device, node); in siox_device_remove()
860 smaster->num_devices--; in siox_device_remove()
862 smaster->setbuf_len -= sdevice->inbytes; in siox_device_remove()
863 smaster->getbuf_len -= sdevice->outbytes; in siox_device_remove()
865 if (!smaster->num_devices) in siox_device_remove()
866 __siox_stop(smaster); in siox_device_remove()
868 siox_master_unlock(smaster); in siox_device_remove()