Project

General

Profile

Download (2.22 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
/* (C) 2011-2012 by Harald Welte <laforge@gnumonks.org>
3
 *
4
 * All Rights Reserved
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

    
20
#include <stdint.h>
21
#include <unistd.h>
22
#include <errno.h>
23

    
24
#include <common.h>
25
#include <logging.h>
26
#include <tuner_e4k.h>
27

    
28
//#include <twi/twi.h>
29
#include <twi/twid.h>
30
#include <pio/pio.h>
31
#include <board.h>
32

    
33

    
34
int e4k_reg_write(struct e4k_state *e4k, uint8_t reg, uint8_t val)
35
{
36
	unsigned char rc;
37

    
38
	rc = TWID_Write(e4k->i2c_dev, e4k->i2c_addr, reg, 1, &val, 1, NULL);
39
	if (rc != 0) {
40
		LOGP(DTUN, LOGL_ERROR, "Error %u in TWID_Write\n", rc);
41
		return -EIO;
42
	}
43

    
44
	return 0;
45
}
46

    
47
uint8_t e4k_reg_read(struct e4k_state *e4k, uint8_t reg)
48
{
49
	unsigned char rc;
50
	uint8_t val;
51

    
52
	rc = TWID_Read(e4k->i2c_dev, e4k->i2c_addr, reg, 1, &val, 1, NULL);
53
	if (rc != 0) {
54
		LOGP(DTUN, LOGL_ERROR, "Error %u in TWID_Read\n", rc);
55
		return -EIO;
56
	}
57

    
58
	return val;
59
}
60

    
61

    
62
/* We assume the caller has already done TWID_initialize() */
63
int sam3u_e4k_init(struct e4k_state *e4k, void *i2c, uint8_t slave_addr)
64
{
65
	e4k->i2c_dev = i2c;
66
	e4k->i2c_addr = slave_addr;
67

    
68
	return 0;
69
}
70

    
71
static const Pin pin_rfstby = PIN_RFSTBY;
72
static const Pin pin_pwdn = PIN_PDWN;
73

    
74
/*! \brief Enable or disable Power of E4K
75
 *  \param[in] e4k E4K reference
76
 *  \param[in] on Enable (1) or disable (0) Power
77
 */
78
void sam3u_e4k_power(struct e4k_state *e4k, int on)
79
{
80
	if (on)
81
		PIO_Set(&pin_pwdn);
82
	else
83
		PIO_Clear(&pin_pwdn);
84
}
85

    
86
/*! \brief Enable or disable standby mode of E4K
87
 *  \param[in] e4k E4K reference
88
 *  \param[in] on Enable (1) or disable (0) STBY
89
 */
90
void sam3u_e4k_stby(struct e4k_state *e4k, int on)
91
{
92
	if (on)
93
		PIO_Clear(&pin_rfstby);
94
	else
95
		PIO_Set(&pin_rfstby);
96
}
(10-10/11)
Add picture from clipboard (Maximum size: 48.8 MB)