1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/i2c_bus.h>
4 #include <device/device.h>
8 /* This function can be used from outside the chip driver to read input. */
9 uint8_t pca9538_read_input(void)
11 struct device
*dev
= pca9538_get_dev();
16 return (uint8_t)(i2c_dev_readb_at(dev
, INPUT_REG
));
19 /* This function can be used from outside the chip driver to set output. */
20 void pca9538_set_output(uint8_t val
)
22 struct device
*dev
= pca9538_get_dev();
25 i2c_dev_writeb_at(dev
, OUTPUT_REG
, val
);
28 static void pca9538_init(struct device
*dev
)
30 struct drivers_i2c_pca9538_config
*config
= dev
->chip_info
;
34 /* Set up registers as requested in devicetree. */
35 i2c_dev_writeb_at(dev
, INPUT_INVERT_REG
, config
->invert
);
36 i2c_dev_writeb_at(dev
, OUTPUT_REG
, config
->out_val
);
37 i2c_dev_writeb_at(dev
, IO_CONFIG_REG
, config
->in_out
);
40 static struct device_operations pca9538_ops
= {
41 .read_resources
= noop_read_resources
,
42 .set_resources
= noop_set_resources
,
46 static void pca9538_enable(struct device
*dev
)
48 dev
->ops
= &pca9538_ops
;
51 struct chip_operations drivers_i2c_pca9538_ops
= {
53 .enable_dev
= pca9538_enable