Linux kernel header file macro about S3C2410 gpio

Source: Internet
Author: User
Tags define definition

Linux kernel header file macro about S3C2410 gpio

1. gpio register Definition
1. # define gpcon (x) _ reg2 (0x56000000, (x) * 0x10)
This statement defines the control register of gpio 2410. Note that the _ reg2 parameter is the physical address of the register. This physical address is converted to a virtual address through the _ reg2 macro, compare the 2410 manual to get the corresponding relationship:
Gpcon (1) ------ port a 0x56000000
Gpcon (2) ------ port B 0x56000010
Gpcon (3) ------ port C 0x56000020
....
....
....
Gpcon (8) ------ port H 0x56000070
2. # define gpdat (x) _ reg2 (0x56000004, (x) * 0x10)
This statement defines the 2410 gpio data register. The definition method is the same as that of the gpcon macro.
Gpdat (1) ------ port a 0x56000004
Gpdat (2) ------ port B 0x56000014
Gpdat (3) ------ port C 0x56000024
....
....
....
Gpdat (8) ------ port H 0x56000074
3. # define gpup (x) _ reg2 (0x56000008, (x) * 0x10)
This statement defines the up-pull resistance mask/activation register of the 2410 gpio, which is defined in the same way as the gpcon macro.
Gpup (1) ------ port a 0x56000008
Gpup (2) ------ port B 0x56000018
Gpup (3) ------ port C 0x56000028
....
....
....
Gpup (8) ------ port H 0x56000078
Ii. gpio port number Definition
Use gpio_g12 to describe how to define the port number of the IO port in the kernel header file $(kernel_include)/ASM-arm/ARCH/S3C2410. h. Defining gpio ports mainly involves the following macros:
# Define make_gpio_num (p, O) (P <gpio_port_shiftt) | (O <gpio_ofs_shift) # define gpio_g12 make_gpio_num (portg_ofs, 12) the swap value is 8, represents the displacement of the gpio group number in the whole gpio port number (such as gpio_g12) Field
The value of gpio_ofs_shift is 0, which indicates the displacement of the Offset number in the gpio group in the whole gpio port number (such as gpio_g12) field.
There are 117 input/output port pins in S3C2410. It can be divided into the following eight groups:
-Port A (GPA): 23-output port # define porta_ofs 0
-Port B (GPB): 11-input/output port # define portb_ofs 1
-Port C (GPC): 16-input/output port # define portc_ofs 2
-Port D (GPD): 16-input/output port # define portd_ofs 3
-Port E (GPE): 16-input/output port # define porte_ofs 4
-Port F (GPF): 8-input/output port # define portf_ofs 5
-Port g (GPG): 16-input/output port # define portg_ofs 6
-Port H (gph): 11-input/output port # define porth_ofs 7

Gpg12 belongs to the G group and the intra-group offset is 12. From the two macro definitions above, we can clearly see the structure of gpio_g12:


