Path: blob/master/drivers/input/joystick/iforce/iforce.h
15115 views
/*1* Copyright (c) 2000-2002 Vojtech Pavlik <[email protected]>2* Copyright (c) 2001-2002, 2007 Johann Deneux <[email protected]>3*4* USB/RS232 I-Force joysticks and wheels.5*/67/*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA21*22* Should you need to contact me, the author, you can do so either by23* e-mail - mail your message to <[email protected]>, or by paper mail:24* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic25*/2627#include <linux/kernel.h>28#include <linux/slab.h>29#include <linux/input.h>30#include <linux/module.h>31#include <linux/init.h>32#include <linux/spinlock.h>33#include <linux/usb.h>34#include <linux/serio.h>35#include <linux/circ_buf.h>36#include <linux/mutex.h>3738/* This module provides arbitrary resource management routines.39* I use it to manage the device's memory.40* Despite the name of this module, I am *not* going to access the ioports.41*/42#include <linux/ioport.h>434445#define IFORCE_MAX_LENGTH 164647/* iforce::bus */48#define IFORCE_232 149#define IFORCE_USB 25051#define IFORCE_EFFECTS_MAX 325253/* Each force feedback effect is made of one core effect, which can be54* associated to at most to effect modifiers55*/56#define FF_MOD1_IS_USED 057#define FF_MOD2_IS_USED 158#define FF_CORE_IS_USED 259#define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */60#define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */61#define FF_CORE_UPDATE 5 /* Effect is being updated */62#define FF_MODCORE_CNT 66364struct iforce_core_effect {65/* Information about where modifiers are stored in the device's memory */66struct resource mod1_chunk;67struct resource mod2_chunk;68unsigned long flags[BITS_TO_LONGS(FF_MODCORE_CNT)];69};7071#define FF_CMD_EFFECT 0x010e72#define FF_CMD_ENVELOPE 0x020873#define FF_CMD_MAGNITUDE 0x030374#define FF_CMD_PERIOD 0x040775#define FF_CMD_CONDITION 0x050a7677#define FF_CMD_AUTOCENTER 0x400278#define FF_CMD_PLAY 0x410379#define FF_CMD_ENABLE 0x420180#define FF_CMD_GAIN 0x43018182#define FF_CMD_QUERY 0xff018384/* Buffer for async write */85#define XMIT_SIZE 25686#define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -187/* iforce::xmit_flags */88#define IFORCE_XMIT_RUNNING 089#define IFORCE_XMIT_AGAIN 19091struct iforce_device {92u16 idvendor;93u16 idproduct;94char *name;95signed short *btn;96signed short *abs;97signed short *ff;98};99100struct iforce {101struct input_dev *dev; /* Input device interface */102struct iforce_device *type;103int bus;104105unsigned char data[IFORCE_MAX_LENGTH];106unsigned char edata[IFORCE_MAX_LENGTH];107u16 ecmd;108u16 expect_packet;109110#ifdef CONFIG_JOYSTICK_IFORCE_232111struct serio *serio; /* RS232 transfer */112int idx, pkt, len, id;113unsigned char csum;114#endif115#ifdef CONFIG_JOYSTICK_IFORCE_USB116struct usb_device *usbdev; /* USB transfer */117struct urb *irq, *out, *ctrl;118struct usb_ctrlrequest cr;119#endif120spinlock_t xmit_lock;121/* Buffer used for asynchronous sending of bytes to the device */122struct circ_buf xmit;123unsigned char xmit_data[XMIT_SIZE];124unsigned long xmit_flags[1];125126/* Force Feedback */127wait_queue_head_t wait;128struct resource device_memory;129struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];130struct mutex mem_mutex;131};132133/* Get hi and low bytes of a 16-bits int */134#define HI(a) ((unsigned char)((a) >> 8))135#define LO(a) ((unsigned char)((a) & 0xff))136137/* For many parameters, it seems that 0x80 is a special value that should138* be avoided. Instead, we replace this value by 0x7f139*/140#define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))141142/* Encode a time value */143#define TIME_SCALE(a) (a)144145146/* Public functions */147/* iforce-serio.c */148void iforce_serial_xmit(struct iforce *iforce);149150/* iforce-usb.c */151void iforce_usb_xmit(struct iforce *iforce);152153/* iforce-main.c */154int iforce_init_device(struct iforce *iforce);155156/* iforce-packets.c */157int iforce_control_playback(struct iforce*, u16 id, unsigned int);158void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);159int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);160void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;161int iforce_get_id_packet(struct iforce *iforce, char *packet);162163/* iforce-ff.c */164int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);165int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);166int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);167168/* Public variables */169extern struct serio_driver iforce_serio_drv;170extern struct usb_driver iforce_usb_driver;171172173