1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/i2c_bus.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.
20 for (uint8_t i
= 0; i
< length
; i
++) {
21 res
= i2c_dev_writeb_at(dev
, addr
+ i
, values
[i
]);
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);
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");
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
;
54 printk(BIOS_DEBUG
, "tas5825m id %d\n", config
->id
);
55 int res
= tas5825m_setup(dev
, config
->id
);
57 printk(BIOS_ERR
, "tas5825m init failed: %d\n", res
);
59 printk(BIOS_DEBUG
, "tas5825m init successful\n");
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
,