| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/i2c_bus.h> |
| 5 |
#include "chip.h" |
| 6 |
#include "tas5825m.h" |
| 7 |
|
| 8 |
int tas5825m_write_at(struct device *dev, uint8_t addr, uint8_t value) |
| 9 |
{ |
| 10 |
return i2c_dev_writeb_at(dev, addr, value); |
| 11 |
} |
| 12 |
|
| 13 |
int tas5825m_write_block_at(struct device *dev, uint8_t addr, |
| 14 |
const uint8_t *values, uint8_t length) |
| 15 |
{ |
| 16 |
|
| 17 |
|
| 18 |
|
| 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; |
| 24 |
} |
| 25 |
return (int)length; |
| 26 |
} |
| 27 |
|
| 28 |
int tas5825m_set_page(struct device *dev, uint8_t page) |
| 29 |
{ |
| 30 |
return tas5825m_write_at(dev, 0x00, page); |
| 31 |
} |
| 32 |
|
| 33 |
int tas5825m_set_book(struct device *dev, uint8_t book) |
| 34 |
{ |
| 35 |
int res = tas5825m_set_page(dev, 0x00); |
| 36 |
if (res < 0) |
| 37 |
return res; |
| 38 |
return tas5825m_write_at(dev, 0x7F, book); |
| 39 |
} |
| 40 |
|
| 41 |
__weak int tas5825m_setup(struct device *dev, int id) |
| 42 |
{ |
| 43 |
printk(BIOS_ERR, "tas5825m: setup not implemented\n"); |
| 44 |
return -1; |
| 45 |
} |
| 46 |
|
| 47 |
static void tas5825m_init(struct device *dev) |
| 48 |
{ |
| 49 |
if (dev->enabled && dev->path.type == DEVICE_PATH_I2C && i2c_link(dev)) { |
| 50 |
printk(BIOS_DEBUG, "tas5825m at %s\n", dev_path(dev)); |
| 51 |
|
| 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"); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
static struct device_operations tas5825m_operations = { |
| 67 |
.read_resources = noop_read_resources, |
| 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 |
|
| 77 |
struct chip_operations drivers_i2c_tas5825m_ops = { |
| 78 |
.name = "TI TAS5825M Amplifier", |
| 79 |
.enable_dev = tas5825m_enable_dev, |
| 80 |
}; |