7ce445b32d53256ef212f8ae5fff98de13feb91e
[coreboot.git] / src / drivers / i2c / adm1027 / adm1027.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 <cpu/x86/msr.h>
8 #include "chip.h"
9
10 #define ADM1027_REG_CONFIG1     0x40
11 #define CFG1_STRT               0x01
12 #define CFG1_LOCK               0x02
13 #define CFG1_RDY                0x04
14 #define CFG1_FSPD               0x08
15 #define CFG1_VXI                0x10
16 #define CFT1_FSPDIS             0x20
17 #define CFG1_TODIS              0x40
18 #define CFG1_VCC                0x80
19 #define ADM1027_REG_CONFIG2     0x73
20 #define ADM1027_REG_CONFIG3     0x78
21
22 static void adm1027_enable_monitoring(device_t dev)
23 {
24         int result;
25
26         result = smbus_read_byte(dev, ADM1027_REG_CONFIG1);
27
28         if (!(result & CFG1_RDY)) {
29                 printk_debug("ADM1027: monitoring not ready\r\n");
30                 return;
31         }
32         result = (result | CFG1_STRT);
33         result = smbus_write_byte(dev, ADM1027_REG_CONFIG1, result);
34
35         result = smbus_read_byte(dev, ADM1027_REG_CONFIG1);
36         if (!(result & CFG1_STRT)) {
37                 printk_debug("ADM1027: monitoring would not enable\r\n");
38         }
39         printk_debug("ADM1027: monitoring enabled\r\n");
40 }
41
42 static void adm1027_init(device_t dev)
43 {
44         if (dev->enabled && dev->path.type == DEVICE_PATH_I2C) {
45                 if (ops_smbus_bus(get_pbus_smbus(dev))) {
46                         if (dev->bus->dev->path.type == DEVICE_PATH_I2C)
47                                 smbus_set_link(dev);    // it is under mux 
48                         adm1027_enable_monitoring(dev);
49                 }
50
51         }
52 }
53
54 static void adm1027_noop(device_t dummy)
55 {
56 }
57
58 static struct device_operations adm1027_operations = {
59         .read_resources         = adm1027_noop,
60         .set_resources          = adm1027_noop,
61         .enable_resources       = adm1027_noop,
62         .init                   = adm1027_init,
63 };
64
65 static void enable_dev(struct device *dev)
66 {
67         dev->ops = &adm1027_operations;
68 }
69
70 struct chip_operations drivers_i2c_adm1027_ops = {
71         CHIP_NAME("adm1027")
72         .enable_dev = enable_dev,
73 };