~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/rt715-sdca-sdw.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/codecs/rt715-sdca-sdw.c (Version linux-6.12-rc7) and /sound/soc/codecs/rt715-sdca-sdw.c (Version linux-5.17.15)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 //                                                  2 //
  3 // rt715-sdca-sdw.c -- rt715 ALSA SoC audio dr      3 // rt715-sdca-sdw.c -- rt715 ALSA SoC audio driver
  4 //                                                  4 //
  5 // Copyright(c) 2020 Realtek Semiconductor Cor      5 // Copyright(c) 2020 Realtek Semiconductor Corp.
  6 //                                                  6 //
  7 //                                                  7 //
  8                                                     8 
  9 #include <linux/delay.h>                            9 #include <linux/delay.h>
 10 #include <linux/device.h>                          10 #include <linux/device.h>
 11 #include <linux/mod_devicetable.h>                 11 #include <linux/mod_devicetable.h>
 12 #include <linux/soundwire/sdw.h>                   12 #include <linux/soundwire/sdw.h>
 13 #include <linux/soundwire/sdw_type.h>              13 #include <linux/soundwire/sdw_type.h>
 14 #include <linux/soundwire/sdw_registers.h>         14 #include <linux/soundwire/sdw_registers.h>
 15 #include <linux/module.h>                          15 #include <linux/module.h>
 16 #include <linux/pm_runtime.h>                  << 
 17 #include <linux/regmap.h>                          16 #include <linux/regmap.h>
 18 #include <sound/soc.h>                             17 #include <sound/soc.h>
 19 #include "rt715-sdca.h"                            18 #include "rt715-sdca.h"
 20 #include "rt715-sdca-sdw.h"                        19 #include "rt715-sdca-sdw.h"
 21                                                    20 
 22 static bool rt715_sdca_readable_register(struc     21 static bool rt715_sdca_readable_register(struct device *dev, unsigned int reg)
 23 {                                                  22 {
 24         switch (reg) {                             23         switch (reg) {
 25         case 0x201a ... 0x2027:                    24         case 0x201a ... 0x2027:
 26         case 0x2029 ... 0x202a:                    25         case 0x2029 ... 0x202a:
 27         case 0x202d ... 0x2034:                    26         case 0x202d ... 0x2034:
 28         case 0x2200 ... 0x2204:                    27         case 0x2200 ... 0x2204:
 29         case 0x2206 ... 0x2212:                    28         case 0x2206 ... 0x2212:
 30         case 0x2230 ... 0x2239:                    29         case 0x2230 ... 0x2239:
 31         case 0x2f5b:                               30         case 0x2f5b:
 32         case SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715     31         case SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN,
 33                 RT715_SDCA_SMPU_TRIG_ST_CTRL,      32                 RT715_SDCA_SMPU_TRIG_ST_CTRL, CH_00):
 34                 return true;                       33                 return true;
 35         default:                                   34         default:
 36                 return false;                      35                 return false;
 37         }                                          36         }
 38 }                                                  37 }
 39                                                    38 
 40 static bool rt715_sdca_volatile_register(struc     39 static bool rt715_sdca_volatile_register(struct device *dev, unsigned int reg)
 41 {                                                  40 {
 42         switch (reg) {                             41         switch (reg) {
 43         case 0x201b:                               42         case 0x201b:
 44         case 0x201c:                               43         case 0x201c:
 45         case 0x201d:                               44         case 0x201d:
 46         case 0x201f:                               45         case 0x201f:
 47         case 0x2021:                               46         case 0x2021:
 48         case 0x2023:                               47         case 0x2023:
 49         case 0x2230:                               48         case 0x2230:
 50         case 0x202d ... 0x202f: /* BRA */          49         case 0x202d ... 0x202f: /* BRA */
 51         case 0x2200 ... 0x2212: /* i2c debug *     50         case 0x2200 ... 0x2212: /* i2c debug */
 52         case 0x2f07:                               51         case 0x2f07:
 53         case 0x2f1b ... 0x2f1e:                    52         case 0x2f1b ... 0x2f1e:
 54         case 0x2f30 ... 0x2f34:                    53         case 0x2f30 ... 0x2f34:
 55         case 0x2f50 ... 0x2f51:                    54         case 0x2f50 ... 0x2f51:
 56         case 0x2f53 ... 0x2f59:                    55         case 0x2f53 ... 0x2f59:
 57         case 0x2f5c ... 0x2f5f:                    56         case 0x2f5c ... 0x2f5f:
 58         case SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715     57         case SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN,
 59                 RT715_SDCA_SMPU_TRIG_ST_CTRL,      58                 RT715_SDCA_SMPU_TRIG_ST_CTRL, CH_00): /* VAD Searching status */
 60                 return true;                       59                 return true;
 61         default:                                   60         default:
 62                 return false;                      61                 return false;
 63         }                                          62         }
 64 }                                                  63 }
 65                                                    64 
 66 static bool rt715_sdca_mbq_readable_register(s     65 static bool rt715_sdca_mbq_readable_register(struct device *dev, unsigned int reg)
 67 {                                                  66 {
 68         switch (reg) {                             67         switch (reg) {
 69         case 0x2000000:                            68         case 0x2000000:
 70         case 0x200002b:                            69         case 0x200002b:
 71         case 0x2000036:                            70         case 0x2000036:
 72         case 0x2000037:                            71         case 0x2000037:
 73         case 0x2000039:                            72         case 0x2000039:
 74         case 0x2000044:                            73         case 0x2000044:
 75         case 0x6100000:                            74         case 0x6100000:
 76                 return true;                       75                 return true;
 77         default:                                   76         default:
 78                 return false;                      77                 return false;
 79         }                                          78         }
 80 }                                                  79 }
 81                                                    80 
 82 static bool rt715_sdca_mbq_volatile_register(s     81 static bool rt715_sdca_mbq_volatile_register(struct device *dev, unsigned int reg)
 83 {                                                  82 {
 84         switch (reg) {                             83         switch (reg) {
 85         case 0x2000000:                            84         case 0x2000000:
 86                 return true;                       85                 return true;
 87         default:                                   86         default:
 88                 return false;                      87                 return false;
 89         }                                          88         }
 90 }                                                  89 }
 91                                                    90 
 92 static const struct regmap_config rt715_sdca_r     91 static const struct regmap_config rt715_sdca_regmap = {
 93         .reg_bits = 32,                            92         .reg_bits = 32,
 94         .val_bits = 8,                             93         .val_bits = 8,
 95         .readable_reg = rt715_sdca_readable_re     94         .readable_reg = rt715_sdca_readable_register,
 96         .volatile_reg = rt715_sdca_volatile_re     95         .volatile_reg = rt715_sdca_volatile_register,
 97         .max_register = 0x43ffffff,                96         .max_register = 0x43ffffff,
 98         .reg_defaults = rt715_reg_defaults_sdc     97         .reg_defaults = rt715_reg_defaults_sdca,
 99         .num_reg_defaults = ARRAY_SIZE(rt715_r     98         .num_reg_defaults = ARRAY_SIZE(rt715_reg_defaults_sdca),
100         .cache_type = REGCACHE_MAPLE,          !!  99         .cache_type = REGCACHE_RBTREE,
101         .use_single_read = true,                  100         .use_single_read = true,
102         .use_single_write = true,                 101         .use_single_write = true,
103 };                                                102 };
104                                                   103 
105 static const struct regmap_config rt715_sdca_m    104 static const struct regmap_config rt715_sdca_mbq_regmap = {
106         .name = "sdw-mbq",                        105         .name = "sdw-mbq",
107         .reg_bits = 32,                           106         .reg_bits = 32,
108         .val_bits = 16,                           107         .val_bits = 16,
109         .readable_reg = rt715_sdca_mbq_readabl    108         .readable_reg = rt715_sdca_mbq_readable_register,
110         .volatile_reg = rt715_sdca_mbq_volatil    109         .volatile_reg = rt715_sdca_mbq_volatile_register,
111         .max_register = 0x43ffffff,               110         .max_register = 0x43ffffff,
112         .reg_defaults = rt715_mbq_reg_defaults    111         .reg_defaults = rt715_mbq_reg_defaults_sdca,
113         .num_reg_defaults = ARRAY_SIZE(rt715_m    112         .num_reg_defaults = ARRAY_SIZE(rt715_mbq_reg_defaults_sdca),
114         .cache_type = REGCACHE_MAPLE,          !! 113         .cache_type = REGCACHE_RBTREE,
115         .use_single_read = true,                  114         .use_single_read = true,
116         .use_single_write = true,                 115         .use_single_write = true,
117 };                                                116 };
118                                                   117 
119 static int rt715_sdca_update_status(struct sdw    118 static int rt715_sdca_update_status(struct sdw_slave *slave,
120                                 enum sdw_slave    119                                 enum sdw_slave_status status)
121 {                                                 120 {
122         struct rt715_sdca_priv *rt715 = dev_ge    121         struct rt715_sdca_priv *rt715 = dev_get_drvdata(&slave->dev);
123                                                   122 
                                                   >> 123         /* Update the status */
                                                   >> 124         rt715->status = status;
                                                   >> 125 
124         /*                                        126         /*
125          * Perform initialization only if slav    127          * Perform initialization only if slave status is present and
126          * hw_init flag is false                  128          * hw_init flag is false
127          */                                       129          */
128         if (rt715->hw_init || status != SDW_SL !! 130         if (rt715->hw_init || rt715->status != SDW_SLAVE_ATTACHED)
129                 return 0;                         131                 return 0;
130                                                   132 
131         /* perform I/O transfers required for     133         /* perform I/O transfers required for Slave initialization */
132         return rt715_sdca_io_init(&slave->dev,    134         return rt715_sdca_io_init(&slave->dev, slave);
133 }                                                 135 }
134                                                   136 
135 static int rt715_sdca_read_prop(struct sdw_sla    137 static int rt715_sdca_read_prop(struct sdw_slave *slave)
136 {                                                 138 {
137         struct sdw_slave_prop *prop = &slave->    139         struct sdw_slave_prop *prop = &slave->prop;
138         int nval, i;                              140         int nval, i;
139         u32 bit;                                  141         u32 bit;
140         unsigned long addr;                       142         unsigned long addr;
141         struct sdw_dpn_prop *dpn;                 143         struct sdw_dpn_prop *dpn;
142                                                   144 
143         prop->paging_support = true;              145         prop->paging_support = true;
144                                                   146 
145         /* first we need to allocate memory fo    147         /* first we need to allocate memory for set bits in port lists */
146         prop->source_ports = 0x50;/* BITMAP: 0    148         prop->source_ports = 0x50;/* BITMAP: 01010000 */
147         prop->sink_ports = 0x0; /* BITMAP:  00    149         prop->sink_ports = 0x0; /* BITMAP:  00000000 */
148                                                   150 
149         nval = hweight32(prop->source_ports);     151         nval = hweight32(prop->source_ports);
150         prop->src_dpn_prop = devm_kcalloc(&sla    152         prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
151                                         sizeof    153                                         sizeof(*prop->src_dpn_prop),
152                                         GFP_KE    154                                         GFP_KERNEL);
153         if (!prop->src_dpn_prop)                  155         if (!prop->src_dpn_prop)
154                 return -ENOMEM;                   156                 return -ENOMEM;
155                                                   157 
156         dpn = prop->src_dpn_prop;                 158         dpn = prop->src_dpn_prop;
157         i = 0;                                    159         i = 0;
158         addr = prop->source_ports;                160         addr = prop->source_ports;
159         for_each_set_bit(bit, &addr, 32) {        161         for_each_set_bit(bit, &addr, 32) {
160                 dpn[i].num = bit;                 162                 dpn[i].num = bit;
161                 dpn[i].simple_ch_prep_sm = tru    163                 dpn[i].simple_ch_prep_sm = true;
162                 dpn[i].ch_prep_timeout = 10;      164                 dpn[i].ch_prep_timeout = 10;
163                 i++;                              165                 i++;
164         }                                         166         }
165                                                   167 
166         /* set the timeout values */              168         /* set the timeout values */
167         prop->clk_stop_timeout = 200;          !! 169         prop->clk_stop_timeout = 20;
168                                                   170 
169         return 0;                                 171         return 0;
170 }                                                 172 }
171                                                   173 
172 static const struct sdw_slave_ops rt715_sdca_s !! 174 static struct sdw_slave_ops rt715_sdca_slave_ops = {
173         .read_prop = rt715_sdca_read_prop,        175         .read_prop = rt715_sdca_read_prop,
174         .update_status = rt715_sdca_update_sta    176         .update_status = rt715_sdca_update_status,
175 };                                                177 };
176                                                   178 
177 static int rt715_sdca_sdw_probe(struct sdw_sla    179 static int rt715_sdca_sdw_probe(struct sdw_slave *slave,
178                            const struct sdw_de    180                            const struct sdw_device_id *id)
179 {                                                 181 {
180         struct regmap *mbq_regmap, *regmap;       182         struct regmap *mbq_regmap, *regmap;
181                                                   183 
                                                   >> 184         slave->ops = &rt715_sdca_slave_ops;
                                                   >> 185 
182         /* Regmap Initialization */               186         /* Regmap Initialization */
183         mbq_regmap = devm_regmap_init_sdw_mbq(    187         mbq_regmap = devm_regmap_init_sdw_mbq(slave, &rt715_sdca_mbq_regmap);
184         if (IS_ERR(mbq_regmap))                   188         if (IS_ERR(mbq_regmap))
185                 return PTR_ERR(mbq_regmap);       189                 return PTR_ERR(mbq_regmap);
186                                                   190 
187         regmap = devm_regmap_init_sdw(slave, &    191         regmap = devm_regmap_init_sdw(slave, &rt715_sdca_regmap);
188         if (IS_ERR(regmap))                       192         if (IS_ERR(regmap))
189                 return PTR_ERR(regmap);           193                 return PTR_ERR(regmap);
190                                                   194 
191         return rt715_sdca_init(&slave->dev, mb    195         return rt715_sdca_init(&slave->dev, mbq_regmap, regmap, slave);
192 }                                                 196 }
193                                                   197 
194 static int rt715_sdca_sdw_remove(struct sdw_sl << 
195 {                                              << 
196         pm_runtime_disable(&slave->dev);       << 
197                                                << 
198         return 0;                              << 
199 }                                              << 
200                                                << 
201 static const struct sdw_device_id rt715_sdca_i    198 static const struct sdw_device_id rt715_sdca_id[] = {
202         SDW_SLAVE_ENTRY_EXT(0x025d, 0x715, 0x3    199         SDW_SLAVE_ENTRY_EXT(0x025d, 0x715, 0x3, 0x1, 0),
203         SDW_SLAVE_ENTRY_EXT(0x025d, 0x714, 0x3    200         SDW_SLAVE_ENTRY_EXT(0x025d, 0x714, 0x3, 0x1, 0),
204         {},                                       201         {},
205 };                                                202 };
206 MODULE_DEVICE_TABLE(sdw, rt715_sdca_id);          203 MODULE_DEVICE_TABLE(sdw, rt715_sdca_id);
207                                                   204 
208 static int __maybe_unused rt715_dev_suspend(st    205 static int __maybe_unused rt715_dev_suspend(struct device *dev)
209 {                                                 206 {
210         struct rt715_sdca_priv *rt715 = dev_ge    207         struct rt715_sdca_priv *rt715 = dev_get_drvdata(dev);
211                                                   208 
212         if (!rt715->hw_init)                      209         if (!rt715->hw_init)
213                 return 0;                         210                 return 0;
214                                                   211 
215         regcache_cache_only(rt715->regmap, tru    212         regcache_cache_only(rt715->regmap, true);
216         regcache_mark_dirty(rt715->regmap);       213         regcache_mark_dirty(rt715->regmap);
217         regcache_cache_only(rt715->mbq_regmap,    214         regcache_cache_only(rt715->mbq_regmap, true);
218         regcache_mark_dirty(rt715->mbq_regmap)    215         regcache_mark_dirty(rt715->mbq_regmap);
219                                                   216 
220         return 0;                                 217         return 0;
221 }                                                 218 }
222                                                   219 
223 #define RT715_PROBE_TIMEOUT 5000                  220 #define RT715_PROBE_TIMEOUT 5000
224                                                   221 
225 static int __maybe_unused rt715_dev_resume(str    222 static int __maybe_unused rt715_dev_resume(struct device *dev)
226 {                                                 223 {
227         struct sdw_slave *slave = dev_to_sdw_d    224         struct sdw_slave *slave = dev_to_sdw_dev(dev);
228         struct rt715_sdca_priv *rt715 = dev_ge    225         struct rt715_sdca_priv *rt715 = dev_get_drvdata(dev);
229         unsigned long time;                       226         unsigned long time;
230                                                   227 
231         if (!rt715->first_hw_init)                228         if (!rt715->first_hw_init)
232                 return 0;                         229                 return 0;
233                                                   230 
234         if (!slave->unattach_request)             231         if (!slave->unattach_request)
235                 goto regmap_sync;                 232                 goto regmap_sync;
236                                                   233 
237         time = wait_for_completion_timeout(&sl !! 234         time = wait_for_completion_timeout(&slave->enumeration_complete,
238                                            mse    235                                            msecs_to_jiffies(RT715_PROBE_TIMEOUT));
239         if (!time) {                              236         if (!time) {
240                 dev_err(&slave->dev, "%s: Init !! 237                 dev_err(&slave->dev, "Enumeration not complete, timed out\n");
241                 sdw_show_ping_status(slave->bu << 
242                                                << 
243                 return -ETIMEDOUT;                238                 return -ETIMEDOUT;
244         }                                         239         }
245                                                   240 
246 regmap_sync:                                      241 regmap_sync:
247         slave->unattach_request = 0;              242         slave->unattach_request = 0;
248         regcache_cache_only(rt715->regmap, fal    243         regcache_cache_only(rt715->regmap, false);
249         regcache_sync_region(rt715->regmap,       244         regcache_sync_region(rt715->regmap,
250                 SDW_SDCA_CTL(FUN_JACK_CODEC, R    245                 SDW_SDCA_CTL(FUN_JACK_CODEC, RT715_SDCA_ST_EN, RT715_SDCA_ST_CTRL,
251                         CH_00),                   246                         CH_00),
252                 SDW_SDCA_CTL(FUN_MIC_ARRAY, RT    247                 SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN,
253                         RT715_SDCA_SMPU_TRIG_S    248                         RT715_SDCA_SMPU_TRIG_ST_CTRL, CH_00));
254         regcache_cache_only(rt715->mbq_regmap,    249         regcache_cache_only(rt715->mbq_regmap, false);
255         regcache_sync_region(rt715->mbq_regmap    250         regcache_sync_region(rt715->mbq_regmap, 0x2000000, 0x61020ff);
256         regcache_sync_region(rt715->mbq_regmap    251         regcache_sync_region(rt715->mbq_regmap,
257                 SDW_SDCA_CTL(FUN_JACK_CODEC, R    252                 SDW_SDCA_CTL(FUN_JACK_CODEC, RT715_SDCA_ST_EN, RT715_SDCA_ST_CTRL,
258                         CH_00),                   253                         CH_00),
259                 SDW_SDCA_CTL(FUN_MIC_ARRAY, RT    254                 SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN,
260                         RT715_SDCA_SMPU_TRIG_S    255                         RT715_SDCA_SMPU_TRIG_ST_CTRL, CH_00));
261                                                   256 
262         return 0;                                 257         return 0;
263 }                                                 258 }
264                                                   259 
265 static const struct dev_pm_ops rt715_pm = {       260 static const struct dev_pm_ops rt715_pm = {
266         SET_SYSTEM_SLEEP_PM_OPS(rt715_dev_susp    261         SET_SYSTEM_SLEEP_PM_OPS(rt715_dev_suspend, rt715_dev_resume)
267         SET_RUNTIME_PM_OPS(rt715_dev_suspend,     262         SET_RUNTIME_PM_OPS(rt715_dev_suspend, rt715_dev_resume, NULL)
268 };                                                263 };
269                                                   264 
270 static struct sdw_driver rt715_sdw_driver = {     265 static struct sdw_driver rt715_sdw_driver = {
271         .driver = {                               266         .driver = {
272                 .name = "rt715-sdca",             267                 .name = "rt715-sdca",
                                                   >> 268                 .owner = THIS_MODULE,
273                 .pm = &rt715_pm,                  269                 .pm = &rt715_pm,
274         },                                        270         },
275         .probe = rt715_sdca_sdw_probe,            271         .probe = rt715_sdca_sdw_probe,
276         .remove = rt715_sdca_sdw_remove,       << 
277         .ops = &rt715_sdca_slave_ops,             272         .ops = &rt715_sdca_slave_ops,
278         .id_table = rt715_sdca_id,                273         .id_table = rt715_sdca_id,
279 };                                                274 };
280 module_sdw_driver(rt715_sdw_driver);              275 module_sdw_driver(rt715_sdw_driver);
281                                                   276 
282 MODULE_DESCRIPTION("ASoC RT715 driver SDW SDCA    277 MODULE_DESCRIPTION("ASoC RT715 driver SDW SDCA");
283 MODULE_AUTHOR("Jack Yu <jack.yu@realtek.com>")    278 MODULE_AUTHOR("Jack Yu <jack.yu@realtek.com>");
284 MODULE_LICENSE("GPL v2");                         279 MODULE_LICENSE("GPL v2");
285                                                   280 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php