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