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()
557 struct siox_master *smaster = to_siox_master(dev); in active_show() local
559 return sprintf(buf, "%d\n", smaster->active); in active_show()
566 struct siox_master *smaster = to_siox_master(dev); in active_store() local
575 ret = siox_start(smaster); in active_store()
577 ret = siox_stop(smaster); in active_store()
587 static struct siox_device *siox_device_add(struct siox_master *smaster,
595 struct siox_master *smaster = to_siox_master(dev); in device_add_store() local
609 siox_device_add(smaster, "siox-12x8", inbytes, outbytes, statustype); in device_add_store()
616 static void siox_device_remove(struct siox_master *smaster);
622 struct siox_master *smaster = to_siox_master(dev); in device_remove_store() local
625 siox_device_remove(smaster); in device_remove_store()
635 struct siox_master *smaster = to_siox_master(dev); in poll_interval_ns_show() local
637 return sprintf(buf, "%lld\n", jiffies_to_nsecs(smaster->poll_interval)); in poll_interval_ns_show()
644 struct siox_master *smaster = to_siox_master(dev); in poll_interval_ns_store() local
652 siox_master_lock(smaster); in poll_interval_ns_store()
654 smaster->poll_interval = nsecs_to_jiffies(val); in poll_interval_ns_store()
656 siox_master_unlock(smaster); in poll_interval_ns_store()
674 struct siox_master *smaster = to_siox_master(dev); in siox_master_release() local
676 kfree(smaster); in siox_master_release()
687 struct siox_master *smaster; in siox_master_alloc() local
692 smaster = kzalloc(sizeof(*smaster) + size, GFP_KERNEL); in siox_master_alloc()
693 if (!smaster) in siox_master_alloc()
696 device_initialize(&smaster->dev); in siox_master_alloc()
698 smaster->busno = -1; in siox_master_alloc()
699 smaster->dev.bus = &siox_bus_type; in siox_master_alloc()
700 smaster->dev.type = &siox_master_type; in siox_master_alloc()
701 smaster->dev.parent = dev; in siox_master_alloc()
702 smaster->poll_interval = DIV_ROUND_UP(HZ, 40); in siox_master_alloc()
704 dev_set_drvdata(&smaster->dev, &smaster[1]); in siox_master_alloc()
706 return smaster; in siox_master_alloc()
710 int siox_master_register(struct siox_master *smaster) in siox_master_register() argument
717 if (!smaster->pushpull) in siox_master_register()
720 dev_set_name(&smaster->dev, "siox-%d", smaster->busno); in siox_master_register()
722 mutex_init(&smaster->lock); in siox_master_register()
723 INIT_LIST_HEAD(&smaster->devices); in siox_master_register()
725 smaster->last_poll = jiffies; in siox_master_register()
726 smaster->poll_thread = kthread_run(siox_poll_thread, smaster, in siox_master_register()
727 "siox-%d", smaster->busno); in siox_master_register()
728 if (IS_ERR(smaster->poll_thread)) { in siox_master_register()
729 smaster->active = 0; in siox_master_register()
730 return PTR_ERR(smaster->poll_thread); in siox_master_register()
733 ret = device_add(&smaster->dev); in siox_master_register()
735 kthread_stop(smaster->poll_thread); in siox_master_register()
741 void siox_master_unregister(struct siox_master *smaster) in siox_master_unregister() argument
744 device_del(&smaster->dev); in siox_master_unregister()
746 siox_master_lock(smaster); in siox_master_unregister()
748 __siox_stop(smaster); in siox_master_unregister()
750 while (smaster->num_devices) { in siox_master_unregister()
753 sdevice = container_of(smaster->devices.prev, in siox_master_unregister()
756 smaster->num_devices--; in siox_master_unregister()
758 siox_master_unlock(smaster); in siox_master_unregister()
762 siox_master_lock(smaster); in siox_master_unregister()
765 siox_master_unlock(smaster); in siox_master_unregister()
767 put_device(&smaster->dev); in siox_master_unregister()
771 static struct siox_device *siox_device_add(struct siox_master *smaster, in siox_device_add() argument
788 sdevice->smaster = smaster; in siox_device_add()
789 sdevice->dev.parent = &smaster->dev; in siox_device_add()
793 siox_master_lock(smaster); in siox_device_add()
796 smaster->busno, smaster->num_devices); in siox_device_add()
798 buf_len = smaster->setbuf_len + inbytes + in siox_device_add()
799 smaster->getbuf_len + outbytes; in siox_device_add()
800 if (smaster->buf_len < buf_len) { in siox_device_add()
801 u8 *buf = krealloc(smaster->buf, buf_len, GFP_KERNEL); in siox_device_add()
804 dev_err(&smaster->dev, in siox_device_add()
810 smaster->buf_len = buf_len; in siox_device_add()
811 smaster->buf = buf; in siox_device_add()
816 dev_err(&smaster->dev, "failed to register device: %d\n", ret); in siox_device_add()
821 smaster->num_devices++; in siox_device_add()
822 list_add_tail(&sdevice->node, &smaster->devices); in siox_device_add()
824 smaster->setbuf_len += sdevice->inbytes; in siox_device_add()
825 smaster->getbuf_len += sdevice->outbytes; in siox_device_add()
836 siox_master_unlock(smaster); in siox_device_add()
846 siox_master_unlock(smaster); in siox_device_add()
853 static void siox_device_remove(struct siox_master *smaster) in siox_device_remove() argument
857 siox_master_lock(smaster); in siox_device_remove()
859 if (!smaster->num_devices) { in siox_device_remove()
860 siox_master_unlock(smaster); in siox_device_remove()
864 sdevice = container_of(smaster->devices.prev, struct siox_device, node); in siox_device_remove()
866 smaster->num_devices--; in siox_device_remove()
868 smaster->setbuf_len -= sdevice->inbytes; in siox_device_remove()
869 smaster->getbuf_len -= sdevice->outbytes; in siox_device_remove()
871 if (!smaster->num_devices) in siox_device_remove()
872 __siox_stop(smaster); in siox_device_remove()
874 siox_master_unlock(smaster); in siox_device_remove()