#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/tlc59116.h>
#define DRIVER_NAME "tlc59116"
int tlc59116_write(struct i2c_client *client, u8 addr, u8 data)
{
u8 buffer[2];
int ret;
dev_dbg(&client->dev, "writing %u to i2c address %u\n",
(unsigned int) data, (unsigned int) addr);
buffer[0] = addr;
buffer[1] = data;
ret = i2c_master_send(client, buffer, 2);
if (ret != 2) {
dev_err(&client->dev, "failed to write\n");
if (ret < 0)
return ret;
else return -EIO;
}
return 0;
}
EXPORT_SYMBOL(tlc59116_write);
/**
* @n Description : Perform a single read (1B) from register
* @n Pre-condition : None
* @n Constraints : None
* @param [in] : Handle to slave device
* @param [in] : addr address of register to read
* @param [in] : data data read from device
* @return : error codes: 0 if ok
*
* @warning: "data" param is affected only if reading is ok
*
* @author M.Mondo
*/
int tlc59116_read(struct i2c_client *client, u8 addr, u8 *data)
{
u8 buffer_add;
u8 buffer_read;
int ret;
int loc_ret;
buffer_add = addr;
buffer_read = 0x0U;
ret = 0U; /* No errors */
loc_ret = 0U;
/* Register set */
loc_ret = i2c_master_send(client, &buffer_add, 1U);
if (1U == loc_ret) /* "i2c_master_send" reports numbers of byte send, if ok, otherwise negative value */
{
loc_ret = i2c_master_recv(client, &buffer_read, 1U); /* 1 -> num bytes to read */
if (1U == loc_ret)
{
*data = buffer_read; /* update data read */
}
else
{
ret = 0x01;
}
}
else
{
ret = 0x02;
}
return ret;
}
EXPORT_SYMBOL(tlc59116_read);
static void tlc59116_ResetLedDriver(void)
{
//RESET_OUT_OFF();
//arch_sleep(1);
//RESET_OUT_ON();
//arch_sleep(1);
}
static int tlc59116_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct tlc59116_data *data;
int err;
data = kzalloc(sizeof(struct tlc59116_data), GFP_KERNEL);
if (!data) {
err = -ENOMEM;
goto exit;
}
i2c_set_clientdata(client, data);
dev_info(&client->dev, "%s (LED DRIVER) chip found...\n", client->name);
#if 0
data->attrs.attrs = cy8c9520a_attr;
err = sysfs_create_group(&client->dev.kobj, &data->attrs);
if (err)
goto exit_free;
#endif
return 0;
#if 0
exit_free:
kfree(data);
#endif
exit:
return err;
}
static int tlc59116_remove(struct i2c_client *client)
{
struct cy8c9520a_data *data = i2c_get_clientdata(client);
#if 0
sysfs_remove_group(&client->dev.kobj, &data->attrs);
#endif
kfree(data);
return 0;
}
static const struct i2c_device_id tlc59116_i2c_id[] = {
{ "tlc59116", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, tlc59116_i2c_id);
static struct i2c_driver tlc59116_i2c_driver = {
.driver = {
.name = "tlc59116",
.owner = THIS_MODULE,
},
.probe = tlc59116_probe,
.remove = tlc59116_remove,
.id_table = tlc59116_i2c_id,
};
static int __init tlc59116_i2c_init(void)
{
printk("MTA: LED_DRIVER init...\n");
return i2c_add_driver(&tlc59116_i2c_driver);
}
subsys_initcall(tlc59116_i2c_init);
static void __exit tlc59116_i2c_exit(void)
{
i2c_del_driver(&tlc59116_i2c_driver);
}
module_exit(tlc59116_i2c_exit);
tlc59116_linux.zip_Texas_linux led driver_tlc59116
版权申诉
195 浏览量
2022-09-23
00:19:04
上传
评论
收藏 3KB ZIP 举报
刘良运
- 粉丝: 66
- 资源: 1万+
最新资源
- 历届(第1-21届)希望杯数学竞赛初一试题及答案(最新整理).doc全国数学邀请赛(264页资料)
- 水滴.psd
- TokenPocket_V2.1.2_release.apk
- Apache-druid-kafka-rce.yaml
- 基于C#的ASP.NET数据库原理及应用技术课程指导平台的开发
- 基于ROS的智能车轨迹跟踪算法的仿真与设计源码运用PID跟踪算法.zip.zip
- Bug Bounty Tip - i春秋Self-XSS变废为宝的奇思妙想
- 1991-2015年全国初中化学竞赛复赛试题汇编(212页)(24年竞赛复赛真题).docx天原杯
- Apache Flink 未授权访问+远程代码执行.pdf
- hadoop-基于hive的聊天数据分析报表可视化案例数据源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