blob: 0708def9a351ff0341d17b705d23e12038614623 [file] [log] [blame]
developere0cea0f2021-12-16 16:08:26 +08001// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/module.h>
4#include <linux/kernel.h>
5#include <linux/init.h>
6#include <linux/err.h>
7#include <linux/spi/spi.h>
8
9/* alsa sound header */
10#include <sound/soc.h>
11#include <sound/pcm_params.h>
12
13#include "si3218x/si3218x.h"
14
15enum si3218x_spi_type {
16 MTK_EXT_PROSLIC = 0,
17 MTK_EXT_TYPE_NUM
18};
19
20struct mtk_ext_spi_ctrl {
21 int (*spi_probe)(struct spi_device *spi, struct spi_driver *spi_drv);
22 int (*spi_remove)(struct spi_device *spi);
23 const char *stream_name;
24 const char *codec_dai_name;
25 const char *codec_name;
26};
27
28static struct mtk_ext_spi_ctrl mtk_ext_list[MTK_EXT_TYPE_NUM] = {
29 [MTK_EXT_PROSLIC] = {
30 .spi_probe = si3218x_spi_probe,
31 .spi_remove = si3218x_spi_remove,
32 },
33};
34
35static unsigned int mtk_ext_type;
36
37static int mtk_ext_spi_probe(struct spi_device *spi);
38static int mtk_ext_spi_remove(struct spi_device *spi)
39{
40 dev_info(&spi->dev, "%s()\n", __func__);
41
42 if (mtk_ext_list[mtk_ext_type].spi_remove)
43 mtk_ext_list[mtk_ext_type].spi_remove(spi);
44
45 return 0;
46}
47
48static const struct of_device_id mtk_ext_match_table[] = {
49 {.compatible = "silabs,proslic_spi",},
50 {},
51};
52MODULE_DEVICE_TABLE(of, mtk_ext_match_table);
53
54static struct spi_driver mtk_ext_spi_driver = {
55 .driver = {
56 .name = "proslic_spi",
57 .owner = THIS_MODULE,
58 .of_match_table = of_match_ptr(mtk_ext_match_table),
59 },
60 .probe = mtk_ext_spi_probe,
61 .remove = mtk_ext_spi_remove,
62};
63
64module_spi_driver(mtk_ext_spi_driver);
65
66static int mtk_ext_spi_probe(struct spi_device *spi)
67{
68 int i, ret = 0;
69
70 dev_err(&spi->dev, "%s()\n", __func__);
71
72 mtk_ext_type = MTK_EXT_PROSLIC;
73 for (i = 0; i < MTK_EXT_TYPE_NUM; i++) {
74 if (!mtk_ext_list[i].spi_probe)
75 continue;
76
77 ret = mtk_ext_list[i].spi_probe(spi, &mtk_ext_spi_driver);
78 if (ret)
79 continue;
80
81 mtk_ext_type = i;
82 break;
83 }
84
85 return ret;
86}