aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tdmb/tcc3170/src/tcbd_hal.c
blob: fba77e7d1bcf86579c1f534ea42a401ad7f4a2c7 (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
/*
 * tcbd_hal.c
 *
 * Author:  <linux@telechips.com>
 * Description: Telechips broadcast driver
 *
 * Copyright (c) Telechips, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/delay.h>

#include <bsp.h>

#include "tcpal_os.h"
#include "tcpal_debug.h"
#include "tcbd_hal.h"
#include "tcbd_feature.h"

#define __USE_DXB0_IRQ__
/*#define __USE_DXB1_IRQ__*/

#ifdef __USE_TC_CPU__
static PGPIO RGPIO;
static PPIC   RPIC;
#endif

void tchal_init(void)
{
#ifdef __USE_TC_CPU__
	tcbd_debug(DEBUG_TCHAL, "\n");
	RGPIO = (PGPIO)tcc_p2v(HwGPIO_BASE);
	RPIC = (PPIC)tcc_p2v(HwPIC_BASE);
#endif
	tchal_power_down_device();
}

void tchal_reset_device(void)
{
#ifdef __USE_TC_CPU__
	tcbd_debug(DEBUG_TCHAL, "\n");
#if defined(__CSPI_ONLY__)
	/* select peripheral mode as SPI */
#if defined(__USE_DXB1_IRQ__)
	BITCLR(RGPIO->GPAFN1, Hw16 - Hw12); /* DXB1_IRQ Set GPIO mode*/
	BITSET(RGPIO->GPAEN,  Hw11);		/* DXB1_IRQ output mode*/
	BITCLR(RGPIO->GPADAT, Hw11);		/* DXB1_IRQ clear*/
#elif defined(__USE_DXB0_IRQ__)
	BITCLR(RGPIO->GPDFN1, Hw8 - Hw4);  /* DXB0_IRQ Set GPIO mode*/
	BITSET(RGPIO->GPDEN,  Hw9); /* DXB0_IRQ output mode*/
	BITCLR(RGPIO->GPDDAT, Hw9); /* DXB0_IRQ clear*/
#endif /*__USE_DXB1_IRQ__*/
#endif /*__CSPI_ONLY__*/

	/* reset */
#if defined(__CSPI_ONLY__)
	BITCLR(RGPIO->GPEFN1, Hw16 - Hw12); /* DXB1_RST# Set GPIO mode */
	BITSET(RGPIO->GPEEN,  Hw11);/* DXB1_RST# Set GPIO Output mode*/
	BITCLR(RGPIO->GPEDAT, Hw11);/* DXB1_RST# Clear */
	tcpal_msleep(10);
	BITSET(RGPIO->GPEDAT, Hw11);/* DXB1_RST# Set*/
#elif defined(__I2C_STS__)
	BITCLR(RGPIO->GPDFN1, Hw4 - Hw0); /* DXB0_RST# Set GPIO mode */
	BITSET(RGPIO->GPDEN,  Hw8); /* DXB0_RST# Set GPIO Output mode*/
	BITCLR(RGPIO->GPDDAT, Hw8); /* DXB0_RST# Clear */
	tcpal_msleep(10);
	BITSET(RGPIO->GPDDAT, Hw8); /* DXB0_RST# Set*/
#else /*__CSPI_ONLY__ || __I2C_STS__*/
#error "you must define __CSPI_ONLY__ or __I2C_STS__"
#endif /*!__CSPI_ONLY__ && !__I2C_STS__*/
#endif
}

void tchal_power_on_device(void)
{
#ifdef __USE_TC_CPU__
	tcbd_debug(DEBUG_TCHAL, "\n");
	BITCLR(RGPIO->GPEFN0, Hw16 - Hw12);/* DXB1_PD Set GPIO mode*/

	BITSET(RGPIO->GPEEN,  Hw3);/* DXB1_PD Set GPIO Output mode*/
	BITCLR(RGPIO->GPEDAT, Hw3);/* DXB1_PD Clear*/
	tcpal_msleep(10);
	BITSET(RGPIO->GPEDAT, Hw3);/* DXB1_PD Set*/
	tcpal_msleep(10);

	tchal_reset_device();
	tchal_irq_setup();
#endif
}


void tchal_power_down_device(void)
{
#ifdef __USE_TC_CPU__
	tcbd_debug(DEBUG_TCHAL, "\n");
	BITCLR(RGPIO->GPEFN0, Hw16 - Hw12);
	BITSET(RGPIO->GPEEN,  Hw3);/* DXB1_PD Set GPIO Output mode*/
	BITCLR(RGPIO->GPEDAT, Hw3);/* DXB1_PD Clear*/
#if defined(__CSPI_ONLY__)
	BITCLR(RGPIO->GPEDAT, Hw11);/* DXB1_RST# Clear*/
#elif defined(__I2C_STS__)
	BITCLR(RGPIO->GPDDAT, Hw8);/* DXB0_RST# Clear */
#else
#error "you must define __CSPI_ONLY__ or __I2C_STS__"
#endif
#endif
}

void tchal_irq_setup(void)
{
#ifdef __USE_TC_CPU__
#if defined(__USE_DXB1_IRQ__)
	BITCLR(RGPIO->GPAFN1, Hw16 - Hw12);/* DXB1_IRQ Set GPIO mode*/
	BITCLR(RGPIO->GPAEN,  Hw11);/* DXB1_IRQ input mode*/

	BITCSET(RGPIO->EINTSEL0, Hw32 - Hw24, 11<<24); /*GPIO_A11*/
#elif defined(__USE_DXB0_IRQ__)
	BITCLR(RGPIO->GPDFN1, Hw8 - Hw4); /* DXB0_IRQ Set GPIO mode*/
	BITCLR(RGPIO->GPDEN, Hw9);        /* DXB0_IRQ input mode*/

	BITCSET(RGPIO->EINTSEL0, Hw32 - Hw24, 20<<24); /*GPIO_D9*/
#endif /*__USE_DXB1_IRQ__*/
	BITSET(RPIC->POL0, 1<<IRQ_TC317X);
#endif
}