blob: e1ad8b00717a5ecfb9fe4cea771668e67f929ff8 [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
Patrick Delaunay9742bee2020-11-06 19:02:00 +01009#define LOG_CATEGORY UCLASS_I2C_GENERIC
10
Patrick Delaunayfcb6b0b2020-06-29 10:34:06 +020011#include <dm.h>
12#include <i2c.h>
13
14/* REGISTER */
15#define STUSB160X_CC_CONNECTION_STATUS 0x0E
16
17/* STUSB160X_CC_CONNECTION_STATUS bitfields */
18#define STUSB160X_CC_ATTACH BIT(0)
19
20int stusb160x_cable_connected(void)
21{
22 struct udevice *dev;
23 int ret;
24
25 ret = uclass_get_device_by_driver(UCLASS_I2C_GENERIC,
Simon Glass65130cd2020-12-28 20:34:56 -070026 DM_DRIVER_GET(stusb160x),
Patrick Delaunayfcb6b0b2020-06-29 10:34:06 +020027 &dev);
28 if (ret < 0)
29 return ret;
30
31 ret = dm_i2c_reg_read(dev, STUSB160X_CC_CONNECTION_STATUS);
32 if (ret < 0)
33 return 0;
34
35 return ret & STUSB160X_CC_ATTACH;
36}
37
38static const struct udevice_id stusb160x_ids[] = {
39 { .compatible = "st,stusb1600" },
40 {}
41};
42
43U_BOOT_DRIVER(stusb160x) = {
44 .name = "stusb160x",
45 .id = UCLASS_I2C_GENERIC,
46 .of_match = stusb160x_ids,
47};