17 #include <linux/module.h>
19 #include <linux/device.h>
26 #include <linux/slab.h>
39 if (mcbsp->
pdata->reg_size == 2) {
48 static int omap_mcbsp_read(
struct omap_mcbsp *mcbsp,
u16 reg,
bool from_cache)
52 if (mcbsp->
pdata->reg_size == 2) {
54 ((
u16 *)mcbsp->reg_cache)[reg];
57 ((
u32 *)mcbsp->reg_cache)[reg];
66 static int omap_mcbsp_st_read(
struct omap_mcbsp *mcbsp,
u16 reg)
71 #define MCBSP_READ(mcbsp, reg) \
72 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
73 #define MCBSP_WRITE(mcbsp, reg, val) \
74 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
75 #define MCBSP_READ_CACHE(mcbsp, reg) \
76 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
78 #define MCBSP_ST_READ(mcbsp, reg) \
79 omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
80 #define MCBSP_ST_WRITE(mcbsp, reg, val) \
81 omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
83 static void omap_mcbsp_dump_reg(
struct omap_mcbsp *mcbsp)
85 dev_dbg(mcbsp->
dev,
"**** McBSP%d regs ****\n", mcbsp->
id);
112 dev_dbg(mcbsp->
dev,
"***********************\n");
121 dev_dbg(mcbsp->
dev,
"IRQ callback : 0x%x\n", irqst);
124 dev_err(mcbsp->
dev,
"RX Frame Sync Error!\n");
130 dev_dbg(mcbsp->
dev,
"RX Buffer Threshold Reached\n");
132 dev_err(mcbsp->
dev,
"RX Buffer Underflow!\n");
137 dev_err(mcbsp->
dev,
"TX Frame Sync Error!\n");
143 dev_dbg(mcbsp->
dev,
"TX Buffer threshold Reached\n");
145 dev_err(mcbsp->
dev,
"TX Buffer Underflow!\n");
149 dev_dbg(mcbsp->
dev,
"TX Buffer empty at end of frame\n");
156 static irqreturn_t omap_mcbsp_tx_irq_handler(
int irq,
void *dev_id)
162 dev_dbg(mcbsp_tx->
dev,
"TX IRQ callback : 0x%x\n", irqst_spcr2);
165 dev_err(mcbsp_tx->
dev,
"TX Frame Sync Error! : 0x%x\n",
174 static irqreturn_t omap_mcbsp_rx_irq_handler(
int irq,
void *dev_id)
180 dev_dbg(mcbsp_rx->
dev,
"RX IRQ callback : 0x%x\n", irqst_spcr1);
183 dev_err(mcbsp_rx->
dev,
"RX Frame Sync Error! : 0x%x\n",
201 dev_dbg(mcbsp->
dev,
"Configuring McBSP%d phys_base: 0x%08lx\n",
216 if (mcbsp->
pdata->has_ccr) {
221 if (mcbsp->
pdata->has_wakeup)
238 static int omap_mcbsp_dma_reg_params(
struct omap_mcbsp *mcbsp,
243 if (mcbsp->
pdata->reg_size == 2) {
258 static void omap_st_on(
struct omap_mcbsp *mcbsp)
262 if (mcbsp->
pdata->enable_st_clock)
263 mcbsp->
pdata->enable_st_clock(mcbsp->
id, 1);
274 static void omap_st_off(
struct omap_mcbsp *mcbsp)
284 if (mcbsp->
pdata->enable_st_clock)
285 mcbsp->
pdata->enable_st_clock(mcbsp->
id, 0);
299 for (i = 0; i < 128; i++)
311 dev_err(mcbsp->
dev,
"McBSP FIR load error!\n");
314 static void omap_st_chgain(
struct omap_mcbsp *mcbsp)
333 spin_lock_irq(&mcbsp->
lock);
336 else if (channel == 1)
342 omap_st_chgain(mcbsp);
343 spin_unlock_irq(&mcbsp->
lock);
356 spin_lock_irq(&mcbsp->
lock);
359 else if (channel == 1)
363 spin_unlock_irq(&mcbsp->
lock);
368 static int omap_st_start(
struct omap_mcbsp *mcbsp)
373 omap_st_fir_write(mcbsp, st_data->
taps);
374 omap_st_chgain(mcbsp);
392 spin_lock_irq(&mcbsp->
lock);
394 omap_st_start(mcbsp);
395 spin_unlock_irq(&mcbsp->
lock);
400 static int omap_st_stop(
struct omap_mcbsp *mcbsp)
422 spin_lock_irq(&mcbsp->
lock);
425 spin_unlock_irq(&mcbsp->
lock);
447 if (mcbsp->
pdata->buffer_size == 0)
450 if (threshold && threshold <= mcbsp->max_tx_thres)
461 if (mcbsp->
pdata->buffer_size == 0)
464 if (threshold && threshold <= mcbsp->max_rx_thres)
475 if (mcbsp->
pdata->buffer_size == 0)
482 return mcbsp->
pdata->buffer_size - buffstat;
493 if (mcbsp->
pdata->buffer_size == 0)
502 if (threshold <= buffstat)
505 return threshold - buffstat;
518 spin_lock(&mcbsp->
lock);
520 dev_err(mcbsp->
dev,
"McBSP%d is currently in use\n",
528 spin_unlock(&mcbsp->
lock);
531 mcbsp->
pdata->ops->request(mcbsp->
id - 1);
542 "McBSP", (
void *)mcbsp);
544 dev_err(mcbsp->
dev,
"Unable to request IRQ\n");
545 goto err_clk_disable;
549 "McBSP TX", (
void *)mcbsp);
551 dev_err(mcbsp->
dev,
"Unable to request TX IRQ\n");
552 goto err_clk_disable;
556 "McBSP RX", (
void *)mcbsp);
558 dev_err(mcbsp->
dev,
"Unable to request RX IRQ\n");
568 mcbsp->
pdata->ops->free(mcbsp->
id - 1);
571 if (mcbsp->
pdata->has_wakeup)
574 spin_lock(&mcbsp->
lock);
578 spin_unlock(&mcbsp->
lock);
589 mcbsp->
pdata->ops->free(mcbsp->
id - 1);
592 if (mcbsp->
pdata->has_wakeup)
618 spin_lock(&mcbsp->
lock);
620 dev_err(mcbsp->
dev,
"McBSP%d was not reserved\n", mcbsp->
id);
624 spin_unlock(&mcbsp->
lock);
641 omap_st_start(mcbsp);
678 if (mcbsp->
pdata->has_ccr) {
689 omap_mcbsp_dump_reg(mcbsp);
699 if (mcbsp->
pdata->has_ccr) {
709 if (mcbsp->
pdata->has_ccr) {
744 if (IS_ERR(fck_src)) {
745 dev_err(mcbsp->
dev,
"CLKS: could not clk_get() %s\n", src);
749 pm_runtime_put_sync(mcbsp->
dev);
753 dev_err(mcbsp->
dev,
"CLKS: could not clk_set_parent() to %s\n",
759 pm_runtime_get_sync(mcbsp->
dev);
767 #define max_thres(m) (mcbsp->pdata->buffer_size)
768 #define valid_threshold(m, val) ((val) <= max_thres(m))
769 #define THRESHOLD_PROP_BUILDER(prop) \
770 static ssize_t prop##_show(struct device *dev, \
771 struct device_attribute *attr, char *buf) \
773 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
775 return sprintf(buf, "%u\n", mcbsp->prop); \
778 static ssize_t prop##_store(struct device *dev, \
779 struct device_attribute *attr, \
780 const char *buf, size_t size) \
782 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
786 status = strict_strtoul(buf, 0, &val); \
790 if (!valid_threshold(mcbsp, val)) \
797 static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
802 static const char *dma_op_modes[] = {
803 "element",
"threshold",
812 const char *
const *
s;
816 for (s = &dma_op_modes[i]; i <
ARRAY_SIZE(dma_op_modes); s++, i++) {
817 if (dma_op_mode == i)
818 len +=
sprintf(buf + len,
"[%s] ", *s);
820 len +=
sprintf(buf + len,
"%s ", *s);
822 len +=
sprintf(buf + len,
"\n");
829 const char *buf,
size_t size)
832 const char *
const *
s;
835 for (s = &dma_op_modes[i]; i <
ARRAY_SIZE(dma_op_modes); s++, i++)
842 spin_lock_irq(&mcbsp->
lock);
850 spin_unlock_irq(&mcbsp->
lock);
855 static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
857 static const struct attribute *additional_attrs[] = {
858 &dev_attr_max_tx_thres.attr,
859 &dev_attr_max_rx_thres.attr,
860 &dev_attr_dma_op_mode.attr,
865 .attrs = (
struct attribute **)additional_attrs,
876 spin_lock_irq(&mcbsp->
lock);
877 for (i = 0; i < st_data->
nr_taps; i++)
878 status +=
sprintf(&buf[status], (i ?
", %d" :
"%d"),
881 status +=
sprintf(&buf[status],
"\n");
882 spin_unlock_irq(&mcbsp->
lock);
889 const char *buf,
size_t size)
895 spin_lock_irq(&mcbsp->
lock);
900 status =
sscanf(buf,
"%d%n", &val, &tmp);
901 if (status < 0 || status == 0) {
905 if (val < -32768 || val > 32767) {
919 spin_unlock_irq(&mcbsp->
lock);
924 static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
926 static const struct attribute *sidetone_attrs[] = {
927 &dev_attr_st_taps.attr,
932 .attrs = (
struct attribute **)sidetone_attrs,
964 struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
975 dev_err(mcbsp->
dev,
"invalid memory resource\n");
980 dev_name(&pdev->
dev))) {
981 dev_err(mcbsp->
dev,
"memory region already claimed\n");
1020 dev_err(&pdev->
dev,
"invalid rx DMA channel\n");
1024 mcbsp->
dma_data[1].name =
"Audio Capture";
1026 mcbsp->
dma_data[1].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 1);
1030 dev_err(&pdev->
dev,
"invalid tx DMA channel\n");
1034 mcbsp->
dma_data[0].name =
"Audio Playback";
1036 mcbsp->
dma_data[0].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 0);
1039 if (IS_ERR(mcbsp->
fclk)) {
1040 ret = PTR_ERR(mcbsp->
fclk);
1041 dev_err(mcbsp->
dev,
"unable to get fck: %d\n", ret);
1046 if (mcbsp->
pdata->buffer_size) {
1059 &additional_attr_group);
1062 "Unable to create additional controls\n");
1072 ret = omap_st_add(mcbsp, res);
1075 "Unable to create sidetone controls\n");
1083 if (mcbsp->
pdata->buffer_size)
1092 if (mcbsp->
pdata->buffer_size)