blob: 592916afbdbeb3e7ac9b934d9d8c381f23533dde [file] [log] [blame]
Yinghai Lu7213d0f2004-12-03 03:39:04 +00001#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 Lu7213d0f2004-12-03 03:39:04 +00007#include <cpu/x86/msr.h>
Yinghai Lu7213d0f2004-12-03 03:39:04 +00008
Vikram Narayanan0786bc62011-12-26 22:52:01 +05309#define ADM1026_DEVICE 0x2d /* Either 0x2c or 0x2d or 0x2e */
Yinghai Lu7213d0f2004-12-03 03:39:04 +000010#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 Georgi62b35132009-08-26 18:14:30 +000018#define CFG1_RESET 0x80
Yinghai Lu7213d0f2004-12-03 03:39:04 +000019#define ADM1026_REG_CONFIG2 0x01
20#define ADM1026_REG_CONFIG3 0x07
21
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110022static void adm1026_enable_monitoring(struct device *dev)
Yinghai Lu7213d0f2004-12-03 03:39:04 +000023{
Vikram Narayanan0786bc62011-12-26 22:52:01 +053024 int result;
25 result = smbus_read_byte(dev, ADM1026_REG_CONFIG1);
Yinghai Lu7213d0f2004-12-03 03:39:04 +000026
Vikram Narayanan0786bc62011-12-26 22:52:01 +053027 result = (result | CFG1_MONITOR) & ~(CFG1_INT_CLEAR | CFG1_RESET);
28 result = smbus_write_byte(dev, ADM1026_REG_CONFIG1, result);
Yinghai Lu7213d0f2004-12-03 03:39:04 +000029
Vikram Narayanan0786bc62011-12-26 22:52:01 +053030 result = smbus_read_byte(dev, ADM1026_REG_CONFIG1);
31 if (!(result & CFG1_MONITOR)) {
32 printk(BIOS_DEBUG, "ADM1026: monitoring would not enable");
33 }
Yinghai Lu7213d0f2004-12-03 03:39:04 +000034}
Vikram Narayanan0786bc62011-12-26 22:52:01 +053035
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110036static void adm1026_init(struct device *dev)
Vikram Narayananea07b9f2012-01-21 15:32:59 +053037{
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 Lu7213d0f2004-12-03 03:39:04 +000047static struct device_operations adm1026_operations = {
Edward O'Callaghan524625d2014-10-31 07:55:45 +110048 .read_resources = DEVICE_NOOP,
49 .set_resources = DEVICE_NOOP,
50 .enable_resources = DEVICE_NOOP,
Vikram Narayanan0786bc62011-12-26 22:52:01 +053051 .init = adm1026_init,
Yinghai Lu7213d0f2004-12-03 03:39:04 +000052};
53
54static void enable_dev(struct device *dev)
55{
56 dev->ops = &adm1026_operations;
57}
58
59struct chip_operations drivers_i2c_adm1026_ops = {
60 CHIP_NAME("adm1026")
Stefan Reinauer14e22772010-04-27 06:56:47 +000061 .enable_dev = enable_dev,
Yinghai Lu7213d0f2004-12-03 03:39:04 +000062};