blob: a716d1937d725a8267858b0a3f419b98ad4ae666 [file] [log] [blame]
Felix Held3f3eca92020-01-23 17:12:32 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
Stefan Reinauereca92fb2006-08-23 14:28:37 +00002
Uwe Hermannd82baa12006-12-05 14:13:10 +00003/* RAM-based driver for SMSC LPC47N217 Super I/O chip. */
Uwe Hermannd82baa12006-12-05 14:13:10 +00004
Stefan Reinauereca92fb2006-08-23 14:28:37 +00005#include <arch/io.h>
6#include <device/device.h>
7#include <device/pnp.h>
8#include <console/console.h>
Stefan Reinauereca92fb2006-08-23 14:28:37 +00009#include <assert.h>
Elyes HAOUAS2329a252019-05-15 22:11:18 +020010
Stefan Reinauereca92fb2006-08-23 14:28:37 +000011#include "lpc47n217.h"
12
Zheng Bao9db833b2009-12-28 09:59:44 +000013/* Forward declarations */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110014static void enable_dev(struct device *dev);
15static void lpc47n217_pnp_set_resources(struct device *dev);
16static void lpc47n217_pnp_enable_resources(struct device *dev);
17static void lpc47n217_pnp_enable(struct device *dev);
18static void lpc47n217_init(struct device *dev);
19static void lpc47n217_pnp_set_resource(struct device *dev, struct resource *resource);
20static void lpc47n217_pnp_set_iobase(struct device *dev, u16 iobase);
21static void lpc47n217_pnp_set_drq(struct device *dev, u8 drq);
22static void lpc47n217_pnp_set_irq(struct device *dev, u8 irq);
23static void lpc47n217_pnp_set_enable(struct device *dev, int enable);
24static void pnp_enter_conf_state(struct device *dev);
25static void pnp_exit_conf_state(struct device *dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000026
Stefan Reinauereca92fb2006-08-23 14:28:37 +000027struct chip_operations superio_smsc_lpc47n217_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +000028 CHIP_NAME("SMSC LPC47N217 Super I/O")
Stefan Reinauereca92fb2006-08-23 14:28:37 +000029 .enable_dev = enable_dev,
30};
31
32static struct device_operations ops = {
33 .read_resources = pnp_read_resources,
34 .set_resources = lpc47n217_pnp_set_resources,
35 .enable_resources = lpc47n217_pnp_enable_resources,
36 .enable = lpc47n217_pnp_enable,
37 .init = lpc47n217_init,
38};
39
40static struct pnp_info pnp_dev_info[] = {
Felix Heldb0d868e2018-07-06 23:39:00 +020041 { NULL, LPC47N217_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
42 { NULL, LPC47N217_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
43 { NULL, LPC47N217_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, }
Stefan Reinauereca92fb2006-08-23 14:28:37 +000044};
45
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000046/**
47 * Create device structures and allocate resources to devices specified in the
48 * pnp_dev_info array (above).
49 *
50 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +000051 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110052static void enable_dev(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +000053{
Felix Heldb0d868e2018-07-06 23:39:00 +020054 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000055}
56
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000057/**
58 * Configure the specified Super I/O device with the resources (I/O space,
59 * etc.) that have been allocate for it.
60 *
Uwe Hermanna69d9782010-11-15 19:35:14 +000061 * NOTE: Cannot use pnp_set_resources() here because it assumes chip
62 * support for logical devices, which the LPC47N217 doesn't have.
63 *
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000064 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +000065 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110066static void lpc47n217_pnp_set_resources(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +000067{
Myles Watsonc25cc112010-05-21 14:33:48 +000068 struct resource *res;
Stefan Reinauereca92fb2006-08-23 14:28:37 +000069
Zheng Bao9db833b2009-12-28 09:59:44 +000070 pnp_enter_conf_state(dev);
Uwe Hermanna69d9782010-11-15 19:35:14 +000071 for (res = dev->resource_list; res; res = res->next)
Myles Watsonc25cc112010-05-21 14:33:48 +000072 lpc47n217_pnp_set_resource(dev, res);
Zheng Bao9db833b2009-12-28 09:59:44 +000073 /* dump_pnp_device(dev); */
Elyes HAOUAS5bd5a9a2018-05-28 16:21:04 +020074 pnp_exit_conf_state(dev);
Zheng Bao9db833b2009-12-28 09:59:44 +000075}
Stefan Reinauereca92fb2006-08-23 14:28:37 +000076
Uwe Hermanna69d9782010-11-15 19:35:14 +000077/*
78 * NOTE: Cannot use pnp_enable_resources() here because it assumes chip
79 * support for logical devices, which the LPC47N217 doesn't have.
80 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110081static void lpc47n217_pnp_enable_resources(struct device *dev)
Zheng Bao9db833b2009-12-28 09:59:44 +000082{
83 pnp_enter_conf_state(dev);
Zheng Bao9db833b2009-12-28 09:59:44 +000084 lpc47n217_pnp_set_enable(dev, 1);
Zheng Bao9db833b2009-12-28 09:59:44 +000085 pnp_exit_conf_state(dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000086}
87
Uwe Hermanna69d9782010-11-15 19:35:14 +000088/*
89 * NOTE: Cannot use pnp_set_enable() here because it assumes chip
90 * support for logical devices, which the LPC47N217 doesn't have.
91 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110092static void lpc47n217_pnp_enable(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +000093{
Zheng Bao9db833b2009-12-28 09:59:44 +000094 pnp_enter_conf_state(dev);
Rudolf Marek0c8e6642011-02-19 14:51:31 +000095 lpc47n217_pnp_set_enable(dev, !!dev->enabled);
Zheng Bao9db833b2009-12-28 09:59:44 +000096 pnp_exit_conf_state(dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000097}
98
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000099/**
100 * Initialize the specified Super I/O device.
101 *
102 * Devices other than COM ports are ignored. For COM ports, we configure the
103 * baud rate.
104 *
105 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +0000106 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100107static void lpc47n217_init(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000108{
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000109 if (!dev->enabled)
110 return;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000111}
112
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100113static void lpc47n217_pnp_set_resource(struct device *dev, struct resource *resource)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000114{
115 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
zbao9bf356f2012-08-03 15:09:09 +0800116 printk(BIOS_ERR, "ERROR: %s %02lx not allocated\n",
Uwe Hermanna69d9782010-11-15 19:35:14 +0000117 dev_path(dev), resource->index);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000118 return;
119 }
120
Uwe Hermanna69d9782010-11-15 19:35:14 +0000121 /* Now store the resource. */
122
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000123 /*
124 * NOTE: Cannot use pnp_set_XXX() here because they assume chip
125 * support for logical devices, which the LPC47N217 doesn't have.
Zheng Bao9db833b2009-12-28 09:59:44 +0000126 */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000127 if (resource->flags & IORESOURCE_IO) {
128 lpc47n217_pnp_set_iobase(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000129 } else if (resource->flags & IORESOURCE_DRQ) {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000130 lpc47n217_pnp_set_drq(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000131 } else if (resource->flags & IORESOURCE_IRQ) {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000132 lpc47n217_pnp_set_irq(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000133 } else {
zbao9bf356f2012-08-03 15:09:09 +0800134 printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n",
Uwe Hermanna69d9782010-11-15 19:35:14 +0000135 dev_path(dev), resource->index);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000136 return;
137 }
138 resource->flags |= IORESOURCE_STORED;
139
140 report_resource_stored(dev, resource, "");
141}
142
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100143static void lpc47n217_pnp_set_iobase(struct device *dev, u16 iobase)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000144{
145 ASSERT(!(iobase & 0x3));
Zheng Bao9db833b2009-12-28 09:59:44 +0000146
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100147 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000148 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000149 pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
150 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000151 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000152 pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
153 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000154 case LPC47N217_SP2:
155 pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
156 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000157 default:
158 BUG();
159 break;
160 }
161}
162
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100163static void lpc47n217_pnp_set_drq(struct device *dev, u8 drq)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000164{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000165 const u8 PP_DMA_MASK = 0x0F;
166 const u8 PP_DMA_SELECTION_REGISTER = 0x26;
167 u8 current_config, new_config;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000168
Uwe Hermanna69d9782010-11-15 19:35:14 +0000169 if (dev->path.pnp.device == LPC47N217_PP) {
170 current_config = pnp_read_config(dev,
171 PP_DMA_SELECTION_REGISTER);
172 ASSERT(!(drq & ~PP_DMA_MASK)); /* DRQ out of range? */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000173 new_config = (current_config & ~PP_DMA_MASK) | drq;
174 pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config);
175 } else {
176 BUG();
177 }
178}
179
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100180static void lpc47n217_pnp_set_irq(struct device *dev, u8 irq)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000181{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000182 u8 irq_config_register = 0, irq_config_mask = 0;
183 u8 current_config, new_config;
Zheng Bao9db833b2009-12-28 09:59:44 +0000184
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100185 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000186 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000187 irq_config_register = 0x27;
188 irq_config_mask = 0x0F;
189 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000190 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000191 irq_config_register = 0x28;
192 irq_config_mask = 0xF0;
193 irq <<= 4;
194 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000195 case LPC47N217_SP2:
196 irq_config_register = 0x28;
197 irq_config_mask = 0x0F;
198 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000199 default:
200 BUG();
201 return;
202 }
203
Uwe Hermanna69d9782010-11-15 19:35:14 +0000204 ASSERT(!(irq & ~irq_config_mask)); /* IRQ out of range? */
Zheng Bao9db833b2009-12-28 09:59:44 +0000205
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000206 current_config = pnp_read_config(dev, irq_config_register);
207 new_config = (current_config & ~irq_config_mask) | irq;
208 pnp_write_config(dev, irq_config_register, new_config);
209}
210
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100211static void lpc47n217_pnp_set_enable(struct device *dev, int enable)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000212{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000213 u8 power_register = 0, power_mask = 0, current_power, new_power;
Zheng Bao9db833b2009-12-28 09:59:44 +0000214
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100215 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000216 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000217 power_register = 0x01;
218 power_mask = 0x04;
219 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000220 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000221 power_register = 0x02;
222 power_mask = 0x08;
223 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000224 case LPC47N217_SP2:
225 power_register = 0x02;
226 power_mask = 0x80;
227 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000228 default:
229 BUG();
230 return;
231 }
232
233 current_power = pnp_read_config(dev, power_register);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000234 new_power = current_power & ~power_mask; /* Disable by default. */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000235 if (enable) {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000236 struct resource* ioport_resource;
237 ioport_resource = find_resource(dev, PNP_IDX_IO0);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000238 lpc47n217_pnp_set_iobase(dev, ioport_resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000239 new_power |= power_mask; /* Enable. */
Zheng Bao9db833b2009-12-28 09:59:44 +0000240 } else {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000241 lpc47n217_pnp_set_iobase(dev, 0);
242 }
243 pnp_write_config(dev, power_register, new_power);
244}
245
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100246static void pnp_enter_conf_state(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000247{
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000248 outb(0x55, dev->path.pnp.port);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000249}
250
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100251static void pnp_exit_conf_state(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000252{
Zheng Bao9db833b2009-12-28 09:59:44 +0000253 outb(0xaa, dev->path.pnp.port);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000254}