Commit cc416a8b authored by Sam Hurst's avatar Sam Hurst Committed by Carles Cufi
Browse files

usb-c: tcpc: Add support for Dead Battery



Add Dead Battery functionality to the TCPC drive

Signed-off-by: default avatarSam Hurst <sbh1187@gmail.com>
parent de0a64fa
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1382,6 +1382,20 @@ static int ucpd_init(const struct device *dev)
		/* Enable UCPD port */
		LL_UCPD_Enable(config->ucpd_port);

		/* Enable Dead Battery Support */
		if (config->ucpd_dead_battery) {
#ifdef CONFIG_SOC_SERIES_STM32G0X
			uint32_t cr;

			cr = LL_UCPD_ReadReg(config->ucpd_port, CR);
			cr |= UCPD_CR_DBATTEN;
			LL_UCPD_WriteReg(config->ucpd_port, CR, cr);
			update_stm32g0x_cc_line(config->ucpd_port);
#else
			CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS);
#endif
		}

		/* Initialize the isr */
		ucpd_isr_init(dev);
	} else {
@@ -1445,6 +1459,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 0,
		.ucpd_params.transwin = DT_INST_PROP(inst, transwin) - 1,		\
		.ucpd_params.IfrGap = DT_INST_PROP(inst, ifrgap) - 1,			\
		.ucpd_params.HbitClockDiv = DT_INST_PROP(inst, hbitclkdiv) - 1,		\
		.ucpd_dead_battery = DT_INST_PROP(inst, dead_battery),			\
	};										\
	DEVICE_DT_INST_DEFINE(inst,							\
			      &ucpd_init,						\
+8 −0
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@
			       UCPD_ICR_TXMSGSENTCF | \
			       UCPD_ICR_TXMSGDISCCF)

/**
 * @brief For STM32G0X devices, this macro enables
 *	  Dead Battery functionality
 */
#define UCPD_CR_DBATTEN BIT(15)

/**
 * @brief Map UCPD ANASUB value to TCPC RP value
 *
@@ -259,6 +265,8 @@ struct tcpc_config {
	UCPD_TypeDef *ucpd_port;
	/* STM32 UCPD parameters */
	LL_UCPD_InitTypeDef ucpd_params;
	/* STM32 UCPD dead battery support */
	bool ucpd_dead_battery;
};

/**
+6 −0
Original line number Diff line number Diff line
@@ -63,6 +63,12 @@ properties:
      half-bit clock (hbit_clk)
      Valid range: 1 - 64

  dead-battery:
    type: boolean
    description: |
      Determine if USB-C Dead Battery pull-down's should be
      applied to the CC lines.

  pinctrl-0:
    required: true