Skip to content

Commit e636fb2

Browse files
XenuIsWatchingdanieldegrasse
authored andcommitted
drivers: sensor: bmm350: add pad ctrl and int ctrl dts config
Add configurations for setting the pad drive strength and the interrupt active high/low and od/pp. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
1 parent d2fdf52 commit e636fb2

File tree

4 files changed

+74
-18
lines changed

4 files changed

+74
-18
lines changed

drivers/sensor/bosch/bmm350/bmm350.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ static DEVICE_API(sensor, bmm350_api_funcs) = {
945945

946946
static int bmm350_init_chip(const struct device *dev)
947947
{
948+
const struct bmm350_config *config = dev->config;
948949
struct bmm350_pmu_cmd_status_0 pmu_cmd_stat_0 = {0};
949950
/* Variable to store soft-reset command */
950951
uint8_t soft_reset;
@@ -975,6 +976,14 @@ static int bmm350_init_chip(const struct device *dev)
975976
LOG_ERR("invalid chip id 0x%x", chip_id[2]);
976977
goto err_poweroff;
977978
}
979+
980+
/* Set pad drive strength */
981+
ret = bmm350_reg_write(dev, BMM350_REG_PAD_CTRL, config->drive_strength);
982+
if (ret < 0) {
983+
LOG_ERR("%s: failed to set pad drive strength", dev->name);
984+
return ret;
985+
}
986+
978987
ret = bmm350_otp_dump_after_boot(dev);
979988
LOG_DBG("bmm350 chip_id 0x%x otp dump after boot %d\n", chip_id[2], ret);
980989

@@ -1071,7 +1080,13 @@ static int bmm350_init(const struct device *dev)
10711080

10721081
/* Initializes a struct bmm350_config for an instance on an I2C bus. */
10731082
#define BMM350_CONFIG_I2C(inst) .bus.i2c = I2C_DT_SPEC_INST_GET(inst), .bus_io = &bmm350_bus_io_i2c,
1074-
#define BMM350_INT_CFG(inst) .drdy_int = GPIO_DT_SPEC_INST_GET_OR(inst, drdy_gpios, {0}),
1083+
#define BMM350_INT_CFG(inst) \
1084+
.drdy_int = GPIO_DT_SPEC_INST_GET_OR(inst, drdy_gpios, {0}), \
1085+
.int_flags = FIELD_PREP(BMM350_INT_CTRL_INT_POL_MSK, \
1086+
DT_INST_PROP(inst, active_high_int)) | \
1087+
FIELD_PREP(BMM350_INT_CTRL_INT_OD_MSK, DT_INST_PROP(inst, push_pull_int)) | \
1088+
BMM350_INT_CTRL_DRDY_DATA_REG_EN_MSK | \
1089+
BMM350_INT_CTRL_INT_OUTPUT_EN_MSK,
10751090

10761091
#define BMM350_DEFINE(inst) \
10771092
static struct bmm350_data bmm350_data_##inst; \
@@ -1080,7 +1095,8 @@ static int bmm350_init(const struct device *dev)
10801095
.bus_io = &bmm350_bus_io_i2c, \
10811096
.default_odr = DT_INST_ENUM_IDX(inst, odr) + BMM350_DATA_RATE_400HZ, \
10821097
.default_osr = DT_INST_PROP(inst, osr), \
1083-
BMM350_INT_CFG(inst)}; \
1098+
.drive_strength = DT_INST_PROP(inst, drive_strength), \
1099+
IF_ENABLED(CONFIG_BMM350_TRIGGER, (BMM350_INT_CFG(inst)))}; \
10841100
\
10851101
PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \
10861102
\

