w1: fix omap 1-wire driver compilation
[safe/jmp/linux-2.6] / drivers / mfd / sm501.c
index 4d9aaf9..bc9275c 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/pci.h>
 #include <linux/i2c-gpio.h>
+#include <linux/slab.h>
 
 #include <linux/sm501.h>
 #include <linux/sm501-regs.h>
@@ -41,6 +42,7 @@ struct sm501_gpio_chip {
        struct gpio_chip        gpio;
        struct sm501_gpio       *ourgpio;       /* to get back to parent. */
        void __iomem            *regbase;
+       void __iomem            *control;       /* address of control reg. */
 };
 
 struct sm501_gpio {
@@ -366,7 +368,8 @@ int sm501_unit_power(struct device *dev, unsigned int unit, unsigned int to)
                break;
 
        default:
-               return -1;
+               gate = -1;
+               goto already;
        }
 
        writel(mode, sm->regs + SM501_POWER_MODE_CONTROL);
@@ -521,7 +524,7 @@ unsigned long sm501_set_clock(struct device *dev,
        unsigned long clock = readl(sm->regs + SM501_CURRENT_CLOCK);
        unsigned char reg;
        unsigned int pll_reg = 0;
-       unsigned long sm501_freq; /* the actual frequency acheived */
+       unsigned long sm501_freq; /* the actual frequency achieved */
 
        struct sm501_clock to;
 
@@ -531,7 +534,7 @@ unsigned long sm501_set_clock(struct device *dev,
 
        switch (clksrc) {
        case SM501_CLOCK_P2XCLK:
-               /* This clock is divided in half so to achive the
+               /* This clock is divided in half so to achieve the
                 * requested frequency the value must be multiplied by
                 * 2. This clock also has an additional pre divisor */
 
@@ -560,7 +563,7 @@ unsigned long sm501_set_clock(struct device *dev,
                break;
 
        case SM501_CLOCK_V2XCLK:
-               /* This clock is divided in half so to achive the
+               /* This clock is divided in half so to achieve the
                 * requested frequency the value must be multiplied by 2. */
 
                sm501_freq = (sm501_select_clock(2 * req_freq, &to, 3) / 2);
@@ -646,7 +649,7 @@ unsigned long sm501_find_clock(struct device *dev,
                               unsigned long req_freq)
 {
        struct sm501_devdata *sm = dev_get_drvdata(dev);
-       unsigned long sm501_freq; /* the frequency achiveable by the 501 */
+       unsigned long sm501_freq; /* the frequency achieveable by the 501 */
        struct sm501_clock to;
 
        switch (clksrc) {
@@ -908,6 +911,25 @@ static int sm501_gpio_get(struct gpio_chip *chip, unsigned offset)
        return result & 1UL;
 }
 
+static void sm501_gpio_ensure_gpio(struct sm501_gpio_chip *smchip,
+                                  unsigned long bit)
+{
+       unsigned long ctrl;
+
+       /* check and modify if this pin is not set as gpio. */
+
+       if (readl(smchip->control) & bit) {
+               dev_info(sm501_gpio_to_dev(smchip->ourgpio)->dev,
+                        "changing mode of gpio, bit %08lx\n", bit);
+
+               ctrl = readl(smchip->control);
+               ctrl &= ~bit;
+               writel(ctrl, smchip->control);
+
+               sm501_sync_regs(sm501_gpio_to_dev(smchip->ourgpio));
+       }
+}
+
 static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 
 {
@@ -929,6 +951,8 @@ static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
        writel(val, regs);
 
        sm501_sync_regs(sm501_gpio_to_dev(smgpio));
+       sm501_gpio_ensure_gpio(smchip, bit);
+
        spin_unlock_irqrestore(&smgpio->lock, save);
 }
 
@@ -941,8 +965,8 @@ static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset)
        unsigned long save;
        unsigned long ddr;
 
-       dev_info(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n",
-                __func__, chip, offset);
+       dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n",
+               __func__, chip, offset);
 
        spin_lock_irqsave(&smgpio->lock, save);
 
@@ -950,6 +974,8 @@ static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset)
        writel(ddr & ~bit, regs + SM501_GPIO_DDR_LOW);
 
        sm501_sync_regs(sm501_gpio_to_dev(smgpio));
+       sm501_gpio_ensure_gpio(smchip, bit);
+
        spin_unlock_irqrestore(&smgpio->lock, save);
 
        return 0;
@@ -1012,9 +1038,11 @@ static int __devinit sm501_gpio_register_chip(struct sm501_devdata *sm,
                if (base > 0)
                        base += 32;
                chip->regbase = gpio->regs + SM501_GPIO_DATA_HIGH;
+               chip->control = sm->regs + SM501_GPIO63_32_CONTROL;
                gchip->label  = "SM501-HIGH";
        } else {
                chip->regbase = gpio->regs + SM501_GPIO_DATA_LOW;
+               chip->control = sm->regs + SM501_GPIO31_0_CONTROL;
                gchip->label  = "SM501-LOW";
        }
 
@@ -1024,7 +1052,7 @@ static int __devinit sm501_gpio_register_chip(struct sm501_devdata *sm,
        return gpiochip_add(gchip);
 }
 
-static int sm501_register_gpio(struct sm501_devdata *sm)
+static int __devinit sm501_register_gpio(struct sm501_devdata *sm)
 {
        struct sm501_gpio *gpio = &sm->gpio;
        resource_size_t iobase = sm->io_res->start + SM501_GPIO;
@@ -1295,7 +1323,7 @@ static unsigned int sm501_mem_local[] = {
  * Common init code for an SM501
 */
 
-static int sm501_init_dev(struct sm501_devdata *sm)
+static int __devinit sm501_init_dev(struct sm501_devdata *sm)
 {
        struct sm501_initdata *idata;
        struct sm501_platdata *pdata;
@@ -1371,34 +1399,34 @@ static int sm501_init_dev(struct sm501_devdata *sm)
        return 0;
 }
 
-static int sm501_plat_probe(struct platform_device *dev)
+static int __devinit sm501_plat_probe(struct platform_device *dev)
 {
        struct sm501_devdata *sm;
-       int err;
+       int ret;
 
        sm = kzalloc(sizeof(struct sm501_devdata), GFP_KERNEL);
        if (sm == NULL) {
                dev_err(&dev->dev, "no memory for device data\n");
-               err = -ENOMEM;
+               ret = -ENOMEM;
                goto err1;
        }
 
        sm->dev = &dev->dev;
        sm->pdev_id = dev->id;
-       sm->irq = platform_get_irq(dev, 0);
-       sm->io_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
-       sm->mem_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        sm->platdata = dev->dev.platform_data;
 
-       if (sm->irq < 0) {
+       ret = platform_get_irq(dev, 0);
+       if (ret < 0) {
                dev_err(&dev->dev, "failed to get irq resource\n");
-               err = sm->irq;
                goto err_res;
        }
+       sm->irq = ret;
 
+       sm->io_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
+       sm->mem_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        if (sm->io_res == NULL || sm->mem_res == NULL) {
                dev_err(&dev->dev, "failed to get IO resource\n");
-               err = -ENOENT;
+               ret = -ENOENT;
                goto err_res;
        }
 
@@ -1407,18 +1435,17 @@ static int sm501_plat_probe(struct platform_device *dev)
 
        if (sm->regs_claim == NULL) {
                dev_err(&dev->dev, "cannot claim registers\n");
-               err= -EBUSY;
+               ret = -EBUSY;
                goto err_res;
        }
 
        platform_set_drvdata(dev, sm);
 
-       sm->regs = ioremap(sm->io_res->start,
-                          (sm->io_res->end - sm->io_res->start) - 1);
+       sm->regs = ioremap(sm->io_res->start, resource_size(sm->io_res));
 
        if (sm->regs == NULL) {
                dev_err(&dev->dev, "cannot remap registers\n");
-               err = -EIO;
+               ret = -EIO;
                goto err_claim;
        }
 
@@ -1430,7 +1457,7 @@ static int sm501_plat_probe(struct platform_device *dev)
  err_res:
        kfree(sm);
  err1:
-       return err;
+       return ret;
 
 }
 
@@ -1560,8 +1587,8 @@ static struct sm501_platdata sm501_pci_platdata = {
        .gpio_base      = -1,
 };
 
-static int sm501_pci_probe(struct pci_dev *dev,
-                          const struct pci_device_id *id)
+static int __devinit sm501_pci_probe(struct pci_dev *dev,
+                                    const struct pci_device_id *id)
 {
        struct sm501_devdata *sm;
        int err;
@@ -1667,7 +1694,7 @@ static void sm501_dev_remove(struct sm501_devdata *sm)
        sm501_gpio_remove(sm);
 }
 
-static void sm501_pci_remove(struct pci_dev *dev)
+static void __devexit sm501_pci_remove(struct pci_dev *dev)
 {
        struct sm501_devdata *sm = pci_get_drvdata(dev);
 
@@ -1701,16 +1728,16 @@ static struct pci_device_id sm501_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, sm501_pci_tbl);
 
-static struct pci_driver sm501_pci_drv = {
+static struct pci_driver sm501_pci_driver = {
        .name           = "sm501",
        .id_table       = sm501_pci_tbl,
        .probe          = sm501_pci_probe,
-       .remove         = sm501_pci_remove,
+       .remove         = __devexit_p(sm501_pci_remove),
 };
 
 MODULE_ALIAS("platform:sm501");
 
-static struct platform_driver sm501_plat_drv = {
+static struct platform_driver sm501_plat_driver = {
        .driver         = {
                .name   = "sm501",
                .owner  = THIS_MODULE,
@@ -1723,14 +1750,14 @@ static struct platform_driver sm501_plat_drv = {
 
 static int __init sm501_base_init(void)
 {
-       platform_driver_register(&sm501_plat_drv);
-       return pci_register_driver(&sm501_pci_drv);
+       platform_driver_register(&sm501_plat_driver);
+       return pci_register_driver(&sm501_pci_driver);
 }
 
 static void __exit sm501_base_exit(void)
 {
-       platform_driver_unregister(&sm501_plat_drv);
-       pci_unregister_driver(&sm501_pci_drv);
+       platform_driver_unregister(&sm501_plat_driver);
+       pci_unregister_driver(&sm501_pci_driver);
 }
 
 module_init(sm501_base_init);