drivers: gpio_sx1509b: add support for pin configuration on device init
IO extenders may provide input signals to LEDs or sensors where leaving the signal undriven may result in increased power consumption or misbehavior. The SX1509B powers up with all signals configured as inputs. Provide a way to indicate which pins should be set as output, and their initial signal level, when the device is configured. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
a49b364244
commit
7821104ee9
|
@ -409,12 +409,6 @@ static int sx1509b_init(struct device *dev)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* Reset state */
|
||||
drv_data->pin_state = (struct sx1509b_pin_state) {
|
||||
.dir = ALL_PINS,
|
||||
.data = ALL_PINS,
|
||||
};
|
||||
|
||||
rc = i2c_reg_write_byte(drv_data->i2c_master, cfg->i2c_slave_addr,
|
||||
SX1509B_REG_RESET, SX1509B_REG_RESET_MAGIC0);
|
||||
if (rc != 0) {
|
||||
|
@ -429,9 +423,30 @@ static int sx1509b_init(struct device *dev)
|
|||
|
||||
k_sleep(K_MSEC(RESET_DELAY_MS));
|
||||
|
||||
/* Reset state mediated by initial configuration */
|
||||
drv_data->pin_state = (struct sx1509b_pin_state) {
|
||||
.dir = (ALL_PINS
|
||||
& ~(DT_INST_0_SEMTECH_SX1509B_INIT_OUT_LOW
|
||||
| DT_INST_0_SEMTECH_SX1509B_INIT_OUT_HIGH)),
|
||||
.data = (ALL_PINS
|
||||
& ~DT_INST_0_SEMTECH_SX1509B_INIT_OUT_LOW),
|
||||
};
|
||||
|
||||
rc = i2c_reg_write_byte(drv_data->i2c_master, cfg->i2c_slave_addr,
|
||||
SX1509B_REG_CLOCK,
|
||||
SX1509B_REG_CLOCK_FOSC_INT_2MHZ);
|
||||
if (rc == 0) {
|
||||
rc = i2c_reg_write_word_be(drv_data->i2c_master,
|
||||
cfg->i2c_slave_addr,
|
||||
SX1509B_REG_DATA,
|
||||
drv_data->pin_state.data);
|
||||
}
|
||||
if (rc == 0) {
|
||||
rc = i2c_reg_write_word_be(drv_data->i2c_master,
|
||||
cfg->i2c_slave_addr,
|
||||
SX1509B_REG_DIR,
|
||||
drv_data->pin_state.dir);
|
||||
}
|
||||
if (rc != 0) {
|
||||
goto out;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,22 @@ properties:
|
|||
required: true
|
||||
const: 16
|
||||
|
||||
init-out-low:
|
||||
type: int
|
||||
required: false
|
||||
default: 0
|
||||
description: |
|
||||
Bit mask identifying pins that should be initialized as outputs
|
||||
driven low.
|
||||
|
||||
init-out-high:
|
||||
type: int
|
||||
required: false
|
||||
default: 0
|
||||
description: |
|
||||
Bit mask identifying pins that should be initialized as outputs
|
||||
driven high.
|
||||
|
||||
gpio-cells:
|
||||
- pin
|
||||
- flags
|
||||
|
|
|
@ -148,6 +148,8 @@
|
|||
#define DT_INST_0_SEMTECH_SX1509B_LABEL ""
|
||||
#define DT_INST_0_SEMTECH_SX1509B_BASE_ADDRESS 0
|
||||
#define DT_INST_0_SEMTECH_SX1509B_BUS_NAME ""
|
||||
#define DT_INST_0_SEMTECH_SX1509B_INIT_OUT_LOW 0
|
||||
#define DT_INST_0_SEMTECH_SX1509B_INIT_OUT_HIGH 0
|
||||
#endif
|
||||
|
||||
#ifndef DT_INST_0_ST_LSM6DSL_LABEL
|
||||
|
|
Loading…
Reference in a new issue