1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <hostIntf.h>
18 #include <hostIntf_priv.h>
19 #include <variant/inc/variant.h>
20 #include <plat/inc/bl.h>
21 #include <plat/inc/cmsis.h>
22 #include <plat/inc/spi.h>
23
24
platHostIntfInit()25 const struct HostIntfComm *platHostIntfInit()
26 {
27 uint32_t priorityGroup = NVIC_GetPriorityGrouping();
28 uint32_t priority, preemptPriority, subPriority;
29 enum IRQn rx, tx;
30 const struct HostIntfComm *ret = NULL;
31
32 #if defined(PLATFORM_HOST_INTF_I2C_BUS)
33 ret = hostIntfI2cInit(PLATFORM_HOST_INTF_I2C_BUS);
34 #elif defined(PLATFORM_HOST_INTF_SPI_BUS)
35 ret = hostIntfSpiInit(PLATFORM_HOST_INTF_SPI_BUS);
36
37 /* get the rx and tx irq numbers used by the host spi bus */
38 ret->request();
39 rx = spiRxIrq(PLATFORM_HOST_INTF_SPI_BUS);
40 tx = spiTxIrq(PLATFORM_HOST_INTF_SPI_BUS);
41 ret->release();
42
43 /* make the tx and rx dma isrs execute before other isrs when multiple
44 interrupts are pending (if avaliable subpriority bits).
45 We do not change the preempt priority */
46 priority = NVIC_GetPriority(rx);
47 NVIC_DecodePriority (priority, priorityGroup, &preemptPriority, &subPriority);
48 if (&subPriority > 0)
49 subPriority --;
50 NVIC_SetPriority(rx, NVIC_EncodePriority(priorityGroup, preemptPriority, subPriority));
51
52 priority = NVIC_GetPriority(tx);
53 NVIC_DecodePriority (priority, priorityGroup, &preemptPriority, &subPriority);
54 if (&subPriority > 0)
55 subPriority --;
56 NVIC_SetPriority(tx, NVIC_EncodePriority(priorityGroup, preemptPriority, subPriority));
57 #else
58 #error "No host interface bus specified"
59 #endif
60 return ret;
61 }
62
platHwType(void)63 uint16_t platHwType(void)
64 {
65 return PLATFORM_HW_TYPE;
66 }
67
platHwVer(void)68 uint16_t platHwVer(void)
69 {
70 return PLATFORM_HW_VER;
71 }
72
platBlVer()73 uint16_t platBlVer()
74 {
75 return BL.blGetVersion();
76 }
77