fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / net / irda / sa1100_ir.c
index c4b7b2a..937372d 100644 (file)
@@ -18,7 +18,6 @@
  *     power_leve:level        - set the transmitter power level
  *     tx_lpm:0|1              - set transmit low power mode
  */
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/types.h>
@@ -29,7 +28,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 
 #include <net/irda/irda.h>
 #include <asm/irq.h>
 #include <asm/dma.h>
 #include <asm/hardware.h>
-#include <asm/mach-types.h>
-
-#include <asm/arch/assabet.h>
-#include <asm/arch/h3600.h>
-#include <asm/arch/yopy.h>
-
-#ifndef GPIO_IRDA_FIR
-#define GPIO_IRDA_FIR          (0)
-#endif
-
-#ifndef GPIO_IRDA_POWER
-#define GPIO_IRDA_POWER                (0)
-#endif
+#include <asm/mach/irda.h>
 
 static int power_level = 3;
 static int tx_lpm;
@@ -75,6 +62,7 @@ struct sa1100_irda {
 
        struct net_device_stats stats;
        struct device           *dev;
+       struct irda_platform_data *pdata;
        struct irlap_cb         *irlap;
        struct qos_info         qos;
 
@@ -170,12 +158,8 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed)
                Ser2UTSR0 = UTSR0_REB | UTSR0_RBB | UTSR0_RID;
                Ser2UTCR3 = UTCR3_RIE | UTCR3_RXE | UTCR3_TXE;
 
-               if (machine_is_assabet())
-                       ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL);
-               if (machine_is_h3xxx())
-                       clr_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
-               if (machine_is_yopy())
-                       PPSR &= ~GPIO_IRDA_FIR;
+               if (si->pdata->set_speed)
+                       si->pdata->set_speed(si->dev, speed);
 
                si->speed = speed;
 
@@ -194,12 +178,8 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed)
 
                si->speed = speed;
 
-               if (machine_is_assabet())
-                       ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL);
-               if (machine_is_h3xxx())
-                       set_h3600_egpio(IPAQ_EGPIO_IR_FSEL);
-               if (machine_is_yopy())
-                       PPSR |= GPIO_IRDA_FIR;
+               if (si->pdata->set_speed)
+                       si->pdata->set_speed(si->dev, speed);
 
                sa1100_irda_rx_alloc(si);
                sa1100_irda_rx_dma_start(si);
@@ -215,51 +195,6 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed)
        return ret;
 }
 
-/*
- * This sets the IRDA power level on the Assabet.
- */
-static inline int
-sa1100_irda_set_power_assabet(struct sa1100_irda *si, unsigned int state)
-{
-       static unsigned int bcr_state[4] = {
-               ASSABET_BCR_IRDA_MD0,
-               ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0,
-               ASSABET_BCR_IRDA_MD1,
-               0
-       };
-
-       if (state < 4) {
-               state = bcr_state[state];
-               ASSABET_BCR_clear(state ^ (ASSABET_BCR_IRDA_MD1|
-                                          ASSABET_BCR_IRDA_MD0));
-               ASSABET_BCR_set(state);
-       }
-       return 0;
-}
-
-/*
- * This turns the IRDA power on or off on the Compaq H3600
- */
-static inline int
-sa1100_irda_set_power_h3600(struct sa1100_irda *si, unsigned int state)
-{
-       assign_h3600_egpio( IPAQ_EGPIO_IR_ON, state );
-       return 0;
-}
-
-/*
- * This turns the IRDA power on or off on the Yopy
- */
-static inline int
-sa1100_irda_set_power_yopy(struct sa1100_irda *si, unsigned int state)
-{
-       if (state)
-               PPSR &= ~GPIO_IRDA_POWER;
-       else
-               PPSR |= GPIO_IRDA_POWER;
-       return 0;
-}
-
 /*
  * Control the power state of the IrDA transmitter.
  * State:
@@ -274,14 +209,8 @@ static int
 __sa1100_irda_set_power(struct sa1100_irda *si, unsigned int state)
 {
        int ret = 0;
-
-       if (machine_is_assabet())
-               ret = sa1100_irda_set_power_assabet(si, state);
-       if (machine_is_h3xxx())
-               ret = sa1100_irda_set_power_h3600(si, state);
-       if (machine_is_yopy())
-               ret = sa1100_irda_set_power_yopy(si, state);
-
+       if (si->pdata->set_power)
+               ret = si->pdata->set_power(si->dev, state);
        return ret;
 }
 
@@ -304,11 +233,8 @@ static int sa1100_irda_startup(struct sa1100_irda *si)
        /*
         * Ensure that the ports for this device are setup correctly.
         */
-       if (machine_is_yopy()) {
-               PPDR |= GPIO_IRDA_POWER | GPIO_IRDA_FIR;
-               PPSR |= GPIO_IRDA_POWER | GPIO_IRDA_FIR;
-               PSDR |= GPIO_IRDA_POWER | GPIO_IRDA_FIR;
-       }
+       if (si->pdata->startup)
+               si->pdata->startup(si->dev);
 
        /*
         * Configure PPC for IRDA - we want to drive TXD2 low.
@@ -333,10 +259,15 @@ static int sa1100_irda_startup(struct sa1100_irda *si)
        Ser2UTSR0 = UTSR0_REB | UTSR0_RBB | UTSR0_RID;
 
        ret = sa1100_irda_set_speed(si, si->speed = 9600);
-       if (ret)
-               return ret;
+       if (ret) {
+               Ser2UTCR3 = 0;
+               Ser2HSCR0 = 0;
 
-       return 0;
+               if (si->pdata->shutdown)
+                       si->pdata->shutdown(si->dev);
+       }
+
+       return ret;
 }
 
 static void sa1100_irda_shutdown(struct sa1100_irda *si)
@@ -350,18 +281,21 @@ static void sa1100_irda_shutdown(struct sa1100_irda *si)
        /* Disable the port. */
        Ser2UTCR3 = 0;
        Ser2HSCR0 = 0;
