npcm7xx_adc.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Nuvoton NPCM7xx ADC Module
  3. *
  4. * Copyright 2020 Google LLC
  5. *
  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.
  10. *
  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.
  15. */
  16. #ifndef NPCM7XX_ADC_H
  17. #define NPCM7XX_ADC_H
  18. #include "hw/clock.h"
  19. #include "hw/irq.h"
  20. #include "hw/sysbus.h"
  21. #include "qemu/timer.h"
  22. #define NPCM7XX_ADC_NUM_INPUTS 8
  23. /**
  24. * This value should not be changed unless write_adc_calibration function in
  25. * hw/arm/npcm7xx.c is also changed.
  26. */
  27. #define NPCM7XX_ADC_NUM_CALIB 2
  28. /**
  29. * struct NPCM7xxADCState - Analog to Digital Converter Module device state.
  30. * @parent: System bus device.
  31. * @iomem: Memory region through which registers are accessed.
  32. * @conv_timer: The timer counts down remaining cycles for the conversion.
  33. * @irq: GIC interrupt line to fire on expiration (if enabled).
  34. * @con: The Control Register.
  35. * @data: The Data Buffer.
  36. * @clock: The ADC Clock.
  37. * @adci: The input voltage in units of uV. 1uv = 1e-6V.
  38. * @vref: The external reference voltage.
  39. * @iref: The internal reference voltage, initialized at launch time.
  40. * @rv: The calibrated output values of 0.5V and 1.5V for the ADC.
  41. */
  42. struct NPCM7xxADCState {
  43. SysBusDevice parent;
  44. MemoryRegion iomem;
  45. QEMUTimer conv_timer;
  46. qemu_irq irq;
  47. uint32_t con;
  48. uint32_t data;
  49. Clock *clock;
  50. /* Voltages are in unit of uV. 1V = 1000000uV. */
  51. uint32_t adci[NPCM7XX_ADC_NUM_INPUTS];
  52. uint32_t vref;
  53. uint32_t iref;
  54. uint16_t calibration_r_values[NPCM7XX_ADC_NUM_CALIB];
  55. };
  56. #define TYPE_NPCM7XX_ADC "npcm7xx-adc"
  57. OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxADCState, NPCM7XX_ADC)
  58. #endif /* NPCM7XX_ADC_H */