0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include <linux/slab.h>
0027
0028 #include "dm_services.h"
0029
0030 #include "include/gpio_interface.h"
0031 #include "include/gpio_types.h"
0032 #include "hw_gpio.h"
0033 #include "hw_generic.h"
0034
0035 #include "reg_helper.h"
0036 #include "generic_regs.h"
0037
0038 #undef FN
0039 #define FN(reg_name, field_name) \
0040 generic->shifts->field_name, generic->masks->field_name
0041
0042 #define CTX \
0043 generic->base.base.ctx
0044 #define REG(reg)\
0045 (generic->regs->reg)
0046
0047 struct gpio;
0048
0049 static void dal_hw_generic_destruct(
0050 struct hw_generic *pin)
0051 {
0052 dal_hw_gpio_destruct(&pin->base);
0053 }
0054
0055 static void dal_hw_generic_destroy(
0056 struct hw_gpio_pin **ptr)
0057 {
0058 struct hw_generic *generic = HW_GENERIC_FROM_BASE(*ptr);
0059
0060 dal_hw_generic_destruct(generic);
0061
0062 kfree(generic);
0063
0064 *ptr = NULL;
0065 }
0066
0067 static enum gpio_result set_config(
0068 struct hw_gpio_pin *ptr,
0069 const struct gpio_config_data *config_data)
0070 {
0071 struct hw_generic *generic = HW_GENERIC_FROM_BASE(ptr);
0072
0073 if (!config_data)
0074 return GPIO_RESULT_INVALID_DATA;
0075
0076 REG_UPDATE_2(mux,
0077 GENERIC_EN, config_data->config.generic_mux.enable_output_from_mux,
0078 GENERIC_SEL, config_data->config.generic_mux.mux_select);
0079
0080 return GPIO_RESULT_OK;
0081 }
0082
0083 static const struct hw_gpio_pin_funcs funcs = {
0084 .destroy = dal_hw_generic_destroy,
0085 .open = dal_hw_gpio_open,
0086 .get_value = dal_hw_gpio_get_value,
0087 .set_value = dal_hw_gpio_set_value,
0088 .set_config = set_config,
0089 .change_mode = dal_hw_gpio_change_mode,
0090 .close = dal_hw_gpio_close,
0091 };
0092
0093 static void dal_hw_generic_construct(
0094 struct hw_generic *pin,
0095 enum gpio_id id,
0096 uint32_t en,
0097 struct dc_context *ctx)
0098 {
0099 dal_hw_gpio_construct(&pin->base, id, en, ctx);
0100 pin->base.base.funcs = &funcs;
0101 }
0102
0103 void dal_hw_generic_init(
0104 struct hw_generic **hw_generic,
0105 struct dc_context *ctx,
0106 enum gpio_id id,
0107 uint32_t en)
0108 {
0109 if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
0110 ASSERT_CRITICAL(false);
0111 *hw_generic = NULL;
0112 }
0113
0114 *hw_generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL);
0115 if (!*hw_generic) {
0116 ASSERT_CRITICAL(false);
0117 return;
0118 }
0119
0120 dal_hw_generic_construct(*hw_generic, id, en, ctx);
0121 }
0122
0123
0124 struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio)
0125 {
0126 struct hw_generic *hw_generic = dal_gpio_get_generic(gpio);
0127
0128 return &hw_generic->base.base;
0129 }