~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/m68k/platform/coldfire/gpio.c

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Coldfire generic GPIO support.
  3  *
  4  * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as published by
  8  * the Free Software Foundation; version 2 of the License.
  9  *
 10  * This program is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  */
 15 
 16 #include <linux/kernel.h>
 17 #include <linux/module.h>
 18 #include <linux/init.h>
 19 #include <linux/device.h>
 20 
 21 #include <linux/io.h>
 22 #include <asm/coldfire.h>
 23 #include <asm/mcfsim.h>
 24 #include <asm/mcfgpio.h>
 25 
 26 int __mcfgpio_get_value(unsigned gpio)
 27 {
 28         return mcfgpio_read(__mcfgpio_ppdr(gpio)) & mcfgpio_bit(gpio);
 29 }
 30 EXPORT_SYMBOL(__mcfgpio_get_value);
 31 
 32 void __mcfgpio_set_value(unsigned gpio, int value)
 33 {
 34         if (gpio < MCFGPIO_SCR_START) {
 35                 unsigned long flags;
 36                 MCFGPIO_PORTTYPE data;
 37 
 38                 local_irq_save(flags);
 39                 data = mcfgpio_read(__mcfgpio_podr(gpio));
 40                 if (value)
 41                         data |= mcfgpio_bit(gpio);
 42                 else
 43                         data &= ~mcfgpio_bit(gpio);
 44                 mcfgpio_write(data, __mcfgpio_podr(gpio));
 45                 local_irq_restore(flags);
 46         } else {
 47                 if (value)
 48                         mcfgpio_write(mcfgpio_bit(gpio),
 49                                         MCFGPIO_SETR_PORT(gpio));
 50                 else
 51                         mcfgpio_write(~mcfgpio_bit(gpio),
 52                                         MCFGPIO_CLRR_PORT(gpio));
 53         }
 54 }
 55 EXPORT_SYMBOL(__mcfgpio_set_value);
 56 
 57 int __mcfgpio_direction_input(unsigned gpio)
 58 {
 59         unsigned long flags;
 60         MCFGPIO_PORTTYPE dir;
 61 
 62         local_irq_save(flags);
 63         dir = mcfgpio_read(__mcfgpio_pddr(gpio));
 64         dir &= ~mcfgpio_bit(gpio);
 65         mcfgpio_write(dir, __mcfgpio_pddr(gpio));
 66         local_irq_restore(flags);
 67 
 68         return 0;
 69 }
 70 EXPORT_SYMBOL(__mcfgpio_direction_input);
 71 
 72 int __mcfgpio_direction_output(unsigned gpio, int value)
 73 {
 74         unsigned long flags;
 75         MCFGPIO_PORTTYPE data;
 76 
 77         local_irq_save(flags);
 78         data = mcfgpio_read(__mcfgpio_pddr(gpio));
 79         if (value)
 80                 data |= mcfgpio_bit(gpio);
 81         else
 82                 data &= mcfgpio_bit(gpio);
 83         mcfgpio_write(data, __mcfgpio_pddr(gpio));
 84 
 85         /* now set the data to output */
 86         if (gpio < MCFGPIO_SCR_START) {
 87                 data = mcfgpio_read(__mcfgpio_podr(gpio));
 88                 if (value)
 89                         data |= mcfgpio_bit(gpio);
 90                 else
 91                         data &= ~mcfgpio_bit(gpio);
 92                 mcfgpio_write(data, __mcfgpio_podr(gpio));
 93         } else {
 94                  if (value)
 95                         mcfgpio_write(mcfgpio_bit(gpio),
 96                                         MCFGPIO_SETR_PORT(gpio));
 97                  else
 98                          mcfgpio_write(~mcfgpio_bit(gpio),
 99                                          MCFGPIO_CLRR_PORT(gpio));
100         }
101         local_irq_restore(flags);
102         return 0;
103 }
104 EXPORT_SYMBOL(__mcfgpio_direction_output);
105 
106 int __mcfgpio_request(unsigned gpio)
107 {
108         return 0;
109 }
110 EXPORT_SYMBOL(__mcfgpio_request);
111 
112 void __mcfgpio_free(unsigned gpio)
113 {
114         __mcfgpio_direction_input(gpio);
115 }
116 EXPORT_SYMBOL(__mcfgpio_free);
117 
118 #ifdef CONFIG_GPIOLIB
119 
120 int mcfgpio_direction_input(struct gpio_chip *chip, unsigned offset)
121 {
122         return __mcfgpio_direction_input(offset);
123 }
124 
125 int mcfgpio_get_value(struct gpio_chip *chip, unsigned offset)
126 {
127         return __mcfgpio_get_value(offset);
128 }
129 
130 int mcfgpio_direction_output(struct gpio_chip *chip, unsigned offset, int value)
131 {
132         return __mcfgpio_direction_output(offset, value);
133 }
134 
135 void mcfgpio_set_value(struct gpio_chip *chip, unsigned offset, int value)
136 {
137         __mcfgpio_set_value(offset, value);
138 }
139 
140 int mcfgpio_request(struct gpio_chip *chip, unsigned offset)
141 {
142         return __mcfgpio_request(offset);
143 }
144 
145 void mcfgpio_free(struct gpio_chip *chip, unsigned offset)
146 {
147         __mcfgpio_free(offset);
148 }
149 
150 struct bus_type mcfgpio_subsys = {
151         .name           = "gpio",
152         .dev_name       = "gpio",
153 };
154 
155 static struct gpio_chip mcfgpio_chip = {
156         .label                  = "mcfgpio",
157         .request                = mcfgpio_request,
158         .free                   = mcfgpio_free,
159         .direction_input        = mcfgpio_direction_input,
160         .direction_output       = mcfgpio_direction_output,
161         .get                    = mcfgpio_get_value,
162         .set                    = mcfgpio_set_value,
163         .base                   = 0,
164         .ngpio                  = MCFGPIO_PIN_MAX,
165 };
166 
167 static int __init mcfgpio_sysinit(void)
168 {
169         gpiochip_add(&mcfgpio_chip);
170         return subsys_system_register(&mcfgpio_subsys, NULL);
171 }
172 
173 core_initcall(mcfgpio_sysinit);
174 #endif
175 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp