Skip to content

Commit 8fe2b65

Browse files
Michael Bueschlinvjw
authored andcommitted
ssb: Turn suspend/resume upside down
Turn the SSB bus suspend mechanism upside down. Instead of deciding by an internal reference count when to suspend/resume, let the parent bus call us in their suspend/resume routine. Signed-off-by: Michael Buesch <mb@bu3sch.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 5100d5a commit 8fe2b65

8 files changed

Lines changed: 88 additions & 67 deletions

File tree

‎drivers/net/wireless/b43/pcmcia.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
4343
#ifdef CONFIG_PM
4444
static int b43_pcmcia_suspend(struct pcmcia_device *dev)
4545
{
46-
//TODO
47-
return 0;
46+
struct ssb_bus *ssb = dev->priv;
47+
48+
return ssb_bus_suspend(ssb);
4849
}
4950

5051
static int b43_pcmcia_resume(struct pcmcia_device *dev)
5152
{
52-
//TODO
53-
return 0;
53+
struct ssb_bus *ssb = dev->priv;
54+
55+
return ssb_bus_resume(ssb);
5456
}
5557
#else /* CONFIG_PM */
5658
# define b43_pcmcia_suspend NULL

‎drivers/ssb/driver_chipcommon.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void ssb_chipcommon_init(struct ssb_chipcommon *cc)
251251
calc_fast_powerup_delay(cc);
252252
}
253253

254-
void ssb_chipco_suspend(struct ssb_chipcommon *cc, pm_message_t state)
254+
void ssb_chipco_suspend(struct ssb_chipcommon *cc)
255255
{
256256
if (!cc->dev)
257257
return;

‎drivers/ssb/main.c‎

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,12 @@ static void ssb_device_put(struct ssb_device *dev)
120120
put_device(dev->dev);
121121
}
122122

