Skip to content

Commit 76d4ada

Browse files
eberman-quicJassiBrar
authored andcommitted
mailbox: pcc: Use mbox_bind_client
Use generic mbox_bind_client() to bind omap mailbox channel to a client. mbox_bind_client is identical to the replaced lines, except that it: - Does the operation under con_mutex which prevents possible races in removal path - Sets TXDONE_BY_ACK if pcc uses TXDONE_BY_POLL and the client knows when tx is done. TXDONE_BY_ACK is already set if there's no interrupt, so this is not applicable. - Calls chan->mbox->ops->startup. This is usecase for requesting irq: move the devm_request_irq into the startup callback and unregister it in the shutdown path. Tested-by: Sudeep Holla <[email protected]> Signed-off-by: Elliot Berman <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent f11ff34 commit 76d4ada

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

drivers/mailbox/pcc.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
282282
{
283283
struct pcc_chan_info *pchan;
284284
struct mbox_chan *chan;
285-
struct device *dev;
286-
unsigned long flags;
285+
int rc;
287286

288287
if (subspace_id < 0 || subspace_id >= pcc_chan_count)
289288
return ERR_PTR(-ENOENT);
@@ -294,32 +293,10 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
294293
pr_err("Channel not found for idx: %d\n", subspace_id);
295294
return ERR_PTR(-EBUSY);
296295
}
297-
dev = chan->mbox->dev;
298296

299-
spin_lock_irqsave(&chan->lock, flags);
300-
chan->msg_free = 0;
301-
chan->msg_count = 0;
302-
chan->active_req = NULL;
303-
chan->cl = cl;
304-
init_completion(&chan->tx_complete);
305-
306-
if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone)
307-
chan->txdone_method = TXDONE_BY_ACK;
308-
309-
spin_unlock_irqrestore(&chan->lock, flags);
310-
311-
if (pchan->plat_irq > 0) {
312-
int rc;
313-
314-
rc = devm_request_irq(dev, pchan->plat_irq, pcc_mbox_irq, 0,
315-
MBOX_IRQ_NAME, chan);
316-
if (unlikely(rc)) {
317-
dev_err(dev, "failed to register PCC interrupt %d\n",
318-
pchan->plat_irq);
319-
pcc_mbox_free_channel(&pchan->chan);
320-
return ERR_PTR(rc);
321-
}
322-
}
297+
rc = mbox_bind_client(chan, cl);
298+
if (rc)
299+
return ERR_PTR(rc);
323300

324301
return &pchan->chan;
325302
}
@@ -333,23 +310,12 @@ EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
333310
*/
334311
void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan)
335312
{
336-
struct pcc_chan_info *pchan_info = to_pcc_chan_info(pchan);
337313
struct mbox_chan *chan = pchan->mchan;
338-
unsigned long flags;
339314

340315
if (!chan || !chan->cl)
341316
return;
342317

343-
if (pchan_info->plat_irq > 0)
344-
devm_free_irq(chan->mbox->dev, pchan_info->plat_irq, chan);
345-
346-
spin_lock_irqsave(&chan->lock, flags);
347-
chan->cl = NULL;
348-
chan->active_req = NULL;
349-
if (chan->txdone_method == TXDONE_BY_ACK)
350-
chan->txdone_method = TXDONE_BY_POLL;
351-
352-
spin_unlock_irqrestore(&chan->lock, flags);
318+
mbox_free_channel(chan);
353319
}
354320
EXPORT_SYMBOL_GPL(pcc_mbox_free_channel);
355321

@@ -377,8 +343,48 @@ static int pcc_send_data(struct mbox_chan *chan, void *data)
377343
return pcc_chan_reg_read_modify_write(&pchan->db);
378344
}
379345

346+
/**
347+
* pcc_startup - Called from Mailbox Controller code. Used here
348+
* to request the interrupt.
349+
* @chan: Pointer to Mailbox channel to startup.
350+
*
351+
* Return: Err if something failed else 0 for success.
352+
*/
353+
static int pcc_startup(struct mbox_chan *chan)
354+
{
355+
struct pcc_chan_info *pchan = chan->con_priv;
356+
int rc;
357+
358+
if (pchan->plat_irq > 0) {
359+
rc = devm_request_irq(chan->mbox->dev, pchan->plat_irq, pcc_mbox_irq, 0,
360+
MBOX_IRQ_NAME, chan);
361+
if (unlikely(rc)) {
362+
dev_err(chan->mbox->dev, "failed to register PCC interrupt %d\n",
363+
pchan->plat_irq);
364+
return rc;
365+
}
366+
}
367+
368+
return 0;
369+
}
370+
371+
/**
372+
* pcc_shutdown - Called from Mailbox Controller code. Used here
373+
* to free the interrupt.
374+
* @chan: Pointer to Mailbox channel to shutdown.
375+
*/
376+
static void pcc_shutdown(struct mbox_chan *chan)
377+
{
378+
struct pcc_chan_info *pchan = chan->con_priv;
379+
380+
if (pchan->plat_irq > 0)
381+
devm_free_irq(chan->mbox->dev, pchan->plat_irq, chan);
382+
}
383+
380384
static const struct mbox_chan_ops pcc_chan_ops = {
381385
.send_data = pcc_send_data,
386+
.startup = pcc_startup,
387+
.shutdown = pcc_shutdown,
382388
};
383389

384390
/**

0 commit comments

Comments
 (0)