嵌入式爱好者

查看: 13583|回复: 1

[Linux] 如何修改一个被占用的管脚,将其修改为普通gpio

[复制链接]

20

主题

34

帖子

101

积分

扫一扫,手机访问本帖
发表于 2021-3-31 19:52:34 | 显示全部楼层 |阅读模式
评估板的F11_VOUT1_D0信号被用作了屏线的vd0_b0, 我们新设计的板子把这个管脚用作普通的GPIO去控制一个芯片,设备树里面没有找到F11_VOUT1_D0管脚的信息,GPIO8 0,地址0x4A0035dc等信息,


我在设备树里添加了新的节点,代码如下。
写了一个新的驱动,通过insmod安装,demoApp设置这个GPIO的高低变化,可以安装,应用的时候会报错,错误内容见后面的表格;
如果管脚设置为led7 ,CTRL_CORE_PAD_MCASP2_AXR2,GPIO6_8,同样的方法、流程就没有问题,可以控制led7的闪烁。


请问我还有做什么吗?

  


  1. mygpio56 {
  2.                 pinctrl-names = "default";
  3.                 pinctrl-0 = <&mygpio56_user_gpio>;
  4.                 status = "okay";
  5.                   compatible = "gpio567";
  6.                   mygpio568 {
  7.                                label = "mygpio569";  
  8.                                gpios = <&gpio8 0 GPIO_ACTIVE_LOW>;
  9.                     
  10.                             };

  11.                };

  12. mygpio56_user_gpio: mygpio56_user_gpio {
  13.                 pinctrl-single,pins = <                
  14.                          DRA7XX_CORE_IOPAD(0x35dc, MUX_MODE14 | PIN_OUTPUT_PULLUP) /* gpio8-0 spi */
  15.                 >;
  16.         };
