diff options
Diffstat (limited to 'sound/soc/sh/fsi.c')
-rw-r--r-- | sound/soc/sh/fsi.c | 606 |
1 files changed, 321 insertions, 285 deletions
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c index 58c6bec642de..507e709f2807 100644 --- a/sound/soc/sh/fsi.c +++ b/sound/soc/sh/fsi.c | |||
@@ -80,11 +80,12 @@ | |||
80 | #define B_CLK 0x00000010 | 80 | #define B_CLK 0x00000010 |
81 | #define A_CLK 0x00000001 | 81 | #define A_CLK 0x00000001 |
82 | 82 | ||
83 | /* INT_ST */ | 83 | /* IO SHIFT / MACRO */ |
84 | #define INT_B_IN (1 << 12) | 84 | #define BI_SHIFT 12 |
85 | #define INT_B_OUT (1 << 8) | 85 | #define BO_SHIFT 8 |
86 | #define INT_A_IN (1 << 4) | 86 | #define AI_SHIFT 4 |
87 | #define INT_A_OUT (1 << 0) | 87 | #define AO_SHIFT 0 |
88 | #define AB_IO(param, shift) (param << shift) | ||
88 | 89 | ||
89 | /* SOFT_RST */ | 90 | /* SOFT_RST */ |
90 | #define PBSR (1 << 12) /* Port B Software Reset */ | 91 | #define PBSR (1 << 12) /* Port B Software Reset */ |
@@ -93,33 +94,43 @@ | |||
93 | #define FSISR (1 << 0) /* Software Reset */ | 94 | #define FSISR (1 << 0) /* Software Reset */ |
94 | 95 | ||
95 | /* FIFO_SZ */ | 96 | /* FIFO_SZ */ |
96 | #define OUT_SZ_MASK 0x7 | 97 | #define FIFO_SZ_MASK 0x7 |
97 | #define BO_SZ_SHIFT 8 | ||
98 | #define AO_SZ_SHIFT 0 | ||
99 | 98 | ||
100 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 | 99 | #define FSI_RATES SNDRV_PCM_RATE_8000_96000 |
101 | 100 | ||
102 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) | 101 | #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) |
103 | 102 | ||
104 | /************************************************************************ | 103 | /* |
104 | * FSI driver use below type name for variable | ||
105 | * | ||
106 | * xxx_len : data length | ||
107 | * xxx_width : data width | ||
108 | * xxx_offset : data offset | ||
109 | * xxx_num : number of data | ||
110 | */ | ||
111 | |||
112 | /* | ||
113 | * struct | ||
114 | */ | ||
105 | 115 | ||
116 | struct fsi_stream { | ||
117 | struct snd_pcm_substream *substream; | ||
106 | 118 | ||
107 | struct | 119 | int fifo_max_num; |
120 | int chan_num; | ||
108 | 121 | ||
122 | int buff_offset; | ||
123 | int buff_len; | ||
124 | int period_len; | ||
125 | int period_num; | ||
126 | }; | ||
109 | 127 | ||
110 | ************************************************************************/ | ||
111 | struct fsi_priv { | 128 | struct fsi_priv { |
112 | void __iomem *base; | 129 | void __iomem *base; |
113 | struct snd_pcm_substream *substream; | ||
114 | struct fsi_master *master; | 130 | struct fsi_master *master; |
115 | 131 | ||
116 | int fifo_max; | 132 | struct fsi_stream playback; |
117 | int chan; | 133 | struct fsi_stream capture; |
118 | |||
119 | int byte_offset; | ||
120 | int period_len; | ||
121 | int buffer_len; | ||
122 | int periods; | ||
123 | 134 | ||
124 | u32 mst_ctrl; | 135 | u32 mst_ctrl; |
125 | }; | 136 | }; |
@@ -142,13 +153,10 @@ struct fsi_master { | |||
142 | spinlock_t lock; | 153 | spinlock_t lock; |
143 | }; | 154 | }; |
144 | 155 | ||
145 | /************************************************************************ | 156 | /* |
146 | 157 | * basic read write function | |
147 | 158 | */ | |
148 | basic read write function | ||
149 | |||
150 | 159 | ||
151 | ************************************************************************/ | ||
152 | static void __fsi_reg_write(u32 reg, u32 data) | 160 | static void __fsi_reg_write(u32 reg, u32 data) |
153 | { | 161 | { |
154 | /* valid data area is 24bit */ | 162 | /* valid data area is 24bit */ |
@@ -251,13 +259,10 @@ static void fsi_master_mask_set(struct fsi_master *master, | |||
251 | spin_unlock_irqrestore(&master->lock, flags); | 259 | spin_unlock_irqrestore(&master->lock, flags); |
252 | } | 260 | } |
253 | 261 | ||
254 | /************************************************************************ | 262 | /* |
255 | 263 | * basic function | |
256 | 264 | */ | |
257 | basic function | ||
258 | |||
259 | 265 | ||
260 | ************************************************************************/ | ||
261 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) | 266 | static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) |
262 | { | 267 | { |
263 | return fsi->master; | 268 | return fsi->master; |
@@ -271,16 +276,19 @@ static int fsi_is_port_a(struct fsi_priv *fsi) | |||
271 | static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream) | 276 | static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream) |
272 | { | 277 | { |
273 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 278 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
274 | struct snd_soc_dai_link *machine = rtd->dai; | ||
275 | 279 | ||
276 | return machine->cpu_dai; | 280 | return rtd->cpu_dai; |
277 | } | 281 | } |
278 | 282 | ||
279 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) | 283 | static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) |
280 | { | 284 | { |
281 | struct snd_soc_dai *dai = fsi_get_dai(substream); | 285 | struct snd_soc_dai *dai = fsi_get_dai(substream); |
286 | struct fsi_master *master = snd_soc_dai_get_drvdata(dai); | ||
282 | 287 | ||
283 | return dai->private_data; | 288 | if (dai->id == 0) |
289 | return &master->fsia; | ||
290 | else | ||
291 | return &master->fsib; | ||
284 | } | 292 | } |
285 | 293 | ||
286 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) | 294 | static u32 fsi_get_info_flags(struct fsi_priv *fsi) |
@@ -292,6 +300,22 @@ static u32 fsi_get_info_flags(struct fsi_priv *fsi) | |||
292 | master->info->portb_flags; | 300 | master->info->portb_flags; |
293 | } | 301 | } |
294 | 302 | ||
303 | static inline int fsi_stream_is_play(int stream) | ||
304 | { | ||
305 | return stream == SNDRV_PCM_STREAM_PLAYBACK; | ||
306 | } | ||
307 | |||
308 | static inline int fsi_is_play(struct snd_pcm_substream *substream) | ||
309 | { | ||
310 | return fsi_stream_is_play(substream->stream); | ||
311 | } | ||
312 | |||
313 | static inline struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi, | ||
314 | int is_play) | ||
315 | { | ||
316 | return is_play ? &fsi->playback : &fsi->capture; | ||
317 | } | ||
318 | |||
295 | static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play) | 319 | static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play) |
296 | { | 320 | { |
297 | u32 mode; | 321 | u32 mode; |
@@ -307,63 +331,144 @@ static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play) | |||
307 | return (mode & flags) != mode; | 331 | return (mode & flags) != mode; |
308 | } | 332 | } |
309 | 333 | ||
310 | static u32 fsi_port_ab_io_bit(struct fsi_priv *fsi, int is_play) | 334 | static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play) |
311 | { | 335 | { |
312 | int is_porta = fsi_is_port_a(fsi); | 336 | int is_porta = fsi_is_port_a(fsi); |
313 | u32 data; | 337 | u32 shift; |
314 | 338 | ||
315 | if (is_porta) | 339 | if (is_porta) |
316 | data = is_play ? (1 << 0) : (1 << 4); | 340 | shift = is_play ? AO_SHIFT : AI_SHIFT; |
317 | else | 341 | else |
318 | data = is_play ? (1 << 8) : (1 << 12); | 342 | shift = is_play ? BO_SHIFT : BI_SHIFT; |
319 | 343 | ||
320 | return data; | 344 | return shift; |
321 | } | 345 | } |
322 | 346 | ||
323 | static void fsi_stream_push(struct fsi_priv *fsi, | 347 | static void fsi_stream_push(struct fsi_priv *fsi, |
348 | int is_play, | ||
324 | struct snd_pcm_substream *substream, | 349 | struct snd_pcm_substream *substream, |
325 | u32 buffer_len, | 350 | u32 buffer_len, |
326 | u32 period_len) | 351 | u32 period_len) |
327 | { | 352 | { |
328 | fsi->substream = substream; | 353 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
329 | fsi->buffer_len = buffer_len; | 354 | |
330 | fsi->period_len = period_len; | 355 | io->substream = substream; |
331 | fsi->byte_offset = 0; | 356 | io->buff_len = buffer_len; |
332 | fsi->periods = 0; | 357 | io->buff_offset = 0; |
358 | io->period_len = period_len; | ||
359 | io->period_num = 0; | ||
333 | } | 360 | } |
334 | 361 | ||
335 | static void fsi_stream_pop(struct fsi_priv *fsi) | 362 | static void fsi_stream_pop(struct fsi_priv *fsi, int is_play) |
336 | { | 363 | { |
337 | fsi->substream = NULL; | 364 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
338 | fsi->buffer_len = 0; | 365 | |
339 | fsi->period_len = 0; | 366 | io->substream = NULL; |
340 | fsi->byte_offset = 0; | 367 | io->buff_len = 0; |
341 | fsi->periods = 0; | 368 | io->buff_offset = 0; |
369 | io->period_len = 0; | ||
370 | io->period_num = 0; | ||
342 | } | 371 | } |
343 | 372 | ||
344 | static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play) | 373 | static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play) |
345 | { | 374 | { |
346 | u32 status; | 375 | u32 status; |
347 | u32 reg = is_play ? DOFF_ST : DIFF_ST; | 376 | u32 reg = is_play ? DOFF_ST : DIFF_ST; |
348 | int residue; | 377 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
378 | int data_num; | ||
349 | 379 | ||
350 | status = fsi_reg_read(fsi, reg); | 380 | status = fsi_reg_read(fsi, reg); |
351 | residue = 0x1ff & (status >> 8); | 381 | data_num = 0x1ff & (status >> 8); |
352 | residue *= fsi->chan; | 382 | data_num *= io->chan_num; |
383 | |||
384 | return data_num; | ||
385 | } | ||
386 | |||
387 | static int fsi_len2num(int len, int width) | ||
388 | { | ||
389 | return len / width; | ||
390 | } | ||
391 | |||
392 | #define fsi_num2offset(a, b) fsi_num2len(a, b) | ||
393 | static int fsi_num2len(int num, int width) | ||
394 | { | ||
395 | return num * width; | ||
396 | } | ||
397 | |||
398 | static int fsi_get_frame_width(struct fsi_priv *fsi, int is_play) | ||
399 | { | ||
400 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); | ||
401 | struct snd_pcm_substream *substream = io->substream; | ||
402 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
403 | |||
404 | return frames_to_bytes(runtime, 1) / io->chan_num; | ||
405 | } | ||
406 | |||
407 | /* | ||
408 | * dma function | ||
409 | */ | ||
410 | |||
411 | static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream) | ||
412 | { | ||
413 | int is_play = fsi_stream_is_play(stream); | ||
414 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); | ||
415 | |||
416 | return io->substream->runtime->dma_area + io->buff_offset; | ||
417 | } | ||
418 | |||
419 | static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num) | ||
420 | { | ||
421 | u16 *start; | ||
422 | int i; | ||
423 | |||
424 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); | ||
425 | |||
426 | for (i = 0; i < num; i++) | ||
427 | fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8)); | ||
428 | } | ||
429 | |||
430 | static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num) | ||
431 | { | ||
432 | u16 *start; | ||
433 | int i; | ||
353 | 434 | ||
354 | return residue; | 435 | start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
436 | |||
437 | |||
438 | for (i = 0; i < num; i++) | ||
439 | *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8); | ||
355 | } | 440 | } |
356 | 441 | ||
357 | /************************************************************************ | 442 | static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num) |
443 | { | ||
444 | u32 *start; | ||
445 | int i; | ||
446 | |||
447 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK); | ||
448 | |||
449 | |||
450 | for (i = 0; i < num; i++) | ||
451 | fsi_reg_write(fsi, DODT, *(start + i)); | ||
452 | } | ||
358 | 453 | ||
454 | static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num) | ||
455 | { | ||
456 | u32 *start; | ||
457 | int i; | ||
359 | 458 | ||
360 | irq function | 459 | start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE); |
361 | 460 | ||
461 | for (i = 0; i < num; i++) | ||
462 | *(start + i) = fsi_reg_read(fsi, DIDT); | ||
463 | } | ||
464 | |||
465 | /* | ||
466 | * irq function | ||
467 | */ | ||
362 | 468 | ||
363 | ************************************************************************/ | ||
364 | static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) | 469 | static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) |
365 | { | 470 | { |
366 | u32 data = fsi_port_ab_io_bit(fsi, is_play); | 471 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
367 | struct fsi_master *master = fsi_get_master(fsi); | 472 | struct fsi_master *master = fsi_get_master(fsi); |
368 | 473 | ||
369 | fsi_master_mask_set(master, master->core->imsk, data, data); | 474 | fsi_master_mask_set(master, master->core->imsk, data, data); |
@@ -372,7 +477,7 @@ static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) | |||
372 | 477 | ||
373 | static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) | 478 | static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) |
374 | { | 479 | { |
375 | u32 data = fsi_port_ab_io_bit(fsi, is_play); | 480 | u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play)); |
376 | struct fsi_master *master = fsi_get_master(fsi); | 481 | struct fsi_master *master = fsi_get_master(fsi); |
377 | 482 | ||
378 | fsi_master_mask_set(master, master->core->imsk, data, 0); | 483 | fsi_master_mask_set(master, master->core->imsk, data, 0); |
@@ -394,20 +499,18 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi) | |||
394 | u32 data = 0; | 499 | u32 data = 0; |
395 | struct fsi_master *master = fsi_get_master(fsi); | 500 | struct fsi_master *master = fsi_get_master(fsi); |
396 | 501 | ||
397 | data |= fsi_port_ab_io_bit(fsi, 0); | 502 | data |= AB_IO(1, fsi_get_port_shift(fsi, 0)); |
398 | data |= fsi_port_ab_io_bit(fsi, 1); | 503 | data |= AB_IO(1, fsi_get_port_shift(fsi, 1)); |
399 | 504 | ||
400 | /* clear interrupt factor */ | 505 | /* clear interrupt factor */ |
401 | fsi_master_mask_set(master, master->core->int_st, data, 0); | 506 | fsi_master_mask_set(master, master->core->int_st, data, 0); |
402 | } | 507 | } |
403 | 508 | ||
404 | /************************************************************************ | 509 | /* |
405 | 510 | * SPDIF master clock function | |
406 | 511 | * | |
407 | SPDIF master clock function | 512 | * These functions are used later FSI2 |
408 | 513 | */ | |
409 | These functions are used later FSI2 | ||
410 | ************************************************************************/ | ||
411 | static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) | 514 | static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) |
412 | { | 515 | { |
413 | struct fsi_master *master = fsi_get_master(fsi); | 516 | struct fsi_master *master = fsi_get_master(fsi); |
@@ -424,13 +527,10 @@ static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) | |||
424 | fsi_master_mask_set(master, fsi->mst_ctrl, val, 0); | 527 | fsi_master_mask_set(master, fsi->mst_ctrl, val, 0); |
425 | } | 528 | } |
426 | 529 | ||
427 | /************************************************************************ | 530 | /* |
428 | 531 | * ctrl function | |
429 | 532 | */ | |
430 | ctrl function | ||
431 | |||
432 | 533 | ||
433 | ************************************************************************/ | ||
434 | static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable) | 534 | static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable) |
435 | { | 535 | { |
436 | u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4); | 536 | u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4); |
@@ -447,14 +547,15 @@ static void fsi_fifo_init(struct fsi_priv *fsi, | |||
447 | struct snd_soc_dai *dai) | 547 | struct snd_soc_dai *dai) |
448 | { | 548 | { |
449 | struct fsi_master *master = fsi_get_master(fsi); | 549 | struct fsi_master *master = fsi_get_master(fsi); |
550 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); | ||
450 | u32 ctrl, shift, i; | 551 | u32 ctrl, shift, i; |
451 | 552 | ||
452 | /* get on-chip RAM capacity */ | 553 | /* get on-chip RAM capacity */ |
453 | shift = fsi_master_read(master, FIFO_SZ); | 554 | shift = fsi_master_read(master, FIFO_SZ); |
454 | shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT; | 555 | shift >>= fsi_get_port_shift(fsi, is_play); |
455 | shift &= OUT_SZ_MASK; | 556 | shift &= FIFO_SZ_MASK; |
456 | fsi->fifo_max = 256 << shift; | 557 | io->fifo_max_num = 256 << shift; |
457 | dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max); | 558 | dev_dbg(dai->dev, "fifo = %d words\n", io->fifo_max_num); |
458 | 559 | ||
459 | /* | 560 | /* |
460 | * The maximum number of sample data varies depending | 561 | * The maximum number of sample data varies depending |
@@ -475,9 +576,10 @@ static void fsi_fifo_init(struct fsi_priv *fsi, | |||
475 | * 7 channels: 32 ( 32 x 7 = 224) | 576 | * 7 channels: 32 ( 32 x 7 = 224) |
476 | * 8 channels: 32 ( 32 x 8 = 256) | 577 | * 8 channels: 32 ( 32 x 8 = 256) |
477 | */ | 578 | */ |
478 | for (i = 1; i < fsi->chan; i <<= 1) | 579 | for (i = 1; i < io->chan_num; i <<= 1) |
479 | fsi->fifo_max >>= 1; | 580 | io->fifo_max_num >>= 1; |
480 | dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max); | 581 | dev_dbg(dai->dev, "%d channel %d store\n", |
582 | io->chan_num, io->fifo_max_num); | ||
481 | 583 | ||
482 | ctrl = is_play ? DOFF_CTL : DIFF_CTL; | 584 | ctrl = is_play ? DOFF_CTL : DIFF_CTL; |
483 | 585 | ||
@@ -500,84 +602,114 @@ static void fsi_soft_all_reset(struct fsi_master *master) | |||
500 | mdelay(10); | 602 | mdelay(10); |
501 | } | 603 | } |
502 | 604 | ||
503 | /* playback interrupt */ | 605 | static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int startup, int stream) |
504 | static int fsi_data_push(struct fsi_priv *fsi, int startup) | ||
505 | { | 606 | { |
506 | struct snd_pcm_runtime *runtime; | 607 | struct snd_pcm_runtime *runtime; |
507 | struct snd_pcm_substream *substream = NULL; | 608 | struct snd_pcm_substream *substream = NULL; |
508 | u32 status; | 609 | int is_play = fsi_stream_is_play(stream); |
509 | int send; | 610 | struct fsi_stream *io = fsi_get_stream(fsi, is_play); |
510 | int fifo_free; | 611 | u32 status_reg = is_play ? DOFF_ST : DIFF_ST; |
511 | int width; | 612 | int data_residue_num; |
512 | u8 *start; | 613 | int data_num; |
513 | int i, over_period; | 614 | int data_num_max; |
615 | int ch_width; | ||
616 | int over_period; | ||
617 | void (*fn)(struct fsi_priv *fsi, int size); | ||
514 | 618 | ||
515 | if (!fsi || | 619 | if (!fsi || |
516 | !fsi->substream || | 620 | !io->substream || |
517 | !fsi->substream->runtime) | 621 | !io->substream->runtime) |
518 | return -EINVAL; | 622 | return -EINVAL; |
519 | 623 | ||
520 | over_period = 0; | 624 | over_period = 0; |
521 | substream = fsi->substream; | 625 | substream = io->substream; |
522 | runtime = substream->runtime; | 626 | runtime = substream->runtime; |
523 | 627 | ||
524 | /* FSI FIFO has limit. | 628 | /* FSI FIFO has limit. |
525 | * So, this driver can not send periods data at a time | 629 | * So, this driver can not send periods data at a time |
526 | */ | 630 | */ |
527 | if (fsi->byte_offset >= | 631 | if (io->buff_offset >= |
528 | fsi->period_len * (fsi->periods + 1)) { | 632 | fsi_num2offset(io->period_num + 1, io->period_len)) { |
529 | 633 | ||
530 | over_period = 1; | 634 | over_period = 1; |
531 | fsi->periods = (fsi->periods + 1) % runtime->periods; | 635 | io->period_num = (io->period_num + 1) % runtime->periods; |
532 | 636 | ||
533 | if (0 == fsi->periods) | 637 | if (0 == io->period_num) |
534 | fsi->byte_offset = 0; | 638 | io->buff_offset = 0; |
535 | } | 639 | } |
536 | 640 | ||
537 | /* get 1 channel data width */ | 641 | /* get 1 channel data width */ |
538 | width = frames_to_bytes(runtime, 1) / fsi->chan; | 642 | ch_width = fsi_get_frame_width(fsi, is_play); |
539 | 643 | ||
540 | /* get send size for alsa */ | 644 | /* get residue data number of alsa */ |
541 | send = (fsi->buffer_len - fsi->byte_offset) / width; | 645 | data_residue_num = fsi_len2num(io->buff_len - io->buff_offset, |
542 | 646 | ch_width); | |
543 | /* get FIFO free size */ | 647 | |
544 | fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1); | 648 | if (is_play) { |
545 | 649 | /* | |
546 | /* size check */ | 650 | * for play-back |
547 | if (fifo_free < send) | 651 | * |
548 | send = fifo_free; | 652 | * data_num_max : number of FSI fifo free space |
653 | * data_num : number of ALSA residue data | ||
654 | */ | ||
655 | data_num_max = io->fifo_max_num * io->chan_num; | ||
656 | data_num_max -= fsi_get_fifo_data_num(fsi, is_play); | ||
657 | |||
658 | data_num = data_residue_num; | ||
659 | |||
660 | switch (ch_width) { | ||
661 | case 2: | ||
662 | fn = fsi_dma_soft_push16; | ||
663 | break; | ||
664 | case 4: | ||
665 | fn = fsi_dma_soft_push32; | ||
666 | break; | ||
667 | default: | ||
668 | return -EINVAL; | ||
669 | } | ||
670 | } else { | ||
671 | /* | ||
672 | * for capture | ||
673 | * | ||
674 | * data_num_max : number of ALSA free space | ||
675 | * data_num : number of data in FSI fifo | ||
676 | */ | ||
677 | data_num_max = data_residue_num; | ||
678 | data_num = fsi_get_fifo_data_num(fsi, is_play); | ||
679 | |||
680 | switch (ch_width) { | ||
681 | case 2: | ||
682 | fn = fsi_dma_soft_pop16; | ||
683 | break; | ||
684 | case 4: | ||
685 | fn = fsi_dma_soft_pop32; | ||
686 | break; | ||
687 | default: | ||
688 | return -EINVAL; | ||
689 | } | ||
690 | } | ||
549 | 691 | ||
550 | start = runtime->dma_area; | 692 | data_num = min(data_num, data_num_max); |
551 | start += fsi->byte_offset; | ||
552 | 693 | ||
553 | switch (width) { | 694 | fn(fsi, data_num); |
554 | case 2: | ||
555 | for (i = 0; i < send; i++) | ||
556 | fsi_reg_write(fsi, DODT, | ||
557 | ((u32)*((u16 *)start + i) << 8)); | ||
558 | break; | ||
559 | case 4: | ||
560 | for (i = 0; i < send; i++) | ||
561 | fsi_reg_write(fsi, DODT, *((u32 *)start + i)); | ||
562 | break; | ||
563 | default: | ||
564 | return -EINVAL; | ||
565 | } | ||
566 | 695 | ||
567 | fsi->byte_offset += send * width; | 696 | /* update buff_offset */ |
697 | io->buff_offset += fsi_num2offset(data_num, ch_width); | ||
568 | 698 | ||
569 | status = fsi_reg_read(fsi, DOFF_ST); | 699 | /* check fifo status */ |
570 | if (!startup) { | 700 | if (!startup) { |
571 | struct snd_soc_dai *dai = fsi_get_dai(substream); | 701 | struct snd_soc_dai *dai = fsi_get_dai(substream); |
702 | u32 status = fsi_reg_read(fsi, status_reg); | ||
572 | 703 | ||
573 | if (status & ERR_OVER) | 704 | if (status & ERR_OVER) |
574 | dev_err(dai->dev, "over run\n"); | 705 | dev_err(dai->dev, "over run\n"); |
575 | if (status & ERR_UNDER) | 706 | if (status & ERR_UNDER) |
576 | dev_err(dai->dev, "under run\n"); | 707 | dev_err(dai->dev, "under run\n"); |
577 | } | 708 | } |
578 | fsi_reg_write(fsi, DOFF_ST, 0); | 709 | fsi_reg_write(fsi, status_reg, 0); |
579 | 710 | ||
580 | fsi_irq_enable(fsi, 1); | 711 | /* re-enable irq */ |
712 | fsi_irq_enable(fsi, is_play); | ||
581 | 713 | ||
582 | if (over_period) | 714 | if (over_period) |
583 | snd_pcm_period_elapsed(substream); | 715 | snd_pcm_period_elapsed(substream); |
@@ -587,85 +719,12 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup) | |||
587 | 719 | ||
588 | static int fsi_data_pop(struct fsi_priv *fsi, int startup) | 720 | static int fsi_data_pop(struct fsi_priv *fsi, int startup) |
589 | { | 721 | { |
590 | struct snd_pcm_runtime *runtime; | 722 | return fsi_fifo_data_ctrl(fsi, startup, SNDRV_PCM_STREAM_CAPTURE); |
591 | struct snd_pcm_substream *substream = NULL; | 723 | } |
592 | u32 status; | ||
593 | int free; | ||
594 | int fifo_fill; | ||
595 | int width; | ||
596 | u8 *start; | ||
597 | int i, over_period; | ||
598 | |||
599 | if (!fsi || | ||
600 | !fsi->substream || | ||
601 | !fsi->substream->runtime) | ||
602 | return -EINVAL; | ||
603 | |||
604 | over_period = 0; | ||
605 | substream = fsi->substream; | ||
606 | runtime = substream->runtime; | ||
607 | |||
608 | /* FSI FIFO has limit. | ||
609 | * So, this driver can not send periods data at a time | ||
610 | */ | ||
611 | if (fsi->byte_offset >= | ||
612 | fsi->period_len * (fsi->periods + 1)) { | ||
613 | |||
614 | over_period = 1; | ||
615 | fsi->periods = (fsi->periods + 1) % runtime->periods; | ||
616 | |||
617 | if (0 == fsi->periods) | ||
618 | fsi->byte_offset = 0; | ||
619 | } | ||
620 | |||
621 | /* get 1 channel data width */ | ||
622 | width = frames_to_bytes(runtime, 1) / fsi->chan; | ||
623 | |||
624 | /* get free space for alsa */ | ||
625 | free = (fsi->buffer_len - fsi->byte_offset) / width; | ||
626 | |||
627 | /* get recv size */ | ||
628 | fifo_fill = fsi_get_fifo_residue(fsi, 0); | ||
629 | |||
630 | if (free < fifo_fill) | ||
631 | fifo_fill = free; | ||
632 | |||
633 | start = runtime->dma_area; | ||
634 | start += fsi->byte_offset; | ||
635 | |||
636 | switch (width) { | ||
637 | case 2: | ||
638 | for (i = 0; i < fifo_fill; i++) | ||
639 | *((u16 *)start + i) = | ||
640 | (u16)(fsi_reg_read(fsi, DIDT) >> 8); | ||
641 | break; | ||
642 | case 4: | ||
643 | for (i = 0; i < fifo_fill; i++) | ||
644 | *((u32 *)start + i) = fsi_reg_read(fsi, DIDT); | ||
645 | break; | ||
646 | default: | ||
647 | return -EINVAL; | ||
648 | } | ||
649 | |||
650 | fsi->byte_offset += fifo_fill * width; | ||
651 | |||
652 | status = fsi_reg_read(fsi, DIFF_ST); | ||
653 | if (!startup) { | ||
654 | struct snd_soc_dai *dai = fsi_get_dai(substream); | ||
655 | |||
656 | if (status & ERR_OVER) | ||
657 | dev_err(dai->dev, "over run\n"); | ||
658 | if (status & ERR_UNDER) | ||
659 | dev_err(dai->dev, "under run\n"); | ||
660 | } | ||
661 | fsi_reg_write(fsi, DIFF_ST, 0); | ||
662 | |||
663 | fsi_irq_enable(fsi, 0); | ||
664 | |||
665 | if (over_period) | ||
666 | snd_pcm_period_elapsed(substream); | ||
667 | 724 | ||
668 | return 0; | 725 | static int fsi_data_push(struct fsi_priv *fsi, int startup) |
726 | { | ||
727 | return fsi_fifo_data_ctrl(fsi, startup, SNDRV_PCM_STREAM_PLAYBACK); | ||
669 | } | 728 | } |
670 | 729 | ||
671 | static irqreturn_t fsi_interrupt(int irq, void *data) | 730 | static irqreturn_t fsi_interrupt(int irq, void *data) |
@@ -677,13 +736,13 @@ static irqreturn_t fsi_interrupt(int irq, void *data) | |||
677 | fsi_master_mask_set(master, SOFT_RST, IR, 0); | 736 | fsi_master_mask_set(master, SOFT_RST, IR, 0); |
678 | fsi_master_mask_set(master, SOFT_RST, IR, IR); | 737 | fsi_master_mask_set(master, SOFT_RST, IR, IR); |
679 | 738 | ||
680 | if (int_st & INT_A_OUT) | 739 | if (int_st & AB_IO(1, AO_SHIFT)) |
681 | fsi_data_push(&master->fsia, 0); | 740 | fsi_data_push(&master->fsia, 0); |
682 | if (int_st & INT_B_OUT) | 741 | if (int_st & AB_IO(1, BO_SHIFT)) |
683 | fsi_data_push(&master->fsib, 0); | 742 | fsi_data_push(&master->fsib, 0); |
684 | if (int_st & INT_A_IN) | 743 | if (int_st & AB_IO(1, AI_SHIFT)) |
685 | fsi_data_pop(&master->fsia, 0); | 744 | fsi_data_pop(&master->fsia, 0); |
686 | if (int_st & INT_B_IN) | 745 | if (int_st & AB_IO(1, BI_SHIFT)) |
687 | fsi_data_pop(&master->fsib, 0); | 746 | fsi_data_pop(&master->fsib, 0); |
688 | 747 | ||
689 | fsi_irq_clear_all_status(master); | 748 | fsi_irq_clear_all_status(master); |
@@ -691,25 +750,24 @@ static irqreturn_t fsi_interrupt(int irq, void *data) | |||
691 | return IRQ_HANDLED; | 750 | return IRQ_HANDLED; |
692 | } | 751 | } |
693 | 752 | ||
694 | /************************************************************************ | 753 | /* |
695 | 754 | * dai ops | |
696 | 755 | */ | |
697 | dai ops | ||
698 | |||
699 | 756 | ||
700 | ************************************************************************/ | ||
701 | static int fsi_dai_startup(struct snd_pcm_substream *substream, | 757 | static int fsi_dai_startup(struct snd_pcm_substream *substream, |
702 | struct snd_soc_dai *dai) | 758 | struct snd_soc_dai *dai) |
703 | { | 759 | { |
704 | struct fsi_priv *fsi = fsi_get_priv(substream); | 760 | struct fsi_priv *fsi = fsi_get_priv(substream); |
705 | u32 flags = fsi_get_info_flags(fsi); | ||
706 | struct fsi_master *master = fsi_get_master(fsi); | 761 | struct fsi_master *master = fsi_get_master(fsi); |
762 | struct fsi_stream *io; | ||
763 | u32 flags = fsi_get_info_flags(fsi); | ||
707 | u32 fmt; | 764 | u32 fmt; |
708 | u32 reg; | 765 | u32 reg; |
709 | u32 data; | 766 | u32 data; |
710 | int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); | 767 | int is_play = fsi_is_play(substream); |
711 | int is_master; | 768 | int is_master; |
712 | int ret = 0; | 769 | |
770 | io = fsi_get_stream(fsi, is_play); | ||
713 | 771 | ||
714 | pm_runtime_get_sync(dai->dev); | 772 | pm_runtime_get_sync(dai->dev); |
715 | 773 | ||
@@ -741,29 +799,29 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
741 | switch (fmt) { | 799 | switch (fmt) { |
742 | case SH_FSI_FMT_MONO: | 800 | case SH_FSI_FMT_MONO: |
743 | data = CR_MONO; | 801 | data = CR_MONO; |
744 | fsi->chan = 1; | 802 | io->chan_num = 1; |
745 | break; | 803 | break; |
746 | case SH_FSI_FMT_MONO_DELAY: | 804 | case SH_FSI_FMT_MONO_DELAY: |
747 | data = CR_MONO_D; | 805 | data = CR_MONO_D; |
748 | fsi->chan = 1; | 806 | io->chan_num = 1; |
749 | break; | 807 | break; |
750 | case SH_FSI_FMT_PCM: | 808 | case SH_FSI_FMT_PCM: |
751 | data = CR_PCM; | 809 | data = CR_PCM; |
752 | fsi->chan = 2; | 810 | io->chan_num = 2; |
753 | break; | 811 | break; |
754 | case SH_FSI_FMT_I2S: | 812 | case SH_FSI_FMT_I2S: |
755 | data = CR_I2S; | 813 | data = CR_I2S; |
756 | fsi->chan = 2; | 814 | io->chan_num = 2; |
757 | break; | 815 | break; |
758 | case SH_FSI_FMT_TDM: | 816 | case SH_FSI_FMT_TDM: |
759 | fsi->chan = is_play ? | 817 | io->chan_num = is_play ? |
760 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); | 818 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
761 | data = CR_TDM | (fsi->chan - 1); | 819 | data = CR_TDM | (io->chan_num - 1); |
762 | break; | 820 | break; |
763 | case SH_FSI_FMT_TDM_DELAY: | 821 | case SH_FSI_FMT_TDM_DELAY: |
764 | fsi->chan = is_play ? | 822 | io->chan_num = is_play ? |
765 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); | 823 | SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags); |
766 | data = CR_TDM_D | (fsi->chan - 1); | 824 | data = CR_TDM_D | (io->chan_num - 1); |
767 | break; | 825 | break; |
768 | case SH_FSI_FMT_SPDIF: | 826 | case SH_FSI_FMT_SPDIF: |
769 | if (master->core->ver < 2) { | 827 | if (master->core->ver < 2) { |
@@ -771,7 +829,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
771 | return -EINVAL; | 829 | return -EINVAL; |
772 | } | 830 | } |
773 | data = CR_SPDIF; | 831 | data = CR_SPDIF; |
774 | fsi->chan = 2; | 832 | io->chan_num = 2; |
775 | fsi_spdif_clk_ctrl(fsi, 1); | 833 | fsi_spdif_clk_ctrl(fsi, 1); |
776 | fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010); | 834 | fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010); |
777 | break; | 835 | break; |
@@ -788,14 +846,14 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, | |||
788 | /* fifo init */ | 846 | /* fifo init */ |
789 | fsi_fifo_init(fsi, is_play, dai); | 847 | fsi_fifo_init(fsi, is_play, dai); |
790 | 848 | ||
791 | return ret; | 849 | return 0; |
792 | } | 850 | } |
793 | 851 | ||
794 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, | 852 | static void fsi_dai_shutdown(struct snd_pcm_substream *substream, |
795 | struct snd_soc_dai *dai) | 853 | struct snd_soc_dai *dai) |
796 | { | 854 | { |
797 | struct fsi_priv *fsi = fsi_get_priv(substream); | 855 | struct fsi_priv *fsi = fsi_get_priv(substream); |
798 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; | 856 | int is_play = fsi_is_play(substream); |
799 | 857 | ||
800 | fsi_irq_disable(fsi, is_play); | 858 | fsi_irq_disable(fsi, is_play); |
801 | fsi_clk_ctrl(fsi, 0); | 859 | fsi_clk_ctrl(fsi, 0); |
@@ -808,19 +866,19 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, | |||
808 | { | 866 | { |
809 | struct fsi_priv *fsi = fsi_get_priv(substream); | 867 | struct fsi_priv *fsi = fsi_get_priv(substream); |
810 | struct snd_pcm_runtime *runtime = substream->runtime; | 868 | struct snd_pcm_runtime *runtime = substream->runtime; |
811 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; | 869 | int is_play = fsi_is_play(substream); |
812 | int ret = 0; | 870 | int ret = 0; |
813 | 871 | ||
814 | switch (cmd) { | 872 | switch (cmd) { |
815 | case SNDRV_PCM_TRIGGER_START: | 873 | case SNDRV_PCM_TRIGGER_START: |
816 | fsi_stream_push(fsi, substream, | 874 | fsi_stream_push(fsi, is_play, substream, |
817 | frames_to_bytes(runtime, runtime->buffer_size), | 875 | frames_to_bytes(runtime, runtime->buffer_size), |
818 | frames_to_bytes(runtime, runtime->period_size)); | 876 | frames_to_bytes(runtime, runtime->period_size)); |
819 | ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1); | 877 | ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1); |
820 | break; | 878 | break; |
821 | case SNDRV_PCM_TRIGGER_STOP: | 879 | case SNDRV_PCM_TRIGGER_STOP: |
822 | fsi_irq_disable(fsi, is_play); | 880 | fsi_irq_disable(fsi, is_play); |
823 | fsi_stream_pop(fsi); | 881 | fsi_stream_pop(fsi, is_play); |
824 | break; | 882 | break; |
825 | } | 883 | } |
826 | 884 | ||
@@ -835,7 +893,7 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream, | |||
835 | struct fsi_master *master = fsi_get_master(fsi); | 893 | struct fsi_master *master = fsi_get_master(fsi); |
836 | int (*set_rate)(int is_porta, int rate) = master->info->set_rate; | 894 | int (*set_rate)(int is_porta, int rate) = master->info->set_rate; |
837 | int fsi_ver = master->core->ver; | 895 | int fsi_ver = master->core->ver; |
838 | int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); | 896 | int is_play = fsi_is_play(substream); |
839 | int ret; | 897 | int ret; |
840 | 898 | ||
841 | /* if slave mode, set_rate is not needed */ | 899 | /* if slave mode, set_rate is not needed */ |
@@ -916,13 +974,10 @@ static struct snd_soc_dai_ops fsi_dai_ops = { | |||
916 | .hw_params = fsi_dai_hw_params, | 974 | .hw_params = fsi_dai_hw_params, |
917 | }; | 975 | }; |
918 | 976 | ||
919 | /************************************************************************ | 977 | /* |
920 | 978 | * pcm ops | |
921 | 979 | */ | |
922 | pcm ops | ||
923 | |||
924 | 980 | ||
925 | ************************************************************************/ | ||
926 | static struct snd_pcm_hardware fsi_pcm_hardware = { | 981 | static struct snd_pcm_hardware fsi_pcm_hardware = { |
927 | .info = SNDRV_PCM_INFO_INTERLEAVED | | 982 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
928 | SNDRV_PCM_INFO_MMAP | | 983 | SNDRV_PCM_INFO_MMAP | |
@@ -971,9 +1026,10 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream) | |||
971 | { | 1026 | { |
972 | struct snd_pcm_runtime *runtime = substream->runtime; | 1027 | struct snd_pcm_runtime *runtime = substream->runtime; |
973 | struct fsi_priv *fsi = fsi_get_priv(substream); | 1028 | struct fsi_priv *fsi = fsi_get_priv(substream); |
1029 | struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream)); | ||
974 | long location; | 1030 | long location; |
975 | 1031 | ||
976 | location = (fsi->byte_offset - 1); | 1032 | location = (io->buff_offset - 1); |
977 | if (location < 0) | 1033 | if (location < 0) |
978 | location = 0; | 1034 | location = 0; |
979 | 1035 | ||
@@ -988,13 +1044,10 @@ static struct snd_pcm_ops fsi_pcm_ops = { | |||
988 | .pointer = fsi_pointer, | 1044 | .pointer = fsi_pointer, |
989 | }; | 1045 | }; |
990 | 1046 | ||
991 | /************************************************************************ | 1047 | /* |
992 | 1048 | * snd_soc_platform | |
993 | 1049 | */ | |
994 | snd_soc_platform | ||
995 | |||
996 | 1050 | ||
997 | ************************************************************************/ | ||
998 | #define PREALLOC_BUFFER (32 * 1024) | 1051 | #define PREALLOC_BUFFER (32 * 1024) |
999 | #define PREALLOC_BUFFER_MAX (32 * 1024) | 1052 | #define PREALLOC_BUFFER_MAX (32 * 1024) |
1000 | 1053 | ||
@@ -1018,17 +1071,13 @@ static int fsi_pcm_new(struct snd_card *card, | |||
1018 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); | 1071 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); |
1019 | } | 1072 | } |
1020 | 1073 | ||
1021 | /************************************************************************ | 1074 | /* |
1022 | 1075 | * alsa struct | |
1023 | 1076 | */ | |
1024 | alsa struct | ||
1025 | |||
1026 | 1077 | ||
1027 | ************************************************************************/ | 1078 | static struct snd_soc_dai_driver fsi_soc_dai[] = { |
1028 | struct snd_soc_dai fsi_soc_dai[] = { | ||
1029 | { | 1079 | { |
1030 | .name = "FSIA", | 1080 | .name = "fsia-dai", |
1031 | .id = 0, | ||
1032 | .playback = { | 1081 | .playback = { |
1033 | .rates = FSI_RATES, | 1082 | .rates = FSI_RATES, |
1034 | .formats = FSI_FMTS, | 1083 | .formats = FSI_FMTS, |
@@ -1044,8 +1093,7 @@ struct snd_soc_dai fsi_soc_dai[] = { | |||
1044 | .ops = &fsi_dai_ops, | 1093 | .ops = &fsi_dai_ops, |
1045 | }, | 1094 | }, |
1046 | { | 1095 | { |
1047 | .name = "FSIB", | 1096 | .name = "fsib-dai", |
1048 | .id = 1, | ||
1049 | .playback = { | 1097 | .playback = { |
1050 | .rates = FSI_RATES, | 1098 | .rates = FSI_RATES, |
1051 | .formats = FSI_FMTS, | 1099 | .formats = FSI_FMTS, |
@@ -1061,23 +1109,17 @@ struct snd_soc_dai fsi_soc_dai[] = { | |||
1061 | .ops = &fsi_dai_ops, | 1109 | .ops = &fsi_dai_ops, |
1062 | }, | 1110 | }, |
1063 | }; | 1111 | }; |
1064 | EXPORT_SYMBOL_GPL(fsi_soc_dai); | ||
1065 | 1112 | ||
1066 | struct snd_soc_platform fsi_soc_platform = { | 1113 | static struct snd_soc_platform_driver fsi_soc_platform = { |
1067 | .name = "fsi-pcm", | 1114 | .ops = &fsi_pcm_ops, |
1068 | .pcm_ops = &fsi_pcm_ops, | ||
1069 | .pcm_new = fsi_pcm_new, | 1115 | .pcm_new = fsi_pcm_new, |
1070 | .pcm_free = fsi_pcm_free, | 1116 | .pcm_free = fsi_pcm_free, |
1071 | }; | 1117 | }; |
1072 | EXPORT_SYMBOL_GPL(fsi_soc_platform); | ||
1073 | |||
1074 | /************************************************************************ | ||
1075 | |||
1076 | |||
1077 | platform function | ||
1078 | 1118 | ||
1119 | /* | ||
1120 | * platform function | ||
1121 | */ | ||
1079 | 1122 | ||
1080 | ************************************************************************/ | ||
1081 | static int fsi_probe(struct platform_device *pdev) | 1123 | static int fsi_probe(struct platform_device *pdev) |
1082 | { | 1124 | { |
1083 | struct fsi_master *master; | 1125 | struct fsi_master *master; |
@@ -1132,11 +1174,7 @@ static int fsi_probe(struct platform_device *pdev) | |||
1132 | 1174 | ||
1133 | pm_runtime_enable(&pdev->dev); | 1175 | pm_runtime_enable(&pdev->dev); |
1134 | pm_runtime_resume(&pdev->dev); | 1176 | pm_runtime_resume(&pdev->dev); |
1135 | 1177 | dev_set_drvdata(&pdev->dev, master); | |
1136 | fsi_soc_dai[0].dev = &pdev->dev; | ||
1137 | fsi_soc_dai[0].private_data = &master->fsia; | ||
1138 | fsi_soc_dai[1].dev = &pdev->dev; | ||
1139 | fsi_soc_dai[1].private_data = &master->fsib; | ||
1140 | 1178 | ||
1141 | fsi_soft_all_reset(master); | 1179 | fsi_soft_all_reset(master); |
1142 | 1180 | ||
@@ -1147,13 +1185,13 @@ static int fsi_probe(struct platform_device *pdev) | |||
1147 | goto exit_iounmap; | 1185 | goto exit_iounmap; |
1148 | } | 1186 | } |
1149 | 1187 | ||
1150 | ret = snd_soc_register_platform(&fsi_soc_platform); | 1188 | ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform); |
1151 | if (ret < 0) { | 1189 | if (ret < 0) { |
1152 | dev_err(&pdev->dev, "cannot snd soc register\n"); | 1190 | dev_err(&pdev->dev, "cannot snd soc register\n"); |
1153 | goto exit_free_irq; | 1191 | goto exit_free_irq; |
1154 | } | 1192 | } |
1155 | 1193 | ||
1156 | return snd_soc_register_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); | 1194 | return snd_soc_register_dais(&pdev->dev, fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); |
1157 | 1195 | ||
1158 | exit_free_irq: | 1196 | exit_free_irq: |
1159 | free_irq(irq, master); | 1197 | free_irq(irq, master); |
@@ -1171,10 +1209,10 @@ static int fsi_remove(struct platform_device *pdev) | |||
1171 | { | 1209 | { |
1172 | struct fsi_master *master; | 1210 | struct fsi_master *master; |
1173 | 1211 | ||
1174 | master = fsi_get_master(fsi_soc_dai[0].private_data); | 1212 | master = dev_get_drvdata(&pdev->dev); |
1175 | 1213 | ||
1176 | snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); | 1214 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai)); |
1177 | snd_soc_unregister_platform(&fsi_soc_platform); | 1215 | snd_soc_unregister_platform(&pdev->dev); |
1178 | 1216 | ||
1179 | pm_runtime_disable(&pdev->dev); | 1217 | pm_runtime_disable(&pdev->dev); |
1180 | 1218 | ||
@@ -1183,11 +1221,6 @@ static int fsi_remove(struct platform_device *pdev) | |||
1183 | iounmap(master->base); | 1221 | iounmap(master->base); |
1184 | kfree(master); | 1222 | kfree(master); |
1185 | 1223 | ||
1186 | fsi_soc_dai[0].dev = NULL; | ||
1187 | fsi_soc_dai[0].private_data = NULL; | ||
1188 | fsi_soc_dai[1].dev = NULL; | ||
1189 | fsi_soc_dai[1].private_data = NULL; | ||
1190 | |||
1191 | return 0; | 1224 | return 0; |
1192 | } | 1225 | } |
1193 | 1226 | ||
@@ -1229,11 +1262,13 @@ static struct fsi_core fsi2_core = { | |||
1229 | static struct platform_device_id fsi_id_table[] = { | 1262 | static struct platform_device_id fsi_id_table[] = { |
1230 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, | 1263 | { "sh_fsi", (kernel_ulong_t)&fsi1_core }, |
1231 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, | 1264 | { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, |
1265 | {}, | ||
1232 | }; | 1266 | }; |
1267 | MODULE_DEVICE_TABLE(platform, fsi_id_table); | ||
1233 | 1268 | ||
1234 | static struct platform_driver fsi_driver = { | 1269 | static struct platform_driver fsi_driver = { |
1235 | .driver = { | 1270 | .driver = { |
1236 | .name = "sh_fsi", | 1271 | .name = "fsi-pcm-audio", |
1237 | .pm = &fsi_pm_ops, | 1272 | .pm = &fsi_pm_ops, |
1238 | }, | 1273 | }, |
1239 | .probe = fsi_probe, | 1274 | .probe = fsi_probe, |
@@ -1250,6 +1285,7 @@ static void __exit fsi_mobile_exit(void) | |||
1250 | { | 1285 | { |
1251 | platform_driver_unregister(&fsi_driver); | 1286 | platform_driver_unregister(&fsi_driver); |
1252 | } | 1287 | } |
1288 | |||
1253 | module_init(fsi_mobile_init); | 1289 | module_init(fsi_mobile_init); |
1254 | module_exit(fsi_mobile_exit); | 1290 | module_exit(fsi_mobile_exit); |
1255 | 1291 | ||