coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pca9538.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/i2c_bus.h>
4 #include <device/device.h>
5 #include "pca9538.h"
6 #include "chip.h"
7 
8 /* This function can be used from outside the chip driver to read input. */
10 {
11  struct device *dev = pca9538_get_dev();
12 
13  if (!dev)
14  return 0;
15  else
16  return (uint8_t)(i2c_dev_readb_at(dev, INPUT_REG));
17 }
18 
19 /* This function can be used from outside the chip driver to set output. */
21 {
22  struct device *dev = pca9538_get_dev();
23 
24  if (dev)
26 }
27 
28 static void pca9538_init(struct device *dev)
29 {
31 
32  if (!config)
33  return;
34  /* Set up registers as requested in devicetree. */
36  i2c_dev_writeb_at(dev, OUTPUT_REG, config->out_val);
37  i2c_dev_writeb_at(dev, IO_CONFIG_REG, config->in_out);
38 }
39 
40 static struct device_operations pca9538_ops = {
42  .set_resources = noop_set_resources,
43  .init = pca9538_init,
44 };
45 
46 static void pca9538_enable(struct device *dev)
47 {
48  dev->ops = &pca9538_ops;
49 }
50 
52  CHIP_NAME("PCA9538")
53  .enable_dev = pca9538_enable
54 };
int i2c_dev_writeb_at(struct device *const dev, const uint8_t off, const uint8_t val)
Definition: i2c_bus.c:121
int i2c_dev_readb_at(struct device *const dev, uint8_t off)
Definition: i2c_bus.c:84
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
enum board_config config
Definition: memory.c:448
static struct device_operations pca9538_ops
Definition: pca9538.c:40
uint8_t pca9538_read_input(void)
Definition: pca9538.c:9
void pca9538_set_output(uint8_t val)
Definition: pca9538.c:20
static void pca9538_enable(struct device *dev)
Definition: pca9538.c:46
struct chip_operations drivers_i2c_pca9538_ops
Definition: pca9538.c:51
static void pca9538_init(struct device *dev)
Definition: pca9538.c:28
#define OUTPUT_REG
Definition: pca9538.h:11
struct device * pca9538_get_dev(void)
#define INPUT_REG
Definition: pca9538.h:10
#define IO_CONFIG_REG
Definition: pca9538.h:13
#define INPUT_INVERT_REG
Definition: pca9538.h:12
unsigned char uint8_t
Definition: stdint.h:8
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
u8 val
Definition: sys.c:300