🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# FBTFT分析 FBTFT用于小尺寸屏的驱动,这里来分析下其结构。 每个实例只会有一种屏,所以在形如drivers/staging/fbtft/fb_ili9341.c的文件的最后是这样的: ~~~ FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9341", &display); MODULE_ALIAS("spi:" DRVNAME); MODULE_ALIAS("platform:" DRVNAME); MODULE_ALIAS("spi:ili9341"); MODULE_ALIAS("platform:ili9341"); MODULE_DESCRIPTION("FB driver for the ILI9341 LCD display controller"); MODULE_AUTHOR("Christian Vogelgsang"); MODULE_LICENSE("GPL"); ~~~ ~~~ #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \ \ static int fbtft_driver_probe_spi(struct spi_device *spi) \ { \ return fbtft_probe_common(_display, spi, NULL); \ } \ \ static int fbtft_driver_remove_spi(struct spi_device *spi) \ { \ struct fb_info *info = spi_get_drvdata(spi); \ \ return fbtft_remove_common(&spi->dev, info); \ } \ \ static int fbtft_driver_probe_pdev(struct platform_device *pdev) \ { \ return fbtft_probe_common(_display, NULL, pdev); \ } \ \ static int fbtft_driver_remove_pdev(struct platform_device *pdev) \ { \ struct fb_info *info = platform_get_drvdata(pdev); \ \ return fbtft_remove_common(&pdev->dev, info); \ } \ \ static const struct of_device_id dt_ids[] = { \ { .compatible = _compatible }, \ {}, \ }; \ \ MODULE_DEVICE_TABLE(of, dt_ids); \ \ \ static struct spi_driver fbtft_driver_spi_driver = { \ .driver = { \ .name = _name, \ .of_match_table = of_match_ptr(dt_ids), \ }, \ .probe = fbtft_driver_probe_spi, \ .remove = fbtft_driver_remove_spi, \ }; \ \ static struct platform_driver fbtft_driver_platform_driver = { \ .driver = { \ .name = _name, \ .owner = THIS_MODULE, \ .of_match_table = of_match_ptr(dt_ids), \ }, \ .probe = fbtft_driver_probe_pdev, \ .remove = fbtft_driver_remove_pdev, \ }; \ \ static int __init fbtft_driver_module_init(void) \ { \ int ret; \ \ ret = spi_register_driver(&fbtft_driver_spi_driver); \ if (ret < 0) \ return ret; \ return platform_driver_register(&fbtft_driver_platform_driver); \ } \ \ static void __exit fbtft_driver_module_exit(void) \ { \ spi_unregister_driver(&fbtft_driver_spi_driver); \ platform_driver_unregister(&fbtft_driver_platform_driver); \ } \ \ module_init(fbtft_driver_module_init); \ module_exit(fbtft_driver_module_exit); ~~~ 所以加载时候,会先运行 ~~~ static int __init fbtft_driver_module_init(void) { int ret; ret = spi_register_driver(&fbtft_driver_spi_driver); if (ret < 0) return ret; return platform_driver_register(&fbtft_driver_platform_driver); } ~~~