2 * This file is part of the coreboot project.
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>
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.
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.
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
22 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/path.h>
26 #include <device/smbus.h>
28 struct bus *get_pbus_smbus(device_t dev)
30 struct bus *pbus = dev->bus;
31 while (pbus && pbus->dev && !ops_smbus_bus(pbus)) {
32 pbus = pbus->dev->bus;
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));
41 /*multi level i2c MUX??? may need to find the first i2c device and then set link
43 1 store get_pbus_smbus list link
44 2 reverse the link and call set link */
46 int smbus_set_link(device_t dev)
48 struct bus *pbus_a[4]; // 4 level mux only. Enough?
49 struct bus *pbus = dev->bus;
52 while(pbus && pbus->dev && (pbus->dev->path.type==DEVICE_PATH_I2C)) {
53 pbus_a[pbus_num++] = pbus;
54 pbus = pbus->dev->bus;
56 // printk_info("smbus_set_link: ");
57 for (i=pbus_num-1; i>=0; i--) {
58 // printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link);
59 if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) {
60 if (pbus_a[i]->dev->ops && pbus_a[i]->dev->ops->set_link)
61 pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev, pbus_a[i]->link);
64 // printk_info(" %s\n", dev_path(dev));
69 int smbus_quick_read(device_t dev)
71 return ops_smbus_bus(get_pbus_smbus(dev))->quick_read(dev);
73 int smbus_quick_write(device_t dev)
75 return ops_smbus_bus(get_pbus_smbus(dev))->quick_write(dev);
77 int smbus_recv_byte(device_t dev)
79 return ops_smbus_bus(get_pbus_smbus(dev))->recv_byte(dev);
81 int smbus_send_byte(device_t dev, uint8_t byte)
83 return ops_smbus_bus(get_pbus_smbus(dev))->send_byte(dev, byte);
85 int smbus_read_byte(device_t dev, uint8_t addr)
87 return ops_smbus_bus(get_pbus_smbus(dev))->read_byte(dev, addr);
89 int smbus_write_byte(device_t dev, uint8_t addr, uint8_t val)
91 return ops_smbus_bus(get_pbus_smbus(dev))->write_byte(dev, addr, val);
93 int smbus_read_word(device_t dev, uint8_t addr)
95 return ops_smbus_bus(get_pbus_smbus(dev))->read_word(dev, addr);
97 int smbus_write_word(device_t dev, uint8_t addr, uint16_t val)
99 return ops_smbus_bus(get_pbus_smbus(dev))->write_word(dev, addr, val);
101 int smbus_process_call(device_t dev, uint8_t cmd, uint16_t data)
103 return ops_smbus_bus(get_pbus_smbus(dev))->process_call(dev, cmd, data);
105 int smbus_block_read(device_t dev, uint8_t cmd, uint8_t bytes, uint8_t *buffer)
107 return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes, buffer);
109 int smbus_block_write(device_t dev, uint8_t cmd, uint8_t bytes, const uint8_t *buffer)
111 return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes, buffer);