0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include <linux/init.h>
0032 #include <linux/kernel.h>
0033 #include <linux/types.h>
0034 #include <linux/gpio.h>
0035 #include <asm/mach-au1x00/gpio-au1000.h>
0036 #include <asm/mach-au1x00/gpio-au1300.h>
0037
0038 static int gpio2_get(struct gpio_chip *chip, unsigned offset)
0039 {
0040 return !!alchemy_gpio2_get_value(offset + ALCHEMY_GPIO2_BASE);
0041 }
0042
0043 static void gpio2_set(struct gpio_chip *chip, unsigned offset, int value)
0044 {
0045 alchemy_gpio2_set_value(offset + ALCHEMY_GPIO2_BASE, value);
0046 }
0047
0048 static int gpio2_direction_input(struct gpio_chip *chip, unsigned offset)
0049 {
0050 return alchemy_gpio2_direction_input(offset + ALCHEMY_GPIO2_BASE);
0051 }
0052
0053 static int gpio2_direction_output(struct gpio_chip *chip, unsigned offset,
0054 int value)
0055 {
0056 return alchemy_gpio2_direction_output(offset + ALCHEMY_GPIO2_BASE,
0057 value);
0058 }
0059
0060 static int gpio2_to_irq(struct gpio_chip *chip, unsigned offset)
0061 {
0062 return alchemy_gpio2_to_irq(offset + ALCHEMY_GPIO2_BASE);
0063 }
0064
0065
0066 static int gpio1_get(struct gpio_chip *chip, unsigned offset)
0067 {
0068 return !!alchemy_gpio1_get_value(offset + ALCHEMY_GPIO1_BASE);
0069 }
0070
0071 static void gpio1_set(struct gpio_chip *chip,
0072 unsigned offset, int value)
0073 {
0074 alchemy_gpio1_set_value(offset + ALCHEMY_GPIO1_BASE, value);
0075 }
0076
0077 static int gpio1_direction_input(struct gpio_chip *chip, unsigned offset)
0078 {
0079 return alchemy_gpio1_direction_input(offset + ALCHEMY_GPIO1_BASE);
0080 }
0081
0082 static int gpio1_direction_output(struct gpio_chip *chip,
0083 unsigned offset, int value)
0084 {
0085 return alchemy_gpio1_direction_output(offset + ALCHEMY_GPIO1_BASE,
0086 value);
0087 }
0088
0089 static int gpio1_to_irq(struct gpio_chip *chip, unsigned offset)
0090 {
0091 return alchemy_gpio1_to_irq(offset + ALCHEMY_GPIO1_BASE);
0092 }
0093
0094 struct gpio_chip alchemy_gpio_chip[] = {
0095 [0] = {
0096 .label = "alchemy-gpio1",
0097 .direction_input = gpio1_direction_input,
0098 .direction_output = gpio1_direction_output,
0099 .get = gpio1_get,
0100 .set = gpio1_set,
0101 .to_irq = gpio1_to_irq,
0102 .base = ALCHEMY_GPIO1_BASE,
0103 .ngpio = ALCHEMY_GPIO1_NUM,
0104 },
0105 [1] = {
0106 .label = "alchemy-gpio2",
0107 .direction_input = gpio2_direction_input,
0108 .direction_output = gpio2_direction_output,
0109 .get = gpio2_get,
0110 .set = gpio2_set,
0111 .to_irq = gpio2_to_irq,
0112 .base = ALCHEMY_GPIO2_BASE,
0113 .ngpio = ALCHEMY_GPIO2_NUM,
0114 },
0115 };
0116
0117 static int alchemy_gpic_get(struct gpio_chip *chip, unsigned int off)
0118 {
0119 return !!au1300_gpio_get_value(off + AU1300_GPIO_BASE);
0120 }
0121
0122 static void alchemy_gpic_set(struct gpio_chip *chip, unsigned int off, int v)
0123 {
0124 au1300_gpio_set_value(off + AU1300_GPIO_BASE, v);
0125 }
0126
0127 static int alchemy_gpic_dir_input(struct gpio_chip *chip, unsigned int off)
0128 {
0129 return au1300_gpio_direction_input(off + AU1300_GPIO_BASE);
0130 }
0131
0132 static int alchemy_gpic_dir_output(struct gpio_chip *chip, unsigned int off,
0133 int v)
0134 {
0135 return au1300_gpio_direction_output(off + AU1300_GPIO_BASE, v);
0136 }
0137
0138 static int alchemy_gpic_gpio_to_irq(struct gpio_chip *chip, unsigned int off)
0139 {
0140 return au1300_gpio_to_irq(off + AU1300_GPIO_BASE);
0141 }
0142
0143 static struct gpio_chip au1300_gpiochip = {
0144 .label = "alchemy-gpic",
0145 .direction_input = alchemy_gpic_dir_input,
0146 .direction_output = alchemy_gpic_dir_output,
0147 .get = alchemy_gpic_get,
0148 .set = alchemy_gpic_set,
0149 .to_irq = alchemy_gpic_gpio_to_irq,
0150 .base = AU1300_GPIO_BASE,
0151 .ngpio = AU1300_GPIO_NUM,
0152 };
0153
0154 static int __init alchemy_gpiochip_init(void)
0155 {
0156 int ret = 0;
0157
0158 switch (alchemy_get_cputype()) {
0159 case ALCHEMY_CPU_AU1000:
0160 ret = gpiochip_add_data(&alchemy_gpio_chip[0], NULL);
0161 break;
0162 case ALCHEMY_CPU_AU1500...ALCHEMY_CPU_AU1200:
0163 ret = gpiochip_add_data(&alchemy_gpio_chip[0], NULL);
0164 ret |= gpiochip_add_data(&alchemy_gpio_chip[1], NULL);
0165 break;
0166 case ALCHEMY_CPU_AU1300:
0167 ret = gpiochip_add_data(&au1300_gpiochip, NULL);
0168 break;
0169 }
0170 return ret;
0171 }
0172 arch_initcall(alchemy_gpiochip_init);