acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / i2c / pca9538 / pca9538.c
blobf8933ec10558d01db9bac05f057e69f0c530bbfd
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/i2c_bus.h>
4 #include <device/device.h>
5 #include "pca9538.h"
6 #include "chip.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();
13 if (!dev)
14 return 0;
15 else
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();
24 if (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;
32 if (!config)
33 return;
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,
43 .init = pca9538_init,
46 static void pca9538_enable(struct device *dev)
48 dev->ops = &pca9538_ops;
51 struct chip_operations drivers_i2c_pca9538_ops = {
52 .name = "PCA9538",
53 .enable_dev = pca9538_enable