-#include <console/console.h>
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2005 Tyan
+ * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
+ * Copyright (C) 2007 Ward Vandewege <ward@gnu.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <device/device.h>
-#include <device/pci.h>
-#include <device/pci_ids.h>
-#include <device/pci_ops.h>
-#include "../../../northbridge/amd/amdk8/northbridge.h"
+#include <console/console.h>
+#include <device/smbus.h>
#include "chip.h"
-#if 0
-static void fixup_lsi_53c1030(struct device *pdev)
+/**
+ * Do some S2881-specific HWM initialization for the ADT7463 chip.
+ *
+ * See Analog Devices ADT7463 datasheet, Rev C (2004):
+ * http://www.analog.com/en/prod/0,,766_825_ADT7463,00.html
+ */
+static void adt7463_init(device_t dev)
{
-// uint8_t byte;
- uint16_t word;
-
- byte = 1;
- pci_write_config8(pdev, 0xff, byte);
- // Set the device id
-// pci_write_config_word(pdev, PCI_DEVICE_ID, PCI_DEVICE_ID_LSILOGIC_53C1030);
- // Set the subsytem vendor id
-// pci_write_config16(pdev, PCI_SUBSYSTEM_VENDOR_ID, PCI_VENDOR_ID_TYAN);
- word = 0x10f1;
- pci_write_config16(pdev, PCI_SUBSYSTEM_VENDOR_ID, word);
- // Set the subsytem id
- word = 0x2880;
- pci_write_config16(pdev, PCI_SUBSYSTEM_ID, word);
- // Disable writes to the device id
- byte = 0;
- pci_write_config8(pdev, 0xff, byte);
-
-// lsi_scsi_init(pdev);
-
+ device_t smbus_dev, adt7463;
+ struct device_path path;
+ int result;
+
+ /* Find the SMBus controller (AMD-8111). */
+ smbus_dev = dev_find_device(0x1022, 0x746b, 0);
+ if (!smbus_dev)
+ die("SMBus controller not found\n");
+ printk_debug("SMBus controller found\n");
+
+ /* Find the ADT7463 device. */
+ path.type = DEVICE_PATH_I2C;
+ path.i2c.device = 0x2d;
+ adt7463 = find_dev_path(smbus_dev->link, &path);
+ if (!adt7463)
+ die("ADT7463 not found\n");
+ printk_debug("ADT7463 found\n");
+
+ /* Set all fans to 'Fastest Speed Calculated by All 3 Temperature
+ * Channels Controls PWMx'.
+ */
+ result = smbus_write_byte(adt7463, 0x5c, 0xc2);
+ result = smbus_write_byte(adt7463, 0x5d, 0xc2);
+ result = smbus_write_byte(adt7463, 0x5e, 0xc2);
+
+ /* Make sure that our fans never stop when temp. falls below Tmin,
+ * but rather keep going at minimum duty cycle (applies to automatic
+ * fan control mode only).
+ */
+ result = smbus_write_byte(adt7463, 0x62, 0xc0);
+
+ /* Set minimum PWM duty cycle to 25%, rather than the default 50%. */
+ result = smbus_write_byte(adt7463, 0x64, 0x40);
+ result = smbus_write_byte(adt7463, 0x65, 0x40);
+ result = smbus_write_byte(adt7463, 0x66, 0x40);
+
+ /* Set Tmin to 55C, rather than the default 90C. Above this temperature
+ * the fans will start blowing harder as temperature increases
+ * (automatic mode only).
+ */
+ result = smbus_write_byte(adt7463, 0x67, 0x37);
+ result = smbus_write_byte(adt7463, 0x68, 0x37);
+ result = smbus_write_byte(adt7463, 0x69, 0x37);
+
+ /* Set THERM limit to 70C, rather than the default 100C.
+ * The fans will kick in at 100% if the sensors reach this temperature,
+ * (only in automatic mode, but supposedly even when hardware is
+ * locked up). This is a failsafe measure.
+ */
+ result = smbus_write_byte(adt7463, 0x6a, 0x46);
+ result = smbus_write_byte(adt7463, 0x6b, 0x46);
+ result = smbus_write_byte(adt7463, 0x6c, 0x46);
+
+ /* Remote temperature 1 offset (LSB == 0.25C). */
+ result = smbus_write_byte(adt7463, 0x70, 0x02);
+
+ /* Remote temperature 2 offset (LSB == 0.25C). */
+ result = smbus_write_byte(adt7463, 0x72, 0x01);
+
+ /* Set TACH measurements to normal (1/second). */
+ result = smbus_write_byte(adt7463, 0x78, 0xf0);
+
+ printk_debug("ADT7463 properly initialized\n");
}
-#endif
-#if 0
-static void print_pci_regs(struct device *dev)
+static void dummy_noop(device_t dummy)
{
- uint8_t byte;
- int i;
-
- for(i=0;i<256;i++) {
- byte = pci_read_config8(dev, i);
-
- if((i%16)==0) printk_debug("\n%02x:",i);
- printk_debug(" %02x",byte);
- }
- printk_debug("\n");
-
-// pci_write_config8(dev, 0x4, byte);
-
}
-#endif
-#if 0
-static void print_mem(void)
-{
- unsigned int i;
- unsigned int low_1MB = 0xf4107000;
- for(i=low_1MB;i<low_1MB+1024;i++) {
- if((i%16)==0) printk_debug("\n %08x:",i);
- printk_debug(" %02x ",(unsigned char)*((unsigned char *)i));
- }
-#if 0
- for(i=low_1MB;i<low_1MB+1024*4;i++) {
- if((i%16)==0) printk_debug("\n %08x:",i);
- printk_debug(" %c ",(unsigned char)*((unsigned char *)i));
- }
-#endif
- }
-#endif
-#if 0
-static void amd8111_enable_rom(void)
-{
- uint8_t byte;
- struct device *dev;
- /* Enable 4MB rom access at 0xFFC00000 - 0xFFFFFFFF */
- /* Locate the amd8111 */
- dev = dev_find_device(0x1022, 0x7468, 0);
+static struct device_operations dummy_operations = {
+ .read_resources = dummy_noop,
+ .set_resources = dummy_noop,
+ .enable_resources = dummy_noop,
+ .init = adt7463_init,
+};
- /* Set the 4MB enable bit bit */
- byte = pci_read_config8(dev, 0x43);
- byte |= 0x80;
- pci_write_config8(dev, 0x43, byte);
-}
-#endif
-#if 0
-static void onboard_scsi_fixup(void)
+static unsigned int scan_root_bus(device_t root, unsigned int max)
{
- struct device *dev;
-#if 1
- unsigned char i,j,k;
-
- for(i=0;i<=15;i++) {
- for(j=0;j<=0x1f;j++) {
- for (k=0;k<=6;k++){
- dev = dev_find_slot(i, PCI_DEVFN(j, k));
- if (dev) {
- printk_debug("%02x:%02x:%02x",i,j,k);
- print_pci_regs(dev);
- }
- }
- }
- }
-#endif
+ struct device_path path;
+ device_t dummy;
+ unsigned link_i;
+ max = root_dev_scan_bus(root, max);
-#if 0
- dev = dev_find_device(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030,0);
- if(!dev) {
- printk_info("LSI_SCSI_FW_FIXUP: No Device Found!");
- return;
- }
+ printk_debug("scan_root_bus ok\n");
- lsi_scsi_init(dev);
-#endif
-// print_mem();
-// amd8111_enable_rom();
-}
-#endif
-#if 0
-static void vga_fixup(void) {
- // we do this right here because:
- // - all the hardware is working, and some VGA bioses seem to need
- // that
- // - we need page 0 below for linuxbios tables.
-#if CONFIG_REALMODE_IDT == 1
- printk_debug("INSTALL REAL-MODE IDT\n");
- setup_realmode_idt();
-#endif
-#if CONFIG_VGABIOS == 1
- printk_debug("DO THE VGA BIOS\n");
- do_vgabios(0x0600);
- post_code(0x93);
-#endif
+ /* The following is a little silly. We need a hook into the boot
+ * process *after* the ADT7463 device has been initialized. So we
+ * create this dummy device, and we put the ADT7463 S2881 specific
+ * settings in its init function, which gets called
+ * as the last device to be initialized.
+ */
+ link_i = root->links;
+ if (link_i >= MAX_LINKS) {
+ printk_debug("Reached MAX_LINKS, not configuring ADT7463");
+ return max;
+ }
+ root->link[link_i].link = link_i;
+ root->link[link_i].dev = root;
+ root->link[link_i].children = 0;
+ root->links++;
+
+ path.type = DEVICE_PATH_PNP;
+ path.pnp.port = 0;
+ path.pnp.device = 0;
+ dummy = alloc_dev(&root->link[link_i], &path);
+ dummy->ops = &dummy_operations;
+
+ return max;
}
-#endif
-
-#if 0
-static void
-enable(struct chip *chip, enum chip_pass pass)
-{
-
- struct mainboard_tyan_s2895_config *conf =
- (struct mainboard_tyan_s2895_config *)chip->chip_info;
-
- switch (pass) {
- default: break;
-// case CONF_PASS_PRE_CONSOLE:
-// case CONF_PASS_PRE_PCI:
-// case CONF_PASS_POST_PCI:
- case CONF_PASS_PRE_BOOT:
-// if (conf->fixup_scsi)
-// onboard_scsi_fixup();
-// if (conf->fixup_vga)
-// vga_fixup();
- printk_debug("mainboard fixup pass %d done\r\n",
- pass);
- break;
- }
+static struct device_operations mainboard_operations = {
+ .read_resources = root_dev_read_resources,
+ .set_resources = root_dev_set_resources,
+ .enable_resources = root_dev_enable_resources,
+ .init = root_dev_init,
+ .scan_bus = scan_root_bus,
+};
+static void enable_dev(struct device *dev)
+{
+ dev->ops = &mainboard_operations;
}
-#endif
-struct chip_operations mainboard_tyan_s2881_ops = {
- CHIP_NAME("Tyan s2881 mainboard")
+struct chip_operations mainboard_ops = {
+ CHIP_NAME("Tyan S2881 Mainboard")
+ .enable_dev = enable_dev,
};