Skip to content

Instantly share code, notes, and snippets.

@iceaway iceaway/pwm_rpmsg.c
Created Mar 24, 2020

Embed
What would you like to do?
rpmsg driver
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/idr.h>
#include <linux/rpmsg.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <linux/semaphore.h>
#include "pwm_rpmsg.h"
static struct mutex ept_mutex;
static ssize_t duty_cycle_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "duty_cycle\n");
}
static ssize_t duty_cycle_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
/*
unsigned long dc;
int ret;
ret = kstrtoul(buf, 10, &dc);
if (ret != 0)
return ret;
*/
pr_info("dev=%p", dev);
return count;
}
static DEVICE_ATTR_RW(duty_cycle);
static ssize_t period_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "period\n");
}
static ssize_t period_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return -EPIPE;
}
static DEVICE_ATTR_RW(period);
static ssize_t invert_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "invert\n");
}
static ssize_t invert_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return -EPIPE;
}
static DEVICE_ATTR_RW(invert);
static struct attribute *dev_pwm_attrs[] = {
&dev_attr_duty_cycle.attr,
&dev_attr_period.attr,
&dev_attr_invert.attr,
NULL
};
ATTRIBUTE_GROUPS(dev_pwm);
static int pwm_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
void *priv, u32 src)
{
/* do stuff */
return 0;
}
static int pwm_rpmsg_probe(struct rpmsg_device *rpdev)
{
dev_info(&rpdev->dev, "pwm driver probed, rpdev=%p, rpdev->dev=%p\n",
rpdev, &rpdev->dev);
return 0;
}
static void pwm_rpmsg_remove(struct rpmsg_device *rpdev)
{
/* Code to run when the module is removed */
mutex_lock(&ept_mutex);
if (rpdev->ept) {
rpmsg_destroy_ept(rpdev->ept);
rpdev->ept = NULL;
}
mutex_unlock(&ept_mutex);
mutex_destroy(&ept_mutex);
dev_info(&rpdev->dev, "pwm driver removed\n");
}
static struct rpmsg_device_id pwm_rpmsg_device_id_table[] = {
{ .name = "m4-pwm-channel" },
{ },
};
static struct rpmsg_driver pwm_rpmsg_driver = {
.probe = pwm_rpmsg_probe,
.remove = pwm_rpmsg_remove,
.callback = pwm_rpmsg_cb,
.id_table = pwm_rpmsg_device_id_table,
.drv = {
.groups = dev_pwm_groups,
.name = "pwm_rpmsg",
},
};
static int pwm_rpmsg_init(void)
{
int ret;
pr_info("pwm: module init\n");
ret = register_rpmsg_driver(&pwm_rpmsg_driver);
if (ret < 0) {
pr_err("pwm: failed to register pwm driver\n");
}
return ret;
}
postcore_initcall(pwm_rpmsg_init);
static void pwm_rpmsg_exit(void)
{
/* Code when module exits */
unregister_rpmsg_driver(&pwm_rpmsg_driver);
}
module_exit(pwm_rpmsg_exit);
MODULE_ALIAS("pwm:rpmsg_pwm");
MODULE_LICENSE("GPL v2");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.