aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ortiz <samuel@sortiz.org>2006-05-25 19:21:10 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-06-18 00:26:22 -0400
commit898b1d16f8230fb912a0c2248df685735c6ceda3 (patch)
treee5e78b80373b4e2c74d9870d70f9deee0b3f7677
parentbc1d6937e6cf4e81a5afeae2c9cf35ffb0905ba5 (diff)
[IRDA]: ali-ircc: using device model power management
This patch gets rid of the old power management code and now uses the device model for the ali-ircc driver. Signed-off-by: Samuel Ortiz <samuel@sortiz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/irda/ali-ircc.c106
1 files changed, 51 insertions, 55 deletions
diff --git a/drivers/net/irda/ali-ircc.c b/drivers/net/irda/ali-ircc.c
index 2e7882eb7d6f..bf1fca5a3fa0 100644
--- a/drivers/net/irda/ali-ircc.c
+++ b/drivers/net/irda/ali-ircc.c
@@ -34,14 +34,12 @@
34#include <linux/rtnetlink.h> 34#include <linux/rtnetlink.h>
35#include <linux/serial_reg.h> 35#include <linux/serial_reg.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/platform_device.h>
37 38
38#include <asm/io.h> 39#include <asm/io.h>
39#include <asm/dma.h> 40#include <asm/dma.h>
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
41 42
42#include <linux/pm.h>
43#include <linux/pm_legacy.h>
44
45#include <net/irda/wrapper.h> 43#include <net/irda/wrapper.h>
46#include <net/irda/irda.h> 44#include <net/irda/irda.h>
47#include <net/irda/irda_device.h> 45#include <net/irda/irda_device.h>
@@ -51,7 +49,19 @@
51#define CHIP_IO_EXTENT 8 49#define CHIP_IO_EXTENT 8
52#define BROKEN_DONGLE_ID 50#define BROKEN_DONGLE_ID
53 51
54static char *driver_name = "ali-ircc"; 52#define ALI_IRCC_DRIVER_NAME "ali-ircc"
53
54/* Power Management */
55static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state);
56static int ali_ircc_resume(struct platform_device *dev);
57
58static struct platform_driver ali_ircc_driver = {
59 .suspend = ali_ircc_suspend,
60 .resume = ali_ircc_resume,
61 .driver = {
62 .name = ALI_IRCC_DRIVER_NAME,
63 },
64};
55 65
56/* Module parameters */ 66/* Module parameters */
57static int qos_mtt_bits = 0x07; /* 1 ms or more */ 67static int qos_mtt_bits = 0x07; /* 1 ms or more */
@@ -97,10 +107,7 @@ static int ali_ircc_is_receiving(struct ali_ircc_cb *self);
97static int ali_ircc_net_open(struct net_device *dev); 107static int ali_ircc_net_open(struct net_device *dev);
98static int ali_ircc_net_close(struct net_device *dev); 108static int ali_ircc_net_close(struct net_device *dev);
99static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 109static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
100static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
101static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud); 110static void ali_ircc_change_speed(struct ali_ircc_cb *self, __u32 baud);
102static void ali_ircc_suspend(struct ali_ircc_cb *self);
103static void ali_ircc_wakeup(struct ali_ircc_cb *self);
104static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev); 111static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev);
105 112
106/* SIR function */ 113/* SIR function */
@@ -145,6 +152,14 @@ static int __init ali_ircc_init(void)
145 int i = 0; 152 int i = 0;
146 153
147 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 154 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
155
156 ret = platform_driver_register(&ali_ircc_driver);
157 if (ret) {
158 IRDA_ERROR("%s, Can't register driver!\n",
159 ALI_IRCC_DRIVER_NAME);
160 return ret;
161 }
162
148 163
149 /* Probe for all the ALi chipsets we know about */ 164 /* Probe for all the ALi chipsets we know about */
150 for (chip= chips; chip->name; chip++, i++) 165 for (chip= chips; chip->name; chip++, i++)
@@ -214,6 +229,10 @@ static int __init ali_ircc_init(void)
214 } 229 }
215 230
216 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 231 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
232
233 if (ret)
234 platform_driver_unregister(&ali_ircc_driver);
235
217 return ret; 236 return ret;
218} 237}
219 238
@@ -228,14 +247,14 @@ static void __exit ali_ircc_cleanup(void)
228 int i; 247 int i;
229 248
230 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 249 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
231
232 pm_unregister_all(ali_ircc_pmproc);
233 250
234 for (i=0; i < 4; i++) { 251 for (i=0; i < 4; i++) {
235 if (dev_self[i]) 252 if (dev_self[i])
236 ali_ircc_close(dev_self[i]); 253 ali_ircc_close(dev_self[i]);
237 } 254 }
238 255
256 platform_driver_unregister(&ali_ircc_driver);
257
239 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 258 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
240} 259}
241 260
@@ -249,7 +268,6 @@ static int ali_ircc_open(int i, chipio_t *info)
249{ 268{
250 struct net_device *dev; 269 struct net_device *dev;
251 struct ali_ircc_cb *self; 270 struct ali_ircc_cb *self;
252 struct pm_dev *pmdev;
253 int dongle_id; 271 int dongle_id;
254 int err; 272 int err;
255 273
@@ -284,7 +302,8 @@ static int ali_ircc_open(int i, chipio_t *info)
284 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */ 302 self->io.fifo_size = 16; /* SIR: 16, FIR: 32 Benjamin 2000/11/1 */
285 303
286 /* Reserve the ioports that we need */ 304 /* Reserve the ioports that we need */
287 if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) { 305 if (!request_region(self->io.fir_base, self->io.fir_ext,
306 ALI_IRCC_DRIVER_NAME)) {
288 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__, 307 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
289 self->io.fir_base); 308 self->io.fir_base);
290 err = -ENODEV; 309 err = -ENODEV;
@@ -354,13 +373,10 @@ static int ali_ircc_open(int i, chipio_t *info)
354 373
355 /* Check dongle id */ 374 /* Check dongle id */
356 dongle_id = ali_ircc_read_dongle_id(i, info); 375 dongle_id = ali_ircc_read_dongle_id(i, info);
357 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]); 376 IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__,
377 ALI_IRCC_DRIVER_NAME, dongle_types[dongle_id]);
358 378
359 self->io.dongle_id = dongle_id; 379 self->io.dongle_id = dongle_id;
360
361 pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, ali_ircc_pmproc);
362 if (pmdev)
363 pmdev->data = self;
364 380
365 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__); 381 IRDA_DEBUG(2, "%s(), ----------------- End -----------------\n", __FUNCTION__);
366 382
@@ -548,12 +564,11 @@ static int ali_ircc_setup(chipio_t *info)
548 /* Should be 0x00 in the M1535/M1535D */ 564 /* Should be 0x00 in the M1535/M1535D */
549 if(version != 0x00) 565 if(version != 0x00)
550 { 566 {
551 IRDA_ERROR("%s, Wrong chip version %02x\n", driver_name, version); 567 IRDA_ERROR("%s, Wrong chip version %02x\n",
568 ALI_IRCC_DRIVER_NAME, version);
552 return -1; 569 return -1;
553 } 570 }
554 571
555 // IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
556
557 /* Set FIR FIFO Threshold Register */ 572 /* Set FIR FIFO Threshold Register */
558 switch_bank(iobase, BANK1); 573 switch_bank(iobase, BANK1);
559 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR); 574 outb(RX_FIFO_Threshold, iobase+FIR_FIFO_TR);
@@ -583,7 +598,8 @@ static int ali_ircc_setup(chipio_t *info)
583 /* Switch to SIR space */ 598 /* Switch to SIR space */
584 FIR2SIR(iobase); 599 FIR2SIR(iobase);
585 600
586 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name); 601 IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n",
602 ALI_IRCC_DRIVER_NAME);
587 603
588 /* Enable receive interrupts */ 604 /* Enable receive interrupts */
589 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM 605 // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
@@ -647,7 +663,8 @@ static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id,
647 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__); 663 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
648 664
649 if (!dev) { 665 if (!dev) {
650 IRDA_WARNING("%s: irq %d for unknown device.\n", driver_name, irq); 666 IRDA_WARNING("%s: irq %d for unknown device.\n",
667 ALI_IRCC_DRIVER_NAME, irq);
651 return IRQ_NONE; 668 return IRQ_NONE;
652 } 669 }
653 670
@@ -1328,7 +1345,8 @@ static int ali_ircc_net_open(struct net_device *dev)
1328 /* Request IRQ and install Interrupt Handler */ 1345 /* Request IRQ and install Interrupt Handler */
1329 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev)) 1346 if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev))
1330 { 1347 {
1331 IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name, 1348 IRDA_WARNING("%s, unable to allocate irq=%d\n",
1349 ALI_IRCC_DRIVER_NAME,
1332 self->io.irq); 1350 self->io.irq);
1333 return -EAGAIN; 1351 return -EAGAIN;
1334 } 1352 }
@@ -1338,7 +1356,8 @@ static int ali_ircc_net_open(struct net_device *dev)
1338 * failure. 1356 * failure.
1339 */ 1357 */
1340 if (request_dma(self->io.dma, dev->name)) { 1358 if (request_dma(self->io.dma, dev->name)) {
1341 IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name, 1359 IRDA_WARNING("%s, unable to allocate dma=%d\n",
1360 ALI_IRCC_DRIVER_NAME,
1342 self->io.dma); 1361 self->io.dma);
1343 free_irq(self->io.irq, self); 1362 free_irq(self->io.irq, self);
1344 return -EAGAIN; 1363 return -EAGAIN;
@@ -2108,61 +2127,38 @@ static struct net_device_stats *ali_ircc_net_get_stats(struct net_device *dev)
2108 return &self->stats; 2127 return &self->stats;
2109} 2128}
2110 2129
2111static void ali_ircc_suspend(struct ali_ircc_cb *self) 2130static int ali_ircc_suspend(struct platform_device *dev, pm_message_t state)
2112{ 2131{
2113 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ ); 2132 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2114 2133
2115 IRDA_MESSAGE("%s, Suspending\n", driver_name); 2134 IRDA_MESSAGE("%s, Suspending\n", ALI_IRCC_DRIVER_NAME);
2116 2135
2117 if (self->io.suspended) 2136 if (self->io.suspended)
2118 return; 2137 return 0;
2119 2138
2120 ali_ircc_net_close(self->netdev); 2139 ali_ircc_net_close(self->netdev);
2121 2140
2122 self->io.suspended = 1; 2141 self->io.suspended = 1;
2123 2142
2124 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ ); 2143 return 0;
2125} 2144}
2126 2145
2127static void ali_ircc_wakeup(struct ali_ircc_cb *self) 2146static int ali_ircc_resume(struct platform_device *dev)
2128{ 2147{
2129 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ ); 2148 struct ali_ircc_cb *self = platform_get_drvdata(dev);
2130 2149
2131 if (!self->io.suspended) 2150 if (!self->io.suspended)
2132 return; 2151 return 0;
2133 2152
2134 ali_ircc_net_open(self->netdev); 2153 ali_ircc_net_open(self->netdev);
2135 2154
2136 IRDA_MESSAGE("%s, Waking up\n", driver_name); 2155 IRDA_MESSAGE("%s, Waking up\n", ALI_IRCC_DRIVER_NAME);
2137 2156
2138 self->io.suspended = 0; 2157 self->io.suspended = 0;
2139
2140 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2141}
2142 2158
2143static int ali_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
2144{
2145 struct ali_ircc_cb *self = (struct ali_ircc_cb*) dev->data;
2146
2147 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
2148
2149 if (self) {
2150 switch (rqst) {
2151 case PM_SUSPEND:
2152 ali_ircc_suspend(self);
2153 break;
2154 case PM_RESUME:
2155 ali_ircc_wakeup(self);
2156 break;
2157 }
2158 }
2159
2160 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __FUNCTION__ );
2161
2162 return 0; 2159 return 0;
2163} 2160}
2164 2161
2165
2166/* ALi Chip Function */ 2162/* ALi Chip Function */
2167 2163
2168static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable) 2164static void SetCOMInterrupts(struct ali_ircc_cb *self , unsigned char enable)