一:注册platform device

注册一个platfrom device一般需要初始化两个内容,设备占用的资源resource和设备私有数据dev.platfrom_data。设备的resource占用的资源主要包含两个方面:IO内存和IRQ资源信息,有时也包含DMA。

resource结构:

   1:  struct resource {
   2:      resource_size_t start;//定义资源的起始地址 
   3:      resource_size_t end;//定义资源的结束地址
   4:      const char *name;//定义资源的名称 
   5:      unsigned long flags;//定义资源的类型,比如MEM,IO,IRQ,DMA类型
   6:      struct resource *parent, *sibling, *child;//资源链表指针 
   7:  };

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

笔者当前的君正board有三个串口:

   1:  #ifdef CONFIG_SERIAL_JZ47XX_UART0
   2:  /* UART ( uart controller) */
   3:  static struct resource jz_uart0_resources[] = {
   4:      [0] = {
   5:          .start          = UART0_IOBASE,
   6:          .end            = UART0_IOBASE + 0x1000 - 1,
   7:          .flags          = IORESOURCE_MEM,
   8:      },
   9:      [1] = {
  10:          .start          = IRQ_UART0,
  11:          .end            = IRQ_UART0,
  12:          .flags          = IORESOURCE_IRQ,
  13:      },
  14:  #ifdef CONFIG_SERIAL_JZ47XX_UART0_DMA
  15:      [2] = {
  16:          .start          = JZDMA_REQ_UART0,
  17:          .flags          = IORESOURCE_DMA,
  18:      },
  19:  #endif
  20:  };
  21:   
  22:  struct platform_device jz_uart0_device = {
  23:      .name = "jz-uart",
  24:      .id = 0,
  25:      .num_resources  = ARRAY_SIZE(jz_uart0_resources),
  26:      .resource       = jz_uart0_resources,
  27:  };
  28:  #endif
  29:  #ifdef CONFIG_SERIAL_JZ47XX_UART1
  30:  static struct resource jz_uart1_resources[] = {
  31:      [0] = {
  32:          .start          = UART1_IOBASE,
  33:          .end            = UART1_IOBASE + 0x1000 - 1,
  34:          .flags          = IORESOURCE_MEM,
  35:      },
  36:      [1] = {
  37:          .start          = IRQ_UART1,
  38:          .end            = IRQ_UART1,
  39:          .flags          = IORESOURCE_IRQ,
  40:      },
  41:  #ifdef CONFIG_SERIAL_JZ47XX_UART1_DMA
  42:      [2] = {
  43:          .start          = JZDMA_REQ_UART1,
  44:          .flags          = IORESOURCE_DMA,
  45:      },
  46:  #endif
  47:  };
  48:  struct platform_device jz_uart1_device = {
  49:      .name = "jz-uart",
  50:      .id = 1,
  51:      .num_resources  = ARRAY_SIZE(jz_uart1_resources),
  52:      .resource       = jz_uart1_resources,
  53:  };
  54:  #endif
  55:  #ifdef CONFIG_SERIAL_JZ47XX_UART2
  56:  static struct resource jz_uart2_resources[] = {
  57:      [0] = {
  58:          .start          = UART2_IOBASE,
  59:          .end            = UART2_IOBASE + 0x1000 - 1,
  60:          .flags          = IORESOURCE_MEM,
  61:      },
  62:      [1] = {
  63:          .start          = IRQ_UART2,
  64:          .end            = IRQ_UART2,
  65:          .flags          = IORESOURCE_IRQ,
  66:      },
  67:  #ifdef CONFIG_SERIAL_JZ47XX_UART2_DMA
  68:      [2] = {
  69:          .start          = JZDMA_REQ_UART2,
  70:          .flags          = IORESOURCE_DMA,
  71:      },
  72:  #endif
  73:  };
  74:   
  75:  struct platform_device jz_uart2_device = {
  76:      .name = "jz-uart",
  77:      .id = 2,
  78:      .num_resources  = ARRAY_SIZE(jz_uart2_resources),
  79:      .resource       = jz_uart2_resources,
  80:  };
  81:  #endif

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

