123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- /*
- * Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
- *
- * 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 "../ssp.h"
- #define VENDOR "MAXIM"
- #define CHIP_ID "MAX88005"
- #define CANCELATION_FILE_PATH "/efs/prox_cal"
- #define LCD_LDI_FILE_PATH "/sys/class/lcd/panel/window_type"
- #define LINE_1 '4'
- #define LINE_2 '2'
- #define LDI_OTHERS '0'
- #define LDI_GRAY '1'
- #define LDI_WHITE '2'
- /*************************************************************************/
- /* factory Sysfs */
- /*************************************************************************/
- static ssize_t prox_vendor_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return sprintf(buf, "%s\n", VENDOR);
- }
- static ssize_t prox_name_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return sprintf(buf, "%s\n", CHIP_ID);
- }
- static ssize_t proximity_avg_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct ssp_data *data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%d,%d,%d\n",
- data->buf[PROXIMITY_RAW].prox[1],
- data->buf[PROXIMITY_RAW].prox[2],
- data->buf[PROXIMITY_RAW].prox[3]);
- }
- static ssize_t proximity_avg_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- char chTempbuf[2] = { 1, 20};
- int iRet;
- int64_t dEnable;
- struct ssp_data *data = dev_get_drvdata(dev);
- iRet = kstrtoll(buf, 10, &dEnable);
- if (iRet < 0)
- return iRet;
- if (dEnable) {
- send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, chTempbuf, 2);
- data->bProximityRawEnabled = true;
- } else {
- send_instruction(data, REMOVE_SENSOR, PROXIMITY_RAW,
- chTempbuf, 2);
- data->bProximityRawEnabled = false;
- }
- return size;
- }
- static unsigned char get_proximity_rawdata(struct ssp_data *data)
- {
- unsigned char uRowdata = 0;
- char chTempbuf[2] = { 1, 20};
- if (data->bProximityRawEnabled == false) {
- send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, chTempbuf, 2);
- msleep(200);
- uRowdata = data->buf[PROXIMITY_RAW].prox[0];
- send_instruction(data, REMOVE_SENSOR, PROXIMITY_RAW,
- chTempbuf, 2);
- } else {
- uRowdata = data->buf[PROXIMITY_RAW].prox[0];
- }
- return uRowdata;
- }
- static ssize_t proximity_state_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct ssp_data *data = dev_get_drvdata(dev);
- return sprintf(buf, "%u\n", get_proximity_rawdata(data));
- }
- static int get_proximity_threshold(struct ssp_data *data)
- {
- if (data->uProxCanc <= (DEFAULT_THRESHOLD_LOW >> 1))
- return FAIL;
- data->uProxThreshHi = DEFAULT_THRESHOLD_HI
- + (data->uProxCanc - (DEFAULT_THRESHOLD_LOW >> 1));
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW
- + (data->uProxCanc - (DEFAULT_THRESHOLD_LOW >> 1));
- return SUCCESS;
- }
- static void change_proximity_default_threshold(struct ssp_data *data)
- {
- switch (data->chLcdLdi[1]) {
- case LDI_GRAY:
- data->uProxThreshHi = GRAY_OCTA_DEFAULT_THRESHOLD;
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW;
- break;
- case LDI_WHITE:
- data->uProxThreshHi = WHITE_OCTA_DEFAULT_THRESHOLD;
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW;
- break;
- case LDI_OTHERS:
- data->uProxThreshHi = OTHERS_OCTA_DEFAULT_THRESHOLD;
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW;
- break;
- default:
- data->uProxThreshHi = DEFAULT_THRESHOLD_HI;
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW;
- break;
- }
- }
- int proximity_open_lcd_ldi(struct ssp_data *data)
- {
- int iRet = 0;
- mm_segment_t old_fs;
- struct file *cancel_filp = NULL;
- old_fs = get_fs();
- set_fs(KERNEL_DS);
- cancel_filp = filp_open(LCD_LDI_FILE_PATH, O_RDONLY, 0666);
- if (IS_ERR(cancel_filp)) {
- iRet = PTR_ERR(cancel_filp);
- if (iRet != -ENOENT)
- pr_err("[SSP]: %s - Can't open lcd ldi file\n",
- __func__);
- set_fs(old_fs);
- data->chLcdLdi[0] = 0;
- data->chLcdLdi[1] = 0;
- goto exit;
- }
- iRet = cancel_filp->f_op->read(cancel_filp,
- (u8 *)data->chLcdLdi, sizeof(u8) * 2, &cancel_filp->f_pos);
- if (iRet != (sizeof(u8) * 2)) {
- pr_err("[SSP]: %s - Can't read the lcd ldi data\n", __func__);
- iRet = -EIO;
- }
- ssp_dbg("[SSP]: %s - %c%c\n", __func__,
- data->chLcdLdi[0], data->chLcdLdi[1]);
- filp_close(cancel_filp, current->files);
- set_fs(old_fs);
- exit:
- change_proximity_default_threshold(data);
- return iRet;
- }
- int proximity_open_calibration(struct ssp_data *data)
- {
- int iRet = 0;
- mm_segment_t old_fs;
- struct file *cancel_filp = NULL;
- old_fs = get_fs();
- set_fs(KERNEL_DS);
- cancel_filp = filp_open(CANCELATION_FILE_PATH, O_RDONLY, 0666);
- if (IS_ERR(cancel_filp)) {
- iRet = PTR_ERR(cancel_filp);
- if (iRet != -ENOENT)
- pr_err("[SSP]: %s - Can't open cancelation file\n",
- __func__);
- set_fs(old_fs);
- goto exit;
- }
- iRet = cancel_filp->f_op->read(cancel_filp,
- (u8 *)&data->uProxCanc, sizeof(u8), &cancel_filp->f_pos);
- if (iRet != sizeof(u8)) {
- pr_err("[SSP]: %s - Can't read the cancel data\n", __func__);
- iRet = -EIO;
- }
- if (data->uProxCanc != 0) /*If there is an offset cal data. */
- get_proximity_threshold(data);
- pr_info("%s: proximity ps_canc = %d, ps_thresh hi - %d lo - %d\n",
- __func__, data->uProxCanc, data->uProxThreshHi,
- data->uProxThreshLow);
- filp_close(cancel_filp, current->files);
- set_fs(old_fs);
- exit:
- set_proximity_threshold(data);
- return iRet;
- }
- static int proximity_store_cancelation(struct ssp_data *data, int iCalCMD)
- {
- int iRet = 0;
- mm_segment_t old_fs;
- struct file *cancel_filp = NULL;
- if (iCalCMD) {
- data->uProxCanc = get_proximity_rawdata(data);
- get_proximity_threshold(data);
- } else {
- data->uProxThreshHi = DEFAULT_THRESHOLD_HI;
- data->uProxThreshLow = DEFAULT_THRESHOLD_LOW;
- data->uProxCanc = 0;
- }
- set_proximity_threshold(data);
- old_fs = get_fs();
- set_fs(KERNEL_DS);
- cancel_filp = filp_open(CANCELATION_FILE_PATH,
- O_CREAT | O_TRUNC | O_WRONLY, 0666);
- if (IS_ERR(cancel_filp)) {
- pr_err("%s: Can't open cancelation file\n", __func__);
- set_fs(old_fs);
- iRet = PTR_ERR(cancel_filp);
- return iRet;
- }
- iRet = cancel_filp->f_op->write(cancel_filp, (u8 *)&data->uProxCanc,
- sizeof(u8), &cancel_filp->f_pos);
- if (iRet != sizeof(u8)) {
- pr_err("%s: Can't write the cancel data to file\n", __func__);
- iRet = -EIO;
- }
- filp_close(cancel_filp, current->files);
- set_fs(old_fs);
- return iRet;
- }
- static ssize_t proximity_cancel_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct ssp_data *data = dev_get_drvdata(dev);
- ssp_dbg("[SSP]: uProxThresh : hi : %u lo : %u, uProxCanc = %u\n",
- data->uProxThreshHi, data->uProxThreshLow, data->uProxCanc);
- return sprintf(buf, "%u,%u\n", data->uProxCanc, data->uProxThreshHi);
- }
- static ssize_t proximity_cancel_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- int iCalCMD = 0, iRet = 0;
- struct ssp_data *data = dev_get_drvdata(dev);
- if (sysfs_streq(buf, "1")) /* calibrate cancelation value */
- iCalCMD = 1;
- else if (sysfs_streq(buf, "0")) /* reset cancelation value */
- iCalCMD = 0;
- else {
- pr_debug("%s: invalid value %d\n", __func__, *buf);
- return -EINVAL;
- }
- iRet = proximity_store_cancelation(data, iCalCMD);
- if (iRet < 0) {
- pr_err("[SSP]: - %s proximity_store_cancelation() failed\n",
- __func__);
- return iRet;
- }
- ssp_dbg("[SSP]: %s - %u\n", __func__, iCalCMD);
- return size;
- }
- static ssize_t proximity_thresh_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct ssp_data *data = dev_get_drvdata(dev);
- ssp_dbg("[SSP]: uProxThresh = hi - %u, lo - %u\n",
- data->uProxThreshHi, data->uProxThreshLow);
- return sprintf(buf, "%u\n", data->uProxThreshHi);
- }
- static ssize_t proximity_thresh_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- char chTemp;
- u8 uNewThresh = DEFAULT_THRESHOLD_HI;
- int iRet = 0;
- struct ssp_data *data = dev_get_drvdata(dev);
- iRet = kstrtou8(buf, 10, &uNewThresh);
- if (iRet < 0)
- pr_err("[SSP]: %s - kstrtoint failed.", __func__);
- chTemp = uNewThresh - DEFAULT_THRESHOLD_HI;
- if (chTemp < 0)
- chTemp = 0;
- data->uProxThreshHi = uNewThresh;
- data->uProxThreshLow = (unsigned char)(DEFAULT_THRESHOLD_LOW + chTemp);
- set_proximity_threshold(data);
- ssp_dbg("[SSP]: %s - new prox threshold : hi - %u, lo - %u\n",
- __func__, data->uProxThreshHi, data->uProxThreshLow);
- return size;
- }
- static ssize_t barcode_emul_enable_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct ssp_data *data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n", data->bBarcodeEnabled);
- }
- static ssize_t barcode_emul_enable_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- int iRet;
- int64_t dEnable;
- struct ssp_data *data = dev_get_drvdata(dev);
- iRet = kstrtoll(buf, 10, &dEnable);
- if (iRet < 0)
- return iRet;
- if (dEnable)
- set_proximity_barcode_enable(data, true);
- else
- set_proximity_barcode_enable(data, false);
- return size;
- }
- static DEVICE_ATTR(vendor, S_IRUGO, prox_vendor_show, NULL);
- static DEVICE_ATTR(name, S_IRUGO, prox_name_show, NULL);
- static DEVICE_ATTR(state, S_IRUGO, proximity_state_show, NULL);
- static DEVICE_ATTR(barcode_emul_en, S_IRUGO | S_IWUSR | S_IWGRP,
- barcode_emul_enable_show, barcode_emul_enable_store);
- static DEVICE_ATTR(prox_avg, S_IRUGO | S_IWUSR | S_IWGRP,
- proximity_avg_show, proximity_avg_store);
- static DEVICE_ATTR(prox_cal, S_IRUGO | S_IWUSR | S_IWGRP,
- proximity_cancel_show, proximity_cancel_store);
- static DEVICE_ATTR(prox_thresh, S_IRUGO | S_IWUSR | S_IWGRP,
- proximity_thresh_show, proximity_thresh_store);
- static struct device_attribute *prox_attrs[] = {
- &dev_attr_vendor,
- &dev_attr_name,
- &dev_attr_state,
- &dev_attr_prox_avg,
- &dev_attr_prox_cal,
- &dev_attr_prox_thresh,
- &dev_attr_barcode_emul_en,
- NULL,
- };
- void initialize_prox_factorytest(struct ssp_data *data)
- {
- sensors_register(data->prox_device, data,
- prox_attrs, "proximity_sensor");
- }
- void remove_prox_factorytest(struct ssp_data *data)
- {
- sensors_unregister(data->prox_device, prox_attrs);
- }
|