summaryrefstree
path: root/kernel/drivers/devfreq/devfreq_exynos.h
blob: 9ec56a54b99323788f239cb1fd6267495beced94 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/*
 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 *              Sangkyu Kim(skwith.kim@samsung.com)
 *
 * 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.
 */

#ifndef __DEVFREQ_EXYNOS_H
#define __DEVFREQ_EXYNOS_H __FILE__

#include <linux/clk.h>

#include <mach/pm_domains.h>

#define VOLT_STEP	(12500)

struct devfreq_data_int;
struct devfreq_data_mif;
struct devfreq_data_isp;
struct devfreq_data_disp;
typedef int(*devfreq_init_of_fn)(void *);
typedef int(*devfreq_deinit_of_fn)(void *);

struct devfreq_opp_table {
	unsigned int idx;
	unsigned long freq;
	unsigned long volt;
};

struct devfreq_clk_state {
	int clk_idx;
	int parent_clk_idx;
};

struct devfreq_clk_states {
	struct devfreq_clk_state *state;
	unsigned int state_count;
};

struct devfreq_clk_value {
	unsigned int reg;
	unsigned int set_value;
	unsigned int clr_value;
};

struct devfreq_clk_info {
	unsigned int idx;
	unsigned long freq;
	int pll;
	struct devfreq_clk_states *states;
};

struct devfreq_clk_list {
	const char *clk_name;
	struct clk *clk;
};

struct exynos_devfreq_platdata {
	unsigned long default_qos;
};

struct devfreq_info {
	unsigned int old;
	unsigned int new;
};

struct devfreq_pm_domain_link {
	const char *pm_domain_name;
	struct exynos_pm_domain *pm_domain;
};

struct devfreq_dynamic_clkgate {
	unsigned long	paddr;
	unsigned long	vaddr;
	unsigned int	bit;
	unsigned long	freq;
};

#if defined(CONFIG_ARM_EXYNOS5433_BUS_DEVFREQ)
struct devfreq_data_mif {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_mif;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;

	struct notifier_block tmu_notifier;

	bool use_dvfs;

	void __iomem *base_mif;
	void __iomem *base_sysreg_mif;
	void __iomem *base_drex0;
	void __iomem *base_drex1;
	void __iomem *base_lpddr_phy0;
	void __iomem *base_lpddr_phy1;

	int default_qos;
	int initial_freq;
	int cal_qos_max;
	int max_state;
	bool dll_status;

	unsigned int *mif_asv_abb_table;

	int (*mif_set_freq)(struct devfreq_data_mif *data, int index, int old_index);
	int (*mif_set_and_change_timing_set)(struct devfreq_data_mif *data, int index);
	int (*mif_set_timeout)(struct devfreq_data_mif *data, int index);
	int (*mif_set_dll)(struct devfreq_data_mif *data, unsigned long volt, int index);
	void  (*mif_dynamic_setting)(struct devfreq_data_mif *data, bool flag);
	int (*mif_set_volt)(struct devfreq_data_mif *data, unsigned long volt,  unsigned long volt_range);
	int (*mif_pre_process)(struct device *dev, struct devfreq_data_mif *data, int *index, int *old_index, unsigned long *freq, unsigned long *old_freq);
	int (*mif_post_process)(struct device *dev, struct devfreq_data_mif *data, int *index, int *old_index, unsigned long *freq, unsigned long *old_freq);
};

struct devfreq_data_int {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_int;
	struct regulator *vdd_int_m;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;

	unsigned long initial_freq;
	unsigned long default_qos;
	int max_state;

	unsigned int *int_asv_abb_table;

	unsigned long target_volt;
	unsigned long volt_constraint_isp;
	unsigned int use_dvfs;

	struct notifier_block tmu_notifier;

