summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/msm/disp/dpu1/dpu_power_handle.h
blob: 124ebc93c877a3687b23da97c5be22a40b0b58b6 (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
/* Copyright (c) 2016-2018, The Linux Foundation. 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 and
 * only 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.
 *
 */

#ifndef _DPU_POWER_HANDLE_H_
#define _DPU_POWER_HANDLE_H_

#define MAX_CLIENT_NAME_LEN 128

#define DPU_POWER_HANDLE_ENABLE_BUS_AB_QUOTA	0
#define DPU_POWER_HANDLE_DISABLE_BUS_AB_QUOTA	0
#define DPU_POWER_HANDLE_ENABLE_BUS_IB_QUOTA	1600000000
#define DPU_POWER_HANDLE_DISABLE_BUS_IB_QUOTA	0

#include "dpu_io_util.h"

/* events will be triggered on power handler enable/disable */
#define DPU_POWER_EVENT_DISABLE	BIT(0)
#define DPU_POWER_EVENT_ENABLE	BIT(1)

/**
 * enum DPU_POWER_HANDLE_DBUS_ID - data bus identifier
 * @DPU_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
 * @DPU_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
 * @DPU_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
 */
enum DPU_POWER_HANDLE_DBUS_ID {
	DPU_POWER_HANDLE_DBUS_ID_MNOC,
	DPU_POWER_HANDLE_DBUS_ID_LLCC,
	DPU_POWER_HANDLE_DBUS_ID_EBI,
	DPU_POWER_HANDLE_DBUS_ID_MAX,
};

/*
 * struct dpu_power_event - local event registration structure
 * @client_name: name of the client registering
 * @cb_fnc: pointer to desired callback function
 * @usr: user pointer to pass to callback event trigger
 * @event: refer to DPU_POWER_HANDLE_EVENT_*
 * @list: list to attach event master list
 * @active: indicates the state of dpu power handle
 */
struct dpu_power_event {
	char client_name[MAX_CLIENT_NAME_LEN];
	void (*cb_fnc)(u32 event_type, void *usr);
	void *usr;
	u32 event_type;
	struct list_head list;
	bool active;
};

/**
 * struct dpu_power_handle: power handle main struct
 * @phandle_lock: lock to synchronize the enable/disable
 * @dev: pointer to device structure
 * @usecase_ndx: current usecase index
 * @event_list: current power handle event list
 */
struct dpu_power_handle {
	struct mutex phandle_lock;
	struct device *dev;
	u32 current_usecase_ndx;
	struct list_head event_list;
};

/**
 * dpu_power_resource_init() - initializes the dpu power handle
 * @pdev:   platform device to search the power resources
 * @pdata:  power handle to store the power resources
 */
void dpu_power_resource_init(struct platform_device *pdev,
	struct dpu_power_handle *pdata);

/**
 * dpu_power_resource_deinit() - release the dpu power handle
 * @pdev:   platform device for power resources
 * @pdata:  power handle containing the resources
 *
 * Return: error code.
 */
void dpu_power_resource_deinit(struct platform_device *pdev,
	struct dpu_power_handle *pdata);

/**
 * dpu_power_resource_enable() - enable/disable the power resources
 * @pdata:  power handle containing the resources
 * @enable: boolean request for enable/disable
 *
 * Return: error code.
 */
int dpu_power_resource_enable(struct dpu_power_handle *pdata, bool enable);

/**
 * dpu_power_handle_register_event - register a callback function for an event.
 *	Clients can register for multiple events with a single register.
 *	Any block with access to phandle can register for the event
 *	notification.
 * @phandle:	power handle containing the resources
 * @event_type:	event type to register; refer DPU_POWER_HANDLE_EVENT_*
 * @cb_fnc:	pointer to desired callback function
 * @usr:	user pointer to pass to callback on event trigger
 *
 * Return:	event pointer if success, or error code otherwise
 */
struct dpu_power_event *dpu_power_handle_register_event(
		struct dpu_power_handle *phandle,
		u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
		void *usr, char *client_name);
/**
 * dpu_power_handle_unregister_event - unregister callback for event(s)
 * @phandle:	power handle containing the resources
 * @event:	event pointer returned after power handle register
 */
void dpu_power_handle_unregister_event(struct dpu_power_handle *phandle,
		struct dpu_power_event *event);

#endif /* _DPU_POWER_HANDLE_H_ */