/*
* USB Type-C Connector Class
*
* Copyright (C) 2017, Intel Corporation
* Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/device.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/usb/typec.h>
struct typec_mode {
int index;
u32 vdo;
char *desc;
enum typec_port_type roles;
struct typec_altmode *alt_mode;
unsigned int active:1;
char group_name[6];
struct attribute_group group;
struct attribute *attrs[5];
struct device_attribute vdo_attr;
struct device_attribute desc_attr;
struct device_attribute active_attr;
struct device_attribute roles_attr;
};
struct typec_altmode {
struct device dev;
u16 svid;
int n_modes;
struct typec_mode modes[ALTMODE_MAX_MODES];
const struct attribute_group *mode_groups[ALTMODE_MAX_MODES];
};
struct typec_plug {
struct device dev;
enum typec_plug_index index;
};
struct typec_cable {
struct device dev;
enum typec_plug_type type;
struct usb_pd_identity *identity;
unsigned int active:1;
};
struct typec_partner {
struct device dev;
unsigned int usb_pd:1;
struct usb_pd_identity *identity;
enum typec_accessory accessory;
};
struct typec_port {
unsigned int id;
struct device dev;
int prefer_role;
enum typec_data_role data_role;
enum typec_role pwr_role;
enum typec_role vconn_role;
enum typec_pwr_opmode pwr_opmode;
enum typec_port_type port_type;
struct mutex port_type_lock;
const struct typec_capability *cap;
};
#define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
#define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
#define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
#define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
#define to_altmode(_dev_) container_of(_dev_, struct typec_altmode, dev)
static const struct device_type typec_partner_dev_type;
static const struct device_type typec_cable_dev_type;
static const struct device_type typec_plug_dev_type;
static const struct device_type typec_port_dev_type;
#define is_typec_partner(_dev_) (_dev_->type == &typec_partner_dev_type)
#define is_typec_cable(_dev_) (_dev_->type == &typec_cable_dev_type)
#define is_typec_plug(_dev_) (_dev_->type == &typec_plug_dev_type)
#define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type)
static DEFINE_IDA(typec_index_ida);
static struct class *typec_class;
/* Common attributes */
stati