opentitanlib/transport/hyperdebug/
ti50.rs

1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5use anyhow::{Result, bail};
6use std::rc::Rc;
7
8use crate::io::gpio::GpioPin;
9use crate::transport::hyperdebug::i2c::Mode;
10use crate::transport::hyperdebug::{Flavor, Inner, StandardFlavor, VID_GOOGLE};
11use crate::transport::{TransportError, TransportInterfaceType};
12
13// The GSC has some capability to control GPIO lines inside a Chromebook, and to program the AP
14// firmware flash chip via SPI.  This "flavor" allows OpenTitanTool to access those capabilities.
15pub struct Ti50Flavor {}
16
17impl Ti50Flavor {
18    const PID_TI50: u16 = 0x504a;
19}
20
21impl Flavor for Ti50Flavor {
22    fn gpio_pin(inner: &Rc<Inner>, pinname: &str) -> Result<Rc<dyn GpioPin>> {
23        StandardFlavor::gpio_pin(inner, pinname)
24    }
25
26    fn spi_index(_inner: &Rc<Inner>, instance: &str) -> Result<(u8, u8)> {
27        if instance == "AP" {
28            return Ok((super::spi::USB_SPI_REQ_ENABLE_AP, 0));
29        } else if instance == "EC" {
30            return Ok((super::spi::USB_SPI_REQ_ENABLE_EC, 0));
31        }
32        bail!(TransportError::InvalidInstance(
33            TransportInterfaceType::Spi,
34            instance.to_string()
35        ))
36    }
37
38    fn i2c_index(_inner: &Rc<Inner>, instance: &str) -> Result<(u8, Mode)> {
39        if instance == "I2C1" {
40            return Ok((0, Mode::Host));
41        } else if instance == "I2C2" {
42            return Ok((1, Mode::Host));
43        }
44        bail!(TransportError::InvalidInstance(
45            TransportInterfaceType::I2c,
46            instance.to_string()
47        ))
48    }
49
50    fn get_default_usb_vid() -> u16 {
51        VID_GOOGLE
52    }
53
54    fn get_default_usb_pid() -> u16 {
55        Self::PID_TI50
56    }
57}