Skip to content

Commit 371ca13

Browse files
jjdalynhkartben
authored andcommitted
drivers: adc: microchip: Different channels per package type
LJ packages have 16 ADC channels vs 8 for SZ packages. Enhance devicetree to account for this as well as conditional defines/code. Signed-off-by: Jeff Daly <[email protected]>
1 parent 662d9c7 commit 371ca13

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

drivers/adc/adc_mchp_xec.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ enum adc_pm_policy_state_flag {
4747
ADC_PM_POLICY_STATE_FLAG_COUNT,
4848
};
4949

50+
#define XEC_ADC_CFG_CHANNELS DT_INST_PROP(0, channels)
5051

5152
struct adc_xec_regs {
5253
uint32_t control_reg;
5354
uint32_t delay_reg;
5455
uint32_t status_reg;
5556
uint32_t single_reg;
5657
uint32_t repeat_reg;
57-
uint32_t channel_read_reg[8];
58-
uint32_t unused[18];
58+
uint32_t channel_read_reg[XEC_ADC_CFG_CHANNELS];
59+
uint32_t unused[10 + (MCHP_ADC_MAX_CHAN - XEC_ADC_CFG_CHANNELS)];
5960
uint32_t config_reg;
6061
uint32_t vref_channel_reg;
6162
uint32_t vref_control_reg;
@@ -139,7 +140,7 @@ static int adc_xec_channel_setup(const struct device *dev,
139140
return -EINVAL;
140141
}
141142

142-
if (channel_cfg->channel_id >= MCHP_ADC_MAX_CHAN) {
143+
if (channel_cfg->channel_id >= XEC_ADC_CFG_CHANNELS) {
143144
return -EINVAL;
144145
}
145146

@@ -205,7 +206,7 @@ static int adc_xec_start_read(const struct device *dev,
205206
struct adc_xec_data * const data = dev->data;
206207
uint32_t sar_ctrl;
207208

208-
if (sequence->channels & ~BIT_MASK(MCHP_ADC_MAX_CHAN)) {
209+
if (sequence->channels & ~BIT_MASK(XEC_ADC_CFG_CHANNELS)) {
209210
LOG_ERR("Incorrect channels, bitmask 0x%x", sequence->channels);
210211
return -EINVAL;
211212
}

dts/arm/microchip/mec1501hsz.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
status = "disabled";
443443
#io-channel-cells = <1>;
444444
clktime = <32>;
445+
channels = <8>;
445446
};
446447
kbd0: kbd@40009c00 {
447448
compatible = "microchip,xec-kbd";

dts/arm/microchip/mec172x_common.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ adc0: adc@40007c00 {
650650
status = "disabled";
651651
#io-channel-cells = <1>;
652652
clktime = <32>;
653+
channels = <16>;
653654
};
654655
kbd0: kbd@40009c00 {
655656
compatible = "microchip,xec-kbd";

dts/arm/microchip/mec172xnsz.dtsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@
7575
&systick {
7676
status = "disabled";
7777
};
78+
79+
&adc0 {
80+
channels = <8>;
81+
};

dts/bindings/adc/microchip,xec-adc.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ properties:
3333
required: true
3434
description: ADC clock high & low time count value <1:255>
3535

36+
channels:
37+
type: int
38+
required: true
39+
description: Number of ADC channels supported by SoC
40+
3641
pinctrl-0:
3742
required: true
3843

soc/microchip/mec/common/reg/mec_adc.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
#include <stdint.h>
1111
#include <stddef.h>
1212

13+
#if defined(CONFIG_SOC_MEC172X_NLJ)
14+
/* 16 ADC channels numbered 0 - 15 */
15+
#define MCHP_ADC_MAX_CHAN 16u
16+
#define MCHP_ADC_MAX_CHAN_MASK 0x0fu
17+
#else
1318
/* Eight ADC channels numbered 0 - 7 */
1419
#define MCHP_ADC_MAX_CHAN 8u
1520
#define MCHP_ADC_MAX_CHAN_MASK 0x07u
21+
#endif
1622

1723
/* Control register */
1824
#define MCHP_ADC_CTRL_REG_OFS 0u
@@ -42,15 +48,27 @@
4248

4349
/* Single Conversion Select register */
4450
#define MCHP_ADC_SCS_REG_OFS 0x0cu
51+
#if defined(CONFIG_SOC_MEC172X_NLJ)
52+
#define MCHP_ADC_SCS_REG_MASK 0xffffu
53+
#define MCHP_ADC_SCS_CH_0_15 0xffffu
54+
#define MCHP_ADC_SCS_CH(n) BIT(((n) & 0x0fu))
55+
#else
4556
#define MCHP_ADC_SCS_REG_MASK 0xffu
4657
#define MCHP_ADC_SCS_CH_0_7 0xffu
4758
#define MCHP_ADC_SCS_CH(n) BIT(((n) & 0x07u))
59+
#endif
4860

4961
/* Repeat Conversion Select register */
5062
#define MCHP_ADC_RCS_REG_OFS 0x10u
63+
#if defined(CONFIG_SOC_MEC172X_NLJ)
64+
#define MCHP_ADC_RCS_REG_MASK 0xffffu
65+
#define MCHP_ADC_RCS_CH_0_15 0xffffu
66+
#define MCHP_ADC_RCS_CH(n) BIT(((n) & 0x0fu))
67+
#else
5168
#define MCHP_ADC_RCS_REG_MASK 0xffu
5269
#define MCHP_ADC_RCS_CH_0_7 0xffu
5370
#define MCHP_ADC_RCS_CH(n) BIT(((n) & 0x07u))
71+
#endif
5472

5573
/* Channel reading registers */
5674
#define MCHP_ADC_RDCH_REG_MASK 0xfffu
@@ -62,6 +80,14 @@
6280
#define MCHP_ADC_RDCH5_REG_OFS 0x28u
6381
#define MCHP_ADC_RDCH6_REG_OFS 0x2cu
6482
#define MCHP_ADC_RDCH7_REG_OFS 0x30u
83+
#define MCHP_ADC_RDCH8_REG_OFS 0x34u
84+
#define MCHP_ADC_RDCH9_REG_OFS 0x38u
85+
#define MCHP_ADC_RDCH10_REG_OFS 0x3cu
86+
#define MCHP_ADC_RDCH11_REG_OFS 0x40u
87+
#define MCHP_ADC_RDCH12_REG_OFS 0x44u
88+
#define MCHP_ADC_RDCH13_REG_OFS 0x48u
89+
#define MCHP_ADC_RDCH14_REG_OFS 0x4cu
90+
#define MCHP_ADC_RDCH15_REG_OFS 0x50u
6591

6692
/* Configuration register */
6793
#define MCHP_ADC_CFG_REG_OFS 0x7cu
@@ -76,9 +102,15 @@
76102
/* Channel Vref Select register */
77103
#define MCHP_ADC_CH_VREF_SEL_REG_OFS 0x80u
78104
#define MCHP_ADC_CH_VREF_SEL_REG_MASK 0x00ffffffu
105+
#if defined(CONFIG_SOC_MEC172X_NLJ)
106+
#define MCHP_ADC_CH_VREF_SEL_MASK(n) SHLU32(0x03u, (((n) & 0x0f) * 2u))
107+
#define MCHP_ADC_CH_VREF_SEL_PAD(n) 0u
108+
#define MCHP_ADC_CH_VREF_SEL_GPIO(n) SHLU32(0x01u, (((n) & 0x0f) * 2u))
109+
#else
79110
#define MCHP_ADC_CH_VREF_SEL_MASK(n) SHLU32(0x03u, (((n) & 0x07) * 2u))
80111
#define MCHP_ADC_CH_VREF_SEL_PAD(n) 0u
81112
#define MCHP_ADC_CH_VREF_SEL_GPIO(n) SHLU32(0x01u, (((n) & 0x07) * 2u))
113+
#endif
82114

83115
/* Vref Control register */
84116
#define MCHP_ADC_VREF_CTRL_REG_OFS 0x84u
@@ -131,8 +163,8 @@ struct adc_regs {
131163
volatile uint32_t STATUS;
132164
volatile uint32_t SINGLE;
133165
volatile uint32_t REPEAT;
134-
volatile uint32_t RD[8];
135-
uint8_t RSVD1[0x7c - 0x34];
166+
volatile uint32_t RD[MCHP_ADC_MAX_CHAN];
167+
uint8_t RSVD1[0x7c - ((MCHP_ADC_MAX_CHAN * 4) + 0x14)];
136168
volatile uint32_t CONFIG;
137169
volatile uint32_t VREF_CHAN_SEL;
138170
volatile uint32_t VREF_CTRL;

0 commit comments

Comments
 (0)