2 * arch/arm/mach-ns9xxx/gpio-ns9360.c
4 * Copyright (C) 2006,2007 by Digi International Inc.
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>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <asm/arch-ns9xxx/regs-bbu.h>
18 #include <asm/arch-ns9xxx/processor-ns9360.h>
20 #include "gpio-ns9360.h"
22 static inline int ns9360_valid_gpio(unsigned gpio)
27 static inline void __iomem *ns9360_gpio_get_gconfaddr(unsigned gpio)
30 return BBU_GCONFb1(gpio / 8);
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)
46 /* this could be optimised away on ns9750 only builds */
50 static inline void __iomem *ns9360_gpio_get_gstataddr(unsigned gpio)
57 /* this could be optimised away on ns9750 only builds */
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);
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);
81 int ns9360_gpio_configure(unsigned gpio, int inv, int func)
83 if (likely(ns9360_valid_gpio(gpio))) {
85 printk(KERN_WARNING "use gpio_direction_input "
86 "or gpio_direction_output\n");
89 return __ns9360_gpio_configure(gpio, 0, inv, func);
93 EXPORT_SYMBOL(ns9360_gpio_configure);
95 int ns9360_gpio_get_value(unsigned gpio)
97 void __iomem *stat = ns9360_gpio_get_gstataddr(gpio);
100 ret = 1 & (__raw_readl(stat) >> (gpio & 31));
105 void ns9360_gpio_set_value(unsigned gpio, int value)
107 void __iomem *ctrl = ns9360_gpio_get_gctrladdr(gpio);
110 ctrlval = __raw_readl(ctrl);
113 ctrlval |= 1 << (gpio & 31);
115 ctrlval &= ~(1 << (gpio & 31));
117 __raw_writel(ctrlval, ctrl);