| // Copyright 2017 The Fuchsia Authors. All rights reserved. |
| // |
| // Redistribution and use in source and binary forms, with or without |
| // modification, are permitted provided that the following conditions are |
| // met: |
| // |
| // * Redistributions of source code must retain the above copyright |
| // notice, this list of conditions and the following disclaimer. |
| // * Redistributions in binary form must reproduce the above |
| // copyright notice, this list of conditions and the following disclaimer |
| // in the documentation and/or other materials provided with the |
| // distribution. |
| // * Neither the name of Google Inc. nor the names of its |
| // contributors may be used to endorse or promote products derived from |
| // this software without specific prior written permission. |
| // |
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| #include <err.h> |
| #include <debug.h> |
| #include <target.h> |
| #include <compiler.h> |
| #include <dev/gpio.h> |
| #include <dev/i2c.h> |
| #include <lib/console.h> |
| #include <platform/gpio.h> |
| #include <platform/stm32.h> |
| #include <platform/usbc.h> |
| #include <target/gpioconfig.h> |
| #include <target/usb.h> |
| |
| static uint8_t board_id; |
| |
| void target_early_init(void) |
| { |
| gpio_config(GPIO_UART_TX, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_UART_RX, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| |
| gpio_config(GPIO_SCL, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_SDA, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_ALERT_HIGH, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| gpio_config(GPIO_ALERT_LOW, GPIO_STM32_AF | GPIO_STM32_AFn(1)); |
| |
| gpio_config(GPIO_BOARD_ID0, GPIO_INPUT); |
| gpio_config(GPIO_BOARD_ID1, GPIO_INPUT); |
| gpio_config(GPIO_BOARD_ID2, GPIO_INPUT); |
| gpio_config(GPIO_BOARD_ID3, GPIO_INPUT); |
| |
| gpio_set(GPIO_LED_RED, 1); |
| gpio_set(GPIO_LED_GREEN, 1); |
| gpio_set(GPIO_LED_BLUE, 1); |
| |
| gpio_config(GPIO_LED_RED, GPIO_OUTPUT | GPIO_STM32_OD); |
| gpio_config(GPIO_LED_GREEN, GPIO_OUTPUT | GPIO_STM32_OD); |
| gpio_config(GPIO_LED_BLUE, GPIO_OUTPUT | GPIO_STM32_OD); |
| |
| gpio_set(GPIO_POWER_ENABLE_J, 0); |
| gpio_config(GPIO_POWER_ENABLE_J, GPIO_OUTPUT); |
| |
| board_id = gpio_get(GPIO_BOARD_ID0) |
| | gpio_get(GPIO_BOARD_ID1) << 1 |
| | gpio_get(GPIO_BOARD_ID2) << 2 |
| | gpio_get(GPIO_BOARD_ID3) << 3; |
| |
| stm32_debug_early_init(); |
| i2c_init_early(); |
| } |
| |
| void target_init(void) |
| { |
| stm32_debug_init(); |
| i2c_init(); |
| stm32_usbc_init(); |
| target_usb_setup(); |
| |
| printf("zedmon online. board_id=%1x\n", board_id); |
| } |
| |
| void target_set_debug_led(unsigned int led, bool on) |
| { |
| switch (led) { |
| case 0: |
| gpio_set(GPIO_LED_RED, !on); |
| break; |
| } |
| } |