编写一个驱动程序,开机时,没有看到probe打印,请大侠帮我看看,

carl.xu 2020-09-16 11:52:58
你们好:
编写一个驱动程序,开机时,没有看到probe打印,请大侠帮我看看,指导一下,感谢
/*
* ktd2150 driver
*
* Copyright (C) 2013 Texas Instruments
*
* Author: Milo(Woogyom) Kim <milo.kim@ti.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_data/leds-lp55xx.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/fb.h>
#include <linux/notifier.h>


struct ktd2150_platform_data{
struct notifier_block ktd_fb_notifier;
struct i2c_client *client;
};

static int ktd2150_i2c_write(struct i2c_client *client, int addr, int value)
{
char buf[2] = {addr,value};
struct i2c_msg msg = {
.addr = client->addr,
//.flags = I2C_M_IGNORE_NAK,
.flags = 0,
.len = 2,
.buf = buf
};
int error;
error = i2c_transfer(client->adapter,&msg,1);
return error < 0 ? error : 0;
}


int gpio_ktd2150_suspend(struct i2c_client *client)
{
int ret = 0;
//struct i2c_client *client = to_i2c_client(dev);
printk("============= tom test get in ktd2150 suspend =======================\n");
ret = ktd2150_i2c_write(client,0x03,0x43);
if(ret){
printk("============= write clent register 0x03 failed! =======================\n");
return ret;
}
return 0;
}

EXPORT_SYMBOL(gpio_ktd2150_suspend);

int gpio_ktd2150_resume(struct i2c_client *client)
{
int ret = 0;
//struct i2c_client *client = to_i2c_client(dev);
printk("============= tom test get in ktd2150 resume =======================\n");
ret = ktd2150_i2c_write(client,0x03,0x5b);
if(ret){
printk("============= write clent register 0x03 failed! =======================\n");
return ret;
}
return 0;
}

EXPORT_SYMBOL(gpio_ktd2150_resume);

/*
static int fb_notifier_callback(struct notifier_block *nb,
unsigned long action, void *data)
{
volatile int blank;
struct fb_event *evdata = data;
const struct ktd2150_platform_data *pdata =
container_of(nb, struct ktd2150_platform_data, ktd_fb_notifier);
printk("==================== tom test FB notifier callback ========================\n");

if (evdata && evdata->data) {
if (action == FB_EVENT_BLANK) {
blank = *(int *)evdata->data;
if (blank == FB_BLANK_UNBLANK) {
gpio_ktd2150_resume(pdata->client);
return NOTIFY_OK;
}
} else if (action == FB_EARLY_EVENT_BLANK) {
blank = *(int *)evdata->data;
if (blank == FB_BLANK_POWERDOWN) {
gpio_ktd2150_suspend(pdata->client);
return NOTIFY_OK;
}
}
}

return NOTIFY_DONE;
}

static int ktd2150_init_pm_fb_notifier(struct ktd2150_platform_data *pdata)
{
printk(" ==== tom test Init FB notifier ================= \n");

pdata->ktd_fb_notifier.notifier_call = fb_notifier_callback;

return fb_register_client(&pdata->ktd_fb_notifier);
}
*/
static int ktd2150_init_device(struct i2c_client *client)
{
int ret = 0;
// int i = 0;
// gpio_direction_output(pdata->enp_gpio,1);
// gpio_direction_output(pdata->enn_gpio,1);
// msleep(100);
/* ret = ktd2150_i2c_write(client,0x02,0x0f);
if(ret){
printk("============= write clent register 0x02 failed! =======================\n");
return ret;
}
ret = ktd2150_i2c_write(client,0x02,0x08);
if(ret){
printk("============= write clent register 0x02 failed! =======================\n");
return ret;
}*/
ret = ktd2150_i2c_write(client,0x00,0xb8);
if(ret){
printk("============= client_addr: %d write clent register 0x00 failed! =======================\n",client->addr);
return ret;
}
ret = ktd2150_i2c_write(client,0x01,0xb8);
if(ret){
printk("============= write clent register 0x01 failed! =======================\n");
return ret;
}

// for(i=0; i<1000; i++){
ret = ktd2150_i2c_write(client,0x03,0x5b);
// msleep(1);
// }
if(ret){
printk("============= write clent register 0x03 failed! =======================\n");
return ret;
}
return ret;

}

