Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
raspberrypi-kernel
提交
6037fcad
R
raspberrypi-kernel
项目概览
openeuler
/
raspberrypi-kernel
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
raspberrypi-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6037fcad
编写于
8月 22, 2013
作者:
M
Mark Brown
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'asoc/topic/max9877' into asoc-next
上级
588701ef
5cf9da8a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
92 addition
and
202 deletion
+92
-202
sound/soc/codecs/max9877.c
sound/soc/codecs/max9877.c
+92
-202
未找到文件。
sound/soc/codecs/max9877.c
浏览文件 @
6037fcad
...
...
@@ -14,170 +14,21 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <sound/soc.h>
#include <sound/tlv.h>
#include "max9877.h"
static
struct
i2c_client
*
i2c
;
static
struct
regmap
*
regmap
;
static
u8
max9877_regs
[
5
]
=
{
0x40
,
0x00
,
0x00
,
0x00
,
0x49
};
static
void
max9877_write_regs
(
void
)
{
unsigned
int
i
;
u8
data
[
6
];
data
[
0
]
=
MAX9877_INPUT_MODE
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
max9877_regs
);
i
++
)
data
[
i
+
1
]
=
max9877_regs
[
i
];
if
(
i2c_master_send
(
i2c
,
data
,
6
)
!=
6
)
dev_err
(
&
i2c
->
dev
,
"i2c write failed
\n
"
);
}
static
int
max9877_get_reg
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
struct
soc_mixer_control
*
mc
=
(
struct
soc_mixer_control
*
)
kcontrol
->
private_value
;
unsigned
int
reg
=
mc
->
reg
;
unsigned
int
shift
=
mc
->
shift
;
unsigned
int
mask
=
mc
->
max
;
unsigned
int
invert
=
mc
->
invert
;
ucontrol
->
value
.
integer
.
value
[
0
]
=
(
max9877_regs
[
reg
]
>>
shift
)
&
mask
;
if
(
invert
)
ucontrol
->
value
.
integer
.
value
[
0
]
=
mask
-
ucontrol
->
value
.
integer
.
value
[
0
];
return
0
;
}
static
int
max9877_set_reg
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
struct
soc_mixer_control
*
mc
=
(
struct
soc_mixer_control
*
)
kcontrol
->
private_value
;
unsigned
int
reg
=
mc
->
reg
;
unsigned
int
shift
=
mc
->
shift
;
unsigned
int
mask
=
mc
->
max
;
unsigned
int
invert
=
mc
->
invert
;
unsigned
int
val
=
(
ucontrol
->
value
.
integer
.
value
[
0
]
&
mask
);
if
(
invert
)
val
=
mask
-
val
;
if
(((
max9877_regs
[
reg
]
>>
shift
)
&
mask
)
==
val
)
return
0
;
max9877_regs
[
reg
]
&=
~
(
mask
<<
shift
);
max9877_regs
[
reg
]
|=
val
<<
shift
;
max9877_write_regs
();
return
1
;
}
static
int
max9877_get_2reg
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
struct
soc_mixer_control
*
mc
=
(
struct
soc_mixer_control
*
)
kcontrol
->
private_value
;
unsigned
int
reg
=
mc
->
reg
;
unsigned
int
reg2
=
mc
->
rreg
;
unsigned
int
shift
=
mc
->
shift
;
unsigned
int
mask
=
mc
->
max
;
ucontrol
->
value
.
integer
.
value
[
0
]
=
(
max9877_regs
[
reg
]
>>
shift
)
&
mask
;
ucontrol
->
value
.
integer
.
value
[
1
]
=
(
max9877_regs
[
reg2
]
>>
shift
)
&
mask
;
return
0
;
}
static
int
max9877_set_2reg
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
struct
soc_mixer_control
*
mc
=
(
struct
soc_mixer_control
*
)
kcontrol
->
private_value
;
unsigned
int
reg
=
mc
->
reg
;
unsigned
int
reg2
=
mc
->
rreg
;
unsigned
int
shift
=
mc
->
shift
;
unsigned
int
mask
=
mc
->
max
;
unsigned
int
val
=
(
ucontrol
->
value
.
integer
.
value
[
0
]
&
mask
);
unsigned
int
val2
=
(
ucontrol
->
value
.
integer
.
value
[
1
]
&
mask
);
unsigned
int
change
=
0
;
if
(((
max9877_regs
[
reg
]
>>
shift
)
&
mask
)
!=
val
)
change
=
1
;
if
(((
max9877_regs
[
reg2
]
>>
shift
)
&
mask
)
!=
val2
)
change
=
1
;
if
(
change
)
{
max9877_regs
[
reg
]
&=
~
(
mask
<<
shift
);
max9877_regs
[
reg
]
|=
val
<<
shift
;
max9877_regs
[
reg2
]
&=
~
(
mask
<<
shift
);
max9877_regs
[
reg2
]
|=
val2
<<
shift
;
max9877_write_regs
();
}
return
change
;
}
static
int
max9877_get_out_mode
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
u8
value
=
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&
MAX9877_OUTMODE_MASK
;
if
(
value
)
value
-=
1
;
ucontrol
->
value
.
integer
.
value
[
0
]
=
value
;
return
0
;
}
static
int
max9877_set_out_mode
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
u8
value
=
ucontrol
->
value
.
integer
.
value
[
0
];
value
+=
1
;
if
((
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&
MAX9877_OUTMODE_MASK
)
==
value
)
return
0
;
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&=
~
MAX9877_OUTMODE_MASK
;
max9877_regs
[
MAX9877_OUTPUT_MODE
]
|=
value
;
max9877_write_regs
();
return
1
;
}
static
int
max9877_get_osc_mode
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
u8
value
=
(
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&
MAX9877_OSC_MASK
);
value
=
value
>>
MAX9877_OSC_OFFSET
;
ucontrol
->
value
.
integer
.
value
[
0
]
=
value
;
return
0
;
}
static
int
max9877_set_osc_mode
(
struct
snd_kcontrol
*
kcontrol
,
struct
snd_ctl_elem_value
*
ucontrol
)
{
u8
value
=
ucontrol
->
value
.
integer
.
value
[
0
];
value
=
value
<<
MAX9877_OSC_OFFSET
;
if
((
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&
MAX9877_OSC_MASK
)
==
value
)
return
0
;
max9877_regs
[
MAX9877_OUTPUT_MODE
]
&=
~
MAX9877_OSC_MASK
;
max9877_regs
[
MAX9877_OUTPUT_MODE
]
|=
value
;
max9877_write_regs
();
return
1
;
}
static
struct
reg_default
max9877_regs
[]
=
{
{
0
,
0x40
},
{
1
,
0x00
},
{
2
,
0x00
},
{
3
,
0x00
},
{
4
,
0x49
},
};
static
const
unsigned
int
max9877_pgain_tlv
[]
=
{
TLV_DB_RANGE_HEAD
(
2
),
...
...
@@ -212,65 +63,104 @@ static const char *max9877_osc_mode[] = {
};
static
const
struct
soc_enum
max9877_enum
[]
=
{
SOC_ENUM_SINGLE_EXT
(
ARRAY_SIZE
(
max9877_out_mode
),
max9877_out_mode
),
SOC_ENUM_SINGLE_EXT
(
ARRAY_SIZE
(
max9877_osc_mode
),
max9877_osc_mode
),
SOC_ENUM_SINGLE
(
MAX9877_OUTPUT_MODE
,
0
,
ARRAY_SIZE
(
max9877_out_mode
),
max9877_out_mode
),
SOC_ENUM_SINGLE
(
MAX9877_OUTPUT_MODE
,
MAX9877_OSC_OFFSET
,
ARRAY_SIZE
(
max9877_osc_mode
),
max9877_osc_mode
),
};
static
const
struct
snd_kcontrol_new
max9877_controls
[]
=
{
SOC_SINGLE_EXT_TLV
(
"MAX9877 PGAINA Playback Volume"
,
MAX9877_INPUT_MODE
,
0
,
2
,
0
,
max9877_get_reg
,
max9877_set_reg
,
max9877_pgain_tlv
),
SOC_SINGLE_EXT_TLV
(
"MAX9877 PGAINB Playback Volume"
,
MAX9877_INPUT_MODE
,
2
,
2
,
0
,
max9877_get_reg
,
max9877_set_reg
,
max9877_pgain_tlv
),
SOC_SINGLE_EXT_TLV
(
"MAX9877 Amp Speaker Playback Volume"
,
MAX9877_SPK_VOLUME
,
0
,
31
,
0
,
max9877_get_reg
,
max9877_set_reg
,
max9877_output_tlv
),
SOC_DOUBLE_R_EXT_TLV
(
"MAX9877 Amp HP Playback Volume"
,
MAX9877_HPL_VOLUME
,
MAX9877_HPR_VOLUME
,
0
,
31
,
0
,
max9877_get_2reg
,
max9877_set_2reg
,
max9877_output_tlv
),
SOC_SINGLE_EXT
(
"MAX9877 INB Stereo Switch"
,
MAX9877_INPUT_MODE
,
4
,
1
,
1
,
max9877_get_reg
,
max9877_set_reg
),
SOC_SINGLE_EXT
(
"MAX9877 INA Stereo Switch"
,
MAX9877_INPUT_MODE
,
5
,
1
,
1
,
max9877_get_reg
,
max9877_set_reg
),
SOC_SINGLE_EXT
(
"MAX9877 Zero-crossing detection Switch"
,
MAX9877_INPUT_MODE
,
6
,
1
,
0
,
max9877_get_reg
,
max9877_set_reg
),
SOC_SINGLE_EXT
(
"MAX9877 Bypass Mode Switch"
,
MAX9877_OUTPUT_MODE
,
6
,
1
,
0
,
max9877_get_reg
,
max9877_set_reg
),
SOC_SINGLE_EXT
(
"MAX9877 Shutdown Mode Switch"
,
MAX9877_OUTPUT_MODE
,
7
,
1
,
1
,
max9877_get_reg
,
max9877_set_reg
),
SOC_ENUM_EXT
(
"MAX9877 Output Mode"
,
max9877_enum
[
0
],
max9877_get_out_mode
,
max9877_set_out_mode
),
SOC_ENUM_EXT
(
"MAX9877 Oscillator Mode"
,
max9877_enum
[
1
],
max9877_get_osc_mode
,
max9877_set_osc_mode
),
SOC_SINGLE_TLV
(
"MAX9877 PGAINA Playback Volume"
,
MAX9877_INPUT_MODE
,
0
,
2
,
0
,
max9877_pgain_tlv
),
SOC_SINGLE_TLV
(
"MAX9877 PGAINB Playback Volume"
,
MAX9877_INPUT_MODE
,
2
,
2
,
0
,
max9877_pgain_tlv
),
SOC_SINGLE_TLV
(
"MAX9877 Amp Speaker Playback Volume"
,
MAX9877_SPK_VOLUME
,
0
,
31
,
0
,
max9877_output_tlv
),
SOC_DOUBLE_R_TLV
(
"MAX9877 Amp HP Playback Volume"
,
MAX9877_HPL_VOLUME
,
MAX9877_HPR_VOLUME
,
0
,
31
,
0
,
max9877_output_tlv
),
SOC_SINGLE
(
"MAX9877 INB Stereo Switch"
,
MAX9877_INPUT_MODE
,
4
,
1
,
1
),
SOC_SINGLE
(
"MAX9877 INA Stereo Switch"
,
MAX9877_INPUT_MODE
,
5
,
1
,
1
),
SOC_SINGLE
(
"MAX9877 Zero-crossing detection Switch"
,
MAX9877_INPUT_MODE
,
6
,
1
,
0
),
SOC_SINGLE
(
"MAX9877 Bypass Mode Switch"
,
MAX9877_OUTPUT_MODE
,
6
,
1
,
0
),
SOC_ENUM
(
"MAX9877 Output Mode"
,
max9877_enum
[
0
]),
SOC_ENUM
(
"MAX9877 Oscillator Mode"
,
max9877_enum
[
1
]),
};
/* This function is called from ASoC machine driver */
int
max9877_add_controls
(
struct
snd_soc_codec
*
codec
)
{
return
snd_soc_add_codec_controls
(
codec
,
max9877_controls
,
ARRAY_SIZE
(
max9877_controls
));
}
EXPORT_SYMBOL_GPL
(
max9877_add_controls
);
static
const
struct
snd_soc_dapm_widget
max9877_dapm_widgets
[]
=
{
SND_SOC_DAPM_INPUT
(
"INA1"
),
SND_SOC_DAPM_INPUT
(
"INA2"
),
SND_SOC_DAPM_INPUT
(
"INB1"
),
SND_SOC_DAPM_INPUT
(
"INB2"
),
SND_SOC_DAPM_INPUT
(
"RXIN+"
),
SND_SOC_DAPM_INPUT
(
"RXIN-"
),
SND_SOC_DAPM_PGA
(
"SHDN"
,
MAX9877_OUTPUT_MODE
,
7
,
1
,
NULL
,
0
),
SND_SOC_DAPM_OUTPUT
(
"OUT+"
),
SND_SOC_DAPM_OUTPUT
(
"OUT-"
),
SND_SOC_DAPM_OUTPUT
(
"HPL"
),
SND_SOC_DAPM_OUTPUT
(
"HPR"
),
};
static
const
struct
snd_soc_dapm_route
max9877_dapm_routes
[]
=
{
{
"SHDN"
,
NULL
,
"INA1"
},
{
"SHDN"
,
NULL
,
"INA2"
},
{
"SHDN"
,
NULL
,
"INB1"
},
{
"SHDN"
,
NULL
,
"INB2"
},
{
"OUT+"
,
NULL
,
"RXIN+"
},
{
"OUT+"
,
NULL
,
"SHDN"
},
{
"OUT-"
,
NULL
,
"SHDN"
},
{
"OUT-"
,
NULL
,
"RXIN-"
},
{
"HPL"
,
NULL
,
"SHDN"
},
{
"HPR"
,
NULL
,
"SHDN"
},
};
static
const
struct
snd_soc_codec_driver
max9877_codec
=
{
.
controls
=
max9877_controls
,
.
num_controls
=
ARRAY_SIZE
(
max9877_controls
),
.
dapm_widgets
=
max9877_dapm_widgets
,
.
num_dapm_widgets
=
ARRAY_SIZE
(
max9877_dapm_widgets
),
.
dapm_routes
=
max9877_dapm_routes
,
.
num_dapm_routes
=
ARRAY_SIZE
(
max9877_dapm_routes
),
};
static
const
struct
regmap_config
max9877_regmap
=
{
.
reg_bits
=
8
,
.
val_bits
=
8
,
.
reg_defaults
=
max9877_regs
,
.
num_reg_defaults
=
ARRAY_SIZE
(
max9877_regs
),
.
cache_type
=
REGCACHE_RBTREE
,
};
static
int
max9877_i2c_probe
(
struct
i2c_client
*
client
,
const
struct
i2c_device_id
*
id
)
{
i
2c
=
client
;
i
nt
i
;
max9877_write_regs
();
regmap
=
devm_regmap_init_i2c
(
client
,
&
max9877_regmap
);
if
(
IS_ERR
(
regmap
))
return
PTR_ERR
(
regmap
);
return
0
;
/* Ensure the device is in reset state */
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
max9877_regs
);
i
++
)
regmap_write
(
regmap
,
max9877_regs
[
i
].
reg
,
max9877_regs
[
i
].
def
);
return
snd_soc_register_codec
(
&
client
->
dev
,
&
max9877_codec
,
NULL
,
0
);
}
static
int
max9877_i2c_remove
(
struct
i2c_client
*
client
)
{
i2c
=
NULL
;
snd_soc_unregister_codec
(
&
client
->
dev
)
;
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录