About calling kernel functions in the driver to implement gpio register settings

Publisher:advancement4Latest update time:2019-11-12 Source: 51heiKeywords:Driver Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Series Function

The functions are defined in arch/arm/mach-s3c2410/gpio.c, and the related macros are defined in include/asm-arm/arch-s3c2410/regs-gpio.h

(1) void s3c2410_gpio_setpin(unsigned int pin, unsigned intto);

Set the output value of the corresponding GPIO port, for example:

pin=S3C2410_GPG2, to=0, then set the output value of S3C2410_GPG2 to 0;

pin=S3C2410_GPG2, to=1, then set the output value of S3C2410_GPG2 to 1.

Function definition:

viewplain


void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)  

{  

    void __iomem *base = S3C2410_GPIO_BASE(pin);  

    unsigned long offs = S3C2410_GPIO_OFFSET(pin);  

    unsigned long flags;  

    unsigned long dat;  

  

    local_irq_save(flags);  

  

    dat = __raw_readl(base + 0x04);  

    dat &= ~(1 << offs);  

    dat |= to << offs;  

    __raw_writel(dat, base + 0x04);  

  

    local_irq_restore(flags);  

}  

EXPORT_SYMBOL(s3c2410_gpio_setpin);  



(2) unsigned int s3c2410_gpio_getpin(unsigned intpin);

Get the value of the corresponding GPIO port.

Function definition:

viewplain


unsigned int s3c2410_gpio_getpin(unsigned int pin)  

{  

    void __iomem *base = S3C2410_GPIO_BASE(pin);  

    unsigned long offs = S3C2410_GPIO_OFFSET(pin);  

  

    return __raw_readl(base + 0x04) & (1<< offs);  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_getpin);  



(3) void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function);

Set the working mode of the corresponding GPIO port, input, output, interrupt, etc.

Function definition:

viewplain


void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)  

{  

    void __iomem *base = S3C2410_GPIO_BASE(pin);  

    unsigned long mask;  

    unsigned long con;  

    unsigned long flags;  

  

    if (pin < S3C2410_GPIO_BANKB) {  

        mask = 1 << S3C2410_GPIO_OFFSET(pin);  

    } else {  

        mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;  

    }  

  

    local_irq_save(flags);  

  

    con = __raw_readl(base + 0x00);  

    con &= ~mask;  

    con |= function;  

  

    __raw_writel(con, base + 0x00);  

  

    local_irq_restore(flags);  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_cfgpin);  



(4) unsigned int s3c2410_gpio_getcfg(unsigned intpin);

Get the working mode of the corresponding GPIO port, including input, output, interrupt, etc.

Function definition:

viewplain


unsigned int s3c2410_gpio_getcfg(unsigned int pin)  

{  

    void __iomem *base = S3C2410_GPIO_BASE(pin);  

    unsigned long mask;  

  

    if (pin < S3C2410_GPIO_BANKB) {  

        mask = 1 << S3C2410_GPIO_OFFSET(pin);  

    } else {  

        mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;  

    }  

  

    return __raw_readl(base) & mask;  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_getcfg);  



(5) voids3c2410_gpio_pullup(unsigned int pin, unsigned intto);

Set the level of the corresponding GPIO port, for example:

pin=S3C2410_GPG2, to=0, then pull down S3C2410_GPG2, that is, set the value of S3C2410_GPG2 to 0;

pin=S3C2410_GPG2, to=1, then pull up S3C2410_GPG2, that is, set the value of S3C2410_GPG2 to 1.

Function definition:

viewplain


void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)  

{  

    void __iomem *base = S3C2410_GPIO_BASE(pin);  

    unsigned long offs = S3C2410_GPIO_OFFSET(pin);  

    unsigned long flags;  

    unsigned long up;  

  

    if (pin < S3C2410_GPIO_BANKB)  

        return;  

  

    local_irq_save(flags);  

  

    up = __raw_readl(base + 0x08);  

    up &= ~(1L << offs);  

    up |= to << offs;  

    __raw_writel(up, base + 0x08);  

  

    local_irq_restore(flags);  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_pullup);  



(6) unsigned int s3c2410_modify_misccr(unsigned int clear,unsigned int change);

Miscellaneous settings, set register MISCCR, see the function definition for details.

Function definition:

viewplain


unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)  

{  

    unsigned long flags;  

    unsigned long misccr;  

  

    local_irq_save(flags);  

    misccr = __raw_readl(S3C2410_MISCCR);  

    misccr &= ~clear;  

    misccr ^= change;  

    __raw_writel(misccr, S3C2410_MISCCR);  

    local_irq_restore(flags);  

  

    return misccr;  

}  

  

EXPORT_SYMBOL(s3c2410_modify_misccr);  



(7) int s3c2410_gpio_getirq(unsigned intpin);

Get the interrupt number corresponding to the corresponding GPIO port.

Function definition:

viewplain


int s3c2410_gpio_getirq(unsigned int pin)  

