drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / pinctrl / pinctrl-at91.c
index 5cbadc9ad2e84ab26a5de4078cbb6c64cfcdddb9..314e5e8e91224b7dc79e9bce71d0fb6b92fc9700 100644 (file)
@@ -293,7 +293,7 @@ static void at91_dt_free_map(struct pinctrl_dev *pctldev,
 {
 }
 
-static struct pinctrl_ops at91_pctrl_ops = {
+static const struct pinctrl_ops at91_pctrl_ops = {
        .get_groups_count       = at91_get_groups_count,
        .get_group_name         = at91_get_group_name,
        .get_group_pins         = at91_get_group_pins,
@@ -302,7 +302,7 @@ static struct pinctrl_ops at91_pctrl_ops = {
        .dt_free_map            = at91_dt_free_map,
 };
 
-static void __iomem * pin_to_controller(struct at91_pinctrl *info,
+static void __iomem *pin_to_controller(struct at91_pinctrl *info,
                                 unsigned int bank)
 {
        return gpio_chips[bank]->regbase;
@@ -325,7 +325,7 @@ static void at91_mux_disable_interrupt(void __iomem *pio, unsigned mask)
 
 static unsigned at91_mux_get_pullup(void __iomem *pio, unsigned pin)
 {
-       return (readl_relaxed(pio + PIO_PUSR) >> pin) & 0x1;
+       return !((readl_relaxed(pio + PIO_PUSR) >> pin) & 0x1);
 }
 
 static void at91_mux_set_pullup(void __iomem *pio, unsigned mask, bool on)
@@ -445,7 +445,7 @@ static void at91_mux_pio3_set_debounce(void __iomem *pio, unsigned mask,
 
 static bool at91_mux_pio3_get_pulldown(void __iomem *pio, unsigned pin)
 {
-       return (__raw_readl(pio + PIO_PPDSR) >> pin) & 0x1;
+       return !((__raw_readl(pio + PIO_PPDSR) >> pin) & 0x1);
 }
 
 static void at91_mux_pio3_set_pulldown(void __iomem *pio, unsigned mask, bool is_on)
@@ -500,7 +500,7 @@ static void at91_pin_dbg(const struct device *dev, const struct at91_pmx_pin *pi
        }
 }
 
-static int pin_check_config(struct at91_pinctrl *info, const charname,
+static int pin_check_config(struct at91_pinctrl *info, const char *name,
                            int index, const struct at91_pmx_pin *pin)
 {
        int mux;
@@ -578,7 +578,7 @@ static int at91_pmx_enable(struct pinctrl_dev *pctldev, unsigned selector,
                pio = pin_to_controller(info, pin->bank);
                mask = pin_to_mask(pin->pin);
                at91_mux_disable_interrupt(pio, mask);
-               switch(pin->mux) {
+               switch (pin->mux) {
                case AT91_MUX_GPIO:
                        at91_mux_gpio_enable(pio, mask, 1);
                        break;
@@ -695,7 +695,7 @@ static void at91_gpio_disable_free(struct pinctrl_dev *pctldev,
        /* Set the pin to some default state, GPIO is usually default */
 }
 
-static struct pinmux_ops at91_pmx_ops = {
+static const struct pinmux_ops at91_pmx_ops = {
        .get_functions_count    = at91_pmx_get_funcs_count,
        .get_function_name      = at91_pmx_get_func_name,
        .get_function_groups    = at91_pmx_get_groups,
@@ -775,7 +775,7 @@ static void at91_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
 {
 }
 
-static struct pinconf_ops at91_pinconf_ops = {
+static const struct pinconf_ops at91_pinconf_ops = {
        .pin_config_get                 = at91_pinconf_get,
        .pin_config_set                 = at91_pinconf_set,
        .pin_config_dbg_show            = at91_pinconf_dbg_show,
@@ -811,7 +811,7 @@ static int at91_pinctrl_mux_mask(struct at91_pinctrl *info,
 {
        int ret = 0;
        int size;
-       const const __be32 *list;
+       const __be32 *list;
 
        list = of_get_property(np, "atmel,mux-mask", &size);
        if (!list) {
@@ -845,7 +845,7 @@ static int at91_pinctrl_parse_groups(struct device_node *np,
 {
        struct at91_pmx_pin *pin;
        int size;
-       const const __be32 *list;
+       const __be32 *list;
        int i, j;
 
        dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
@@ -943,7 +943,7 @@ static int at91_pinctrl_probe_dt(struct platform_device *pdev,
                return -ENODEV;
 
        info->dev = &pdev->dev;
-       info->ops = (struct at91_pinctrl_mux_ops*)
+       info->ops = (struct at91_pinctrl_mux_ops *)
                of_match_device(at91_pinctrl_of_match, &pdev->dev)->data;
        at91_pinctrl_child_count(info, np);
 
@@ -1001,7 +1001,7 @@ static int at91_pinctrl_probe(struct platform_device *pdev)
 {
        struct at91_pinctrl *info;
        struct pinctrl_pin_desc *pdesc;
-       int ret, i, j ,k;
+       int ret, i, jk;
 
        info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
        if (!info)
@@ -1276,21 +1276,80 @@ static int alt_gpio_irq_type(struct irq_data *d, unsigned type)
 }
 
 #ifdef CONFIG_PM
+
+static u32 wakeups[MAX_GPIO_BANKS];
+static u32 backups[MAX_GPIO_BANKS];
+
 static int gpio_irq_set_wake(struct irq_data *d, unsigned state)
 {
        struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
        unsigned        bank = at91_gpio->pioc_idx;
+       unsigned mask = 1 << d->hwirq;
 
        if (unlikely(bank >= MAX_GPIO_BANKS))
                return -EINVAL;
 
+       if (state)
+               wakeups[bank] |= mask;
+       else
+               wakeups[bank] &= ~mask;
+
        irq_set_irq_wake(at91_gpio->pioc_virq, state);
 
        return 0;
 }
+
+void at91_pinctrl_gpio_suspend(void)
+{
+       int i;
+
+       for (i = 0; i < gpio_banks; i++) {
+               void __iomem  *pio;
+
+               if (!gpio_chips[i])
+                       continue;
+
+               pio = gpio_chips[i]->regbase;
+
+               backups[i] = __raw_readl(pio + PIO_IMR);
+               __raw_writel(backups[i], pio + PIO_IDR);
+               __raw_writel(wakeups[i], pio + PIO_IER);
+
+               if (!wakeups[i]) {
+                       clk_unprepare(gpio_chips[i]->clock);
+                       clk_disable(gpio_chips[i]->clock);
+               } else {
+                       printk(KERN_DEBUG "GPIO-%c may wake for %08x\n",
+                              'A'+i, wakeups[i]);
+               }
+       }
+}
+
+void at91_pinctrl_gpio_resume(void)
+{
+       int i;
+
+       for (i = 0; i < gpio_banks; i++) {
+               void __iomem  *pio;
+
+               if (!gpio_chips[i])
+                       continue;
+
+               pio = gpio_chips[i]->regbase;
+
+               if (!wakeups[i]) {
+                       if (clk_prepare(gpio_chips[i]->clock) == 0)
+                               clk_enable(gpio_chips[i]->clock);
+               }
+
+               __raw_writel(wakeups[i], pio + PIO_IDR);
+               __raw_writel(backups[i], pio + PIO_IER);
+       }
+}
+
 #else
 #define gpio_irq_set_wake      NULL
-#endif
+#endif /* CONFIG_PM */
 
 static struct irq_chip gpio_irqchip = {
        .name           = "GPIO",
@@ -1508,7 +1567,7 @@ static int at91_gpio_probe(struct platform_device *pdev)
                goto err;
        }
 
-       at91_chip->ops = (struct at91_pinctrl_mux_ops*)
+       at91_chip->ops = (struct at91_pinctrl_mux_ops *)
                of_match_device(at91_gpio_of_match, &pdev->dev)->data;
        at91_chip->pioc_virq = irq;
        at91_chip->pioc_idx = alias_idx;
@@ -1545,7 +1604,8 @@ static int at91_gpio_probe(struct platform_device *pdev)
                        chip->ngpio = ngpio;
        }
 
-       names = devm_kzalloc(&pdev->dev, sizeof(char*) * chip->ngpio, GFP_KERNEL);
+       names = devm_kzalloc(&pdev->dev, sizeof(char *) * chip->ngpio,
+                            GFP_KERNEL);
 
        if (!names) {
                ret = -ENOMEM;
@@ -1555,7 +1615,7 @@ static int at91_gpio_probe(struct platform_device *pdev)
        for (i = 0; i < chip->ngpio; i++)
                names[i] = kasprintf(GFP_KERNEL, "pio%c%d", alias_idx + 'A', i);
 
-       chip->names = (const char*const*)names;
+       chip->names = (const char *const *)names;
 
        range = &at91_chip->range;
        range->name = chip->label;