drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c- Extension
.c- Size
- 2523 bytes
- Lines
- 103
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/pci.hdrm/drm_atomic_helper.hdrm/drm_probe_helper.hhibmc_drm_drv.h
Detected Declarations
function Copyrightfunction hibmc_get_i2c_signalfunction hibmc_ddc_setsdafunction hibmc_ddc_setsclfunction hibmc_ddc_getsdafunction hibmc_ddc_getsclfunction hibmc_ddc_createfunction hibmc_ddc_del
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/* Hisilicon Hibmc SoC drm driver
*
* Based on the bochs drm driver.
*
* Copyright (c) 2016 Huawei Limited.
*
* Author:
* Tian Tao <tiantao6@hisilicon.com>
*/
#include <linux/delay.h>
#include <linux/pci.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_probe_helper.h>
#include "hibmc_drm_drv.h"
#define GPIO_DATA 0x0802A0
#define GPIO_DATA_DIRECTION 0x0802A4
#define I2C_SCL_MASK BIT(0)
#define I2C_SDA_MASK BIT(1)
static void hibmc_set_i2c_signal(void *data, u32 mask, int value)
{
struct hibmc_vdac *vdac = data;
struct hibmc_drm_private *priv = to_hibmc_drm_private(vdac->connector.dev);
u32 tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
if (value) {
tmp_dir &= ~mask;
writel(tmp_dir, priv->mmio + GPIO_DATA_DIRECTION);
} else {
u32 tmp_data = readl(priv->mmio + GPIO_DATA);
tmp_data &= ~mask;
writel(tmp_data, priv->mmio + GPIO_DATA);
tmp_dir |= mask;
writel(tmp_dir, priv->mmio + GPIO_DATA_DIRECTION);
}
}
static int hibmc_get_i2c_signal(void *data, u32 mask)
{
struct hibmc_vdac *vdac = data;
struct hibmc_drm_private *priv = to_hibmc_drm_private(vdac->connector.dev);
u32 tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
if ((tmp_dir & mask) != mask) {
tmp_dir &= ~mask;
writel(tmp_dir, priv->mmio + GPIO_DATA_DIRECTION);
}
return (readl(priv->mmio + GPIO_DATA) & mask) ? 1 : 0;
}
static void hibmc_ddc_setsda(void *data, int state)
{
hibmc_set_i2c_signal(data, I2C_SDA_MASK, state);
}
static void hibmc_ddc_setscl(void *data, int state)
{
hibmc_set_i2c_signal(data, I2C_SCL_MASK, state);
}
static int hibmc_ddc_getsda(void *data)
{
return hibmc_get_i2c_signal(data, I2C_SDA_MASK);
}
static int hibmc_ddc_getscl(void *data)
{
return hibmc_get_i2c_signal(data, I2C_SCL_MASK);
}
int hibmc_ddc_create(struct drm_device *drm_dev, struct hibmc_vdac *vdac)
{
vdac->adapter.owner = THIS_MODULE;
snprintf(vdac->adapter.name, I2C_NAME_SIZE, "HIS i2c bit bus");
vdac->adapter.dev.parent = drm_dev->dev;
i2c_set_adapdata(&vdac->adapter, vdac);
vdac->adapter.algo_data = &vdac->bit_data;
vdac->bit_data.udelay = 20;
vdac->bit_data.timeout = usecs_to_jiffies(2000);
vdac->bit_data.data = vdac;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/pci.h`, `drm/drm_atomic_helper.h`, `drm/drm_probe_helper.h`, `hibmc_drm_drv.h`.
- Detected declarations: `function Copyright`, `function hibmc_get_i2c_signal`, `function hibmc_ddc_setsda`, `function hibmc_ddc_setscl`, `function hibmc_ddc_getsda`, `function hibmc_ddc_getscl`, `function hibmc_ddc_create`, `function hibmc_ddc_del`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.