1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright (C) 2018 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.
*/
#include "fingerprint.h"
#include "qbt2000_common.h"
#if defined(CONFIG_TZDEV_BOOST) && defined(ENABLE_SENSORS_FPRINT_SECURE)
#include <../drivers/misc/tzdev/tz_boost.h>
#endif
int qbt2000_sec_spi_prepare(int speed)
{
struct clk *fp_spi_pclk, *fp_spi_sclk;
int ret;
fp_spi_pclk = clk_get(NULL, "fp-spi-pclk");
if (IS_ERR(fp_spi_pclk)) {
pr_err("%s: Can't get fp_spi_pclk\n", __func__);
return -1;
}
fp_spi_sclk = clk_get(NULL, "fp-spi-sclk");
if (IS_ERR(fp_spi_sclk)) {
pr_err("%s: Can't get fp_spi_sclk\n", __func__);
return -1;
}
clk_prepare_enable(fp_spi_pclk);
clk_prepare_enable(fp_spi_sclk);
if (clk_get_rate(fp_spi_sclk) != (speed * 4)) {
ret = clk_set_rate(fp_spi_sclk, speed * 4);
if (ret < 0)
pr_err("%s, SPI clk set failed: %d\n", __func__, ret);
else
pr_debug("%s, Set SPI clock rate: %u(%lu)\n",
__func__, speed, clk_get_rate(fp_spi_sclk) / 4);
} else
pr_debug("%s, Set SPI clock rate: %u(%lu)\n",
__func__, speed, clk_get_rate(fp_spi_sclk) / 4);
clk_put(fp_spi_pclk);
clk_put(fp_spi_sclk);
return 0;
}
int qbt2000_sec_spi_unprepare(void)
{
struct clk *fp_spi_pclk, *fp_spi_sclk;
fp_spi_pclk = clk_get(NULL, "fp-spi-pclk");
if (IS_ERR(fp_spi_pclk)) {
pr_err("%s: Can't get fp_spi_pclk\n", __func__);
return -1;
}
fp_spi_sclk = clk_get(NULL, "fp-spi-sclk");
if (IS_ERR(fp_spi_sclk)) {
pr_err("%s: Can't get fp_spi_sclk\n", __func__);
return -1;
}
clk_disable_unprepare(fp_spi_pclk);
clk_disable_unprepare(fp_spi_sclk);
clk_put(fp_spi_pclk);
clk_put(fp_spi_sclk);
return 0;
}
int qbt2000_set_clk(struct qbt2000_drvdata *drvdata, bool onoff)
{
int rc = 0;
if (drvdata->enabled_clk == onoff) {
pr_err("%s: already %s\n", __func__, onoff ? "enabled" : "disabled");
return rc;
}
if (onoff) {
rc = qbt2000_sec_spi_prepare(drvdata->spi_speed);
if (rc < 0) {
pr_err("%s: couldn't enable spi clk: %d\n", __func__, rc);
return rc;
}
wake_lock(&drvdata->fp_spi_lock);
drvdata->enabled_clk = true;
} else {
rc = qbt2000_sec_spi_unprepare();
if (rc < 0) {
pr_err("%s: couldn't disable spi clk: %d\n", __func__, rc);
return rc;
}
wake_unlock(&drvdata->fp_spi_lock);
drvdata->enabled_clk = false;
}
return rc;
}
int qbt2000_register_platform_variable(struct qbt2000_drvdata *drvdata)
{
return 0;
}
int qbt2000_unregister_platform_variable(struct qbt2000_drvdata *drvdata)
{
return 0;
}
int qbt2000_set_cpu_speedup(struct qbt2000_drvdata *drvdata, int onoff)
{
int rc = 0;
#if defined(CONFIG_TZDEV_BOOST) && defined(ENABLE_SENSORS_FPRINT_SECURE)
if (onoff) {
pr_info("%s: SPEEDUP ON:%d\n", __func__, onoff);
tz_boost_enable();
} else {
pr_info("%s: SPEEDUP OFF:%d\n", __func__, onoff);
tz_boost_disable();
}
#endif
return rc;
}
|