summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/board-apalis-tk1-sysedp.c
blob: 298440457afe2aa8a5a456fd4f0063d9348305cb (plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Copyright (c) 2016 Toradex AG. 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 Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/sysedp.h>
#include <linux/platform_device.h>
#include <linux/platform_data/tegra_edp.h>
#include <linux/power_supply.h>
#include <mach/edp.h>
#include "board.h"
#include "board-panel.h"

/* --- EDP consumers data --- */
/* TODO static unsigned int ov5693_states[] = { 0, 300 };*/
static unsigned int mt9m114_states[] = { 0, 150 };
static unsigned int sdhci_states[] = { 0, 966 };
static unsigned int speaker_states[] = { 0, 1080 };
static unsigned int wifi_states[] = { 0, 3070 };

/* 10 inch panel */
static unsigned int pwm_backlight_states[] = {
	0, 425, 851, 1276, 1702, 2127, 2553, 2978, 3404, 3829, 4255
};

/* TODO
static unsigned int as364x_states[] = {
	0, 350, 700, 1050, 1400, 1750, 2100, 2450, 2800, 3150, 3500
};
*/

static struct sysedp_consumer_data apalis_tk1_sysedp_consumer_data[] = {
	/* TODO SYSEDP_CONSUMER_DATA("ov5693", ov5693_states), */
	SYSEDP_CONSUMER_DATA("mt9m114", mt9m114_states),
	SYSEDP_CONSUMER_DATA("speaker", speaker_states),
	SYSEDP_CONSUMER_DATA("wifi", wifi_states),
	SYSEDP_CONSUMER_DATA("pwm-backlight", pwm_backlight_states),
	SYSEDP_CONSUMER_DATA("sdhci-tegra.2", sdhci_states),
	SYSEDP_CONSUMER_DATA("sdhci-tegra.3", sdhci_states),
	/* TODO SYSEDP_CONSUMER_DATA("as364x", as364x_states), */
};

static struct sysedp_platform_data apalis_tk1_sysedp_platform_data = {
	.consumer_data = apalis_tk1_sysedp_consumer_data,
	.consumer_data_size = ARRAY_SIZE(apalis_tk1_sysedp_consumer_data),
	.margin = 0,
};

static struct platform_device apalis_tk1_sysedp_device = {
	.name = "sysedp",
	.id = -1,
	.dev = {.platform_data = &apalis_tk1_sysedp_platform_data}
};

void __init apalis_tk1_new_sysedp_init(void)
{
	int r;

	r = platform_device_register(&apalis_tk1_sysedp_device);
	WARN_ON(r);
}

/* --- Battery monitor data --- */
static struct sysedp_batmon_ibat_lut apalis_tk1_ibat_lut[] = {
/*-- temp in deci-C, current in milli ampere --*/
	{600, 9750},
	{-300, 9750}
};

/* Values for Leyden HY-LDN-N-TD battery */
/*                           45C      23C     10C      5C      0C    -20 */
static int rbat_data[] = {
	100000, 120000, 140000, 170000, 190000, 210000,	/* 100% */
	100000, 120000, 150000, 170000, 190000, 210000,	/*  55% */
	100000, 130000, 150000, 170000, 200000, 210000,	/*  50% */
	110000, 130000, 160000, 170000, 200000, 210000,	/*  10% */
	120000, 140000, 170000, 180000, 210000, 220000,	/*   0% */
};
static int rbat_temp_axis[] = { 45, 23, 10, 5, 0, -20 };
static int rbat_capacity_axis[] = { 100, 55, 50, 10, 0 };

struct sysedp_batmon_rbat_lut apalis_tk1_rbat_lut = {
	.temp_axis = rbat_temp_axis,
	.temp_size = ARRAY_SIZE(rbat_temp_axis),
	.capacity_axis = rbat_capacity_axis,
	.capacity_size = ARRAY_SIZE(rbat_capacity_axis),
	.data = rbat_data,
	.data_size = ARRAY_SIZE(rbat_data),
};

/* Fuel Gauge is BQ20z45 (SBS battery) */
static struct sysedp_batmon_ocv_lut apalis_tk1_ocv_lut[] = {
	/*SOC, OCV in micro volt */
	{100,	8372010},
	{95,	8163880},
	{90,	8069280},
	{85,	7970700},
	{80,	7894100},
	{75,	7820860},
	{70,	7751890},
	{65,	7691770},
	{60,	7641110},
	{55,	7598990},
	{50,	7564200},
	{45,	7534290},
	{40,	7511410},
	{35,	7491870},
	{30,	7468380},
	{25,	7435720},
	{20,	7388720},
	{15,	7338370},
	{10,	7219650},
	{0,	5999850},
};

static struct sysedp_batmon_calc_platform_data apalis_tk1_batmon_pdata = {
	.power_supply = "sbs-battery",
	.r_const = 70000,	/* in micro ohm */
	.vsys_min = 5880000,	/* in micro volt */
	.ibat_lut = apalis_tk1_ibat_lut,
	.rbat_lut = &apalis_tk1_rbat_lut,
	.ocv_lut = apalis_tk1_ocv_lut,
};

static struct platform_device apalis_tk1_batmon_device = {
	.name = "sysedp_batmon_calc",
	.id = -1,
	.dev = {.platform_data = &apalis_tk1_batmon_pdata}
};

void __init apalis_tk1_sysedp_batmon_init(void)
{
	int r;

	if (get_power_supply_type() != POWER_SUPPLY_TYPE_BATTERY) {
		/* modify platform data on-the-fly to enable virtual battery */
		apalis_tk1_batmon_pdata.power_supply = "test_battery";
		apalis_tk1_batmon_pdata.update_interval = 2000;
	}

	r = platform_device_register(&apalis_tk1_batmon_device);
	WARN_ON(r);
}

static struct tegra_sysedp_platform_data
		apalis_tk1_sysedp_dynamic_capping_platdata = {
	.core_gain = 100,
	.init_req_watts = 20000,
};

static struct platform_device apalis_tk1_sysedp_dynamic_capping = {
	.name = "sysedp_dynamic_capping",
	.id = -1,
	.dev = {.platform_data = &apalis_tk1_sysedp_dynamic_capping_platdata}
};

void __init apalis_tk1_sysedp_dynamic_capping_init(void)
{
	int r;
	struct tegra_sysedp_corecap *corecap;
	unsigned int corecap_size;

	corecap = tegra_get_sysedp_corecap(&corecap_size);
	if (!corecap) {
		WARN_ON(1);
		return;
	}
	apalis_tk1_sysedp_dynamic_capping_platdata.corecap = corecap;
	apalis_tk1_sysedp_dynamic_capping_platdata.corecap_size = corecap_size;

	apalis_tk1_sysedp_dynamic_capping_platdata.cpufreq_lim =
			tegra_get_system_edp_entries
		(&apalis_tk1_sysedp_dynamic_capping_platdata.cpufreq_lim_size);
	if (!apalis_tk1_sysedp_dynamic_capping_platdata.cpufreq_lim) {
		WARN_ON(1);
		return;
	}

	r = platform_device_register(&apalis_tk1_sysedp_dynamic_capping);
	WARN_ON(r);
}