aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tdmb/mtv318/raontv_port.c
blob: 1251a8c19be92b2755f6070c8d5a2bd04c1aa644 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
*
* File name: drivers/media/tdmb/mtv318/src/raontv_port.c
*
* Description : RAONTECH TV OEM source driver.
*
* Copyright (C) (2011, RAONTECH)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
*/

#include "raontv.h"
#include "raontv_internal.h"
#include <linux/spi/spi.h>

#include "tdmb.h"

/* Declares a variable of gurad object if neccessry. */
#if defined(RTV_IF_SPI) || ((defined(RTV_TDMB_ENABLE) \
	|| defined(RTV_DAB_ENABLE)) && !defined(RTV_FIC_POLLING_MODE))
	#if defined(__KERNEL__)
		struct mutex raontv_guard;
    #elif defined(WINCE)
		CRITICAL_SECTION raontv_guard;
    #else
	/* non-OS and RTOS. */
	#endif
#endif

void rtvOEM_ConfigureInterrupt(void)
{
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2) \
	|| ((defined(RTV_TDMB_ENABLE) || defined(RTV_DAB_ENABLE)) \
	&& !defined(RTV_FIC_POLLING_MODE))

	RTV_REG_SET(0x09, 0x00);
	/* [6]INT1 [5]INT0 - 1: Input mode, 0: Output mode */
	RTV_REG_SET(0x0B, 0x00);
	/* [2]INT1 PAD disable [1]INT0 PAD disable */

	RTV_REG_MAP_SEL(HOST_PAGE);
	RTV_REG_SET(0x28, 0x01);
	/* [5:3]INT1 out sel [2:0] INI0 out sel
	- 0:Toggle 1:Level,, 2:"0", 3:"1"*/

   #if defined(RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE)
	RTV_REG_SET(0x29, 0x08);
	/*[3] Interrupt status register clear condition
	- 0:read data by memory access 1:status register access*/
   #else
	RTV_REG_SET(0x29, 0x00);
	/*[3] Interrupt status register clear condition
	- 0:read data by memory access 1:status register access*/
   #endif
	RTV_REG_SET(0x2A, 0x13);
	/* [5]INT1 pol [4]INT0 pol
	- 0:Active High, 1:Active Low [3:0] Period = (INT_TIME+1)/8MHz*/
#endif
}

#if defined(RTV_IF_SPI)
unsigned char mtv_spi_read(unsigned char reg)
{
	int ret;
	u8 out_buf[2], read_out_buf[2];
	u8 in_buf[2];
	struct spi_message msg;
	struct spi_transfer msg_xfer0 = {
		.tx_buf = out_buf,
		.len		= 2,
		.cs_change	= 1,
	};

	struct spi_transfer msg_xfer1 = {
		.tx_buf = read_out_buf,
		.rx_buf = in_buf,
		.len		= 2,
		.cs_change	= 0,
	};

	spi_message_init(&msg);

	out_buf[0] = RAONTV_CHIP_ADDR;
	out_buf[1] = reg;
	spi_message_add_tail(&msg_xfer0, &msg);

	read_out_buf[0] = RAONTV_CHIP_ADDR|0x1;
	read_out_buf[1] = 0xFF;
	spi_message_add_tail(&msg_xfer1, &msg);

	ret = spi_sync(tdmb_get_spi_handle(), &msg);
	if (ret) {
		printk(KERN_ERR "[mtv818_spi_read]  mtv818_spi_read() error: %d\n",
		ret);
		return 0xFF;
	}

	/* printk(KERN_ERR
	"[mtv818_spi_read]  in_buf[0]: 0x%02X, in_buf[1]: 0x%02X\n",
	in_buf[0], in_buf[1]);   */

	return in_buf[1];
}

void mtv_spi_read_burst(unsigned char reg, unsigned char *buf, int size)
{
	int ret;
	u8 out_buf[2], read_out_buf[2];
	struct spi_message msg;
	struct spi_transfer msg_xfer0 = {
		.tx_buf = out_buf,
		.len		= 2,
		.cs_change	= 1,
	};

	struct spi_transfer msg_xfer1 = {
		.tx_buf = read_out_buf,
		.rx_buf = buf,
		.len		= size,
		.cs_change	= 0,
	};

	spi_message_init(&msg);
	out_buf[0] = RAONTV_CHIP_ADDR;
	out_buf[1] = reg;
	spi_message_add_tail(&msg_xfer0, &msg);

	read_out_buf[0] = RAONTV_CHIP_ADDR|0x1;
	spi_message_add_tail(&msg_xfer1, &msg);

	ret = spi_sync(tdmb_get_spi_handle(), &msg);
	if (ret)
		printk(KERN_ERR "[mtv818_spi_read_burst] error: %d\n", ret);
}

void mtv_spi_write(unsigned char reg, unsigned char val)
{
	u8 out_buf[3];
	u8 in_buf[3];
	struct spi_message msg;
	struct spi_transfer msg_xfer = {
		.len		= 3,
		.cs_change	= 0,
	};
	int ret;

	spi_message_init(&msg);

	out_buf[0] = 0x86;
	out_buf[1] = reg;
	out_buf[2] = val;

	msg_xfer.tx_buf = out_buf;
	msg_xfer.rx_buf = in_buf;
	spi_message_add_tail(&msg_xfer, &msg);

	ret = spi_sync(tdmb_get_spi_handle(), &msg);
	if (ret)
		printk(KERN_ERR "[mtv818_spi_write] error: %d\n", ret);
}
#endif