Figure 1 Structure of gpio port number
There are eight groups of ports. From the macro definition above, we can see that the port group number P ranges from 0 ~ 7. The Group offset groups are different. Port A has 23 output ports, so the intra-group offset o is 0 ~ 22. Port G has 16 Io ports, and its intra-group offset o is 0 ~ 15. gpio in other groups and so on.
Iii. write_gpio_bit (x, v) Macro Analysis
Write_gpio_bit macro imports two parameters, the first is the gpio port number, such as gpio_g12; the second parameter is 1 or 0, set the high level or low level output for the corresponding IO port. The specific macro scale is as follows:
# Define write_gpio_bit (x, v )/
({/
Gpdat (grab_port (X) & = ~ (0x1 X )));/
Gpdat (grab_port (x) | = (v) X )));/
})
The grab_port macro parameter is the gpio port number. The function is to parse the group number from the gpio port number. The specific definition is as follows:
# Define grab_port (x) & gpio_port_mask)> gpio_port_shiftt)
The gpio_port_mask is the group number mask and its value is 0x0000ff00, which can be seen in figure 1.
The grab_ofs macro is similar to the grab_port macro. Its function is to parse the intra-group offset from the gpio Port:
# Define grab_ofs (x) & gpio_ofs_mask)> gpio_ofs_shift)
The offset value mask gpio_ofs_mask = 0x000000ff.
Now we can analyze the write_gpio_bit (gpio_g12, 1) statement based on the preceding description: The macro definition of gpio_g12 can calculate the value of 0x0000060c, grab_port (gpio_g12) after parsing, the operated Io belongs to the G group and the group number is 6. The grab_ofs (gpio_g12) resolves the IO port to the 12th pins (starting from 0) of the G group, which is gpg12, the expression value is 12. Write_gpio_bit (gpio_g12, 1) is equivalent to the following two statements:
Gpdat (6) & = ~ (0x112); // The 12th-bit clearing of the gpgdat register
Gpdat (6) | = 112; // write '1' to the 12th-bit gpgdat register'
At this point, we know that the write_gpio_bit (gpio_g12, 1) statement is to pull the gpg12 pin to a high level.
Iv. set_gpio_ctrl (x) Macro Analysis
# Define set_gpio_ctrl (X )/
({Gpcon (grab_port (X) & = ~ (0x3
Gpcon (grab_port (x) | = (grab_mode (X)
Gpup (grab_port (X) & = ~ (1
Gpup (grab_port (x) | = (grab_pullup (x ))
After the write_gpio_bit macro is analyzed, it is easy to see set_gpio_ctrl! In its macro development, only grab_mode (X) and grab_pullup (x) are added) the mode of the IO port and the Enable/shield up resistance of the port are parsed from parameter x respectively. It is worth noting that the parameter X of set_gpio_ctrl not only indicates the gpio port number, but also has the mode status and pull-up resistance control information. The structure of the parameter X is as follows:

Figure 2 parameter field structure of set_gpio_ctrl

The low 16-bit value is the gpio port number described above. The R field in the high 16-bit value is used to shield/enable the pull-up resistance function of the IO port. R = 0: enables the pull-up resistor; r = 1: the pull-up resistor is invalid. The m field is used to set the operating mode of the IO port. m = 0 indicates that the IO port is the input port, M = 1 indicates that the IO port is the output port, and m = 2 indicates that function 1 is optional; M = 3. Optional; function 2.
The set_gpio_ctrl macro is to write the gpxcon (X is ~ H) To set the IO port mode (each bit of gpacon controls an IO port, while gpbcon ~ Gphcon is a two-bit mode that controls an I/O port. By writing gpxup (X is ~ H) To determine whether to enable the pull-up resistance. The typical set_gpio_ctrl call method is as follows:
Set_gpio_ctrl (gpio_mode_out | gpio_pullup_dis | gpio_g12 );
This statement sets gpg12 to the output mode without using the port pull-up resistance.
5. Conclusion
The preceding section analyzes $(linux_kernel_include)/ASM-arm/ARCH/S3C2410 in combination with "S3C2410X 32-bit Proteus microprocessor User's Manual. several macros defined in H to operate on 2410gpio, in addition to the several macros mentioned in this article, include read_gpio_bit (x), read_gpio_reg (x), write_gpio_reg (x, v), etc, the implementation method is similar to the above. I will not go into details here! //////////////////////////////////////// ///////# Define gpcon (x) _ reg2 (0x56000000, (x) * 0x10) <br/> # define gpdat (x) _ reg2 (0x56000004, (x) * 0x10) <br/> # define gpup (x) _ reg2 (0x56000008, (x) * 0x10) </P> <p> # define gpio_ofs_shift0 <br/> # define gpio_port_shiftt8 <br/> # define gpio_pullup_shift16 <br/> # define condition <br /># define gpio_port_mask0x0000ff00 <br/> # define gpio_pullup_mask0x00ff0000 <br/> # defi Ne gpio_mode_mask0xff000000 <br/> # define gpio_mode_in (0 <gpio_mode_shift) <br/> # define gpio_mode_out (1 <gpio_mode_shift) <br/> # define transform (2 <gpio_mode_shift) <br/> # define transform (3 <gpio_mode_shift) <br/> # define gpio_pullup_en (0 <gpio_pullup_shift) <br/> # define gpio_pullup_dis (1 <gpio_pullup_shift) </P> <p> # define porta_ofs0 <br/> # define portb_ofs1 <br/> # define portc_o Fs2 <br/> # define portd_ofs3 <br/> # define porte_ofs4 <br/> # define portf_ofs5 <br/> # define portg_ofs6 <br/> # define porth_ofs7 </P> <p> # define make_gpio_num (p, o) (P <gpio_port_shiftt) | (O <gpio_ofs_shift) </P> <p> # define grab_mode (x) & gpio_mode_mask)> gpio_mode_shift) <br/> # define grab_pullup (x) & gpio_pullup_mask)> gpio_pullup_shift) <br/> # define grab_port (x) & gpio_port_mask)> Gpio_port_shiftt) <br/> # define grab_ofs (x) & gpio_ofs_mask)> gpio_ofs_shift) </P> <p> # define set_gpio_ctrl (X) /<br/> ({gpcon (grab_port (X) & = ~ (0x3 <(grab_ofs (x) * 2);/<br/> gpcon (grab_port (x) | = (grab_mode (X) <(grab_ofs (x) * 2);/<br/> gpup (grab_port (X) & = ~ (1 <grab_ofs (X);/<br/> gpup (grab_port (X) | = (grab_pullup (x )) <grab_ofs (x) ;}) <br/> # define set_gpio_pullup (X)/<br/> ({gpup (grab_port (X ))) & = ~ (1 <grab_ofs (X);/<br/> gpup (grab_port (X) | = (grab_pullup (x )) <grab_ofs (x) ;}) <br/> # define set_gpio_pullup_user (x, v)/<br/> ({gpup (grab_port (X ))) & = ~ (1 <grab_ofs (X);/<br/> gpup (grab_port (X) | = (V) <grab_ofs (x) ;}) <br/> # define set_gpio_mode (X)/<br/> ({gpcon (grab_port (X ))) & = ~ (0x3 <(grab_ofs (x) * 2);/<br/> gpcon (grab_port (X ))) | = (grab_mode (x) <(grab_ofs (x) * 2);}) <br/> # define set_gpio_mode_user (x, V) /<br/> ({gpcon (grab_port (X) & = ~ (0x3 <(grab_ofs (x) * 2);/<br/> gpcon (grab_port (X) | = (V) <(grab_ofs (x) * 2);}) <br/> # define set_gpioa_mode (X) /<br/> ({gpcon (grab_port (X) & = ~ (0x1 <grab_ofs (X);/<br/> gpcon (grab_port (X) | = (grab_mode (x )) <grab_ofs (x) ;}) <br/> # define read_gpio_bit (x) (gpdat (grab_port (X ))) & (1 <grab_ofs (X)> grab_ofs (X) <br/> # define read_gpio_reg (X) (gpdat (grab_port (X) <br/> # define write_gpio_bit (x, v)/<br/> ({gpdat (grab_port (X ))) & = ~ (0x1 <grab_ofs (X);/<br/> gpdat (grab_port (X) | = (V) <grab_ofs (x) ;}) <br/> # define write_gpio_reg (x, V) (gpdat (grab_port (X) = (V )) </P> <p> # define partition (porta_ofs, 0) <br/> # define partition (porta_ofs, 1) <br/> # define gpio_a2make_gpio_num (porta_ofs, 2) <br/> # define gpio_a3make_gpio_num (porta_ofs, 3) <br/> # define gpio_a4make_gpio_num (porta_ofs, 4) <br/> # define partition (porta_ofs, 5) <br/> # define gpio_a6make_gpio_num (porta_ofs, 6) <br/> # define gpio_a7make_gpio_num (porta_ofs, 7) <br/> # define partition (porta_ofs, 8) <br/> # define partition (porta_ofs, 9) <br/> # define partition (porta_ofs, 10) <br/> # define gpio_a11make_gpio_num (porta_ofs, 11) <br/> # define partition (porta_ofs, 12) <br/> # define partition (porta_ofs, 13) <br/> # define gpio_a14make_gpio_num (porta_ofs, 14) <br/> # define partition (porta_ofs, 15) <br/> # define partition (porta_ofs, 16) <br/> # define gpio_a17make_gpio_num (porta_ofs, 17) <br/> # define partition (porta_ofs, 18) <br/> # define partition (porta_ofs, 19) <br/> # define gpio_a20make_gpio_num (porta_ofs, 20) <br/> # define partition (porta_ofs, 21) <br/> # define gpio_a22make_gpio_num (porta_ofs, 22) </P> <p> # define partition (portb_ofs, 0) <br/> # define partition (portb_ofs, 1) <br/> # define gpio_b2make_gpio_num (portb_ofs, 2) <br/> # define gpio_b3make_gpio_num (portb_ofs, 3) <br/> # define gpio_b4make_gpio_num (portb_ofs, 4) <br/> # define partition (portb_ofs, 5) <br/> # define gpio_b6make_gpio_num (portb_ofs, 6) <br/> # define gpio_b7make_gpio_num (portb_ofs, 7) <br/> # define partition (portb_ofs, 8) <br/> # define gpio_b9make_gpio_num (portb_ofs, 9) <br/> # define partition (portb_ofs, 10) </P> <p> # define gpio_c0make_gpio_num (portc_ofs, 0) <br/> # define gpio_c1make_gpio_num (portc_ofs, 1) <br/> # define gpio_c2make_gpio_num (portc_ofs, 2) <br/> # define partition (portc_ofs, 3) <br/> # define gpio_c4make_gpio_num (portc_ofs, 4) <br/> # define gpio_c5make_gpio_num (portc_ofs, 5) <br/> # define gpio_c6make_gpio_num (portc_ofs, 6) <br/> # define partition (portc_ofs, 7) <br/> # define gpio_c8make_gpio_num (portc_ofs, 8) <br/> # define gpio_c9make_gpio_num (portc_ofs, 9) <br/> # define partition (portc_ofs, 10) <br/> # define gpio_c11make_gpio_num (portc_ofs, 11) <br/> # define partition (portc_ofs, 12) <br/> # define gpio_c13make_gpio_num (portc_ofs, 13) <br/> # define partition (portc_ofs, 14) <br/> # define gpio_c15make_gpio_num (portc_ofs, 15) </P> <p> # define partition (portd_ofs, 0) <br/> # define Export (portd_ofs, 1) <br/> # define gpio_d2make_gpio_num (portd_ofs, 2) <br/> # define gpio_d3make_gpio_num (portd_ofs, 3) <br/> # define gpio_d4make_gpio_num (portd_ofs, 4) <br/> # define partition (portd_ofs, 5) <br/> # define gpio_d6make_gpio_num (portd_ofs, 6) <br/> # define Export (portd_ofs, 7) <br/> # define gpio_d8make_gpio_num (portd_ofs, 8) <br/> # define gpio_d9make_gpio_num (portd_ofs, 9) <br/> # define gpio_d10make_gpio_num (portd_ofs, 10) <br/> # define partition (portd_ofs, 11) <br/> # define gpio_d12make_gpio_num (portd_ofs, 12) <br/> # define gpio_d13make_gpio_num (portd_ofs, 13) <br/> # define Export (portd_ofs, 14) <br/> # define gpio_d15make_gpio_num (portd_ofs, 15) </P> <p> # define partition (porte_ofs, 0) <br/> # define partition (porte_ofs, 1) <br/> # define gpio_e2make_gpio_num (porte_ofs, 2) <br/> # define gpio_e3make_gpio_num (porte_ofs, 3) <br/> # define partition (porte_ofs, 4) <br/> # define partition (porte_ofs, 5) <br/> # define gpio_e6make_gpio_num (porte_ofs, 6) <br/> # define partition (porte_ofs, 7) <br/> # define partition (porte_ofs, 8) <br/> # define partition (porte_ofs, 9) <br/> # define partition (porte_ofs, 10) <br/> # define gpio_e11make_gpio_num (porte_ofs, 11) <br/> # define partition (porte_ofs, 12) <br/> # define partition (porte_ofs, 13) <br/> # define gpio_e14make_gpio_num (porte_ofs, 14) <br/> # define partition (porte_ofs, 15) </P> <p> # define gpio_f0make_gpio_num (portf_ofs, 0) <br/> # define partition (portf_ofs, 1) <br/> # define gpio_f2make_gpio_num (portf_ofs, 2) <br/> # define gpio_f3make_gpio_num (portf_ofs, 3) <br/> # define partition (portf_ofs, 4) <br/> # define gpio_f5make_gpio_num (portf_ofs, 5) <br/> # define partition (portf_ofs, 6) <br/> # define gpio_f7make_gpio_num (portf_ofs, 7) </P> <p> # define gpio_g0make_gpio_num (portg_ofs, 0) <br/> # define transform (portg_ofs, 1) <br/> # define gpio_g2make_gpio_num (portg_ofs, 2) <br/> # define gpio_g3make_gpio_num (portg_ofs, 3) <br/> # define gpio_g4make_gpio_num (portg_ofs, 4) <br/> # define partition (portg_ofs, 5) <br/> # define gpio_g6make_gpio_num (portg_ofs, 6) <br/> # define Export (portg_ofs, 7) <br/> # define gpio_g8make_gpio_num (portg_ofs, 8) <br/> # define Export (portg_ofs, 9) <br/> # define gpio_g10make_gpio_num (portg_ofs, 10) <br/> # define gpio_g11make_gpio_num (portg_ofs, 11) <br/> # define gpio_g12make_gpio_num (portg_ofs, 12) <br/> # define Export (portg_ofs, 13) <br/> # define gpio_g14make_gpio_num (portg_ofs, 14) <br/> # define partition (portg_ofs, 15) </P> <p> # define partition (porth_ofs, 0) <br/> # define gpio_h1make_gpio_num (porth_ofs, 1) <br/> # define gpio_h2make_gpio_num (porth_ofs, 2) <br/> # define partition (porth_ofs, 3) <br/> # define gpio_h4make_gpio_num (porth_ofs, 4) <br/> # define gpio_h5make_gpio_num (porth_ofs, 5) <br/> # define partition (porth_ofs, 6) <br/> # define gpio_1_make_gpio_num (porth_ofs, 7) <br/> # define partition (porth_ofs, 8) <br/> # define gpio_h9make_gpio_num (porth_ofs, 9) <br/> # define gpio_h10make_gpio_num (porth_ofs, 10) </P> <p> # define gpio_mode_toutgpio_mode_alt0 <br/> # define definition <br /># define gpio_mode_lendgpio_mode_alt0 <br/> # define tuning <br/> # define Tuning <br/> # define gpio_mode_vdgpio_mode_alt0 <br/> # define tuning <br/> # define restart <br/> # define gpio_mode_sddatgpio_mode_alt0 <br/> # define restart <br/> # define tuning <br/> # define gpio_mode_eintgpio_mode_alt0 <br/> # define gpio_mode_nypongpio_mode_alt1 <br/> # define definition <br/> # define Definition gpio_mode_tclk_abnormalgpio_mode_alt1 <br/> # define restart <br/> # define gpio_mode_ LCD _pwrdngpio_mode_alt1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.