1 /* Copyright 2000 AG Electronics Ltd. */
2 /* Copyright 2003-2004 Linux Networx */
6 /* This code is distributed without warranty under the GPL v2 (see COPYING) */
9 #include <device/device.h>
10 #include <device/pnp.h>
11 #include <console/console.h>
12 #include <device/smbus.h>
16 #include <pc80/keyboard.h>
18 #include "lpc47b397.h"
21 static void pnp_enter_conf_state(device_t dev) {
22 outb(0x55, dev->path.u.pnp.port);
24 static void pnp_exit_conf_state(device_t dev) {
25 outb(0xaa, dev->path.u.pnp.port);
28 static void pnp_write_index(unsigned long port_base, uint8_t reg, uint8_t value)
31 outb(value, port_base + 1);
34 static uint8_t pnp_read_index(unsigned long port_base, uint8_t reg)
37 return inb(port_base + 1);
40 static void enable_hwm_smbus(device_t dev) {
41 /* enable SensorBus register access */
44 value = pnp_read_config(dev, reg);
46 pnp_write_config(dev, reg, value);
49 static void dump_pnp_device(device_t dev)
54 for(i = 0; i <= 255; i++) {
56 if ((i & 0x0f) == 0) {
58 print_debug_char(':');
62 val = pnp_read_config(dev, reg);
67 print_debug_char(' ');
68 print_debug_hex8(val);
69 if ((i & 0x0f) == 0x0f) {
77 static void lpc47b397_init(device_t dev)
79 struct superio_smsc_lpc47b397_config *conf;
80 struct resource *res0, *res1;
84 conf = dev->chip_info;
85 switch(dev->path.u.pnp.device) {
87 res0 = find_resource(dev, PNP_IDX_IO0);
88 init_uart8250(res0->base, &conf->com1);
91 res0 = find_resource(dev, PNP_IDX_IO0);
92 init_uart8250(res0->base, &conf->com2);
95 res0 = find_resource(dev, PNP_IDX_IO0);
96 res1 = find_resource(dev, PNP_IDX_IO1);
97 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
103 void lpc47b397_pnp_set_resources(device_t dev)
106 pnp_enter_conf_state(dev);
108 pnp_set_resources(dev);
111 dump_pnp_device(dev);
114 pnp_exit_conf_state(dev);
118 void lpc47b397_pnp_enable_resources(device_t dev)
121 pnp_enter_conf_state(dev);
123 pnp_enable_resources(dev);
125 switch(dev->path.u.pnp.device) {
127 printk_debug("lpc47b397 SensorBus Register Access enabled\r\n");
128 pnp_set_logical_device(dev);
129 enable_hwm_smbus(dev);
134 dump_pnp_device(dev);
137 pnp_exit_conf_state(dev);
141 void lpc47b397_pnp_enable(device_t dev)
144 pnp_enter_conf_state(dev);
146 pnp_set_logical_device(dev);
149 pnp_set_enable(dev, 1);
152 pnp_set_enable(dev, 0);
155 pnp_exit_conf_state(dev);
159 static struct device_operations ops = {
160 .read_resources = pnp_read_resources,
161 .set_resources = lpc47b397_pnp_set_resources,
162 .enable_resources = lpc47b397_pnp_enable_resources,
163 .enable = lpc47b397_pnp_enable,
164 .init = lpc47b397_init,
170 #define SB_INDEX 0x0b
171 #define SB_DATA0 0x0c
172 #define SB_DATA1 0x0d
173 #define SB_DATA2 0x0e
174 #define SB_DATA3 0x0f
176 static int lsmbus_read_byte(device_t dev, uint8_t address)
179 struct resource *res;
182 device = dev->path.u.i2c.device;
184 res = find_resource(get_pbus_smbus(dev)->dev, PNP_IDX_IO0);
186 pnp_write_index(res->base+HWM_INDEX, 0, device); // why 0?
188 result = pnp_read_index(res->base+SB_INDEX, address); // we only read it one byte one time
193 static int lsmbus_write_byte(device_t dev, uint8_t address, uint8_t val)
196 struct resource *res;
198 device = dev->path.u.i2c.device;
199 res = find_resource(get_pbus_smbus(dev)->dev, PNP_IDX_IO0);
201 pnp_write_index(res->base+HWM_INDEX, 0, device); // why 0?
203 pnp_write_index(res->base+SB_INDEX, address, val); // we only write it one byte one time
208 static struct smbus_bus_operations lops_smbus_bus = {
209 // .recv_byte = lsmbus_recv_byte,
210 // .send_byte = lsmbus_send_byte,
211 .read_byte = lsmbus_read_byte,
212 .write_byte = lsmbus_write_byte,
214 static struct device_operations ops_hwm = {
215 .read_resources = pnp_read_resources,
216 .set_resources = lpc47b397_pnp_set_resources,
217 .enable_resources = lpc47b397_pnp_enable_resources,
218 .enable = lpc47b397_pnp_enable,
219 .init = lpc47b397_init,
220 .scan_bus = scan_static_bus,
221 .ops_smbus_bus = &lops_smbus_bus,
224 static struct pnp_info pnp_dev_info[] = {
225 { &ops, LPC47B397_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
226 { &ops, LPC47B397_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
227 { &ops, LPC47B397_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
228 { &ops, LPC47B397_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
229 { &ops, LPC47B397_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
230 { &ops_hwm, LPC47B397_HWM, PNP_IO0, { 0x7f0, 0 }, },
231 { &ops, LPC47B397_RT, PNP_IO0, { 0x780, 0 }, },
234 static void enable_dev(struct device *dev)
236 pnp_enable_devices(dev, &pnp_ops,
237 sizeof(pnp_dev_info)/sizeof(pnp_dev_info[0]), pnp_dev_info);
240 struct chip_operations superio_smsc_lpc47b397_ops = {
241 CHIP_NAME("smsc lpc47b397")
242 .enable_dev = enable_dev,