0. 背景

最近一直在调试codec芯片,好多代码FAE给的和平台不适配,比如结构体改了之类的,一些编译问题老是忘记,就想着顺手写下总结。

1. function definition is not allowed here

error: function definition is not allowed here

好家伙,它说函数不能够在这里定义。网上看了一下,这个报错的原因是在函数原型里面又定义了一个函数,这个地方不一样啊。

回头看下函数报错的位置,这里for循环的括号丢了一个,添上即可。

(其他还有类似报错,但是 发生在报错函数的前一个函数少一个括号-_-)。

这玩意会带来一系列报错,改一个就改好好多报错。

2. extraneous ‘)’ before ‘;’

627:109: error: extraneous ')' before ';'

这个报错说有个括号很突兀,不晓得哪里来的,extraneous是外来的意思。

然后看了下,发现多了一个括号。

3. no member named ‘codec’ in 'struct snd_soc_dai


这个报错是说,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_FSstruct dentry *debugfs_reg;#endif};

仔细看了下代码,发现这个报错的地方就是根据dai(传进来的参数),找到codec,然后根据codec找到es7210结构体,目的是根据es7210->pcm_pop_work1的地址传参给schedule_delayed_work这个延迟队列,看了下pcm_pop_work1函数是处理POP音的,目前代码还在移植阶段,干脆简单粗暴把这个几个都注释掉:

4. warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement] error

995:6: warning: ISO C90 forbids mixing declarations and code


这个错误真的无力吐槽,也不知道哪个兄弟写的代码…这个要把int i放在前面。

5. implicit declaration of function ‘snd_soc_codec_get_drvdata’ [-Werror,-Wimplicit-function-declaration]

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。

6. implicit declaration of function 'snd_soc_unregister_codec

.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。

7. use of undeclared identifier ‘GPIO_HIGH’

 error: use of undeclared identifier 'GPIO_HIGH'

这个都不用看,直接把宏定义放在代码前面即可。

#define GPIO_LOW 0
#define GPIO_HIGH 1

8. no member named ‘power_enable_gpio’ in ‘struct es7210_priv’

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没有,那就加上。

9. use of undeclared identifier ‘np’

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);
}
kernel\msm-4.19\include\linux\of_gpio.h

于是给它加上文件头。

#include <linux/of_gpio.h>

10. variable has incomplete type ‘struct snd_soc_codec_driver’

snd_soc_codec_driver这个结构体没有,看看对比的codec驱动咋搞的。。

把他换成snd_soc_component_driver。

11. implicit declaration of function ‘gpio_direction_output’ [-Werror,-Wimplicit-function-declaration]

error: implicit declaration of function 'gpio_free'
[-Werror,-Wimplicit-function-declaration] ,gpio_free(es7210->power_enable_gpio);

这个报错前后看了下没啥异常的,原因是没有包含文件头,gpio.h,这个在代码开头添上即可:

#include <linux/gpio.h>

12. incompatible pointer types initializing ‘void (*)(struct snd_soc_component *)’ with an expression of type ‘int (struct snd_soc_component *)’ [-Werror,-Wincompatible-pointer-types]

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结构体,从报错来看应该是定义的结构体成员变量类型不匹配,


所以我们要调整下函数:es7210_remove

static int es7210_remove(struct snd_soc_component *component)
{return 0;
}

修改为:

static void es7210_remove(struct snd_soc_component *component)
{return ;
}

13. field designator ‘reg_word_size’ does not refer to any field in type ‘struct snd_soc_component_driver’

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 *);

14. ‘reg_cache_default’ does not refer to any field in type ‘struct snd_soc_component_driver’

.reg_cache_default = es7210_reg_defaults,


这个也是结构体的成员变量里面没有,它指向的是结构体数组的地址,所以使用unsigned long int,

unsigned long int reg_cache_default;

结果还是类型不匹配-_-,这样改了下就好了:

const struct reg_default *reg_cache_default;

15. field designator ‘reg_cache_size’ does not refer to any field in type ‘struct snd_soc_component_driver’

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]))

从这个宏定义来看,我给它一个整型,

unsigned int reg_cache_size;

16.field designator ‘component_driver’ does not refer to any field in type 'struct snd_soc_component_driver

它这个是结构体里面又嵌入了一个结构体,这个操作很简单,因为默认的结构里里面是有:controls和num_controls
的:


所以修改如下:

17.implicit declaration of function ‘of_get_named_gpio’ [-Werror,-Wimplicit-function-declaration]

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 <linux/of_gpio.h>

