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 #ifndef __DAL_HW_GPIO_H__
0027 #define __DAL_HW_GPIO_H__
0028
0029 #include "gpio_regs.h"
0030
0031 #define FROM_HW_GPIO_PIN(ptr) \
0032 container_of((ptr), struct hw_gpio, base)
0033
0034 struct addr_mask {
0035 uint32_t addr;
0036 uint32_t mask;
0037 };
0038
0039 struct hw_gpio_pin {
0040 const struct hw_gpio_pin_funcs *funcs;
0041 enum gpio_id id;
0042 uint32_t en;
0043 enum gpio_mode mode;
0044 bool opened;
0045 struct dc_context *ctx;
0046 };
0047
0048 struct hw_gpio_pin_funcs {
0049 void (*destroy)(
0050 struct hw_gpio_pin **ptr);
0051 bool (*open)(
0052 struct hw_gpio_pin *pin,
0053 enum gpio_mode mode);
0054 enum gpio_result (*get_value)(
0055 const struct hw_gpio_pin *pin,
0056 uint32_t *value);
0057 enum gpio_result (*set_value)(
0058 const struct hw_gpio_pin *pin,
0059 uint32_t value);
0060 enum gpio_result (*set_config)(
0061 struct hw_gpio_pin *pin,
0062 const struct gpio_config_data *config_data);
0063 enum gpio_result (*change_mode)(
0064 struct hw_gpio_pin *pin,
0065 enum gpio_mode mode);
0066 void (*close)(
0067 struct hw_gpio_pin *pin);
0068 };
0069
0070
0071 struct hw_gpio;
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 struct hw_gpio_pin_reg {
0082 struct addr_mask DC_GPIO_DATA_MASK;
0083 struct addr_mask DC_GPIO_DATA_A;
0084 struct addr_mask DC_GPIO_DATA_EN;
0085 struct addr_mask DC_GPIO_DATA_Y;
0086 };
0087
0088 struct hw_gpio_mux_reg {
0089 struct addr_mask GPIO_MUX_CONTROL;
0090 struct addr_mask GPIO_MUX_STEREO_SEL;
0091 };
0092
0093 struct hw_gpio {
0094 struct hw_gpio_pin base;
0095
0096
0097 struct {
0098 uint32_t mask;
0099 uint32_t a;
0100 uint32_t en;
0101 uint32_t mux;
0102 } store;
0103
0104
0105 bool mux_supported;
0106 const struct gpio_registers *regs;
0107 };
0108
0109 #define HW_GPIO_FROM_BASE(hw_gpio_pin) \
0110 container_of((hw_gpio_pin), struct hw_gpio, base)
0111
0112 void dal_hw_gpio_construct(
0113 struct hw_gpio *pin,
0114 enum gpio_id id,
0115 uint32_t en,
0116 struct dc_context *ctx);
0117
0118 bool dal_hw_gpio_open(
0119 struct hw_gpio_pin *pin,
0120 enum gpio_mode mode);
0121
0122 enum gpio_result dal_hw_gpio_get_value(
0123 const struct hw_gpio_pin *pin,
0124 uint32_t *value);
0125
0126 enum gpio_result dal_hw_gpio_config_mode(
0127 struct hw_gpio *pin,
0128 enum gpio_mode mode);
0129
0130 void dal_hw_gpio_destruct(
0131 struct hw_gpio *pin);
0132
0133 enum gpio_result dal_hw_gpio_set_value(
0134 const struct hw_gpio_pin *ptr,
0135 uint32_t value);
0136
0137 enum gpio_result dal_hw_gpio_change_mode(
0138 struct hw_gpio_pin *ptr,
0139 enum gpio_mode mode);
0140
0141 void dal_hw_gpio_close(
0142 struct hw_gpio_pin *ptr);
0143
0144 #endif