in the previous article, there was an article based on Arm-contexa9-linux Drive development: How to get the unique ID number on the boardin that article, you can refer to it in detail. At that time I used a simple character device driver framework, the final ID number through the Read method can read the ID, but it is too cumbersome, there is no easier way? In fact, this method is called IO address mapping, and today we want to say is the IO address dynamic mapping method, static mapping is too simple, directly call the corresponding interface, configure the corresponding register, set the state can be achieved. Next look at the driver code:
#if 0. IO address:. Static mapping://This header file is related to the platform, different platforms correspond to different gpio.h, that is, there are different configuration information Arch/arm/mach-exynos/include/mach/gpio.hgpio ==> S3C64XX_GPX (n) EXYNOS4X12_GPM0 () exynos4_gpd0 () int gpio_request (GPIO, "name"), Application, void Gpio_free (Gpio), revocation, int gpio_direction_output (Gpio, DAT), configured as output, output 1/0;int gpio_direction_input (GPIO), configured as input, input 1/0;int s3c_gpio_cfgpin (Gpio, S3C_GPIO_SFN (con)); Configured as Con;void gpio_set_value (gpio, DAT), Output 1/0;int gpio_get_value (gpio), Input 1/0;irqnum = GPIO_TO_IRQ (Gpio), Gpio <== > irqnummach_type_tiny4412/* Initial IO mappings */static struct Map_desc exynos_iodesc[] __initdata = {{. Virtual = (unsigned long) S5P_VA_CHIPID,.PFN = __PHYS_TO_PFN (exynos_pa_chipid),. length = Sz_4k,.type = Mt_device,},};. Dynamic mapping: Virt = Ioremap (phys, size),//vmalloc_areaiounmap (Virt),//Convert virtual address to 32-bit integer ioread32 (virt); Iowrite32 (Val, virt);// Convert virtual address to 16-bit integer number ioread16 (); Iowrite16 ();//Convert virtual address to 8-bit integer Ioread8 (); Iowrite8 (); #endif #include <linux/module.h># Include <linux/fs.h> #include <linux/sched.h> #iNclude <linux/delay.h> #include <linux/atomic.h> #include <linux/types.h> #include <linux/ interrupt.h> #include <linux/kthread.h> #include <linux/slab.h>//and IO-related header files # include <linux/io.h >//the physical address of the Board ID 0x10000000-----> through 4412 Manual query to # define Chip_id0x10000000int test_init (void) {int ret;unsigned int * Virt = NULL;PRINTK ("Test init\n");//Map The physical address of the chip_id to a virtual address, assigning a size of 4 bytes to it virt = Ioremap (chip_id, 4);//If the map is complete, the Virt pointer is empty, Returns the error code if (Is_err_or_null (Virt)) {ret =-eio;goto error_map;} Print virtual address PRINTK ("Virt =%p\n", virt);//Print Physical Address printk ("chip_id =%x\n", chip_id);//Convert virtual address to 32-bit integer PRINTK ("*virt =%x\n", IOREAD32 (Virt));//de-address mapping Iounmap (virt); return 0; Error_map:return ret;} void Test_exit (void) {PRINTK ("Test exit\n"); Module_init (Test_init); Module_exit (Test_exit); Module_license ("GPL"); Module_author ("Yangyx"); Module_version ("1.1");
Get the ID number on the TINY4412 board using IO mapping