1#- 2# Copyright (c) 2019 Vladimir Kondratyev 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions 6# are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23# SUCH DAMAGE. 24# 25# 26 27#include <sys/param.h> 28#include <sys/bus.h> 29#include <sys/kernel.h> 30#include <sys/malloc.h> 31#include <dev/hid/hid.h> 32 33# Any function listed here can do unbound sleeps waiting for IO to complete. 34 35INTERFACE hid; 36 37# Interrupts interface 38 39# 40# Allocate memory and initialise interrupt transfers. 41# intr callback function which is called if input data is available. 42# context is the private softc pointer, which will be used to callback. 43# rdesc is pointer to structire containing requested maximal sizes of input, 44# output and feature reports. It is used by hardware transport drivers 45# to determine sizes of internal buffers. 46# This function can be subsequently called with intr parameter set to NULL 47# to request intr_poll method support for transport driver. 48# 49METHOD void intr_setup { 50 device_t dev; 51 device_t child; 52 hid_intr_t intr; 53 void *context; 54 struct hid_rdesc_info *rdesc; 55}; 56 57# 58# Release all allocated resources associated with interrupt transfers. 59# 60METHOD void intr_unsetup { 61 device_t dev; 62 device_t child; 63}; 64 65# 66# Start the interrupt transfers if not already started. 67# 68METHOD int intr_start { 69 device_t dev; 70 device_t child; 71}; 72 73# 74# Stop the interrupt transfers if not already stopped. 75# 76METHOD int intr_stop { 77 device_t dev; 78 device_t child; 79}; 80 81# 82# The following function gets called from the HID keyboard driver when 83# the system has panicked. intr_setup method with NULL passed as intr parameter 84# must be called once before to let transport driver to be prepared. 85# 86METHOD void intr_poll { 87 device_t dev; 88 device_t child; 89}; 90 91# HID interface 92 93# 94# Read out an report descriptor from the HID device. 95# 96METHOD int get_rdesc { 97 device_t dev; 98 device_t child; 99 void *data; 100 hid_size_t len; 101}; 102 103# 104# Get input data from the device. Data should be read in chunks 105# of the size prescribed by the report descriptor. 106# This function interferes with interrupt transfers and should not be used. 107# 108METHOD int read { 109 device_t dev; 110 device_t child; 111 void *data; 112 hid_size_t maxlen; 113 hid_size_t *actlen; 114}; 115 116# 117# Send data to the device. Data should be written in 118# chunks of the size prescribed by the report descriptor. 119# 120METHOD int write { 121 device_t dev; 122 device_t child; 123 const void *data; 124 hid_size_t len; 125}; 126 127# 128# Get a report from the device without waiting for data on the interrupt. 129# Copies a maximum of len bytes of the report data into the memory specified 130# by data. Upon return actlen is set to the number of bytes copied. The type 131# field indicates which report is requested. It should be HID_INPUT_REPORT, 132# HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. This call may fail if the device 133# does not support this feature. 134# 135METHOD int get_report { 136 device_t dev; 137 device_t child; 138 void *data; 139 hid_size_t maxlen; 140 hid_size_t *actlen; 141 uint8_t type; 142 uint8_t id; 143}; 144 145# 146# Set a report in the device. The type field indicates which report is to be 147# set. It should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. 148# The value of the report is specified by the data and the len fields. 149# This call may fail if the device does not support this feature. 150# 151METHOD int set_report { 152 device_t dev; 153 device_t child; 154 const void *data; 155 hid_size_t len; 156 uint8_t type; 157 uint8_t id; 158}; 159 160# 161# Set duration between input reports (in mSec). 162# 163METHOD int set_idle { 164 device_t dev; 165 device_t child; 166 uint16_t duration; 167 uint8_t id; 168}; 169 170# 171# Switch between the boot protocol and the report protocol (or vice versa). 172# 173METHOD int set_protocol { 174 device_t dev; 175 device_t child; 176 uint16_t protocol; 177}; 178 179# 180# Executes arbitrary transport backend command. 181# Format of command is defined by hardware transport driver. 182# 183METHOD int ioctl { 184 device_t dev; 185 device_t child; 186 unsigned long cmd; 187 uintptr_t data; 188}; 189