/*****************************************************************************/
/* Copyright (c) 2008 NXP B.V.                                               */
/*                                                                           */
/* This program is free software; you can redistribute it and/or modify      */
/* it under the terms of the GNU General Public License as published by      */
/* the Free Software Foundation, using version 2 of the License.             */
/*                                                                           */
/* This program is distributed in the hope that it will be useful,           */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              */
/* GNU General Public License for more details.                              */
/*                                                                           */
/* You should have received a copy of the GNU General Public License         */
/* along with this program; if not, write to the Free Software               */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307       */
/* USA.                                                                      */
/*                                                                           */
/*****************************************************************************/
/**
    @file   phStbIR.c
    @brief  Linux implementation of the Infra-red remote control driver.

    @b  Module:  phStbIR Infra-red remote control driver.

*//*

    This is the Linux implementation of the Infra-red remote control driver.



Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 20070116    neill       Original
  2 20070117    steel       update for kernel 2.6.19.1
  3 20070118    neill       Change class device name
  4 20070131    neill       Use consistant naming
  5 20071010    ashetty     Modify Repeat delay for NF remote control
  7 20080205    batelaan    Update file copyright/license text
  8 20080829    batelaan    Print error if input_register_device fails
  9 20081118    neill       Implement a more reliable key repeat mechanism
 10 20090121    batelaan    Update author/license.
--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.
*/

#define __PHSTBIR_C__

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/major.h>

#include <linux/input.h>

#include <linux/string.h>

#include "phStbIR.h"
#include "phStbRCProtocol.h"

#define PHSTBIR_EVENT_ID 0

//  ----------------------- PHSTBIR MODULE Generic Decriptions   ----------------
#define THIS_MODULE_DESCRIPTION     PHSTBIR_MODULE_DESCRIPTION
MODULE_DESCRIPTION(THIS_MODULE_DESCRIPTION);
MODULE_AUTHOR("NXP B.V.");
MODULE_LICENSE("GPL v2");

//  ****************************************************************************
//  *                                                                          *
//  *                           M O D U L E    S T R U C T U R E S             *
//  *                                                                          *
//  ****************************************************************************

static struct input_dev *phStbIR_input_dev;

//  ----------------------- MODULE INIT     ------------------------------------
static int __init phStbIR_init (void)
{
    int error;

    // intialize structure
    phStbIR_input_dev = input_allocate_device();

    phStbIR_input_dev->name = "STB225 Infra-red";
    phStbIR_input_dev->phys = "";

    phStbIR_input_dev->id.bustype = BUS_HOST;
    phStbIR_input_dev->id.vendor  = 0x0001;
    phStbIR_input_dev->id.product = 0x0001;
    phStbIR_input_dev->id.version = 0x0001;

    set_bit(EV_KEY, phStbIR_input_dev->evbit);

    phStbRCProtocol_init(phStbIR_input_dev);

    error = input_register_device(phStbIR_input_dev );
    if (error) {
      printk (KERN_ERR "Could not register device %s (%s-%s)\n", PHSTBIR_MODULE_DESCRIPTION, __DATE__, __TIME__);
      input_free_device(phStbIR_input_dev);
      return error;
    }

    class_device_create(&input_class, NULL,
                         MKDEV(INPUT_MAJOR,PHSTBIR_EVENT_ID),
                         phStbIR_input_dev->cdev.dev, 
                         "infra_red");

    // set repeat/auto-repeat
    // NOTE: The default input layer repeat code is only used if rep[] is NOT set (default
    //       delays are used). 
    //       So set up delays AFTER input_register_device() has been called.
    phStbRCProtocol_setRepeatDelay (phStbIR_input_dev);

    printk ("%s (%s-%s)\n", PHSTBIR_MODULE_DESCRIPTION, __DATE__, __TIME__);
    return 0;
}

//  ----------------------- MODULE EXIT     ------------------------------------
static void __exit phStbIR_exit (void)
{
   class_device_destroy(&input_class, MKDEV(INPUT_MAJOR, PHSTBIR_EVENT_ID));
   input_unregister_device( phStbIR_input_dev );
}

//  ----------------------- MODULE MANAGEMENT   --------------------------------
module_init(phStbIR_init);
module_exit(phStbIR_exit);
