aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-03-06 23:15:42 +0100
committerHarald Welte <laforge@gnumonks.org>2012-03-06 23:15:42 +0100
commit605e3e459f43e024b45c694562a99a3953a00129 (patch)
tree92175a9e6fa5fd7eaed9b5246d1a008f0a27c9a4
parent638afbb89b915742cf7705040f9b2a04592563ca (diff)
add some glue code between the idt82 driver and at91lib SPI
-rw-r--r--driver/idt82v2081.c18
-rw-r--r--driver/idt82v2081.h6
-rw-r--r--driver/idt82v2081_at91.c39
3 files changed, 63 insertions, 0 deletions
diff --git a/driver/idt82v2081.c b/driver/idt82v2081.c
index daf8c18..fe4f512 100644
--- a/driver/idt82v2081.c
+++ b/driver/idt82v2081.c
@@ -3,6 +3,24 @@
#include "idt82v2081.h"
#include "idt82v2081_regs.h"
+/*! \brief Set or clear some (masked) bits inside a register
+ * \param[in] e4k reference to the tuner
+ * \param[in] reg number of the register
+ * \param[in] mask bit-mask of the value
+ * \param[in] val data value to be written to register
+ * \returns 0 on success, negative in case of error
+ */
+static int idt82_reg_set_bit_mask(struct idt82 *idt, uint8_t reg,
+ uint8_t mask, uint8_t val)
+{
+ uint8_t tmp = idt82_reg_read(idt, reg);
+
+ if ((tmp & mask) == val)
+ return 0;
+
+ return idt82_reg_write(idt, reg, (tmp & ~mask) | (val & mask));
+}
+
int idt82_termination(struct idt82 *idt, enum idt82_term term)
{
idt82_reg_set_bit_mask(IDT_REG_TERM, term | (term << IDT_TERM_T_SHIFT),
diff --git a/driver/idt82v2081.h b/driver/idt82v2081.h
index 1d78093..6148492 100644
--- a/driver/idt82v2081.h
+++ b/driver/idt82v2081.h
@@ -18,6 +18,8 @@ enum idt82_mode {
struct idt82 {
enum idt82_mode mode;
enum idt82_term term;
+ void *priv;
+ uint8_t cs;
};
int idt82_termination(struct idt82 *idt, enum idt82_term term);
@@ -30,4 +32,8 @@ int idt82_init(struct idt82 *idt);
int idt82_reg_write(struct idt82 *idt, uint8_t reg, uin8_t val);
int idt82_reg_read(struct idt82 *idt, uint8_t reg);
+/* board specific initializers */
+int idt82_at91_init(struct idt82 *idt, void *spi, unsigned int id,
+ uint8_t cs, uint32_t spi_mr, uint32_t csr);
+
#endif
diff --git a/driver/idt82v2081_at91.c b/driver/idt82v2081_at91.c
new file mode 100644
index 0000000..b00ac0f
--- /dev/null
+++ b/driver/idt82v2081_at91.c
@@ -0,0 +1,39 @@
+#include <stdint.h>
+
+#include <spi/spi.h>
+
+#include "idt82v2081.h"
+
+/* Adaption layer between idt82 driver and at91lib SPI driver */
+
+#define B_READ (1 << 5)
+
+/* backend function for core idt82 driver */
+int idt82_reg_read(struct idt82 *idt, uint8_t reg)
+{
+ uint16_t res;
+
+ SPI_Write(idt->priv, idt->cs, (reg & 0x1F) | B_READ);
+ while (!SPI_IsFinished(idt->priv));
+ res = SPI_Read(idt->priv, idt->cs);
+
+ return res >> 8;
+}
+/* backend function for core idt82 driver */
+int idt82_reg_write(struct idt82 *idt, uint8_t reg, uint8_t val)
+{
+ SPI_Write(idt->priv, idt->cs, (reg & 0x1F) | B_READ | (val << 8));
+
+ return 0;
+}
+
+/* initialize the SPI interface to the IDT82 */
+int idt82_at91_init(struct idt82 *idt, void *spi, unsigned int id,
+ uint8_t cs, uint32_t spi_mr, uint32_t csr)
+{
+ idt->priv = spi;
+
+ SPI_Configure(spi, id, spi_mr);
+ SPI_ConfigureNCPS(spi, cs, csr);
+ SPI_Enable(spi);
+}