Skip to content

Commit acbc14e

Browse files
benediktibknashif
authored andcommitted
drivers: gpio: implement parallel mode in TLE9104
Implement the parallel mode in the powertrain switch TLE9104. This allows that OUT1 and OUT2 are controlled together, as well as OUT3 and OUT4. Signed-off-by: Benedikt Schmidt <[email protected]>
1 parent fb86c45 commit acbc14e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

doc/releases/release-notes-4.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ Drivers and Sensors
212212

213213
* GPIO
214214

215+
* tle9104: Add support for the parallel output mode via setting the properties ``parallel-out12`` and
216+
``parallel-out34``.
217+
215218
* Hardware info
216219

217220
* I2C

drivers/gpio/gpio_tle9104.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct tle9104_gpio_config {
2222
struct gpio_driver_config common;
2323
/* parent MFD */
2424
const struct device *parent;
25+
bool parallel_mode_out12;
26+
bool parallel_mode_out34;
2527
};
2628

2729
struct tle9104_gpio_data {
@@ -80,6 +82,16 @@ static int tle9104_gpio_pin_configure(const struct device *dev, gpio_pin_t pin,
8082
return -ENOTSUP;
8183
}
8284

85+
if (config->parallel_mode_out12 && pin == 1) {
86+
LOG_ERR("cannot configure OUT2 if parallel mode is enabled for OUT1 and OUT2");
87+
return -EINVAL;
88+
}
89+
90+
if (config->parallel_mode_out34 && pin == 3) {
91+
LOG_ERR("cannot configure OUT4 if parallel mode is enabled for OUT3 and OUT4");
92+
return -EINVAL;
93+
}
94+
8395
k_mutex_lock(&data->lock, K_FOREVER);
8496

8597
if ((flags & GPIO_OUTPUT_INIT_LOW) != 0) {
@@ -110,6 +122,16 @@ static int tle9104_gpio_port_set_masked_raw(const struct device *dev, uint32_t m
110122
struct tle9104_gpio_data *data = dev->data;
111123
int result;
112124

125+
if (config->parallel_mode_out12 && (BIT(1) & mask) != 0) {
126+
LOG_ERR("cannot set OUT2 if parallel mode is enabled for OUT1 and OUT2");
127+
return -EINVAL;
128+
}
129+
130+
if (config->parallel_mode_out34 && (BIT(3) & mask) != 0) {
131+
LOG_ERR("cannot set OUT4 if parallel mode is enabled for OUT3 and OUT4");
132+
return -EINVAL;
133+
}
134+
113135
/* cannot execute a bus operation in an ISR context */
114136
if (k_is_in_isr()) {
115137
return -EWOULDBLOCK;
@@ -139,6 +161,16 @@ static int tle9104_gpio_port_toggle_bits(const struct device *dev, uint32_t mask
139161
struct tle9104_gpio_data *data = dev->data;
140162
int result;
141163

164+
if (config->parallel_mode_out12 && (BIT(1) & mask) != 0) {
165+
LOG_ERR("cannot toggle OUT2 if parallel mode is enabled for OUT1 and OUT2");
166+
return -EINVAL;
167+
}
168+
169+
if (config->parallel_mode_out34 && (BIT(3) & mask) != 0) {
170+
LOG_ERR("cannot toggle OUT4 if parallel mode is enabled for OUT3 and OUT4");
171+
return -EINVAL;
172+
}
173+
142174
/* cannot execute a bus operation in an ISR context */
143175
if (k_is_in_isr()) {
144176
return -EWOULDBLOCK;
@@ -176,6 +208,7 @@ static int tle9104_gpio_init(const struct device *dev)
176208
{
177209
const struct tle9104_gpio_config *config = dev->config;
178210
struct tle9104_gpio_data *data = dev->data;
211+
int result;
179212

180213
LOG_DBG("initialize TLE9104 GPIO instance %s", dev->name);
181214

@@ -184,7 +217,7 @@ static int tle9104_gpio_init(const struct device *dev)
184217
return -EINVAL;
185218
}
186219

187-
int result = k_mutex_init(&data->lock);
220+
result = k_mutex_init(&data->lock);
188221
if (result != 0) {
189222
LOG_ERR("unable to initialize mutex");
190223
return result;
@@ -199,6 +232,8 @@ static int tle9104_gpio_init(const struct device *dev)
199232
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \
200233
}, \
201234
.parent = DEVICE_DT_GET(DT_PARENT(DT_DRV_INST(inst))), \
235+
.parallel_mode_out12 = DT_PROP(DT_PARENT(DT_DRV_INST(inst)), parallel_out12), \
236+
.parallel_mode_out34 = DT_PROP(DT_PARENT(DT_DRV_INST(inst)), parallel_out34), \
202237
}; \
203238
\
204239
static struct tle9104_gpio_data tle9104_gpio_##inst##_drvdata; \

drivers/mfd/mfd_tle9104.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#define TLE9104_CFG_CWDTIME_LENGTH 2
3838
#define TLE9104_CFG_CWDTIME_POS 6
39+
#define TLE9104_CFG_OUT34PAR_POS 5
40+
#define TLE9104_CFG_OUT12PAR_POS 4
3941

4042
#define TLE9104_OFFDIAGCFG_DIAGFILTCFG_LENGTH 2
4143
#define TLE9104_OFFDIAGCFG_DIAGFILTCFG_POS 4
@@ -101,6 +103,8 @@ struct tle9104_config {
101103
uint16_t diagnostic_filter_time;
102104
uint16_t overcurrent_shutdown_delay_time;
103105
uint16_t overcurrent_shutdown_threshold;
106+
bool parallel_mode_out12;
107+
bool parallel_mode_out34;
104108
};
105109

106110
struct tle9104_data {
@@ -527,6 +531,16 @@ static int tle9104_init(const struct device *dev)
527531
tle9104_set_register_bits(&register_cfg, TLE9104_CFG_CWDTIME_POS,
528532
TLE9104_CFG_CWDTIME_LENGTH, 0);
529533

534+
if (config->parallel_mode_out12) {
535+
LOG_DBG("use parallel mode for OUT1 and OUT2");
536+
register_cfg |= BIT(TLE9104_CFG_OUT12PAR_POS);
537+
}
538+
539+
if (config->parallel_mode_out34) {
540+
LOG_DBG("use parallel mode for OUT3 and OUT4");
541+
register_cfg |= BIT(TLE9104_CFG_OUT34PAR_POS);
542+
}
543+
530544
result = tle9104_write_register(dev, TLE9104REGISTER_CFG, register_cfg);
531545
if (result != 0) {
532546
LOG_ERR("unable to write configuration");
@@ -598,6 +612,8 @@ static int tle9104_init(const struct device *dev)
598612
DT_INST_ENUM_IDX(inst, overcurrent_shutdown_delay_time), \
599613
.overcurrent_shutdown_threshold = \
600614
DT_INST_ENUM_IDX(inst, overcurrent_shutdown_threshold), \
615+
.parallel_mode_out12 = DT_INST_PROP(inst, parallel_out12), \
616+
.parallel_mode_out34 = DT_INST_PROP(inst, parallel_out34), \
601617
}; \
602618
\
603619
static struct tle9104_data tle9104_##inst##_data; \

dts/bindings/mfd/infineon,tle9104.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,11 @@ properties:
7676
description:
7777
overcurrent shutdown threshold in mA,
7878
default matches power on reset value
79+
80+
parallel-out12:
81+
type: boolean
82+
description: Enables parallel mode for OUT1 and OUT2
83+
84+
parallel-out34:
85+
type: boolean
86+
description: Enables parallel mode for OUT3 and OUT4

0 commit comments

Comments
 (0)