File: evdi_i2c.c

package info (click to toggle)
evdi 1.14.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576 kB
  • sloc: ansic: 5,575; cpp: 474; python: 163; sh: 147; makefile: 143
file content (58 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2020 DisplayLink (UK) Ltd.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License v2. See the file COPYING in the main directory of this archive for
 * more details.
 */

#include "evdi_i2c.h"
#include "evdi_debug.h"
#include "evdi_drm_drv.h"

static int dli2c_access_master(struct i2c_adapter *adapter,
	struct i2c_msg *msgs, int num)
{
	int i = 0, result = 0;
	struct evdi_device *evdi = adapter->algo_data;
	struct evdi_painter *painter = evdi->painter;

	for (i = 0; i < num; i++) {
		if (evdi_painter_i2c_data_notify(painter, &msgs[i]))
			result++;
	}

	return result;
}

static u32 dli2c_func(__always_unused struct i2c_adapter *adapter)
{
	return I2C_FUNC_I2C;
}

static struct i2c_algorithm dli2c_algorithm = {
	.master_xfer = dli2c_access_master,
	.functionality = dli2c_func,
};

int evdi_i2c_add(struct i2c_adapter *adapter, struct device *parent,
	void *ddev)
{
	adapter->owner  = THIS_MODULE;
#if KERNEL_VERSION(6, 8, 0) <= LINUX_VERSION_CODE || defined(EL9)
#else
	adapter->class  = I2C_CLASS_DDC;
#endif
	adapter->algo   = &dli2c_algorithm;
	strscpy(adapter->name, "DisplayLink I2C Adapter", sizeof(adapter->name));
	adapter->dev.parent = parent;
	adapter->algo_data = ddev;

	return i2c_add_adapter(adapter);
}

void evdi_i2c_remove(struct i2c_adapter *adapter)
{
	i2c_del_adapter(adapter);
}