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()
712 struct siox_master *smaster = data; in devm_siox_master_put() local
714 siox_master_put(smaster); in devm_siox_master_put()
720 struct siox_master *smaster; in devm_siox_master_alloc() local
723 smaster = siox_master_alloc(dev, size); in devm_siox_master_alloc()
724 if (!smaster) in devm_siox_master_alloc()
727 ret = devm_add_action_or_reset(dev, devm_siox_master_put, smaster); in devm_siox_master_alloc()
731 return smaster; in devm_siox_master_alloc()
735 int siox_master_register(struct siox_master *smaster) in siox_master_register() argument
742 if (!smaster->pushpull) in siox_master_register()
745 get_device(&smaster->dev); in siox_master_register()
747 dev_set_name(&smaster->dev, "siox-%d", smaster->busno); in siox_master_register()
749 mutex_init(&smaster->lock); in siox_master_register()
750 INIT_LIST_HEAD(&smaster->devices); in siox_master_register()
752 smaster->last_poll = jiffies; in siox_master_register()
753 smaster->poll_thread = kthread_run(siox_poll_thread, smaster, in siox_master_register()
754 "siox-%d", smaster->busno); in siox_master_register()
755 if (IS_ERR(smaster->poll_thread)) { in siox_master_register()
756 smaster->active = 0; in siox_master_register()
757 return PTR_ERR(smaster->poll_thread); in siox_master_register()
760 ret = device_add(&smaster->dev); in siox_master_register()
762 kthread_stop(smaster->poll_thread); in siox_master_register()
768 void siox_master_unregister(struct siox_master *smaster) in siox_master_unregister() argument
771 device_del(&smaster->dev); in siox_master_unregister()
773 siox_master_lock(smaster); in siox_master_unregister()
775 __siox_stop(smaster); in siox_master_unregister()
777 while (smaster->num_devices) { in siox_master_unregister()
780 sdevice = container_of(smaster->devices.prev, in siox_master_unregister()
783 smaster->num_devices--; in siox_master_unregister()
785 siox_master_unlock(smaster); in siox_master_unregister()
789 siox_master_lock(smaster); in siox_master_unregister()
792 siox_master_unlock(smaster); in siox_master_unregister()
794 put_device(&smaster->dev); in siox_master_unregister()
800 struct siox_master *smaster = data; in devm_siox_master_unregister() local
802 siox_master_unregister(smaster); in devm_siox_master_unregister()
805 int devm_siox_master_register(struct device *dev, struct siox_master *smaster) in devm_siox_master_register() argument
809 ret = siox_master_register(smaster); in devm_siox_master_register()
813 return devm_add_action_or_reset(dev, devm_siox_master_unregister, smaster); in devm_siox_master_register()
817 static struct siox_device *siox_device_add(struct siox_master *smaster, in siox_device_add() argument
834 sdevice->smaster = smaster; in siox_device_add()
835 sdevice->dev.parent = &smaster->dev; in siox_device_add()
839 siox_master_lock(smaster); in siox_device_add()
842 smaster->busno, smaster->num_devices); in siox_device_add()
844 buf_len = smaster->setbuf_len + inbytes + in siox_device_add()
845 smaster->getbuf_len + outbytes; in siox_device_add()
846 if (smaster->buf_len < buf_len) { in siox_device_add()
847 u8 *buf = krealloc(smaster->buf, buf_len, GFP_KERNEL); in siox_device_add()
850 dev_err(&smaster->dev, in siox_device_add()
856 smaster->buf_len = buf_len; in siox_device_add()
857 smaster->buf = buf; in siox_device_add()
862 dev_err(&smaster->dev, "failed to register device: %d\n", ret); in siox_device_add()
867 smaster->num_devices++; in siox_device_add()
868 list_add_tail(&sdevice->node, &smaster->devices); in siox_device_add()
870 smaster->setbuf_len += sdevice->inbytes; in siox_device_add()
871 smaster->getbuf_len += sdevice->outbytes; in siox_device_add()
882 siox_master_unlock(smaster); in siox_device_add()
892 siox_master_unlock(smaster); in siox_device_add()
899 static void siox_device_remove(struct siox_master *smaster) in siox_device_remove() argument
903 siox_master_lock(smaster); in siox_device_remove()
905 if (!smaster->num_devices) { in siox_device_remove()
906 siox_master_unlock(smaster); in siox_device_remove()
910 sdevice = container_of(smaster->devices.prev, struct siox_device, node); in siox_device_remove()
912 smaster->num_devices--; in siox_device_remove()
914 smaster->setbuf_len -= sdevice->inbytes; in siox_device_remove()
915 smaster->getbuf_len -= sdevice->outbytes; in siox_device_remove()
917 if (!smaster->num_devices) in siox_device_remove()
918 __siox_stop(smaster); in siox_device_remove()
920 siox_master_unlock(smaster); in siox_device_remove()