Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Arthur Heymans | 24231ac | 2017-06-06 09:46:01 +0200 | [diff] [blame] | 3 | |
| 4 | #include <assert.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/smbus.h> |
Arthur Heymans | 24231ac | 2017-06-06 09:46:01 +0200 | [diff] [blame] | 8 | #include "chip.h" |
Arthur Heymans | 24231ac | 2017-06-06 09:46:01 +0200 | [diff] [blame] | 9 | |
| 10 | #define SMBUS_BLOCK_SIZE 32 |
| 11 | |
| 12 | static void ck505_init(struct device *dev) |
| 13 | { |
| 14 | struct drivers_i2c_ck505_config *config; |
| 15 | int dev_nregs, nregs; |
| 16 | u8 block[SMBUS_BLOCK_SIZE]; |
| 17 | int i; |
| 18 | |
| 19 | if (!dev->enabled || dev->path.type != DEVICE_PATH_I2C) |
| 20 | return; |
| 21 | |
| 22 | config = dev->chip_info; |
| 23 | |
| 24 | dev_nregs = smbus_block_read(dev, 0, sizeof(block), block); |
| 25 | |
| 26 | if (dev_nregs < 0) { |
| 27 | printk(BIOS_ERR, "Failed reading ck505 configuration!\n"); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | /* This means that the devicetree doesn't have to specify nregs */ |
| 32 | nregs = MIN(MIN(dev_nregs, config->nregs == 0 ? SMBUS_BLOCK_SIZE |
| 33 | : config->nregs), ARRAY_SIZE(config->mask)); |
| 34 | |
| 35 | |
| 36 | printk(BIOS_DEBUG, "Changing %d of the %d ck505 config bytes.\n", |
| 37 | nregs, dev_nregs); |
| 38 | |
| 39 | assert(ARRAY_SIZE(config->mask) == ARRAY_SIZE(config->regs)); |
| 40 | |
| 41 | for (i = 0; i < nregs && i < SMBUS_BLOCK_SIZE; i++) |
| 42 | block[i] = (block[i] & ~config->mask[i]) | config->regs[i]; |
| 43 | |
| 44 | if (smbus_block_write(dev, 0, dev_nregs, block) < 0) |
| 45 | printk(BIOS_ERR, "Failed writing ck505 configuration!\n"); |
| 46 | } |
| 47 | |
| 48 | static struct device_operations ck505_operations = { |
| 49 | .read_resources = DEVICE_NOOP, |
| 50 | .set_resources = DEVICE_NOOP, |
| 51 | .enable_resources = DEVICE_NOOP, |
| 52 | .init = ck505_init, |
| 53 | }; |
| 54 | |
| 55 | static void enable_dev(struct device *dev) |
| 56 | { |
| 57 | dev->ops = &ck505_operations; |
| 58 | } |
| 59 | |
| 60 | struct chip_operations drivers_i2c_ck505_ops = { |
| 61 | CHIP_NAME("CK505 Clock generator") |
| 62 | .enable_dev = enable_dev, |
| 63 | }; |