coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ck505.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <assert.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/smbus.h>
7 #include "chip.h"
8 
9 #define SMBUS_BLOCK_SIZE 32
10 
11 static void ck505_init(struct device *dev)
12 {
14  int dev_nregs, nregs;
15  u8 block[SMBUS_BLOCK_SIZE];
16  int i;
17 
18  if (!dev->enabled || dev->path.type != DEVICE_PATH_I2C)
19  return;
20 
21  config = dev->chip_info;
22 
23  dev_nregs = smbus_block_read(dev, 0, sizeof(block), block);
24 
25  if (dev_nregs < 0) {
26  printk(BIOS_ERR, "Failed reading ck505 configuration!\n");
27  return;
28  }
29 
30  /* This means that the devicetree doesn't have to specify nregs */
31  nregs = MIN(MIN(dev_nregs, config->nregs == 0 ? SMBUS_BLOCK_SIZE
32  : config->nregs), ARRAY_SIZE(config->mask));
33 
34  printk(BIOS_DEBUG, "Changing %d of the %d ck505 config bytes.\n",
35  nregs, dev_nregs);
36 
37  assert(ARRAY_SIZE(config->mask) == ARRAY_SIZE(config->regs));
38 
39  for (i = 0; i < nregs && i < SMBUS_BLOCK_SIZE; i++)
40  block[i] = (block[i] & ~config->mask[i]) | config->regs[i];
41 
42  if (smbus_block_write(dev, 0, dev_nregs, block) < 0)
43  printk(BIOS_ERR, "Failed writing ck505 configuration!\n");
44 }
45 
46 static struct device_operations ck505_operations = {
48  .set_resources = noop_set_resources,
49  .init = ck505_init,
50 };
51 
52 static void enable_dev(struct device *dev)
53 {
54  dev->ops = &ck505_operations;
55 }
56 
58  CHIP_NAME("CK505 Clock generator")
59  .enable_dev = enable_dev,
60 };
#define assert(statement)
Definition: assert.h:74
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define MIN(a, b)
Definition: helpers.h:37
#define SMBUS_BLOCK_SIZE
Definition: ck505.c:9
struct chip_operations drivers_i2c_ck505_ops
Definition: ck505.c:57
static struct device_operations ck505_operations
Definition: ck505.c:46
static void enable_dev(struct device *dev)
Definition: ck505.c:52
static void ck505_init(struct device *dev)
Definition: ck505.c:11
#define printk(level,...)
Definition: stdlib.h:16
int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
Definition: smbus_ops.c:34
int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
Definition: smbus_ops.c:26
#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
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
@ DEVICE_PATH_I2C
Definition: path.h:11
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
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
const int nregs
Definition: chip.h:7