coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
saradc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <assert.h>
5 #include <delay.h>
6 #include <soc/clock.h>
7 #include <soc/saradc.h>
8 #include <stdint.h>
9 #include <timer.h>
10 
16 };
17 check_member(rk3399_saradc_regs, dly_pu_soc, 0xc);
18 
20 
21 /* SARADC_STAS: conversion done */
22 #define ADC_STOP 0
23 
24 /* SARADC_CTRL */
25 #define INT_EN (1 << 5)
26 #define ADC_PWR_CTRL (1 << 3)
27 #define ADC_CHN_SEL_MASK 7
28 #define ADC_CHN_SEL_SHIFT 0
29 
30 /* SARADC_DATA, 10[0:9] bits */
31 #define DATA_MASK 0x3FF
32 
33 #define SARADC_HZ (4*MHz)
34 
35 #define SARADC_MAX_CHANNEL 6
36 
37 #define SARADC_DELAY_PU (1 * 1000 * 1000 * 1000 / SARADC_HZ * 4)
38 
40 {
41  u32 adc_value;
42  struct stopwatch sw;
43 
46 
47  /* power down adc converter */
49 
50  /* select channel */
53  chn << ADC_CHN_SEL_SHIFT);
54 
55  /* power up */
57 
59 
61  do {
62  if (read32(&rk3399_saradc->stas) == ADC_STOP) {
63  adc_value = read32(&rk3399_saradc->data) & DATA_MASK;
64  return adc_value;
65  }
66  } while (!stopwatch_expired(&sw));
67 
68  return -1;
69 }
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define assert(statement)
Definition: assert.h:74
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
#define clrbits32(addr, clear)
Definition: mmio.h:26
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
Definition: timer.h:133
check_member(rk3399_saradc_regs, dly_pu_soc, 0xc)
#define ADC_STOP
Definition: saradc.c:22
#define ADC_PWR_CTRL
Definition: saradc.c:26
#define ADC_CHN_SEL_SHIFT
Definition: saradc.c:28
#define SARADC_DELAY_PU
Definition: saradc.c:37
#define SARADC_MAX_CHANNEL
Definition: saradc.c:35
#define DATA_MASK
Definition: saradc.c:31
#define ADC_CHN_SEL_MASK
Definition: saradc.c:27
#define SARADC_HZ
Definition: saradc.c:33
u32 get_saradc_value(u32 chn)
Definition: saradc.c:39
struct rk3399_saradc_regs * rk3399_saradc
Definition: saradc.c:19
#define SARADC_BASE
Definition: addressmap.h:11
void rkclk_configure_saradc(unsigned int hz)
Definition: clock.c:823
uint32_t u32
Definition: stdint.h:51
void udelay(uint32_t us)
Definition: udelay.c:15