blob: 21a91f048974347dd58d39b9d235c543d0756489 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* 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
13enum 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
25enum MESON_SARADC_AVG_MODE {
26 NO_AVERAGING = 0x0,
27 MEAN_AVERAGING = 0x1,
28 MEDIAN_AVERAGING = 0x2,
29};
30
31enum MESON_SARADC_NUM_SAMPLES {
32 ONE_SAMPLE = 0x0,
33 TWO_SAMPLES = 0x1,
34 FOUR_SAMPLES = 0x2,
35 EIGHT_SAMPLES = 0x3,
36};
37
38enum MESON_SARADC_RESOLUTION {
39 SARADC_10BIT = 10,
Huqiang Qin53704332024-01-10 18:38:33 +080040 SARADC_11BIT = 11,
Bo Lv72d0e902023-01-02 14:27:34 +000041 SARADC_12BIT = 12,
42 SARADC_22BIT = 22,
43};
44
45enum MESON_SARADC_BIT_STATE {
46 BIT_LOW = 0,
47 BIT_HIGH = 1,
48};
49
50struct meson_saradc;
51
52struct meson_saradc_diff_ops {
53 void (*extra_init)(struct meson_saradc *priv);
Huqiang Qin53704332024-01-10 18:38:33 +080054 void (*set_test_input_mux)(struct meson_saradc *priv, int ch, int mux);
Bo Lv72d0e902023-01-02 14:27:34 +000055 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 Qin7a5665f2023-02-23 13:39:10 +080061 struct adc_uclass_plat *uc_pdata, int val);
Bo Lv72d0e902023-01-02 14:27:34 +000062};
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 Qina11c2302023-08-03 13:17:55 +080069 * @reg11_bandgap_en_mask: txhd2/s1a: bit[12]; g12a: bit[13]
Bo Lv72d0e902023-01-02 14:27:34 +000070 * @reg11_vref_en: g12a and later: 0; others(axg etc): 1
Huqiang Qinb3b003c2023-07-06 17:22:05 +080071 * @reg11_vcm_sel: g12a and later: 0; others(axg etc): 1
Huqiang Qina11c2302023-08-03 13:17:55 +080072 * @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 Lv72d0e902023-01-02 14:27:34 +000074 * @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 Qin53704332024-01-10 18:38:33 +080080 * @auto_calibration: software automatic calibration
81 * @out_resolution: output resolution after automatic calibration
Bo Lv72d0e902023-01-02 14:27:34 +000082 */
83struct meson_saradc_data {
84 bool reg3_ring_counter_disable;
Huqiang Qina11c2302023-08-03 13:17:55 +080085 unsigned int reg11_bandgap_en_mask;
Bo Lv72d0e902023-01-02 14:27:34 +000086 bool reg11_vref_en;
Huqiang Qinb3b003c2023-07-06 17:22:05 +080087 bool reg11_vcm_sel;
Bo Lv72d0e902023-01-02 14:27:34 +000088 bool reg11_eoc;
Huqiang Qina11c2302023-08-03 13:17:55 +080089 unsigned int reg13_calib_factor_mask;
Bo Lv72d0e902023-01-02 14:27:34 +000090 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 Qin53704332024-01-10 18:38:33 +080098 bool auto_calibration;
99 unsigned int out_resolution;
Bo Lv72d0e902023-01-02 14:27:34 +0000100};
101
102struct 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 Qin53704332024-01-10 18:38:33 +0800111 int calibration_param[2];
112 bool param_valid;
Bo Lv72d0e902023-01-02 14:27:34 +0000113};
114
115extern const struct adc_ops meson_saradc_ops;
116int meson_saradc_probe(struct udevice *dev);
117int meson_saradc_remove(struct udevice *dev);
Huqiang Qin7a5665f2023-02-23 13:39:10 +0800118int meson_saradc_of_to_plat(struct udevice *dev);
Bo Lv72d0e902023-01-02 14:27:34 +0000119
Bo Lv72d0e902023-01-02 14:27:34 +0000120#endif /*_MESON_SARADC_H_*/