复制代码
报错内容:

  1. [15705.814706] ------------[ cut here ]------------
  2. [15705.819357] WARNING: CPU: 0 PID: 1330 at drivers/bus/omap_l3_noc.c:147 l3_interrupt_handler+0x25c/0x36c
  3. [15705.828790] 44000000.ocp:L3 Custom Error: MASTER MPU TARGET L4_PER1_P3 (Read): Data Access in User mode during Functional access
  4. [15705.840402] Modules linked in: mygpio567(O) sha512_generic sha512_arm sha256_generic sha1_generic sha1_arm_neon sha1_arm md5 cbc xfrm_user xfrm4_tunnel ipcomp xfrm_ipcomp esp4 ah4 af_key xfrm_algo rfcomm bc_example(O) wlan btusb btrtl btbcm btintel xhci_plat_hcd pru_rproc pruss_intc xhci_hcd rpmsg_proto pruss bluetooth dwc3 udc_core rpmsg_rpc snd_soc_**_card snd_soc_**_card_utils pwm_fan snd_soc_omap_hdmi_audio pvrsrvkm(O) omap_aes_driver c_can_platform c_can omap_sham pruss_soc_bus can_dev omap_wdt ahci_platform libahci_platform libahci libata scsi_mod ti_vip ti_vpe ti_sc ti_csc ti_vpdma dwc3_omap extcon_core w1_therm ti_cal gpio_pisosr rtc_rx8010 ov5640_mipi omap_des ov5640 snd_soc_wm8960 omap_hdq wire spidev des_generic crypto_engine omap_remoteproc virtio_rpmsg_bus rpmsg_core remoteproc sch_fq_codel xr_usb_serial_common usbcore usb_common uio_module_drv(O) uio gdbserverproxy(O) cryptodev(O) cmemk(O) [last unloaded: gt911]
  5. [15705.924154] CPU: 0 PID: 1330 Comm: hello Tainted: G      D W  O    4.9.41 #29
  6. [15705.931319] Hardware name: Generic DRA72X (Flattened Device Tree)
  7. [15705.937436] Backtrace:
  8. [15705.939909] [<c020b2d8>] (dump_backtrace) from [<c020b594>] (show_stack+0x18/0x1c)
  9. [15705.947512]  r7:00000009 r6:60070193 r5:00000000 r4:c10229d0
  10. [15705.953199] [<c020b57c>] (show_stack) from [<c04ace60>] (dump_stack+0x8c/0xa0)
  11. [15705.960456] [<c04acdd4>] (dump_stack) from [<c022e4b8>] (__warn+0xec/0x104)
  12. [15705.967448]  r7:00000009 r6:c0bcd6e0 r5:00000000 r4:ee413b40
  13. [15705.973132] [<c022e3cc>] (__warn) from [<c022e510>] (warn_slowpath_fmt+0x40/0x48)
  14. [15705.980649]  r9:00000006 r8:ef1dd2d0 r7:c0bcd54c r6:00000002 r5:c0bcd60c r4:c0bcd6b0
  15. [15705.988428] [<c022e4d4>] (warn_slowpath_fmt) from [<c04dcd10>] (l3_interrupt_handler+0x25c/0x36c)
  16. [15705.997337]  r3:ef1dd140 r2:c0bcd6b0
  17. [15706.000926]  r4:80080003
  18. [15706.003473] [<c04dcab4>] (l3_interrupt_handler) from [<c027fd20>] (__handle_irq_event_percpu+0xb4/0x138)
  19. [15706.012995]  r10:c101a4af r9:ef1d1200 r8:00000017 r7:ee413c64 r6:00000000 r5:ef1d1200
  20. [15706.020855]  r4:ef1dd640
  21. [15706.023401] [<c027fc6c>] (__handle_irq_event_percpu) from [<c027fdc8>] (handle_irq_event_percpu+0x24/0x60)
  22. [15706.033096]  r10:bf545360 r9:ee412000 r8:ef006000 r7:00000000 r6:c1008c34 r5:ef1d1200
  23. [15706.040956]  r4:ef1d1200
  24. [15706.043500] [<c027fda4>] (handle_irq_event_percpu) from [<c027fe44>] (handle_irq_event+0x40/0x64)
  25. [15706.052409]  r5:ef1d1260 r4:ef1d1200
  26. [15706.056002] [<c027fe04>] (handle_irq_event) from [<c02834f0>] (handle_fasteoi_irq+0xc0/0x190)
  27. [15706.064563]  r7:00000000 r6:c1008c34 r5:ef1d1260 r4:ef1d1200
  28. [15706.070247] [<c0283430>] (handle_fasteoi_irq) from [<c027ef48>] (generic_handle_irq+0x2c/0x3c)
  29. [15706.078894]  r7:00000000 r6:00000000 r5:00000017 r4:c0e5cde0
  30. [15706.084579] [<c027ef1c>] (generic_handle_irq) from [<c027f4d0>] (__handle_domain_irq+0x64/0xbc)
  31. [15706.093316] [<c027f46c>] (__handle_domain_irq) from [<c02014a0>] (gic_handle_irq+0x40/0x7c)
  32. [15706.101703]  r9:ee412000 r8:fa213000 r7:fa212000 r6:ee413d20 r5:fa21200c r4:c1003424
  33. [15706.109479] [<c0201460>] (gic_handle_irq) from [<c020c138>] (__irq_svc+0x58/0x8c)
  34. [15706.116993] Exception stack(0xee413d20 to 0xee413d68)
  35. [15706.122066] 3d20: 00000000 fa053000 00000001 bf5459c0 bf545770 c103408c 00000038 c1034074
  36. [15706.130278] 3d40: ee1a9b40 ed31d360 bf545360 ee413d7c ee413c30 ee413d70 c02c0f18 bf545054
  37. [15706.138487] 3d60: 60070013 ffffffff
  38. [15706.141990]  r9:ee412000 r8:ee1a9b40 r7:ee413d54 r6:ffffffff r5:60070013 r4:bf545054
  39. [15706.149777] [<bf545020>] (mygpio_open [mygpio567]) from [<c05921bc>] (misc_open+0x15c/0x174)
  40. [15706.158256] [<c0592060>] (misc_open) from [<c0333fc0>] (chrdev_open+0xac/0x190)
  41. [15706.165596]  r10:ee1a9b40 r9:ee413ea8 r8:ef342300 r7:ee1a9b40 r6:ed31d360 r5:ef342300
  42. [15706.173458]  r4:c0a3ec80 r3:c0592060
  43. [15706.177051] [<c0333f14>] (chrdev_open) from [<c032d164>] (do_dentry_open.constprop.3+0x1ec/0x314)
  44. [15706.185961]  r8:ee413f5c r7:c0333f14 r6:ee1a9b48 r5:ed31d360 r4:ee1a9b40
  45. [15706.192691] [<c032cf78>] (do_dentry_open.constprop.3) from [<c032e0a4>] (vfs_open+0x48/0x78)
  46. [15706.201165]  r9:ee413ea8 r8:ee413f5c r7:eec023b8 r6:00000002 r5:ee1a9b40 r4:ee413ea8
  47. [15706.208944] [<c032e05c>] (vfs_open) from [<c033d1f4>] (path_openat+0x344/0xefc)
  48. [15706.216283]  r5:00000000 r4:00000000
  49. [15706.219875] [<c033ceb0>] (path_openat) from [<c033f134>] (do_filp_open+0x6c/0xd0)
  50. [15706.227391]  r10:00000000 r9:ee412000 r8:c0207d84 r7:00000001 r6:ee413f5c r5:ee413ea8
  51. [15706.235250]  r4:00000003
  52. [15706.237795] [<c033f0c8>] (do_filp_open) from [<c032e458>] (do_sys_open+0x11c/0x1cc)
  53. [15706.245483]  r7:fffff000 r6:ed384000 r5:ffffff9c r4:00000003
  54. [15706.251167] [<c032e33c>] (do_sys_open) from [<c032e528>] (SyS_open+0x20/0x24)
  55. [15706.258332]  r9:ee412000 r8:c0207d84 r7:00000005 r6:00000000 r5:00000000 r4:be9d3b38
  56. [15706.266110] [<c032e508>] (SyS_open) from [<c0207be0>] (ret_fast_syscall+0x0/0x34)
  57. [15706.273622] ---[ end trace 7e2b11ee0c31fa61 ]---
  58. [15706.278569] Unhandled fault: asynchronous external abort (0x1211) at 0x00000000
  59. [15706.285911] pgd = ee070680
  60. [15706.288627] [00000000] *pgd=9fa38003, *pmd=00000000
  61. [15706.305552] systemd[1]: systemd-journald.service: Failed with result 'core-dump'.
  62. [15706.331909] systemd[1]: systemd-journald.service: Service has no hold-off time, scheduling restart.
  63. [15706.353929] systemd[1]: Stopped Flush Journal to Persistent Storage.
  64. [15706.360436] systemd[1]: Stopping Flush Journal to Persistent Storage...
  65. [15706.381362] systemd[1]: Stopped Journal Service.
  66. [15706.393271] systemd[1]: Starting Journal Service...
  67. [15706.417041] systemd-journald[1334]: File /run/log/journal/b9d28430c5bb428b8c75daa70d99e56a/system.journal corrupted or uncleanly shut down, renaming and replacing.
