Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <device/device.h> |
| 3 | #include <device/smbus.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
| 6 | #include <device/pci_ops.h> |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 7 | #include <cpu/x86/msr.h> |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 8 | |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 9 | #define ADM1026_DEVICE 0x2d /* Either 0x2c or 0x2d or 0x2e */ |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 10 | #define ADM1026_REG_CONFIG1 0x00 |
| 11 | #define CFG1_MONITOR 0x01 |
| 12 | #define CFG1_INT_ENABLE 0x02 |
| 13 | #define CFG1_INT_CLEAR 0x04 |
| 14 | #define CFG1_AIN8_9 0x08 |
| 15 | #define CFG1_THERM_HOT 0x10 |
| 16 | #define CFT1_DAC_AFC 0x20 |
| 17 | #define CFG1_PWM_AFC 0x40 |
Patrick Georgi | 62b3513 | 2009-08-26 18:14:30 +0000 | [diff] [blame] | 18 | #define CFG1_RESET 0x80 |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 19 | #define ADM1026_REG_CONFIG2 0x01 |
| 20 | #define ADM1026_REG_CONFIG3 0x07 |
| 21 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 22 | static void adm1026_enable_monitoring(struct device *dev) |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 23 | { |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 24 | int result; |
| 25 | result = smbus_read_byte(dev, ADM1026_REG_CONFIG1); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 26 | |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 27 | result = (result | CFG1_MONITOR) & ~(CFG1_INT_CLEAR | CFG1_RESET); |
| 28 | result = smbus_write_byte(dev, ADM1026_REG_CONFIG1, result); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 29 | |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 30 | result = smbus_read_byte(dev, ADM1026_REG_CONFIG1); |
| 31 | if (!(result & CFG1_MONITOR)) { |
| 32 | printk(BIOS_DEBUG, "ADM1026: monitoring would not enable"); |
| 33 | } |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 34 | } |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 35 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 36 | static void adm1026_init(struct device *dev) |
Vikram Narayanan | ea07b9f | 2012-01-21 15:32:59 +0530 | [diff] [blame] | 37 | { |
| 38 | if (dev->enabled && dev->path.type == DEVICE_PATH_I2C) { |
| 39 | if (ops_smbus_bus(get_pbus_smbus(dev))) { |
| 40 | if (dev->bus->dev->path.type == DEVICE_PATH_I2C) |
| 41 | smbus_set_link(dev); // it is under mux |
| 42 | adm1026_enable_monitoring(dev); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 47 | static struct device_operations adm1026_operations = { |
Edward O'Callaghan | 524625d | 2014-10-31 07:55:45 +1100 | [diff] [blame] | 48 | .read_resources = DEVICE_NOOP, |
| 49 | .set_resources = DEVICE_NOOP, |
| 50 | .enable_resources = DEVICE_NOOP, |
Vikram Narayanan | 0786bc6 | 2011-12-26 22:52:01 +0530 | [diff] [blame] | 51 | .init = adm1026_init, |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static void enable_dev(struct device *dev) |
| 55 | { |
| 56 | dev->ops = &adm1026_operations; |
| 57 | } |
| 58 | |
| 59 | struct chip_operations drivers_i2c_adm1026_ops = { |
| 60 | CHIP_NAME("adm1026") |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 61 | .enable_dev = enable_dev, |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 62 | }; |