blob: 911343d8904959e4085409dfc574b454e8da57b9 [file] [log] [blame]
Stefan Reinauer55426df2010-01-17 13:50:17 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2005 Digital Design Corporation
5 * Copyright (C) 2008-2009 coresystems GmbH
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
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.
Stefan Reinauer55426df2010-01-17 13:50:17 +000015 */
16
17/* RAM-based driver for SMSC LPC47N227 Super I/O chip. */
18
Stefan Reinauer55426df2010-01-17 13:50:17 +000019#include <device/device.h>
20#include <device/pnp.h>
21#include <console/console.h>
Stefan Reinauer55426df2010-01-17 13:50:17 +000022#include <assert.h>
Edward O'Callaghandef00be2014-04-30 05:01:52 +100023#include <pc80/keyboard.h>
Antonello Dettori6321d7c2016-03-07 01:59:48 +000024#include <superio/conf_mode.h>
25
Stefan Reinauer55426df2010-01-17 13:50:17 +000026#include "lpc47n227.h"
27
Uwe Hermanna69d9782010-11-15 19:35:14 +000028/* Forward declarations. */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110029static void enable_dev(struct device *dev);
30void lpc47n227_pnp_set_resources(struct device *dev);
31void lpc47n227_pnp_enable_resources(struct device *dev);
32void lpc47n227_pnp_enable(struct device *dev);
33static void lpc47n227_init(struct device *dev);
34static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource);
35void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase);
36void lpc47n227_pnp_set_drq(struct device *dev, u8 drq);
37void lpc47n227_pnp_set_irq(struct device *dev, u8 irq);
38void lpc47n227_pnp_set_enable(struct device *dev, int enable);
Stefan Reinauer55426df2010-01-17 13:50:17 +000039
40struct chip_operations superio_smsc_lpc47n227_ops = {
41 CHIP_NAME("SMSC LPC47N227 Super I/O")
Uwe Hermanna69d9782010-11-15 19:35:14 +000042 .enable_dev = enable_dev,
Stefan Reinauer55426df2010-01-17 13:50:17 +000043};
44
45static struct device_operations ops = {
Uwe Hermanna69d9782010-11-15 19:35:14 +000046 .read_resources = pnp_read_resources,
47 .set_resources = lpc47n227_pnp_set_resources,
Stefan Reinauer55426df2010-01-17 13:50:17 +000048 .enable_resources = lpc47n227_pnp_enable_resources,
Uwe Hermanna69d9782010-11-15 19:35:14 +000049 .enable = lpc47n227_pnp_enable,
50 .init = lpc47n227_init,
Patrick Rudolph98b72da2019-12-10 12:08:37 +010051 .ops_pnp_mode = &pnp_conf_mode_55_aa,
Stefan Reinauer55426df2010-01-17 13:50:17 +000052};
53
54static struct pnp_info pnp_dev_info[] = {
Felix Heldb0d868e2018-07-06 23:39:00 +020055 { NULL, LPC47N227_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
56 { NULL, LPC47N227_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
57 { NULL, LPC47N227_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
58 { NULL, LPC47N227_KBDC, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07f8, 0x07f8, },
Stefan Reinauer55426df2010-01-17 13:50:17 +000059};
60
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000061/**
62 * Create device structures and allocate resources to devices specified in the
63 * pnp_dev_info array (above).
64 *
65 * @param dev Pointer to structure describing a Super I/O device.
66 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110067static void enable_dev(struct device *dev)
Stefan Reinauer55426df2010-01-17 13:50:17 +000068{
Felix Heldb0d868e2018-07-06 23:39:00 +020069 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Stefan Reinauer55426df2010-01-17 13:50:17 +000070}
71
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000072/**
73 * Configure the specified Super I/O device with the resources (I/O space,
74 * etc.) that have been allocate for it.
75 *
Uwe Hermanna69d9782010-11-15 19:35:14 +000076 * NOTE: Cannot use pnp_set_resources() here because it assumes chip
77 * support for logical devices, which the LPC47N227 doesn't have.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070078 *
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000079 * @param dev Pointer to structure describing a Super I/O device.
80 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110081void lpc47n227_pnp_set_resources(struct device *dev)
Stefan Reinauer55426df2010-01-17 13:50:17 +000082{
Myles Watsonc25cc112010-05-21 14:33:48 +000083 struct resource *res;
Stefan Reinauer55426df2010-01-17 13:50:17 +000084
Patrick Rudolph98b72da2019-12-10 12:08:37 +010085 pnp_enter_conf_mode(dev);
Myles Watsonc25cc112010-05-21 14:33:48 +000086 for (res = dev->resource_list; res; res = res->next)
87 lpc47n227_pnp_set_resource(dev, res);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010088 pnp_exit_conf_mode(dev);
Stefan Reinauer55426df2010-01-17 13:50:17 +000089}
90
Uwe Hermanna69d9782010-11-15 19:35:14 +000091/*
92 * NOTE: Cannot use pnp_enable_resources() here because it assumes chip
93 * support for logical devices, which the LPC47N227 doesn't have.
94 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110095void lpc47n227_pnp_enable_resources(struct device *dev)
Stefan Reinauer55426df2010-01-17 13:50:17 +000096{
Patrick Rudolph98b72da2019-12-10 12:08:37 +010097 pnp_enter_conf_mode(dev);
Stefan Reinauer55426df2010-01-17 13:50:17 +000098 lpc47n227_pnp_set_enable(dev, 1);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010099 pnp_exit_conf_mode(dev);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000100}
101
Uwe Hermanna69d9782010-11-15 19:35:14 +0000102/*
103 * NOTE: Cannot use pnp_set_enable() here because it assumes chip
104 * support for logical devices, which the LPC47N227 doesn't have.
105 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100106void lpc47n227_pnp_enable(struct device *dev)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000107{
Patrick Rudolph98b72da2019-12-10 12:08:37 +0100108 pnp_enter_conf_mode(dev);
Rudolf Marek0c8e6642011-02-19 14:51:31 +0000109 lpc47n227_pnp_set_enable(dev, !!dev->enabled);
Patrick Rudolph98b72da2019-12-10 12:08:37 +0100110 pnp_exit_conf_mode(dev);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000111}
112
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000113/**
114 * Initialize the specified Super I/O device.
115 *
116 * Devices other than COM ports and keyboard controller are ignored.
117 * For COM ports, we configure the baud rate.
118 *
119 * @param dev Pointer to structure describing a Super I/O device.
120 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100121static void lpc47n227_init(struct device *dev)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000122{
Stefan Reinauer55426df2010-01-17 13:50:17 +0000123
124 if (!dev->enabled)
125 return;
126
127 switch (dev->path.pnp.device) {
Stefan Reinauer55426df2010-01-17 13:50:17 +0000128 case LPC47N227_KBDC:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_DEBUG, "LPC47N227: Initializing keyboard.\n");
Timothy Pearson448e3862015-11-24 14:12:01 -0600130 pc_keyboard_init(NO_AUX_DEVICE);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000131 break;
132 }
133}
134
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100135static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000136{
137 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000138 printk(BIOS_ERR, "ERROR: %s %02lx not allocated\n",
Uwe Hermanna69d9782010-11-15 19:35:14 +0000139 dev_path(dev), resource->index);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000140 return;
141 }
142
Uwe Hermanna69d9782010-11-15 19:35:14 +0000143 /* Now store the resource. */
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000144 /*
145 * NOTE: Cannot use pnp_set_XXX() here because they assume chip
146 * support for logical devices, which the LPC47N227 doesn't have.
147 */
Stefan Reinauer55426df2010-01-17 13:50:17 +0000148 if (resource->flags & IORESOURCE_IO) {
149 lpc47n227_pnp_set_iobase(dev, resource->base);
150 } else if (resource->flags & IORESOURCE_DRQ) {
151 lpc47n227_pnp_set_drq(dev, resource->base);
152 } else if (resource->flags & IORESOURCE_IRQ) {
153 lpc47n227_pnp_set_irq(dev, resource->base);
154 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000155 printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n",
Uwe Hermanna69d9782010-11-15 19:35:14 +0000156 dev_path(dev), resource->index);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000157 return;
158 }
159 resource->flags |= IORESOURCE_STORED;
160
161 report_resource_stored(dev, resource, "");
162}
163
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100164void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000165{
166 ASSERT(!(iobase & 0x3));
167
168 switch (dev->path.pnp.device) {
169 case LPC47N227_PP:
170 pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
171 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000172 case LPC47N227_SP1:
173 pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
174 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000175 case LPC47N227_SP2:
176 pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
177 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000178 case LPC47N227_KBDC:
179 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000180 default:
181 BUG();
182 break;
183 }
184}
185
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100186void lpc47n227_pnp_set_drq(struct device *dev, u8 drq)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000187{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000188 const u8 PP_DMA_MASK = 0x0F;
189 const u8 PP_DMA_SELECTION_REGISTER = 0x26;
190 u8 current_config, new_config;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000191
Uwe Hermanna69d9782010-11-15 19:35:14 +0000192 if (dev->path.pnp.device == LPC47N227_PP) {
193 current_config = pnp_read_config(dev,
194 PP_DMA_SELECTION_REGISTER);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000195 ASSERT(!(drq & ~PP_DMA_MASK)); // DRQ out of range??
Stefan Reinauer55426df2010-01-17 13:50:17 +0000196 new_config = (current_config & ~PP_DMA_MASK) | drq;
197 pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config);
198 } else {
199 BUG();
200 }
201}
202
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100203void lpc47n227_pnp_set_irq(struct device *dev, u8 irq)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000204{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000205 u8 irq_config_register = 0, irq_config_mask = 0;
206 u8 current_config, new_config;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000207
208 switch (dev->path.pnp.device) {
209 case LPC47N227_PP:
210 irq_config_register = 0x27;
211 irq_config_mask = 0x0F;
212 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000213 case LPC47N227_SP1:
214 irq_config_register = 0x28;
215 irq_config_mask = 0xF0;
216 irq <<= 4;
217 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000218 case LPC47N227_SP2:
219 irq_config_register = 0x28;
220 irq_config_mask = 0x0F;
221 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000222 case LPC47N227_KBDC:
223 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000224 default:
225 BUG();
226 return;
227 }
228
229 current_config = pnp_read_config(dev, irq_config_register);
230 new_config = (current_config & ~irq_config_mask) | irq;
231 pnp_write_config(dev, irq_config_register, new_config);
232}
233
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100234void lpc47n227_pnp_set_enable(struct device *dev, int enable)
Stefan Reinauer55426df2010-01-17 13:50:17 +0000235{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000236 u8 power_register = 0, power_mask = 0, current_power, new_power;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000237
238 switch (dev->path.pnp.device) {
239 case LPC47N227_PP:
240 power_register = 0x01;
241 power_mask = 0x04;
242 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000243 case LPC47N227_SP1:
244 power_register = 0x02;
245 power_mask = 0x08;
246 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000247 case LPC47N227_SP2:
248 power_register = 0x02;
249 power_mask = 0x80;
250 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000251 case LPC47N227_KBDC:
252 break;
Stefan Reinauer55426df2010-01-17 13:50:17 +0000253 default:
254 BUG();
255 return;
256 }
257
258 current_power = pnp_read_config(dev, power_register);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000259 new_power = current_power & ~power_mask; /* Disable by default. */
Stefan Reinauer55426df2010-01-17 13:50:17 +0000260 if (enable) {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000261 struct resource *ioport_resource;
262 ioport_resource = find_resource(dev, PNP_IDX_IO0);
Stefan Reinauer55426df2010-01-17 13:50:17 +0000263 lpc47n227_pnp_set_iobase(dev, ioport_resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000264 new_power |= power_mask; /* Enable. */
Stefan Reinauer55426df2010-01-17 13:50:17 +0000265 } else {
266 lpc47n227_pnp_set_iobase(dev, 0);
267 }
268 pnp_write_config(dev, power_register, new_power);
269}