blob: 5c376015d7d8f8eaaa0ce3dd18dd9f792c47c911 [file] [log] [blame]
/*
* ltc4266.h
*
* LTC4266 driver header
*
* Author: Cradlepoint Technology, Inc. <source@cradlepoint.com>
* Kyle Swenson <kswenson@cradlepoint.com>
*
* Copyright 2019 Cradlepoint Technology, Inc.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __LTC4266_DRIVER_H__
#define __LTC4266_DRIVER_H__
enum {
READ_CURRENT = 0,
READ_VOLTAGE = 2
};
#define LTC4266_NPORTS 4
struct pse_port_device;
uint32_t ltc4266_read_iv(struct pse_port_device *port, uint8_t iv);
uint8_t ltc4266_port_stat(struct pse_port_device *port);
int ltc4266_port_disconnect_detect_enable(struct pse_port_device *port, int enable);
int ltc4266_port_class_enable(struct pse_port_device *port, int enable);
int ltc4266_port_detect_enable(struct pse_port_device *port, int enable);
int ltc4266_port_mode(struct pse_port_device *port, uint8_t opmd);
int ltc4266_port_power(struct pse_port_device *port, int enabled);
int ltc4266_port_highpower(struct pse_port_device *port, uint8_t enable);
int ltc4266_port_set_icut(struct pse_port_device *port, int icut);
int ltc4266_port_set_ilim(struct pse_port_device *port, int icut);
int ltc4266_port_legacy_enable(struct pse_port_device *port, uint8_t enable);
int ltc4266_port_init(struct pse_port_device *port);
int ltc4266_port_powered(struct pse_port_device *port);
uint8_t ltc4266_port_stat(struct pse_port_device *port);
int ltc4266_port_get_icut(struct pse_port_device *port);
int ltc4266_port_get_ilim(struct pse_port_device *port);
uint8_t class_map(uint8_t);
uint8_t detect_map(uint8_t);
/* This is the port operations structure that is registered with the pse class
* on a per-port basis. The structure and the functions that implement it are
* defined in ltc4266-ops
*/
extern struct pse_port_ops ltc4266_port_ops;
/* LTC4266 specific values for the disconnect event */
enum {
LTC4266_DISCONNECT_UNDERCURRENT,
LTC4266_DISCONNECT_OVERCURRENT,
LTC4266_DISCONNECT_STARTUP_OVERCURRENT,
};
/* LTC4266 specific values for the classification result */
enum {
LTC4266_CLASS_UNKNOWN = 0,
LTC4266_CLASS_1,
LTC4266_CLASS_2,
LTC4266_CLASS_3,
LTC4266_CLASS_4,
LTC4266_CLASS_ERR,
LTC4266_CLASS_0,
LTC4266_CLASS_OVERCURRENT
};
/* LTC4266 specific values for the detection result */
enum {
LTC4266_DETECT_INCOMPLETE = 0,
LTC4266_DETECT_SHORT,
LTC4266_DETECT_HIGHCAP,
LTC4266_DETECT_RSIG_LOW,
LTC4266_DETECT_RSIG_GOOD,
LTC4266_DETECT_RSIG_HIGH,
LTC4266_DETECT_OPEN,
LTC4266_DETECT_BAD_PORT_VOLTAGE
};
/* LTC4266 port operation mode. OPMD_SEMI is the only supported mode at this time */
enum {
OPMD_SHUTDOWN = 0,
OPMD_MANUAL,
OPMD_SEMI,
OPMD_AUTO
};
/* LTC4266 (global) Tstart time. Controls the length of the "Inrush" startup phase.*/
enum {
LTC4266_TSTART_60_MS = 0,
LTC4266_TSTART_30_MS,
LTC4266_TSTART_120_MS,
LTC4266_TSTART_240_MS
};
/* LTC4266- Controls the length of time for which a port may exceed icut*/
enum {
LTC4266_TCUT_60_MS = 0,
LTC4266_TCUT_30_MS,
LTC4266_TCUT_120_MS,
LTC4266_TCUT_240_MS
};
/* LTC4266- Controls the length time for which a may be in undercurrent without being considered "disconnected"*/
enum {
LTC4266_TDIS_360_MS = 0,
LTC4266_TDIS_90_MS,
LTC4266_TDIS_180_MS,
LTC4266_TDIS_720_MS
};
struct ltc4266_device {
struct pse_port_device *pse_ports[LTC4266_NPORTS];
struct i2c_client *client; /* I2C Client */
struct mutex lock; /* Protect Read-Modify-Write Sequences */
struct work_struct work_struct;
struct timer_list timer;
};
int ltc4266_write_reg(struct ltc4266_device *ltc4266, uint8_t reg, uint8_t value, uint8_t mask);
void ltc4266_enable_interrupts(struct i2c_client *client);
int ltc4266_disable_interrupts(struct i2c_client *client);
uint32_t ltc4266_read_iv(struct pse_port_device *port, uint8_t iv);
#endif