/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 1999 Andreas Gal * Copyright (c) 2000-2001 Vojtech Pavlik * Copyright (c) 2006-2007 Jiri Kosina
*/ /* * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
*/ #ifndef __HID_H #define __HID_H
/* * We parse each description item into this structure. Short items data * values are expanded to 32-bit signed int, long items contain a pointer * into the data area.
*/
/* * HID device groups * * Note: HID_GROUP_ANY is declared in linux/mod_devicetable.h * and has a value of 0x0000
*/ #define HID_GROUP_GENERIC 0x0001 #define HID_GROUP_MULTITOUCH 0x0002 #define HID_GROUP_SENSOR_HUB 0x0003 #define HID_GROUP_MULTITOUCH_WIN_8 0x0004
/* * This is the global environment of the parser. This information is * persistent for main-items. The global environment can be saved and * restored with PUSH/POP statements.
*/
struct hid_field { unsigned physical; /* physical usage for this field */ unsigned logical; /* logical usage for this field */ unsigned application; /* application usage for this field */ struct hid_usage *usage; /* usage table for this function */ unsigned maxusage; /* maximum usage index */ unsigned flags; /* main-item flags (i.e. volatile,array,constant) */ unsigned report_offset; /* bit offset in the report */ unsigned report_size; /* size of this field in the report */ unsigned report_count; /* number of this field in the report */ unsigned report_type; /* (input,output,feature) */
__s32 *value; /* last known value(s) */
__s32 *new_value; /* newly read value(s) */
__s32 *usages_priorities; /* priority of each usage when reading the report * bits 8-16 are reserved for hid-input usage
*/
__s32 logical_minimum;
__s32 logical_maximum;
__s32 physical_minimum;
__s32 physical_maximum;
__s32 unit_exponent; unsigned unit; bool ignored; /* this field is ignored in this event */ struct hid_report *report; /* associated report */ unsigned index; /* index into report->field[] */ /* hidinput data */ struct hid_input *hidinput; /* associated input structure */
__u16 dpad; /* dpad input code */ unsignedint slot_idx; /* slot index in a report */
};
#define HID_MIN_BUFFER_SIZE 64 /* make sure there is at least a packet size of space */ #define HID_MAX_BUFFER_SIZE 16384 /* 16kb */ #define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */ #define HID_OUTPUT_FIFO_SIZE 64
#ifdef CONFIG_HID_BATTERY_STRENGTH /* * Power supply information for HID devices which report * battery strength. power_supply was successfully registered if * battery is non-NULL.
*/ struct power_supply *battery;
__s32 battery_capacity;
__s32 battery_min;
__s32 battery_max;
__s32 battery_report_type;
__s32 battery_report_id;
__s32 battery_charge_status; enum hid_battery_status battery_status; bool battery_avoid_query;
ktime_t battery_ratelimit_time; #endif
unsignedlong status; /* see STAT flags above */ unsigned claimed; /* Claimed by hidinput, hiddev? */ unsigned quirks; /* Various quirks the device can pull on us */ unsigned initial_quirks; /* Initial set of quirks supplied when creating device */ bool io_started; /* If IO has started */
struct list_head inputs; /* The list of inputs */ void *hiddev; /* The hiddev structure */ void *hidraw;
/** * struct hid_driver * @name: driver name (e.g. "Footech_bar-wheel") * @id_table: which devices is this driver for (must be non-NULL for probe * to be called) * @dyn_list: list of dynamically added device ids * @dyn_lock: lock protecting @dyn_list * @match: check if the given device is handled by this driver * @probe: new device inserted * @remove: device removed (NULL if not a hot-plug capable driver) * @report_table: on which reports to call raw_event (NULL means all) * @raw_event: if report in report_table, this hook is called (NULL means nop) * @usage_table: on which events to call event (NULL means all) * @event: if usage in usage_table, this hook is called (NULL means nop) * @report: this hook is called after parsing a report (NULL means nop) * @report_fixup: called before report descriptor parsing (NULL means nop) * @input_mapping: invoked on input registering before mapping an usage * @input_mapped: invoked on input registering after mapping an usage * @input_configured: invoked just before the device is registered * @feature_mapping: invoked on feature registering * @suspend: invoked on suspend (NULL means nop) * @resume: invoked on resume if device was not reset (NULL means nop) * @reset_resume: invoked on resume if device was reset (NULL means nop) * @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop) * @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop) * * probe should return -errno on error, or 0 on success. During probe, * input will not be passed to raw_event unless hid_device_io_start is * called. * * raw_event and event should return negative on error, any other value will * pass the event on to .event() typically return 0 for success. * * input_mapping shall return a negative value to completely ignore this usage * (e.g. doubled or invalid usage), zero to continue with parsing of this * usage by generic code (no special handling needed) or positive to skip * generic parsing (needed special handling which was done in the hook already) * input_mapped shall return negative to inform the layer that this usage * should not be considered for further processing or zero to notify that * no processing was performed and should be done in a generic manner * Both these functions may be NULL which means the same behavior as returning * zero from them.
*/ struct hid_driver { char *name; conststruct hid_device_id *id_table;
/** * struct hid_ll_driver - low level driver callbacks * @start: called on probe to start the device * @stop: called on remove * @open: called by input layer on open * @close: called by input layer on close * @power: request underlying hardware to enter requested power mode * @parse: this method is called only once to parse the device data, * shouldn't allocate anything to not leak memory * @request: send report request to device (e.g. feature report) * @wait: wait for buffered io to complete (send/recv reports) * @raw_request: send raw report request to device (e.g. feature report) * @output_report: send output report to device * @idle: send idle request to device * @may_wakeup: return if device may act as a wakeup source during system-suspend * @max_buffer_size: over-ride maximum data buffer size (default: HID_MAX_BUFFER_SIZE)
*/ struct hid_ll_driver { int (*start)(struct hid_device *hdev); void (*stop)(struct hid_device *hdev);
int (*open)(struct hid_device *hdev); void (*close)(struct hid_device *hdev);
int (*power)(struct hid_device *hdev, int level);
int (*parse)(struct hid_device *hdev);
void (*request)(struct hid_device *hdev, struct hid_report *report, int reqtype);
int (*wait)(struct hid_device *hdev);
int (*raw_request) (struct hid_device *hdev, unsignedchar reportnum,
__u8 *buf, size_t len, unsignedchar rtype, int reqtype);
int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len);
int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); bool (*may_wakeup)(struct hid_device *hdev);
/* Applications from HID Usage Tables 4/8/99 Version 1.1 */ /* We ignore a few input applications that are not widely used */ #define IS_INPUT_APPLICATION(a) \
(((a >= HID_UP_GENDESK) && (a <= HID_GD_MULTIAXIS)) \
|| ((a >= HID_DG_DIGITIZER) && (a <= HID_DG_WHITEBOARD)) \
|| (a == HID_GD_SYSTEM_CONTROL) || (a == HID_CP_CONSUMER_CONTROL) \
|| (a == HID_GD_WIRELESS_RADIO_CTLS))
/* use a define to avoid include chaining to get THIS_MODULE & friends */ #define hid_register_driver(driver) \
__hid_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
/** * module_hid_driver() - Helper macro for registering a HID driver * @__hid_driver: hid_driver struct * * Helper macro for HID drivers which do not do anything special in module * init/exit. This eliminates a lot of boilerplate. Each module may only * use this macro once, and calling it replaces module_init() and module_exit()
*/ #define module_hid_driver(__hid_driver) \
module_driver(__hid_driver, hid_register_driver, \
hid_unregister_driver)
/** * hid_device_io_start - enable HID input during probe, remove * * @hid: the device * * This should only be called during probe or remove and only be * called by the thread calling probe or remove. It will allow * incoming packets to be delivered to the driver.
*/ staticinlinevoid hid_device_io_start(struct hid_device *hid) { if (hid->io_started) {
dev_warn(&hid->dev, "io already started\n"); return;
}
hid->io_started = true;
up(&hid->driver_input_lock);
}
/** * hid_device_io_stop - disable HID input during probe, remove * * @hid: the device * * Should only be called after hid_device_io_start. It will prevent * incoming packets from going to the driver for the duration of * probe, remove. If called during probe, packets will still go to the * driver after probe is complete. This function should only be called * by the thread calling probe or remove.
*/ staticinlinevoid hid_device_io_stop(struct hid_device *hid) { if (!hid->io_started) {
dev_warn(&hid->dev, "io already stopped\n"); return;
}
hid->io_started = false;
down(&hid->driver_input_lock);
}
/** * hid_map_usage - map usage input bits * * @hidinput: hidinput which we are interested in * @usage: usage to fill in * @bit: pointer to input->{}bit (out parameter) * @max: maximal valid usage->code to consider later (out parameter) * @type: input event type (EV_KEY, EV_REL, ...) * @c: code which corresponds to this usage and type * * The value pointed to by @bit will be set to NULL if either @type is * an unhandled event type, or if @c is out of range for @type. This * can be used as an error condition.
*/ staticinlinevoid hid_map_usage(struct hid_input *hidinput, struct hid_usage *usage, unsignedlong **bit, int *max,
__u8 type, unsignedint c)
{ struct input_dev *input = hidinput->input; unsignedlong *bmap = NULL; unsignedint limit = 0;
switch (type) { case EV_ABS:
bmap = input->absbit;
limit = ABS_MAX; break; case EV_REL:
bmap = input->relbit;
limit = REL_MAX; break; case EV_KEY:
bmap = input->keybit;
limit = KEY_MAX; break; case EV_LED:
bmap = input->ledbit;
limit = LED_MAX; break; case EV_MSC:
bmap = input->mscbit;
limit = MSC_MAX; break;
}
/** * hid_map_usage_clear - map usage input bits and clear the input bit * * @hidinput: hidinput which we are interested in * @usage: usage to fill in * @bit: pointer to input->{}bit (out parameter) * @max: maximal valid usage->code to consider later (out parameter) * @type: input event type (EV_KEY, EV_REL, ...) * @c: code which corresponds to this usage and type * * The same as hid_map_usage, except the @c bit is also cleared in supported * bits (@bit).
*/ staticinlinevoid hid_map_usage_clear(struct hid_input *hidinput, struct hid_usage *usage, unsignedlong **bit, int *max,
__u8 type, __u16 c)
{
hid_map_usage(hidinput, usage, bit, max, type, c); if (*bit)
clear_bit(usage->code, *bit);
}
/** * hid_parse - parse HW reports * * @hdev: hid device * * Call this from probe after you set up the device (if needed). Your * report_fixup will be called (if non-NULL) after reading raw report from * device before passing it to hid layer for real parsing.
*/ staticinlineint __must_check hid_parse(struct hid_device *hdev)
{ return hid_open_report(hdev);
}
/** * hid_hw_power - requests underlying HW to go into given power mode * * @hdev: hid device * @level: requested power level (one of %PM_HINT_* defines) * * This function requests underlying hardware to enter requested power * mode.
*/
/** * hid_hw_idle - send idle request to device * * @hdev: hid device * @report: report to control * @idle: idle state * @reqtype: hid request type
*/ staticinlineint hid_hw_idle(struct hid_device *hdev, int report, int idle, enum hid_class_request reqtype)
{ if (hdev->ll_driver->idle) return hdev->ll_driver->idle(hdev, report, idle, reqtype);
return 0;
}
/** * hid_hw_may_wakeup - return if the hid device may act as a wakeup source during system-suspend * * @hdev: hid device
*/ staticinlinebool hid_hw_may_wakeup(struct hid_device *hdev)
{ if (hdev->ll_driver->may_wakeup) return hdev->ll_driver->may_wakeup(hdev);
if (hdev->dev.parent) return device_may_wakeup(hdev->dev.parent);
returnfalse;
}
/** * hid_hw_wait - wait for buffered io to complete * * @hdev: hid device
*/ staticinlinevoid hid_hw_wait(struct hid_device *hdev)
{ if (hdev->ll_driver->wait)
hdev->ll_driver->wait(hdev);
}
/** * hid_report_len - calculate the report length * * @report: the report whose length we want to know * * The length counts the report ID byte, but only if the ID is nonzero * and therefore is included in the report. Reports whose ID is zero * never include an ID byte.
*/ staticinline u32 hid_report_len(struct hid_report *report)
{ return DIV_ROUND_UP(report->size, 8) + (report->id > 0);
}
int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, int interrupt);
/* HID quirks API */ unsignedlong hid_lookup_quirk(conststruct hid_device *hdev); int hid_quirks_init(char **quirks_param, __u16 bus, int count); void hid_quirks_exit(__u16 bus);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.