// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2017-2020 Jacopo Mondi * Copyright (C) 2017-2020 Kieran Bingham * Copyright (C) 2017-2020 Laurent Pinchart * Copyright (C) 2017-2020 Niklas Söderlund * Copyright (C) 2016 Renesas Electronics Corporation * Copyright (C) 2015 Cogent Embedded, Inc. * * This file exports functions to control the Maxim MAX9271 GMSL serializer * chip. This is not a self-contained driver, as MAX9271 is usually embedded in * camera modules with at least one image sensor and optional additional * components, such as uController units or ISPs/DSPs. * * Drivers for the camera modules (i.e. rdacm20/21) are expected to use * functions exported from this library driver to maximize code re-use.
*/
ret = i2c_smbus_write_byte_data(dev->client, reg, val); if (ret < 0)
dev_err(&dev->client->dev, "%s: register 0x%02x write failed (%d)\n",
__func__, reg, ret);
return ret;
}
/* * max9271_pclk_detect() - Detect valid pixel clock from image sensor * * Wait up to 10ms for a valid pixel clock. * * Returns 0 for success, < 0 for pixel clock not properly detected
*/ staticint max9271_pclk_detect(struct max9271_device *dev)
{ unsignedint i; int ret;
for (i = 0; i < 100; i++) {
ret = max9271_read(dev, 0x15); if (ret < 0) return ret;
if (ret & MAX9271_PCLKDET) return 0;
usleep_range(50, 100);
}
dev_err(&dev->client->dev, "Unable to detect valid pixel clock\n");
return -EIO;
}
void max9271_wake_up(struct max9271_device *dev)
{ /* * Use the chip default address as this function has to be called * before any other one.
*/
dev->client->addr = MAX9271_DEFAULT_ADDR;
i2c_smbus_read_byte(dev->client);
usleep_range(5000, 8000);
}
EXPORT_SYMBOL_GPL(max9271_wake_up);
int max9271_set_serial_link(struct max9271_device *dev, bool enable)
{ int ret;
u8 val = MAX9271_REVCCEN | MAX9271_FWDCCEN;
if (enable) {
ret = max9271_pclk_detect(dev); if (ret) return ret;
val |= MAX9271_SEREN;
} else {
val |= MAX9271_CLINKEN;
}
/* * The serializer temporarily disables the reverse control channel for * 350µs after starting/stopping the forward serial link, but the * deserializer synchronization time isn't clearly documented. * * According to the serializer datasheet we should wait 3ms, while * according to the deserializer datasheet we should wait 5ms. * * Short delays here appear to show bit-errors in the writes following. * Therefore a conservative delay seems best here.
*/
ret = max9271_write(dev, 0x04, val); if (ret < 0) return ret;
int max9271_configure_i2c(struct max9271_device *dev, u8 i2c_config)
{ int ret;
ret = max9271_write(dev, 0x0d, i2c_config); if (ret < 0) return ret;
/* The delay required after an I2C bus configuration change is not * characterized in the serializer manual. Sleep up to 5msec to * stay safe.
*/
usleep_range(3500, 5000);
int max9271_set_high_threshold(struct max9271_device *dev, bool enable)
{ int ret;
ret = max9271_read(dev, 0x08); if (ret < 0) return ret;
/* * Enable or disable reverse channel high threshold to increase * immunity to power supply noise.
*/
ret = max9271_write(dev, 0x08, enable ? ret | BIT(0) : ret & ~BIT(0)); if (ret < 0) return ret;
int max9271_configure_gmsl_link(struct max9271_device *dev)
{ int ret;
/* * Configure the GMSL link: * * - Double input mode, high data rate, 24-bit mode * - Latch input data on PCLKIN rising edge * - Enable HS/VS encoding * - 1-bit parity error detection * * TODO: Make the GMSL link configuration parametric.
*/
ret = max9271_write(dev, 0x07, MAX9271_DBL | MAX9271_HVEN |
MAX9271_EDC_1BIT_PARITY); if (ret < 0) return ret;
usleep_range(5000, 8000);
/* * Adjust spread spectrum to +4% and auto-detect pixel clock * and serial link rate.
*/
ret = max9271_write(dev, 0x02,
MAX9271_SPREAD_SPECT_4 | MAX9271_R02_RES |
MAX9271_PCLK_AUTODETECT |
MAX9271_SERIAL_AUTODETECT); if (ret < 0) return ret;
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.