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(
65 return GPIO_RESULT_ALREADY_OPENED;
68 // No action if allocation failed during gpio construct
69 if (!gpio->hw_container.ddc) {
71 return GPIO_RESULT_NON_SPECIFIC_ERROR;
75 return dal_gpio_service_open(gpio);
78 enum gpio_result dal_gpio_get_value(
79 const struct gpio *gpio,
84 return GPIO_RESULT_NULL_HANDLE;
87 return gpio->pin->funcs->get_value(gpio->pin, value);
90 enum gpio_result dal_gpio_set_value(
91 const struct gpio *gpio,
96 return GPIO_RESULT_NULL_HANDLE;
99 return gpio->pin->funcs->set_value(gpio->pin, value);
102 enum gpio_mode dal_gpio_get_mode(
103 const struct gpio *gpio)
108 enum gpio_result dal_gpio_lock_pin(
111 return dal_gpio_service_lock(gpio->service, gpio->id, gpio->en);
114 enum gpio_result dal_gpio_unlock_pin(
117 return dal_gpio_service_unlock(gpio->service, gpio->id, gpio->en);
120 enum gpio_result dal_gpio_change_mode(
126 return GPIO_RESULT_NULL_HANDLE;
129 return gpio->pin->funcs->change_mode(gpio->pin, mode);
132 enum gpio_id dal_gpio_get_id(
133 const struct gpio *gpio)
138 uint32_t dal_gpio_get_enum(
139 const struct gpio *gpio)
144 enum gpio_result dal_gpio_set_config(
146 const struct gpio_config_data *config_data)
150 return GPIO_RESULT_NULL_HANDLE;
153 return gpio->pin->funcs->set_config(gpio->pin, config_data);
156 enum gpio_result dal_gpio_get_pin_info(
157 const struct gpio *gpio,
158 struct gpio_pin_info *pin_info)
160 return gpio->service->translate.funcs->id_to_offset(
161 gpio->id, gpio->en, pin_info) ?
162 GPIO_RESULT_OK : GPIO_RESULT_INVALID_DATA;
165 enum sync_source dal_gpio_get_sync_source(
166 const struct gpio *gpio)
169 case GPIO_ID_GENERIC:
172 return SYNC_SOURCE_IO_GENERIC_A;
174 return SYNC_SOURCE_IO_GENERIC_B;
176 return SYNC_SOURCE_IO_GENERIC_C;
178 return SYNC_SOURCE_IO_GENERIC_D;
180 return SYNC_SOURCE_IO_GENERIC_E;
182 return SYNC_SOURCE_IO_GENERIC_F;
184 return SYNC_SOURCE_NONE;
189 case GPIO_SYNC_HSYNC_A:
190 return SYNC_SOURCE_IO_HSYNC_A;
191 case GPIO_SYNC_VSYNC_A:
192 return SYNC_SOURCE_IO_VSYNC_A;
193 case GPIO_SYNC_HSYNC_B:
194 return SYNC_SOURCE_IO_HSYNC_B;
195 case GPIO_SYNC_VSYNC_B:
196 return SYNC_SOURCE_IO_VSYNC_B;
198 return SYNC_SOURCE_NONE;
204 return SYNC_SOURCE_IO_HPD1;
206 return SYNC_SOURCE_IO_HPD2;
208 return SYNC_SOURCE_NONE;
213 case GPIO_GSL_GENLOCK_CLOCK:
214 return SYNC_SOURCE_GSL_IO_GENLOCK_CLOCK;
215 case GPIO_GSL_GENLOCK_VSYNC:
216 return SYNC_SOURCE_GSL_IO_GENLOCK_VSYNC;
217 case GPIO_GSL_SWAPLOCK_A:
218 return SYNC_SOURCE_GSL_IO_SWAPLOCK_A;
219 case GPIO_GSL_SWAPLOCK_B:
220 return SYNC_SOURCE_GSL_IO_SWAPLOCK_B;
222 return SYNC_SOURCE_NONE;
226 return SYNC_SOURCE_NONE;
230 enum gpio_pin_output_state dal_gpio_get_output_state(
231 const struct gpio *gpio)
233 return gpio->output_state;
236 struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio)
238 return gpio->hw_container.ddc;
241 struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio)
243 return gpio->hw_container.hpd;
246 struct hw_generic *dal_gpio_get_generic(struct gpio *gpio)
248 return gpio->hw_container.generic;
257 dal_gpio_service_close(gpio->service, &gpio->pin);
259 gpio->mode = GPIO_MODE_UNKNOWN;
264 * Creation and destruction
267 struct gpio *dal_gpio_create(
268 struct gpio_service *service,
271 enum gpio_pin_output_state output_state)
273 struct gpio *gpio = kzalloc(sizeof(struct gpio), GFP_KERNEL);
276 ASSERT_CRITICAL(false);
280 gpio->service = service;
284 gpio->mode = GPIO_MODE_UNKNOWN;
285 gpio->output_state = output_state;
287 //initialize hw_container union based on id
289 case GPIO_ID_DDC_DATA:
290 gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
292 case GPIO_ID_DDC_CLOCK:
293 gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
295 case GPIO_ID_GENERIC:
296 gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en);
299 gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en);
301 // TODO: currently gpio for sync and gsl does not get created, might need it later
307 ASSERT_CRITICAL(false);
314 void dal_gpio_destroy(
317 if (!gpio || !*gpio) {
318 ASSERT_CRITICAL(false);
322 switch ((*gpio)->id) {
323 case GPIO_ID_DDC_DATA:
324 kfree((*gpio)->hw_container.ddc);
325 (*gpio)->hw_container.ddc = NULL;
327 case GPIO_ID_DDC_CLOCK:
328 //TODO: might want to change it to init_ddc_clock
329 kfree((*gpio)->hw_container.ddc);
330 (*gpio)->hw_container.ddc = NULL;
332 case GPIO_ID_GENERIC:
333 kfree((*gpio)->hw_container.generic);
334 (*gpio)->hw_container.generic = NULL;
337 kfree((*gpio)->hw_container.hpd);
338 (*gpio)->hw_container.hpd = NULL;
340 // TODO: currently gpio for sync and gsl does not get created, might need it later