{  

    if (pin < S3C2410_GPF0 || pin > S3C2410_GPG15_EINT23)  

        return -1;   

  

    if (pin < S3C2410_GPG0 && pin > S3C2410_GPF7)  

        return -1;   

  

    if (pin < S3C2410_GPF4)  

        return (pin - S3C2410_GPF0) + IRQ_EINT0;  

  

    if (pin < S3C2410_GPG0)  

        return (pin - S3C2410_GPF4) + IRQ_EINT4;  

  

    return (pin - S3C2410_GPG0) + IRQ_EINT8;  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_getirq);  



(8) int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on, unsigned int config);

Interrupt filter configuration, see the function definition for details.

Function definition:

viewplain


int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,  

               unsigned int config)  

{  

    void __iomem *reg = S3C2410_EINFLT0;  

    unsigned long flags;  

    unsigned long val;  

  

    if (pin < S3C2410_GPG8 || pin > S3C2410_GPG15)  

        return -1;  

  

    config &= 0xff;  

  

    pin -= S3C2410_GPG8_EINT16;  

    reg += pin & ~3;  

  

    local_irq_save(flags);  

  

      

  

    val = __raw_readl(reg);  

    val &= ~(0xff << ((pin & 3) * 8));  

    val |= config << ((pin & 3) * 8);  

    __raw_writel(val, reg);  

  

      

  

    val = __raw_readl(S3C2410_EXTINT2);  

    val &= ~(1 << ((pin * 4) + 3));  

    val |= on << ((pin * 4) + 3);  

    __raw_writel(val, S3C2410_EXTINT2);  

  

    local_irq_restore(flags);  

  

    return 0;  

}  

  

EXPORT_SYMBOL(s3c2410_gpio_irqfilter); 

Keywords:Driver Reference address:About calling kernel functions in the driver to implement gpio register settings

Previous article:Make the mnt folder of the arm development board visible as a mount in the Linux virtual machine
Next article:ARM for ADS1.2

Recommended ReadingLatest update time:2024-11-16 13:45

LED digital tube driver chip selection guide
LED digital tube driver chip selection guide TM1620/TM1637/TM1668 and other LED digital tube driver chips are LED digital tube driver chips used in small household appliances, set-top boxes, electronic scales and other products. They can replace the traditional digital tube driver chips 74HC164, 4094, 374 plus trans
[Microcontroller]
USB device driver transplantation U disk mounting
Migration environment BootLoader: u-boot-1.1.6 kernel:linux-2.6.30.4 CPU: S3C2440 Transplantation steps In the linux-2.6.30.4 kernel, USB flash drives, USB mice and keyboards are already supported. Here you only need to make corresponding configurations to support them. 1. Kernel configuration #make menuconfig, th
[Microcontroller]
USB device driver transplantation U disk mounting
Character device driver key driver---interrupt mode
Interrupt function: include #include linux/irq.h request_irq(irq,handle,irqflag,name,dev_id) {     1. Allocate an irqaction structure     2. Put this structure into irq_desc (action linked list)    3. Set the pins    4. Enable interrupts } free_irq(irq,dev_id) {       1. irqaciton出链       2. Disable interruptions } -
[Microcontroller]
Intel: "Cultivation + Delivery" dual-driven talent strategy upgrade to create an ecological closed loop
June 22, 2021, Chongqing——Intelligent movement with "cores" and people-oriented. Today, Intel FPGA China Innovation Center announced the launch of special training and delivery cooperation for FPGA talents with many ecological partners. As an important strategic upgrade of Intel FPGA talent training, Intel FPGA China
[Embedded]
Intel:
Researchers create micro-drone propelled by light-driven nanomotors
A handheld laser pointer produces no noticeable recoil when it "fires" - even though it fires a directed stream of light particles. The reason is simply that its mass is relatively large compared to the very tiny recoil pulse caused when the light particles leave the laser pointer. However, it has long been know
[Internet of Things]
Researchers create micro-drone propelled by light-driven nanomotors
How to use cancellation drive circuit to improve common mode rejection ratio
ECG detection is the detection of weak signals under strong common-mode interference. In order to improve the common-mode rejection ratio of the circuit, a cancellation drive circuit (right leg drive) is often used to improve the common-mode rejection ratio. The ECG signal is a differential voltage between spec
[Medical Electronics]
How to use cancellation drive circuit to improve common mode rejection ratio
Touch screen driver solution based on Linux system
introduction As an input device, the touch screen has the advantages of being durable, fast in response, space-saving, and easy to communicate. It provides a simple, convenient, and natural way of human-computer interaction and is currently widely used in industrial control, electronic inquiry, and consumer ele
[Power Management]
Touch screen driver solution based on Linux system
High-efficiency 120 white LED driving technology based on SC442 design
SC442 is a 10-channel high-efficiency 120 white LED driver with an input voltage of 4.5V-21V. The high-efficiency boost converter can make the output voltage up to 42V, which is very suitable for medium to large LCD displays. The current sink is programmable, up to 30mA per channel, and the current matching between
[Power Management]
High-efficiency 120 white LED driving technology based on SC442 design
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号