Fixed MTP to work with TWRP

This commit is contained in:
awab228 2018-06-19 23:16:04 +02:00
commit f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions

View file

@ -0,0 +1,59 @@
#
# Sensor drivers configuration
#
menuconfig SENSORS_FINGERPRINT
bool "Finger Print Sensor devices"
help
Say Y here, and a list of sensors drivers will be displayed.
Everything that didn't fit into the other categories is here. This option
doesn't affect the kernel.
If unsure, say Y.
if SENSORS_FINGERPRINT
config SENSORS_FINGERPRINT_SYSFS
tristate "fingerprint sensor sysfs support"
default n
help
If you say yes here you get support for
fingerprint sensor FINGERPRINT_SYSFS
config SENSORS_VFS7XXX
tristate "VFS7XXX fingerprint sensor support"
default n
help
If you say yes here you get support for Validity's
fingerprint sensor VFS7XXX.
config SENSORS_FPRINT_SECURE
tristate "VFS61XX fingerprint sensor support"
default n
help
If you say yes here you get support for Validity's
fingerprint sensor enable secure zone.
config SENSORS_FINGERPRINT_32BITS_PLATFORM_ONLY
tristate "Fingerprint sensor supports only 32bits platform"
default n
help
If you say yes here the non TZ device driver will only supports
32bits platform.
config SENSORS_ET320
tristate "ET320 fingerprint sensor supprot"
default n
help
If you say yes here you get support for Egistec's
fingerprint sensor ET320.
config SENSORS_ET510
tristate "ET510 fingerprint sensor supprot"
default n
help
If you say yes here you get support for Egistec's
fingerprint sensor ET510.
config SENSORS_FINGERPRINT_DUALIZATION
tristate "Fingerprint sensor supports dualization et320 and viper2"
default n
help
If you say yes here vendor pin check will be enabled.
config SENSORS_FP_LOCKSCREEN_MODE
tristate "fingerprint sensor support fast wake up"
default n
help
If you say yes here you can use lockscreen mode for optimizing
endif

View file

