mb/google/brya: Create rull variant
[coreboot2.git] / src / drivers / i2c / tas5825m / tas5825m.c
blobead1b167e8ebc106583ebae384ccfbdf8e6e0c04
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/i2c_bus.h>
5 #include "chip.h"
6 #include "tas5825m.h"
8 int tas5825m_write_at(struct device *dev, uint8_t addr, uint8_t value)
10 return i2c_dev_writeb_at(dev, addr, value);
13 int tas5825m_write_block_at(struct device *dev, uint8_t addr,
14 const uint8_t *values, uint8_t length)
16 // TODO: use I2C block write for better performance; SMBus does not
17 // have `transfer` op for it.
19 int res = 0;
20 for (uint8_t i = 0; i < length; i++) {
21 res = i2c_dev_writeb_at(dev, addr + i, values[i]);
22 if (res < 0)
23 return res;
25 return (int)length;
28 int tas5825m_set_page(struct device *dev, uint8_t page)
30 return tas5825m_write_at(dev, 0x00, page);
33 int tas5825m_set_book(struct device *dev, uint8_t book)
35 int res = tas5825m_set_page(dev, 0x00);
36 if (res < 0)
37 return res;
38 return tas5825m_write_at(dev, 0x7F, book);
41 __weak int tas5825m_setup(struct device *dev, int id)
43 printk(BIOS_ERR, "tas5825m: setup not implemented\n");
44 return -1;
47 static void tas5825m_init(struct device *dev)
49 if (dev->enabled && dev->path.type == DEVICE_PATH_I2C && i2c_link(dev)) {
50 printk(BIOS_DEBUG, "tas5825m at %s\n", dev_path(dev));
52 struct drivers_i2c_tas5825m_config *config = dev->chip_info;
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");
66 static struct device_operations tas5825m_operations = {
67 .read_resources = noop_read_resources,
68 .set_resources = noop_set_resources,
69 .init = tas5825m_init,
72 static void tas5825m_enable_dev(struct device *dev)
74 dev->ops = &tas5825m_operations;
77 struct chip_operations drivers_i2c_tas5825m_ops = {
78 .name = "TI TAS5825M Amplifier",
79 .enable_dev = tas5825m_enable_dev,