当前位置:网站首页>i2c client驅動
i2c client驅動
2022-07-21 16:19:00 【juno】
I2C設備驅動框架
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/of.h>
#include <linux/of_device.h>
struct foobar_i2c_device_data {
struct i2c_client *client;
struct i2c_adapter *adap;
};
static int foobar_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct i2c_adapter *adap = client->adapter;
struct foobar_i2c_device_data *device;
dev_info(&client->dev, "probe\n");
device = devm_kzalloc(&client->dev, sizeof(*device), GFP_KERNEL);
if (!device)
return -ENOMEM;
device->client = client;
device->adap = adap;
dev_info(&client->dev, "addr:%x\n", client->addr);
i2c_set_clientdata(client, device);
return 0;
}
static int foobar_i2c_remove(struct i2c_client *client)
{
struct foobar_i2c_device_data *device = i2c_get_clientdata(client);
return 0;
}
static const struct of_device_id foobar_of_match[] = {
{
.compatible ="dummy,foobar-device"
},
{
/* */
}
};
MODULE_DEVICE_TABLE(of, foobar_of_match);
const struct i2c_device_id foobar_id[] = {
{
.name = "foobar",
},
{
/* */
}
};
static struct i2c_driver foobar_driver = {
.driver = {
.name = "foobar",
.of_match_table = of_match_ptr(foobar_of_match),
},
.probe = foobar_i2c_probe,
.remove = foobar_i2c_remove,
.id_table = foobar_id,
};
module_i2c_driver(foobar_driver);
MODULE_LICENSE("GPL");
I2C設備驅動框架本身比較簡單,重要的是相對的子系統驅動
I2C設備的設備樹有點特別的地方,在probe的參數裏的client裏的addr在設備樹裏設置reg屬性,
設置了REG屬性之後,在ADAPTER驅動PROBE的時候會自動填充client,如下圖:
i2c3:[email protected] {
compatible = "s5pv210,i2c-adapter";
#address-cells = <1>;
#size-cells = <1>;
mode = "i2c";
reg = <0xe1800000 0x10>;
[email protected]0x46 {
compatible = "dummy,foobar-device";
reg = <0x46>;
};
};
边栏推荐
- Visual studio easy to use plug-in sharing
- Dam Chapter 13 (data quality management)
- Because mongodb didn't get started, I lost an internship
- Training of head and neck segmentation networks with shape prior on small datasets
- Change dimension style text fill color
- Dynamic characteristics and interaction in virtual environment
- Use priority queue_ Queue implements unordered to base_ Value filtering of map on value value value
- How to modify the default path of CONDA virtual environment
- Lighting plus
- Le moteur 3D de dtos titos remplacera le moteur de jeu Giant Beast et réalisera la substitution de localisation
猜你喜欢
这款国产API神器工具也太强了吧...让我放弃了postman
Lighting plus
Easygbs platform setup tips: how to hide the platform web page from being accessed?
Wechat vaccine appointment applet graduation project of applet completion work (7) mid term inspection report
What preliminary work does the enterprise need to do to establish its own applet and app?
At present, pytest, the hottest testing framework, is a magical explanation
Okaleido tiger NFT is about to log in to binance NFT platform, and the future market continues to be optimistic
Database constraint & MySQL advanced query
Wechat vaccine appointment applet graduation design of applet completion works (1) development outline
Why does someone choose the one with high quotation in software development? Did they lose money?
随机推荐
Dynamic characteristics and interaction in virtual environment
I2C client driver
i2c adapter驅動
How can traditional retail enterprises promote consumption cycle and share purchase mode to enable the development of physical enterprises?
Shape and boundary-aware multi-branch model for semi-supervised medical image segmentation
Devaxpress treelist enables the selection of parent node column values and all its child nodes
Realize joint testing through TPT fusion platform
Vtk9.0.1+qt5.13 manually create four windows (mpr+3d)
[dip/ implementation of simple digital image processing system] high score course design paper sharing
Upload a folder (including subfolders and files) in VSS
Which is the best multilingual mall system? Comparison of three famous cross-border e-commerce manufacturers
At present, pytest, the hottest testing framework, is a magical explanation
Origin 2022 download nanny level installation tutorial
Characteristics of let keyword
2022山东视力防控大会,中国护眼产品展,济南近视矫正设备展
vtk9.0.1+Qt5.13手动创建四窗口(MPR+3D)
c || 文件操作
Mohist patrol source code
Project summary: document management system
[mqtt from introduction to improvement series | 08] mqtt3.1.1 topic details