Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Sean Nelson <snelson@nmt.edu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pnp.h> |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 20 | #include <superio/conf_mode.h> |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <string.h> |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 23 | #include <lib.h> |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 24 | #include <pc80/mc146818rtc.h> |
| 25 | #include <stdlib.h> |
Edward O'Callaghan | def00be | 2014-04-30 05:01:52 +1000 | [diff] [blame] | 26 | #include <pc80/keyboard.h> |
Edward O'Callaghan | 0403c863 | 2014-04-30 17:17:03 +1000 | [diff] [blame] | 27 | #include "chip.h" |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 28 | #include "w83697hf.h" |
| 29 | |
Florian Zumbiehl | 85392a8 | 2011-11-01 20:19:06 +0100 | [diff] [blame] | 30 | static void hwmon_set_fan_divisor(unsigned int base, int num, unsigned int divisor) { |
| 31 | unsigned char enc, buf; |
| 32 | |
| 33 | if (divisor) { |
| 34 | enc = log2(divisor); |
| 35 | if (1 << enc != divisor || enc > 7) |
| 36 | die("invalid fan divisor"); |
| 37 | outb(0x4e, base + 5); |
| 38 | outb(0x00, base + 6); |
| 39 | outb(0x47, base + 5); |
| 40 | outb((inb(base + 6) & ~(0x30 << (num * 2))) | ((enc & 3) << (4 + num * 2)), base + 6); |
| 41 | outb(0x5d, base + 5); |
| 42 | buf = inb(base + 6); |
| 43 | /* the above inb() auto-increments the address pointer ... */ |
| 44 | outb(0x5d, base + 5); |
| 45 | outb((buf & ~(0x20 << num)) | ((enc & 4) << (3 + num)), base + 6); |
| 46 | } |
| 47 | } |
| 48 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 49 | static void w83697hf_init(struct device *dev) |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 50 | { |
Florian Zumbiehl | 85392a8 | 2011-11-01 20:19:06 +0100 | [diff] [blame] | 51 | struct resource *res0; |
| 52 | struct superio_winbond_w83697hf_config *cfg; |
| 53 | |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 54 | if (!dev->enabled) |
| 55 | return; |
Florian Zumbiehl | 85392a8 | 2011-11-01 20:19:06 +0100 | [diff] [blame] | 56 | |
| 57 | cfg = dev->chip_info; |
| 58 | |
| 59 | switch (dev->path.pnp.device) { |
| 60 | case W83697HF_HWM: |
| 61 | if (cfg) { |
| 62 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 63 | hwmon_set_fan_divisor(res0->base, 0, cfg->hwmon_fan1_divisor); |
| 64 | hwmon_set_fan_divisor(res0->base, 1, cfg->hwmon_fan2_divisor); |
| 65 | } |
| 66 | break; |
| 67 | } |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 70 | static struct device_operations ops = { |
| 71 | .read_resources = pnp_read_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 72 | .set_resources = pnp_set_resources, |
| 73 | .enable_resources = pnp_enable_resources, |
| 74 | .enable = pnp_alt_enable, |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 75 | .init = w83697hf_init, |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 76 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static struct pnp_info pnp_dev_info[] = { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 80 | { &ops, W83697HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 81 | { &ops, W83697HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 82 | { &ops, W83697HF_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 83 | { &ops, W83697HF_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 84 | { &ops, W83697HF_CIR, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 85 | { &ops, W83697HF_GAME_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x07ff, 0}, {0x07fe, 4}, }, |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 86 | { &ops, W83697HF_MIDI_GPIO5, }, |
| 87 | { &ops, W83697HF_GPIO234, }, |
| 88 | { &ops, W83697HF_ACPI, }, |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 89 | { &ops, W83697HF_HWM, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, }, |
Sean Nelson | 3d135e6 | 2008-07-21 14:49:04 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static void enable_dev(struct device *dev) |
| 93 | { |
| 94 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 95 | } |
| 96 | |
| 97 | struct chip_operations superio_winbond_w83697hf_ops = { |
| 98 | CHIP_NAME("Winbond W83697HF Super I/O") |
| 99 | .enable_dev = enable_dev, |
| 100 | }; |