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