diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2012-02-14 11:20:58 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@ti.com> | 2012-03-12 09:34:19 -0400 |
commit | 45656b44f6d1968d838f3abcf3a264ee9fa2fc62 (patch) | |
tree | af489389d8565bdd83f756115239524814b902d9 /sound/soc/omap/mcbsp.c | |
parent | 219f43164e8c611c6b8e7b628def9183098b430b (diff) |
ASoC: omap-mcbsp: Create a single driver for McBSP
The OMAP McBSP driver stack used to contain two different
drivers. One of them was used as kind low-level access to
the IP, while the other driver was the ASoC DAI driver.
There were global, shared structures, in different places,
the McBSP instances are reffered with id numbers (sometimes
0 based, in other cases 1 based id numbers).
Create one single driver for OMAP McBSP with name: omap-mcbsp.
Convert the old omap-mcbsp driver initially to be a library
for the omap-mcbsp DAI driver. With this change we can get rid
of all global variables, structures.
Further cleanup is coming...
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
Tested-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Signed-off-by: Liam Girdwood <lrg@ti.com>
Diffstat (limited to 'sound/soc/omap/mcbsp.c')
-rw-r--r-- | sound/soc/omap/mcbsp.c | 284 |
1 files changed, 38 insertions, 246 deletions
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c index 20d46bf3626b..be92a28e19ed 100644 --- a/sound/soc/omap/mcbsp.c +++ b/sound/soc/omap/mcbsp.c | |||
@@ -30,12 +30,6 @@ | |||
30 | 30 | ||
31 | #include "mcbsp.h" | 31 | #include "mcbsp.h" |
32 | 32 | ||
33 | struct omap_mcbsp **mcbsp_ptr; | ||
34 | int omap_mcbsp_count; | ||
35 | |||
36 | #define omap_mcbsp_check_valid_id(id) (id < omap_mcbsp_count) | ||
37 | #define id_to_mcbsp_ptr(id) mcbsp_ptr[id]; | ||
38 | |||
39 | static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) | 33 | static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) |
40 | { | 34 | { |
41 | void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step; | 35 | void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step; |
@@ -84,10 +78,8 @@ static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg) | |||
84 | #define MCBSP_ST_WRITE(mcbsp, reg, val) \ | 78 | #define MCBSP_ST_WRITE(mcbsp, reg, val) \ |
85 | omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val) | 79 | omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val) |
86 | 80 | ||
87 | static void omap_mcbsp_dump_reg(u8 id) | 81 | static void omap_mcbsp_dump_reg(struct omap_mcbsp *mcbsp) |
88 | { | 82 | { |
89 | struct omap_mcbsp *mcbsp = id_to_mcbsp_ptr(id); | ||
90 | |||
91 | dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id); | 83 | dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id); |
92 | dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n", | 84 | dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n", |
93 | MCBSP_READ(mcbsp, DRR2)); | 85 | MCBSP_READ(mcbsp, DRR2)); |
@@ -160,16 +152,9 @@ static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id) | |||
160 | * You either call this function or set the McBSP registers | 152 | * You either call this function or set the McBSP registers |
161 | * by yourself before calling omap_mcbsp_start(). | 153 | * by yourself before calling omap_mcbsp_start(). |
162 | */ | 154 | */ |
163 | void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config) | 155 | void omap_mcbsp_config(struct omap_mcbsp *mcbsp, |
156 | const struct omap_mcbsp_reg_cfg *config) | ||
164 | { | 157 | { |
165 | struct omap_mcbsp *mcbsp; | ||
166 | |||
167 | if (!omap_mcbsp_check_valid_id(id)) { | ||
168 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
169 | return; | ||
170 | } | ||
171 | mcbsp = id_to_mcbsp_ptr(id); | ||
172 | |||
173 | dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n", | 158 | dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n", |
174 | mcbsp->id, mcbsp->phys_base); | 159 | mcbsp->id, mcbsp->phys_base); |
175 | 160 | ||
@@ -190,7 +175,6 @@ void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config) | |||
190 | MCBSP_WRITE(mcbsp, RCCR, config->rccr); | 175 | MCBSP_WRITE(mcbsp, RCCR, config->rccr); |
191 | } | 176 | } |
192 | } | 177 | } |
193 | EXPORT_SYMBOL(omap_mcbsp_config); | ||
194 | 178 | ||
195 | /** | 179 | /** |
196 | * omap_mcbsp_dma_params - returns the dma channel number | 180 | * omap_mcbsp_dma_params - returns the dma channel number |
@@ -200,22 +184,13 @@ EXPORT_SYMBOL(omap_mcbsp_config); | |||
200 | * Returns the dma channel number for the rx channel or tx channel | 184 | * Returns the dma channel number for the rx channel or tx channel |
201 | * based on the value of @stream for the requested mcbsp given by @id | 185 | * based on the value of @stream for the requested mcbsp given by @id |
202 | */ | 186 | */ |
203 | int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream) | 187 | int omap_mcbsp_dma_ch_params(struct omap_mcbsp *mcbsp, unsigned int stream) |
204 | { | 188 | { |
205 | struct omap_mcbsp *mcbsp; | ||
206 | |||
207 | if (!omap_mcbsp_check_valid_id(id)) { | ||
208 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
209 | return -ENODEV; | ||
210 | } | ||
211 | mcbsp = id_to_mcbsp_ptr(id); | ||
212 | |||
213 | if (stream) | 189 | if (stream) |
214 | return mcbsp->dma_rx_sync; | 190 | return mcbsp->dma_rx_sync; |
215 | else | 191 | else |
216 | return mcbsp->dma_tx_sync; | 192 | return mcbsp->dma_tx_sync; |
217 | } | 193 | } |
218 | EXPORT_SYMBOL(omap_mcbsp_dma_ch_params); | ||
219 | 194 | ||
220 | /** | 195 | /** |
221 | * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register | 196 | * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register |
@@ -226,17 +201,10 @@ EXPORT_SYMBOL(omap_mcbsp_dma_ch_params); | |||
226 | * to be used by DMA for transferring/receiving data based on the value of | 201 | * to be used by DMA for transferring/receiving data based on the value of |
227 | * @stream for the requested mcbsp given by @id | 202 | * @stream for the requested mcbsp given by @id |
228 | */ | 203 | */ |
229 | int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream) | 204 | int omap_mcbsp_dma_reg_params(struct omap_mcbsp *mcbsp, unsigned int stream) |
230 | { | 205 | { |
231 | struct omap_mcbsp *mcbsp; | ||
232 | int data_reg; | 206 | int data_reg; |
233 | 207 | ||
234 | if (!omap_mcbsp_check_valid_id(id)) { | ||
235 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
236 | return -ENODEV; | ||
237 | } | ||
238 | mcbsp = id_to_mcbsp_ptr(id); | ||
239 | |||
240 | if (mcbsp->pdata->reg_size == 2) { | 208 | if (mcbsp->pdata->reg_size == 2) { |
241 | if (stream) | 209 | if (stream) |
242 | data_reg = OMAP_MCBSP_REG_DRR1; | 210 | data_reg = OMAP_MCBSP_REG_DRR1; |
@@ -251,7 +219,6 @@ int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream) | |||
251 | 219 | ||
252 | return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step; | 220 | return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step; |
253 | } | 221 | } |
254 | EXPORT_SYMBOL(omap_mcbsp_dma_reg_params); | ||
255 | 222 | ||
256 | static void omap_st_on(struct omap_mcbsp *mcbsp) | 223 | static void omap_st_on(struct omap_mcbsp *mcbsp) |
257 | { | 224 | { |
@@ -320,18 +287,11 @@ static void omap_st_chgain(struct omap_mcbsp *mcbsp) | |||
320 | ST_CH1GAIN(st_data->ch1gain)); | 287 | ST_CH1GAIN(st_data->ch1gain)); |
321 | } | 288 | } |
322 | 289 | ||
323 | int omap_st_set_chgain(unsigned int id, int channel, s16 chgain) | 290 | int omap_st_set_chgain(struct omap_mcbsp *mcbsp, int channel, s16 chgain) |
324 | { | 291 | { |
325 | struct omap_mcbsp *mcbsp; | ||
326 | struct omap_mcbsp_st_data *st_data; | 292 | struct omap_mcbsp_st_data *st_data; |
327 | int ret = 0; | 293 | int ret = 0; |
328 | 294 | ||
329 | if (!omap_mcbsp_check_valid_id(id)) { | ||
330 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
331 | return -ENODEV; | ||
332 | } | ||
333 | |||
334 | mcbsp = id_to_mcbsp_ptr(id); | ||
335 | st_data = mcbsp->st_data; | 295 | st_data = mcbsp->st_data; |
336 | 296 | ||
337 | if (!st_data) | 297 | if (!st_data) |
@@ -351,20 +311,12 @@ int omap_st_set_chgain(unsigned int id, int channel, s16 chgain) | |||
351 | 311 | ||
352 | return ret; | 312 | return ret; |
353 | } | 313 | } |
354 | EXPORT_SYMBOL(omap_st_set_chgain); | ||
355 | 314 | ||
356 | int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain) | 315 | int omap_st_get_chgain(struct omap_mcbsp *mcbsp, int channel, s16 *chgain) |
357 | { | 316 | { |
358 | struct omap_mcbsp *mcbsp; | ||
359 | struct omap_mcbsp_st_data *st_data; | 317 | struct omap_mcbsp_st_data *st_data; |
360 | int ret = 0; | 318 | int ret = 0; |
361 | 319 | ||
362 | if (!omap_mcbsp_check_valid_id(id)) { | ||
363 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
364 | return -ENODEV; | ||
365 | } | ||
366 | |||
367 | mcbsp = id_to_mcbsp_ptr(id); | ||
368 | st_data = mcbsp->st_data; | 320 | st_data = mcbsp->st_data; |
369 | 321 | ||
370 | if (!st_data) | 322 | if (!st_data) |
@@ -381,7 +333,6 @@ int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain) | |||
381 | 333 | ||
382 | return ret; | 334 | return ret; |
383 | } | 335 | } |
384 | EXPORT_SYMBOL(omap_st_get_chgain); | ||
385 | 336 | ||
386 | static int omap_st_start(struct omap_mcbsp *mcbsp) | 337 | static int omap_st_start(struct omap_mcbsp *mcbsp) |
387 | { | 338 | { |
@@ -400,17 +351,10 @@ static int omap_st_start(struct omap_mcbsp *mcbsp) | |||
400 | return 0; | 351 | return 0; |
401 | } | 352 | } |
402 | 353 | ||
403 | int omap_st_enable(unsigned int id) | 354 | int omap_st_enable(struct omap_mcbsp *mcbsp) |
404 | { | 355 | { |
405 | struct omap_mcbsp *mcbsp; | ||
406 | struct omap_mcbsp_st_data *st_data; | 356 | struct omap_mcbsp_st_data *st_data; |
407 | 357 | ||
408 | if (!omap_mcbsp_check_valid_id(id)) { | ||
409 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
410 | return -ENODEV; | ||
411 | } | ||
412 | |||
413 | mcbsp = id_to_mcbsp_ptr(id); | ||
414 | st_data = mcbsp->st_data; | 358 | st_data = mcbsp->st_data; |
415 | 359 | ||
416 | if (!st_data) | 360 | if (!st_data) |
@@ -423,7 +367,6 @@ int omap_st_enable(unsigned int id) | |||
423 | 367 | ||
424 | return 0; | 368 | return 0; |
425 | } | 369 | } |
426 | EXPORT_SYMBOL(omap_st_enable); | ||
427 | 370 | ||
428 | static int omap_st_stop(struct omap_mcbsp *mcbsp) | 371 | static int omap_st_stop(struct omap_mcbsp *mcbsp) |
429 | { | 372 | { |
@@ -439,18 +382,11 @@ static int omap_st_stop(struct omap_mcbsp *mcbsp) | |||
439 | return 0; | 382 | return 0; |
440 | } | 383 | } |
441 | 384 | ||
442 | int omap_st_disable(unsigned int id) | 385 | int omap_st_disable(struct omap_mcbsp *mcbsp) |
443 | { | 386 | { |
444 | struct omap_mcbsp *mcbsp; | ||
445 | struct omap_mcbsp_st_data *st_data; | 387 | struct omap_mcbsp_st_data *st_data; |
446 | int ret = 0; | 388 | int ret = 0; |
447 | 389 | ||
448 | if (!omap_mcbsp_check_valid_id(id)) { | ||
449 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
450 | return -ENODEV; | ||
451 | } | ||
452 | |||
453 | mcbsp = id_to_mcbsp_ptr(id); | ||
454 | st_data = mcbsp->st_data; | 390 | st_data = mcbsp->st_data; |
455 | 391 | ||
456 | if (!st_data) | 392 | if (!st_data) |
@@ -463,19 +399,11 @@ int omap_st_disable(unsigned int id) | |||
463 | 399 | ||
464 | return ret; | 400 | return ret; |
465 | } | 401 | } |
466 | EXPORT_SYMBOL(omap_st_disable); | ||
467 | 402 | ||
468 | int omap_st_is_enabled(unsigned int id) | 403 | int omap_st_is_enabled(struct omap_mcbsp *mcbsp) |
469 | { | 404 | { |
470 | struct omap_mcbsp *mcbsp; | ||
471 | struct omap_mcbsp_st_data *st_data; | 405 | struct omap_mcbsp_st_data *st_data; |
472 | 406 | ||
473 | if (!omap_mcbsp_check_valid_id(id)) { | ||
474 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
475 | return -ENODEV; | ||
476 | } | ||
477 | |||
478 | mcbsp = id_to_mcbsp_ptr(id); | ||
479 | st_data = mcbsp->st_data; | 407 | st_data = mcbsp->st_data; |
480 | 408 | ||
481 | if (!st_data) | 409 | if (!st_data) |
@@ -484,115 +412,65 @@ int omap_st_is_enabled(unsigned int id) | |||
484 | 412 | ||
485 | return st_data->enabled; | 413 | return st_data->enabled; |
486 | } | 414 | } |
487 | EXPORT_SYMBOL(omap_st_is_enabled); | ||
488 | 415 | ||
489 | /* | 416 | /* |
490 | * omap_mcbsp_set_rx_threshold configures the transmit threshold in words. | 417 | * omap_mcbsp_set_rx_threshold configures the transmit threshold in words. |
491 | * The threshold parameter is 1 based, and it is converted (threshold - 1) | 418 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
492 | * for the THRSH2 register. | 419 | * for the THRSH2 register. |
493 | */ | 420 | */ |
494 | void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold) | 421 | void omap_mcbsp_set_tx_threshold(struct omap_mcbsp *mcbsp, u16 threshold) |
495 | { | 422 | { |
496 | struct omap_mcbsp *mcbsp; | ||
497 | |||
498 | if (!omap_mcbsp_check_valid_id(id)) { | ||
499 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
500 | return; | ||
501 | } | ||
502 | mcbsp = id_to_mcbsp_ptr(id); | ||
503 | if (mcbsp->pdata->buffer_size == 0) | 423 | if (mcbsp->pdata->buffer_size == 0) |
504 | return; | 424 | return; |
505 | 425 | ||
506 | if (threshold && threshold <= mcbsp->max_tx_thres) | 426 | if (threshold && threshold <= mcbsp->max_tx_thres) |
507 | MCBSP_WRITE(mcbsp, THRSH2, threshold - 1); | 427 | MCBSP_WRITE(mcbsp, THRSH2, threshold - 1); |
508 | } | 428 | } |
509 | EXPORT_SYMBOL(omap_mcbsp_set_tx_threshold); | ||
510 | 429 | ||
511 | /* | 430 | /* |
512 | * omap_mcbsp_set_rx_threshold configures the receive threshold in words. | 431 | * omap_mcbsp_set_rx_threshold configures the receive threshold in words. |
513 | * The threshold parameter is 1 based, and it is converted (threshold - 1) | 432 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
514 | * for the THRSH1 register. | 433 | * for the THRSH1 register. |
515 | */ | 434 | */ |
516 | void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold) | 435 | void omap_mcbsp_set_rx_threshold(struct omap_mcbsp *mcbsp, u16 threshold) |
517 | { | 436 | { |
518 | struct omap_mcbsp *mcbsp; | ||
519 | |||
520 | if (!omap_mcbsp_check_valid_id(id)) { | ||
521 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
522 | return; | ||
523 | } | ||
524 | mcbsp = id_to_mcbsp_ptr(id); | ||
525 | if (mcbsp->pdata->buffer_size == 0) | 437 | if (mcbsp->pdata->buffer_size == 0) |
526 | return; | 438 | return; |
527 | 439 | ||
528 | if (threshold && threshold <= mcbsp->max_rx_thres) | 440 | if (threshold && threshold <= mcbsp->max_rx_thres) |
529 | MCBSP_WRITE(mcbsp, THRSH1, threshold - 1); | 441 | MCBSP_WRITE(mcbsp, THRSH1, threshold - 1); |
530 | } | 442 | } |
531 | EXPORT_SYMBOL(omap_mcbsp_set_rx_threshold); | ||
532 | 443 | ||
533 | /* | 444 | /* |
534 | * omap_mcbsp_get_max_tx_thres just return the current configured | 445 | * omap_mcbsp_get_max_tx_thres just return the current configured |
535 | * maximum threshold for transmission | 446 | * maximum threshold for transmission |
536 | */ | 447 | */ |
537 | u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) | 448 | u16 omap_mcbsp_get_max_tx_threshold(struct omap_mcbsp *mcbsp) |
538 | { | 449 | { |
539 | struct omap_mcbsp *mcbsp; | ||
540 | |||
541 | if (!omap_mcbsp_check_valid_id(id)) { | ||
542 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
543 | return -ENODEV; | ||
544 | } | ||
545 | mcbsp = id_to_mcbsp_ptr(id); | ||
546 | |||
547 | return mcbsp->max_tx_thres; | 450 | return mcbsp->max_tx_thres; |
548 | } | 451 | } |
549 | EXPORT_SYMBOL(omap_mcbsp_get_max_tx_threshold); | ||
550 | 452 | ||
551 | /* | 453 | /* |
552 | * omap_mcbsp_get_max_rx_thres just return the current configured | 454 | * omap_mcbsp_get_max_rx_thres just return the current configured |
553 | * maximum threshold for reception | 455 | * maximum threshold for reception |
554 | */ | 456 | */ |
555 | u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) | 457 | u16 omap_mcbsp_get_max_rx_threshold(struct omap_mcbsp *mcbsp) |
556 | { | 458 | { |
557 | struct omap_mcbsp *mcbsp; | ||
558 | |||
559 | if (!omap_mcbsp_check_valid_id(id)) { | ||
560 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
561 | return -ENODEV; | ||
562 | } | ||
563 | mcbsp = id_to_mcbsp_ptr(id); | ||
564 | |||
565 | return mcbsp->max_rx_thres; | 459 | return mcbsp->max_rx_thres; |
566 | } | 460 | } |
567 | EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold); | ||
568 | 461 | ||
569 | u16 omap_mcbsp_get_fifo_size(unsigned int id) | 462 | u16 omap_mcbsp_get_fifo_size(struct omap_mcbsp *mcbsp) |
570 | { | 463 | { |
571 | struct omap_mcbsp *mcbsp; | ||
572 | |||
573 | if (!omap_mcbsp_check_valid_id(id)) { | ||
574 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
575 | return -ENODEV; | ||
576 | } | ||
577 | mcbsp = id_to_mcbsp_ptr(id); | ||
578 | |||
579 | return mcbsp->pdata->buffer_size; | 464 | return mcbsp->pdata->buffer_size; |
580 | } | 465 | } |
581 | EXPORT_SYMBOL(omap_mcbsp_get_fifo_size); | ||
582 | 466 | ||
583 | /* | 467 | /* |
584 | * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO | 468 | * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO |
585 | */ | 469 | */ |
586 | u16 omap_mcbsp_get_tx_delay(unsigned int id) | 470 | u16 omap_mcbsp_get_tx_delay(struct omap_mcbsp *mcbsp) |
587 | { | 471 | { |
588 | struct omap_mcbsp *mcbsp; | ||
589 | u16 buffstat; | 472 | u16 buffstat; |
590 | 473 | ||
591 | if (!omap_mcbsp_check_valid_id(id)) { | ||
592 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
593 | return -ENODEV; | ||
594 | } | ||
595 | mcbsp = id_to_mcbsp_ptr(id); | ||
596 | if (mcbsp->pdata->buffer_size == 0) | 474 | if (mcbsp->pdata->buffer_size == 0) |
597 | return 0; | 475 | return 0; |
598 | 476 | ||
@@ -602,22 +480,15 @@ u16 omap_mcbsp_get_tx_delay(unsigned int id) | |||
602 | /* Number of slots are different in McBSP ports */ | 480 | /* Number of slots are different in McBSP ports */ |
603 | return mcbsp->pdata->buffer_size - buffstat; | 481 | return mcbsp->pdata->buffer_size - buffstat; |
604 | } | 482 | } |
605 | EXPORT_SYMBOL(omap_mcbsp_get_tx_delay); | ||
606 | 483 | ||
607 | /* | 484 | /* |
608 | * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO | 485 | * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO |
609 | * to reach the threshold value (when the DMA will be triggered to read it) | 486 | * to reach the threshold value (when the DMA will be triggered to read it) |
610 | */ | 487 | */ |
611 | u16 omap_mcbsp_get_rx_delay(unsigned int id) | 488 | u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp) |
612 | { | 489 | { |
613 | struct omap_mcbsp *mcbsp; | ||
614 | u16 buffstat, threshold; | 490 | u16 buffstat, threshold; |
615 | 491 | ||
616 | if (!omap_mcbsp_check_valid_id(id)) { | ||
617 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
618 | return -ENODEV; | ||
619 | } | ||
620 | mcbsp = id_to_mcbsp_ptr(id); | ||
621 | if (mcbsp->pdata->buffer_size == 0) | 492 | if (mcbsp->pdata->buffer_size == 0) |
622 | return 0; | 493 | return 0; |
623 | 494 | ||
@@ -632,41 +503,25 @@ u16 omap_mcbsp_get_rx_delay(unsigned int id) | |||
632 | else | 503 | else |
633 | return threshold - buffstat; | 504 | return threshold - buffstat; |
634 | } | 505 | } |
635 | EXPORT_SYMBOL(omap_mcbsp_get_rx_delay); | ||
636 | 506 | ||
637 | /* | 507 | /* |
638 | * omap_mcbsp_get_dma_op_mode just return the current configured | 508 | * omap_mcbsp_get_dma_op_mode just return the current configured |
639 | * operating mode for the mcbsp channel | 509 | * operating mode for the mcbsp channel |
640 | */ | 510 | */ |
641 | int omap_mcbsp_get_dma_op_mode(unsigned int id) | 511 | int omap_mcbsp_get_dma_op_mode(struct omap_mcbsp *mcbsp) |
642 | { | 512 | { |
643 | struct omap_mcbsp *mcbsp; | ||
644 | int dma_op_mode; | 513 | int dma_op_mode; |
645 | 514 | ||
646 | if (!omap_mcbsp_check_valid_id(id)) { | ||
647 | printk(KERN_ERR "%s: Invalid id (%u)\n", __func__, id + 1); | ||
648 | return -ENODEV; | ||
649 | } | ||
650 | mcbsp = id_to_mcbsp_ptr(id); | ||
651 | |||
652 | dma_op_mode = mcbsp->dma_op_mode; | 515 | dma_op_mode = mcbsp->dma_op_mode; |
653 | 516 | ||
654 | return dma_op_mode; | 517 | return dma_op_mode; |
655 | } | 518 | } |
656 | EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode); | ||
657 | 519 | ||
658 | int omap_mcbsp_request(unsigned int id) | 520 | int omap_mcbsp_request(struct omap_mcbsp *mcbsp) |
659 | { | 521 | { |
660 | struct omap_mcbsp *mcbsp; | ||
661 | void *reg_cache; | 522 | void *reg_cache; |
662 | int err; | 523 | int err; |
663 | 524 | ||
664 | if (!omap_mcbsp_check_valid_id(id)) { | ||
665 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
666 | return -ENODEV; | ||
667 | } | ||
668 | mcbsp = id_to_mcbsp_ptr(id); | ||
669 | |||
670 | reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL); | 525 | reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL); |
671 | if (!reg_cache) { | 526 | if (!reg_cache) { |
672 | return -ENOMEM; | 527 | return -ENOMEM; |
@@ -685,9 +540,7 @@ int omap_mcbsp_request(unsigned int id) | |||
685 | spin_unlock(&mcbsp->lock); | 540 | spin_unlock(&mcbsp->lock); |
686 | 541 | ||
687 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request) | 542 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request) |
688 | mcbsp->pdata->ops->request(id); | 543 | mcbsp->pdata->ops->request(mcbsp->id - 1); |
689 | |||
690 | pm_runtime_get_sync(mcbsp->dev); | ||
691 | 544 | ||
692 | /* Enable wakeup behavior */ | 545 | /* Enable wakeup behavior */ |
693 | if (mcbsp->pdata->has_wakeup) | 546 | if (mcbsp->pdata->has_wakeup) |
@@ -726,14 +579,12 @@ err_free_irq: | |||
726 | free_irq(mcbsp->tx_irq, (void *)mcbsp); | 579 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
727 | err_clk_disable: | 580 | err_clk_disable: |
728 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) | 581 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
729 | mcbsp->pdata->ops->free(id); | 582 | mcbsp->pdata->ops->free(mcbsp->id - 1); |
730 | 583 | ||
731 | /* Disable wakeup behavior */ | 584 | /* Disable wakeup behavior */ |
732 | if (mcbsp->pdata->has_wakeup) | 585 | if (mcbsp->pdata->has_wakeup) |
733 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); | 586 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); |
734 | 587 | ||
735 | pm_runtime_put_sync(mcbsp->dev); | ||
736 | |||
737 | spin_lock(&mcbsp->lock); | 588 | spin_lock(&mcbsp->lock); |
738 | mcbsp->free = true; | 589 | mcbsp->free = true; |
739 | mcbsp->reg_cache = NULL; | 590 | mcbsp->reg_cache = NULL; |
@@ -743,28 +594,18 @@ err_kfree: | |||
743 | 594 | ||
744 | return err; | 595 | return err; |
745 | } | 596 | } |
746 | EXPORT_SYMBOL(omap_mcbsp_request); | ||
747 | 597 | ||
748 | void omap_mcbsp_free(unsigned int id) | 598 | void omap_mcbsp_free(struct omap_mcbsp *mcbsp) |
749 | { | 599 | { |
750 | struct omap_mcbsp *mcbsp; | ||
751 | void *reg_cache; | 600 | void *reg_cache; |
752 | 601 | ||
753 | if (!omap_mcbsp_check_valid_id(id)) { | ||
754 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
755 | return; | ||
756 | } | ||
757 | mcbsp = id_to_mcbsp_ptr(id); | ||
758 | |||
759 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) | 602 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
760 | mcbsp->pdata->ops->free(id); | 603 | mcbsp->pdata->ops->free(mcbsp->id - 1); |
761 | 604 | ||
762 | /* Disable wakeup behavior */ | 605 | /* Disable wakeup behavior */ |
763 | if (mcbsp->pdata->has_wakeup) | 606 | if (mcbsp->pdata->has_wakeup) |
764 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); | 607 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); |
765 | 608 | ||
766 | pm_runtime_put_sync(mcbsp->dev); | ||
767 | |||
768 | if (mcbsp->rx_irq) | 609 | if (mcbsp->rx_irq) |
769 | free_irq(mcbsp->rx_irq, (void *)mcbsp); | 610 | free_irq(mcbsp->rx_irq, (void *)mcbsp); |
770 | free_irq(mcbsp->tx_irq, (void *)mcbsp); | 611 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
@@ -782,25 +623,17 @@ void omap_mcbsp_free(unsigned int id) | |||
782 | if (reg_cache) | 623 | if (reg_cache) |
783 | kfree(reg_cache); | 624 | kfree(reg_cache); |
784 | } | 625 | } |
785 | EXPORT_SYMBOL(omap_mcbsp_free); | ||
786 | 626 | ||
787 | /* | 627 | /* |
788 | * Here we start the McBSP, by enabling transmitter, receiver or both. | 628 | * Here we start the McBSP, by enabling transmitter, receiver or both. |
789 | * If no transmitter or receiver is active prior calling, then sample-rate | 629 | * If no transmitter or receiver is active prior calling, then sample-rate |
790 | * generator and frame sync are started. | 630 | * generator and frame sync are started. |
791 | */ | 631 | */ |
792 | void omap_mcbsp_start(unsigned int id, int tx, int rx) | 632 | void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx) |
793 | { | 633 | { |
794 | struct omap_mcbsp *mcbsp; | ||
795 | int enable_srg = 0; | 634 | int enable_srg = 0; |
796 | u16 w; | 635 | u16 w; |
797 | 636 | ||
798 | if (!omap_mcbsp_check_valid_id(id)) { | ||
799 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
800 | return; | ||
801 | } | ||
802 | mcbsp = id_to_mcbsp_ptr(id); | ||
803 | |||
804 | if (mcbsp->st_data) | 637 | if (mcbsp->st_data) |
805 | omap_st_start(mcbsp); | 638 | omap_st_start(mcbsp); |
806 | 639 | ||
@@ -850,23 +683,14 @@ void omap_mcbsp_start(unsigned int id, int tx, int rx) | |||
850 | } | 683 | } |
851 | 684 | ||
852 | /* Dump McBSP Regs */ | 685 | /* Dump McBSP Regs */ |
853 | omap_mcbsp_dump_reg(id); | 686 | omap_mcbsp_dump_reg(mcbsp); |
854 | } | 687 | } |
855 | EXPORT_SYMBOL(omap_mcbsp_start); | ||
856 | 688 | ||
857 | void omap_mcbsp_stop(unsigned int id, int tx, int rx) | 689 | void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx) |
858 | { | 690 | { |
859 | struct omap_mcbsp *mcbsp; | ||
860 | int idle; | 691 | int idle; |
861 | u16 w; | 692 | u16 w; |
862 | 693 | ||
863 | if (!omap_mcbsp_check_valid_id(id)) { | ||
864 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); | ||
865 | return; | ||
866 | } | ||
867 | |||
868 | mcbsp = id_to_mcbsp_ptr(id); | ||
869 | |||
870 | /* Reset transmitter */ | 694 | /* Reset transmitter */ |
871 | tx &= 1; | 695 | tx &= 1; |
872 | if (mcbsp->pdata->has_ccr) { | 696 | if (mcbsp->pdata->has_ccr) { |
@@ -899,19 +723,11 @@ void omap_mcbsp_stop(unsigned int id, int tx, int rx) | |||
899 | if (mcbsp->st_data) | 723 | if (mcbsp->st_data) |
900 | omap_st_stop(mcbsp); | 724 | omap_st_stop(mcbsp); |
901 | } | 725 | } |
902 | EXPORT_SYMBOL(omap_mcbsp_stop); | ||
903 | 726 | ||
904 | int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id) | 727 | int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id) |
905 | { | 728 | { |
906 | struct omap_mcbsp *mcbsp; | ||
907 | const char *src; | 729 | const char *src; |
908 | 730 | ||
909 | if (!omap_mcbsp_check_valid_id(id)) { | ||
910 | pr_err("%s: Invalid id (%d)\n", __func__, id + 1); | ||
911 | return -EINVAL; | ||
912 | } | ||
913 | mcbsp = id_to_mcbsp_ptr(id); | ||
914 | |||
915 | if (fck_src_id == MCBSP_CLKS_PAD_SRC) | 731 | if (fck_src_id == MCBSP_CLKS_PAD_SRC) |
916 | src = "clks_ext"; | 732 | src = "clks_ext"; |
917 | else if (fck_src_id == MCBSP_CLKS_PRCM_SRC) | 733 | else if (fck_src_id == MCBSP_CLKS_PRCM_SRC) |
@@ -924,13 +740,14 @@ int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id) | |||
924 | else | 740 | else |
925 | return -EINVAL; | 741 | return -EINVAL; |
926 | } | 742 | } |
927 | EXPORT_SYMBOL(omap2_mcbsp_set_clks_src); | ||
928 | 743 | ||
929 | void omap2_mcbsp1_mux_clkr_src(u8 mux) | 744 | void omap2_mcbsp1_mux_clkr_src(struct omap_mcbsp *mcbsp, u8 mux) |
930 | { | 745 | { |
931 | struct omap_mcbsp *mcbsp; | ||
932 | const char *src; | 746 | const char *src; |
933 | 747 | ||
748 | if (mcbsp->id != 1) | ||
749 | return; | ||
750 | |||
934 | if (mux == CLKR_SRC_CLKR) | 751 | if (mux == CLKR_SRC_CLKR) |
935 | src = "clkr"; | 752 | src = "clkr"; |
936 | else if (mux == CLKR_SRC_CLKX) | 753 | else if (mux == CLKR_SRC_CLKX) |
@@ -938,17 +755,17 @@ void omap2_mcbsp1_mux_clkr_src(u8 mux) | |||
938 | else | 755 | else |
939 | return; | 756 | return; |
940 | 757 | ||
941 | mcbsp = id_to_mcbsp_ptr(0); | ||
942 | if (mcbsp->pdata->mux_signal) | 758 | if (mcbsp->pdata->mux_signal) |
943 | mcbsp->pdata->mux_signal(mcbsp->dev, "clkr", src); | 759 | mcbsp->pdata->mux_signal(mcbsp->dev, "clkr", src); |
944 | } | 760 | } |
945 | EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src); | ||
946 | 761 | ||
947 | void omap2_mcbsp1_mux_fsr_src(u8 mux) | 762 | void omap2_mcbsp1_mux_fsr_src(struct omap_mcbsp *mcbsp, u8 mux) |
948 | { | 763 | { |
949 | struct omap_mcbsp *mcbsp; | ||
950 | const char *src; | 764 | const char *src; |
951 | 765 | ||
766 | if (mcbsp->id != 1) | ||
767 | return; | ||
768 | |||
952 | if (mux == FSR_SRC_FSR) | 769 | if (mux == FSR_SRC_FSR) |
953 | src = "fsr"; | 770 | src = "fsr"; |
954 | else if (mux == FSR_SRC_FSX) | 771 | else if (mux == FSR_SRC_FSX) |
@@ -956,11 +773,9 @@ void omap2_mcbsp1_mux_fsr_src(u8 mux) | |||
956 | else | 773 | else |
957 | return; | 774 | return; |
958 | 775 | ||
959 | mcbsp = id_to_mcbsp_ptr(0); | ||
960 | if (mcbsp->pdata->mux_signal) | 776 | if (mcbsp->pdata->mux_signal) |
961 | mcbsp->pdata->mux_signal(mcbsp->dev, "fsr", src); | 777 | mcbsp->pdata->mux_signal(mcbsp->dev, "fsr", src); |
962 | } | 778 | } |
963 | EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src); | ||
964 | 779 | ||
965 | #define max_thres(m) (mcbsp->pdata->buffer_size) | 780 | #define max_thres(m) (mcbsp->pdata->buffer_size) |
966 | #define valid_threshold(m, val) ((val) <= max_thres(m)) | 781 | #define valid_threshold(m, val) ((val) <= max_thres(m)) |
@@ -1177,11 +992,10 @@ static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp) | |||
1177 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. | 992 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. |
1178 | * 730 has only 2 McBSP, and both of them are MPU peripherals. | 993 | * 730 has only 2 McBSP, and both of them are MPU peripherals. |
1179 | */ | 994 | */ |
1180 | static int __devinit omap_mcbsp_probe(struct platform_device *pdev) | 995 | int __devinit omap_mcbsp_probe(struct platform_device *pdev) |
1181 | { | 996 | { |
1182 | struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; | 997 | struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; |
1183 | struct omap_mcbsp *mcbsp; | 998 | struct omap_mcbsp *mcbsp; |
1184 | int id = pdev->id - 1; | ||
1185 | struct resource *res; | 999 | struct resource *res; |
1186 | int ret = 0; | 1000 | int ret = 0; |
1187 | 1001 | ||
@@ -1194,12 +1008,6 @@ static int __devinit omap_mcbsp_probe(struct platform_device *pdev) | |||
1194 | 1008 | ||
1195 | dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); | 1009 | dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); |
1196 | 1010 | ||
1197 | if (id >= omap_mcbsp_count) { | ||
1198 | dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id); | ||
1199 | ret = -EINVAL; | ||
1200 | goto exit; | ||
1201 | } | ||
1202 | |||
1203 | mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); | 1011 | mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); |
1204 | if (!mcbsp) { | 1012 | if (!mcbsp) { |
1205 | ret = -ENOMEM; | 1013 | ret = -ENOMEM; |
@@ -1207,7 +1015,7 @@ static int __devinit omap_mcbsp_probe(struct platform_device *pdev) | |||
1207 | } | 1015 | } |
1208 | 1016 | ||
1209 | spin_lock_init(&mcbsp->lock); | 1017 | spin_lock_init(&mcbsp->lock); |
1210 | mcbsp->id = id + 1; | 1018 | mcbsp->id = pdev->id; |
1211 | mcbsp->free = true; | 1019 | mcbsp->free = true; |
1212 | 1020 | ||
1213 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); | 1021 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
@@ -1268,7 +1076,6 @@ static int __devinit omap_mcbsp_probe(struct platform_device *pdev) | |||
1268 | 1076 | ||
1269 | mcbsp->pdata = pdata; | 1077 | mcbsp->pdata = pdata; |
1270 | mcbsp->dev = &pdev->dev; | 1078 | mcbsp->dev = &pdev->dev; |
1271 | mcbsp_ptr[id] = mcbsp; | ||
1272 | platform_set_drvdata(pdev, mcbsp); | 1079 | platform_set_drvdata(pdev, mcbsp); |
1273 | pm_runtime_enable(mcbsp->dev); | 1080 | pm_runtime_enable(mcbsp->dev); |
1274 | 1081 | ||
@@ -1323,7 +1130,7 @@ exit: | |||
1323 | return ret; | 1130 | return ret; |
1324 | } | 1131 | } |
1325 | 1132 | ||
1326 | static int __devexit omap_mcbsp_remove(struct platform_device *pdev) | 1133 | int __devexit omap_mcbsp_remove(struct platform_device *pdev) |
1327 | { | 1134 | { |
1328 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); | 1135 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); |
1329 | 1136 | ||
@@ -1349,18 +1156,3 @@ static int __devexit omap_mcbsp_remove(struct platform_device *pdev) | |||
1349 | 1156 | ||
1350 | return 0; | 1157 | return 0; |
1351 | } | 1158 | } |
1352 | |||
1353 | static struct platform_driver omap_mcbsp_driver = { | ||
1354 | .probe = omap_mcbsp_probe, | ||
1355 | .remove = __devexit_p(omap_mcbsp_remove), | ||
1356 | .driver = { | ||
1357 | .name = "omap-mcbsp", | ||
1358 | }, | ||
1359 | }; | ||
1360 | |||
1361 | module_platform_driver(omap_mcbsp_driver); | ||
1362 | |||
1363 | MODULE_AUTHOR("Samuel Ortiz <samuel.ortiz@nokia.com>"); | ||
1364 | MODULE_DESCRIPTION("OMAP McBSP core driver"); | ||
1365 | MODULE_LICENSE("GPL"); | ||
1366 | MODULE_ALIAS("platform:omap-mcbsp"); | ||