coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tas5825m.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/smbus.h>
5 #include <device/pci.h>
6 #include "chip.h"
7 #include "tas5825m.h"
8 
10 {
11  return smbus_write_byte(dev, addr, value);
12 }
13 
14 //TODO: use I2C block write for better performance
16  const uint8_t *values, uint8_t length)
17 {
18  int res = 0;
19  for (uint8_t i = 0; i < length; i++) {
20  res = smbus_write_byte(dev, addr + i, values[i]);
21  if (res < 0)
22  return res;
23  }
24  return (int)length;
25 }
26 
27 int tas5825m_set_page(struct device *dev, uint8_t page)
28 {
29  return tas5825m_write_at(dev, 0x00, page);
30 }
31 
32 int tas5825m_set_book(struct device *dev, uint8_t book)
33 {
34  int res = tas5825m_set_page(dev, 0x00);
35  if (res < 0)
36  return res;
37  return tas5825m_write_at(dev, 0x7F, book);
38 }
39 
40 __weak int tas5825m_setup(struct device *dev, int id)
41 {
42  printk(BIOS_ERR, "tas5825m: setup not implemented\n");
43  return -1;
44 }
45 
46 static void tas5825m_init(struct device *dev)
47 {
48  if (dev->enabled && dev->path.type == DEVICE_PATH_I2C &&
50  printk(BIOS_DEBUG, "tas5825m at %s\n", dev_path(dev));
51 
53  if (config) {
54  printk(BIOS_DEBUG, "tas5825m id %d\n", config->id);
55  int res = tas5825m_setup(dev, config->id);
56  if (res)
57  printk(BIOS_ERR, "tas5825m init failed: %d\n", res);
58  else
59  printk(BIOS_DEBUG, "tas5825m init successful\n");
60  } else {
61  printk(BIOS_ERR, "tas5825m: failed to find config\n");
62  }
63  }
64 }
65 
66 static struct device_operations tas5825m_operations = {
68  .set_resources = noop_set_resources,
69  .init = tas5825m_init,
70 };
71 
72 static void tas5825m_enable_dev(struct device *dev)
73 {
74  dev->ops = &tas5825m_operations;
75 }
76 
78  CHIP_NAME("TI TAS5825M Amplifier")
79  .enable_dev = tas5825m_enable_dev,
80 };
pte_t value
Definition: mmu.c:91
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
struct bus * get_pbus_smbus(struct device *dev)
Definition: smbus_ops.c:8
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
struct chip_operations drivers_i2c_tas5825m_ops
Definition: tas5825m.c:77
int tas5825m_set_book(struct device *dev, uint8_t book)
Definition: tas5825m.c:32
static struct device_operations tas5825m_operations
Definition: tas5825m.c:66
static void tas5825m_enable_dev(struct device *dev)
Definition: tas5825m.c:72
static void tas5825m_init(struct device *dev)
Definition: tas5825m.c:46
int tas5825m_write_at(struct device *dev, uint8_t addr, uint8_t value)
Definition: tas5825m.c:9
int tas5825m_write_block_at(struct device *dev, uint8_t addr, const uint8_t *values, uint8_t length)
Definition: tas5825m.c:15
int tas5825m_set_page(struct device *dev, uint8_t page)
Definition: tas5825m.c:27
__weak int tas5825m_setup(struct device *dev, int id)
Definition: tas5825m.c:40
uint64_t length
Definition: fw_cfg_if.h:1
#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
static const struct smbus_bus_operations * ops_smbus_bus(struct bus *bus)
Definition: smbus.h:19
static int smbus_write_byte(struct device *const dev, u8 addr, u8 val)
Definition: smbus.h:48
#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
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
unsigned char uint8_t
Definition: stdint.h:8
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