Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-34
[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 <part/hard_reset.h>
8 #include <cpu/x86/msr.h>
9 #include "chip.h"
10
11 #define ADM1027_REG_CONFIG1 0x40
12 #define CFG1_STRT       0x01
13 #define CFG1_LOCK       0x02
14 #define CFG1_RDY        0x04
15 #define CFG1_FSPD       0x08
16 #define CFG1_VXI        0x10
17 #define CFT1_FSPDIS     0x20
18 #define CFG1_TODIS      0x40
19 #define CFG1_VCC        0x80
20 #define ADM1027_REG_CONFIG2 0x73
21 #define ADM1027_REG_CONFIG3 0x78
22
23 static void adm1027_enable_monitoring(device_t dev)
24 {        
25         int result;
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 }
40
41 static void adm1027_init(device_t dev)
42 {
43         if (dev->enabled && dev->path.type == DEVICE_PATH_I2C)
44         {
45                 if(ops_smbus_bus(get_pbus_smbus(dev))) {
46                         if( dev->bus->dev->path.type == DEVICE_PATH_I2C) smbus_set_link(dev); // it is under mux 
47                         adm1027_enable_monitoring(dev);
48                 }
49                 
50         }
51
52 }
53 static void adm1027_noop(device_t dummy)
54 {
55 }
56
57 static struct device_operations adm1027_operations = {
58         .read_resources   = adm1027_noop,
59         .set_resources    = adm1027_noop,
60         .enable_resources = adm1027_noop,
61         .init             = adm1027_init,
62 };
63
64 static void enable_dev(struct device *dev)
65 {
66         dev->ops = &adm1027_operations;
67 }
68
69 struct chip_operations drivers_i2c_adm1027_ops = {
70         CHIP_NAME("adm1027")
71         .enable_dev = enable_dev, 
72 };