123-
static int ssb_bus_resume(struct ssb_bus *bus)
124-
{
125-
int err;
126-
127-
ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
128-
err = ssb_pcmcia_init(bus);
129-
if (err) {
130-
/* No need to disable XTAL, as we don't have one on PCMCIA. */
131-
return err;
132-
}
133-
ssb_chipco_resume(&bus->chipco);
134-
135-
return 0;
136-
}
137-
138123
static int ssb_device_resume(struct device *dev)
139124
{
140125
struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
141126
struct ssb_driver *ssb_drv;
142-
struct ssb_bus *bus;
143127
int err = 0;
144128

145-
bus = ssb_dev->bus;
146-
if (bus->suspend_cnt == bus->nr_devices) {
147-
err = ssb_bus_resume(bus);
148-
if (err)
149-
return err;
150-
}
151-
bus->suspend_cnt--;
152129
if (dev->driver) {
153130
ssb_drv = drv_to_ssb_drv(dev->driver);
154131
if (ssb_drv && ssb_drv->resume)
@@ -160,27 +137,10 @@ static int ssb_device_resume(struct device *dev)
160137
return err;
161138
}
162139

163-
static void ssb_bus_suspend(struct ssb_bus *bus, pm_message_t state)
164-
{
165-
ssb_chipco_suspend(&bus->chipco, state);
166-
ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
167-
168-
/* Reset HW state information in memory, so that HW is
169-
* completely reinitialized on resume. */
170-
bus->mapped_device = NULL;
171-
#ifdef CONFIG_SSB_DRIVER_PCICORE
172-
bus->pcicore.setup_done = 0;
173-
#endif
174-
#ifdef CONFIG_SSB_DEBUG
175-
bus->powered_up = 0;
176-
#endif
177-
}
178-
179140
static int ssb_device_suspend(struct device *dev, pm_message_t state)
180141
{
181142
struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
182143
struct ssb_driver *ssb_drv;
183-
struct ssb_bus *bus;
184144
int err = 0;
185145

186146
if (dev->driver) {
@@ -190,17 +150,44 @@ static int ssb_device_suspend(struct device *dev, pm_message_t state)
190150
if (err)
191151
goto out;
192152
}
153+
out:
154+
return err;
155+
}
156+
157+
int ssb_bus_resume(struct ssb_bus *bus)
158+
{
159+
int err;
193160

194-
bus = ssb_dev->bus;
195-
bus->suspend_cnt++;
196-
if (bus->suspend_cnt == bus->nr_devices) {
197-
/* All devices suspended. Shutdown the bus. */
198-
ssb_bus_suspend(bus, state);
161+
/* Reset HW state information in memory, so that HW is
162+
* completely reinitialized. */
163+
bus->mapped_device = NULL;
164+
#ifdef CONFIG_SSB_DRIVER_PCICORE
165+
bus->pcicore.setup_done = 0;
166+
#endif
167+
168+
err = ssb_bus_powerup(bus, 0);
169+
if (err)
170+
return err;
171+
err = ssb_pcmcia_hardware_setup(bus);
172+
if (err) {
173+
ssb_bus_may_powerdown(bus);
174+
return err;
199175
}
176+
ssb_chipco_resume(&bus->chipco);
177+
ssb_bus_may_powerdown(bus);
200178

201-
out:
202-
return err;
179+
return 0;
180+
}
181+
EXPORT_SYMBOL(ssb_bus_resume);
182+
183+
int ssb_bus_suspend(struct ssb_bus *bus)
184+
{
185+
ssb_chipco_suspend(&bus->chipco);
186+
ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
187+
188+
return 0;
203189
}
190+
EXPORT_SYMBOL(ssb_bus_suspend);
204191

205192
#ifdef CONFIG_SSB_PCIHOST
206193
int ssb_devices_freeze(struct ssb_bus *bus)

‎drivers/ssb/pcihost_wrapper.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#ifdef CONFIG_PM
1919
static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
2020
{
21+
struct ssb_bus *ssb = pci_get_drvdata(dev);
22+
int err;
23+
24+
err = ssb_bus_suspend(ssb);
25+
if (err)
26+
return err;
2127
pci_save_state(dev);
2228
pci_disable_device(dev);
2329
pci_set_power_state(dev, pci_choose_state(dev, state));
@@ -27,13 +33,17 @@ static int ssb_pcihost_suspend(struct pci_dev *dev, pm_message_t state)
2733

2834
static int ssb_pcihost_resume(struct pci_dev *dev)
2935
{
36+
struct ssb_bus *ssb = pci_get_drvdata(dev);
3037
int err;
3138

3239
pci_set_power_state(dev, 0);
3340
err = pci_enable_device(dev);
3441
if (err)
3542
return err;
3643
pci_restore_state(dev);
44+
err = ssb_bus_resume(ssb);
45+
if (err)
46+
return err;
3747

3848
return 0;
3949
}

‎drivers/ssb/pcmcia.c‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,29 @@ static int ssb_pcmcia_cor_setup(struct ssb_bus *bus, u8 cor)
684684
return 0;
685685
}
686686

687+
/* Initialize the PCMCIA hardware. This is called on Init and Resume. */
688+
int ssb_pcmcia_hardware_setup(struct ssb_bus *bus)
689+
{
690+
int err;
691+
692+
if (bus->bustype != SSB_BUSTYPE_PCMCIA)
693+
return 0;
694+
695+
/* Switch segment to a known state and sync
696+
* bus->mapped_pcmcia_seg with hardware state. */
697+
ssb_pcmcia_switch_segment(bus, 0);
698+
/* Init the COR register. */
699+
err = ssb_pcmcia_cor_setup(bus, CISREG_COR);
700+
if (err)
701+
return err;
702+
/* Some cards also need this register to get poked. */
703+
err = ssb_pcmcia_cor_setup(bus, CISREG_COR + 0x80);
704+
if (err)
705+
return err;
706+
707+
return 0;
708+
}
709+
687710
void ssb_pcmcia_exit(struct ssb_bus *bus)
688711
{
689712
if (bus->bustype != SSB_BUSTYPE_PCMCIA)
@@ -699,16 +722,7 @@ int ssb_pcmcia_init(struct ssb_bus *bus)
699722
if (bus->bustype != SSB_BUSTYPE_PCMCIA)
700723
return 0;
701724

702-
/* Switch segment to a known state and sync
703-
* bus->mapped_pcmcia_seg with hardware state. */
704-
ssb_pcmcia_switch_segment(bus, 0);
705-
706-
/* Init the COR register. */
707-
err = ssb_pcmcia_cor_setup(bus, CISREG_COR);
708-
if (err)
709-
goto error;
710-
/* Some cards also need this register to get poked. */
711-
err = ssb_pcmcia_cor_setup(bus, CISREG_COR + 0x80);
725+
err = ssb_pcmcia_hardware_setup(bus);
712726
if (err)
713727
goto error;
714728

‎drivers/ssb/ssb_private.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern int ssb_pcmcia_switch_segment(struct ssb_bus *bus,
8181
u8 seg);
8282
extern int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
8383
struct ssb_init_invariants *iv);
84+
extern int ssb_pcmcia_hardware_setup(struct ssb_bus *bus);
8485
extern void ssb_pcmcia_exit(struct ssb_bus *bus);
8586
extern int ssb_pcmcia_init(struct ssb_bus *bus);
8687
extern const struct ssb_bus_ops ssb_pcmcia_ops;
@@ -100,6 +101,10 @@ static inline int ssb_pcmcia_switch_segment(struct ssb_bus *bus,
100101
{
101102
return 0;
102103
}
104+
static inline int ssb_pcmcia_hardware_setup(struct ssb_bus *bus)
105+
{
106+
return 0;
107+
}
103108
static inline void ssb_pcmcia_exit(struct ssb_bus *bus)
104109
{
105110
}

‎include/linux/ssb/ssb.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ struct ssb_bus {
260260
struct ssb_device devices[SSB_MAX_NR_CORES];
261261
u8 nr_devices;
262262

263-
/* Reference count. Number of suspended devices. */
264-
u8 suspend_cnt;
265-
266263
/* Software ID number for this bus. */
267264
unsigned int busnumber;
268265

@@ -334,6 +331,13 @@ extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
334331

335332
extern void ssb_bus_unregister(struct ssb_bus *bus);
336333

334+
/* Suspend a SSB bus.
335+
* Call this from the parent bus suspend routine. */
336+
extern int ssb_bus_suspend(struct ssb_bus *bus);
337+
/* Resume a SSB bus.
338+
* Call this from the parent bus resume routine. */
339+
extern int ssb_bus_resume(struct ssb_bus *bus);
340+
337341
extern u32 ssb_clockspeed(struct ssb_bus *bus);
338342

339343
/* Is the device enabled in hardware? */

‎include/linux/ssb/ssb_driver_chipcommon.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ static inline bool ssb_chipco_available(struct ssb_chipcommon *cc)
367367

368368
extern void ssb_chipcommon_init(struct ssb_chipcommon *cc);
369369

370-
#include <linux/pm.h>
371-
extern void ssb_chipco_suspend(struct ssb_chipcommon *cc, pm_message_t state);
370+
extern void ssb_chipco_suspend(struct ssb_chipcommon *cc);
372371
extern void ssb_chipco_resume(struct ssb_chipcommon *cc);
373372

374373
extern void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc,

0 commit comments

Comments
 (0)