Path: blob/master/drivers/input/gameport/fm801-gp.c
17531 views
/*1* FM801 gameport driver for Linux2*3* Copyright (c) by Takashi Iwai <[email protected]>4*5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.19*20*/2122#include <asm/io.h>23#include <linux/delay.h>24#include <linux/errno.h>25#include <linux/ioport.h>26#include <linux/kernel.h>27#include <linux/module.h>28#include <linux/pci.h>29#include <linux/init.h>30#include <linux/slab.h>31#include <linux/gameport.h>3233#define PCI_VENDOR_ID_FORTEMEDIA 0x131934#define PCI_DEVICE_ID_FM801_GP 0x08023536#define HAVE_COOKED3738struct fm801_gp {39struct gameport *gameport;40struct resource *res_port;41};4243#ifdef HAVE_COOKED44static int fm801_gp_cooked_read(struct gameport *gameport, int *axes, int *buttons)45{46unsigned short w;4748w = inw(gameport->io + 2);49*buttons = (~w >> 14) & 0x03;50axes[0] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);51w = inw(gameport->io + 4);52axes[1] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);53w = inw(gameport->io + 6);54*buttons |= ((~w >> 14) & 0x03) << 2;55axes[2] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);56w = inw(gameport->io + 8);57axes[3] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);58outw(0xff, gameport->io); /* reset */5960return 0;61}62#endif6364static int fm801_gp_open(struct gameport *gameport, int mode)65{66switch (mode) {67#ifdef HAVE_COOKED68case GAMEPORT_MODE_COOKED:69return 0;70#endif71case GAMEPORT_MODE_RAW:72return 0;73default:74return -1;75}7677return 0;78}7980static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device_id *id)81{82struct fm801_gp *gp;83struct gameport *port;84int error;8586gp = kzalloc(sizeof(struct fm801_gp), GFP_KERNEL);87port = gameport_allocate_port();88if (!gp || !port) {89printk(KERN_ERR "fm801-gp: Memory allocation failed\n");90error = -ENOMEM;91goto err_out_free;92}9394error = pci_enable_device(pci);95if (error)96goto err_out_free;9798port->open = fm801_gp_open;99#ifdef HAVE_COOKED100port->cooked_read = fm801_gp_cooked_read;101#endif102gameport_set_name(port, "FM801");103gameport_set_phys(port, "pci%s/gameport0", pci_name(pci));104port->dev.parent = &pci->dev;105port->io = pci_resource_start(pci, 0);106107gp->gameport = port;108gp->res_port = request_region(port->io, 0x10, "FM801 GP");109if (!gp->res_port) {110printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n",111port->io, port->io + 0x0f);112error = -EBUSY;113goto err_out_disable_dev;114}115116pci_set_drvdata(pci, gp);117118outb(0x60, port->io + 0x0d); /* enable joystick 1 and 2 */119gameport_register_port(port);120121return 0;122123err_out_disable_dev:124pci_disable_device(pci);125err_out_free:126gameport_free_port(port);127kfree(gp);128return error;129}130131static void __devexit fm801_gp_remove(struct pci_dev *pci)132{133struct fm801_gp *gp = pci_get_drvdata(pci);134135gameport_unregister_port(gp->gameport);136release_resource(gp->res_port);137kfree(gp);138139pci_disable_device(pci);140}141142static const struct pci_device_id fm801_gp_id_table[] = {143{ PCI_VENDOR_ID_FORTEMEDIA, PCI_DEVICE_ID_FM801_GP, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },144{ 0 }145};146147static struct pci_driver fm801_gp_driver = {148.name = "FM801_gameport",149.id_table = fm801_gp_id_table,150.probe = fm801_gp_probe,151.remove = __devexit_p(fm801_gp_remove),152};153154static int __init fm801_gp_init(void)155{156return pci_register_driver(&fm801_gp_driver);157}158159static void __exit fm801_gp_exit(void)160{161pci_unregister_driver(&fm801_gp_driver);162}163164module_init(fm801_gp_init);165module_exit(fm801_gp_exit);166167MODULE_DEVICE_TABLE(pci, fm801_gp_id_table);168169MODULE_DESCRIPTION("FM801 gameport driver");170MODULE_AUTHOR("Takashi Iwai <[email protected]>");171MODULE_LICENSE("GPL");172173174