diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/spi-dm320.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/spi-dm320.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/firmware/target/arm/tms320dm320/spi-dm320.c b/firmware/target/arm/tms320dm320/spi-dm320.c index 2d5637b70e..262b0611ac 100644 --- a/firmware/target/arm/tms320dm320/spi-dm320.c +++ b/firmware/target/arm/tms320dm320/spi-dm320.c | |||
@@ -39,16 +39,24 @@ struct SPI_info { | |||
39 | volatile unsigned short *setreg; | 39 | volatile unsigned short *setreg; |
40 | volatile unsigned short *clrreg; | 40 | volatile unsigned short *clrreg; |
41 | int bit; | 41 | int bit; |
42 | bool idle_low; | ||
43 | char divider; | ||
42 | }; | 44 | }; |
43 | 45 | ||
44 | struct SPI_info spi_targets[] = | 46 | struct SPI_info spi_targets[] = |
45 | { | 47 | { |
46 | #ifndef CREATIVE_ZVx | 48 | #ifndef CREATIVE_ZVx |
47 | [SPI_target_TSC2100] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_TS_ENABLE }, | 49 | [SPI_target_TSC2100] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, |
48 | [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, GIO_RTC_ENABLE}, | 50 | GIO_TS_ENABLE, true, 0x07}, |
49 | [SPI_target_BACKLIGHT] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_BL_ENABLE }, | 51 | /* RTC seems to have timing problems if the CLK idles low */ |
52 | [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, | ||
53 | GIO_RTC_ENABLE, false, 0x3F}, | ||
54 | /* This appears to work properly idleing low, idling high is very glitchy */ | ||
55 | [SPI_target_BACKLIGHT] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, | ||
56 | GIO_BL_ENABLE, true, 0x07}, | ||
50 | #else | 57 | #else |
51 | [SPI_target_LTV250QV] = { &IO_GIO_BITCLR2, &IO_GIO_BITSET2, GIO_LCD_ENABLE}, | 58 | [SPI_target_LTV250QV] = { &IO_GIO_BITCLR2, &IO_GIO_BITSET2, |
59 | GIO_LCD_ENABLE, true, 0x07}, | ||
52 | #endif | 60 | #endif |
53 | }; | 61 | }; |
54 | 62 | ||
@@ -65,22 +73,27 @@ static void spi_disable_all_targets(void) | |||
65 | } | 73 | } |
66 | 74 | ||
67 | int spi_block_transfer(enum SPI_target target, | 75 | int spi_block_transfer(enum SPI_target target, |
68 | const bool spi_msb_first, | ||
69 | const uint8_t *tx_bytes, unsigned int tx_size, | 76 | const uint8_t *tx_bytes, unsigned int tx_size, |
70 | uint8_t *rx_bytes, unsigned int rx_size) | 77 | uint8_t *rx_bytes, unsigned int rx_size) |
71 | { | 78 | { |
72 | mutex_lock(&spi_mtx); | 79 | mutex_lock(&spi_mtx); |
73 | 80 | ||
74 | IO_SERIAL0_MODE = (IO_SERIAL0_MODE& ~(spi_msb_first<<9))|(spi_msb_first<<9); | 81 | IO_SERIAL0_MODE &= ~(1<<10); |
82 | IO_SERIAL0_MODE |= (spi_targets[target].idle_low << 10); | ||
83 | |||
84 | IO_SERIAL0_MODE &= ~(0xFF); | ||
85 | IO_SERIAL0_MODE |= spi_targets[target].divider; | ||
75 | 86 | ||
76 | /* Activate the slave select pin */ | 87 | /* Activate the slave select pin */ |
77 | *spi_targets[target].setreg = spi_targets[target].bit; | 88 | if(tx_size) { |
89 | IO_SERIAL0_TX_ENABLE = 0x0001; | ||
90 | *spi_targets[target].setreg = spi_targets[target].bit; | ||
91 | } | ||
78 | 92 | ||
79 | while (tx_size--) | 93 | while (tx_size--) |
80 | { | 94 | { |
81 | /* Send one byte */ | 95 | /* Send one byte */ |
82 | IO_SERIAL0_TX_DATA = *tx_bytes++; | 96 | IO_SERIAL0_TX_DATA = *tx_bytes++; |
83 | |||
84 | /* Wait until transfer finished */ | 97 | /* Wait until transfer finished */ |
85 | while (IO_SERIAL0_RX_DATA & IO_SERIAL0_XMIT); | 98 | while (IO_SERIAL0_RX_DATA & IO_SERIAL0_XMIT); |
86 | } | 99 | } |
@@ -106,8 +119,8 @@ int spi_block_transfer(enum SPI_target target, | |||
106 | void spi_init(void) | 119 | void spi_init(void) |
107 | { | 120 | { |
108 | mutex_init(&spi_mtx); | 121 | mutex_init(&spi_mtx); |
109 | 122 | ||
110 | IO_SERIAL0_MODE = 0x3607; | 123 | IO_SERIAL0_MODE = 0x2200 | 0x3F; |
111 | /* Enable TX */ | 124 | /* Enable TX */ |
112 | IO_SERIAL0_TX_ENABLE = 0x0001; | 125 | IO_SERIAL0_TX_ENABLE = 0x0001; |
113 | #ifndef CREATIVE_ZVx | 126 | #ifndef CREATIVE_ZVx |
@@ -115,7 +128,8 @@ void spi_init(void) | |||
115 | IO_GIO_DIR1 &= ~GIO_TS_ENABLE; | 128 | IO_GIO_DIR1 &= ~GIO_TS_ENABLE; |
116 | /* Set GIO 12 to output for rtc slave enable */ | 129 | /* Set GIO 12 to output for rtc slave enable */ |
117 | IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; | 130 | IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; |
118 | #endif | 131 | #endif |
119 | spi_disable_all_targets(); /* make sure only one is ever enabled at a time */ | 132 | /* make sure only one is ever enabled at a time */ |
133 | spi_disable_all_targets(); | ||
120 | 134 | ||
121 | } | 135 | } |