summaryrefslogtreecommitdiff
path: root/drivers/media/pci/tw5864/tw5864-util.c
blob: b9cebe9d1740f50a9a2b54bb59cf9c67124e6c85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: GPL-2.0
#include "tw5864.h"

void tw5864_indir_writeb(struct tw5864_dev *dev, u16 addr, u8 data)
{
	int retries = 30000;

	while (tw_readl(TW5864_IND_CTL) & BIT(31) && --retries)
		;
	if (!retries)
		dev_err(&dev->pci->dev,
			"tw_indir_writel() retries exhausted before writing\n");

	tw_writel(TW5864_IND_DATA, data);
	tw_writel(TW5864_IND_CTL, addr << 2 | TW5864_RW | TW5864_ENABLE);
}

u8 tw5864_indir_readb(struct tw5864_dev *dev, u16 addr)
{
	int retries = 30000;

	while (tw_readl(TW5864_IND_CTL) & BIT(31) && --retries)
		;
	if (!retries)
		dev_err(&dev->pci->dev,
			"tw_indir_readl() retries exhausted before reading\n");

	tw_writel(TW5864_IND_CTL, addr << 2 | TW5864_ENABLE);

	retries = 30000;
	while (tw_readl(TW5864_IND_CTL) & BIT(31) && --retries)
		;
	if (!retries)
		dev_err(&dev->pci->dev,
			"tw_indir_readl() retries exhausted at reading\n");

	return tw_readl(TW5864_IND_DATA);
}