I have a device driver and run under Android platfrom (kernel
version is 2.6.29) .
I added it(below code) to let HAL to access, but it would
fail.
If I use the command:"mknod /dev/myI2C -c 10 60" to create
the device node
again(character device node), it can access.
How to modify the driver to let device node work without
creating again?
Thanks for your BIG help.
BR,
Alan
//------------------------------------------------------------------------------------------//
static struct i2c_client *myI2C_i2c_client = NULL;
/* Addresses to scan */
static unsigned short normal_i2c[] = { myI2C_I2C_SLAVE_ADDR,
I2C_CLIENT_END };
/* Insmod parameters */
I2C_CLIENT_INSMOD_1(myI2C);
static int myI2C_i2c_attach_adapter(struct i2c_adapter *adapter);
static int myI2C_i2c_detect(struct i2c_adapter *adapter, int address,
int kind);
static int myI2C_i2c_detach_client(struct i2c_client *client);
struct myI2C_i2c_data {
struct i2c_client client;
};
static struct i2c_driver myI2C_i2c_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "myI2C driver",
},
.attach_adapter = myI2C_i2c_attach_adapter,
.detach_client = myI2C_i2c_detach_client,
.id = I2C_DRIVERID_MYI2C,
};
static ssize_t show_chipinfo_value(struct device *dev, struct
device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", "myI2C");
}
static ssize_t show_rawdata_value(struct device *dev, struct
device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", "123");
}
static DEVICE_ATTR(chipinfo, S_IRUGO, show_chipinfo_value, NULL);
static DEVICE_ATTR(rawdata, S_IRUGO, show_rawdata_value, NULL);
static int myI2C_open(struct inode *inode, struct file *file)
{
return nonseekable_open(inode, file);
}
static int myI2C_release(struct inode *inode, struct file *file)
{
return 0;
}
static int myI2C_ioctl(struct inode *inode, struct file *file,
unsigned int cmd,
unsigned long arg)
{
return 0;
}
static struct file_operations myI2C_fops = {
.owner = THIS_MODULE,
.open = myI2C_open,
.release = myI2C_release,
.ioctl = myI2C_ioctl,
};
static struct miscdevice myI2C_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "myI2C",
.fops = &myI2C_fops,
};
static int myI2C_i2c_attach_adapter(struct i2c_adapter *adapter)
{
int res;
res = i2c_probe(adapter, &addr_data, myI2C_i2c_detect);
return res;
}
static int myI2C_i2c_detect(struct i2c_adapter *adapter, int address,
int kind)
{
struct i2c_client *new_client;
struct myI2C_i2c_data *data;
int err = 0;
if (!(data = kmalloc(sizeof(struct myI2C_i2c_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
memset(data, 0, sizeof(struct myI2C_i2c_data));
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &myI2C_i2c_driver;
new_client->flags = 0;
strlcpy(new_client->name, "myI2C_i2c", I2C_NAME_SIZE);
myI2C_i2c_client = new_client;
if ((err = i2c_attach_client(new_client)))
goto exit_kfree;
err = misc_register(&myI2C_device);
if (err) {
printk(KERN_ERR
"myI2C_device register failed\n");
goto exit_misc_device_register_failed;
}
err = device_create_file(&new_client->dev, &dev_attr_chipinfo);
err = device_create_file(&new_client->dev, &dev_attr_sensordata);
return 0;
exit_misc_device_register_failed:
exit_kfree:
kfree(data);
exit:
return err;
}
static int myI2C_i2c_detach_client(struct i2c_client *client)
{
int err;
if ((err = i2c_detach_client(client)))
return err;
myI2C_i2c_client = NULL;
kfree(i2c_get_clientdata(client));
return 0;
}
static int __init myI2C_init(void)
{
return i2c_add_driver(&myI2C_i2c_driver);
}
static void __exit myI2C_exit(void)
{
i2c_del_driver(&myI2C_i2c_driver);
}
module_init(myI2C_init);
module_exit(myI2C_exit);
MODULE_AUTHOR("MyTester");
MODULE_DESCRIPTION("MYI2C driver");
MODULE_LICENSE("GPL");
//------------------------------------------------------------------------------------------//
This isn't necessarily the best solution, but for static mknodes
on systems that use udev (??? not sure about Android), then you
can place your mknod files into /lib/udev/devices
This might NOT be what you need... just a guess.
Are you using udev to manage automatic device creates?
Android doesn't use udev. One of the few ideas in the Google-paid
'reimplement the world' I actually second wholeheartedly. People who
design programming languages whose in flow-control factility is 'goto'
shouldn't cause troubles anywhere except on their own computers.
Android doesn't use udev. One of the few ideas in the Google-paid
'reimplement the world'-crusafe I actually second wholeheartedly. People who
design programming languages whose only flow-control factility is 'goto'
I found because the permissions of device node need to change.
When using misc_register to create device node, it only has r/w
permissions in file-owner.
So I would change the permissions to 0666 to others have r/w
permissions and the HAL can access to device node.
Thanks for your information.
BR,
Alan