Skip to content

Commit 5829e9b

Browse files
dvhartSamuel Ortiz
authored andcommitted
mfd: lpc_sch: Accomodate partial population of the MFD devices
The current probe aborts if any of the 3 base address registers are disabled. On a TunnelCreek system I am working on, this resulted in the SMBIOS and GPIO devices being removed when it couldn't read the base address for the watchdog timer. This patch accommodates partial population of the lpc_sch_cells array and only aborts if all the base address registers are disabled. A max size array is allocated and the individual device cells are added to it after their base addresses are successfully determined. This simplifies the code a bit by removing the need for the separate tunnelcreek cells array and combining some of the add/remove logic. Cc: Grant Likely <grant.likely@secretlab.ca>, Cc: Denis Turischev <denis@compulab.co.il>, Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Cc: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent c3e9e6b commit 5829e9b

1 file changed

Lines changed: 71 additions & 76 deletions

File tree

‎drivers/mfd/lpc_sch.c‎

Lines changed: 71 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,32 @@ static struct resource smbus_sch_resource = {
4545
.flags = IORESOURCE_IO,
4646
};
4747

48-
4948
static struct resource gpio_sch_resource = {
5049
.flags = IORESOURCE_IO,
5150
};
5251

53-
static struct mfd_cell lpc_sch_cells[] = {
54-
{
55-
.name = "isch_smbus",
56-
.num_resources = 1,
57-
.resources = &smbus_sch_resource,
58-
},
59-
{
60-
.name = "sch_gpio",
61-
.num_resources = 1,
62-
.resources = &gpio_sch_resource,
63-
},
64-
};
65-
6652
static struct resource wdt_sch_resource = {
6753
.flags = IORESOURCE_IO,
6854
};
6955

