Lines Matching defs: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);
553 struct siox_master *smaster = to_siox_master(dev);
555 return sprintf(buf, "%d\n", smaster->active);
562 struct siox_master *smaster = to_siox_master(dev);
571 ret = siox_start(smaster);
573 ret = siox_stop(smaster);
583 static struct siox_device *siox_device_add(struct siox_master *smaster,
591 struct siox_master *smaster = to_siox_master(dev);
605 siox_device_add(smaster, "siox-12x8", inbytes, outbytes, statustype);
612 static void siox_device_remove(struct siox_master *smaster);
618 struct siox_master *smaster = to_siox_master(dev);
621 siox_device_remove(smaster);
631 struct siox_master *smaster = to_siox_master(dev);
633 return sprintf(buf, "%lld\n", jiffies_to_nsecs(smaster->poll_interval));
640 struct siox_master *smaster = to_siox_master(dev);
648 siox_master_lock(smaster);
650 smaster->poll_interval = nsecs_to_jiffies(val);
652 siox_master_unlock(smaster);
670 struct siox_master *smaster = to_siox_master(dev);
672 kfree(smaster);
683 struct siox_master *smaster;
688 smaster = kzalloc(sizeof(*smaster) + size, GFP_KERNEL);
689 if (!smaster)
692 device_initialize(&smaster->dev);
694 smaster->busno = -1;
695 smaster->dev.bus = &siox_bus_type;
696 smaster->dev.type = &siox_master_type;
697 smaster->dev.parent = dev;
698 smaster->poll_interval = DIV_ROUND_UP(HZ, 40);
700 dev_set_drvdata(&smaster->dev, &smaster[1]);
702 return smaster;
706 int siox_master_register(struct siox_master *smaster)
713 if (!smaster->pushpull)
716 dev_set_name(&smaster->dev, "siox-%d", smaster->busno);
718 mutex_init(&smaster->lock);
719 INIT_LIST_HEAD(&smaster->devices);
721 smaster->last_poll = jiffies;
722 smaster->poll_thread = kthread_run(siox_poll_thread, smaster,
723 "siox-%d", smaster->busno);
724 if (IS_ERR(smaster->poll_thread)) {
725 smaster->active = 0;
726 return PTR_ERR(smaster->poll_thread);
729 ret = device_add(&smaster->dev);
731 kthread_stop(smaster->poll_thread);
737 void siox_master_unregister(struct siox_master *smaster)
740 device_del(&smaster->dev);
742 siox_master_lock(smaster);
744 __siox_stop(smaster);
746 while (smaster->num_devices) {
749 sdevice = container_of(smaster->devices.prev,
752 smaster->num_devices--;
754 siox_master_unlock(smaster);
758 siox_master_lock(smaster);
761 siox_master_unlock(smaster);
763 put_device(&smaster->dev);
767 static struct siox_device *siox_device_add(struct siox_master *smaster,
784 sdevice->smaster = smaster;
785 sdevice->dev.parent = &smaster->dev;
789 siox_master_lock(smaster);
792 smaster->busno, smaster->num_devices);
794 buf_len = smaster->setbuf_len + inbytes +
795 smaster->getbuf_len + outbytes;
796 if (smaster->buf_len < buf_len) {
797 u8 *buf = krealloc(smaster->buf, buf_len, GFP_KERNEL);
800 dev_err(&smaster->dev,
806 smaster->buf_len = buf_len;
807 smaster->buf = buf;
812 dev_err(&smaster->dev, "failed to register device: %d\n", ret);
817 smaster->num_devices++;
818 list_add_tail(&sdevice->node, &smaster->devices);
820 smaster->setbuf_len += sdevice->inbytes;
821 smaster->getbuf_len += sdevice->outbytes;
832 siox_master_unlock(smaster);
842 siox_master_unlock(smaster);
849 static void siox_device_remove(struct siox_master *smaster)
853 siox_master_lock(smaster);
855 if (!smaster->num_devices) {
856 siox_master_unlock(smaster);
860 sdevice = container_of(smaster->devices.prev, struct siox_device, node);
862 smaster->num_devices--;
864 smaster->setbuf_len -= sdevice->inbytes;
865 smaster->getbuf_len -= sdevice->outbytes;
867 if (!smaster->num_devices)
868 __siox_stop(smaster);
870 siox_master_unlock(smaster);