drivers/sensor/bosch/bmm350/bmm350.h

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,30 @@ enum bmm350_signed_bit {
183183
#define BMM350_PMU_CMD_STATUS_0_BR_FAST UINT8_C(0x07)
184184

185185
/*********************** Macros for bit masking ***************************/
186-
#define BMM350_AVG_MSK (0x30)
187-
#define BMM350_AVG_POS UINT8_C(0x04)
188-
#define BMM350_PMU_CMD_BUSY_MSK UINT8_C(0x01)
189-
#define BMM350_PMU_CMD_BUSY_POS UINT8_C(0x00)
190-
#define BMM350_ODR_OVWR_MSK UINT8_C(0x02)
191-
#define BMM350_ODR_OVWR_POS UINT8_C(0x01)
192-
#define BMM350_AVG_OVWR_MSK UINT8_C(0x04)
193-
#define BMM350_AVG_OVWR_POS UINT8_C(0x02)
194-
#define BMM350_PWR_MODE_IS_NORMAL_MSK UINT8_C(0x08)
195-
#define BMM350_PWR_MODE_IS_NORMAL_POS UINT8_C(0x03)
196-
#define BMM350_CMD_IS_ILLEGAL_MSK UINT8_C(0x10)
197-
#define BMM350_CMD_IS_ILLEGAL_POS UINT8_C(0x04)
198-
#define BMM350_PMU_CMD_VALUE_MSK UINT8_C(0xE0)
199-
#define BMM350_PMU_CMD_VALUE_POS UINT8_C(0x05)
186+
#define BMM350_AVG_MSK (0x30)
187+
#define BMM350_AVG_POS UINT8_C(0x04)
188+
#define BMM350_PMU_CMD_BUSY_MSK UINT8_C(0x01)
189+
#define BMM350_PMU_CMD_BUSY_POS UINT8_C(0x00)
190+
#define BMM350_ODR_OVWR_MSK UINT8_C(0x02)
191+
#define BMM350_ODR_OVWR_POS UINT8_C(0x01)
192+
#define BMM350_AVG_OVWR_MSK UINT8_C(0x04)
193+
#define BMM350_AVG_OVWR_POS UINT8_C(0x02)
194+
#define BMM350_PWR_MODE_IS_NORMAL_MSK UINT8_C(0x08)
195+
#define BMM350_PWR_MODE_IS_NORMAL_POS UINT8_C(0x03)
196+
#define BMM350_CMD_IS_ILLEGAL_MSK UINT8_C(0x10)
197+
#define BMM350_CMD_IS_ILLEGAL_POS UINT8_C(0x04)
198+
#define BMM350_PMU_CMD_VALUE_MSK UINT8_C(0xE0)
199+
#define BMM350_PMU_CMD_VALUE_POS UINT8_C(0x05)
200+
#define BMM350_INT_CTRL_INT_MODE_MSK UINT8_C(0x01)
201+
#define BMM350_INT_CTRL_INT_MODE_POS UINT8_C(0x00)
202+
#define BMM350_INT_CTRL_INT_POL_MSK UINT8_C(0x02)
203+
#define BMM350_INT_CTRL_INT_POL_POS UINT8_C(0x01)
204+
#define BMM350_INT_CTRL_INT_OD_MSK UINT8_C(0x04)
205+
#define BMM350_INT_CTRL_INT_OD_POS UINT8_C(0x02)
206+
#define BMM350_INT_CTRL_INT_OUTPUT_EN_MSK UINT8_C(0x08)
207+
#define BMM350_INT_CTRL_INT_OUTPUT_EN_POS UINT8_C(0x03)
208+
#define BMM350_INT_CTRL_DRDY_DATA_REG_EN_MSK UINT8_C(0x80)
209+
#define BMM350_INT_CTRL_DRDY_DATA_REG_EN_POS UINT8_C(0x07)
200210

201211
/**************************** Self-test macros **********************/
202212
#define BMM350_SELF_TEST_DISABLE UINT8_C(0x00)
@@ -271,7 +281,6 @@ enum bmm350_signed_bit {
271281
#define BMM350_ODR_1_5625HZ UINT8_C(0xA)
272282
#define BMM350_ODR_MSK UINT8_C(0xf)
273283
#define BMM350_ODR_POS UINT8_C(0x0)
274-
#define BMM350_DATA_READY_INT_CTRL UINT8_C(0x8e)
275284

276285
/* Macro to SET and GET BITS of a register*/
277286
#define BMM350_SET_BITS(reg_data, bitname, data) \
@@ -451,9 +460,13 @@ struct bmm350_raw_mag_data {
451460
struct bmm350_config {
452461
struct bmm350_bus bus;
453462
const struct bmm350_bus_io *bus_io;
463+
#ifdef CONFIG_BMM350_TRIGGER
454464
struct gpio_dt_spec drdy_int;
465+
uint8_t int_flags;
466+
#endif
455467
uint8_t default_odr;
456468
uint8_t default_osr;
469+
uint8_t drive_strength;
457470
};
458471

459472
struct bmm350_data {

drivers/sensor/bosch/bmm350/bmm350_trigger.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void bmm350_gpio_callback(const struct device *port, struct gpio_callback
8080
int bmm350_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
8181
sensor_trigger_handler_t handler)
8282
{
83+
const struct bmm350_config *cfg = dev->config;
8384
struct bmm350_data *data = dev->data;
8485
int ret = 0;
8586

@@ -91,7 +92,7 @@ int bmm350_trigger_set(const struct device *dev, const struct sensor_trigger *tr
9192
data->drdy_handler = handler;
9293

9394
/* Set PMU command configuration */
94-
ret = bmm350_reg_write(dev, BMM350_REG_INT_CTRL, BMM350_DATA_READY_INT_CTRL);
95+
ret = bmm350_reg_write(dev, BMM350_REG_INT_CTRL, cfg->int_flags);
9596
if (ret < 0) {
9697
return ret;
9798
}

dts/bindings/sensor/bosch,bmm350.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,29 @@ properties:
5252
- 2
5353
- 4
5454
- 8
55+
56+
push-pull-int:
57+
type: boolean
58+
description: |
59+
Set for push-pull interrupt. Otherwise, it is open-drain.
60+
61+
active-high-int:
62+
type: boolean
63+
description: |
64+
Set for a active high interrupt. Otherwise, it is active-low.
65+
66+
drive-strength:
67+
type: int
68+
description: |
69+
The pad drive strength. 7 is the strongest. 0 is the weakest.
70+
Reset Value of the BMM350 is 7.
71+
default: 7
72+
enum:
73+
- 0
74+
- 1
75+
- 2
76+
- 3
77+
- 4
78+
- 5
79+
- 6
80+
- 7

0 commit comments

Comments
 (0)