// SPDX-License-Identifier: GPL-2.0 /* * The Gateworks System Controller (GSC) is a multi-function * device designed for use in Gateworks Single Board Computers. * The control interface is I2C, with an interrupt. The device supports * system functions such as push-button monitoring, multiple ADC's for * voltage and temperature monitoring, fan controller and watchdog monitor. * * Copyright (C) 2020 Gateworks Corporation
*/
/* * The GSC suffers from an errata where occasionally during * ADC cycles the chip can NAK I2C transactions. To ensure we have reliable * register access we place retries around register access.
*/ #define I2C_RETRIES 3
int gsc_write(void *context, unsignedint reg, unsignedint val)
{ struct i2c_client *client = context; int retry, ret;
for (retry = 0; retry < I2C_RETRIES; retry++) {
ret = i2c_smbus_write_byte_data(client, reg, val); /* * -EAGAIN returned when the i2c host controller is busy * -EIO returned when i2c device is busy
*/ if (ret != -EAGAIN && ret != -EIO) break;
}
return 0;
}
EXPORT_SYMBOL_GPL(gsc_write);
int gsc_read(void *context, unsignedint reg, unsignedint *val)
{ struct i2c_client *client = context; int retry, ret;
for (retry = 0; retry < I2C_RETRIES; retry++) {
ret = i2c_smbus_read_byte_data(client, reg); /* * -EAGAIN returned when the i2c host controller is busy * -EIO returned when i2c device is busy
*/ if (ret != -EAGAIN && ret != -EIO) break;
}
*val = ret & 0xff;
return 0;
}
EXPORT_SYMBOL_GPL(gsc_read);
/* * gsc_powerdown - API to use GSC to power down board for a specific time * * secs - number of seconds to remain powered off
*/ staticint gsc_powerdown(struct gsc_dev *gsc, unsignedlong secs)
{ int ret; unsignedchar regs[4];
dev_info(&gsc->i2c->dev, "GSC powerdown for %ld seconds\n",
secs);
put_unaligned_le32(secs, regs);
ret = regmap_bulk_write(gsc->regmap, GSC_TIME_ADD, regs, 4); if (ret) return ret;
ret = regmap_update_bits(gsc->regmap, GSC_CTRL_1,
BIT(GSC_CTRL_1_SLEEP_ADD),
BIT(GSC_CTRL_1_SLEEP_ADD)); if (ret) return ret;
ret = regmap_update_bits(gsc->regmap, GSC_CTRL_1,
BIT(GSC_CTRL_1_SLEEP_ACTIVATE) |
BIT(GSC_CTRL_1_SLEEP_ENABLE),
BIT(GSC_CTRL_1_SLEEP_ACTIVATE) |
BIT(GSC_CTRL_1_SLEEP_ENABLE));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.