coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
superio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /* RAM-based driver for SMSC LPC47N227 Super I/O chip. */
4 
5 #include <device/device.h>
6 #include <device/pnp.h>
7 #include <console/console.h>
8 #include <assert.h>
9 #include <pc80/keyboard.h>
10 #include <superio/conf_mode.h>
11 
12 #include "lpc47n227.h"
13 
14 /* Forward declarations. */
15 static void enable_dev(struct device *dev);
16 void lpc47n227_pnp_set_resources(struct device *dev);
17 void lpc47n227_pnp_enable_resources(struct device *dev);
18 void lpc47n227_pnp_enable(struct device *dev);
19 static void lpc47n227_init(struct device *dev);
20 static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource);
21 void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase);
22 void lpc47n227_pnp_set_drq(struct device *dev, u8 drq);
23 void lpc47n227_pnp_set_irq(struct device *dev, u8 irq);
24 void lpc47n227_pnp_set_enable(struct device *dev, int enable);
25 
27  CHIP_NAME("SMSC LPC47N227 Super I/O")
28  .enable_dev = enable_dev,
29 };
30 
31 static struct device_operations ops = {
33  .set_resources = lpc47n227_pnp_set_resources,
34  .enable_resources = lpc47n227_pnp_enable_resources,
35  .enable = lpc47n227_pnp_enable,
36  .init = lpc47n227_init,
37  .ops_pnp_mode = &pnp_conf_mode_55_aa,
38 };
39 
40 static struct pnp_info pnp_dev_info[] = {
41  { NULL, LPC47N227_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
42  { NULL, LPC47N227_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
43  { NULL, LPC47N227_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
44  { NULL, LPC47N227_KBDC, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07f8, 0x07f8, },
45 };
46 
47 /**
48  * Create device structures and allocate resources to devices specified in the
49  * pnp_dev_info array (above).
50  *
51  * @param dev Pointer to structure describing a Super I/O device.
52  */
53 static void enable_dev(struct device *dev)
54 {
56 }
57 
58 /**
59  * Configure the specified Super I/O device with the resources (I/O space,
60  * etc.) that have been allocate for it.
61  *
62  * NOTE: Cannot use pnp_set_resources() here because it assumes chip
63  * support for logical devices, which the LPC47N227 doesn't have.
64  *
65  * @param dev Pointer to structure describing a Super I/O device.
66  */
68 {
69  struct resource *res;
70 
72  for (res = dev->resource_list; res; res = res->next)
74  pnp_exit_conf_mode(dev);
75 }
76 
77 /*
78  * NOTE: Cannot use pnp_enable_resources() here because it assumes chip
79  * support for logical devices, which the LPC47N227 doesn't have.
80  */
82 {
85  pnp_exit_conf_mode(dev);
86 }
87 
88 /*
89  * NOTE: Cannot use pnp_set_enable() here because it assumes chip
90  * support for logical devices, which the LPC47N227 doesn't have.
91  */
92 void lpc47n227_pnp_enable(struct device *dev)
93 {
95  lpc47n227_pnp_set_enable(dev, !!dev->enabled);
96  pnp_exit_conf_mode(dev);
97 }
98 
99 /**
100  * Initialize the specified Super I/O device.
101  *
102  * Devices other than COM ports and keyboard controller are ignored.
103  * For COM ports, we configure the baud rate.
104  *
105  * @param dev Pointer to structure describing a Super I/O device.
106  */
107 static void lpc47n227_init(struct device *dev)
108 {
109 
110  if (!dev->enabled)
111  return;
112 
113  switch (dev->path.pnp.device) {
114  case LPC47N227_KBDC:
115  printk(BIOS_DEBUG, "LPC47N227: Initializing keyboard.\n");
117  break;
118  }
119 }
120 
121 static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource)
122 {
123  if (!(resource->flags & IORESOURCE_ASSIGNED)) {
124  printk(BIOS_ERR, "%s %02lx not allocated\n",
125  dev_path(dev), resource->index);
126  return;
127  }
128 
129  /* Now store the resource. */
130  /*
131  * NOTE: Cannot use pnp_set_XXX() here because they assume chip
132  * support for logical devices, which the LPC47N227 doesn't have.
133  */
134  if (resource->flags & IORESOURCE_IO) {
136  } else if (resource->flags & IORESOURCE_DRQ) {
138  } else if (resource->flags & IORESOURCE_IRQ) {
140  } else {
141  printk(BIOS_ERR, "%s %02lx unknown resource type\n",
142  dev_path(dev), resource->index);
143  return;
144  }
146 
148 }
149 
150 void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase)
151 {
152  ASSERT(!(iobase & 0x3));
153 
154  switch (dev->path.pnp.device) {
155  case LPC47N227_PP:
156  pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
157  break;
158  case LPC47N227_SP1:
159  pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
160  break;
161  case LPC47N227_SP2:
162  pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
163  break;
164  case LPC47N227_KBDC:
165  break;
166  default:
167  BUG();
168  break;
169  }
170 }
171 
172 void lpc47n227_pnp_set_drq(struct device *dev, u8 drq)
173 {
174  const u8 PP_DMA_MASK = 0x0F;
175  const u8 PP_DMA_SELECTION_REGISTER = 0x26;
176  u8 current_config, new_config;
177 
178  if (dev->path.pnp.device == LPC47N227_PP) {
179  current_config = pnp_read_config(dev,
180  PP_DMA_SELECTION_REGISTER);
181  ASSERT(!(drq & ~PP_DMA_MASK)); // DRQ out of range??
182  new_config = (current_config & ~PP_DMA_MASK) | drq;
183  pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config);
184  } else {
185  BUG();
186  }
187 }
188 
189 void lpc47n227_pnp_set_irq(struct device *dev, u8 irq)
190 {
191  u8 irq_config_register = 0, irq_config_mask = 0;
192  u8 current_config, new_config;
193 
194  switch (dev->path.pnp.device) {
195  case LPC47N227_PP:
196  irq_config_register = 0x27;
197  irq_config_mask = 0x0F;
198  break;
199  case LPC47N227_SP1:
200  irq_config_register = 0x28;
201  irq_config_mask = 0xF0;
202  irq <<= 4;
203  break;
204  case LPC47N227_SP2:
205  irq_config_register = 0x28;
206  irq_config_mask = 0x0F;
207  break;
208  case LPC47N227_KBDC:
209  break;
210  default:
211  BUG();
212  return;
213  }
214 
215  current_config = pnp_read_config(dev, irq_config_register);
216  new_config = (current_config & ~irq_config_mask) | irq;
217  pnp_write_config(dev, irq_config_register, new_config);
218 }
219 
220 void lpc47n227_pnp_set_enable(struct device *dev, int enable)
221 {
222  u8 power_register = 0, power_mask = 0, current_power, new_power;
223 
224  switch (dev->path.pnp.device) {
225  case LPC47N227_PP:
226  power_register = 0x01;
227  power_mask = 0x04;
228  break;
229  case LPC47N227_SP1:
230  power_register = 0x02;
231  power_mask = 0x08;
232  break;
233  case LPC47N227_SP2:
234  power_register = 0x02;
235  power_mask = 0x80;
236  break;
237  case LPC47N227_KBDC:
238  break;
239  default:
240  BUG();
241  return;
242  }
243 
244  current_power = pnp_read_config(dev, power_register);
245  new_power = current_power & ~power_mask; /* Disable by default. */
246  if (enable) {
247  struct resource *ioport_resource;
248  ioport_resource = find_resource(dev, PNP_IDX_IO0);
249  lpc47n227_pnp_set_iobase(dev, ioport_resource->base);
250  new_power |= power_mask; /* Enable. */
251  } else {
252  lpc47n227_pnp_set_iobase(dev, 0);
253  }
254  pnp_write_config(dev, power_register, new_power);
255 }
#define BUG()
Definition: assert.h:65
#define ASSERT(x)
Definition: assert.h:44
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
const struct pnp_mode_ops pnp_conf_mode_55_aa
Definition: conf_mode.c:175
void report_resource_stored(struct device *dev, const struct resource *resource, const char *comment)
Print the resource that was just stored.
Definition: device_util.c:508
struct resource * find_resource(const struct device *dev, unsigned int index)
Return an existing resource structure for a given index.
Definition: device_util.c:394
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
#define CHIP_NAME(X)
Definition: device.h:32
uint8_t pc_keyboard_init(uint8_t probe_aux)
Definition: keyboard.c:229
#define NO_AUX_DEVICE
Definition: keyboard.h:6
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define LPC47N227_KBDC
Definition: lpc47n227.h:16
#define LPC47N227_SP2
Definition: lpc47n227.h:15
#define LPC47N227_PP
Definition: lpc47n227.h:13
#define LPC47N227_SP1
Definition: lpc47n227.h:14
#define PNP_DRQ0
Definition: pnp.h:49
#define PNP_IO1
Definition: pnp.h:43
#define PNP_IO0
Definition: pnp.h:42
#define PNP_IRQ0
Definition: pnp.h:47
#define PNP_IDX_IO0
Definition: pnp_def.h:5
void pnp_exit_conf_mode(struct device *dev)
Definition: pnp_device.c:17
void pnp_read_resources(struct device *dev)
Definition: pnp_device.c:114
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, unsigned int functions, struct pnp_info *info)
Definition: pnp_device.c:371
u8 pnp_read_config(struct device *dev, u8 reg)
Definition: pnp_device.c:44
void pnp_enter_conf_mode(struct device *dev)
Definition: pnp_device.c:11
void pnp_write_config(struct device *dev, u8 reg, u8 value)
Definition: pnp_device.c:38
#define IORESOURCE_IRQ
Definition: resource.h:11
#define IORESOURCE_DRQ
Definition: resource.h:12
#define IORESOURCE_STORED
Definition: resource.h:32
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
static void lpc47n227_init(struct device *dev)
Initialize the specified Super I/O device.
Definition: superio.c:107
struct chip_operations superio_smsc_lpc47n227_ops
Definition: superio.c:26
void lpc47n227_pnp_set_enable(struct device *dev, int enable)
Definition: superio.c:220
void lpc47n227_pnp_enable_resources(struct device *dev)
Definition: superio.c:81
static void enable_dev(struct device *dev)
Create device structures and allocate resources to devices specified in the pnp_dev_info array (above...
Definition: superio.c:53
void lpc47n227_pnp_set_irq(struct device *dev, u8 irq)
Definition: superio.c:189
static struct device_operations ops
Definition: superio.c:31
static struct pnp_info pnp_dev_info[]
Definition: superio.c:40
void lpc47n227_pnp_set_drq(struct device *dev, u8 drq)
Definition: superio.c:172
static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource)
Definition: superio.c:121
void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase)
Definition: superio.c:150
void lpc47n227_pnp_set_resources(struct device *dev)
Configure the specified Super I/O device with the resources (I/O space, etc.) that have been allocate...
Definition: superio.c:67
void lpc47n227_pnp_enable(struct device *dev)
Definition: superio.c:92
#define NULL
Definition: stddef.h:19
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pnp_path pnp
Definition: path.h:117
Definition: device.h:107
struct device_path path
Definition: device.h:115
DEVTREE_CONST struct resource * resource_list
Definition: device.h:134
unsigned int enabled
Definition: device.h:122
Definition: pnp.h:37
unsigned int device
Definition: path.h:59
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
unsigned long index
Definition: resource.h:50
DEVTREE_CONST struct resource * next
Definition: resource.h:48