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 "dm_services.h"
32 #include "include/gpio_interface.h"
33 #include "include/gpio_service_interface.h"
35 #include "hw_translate.h"
36 #include "hw_factory.h"
37 #include "gpio_service.h"
40 * Post-requisites: headers required by this unit
52 enum gpio_result dal_gpio_open(
56 return dal_gpio_open_ex(gpio, mode);
59 enum gpio_result dal_gpio_open_ex(
64 ASSERT_CRITICAL(false);
65 return GPIO_RESULT_ALREADY_OPENED;
70 return dal_gpio_service_open(
71 gpio->service, gpio->id, gpio->en, mode, &gpio->pin);
74 enum gpio_result dal_gpio_get_value(
75 const struct gpio *gpio,
80 return GPIO_RESULT_NULL_HANDLE;
83 return gpio->pin->funcs->get_value(gpio->pin, value);
86 enum gpio_result dal_gpio_set_value(
87 const struct gpio *gpio,
92 return GPIO_RESULT_NULL_HANDLE;
95 return gpio->pin->funcs->set_value(gpio->pin, value);
98 enum gpio_mode dal_gpio_get_mode(
99 const struct gpio *gpio)
104 enum gpio_result dal_gpio_change_mode(
110 return GPIO_RESULT_NULL_HANDLE;
113 return gpio->pin->funcs->change_mode(gpio->pin, mode);
116 enum gpio_id dal_gpio_get_id(
117 const struct gpio *gpio)
122 uint32_t dal_gpio_get_enum(
123 const struct gpio *gpio)
128 enum gpio_result dal_gpio_set_config(
130 const struct gpio_config_data *config_data)
134 return GPIO_RESULT_NULL_HANDLE;
137 return gpio->pin->funcs->set_config(gpio->pin, config_data);
140 enum gpio_result dal_gpio_get_pin_info(
141 const struct gpio *gpio,
142 struct gpio_pin_info *pin_info)
144 return gpio->service->translate.funcs->id_to_offset(
145 gpio->id, gpio->en, pin_info) ?
146 GPIO_RESULT_OK : GPIO_RESULT_INVALID_DATA;
149 enum sync_source dal_gpio_get_sync_source(
150 const struct gpio *gpio)
153 case GPIO_ID_GENERIC:
156 return SYNC_SOURCE_IO_GENERIC_A;
158 return SYNC_SOURCE_IO_GENERIC_B;
160 return SYNC_SOURCE_IO_GENERIC_C;
162 return SYNC_SOURCE_IO_GENERIC_D;
164 return SYNC_SOURCE_IO_GENERIC_E;
166 return SYNC_SOURCE_IO_GENERIC_F;
168 return SYNC_SOURCE_NONE;
173 case GPIO_SYNC_HSYNC_A:
174 return SYNC_SOURCE_IO_HSYNC_A;
175 case GPIO_SYNC_VSYNC_A:
176 return SYNC_SOURCE_IO_VSYNC_A;
177 case GPIO_SYNC_HSYNC_B:
178 return SYNC_SOURCE_IO_HSYNC_B;
179 case GPIO_SYNC_VSYNC_B:
180 return SYNC_SOURCE_IO_VSYNC_B;
182 return SYNC_SOURCE_NONE;
188 return SYNC_SOURCE_IO_HPD1;
190 return SYNC_SOURCE_IO_HPD2;
192 return SYNC_SOURCE_NONE;
197 case GPIO_GSL_GENLOCK_CLOCK:
198 return SYNC_SOURCE_GSL_IO_GENLOCK_CLOCK;
199 case GPIO_GSL_GENLOCK_VSYNC:
200 return SYNC_SOURCE_GSL_IO_GENLOCK_VSYNC;
201 case GPIO_GSL_SWAPLOCK_A:
202 return SYNC_SOURCE_GSL_IO_SWAPLOCK_A;
203 case GPIO_GSL_SWAPLOCK_B:
204 return SYNC_SOURCE_GSL_IO_SWAPLOCK_B;
206 return SYNC_SOURCE_NONE;
210 return SYNC_SOURCE_NONE;
214 enum gpio_pin_output_state dal_gpio_get_output_state(
215 const struct gpio *gpio)
217 return gpio->output_state;
226 dal_gpio_service_close(gpio->service, &gpio->pin);
228 gpio->mode = GPIO_MODE_UNKNOWN;
233 * Creation and destruction
236 struct gpio *dal_gpio_create(
237 struct gpio_service *service,
240 enum gpio_pin_output_state output_state)
242 struct gpio *gpio = kzalloc(sizeof(struct gpio), GFP_KERNEL);
245 ASSERT_CRITICAL(false);
249 gpio->service = service;
253 gpio->mode = GPIO_MODE_UNKNOWN;
254 gpio->output_state = output_state;
259 void dal_gpio_destroy(
262 if (!gpio || !*gpio) {
263 ASSERT_CRITICAL(false);
267 dal_gpio_close(*gpio);