xref: /freebsd/sys/dev/hid/hid_if.m (revision 031beb4e)
1961a3535SVladimir Kondratyev#-
2961a3535SVladimir Kondratyev# Copyright (c) 2019 Vladimir Kondratyev
3961a3535SVladimir Kondratyev#
4961a3535SVladimir Kondratyev# Redistribution and use in source and binary forms, with or without
5961a3535SVladimir Kondratyev# modification, are permitted provided that the following conditions
6961a3535SVladimir Kondratyev# are met:
7961a3535SVladimir Kondratyev# 1. Redistributions of source code must retain the above copyright
8961a3535SVladimir Kondratyev#    notice, this list of conditions and the following disclaimer.
9961a3535SVladimir Kondratyev# 2. Redistributions in binary form must reproduce the above copyright
10961a3535SVladimir Kondratyev#    notice, this list of conditions and the following disclaimer in the
11961a3535SVladimir Kondratyev#    documentation and/or other materials provided with the distribution.
12961a3535SVladimir Kondratyev#
13961a3535SVladimir Kondratyev# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14961a3535SVladimir Kondratyev# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15961a3535SVladimir Kondratyev# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16961a3535SVladimir Kondratyev# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17961a3535SVladimir Kondratyev# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18961a3535SVladimir Kondratyev# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19961a3535SVladimir Kondratyev# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20961a3535SVladimir Kondratyev# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21961a3535SVladimir Kondratyev# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22961a3535SVladimir Kondratyev# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23961a3535SVladimir Kondratyev# SUCH DAMAGE.
24961a3535SVladimir Kondratyev#
25961a3535SVladimir Kondratyev#
26961a3535SVladimir Kondratyev
27961a3535SVladimir Kondratyev#include <sys/param.h>
28961a3535SVladimir Kondratyev#include <sys/bus.h>
29961a3535SVladimir Kondratyev#include <sys/kernel.h>
30961a3535SVladimir Kondratyev#include <sys/malloc.h>
31961a3535SVladimir Kondratyev#include <dev/hid/hid.h>
32961a3535SVladimir Kondratyev
33961a3535SVladimir Kondratyev# Any function listed here can do unbound sleeps waiting for IO to complete.
34961a3535SVladimir Kondratyev
35961a3535SVladimir KondratyevINTERFACE hid;
36961a3535SVladimir Kondratyev
37961a3535SVladimir Kondratyev# Interrupts interface
38961a3535SVladimir Kondratyev
39961a3535SVladimir Kondratyev#
40961a3535SVladimir Kondratyev# Allocate memory and initialise interrupt transfers.
41961a3535SVladimir Kondratyev# intr callback function which is called if input data is available.
42961a3535SVladimir Kondratyev# context is the private softc pointer, which will be used to callback.
43961a3535SVladimir Kondratyev# rdesc is pointer to structire containing requested maximal sizes of input,
44961a3535SVladimir Kondratyev# output and feature reports.  It is used by hardware transport drivers
45961a3535SVladimir Kondratyev# to determine sizes of internal buffers.
469aa0e5afSVladimir Kondratyev# This function can be subsequently called with intr parameter set to NULL
479aa0e5afSVladimir Kondratyev# to request intr_poll method support for transport driver.
48961a3535SVladimir Kondratyev#
49961a3535SVladimir KondratyevMETHOD void intr_setup {
50961a3535SVladimir Kondratyev	device_t dev;
514b171281SVladimir Kondratyev	device_t child;
52961a3535SVladimir Kondratyev	hid_intr_t intr;
53961a3535SVladimir Kondratyev	void *context;
54961a3535SVladimir Kondratyev	struct hid_rdesc_info *rdesc;
55961a3535SVladimir Kondratyev};
56961a3535SVladimir Kondratyev
57961a3535SVladimir Kondratyev#
58961a3535SVladimir Kondratyev# Release all allocated resources associated with interrupt transfers.
59961a3535SVladimir Kondratyev#
60961a3535SVladimir KondratyevMETHOD void intr_unsetup {
61961a3535SVladimir Kondratyev	device_t dev;
624b171281SVladimir Kondratyev	device_t child;
63961a3535SVladimir Kondratyev};
64961a3535SVladimir Kondratyev
65961a3535SVladimir Kondratyev#
66961a3535SVladimir Kondratyev# Start the interrupt transfers if not already started.
67961a3535SVladimir Kondratyev#
68961a3535SVladimir KondratyevMETHOD int intr_start {
69961a3535SVladimir Kondratyev	device_t dev;
704b171281SVladimir Kondratyev	device_t child;
71961a3535SVladimir Kondratyev};
72961a3535SVladimir Kondratyev
73961a3535SVladimir Kondratyev#
74961a3535SVladimir Kondratyev# Stop the interrupt transfers if not already stopped.
75961a3535SVladimir Kondratyev#
76961a3535SVladimir KondratyevMETHOD int intr_stop {
77961a3535SVladimir Kondratyev	device_t dev;
784b171281SVladimir Kondratyev	device_t child;
79961a3535SVladimir Kondratyev};
80961a3535SVladimir Kondratyev
81961a3535SVladimir Kondratyev#
829aa0e5afSVladimir Kondratyev# The following function gets called from the HID keyboard driver when
839094c3a7SGordon Bergling# the system has panicked. intr_setup method with NULL passed as intr parameter
849aa0e5afSVladimir Kondratyev# must be called once before to let transport driver to be prepared.
85961a3535SVladimir Kondratyev#
86961a3535SVladimir KondratyevMETHOD void intr_poll {
87961a3535SVladimir Kondratyev	device_t dev;
884b171281SVladimir Kondratyev	device_t child;
89961a3535SVladimir Kondratyev};
90961a3535SVladimir Kondratyev
91961a3535SVladimir Kondratyev# HID interface
92961a3535SVladimir Kondratyev
93961a3535SVladimir Kondratyev#
94961a3535SVladimir Kondratyev# Read out an report descriptor from the HID device.
95961a3535SVladimir Kondratyev#
96961a3535SVladimir KondratyevMETHOD int get_rdesc {
97961a3535SVladimir Kondratyev	device_t dev;
984b171281SVladimir Kondratyev	device_t child;
99961a3535SVladimir Kondratyev	void *data;
100961a3535SVladimir Kondratyev	hid_size_t len;
101961a3535SVladimir Kondratyev};
102961a3535SVladimir Kondratyev
103961a3535SVladimir Kondratyev#
104961a3535SVladimir Kondratyev# Get input data from the device. Data should be read in chunks
105961a3535SVladimir Kondratyev# of the size prescribed by the report descriptor.
106961a3535SVladimir Kondratyev# This function interferes with interrupt transfers and should not be used.
107961a3535SVladimir Kondratyev#
108961a3535SVladimir KondratyevMETHOD int read {
109961a3535SVladimir Kondratyev	device_t dev;
1104b171281SVladimir Kondratyev	device_t child;
111961a3535SVladimir Kondratyev	void *data;
112961a3535SVladimir Kondratyev	hid_size_t maxlen;
113961a3535SVladimir Kondratyev	hid_size_t *actlen;
114961a3535SVladimir Kondratyev};
115961a3535SVladimir Kondratyev
116961a3535SVladimir Kondratyev#
117961a3535SVladimir Kondratyev# Send data to the device. Data should be written in
118961a3535SVladimir Kondratyev# chunks of the size prescribed by the report descriptor.
119961a3535SVladimir Kondratyev#
120961a3535SVladimir KondratyevMETHOD int write {
121961a3535SVladimir Kondratyev	device_t dev;
1224b171281SVladimir Kondratyev	device_t child;
123961a3535SVladimir Kondratyev	const void *data;
124961a3535SVladimir Kondratyev	hid_size_t len;
125961a3535SVladimir Kondratyev};
126961a3535SVladimir Kondratyev
127961a3535SVladimir Kondratyev#
128961a3535SVladimir Kondratyev# Get a report from the device without waiting for data on the interrupt.
129961a3535SVladimir Kondratyev# Copies a maximum of len bytes of the report data into the memory specified
130961a3535SVladimir Kondratyev# by data. Upon return actlen is set to the number of bytes copied. The type
131961a3535SVladimir Kondratyev# field indicates which report is requested. It should be HID_INPUT_REPORT,
132961a3535SVladimir Kondratyev# HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. This call may fail if the device
133961a3535SVladimir Kondratyev# does not support this feature.
134961a3535SVladimir Kondratyev#
135961a3535SVladimir KondratyevMETHOD int get_report {
136961a3535SVladimir Kondratyev	device_t dev;
1374b171281SVladimir Kondratyev	device_t child;
138961a3535SVladimir Kondratyev	void *data;
139961a3535SVladimir Kondratyev	hid_size_t maxlen;
140961a3535SVladimir Kondratyev	hid_size_t *actlen;
141961a3535SVladimir Kondratyev	uint8_t type;
142961a3535SVladimir Kondratyev	uint8_t id;
143961a3535SVladimir Kondratyev};
144961a3535SVladimir Kondratyev
145961a3535SVladimir Kondratyev#
146961a3535SVladimir Kondratyev# Set a report in the device. The type field indicates which report is to be
147961a3535SVladimir Kondratyev# set. It should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT.
148961a3535SVladimir Kondratyev# The value of the report is specified by the data and the len fields.
149961a3535SVladimir Kondratyev# This call may fail if the device does not support this feature.
150961a3535SVladimir Kondratyev#
151961a3535SVladimir KondratyevMETHOD int set_report {
152961a3535SVladimir Kondratyev	device_t dev;
1534b171281SVladimir Kondratyev	device_t child;
154961a3535SVladimir Kondratyev	const void *data;
155961a3535SVladimir Kondratyev	hid_size_t len;
156961a3535SVladimir Kondratyev	uint8_t type;
157961a3535SVladimir Kondratyev	uint8_t id;
158961a3535SVladimir Kondratyev};
159961a3535SVladimir Kondratyev
160961a3535SVladimir Kondratyev#
161961a3535SVladimir Kondratyev# Set duration between input reports (in mSec).
162961a3535SVladimir Kondratyev#
163961a3535SVladimir KondratyevMETHOD int set_idle {
164961a3535SVladimir Kondratyev	device_t dev;
1654b171281SVladimir Kondratyev	device_t child;
166961a3535SVladimir Kondratyev	uint16_t duration;
167961a3535SVladimir Kondratyev	uint8_t id;
168961a3535SVladimir Kondratyev};
169961a3535SVladimir Kondratyev
170961a3535SVladimir Kondratyev#
171961a3535SVladimir Kondratyev# Switch between the boot protocol and the report protocol (or vice versa).
172961a3535SVladimir Kondratyev#
173961a3535SVladimir KondratyevMETHOD int set_protocol {
174961a3535SVladimir Kondratyev	device_t dev;
1754b171281SVladimir Kondratyev	device_t child;
176961a3535SVladimir Kondratyev	uint16_t protocol;
177961a3535SVladimir Kondratyev};
1785f47c5a3SVladimir Kondratyev
1795f47c5a3SVladimir Kondratyev#
1805f47c5a3SVladimir Kondratyev# Executes arbitrary transport backend command.
1815f47c5a3SVladimir Kondratyev# Format of command is defined by hardware transport driver.
1825f47c5a3SVladimir Kondratyev#
1835f47c5a3SVladimir KondratyevMETHOD int ioctl {
1845f47c5a3SVladimir Kondratyev	device_t dev;
1854b171281SVladimir Kondratyev	device_t child;
1865f47c5a3SVladimir Kondratyev	unsigned long cmd;
1875f47c5a3SVladimir Kondratyev	uintptr_t data;
1885f47c5a3SVladimir Kondratyev};
189