Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / devices / smbus_ops.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Tyan
5  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
6  * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <stdint.h>
24 #include <device/device.h>
25 #include <device/path.h>
26 #include <device/smbus.h>
27
28 struct bus *get_pbus_smbus(device_t dev)
29 {
30         struct bus *pbus = dev->bus;
31         while (pbus && pbus->dev && !ops_smbus_bus(pbus)) {
32                 pbus = pbus->dev->bus;
33         }
34         if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_smbus_bus) {
35                 printk_alert("%s Cannot find smbus bus operations", dev_path(dev));
36                 die("");
37                 for(;;);
38         }
39         return pbus;
40 }
41
42 /*multi level i2c MUX??? may need to find the first i2c device and then set link
43  * down to current dev
44   1 store get_pbus_smbus list link
45   2 reverse the link and call set link */
46
47 int smbus_set_link(device_t dev)
48 {
49         struct bus *pbus_a[4]; // 4 level mux only. Enough?
50         struct bus *pbus = dev->bus;
51         int pbus_num=0;
52         int i;
53         while(pbus && pbus->dev && (pbus->dev->path.type==DEVICE_PATH_I2C)) {
54                 pbus_a[pbus_num++] = pbus;
55                 pbus = pbus->dev->bus;
56         }
57 //      printk_info("smbus_set_link: ");
58         for (i=pbus_num-1; i>=0; i--) {
59 //              printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link);
60                 if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) {
61                         if (pbus_a[i]->dev->ops && pbus_a[i]->dev->ops->set_link)
62                                 pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev, pbus_a[i]->link);
63                 }
64         }
65 //      printk_info(" %s\n", dev_path(dev));
66
67         return pbus_num;
68 }
69
70 int smbus_quick_read(device_t dev)
71 {
72         return ops_smbus_bus(get_pbus_smbus(dev))->quick_read(dev);
73 }
74 int smbus_quick_write(device_t dev)
75 {
76         return ops_smbus_bus(get_pbus_smbus(dev))->quick_write(dev);
77 }
78 int smbus_recv_byte(device_t dev)
79 {
80         return ops_smbus_bus(get_pbus_smbus(dev))->recv_byte(dev);
81 }
82 int smbus_send_byte(device_t dev, uint8_t byte)
83 {
84         return ops_smbus_bus(get_pbus_smbus(dev))->send_byte(dev, byte);
85 }
86 int smbus_read_byte(device_t dev, uint8_t addr)
87 {
88         return ops_smbus_bus(get_pbus_smbus(dev))->read_byte(dev, addr);
89 }
90 int smbus_write_byte(device_t dev, uint8_t addr, uint8_t val)
91 {
92         return ops_smbus_bus(get_pbus_smbus(dev))->write_byte(dev, addr, val);
93 }
94 int smbus_read_word(device_t dev, uint8_t addr)
95 {
96         return ops_smbus_bus(get_pbus_smbus(dev))->read_word(dev, addr);
97 }
98 int smbus_write_word(device_t dev, uint8_t addr, uint16_t val)
99 {
100         return ops_smbus_bus(get_pbus_smbus(dev))->write_word(dev, addr, val);
101 }
102 int smbus_process_call(device_t dev, uint8_t cmd, uint16_t data)
103 {
104         return ops_smbus_bus(get_pbus_smbus(dev))->process_call(dev, cmd, data);
105 }
106 int smbus_block_read(device_t dev, uint8_t cmd, uint8_t bytes, uint8_t *buffer)
107 {
108         return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes, buffer);
109 }
110 int smbus_block_write(device_t dev, uint8_t cmd, uint8_t bytes, const uint8_t *buffer)
111 {
112         return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes, buffer);
113 }
114
115