coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
kempld.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 
6 #include "chip.h"
7 #include "kempld.h"
8 #include "kempld_internal.h"
9 
10 static void kempld_uart_read_resources(struct device *dev)
11 {
12  static const unsigned int io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
13 
14  const struct ec_kontron_kempld_config *const config = dev->chip_info;
15 
16  struct resource *const res_io = new_resource(dev, 0);
17  struct resource *const res_irq = new_resource(dev, 1);
18  const unsigned int uart = dev->path.generic.subid;
19 
20  if (!config || !res_io || !res_irq || uart >= KEMPLD_NUM_UARTS)
21  return;
22 
23  const enum kempld_uart_io io = config->uart[uart].io;
24  if (io >= ARRAY_SIZE(io_addr)) {
25  printk(BIOS_ERR, "KEMPLD: Bad io value '%d' for UART#%u\n.", io, uart);
26  dev->enabled = false;
27  return;
28  }
29 
30  const int irq = config->uart[uart].irq;
31  if (irq >= 16) {
32  printk(BIOS_ERR, "KEMPLD: Bad irq value '%d' for UART#%u\n.", irq, uart);
33  dev->enabled = false;
34  return;
35  }
36 
37  res_io->base = io_addr[io];
38  res_io->size = 8;
41  res_irq->base = irq;
42  res_irq->size = 1;
43  res_irq->flags = IORESOURCE_IO | IORESOURCE_FIXED |
45 
46  if (kempld_get_mutex(100) < 0)
47  return;
48 
49  const uint8_t reg = uart ? KEMPLD_UART_1 : KEMPLD_UART_0;
50  const uint8_t val = kempld_read8(reg);
51  kempld_write8(reg,
53  io << KEMPLD_UART_IO_SHIFT |
54  irq << KEMPLD_UART_IRQ_SHIFT);
55 
57 }
58 
59 static void kempld_uart_enable_resources(struct device *dev)
60 {
61  if (kempld_get_mutex(100) < 0)
62  return;
63 
64  const unsigned int uart = dev->path.generic.subid;
65  const uint8_t reg = uart ? KEMPLD_UART_1 : KEMPLD_UART_0;
67 
69 }
70 
71 static struct device_operations kempld_uart_ops = {
73  .enable_resources = kempld_uart_enable_resources,
74 };
75 
76 static void kempld_enable_dev(struct device *const dev)
77 {
78  if (dev->path.type == DEVICE_PATH_GENERIC) {
79  switch (dev->path.generic.id) {
80  case 0:
81  if (dev->path.generic.subid < KEMPLD_NUM_UARTS) {
82  dev->ops = &kempld_uart_ops;
83  break;
84  }
86  case 1:
87  if (dev->path.generic.subid == 0) {
89  break;
90  }
92  default:
93  printk(BIOS_WARNING, "KEMPLD: Spurious device %s.\n", dev_path(dev));
94  break;
95  }
96  } else if (dev->path.type == DEVICE_PATH_GPIO) {
97  if (dev->path.gpio.id == 0) {
98  if (kempld_gpio_pads_config(dev) < 0)
99  printk(BIOS_ERR, "KEMPLD: GPIO configuration failed!\n");
100  } else {
101  printk(BIOS_WARNING, "KEMPLD: Spurious GPIO device %s.\n",
102  dev_path(dev));
103  }
104  }
105 }
106 
108  CHIP_NAME("Kontron KEMPLD")
109  .enable_dev = kempld_enable_dev,
110 };
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
#define __fallthrough
Definition: compiler.h:39
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
void kempld_write8(const uint8_t addr, const uint8_t data)
Definition: early_kempld.c:11
int kempld_get_mutex(int timeout_ms)
Definition: early_kempld.c:23
void kempld_release_mutex(void)
Definition: early_kempld.c:30
uint8_t kempld_read8(const uint8_t addr)
Definition: early_kempld.c:17
#define KEMPLD_NUM_UARTS
Definition: chip.h:6
kempld_uart_io
Definition: chip.h:16
#define CHIP_NAME(X)
Definition: device.h:32
static void kempld_uart_enable_resources(struct device *dev)
Definition: kempld.c:59
static void kempld_uart_read_resources(struct device *dev)
Definition: kempld.c:10
struct chip_operations ec_kontron_kempld_ops
Definition: kempld.c:107
static void kempld_enable_dev(struct device *const dev)
Definition: kempld.c:76
static struct device_operations kempld_uart_ops
Definition: kempld.c:71
int kempld_gpio_pads_config(struct device *dev)
Definition: kempld_gpio.c:59
void kempld_i2c_device_init(struct device *const dev)
Definition: kempld_i2c.c:228
#define KEMPLD_UART_0
#define KEMPLD_UART_IRQ_SHIFT
#define KEMPLD_UART_1
#define KEMPLD_UART_IRQ_MASK
#define KEMPLD_UART_IO_MASK
#define KEMPLD_UART_ENABLE
#define KEMPLD_UART_IO_SHIFT
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
enum board_config config
Definition: memory.c:448
@ DEVICE_PATH_GPIO
Definition: path.h:22
@ DEVICE_PATH_GENERIC
Definition: path.h:18
#define IORESOURCE_STORED
Definition: resource.h:32
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
#define IORESOURCE_FIXED
Definition: resource.h:36
unsigned char uint8_t
Definition: stdint.h:8
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct generic_path generic
Definition: path.h:125
struct gpio_path gpio
Definition: path.h:129
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
unsigned int subid
Definition: path.h:97
unsigned int id
Definition: path.h:96
unsigned int id
Definition: path.h:110
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
u8 val
Definition: sys.c:300