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