blob: bbdb7bffa992f79d68ec50ff2fa13fc87f267f0d [file] [log] [blame]
Ronald G. Minnich142babf2004-03-12 16:54:31 +00001/* Copyright 2000 AG Electronics Ltd. */
2/* Copyright 2003-2004 Linux Networx */
Myles Watsoncee94382008-10-02 19:21:30 +00003/* Copyright 2004 Tyan
Ronald G. Minnich142babf2004-03-12 16:54:31 +00004 By LYH change from PC87360 */
5/* This code is distributed without warranty under the GPL v2 (see COPYING) */
6
7#include <arch/io.h>
8#include <device/device.h>
9#include <device/pnp.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000010#include <console/console.h>
11#include <string.h>
12#include <bitops.h>
13#include <uart8250.h>
14#include <pc80/keyboard.h>
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000015#include <pc80/mc146818rtc.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000016#include <stdlib.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000017#include "chip.h"
18#include "w83627hf.h"
19
Yinghai Lu70093f72004-07-01 03:55:03 +000020
Myles Watsoncee94382008-10-02 19:21:30 +000021static void pnp_enter_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000022{
Myles Watsoncee94382008-10-02 19:21:30 +000023 outb(0x87, dev->path.u.pnp.port);
24 outb(0x87, dev->path.u.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000025}
Myles Watsoncee94382008-10-02 19:21:30 +000026static void pnp_exit_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000027{
Myles Watsoncee94382008-10-02 19:21:30 +000028 outb(0xaa, dev->path.u.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000029}
30
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000031static void pnp_write_index(unsigned long port_base, uint8_t reg, uint8_t value)
Yinghai Lu70093f72004-07-01 03:55:03 +000032{
Myles Watsoncee94382008-10-02 19:21:30 +000033 outb(reg, port_base);
34 outb(value, port_base + 1);
Yinghai Lu70093f72004-07-01 03:55:03 +000035}
36
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000037static uint8_t pnp_read_index(unsigned long port_base, uint8_t reg)
Yinghai Lu70093f72004-07-01 03:55:03 +000038{
Myles Watsoncee94382008-10-02 19:21:30 +000039 outb(reg, port_base);
40 return inb(port_base + 1);
41}
Yinghai Lu70093f72004-07-01 03:55:03 +000042
43static void enable_hwm_smbus(device_t dev) {
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000044 /* set the pin 91,92 as I2C bus */
Yinghai Lu70093f72004-07-01 03:55:03 +000045 uint8_t reg, value;
46 reg = 0x2b;
47 value = pnp_read_config(dev, reg);
48 value &= 0x3f;
49 pnp_write_config(dev, reg, value);
50}
51
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000052static void init_acpi(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +000053{
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000054 uint8_t value = 0x20;
55 int power_on = 1;
Yinghai Lu70093f72004-07-01 03:55:03 +000056
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000057 get_option(&power_on, "power_on_after_fail");
58 pnp_enter_ext_func_mode(dev);
Myles Watsoncee94382008-10-02 19:21:30 +000059 pnp_write_index(dev->path.u.pnp.port,7,0x0a);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000060 value = pnp_read_config(dev, 0xE4);
61 value &= ~(3<<5);
62 if(power_on) {
63 value |= (1<<5);
64 }
65 pnp_write_config(dev, 0xE4, value);
Myles Watsoncee94382008-10-02 19:21:30 +000066 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +000067}
Yinghai Lu70093f72004-07-01 03:55:03 +000068
69static void init_hwm(unsigned long base)
70{
71 uint8_t reg, value;
72 int i;
73
74 unsigned hwm_reg_values[] = {
Myles Watsoncee94382008-10-02 19:21:30 +000075/* reg mask data */
76 0x40, 0xff, 0x81, /* start HWM */
77 0x48, 0xaa, 0x2a, /* set SMBus base to 0x54>>1 */
78 0x4a, 0x21, 0x21, /* set T2 SMBus base to 0x92>>1 and T3 SMBus base to 0x94>>1 */
79 0x4e, 0x80, 0x00,
80 0x43, 0x00, 0xff,
81 0x44, 0x00, 0x3f,
82 0x4c, 0xbf, 0x18,
83 0x4d, 0xff, 0x80 /* turn off beep */
84
Yinghai Lu70093f72004-07-01 03:55:03 +000085 };
86
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000087 for(i = 0; i< ARRAY_SIZE(hwm_reg_values); i+=3 ) {
Yinghai Lu70093f72004-07-01 03:55:03 +000088 reg = hwm_reg_values[i];
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000089 value = pnp_read_index(base, reg);
Yinghai Lu70093f72004-07-01 03:55:03 +000090 value &= 0xff & hwm_reg_values[i+1];
91 value |= 0xff & hwm_reg_values[i+2];
92#if 0
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000093 printk_debug("base = 0x%04x, reg = 0x%02x, value = 0x%02x\r\n", base, reg,value);
Yinghai Lu70093f72004-07-01 03:55:03 +000094#endif
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000095 pnp_write_index(base, reg, value);
Yinghai Lu70093f72004-07-01 03:55:03 +000096 }
97}
98
Yinghai Lu70093f72004-07-01 03:55:03 +000099static void w83627hf_init(device_t dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000100{
101 struct superio_winbond_w83627hf_config *conf;
102 struct resource *res0, *res1;
Li-Ta Lo69c5a902004-04-29 20:08:54 +0000103 if (!dev->enabled) {
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000104 return;
105 }
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000106 conf = dev->chip_info;
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000107 switch(dev->path.u.pnp.device) {
Myles Watsoncee94382008-10-02 19:21:30 +0000108 case W83627HF_SP1:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000109 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000110 init_uart8250(res0->base, &conf->com1);
111 break;
112 case W83627HF_SP2:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000113 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000114 init_uart8250(res0->base, &conf->com2);
115 break;
116 case W83627HF_KBC:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000117 res0 = find_resource(dev, PNP_IDX_IO0);
118 res1 = find_resource(dev, PNP_IDX_IO1);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000119 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
120 break;
Myles Watsoncee94382008-10-02 19:21:30 +0000121 case W83627HF_HWM:
122 res0 = find_resource(dev, PNP_IDX_IO0);
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000123#define HWM_INDEX_PORT 5
Myles Watsoncee94382008-10-02 19:21:30 +0000124 init_hwm(res0->base + HWM_INDEX_PORT);
125 break;
126 case W83627HF_ACPI:
127 init_acpi(dev);
128 break;
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000129 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000130}
131
132void w83627hf_pnp_set_resources(device_t dev)
133{
Myles Watsoncee94382008-10-02 19:21:30 +0000134 pnp_enter_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000135 pnp_set_resources(dev);
Myles Watsoncee94382008-10-02 19:21:30 +0000136 pnp_exit_ext_func_mode(dev);
137
138}
139
Yinghai Lu70093f72004-07-01 03:55:03 +0000140void w83627hf_pnp_enable_resources(device_t dev)
Myles Watsoncee94382008-10-02 19:21:30 +0000141{
142 pnp_enter_ext_func_mode(dev);
143 pnp_enable_resources(dev);
144 switch(dev->path.u.pnp.device) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000145 case W83627HF_HWM:
Stefan Reinauere74f91a2005-01-13 18:58:41 +0000146 printk_debug("w83627hf hwm smbus enabled\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000147 enable_hwm_smbus(dev);
148 break;
149 }
Myles Watsoncee94382008-10-02 19:21:30 +0000150 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000151
152}
153
154void w83627hf_pnp_enable(device_t dev)
155{
156
Myles Watsoncee94382008-10-02 19:21:30 +0000157 if (!dev->enabled) {
158 pnp_enter_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000159
Myles Watsoncee94382008-10-02 19:21:30 +0000160 pnp_set_logical_device(dev);
161 pnp_set_enable(dev, 0);
Yinghai Lu70093f72004-07-01 03:55:03 +0000162
Myles Watsoncee94382008-10-02 19:21:30 +0000163 pnp_exit_ext_func_mode(dev);
164 }
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000165}
166
167static struct device_operations ops = {
168 .read_resources = pnp_read_resources,
Yinghai Lu70093f72004-07-01 03:55:03 +0000169 .set_resources = w83627hf_pnp_set_resources,
170 .enable_resources = w83627hf_pnp_enable_resources,
171 .enable = w83627hf_pnp_enable,
172 .init = w83627hf_init,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000173};
174
175static struct pnp_info pnp_dev_info[] = {
Myles Watsoncee94382008-10-02 19:21:30 +0000176 { &ops, W83627HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
177 { &ops, W83627HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
178 { &ops, W83627HF_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
179 { &ops, W83627HF_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
180 // No 4 { 0,},
181 { &ops, W83627HF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
182 { &ops, W83627HF_CIR, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
183 { &ops, W83627HF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, { 0x7ff, 0 }, {0x7fe, 0x4}, },
184 { &ops, W83627HF_GPIO2, },
185 { &ops, W83627HF_GPIO3, },
186 { &ops, W83627HF_ACPI, },
187 { &ops, W83627HF_HWM, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000188};
189
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000190static void enable_dev(struct device *dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000191{
Eric Biederman69afe282004-11-11 06:53:24 +0000192 pnp_enable_devices(dev, &ops,
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +0000193 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000194}
195
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000196struct chip_operations superio_winbond_w83627hf_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +0000197 CHIP_NAME("Winbond W83627HF Super I/O")
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000198 .enable_dev = enable_dev,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000199};