@ -0,0 +1,12 @@
#
# Makefile for the sensors drivers.
#
# Each configuration option enables a list of files.
ccflags-y := $(KBUILD_FP_SENSOR_CFLAGS)
obj-$(CONFIG_SENSORS_FINGERPRINT_SYSFS) += fingerprint_sysfs.o
obj-$(CONFIG_SENSORS_VFS7XXX) += vfs7xxx.o
obj-$(CONFIG_SENSORS_ET320) += et320-spi.o et320-spi_data_transfer.o
obj-$(CONFIG_SENSORS_ET510) += et510-spi.o et510-spi_data_transfer.o

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,965 @@
/*
* Copyright (C) 2016 Samsung Electronics. 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
* version 2 as published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <linux/kernel.h>
#include <linux/uaccess.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include "et510.h"
int etspi_io_burst_write_register(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
struct spi_transfer xfer =
{
.tx_buf = etspi->buf,
.len = ioc->len + 1,
};
if(ioc->len <= 0 || ioc->len + 2 > etspi->bufsiz) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
memset(etspi->buf, 0, ioc->len + 1);
*etspi->buf = OP_REG_W_C;
if(copy_from_user(etspi->buf + 1,
(const u8 __user *) (uintptr_t) ioc->tx_buf, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
goto end;
}
pr_debug("%s tx_buf = %p op = %x reg = %x, len = %d\n", __func__,
ioc->tx_buf, *etspi->buf, *(etspi->buf + 1), xfer.len);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
end:
return status;
#endif
}
int etspi_io_burst_write_register_backward(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
struct spi_transfer xfer =
{
.tx_buf = etspi->buf,
.len = ioc->len + 1,
};
if (ioc->len <= 0 || ioc->len + 2 > etspi->bufsiz) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
memset(etspi->buf, 0, ioc->len + 1);
*etspi->buf = OP_REG_W_C_BW;
if (copy_from_user(etspi->buf + 1,
(const u8 __user *) (uintptr_t)ioc->tx_buf, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
goto end;
}
pr_debug("%s tx_buf = %p op = %x reg = %x, len = %d\n", __func__,
ioc->tx_buf, *etspi->buf, *(etspi->buf + 1), xfer.len);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
end:
return status;
#endif
}
int etspi_io_burst_read_register(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
struct spi_transfer xfer =
{
.tx_buf = etspi->buf,
.rx_buf = etspi->buf,
.len = ioc->len + 2,
};
if (ioc->len <= 0 || ioc->len + 2 > etspi->bufsiz) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
memset(etspi->buf, 0, xfer.len);
*etspi->buf = OP_REG_R_C;
if(copy_from_user(etspi->buf + 1,
(const u8 __user *) (uintptr_t) ioc->tx_buf, 1)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
goto end;
}
pr_debug("%s tx_buf = %p op = %x reg = %x, len = %d\n", __func__,
ioc->tx_buf, *etspi->buf, *(etspi->buf + 1), xfer.len);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
if (copy_to_user((u8 __user *) (uintptr_t)ioc->rx_buf, etspi->buf + 2,
ioc->len)) {
status = -EFAULT;
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
goto end;
}
end:
return status;
#endif
}
int etspi_io_burst_read_register_backward(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
struct spi_transfer xfer =
{
.tx_buf = etspi->buf,
.rx_buf = etspi->buf,
.len = ioc->len + 2,
};
if (ioc->len <= 0 || ioc->len + 2 > etspi->bufsiz) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
memset(etspi->buf, 0, xfer.len);
*etspi->buf = OP_REG_R_C_BW;
if (copy_from_user(etspi->buf + 1,
(const u8 __user *) (uintptr_t)ioc->tx_buf, 1)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
goto end;
}
pr_debug("%s tx_buf = %p op = %x reg = %x, len = %d\n", __func__,
ioc->tx_buf, *etspi->buf, *(etspi->buf + 1), xfer.len);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
if (copy_to_user((u8 __user *) (uintptr_t)ioc->rx_buf, etspi->buf + 2,
ioc->len)) {
status = -EFAULT;
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
goto end;
}
end:
return status;
#endif
}
int etspi_io_read_registerex(struct etspi_data *etspi, u8 *addr, u8 *buf, u32 len)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
struct spi_transfer xfer =
{
.tx_buf = etspi->buf,
.rx_buf = etspi->buf,
.len = len + 2,
};
if (len <= 0 || len + 2 > etspi->bufsiz) {
status = -ENOMEM;
pr_err(KERN_ERR "%s error status = %d", __func__, status);
goto end;
}
memset(etspi->buf, 0, xfer.len);
*etspi->buf = OP_REG_R;
if (copy_from_user(etspi->buf + 1, (const u8 __user *) (uintptr_t) addr
, 1)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
goto end;
}
pr_debug("%s addr = %p op = %x reg = %x len = %d tx = %p, rx = %p",
__func__, addr, etspi->buf[0], etspi->buf[1], len, xfer.tx_buf, xfer.rx_buf);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n"
, __func__, status);
goto end;
}
if (copy_to_user((u8 __user *) (uintptr_t) buf, etspi->buf + 2, len)) {
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
status = -EFAULT;
goto end;
}
end:
return status;
#endif
}
/* Read io register */
int etspi_io_read_register(struct etspi_data *etspi, u8 *addr, u8 *buf)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
struct spi_message m;
int read_len = 1;
u8 tx[] = { OP_REG_R, 0x00, 0x00 };
u8 val, addrval;
u8 rx[] = { 0xFF, 0x00, 0x00 };
struct spi_transfer xfer = {
.tx_buf = tx,
.rx_buf = rx,
.len = 3,
};
if (copy_from_user(&addrval, (const u8 __user *) (uintptr_t) addr
, read_len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
return status;
}
tx[1] = addrval;
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n"
, __func__, status);
return status;
}
val = rx[2];
pr_debug("%s len = %d addr = %p val = %x\n", __func__, read_len, addr, val);
if (copy_to_user((u8 __user *) (uintptr_t) buf, &val, read_len)) {
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
status = -EFAULT;
return status;
}
return status;
#endif
}
/* Write data to register */
int etspi_io_write_register(struct etspi_data *etspi, u8 *buf)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status = 0;
int write_len = 2;
struct spi_message m;
u8 tx[] = { OP_REG_W, 0x00, 0x00 };
u8 val[3];
struct spi_transfer xfer = {
.tx_buf = tx,
.len = 3,
};
if (copy_from_user(val, (const u8 __user *) (uintptr_t) buf
, write_len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
return status;
}
pr_debug("%s write_len = %d addr = %x data = %x\n", __func__, write_len, val[0], val[1]);
tx[1] = val[0];
tx[2] = val[1];
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n",
__func__, status);
return status;
}
return status;
#endif
}
int etspi_write_register(struct etspi_data *etspi, u8 addr, u8 buf)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 tx[] = {OP_REG_W, addr, buf};
struct spi_transfer xfer = {
.tx_buf = tx,
.rx_buf = NULL,
.len = 3,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s address = %x result = %x %x\n"
__func__, addr, result[1], result[2]);
} else {
pr_err(KERN_ERR "%s read data error status = %d\n"
, __func__, status);
}
return status;
#endif
}
int etspi_read_register(struct etspi_data *etspi, u8 addr, u8 *buf)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 read_value[] = {OP_REG_R, addr, 0x00};
u8 result[] = {0xFF, 0xFF, 0xFF};
struct spi_transfer xfer = {
.tx_buf = read_value,
.rx_buf = result,
.len = 3,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
*buf = result[2];
DEBUG_PRINT("%s address = %x result = %x %x\n"
__func__, addr, result[1], result[2]);
} else {
pr_err(KERN_ERR "%s read data error status = %d\n"
, __func__, status);
}
return status;
#endif
}
int etspi_io_nvm_read(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 addr/* nvm logical address */, buf[] = {OP_NVM_RE, 0x00};
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = NULL,
.len = 2,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s nvm enabled\n", __func__);
} else {
pr_err(KERN_ERR "%s nvm enable error status = %d\n"
, __func__, status);
}
usleep_range(10, 50);
if (copy_from_user(&addr, (const u8 __user *) (uintptr_t) ioc->tx_buf
, 1)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
return status;
}
etspi->buf[0] = OP_NVM_ON_R;
pr_debug("%s logical addr(%x) len(%d)\n", __func__, addr, ioc->len);
if ((addr + ioc->len) > MAX_NVM_LEN)
return -EINVAL;
/* transfer to nvm physical address*/
etspi->buf[1] = ((addr % 2) ? (addr - 1) : addr) / 2 ;
/* thansfer to nvm physical length */
xfer.len = ((ioc->len % 2) ? ioc->len + 1 : (addr % 2 ? ioc->len + 2 : ioc->len)) + 3;
if ( xfer.len >= LARGE_SPI_TRANSFER_BUFFER) {
if ((xfer.len) % DIVISION_OF_IMAGE != 0)
xfer.len = xfer.len + (DIVISION_OF_IMAGE - (xfer.len % DIVISION_OF_IMAGE));
}
xfer.tx_buf = xfer.rx_buf = etspi->buf;
pr_debug("%s nvm read addr(%d) len(%d) xfer.rx_buf(%p), etspi->buf(%p)\n",
__func__, etspi->buf[1], xfer.len, xfer.rx_buf, etspi->buf);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
return status;
}
if (copy_to_user((u8 __user *) (uintptr_t) ioc->rx_buf, xfer.rx_buf + 3, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
status = -EFAULT;
return status;
}
return status;
#endif
}
int etspi_io_nvm_write(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status, i, j, len/* physical nvm lengh */;
struct spi_message m;
u8 *bufw = NULL, buf[MAX_NVM_LEN + 1] = {OP_NVM_WE, 0x00}, addr/* nvm physical addr */;
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = NULL,
.len = 2,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s nvm enabled\n", __func__);
} else {
pr_err(KERN_ERR "%s nvm enable error status = %d\n"
, __func__, status);
}
usleep_range(10, 50);
pr_debug("%s buf(%p) tx_buf(%p) len(%d)\n", __func__, buf, ioc->tx_buf, ioc->len);
if (copy_from_user(buf, (const u8 __user *) (uintptr_t) ioc->tx_buf
, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
return status;
}
if ((buf[0] + (ioc->len - 1)) > MAX_NVM_LEN)
return -EINVAL;
if((buf[0] % 2) || ((ioc->len - 1) % 2)){
/* TODO: add non alignment handling */
pr_err("%s can't handle address alignment issue. %d %d \n",
__func__, buf[0], ioc->len);
return -EINVAL;
}
bufw = kmalloc(NVM_WRITE_LENGTH , GFP_KERNEL);
/*TODO: need to dynamic assign nvm lengh*/
if (bufw == NULL) {
status = -ENOMEM;
pr_err("%s bufw kmalloc error\n", __func__);
return status;
} else {
xfer.tx_buf = xfer.rx_buf = bufw;
xfer.len = NVM_WRITE_LENGTH;
}
len = (ioc->len - 1) / 2;
pr_debug("%s nvm write addr(%d) len(%d) xfer.tx_buf(%p), etspi->buf(%p)\n",
__func__, buf[0], len, xfer.tx_buf, etspi->buf);
for (i = 0 , addr = buf[0] / 2/* thansfer to nvm physical length */;
i < len; i++) {
bufw[0] = OP_NVM_ON_W;
bufw[1] = addr++;
bufw[2] = buf[i * 2 + 1];
bufw[3] = buf[i * 2 + 2];
memset(bufw + 4, 1, NVM_WRITE_LENGTH - 4);
pr_debug("%s write transaction (%d): %x %x %x %x\n",
__func__, i, bufw[0], bufw[1], bufw[2], bufw[3]);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
for(j = 0; j < NVM_WRITE_LENGTH - 4; j++) {
if(bufw[4 + j] == 0) {
pr_debug("%s nvm write ready(%d)\n",__func__, j );
break;
}
if(j == NVM_WRITE_LENGTH - 5) {
pr_err(KERN_ERR "%s nvm write fail(timeout)\n", __func__);
status = -EIO;
goto end;
}
}
}
end:
if(bufw) kfree(bufw);
return status;
#endif
}
int etspi_nvm_read(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 addr/* nvm logical address */, buf[] = {OP_NVM_RE, 0x00};
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = NULL,
.len = 2,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s nvm enabled\n", __func__);
} else {
pr_err(KERN_ERR "%s nvm enable error status = %d\n"
, __func__, status);
}
usleep_range(10, 50);
addr = ioc->tx_buf[0];
etspi->buf[0] = OP_NVM_ON_R;
pr_debug("%s logical addr(%x) len(%d)\n", __func__, addr, ioc->len);
if ((addr + ioc->len) > MAX_NVM_LEN)
return -EINVAL;
/* transfer to nvm physical address*/
etspi->buf[1] = ((addr % 2) ? (addr - 1) : addr) / 2 ;
/* thansfer to nvm physical length */
xfer.len = ((ioc->len % 2) ? ioc->len + 1 : (addr % 2 ? ioc->len + 2 : ioc->len)) + 3;
if ( xfer.len >= LARGE_SPI_TRANSFER_BUFFER) {
if ((xfer.len) % DIVISION_OF_IMAGE != 0)
xfer.len = xfer.len + (DIVISION_OF_IMAGE - (xfer.len % DIVISION_OF_IMAGE));
}
xfer.tx_buf = xfer.rx_buf = etspi->buf;
pr_debug("%s nvm read addr(%d) len(%d) xfer.rx_buf(%p), etspi->buf(%p)\n",
__func__, etspi->buf[1], xfer.len, xfer.rx_buf, etspi->buf);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
return status;
}
if (memcpy((u8 __user *) (uintptr_t) ioc->rx_buf, xfer.rx_buf + 3, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_to_user fail status\n", __func__);
status = -EFAULT;
return status;
}
return status;
#endif
}
int etspi_io_nvm_writeex(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status, i, j, len/* physical nvm lengh */, wlen;
struct spi_message m;
u8 *bufw = NULL, bufr[MAX_NVM_LEN + 3], buf[MAX_NVM_LEN + 3] = {OP_NVM_WE, 0x00};
u8 addr/* nvm physical addr */, *tmp = NULL;
struct egis_ioc_transfer r;
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = NULL,
.len = 2,
};
pr_debug("%s buf(%p) tx_buf(%p) len(%d)\n", __func__, buf, ioc->tx_buf, ioc->len);
if (copy_from_user(buf, (const u8 __user *) (uintptr_t) ioc->tx_buf
, ioc->len)) {
pr_err(KERN_ERR "%s buffer copy_from_user fail\n", __func__);
status = -EFAULT;
return status;
}
if ((buf[0] + (ioc->len - 3)) > MAX_NVM_LEN)
return -EINVAL;
if((buf[0] % 2) || ((ioc->len - 3) % 2)){
/* address non-alignment handling */
pr_debug("%s handle address alignment issue. %d %d \n",
__func__, buf[0], ioc->len);
r.tx_buf = r.rx_buf = bufr;
r.len = ioc->len;
if(buf[0] % 2){
r.tx_buf[0] = buf[0] - 1;
r.len = ioc->len % 2 ? r.len + 1 : r.len + 2;
} else {
if(ioc->len % 2) r.len++;
}
pr_debug("%s fixed address alignment issue. %d %d \n",
__func__, r.tx_buf[0], r.len);
etspi_nvm_read(etspi, &r);
tmp = bufr;
if(buf[0] % 2) tmp++;
memcpy(tmp, buf, ioc->len);
}
buf[0] = OP_NVM_WE;
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s nvm enabled\n", __func__);
} else {
pr_err(KERN_ERR "%s nvm enable error status = %d\n"
, __func__, status);
}
usleep_range(10, 50);
wlen = *(u16 *)(buf + 1);
pr_debug("%s wlen(%d)\n",__func__,wlen);
if(wlen > 8192) wlen = 8196;
bufw = kmalloc(wlen , GFP_KERNEL);
if (bufw == NULL) {
status = -ENOMEM;
pr_err("%s bufw kmalloc error\n", __func__);
return status;
} else {
xfer.tx_buf = xfer.rx_buf = bufw;
xfer.len = wlen;
}
if((buf[0] % 2) || ((ioc->len - 3) % 2)){
memcpy(buf, bufr, r.len);
ioc->len = r.len;
}
len = (ioc->len - 3) / 2;
pr_debug("%s nvm write addr(%d) len(%d) xfer.tx_buf(%p), etspi->buf(%p), wlen(%d)\n",
__func__, buf[0], len, xfer.tx_buf, etspi->buf, wlen);
for (i = 0 , addr = buf[0] / 2/* thansfer to nvm physical length */;
i < len; i++) {
bufw[0] = OP_NVM_ON_W;
bufw[1] = addr++;
bufw[2] = buf[i * 2 + 3];
bufw[3] = buf[i * 2 + 4];
memset(bufw + 4, 1, wlen - 4);
pr_debug("%s write transaction (%d): %x %x %x %x\n",
__func__, i, bufw[0], bufw[1], bufw[2], bufw[3]);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s error status = %d\n", __func__, status);
goto end;
}
for(j = 0; j < wlen - 4; j++) {
if(bufw[4 + j] == 0) {
pr_debug("%s nvm write ready(%d)\n",__func__, j );
break;
}
if(j == wlen - 5) {
pr_err(KERN_ERR "%s nvm write fail(timeout)\n", __func__);
status = -EIO;
goto end;
}
}
}
end:
if(bufw) kfree(bufw);
return status;
#endif
}
int etspi_io_nvm_off(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 buf[] = {OP_NVM_OFF, 0x00};
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = NULL,
.len = 2,
};
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status == 0) {
DEBUG_PRINT("%s nvm disabled\n", __func__);
} else {
pr_err(KERN_ERR "%s nvm disable error status = %d\n"
, __func__, status);
}
return status;
#endif
}
int etspi_io_vdm_read(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 *buf = NULL;
struct spi_transfer xfer = {
.tx_buf = NULL,
.rx_buf = NULL,
.len = ioc->len + 1,
};
if ( xfer.len >= LARGE_SPI_TRANSFER_BUFFER) {
if ((xfer.len) % DIVISION_OF_IMAGE != 0)
xfer.len = xfer.len + (DIVISION_OF_IMAGE - (xfer.len % DIVISION_OF_IMAGE));
}
buf = kzalloc(xfer.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
xfer.tx_buf = xfer.rx_buf = buf;
buf[0] = OP_VDM_R;
pr_debug("%s len = %d, xfer.len = %d, buf = %p, rx_buf = %p\n", __func__,
ioc->len, xfer.len, buf, ioc->rx_buf);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n", __func__, status);
goto end;
}
if (copy_to_user((u8 __user *) (uintptr_t) ioc->rx_buf, buf + 1, ioc->len)) {
pr_err(KERN_ERR "buffer copy_to_user fail status\n");
status = -EFAULT;
}
end:
if(buf) kfree(buf);
return status;
#endif
}
int etspi_io_vdm_write(struct etspi_data *etspi, struct egis_ioc_transfer *ioc)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 *buf = NULL;
struct spi_transfer xfer = {
.tx_buf = NULL,
.rx_buf = NULL,
.len = ioc->len + 1,
};
if ( xfer.len >= LARGE_SPI_TRANSFER_BUFFER) {
if ((xfer.len) % DIVISION_OF_IMAGE != 0)
xfer.len = xfer.len + (DIVISION_OF_IMAGE - (xfer.len % DIVISION_OF_IMAGE));
}
buf = kzalloc(xfer.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
if (copy_from_user((u8 __user *) (uintptr_t) buf + 1, ioc->tx_buf, ioc->len)) {
pr_err(KERN_ERR "buffer copy_from_user fail status\n");
status = -EFAULT;
goto end;
}
xfer.tx_buf = xfer.rx_buf = buf;
buf[0] = OP_VDM_W;
pr_debug("%s len = %d, xfer.len = %d, buf = %p, tx_buf = %p\n", __func__,
ioc->len, xfer.len, buf, ioc->tx_buf);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n", __func__, status);
}
end:
if(buf) kfree(buf);
return status;
#endif
}
int etspi_io_get_frame(struct etspi_data *etspi, u8 *fr, u32 size)
{
#ifdef ENABLE_SENSORS_FPRINT_SECURE
return 0;
#else
int status;
struct spi_message m;
u8 *buf = NULL;
struct spi_transfer xfer = {
.tx_buf = NULL,
.rx_buf = NULL,
.len = size + 1,
};
if ( xfer.len >= LARGE_SPI_TRANSFER_BUFFER) {
if ((xfer.len) % DIVISION_OF_IMAGE != 0)
xfer.len = xfer.len + (DIVISION_OF_IMAGE - (xfer.len % DIVISION_OF_IMAGE));
}
buf = kzalloc(xfer.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
xfer.tx_buf = xfer.rx_buf = buf;
buf[0] = OP_IMG_R;
pr_debug("%s size = %d, xfer.len = %d, buf = %p, fr = %p\n", __func__,
size, xfer.len, buf, fr);
spi_message_init(&m);
spi_message_add_tail(&xfer, &m);
status = spi_sync(etspi->spi, &m);
if (status < 0) {
pr_err(KERN_ERR "%s read data error status = %d\n", __func__, status);
goto end;
}
if (copy_to_user((u8 __user *) (uintptr_t) fr, buf + 1, size)) {
pr_err(KERN_ERR "buffer copy_to_user fail status\n");
status = -EFAULT;
}
end:
if(buf) kfree(buf);
return status;
#endif
}

263
drivers/fingerprint/et510.h Normal file
View file

@ -0,0 +1,263 @@
/*
* Copyright (C) 2016 Samsung Electronics. 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
* version 2 as published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _ET510_LINUX_DIRVER_H_
#define _ET510_LINUX_DIRVER_H_
#ifdef ENABLE_SENSORS_FPRINT_SECURE
#define FEATURE_SPI_WAKELOCK
#endif /* CONFIG_SEC_FACTORY */
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/platform_data/spi-s3c64xx.h>
#ifdef ENABLE_SENSORS_FPRINT_SECURE
#include <linux/wakelock.h>
#include <linux/clk.h>
#include <linux/pm_runtime.h>
#include <linux/spi/spidev.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_dma.h>
#include <linux/amba/bus.h>
#include <linux/amba/pl330.h>
#if defined(CONFIG_SECURE_OS_BOOSTER_API)
#if defined(CONFIG_SOC_EXYNOS8890) || defined(CONFIG_SOC_EXYNOS7870) \
|| defined(CONFIG_SOC_EXYNOS7880) || defined(CONFIG_SOC_EXYNOS7570)
#include <soc/samsung/secos_booster.h>
#else
#include <mach/secos_booster.h>
#endif
#endif
struct sec_spi_info {
int port;
unsigned long speed;
};
#endif
/*#define ET510_SPI_DEBUG*/
#ifdef ET510_SPI_DEBUG
#define DEBUG_PRINT(fmt, args...) pr_err(fmt, ## args)
#else
#define DEBUG_PRINT(fmt, args...)
#endif
#define VENDOR "EGISTEC"
#define CHIP_ID "ET510"
/* assigned */
#define ET510_MAJOR 153
/* ... up to 256 */
#define N_SPI_MINORS 32
#define OP_REG_R 0x20
#define OP_REG_R_C 0x22
#define OP_REG_R_C_BW 0x23
#define OP_REG_W 0x24
#define OP_REG_W_C 0x26
#define OP_REG_W_C_BW 0x27
#define OP_NVM_ON_R 0x40
#define OP_NVM_ON_W 0x42
#define OP_NVM_RE 0x44
#define OP_NVM_WE 0x46
#define OP_NVM_OFF 0x48
#define OP_IMG_R 0x50
#define OP_VDM_R 0x60
#define OP_VDM_W 0x62
#define BITS_PER_WORD 8
#define SLOW_BAUD_RATE 12500000
#define DRDY_IRQ_ENABLE 1
#define DRDY_IRQ_DISABLE 0
#define ET510_INT_DETECTION_PERIOD 10
#define ET510_DETECTION_THRESHOLD 10
#define FP_REGISTER_READ 0x01
#define FP_REGISTER_WRITE 0x02
#define FP_GET_ONE_IMG 0x03
#define FP_SENSOR_RESET 0x04
#define FP_POWER_CONTROL 0x05
#define FP_SET_SPI_CLOCK 0x06
#define FP_RESET_SET 0x07
#define FP_REGISTER_BREAD 0x20
#define FP_REGISTER_BWRITE 0x21
#define FP_REGISTER_MREAD 0x22
#define FP_REGISTER_MWRITE 0x23
#define FP_REGISTER_BREAD_BACKWARD 0x24
#define FP_REGISTER_BWRITE_BACKWARD 0x25
#define FP_VDM_READ 0x30
#define FP_VDM_WRITE 0x31
#define FP_NVM_READ 0X40
#define FP_NVM_WRITE 0x41
#define FP_NVM_OFF 0x42
#define FP_NVM_WRITEEX 0x43
#ifdef ENABLE_SENSORS_FPRINT_SECURE
#define FP_DIABLE_SPI_CLOCK 0x10
#define FP_CPU_SPEEDUP 0x11
#define FP_SET_SENSOR_TYPE 0x14
/* Do not use ioctl number 0x15 */
#define FP_SET_LOCKSCREEN 0x16
#define FP_SET_WAKE_UP_SIGNAL 0x17
#endif
#define FP_POWER_CONTROL_ET510 0x18
#define FP_IOCTL_RESERVED_01 0x19
/* trigger signal initial routine */
#define INT_TRIGGER_INIT 0xa4
/* trigger signal close routine */
#define INT_TRIGGER_CLOSE 0xa5
/* read trigger status */
#define INT_TRIGGER_READ 0xa6
/* polling trigger status */
#define INT_TRIGGER_POLLING 0xa7
/* polling abort */
#define INT_TRIGGER_ABORT 0xa8
/* Sensor Registers */
#define FDATA_ET510_ADDR 0x00
#define FSTATUS_ET510_ADDR 0x01
/* Detect Define */
#define FRAME_READY_MASK 0x01
#define SHIFT_BYTE_OF_IMAGE 0
#define DIVISION_OF_IMAGE 4
#define LARGE_SPI_TRANSFER_BUFFER 64
#define MAX_NVM_LEN 32 * 2 /* NVM length in bytes (32 * 16 bits internally)*/
#define NVM_WRITE_LENGTH 4096
#define DETECT_ADM 1
struct egis_ioc_transfer {
u8 *tx_buf;
u8 *rx_buf;
u32 len;
u32 speed_hz;
u16 delay_usecs;
u8 bits_per_word;
u8 cs_change;
u8 opcode;
u8 pad[3];
};
/*
* If platform is 32bit and kernel is 64bit
* We will alloc egis_ioc_transfer for 64bit and 32bit
* We use ioc_32(32bit) to get data from user mode.
* Then copy the ioc_32 to ioc(64bit).
*/
#ifdef CONFIG_SENSORS_FINGERPRINT_32BITS_PLATFORM_ONLY
struct egis_ioc_transfer_32 {
u32 tx_buf;
u32 rx_buf;
u32 len;
u32 speed_hz;
u16 delay_usecs;
u8 bits_per_word;
u8 cs_change;
u8 opcode;
u8 pad[3];
};
#endif
#define EGIS_IOC_MAGIC 'k'
#define EGIS_MSGSIZE(N) \
((((N)*(sizeof(struct egis_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
? ((N)*(sizeof(struct egis_ioc_transfer))) : 0)
#define EGIS_IOC_MESSAGE(N) _IOW(EGIS_IOC_MAGIC, 0, char[EGIS_MSGSIZE(N)])
struct etspi_data {
dev_t devt;
spinlock_t spi_lock;
struct spi_device *spi;
struct list_head device_entry;
/* buffer is NULL unless this device is open (users > 0) */
struct mutex buf_lock;
unsigned users;
u8 *buf;/* tx buffer for sensor register read/write */
unsigned bufsiz; /* MAX size of tx and rx buffer */
unsigned int drdyPin; /* DRDY GPIO pin number */
unsigned int sleepPin; /* Sleep GPIO pin number */
unsigned int ldo_pin; /* Ldo GPIO pin number */
#ifndef ENABLE_SENSORS_FPRINT_SECURE
#ifdef CONFIG_SOC_EXYNOS8890
/* set cs pin in fp driver, use only Exynos8890 */
/* for use auto cs mode with dualization fp sensor */
unsigned int cs_gpio;
#endif
#endif
unsigned int spi_cs; /* spi cs pin <temporary gpio setting> */
unsigned int drdy_irq_flag; /* irq flag */
bool ldo_onoff;
/* For polling interrupt */
int int_count;
struct timer_list timer;
struct work_struct work_debug;
struct workqueue_struct *wq_dbg;
struct timer_list dbg_timer;
int sensortype;
#ifdef CONFIG_SENSORS_FINGERPRINT_SYSFS
struct device *fp_device;
#endif
#ifdef ENABLE_SENSORS_FPRINT_SECURE
bool enabled_clk;
#ifdef FEATURE_SPI_WAKELOCK
struct wake_lock fp_spi_lock;
#endif
#endif
bool tz_mode;
int detect_period;
int detect_threshold;
bool finger_on;
};
int etspi_io_burst_read_register(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc);
int etspi_io_burst_read_register_backward(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc);
int etspi_io_burst_write_register(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc);
int etspi_io_burst_write_register_backward(struct etspi_data *etspi,
struct egis_ioc_transfer *ioc);
int etspi_io_read_register(struct etspi_data *etspi, u8 *addr, u8 *buf);
int etspi_io_read_registerex(struct etspi_data *etspi, u8 *addr, u8 *buf, u32 len);
int etspi_io_write_register(struct etspi_data *etspi, u8 *buf);
int etspi_read_register(struct etspi_data *etspi, u8 addr, u8 *buf);
int etspi_write_register(struct etspi_data *etspi, u8 addr, u8 buf);
int etspi_io_nvm_read(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_nvm_write(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_nvm_writeex(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_nvm_off(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_vdm_read(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_vdm_write(struct etspi_data *etspi, struct egis_ioc_transfer *ioc);
int etspi_io_get_frame(struct etspi_data *etspi, u8 *frame, u32 size);
#ifdef CONFIG_SENSORS_FINGERPRINT_SYSFS
extern int fingerprint_register(struct device *dev, void *drvdata,
struct device_attribute *attributes[], char *name);
extern void fingerprint_unregister(struct device *dev,
struct device_attribute *attributes[]);
#endif
#endif

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2013 Samsung Electronics. 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
* version 2 as published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef FINGERPRINT_H_
#define FINGERPRINT_H_
#include <linux/clk.h>
/* fingerprint debug timer */
#define FPSENSOR_DEBUG_TIMER_SEC (10 * HZ)
/* For Sensor Type Check */
enum {
SENSOR_UNKNOWN = -1,
SENSOR_FAILED,
SENSOR_VIPER,
SENSOR_RAPTOR,
SENSOR_EGIS,
};
#define SENSOR_STATUS_SIZE 5
static char sensor_status[SENSOR_STATUS_SIZE][8] ={"unknown", "failed",
"viper", "raptor", "egis"};
#ifdef CONFIG_SENSORS_FINGERPRINT_DUALIZATION
extern int FP_CHECK; /* extern variable */
#endif
#ifdef ENABLE_SENSORS_FPRINT_SECURE
#define MC_FC_FP_PM_SUSPEND ((uint32_t)(0x83000021))
#define MC_FC_FP_PM_RESUME ((uint32_t)(0x83000022))
#define MC_FC_FP_CS_SET ((uint32_t)(0x83000027))
#define MC_FC_FP_PM_SUSPEND_CS_HIGH ((uint32_t)(0x83000028))
extern int fpsensor_goto_suspend;
EXPORT_SYMBOL(fpsensor_goto_suspend);
#endif
#endif

View file

@ -0,0 +1,120 @@
/*
* Copyright (C) 2013 Samsung Electronics. 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
* version 2 as published by the Free Software Foundation.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
/*
* fingerprint sysfs class
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/err.h>
struct class *fingerprint_class;
EXPORT_SYMBOL_GPL(fingerprint_class);
/*
* Create sysfs interface
*/
static void set_fingerprint_attr(struct device *dev,
struct device_attribute *attributes[])
{
int i;
for (i = 0; attributes[i] != NULL; i++)
if ((device_create_file(dev, attributes[i])) < 0)
pr_err("%s: fail device_create_file"\
"(dev, attributes[%d])\n", __func__, i);
}
int fingerprint_register(struct device *dev, void *drvdata,
struct device_attribute *attributes[], char *name)
{
int ret = 0;
if (!fingerprint_class) {
fingerprint_class = class_create(THIS_MODULE, "fingerprint");
if (IS_ERR(fingerprint_class))
return PTR_ERR(fingerprint_class);
}
dev = device_create(fingerprint_class, NULL, 0, drvdata, "%s", name);
if (IS_ERR(dev)) {
ret = PTR_ERR(dev);
pr_err("%s: device_create failed!"\
"[%d]\n", __func__, ret);
return ret;
}
set_fingerprint_attr(dev, attributes);
return 0;
}
EXPORT_SYMBOL_GPL(fingerprint_register);
void fingerprint_unregister(struct device *dev,
struct device_attribute *attributes[])
{
int i;
for (i = 0; attributes[i] != NULL; i++)
device_remove_file(dev, attributes[i]);
}
EXPORT_SYMBOL_GPL(fingerprint_unregister);
void destroy_fingerprint_class(void)
{
if (fingerprint_class) {
class_destroy(fingerprint_class);
fingerprint_class = NULL;
}
}
EXPORT_SYMBOL_GPL(destroy_fingerprint_class);
static int __init fingerprint_class_init(void)
{
pr_info("%s\n", __func__);
fingerprint_class = class_create(THIS_MODULE, "fingerprint");
if (IS_ERR(fingerprint_class)) {
pr_err("%s, create fingerprint_class is failed.(err=%d)\n",
__func__, IS_ERR(fingerprint_class));
return PTR_ERR(fingerprint_class);
}
fingerprint_class->dev_uevent = NULL;
return 0;
}
static void __exit fingerprint_class_exit(void)
{
if (fingerprint_class) {
class_destroy(fingerprint_class);
fingerprint_class = NULL;
}
}
subsys_initcall(fingerprint_class_init);
module_exit(fingerprint_class_exit);
MODULE_DESCRIPTION("fingerprint sysfs class");
MODULE_LICENSE("GPL");