+
+       if (si->pdata->shutdown)
+               si->pdata->shutdown(si->dev);
 }
 
 #ifdef CONFIG_PM
 /*
  * Suspend the IrDA interface.
  */
-static int sa1100_irda_suspend(struct device *_dev, u32 state, u32 level)
+static int sa1100_irda_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       struct net_device *dev = dev_get_drvdata(_dev);
+       struct net_device *dev = platform_get_drvdata(pdev);
        struct sa1100_irda *si;
 
-       if (!dev || level != SUSPEND_DISABLE)
+       if (!dev)
                return 0;
 
        si = dev->priv;
@@ -381,12 +315,12 @@ static int sa1100_irda_suspend(struct device *_dev, u32 state, u32 level)
 /*
  * Resume the IrDA interface.
  */
-static int sa1100_irda_resume(struct device *_dev, u32 level)
+static int sa1100_irda_resume(struct platform_device *pdev)
 {
-       struct net_device *dev = dev_get_drvdata(_dev);
+       struct net_device *dev = platform_get_drvdata(pdev);
        struct sa1100_irda *si;
 
-       if (!dev || level != RESUME_ENABLE)
+       if (!dev)
                return 0;
 
        si = dev->priv;
@@ -645,7 +579,7 @@ static void sa1100_irda_fir_irq(struct net_device *dev)
        sa1100_irda_rx_dma_start(si);
 }
 
-static irqreturn_t sa1100_irda_irq(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t sa1100_irda_irq(int irq, void *dev_id)
 {
        struct net_device *dev = dev_id;
        if (IS_FIR(((struct sa1100_irda *)dev->priv)))
@@ -760,8 +694,7 @@ static int sa1100_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
                /*
                 * We must not be transmitting...
                 */
-               if (si->txskb)
-                       BUG();
+               BUG_ON(si->txskb);
 
                netif_stop_queue(dev);
 
@@ -951,14 +884,16 @@ static int sa1100_irda_init_iobuf(iobuff_t *io, int size)
        return io->head ? 0 : -ENOMEM;
 }
 
-static int sa1100_irda_probe(struct device *_dev)
+static int sa1100_irda_probe(struct platform_device *pdev)
 {
-       struct platform_device *pdev = to_platform_device(_dev);
        struct net_device *dev;
        struct sa1100_irda *si;
        unsigned int baudrate_mask;
        int err;
 
+       if (!pdev->dev.platform_data)
+               return -EINVAL;
+
        err = request_mem_region(__PREG(Ser2UTCR0), 0x24, "IrDA") ? 0 : -EBUSY;
        if (err)
                goto err_mem_1;
@@ -975,6 +910,7 @@ static int sa1100_irda_probe(struct device *_dev)
 
        si = dev->priv;
        si->dev = &pdev->dev;
+       si->pdata = pdev->dev.platform_data;
 
        /*
         * Initialise the HP-SIR buffers
@@ -1028,7 +964,7 @@ static int sa1100_irda_probe(struct device *_dev)
 
        err = register_netdev(dev);
        if (err == 0)
-               dev_set_drvdata(&pdev->dev, si);
+               platform_set_drvdata(pdev, dev);
 
        if (err) {
  err_mem_5:
@@ -1046,9 +982,9 @@ static int sa1100_irda_probe(struct device *_dev)
        return err;
 }
 
-static int sa1100_irda_remove(struct device *_dev)
+static int sa1100_irda_remove(struct platform_device *pdev)
 {
-       struct net_device *dev = dev_get_drvdata(_dev);
+       struct net_device *dev = platform_get_drvdata(pdev);
 
        if (dev) {
                struct sa1100_irda *si = dev->priv;
@@ -1065,24 +1001,18 @@ static int sa1100_irda_remove(struct device *_dev)
        return 0;
 }
 
-static struct device_driver sa1100ir_driver = {
-       .name           = "sa11x0-ir",
-       .bus            = &platform_bus_type,
+static struct platform_driver sa1100ir_driver = {
        .probe          = sa1100_irda_probe,
        .remove         = sa1100_irda_remove,
        .suspend        = sa1100_irda_suspend,
        .resume         = sa1100_irda_resume,
-};
-
-static struct platform_device sa1100ir_device = {
-       .name           = "sa11x0-ir",
-       .id             = 0,
+       .driver         = {
+               .name   = "sa11x0-ir",
+       },
 };
 
 static int __init sa1100_irda_init(void)
 {
-       int ret;
-
        /*
         * Limit power level a sensible range.
         */
@@ -1091,19 +1021,12 @@ static int __init sa1100_irda_init(void)
        if (power_level > 3)
                power_level = 3;
 
-       ret = driver_register(&sa1100ir_driver);
-       if (ret == 0) {
-               ret = platform_device_register(&sa1100ir_device);
-               if (ret)
-                       driver_unregister(&sa1100ir_driver);
-       }
-       return ret;
+       return platform_driver_register(&sa1100ir_driver);
 }
 
 static void __exit sa1100_irda_exit(void)
 {
-       driver_unregister(&sa1100ir_driver);
-       platform_device_unregister(&sa1100ir_device);
+       platform_driver_unregister(&sa1100ir_driver);
 }
 
 module_init(sa1100_irda_init);