18. unused function ‘es7210_multi_chips_write’

 warning: unused function 'es7210_multi_chips_write' [-Wunused-function]error, forbidden warning:

代码被调用的地方,默认全部被注释了,所以直接把这个函数也注释了即可。


好家伙,我解了50-60个编译报错,终于编过去了。

[Linux Audio Driver] 移植外部CODEC常见编译报错解决(持续更新)相关推荐

  1. firefly AIO-RK3399J Linux SDK编译报错解决

    Firefly AIO-RK3399J Linux SDK编译报错解决 Zhang-Zhen 2020-09-30 22:01:04  收藏 分类专栏: RK3399工作记录 文章标签: linux  ...

  2. linux系统Nginx下载安装步骤(含报错解决方法)

    linux系统Nginx下载安装步骤(含报错解决方法) 基础步骤 安装过程可能出现的报错及解决方法 执行 ./configure --prefix=/opt/nginx 报错 执行 make inst ...

  3. Frambuffer_rd在Windows下的vivado 2020.1编译报错解决方法

    vivado2020.1 HLS生成的IP在Windows下报错 Frambuffer_rd在Windows下的vivado 2020.1编译报错解决方法 我的解决方法: 编译过程如下 之后重新对工程 ...

  4. centos7 npm bulid编译报错解决

    centos npm bulid编译报错解决: (1)npm run build报错(npm ERR! code ELIFECYCLE)的解决办法 删除以前安装的依赖,删除package锁的版本: r ...

  5. Keil MDK 工程输入中文汉字编译报错解决办法

    Keil MDK 工程输入中文汉字编译报错解决办法 官方说明:https://www.keil.com/support/man/docs/armcc/armcc_chr1359124934197.ht ...

  6. [Linux Audio Driver] Android7 外部PA Speaker代码结构

    0. 背景 平台:MSM8953 kernel version: msm-3.18. 1. enable_spk_ext_pa 代码路径:LA.UM.5.6\kernel\msm-3.18\sound ...

  7. 编译报错+解决方法:错误: 找不到符号

    [0]README 1)本文主要解决"错误,找不到符号" [1] console error info 1)error :  E:\bench-cluster\mybatis_in ...

  8. 使用ButterKnife时的编译报错解决

    错误一:gradle编译报错,版本不合适: 在Android studio中使用butterKnife时,出现了编译报错,根据错误提示,是缺少了gradle-3.3-all的安装包,我们从网上下载下来 ...

  9. linux安装nginx详细步骤和make编译报错问题(保姆级)

    目录 1.安装依赖包 2.下载并解压安装包 3.安装nginx 3-1.源码编辑时常见错误解决方法 4.启动nginx服务 4-1.配置nginx.conf 5.重启nginx 6.若想使用外部主机访 ...

最新文章

  1. 关于学习Python的一点学习总结(42->继承list)
  2. 我!90后!重庆女孩!在淘宝给别人改简历,年入百万!
  3. chrono 使用备注
  4. 学数答题160909-取整函数
  5. AD9910高速集成DDS芯片(verilog篇-串行模式篇-22个寄存器SPI通信周期控制)
  6. Java中synchronized和Lock的区别
  7. boost::owner_hash相关的测试程序
  8. XHTML、HTML4,HTML5 之间的区别
  9. 【codevs1116】四色问题,深搜入门题目
  10. 转 TCP中的序号和确认号
  11. php学习第一讲----php是什么?
  12. 【C语言】游戏管理系统简单设计
  13. 控制直流电机正反转以及刹车电路设计
  14. 用线性探测法处理冲突时的散列表_案例
  15. Win10 安装 SQL Server 2008 与使用指南
  16. vue+typescript(vben-admin)前端开发
  17. 望夫山[阳江民俗文化]
  18. 手机 App 的技术栈
  19. ST-LINK/V2 + STM8 + STVP 下载程序+Error on Option Bytes
  20. java毕业生设计药房药品采购集中管理系统计算机源码+系统+mysql+调试部署+lw

热门文章

  1. delphi删除文本内容_文本编辑器EmEditor快捷键指令
  2. java 能实现csgo吗
  3. ios textfield 拼音输入 完成才录入
  4. 高德地图广告投放的优势、效果!
  5. CCF BDCI大赛急速报名,OneFlow四大训练赛题等你来战
  6. 第四单元:丰富的网页媒体
  7. HTML如何使用隐藏图片,css3如何隐藏图片?
  8. Angular2 模型渲染的一个坑
  9. C++ 模版类和模板函数介绍及使用
  10. 致大学计算机老师的一封信,致大学老师的一封信