Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
0003 
0004 extern unsigned scx200_gpio_base;
0005 extern unsigned long scx200_gpio_shadow[2];
0006 extern struct nsc_gpio_ops scx200_gpio_ops;
0007 
0008 #define scx200_gpio_present() (scx200_gpio_base!=0)
0009 
0010 /* Definitions to make sure I do the same thing in all functions */
0011 #define __SCx200_GPIO_BANK unsigned bank = index>>5
0012 #define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
0013 #define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank
0014 #define __SCx200_GPIO_INDEX index &= 31
0015 
0016 #define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
0017 
0018 /* returns the value of the GPIO pin */
0019 
0020 static inline int scx200_gpio_get(unsigned index) {
0021     __SCx200_GPIO_BANK;
0022     __SCx200_GPIO_IOADDR + 0x04;
0023     __SCx200_GPIO_INDEX;
0024         
0025     return (inl(ioaddr) & (1<<index)) ? 1 : 0;
0026 }
0027 
0028 /* return the value driven on the GPIO signal (the value that will be
0029    driven if the GPIO is configured as an output, it might not be the
0030    state of the GPIO right now if the GPIO is configured as an input) */
0031 
0032 static inline int scx200_gpio_current(unsigned index) {
0033         __SCx200_GPIO_BANK;
0034     __SCx200_GPIO_INDEX;
0035         
0036     return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
0037 }
0038 
0039 /* drive the GPIO signal high */
0040 
0041 static inline void scx200_gpio_set_high(unsigned index) {
0042     __SCx200_GPIO_BANK;
0043     __SCx200_GPIO_IOADDR;
0044     __SCx200_GPIO_SHADOW;
0045     __SCx200_GPIO_INDEX;
0046     set_bit(index, shadow); /* __set_bit()? */
0047     __SCx200_GPIO_OUT;
0048 }
0049 
0050 /* drive the GPIO signal low */
0051 
0052 static inline void scx200_gpio_set_low(unsigned index) {
0053     __SCx200_GPIO_BANK;
0054     __SCx200_GPIO_IOADDR;
0055     __SCx200_GPIO_SHADOW;
0056     __SCx200_GPIO_INDEX;
0057     clear_bit(index, shadow); /* __clear_bit()? */
0058     __SCx200_GPIO_OUT;
0059 }
0060 
0061 /* drive the GPIO signal to state */
0062 
0063 static inline void scx200_gpio_set(unsigned index, int state) {
0064     __SCx200_GPIO_BANK;
0065     __SCx200_GPIO_IOADDR;
0066     __SCx200_GPIO_SHADOW;
0067     __SCx200_GPIO_INDEX;
0068     if (state)
0069         set_bit(index, shadow);
0070     else
0071         clear_bit(index, shadow);
0072     __SCx200_GPIO_OUT;
0073 }
0074 
0075 /* toggle the GPIO signal */
0076 static inline void scx200_gpio_change(unsigned index) {
0077     __SCx200_GPIO_BANK;
0078     __SCx200_GPIO_IOADDR;
0079     __SCx200_GPIO_SHADOW;
0080     __SCx200_GPIO_INDEX;
0081     change_bit(index, shadow);
0082     __SCx200_GPIO_OUT;
0083 }
0084 
0085 #undef __SCx200_GPIO_BANK
0086 #undef __SCx200_GPIO_IOADDR
0087 #undef __SCx200_GPIO_SHADOW
0088 #undef __SCx200_GPIO_INDEX
0089 #undef __SCx200_GPIO_OUT