Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 1 | /* Copyright 2000 AG Electronics Ltd. */ |
| 2 | /* Copyright 2003-2004 Linux Networx */ |
| 3 | /* Copyright 2004 Tyan |
| 4 | By LYH change from PC87360 */ |
| 5 | /* This code is distributed without warranty under the GPL v2 (see COPYING) */ |
| 6 | |
| 7 | /* 2006-4-24 |
| 8 | * Adapted for the w83977 by rsmith <smithbone@gmail.com> |
| 9 | * This is mostly just a search and replace on the part type |
| 10 | * TODO: Actually see if all the sub functionis exist and are |
| 11 | * setup correctly. |
| 12 | */ |
| 13 | |
| 14 | #include <arch/io.h> |
| 15 | #include <device/device.h> |
| 16 | #include <device/pnp.h> |
| 17 | #include <console/console.h> |
| 18 | #include <string.h> |
| 19 | #include <bitops.h> |
| 20 | #include <uart8250.h> |
| 21 | #include <pc80/keyboard.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 23 | #include "chip.h" |
| 24 | #include "w83977tf.h" |
| 25 | |
| 26 | static void w83977tf_enter_ext_func_mode(device_t dev) |
| 27 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame^] | 28 | outb(0x87, dev->path.pnp.port); |
| 29 | outb(0x87, dev->path.pnp.port); |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 30 | } |
| 31 | static void w83977tf_exit_ext_func_mode(device_t dev) |
| 32 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame^] | 33 | outb(0xaa, dev->path.pnp.port); |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void w83977tf_init(device_t dev) |
| 37 | { |
| 38 | struct superio_winbond_w83977tf_config *conf; |
| 39 | struct resource *res0, *res1; |
| 40 | /* Wishlist handle well known programming interfaces more |
| 41 | * generically. |
| 42 | */ |
| 43 | if (!dev->enabled) { |
| 44 | return; |
| 45 | } |
| 46 | conf = dev->chip_info; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame^] | 47 | switch(dev->path.pnp.device) { |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 48 | case W83977TF_SP1: |
| 49 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 50 | init_uart8250(res0->base, &conf->com1); |
| 51 | break; |
| 52 | case W83977TF_SP2: |
| 53 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 54 | init_uart8250(res0->base, &conf->com2); |
| 55 | break; |
| 56 | case W83977TF_KBC: |
| 57 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 58 | res1 = find_resource(dev, PNP_IDX_IO1); |
| 59 | init_pc_keyboard(res0->base, res1->base, &conf->keyboard); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static void w83977tf_set_resources(device_t dev) |
| 65 | { |
| 66 | w83977tf_enter_ext_func_mode(dev); |
| 67 | pnp_set_resources(dev); |
| 68 | w83977tf_exit_ext_func_mode(dev); |
| 69 | } |
| 70 | |
| 71 | static void w83977tf_enable_resources(device_t dev) |
| 72 | { |
| 73 | w83977tf_enter_ext_func_mode(dev); |
| 74 | pnp_enable_resources(dev); |
| 75 | w83977tf_exit_ext_func_mode(dev); |
| 76 | } |
| 77 | |
| 78 | static void w83977tf_enable(device_t dev) |
| 79 | { |
| 80 | w83977tf_enter_ext_func_mode(dev); |
| 81 | pnp_enable(dev); |
| 82 | w83977tf_exit_ext_func_mode(dev); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | static struct device_operations ops = { |
| 87 | .read_resources = pnp_read_resources, |
| 88 | .set_resources = w83977tf_set_resources, |
| 89 | .enable_resources = w83977tf_enable_resources, |
| 90 | .enable = w83977tf_enable, |
| 91 | .init = w83977tf_init, |
| 92 | }; |
| 93 | |
| 94 | static struct pnp_info pnp_dev_info[] = { |
| 95 | { &ops, W83977TF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 96 | { &ops, W83977TF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 97 | { &ops, W83977TF_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 98 | { &ops, W83977TF_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 99 | // No 4 { 0,}, |
| 100 | { &ops, W83977TF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, }, |
| 101 | { &ops, W83977TF_CIR, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 102 | { &ops, W83977TF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, { 0x7ff, 0 }, {0x7fe, 4} }, |
| 103 | { &ops, W83977TF_ACPI, PNP_IRQ0, }, |
| 104 | }; |
| 105 | |
| 106 | static void enable_dev(device_t dev) |
| 107 | { |
| 108 | pnp_enable_devices(dev, &ops, |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 109 | ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | struct chip_operations superio_winbond_w83977tf_ops = { |
Uwe Hermann | a7aa29b | 2006-11-05 18:50:49 +0000 | [diff] [blame] | 113 | CHIP_NAME("Winbond W83977TF Super I/O") |
Richard Smith | 924f92f | 2006-07-29 17:40:36 +0000 | [diff] [blame] | 114 | .enable_dev = enable_dev, |
| 115 | }; |