static int ktd2150_parse_dt(struct device *dev)
{
struct device_node *np;
int ret = 0;
int gpio;
if(!dev)
return -ENODEV;
np = dev->of_node;
gpio = of_get_named_gpio(np, "dp-gpio", 0);
if(gpio_is_valid(gpio)){
ret = gpio_request(gpio,"dp-gpio");
if(ret){
printk("====================%s,%d request gpio %d failed!===================\n",__func__,__LINE__,gpio);
goto out;
}
gpio_direction_output(gpio,1);
}
/* pdata->enn_gpio = of_get_named_gpio(np, "enn-gpio", 0);
if(gpio_is_valid(pdata->enn_gpio)){
ret = gpio_request(pdata->enn_gpio,"enn-gpio");
if(ret){
printk("====================%s,%d request gpio %d failed!===================\n",__func__,__LINE__,pdata->enn_gpio);
return ret;
}
}
*/
out:
return 0;
}

static int ktd2150_probe(struct i2c_client *client, const struct i2c_device_id *id )
{
int ret = 0;
struct ktd2150_platform_data *pdata;
printk("=============== %s in ,%d =================\n",__func__,__LINE__);
/* if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
printk("I2C check functionality failed.");
return -ENODEV;
}
*/
if (client->dev.of_node) {
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
if(!pdata)
return -ENOMEM;
ret = ktd2150_parse_dt(&client->dev);
if(ret < 0){
printk("============== get dt data failed! =====================\n");
return ret;
}

}
pdata->client = client;
ret = ktd2150_init_device(client);
if(ret){
printk("============== init ktd2150 failed! ret : %d =====================\n",ret);
goto error;
}
/* ret = ktd2150_init_pm_fb_notifier(pdata);
if (ret) {
printk("=========================== tom test Init FB notifier failed %d ==================\n", ret);
}
*/
printk("=============== %s success ,%d =================\n",__func__,__LINE__);
return 0;
error:
/* if (gpio_is_valid(pdata->enp_gpio))
gpio_free(pdata->enp_gpio);
printk("=============== %s failed ,%d ret : %d =================\n",__func__,__LINE__,ret);
if (gpio_is_valid(pdata->enn_gpio))
gpio_free(pdata->enn_gpio);
printk("=============== %s failed ,%d ret : %d =================\n",__func__,__LINE__,ret);
*/
return ret;
}

static int ktd2150_remove(struct i2c_client *client)
{
return 0;
}

static const struct i2c_device_id ktd2150_id[] = {
{"ablyktd2150", 0},
{},
};

static struct of_device_id ktd2150_match_table[] = {
{ .compatible = "ablyktd2150",},
{},
};

static struct i2c_driver ktd2150_driver = {
.probe = ktd2150_probe,
.remove = ktd2150_remove,
.driver = {
.name = "ablyktd2150",
.owner = THIS_MODULE,
.of_match_table = ktd2150_match_table,
},
.id_table = ktd2150_id,
};

static int __init ktd2150_init(void)
{
int ret = 0;
printk("=============== %s in ,%d =================\n",__func__,__LINE__);
ret = i2c_add_driver(&ktd2150_driver);
if(ret != 0){
printk("=============== ktd2150_driver register failed!=================\n");
}
printk("=============== %s out ,%d =================\n",__func__,__LINE__);
return ret;
}

static void __exit ktd2150_exit(void)
{
i2c_del_driver(&ktd2150_driver);
}

module_init(ktd2150_init);
module_exit(ktd2150_exit);

MODULE_DESCRIPTION("ABLY KTD2150 Driver");
MODULE_AUTHOR("tom");
MODULE_LICENSE("GPL");
...全文
3403 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
carl.xu 2020-09-16
  • 打赏
  • 举报
回复
ktd2150_init 确定已经走了,就是device与driver不匹配,怎么弄才好,请指导一下
carl.xu 2020-09-16
  • 打赏
  • 举报
回复
我再试试,dtsi中配置,我的理解应该莫问题呀
yoveldf 2020-09-16
  • 打赏
  • 举报
回复
注册一个同名字的device
carl.xu 2020-09-16
  • 打赏
  • 举报
回复
我想在此基础上添加suspend resume函数,不走probe,不知可以不

21,595

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