98691008235e008dee1d6124096917373587aa01
[coreboot.git] / src / drivers / i2c / adm1026 / adm1026.c
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>
7 #include <part/hard_reset.h>
8 #include <cpu/x86/msr.h>
9 #include "chip.h"
10
11 #define ADM1026_DEVICE 0x2d /* Either 0x2c or 0x2d or 0x2e */
12 #define ADM1026_REG_CONFIG1 0x00
13 #define CFG1_MONITOR     0x01
14 #define CFG1_INT_ENABLE  0x02
15 #define CFG1_INT_CLEAR   0x04
16 #define CFG1_AIN8_9      0x08
17 #define CFG1_THERM_HOT   0x10
18 #define CFT1_DAC_AFC     0x20
19 #define CFG1_PWM_AFC     0x40
20 #define CFG1_RESET       0x80
21 #define ADM1026_REG_CONFIG2 0x01
22 #define ADM1026_REG_CONFIG3 0x07
23
24 static void adm1026_enable_monitoring(device_t dev);
25
26 static void adm1026_init(device_t dev)
27 {
28         if (dev->enabled && dev->path.type == DEVICE_PATH_I2C)
29         {
30                 if(ops_smbus_bus(get_pbus_smbus(dev))) {
31                         if( dev->bus->dev->path.type == DEVICE_PATH_I2C) smbus_set_link(dev); // it is under mux 
32                         adm1026_enable_monitoring(dev);
33                 }
34                 
35         }
36
37 }
38 static void adm1026_enable_monitoring(device_t dev)
39 {
40         int result;
41         result = smbus_read_byte(dev, ADM1026_REG_CONFIG1);
42
43         result = (result | CFG1_MONITOR) & ~(CFG1_INT_CLEAR | CFG1_RESET);
44         result = smbus_write_byte(dev, ADM1026_REG_CONFIG1, result);
45
46         result = smbus_read_byte(dev, ADM1026_REG_CONFIG1);
47         if (!(result & CFG1_MONITOR)) {
48                 printk_debug("ADM1026: monitoring would not enable");
49         }
50 }
51 static void adm1026_noop(device_t dummy)
52 {
53 }
54
55 static struct device_operations adm1026_operations = {
56         .read_resources   = adm1026_noop,
57         .set_resources    = adm1026_noop,
58         .enable_resources = adm1026_noop,
59         .init             = adm1026_init,
60 };
61
62 static void enable_dev(struct device *dev)
63 {
64         dev->ops = &adm1026_operations;
65 }
66
67 struct chip_operations drivers_i2c_adm1026_ops = {
68         CHIP_NAME("adm1026")
69         .enable_dev = enable_dev, 
70 };