头文件:
/*
* filename: rohm_scm_proximity.h
*/
#ifndef __ROHM_SCM_PROXIMTIY__
#define __ROHM_SCM_PROXIMTIY__
#define ROHM_PROXIMITY "rohm_proximity"
#define PROXIMITY_DEVICE "rohm_proximity"
#include <linux/types.h>
#include <linux/ioctl.h>
#define ROHM_PROXIMITY_IOCTL_MAGIC 'r'
#define ROHM_PROXIMITY_IOCTL_GET_ENABLED _IOR(ROHM_PROXIMITY_IOCTL_MAGIC, 1, int *)
#define ROHM_PROXIMITY_IOCTL_ENABLE _IOW(ROHM_PROXIMITY_IOCTL_MAGIC, 2, int *)
#endif
/*
* File: rohm_scm_proximity.c
* Based on:
* Author: Yunlong Wang <Yunlong.Wang@spreadtrum.com>
*
* Created: 2011-04-08
* Description: Rohm Proximity Sensor Driver
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/platform_device.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/wakelock.h>
#include <mach/mfp.h>
#include <mach/adc_drvapi.h>
#include "rohm_scm_proximity.h"
#define PS_DEBUG 1
#define RHOM_PROXIMITY_DATA_POLL_TIMER 100
#define RHOM_PROXIMITY_THRESHOLD 500
#define RHOM_PROXIMITY_ADC_CHANNEL 1
//static int debug_level=0;
static int debug_level=1;
#if PS_DEBUG
#define PS_DBG(format, ...) \
if(debug_level == 1) \
printk(KERN_INFO "PROXIMITY: " format , ## __VA_ARGS__)
#else
#define PS_DBG(format, ...)
#endif
extern int sprd_3rdparty_gpio_proximity_trans;
extern int sprd_3rdparty_gpio_proximity_recv;
struct rohm_proximity_platform_data {
int gpio_trans; /*control transmit light*/
int gpio_recv; /*control recevie light*/
};
static struct rohm_proximity_platform_data proximity_platform_data;
static struct wake_lock prox_delayed_work_wake_lock;
static struct rohm_proximity_data {
struct input_dev *input_dev;
struct rohm_proximity_platform_data *pdata;
struct delayed_work work;
struct workqueue_struct *work_queue;
int enabled;
} proximity_data;
static int misc_opened;
static int p