acpiphp: Execute ACPI _REG method for hotadded devices
[linux/fpc-iii.git] / arch / arm / mach-ns9xxx / gpio-ns9360.c
blob377330c1b250d69df22be7dec4b1465c252dc49f
1 /*
2 * arch/arm/mach-ns9xxx/gpio-ns9360.c
4 * Copyright (C) 2006,2007 by Digi International Inc.
5 * All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 #include <linux/bug.h>
12 #include <linux/errno.h>
13 #include <linux/io.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <mach/regs-bbu.h>
18 #include <mach/processor-ns9360.h>
20 #include "gpio-ns9360.h"
22 static inline int ns9360_valid_gpio(unsigned gpio)
24 return gpio <= 72;
27 static inline void __iomem *ns9360_gpio_get_gconfaddr(unsigned gpio)
29 if (gpio < 56)
30 return BBU_GCONFb1(gpio / 8);
31 else
33 * this could be optimised away on
34 * ns9750 only builds, but it isn't ...
36 return BBU_GCONFb2((gpio - 56) / 8);
39 static inline void __iomem *ns9360_gpio_get_gctrladdr(unsigned gpio)
41 if (gpio < 32)
42 return BBU_GCTRL1;
43 else if (gpio < 64)
44 return BBU_GCTRL2;
45 else
46 /* this could be optimised away on ns9750 only builds */
47 return BBU_GCTRL3;
50 static inline void __iomem *ns9360_gpio_get_gstataddr(unsigned gpio)
52 if (gpio < 32)
53 return BBU_GSTAT1;
54 else if (gpio < 64)
55 return BBU_GSTAT2;
56 else
57 /* this could be optimised away on ns9750 only builds */
58 return BBU_GSTAT3;
62 * each gpio can serve for 4 different purposes [0..3]. These are called
63 * "functions" and passed in the parameter func. Functions 0-2 are always some
64 * special things, function 3 is GPIO. If func == 3 dir specifies input or
65 * output, and with inv you can enable an inverter (independent of func).
67 int __ns9360_gpio_configure(unsigned gpio, int dir, int inv, int func)
69 void __iomem *conf = ns9360_gpio_get_gconfaddr(gpio);
70 u32 confval;
72 confval = __raw_readl(conf);
73 REGSETIM_IDX(confval, BBU_GCONFx, DIR, gpio & 7, dir);
74 REGSETIM_IDX(confval, BBU_GCONFx, INV, gpio & 7, inv);
75 REGSETIM_IDX(confval, BBU_GCONFx, FUNC, gpio & 7, func);
76 __raw_writel(confval, conf);
78 return 0;
81 int ns9360_gpio_configure(unsigned gpio, int inv, int func)
83 if (likely(ns9360_valid_gpio(gpio))) {
84 if (func == 3) {
85 printk(KERN_WARNING "use gpio_direction_input "
86 "or gpio_direction_output\n");
87 return -EINVAL;
88 } else
89 return __ns9360_gpio_configure(gpio, 0, inv, func);
90 } else
91 return -EINVAL;
93 EXPORT_SYMBOL(ns9360_gpio_configure);
95 int ns9360_gpio_get_value(unsigned gpio)
97 void __iomem *stat = ns9360_gpio_get_gstataddr(gpio);
98 int ret;
100 ret = 1 & (__raw_readl(stat) >> (gpio & 31));
102 return ret;
105 void ns9360_gpio_set_value(unsigned gpio, int value)
107 void __iomem *ctrl = ns9360_gpio_get_gctrladdr(gpio);
108 u32 ctrlval;
110 ctrlval = __raw_readl(ctrl);
112 if (value)
113 ctrlval |= 1 << (gpio & 31);
114 else
115 ctrlval &= ~(1 << (gpio & 31));
117 __raw_writel(ctrlval, ctrl);