blob: b10e8a1b281286065c63b8c10e034d07da21b4f4 [file] [log] [blame]
Stefan Reinauereca92fb2006-08-23 14:28:37 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Stefan Reinauereca92fb2006-08-23 14:28:37 +00003 *
Uwe Hermannd82baa12006-12-05 14:13:10 +00004 * Copyright (C) 2000 AG Electronics Ltd.
5 * Copyright (C) 2003-2004 Linux Networx
Zheng Bao9db833b2009-12-28 09:59:44 +00006 * Copyright (C) 2004 Tyan
Stefan Reinauereca92fb2006-08-23 14:28:37 +00007 * Copyright (C) 2005 Digital Design Corporation
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Stefan Reinauereca92fb2006-08-23 14:28:37 +000018 */
19
Uwe Hermannd82baa12006-12-05 14:13:10 +000020/* RAM-based driver for SMSC LPC47N217 Super I/O chip. */
Uwe Hermannd82baa12006-12-05 14:13:10 +000021
Stefan Reinauereca92fb2006-08-23 14:28:37 +000022#include <arch/io.h>
23#include <device/device.h>
24#include <device/pnp.h>
25#include <console/console.h>
26#include <device/smbus.h>
Stefan Reinauereca92fb2006-08-23 14:28:37 +000027#include <assert.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000028#include <stdlib.h>
Stefan Reinauereca92fb2006-08-23 14:28:37 +000029#include "lpc47n217.h"
30
Zheng Bao9db833b2009-12-28 09:59:44 +000031/* Forward declarations */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110032static void enable_dev(struct device *dev);
33static void lpc47n217_pnp_set_resources(struct device *dev);
34static void lpc47n217_pnp_enable_resources(struct device *dev);
35static void lpc47n217_pnp_enable(struct device *dev);
36static void lpc47n217_init(struct device *dev);
37static void lpc47n217_pnp_set_resource(struct device *dev, struct resource *resource);
38static void lpc47n217_pnp_set_iobase(struct device *dev, u16 iobase);
39static void lpc47n217_pnp_set_drq(struct device *dev, u8 drq);
40static void lpc47n217_pnp_set_irq(struct device *dev, u8 irq);
41static void lpc47n217_pnp_set_enable(struct device *dev, int enable);
42static void pnp_enter_conf_state(struct device *dev);
43static void pnp_exit_conf_state(struct device *dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000044
Stefan Reinauereca92fb2006-08-23 14:28:37 +000045struct chip_operations superio_smsc_lpc47n217_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +000046 CHIP_NAME("SMSC LPC47N217 Super I/O")
Stefan Reinauereca92fb2006-08-23 14:28:37 +000047 .enable_dev = enable_dev,
48};
49
50static struct device_operations ops = {
51 .read_resources = pnp_read_resources,
52 .set_resources = lpc47n217_pnp_set_resources,
53 .enable_resources = lpc47n217_pnp_enable_resources,
54 .enable = lpc47n217_pnp_enable,
55 .init = lpc47n217_init,
56};
57
58static struct pnp_info pnp_dev_info[] = {
Felix Heldb0d868e2018-07-06 23:39:00 +020059 { NULL, LPC47N217_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
60 { NULL, LPC47N217_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
61 { NULL, LPC47N217_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, }
Stefan Reinauereca92fb2006-08-23 14:28:37 +000062};
63
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000064/**
65 * Create device structures and allocate resources to devices specified in the
66 * pnp_dev_info array (above).
67 *
68 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +000069 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110070static void enable_dev(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +000071{
Felix Heldb0d868e2018-07-06 23:39:00 +020072 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Stefan Reinauereca92fb2006-08-23 14:28:37 +000073}
74
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000075/**
76 * Configure the specified Super I/O device with the resources (I/O space,
77 * etc.) that have been allocate for it.
78 *
Uwe Hermanna69d9782010-11-15 19:35:14 +000079 * NOTE: Cannot use pnp_set_resources() here because it assumes chip
80 * support for logical devices, which the LPC47N217 doesn't have.
81 *
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000082 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +000083 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110084static void lpc47n217_pnp_set_resources(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +000085{
Myles Watsonc25cc112010-05-21 14:33:48 +000086 struct resource *res;
Stefan Reinauereca92fb2006-08-23 14:28:37 +000087
Zheng Bao9db833b2009-12-28 09:59:44 +000088 pnp_enter_conf_state(dev);
Uwe Hermanna69d9782010-11-15 19:35:14 +000089 for (res = dev->resource_list; res; res = res->next)
Myles Watsonc25cc112010-05-21 14:33:48 +000090 lpc47n217_pnp_set_resource(dev, res);
Zheng Bao9db833b2009-12-28 09:59:44 +000091 /* dump_pnp_device(dev); */
Elyes HAOUAS5bd5a9a2018-05-28 16:21:04 +020092 pnp_exit_conf_state(dev);
Zheng Bao9db833b2009-12-28 09:59:44 +000093}
Stefan Reinauereca92fb2006-08-23 14:28:37 +000094
Uwe Hermanna69d9782010-11-15 19:35:14 +000095/*
96 * NOTE: Cannot use pnp_enable_resources() here because it assumes chip
97 * support for logical devices, which the LPC47N217 doesn't have.
98 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110099static void lpc47n217_pnp_enable_resources(struct device *dev)
Zheng Bao9db833b2009-12-28 09:59:44 +0000100{
101 pnp_enter_conf_state(dev);
Zheng Bao9db833b2009-12-28 09:59:44 +0000102 lpc47n217_pnp_set_enable(dev, 1);
Zheng Bao9db833b2009-12-28 09:59:44 +0000103 pnp_exit_conf_state(dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000104}
105
Uwe Hermanna69d9782010-11-15 19:35:14 +0000106/*
107 * NOTE: Cannot use pnp_set_enable() here because it assumes chip
108 * support for logical devices, which the LPC47N217 doesn't have.
109 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100110static void lpc47n217_pnp_enable(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000111{
Zheng Bao9db833b2009-12-28 09:59:44 +0000112 pnp_enter_conf_state(dev);
Rudolf Marek0c8e6642011-02-19 14:51:31 +0000113 lpc47n217_pnp_set_enable(dev, !!dev->enabled);
Zheng Bao9db833b2009-12-28 09:59:44 +0000114 pnp_exit_conf_state(dev);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000115}
116
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000117/**
118 * Initialize the specified Super I/O device.
119 *
120 * Devices other than COM ports are ignored. For COM ports, we configure the
121 * baud rate.
122 *
123 * @param dev Pointer to structure describing a Super I/O device.
Zheng Bao9db833b2009-12-28 09:59:44 +0000124 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100125static void lpc47n217_init(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000126{
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000127 if (!dev->enabled)
128 return;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000129}
130
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100131static void lpc47n217_pnp_set_resource(struct device *dev, struct resource *resource)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000132{
133 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
zbao9bf356f2012-08-03 15:09:09 +0800134 printk(BIOS_ERR, "ERROR: %s %02lx not allocated\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
Uwe Hermanna69d9782010-11-15 19:35:14 +0000139 /* Now store the resource. */
140
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000141 /*
142 * NOTE: Cannot use pnp_set_XXX() here because they assume chip
143 * support for logical devices, which the LPC47N217 doesn't have.
Zheng Bao9db833b2009-12-28 09:59:44 +0000144 */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000145 if (resource->flags & IORESOURCE_IO) {
146 lpc47n217_pnp_set_iobase(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000147 } else if (resource->flags & IORESOURCE_DRQ) {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000148 lpc47n217_pnp_set_drq(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000149 } else if (resource->flags & IORESOURCE_IRQ) {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000150 lpc47n217_pnp_set_irq(dev, resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000151 } else {
zbao9bf356f2012-08-03 15:09:09 +0800152 printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n",
Uwe Hermanna69d9782010-11-15 19:35:14 +0000153 dev_path(dev), resource->index);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000154 return;
155 }
156 resource->flags |= IORESOURCE_STORED;
157
158 report_resource_stored(dev, resource, "");
159}
160
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100161static void lpc47n217_pnp_set_iobase(struct device *dev, u16 iobase)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000162{
163 ASSERT(!(iobase & 0x3));
Zheng Bao9db833b2009-12-28 09:59:44 +0000164
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100165 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000166 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000167 pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
168 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000169 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000170 pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
171 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000172 case LPC47N217_SP2:
173 pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
174 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000175 default:
176 BUG();
177 break;
178 }
179}
180
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100181static void lpc47n217_pnp_set_drq(struct device *dev, u8 drq)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000182{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000183 const u8 PP_DMA_MASK = 0x0F;
184 const u8 PP_DMA_SELECTION_REGISTER = 0x26;
185 u8 current_config, new_config;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000186
Uwe Hermanna69d9782010-11-15 19:35:14 +0000187 if (dev->path.pnp.device == LPC47N217_PP) {
188 current_config = pnp_read_config(dev,
189 PP_DMA_SELECTION_REGISTER);
190 ASSERT(!(drq & ~PP_DMA_MASK)); /* DRQ out of range? */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000191 new_config = (current_config & ~PP_DMA_MASK) | drq;
192 pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config);
193 } else {
194 BUG();
195 }
196}
197
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100198static void lpc47n217_pnp_set_irq(struct device *dev, u8 irq)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000199{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000200 u8 irq_config_register = 0, irq_config_mask = 0;
201 u8 current_config, new_config;
Zheng Bao9db833b2009-12-28 09:59:44 +0000202
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100203 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000204 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000205 irq_config_register = 0x27;
206 irq_config_mask = 0x0F;
207 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000208 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000209 irq_config_register = 0x28;
210 irq_config_mask = 0xF0;
211 irq <<= 4;
212 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000213 case LPC47N217_SP2:
214 irq_config_register = 0x28;
215 irq_config_mask = 0x0F;
216 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000217 default:
218 BUG();
219 return;
220 }
221
Uwe Hermanna69d9782010-11-15 19:35:14 +0000222 ASSERT(!(irq & ~irq_config_mask)); /* IRQ out of range? */
Zheng Bao9db833b2009-12-28 09:59:44 +0000223
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000224 current_config = pnp_read_config(dev, irq_config_register);
225 new_config = (current_config & ~irq_config_mask) | irq;
226 pnp_write_config(dev, irq_config_register, new_config);
227}
228
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100229static void lpc47n217_pnp_set_enable(struct device *dev, int enable)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000230{
Uwe Hermanna69d9782010-11-15 19:35:14 +0000231 u8 power_register = 0, power_mask = 0, current_power, new_power;
Zheng Bao9db833b2009-12-28 09:59:44 +0000232
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100233 switch (dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000234 case LPC47N217_PP:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000235 power_register = 0x01;
236 power_mask = 0x04;
237 break;
Zheng Bao9db833b2009-12-28 09:59:44 +0000238 case LPC47N217_SP1:
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000239 power_register = 0x02;
240 power_mask = 0x08;
241 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000242 case LPC47N217_SP2:
243 power_register = 0x02;
244 power_mask = 0x80;
245 break;
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000246 default:
247 BUG();
248 return;
249 }
250
251 current_power = pnp_read_config(dev, power_register);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000252 new_power = current_power & ~power_mask; /* Disable by default. */
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000253 if (enable) {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000254 struct resource* ioport_resource;
255 ioport_resource = find_resource(dev, PNP_IDX_IO0);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000256 lpc47n217_pnp_set_iobase(dev, ioport_resource->base);
Uwe Hermanna69d9782010-11-15 19:35:14 +0000257 new_power |= power_mask; /* Enable. */
Zheng Bao9db833b2009-12-28 09:59:44 +0000258 } else {
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000259 lpc47n217_pnp_set_iobase(dev, 0);
260 }
261 pnp_write_config(dev, power_register, new_power);
262}
263
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100264static void pnp_enter_conf_state(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000265{
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000266 outb(0x55, dev->path.pnp.port);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000267}
268
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100269static void pnp_exit_conf_state(struct device *dev)
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000270{
Zheng Bao9db833b2009-12-28 09:59:44 +0000271 outb(0xaa, dev->path.pnp.port);
Stefan Reinauereca92fb2006-08-23 14:28:37 +0000272}