2011-6-18 0:49:26

I2C总线
SDA SCL

 SDA 线上的数据必须在时钟的高电平周期保持稳定。数据线的高或低电平状态只  I2C位传输数据有效性
有在SCL 线的时钟信号是低电平时才能改变


struct i2c_driver {
 int id;
 unsigned int class;

 /* Notifies the driver that a new bus has appeared. This routine
  * can be used by the driver to test if the bus meets its conditions
  * & seek for the presence of the chip(s) it supports. If found, it
  * registers the client(s) that are on the bus to the i2c admin. via
  * i2c_attach_client.
  */
 int (*attach_adapter)(struct i2c_adapter *);
 int (*detach_adapter)(struct i2c_adapter *);

 /* tells the driver that a client is about to be deleted & gives it
  * the chance to remove its private data. Also, if the client struct
  * has been dynamically allocated by the driver in the function above,
  * it must be freed here.
  */
 int (*detach_client)(struct i2c_client *);

 /* driver model interfaces that don't relate to enumeration  */
 void (*shutdown)(struct i2c_client *);
 int (*suspend)(struct i2c_client *, pm_message_t mesg);
 int (*resume)(struct i2c_client *);

 /* a ioctl like command that can be used to perform specific functions
  * with the device.
  */
 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);

 struct device_driver driver;
 struct list_head list;
};


i2c_driver 和 device_driver 之间的关系

struct i2c_client {
 unsigned int flags;  /* div., see below  */
 unsigned short addr;  /* chip address - NOTE: 7bit */
     /* addresses are stored in the */
     /* _LOWER_ 7 bits  */
 struct i2c_adapter *adapter; /* the adapter we sit on */
 struct i2c_driver *driver; /* and our access routines */
 int usage_count;  /* How many accesses currently  */
     /* to the client  */
 struct device dev;  /* the device structure  */
 struct list_head list;
 char name[I2C_NAME_SIZE];
 struct completion released;
};

i2c_client 和device之间的关系


static void i2c_device_shutdown(struct device *dev)
{
 struct i2c_driver *driver;

 if (!dev->driver)
  return;
 driver = to_i2c_driver(dev->driver);
 if (driver->shutdown)
  driver->shutdown(to_i2c_client(dev));
}

有关闭就调用关闭方法

struct bus_type {
 const char  * name;

 struct subsystem subsys;
 struct kset  drivers;
 struct kset  devices;
 struct klist  klist_devices;
 struct klist  klist_drivers;

 struct blocking_notifier_head bus_notifier;

 struct bus_attribute * bus_attrs;
 struct device_attribute * dev_attrs;
 struct driver_attribute * drv_attrs;

 int  (*match)(struct device * dev, struct device_driver * drv);
 int  (*uevent)(struct device *dev, char **envp,
      int num_envp, char *buffer, int buffer_size);
 int  (*probe)(struct device * dev);
 int  (*remove)(struct device * dev);
 void  (*shutdown)(struct device * dev);

 int (*suspend)(struct device * dev, pm_message_t state);
 int (*suspend_late)(struct device * dev, pm_message_t state);
 int (*resume_early)(struct device * dev);
 int (*resume)(struct device * dev);
};


总线类型


struct bus_type i2c_bus_type = {
 .name  = "i2c",
 .match  = i2c_device_match,
 .probe  = i2c_device_probe,
 .remove  = i2c_device_remove,
 .shutdown = i2c_device_shutdown,
 .suspend = i2c_device_suspend,
 .resume  = i2c_device_resume,
};

要就没有,要就调用驱动的

struct i2c_adapter {
 struct module *owner;
 unsigned int id;
 unsigned int class;
 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
 void *algo_data;

 /* --- administration stuff. */
 int (*client_register)(struct i2c_client *);
 int (*client_unregister)(struct i2c_client *);

 /* data fields that are valid for all devices */
 u8 level;    /* nesting level for lockdep */
#if defined(CONFIG_I2C_POLLING)
 spinlock_t bus_lock;
#else
 struct mutex bus_lock;
#endif
 struct mutex clist_lock;

 int timeout;
 int retries;
 struct device dev;  /* the adapter device */
 struct class_device class_dev; /* the class device */

 int nr;
 struct list_head clients;
 struct list_head list;
 char name[I2C_NAME_SIZE];
 struct completion dev_released;
 struct completion class_dev_released;
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值