Skip to content

Commit

Permalink
V4L/DVB (4323): [budget/budget-av/budget-ci/budget-patch drivers] fix…
Browse files Browse the repository at this point in the history
…ed DMA start/stop code

Fix bug reported by Andrew de Quincey:
After cold boot the saa7146 DMA did not start if the demuxer was opened
before the frontend has locked to the signal.
DMA transfers will be started now if (and only if)
the frontend is locked and data should be sent to the demuxer.

Signed-off-by: Oliver Endriss <o.endriss@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
  • Loading branch information
Oliver Endriss authored and Mauro Carvalho Chehab committed Jul 29, 2006
1 parent 3117bee commit 32e4c3a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
3 changes: 3 additions & 0 deletions drivers/media/dvb/ttpci/budget-av.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,9 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
budget_av->budget.dvb_adapter.priv = budget_av;
frontend_init(budget_av);
ciintf_init(budget_av);

ttpci_budget_init_hooks(&budget_av->budget);

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/media/dvb/ttpci/budget-ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,8 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
budget_ci->budget.dvb_adapter.priv = budget_ci;
frontend_init(budget_ci);

ttpci_budget_init_hooks(&budget_ci->budget);

return 0;
}

Expand Down
57 changes: 44 additions & 13 deletions drivers/media/dvb/ttpci/budget-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ static int stop_ts_capture(struct budget *budget)
{
dprintk(2, "budget: %p\n", budget);

if (--budget->feeding)
return budget->feeding;

saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off
SAA7146_IER_DISABLE(budget->dev, MASK_10);
return 0;
Expand All @@ -77,8 +74,8 @@ static int start_ts_capture(struct budget *budget)

dprintk(2, "budget: %p\n", budget);

if (budget->feeding)
return ++budget->feeding;
if (!budget->feeding || !budget->fe_synced)
return 0;

saa7146_write(dev, MC1, MASK_20); // DMA3 off

Expand Down Expand Up @@ -139,7 +136,33 @@ static int start_ts_capture(struct budget *budget)
SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
saa7146_write(dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */

return ++budget->feeding;
return 0;
}

static int budget_read_fe_status(struct dvb_frontend *fe, fe_status_t *status)
{
struct budget *budget = (struct budget *) fe->dvb->priv;
int synced;
int ret;

if (budget->read_fe_status)
ret = budget->read_fe_status(fe, status);
else
ret = -EINVAL;

if (!ret) {
synced = (*status & FE_HAS_LOCK);
if (synced != budget->fe_synced) {
budget->fe_synced = synced;
spin_lock(&budget->feedlock);
if (synced)
start_ts_capture(budget);
else
stop_ts_capture(budget);
spin_unlock(&budget->feedlock);
}
}
return ret;
}

static void vpeirq(unsigned long data)
Expand Down Expand Up @@ -267,7 +290,7 @@ static int budget_start_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct budget *budget = (struct budget *) demux->priv;
int status;
int status = 0;

dprintk(2, "budget: %p\n", budget);

Expand All @@ -276,7 +299,8 @@ static int budget_start_feed(struct dvb_demux_feed *feed)

spin_lock(&budget->feedlock);
feed->pusi_seen = 0; /* have a clean section start */
status = start_ts_capture(budget);
if (budget->feeding++ == 0)
status = start_ts_capture(budget);
spin_unlock(&budget->feedlock);
return status;
}
Expand All @@ -285,12 +309,13 @@ static int budget_stop_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct budget *budget = (struct budget *) demux->priv;
int status;
int status = 0;

dprintk(2, "budget: %p\n", budget);

spin_lock(&budget->feedlock);
status = stop_ts_capture(budget);
if (--budget->feeding == 0)
status = stop_ts_capture(budget);
spin_unlock(&budget->feedlock);
return status;
}
Expand Down Expand Up @@ -470,6 +495,14 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
return ret;
}

void ttpci_budget_init_hooks(struct budget *budget)
{
if (budget->dvb_frontend && !budget->read_fe_status) {
budget->read_fe_status = budget->dvb_frontend->ops.read_status;
budget->dvb_frontend->ops.read_status = budget_read_fe_status;
}
}

int ttpci_budget_deinit(struct budget *budget)
{
struct saa7146_dev *dev = budget->dev;
Expand Down Expand Up @@ -508,18 +541,16 @@ void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port)
spin_lock(&budget->feedlock);
budget->video_port = video_port;
if (budget->feeding) {
int oldfeeding = budget->feeding;
budget->feeding = 1;
stop_ts_capture(budget);
start_ts_capture(budget);
budget->feeding = oldfeeding;
}
spin_unlock(&budget->feedlock);
}

EXPORT_SYMBOL_GPL(ttpci_budget_debiread);
EXPORT_SYMBOL_GPL(ttpci_budget_debiwrite);
EXPORT_SYMBOL_GPL(ttpci_budget_init);
EXPORT_SYMBOL_GPL(ttpci_budget_init_hooks);
EXPORT_SYMBOL_GPL(ttpci_budget_deinit);
EXPORT_SYMBOL_GPL(ttpci_budget_irq10_handler);
EXPORT_SYMBOL_GPL(ttpci_budget_set_video_port);
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/dvb/ttpci/budget-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
budget->dvb_adapter.priv = budget;
frontend_init(budget);

ttpci_budget_init_hooks(budget);

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/media/dvb/ttpci/budget.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_
budget->dvb_adapter.priv = budget;
frontend_init(budget);

ttpci_budget_init_hooks(budget);

return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions drivers/media/dvb/ttpci/budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ struct budget {
struct dmx_frontend hw_frontend;
struct dmx_frontend mem_frontend;

int fe_synced;
struct mutex pid_mutex;

int ci_present;
int video_port;

Expand All @@ -74,6 +71,9 @@ struct budget {

struct dvb_adapter dvb_adapter;
struct dvb_frontend *dvb_frontend;
int (*read_fe_status)(struct dvb_frontend *fe, fe_status_t *status);
int fe_synced;

void *priv;
};

Expand Down Expand Up @@ -106,6 +106,7 @@ static struct saa7146_pci_extension_data x_var = { \
extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
struct saa7146_pci_extension_data *info,
struct module *owner);
extern void ttpci_budget_init_hooks(struct budget *budget);
extern int ttpci_budget_deinit(struct budget *budget);
extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr);
extern void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port);
Expand Down

0 comments on commit 32e4c3a

Please sign in to comment.