70-
static struct mfd_cell tunnelcreek_cells[] = {
71-
{
72-
.name = "ie6xx_wdt",
73-
.num_resources = 1,
74-
.resources = &wdt_sch_resource,
75-
},
56+
static struct mfd_cell lpc_sch_cells[3];
57+
58+
static struct mfd_cell isch_smbus_cell = {
59+
.name = "isch_smbus",
60+
.num_resources = 1,
61+
.resources = &smbus_sch_resource,
62+
};
63+
64+
static struct mfd_cell sch_gpio_cell = {
65+
.name = "sch_gpio",
66+
.num_resources = 1,
67+
.resources = &gpio_sch_resource,
68+
};
69+
70+
static struct mfd_cell wdt_sch_cell = {
71+
.name = "ie6xx_wdt",
72+
.num_resources = 1,
73+
.resources = &wdt_sch_resource,
7674
};
7775

7876
static DEFINE_PCI_DEVICE_TABLE(lpc_sch_ids) = {
@@ -88,79 +86,76 @@ static int lpc_sch_probe(struct pci_dev *dev,
8886
{
8987
unsigned int base_addr_cfg;
9088
unsigned short base_addr;
91-
int i;
89+
int i, cells = 0;
9290
int ret;
9391

9492
pci_read_config_dword(dev, SMBASE, &base_addr_cfg);
95-
if (!(base_addr_cfg & (1 << 31))) {
96-
dev_err(&dev->dev, "Decode of the SMBus I/O range disabled\n");
97-
return -ENODEV;
98-
}
99-
base_addr = (unsigned short)base_addr_cfg;
100-
if (base_addr == 0) {
101-
dev_err(&dev->dev, "I/O space for SMBus uninitialized\n");
102-
return -ENODEV;
103-
}
104-
105-
smbus_sch_resource.start = base_addr;
106-
smbus_sch_resource.end = base_addr + SMBUS_IO_SIZE - 1;
93+
base_addr = 0;
94+
if (!(base_addr_cfg & (1 << 31)))
95+
dev_warn(&dev->dev, "Decode of the SMBus I/O range disabled\n");
96+
else
97+
base_addr = (unsigned short)base_addr_cfg;
10798

108-
pci_read_config_dword(dev, GPIOBASE, &base_addr_cfg);
109-
if (!(base_addr_cfg & (1 << 31))) {
110-
dev_err(&dev->dev, "Decode of the GPIO I/O range disabled\n");
111-
return -ENODEV;
112-
}
113-
base_addr = (unsigned short)base_addr_cfg;
11499
if (base_addr == 0) {
115-
dev_err(&dev->dev, "I/O space for GPIO uninitialized\n");
116-
return -ENODEV;
100+
dev_warn(&dev->dev, "I/O space for SMBus uninitialized\n");
101+
} else {
102+
lpc_sch_cells[cells++] = isch_smbus_cell;
103+
smbus_sch_resource.start = base_addr;
104+
smbus_sch_resource.end = base_addr + SMBUS_IO_SIZE - 1;
117105
}
118106

119-
gpio_sch_resource.start = base_addr;
120-
121-
if (id->device == PCI_DEVICE_ID_INTEL_CENTERTON_ILB)
122-
gpio_sch_resource.end = base_addr + GPIO_IO_SIZE_CENTERTON - 1;
107+
pci_read_config_dword(dev, GPIOBASE, &base_addr_cfg);
108+
base_addr = 0;
109+
if (!(base_addr_cfg & (1 << 31)))
110+
dev_warn(&dev->dev, "Decode of the GPIO I/O range disabled\n");
123111
else
124-
gpio_sch_resource.end = base_addr + GPIO_IO_SIZE - 1;
125-
126-
for (i=0; i < ARRAY_SIZE(lpc_sch_cells); i++)
127-
lpc_sch_cells[i].id = id->device;
112+
base_addr = (unsigned short)base_addr_cfg;
128113

129-
ret = mfd_add_devices(&dev->dev, 0,
130-
lpc_sch_cells, ARRAY_SIZE(lpc_sch_cells), NULL,
131-
0, NULL);
132-
if (ret)
133-
goto out_dev;
114+
if (base_addr == 0) {
115+
dev_warn(&dev->dev, "I/O space for GPIO uninitialized\n");
116+
} else {
117+
lpc_sch_cells[cells++] = sch_gpio_cell;
118+
gpio_sch_resource.start = base_addr;
119+
if (id->device == PCI_DEVICE_ID_INTEL_CENTERTON_ILB)
120+
gpio_sch_resource.end = base_addr + GPIO_IO_SIZE_CENTERTON - 1;
121+
else
122+
gpio_sch_resource.end = base_addr + GPIO_IO_SIZE - 1;
123+
}
134124

135125
if (id->device == PCI_DEVICE_ID_INTEL_ITC_LPC
136-
|| id->device == PCI_DEVICE_ID_INTEL_CENTERTON_ILB) {
126+
|| id->device == PCI_DEVICE_ID_INTEL_CENTERTON_ILB) {
137127
pci_read_config_dword(dev, WDTBASE, &base_addr_cfg);
138-
if (!(base_addr_cfg & (1 << 31))) {
139-
dev_err(&dev->dev, "Decode of the WDT I/O range disabled\n");
140-
ret = -ENODEV;
141-
goto out_dev;
128+
base_addr = 0;
129+
if (!(base_addr_cfg & (1 << 31)))
130+
dev_warn(&dev->dev, "Decode of the WDT I/O range disabled\n");
131+
else
132+
base_addr = (unsigned short)base_addr_cfg;
133+
if (base_addr == 0)
134+
dev_warn(&dev->dev, "I/O space for WDT uninitialized\n");
135+
else {
136+
lpc_sch_cells[cells++] = wdt_sch_cell;
137+
wdt_sch_resource.start = base_addr;
138+
wdt_sch_resource.end = base_addr + WDT_IO_SIZE - 1;
142139
}
143-
base_addr = (unsigned short)base_addr_cfg;
144-
if (base_addr == 0) {
145-
dev_err(&dev->dev, "I/O space for WDT uninitialized\n");
146-
ret = -ENODEV;
147-
goto out_dev;
148-
}
149-
150-
wdt_sch_resource.start = base_addr;
151-
wdt_sch_resource.end = base_addr + WDT_IO_SIZE - 1;
140+
}
152141

153-
for (i = 0; i < ARRAY_SIZE(tunnelcreek_cells); i++)
154-
tunnelcreek_cells[i].id = id->device;
142+
if (WARN_ON(cells > ARRAY_SIZE(lpc_sch_cells))) {
143+
dev_err(&dev->dev, "Cell count exceeds array size");
144+
return -ENODEV;
145+
}
155146

156-
ret = mfd_add_devices(&dev->dev, 0, tunnelcreek_cells,
157-
ARRAY_SIZE(tunnelcreek_cells), NULL,
158-
0, NULL);
147+
if (cells == 0) {
148+
dev_err(&dev->dev, "All decode registers disabled.\n");
149+
return -ENODEV;
159150
}
160151

161-
return ret;
162-
out_dev:
163-
mfd_remove_devices(&dev->dev);
152+
for (i = 0; i < cells; i++)
153+
lpc_sch_cells[i].id = id->device;
154+
155+
ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
156+
if (ret)
157+
mfd_remove_devices(&dev->dev);
158+
164159
return ret;
165160
}
166161

0 commit comments

Comments
 (0)