Lines Matching refs:ddev

177 	struct sdtx_device *ddev;  member
189 struct sdtx_device *ddev = container_of(kref, struct sdtx_device, kref); in __sdtx_device_release() local
191 mutex_destroy(&ddev->write_lock); in __sdtx_device_release()
192 kfree(ddev); in __sdtx_device_release()
195 static struct sdtx_device *sdtx_device_get(struct sdtx_device *ddev) in sdtx_device_get() argument
197 if (ddev) in sdtx_device_get()
198 kref_get(&ddev->kref); in sdtx_device_get()
200 return ddev; in sdtx_device_get()
203 static void sdtx_device_put(struct sdtx_device *ddev) in sdtx_device_put() argument
205 if (ddev) in sdtx_device_put()
206 kref_put(&ddev->kref, __sdtx_device_release); in sdtx_device_put()
212 static u16 sdtx_translate_base_state(struct sdtx_device *ddev, u8 state) in sdtx_translate_base_state() argument
225 dev_err(ddev->dev, "unknown base state: %#04x\n", state); in sdtx_translate_base_state()
230 static u16 sdtx_translate_latch_status(struct sdtx_device *ddev, u8 status) in sdtx_translate_latch_status() argument
249 dev_err(ddev->dev, "unknown latch status: %#04x\n", status); in sdtx_translate_latch_status()
254 static u16 sdtx_translate_cancel_reason(struct sdtx_device *ddev, u8 reason) in sdtx_translate_cancel_reason() argument
273 dev_err(ddev->dev, "unknown cancel reason: %#04x\n", reason); in sdtx_translate_cancel_reason()
281 static int sdtx_ioctl_get_base_info(struct sdtx_device *ddev, in sdtx_ioctl_get_base_info() argument
288 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_base_info()
290 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &raw); in sdtx_ioctl_get_base_info()
294 info.state = sdtx_translate_base_state(ddev, raw.state); in sdtx_ioctl_get_base_info()
303 static int sdtx_ioctl_get_device_mode(struct sdtx_device *ddev, u16 __user *buf) in sdtx_ioctl_get_device_mode() argument
308 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_device_mode()
310 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_ioctl_get_device_mode()
317 static int sdtx_ioctl_get_latch_status(struct sdtx_device *ddev, u16 __user *buf) in sdtx_ioctl_get_latch_status() argument
322 lockdep_assert_held_read(&ddev->lock); in sdtx_ioctl_get_latch_status()
324 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &latch); in sdtx_ioctl_get_latch_status()
328 return put_user(sdtx_translate_latch_status(ddev, latch), buf); in sdtx_ioctl_get_latch_status()
333 struct sdtx_device *ddev = client->ddev; in __surface_dtx_ioctl() local
335 lockdep_assert_held_read(&ddev->lock); in __surface_dtx_ioctl()
347 return ssam_retry(ssam_bas_latch_lock, ddev->ctrl); in __surface_dtx_ioctl()
350 return ssam_retry(ssam_bas_latch_unlock, ddev->ctrl); in __surface_dtx_ioctl()
353 return ssam_retry(ssam_bas_latch_request, ddev->ctrl); in __surface_dtx_ioctl()
356 return ssam_retry(ssam_bas_latch_confirm, ddev->ctrl); in __surface_dtx_ioctl()
359 return ssam_retry(ssam_bas_latch_heartbeat, ddev->ctrl); in __surface_dtx_ioctl()
362 return ssam_retry(ssam_bas_latch_cancel, ddev->ctrl); in __surface_dtx_ioctl()
365 return sdtx_ioctl_get_base_info(ddev, (struct sdtx_base_info __user *)arg); in __surface_dtx_ioctl()
368 return sdtx_ioctl_get_device_mode(ddev, (u16 __user *)arg); in __surface_dtx_ioctl()
371 return sdtx_ioctl_get_latch_status(ddev, (u16 __user *)arg); in __surface_dtx_ioctl()
383 if (down_read_killable(&client->ddev->lock)) in surface_dtx_ioctl()
386 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &client->ddev->flags)) { in surface_dtx_ioctl()
387 up_read(&client->ddev->lock); in surface_dtx_ioctl()
393 up_read(&client->ddev->lock); in surface_dtx_ioctl()
402 struct sdtx_device *ddev = container_of(file->private_data, struct sdtx_device, mdev); in surface_dtx_open() local
410 client->ddev = sdtx_device_get(ddev); in surface_dtx_open()
420 down_write(&ddev->client_lock); in surface_dtx_open()
428 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_open()
429 up_write(&ddev->client_lock); in surface_dtx_open()
431 sdtx_device_put(client->ddev); in surface_dtx_open()
436 list_add_tail(&client->node, &ddev->client_list); in surface_dtx_open()
437 up_write(&ddev->client_lock); in surface_dtx_open()
448 down_write(&client->ddev->client_lock); in surface_dtx_release()
450 up_write(&client->ddev->client_lock); in surface_dtx_release()
453 sdtx_device_put(client->ddev); in surface_dtx_release()
463 struct sdtx_device *ddev = client->ddev; in surface_dtx_read() local
467 if (down_read_killable(&ddev->lock)) in surface_dtx_read()
471 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_read()
472 up_read(&ddev->lock); in surface_dtx_read()
479 up_read(&ddev->lock); in surface_dtx_read()
484 status = wait_event_interruptible(ddev->waitq, in surface_dtx_read()
487 &ddev->flags)); in surface_dtx_read()
491 if (down_read_killable(&ddev->lock)) in surface_dtx_read()
495 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags)) { in surface_dtx_read()
496 up_read(&ddev->lock); in surface_dtx_read()
503 up_read(&ddev->lock); in surface_dtx_read()
511 up_read(&ddev->lock); in surface_dtx_read()
517 up_read(&ddev->lock); in surface_dtx_read()
522 up_read(&ddev->lock); in surface_dtx_read()
531 if (test_bit(SDTX_DEVICE_SHUTDOWN_BIT, &client->ddev->flags)) in surface_dtx_poll()
534 poll_wait(file, &client->ddev->waitq, pt); in surface_dtx_poll()
593 static void sdtx_update_device_mode(struct sdtx_device *ddev, unsigned long delay);
596 static void sdtx_push_event(struct sdtx_device *ddev, struct sdtx_event *evt) in sdtx_push_event() argument
601 lockdep_assert_held(&ddev->write_lock); in sdtx_push_event()
603 down_read(&ddev->client_lock); in sdtx_push_event()
604 list_for_each_entry(client, &ddev->client_list, node) { in sdtx_push_event()
611 dev_warn(ddev->dev, "event buffer overrun\n"); in sdtx_push_event()
615 up_read(&ddev->client_lock); in sdtx_push_event()
617 wake_up_interruptible(&ddev->waitq); in sdtx_push_event()
622 struct sdtx_device *ddev = container_of(nf, struct sdtx_device, notif); in sdtx_notifier() local
649 dev_err(ddev->dev, in sdtx_notifier()
655 mutex_lock(&ddev->write_lock); in sdtx_notifier()
660 clear_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags); in sdtx_notifier()
663 if (ddev->state.base.state == in->data[0] && in sdtx_notifier()
664 ddev->state.base.base_id == in->data[1]) in sdtx_notifier()
667 ddev->state.base.state = in->data[0]; in sdtx_notifier()
668 ddev->state.base.base_id = in->data[1]; in sdtx_notifier()
672 event.base.v.state = sdtx_translate_base_state(ddev, in->data[0]); in sdtx_notifier()
684 event.status.v = sdtx_translate_cancel_reason(ddev, in->data[0]); in sdtx_notifier()
688 clear_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags); in sdtx_notifier()
691 if (ddev->state.latch_status == in->data[0]) in sdtx_notifier()
694 ddev->state.latch_status = in->data[0]; in sdtx_notifier()
698 event.status.v = sdtx_translate_latch_status(ddev, in->data[0]); in sdtx_notifier()
702 sdtx_push_event(ddev, &event.common); in sdtx_notifier()
709 sdtx_update_device_mode(ddev, delay); in sdtx_notifier()
713 mutex_unlock(&ddev->write_lock); in sdtx_notifier()
730 struct sdtx_device *ddev = container_of(work, struct sdtx_device, mode_work.work); in sdtx_device_mode_workfn() local
737 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_device_mode_workfn()
739 dev_err(ddev->dev, "failed to get device mode: %d\n", status); in sdtx_device_mode_workfn()
744 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &base); in sdtx_device_mode_workfn()
746 dev_err(ddev->dev, "failed to get base info: %d\n", status); in sdtx_device_mode_workfn()
757 dev_dbg(ddev->dev, "device mode is invalid, trying again\n"); in sdtx_device_mode_workfn()
758 sdtx_update_device_mode(ddev, SDTX_DEVICE_MODE_DELAY_RECHECK); in sdtx_device_mode_workfn()
762 mutex_lock(&ddev->write_lock); in sdtx_device_mode_workfn()
763 clear_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags); in sdtx_device_mode_workfn()
766 if (ddev->state.device_mode == mode) { in sdtx_device_mode_workfn()
767 mutex_unlock(&ddev->write_lock); in sdtx_device_mode_workfn()
771 ddev->state.device_mode = mode; in sdtx_device_mode_workfn()
777 sdtx_push_event(ddev, &event.e); in sdtx_device_mode_workfn()
781 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet); in sdtx_device_mode_workfn()
782 input_sync(ddev->mode_switch); in sdtx_device_mode_workfn()
784 mutex_unlock(&ddev->write_lock); in sdtx_device_mode_workfn()
787 static void sdtx_update_device_mode(struct sdtx_device *ddev, unsigned long delay) in sdtx_update_device_mode() argument
789 schedule_delayed_work(&ddev->mode_work, delay); in sdtx_update_device_mode()
793 static void __sdtx_device_state_update_base(struct sdtx_device *ddev, in __sdtx_device_state_update_base() argument
798 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_base()
801 if (ddev->state.base.state == info.state && in __sdtx_device_state_update_base()
802 ddev->state.base.base_id == info.base_id) in __sdtx_device_state_update_base()
805 ddev->state.base = info; in __sdtx_device_state_update_base()
809 event.v.state = sdtx_translate_base_state(ddev, info.state); in __sdtx_device_state_update_base()
812 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_base()
816 static void __sdtx_device_state_update_mode(struct sdtx_device *ddev, u8 mode) in __sdtx_device_state_update_mode() argument
827 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_mode()
829 if (sdtx_device_mode_invalid(mode, ddev->state.base.state)) { in __sdtx_device_state_update_mode()
830 dev_dbg(ddev->dev, "device mode is invalid, trying again\n"); in __sdtx_device_state_update_mode()
831 sdtx_update_device_mode(ddev, SDTX_DEVICE_MODE_DELAY_RECHECK); in __sdtx_device_state_update_mode()
836 if (ddev->state.device_mode == mode) in __sdtx_device_state_update_mode()
839 ddev->state.device_mode = mode; in __sdtx_device_state_update_mode()
846 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_mode()
850 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet); in __sdtx_device_state_update_mode()
851 input_sync(ddev->mode_switch); in __sdtx_device_state_update_mode()
855 static void __sdtx_device_state_update_latch(struct sdtx_device *ddev, u8 status) in __sdtx_device_state_update_latch() argument
859 lockdep_assert_held(&ddev->write_lock); in __sdtx_device_state_update_latch()
862 if (ddev->state.latch_status == status) in __sdtx_device_state_update_latch()
865 ddev->state.latch_status = status; in __sdtx_device_state_update_latch()
869 event.v = sdtx_translate_latch_status(ddev, status); in __sdtx_device_state_update_latch()
871 sdtx_push_event(ddev, &event.e); in __sdtx_device_state_update_latch()
876 struct sdtx_device *ddev = container_of(work, struct sdtx_device, state_work.work); in sdtx_device_state_workfn() local
882 set_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags); in sdtx_device_state_workfn()
883 set_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags); in sdtx_device_state_workfn()
884 set_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags); in sdtx_device_state_workfn()
894 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &base); in sdtx_device_state_workfn()
896 dev_err(ddev->dev, "failed to get base state: %d\n", status); in sdtx_device_state_workfn()
900 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &mode); in sdtx_device_state_workfn()
902 dev_err(ddev->dev, "failed to get device mode: %d\n", status); in sdtx_device_state_workfn()
906 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &latch); in sdtx_device_state_workfn()
908 dev_err(ddev->dev, "failed to get latch status: %d\n", status); in sdtx_device_state_workfn()
912 mutex_lock(&ddev->write_lock); in sdtx_device_state_workfn()
922 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_BASE_BIT, &ddev->flags)) in sdtx_device_state_workfn()
923 __sdtx_device_state_update_base(ddev, base); in sdtx_device_state_workfn()
925 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_MODE_BIT, &ddev->flags)) in sdtx_device_state_workfn()
926 __sdtx_device_state_update_mode(ddev, mode); in sdtx_device_state_workfn()
928 if (test_and_clear_bit(SDTX_DEVICE_DIRTY_LATCH_BIT, &ddev->flags)) in sdtx_device_state_workfn()
929 __sdtx_device_state_update_latch(ddev, latch); in sdtx_device_state_workfn()
931 mutex_unlock(&ddev->write_lock); in sdtx_device_state_workfn()
934 static void sdtx_update_device_state(struct sdtx_device *ddev, unsigned long delay) in sdtx_update_device_state() argument
936 schedule_delayed_work(&ddev->state_work, delay); in sdtx_update_device_state()
942 static int sdtx_device_init(struct sdtx_device *ddev, struct device *dev, in sdtx_device_init() argument
948 kref_init(&ddev->kref); in sdtx_device_init()
949 init_rwsem(&ddev->lock); in sdtx_device_init()
950 ddev->dev = dev; in sdtx_device_init()
951 ddev->ctrl = ctrl; in sdtx_device_init()
953 ddev->mdev.minor = MISC_DYNAMIC_MINOR; in sdtx_device_init()
954 ddev->mdev.name = "surface_dtx"; in sdtx_device_init()
955 ddev->mdev.nodename = "surface/dtx"; in sdtx_device_init()
956 ddev->mdev.fops = &surface_dtx_fops; in sdtx_device_init()
958 ddev->notif.base.priority = 1; in sdtx_device_init()
959 ddev->notif.base.fn = sdtx_notifier; in sdtx_device_init()
960 ddev->notif.event.reg = SSAM_EVENT_REGISTRY_SAM; in sdtx_device_init()
961 ddev->notif.event.id.target_category = SSAM_SSH_TC_BAS; in sdtx_device_init()
962 ddev->notif.event.id.instance = 0; in sdtx_device_init()
963 ddev->notif.event.mask = SSAM_EVENT_MASK_NONE; in sdtx_device_init()
964 ddev->notif.event.flags = SSAM_EVENT_SEQUENCED; in sdtx_device_init()
966 init_waitqueue_head(&ddev->waitq); in sdtx_device_init()
967 mutex_init(&ddev->write_lock); in sdtx_device_init()
968 init_rwsem(&ddev->client_lock); in sdtx_device_init()
969 INIT_LIST_HEAD(&ddev->client_list); in sdtx_device_init()
971 INIT_DELAYED_WORK(&ddev->mode_work, sdtx_device_mode_workfn); in sdtx_device_init()
972 INIT_DELAYED_WORK(&ddev->state_work, sdtx_device_state_workfn); in sdtx_device_init()
985 status = ssam_retry(ssam_bas_get_base, ddev->ctrl, &ddev->state.base); in sdtx_device_init()
989 status = ssam_retry(ssam_bas_get_device_mode, ddev->ctrl, &ddev->state.device_mode); in sdtx_device_init()
993 status = ssam_retry(ssam_bas_get_latch_status, ddev->ctrl, &ddev->state.latch_status); in sdtx_device_init()
998 ddev->mode_switch = input_allocate_device(); in sdtx_device_init()
999 if (!ddev->mode_switch) in sdtx_device_init()
1002 ddev->mode_switch->name = "Microsoft Surface DTX Device Mode Switch"; in sdtx_device_init()
1003 ddev->mode_switch->phys = "ssam/01:11:01:00:00/input0"; in sdtx_device_init()
1004 ddev->mode_switch->id.bustype = BUS_HOST; in sdtx_device_init()
1005 ddev->mode_switch->dev.parent = ddev->dev; in sdtx_device_init()
1007 tablet_mode = (ddev->state.device_mode != SDTX_DEVICE_MODE_LAPTOP); in sdtx_device_init()
1008 input_set_capability(ddev->mode_switch, EV_SW, SW_TABLET_MODE); in sdtx_device_init()
1009 input_report_switch(ddev->mode_switch, SW_TABLET_MODE, tablet_mode); in sdtx_device_init()
1011 status = input_register_device(ddev->mode_switch); in sdtx_device_init()
1013 input_free_device(ddev->mode_switch); in sdtx_device_init()
1018 status = ssam_notifier_register(ddev->ctrl, &ddev->notif); in sdtx_device_init()
1023 status = misc_register(&ddev->mdev); in sdtx_device_init()
1031 sdtx_update_device_state(ddev, 0); in sdtx_device_init()
1035 ssam_notifier_unregister(ddev->ctrl, &ddev->notif); in sdtx_device_init()
1036 cancel_delayed_work_sync(&ddev->mode_work); in sdtx_device_init()
1038 input_unregister_device(ddev->mode_switch); in sdtx_device_init()
1044 struct sdtx_device *ddev; in sdtx_device_create() local
1047 ddev = kzalloc(sizeof(*ddev), GFP_KERNEL); in sdtx_device_create()
1048 if (!ddev) in sdtx_device_create()
1051 status = sdtx_device_init(ddev, dev, ctrl); in sdtx_device_create()
1053 sdtx_device_put(ddev); in sdtx_device_create()
1057 return ddev; in sdtx_device_create()
1060 static void sdtx_device_destroy(struct sdtx_device *ddev) in sdtx_device_destroy() argument
1068 set_bit(SDTX_DEVICE_SHUTDOWN_BIT, &ddev->flags); in sdtx_device_destroy()
1071 ssam_notifier_unregister(ddev->ctrl, &ddev->notif); in sdtx_device_destroy()
1074 cancel_delayed_work_sync(&ddev->mode_work); in sdtx_device_destroy()
1077 cancel_delayed_work_sync(&ddev->state_work); in sdtx_device_destroy()
1080 input_unregister_device(ddev->mode_switch); in sdtx_device_destroy()
1083 down_write(&ddev->client_lock); in sdtx_device_destroy()
1084 list_for_each_entry(client, &ddev->client_list, node) { in sdtx_device_destroy()
1087 up_write(&ddev->client_lock); in sdtx_device_destroy()
1090 wake_up_interruptible(&ddev->waitq); in sdtx_device_destroy()
1097 down_write(&ddev->lock); in sdtx_device_destroy()
1098 ddev->dev = NULL; in sdtx_device_destroy()
1099 ddev->ctrl = NULL; in sdtx_device_destroy()
1100 up_write(&ddev->lock); in sdtx_device_destroy()
1103 misc_deregister(&ddev->mdev); in sdtx_device_destroy()
1109 sdtx_device_put(ddev); in sdtx_device_destroy()
1119 struct sdtx_device *ddev = dev_get_drvdata(dev); in surface_dtx_pm_complete() local
1136 sdtx_update_device_state(ddev, msecs_to_jiffies(1000)); in surface_dtx_pm_complete()
1155 struct sdtx_device *ddev; in surface_dtx_platform_probe() local
1162 ddev = sdtx_device_create(&pdev->dev, ctrl); in surface_dtx_platform_probe()
1163 if (IS_ERR(ddev)) in surface_dtx_platform_probe()
1164 return PTR_ERR(ddev); in surface_dtx_platform_probe()
1166 platform_set_drvdata(pdev, ddev); in surface_dtx_platform_probe()
1199 struct sdtx_device *ddev; in surface_dtx_ssam_probe() local
1201 ddev = sdtx_device_create(&sdev->dev, sdev->ctrl); in surface_dtx_ssam_probe()
1202 if (IS_ERR(ddev)) in surface_dtx_ssam_probe()
1203 return PTR_ERR(ddev); in surface_dtx_ssam_probe()
1205 ssam_device_set_drvdata(sdev, ddev); in surface_dtx_ssam_probe()