platform_device_register(&jz_uartXX_device);

注册成功后:(多个device)

ls /sys/bus/platform/devices/
jz-uart.0/  jz-uart.2/

二:注册platfrom driver

   1:  /* serial platfrom driver */
   2:  static struct platform_driver serial_jz47xx_driver = {
   3:      .probe          = serial_jz47xx_probe,
   4:      .remove         = serial_jz47xx_remove,
   5:   
   6:      .driver        = {
   7:          .name    = "jz-uart",
   8:          .owner    = THIS_MODULE,
   9:  #ifdef CONFIG_PM
  10:          .pm    = &serial_jz47xx_pm_ops,
  11:  #endif
  12:      },
  13:  };
  14:   
  15:  int __init serial_jz47xx_init(void)
  16:  {
  17:      int ret;
  18:      /* 功能:uart_register_driver用于将串口驱动uart_driver注册到内核(串口核心层)中,
  19:                  通常在模块初始化函数调用该函数。
  20:        * 参数 drv:要注册的uart_driver
  21:        * 返回值:  成功,返回0;否则返回错误码
  22:       */
  23:      ret = uart_register_driver(&serial_jz47xx_reg);
  24:      if (ret != 0)
  25:          return ret;
  26:   
  27:      /* 注册serial platfrom驱动 */
  28:      ret = platform_driver_register(&serial_jz47xx_driver); 
  29:      if (ret != 0)
  30:          uart_unregister_driver(&serial_jz47xx_reg);
  31:   
  32:      return ret;
  33:  }
  34:   
  35:  void __exit serial_jz47xx_exit(void)
  36:  {
  37:      platform_driver_unregister(&serial_jz47xx_driver);
  38:      uart_unregister_driver(&serial_jz47xx_reg);
  39:  }
  40:   
  41:   
  42:  #ifdef CONFIG_EARLY_INIT_RUN
  43:  rootfs_initcall(serial_jz47xx_init);/*先于module注册*/
  44:   
  45:  #else
  46:  module_init(serial_jz47xx_init);
  47:   
  48:  #endif
  49:   
  50:  module_exit(serial_jz47xx_exit);
  51:   
  52:  MODULE_LICENSE("GPL");
  53:  MODULE_ALIAS("platform:jz47xx-uart");

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

注册成功后:(一个driver对应多个device)

ls /sys/bus/platform/drivers/jz-uart/
bind       jz-uart.0  jz-uart.2  uevent     unbind

最新文章

  1. 关于DDD的学习资料汇总
  2. Groupby - collection processing
  3. td 的colspan属性
  4. HttpClient_使用httpclient必须知道的参数设置及代码写法、存在的风险
  5. HTML5 -1- 简介
  6. iOS常用define宏定义
  7. HBase从hdfs导入数据
  8. commons-lang阅读(一)
  9. KMP算法总结
  10. python运维开发(六)----模块续
  11. 浅谈敏捷组织中PMO的角色
  12. Spring学习笔记IOC与AOP实例
  13. Hibernate第四篇【集合映射、一对多和多对一】
  14. php 将pdf转成图片且将图片拼接
  15. 为WebClient增加Cookie的支持
  16. (转载)Eclipse将引用了第三方jar包的Java项目打包成可执行jar的两种方法
  17. Android的AIDL机制
  18. C 语言 IO 缓存 相关
  19. zookeeper启动报 Unexpected exception, exiting abnormally 错误
  20. BOM、DOM

热门文章

  1. 记录: 一次解决整型溢出攻击(使用scala,隐式转换)
  2. dhcp 学习整理
  3. LeetCode OJ-- Jump Game II **
  4. git tag 的使用
  5. Codeforces 629 B. Far Relative’s Problem
  6. QUICK START GIT
  7. facebook chat 【转】
  8. POJ 3321 Apple Tree 树状数组+DFS
  9. ASP.NET 5已终结,迎来ASP.NET Core 1.0和.NET Core 1.0 转
  10. 立体3D方式 【转】