最近一直在调试codec芯片,好多代码FAE给的和平台不适配,比如结构体改了之类的,一些编译问题老是忘记,就想着顺手写下总结。
error: function definition is not allowed here
好家伙,它说函数不能够在这里定义。网上看了一下,这个报错的原因是在函数原型里面又定义了一个函数,
回头看下函数报错的位置,这里for循环的括号丢了一个,添上即可。
(其他还有类似报错,但是 发生在报错函数的前一个函数少一个括号-_-)。
这玩意会带来一系列报错,改一个就改好好多报错。
627:109: error: extraneous ')' before ';'
这个报错说有个括号很突兀,不晓得哪里来的,extraneous是外来的意思。
然后看了下,发现多了一个括号。
这个报错是说,snd_soc_dai结构体里面缺少成员变量codec,
好家伙,我发现这个snd_soc_codec结构体在android 11直接被干没了。 之前在msm-3.18 、 android 7是有的,如下:
grep -nr "struct snd_soc_codec {" ./kernel/msm-3.18/
/* SoC Audio Codec device */
struct snd_soc_codec {
struct device *dev;
const struct snd_soc_codec_driver *driver;
struct mutex mutex;
struct list_head list;
struct list_head card_list;
int (*volatile_register)(struct snd_soc_codec *, unsigned int);
int (*readable_register)(struct snd_soc_codec *, unsigned int);
int (*writable_register)(struct snd_soc_codec *, unsigned int);
/* runtime */
struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
unsigned int cache_bypass:1; /* Suppress access to the cache */
unsigned int suspended:1; /* Codec is in suspend PM state */
unsigned int ac97_registered:1; /* Codec has been AC97 registered */
unsigned int ac97_created:1; /* Codec has been created by SoC */
unsigned int cache_init:1; /* codec cache has been initialized */
u32 cache_sync; /* Cache needs to be synced to hardware */
/* codec IO */
void *control_data; /* codec control (i2c/3wire) data */
hw_write_t hw_write;
void *reg_cache;
struct mutex cache_rw_mutex;
/* component */
struct snd_soc_component component;
/* dapm */
struct snd_soc_dapm_context dapm;
#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_reg;
#endif
};
仔细看了下代码,发现这个报错的地方就是根据dai(传进来的参数),找到codec,然后根据codec找到es7210结构体,目的是根据es7210->pcm_pop_work1的地址传参给schedule_delayed_work这个延迟队列,看了下pcm_pop_work1函数是处理POP音的,目前代码还在移植阶段,干脆简单粗暴把这个几个都注释掉:
995:6: warning: ISO C90 forbids mixing declarations and code
这个错误真的无力吐槽,也不知道哪个兄弟写的代码…这个要把int i放在前面。
error: implicit declaration of function 'snd_soc_codec_get_drvdata' [-Werror,-Wimplicit-function-declaration]
这里又用到了snd_soc_codec结构体,这里看起来绕不掉了,因为es7210_tdm_init_codec这个函数看起来比较重要。
于是想着看看平台默认的codec驱动是咋搞的,看了下snd_soc_component结构体与snd_soc_codec类似,于是决定全面改写代码,把传参struct snd_soc_codec *codec全部干掉,换成struct snd_soc_component *component。
.c:2187:2: error: implicit declaration of function 'snd_soc_unregister_codec'
[-Werror,-Wimplicit-function-declaration]
snd_soc_unregister_codec这个函数也木得,(后面直接用SI看了,不grep了),还是看了下平台的codec芯片代码,
发现应该是用snd_soc_unregister_component函数。
同样,snd_soc_register_codec这个函数也木有了,我们替换成snd_soc_register_component。
error: use of undeclared identifier 'GPIO_HIGH'
这个都不用看,直接把宏定义放在代码前面即可。
#define GPIO_LOW 0
#define GPIO_HIGH 1
error: no member named 'power_enable_gpio' in 'struct es7210_priv'
struct es7210_priv {
struct regmap *regmap;
struct device *dev;
struct i2c_client *i2c;
unsigned int sysclk;
struct clk *mclk;
struct snd_pcm_hw_constraint_list *sysclk_constraints;
unsigned int tdm_mode;
struct delayed_work pcm_pop_work;
struct delayed_work pcm_pop_work1;
//struct delayed_work es7243_init_work;
struct voltage_supply vol_supply;
int power_enable_gpio;
};
这个没啥说的,成员变量power_enable_gpio没有,那就加上。
error: implicit declaration of function 'gpio_is_valid'
[-Werror,-Wimplicit-function-declaration]
if (!gpio_is_valid(es7210->power_enable_gpio)){
看下 of_get_named_gpio的函数原型:
static inline int of_get_named_gpio(struct device_node *np,
const char *propname, int index)
{
return of_get_named_gpio_flags(np, propname, index, NULL);
}
snd_soc_codec_driver这个结构体没有,看看对比的codec驱动咋搞的。。
把他换成snd_soc_component_driver。
error: implicit declaration of function 'gpio_free'
[-Werror,-Wimplicit-function-declaration] ,gpio_free(es7210->power_enable_gpio);
这个报错前后看了下没啥异常的,原因是没有包含文件头,gpio.h,这个在代码开头添上即可:
#include
error: incompatible pointer types initializing 'void (*)(struct snd_soc_component *)'
with an expression of type 'int (struct snd_soc_component *)' [-Werror,-Wincompatible-pointer-types]
.remove = es7210_remove,
这个地方报错得看下snd_soc_component_driver结构体,从报错来看应该是定义的结构体成员变量类型不匹配,
static int es7210_remove(struct snd_soc_component *component)
{
return 0;
}
修改为:
static void es7210_remove(struct snd_soc_component *component)
{
return ;
}
error: field designator 'reg_word_size' does not refer to any field in type
'struct snd_soc_component_driver'
.reg_word_size = sizeof(u8),
/* component interface */
struct snd_soc_component_driver {
const char *name;
/* Default control and setup, added after probe() is run */
const struct snd_kcontrol_new *controls;
unsigned int num_controls;
const struct snd_soc_dapm_widget *dapm_widgets;
unsigned int num_dapm_widgets;
const struct snd_soc_dapm_route *dapm_routes;
unsigned int num_dapm_routes;
int (*probe)(struct snd_soc_component *);
void (*remove)(struct snd_soc_component *);
int (*suspend)(struct snd_soc_component *);
int (*resume)(struct snd_soc_component *);
unsigned int (*read)(struct snd_soc_component *, unsigned int);
int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
/* pcm creation and destruction */
int (*pcm_new)(struct snd_soc_pcm_runtime *);
void (*pcm_free)(struct snd_pcm *);
/* component wide operations */
int (*set_sysclk)(struct snd_soc_component *component,
int clk_id, int source, unsigned int freq, int dir);
int (*set_pll)(struct snd_soc_component *component, int pll_id,
int source, unsigned int freq_in, unsigned int freq_out);
int (*set_jack)(struct snd_soc_component *component,
struct snd_soc_jack *jack, void *data);
/* DT */
int (*of_xlate_dai_name)(struct snd_soc_component *component,
struct of_phandle_args *args,
const char **dai_name);
int (*of_xlate_dai_id)(struct snd_soc_component *comment,
struct device_node *endpoint);
void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
int subseq);
int (*stream_event)(struct snd_soc_component *, int event);
int (*set_bias_level)(struct snd_soc_component *component,
enum snd_soc_bias_level level);
/*
* For platform-caused delay reporting, where the thread blocks waiting
* for the delay amount to be determined. Defining this will cause the
* ASoC core to skip calling the delay callbacks for all components in
* the runtime.
* Optional.
*/
snd_pcm_sframes_t (*delay_blk)(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai);
const struct snd_pcm_ops *ops;
const struct snd_compr_ops *compr_ops;
/* probe ordering - for components with runtime dependencies */
int probe_order;
int remove_order;
/* bits */
unsigned int idle_bias_on:1;
unsigned int suspend_bias_off:1;
unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
unsigned int endianness:1;
unsigned int non_legacy_dai_naming:1;
/* this component uses topology and ignore machine driver FEs */
const char *ignore_machine;
const char *topology_name_prefix;
int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params);
bool use_dai_pcm_id; /* use the DAI link PCM ID as PCM device number */
int be_pcm_base; /* base device ID for all BE PCMs */
};
看了下结构体的成员变量,这个里面没有reg_word_size,那就给它加上,.reg_word_size = sizeof(u8),这个给它整个short就足够了,
unsigned int (*read)(struct snd_soc_component *, unsigned int);
int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
+ short reg_word_size;
/* pcm creation and destruction */
int (*pcm_new)(struct snd_soc_pcm_runtime *);
.reg_cache_default = es7210_reg_defaults,
这个也是结构体的成员变量里面没有,它指向的是结构体数组的地址,所以使用unsigned long int,
unsigned long int reg_cache_default;
结果还是类型不匹配-_-,这样改了下就好了:
const struct reg_default *reg_cache_default;
error: field designator 'reg_cache_size' does not refer to any field in
type 'struct snd_soc_component_driver'
.reg_cache_size = ARRAY_SIZE(es7210_reg_defaults),
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
从这个宏定义来看,我给它一个整型,
它这个是结构体里面又嵌入了一个结构体,这个操作很简单,因为默认的结构里里面是有:controls和num_controls
的:
implicit declaration of function 'of_get_named_gpio' [-Werror,-Wimplicit-function-declaration]
power_enable_gpio = of_get_named_gpio(np, "es7210,power-enable-gpio", 0);
这个函数原型:of_get_named_gpio,用SI看了下在:
kernel\msm-4.19\include\linux\of_gpio.h
所以加上文件头:
#include
warning: unused function 'es7210_multi_chips_write' [-Wunused-function]
error, forbidden warning:
代码被调用的地方,默认全部被注释了,所以直接把这个函数也注释了即可。