当前位置:网站首页>i2c adapter驅動
i2c adapter驅動
2022-07-21 16:10:00 【juno】
I2C adapter驅動框架
struct xxx_i2c {
void __iomem *base; /* 用於map外設寄存器 */
struct device *dev; /* 無特殊途 */
struct i2c_adapter adap; /* adapter 數據結構 */
struct clk *clk;
u32 quick; /* 設備支持的能力 */
};
static u32 xxx_i2c_functionality(struct i2c_adapter *adap)
{
struct s5pv210_i2c *i2c = container_of(adap, struct s5pv210_i2c, adap);
return i2c->quick;
}
static int xxx_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write,
u8 cmd, int size, union i2c_smbus_data *data)
{
return 0;
}
static const struct i2c_algorithm xxx_i2c_algo = {
.smbus_xfer = xxx_smbus_xfer, /* I2C 控制器收發數據 */
.functionality = xxx_i2c_functionality, /* 獲取設備支持的功能*/
};
static int xxx_i2c_register(struct xxx_i2c *i2c)
{
struct i2c_adapter *adap = &i2c->adap;
adap->algo = &xxx_i2c_algo;
adap->algo.dev.of_node = i2c->dev->of_node;
adap->alog.dev.parent = i2c->dev;
adap->owner = THIS_MODULE;
adap->quick = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C;
return i2c_add_adapter(adap); /* 添加適配器到內核*/
}
static int xxx_i2c_probe(struct platform_device *pdev)
{
struct xxx_i2c *i2c;
int ret;
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); /* 分配設備私有數據 */
if (!i2c)
return -ENOMEM;
i2c->dev = &pdev->dev;
i2c->base = devm_platform_ioremap_resource(pdev, 0); /* map 寄存器內存 */
if (IS_ERR(i2c->base)) {
return PTR_ERR(i2c->base);
}
ret = xxx_i2c_register(i2c);
if (ret)
return ret;
platform_set_drvdata(pdev, i2c);
return 0;
}
static int xxx_i2c_remove(struct platform_device *pdev)
{
struct xxx_i2c *i2c = platform_get_drvdata(pdev);
i2c_del_adapter(&i2c->adap);
return 0;
}
const struct of_device_id xxx_ids[] = {
{
.compatible = "xxx,i2c-adapter"},
};
struct platform_driver xxx_i2c_adap_drv = {
.probe = xxx_i2c_probe,
.remove = xxx_i2c_remove,
.driver = {
.name = "xxx-i2c-adaper",
.of_match_table = xxx_ids,
},
};
module_platform_driver(xxx_i2c_adap_drv);
在I2C adapter驅動中algo中的functionality回調函數返回設備支持的功能,這些功能的定義在uapi/linux/i2c.h中。
smbus_xfer這個函數用於向I2C設備發送數據。
边栏推荐
- i2c adapter驱动
- Draw circles and rectangles with VTK controls
- 设置 当前样式dimstyle
- 【JS】事件传播
- 2022护眼灯展,中医眼科调理展,山东眼睛保健展,中国眼博会
- DTOS帝拓思的3D引擎将取代游戏引擎巨兽,实现国产化替代
- ROS from entry to mastery (x) TF coordinate transformation principle, why do you need TF transformation?
- In the financial scenario, how to accurately select and quickly implement distributed databases?
- 2.4 circular statements
- Blueprism tool menu bar user rights function description -rpa Chapter 2
猜你喜欢
Three structures of C language
Question quotidienne - leetcode1260 - migration de grille 2D - Tableau - Cartographie
c || 数组与指针
Wechat vaccine appointment applet graduation design of applet completion work (2) applet function
Wechat vaccine appointment applet graduation design of applet completion works (1) development outline
DTOS帝拓思的3D引擎将取代游戏引擎巨兽,实现国产化替代
[mqtt from introduction to improvement series | 08] mqtt3.1.1 topic details
修改标注样式文字填充颜色
Wechat vaccine appointment applet graduation project of applet completion work (4) opening report
Daily question-leetcode1260-2d grid migration array mapping
随机推荐
[stc15 controls ws2812 RGB color lamp cascade]
Source code, complement and fixed-point number operation
Esp8266 nodemcu -- use u8g2 library to light OLED
How to modify the default path of CONDA virtual environment
Signal integrity (SI) power integrity (PI) learning notes (XXIX) power distribution network (I)
每日一題-LeetCode1260-二維網格遷移-數組-映射
-实体建模-
DTOs' 3D engine will replace the game engine monster and realize localization
i2c client驱动
I2C client driver
Why is sha256 irreversible and how secure is sha256
Realize joint testing through TPT fusion platform
Wechat applet - "data binding and event binding"
Wechat vaccine appointment applet graduation design of applet completion work (2) applet function
C | file operation
Wechat vaccine appointment applet graduation design of applet completion work (8) graduation design thesis template
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of the asset!
Wechat vaccine appointment applet graduation project of applet completion work (6) opening defense ppt
[JS] tab switching
Self increment of version number