blob: e0a2b76353afb0660dcc75a41e2a30b4f1e5f423 [file] [log] [blame]
Patrick Delaunayfcb6b0b2020-06-29 10:34:06 +02001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * STMicroelectronics STUSB Type-C controller driver
4 * based on Linux drivers/usb/typec/stusb160x.c
5 *
6 * Copyright (C) 2020, STMicroelectronics - All Rights Reserved
7 */
8
9#include <common.h>
10#include <dm.h>
11#include <i2c.h>
12
13/* REGISTER */
14#define STUSB160X_CC_CONNECTION_STATUS 0x0E
15
16/* STUSB160X_CC_CONNECTION_STATUS bitfields */
17#define STUSB160X_CC_ATTACH BIT(0)
18
19int stusb160x_cable_connected(void)
20{
21 struct udevice *dev;
22 int ret;
23
24 ret = uclass_get_device_by_driver(UCLASS_I2C_GENERIC,
Simon Glass65130cd2020-12-28 20:34:56 -070025 DM_DRIVER_GET(stusb160x),
Patrick Delaunayfcb6b0b2020-06-29 10:34:06 +020026 &dev);
27 if (ret < 0)
28 return ret;
29
30 ret = dm_i2c_reg_read(dev, STUSB160X_CC_CONNECTION_STATUS);
31 if (ret < 0)
32 return 0;
33
34 return ret & STUSB160X_CC_ATTACH;
35}
36
37static const struct udevice_id stusb160x_ids[] = {
38 { .compatible = "st,stusb1600" },
39 {}
40};
41
42U_BOOT_DRIVER(stusb160x) = {
43 .name = "stusb160x",
44 .id = UCLASS_I2C_GENERIC,
45 .of_match = stusb160x_ids,
46};