ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2015年2月16日 星期一

為rt5625 codec 的 sysfs 增加一個 mic gain attr

mic gain 是 RT5625_MIC_CTRL,
使用的 write function 是:
snd_soc_write(codec,RT5625_MIC_CTRL,value);
read function 是:
int data = snd_soc_read(codec,RT5625_MIC_CTRL);
所以 sysfs 的 show 和 store:
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,&regvalue);
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);
view raw gistfile1.c hosted with ❤ by GitHub

最後,在 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

沒有留言:

標籤

網誌存檔