lw35-upgrade/ioc/kernel-driver/lw35ioc.c

103 lines
2.3 KiB
C
Raw Normal View History

#include <linux/device.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/serdev.h>
#include <linux/types.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Markus Koch");
MODULE_DESCRIPTION("LW-35 I/O Controller Driver");
MODULE_VERSION("0.1");
static int debug_level = 0;
module_param(debug_level, int, 0);
MODULE_PARM_DESC(debug_level, "Debug level");
static struct of_device_id lw35ioc_dt_ids[] = {
{ .compatible = "brother,lw35", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, lw35ioc_dt_ids);
struct lw35ioc_priv {
struct serdev_device *serdev;
// USER VARS HERE
};
static int lw35ioc_receive_buf(struct serdev_device *serdev,
const unsigned char *data,
size_t count)
{
dev_info(&serdev->dev, "RX: %c\n", data[0]);
return 1; // TODO: return proper value
}
static void lw35ioc_write_wakeup(struct serdev_device *serdev)
{
dev_info(&serdev->dev, "Write wakeup\n");
// schedule work here
}
static struct serdev_device_ops lw35ioc_serdev_ops = {
.receive_buf = lw35ioc_receive_buf,
.write_wakeup = lw35ioc_write_wakeup,
};
static int lw35ioc_probe(struct serdev_device *serdev)
{
struct lw35ioc_priv *priv = NULL;
int ret;
u32 speed = 9600;
printk(KERN_INFO "lw35ioc: probe\n");
priv = devm_kzalloc(&serdev->dev,
sizeof(struct lw35ioc_priv),
GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->serdev = serdev;
serdev_device_set_drvdata(serdev, priv);
serdev_device_set_client_ops(serdev, &lw35ioc_serdev_ops);
ret = serdev_device_open(serdev);
if (ret) {
dev_err(&serdev->dev, "Unable to open device.\n");
goto fail0;
}
speed = serdev_device_set_baudrate(serdev, speed);
dev_info(&serdev->dev, "Using baudrate: %u\n", speed);
dev_info(&serdev->dev, "Loaded driver\n");
return 0;
fail0:
return ret;
}
static void lw35ioc_remove(struct serdev_device *serdev)
{
struct lw35ioc_priv *priv = serdev_device_get_drvdata(serdev);
dev_info(&serdev->dev, "remove\n");
return;
}
static struct serdev_device_driver lw35ioc_driver = {
.probe = lw35ioc_probe,
.remove = lw35ioc_remove,
.driver = {
.name = "lw35ioc",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(lw35ioc_dt_ids),
},
};
module_serdev_device_driver(lw35ioc_driver);