Lines Matching refs:smaster

41 static void siox_master_lock(struct siox_master *smaster)
43 mutex_lock(&smaster->lock);
46 static void siox_master_unlock(struct siox_master *smaster)
48 mutex_unlock(&smaster->lock);
128 static void siox_poll(struct siox_master *smaster)
131 size_t i = smaster->setbuf_len;
135 smaster->last_poll = jiffies;
147 if (++smaster->status > 0x0d)
148 smaster->status = 0;
150 memset(smaster->buf, 0, smaster->setbuf_len);
153 list_for_each_entry(sdevice, &smaster->devices, node) {
156 sdevice->status_written = smaster->status;
170 &smaster->buf[i + 1]);
178 smaster->buf[i] = sdevice->status_written;
180 trace_siox_set_data(smaster, sdevice, devno, i);
185 smaster->pushpull(smaster, smaster->setbuf_len, smaster->buf,
186 smaster->getbuf_len,
187 smaster->buf + smaster->setbuf_len);
193 i = smaster->setbuf_len;
194 list_for_each_entry(sdevice, &smaster->devices, node) {
197 u8 status = smaster->buf[i + sdevice->outbytes - 1];
267 trace_siox_get_data(smaster, sdevice, devno, status_clean, i);
271 sdriver->get_data(sdevice, &smaster->buf[i]);
280 struct siox_master *smaster = data;
283 get_device(&smaster->dev);
287 put_device(&smaster->dev);
291 siox_master_lock(smaster);
293 if (smaster->active) {
295 smaster->last_poll + smaster->poll_interval;
297 siox_poll(smaster);
299 timeout = smaster->poll_interval -
300 (jiffies - smaster->last_poll);
313 siox_master_unlock(smaster);
327 static int __siox_start(struct siox_master *smaster)
329 if (!(smaster->setbuf_len + smaster->getbuf_len))
332 if (!smaster->buf)
335 if (smaster->active)
338 smaster->active = 1;
339 wake_up_process(smaster->poll_thread);
344 static int siox_start(struct siox_master *smaster)
348 siox_master_lock(smaster);
349 ret = __siox_start(smaster);
350 siox_master_unlock(smaster);
355 static int __siox_stop(struct siox_master *smaster)
357 if (smaster->active) {
360 smaster->active = 0;
362 list_for_each_entry(sdevice, &smaster->devices, node) {
373 static int siox_stop(struct siox_master *smaster)
377 siox_master_lock(smaster);
378 ret = __siox_stop(smaster);
379 siox_master_unlock(smaster);
420 siox_master_lock(sdev->smaster);
424 siox_master_unlock(sdev->smaster);
437 siox_master_lock(sdev->smaster);
441 siox_master_unlock(sdev->smaster);
454 siox_master_lock(sdev->smaster);
458 siox_master_unlock(sdev->smaster);
471 siox_master_lock(sdev->smaster);
475 siox_master_unlock(sdev->smaster);
557 struct siox_master *smaster = to_siox_master(dev);
559 return sprintf(buf, "%d\n", smaster->active);
566 struct siox_master *smaster = to_siox_master(dev);
575 ret = siox_start(smaster);
577 ret = siox_stop(smaster);
587 static struct siox_device *siox_device_add(struct siox_master *smaster,
595 struct siox_master *smaster = to_siox_master(dev);
609 siox_device_add(smaster, "siox-12x8", inbytes, outbytes, statustype);
616 static void siox_device_remove(struct siox_master *smaster);
622 struct siox_master *smaster = to_siox_master(dev);
625 siox_device_remove(smaster);
635 struct siox_master *smaster = to_siox_master(dev);
637 return sprintf(buf, "%lld\n", jiffies_to_nsecs(smaster->poll_interval));
644 struct siox_master *smaster = to_siox_master(dev);
652 siox_master_lock(smaster);
654 smaster->poll_interval = nsecs_to_jiffies(val);
656 siox_master_unlock(smaster);
674 struct siox_master *smaster = to_siox_master(dev);
676 kfree(smaster);
687 struct siox_master *smaster;
692 smaster = kzalloc(sizeof(*smaster) + size, GFP_KERNEL);
693 if (!smaster)
696 device_initialize(&smaster->dev);
698 smaster->busno = -1;
699 smaster->dev.bus = &siox_bus_type;
700 smaster->dev.type = &siox_master_type;
701 smaster->dev.parent = dev;
702 smaster->poll_interval = DIV_ROUND_UP(HZ, 40);
704 dev_set_drvdata(&smaster->dev, &smaster[1]);
706 return smaster;
712 struct siox_master *smaster = data;
714 siox_master_put(smaster);
720 struct siox_master *smaster;
723 smaster = siox_master_alloc(dev, size);
724 if (!smaster)
727 ret = devm_add_action_or_reset(dev, devm_siox_master_put, smaster);
731 return smaster;
735 int siox_master_register(struct siox_master *smaster)
742 if (!smaster->pushpull)
745 get_device(&smaster->dev);
747 dev_set_name(&smaster->dev, "siox-%d", smaster->busno);
749 mutex_init(&smaster->lock);
750 INIT_LIST_HEAD(&smaster->devices);
752 smaster->last_poll = jiffies;
753 smaster->poll_thread = kthread_run(siox_poll_thread, smaster,
754 "siox-%d", smaster->busno);
755 if (IS_ERR(smaster->poll_thread)) {
756 smaster->active = 0;
757 return PTR_ERR(smaster->poll_thread);
760 ret = device_add(&smaster->dev);
762 kthread_stop(smaster->poll_thread);
768 void siox_master_unregister(struct siox_master *smaster)
771 device_del(&smaster->dev);
773 siox_master_lock(smaster);
775 __siox_stop(smaster);
777 while (smaster->num_devices) {
780 sdevice = container_of(smaster->devices.prev,
783 smaster->num_devices--;
785 siox_master_unlock(smaster);
789 siox_master_lock(smaster);
792 siox_master_unlock(smaster);
794 put_device(&smaster->dev);
800 struct siox_master *smaster = data;
802 siox_master_unregister(smaster);
805 int devm_siox_master_register(struct device *dev, struct siox_master *smaster)
809 ret = siox_master_register(smaster);
813 return devm_add_action_or_reset(dev, devm_siox_master_unregister, smaster);
817 static struct siox_device *siox_device_add(struct siox_master *smaster,
834 sdevice->smaster = smaster;
835 sdevice->dev.parent = &smaster->dev;
839 siox_master_lock(smaster);
842 smaster->busno, smaster->num_devices);
844 buf_len = smaster->setbuf_len + inbytes +
845 smaster->getbuf_len + outbytes;
846 if (smaster->buf_len < buf_len) {
847 u8 *buf = krealloc(smaster->buf, buf_len, GFP_KERNEL);
850 dev_err(&smaster->dev,
856 smaster->buf_len = buf_len;
857 smaster->buf = buf;
862 dev_err(&smaster->dev, "failed to register device: %d\n", ret);
867 smaster->num_devices++;
868 list_add_tail(&sdevice->node, &smaster->devices);
870 smaster->setbuf_len += sdevice->inbytes;
871 smaster->getbuf_len += sdevice->outbytes;
882 siox_master_unlock(smaster);
892 siox_master_unlock(smaster);
899 static void siox_device_remove(struct siox_master *smaster)
903 siox_master_lock(smaster);
905 if (!smaster->num_devices) {
906 siox_master_unlock(smaster);
910 sdevice = container_of(smaster->devices.prev, struct siox_device, node);
912 smaster->num_devices--;
914 smaster->setbuf_len -= sdevice->inbytes;
915 smaster->getbuf_len -= sdevice->outbytes;
917 if (!smaster->num_devices)
918 __siox_stop(smaster);
920 siox_master_unlock(smaster);