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# $FreeBSD$ 26961a3535SVladimir Kondratyev# 27961a3535SVladimir Kondratyev 28961a3535SVladimir Kondratyev#include <sys/param.h> 29961a3535SVladimir Kondratyev#include <sys/bus.h> 30961a3535SVladimir Kondratyev#include <sys/kernel.h> 31961a3535SVladimir Kondratyev#include <sys/malloc.h> 32961a3535SVladimir Kondratyev#include <dev/hid/hid.h> 33961a3535SVladimir Kondratyev 34961a3535SVladimir Kondratyev# Any function listed here can do unbound sleeps waiting for IO to complete. 35961a3535SVladimir Kondratyev 36961a3535SVladimir KondratyevINTERFACE hid; 37961a3535SVladimir Kondratyev 38961a3535SVladimir Kondratyev# Interrupts interface 39961a3535SVladimir Kondratyev 40961a3535SVladimir Kondratyev# 41961a3535SVladimir Kondratyev# Allocate memory and initialise interrupt transfers. 42961a3535SVladimir Kondratyev# intr callback function which is called if input data is available. 43961a3535SVladimir Kondratyev# context is the private softc pointer, which will be used to callback. 44961a3535SVladimir Kondratyev# rdesc is pointer to structire containing requested maximal sizes of input, 45961a3535SVladimir Kondratyev# output and feature reports. It is used by hardware transport drivers 46961a3535SVladimir Kondratyev# to determine sizes of internal buffers. 479aa0e5afSVladimir Kondratyev# This function can be subsequently called with intr parameter set to NULL 489aa0e5afSVladimir Kondratyev# to request intr_poll method support for transport driver. 49961a3535SVladimir Kondratyev# 50961a3535SVladimir KondratyevMETHOD void intr_setup { 51961a3535SVladimir Kondratyev device_t dev; 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; 62961a3535SVladimir Kondratyev}; 63961a3535SVladimir Kondratyev 64961a3535SVladimir Kondratyev# 65961a3535SVladimir Kondratyev# Start the interrupt transfers if not already started. 66961a3535SVladimir Kondratyev# 67961a3535SVladimir KondratyevMETHOD int intr_start { 68961a3535SVladimir Kondratyev device_t dev; 69961a3535SVladimir Kondratyev}; 70961a3535SVladimir Kondratyev 71961a3535SVladimir Kondratyev# 72961a3535SVladimir Kondratyev# Stop the interrupt transfers if not already stopped. 73961a3535SVladimir Kondratyev# 74961a3535SVladimir KondratyevMETHOD int intr_stop { 75961a3535SVladimir Kondratyev device_t dev; 76961a3535SVladimir Kondratyev}; 77961a3535SVladimir Kondratyev 78961a3535SVladimir Kondratyev# 799aa0e5afSVladimir Kondratyev# The following function gets called from the HID keyboard driver when 809094c3a7SGordon Bergling# the system has panicked. intr_setup method with NULL passed as intr parameter 819aa0e5afSVladimir Kondratyev# must be called once before to let transport driver to be prepared. 82961a3535SVladimir Kondratyev# 83961a3535SVladimir KondratyevMETHOD void intr_poll { 84961a3535SVladimir Kondratyev device_t dev; 85961a3535SVladimir Kondratyev}; 86961a3535SVladimir Kondratyev 87961a3535SVladimir Kondratyev# HID interface 88961a3535SVladimir Kondratyev 89961a3535SVladimir Kondratyev# 90961a3535SVladimir Kondratyev# Read out an report descriptor from the HID device. 91961a3535SVladimir Kondratyev# 92961a3535SVladimir KondratyevMETHOD int get_rdesc { 93961a3535SVladimir Kondratyev device_t dev; 94961a3535SVladimir Kondratyev void *data; 95961a3535SVladimir Kondratyev hid_size_t len; 96961a3535SVladimir Kondratyev}; 97961a3535SVladimir Kondratyev 98961a3535SVladimir Kondratyev# 99961a3535SVladimir Kondratyev# Get input data from the device. Data should be read in chunks 100961a3535SVladimir Kondratyev# of the size prescribed by the report descriptor. 101961a3535SVladimir Kondratyev# This function interferes with interrupt transfers and should not be used. 102961a3535SVladimir Kondratyev# 103961a3535SVladimir KondratyevMETHOD int read { 104961a3535SVladimir Kondratyev device_t dev; 105961a3535SVladimir Kondratyev void *data; 106961a3535SVladimir Kondratyev hid_size_t maxlen; 107961a3535SVladimir Kondratyev hid_size_t *actlen; 108961a3535SVladimir Kondratyev}; 109961a3535SVladimir Kondratyev 110961a3535SVladimir Kondratyev# 111961a3535SVladimir Kondratyev# Send data to the device. Data should be written in 112961a3535SVladimir Kondratyev# chunks of the size prescribed by the report descriptor. 113961a3535SVladimir Kondratyev# 114961a3535SVladimir KondratyevMETHOD int write { 115961a3535SVladimir Kondratyev device_t dev; 116961a3535SVladimir Kondratyev const void *data; 117961a3535SVladimir Kondratyev hid_size_t len; 118961a3535SVladimir Kondratyev}; 119961a3535SVladimir Kondratyev 120961a3535SVladimir Kondratyev# 121961a3535SVladimir Kondratyev# Get a report from the device without waiting for data on the interrupt. 122961a3535SVladimir Kondratyev# Copies a maximum of len bytes of the report data into the memory specified 123961a3535SVladimir Kondratyev# by data. Upon return actlen is set to the number of bytes copied. The type 124961a3535SVladimir Kondratyev# field indicates which report is requested. It should be HID_INPUT_REPORT, 125961a3535SVladimir Kondratyev# HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. This call may fail if the device 126961a3535SVladimir Kondratyev# does not support this feature. 127961a3535SVladimir Kondratyev# 128961a3535SVladimir KondratyevMETHOD int get_report { 129961a3535SVladimir Kondratyev device_t dev; 130961a3535SVladimir Kondratyev void *data; 131961a3535SVladimir Kondratyev hid_size_t maxlen; 132961a3535SVladimir Kondratyev hid_size_t *actlen; 133961a3535SVladimir Kondratyev uint8_t type; 134961a3535SVladimir Kondratyev uint8_t id; 135961a3535SVladimir Kondratyev}; 136961a3535SVladimir Kondratyev 137961a3535SVladimir Kondratyev# 138961a3535SVladimir Kondratyev# Set a report in the device. The type field indicates which report is to be 139961a3535SVladimir Kondratyev# set. It should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. 140961a3535SVladimir Kondratyev# The value of the report is specified by the data and the len fields. 141961a3535SVladimir Kondratyev# This call may fail if the device does not support this feature. 142961a3535SVladimir Kondratyev# 143961a3535SVladimir KondratyevMETHOD int set_report { 144961a3535SVladimir Kondratyev device_t dev; 145961a3535SVladimir Kondratyev const void *data; 146961a3535SVladimir Kondratyev hid_size_t len; 147961a3535SVladimir Kondratyev uint8_t type; 148961a3535SVladimir Kondratyev uint8_t id; 149961a3535SVladimir Kondratyev}; 150961a3535SVladimir Kondratyev 151961a3535SVladimir Kondratyev# 152961a3535SVladimir Kondratyev# Set duration between input reports (in mSec). 153961a3535SVladimir Kondratyev# 154961a3535SVladimir KondratyevMETHOD int set_idle { 155961a3535SVladimir Kondratyev device_t dev; 156961a3535SVladimir Kondratyev uint16_t duration; 157961a3535SVladimir Kondratyev uint8_t id; 158961a3535SVladimir Kondratyev}; 159961a3535SVladimir Kondratyev 160961a3535SVladimir Kondratyev# 161961a3535SVladimir Kondratyev# Switch between the boot protocol and the report protocol (or vice versa). 162961a3535SVladimir Kondratyev# 163961a3535SVladimir KondratyevMETHOD int set_protocol { 164961a3535SVladimir Kondratyev device_t dev; 165961a3535SVladimir Kondratyev uint16_t protocol; 166961a3535SVladimir Kondratyev}; 1675f47c5a3SVladimir Kondratyev 1685f47c5a3SVladimir Kondratyev# 1695f47c5a3SVladimir Kondratyev# Executes arbitrary transport backend command. 1705f47c5a3SVladimir Kondratyev# Format of command is defined by hardware transport driver. 1715f47c5a3SVladimir Kondratyev# 1725f47c5a3SVladimir KondratyevMETHOD int ioctl { 1735f47c5a3SVladimir Kondratyev device_t dev; 1745f47c5a3SVladimir Kondratyev unsigned long cmd; 1755f47c5a3SVladimir Kondratyev uintptr_t data; 1765f47c5a3SVladimir Kondratyev}; 177