Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/iicbus/input/iichid.h
- This file was added.
/* $OpenBSD: iichid.h,v 1.4 2016/01/31 18:24:35 jcs Exp $ */ | |||||
/* | |||||
* HID-over-i2c driver | |||||
* | |||||
* Copyright (c) 2015, 2016 joshua stein <jcs@openbsd.org> | |||||
* | |||||
* Permission to use, copy, modify, and distribute this software for any | |||||
* purpose with or without fee is hereby granted, provided that the above | |||||
* copyright notice and this permission notice appear in all copies. | |||||
* | |||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||||
*/ | |||||
#ifndef _IIC_HID_H_ | |||||
#define _IIC_HID_H_ | |||||
#include <dev/usb/hid.h> | |||||
#include <sys/mouse.h> | |||||
#include <sys/condvar.h> | |||||
/* from usbdi.h: Match codes. */ | |||||
/* First five codes is for a whole device. */ | |||||
#define IMATCH_VENDOR_PRODUCT_REV 14 | |||||
#define IMATCH_VENDOR_PRODUCT 13 | |||||
#define IMATCH_VENDOR_DEVCLASS_DEVPROTO 12 | |||||
#define IMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11 | |||||
#define IMATCH_DEVCLASS_DEVSUBCLASS 10 | |||||
/* Next six codes are for interfaces. */ | |||||
#define IMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9 | |||||
#define IMATCH_VENDOR_PRODUCT_CONF_IFACE 8 | |||||
#define IMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7 | |||||
#define IMATCH_VENDOR_IFACESUBCLASS 6 | |||||
#define IMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5 | |||||
#define IMATCH_IFACECLASS_IFACESUBCLASS 4 | |||||
#define IMATCH_IFACECLASS 3 | |||||
#define IMATCH_IFACECLASS_GENERIC 2 | |||||
/* Generic driver */ | |||||
#define IMATCH_GENERIC 1 | |||||
/* No match */ | |||||
#define IMATCH_NONE 0 | |||||
#define IHIDBUSCF_REPORTID 0 | |||||
#define IHIDBUSCF_REPORTID_DEFAULT -1 | |||||
#define iichidcf_reportid cf_loc[IHIDBUSCF_REPORTID] | |||||
#define IHIDEV_UNK_REPORTID IHIDBUSCF_REPORTID_DEFAULT | |||||
#define I2C_HID_REPORT_TYPE_INPUT 0x1 | |||||
#define I2C_HID_REPORT_TYPE_OUTPUT 0x2 | |||||
#define I2C_HID_REPORT_TYPE_FEATURE 0x3 | |||||
/* 7.2 */ | |||||
enum { | |||||
I2C_HID_CMD_DESCR = 0x0, | |||||
I2C_HID_CMD_RESET = 0x1, | |||||
I2C_HID_CMD_GET_REPORT = 0x2, | |||||
I2C_HID_CMD_SET_REPORT = 0x3, | |||||
I2C_HID_CMD_GET_IDLE = 0x4, | |||||
I2C_HID_CMD_SET_IDLE = 0x5, | |||||
I2C_HID_CMD_GET_PROTO = 0x6, | |||||
I2C_HID_CMD_SET_PROTO = 0x7, | |||||
I2C_HID_CMD_SET_POWER = 0x8, | |||||
/* pseudo commands */ | |||||
I2C_HID_REPORT_DESCR = 0x100, | |||||
}; | |||||
#define I2C_HID_POWER_ON = 0x0; | |||||
#define I2C_HID_POWER_OFF = 0x1; | |||||
/* 5.1.1 - HID Descriptor Format */ | |||||
struct i2c_hid_desc { | |||||
uint16_t wHIDDescLength; | |||||
uint16_t bcdVersion; | |||||
uint16_t wReportDescLength; | |||||
uint16_t wReportDescRegister; | |||||
uint16_t wInputRegister; | |||||
uint16_t wMaxInputLength; | |||||
uint16_t wOutputRegister; | |||||
uint16_t wMaxOutputLength; | |||||
uint16_t wCommandRegister; | |||||
uint16_t wDataRegister; | |||||
uint16_t wVendorID; | |||||
uint16_t wProductID; | |||||
uint16_t wVersionID; | |||||
uint32_t reserved; | |||||
} __packed; | |||||
#define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE) | |||||
#define MOUSE_FLAGS (HIO_RELATIVE) | |||||
#define MS_BUF_SIZE 8 /* bytes */ | |||||
#define MS_BUFQ_MAXLEN 100 /* units */ | |||||
#define MS_BUTTON_MAX 31 /* exclusive, must be less than 32 */ | |||||
#define MS_BUT(i) ((i) < 3 ? (((i) + 2) % 3) : (i)) | |||||
#define MS_INFO_MAX 2 /* maximum number of HID sets */ | |||||
struct ms_info { | |||||
struct hid_location sc_loc_w; | |||||
struct hid_location sc_loc_x; | |||||
struct hid_location sc_loc_y; | |||||
struct hid_location sc_loc_z; | |||||
struct hid_location sc_loc_t; | |||||
struct hid_location sc_loc_btn[MS_BUTTON_MAX]; | |||||
uint32_t sc_flags; | |||||
#define MS_FLAG_X_AXIS 0x0001 | |||||
#define MS_FLAG_Y_AXIS 0x0002 | |||||
#define MS_FLAG_Z_AXIS 0x0004 | |||||
#define MS_FLAG_T_AXIS 0x0008 | |||||
#define MS_FLAG_SBU 0x0010 /* spurious button up events */ | |||||
#define MS_FLAG_REVZ 0x0020 /* Z-axis is reversed */ | |||||
#define MS_FLAG_W_AXIS 0x0040 | |||||
uint8_t sc_iid_w; | |||||
uint8_t sc_iid_x; | |||||
uint8_t sc_iid_y; | |||||
uint8_t sc_iid_z; | |||||
uint8_t sc_iid_t; | |||||
uint8_t sc_iid_btn[MS_BUTTON_MAX]; | |||||
uint8_t sc_buttons; | |||||
}; | |||||
struct iichid_hw { | |||||
uint8_t device_addr; | |||||
uint16_t config_reg; | |||||
}; | |||||
struct ms_tx_entry { | |||||
STAILQ_ENTRY(ms_tx_entry) next; | |||||
uint8_t buf[MS_BUF_SIZE]; | |||||
}; | |||||
STAILQ_HEAD(ms_tx_buf, ms_tx_entry); | |||||
struct iichid_softc { | |||||
device_t dev; | |||||
struct cdev *cdev; | |||||
bool isopen; | |||||
struct ms_tx_entry rbuf; | |||||
uint8_t bytesread; | |||||
struct ms_tx_buf ms_unused_blocks; | |||||
struct ms_tx_buf ms_queue; | |||||
struct iichid_hw hw; | |||||
driver_intr_t* intr_handler; | |||||
struct i2c_hid_desc desc; | |||||
struct ms_info info[MS_INFO_MAX]; | |||||
uint8_t sc_iid; | |||||
mousehw_t sc_hw; | |||||
mousestatus_t sc_status; | |||||
mousemode_t sc_mode; | |||||
struct mtx lock; | |||||
struct cv cv; | |||||
bool detaching; | |||||
uint8_t *input_buf; | |||||
int input_size; | |||||
}; | |||||
struct iichid_acpi_softc { | |||||
device_t dev; | |||||
struct cdev *sc_devnode; | |||||
struct iichid_hw hw; | |||||
uint16_t irq; | |||||
int irq_rid; | |||||
struct resource* irq_res; | |||||
void* irq_cookie; | |||||
struct mtx lock; | |||||
}; | |||||
int iichid_acpi_get_report(device_t dev, struct i2c_hid_desc* hid_desc, enum hid_kind type, int id, void *data, int len); | |||||
#endif /* _IIC_HID_H_ */ |