src.c (d1208404dd477c142680437137c9996b95bfd508) | src.c (5ba17b42e1755c3c5cfe96370cfd47f34d01f62c) |
---|---|
1/* 2 * Renesas R-Car SRC support 3 * 4 * Copyright (C) 2013 Renesas Solutions Corp. 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 6 unchanged lines hidden (view full) --- 15/* SRCx_STATUS */ 16#define OUF_SRCO ((1 << 12) | (1 << 13)) 17#define OUF_SRCI ((1 << 9) | (1 << 8)) 18 19/* SCU_SYSTEM_STATUS0/1 */ 20#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) 21 22struct rsnd_src { | 1/* 2 * Renesas R-Car SRC support 3 * 4 * Copyright (C) 2013 Renesas Solutions Corp. 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as --- 6 unchanged lines hidden (view full) --- 15/* SRCx_STATUS */ 16#define OUF_SRCO ((1 << 12) | (1 << 13)) 17#define OUF_SRCI ((1 << 9) | (1 << 8)) 18 19/* SCU_SYSTEM_STATUS0/1 */ 20#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) 21 22struct rsnd_src { |
23 struct rsnd_src_platform_info *info; /* rcar_snd.h */ | |
24 struct rsnd_mod mod; | 23 struct rsnd_mod mod; |
24 struct rsnd_mod *dma; |
|
25 struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ 26 struct rsnd_kctrl_cfg_s sync; /* sync convert */ 27 u32 convert_rate; /* sampling rate convert */ 28 int err; | 25 struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ 26 struct rsnd_kctrl_cfg_s sync; /* sync convert */ 27 u32 convert_rate; /* sampling rate convert */ 28 int err; |
29 int irq; |
|
29}; 30 31#define RSND_SRC_NAME_SIZE 16 32 | 30}; 31 32#define RSND_SRC_NAME_SIZE 16 33 |
34#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id) 35#define rsnd_src_to_dma(src) ((src)->dma) |
|
33#define rsnd_src_nr(priv) ((priv)->src_nr) 34#define rsnd_enable_sync_convert(src) ((src)->sen.val) | 36#define rsnd_src_nr(priv) ((priv)->src_nr) 37#define rsnd_enable_sync_convert(src) ((src)->sen.val) |
35#define rsnd_src_of_node(priv) \ 36 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") | |
37 38#define rsnd_mod_to_src(_mod) \ 39 container_of((_mod), struct rsnd_src, mod) 40 41#define for_each_rsnd_src(pos, priv, i) \ 42 for ((i) = 0; \ 43 ((i) < rsnd_src_nr(priv)) && \ 44 ((pos) = (struct rsnd_src *)(priv)->src + i); \ --- 19 unchanged lines hidden (view full) --- 64 * |--------| 65 * 66 * Gen2 67 * 68 * [mem] -> [SRC] -> [SSIU] -> [SSI] 69 * |-----------------| 70 */ 71 | 38 39#define rsnd_mod_to_src(_mod) \ 40 container_of((_mod), struct rsnd_src, mod) 41 42#define for_each_rsnd_src(pos, priv, i) \ 43 for ((i) = 0; \ 44 ((i) < rsnd_src_nr(priv)) && \ 45 ((pos) = (struct rsnd_src *)(priv)->src + i); \ --- 19 unchanged lines hidden (view full) --- 65 * |--------| 66 * 67 * Gen2 68 * 69 * [mem] -> [SRC] -> [SSIU] -> [SSI] 70 * |-----------------| 71 */ 72 |
72/* 73 * How to use SRC bypass mode for debugging 74 * 75 * SRC has bypass mode, and it is useful for debugging. 76 * In Gen2 case, 77 * SRCm_MODE controls whether SRC is used or not 78 * SSI_MODE0 controls whether SSIU which receives SRC data 79 * is used or not. 80 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, 81 * but SRC bypass mode needs SSI_MODE0 only. 82 * 83 * This driver request 84 * struct rsnd_src_platform_info { 85 * u32 convert_rate; 86 * int dma_id; 87 * } 88 * 89 * rsnd_src_convert_rate() indicates 90 * above convert_rate, and it controls 91 * whether SRC is used or not. 92 * 93 * ex) doesn't use SRC 94 * static struct rsnd_dai_platform_info rsnd_dai = { 95 * .playback = { .ssi = &rsnd_ssi[0], }, 96 * }; 97 * 98 * ex) uses SRC 99 * static struct rsnd_src_platform_info rsnd_src[] = { 100 * RSND_SCU(48000, 0), 101 * ... 102 * }; 103 * static struct rsnd_dai_platform_info rsnd_dai = { 104 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, 105 * }; 106 * 107 * ex) uses SRC bypass mode 108 * static struct rsnd_src_platform_info rsnd_src[] = { 109 * RSND_SCU(0, 0), 110 * ... 111 * }; 112 * static struct rsnd_dai_platform_info rsnd_dai = { 113 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, 114 * }; 115 * 116 */ 117 118/* 119 * Gen1/Gen2 common functions 120 */ 121static void rsnd_src_soft_reset(struct rsnd_mod *mod) | 73static void rsnd_src_activation(struct rsnd_mod *mod) |
122{ 123 rsnd_mod_write(mod, SRC_SWRSR, 0); 124 rsnd_mod_write(mod, SRC_SWRSR, 1); 125} 126 | 74{ 75 rsnd_mod_write(mod, SRC_SWRSR, 0); 76 rsnd_mod_write(mod, SRC_SWRSR, 1); 77} 78 |
127 128#define rsnd_src_initialize_lock(mod) __rsnd_src_initialize_lock(mod, 1) 129#define rsnd_src_initialize_unlock(mod) __rsnd_src_initialize_lock(mod, 0) 130static void __rsnd_src_initialize_lock(struct rsnd_mod *mod, u32 enable) | 79static void rsnd_src_halt(struct rsnd_mod *mod) |
131{ | 80{ |
132 rsnd_mod_write(mod, SRC_SRCIR, enable); | 81 rsnd_mod_write(mod, SRC_SRCIR, 1); 82 rsnd_mod_write(mod, SRC_SWRSR, 0); |
133} 134 135static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, 136 struct rsnd_mod *mod) 137{ 138 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 139 int is_play = rsnd_io_is_play(io); 140 141 return rsnd_dma_request_channel(rsnd_src_of_node(priv), 142 mod, 143 is_play ? "rx" : "tx"); 144} 145 | 83} 84 85static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, 86 struct rsnd_mod *mod) 87{ 88 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 89 int is_play = rsnd_io_is_play(io); 90 91 return rsnd_dma_request_channel(rsnd_src_of_node(priv), 92 mod, 93 is_play ? "rx" : "tx"); 94} 95 |
146int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, 147 struct rsnd_dai_stream *io, 148 int use_busif) 149{ 150 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 151 int ssi_id = rsnd_mod_id(ssi_mod); 152 153 /* 154 * SSI_MODE0 155 */ 156 rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id), 157 !use_busif << ssi_id); 158 159 /* 160 * SSI_MODE1 161 */ 162 if (rsnd_ssi_is_pin_sharing(io)) { 163 int shift = -1; 164 switch (ssi_id) { 165 case 1: 166 shift = 0; 167 break; 168 case 2: 169 shift = 2; 170 break; 171 case 4: 172 shift = 16; 173 break; 174 } 175 176 if (shift >= 0) 177 rsnd_mod_bset(ssi_mod, SSI_MODE1, 178 0x3 << shift, 179 rsnd_rdai_is_clk_master(rdai) ? 180 0x2 << shift : 0x1 << shift); 181 } 182 183 /* 184 * DMA settings for SSIU 185 */ 186 if (use_busif) { 187 u32 val = rsnd_get_dalign(ssi_mod, io); 188 189 rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR, 190 rsnd_get_adinr_bit(ssi_mod, io)); 191 rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1); 192 rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1); 193 194 rsnd_mod_write(ssi_mod, SSI_BUSIF_DALIGN, val); 195 } 196 197 return 0; 198} 199 200int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, 201 struct rsnd_dai_stream *io) 202{ 203 /* 204 * DMA settings for SSIU 205 */ 206 rsnd_mod_write(ssi_mod, SSI_CTRL, 0); 207 208 return 0; 209} 210 211int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod) 212{ 213 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 214 215 if (rsnd_is_gen1(priv)) 216 return 0; 217 218 /* enable SSI interrupt if Gen2 */ 219 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 220 rsnd_ssi_is_dma_mode(ssi_mod) ? 221 0x0e000000 : 0x0f000000); 222 223 return 0; 224} 225 226int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod) 227{ 228 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 229 230 if (rsnd_is_gen1(priv)) 231 return 0; 232 233 /* disable SSI interrupt if Gen2 */ 234 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000); 235 236 return 0; 237} 238 | |
239static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, 240 struct rsnd_src *src) 241{ 242 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 243 u32 convert_rate; 244 245 if (!runtime) 246 return 0; --- 31 unchanged lines hidden (view full) --- 278 } 279 280 if (!rate) 281 rate = runtime->rate; 282 283 return rate; 284} 285 | 96static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, 97 struct rsnd_src *src) 98{ 99 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 100 u32 convert_rate; 101 102 if (!runtime) 103 return 0; --- 31 unchanged lines hidden (view full) --- 135 } 136 137 if (!rate) 138 rate = runtime->rate; 139 140 return rate; 141} 142 |
286static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, 287 struct rsnd_dai_stream *io) 288{ 289 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 290 struct rsnd_src *src = rsnd_mod_to_src(mod); 291 u32 convert_rate = rsnd_src_convert_rate(io, src); 292 u32 fsrate = 0; 293 294 if (convert_rate) 295 fsrate = 0x0400000 / convert_rate * runtime->rate; 296 297 /* Set channel number and output bit length */ 298 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr_bit(mod, io)); 299 300 /* Enable the initial value of IFS */ 301 if (fsrate) { 302 rsnd_mod_write(mod, SRC_IFSCR, 1); 303 304 /* Set initial value of IFS */ 305 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 306 } 307 308 /* use DMA transfer */ 309 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); 310 311 return 0; 312} 313 | |
314static int rsnd_src_hw_params(struct rsnd_mod *mod, 315 struct rsnd_dai_stream *io, 316 struct snd_pcm_substream *substream, 317 struct snd_pcm_hw_params *fe_params) 318{ 319 struct rsnd_src *src = rsnd_mod_to_src(mod); 320 struct snd_soc_pcm_runtime *fe = substream->private_data; 321 | 143static int rsnd_src_hw_params(struct rsnd_mod *mod, 144 struct rsnd_dai_stream *io, 145 struct snd_pcm_substream *substream, 146 struct snd_pcm_hw_params *fe_params) 147{ 148 struct rsnd_src *src = rsnd_mod_to_src(mod); 149 struct snd_soc_pcm_runtime *fe = substream->private_data; 150 |
322 /* default value (mainly for non-DT) */ 323 src->convert_rate = src->info->convert_rate; 324 | |
325 /* 326 * SRC assumes that it is used under DPCM if user want to use 327 * sampling rate convert. Then, SRC should be FE. 328 * And then, this function will be called *after* BE settings. 329 * this means, each BE already has fixuped hw_params. 330 * see 331 * dpcm_fe_dai_hw_params() 332 * dpcm_be_dai_hw_params() --- 9 unchanged lines hidden (view full) --- 342 if (params_rate(fe_params) != params_rate(be_params)) 343 src->convert_rate = params_rate(be_params); 344 } 345 } 346 347 return 0; 348} 349 | 151 /* 152 * SRC assumes that it is used under DPCM if user want to use 153 * sampling rate convert. Then, SRC should be FE. 154 * And then, this function will be called *after* BE settings. 155 * this means, each BE already has fixuped hw_params. 156 * see 157 * dpcm_fe_dai_hw_params() 158 * dpcm_be_dai_hw_params() --- 9 unchanged lines hidden (view full) --- 168 if (params_rate(fe_params) != params_rate(be_params)) 169 src->convert_rate = params_rate(be_params); 170 } 171 } 172 173 return 0; 174} 175 |
350static int rsnd_src_init(struct rsnd_mod *mod, 351 struct rsnd_priv *priv) | 176static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io, 177 struct rsnd_mod *mod) |
352{ | 178{ |
179 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 180 struct device *dev = rsnd_priv_to_dev(priv); 181 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
|
353 struct rsnd_src *src = rsnd_mod_to_src(mod); | 182 struct rsnd_src *src = rsnd_mod_to_src(mod); |
183 u32 convert_rate = rsnd_src_convert_rate(io, src); 184 u32 ifscr, fsrate, adinr; 185 u32 cr, route; 186 u32 bsdsr, bsisr; 187 uint ratio; |
|
354 | 188 |
355 rsnd_mod_power_on(mod); | 189 if (!runtime) 190 return; |
356 | 191 |
357 rsnd_src_soft_reset(mod); | 192 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 193 if (!convert_rate) 194 ratio = 0; 195 else if (convert_rate > runtime->rate) 196 ratio = 100 * convert_rate / runtime->rate; 197 else 198 ratio = 100 * runtime->rate / convert_rate; |
358 | 199 |
359 rsnd_src_initialize_lock(mod); | 200 if (ratio > 600) { 201 dev_err(dev, "FSO/FSI ratio error\n"); 202 return; 203 } |
360 | 204 |
361 src->err = 0; 362 363 /* reset sync convert_rate */ 364 src->sync.val = 0; 365 366 return 0; 367} 368 369static int rsnd_src_quit(struct rsnd_mod *mod, 370 struct rsnd_dai_stream *io, 371 struct rsnd_priv *priv) 372{ 373 struct rsnd_src *src = rsnd_mod_to_src(mod); 374 struct device *dev = rsnd_priv_to_dev(priv); 375 376 rsnd_mod_power_off(mod); 377 378 if (src->err) 379 dev_warn(dev, "%s[%d] under/over flow err = %d\n", 380 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); 381 382 src->convert_rate = 0; 383 384 /* reset sync convert_rate */ 385 src->sync.val = 0; 386 387 return 0; 388} 389 390static int rsnd_src_start(struct rsnd_mod *mod) 391{ 392 rsnd_src_initialize_unlock(mod); 393 394 return 0; 395} 396 397static int rsnd_src_stop(struct rsnd_mod *mod) 398{ 399 /* nothing to do */ 400 return 0; 401} 402 403/* 404 * Gen1 functions 405 */ 406static int rsnd_src_set_route_gen1(struct rsnd_dai_stream *io, 407 struct rsnd_mod *mod) 408{ 409 struct src_route_config { 410 u32 mask; 411 int shift; 412 } routes[] = { 413 { 0xF, 0, }, /* 0 */ 414 { 0xF, 4, }, /* 1 */ 415 { 0xF, 8, }, /* 2 */ 416 { 0x7, 12, }, /* 3 */ 417 { 0x7, 16, }, /* 4 */ 418 { 0x7, 20, }, /* 5 */ 419 { 0x7, 24, }, /* 6 */ 420 { 0x3, 28, }, /* 7 */ 421 { 0x3, 30, }, /* 8 */ 422 }; 423 u32 mask; 424 u32 val; 425 int id; 426 427 id = rsnd_mod_id(mod); 428 if (id < 0 || id >= ARRAY_SIZE(routes)) 429 return -EIO; 430 | |
431 /* | 205 /* |
432 * SRC_ROUTE_SELECT | 206 * SRC_ADINR |
433 */ | 207 */ |
434 val = rsnd_io_is_play(io) ? 0x1 : 0x2; 435 val = val << routes[id].shift; 436 mask = routes[id].mask << routes[id].shift; | 208 adinr = rsnd_get_adinr_bit(mod, io) | 209 rsnd_get_adinr_chan(mod, io); |
437 | 210 |
438 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); 439 440 return 0; 441} 442 443static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream *io, 444 struct rsnd_mod *mod) 445{ 446 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 447 struct rsnd_src *src = rsnd_mod_to_src(mod); 448 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 449 u32 convert_rate = rsnd_src_convert_rate(io, src); 450 u32 mask; 451 u32 val; 452 int shift; 453 int id = rsnd_mod_id(mod); 454 int ret; 455 | |
456 /* | 211 /* |
457 * SRC_TIMING_SELECT | 212 * SRC_IFSCR / SRC_IFSVR |
458 */ | 213 */ |
459 shift = (id % 4) * 8; 460 mask = 0x1F << shift; | 214 ifscr = 0; 215 fsrate = 0; 216 if (convert_rate) { 217 ifscr = 1; 218 fsrate = 0x0400000 / convert_rate * runtime->rate; 219 } |
461 462 /* | 220 221 /* |
463 * ADG is used as source clock if SRC was used, 464 * then, SSI WS is used as destination clock. 465 * SSI WS is used as source clock if SRC is not used 466 * (when playback, source/destination become reverse when capture) | 222 * SRC_SRCCR / SRC_ROUTE_MODE0 |
467 */ | 223 */ |
468 ret = 0; | 224 cr = 0x00011110; 225 route = 0x0; |
469 if (convert_rate) { | 226 if (convert_rate) { |
470 /* use ADG */ 471 val = 0; 472 ret = rsnd_adg_set_convert_clk_gen1(priv, mod, 473 runtime->rate, 474 convert_rate); 475 } else if (8 == id) { 476 /* use SSI WS, but SRU8 is special */ 477 val = id << shift; 478 } else { 479 /* use SSI WS */ 480 val = (id + 1) << shift; | 227 route = 0x1; 228 229 if (rsnd_enable_sync_convert(src)) { 230 cr |= 0x1; 231 route |= rsnd_io_is_play(io) ? 232 (0x1 << 24) : (0x1 << 25); 233 } |
481 } 482 | 234 } 235 |
483 if (ret < 0) 484 return ret; 485 486 switch (id / 4) { 487 case 0: 488 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); | 236 /* 237 * SRC_BSDSR / SRC_BSISR 238 */ 239 switch (rsnd_mod_id(mod)) { 240 case 5: 241 case 6: 242 case 7: 243 case 8: 244 bsdsr = 0x02400000; /* 6 - 1/6 */ 245 bsisr = 0x00100060; /* 6 - 1/6 */ |
489 break; | 246 break; |
490 case 1: 491 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); | 247 default: 248 bsdsr = 0x01800000; /* 6 - 1/6 */ 249 bsisr = 0x00100060 ;/* 6 - 1/6 */ |
492 break; | 250 break; |
493 case 2: 494 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); 495 break; | |
496 } 497 | 251 } 252 |
498 return 0; 499} | 253 rsnd_mod_write(mod, SRC_SRCIR, 1); /* initialize */ 254 rsnd_mod_write(mod, SRC_ADINR, adinr); 255 rsnd_mod_write(mod, SRC_IFSCR, ifscr); 256 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 257 rsnd_mod_write(mod, SRC_SRCCR, cr); 258 rsnd_mod_write(mod, SRC_BSDSR, bsdsr); 259 rsnd_mod_write(mod, SRC_BSISR, bsisr); 260 rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */ |
500 | 261 |
501static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, 502 struct rsnd_dai_stream *io) 503{ 504 struct rsnd_src *src = rsnd_mod_to_src(mod); 505 int ret; | 262 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); 263 rsnd_mod_write(mod, SRC_I_BUSIF_MODE, 1); 264 rsnd_mod_write(mod, SRC_O_BUSIF_MODE, 1); 265 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); |
506 | 266 |
507 ret = rsnd_src_set_convert_rate(mod, io); 508 if (ret < 0) 509 return ret; 510 511 /* Select SRC mode (fixed value) */ 512 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); 513 514 /* Set the restriction value of the FS ratio (98%) */ 515 rsnd_mod_write(mod, SRC_MNFSR, 516 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); 517 518 /* Gen1/Gen2 are not compatible */ 519 if (rsnd_src_convert_rate(io, src)) 520 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); 521 522 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ 523 524 return 0; | 267 if (convert_rate) 268 rsnd_adg_set_convert_clk_gen2(mod, io, 269 runtime->rate, 270 convert_rate); 271 else 272 rsnd_adg_set_convert_timing_gen2(mod, io); |
525} 526 | 273} 274 |
527static int rsnd_src_init_gen1(struct rsnd_mod *mod, 528 struct rsnd_dai_stream *io, 529 struct rsnd_priv *priv) | 275#define rsnd_src_irq_enable(mod) rsnd_src_irq_ctrol(mod, 1) 276#define rsnd_src_irq_disable(mod) rsnd_src_irq_ctrol(mod, 0) 277static void rsnd_src_irq_ctrol(struct rsnd_mod *mod, int enable) |
530{ | 278{ |
531 int ret; 532 533 ret = rsnd_src_init(mod, priv); 534 if (ret < 0) 535 return ret; 536 537 ret = rsnd_src_set_route_gen1(io, mod); 538 if (ret < 0) 539 return ret; 540 541 ret = rsnd_src_set_convert_rate_gen1(mod, io); 542 if (ret < 0) 543 return ret; 544 545 ret = rsnd_src_set_convert_timing_gen1(io, mod); 546 if (ret < 0) 547 return ret; 548 549 return 0; 550} 551 552static int rsnd_src_start_gen1(struct rsnd_mod *mod, 553 struct rsnd_dai_stream *io, 554 struct rsnd_priv *priv) 555{ 556 int id = rsnd_mod_id(mod); 557 558 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); 559 560 return rsnd_src_start(mod); 561} 562 563static int rsnd_src_stop_gen1(struct rsnd_mod *mod, 564 struct rsnd_dai_stream *io, 565 struct rsnd_priv *priv) 566{ 567 int id = rsnd_mod_id(mod); 568 569 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); 570 571 return rsnd_src_stop(mod); 572} 573 574static struct rsnd_mod_ops rsnd_src_gen1_ops = { 575 .name = SRC_NAME, 576 .dma_req = rsnd_src_dma_req, 577 .init = rsnd_src_init_gen1, 578 .quit = rsnd_src_quit, 579 .start = rsnd_src_start_gen1, 580 .stop = rsnd_src_stop_gen1, 581 .hw_params = rsnd_src_hw_params, 582}; 583 584/* 585 * Gen2 functions 586 */ 587#define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1) 588#define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0) 589static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable) 590{ | |
591 struct rsnd_src *src = rsnd_mod_to_src(mod); 592 u32 sys_int_val, int_val, sys_int_mask; | 279 struct rsnd_src *src = rsnd_mod_to_src(mod); 280 u32 sys_int_val, int_val, sys_int_mask; |
593 int irq = src->info->irq; | 281 int irq = src->irq; |
594 int id = rsnd_mod_id(mod); 595 596 sys_int_val = 597 sys_int_mask = OUF_SRC(id); 598 int_val = 0x3300; 599 600 /* 601 * IRQ is not supported on non-DT 602 * see | 282 int id = rsnd_mod_id(mod); 283 284 sys_int_val = 285 sys_int_mask = OUF_SRC(id); 286 int_val = 0x3300; 287 288 /* 289 * IRQ is not supported on non-DT 290 * see |
603 * rsnd_src_probe_gen2() | 291 * rsnd_src_probe_() |
604 */ 605 if ((irq <= 0) || !enable) { 606 sys_int_val = 0; 607 int_val = 0; 608 } 609 610 /* 611 * WORKAROUND 612 * 613 * ignore over flow error when rsnd_enable_sync_convert() 614 */ 615 if (rsnd_enable_sync_convert(src)) 616 sys_int_val = sys_int_val & 0xffff; 617 618 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); 619 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); 620 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); 621} 622 | 292 */ 293 if ((irq <= 0) || !enable) { 294 sys_int_val = 0; 295 int_val = 0; 296 } 297 298 /* 299 * WORKAROUND 300 * 301 * ignore over flow error when rsnd_enable_sync_convert() 302 */ 303 if (rsnd_enable_sync_convert(src)) 304 sys_int_val = sys_int_val & 0xffff; 305 306 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); 307 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); 308 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); 309} 310 |
623static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod) | 311static void rsnd_src_status_clear(struct rsnd_mod *mod) |
624{ 625 u32 val = OUF_SRC(rsnd_mod_id(mod)); 626 627 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); 628 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); 629} 630 | 312{ 313 u32 val = OUF_SRC(rsnd_mod_id(mod)); 314 315 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); 316 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); 317} 318 |
631static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) | 319static bool rsnd_src_record_error(struct rsnd_mod *mod) |
632{ 633 struct rsnd_src *src = rsnd_mod_to_src(mod); 634 u32 val0, val1; 635 bool ret = false; 636 637 val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); 638 639 /* --- 7 unchanged lines hidden (view full) --- 647 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || 648 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { 649 struct rsnd_src *src = rsnd_mod_to_src(mod); 650 651 src->err++; 652 ret = true; 653 } 654 | 320{ 321 struct rsnd_src *src = rsnd_mod_to_src(mod); 322 u32 val0, val1; 323 bool ret = false; 324 325 val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); 326 327 /* --- 7 unchanged lines hidden (view full) --- 335 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || 336 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { 337 struct rsnd_src *src = rsnd_mod_to_src(mod); 338 339 src->err++; 340 ret = true; 341 } 342 |
655 /* clear error static */ 656 rsnd_src_error_clear_gen2(mod); 657 | |
658 return ret; 659} 660 | 343 return ret; 344} 345 |
661static int _rsnd_src_start_gen2(struct rsnd_mod *mod, 662 struct rsnd_dai_stream *io) | 346static int rsnd_src_start(struct rsnd_mod *mod, 347 struct rsnd_dai_stream *io, 348 struct rsnd_priv *priv) |
663{ 664 struct rsnd_src *src = rsnd_mod_to_src(mod); 665 u32 val; 666 | 349{ 350 struct rsnd_src *src = rsnd_mod_to_src(mod); 351 u32 val; 352 |
667 val = rsnd_get_dalign(mod, io); 668 669 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, val); 670 | |
671 /* 672 * WORKAROUND 673 * 674 * Enable SRC output if you want to use sync convert together with DVC 675 */ 676 val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? 677 0x01 : 0x11; 678 679 rsnd_mod_write(mod, SRC_CTRL, val); 680 | 353 /* 354 * WORKAROUND 355 * 356 * Enable SRC output if you want to use sync convert together with DVC 357 */ 358 val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? 359 0x01 : 0x11; 360 361 rsnd_mod_write(mod, SRC_CTRL, val); 362 |
681 rsnd_src_error_clear_gen2(mod); | 363 return 0; 364} |
682 | 365 |
683 rsnd_src_start(mod); | 366static int rsnd_src_stop(struct rsnd_mod *mod, 367 struct rsnd_dai_stream *io, 368 struct rsnd_priv *priv) 369{ 370 /* 371 * stop SRC output only 372 * see rsnd_src_quit 373 */ 374 rsnd_mod_write(mod, SRC_CTRL, 0x01); |
684 | 375 |
685 rsnd_src_irq_enable_gen2(mod); 686 | |
687 return 0; 688} 689 | 376 return 0; 377} 378 |
690static int _rsnd_src_stop_gen2(struct rsnd_mod *mod) | 379static int rsnd_src_init(struct rsnd_mod *mod, 380 struct rsnd_dai_stream *io, 381 struct rsnd_priv *priv) |
691{ | 382{ |
692 rsnd_src_irq_disable_gen2(mod); | 383 struct rsnd_src *src = rsnd_mod_to_src(mod); |
693 | 384 |
694 rsnd_mod_write(mod, SRC_CTRL, 0); | 385 rsnd_mod_power_on(mod); |
695 | 386 |
696 rsnd_src_error_record_gen2(mod); | 387 rsnd_src_activation(mod); |
697 | 388 |
698 return rsnd_src_stop(mod); | 389 rsnd_src_set_convert_rate(io, mod); 390 391 rsnd_src_status_clear(mod); 392 393 rsnd_src_irq_enable(mod); 394 395 src->err = 0; 396 397 /* reset sync convert_rate */ 398 src->sync.val = 0; 399 400 return 0; |
699} 700 | 401} 402 |
701static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod, 702 struct rsnd_dai_stream *io) | 403static int rsnd_src_quit(struct rsnd_mod *mod, 404 struct rsnd_dai_stream *io, 405 struct rsnd_priv *priv) |
703{ | 406{ |
704 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | 407 struct rsnd_src *src = rsnd_mod_to_src(mod); 408 struct device *dev = rsnd_priv_to_dev(priv); |
705 | 409 |
706 spin_lock(&priv->lock); | 410 rsnd_src_irq_disable(mod); |
707 | 411 |
708 /* ignore all cases if not working */ 709 if (!rsnd_io_is_working(io)) 710 goto rsnd_src_interrupt_gen2_out; | 412 /* stop both out/in */ 413 rsnd_mod_write(mod, SRC_CTRL, 0); |
711 | 414 |
712 if (rsnd_src_error_record_gen2(mod)) { 713 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 714 struct rsnd_src *src = rsnd_mod_to_src(mod); 715 struct device *dev = rsnd_priv_to_dev(priv); | 415 rsnd_src_halt(mod); |
716 | 416 |
717 dev_dbg(dev, "%s[%d] restart\n", 718 rsnd_mod_name(mod), rsnd_mod_id(mod)); | 417 rsnd_mod_power_off(mod); |
719 | 418 |
720 _rsnd_src_stop_gen2(mod); 721 if (src->err < 1024) 722 _rsnd_src_start_gen2(mod, io); 723 else 724 dev_warn(dev, "no more SRC restart\n"); 725 } | 419 if (src->err) 420 dev_warn(dev, "%s[%d] under/over flow err = %d\n", 421 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); |
726 | 422 |
727rsnd_src_interrupt_gen2_out: 728 spin_unlock(&priv->lock); 729} | 423 src->convert_rate = 0; |
730 | 424 |
731static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) 732{ 733 struct rsnd_mod *mod = data; | 425 /* reset sync convert_rate */ 426 src->sync.val = 0; |
734 | 427 |
735 rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2); 736 737 return IRQ_HANDLED; | 428 return 0; |
738} 739 | 429} 430 |
740static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, 741 struct rsnd_dai_stream *io) | 431static void __rsnd_src_interrupt(struct rsnd_mod *mod, 432 struct rsnd_dai_stream *io) |
742{ 743 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | 433{ 434 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
744 struct device *dev = rsnd_priv_to_dev(priv); 745 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | |
746 struct rsnd_src *src = rsnd_mod_to_src(mod); | 435 struct rsnd_src *src = rsnd_mod_to_src(mod); |
747 u32 convert_rate = rsnd_src_convert_rate(io, src); 748 u32 cr, route; 749 uint ratio; 750 int ret; | 436 struct device *dev = rsnd_priv_to_dev(priv); |
751 | 437 |
752 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 753 if (!convert_rate) 754 ratio = 0; 755 else if (convert_rate > runtime->rate) 756 ratio = 100 * convert_rate / runtime->rate; 757 else 758 ratio = 100 * runtime->rate / convert_rate; | 438 spin_lock(&priv->lock); |
759 | 439 |
760 if (ratio > 600) { 761 dev_err(dev, "FSO/FSI ratio error\n"); 762 return -EINVAL; 763 } | 440 /* ignore all cases if not working */ 441 if (!rsnd_io_is_working(io)) 442 goto rsnd_src_interrupt_out; |
764 | 443 |
765 ret = rsnd_src_set_convert_rate(mod, io); 766 if (ret < 0) 767 return ret; | 444 if (rsnd_src_record_error(mod)) { |
768 | 445 |
769 cr = 0x00011110; 770 route = 0x0; 771 if (convert_rate) { 772 route = 0x1; | 446 dev_dbg(dev, "%s[%d] restart\n", 447 rsnd_mod_name(mod), rsnd_mod_id(mod)); |
773 | 448 |
774 if (rsnd_enable_sync_convert(src)) { 775 cr |= 0x1; 776 route |= rsnd_io_is_play(io) ? 777 (0x1 << 24) : (0x1 << 25); 778 } | 449 rsnd_src_stop(mod, io, priv); 450 rsnd_src_start(mod, io, priv); |
779 } 780 | 451 } 452 |
781 rsnd_mod_write(mod, SRC_SRCCR, cr); 782 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); | 453 if (src->err > 1024) { 454 rsnd_src_irq_disable(mod); |
783 | 455 |
784 switch (rsnd_mod_id(mod)) { 785 case 5: 786 case 6: 787 case 7: 788 case 8: 789 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); 790 break; 791 default: 792 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); 793 break; | 456 dev_warn(dev, "no more %s[%d] restart\n", 457 rsnd_mod_name(mod), rsnd_mod_id(mod)); |
794 } 795 | 458 } 459 |
796 rsnd_mod_write(mod, SRC_BSISR, 0x00100060); | 460 rsnd_src_status_clear(mod); 461rsnd_src_interrupt_out: |
797 | 462 |
798 return 0; | 463 spin_unlock(&priv->lock); |
799} 800 | 464} 465 |
801static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io, 802 struct rsnd_mod *mod) | 466static irqreturn_t rsnd_src_interrupt(int irq, void *data) |
803{ | 467{ |
804 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 805 struct rsnd_src *src = rsnd_mod_to_src(mod); 806 u32 convert_rate = rsnd_src_convert_rate(io, src); 807 int ret; | 468 struct rsnd_mod *mod = data; |
808 | 469 |
809 if (convert_rate) 810 ret = rsnd_adg_set_convert_clk_gen2(mod, io, 811 runtime->rate, 812 convert_rate); 813 else 814 ret = rsnd_adg_set_convert_timing_gen2(mod, io); | 470 rsnd_mod_interrupt(mod, __rsnd_src_interrupt); |
815 | 471 |
816 return ret; | 472 return IRQ_HANDLED; |
817} 818 | 473} 474 |
819static int rsnd_src_probe_gen2(struct rsnd_mod *mod, 820 struct rsnd_dai_stream *io, 821 struct rsnd_priv *priv) | 475static int rsnd_src_probe_(struct rsnd_mod *mod, 476 struct rsnd_dai_stream *io, 477 struct rsnd_priv *priv) |
822{ 823 struct rsnd_src *src = rsnd_mod_to_src(mod); 824 struct device *dev = rsnd_priv_to_dev(priv); | 478{ 479 struct rsnd_src *src = rsnd_mod_to_src(mod); 480 struct device *dev = rsnd_priv_to_dev(priv); |
825 int irq = src->info->irq; | 481 int irq = src->irq; |
826 int ret; 827 828 if (irq > 0) { 829 /* 830 * IRQ is not supported on non-DT 831 * see | 482 int ret; 483 484 if (irq > 0) { 485 /* 486 * IRQ is not supported on non-DT 487 * see |
832 * rsnd_src_irq_enable_gen2() | 488 * rsnd_src_irq_enable() |
833 */ 834 ret = devm_request_irq(dev, irq, | 489 */ 490 ret = devm_request_irq(dev, irq, |
835 rsnd_src_interrupt_gen2, | 491 rsnd_src_interrupt, |
836 IRQF_SHARED, 837 dev_name(dev), mod); 838 if (ret) 839 return ret; 840 } 841 | 492 IRQF_SHARED, 493 dev_name(dev), mod); 494 if (ret) 495 return ret; 496 } 497 |
842 ret = rsnd_dma_init(io, 843 rsnd_mod_to_dma(mod), 844 src->info->dma_id); | 498 src->dma = rsnd_dma_attach(io, mod, 0); 499 if (IS_ERR(src->dma)) 500 return PTR_ERR(src->dma); |
845 846 return ret; 847} 848 | 501 502 return ret; 503} 504 |
849static int rsnd_src_remove_gen2(struct rsnd_mod *mod, 850 struct rsnd_dai_stream *io, 851 struct rsnd_priv *priv) 852{ 853 rsnd_dma_quit(io, rsnd_mod_to_dma(mod)); 854 855 return 0; 856} 857 858static int rsnd_src_init_gen2(struct rsnd_mod *mod, 859 struct rsnd_dai_stream *io, 860 struct rsnd_priv *priv) 861{ 862 int ret; 863 864 ret = rsnd_src_init(mod, priv); 865 if (ret < 0) 866 return ret; 867 868 ret = rsnd_src_set_convert_rate_gen2(mod, io); 869 if (ret < 0) 870 return ret; 871 872 ret = rsnd_src_set_convert_timing_gen2(io, mod); 873 if (ret < 0) 874 return ret; 875 876 return 0; 877} 878 879static int rsnd_src_start_gen2(struct rsnd_mod *mod, 880 struct rsnd_dai_stream *io, 881 struct rsnd_priv *priv) 882{ 883 rsnd_dma_start(io, rsnd_mod_to_dma(mod)); 884 885 return _rsnd_src_start_gen2(mod, io); 886} 887 888static int rsnd_src_stop_gen2(struct rsnd_mod *mod, 889 struct rsnd_dai_stream *io, 890 struct rsnd_priv *priv) 891{ 892 int ret; 893 894 ret = _rsnd_src_stop_gen2(mod); 895 896 rsnd_dma_stop(io, rsnd_mod_to_dma(mod)); 897 898 return ret; 899} 900 901static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io, 902 struct rsnd_mod *mod) 903{ 904 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 905 struct rsnd_src *src = rsnd_mod_to_src(mod); 906 u32 convert_rate = rsnd_src_convert_rate(io, src); 907 u32 fsrate; 908 909 if (!runtime) 910 return; 911 912 if (!convert_rate) 913 convert_rate = runtime->rate; 914 915 fsrate = 0x0400000 / convert_rate * runtime->rate; 916 917 /* update IFS */ 918 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 919} 920 921static int rsnd_src_pcm_new_gen2(struct rsnd_mod *mod, | 505static int rsnd_src_pcm_new(struct rsnd_mod *mod, |
922 struct rsnd_dai_stream *io, 923 struct snd_soc_pcm_runtime *rtd) 924{ 925 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); | 506 struct rsnd_dai_stream *io, 507 struct snd_soc_pcm_runtime *rtd) 508{ 509 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
926 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); | |
927 struct rsnd_src *src = rsnd_mod_to_src(mod); 928 int ret; 929 930 /* 931 * enable SRC sync convert if possible 932 */ 933 934 /* 935 * SRC sync convert needs clock master 936 */ 937 if (!rsnd_rdai_is_clk_master(rdai)) 938 return 0; 939 940 /* | 510 struct rsnd_src *src = rsnd_mod_to_src(mod); 511 int ret; 512 513 /* 514 * enable SRC sync convert if possible 515 */ 516 517 /* 518 * SRC sync convert needs clock master 519 */ 520 if (!rsnd_rdai_is_clk_master(rdai)) 521 return 0; 522 523 /* |
941 * SRC In doesn't work if DVC was enabled 942 */ 943 if (dvc && !rsnd_io_is_play(io)) 944 return 0; 945 946 /* | |
947 * enable sync convert 948 */ 949 ret = rsnd_kctrl_new_s(mod, io, rtd, 950 rsnd_io_is_play(io) ? 951 "SRC Out Rate Switch" : 952 "SRC In Rate Switch", | 524 * enable sync convert 525 */ 526 ret = rsnd_kctrl_new_s(mod, io, rtd, 527 rsnd_io_is_play(io) ? 528 "SRC Out Rate Switch" : 529 "SRC In Rate Switch", |
953 rsnd_src_reconvert_update, | 530 rsnd_src_set_convert_rate, |
954 &src->sen, 1); 955 if (ret < 0) 956 return ret; 957 958 ret = rsnd_kctrl_new_s(mod, io, rtd, 959 rsnd_io_is_play(io) ? 960 "SRC Out Rate" : 961 "SRC In Rate", | 531 &src->sen, 1); 532 if (ret < 0) 533 return ret; 534 535 ret = rsnd_kctrl_new_s(mod, io, rtd, 536 rsnd_io_is_play(io) ? 537 "SRC Out Rate" : 538 "SRC In Rate", |
962 rsnd_src_reconvert_update, | 539 rsnd_src_set_convert_rate, |
963 &src->sync, 192000); 964 965 return ret; 966} 967 | 540 &src->sync, 192000); 541 542 return ret; 543} 544 |
968static struct rsnd_mod_ops rsnd_src_gen2_ops = { | 545static struct rsnd_mod_ops rsnd_src_ops = { |
969 .name = SRC_NAME, 970 .dma_req = rsnd_src_dma_req, | 546 .name = SRC_NAME, 547 .dma_req = rsnd_src_dma_req, |
971 .probe = rsnd_src_probe_gen2, 972 .remove = rsnd_src_remove_gen2, 973 .init = rsnd_src_init_gen2, | 548 .probe = rsnd_src_probe_, 549 .init = rsnd_src_init, |
974 .quit = rsnd_src_quit, | 550 .quit = rsnd_src_quit, |
975 .start = rsnd_src_start_gen2, 976 .stop = rsnd_src_stop_gen2, | 551 .start = rsnd_src_start, 552 .stop = rsnd_src_stop, |
977 .hw_params = rsnd_src_hw_params, | 553 .hw_params = rsnd_src_hw_params, |
978 .pcm_new = rsnd_src_pcm_new_gen2, | 554 .pcm_new = rsnd_src_pcm_new, |
979}; 980 981struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) 982{ 983 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 984 id = 0; 985 | 555}; 556 557struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) 558{ 559 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 560 id = 0; 561 |
986 return rsnd_mod_get((struct rsnd_src *)(priv->src) + id); | 562 return rsnd_mod_get(rsnd_src_get(priv, id)); |
987} 988 | 563} 564 |
989static void rsnd_of_parse_src(struct platform_device *pdev, 990 const struct rsnd_of_data *of_data, 991 struct rsnd_priv *priv) | 565int rsnd_src_probe(struct rsnd_priv *priv) |
992{ | 566{ |
993 struct device_node *src_node; | 567 struct device_node *node; |
994 struct device_node *np; | 568 struct device_node *np; |
995 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 996 struct rsnd_src_platform_info *src_info; 997 struct device *dev = &pdev->dev; 998 int nr, i; 999 1000 if (!of_data) 1001 return; 1002 1003 src_node = rsnd_src_of_node(priv); 1004 if (!src_node) 1005 return; 1006 1007 nr = of_get_child_count(src_node); 1008 if (!nr) 1009 goto rsnd_of_parse_src_end; 1010 1011 src_info = devm_kzalloc(dev, 1012 sizeof(struct rsnd_src_platform_info) * nr, 1013 GFP_KERNEL); 1014 if (!src_info) { 1015 dev_err(dev, "src info allocation error\n"); 1016 goto rsnd_of_parse_src_end; 1017 } 1018 1019 info->src_info = src_info; 1020 info->src_info_nr = nr; 1021 1022 i = 0; 1023 for_each_child_of_node(src_node, np) { 1024 src_info[i].irq = irq_of_parse_and_map(np, 0); 1025 1026 i++; 1027 } 1028 1029rsnd_of_parse_src_end: 1030 of_node_put(src_node); 1031} 1032 1033int rsnd_src_probe(struct platform_device *pdev, 1034 const struct rsnd_of_data *of_data, 1035 struct rsnd_priv *priv) 1036{ 1037 struct rcar_snd_info *info = rsnd_priv_to_info(priv); | |
1038 struct device *dev = rsnd_priv_to_dev(priv); 1039 struct rsnd_src *src; | 569 struct device *dev = rsnd_priv_to_dev(priv); 570 struct rsnd_src *src; |
1040 struct rsnd_mod_ops *ops; | |
1041 struct clk *clk; 1042 char name[RSND_SRC_NAME_SIZE]; 1043 int i, nr, ret; 1044 | 571 struct clk *clk; 572 char name[RSND_SRC_NAME_SIZE]; 573 int i, nr, ret; 574 |
1045 ops = NULL; 1046 if (rsnd_is_gen1(priv)) { 1047 ops = &rsnd_src_gen1_ops; 1048 dev_warn(dev, "Gen1 support will be removed soon\n"); 1049 } 1050 if (rsnd_is_gen2(priv)) 1051 ops = &rsnd_src_gen2_ops; 1052 if (!ops) { 1053 dev_err(dev, "unknown Generation\n"); 1054 return -EIO; 1055 } | 575 /* This driver doesn't support Gen1 at this point */ 576 if (rsnd_is_gen1(priv)) 577 return 0; |
1056 | 578 |
1057 rsnd_of_parse_src(pdev, of_data, priv); | 579 node = rsnd_src_of_node(priv); 580 if (!node) 581 return 0; /* not used is not error */ |
1058 | 582 |
1059 /* 1060 * init SRC 1061 */ 1062 nr = info->src_info_nr; 1063 if (!nr) 1064 return 0; | 583 nr = of_get_child_count(node); 584 if (!nr) { 585 ret = -EINVAL; 586 goto rsnd_src_probe_done; 587 } |
1065 1066 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); | 588 589 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
1067 if (!src) 1068 return -ENOMEM; | 590 if (!src) { 591 ret = -ENOMEM; 592 goto rsnd_src_probe_done; 593 } |
1069 1070 priv->src_nr = nr; 1071 priv->src = src; 1072 | 594 595 priv->src_nr = nr; 596 priv->src = src; 597 |
1073 for_each_rsnd_src(src, priv, i) { | 598 i = 0; 599 for_each_child_of_node(node, np) { 600 src = rsnd_src_get(priv, i); 601 |
1074 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", 1075 SRC_NAME, i); 1076 | 602 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", 603 SRC_NAME, i); 604 |
605 src->irq = irq_of_parse_and_map(np, 0); 606 if (!src->irq) { 607 ret = -EINVAL; 608 goto rsnd_src_probe_done; 609 } 610 |
|
1077 clk = devm_clk_get(dev, name); | 611 clk = devm_clk_get(dev, name); |
1078 if (IS_ERR(clk)) 1079 return PTR_ERR(clk); | 612 if (IS_ERR(clk)) { 613 ret = PTR_ERR(clk); 614 goto rsnd_src_probe_done; 615 } |
1080 | 616 |
1081 src->info = &info->src_info[i]; 1082 1083 ret = rsnd_mod_init(priv, rsnd_mod_get(src), ops, clk, RSND_MOD_SRC, i); | 617 ret = rsnd_mod_init(priv, rsnd_mod_get(src), 618 &rsnd_src_ops, clk, rsnd_mod_get_status, 619 RSND_MOD_SRC, i); |
1084 if (ret) | 620 if (ret) |
1085 return ret; | 621 goto rsnd_src_probe_done; 622 623 i++; |
1086 } 1087 | 624 } 625 |
1088 return 0; | 626 ret = 0; 627 628rsnd_src_probe_done: 629 of_node_put(node); 630 631 return ret; |
1089} 1090 | 632} 633 |
1091void rsnd_src_remove(struct platform_device *pdev, 1092 struct rsnd_priv *priv) | 634void rsnd_src_remove(struct rsnd_priv *priv) |
1093{ 1094 struct rsnd_src *src; 1095 int i; 1096 1097 for_each_rsnd_src(src, priv, i) { 1098 rsnd_mod_quit(rsnd_mod_get(src)); 1099 } 1100} | 635{ 636 struct rsnd_src *src; 637 int i; 638 639 for_each_rsnd_src(src, priv, i) { 640 rsnd_mod_quit(rsnd_mod_get(src)); 641 } 642} |