使用的 write function 是:
snd_soc_write(codec,RT5625_MIC_CTRL,value);read function 是:
int data = snd_soc_read(codec,RT5625_MIC_CTRL);所以 sysfs 的 show 和 store:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ssize_t rt5625_mic_ctrl_show(struct device *dev, | |
struct device_attribute *attr, char *buf) | |
{ | |
struct i2c_client *client = to_i2c_client(dev); | |
struct rt5625_priv *rt5625 = i2c_get_clientdata(client); | |
struct snd_soc_codec *codec = rt5625->codec; | |
int data = snd_soc_read(codec, RT5625_MIC_CTRL); | |
return sprintf(buf, "%x",data); | |
} | |
static ssize_t rt5625_mic_ctrl_store(struct device *dev, | |
struct device_attribute *attr, const char *buf, size_t count) | |
{ | |
struct i2c_client *client = to_i2c_client(dev); | |
struct rt5625_priv *rt5625 = i2c_get_clientdata(client); | |
struct snd_soc_codec *codec = rt5625->codec; | |
long regvalue; | |
int status; | |
status = strict_strtol(buf,16,®value); | |
if (status != 0) { | |
printk("rt5625 invalid parameter format %s\n",buf); | |
return -EINVAL; | |
} | |
snd_soc_write(codec, RT5625_MIC_CTRL, (int)regvalue&0xFFFF); | |
return count; | |
} | |
static DEVICE_ATTR(mic_ctrl, S_IRUGO | S_IWUSR | S_IWGRP, | |
rt5625_mic_ctrl_show, rt5625_mic_ctrl_store); |
最後,在 rt5625_probe( ) 裡,加上:
ret = device_create_file(codec->dev, &dev_attr_mic_ctrl); if (ret < 0 ) { dev_err(codec->dev, "Failed to create mic_ctrl sysfs files: %d\n", ret); return ret; }就可以了,
然後在機器啟動後,在 /sys/bus/i2c/drivers/rt5625-codec/0-001e 下,就會出現:
mic_ctrl
cat mic_ctrl 就會顯示 reg22 的值。
echo 800 > mic_ctrl 就會把 800 寫入 reg22
沒有留言:
張貼留言