aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/hid.h
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-05-16 05:49:16 -0400
committerJiri Kosina <jkosina@suse.cz>2008-10-14 17:50:48 -0400
commitc500c9714011edab021591340042787722db9cf0 (patch)
treed6bb0fe483c9f1c71c3d757e9c13d261ca01cd5f /include/linux/hid.h
parent85cdaf524b7ddab627e7d15405693f2511ef7505 (diff)
HID: hid, make parsing event driven
Next step for complete hid bus, this patch includes: - call parser either from probe or from hid-core if there is no probe. - add ll_driver structure and centralize some stuff there (open, close...) - split and merge usb_hid_configure and hid_probe into several functions to allow hooks/fixes between them Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'include/linux/hid.h')
-rw-r--r--include/linux/hid.h104
1 files changed, 99 insertions, 5 deletions
diff --git a/include/linux/hid.h b/include/linux/hid.h
index c4bea0eda85b..ac2584fe65c5 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -419,6 +419,7 @@ struct hid_control_fifo {
419#define HID_CLAIMED_HIDRAW 4 419#define HID_CLAIMED_HIDRAW 4
420 420
421#define HID_STAT_ADDED 1 421#define HID_STAT_ADDED 1
422#define HID_STAT_PARSED 2
422 423
423#define HID_CTRL_RUNNING 1 424#define HID_CTRL_RUNNING 1
424#define HID_OUT_RUNNING 2 425#define HID_OUT_RUNNING 2
@@ -435,6 +436,7 @@ struct hid_input {
435}; 436};
436 437
437struct hid_driver; 438struct hid_driver;
439struct hid_ll_driver;
438 440
439struct hid_device { /* device report descriptor */ 441struct hid_device { /* device report descriptor */
440 __u8 *rdesc; 442 __u8 *rdesc;
@@ -452,6 +454,7 @@ struct hid_device { /* device report descriptor */
452 454
453 struct device dev; /* device */ 455 struct device dev; /* device */
454 struct hid_driver *driver; 456 struct hid_driver *driver;
457 struct hid_ll_driver *ll_driver;
455 458
456 unsigned int status; /* see STAT flags above */ 459 unsigned int status; /* see STAT flags above */
457 unsigned claimed; /* Claimed by hidinput, hiddev? */ 460 unsigned claimed; /* Claimed by hidinput, hiddev? */
@@ -471,11 +474,6 @@ struct hid_device { /* device report descriptor */
471 474
472 __s32 delayed_value; /* For A4 Tech mice hwheel quirk */ 475 __s32 delayed_value; /* For A4 Tech mice hwheel quirk */
473 476
474 /* device-specific function pointers */
475 int (*hidinput_input_event) (struct input_dev *, unsigned int, unsigned int, int);
476 int (*hid_open) (struct hid_device *);
477 void (*hid_close) (struct hid_device *);
478
479 /* hiddev event handler */ 477 /* hiddev event handler */
480 void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field, 478 void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field,
481 struct hid_usage *, __s32); 479 struct hid_usage *, __s32);
@@ -561,9 +559,22 @@ struct hid_usage_id {
561 * @raw_event: if report in report_table, this hook is called (NULL means nop) 559 * @raw_event: if report in report_table, this hook is called (NULL means nop)
562 * @usage_table: on which events to call event (NULL means all) 560 * @usage_table: on which events to call event (NULL means all)
563 * @event: if usage in usage_table, this hook is called (NULL means nop) 561 * @event: if usage in usage_table, this hook is called (NULL means nop)
562 * @report_fixup: called before report descriptor parsing (NULL means nop)
563 * @input_mapping: invoked on input registering before mapping an usage
564 * @input_mapped: invoked on input registering after mapping an usage
564 * 565 *
565 * raw_event and event should return 0 on no action performed, 1 when no 566 * raw_event and event should return 0 on no action performed, 1 when no
566 * further processing should be done and negative on error 567 * further processing should be done and negative on error
568 *
569 * input_mapping shall return a negative value to completely ignore this usage
570 * (e.g. doubled or invalid usage), zero to continue with parsing of this
571 * usage by generic code (no special handling needed) or positive to skip
572 * generic parsing (needed special handling which was done in the hook already)
573 * input_mapped shall return negative to inform the layer that this usage
574 * should not be considered for further processing or zero to notify that
575 * no processing was performed and should be done in a generic manner
576 * Both these functions may be NULL which means the same behavior as returning
577 * zero from them.
567 */ 578 */
568struct hid_driver { 579struct hid_driver {
569 char *name; 580 char *name;
@@ -578,10 +589,43 @@ struct hid_driver {
578 const struct hid_usage_id *usage_table; 589 const struct hid_usage_id *usage_table;
579 int (*event)(struct hid_device *hdev, struct hid_field *field, 590 int (*event)(struct hid_device *hdev, struct hid_field *field,
580 struct hid_usage *usage, __s32 value); 591 struct hid_usage *usage, __s32 value);
592
593 void (*report_fixup)(struct hid_device *hdev, __u8 *buf,
594 unsigned int size);
595
596 int (*input_mapping)(struct hid_device *hdev,
597 struct hid_input *hidinput, struct hid_field *field,
598 struct hid_usage *usage, unsigned long **bit, int *max);
599 int (*input_mapped)(struct hid_device *hdev,
600 struct hid_input *hidinput, struct hid_field *field,
601 struct hid_usage *usage, unsigned long **bit, int *max);
581/* private: */ 602/* private: */
582 struct device_driver driver; 603 struct device_driver driver;
583}; 604};
584 605
606/**
607 * hid_ll_driver - low level driver callbacks
608 * @start: called on probe to start the device
609 * @stop: called on remove
610 * @open: called by input layer on open
611 * @close: called by input layer on close
612 * @hidinput_input_event: event input event (e.g. ff or leds)
613 * @parse: this method is called only once to parse the device data,
614 * shouldn't allocate anything to not leak memory
615 */
616struct hid_ll_driver {
617 int (*start)(struct hid_device *hdev);
618 void (*stop)(struct hid_device *hdev);
619
620 int (*open)(struct hid_device *hdev);
621 void (*close)(struct hid_device *hdev);
622
623 int (*hidinput_input_event) (struct input_dev *idev, unsigned int type,
624 unsigned int code, int value);
625
626 int (*parse)(struct hid_device *hdev);
627};
628
585/* Applications from HID Usage Tables 4/8/99 Version 1.1 */ 629/* Applications from HID Usage Tables 4/8/99 Version 1.1 */
586/* We ignore a few input applications that are not widely used */ 630/* We ignore a few input applications that are not widely used */
587#define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001) || (a == 0x000d0002)) 631#define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001) || (a == 0x000d0002))
@@ -618,6 +662,56 @@ void hid_output_report(struct hid_report *report, __u8 *data);
618struct hid_device *hid_allocate_device(void); 662struct hid_device *hid_allocate_device(void);
619int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size); 663int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
620 664
665/**
666 * hid_parse - parse HW reports
667 *
668 * @hdev: hid device
669 *
670 * Call this from probe after you set up the device (if needed). Your
671 * report_fixup will be called (if non-NULL) after reading raw report from
672 * device before passing it to hid layer for real parsing.
673 */
674static inline int __must_check hid_parse(struct hid_device *hdev)
675{
676 int ret;
677
678 if (hdev->status & HID_STAT_PARSED)
679 return 0;
680
681 ret = hdev->ll_driver->parse(hdev);
682 if (!ret)
683 hdev->status |= HID_STAT_PARSED;
684
685 return ret;
686}
687
688/**
689 * hid_hw_start - start underlaying HW
690 *
691 * @hdev: hid device
692 *
693 * Call this in probe function *after* hid_parse. This will setup HW buffers
694 * and start the device (if not deffered to device open). hid_hw_stop must be
695 * called if this was successfull.
696 */
697static inline int __must_check hid_hw_start(struct hid_device *hdev)
698{
699 return hdev->ll_driver->start(hdev);
700}
701
702/**
703 * hid_hw_stop - stop underlaying HW
704 *
705 * @hdev: hid device
706 *
707 * This is usually called from remove function or from probe when something
708 * failed and hid_hw_start was called already.
709 */
710static inline void hid_hw_stop(struct hid_device *hdev)
711{
712 hdev->ll_driver->stop(hdev);
713}
714
621void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, 715void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
622 int interrupt); 716 int interrupt);
623 717