WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / amd / display / dc / gpio / hw_generic.c
blobf9e847e6555d9b45547903bd1508daaee77df296
1 /*
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.
22 * Authors: AMD
26 #include <linux/slab.h>
28 #include "dm_services.h"
30 #include "include/gpio_interface.h"
31 #include "include/gpio_types.h"
32 #include "hw_gpio.h"
33 #include "hw_generic.h"
35 #include "reg_helper.h"
36 #include "generic_regs.h"
38 #undef FN
39 #define FN(reg_name, field_name) \
40 generic->shifts->field_name, generic->masks->field_name
42 #define CTX \
43 generic->base.base.ctx
44 #define REG(reg)\
45 (generic->regs->reg)
47 struct gpio;
49 static void dal_hw_generic_destruct(
50 struct hw_generic *pin)
52 dal_hw_gpio_destruct(&pin->base);
55 static void dal_hw_generic_destroy(
56 struct hw_gpio_pin **ptr)
58 struct hw_generic *generic = HW_GENERIC_FROM_BASE(*ptr);
60 dal_hw_generic_destruct(generic);
62 kfree(generic);
64 *ptr = NULL;
67 static enum gpio_result set_config(
68 struct hw_gpio_pin *ptr,
69 const struct gpio_config_data *config_data)
71 struct hw_generic *generic = HW_GENERIC_FROM_BASE(ptr);
73 if (!config_data)
74 return GPIO_RESULT_INVALID_DATA;
76 REG_UPDATE_2(mux,
77 GENERIC_EN, config_data->config.generic_mux.enable_output_from_mux,
78 GENERIC_SEL, config_data->config.generic_mux.mux_select);
80 return GPIO_RESULT_OK;
83 static const struct hw_gpio_pin_funcs funcs = {
84 .destroy = dal_hw_generic_destroy,
85 .open = dal_hw_gpio_open,
86 .get_value = dal_hw_gpio_get_value,
87 .set_value = dal_hw_gpio_set_value,
88 .set_config = set_config,
89 .change_mode = dal_hw_gpio_change_mode,
90 .close = dal_hw_gpio_close,
93 static void dal_hw_generic_construct(
94 struct hw_generic *pin,
95 enum gpio_id id,
96 uint32_t en,
97 struct dc_context *ctx)
99 dal_hw_gpio_construct(&pin->base, id, en, ctx);
100 pin->base.base.funcs = &funcs;
103 void dal_hw_generic_init(
104 struct hw_generic **hw_generic,
105 struct dc_context *ctx,
106 enum gpio_id id,
107 uint32_t en)
109 if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
110 ASSERT_CRITICAL(false);
111 *hw_generic = NULL;
114 *hw_generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL);
115 if (!*hw_generic) {
116 ASSERT_CRITICAL(false);
117 return;
120 dal_hw_generic_construct(*hw_generic, id, en, ctx);
124 struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio)
126 struct hw_generic *hw_generic = dal_gpio_get_generic(gpio);
128 return &hw_generic->base.base;