2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 * Pre-requisites: headers required by header of this unit
30 #include <linux/slab.h>
32 #include "dm_services.h"
34 #include "include/gpio_interface.h"
35 #include "include/gpio_service_interface.h"
37 #include "hw_translate.h"
38 #include "hw_factory.h"
39 #include "gpio_service.h"
42 * Post-requisites: headers required by this unit
54 enum gpio_result
dal_gpio_open(
58 return dal_gpio_open_ex(gpio
, mode
);
61 enum gpio_result
dal_gpio_open_ex(
66 ASSERT_CRITICAL(false);
67 return GPIO_RESULT_ALREADY_OPENED
;
70 // No action if allocation failed during gpio construct
71 if (!gpio
->hw_container
.ddc
) {
72 ASSERT_CRITICAL(false);
73 return GPIO_RESULT_NON_SPECIFIC_ERROR
;
77 return dal_gpio_service_open(gpio
);
80 enum gpio_result
dal_gpio_get_value(
81 const struct gpio
*gpio
,
86 return GPIO_RESULT_NULL_HANDLE
;
89 return gpio
->pin
->funcs
->get_value(gpio
->pin
, value
);
92 enum gpio_result
dal_gpio_set_value(
93 const struct gpio
*gpio
,
98 return GPIO_RESULT_NULL_HANDLE
;
101 return gpio
->pin
->funcs
->set_value(gpio
->pin
, value
);
104 enum gpio_mode
dal_gpio_get_mode(
105 const struct gpio
*gpio
)
110 enum gpio_result
dal_gpio_lock_pin(
113 return dal_gpio_service_lock(gpio
->service
, gpio
->id
, gpio
->en
);
116 enum gpio_result
dal_gpio_unlock_pin(
119 return dal_gpio_service_unlock(gpio
->service
, gpio
->id
, gpio
->en
);
122 enum gpio_result
dal_gpio_change_mode(
128 return GPIO_RESULT_NULL_HANDLE
;
131 return gpio
->pin
->funcs
->change_mode(gpio
->pin
, mode
);
134 enum gpio_id
dal_gpio_get_id(
135 const struct gpio
*gpio
)
140 uint32_t dal_gpio_get_enum(
141 const struct gpio
*gpio
)
146 enum gpio_result
dal_gpio_set_config(
148 const struct gpio_config_data
*config_data
)
152 return GPIO_RESULT_NULL_HANDLE
;
155 return gpio
->pin
->funcs
->set_config(gpio
->pin
, config_data
);
158 enum gpio_result
dal_gpio_get_pin_info(
159 const struct gpio
*gpio
,
160 struct gpio_pin_info
*pin_info
)
162 return gpio
->service
->translate
.funcs
->id_to_offset(
163 gpio
->id
, gpio
->en
, pin_info
) ?
164 GPIO_RESULT_OK
: GPIO_RESULT_INVALID_DATA
;
167 enum sync_source
dal_gpio_get_sync_source(
168 const struct gpio
*gpio
)
171 case GPIO_ID_GENERIC
:
174 return SYNC_SOURCE_IO_GENERIC_A
;
176 return SYNC_SOURCE_IO_GENERIC_B
;
178 return SYNC_SOURCE_IO_GENERIC_C
;
180 return SYNC_SOURCE_IO_GENERIC_D
;
182 return SYNC_SOURCE_IO_GENERIC_E
;
184 return SYNC_SOURCE_IO_GENERIC_F
;
186 return SYNC_SOURCE_NONE
;
191 case GPIO_SYNC_HSYNC_A
:
192 return SYNC_SOURCE_IO_HSYNC_A
;
193 case GPIO_SYNC_VSYNC_A
:
194 return SYNC_SOURCE_IO_VSYNC_A
;
195 case GPIO_SYNC_HSYNC_B
:
196 return SYNC_SOURCE_IO_HSYNC_B
;
197 case GPIO_SYNC_VSYNC_B
:
198 return SYNC_SOURCE_IO_VSYNC_B
;
200 return SYNC_SOURCE_NONE
;
206 return SYNC_SOURCE_IO_HPD1
;
208 return SYNC_SOURCE_IO_HPD2
;
210 return SYNC_SOURCE_NONE
;
215 case GPIO_GSL_GENLOCK_CLOCK
:
216 return SYNC_SOURCE_GSL_IO_GENLOCK_CLOCK
;
217 case GPIO_GSL_GENLOCK_VSYNC
:
218 return SYNC_SOURCE_GSL_IO_GENLOCK_VSYNC
;
219 case GPIO_GSL_SWAPLOCK_A
:
220 return SYNC_SOURCE_GSL_IO_SWAPLOCK_A
;
221 case GPIO_GSL_SWAPLOCK_B
:
222 return SYNC_SOURCE_GSL_IO_SWAPLOCK_B
;
224 return SYNC_SOURCE_NONE
;
228 return SYNC_SOURCE_NONE
;
232 enum gpio_pin_output_state
dal_gpio_get_output_state(
233 const struct gpio
*gpio
)
235 return gpio
->output_state
;
238 struct hw_ddc
*dal_gpio_get_ddc(struct gpio
*gpio
)
240 return gpio
->hw_container
.ddc
;
243 struct hw_hpd
*dal_gpio_get_hpd(struct gpio
*gpio
)
245 return gpio
->hw_container
.hpd
;
248 struct hw_generic
*dal_gpio_get_generic(struct gpio
*gpio
)
250 return gpio
->hw_container
.generic
;
259 dal_gpio_service_close(gpio
->service
, &gpio
->pin
);
261 gpio
->mode
= GPIO_MODE_UNKNOWN
;
266 * Creation and destruction
269 struct gpio
*dal_gpio_create(
270 struct gpio_service
*service
,
273 enum gpio_pin_output_state output_state
)
275 struct gpio
*gpio
= kzalloc(sizeof(struct gpio
), GFP_KERNEL
);
278 ASSERT_CRITICAL(false);
282 gpio
->service
= service
;
286 gpio
->mode
= GPIO_MODE_UNKNOWN
;
287 gpio
->output_state
= output_state
;
289 //initialize hw_container union based on id
291 case GPIO_ID_DDC_DATA
:
292 gpio
->service
->factory
.funcs
->init_ddc_data(&gpio
->hw_container
.ddc
, service
->ctx
, id
, en
);
294 case GPIO_ID_DDC_CLOCK
:
295 gpio
->service
->factory
.funcs
->init_ddc_data(&gpio
->hw_container
.ddc
, service
->ctx
, id
, en
);
297 case GPIO_ID_GENERIC
:
298 gpio
->service
->factory
.funcs
->init_generic(&gpio
->hw_container
.generic
, service
->ctx
, id
, en
);
301 gpio
->service
->factory
.funcs
->init_hpd(&gpio
->hw_container
.hpd
, service
->ctx
, id
, en
);
303 // TODO: currently gpio for sync and gsl does not get created, might need it later
309 ASSERT_CRITICAL(false);
316 void dal_gpio_destroy(
319 if (!gpio
|| !*gpio
) {
320 ASSERT_CRITICAL(false);
324 switch ((*gpio
)->id
) {
325 case GPIO_ID_DDC_DATA
:
326 kfree((*gpio
)->hw_container
.ddc
);
327 (*gpio
)->hw_container
.ddc
= NULL
;
329 case GPIO_ID_DDC_CLOCK
:
330 //TODO: might want to change it to init_ddc_clock
331 kfree((*gpio
)->hw_container
.ddc
);
332 (*gpio
)->hw_container
.ddc
= NULL
;
334 case GPIO_ID_GENERIC
:
335 kfree((*gpio
)->hw_container
.generic
);
336 (*gpio
)->hw_container
.generic
= NULL
;
339 kfree((*gpio
)->hw_container
.hpd
);
340 (*gpio
)->hw_container
.hpd
= NULL
;
342 // TODO: currently gpio for sync and gsl does not get created, might need it later