ASoC: ads117x: Add device tree compatible string
[cascardo/linux.git] / drivers / gpu / drm / amd / powerplay / eventmgr / eventmgr.c
1 /*
2  * Copyright 2015 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include "eventmgr.h"
27 #include "hwmgr.h"
28 #include "eventinit.h"
29 #include "eventmanagement.h"
30
31 static int pem_init(struct pp_eventmgr *eventmgr)
32 {
33         int result = 0;
34         struct pem_event_data event_data;
35
36         /* Initialize PowerPlay feature info */
37         pem_init_feature_info(eventmgr);
38
39         /* Initialize event action chains */
40         pem_init_event_action_chains(eventmgr);
41
42         /* Call initialization event */
43         result = pem_handle_event(eventmgr, AMD_PP_EVENT_INITIALIZE, &event_data);
44
45         if (0 != result)
46                 return result;
47
48         /* Register interrupt callback functions */
49         result = pem_register_interrupts(eventmgr);
50         return 0;
51 }
52
53 static void pem_fini(struct pp_eventmgr *eventmgr)
54 {
55         struct pem_event_data event_data;
56
57         pem_uninit_featureInfo(eventmgr);
58         pem_unregister_interrupts(eventmgr);
59
60         pem_handle_event(eventmgr, AMD_PP_EVENT_UNINITIALIZE, &event_data);
61
62         if (eventmgr != NULL)
63                 kfree(eventmgr);
64 }
65
66 int eventmgr_init(struct pp_instance *handle)
67 {
68         int result = 0;
69         struct pp_eventmgr *eventmgr;
70
71         if (handle == NULL)
72                 return -EINVAL;
73
74         eventmgr = kzalloc(sizeof(struct pp_eventmgr), GFP_KERNEL);
75         if (eventmgr == NULL)
76                 return -ENOMEM;
77
78         eventmgr->hwmgr = handle->hwmgr;
79         handle->eventmgr = eventmgr;
80
81         eventmgr->platform_descriptor = &(eventmgr->hwmgr->platform_descriptor);
82         eventmgr->pp_eventmgr_init = pem_init;
83         eventmgr->pp_eventmgr_fini = pem_fini;
84
85         return result;
86 }
87
88 int eventmgr_fini(struct pp_eventmgr *eventmgr)
89 {
90         kfree(eventmgr);
91         return 0;
92 }
93
94 static int pem_handle_event_unlocked(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *data)
95 {
96         if (eventmgr == NULL || event >= AMD_PP_EVENT_MAX || data == NULL)
97                 return -EINVAL;
98
99         return pem_excute_event_chain(eventmgr, eventmgr->event_chain[event], data);
100 }
101
102 int pem_handle_event(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *event_data)
103 {
104         int r = 0;
105
106         r = pem_handle_event_unlocked(eventmgr, event, event_data);
107
108         return r;
109 }
110
111 bool pem_is_hw_access_blocked(struct pp_eventmgr *eventmgr)
112 {
113         return (eventmgr->block_adjust_power_state || phm_is_hw_access_blocked(eventmgr->hwmgr));
114 }