	int (*int_set_freq)(struct devfreq_data_int *data, int index, int old_index);
	int (*int_set_volt)(struct devfreq_data_int *data, unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_disp {
	struct device *dev;
	struct devfreq *devfreq;

	struct mutex lock;
	unsigned int use_dvfs;
	unsigned long initial_freq;
	unsigned long default_qos;
	int max_state;

	int (*disp_set_freq)(struct devfreq_data_disp *data, int index, int old_index);
	int (*disp_set_volt)(struct devfreq_data_disp *data, unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_isp {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_isp;
	unsigned long old_volt;
	unsigned long volt_offset;
	int max_state;

	struct mutex lock;
	unsigned int use_dvfs;
	unsigned long initial_freq;
	unsigned long default_qos;
	struct notifier_block tmu_notifier;

	int (*isp_set_freq)(struct devfreq_data_isp *data, int index, int old_index);
	int (*isp_set_volt)(struct devfreq_data_isp *data, unsigned long volt,  unsigned long volt_range, bool tolower);
};

struct devfreq_thermal_work {
	struct delayed_work devfreq_mif_thermal_work;
	int channel;
	struct workqueue_struct *work_queue;
	unsigned int thermal_level_cs0;
	unsigned int thermal_level_cs1;
	unsigned int polling_period;
	unsigned long max_freq;
};

#define CTRL_LOCK_VALUE_SHIFT	(0x8)
#define CTRL_LOCK_VALUE_MASK	(0x1FF)
#define CTRL_FORCE_SHIFT	(0x7)
#define CTRL_FORCE_MASK		(0x1FF)
#define CTRL_FORCE_OFFSET	(8)

#define MIF_VOLT_STEP		(12500)
#define COLD_VOLT_OFFSET	(37500)
#define LIMIT_COLD_VOLTAGE	(1250000)

unsigned int get_limit_voltage(unsigned int voltage, unsigned int volt_offset);
int exynos5_devfreq_get_idx(struct devfreq_opp_table *table, unsigned int size, unsigned long freq);

int exynos5433_devfreq_mif_init(struct devfreq_data_mif *data);
int exynos5433_devfreq_mif_deinit(struct devfreq_data_mif *data);
int exynos5433_devfreq_int_init(struct devfreq_data_int *data);
int exynos5433_devfreq_int_deinit(struct devfreq_data_int *data);
int exynos5433_devfreq_disp_init(struct devfreq_data_disp *data);
int exynos5433_devfreq_disp_deinit(struct devfreq_data_disp *data);
int exynos5433_devfreq_isp_init(struct devfreq_data_isp *data);
int exynos5433_devfreq_isp_deinit(struct devfreq_data_isp *data);
#elif defined(CONFIG_ARM_EXYNOS7420_BUS_DEVFREQ)
#define MIF_BLK_NUM	4
#define REGULATOR_MIN_MICROVOLT        500000
#define REGULATOR_MAX_MICROVOLT        1000000
struct devfreq_data_mif {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_mif;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;
	struct notifier_block tmu_notifier;
	bool use_dvfs;

	void __iomem *base_cmu_topc;
	void __iomem *base_cmu_mif[MIF_BLK_NUM];
	void __iomem *base_sysreg_mif;
	void __iomem *base_drex[MIF_BLK_NUM];
	void __iomem *base_lp4_phy[MIF_BLK_NUM];
	void __iomem *base_vt_mon_mif[MIF_BLK_NUM];
	void __iomem *base_nsp;

	uint32_t mid; 									/* Manufacturer ID */

	int default_qos;
	int initial_freq;
	int cal_qos_max;
	int max_state;
	int volt_of_avail_max_freq;
	unsigned long cur_freq;

	uint32_t tmu_temp;

	uint32_t mem_density;
	uint32_t tREFI;

	uint32_t per_mrs_en;
	uint32_t pll_safe_idx;
	ulong  switching_pll_rate;		/* dout_sclk_bus0_pll_mif(800M) */

	int (*mif_set_freq)(struct devfreq_data_mif *data, int index, int old_index);
	int (*mif_set_timeout)(struct devfreq_data_mif *data, int index);
	int (*mif_set_volt)(struct devfreq_data_mif *data, unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_int {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_int;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;

	unsigned long initial_freq;
	unsigned long default_qos;
	int max_state;
	int volt_of_avail_max_freq;
	unsigned long cur_freq;

	unsigned long target_volt;
	unsigned int use_dvfs;

	struct notifier_block tmu_notifier;

	int (*int_set_freq)(struct devfreq_data_int *data, int index, int old_index);
	int (*int_set_volt)(struct devfreq_data_int *data, unsigned long volt,  unsigned long volt_range);
	int (*int_get_volt)(struct devfreq_data_int *data);
};

struct devfreq_data_disp {
	struct device *dev;
	struct devfreq *devfreq;

	struct mutex lock;
	unsigned int use_dvfs;
	unsigned long initial_freq;
	unsigned long default_qos;
	int max_state;
	int volt_of_avail_max_freq;
	unsigned long cur_freq;

	struct regulator *vdd_disp_cam0;
	unsigned long old_volt;
	unsigned long volt_offset;
	struct notifier_block tmu_notifier;

	int (*disp_set_freq)(struct devfreq_data_disp *data, int index, int old_index);
	int (*disp_set_volt)(struct devfreq_data_disp *data, unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_isp {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_disp_cam0;
	unsigned long old_volt;
	unsigned long volt_offset;
	int max_state;
	int volt_of_avail_max_freq;
	unsigned long cur_freq;

	struct mutex lock;
	unsigned int use_dvfs;
	unsigned long initial_freq;
	unsigned long default_qos;
	struct notifier_block tmu_notifier;

	int (*isp_set_freq)(struct devfreq_data_isp *data, int index, int old_index);
	int (*isp_set_volt)(struct devfreq_data_isp *data, unsigned long volt,  unsigned long volt_range);
};

struct devfreq_thermal_work {
	struct delayed_work devfreq_mif_thermal_work;
	int channel;
	struct workqueue_struct *work_queue;
	unsigned int thermal_level_ch0_cs0;
	unsigned int thermal_level_ch0_cs1;
	unsigned int thermal_level_ch1_cs0;
	unsigned int thermal_level_ch1_cs1;
	unsigned int thermal_level_ch2_cs0;
	unsigned int thermal_level_ch2_cs1;
	unsigned int thermal_level_ch3_cs0;
	unsigned int thermal_level_ch3_cs1;
	unsigned int polling_period;
	unsigned long max_freq;
	unsigned long min_freq;
};

typedef enum {
	 LP4_Non_SEC=0,
	 LP4_SEC=1,
} lp4_mid_t;

typedef enum {
	LP4_4Gb_Die=0,
	LP4_6Gb_Die=1,
	LP4_8Gb_Die=2,
	LP4_12Gb_Die=3,
	LP4_16Gb_Die=4,
	LP4_24Gb_Die=5,
	LP4_32Gb_Die=6,
	LP4_Invalid_Die=7,
} lp4_density_t;

#define CTRL_LOCK_VALUE_SHIFT	(0x8)
#define CTRL_LOCK_VALUE_MASK	(0x1FF)
#define CTRL_FORCE_SHIFT	(0x7)
#define CTRL_FORCE_MASK		(0x1FF)
#define CTRL_FORCE_OFFSET	(8)

#define COLD_VOLT_OFFSET	(37500)
#define LIMIT_COLD_VOLTAGE	(1175000)

unsigned int get_limit_voltage(unsigned int voltage, unsigned int volt_offset, unsigned int max_volt);
int get_volt_of_avail_max_freq(struct device *dev);
int devfreq_get_opp_idx(struct devfreq_opp_table *table, unsigned int size, unsigned long freq);

int exynos7420_devfreq_mif_init(struct devfreq_data_mif *data);
int exynos7420_devfreq_mif_deinit(struct devfreq_data_mif *data);
int exynos7420_devfreq_int_init(struct devfreq_data_int *data);
int exynos7420_devfreq_int_deinit(struct devfreq_data_int *data);
int exynos7420_devfreq_disp_init(struct devfreq_data_disp *data);
int exynos7420_devfreq_disp_deinit(struct devfreq_data_disp *data);
int exynos7420_devfreq_isp_init(struct devfreq_data_isp *data);
int exynos7420_devfreq_isp_deinit(struct devfreq_data_isp *data);

#elif defined(CONFIG_ARM_EXYNOS7580_BUS_DEVFREQ)
static const struct of_device_id __devfreq_init_of_table_sentinel
	__used __section(__devfreq_init_of_table_end);

static const struct of_device_id __devfreq_deinit_of_table_sentinel
	__used __section(__devfreq_deinit_of_table_end);

#define DEVFREQ_INIT_OF_DECLARE(name, compat, fn)			   \
	static const struct of_device_id __devfreq_init_of_table_##name     \
		__used __section(__devfreq_init_of_table)		   \
		 = { .compatible = compat,				  \
		     .data = (fn == (devfreq_init_of_fn)NULL) ? fn : fn }

#define DEVFREQ_DEINIT_OF_DECLARE(name, compat, fn)			 \
	static const struct of_device_id __devfreq_deinit_of_table_##name   \
		__used __section(__devfreq_deinit_of_table)		 \
		 = { .compatible = compat,				  \
		     .data = (fn == (devfreq_deinit_of_fn)NULL) ? fn : fn }

extern struct of_device_id __devfreq_init_of_table[];
extern struct devfreq_opp_table devfreq_int_opp_list[];

extern struct of_device_id __devfreq_init_of_table[];
extern struct of_device_id __devfreq_deinit_of_table[];
extern struct devfreq_opp_table devfreq_mif_opp_list[];

extern void exynos7580_devfreq_set_dll_lock_value(struct devfreq_data_mif *, int);
extern struct attribute_group devfreq_mif_attr_group;

extern struct of_device_id __devfreq_init_of_table[];
extern struct devfreq_opp_table devfreq_isp_opp_list[];

extern void exynos7580_devfreq_set_dll_lock_value(struct devfreq_data_mif *, int);
extern void exynos7_devfreq_init_thermal(void);
extern struct attribute_group devfreq_mif_attr_group;

#define REGULATOR_MAX_MICROVOLT	INT_MAX

/* DREX, PHY and PMU Base address */
#define DREX_BASE	0x10400000
#define PHY_BASE	0x10420000
#define CMU_MIF_BASE	0x10430000

/* DREX REGISTER: 0x1040_0000 */
#define DREX_MEMCONTROL	0x4
#define DREX_CGCONTROL	0x8
#define DREX_DIRECTCMD	0x10
#define DREX_TIMINGRFCPB	0x20
#define DREX_TIMINGAREF	0x30
#define DREX_TIMINGROW_0	0x34
#define DREX_TIMINGDATA_0	0x38
#define DREX_TIMINGPOWER_0	0x3C
#define DREX_PHYSTATUS	0x40
#define DREX_RDFETCH_0	0x4C
#define DREX_RDFETCH_1	0x50
#define DREX_MRSTATUS	0x54
#define DREX_TIMINGSETSW	0xE0
#define DREX_TIMINGROW_1	0xE4
#define DREX_TIMINGDATA_1	0xE8
#define DREX_TIMINGPOWER_1	0xEC

/* DREX MASK */
#define DREX_TIMINGRFCPB_SET1_MASK	0x3F00
#define DREX_TIMINGRFCPB_SET0_MASK	0x3F
#define DREX_MRSTATUS_THERMAL_LV_MASK	0x7

/* DREX SHIFT */
#define CG_EN_SHIFT	4
#define TIMING_SET_SW_SHIFT	31

/* DREX SET */
#define PB_REF_EN	BIT(27)

/* PHY Control Register: 0x1042_0000 */
#define PHY_MDLL_CON0	0xB0
#define PHY_MDLL_CON1	0xB4
#define PHY_DVFS_CON0	0xB8
#define PHY_DVFS_CON2	0xBC
#define PHY_DVFS_CON3	0xC0
#define PHY_STATUS	0x40

/* PHY MASK */
#define PHY_CTRL_LOCK_NEW_MASK	0x1FF
#define PHY_CTRL_FORCE_MASK	0x1FF

/* PHY SHIFT */
#define CTRL_LOCK_RDEN_SHIFT	23
#define CTRL_LOCK_NEW_SHIFT	20
#define CTRL_FORCE_SHIFT	7
#define CTRL_DLL_ON_SHIFT	5

/* CMU_MIF Register: 0x10430000 */
#define CLK_DIV_STAT_MIF0	0x0700
#define CLK_MUX_STAT_MIF4	0x0410
#define CLK_MUX_STAT_MIF5	0x0414
#define CLK_PAUSE			0x1008

/* CMU_MIF MASK */
#define CLK_DIV_STAT_MIF0_MASK	0x11
#define CLK_MUX_STAT_MIF4_MASK	0x400040
#define CLK_PAUSE_MASK			0x00070000

/* The OPP table level (DREX_CLK 416MHz) */
#define DLL_LOCK_LV	5

struct devfreq_data_mif {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_mif;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;
	struct notifier_block tmu_notifier;
	bool use_dvfs;

	void __iomem *base_mif;
	void __iomem *base_drex;
	void __iomem *base_lpddr_phy;

	int default_qos;
	int initial_freq;
	int cal_qos_max;
	int max_state;

	uint32_t dll_lock_value;

	uint32_t pll_safe_idx;
	ulong  switching_pll_rate;

	int (*mif_set_freq)(struct devfreq_data_mif *data,
					int index, int old_index);
	int (*mif_set_timeout)(struct devfreq_data_mif *data, int index);
	int (*mif_set_volt)(struct devfreq_data_mif *data,
			unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_int {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_int;
	unsigned long old_volt;
	unsigned long volt_offset;

	struct mutex lock;

	unsigned long initial_freq;
	unsigned long default_qos;
	int max_state;

	unsigned long target_volt;
	unsigned int use_dvfs;

	struct notifier_block tmu_notifier;

	int (*int_set_freq)(struct devfreq_data_int *data,
					int index, int old_index);
	int (*int_set_volt)(struct devfreq_data_int *data,
				unsigned long volt,  unsigned long volt_range);
};

struct devfreq_data_isp {
	struct device *dev;
	struct devfreq *devfreq;

	struct regulator *vdd_isp_cam0;
	unsigned long old_volt;
	unsigned long volt_offset;
	int max_state;

	struct mutex lock;
	unsigned int use_dvfs;
	unsigned long initial_freq;
	unsigned long default_qos;
	struct notifier_block tmu_notifier;

	int (*isp_set_freq)(struct devfreq_data_isp *data,
						int index, int old_index);
	int (*isp_set_volt)(struct devfreq_data_isp *data,
			unsigned long volt,  unsigned long volt_range);
};

struct devfreq_thermal_work {
	struct delayed_work devfreq_mif_thermal_work;
	struct workqueue_struct *work_queue;
	unsigned int thermal_level_cs0;
	unsigned int thermal_level_cs1;
	unsigned int polling_period;
	unsigned long max_freq;
};

#define COLD_VOLT_OFFSET	(25000)
#define LIMIT_COLD_VOLTAGE	(1200000)

unsigned int get_limit_voltage(unsigned int voltage, unsigned int volt_offset);
int devfreq_get_opp_idx(struct devfreq_opp_table *table,
			unsigned int size, unsigned long freq);

int exynos7580_devfreq_mif_init(void *data);
int exynos7580_devfreq_mif_deinit(void *data);
int exynos7580_devfreq_int_init(void *data);
int exynos7580_devfreq_int_deinit(void *data);
int exynos7580_devfreq_isp_init(void *data);
int exynos7580_devfreq_isp_deinit(void *data);

#endif

#endif /* __DEVFREQ_EXYNOS_H */