| .. | .. |
|---|
| 27 | 27 | * Pre-requisites: headers required by header of this unit |
|---|
| 28 | 28 | */ |
|---|
| 29 | 29 | |
|---|
| 30 | +#include <linux/slab.h> |
|---|
| 31 | + |
|---|
| 30 | 32 | #include "dm_services.h" |
|---|
| 31 | 33 | |
|---|
| 32 | 34 | #include "include/gpio_interface.h" |
|---|
| .. | .. |
|---|
| 61 | 63 | enum gpio_mode mode) |
|---|
| 62 | 64 | { |
|---|
| 63 | 65 | if (gpio->pin) { |
|---|
| 64 | | - ASSERT_CRITICAL(false); |
|---|
| 66 | + BREAK_TO_DEBUGGER(); |
|---|
| 65 | 67 | return GPIO_RESULT_ALREADY_OPENED; |
|---|
| 66 | 68 | } |
|---|
| 67 | 69 | |
|---|
| 70 | + // No action if allocation failed during gpio construct |
|---|
| 71 | + if (!gpio->hw_container.ddc) { |
|---|
| 72 | + BREAK_TO_DEBUGGER(); |
|---|
| 73 | + return GPIO_RESULT_NON_SPECIFIC_ERROR; |
|---|
| 74 | + } |
|---|
| 68 | 75 | gpio->mode = mode; |
|---|
| 69 | 76 | |
|---|
| 70 | | - return dal_gpio_service_open( |
|---|
| 71 | | - gpio->service, gpio->id, gpio->en, mode, &gpio->pin); |
|---|
| 77 | + return dal_gpio_service_open(gpio); |
|---|
| 72 | 78 | } |
|---|
| 73 | 79 | |
|---|
| 74 | 80 | enum gpio_result dal_gpio_get_value( |
|---|
| .. | .. |
|---|
| 99 | 105 | const struct gpio *gpio) |
|---|
| 100 | 106 | { |
|---|
| 101 | 107 | return gpio->mode; |
|---|
| 108 | +} |
|---|
| 109 | + |
|---|
| 110 | +enum gpio_result dal_gpio_lock_pin( |
|---|
| 111 | + struct gpio *gpio) |
|---|
| 112 | +{ |
|---|
| 113 | + return dal_gpio_service_lock(gpio->service, gpio->id, gpio->en); |
|---|
| 114 | +} |
|---|
| 115 | + |
|---|
| 116 | +enum gpio_result dal_gpio_unlock_pin( |
|---|
| 117 | + struct gpio *gpio) |
|---|
| 118 | +{ |
|---|
| 119 | + return dal_gpio_service_unlock(gpio->service, gpio->id, gpio->en); |
|---|
| 102 | 120 | } |
|---|
| 103 | 121 | |
|---|
| 104 | 122 | enum gpio_result dal_gpio_change_mode( |
|---|
| .. | .. |
|---|
| 217 | 235 | return gpio->output_state; |
|---|
| 218 | 236 | } |
|---|
| 219 | 237 | |
|---|
| 238 | +struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio) |
|---|
| 239 | +{ |
|---|
| 240 | + return gpio->hw_container.ddc; |
|---|
| 241 | +} |
|---|
| 242 | + |
|---|
| 243 | +struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio) |
|---|
| 244 | +{ |
|---|
| 245 | + return gpio->hw_container.hpd; |
|---|
| 246 | +} |
|---|
| 247 | + |
|---|
| 248 | +struct hw_generic *dal_gpio_get_generic(struct gpio *gpio) |
|---|
| 249 | +{ |
|---|
| 250 | + return gpio->hw_container.generic; |
|---|
| 251 | +} |
|---|
| 252 | + |
|---|
| 220 | 253 | void dal_gpio_close( |
|---|
| 221 | 254 | struct gpio *gpio) |
|---|
| 222 | 255 | { |
|---|
| .. | .. |
|---|
| 253 | 286 | gpio->mode = GPIO_MODE_UNKNOWN; |
|---|
| 254 | 287 | gpio->output_state = output_state; |
|---|
| 255 | 288 | |
|---|
| 289 | + //initialize hw_container union based on id |
|---|
| 290 | + switch (gpio->id) { |
|---|
| 291 | + case GPIO_ID_DDC_DATA: |
|---|
| 292 | + gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en); |
|---|
| 293 | + break; |
|---|
| 294 | + case GPIO_ID_DDC_CLOCK: |
|---|
| 295 | + gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en); |
|---|
| 296 | + break; |
|---|
| 297 | + case GPIO_ID_GENERIC: |
|---|
| 298 | + gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en); |
|---|
| 299 | + break; |
|---|
| 300 | + case GPIO_ID_HPD: |
|---|
| 301 | + gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en); |
|---|
| 302 | + break; |
|---|
| 303 | + // TODO: currently gpio for sync and gsl does not get created, might need it later |
|---|
| 304 | + case GPIO_ID_SYNC: |
|---|
| 305 | + break; |
|---|
| 306 | + case GPIO_ID_GSL: |
|---|
| 307 | + break; |
|---|
| 308 | + default: |
|---|
| 309 | + ASSERT_CRITICAL(false); |
|---|
| 310 | + gpio->pin = NULL; |
|---|
| 311 | + } |
|---|
| 312 | + |
|---|
| 256 | 313 | return gpio; |
|---|
| 257 | 314 | } |
|---|
| 258 | 315 | |
|---|
| .. | .. |
|---|
| 264 | 321 | return; |
|---|
| 265 | 322 | } |
|---|
| 266 | 323 | |
|---|
| 267 | | - dal_gpio_close(*gpio); |
|---|
| 324 | + switch ((*gpio)->id) { |
|---|
| 325 | + case GPIO_ID_DDC_DATA: |
|---|
| 326 | + kfree((*gpio)->hw_container.ddc); |
|---|
| 327 | + (*gpio)->hw_container.ddc = NULL; |
|---|
| 328 | + break; |
|---|
| 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; |
|---|
| 333 | + break; |
|---|
| 334 | + case GPIO_ID_GENERIC: |
|---|
| 335 | + kfree((*gpio)->hw_container.generic); |
|---|
| 336 | + (*gpio)->hw_container.generic = NULL; |
|---|
| 337 | + break; |
|---|
| 338 | + case GPIO_ID_HPD: |
|---|
| 339 | + kfree((*gpio)->hw_container.hpd); |
|---|
| 340 | + (*gpio)->hw_container.hpd = NULL; |
|---|
| 341 | + break; |
|---|
| 342 | + // TODO: currently gpio for sync and gsl does not get created, might need it later |
|---|
| 343 | + case GPIO_ID_SYNC: |
|---|
| 344 | + break; |
|---|
| 345 | + case GPIO_ID_GSL: |
|---|
| 346 | + break; |
|---|
| 347 | + default: |
|---|
| 348 | + break; |
|---|
| 349 | + } |
|---|
| 268 | 350 | |
|---|
| 269 | 351 | kfree(*gpio); |
|---|
| 270 | 352 | |
|---|