Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20210330' into...
[qemu/ar7.git] / include / hw / adc / npcm7xx_adc.h
blob7d8442107aed78e76f73befa172801af8ccc6373
1 /*
2 * Nuvoton NPCM7xx ADC Module
4 * Copyright 2020 Google LLC
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 #ifndef NPCM7XX_ADC_H
17 #define NPCM7XX_ADC_H
19 #include "hw/clock.h"
20 #include "hw/irq.h"
21 #include "hw/sysbus.h"
22 #include "qemu/timer.h"
24 #define NPCM7XX_ADC_NUM_INPUTS 8
25 /**
26 * This value should not be changed unless write_adc_calibration function in
27 * hw/arm/npcm7xx.c is also changed.
29 #define NPCM7XX_ADC_NUM_CALIB 2
31 /**
32 * struct NPCM7xxADCState - Analog to Digital Converter Module device state.
33 * @parent: System bus device.
34 * @iomem: Memory region through which registers are accessed.
35 * @conv_timer: The timer counts down remaining cycles for the conversion.
36 * @irq: GIC interrupt line to fire on expiration (if enabled).
37 * @con: The Control Register.
38 * @data: The Data Buffer.
39 * @clock: The ADC Clock.
40 * @adci: The input voltage in units of uV. 1uv = 1e-6V.
41 * @vref: The external reference voltage.
42 * @iref: The internal reference voltage, initialized at launch time.
43 * @rv: The calibrated output values of 0.5V and 1.5V for the ADC.
45 typedef struct {
46 SysBusDevice parent;
48 MemoryRegion iomem;
50 QEMUTimer conv_timer;
52 qemu_irq irq;
53 uint32_t con;
54 uint32_t data;
55 Clock *clock;
57 /* Voltages are in unit of uV. 1V = 1000000uV. */
58 uint32_t adci[NPCM7XX_ADC_NUM_INPUTS];
59 uint32_t vref;
60 uint32_t iref;
62 uint16_t calibration_r_values[NPCM7XX_ADC_NUM_CALIB];
63 } NPCM7xxADCState;
65 #define TYPE_NPCM7XX_ADC "npcm7xx-adc"
66 #define NPCM7XX_ADC(obj) \
67 OBJECT_CHECK(NPCM7xxADCState, (obj), TYPE_NPCM7XX_ADC)
69 #endif /* NPCM7XX_ADC_H */