Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __HID_WIIMOTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __HID_WIIMOTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * HID driver for Nintendo Wii / Wii U peripherals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define WIIMOTE_NAME "Nintendo Wii Remote"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define WIIMOTE_BUFSIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define WIIPROTO_FLAG_LED1		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define WIIPROTO_FLAG_LED2		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define WIIPROTO_FLAG_LED3		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define WIIPROTO_FLAG_LED4		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define WIIPROTO_FLAG_RUMBLE		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define WIIPROTO_FLAG_ACCEL		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define WIIPROTO_FLAG_IR_BASIC		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define WIIPROTO_FLAG_IR_EXT		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define WIIPROTO_FLAG_IR_FULL		0xc0 /* IR_BASIC | IR_EXT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define WIIPROTO_FLAG_EXT_PLUGGED	0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define WIIPROTO_FLAG_EXT_USED		0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define WIIPROTO_FLAG_EXT_ACTIVE	0x0400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define WIIPROTO_FLAG_MP_PLUGGED	0x0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define WIIPROTO_FLAG_MP_USED		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define WIIPROTO_FLAG_MP_ACTIVE		0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define WIIPROTO_FLAG_EXITING		0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define WIIPROTO_FLAG_DRM_LOCKED	0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define WIIPROTO_FLAG_BUILTIN_MP	0x010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define WIIPROTO_FLAG_NO_MP		0x020000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define WIIPROTO_FLAG_PRO_CALIB_DONE	0x040000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 					WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 							WIIPROTO_FLAG_IR_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* return flag for led \num */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) enum wiiproto_keys {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	WIIPROTO_KEY_LEFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	WIIPROTO_KEY_RIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	WIIPROTO_KEY_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	WIIPROTO_KEY_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	WIIPROTO_KEY_PLUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	WIIPROTO_KEY_MINUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	WIIPROTO_KEY_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	WIIPROTO_KEY_TWO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	WIIPROTO_KEY_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	WIIPROTO_KEY_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	WIIPROTO_KEY_HOME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	WIIPROTO_KEY_COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) enum wiimote_devtype {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	WIIMOTE_DEV_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	WIIMOTE_DEV_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	WIIMOTE_DEV_GENERIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	WIIMOTE_DEV_GEN10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	WIIMOTE_DEV_GEN20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	WIIMOTE_DEV_BALANCE_BOARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	WIIMOTE_DEV_PRO_CONTROLLER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	WIIMOTE_DEV_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) enum wiimote_exttype {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	WIIMOTE_EXT_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	WIIMOTE_EXT_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	WIIMOTE_EXT_NUNCHUK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	WIIMOTE_EXT_CLASSIC_CONTROLLER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	WIIMOTE_EXT_BALANCE_BOARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	WIIMOTE_EXT_PRO_CONTROLLER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	WIIMOTE_EXT_DRUMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	WIIMOTE_EXT_GUITAR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	WIIMOTE_EXT_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) enum wiimote_mptype {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	WIIMOTE_MP_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	WIIMOTE_MP_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	WIIMOTE_MP_SINGLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	WIIMOTE_MP_PASSTHROUGH_NUNCHUK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	WIIMOTE_MP_PASSTHROUGH_CLASSIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct wiimote_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	__u8 data[HID_MAX_BUFFER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct wiimote_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct work_struct worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	__u8 head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	__u8 tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct wiimote_buf outq[WIIMOTE_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct wiimote_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	__u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	__u8 accel_split[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	__u8 drm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	__u8 devtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	__u8 exttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	__u8 mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	/* synchronous cmd requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct mutex sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct completion ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	__u32 opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* results of synchronous requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	__u8 cmd_battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	__u8 cmd_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	__u8 *cmd_read_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	__u8 cmd_read_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* calibration/cache data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	__u16 calib_bboard[4][3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	__s16 calib_pro_sticks[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	__u8 pressure_drums[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	__u8 cache_rumble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct wiimote_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct hid_device *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct work_struct rumble_worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct led_classdev *leds[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct input_dev *accel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct input_dev *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct power_supply *battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct power_supply_desc battery_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct input_dev *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct wiimote_debug *debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	} extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct wiimote_queue queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct wiimote_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct work_struct init_worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) extern bool wiimote_dpad_as_analog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* wiimote modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) enum wiimod_module {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	WIIMOD_KEYS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	WIIMOD_RUMBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	WIIMOD_BATTERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	WIIMOD_LED1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	WIIMOD_LED2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	WIIMOD_LED3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	WIIMOD_LED4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	WIIMOD_ACCEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	WIIMOD_IR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	WIIMOD_BUILTIN_MP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	WIIMOD_NO_MP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	WIIMOD_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	WIIMOD_NULL = WIIMOD_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define WIIMOD_FLAG_INPUT		0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define WIIMOD_FLAG_EXT8		0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define WIIMOD_FLAG_EXT16		0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct wiimod_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	__u16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	unsigned long arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int (*probe) (const struct wiimod_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		      struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	void (*remove) (const struct wiimod_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	void (*in_keys) (struct wiimote_data *wdata, const __u8 *keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	void (*in_accel) (struct wiimote_data *wdata, const __u8 *accel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	void (*in_ir) (struct wiimote_data *wdata, const __u8 *ir, bool packed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		       unsigned int id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	void (*in_mp) (struct wiimote_data *wdata, const __u8 *mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	void (*in_ext) (struct wiimote_data *wdata, const __u8 *ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern const struct wiimod_ops *wiimod_table[WIIMOD_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) extern const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) extern const struct wiimod_ops wiimod_mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* wiimote requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) enum wiiproto_reqs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	WIIPROTO_REQ_NULL = 0x0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	WIIPROTO_REQ_RUMBLE = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	WIIPROTO_REQ_LED = 0x11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	WIIPROTO_REQ_DRM = 0x12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	WIIPROTO_REQ_IR1 = 0x13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	WIIPROTO_REQ_SREQ = 0x15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	WIIPROTO_REQ_WMEM = 0x16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	WIIPROTO_REQ_RMEM = 0x17,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	WIIPROTO_REQ_IR2 = 0x1a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	WIIPROTO_REQ_STATUS = 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	WIIPROTO_REQ_DATA = 0x21,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	WIIPROTO_REQ_RETURN = 0x22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* DRM_K: BB*2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	WIIPROTO_REQ_DRM_K = 0x30,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	/* DRM_KA: BB*2 AA*3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	WIIPROTO_REQ_DRM_KA = 0x31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* DRM_KE: BB*2 EE*8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	WIIPROTO_REQ_DRM_KE = 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/* DRM_KAI: BB*2 AA*3 II*12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	WIIPROTO_REQ_DRM_KAI = 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* DRM_KEE: BB*2 EE*19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	WIIPROTO_REQ_DRM_KEE = 0x34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* DRM_KAE: BB*2 AA*3 EE*16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	WIIPROTO_REQ_DRM_KAE = 0x35,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* DRM_KIE: BB*2 II*10 EE*9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	WIIPROTO_REQ_DRM_KIE = 0x36,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* DRM_KAIE: BB*2 AA*3 II*10 EE*6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	WIIPROTO_REQ_DRM_KAIE = 0x37,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* DRM_E: EE*21 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	WIIPROTO_REQ_DRM_E = 0x3d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* DRM_SKAI1: BB*2 AA*1 II*18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	WIIPROTO_REQ_DRM_SKAI1 = 0x3e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/* DRM_SKAI2: BB*2 AA*1 II*18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	WIIPROTO_REQ_DRM_SKAI2 = 0x3f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	WIIPROTO_REQ_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define dev_to_wii(pdev) hid_get_drvdata(to_hid_device(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void __wiimote_schedule(struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) extern void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) extern void wiiproto_req_rumble(struct wiimote_data *wdata, __u8 rumble);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) extern void wiiproto_req_leds(struct wiimote_data *wdata, int leds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) extern void wiiproto_req_status(struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) extern void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) extern void wiiproto_req_ir1(struct wiimote_data *wdata, __u8 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) extern void wiiproto_req_ir2(struct wiimote_data *wdata, __u8 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) extern int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 						const __u8 *wmem, __u8 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) extern ssize_t wiimote_cmd_read(struct wiimote_data *wdata, __u32 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 							__u8 *rmem, __u8 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define wiiproto_req_rreg(wdata, os, sz) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				wiiproto_req_rmem((wdata), false, (os), (sz))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define wiiproto_req_reeprom(wdata, os, sz) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				wiiproto_req_rmem((wdata), true, (os), (sz))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) extern void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 						__u32 offset, __u16 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) extern int wiidebug_init(struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) extern void wiidebug_deinit(struct wiimote_data *wdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static inline int wiidebug_init(void *u) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static inline void wiidebug_deinit(void *u) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* requires the state.lock spinlock to be held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 								__u32 opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return wdata->state.cmd == cmd && wdata->state.opt == opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* requires the state.lock spinlock to be held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline void wiimote_cmd_complete(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	wdata->state.cmd = WIIPROTO_REQ_NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	complete(&wdata->state.ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* requires the state.lock spinlock to be held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static inline void wiimote_cmd_abort(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* Abort synchronous request by waking up the sleeping caller. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * reset the state.cmd field to an invalid value so no further event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 * handlers will work with it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	wdata->state.cmd = WIIPROTO_REQ_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	complete(&wdata->state.ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static inline int wiimote_cmd_acquire(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static inline void wiimote_cmd_acquire_noint(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	mutex_lock(&wdata->state.sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* requires the state.lock spinlock to be held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 								__u32 opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	reinit_completion(&wdata->state.ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	wdata->state.cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	wdata->state.opt = opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static inline void wiimote_cmd_release(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	mutex_unlock(&wdata->state.sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static inline int wiimote_cmd_wait(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* The completion acts as implicit memory barrier so we can safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 * assume that state.cmd is set on success/failure and isn't accessed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * by any other thread, anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	else if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	else if (wdata->state.cmd != WIIPROTO_REQ_NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static inline int wiimote_cmd_wait_noint(struct wiimote_data *wdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	unsigned long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	/* no locking needed; see wiimote_cmd_wait() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	ret = wait_for_completion_timeout(&wdata->state.ready, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	else if (wdata->state.cmd != WIIPROTO_REQ_NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #endif