1 |
ec646799
|
Harald Welte
|
|
2 |
d5c4d1ed
|
Harald Welte
|
/* (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 |
ec646799
|
Harald Welte
|
#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 |
13a54079
|
Harald Welte
|
#include <pio/pio.h>
|
31 |
|
|
#include <board.h>
|
32 |
ec646799
|
Harald Welte
|
|
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 |
180193ce
|
Christian Daniel
|
uint8_t e4k_reg_read(struct e4k_state *e4k, uint8_t reg)
|
48 |
ec646799
|
Harald Welte
|
{
|
49 |
|
|
unsigned char rc;
|
50 |
|
|
uint8_t val;
|
51 |
|
|
|
52 |
be77347f
|
Harald Welte
|
rc = TWID_Read(e4k->i2c_dev, e4k->i2c_addr, reg, 1, &val, 1, NULL);
|
53 |
ec646799
|
Harald Welte
|
if (rc != 0) {
|
54 |
be77347f
|
Harald Welte
|
LOGP(DTUN, LOGL_ERROR, "Error %u in TWID_Read\n", rc);
|
55 |
ec646799
|
Harald Welte
|
return -EIO;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
return val;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
/* We assume the caller has already done TWID_initialize() */
|
63 |
54e0c0bf
|
Harald Welte
|
int sam3u_e4k_init(struct e4k_state *e4k, void *i2c, uint8_t slave_addr)
|
64 |
ec646799
|
Harald Welte
|
{
|
65 |
54e0c0bf
|
Harald Welte
|
e4k->i2c_dev = i2c;
|
66 |
ec646799
|
Harald Welte
|
e4k->i2c_addr = slave_addr;
|
67 |
|
|
|
68 |
|
|
return 0;
|
69 |
|
|
}
|
70 |
13a54079
|
Harald Welte
|
|
71 |
|
|
static const Pin pin_rfstby = PIN_RFSTBY;
|
72 |
|
|
static const Pin pin_pwdn = PIN_PDWN;
|
73 |
|
|
|
74 |
6cd41e8e
|
Harald Welte
|
/*! \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 |
13a54079
|
Harald Welte
|
{
|
80 |
|
|
if (on)
|
81 |
|
|
PIO_Set(&pin_pwdn);
|
82 |
|
|
else
|
83 |
|
|
PIO_Clear(&pin_pwdn);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
6cd41e8e
|
Harald Welte
|
/*! \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 |
13a54079
|
Harald Welte
|
{
|
92 |
|
|
if (on)
|
93 |
|
|
PIO_Clear(&pin_rfstby);
|
94 |
6cd41e8e
|
Harald Welte
|
else
|
95 |
|
|
PIO_Set(&pin_rfstby);
|
96 |
13a54079
|
Harald Welte
|
}
|