复制代码
驱动源码:
  1. #include <linux/slab.h>

  2. #include <linux/device.h>

  3. #include <linux/miscdevice.h>

  4. #include <linux/device.h>

  5. #include <linux/uaccess.h>

  6. #include <linux/fb.h>

  7. #include <linux/init.h>

  8. #include <linux/module.h>

  9. #include <linux/kernel.h>

  10. #include <generated/autoconf.h>

  11. #include <linux/platform_device.h>

  12. #include <linux/fs.h>

  13. #include <linux/ioctl.h>

  14. #include <linux/types.h>

  15. #include <linux/spinlock.h>

  16. #include <linux/cdev.h>

  17. #include <linux/of.h>

  18. #include <asm/uaccess.h>

  19. #include <asm/io.h>

  20. #include <asm/atomic.h>



  21. //#include "mt-plat/mtgpio.h"

  22. #include <linux/types.h>

  23. //#include <mt-plat/mt_gpio.h>

  24. //#include <mt-plat/mt_gpio_core.h>

  25. //#include <mach/gpio_const.h>



  26. /* 生命函数定义 */

  27. static int mygpio_probe(struct platform_device *pdev);

  28. static int mygpio_remove(struct platform_device *pdev);





  29. static const struct of_device_id mygpio_of_match[] = {

  30.         { .compatible = "gpio567", },

  31.         {},

  32. };



  33. static struct platform_driver mygpio_driver = {

  34.         .remove = mygpio_remove,

  35.         .probe = mygpio_probe,

  36.         .driver = {

  37.                         .name = "myGPIO",

  38.                         .owner = THIS_MODULE,

  39.                         .of_match_table = mygpio_of_match,

  40.         },

  41. };





  42. #define GPIO_MUX_ADDR               0x4A0035dc

  43. #define GPIO6_BASE_ADDR             0x48053000

  44. #define GPIO_PIN_INDEX              0



  45. #define GPIO_OE_OFFSET              0x134

  46. #define GPIO_CLRDATAOUT_OFFSET      0x190

  47. #define GPIO_SETDATAOUT_OFFSET      0x194

  48. u32 reg_vir_addr;

  49. static void config_gpio_muxmode(void)

  50. {

  51.     u32 reg_vir;

  52.     printk("my_dev_muxmode\n");

  53.    reg_vir = (u32)ioremap_nocache(GPIO_MUX_ADDR, 0x20);

  54.    if (!reg_vir) {

  55.         printk(": ctrl register remapping failed");                       

  56.     }

  57.     //__raw_writel(0xE, reg_vir +0);

  58.     *(unsigned int *)(reg_vir)= 0x0e;//gpio



  59.     iounmap((void *)reg_vir);

  60. //



  61. }



  62. static int mygpio_open(struct inode *inode, struct file *file)

  63. {

  64.         printk("MyGPIO OPen. \r\n");

  65.         (*( unsigned int *)(reg_vir_addr + GPIO_CLRDATAOUT_OFFSET)) |= 1 << GPIO_PIN_INDEX;

  66.         (*( unsigned int *)(reg_vir_addr + GPIO_OE_OFFSET)) &= ~(1<<GPIO_PIN_INDEX);

  67.         (*( unsigned int *)(reg_vir_addr + GPIO_SETDATAOUT_OFFSET)) |= 1 << GPIO_PIN_INDEX;

  68.         return 0;

  69. }



  70. static ssize_t my_dev_write(struct file *file,const char __user *buf,size_t count,loff_t *offset)

  71. {

  72. #if 0

  73.         int ret;

  74.         ret = copy_from_user(&val,buf,count);

  75.         if(ret<0)

  76.         {

  77.                 printk("ret=%d\n",ret);

  78.                 return ret;

  79.         }

  80.         printk("my_dev_read\n");

  81.        

  82.         return 0;

  83. #endif

  84.         int ret,val;

  85.         char temp[16];

  86.         char status=0;

  87.         memset(temp,0,16);



  88.         ret=copy_from_user(temp,buf,count);

  89.         if(ret<0)

  90.         {

  91.                 printk("ret=%d\n",ret);

  92.                 status=-EFAULT;

  93.                 goto err;

  94.         }

  95.         val=**_strtoul(temp,NULL,0);

  96.         if(val >= 1)

  97.         {

  98.             *( unsigned int *)(reg_vir_addr + GPIO_SETDATAOUT_OFFSET) |= 1 << GPIO_PIN_INDEX;

  99.                 //gpio_set_value(gpio_led_pin,1);

  100.         }

  101.         else

  102.         {

  103.              *( unsigned int *)(reg_vir_addr + GPIO_CLRDATAOUT_OFFSET)|= 1 << GPIO_PIN_INDEX;

  104.                 //gpio_set_value(gpio_led_pin,0);       

  105.          }



  106.         if(!status)

  107.                 status = count;

  108. err:

  109.         return status;

  110. }



  111. static int mygpio_release(struct inode *inode, struct file *file)

  112. {

  113.         printk("MyGPIO Release. \r\n");

  114.        

  115.         return 0;

  116. }



  117. static long mygpio_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

  118. {

  119.         printk("MyGPIO Ioctl. \r\n");

  120.        

  121.         printk("MyGPIO cmd=%d \r\n", cmd);

  122.        

  123.         return 0;

  124. }



  125. static const struct file_operations mygpio_fops = {

  126. /* .owner = THIS_MODULE, */

  127.         .open = mygpio_open,

  128.         .write        =my_dev_write,

  129.         .release = mygpio_release,

  130.         .unlocked_ioctl = mygpio_unlocked_ioctl,

  131. };





  132. static struct miscdevice mygpio_device = {

  133.         .minor = MISC_DYNAMIC_MINOR,                //动态设备号

  134.         .name = "myGPIO",

  135.         .fops = &mygpio_fops,

  136. };







  137. /* My GPIO probe */

  138. static int mygpio_probe(struct platform_device *pdev)

  139. {//

  140.         int ret = 0;

  141.         unsigned int outvalue[32];

  142.        

  143.         printk("MyGPIO Probe. \r\n");

  144.        

  145.         ret = misc_register(&mygpio_device);

  146.         if (ret != 0 )

  147.                 printk("myGPIO: mygpio_device register failed\n");

  148.        

  149.          struct device_node *dn;

  150.          //1.通过节点名字查找指定的节点驱动程序里面调用of_get_address,提示没有?

  151.          dn = of_find_node_by_name(NULL,"mygpio56");

  152.          if(dn==NULL)

  153.          {

  154.               printk("of_find_node_by_name err \r\n");

  155.          }

  156.          else

  157.          {

  158.                   //of_find_node_by_name :mygpio56 /mygpio56 <NULL> mygpio568  compatible

  159.          //   printk("of_find_node_by_name :%s %s %s  %s %s %s\r\n",dn->name,dn->full_name,dn->type,dn->child->name,dn->properties->name, dn->properties->next->name);



  160.                 of_property_read_u32_array(dn->child,dn->child->properties->next->name,outvalue,3);

  161.                 //读取属性中 u8、 u16、 u32 和 u64 类型的数组数据,比如大多数的 reg 属性都是数组数据



  162.                  printk("%s {\n",dn->name);

  163.                  printk("      %s = " %s " ;\n",dn->properties->name,dn->properties->value);

  164.                  printk("      %s = " %s " ;\n",dn->properties->next->name,dn->properties->next->value);

  165.                  printk("         %s {\n",dn->child->name);

  166.                  printk("         %s = " %s " ;\n",dn->child->properties->name,dn->child->properties->value);         

  167.                  printk("         %s = < %x %x %x > ;\n",dn->child->properties->next->name,outvalue[0],outvalue[1],outvalue[2]);

  168.                  printk("};\n};\n");

  169.          }

  170.      ///    u64 size[1]; unsigned int flags[1];

  171.        //  unsigned int *addr;

  172.       //   addr = of_get_address(dn->child, 0, size, flags);

  173.          //of_translate_address(dn->child, const __be32 *in_addr);

  174.          //2. 通过 device_type 属性查找指定的节点,节点对应的 type 字符串,也就是 device_type 属性值。

  175.          //struct device_node *of_find_node_by_type(struct device_node *from, const char *type)

  176.         //3. 根据 device_type 和 compatible 这两个属性查找指定的节点  struct device_node *of_find_compatible_node(struct device_node *from,const char *type,const char *compatible)

  177.         //4 通过 of_device_id 匹配表来查找指定的节点  struct device_node *of_find_matching_node_and_match(struct device_node *from,const struct of_device_id *matches,const struct of_device_id **match)  matches: of_device_id 匹配表,也就是在此匹配表里面查找节点。  match: 找到的匹配的 of_device_id。

  178.         return ret;

  179. }





  180. static int mygpio_remove(struct platform_device *pdev)

  181. {

  182.         int err;

  183.        

  184.         printk("MyGPIO remove. \r\n");



  185.          misc_deregister(&mygpio_device);

  186.        

  187.         return err;

  188. }



  189. static int __init my_gpio_init(void)

  190. {

  191.         int ret = 0;

  192.         printk("my_gpio_init. \r\n");

  193.         printk("Register MyGPIO platform_driver  init. \r\n");



  194.         reg_vir_addr = (u32)ioremap_nocache(GPIO6_BASE_ADDR, 0x800);

  195.            if (!reg_vir_addr) {

  196.                 printk(": ctrl addr remapping failed");                       

  197.             }



  198.         config_gpio_muxmode();



  199.         ret = platform_driver_register(&mygpio_driver);

  200.         if(ret != 0 )

  201.                 printk("unable to register MyGPIO driver.\n");

  202.        

  203.         return ret;

  204. }



  205. /*---------------------------------------------------------------------------*/

  206. static void __exit my_gpio_exit(void)

  207. {

  208.         printk("my_gpio_exit. \r\n");

  209.         iounmap((void *)reg_vir_addr);



  210.           platform_driver_unregister(&mygpio_driver);

  211. }



  212. subsys_initcall(my_gpio_init);

  213. /*module_init(my_gpio_init);*/

  214. module_exit(my_gpio_exit);



  215. MODULE_AUTHOR("zue");

  216. MODULE_DESCRIPTION("MY General Purpose Driver (GPIO)");

  217. MODULE_LICENSE("GPL v2");

  218. /*

  219. insmod newled

  220. [  148.740316] my_gpio_init.

  221. [  148.748510] MyGPIO Probe.  compatible = "gpio567"; 匹配才执行

  222. //

  223. rmmod newled

  224. [  208.688966] my_gpio_exit.

  225. [  208.691893] MyGPIO remove.



  226. app open-->open

  227.     write-->write

  228.     close--->release





  229. */
复制代码


回复

使用道具 举报

20

主题

34

帖子

101

积分

 楼主| 发表于 2021-4-1 09:50:27 | 显示全部楼层
&gpio8 {
        ti,no-reset-on-init;
};
这种操作不起作用呢,如果起作用,GPIO8对应的是屏显示,屏应该不显示内容才对
点评回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-3-28 18:00

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表