Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ |
| 2 | /* |
| 3 | * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #ifndef __MESON_SARADC_H__ |
| 7 | #define __MESON_SARADC_H__ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <adc.h> |
| 11 | #include <clk.h> |
| 12 | |
| 13 | enum ADC_CHANNEL_TYPE { |
| 14 | MESON_SARADC_CH0 = 0, |
| 15 | MESON_SARADC_CH1, |
| 16 | MESON_SARADC_CH2, |
| 17 | MESON_SARADC_CH3, |
| 18 | MESON_SARADC_CH4, |
| 19 | MESON_SARADC_CH5, |
| 20 | MESON_SARADC_CH6, |
| 21 | MESON_SARADC_CH7, |
| 22 | MESON_SARADC_CH_MAX, |
| 23 | }; |
| 24 | |
| 25 | enum MESON_SARADC_AVG_MODE { |
| 26 | NO_AVERAGING = 0x0, |
| 27 | MEAN_AVERAGING = 0x1, |
| 28 | MEDIAN_AVERAGING = 0x2, |
| 29 | }; |
| 30 | |
| 31 | enum MESON_SARADC_NUM_SAMPLES { |
| 32 | ONE_SAMPLE = 0x0, |
| 33 | TWO_SAMPLES = 0x1, |
| 34 | FOUR_SAMPLES = 0x2, |
| 35 | EIGHT_SAMPLES = 0x3, |
| 36 | }; |
| 37 | |
| 38 | enum MESON_SARADC_RESOLUTION { |
| 39 | SARADC_10BIT = 10, |
Huqiang Qin | 5370433 | 2024-01-10 18:38:33 +0800 | [diff] [blame] | 40 | SARADC_11BIT = 11, |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 41 | SARADC_12BIT = 12, |
| 42 | SARADC_22BIT = 22, |
| 43 | }; |
| 44 | |
| 45 | enum MESON_SARADC_BIT_STATE { |
| 46 | BIT_LOW = 0, |
| 47 | BIT_HIGH = 1, |
| 48 | }; |
| 49 | |
| 50 | struct meson_saradc; |
| 51 | |
| 52 | struct meson_saradc_diff_ops { |
| 53 | void (*extra_init)(struct meson_saradc *priv); |
Huqiang Qin | 5370433 | 2024-01-10 18:38:33 +0800 | [diff] [blame] | 54 | void (*set_test_input_mux)(struct meson_saradc *priv, int ch, int mux); |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 55 | void (*enable_decim_filter)(struct meson_saradc *priv, |
| 56 | int ch, unsigned int mode); |
| 57 | void (*set_ref_voltage)(struct meson_saradc *priv, unsigned int mode, |
| 58 | int ch); |
| 59 | int (*get_fifo_channel)(int val); |
| 60 | int (*get_fifo_data)(struct meson_saradc *priv, |
Huqiang Qin | 7a5665f | 2023-02-23 13:39:10 +0800 | [diff] [blame] | 61 | struct adc_uclass_plat *uc_pdata, int val); |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * struct meson_saradc_data - describe the differences of different platform |
| 66 | * |
| 67 | * @reg3_ring_counter_disable: to disable continuous ring counter. |
| 68 | * gxl and later: 1; others(gxtvbb etc): 0 |
Huqiang Qin | a11c230 | 2023-08-03 13:17:55 +0800 | [diff] [blame] | 69 | * @reg11_bandgap_en_mask: txhd2/s1a: bit[12]; g12a: bit[13] |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 70 | * @reg11_vref_en: g12a and later: 0; others(axg etc): 1 |
Huqiang Qin | b3b003c | 2023-07-06 17:22:05 +0800 | [diff] [blame] | 71 | * @reg11_vcm_sel: g12a and later: 0; others(axg etc): 1 |
Huqiang Qin | a11c230 | 2023-08-03 13:17:55 +0800 | [diff] [blame] | 72 | * @reg11_eoc: g12a and later: 1; others(axg etc): 0; txhd2/s1a: 0 |
| 73 | * @reg13_calib_factor_mask: txhd2/s1a: bit[22:16]; g12a: bit[13:8] |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 74 | * @has_bl30_integration: |
| 75 | * @update_vref_conf: only for C2 & A5; C2: 0; A5: 1 |
| 76 | * @num_channels: the number of adc channels |
| 77 | * @self_test_channel: channel of self-test |
| 78 | * @resolution: gxl and later: 12bit; others(gxtvbb etc): 10bit |
| 79 | * @clock_rate: saradc clock rate |
Huqiang Qin | 5370433 | 2024-01-10 18:38:33 +0800 | [diff] [blame] | 80 | * @auto_calibration: software automatic calibration |
| 81 | * @out_resolution: output resolution after automatic calibration |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 82 | */ |
| 83 | struct meson_saradc_data { |
| 84 | bool reg3_ring_counter_disable; |
Huqiang Qin | a11c230 | 2023-08-03 13:17:55 +0800 | [diff] [blame] | 85 | unsigned int reg11_bandgap_en_mask; |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 86 | bool reg11_vref_en; |
Huqiang Qin | b3b003c | 2023-07-06 17:22:05 +0800 | [diff] [blame] | 87 | bool reg11_vcm_sel; |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 88 | bool reg11_eoc; |
Huqiang Qin | a11c230 | 2023-08-03 13:17:55 +0800 | [diff] [blame] | 89 | unsigned int reg13_calib_factor_mask; |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 90 | bool has_bl30_integration; |
| 91 | bool update_vref_conf; |
| 92 | unsigned char self_test_channel; |
| 93 | unsigned char num_channels; |
| 94 | unsigned int resolution; |
| 95 | const struct meson_saradc_diff_ops *dops; |
| 96 | unsigned int capacity; |
| 97 | unsigned long clock_rate; |
Huqiang Qin | 5370433 | 2024-01-10 18:38:33 +0800 | [diff] [blame] | 98 | bool auto_calibration; |
| 99 | unsigned int out_resolution; |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | struct meson_saradc { |
| 103 | phys_addr_t base; |
| 104 | int active_channel; |
| 105 | unsigned int current_mode; |
| 106 | struct clk xtal; |
| 107 | struct clk adc_mux; |
| 108 | struct clk adc_div; |
| 109 | struct clk adc_gate; |
| 110 | struct meson_saradc_data *data; |
Huqiang Qin | 5370433 | 2024-01-10 18:38:33 +0800 | [diff] [blame] | 111 | int calibration_param[2]; |
| 112 | bool param_valid; |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | extern const struct adc_ops meson_saradc_ops; |
| 116 | int meson_saradc_probe(struct udevice *dev); |
| 117 | int meson_saradc_remove(struct udevice *dev); |
Huqiang Qin | 7a5665f | 2023-02-23 13:39:10 +0800 | [diff] [blame] | 118 | int meson_saradc_of_to_plat(struct udevice *dev); |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 119 | |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 120 | #endif /*_MESON_SARADC_H_*/ |