111 lines
3.0 KiB
C
111 lines
3.0 KiB
C
#include <linux/kernel.h>
|
|
#include <linux/kobject.h>
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/sysfs.h>
|
|
|
|
static struct kset *netease_keyset = NULL;
|
|
static struct kobject cpld_ko;
|
|
extern int cx20810_set_mode(int mode, int index);
|
|
extern void netease_cpld_reset(void);
|
|
extern void netease_adau1761_init(void);
|
|
|
|
enum {
|
|
CX20810_NORMAL_MODE = 0,
|
|
CX20810_NORMAL_MODE_SIMPLE,
|
|
CX20810_NIRMAL_MODE_CODEC3,
|
|
CX20810_NIRMAL_MODE_CODEC3_SIMPLE,
|
|
CX20810_96K_16BIT_MODE,
|
|
CX20810_48K_16BIT_MODE,
|
|
};
|
|
|
|
static ssize_t gen_attr_show(struct kobject *kobj, struct attribute *attr,
|
|
char *buf) {
|
|
int count = 0;
|
|
count += sprintf(buf, "Cpld init help:\n");
|
|
count += sprintf(buf + count, "adc rst and config:echo 1 > cpld_init\n");
|
|
count += sprintf(buf + count, "adc rst:echo 2 > cpld_init\n");
|
|
count += sprintf(buf + count, "adc config:echo 3 > cpld_init\n");
|
|
count += sprintf(buf + count, "adau1761 init:echo 4 > cpld_init\n");
|
|
|
|
return count;
|
|
}
|
|
|
|
static ssize_t gen_attr_store(struct kobject *kobj, struct attribute *attr,
|
|
const char *buf, size_t count) {
|
|
long ret = -1;
|
|
kstrtol(buf, 10, &ret);
|
|
|
|
switch (ret) {
|
|
case 1:
|
|
printk("Adc rst and config\n");
|
|
netease_cpld_reset();
|
|
cx20810_set_mode(CX20810_NORMAL_MODE, 0);
|
|
cx20810_set_mode(CX20810_NORMAL_MODE, 1);
|
|
break;
|
|
|
|
case 2:
|
|
printk("Adc rst\n");
|
|
netease_cpld_reset();
|
|
break;
|
|
|
|
case 3:
|
|
printk("Adc config\n");
|
|
cx20810_set_mode(CX20810_NORMAL_MODE, 0);
|
|
cx20810_set_mode(CX20810_NORMAL_MODE, 1);
|
|
break;
|
|
|
|
case 4:
|
|
printk("Init adau1761!\n");
|
|
netease_adau1761_init();
|
|
break;
|
|
|
|
default:
|
|
printk("Can not read your input cmd, need help? type cat cpld_init.");
|
|
}
|
|
|
|
printk("Do finish, Get ret:%d, count:%d, input:%s\n", ret, count, buf);
|
|
// tipa_set_vol(2 * (24-i));
|
|
return count;
|
|
}
|
|
|
|
static const struct sysfs_ops cpld_ktype_ops = {
|
|
.show = gen_attr_show,
|
|
.store = gen_attr_store,
|
|
};
|
|
struct attribute cpld_init_set = {
|
|
.name = "cpld_init",
|
|
.mode = S_IRWXUGO,
|
|
};
|
|
struct attribute *cpld_attr_group[] = {&cpld_init_set, NULL};
|
|
|
|
void cpld_release(struct kobject *kobj) {
|
|
printk("wzj:release %d\n", kobj->name);
|
|
}
|
|
|
|
static struct kobj_type cpld_ko_ktype = {
|
|
.sysfs_ops = &cpld_ktype_ops,
|
|
.default_attrs = cpld_attr_group,
|
|
.release = cpld_release,
|
|
};
|
|
|
|
static int __init netease_config_init(void) {
|
|
printk("Begin to start netease config!\n");
|
|
netease_keyset = kset_create_and_add("netease", NULL, NULL);
|
|
|
|
cpld_ko.kset = netease_keyset;
|
|
kobject_init_and_add(&cpld_ko, &cpld_ko_ktype, NULL, "cpld_control");
|
|
|
|
return 0;
|
|
}
|
|
|
|
module_init(netease_config_init);
|
|
|
|
static void __exit netease_config_exit(void) {}
|
|
module_exit(netease_config_exit);
|
|
|
|
/* Module information */
|
|
MODULE_AUTHOR("Wang zijiao");
|
|
MODULE_DESCRIPTION("Netease config!");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:netease_config"); |