2 * Copyright (c) 2015 NVIDIA Corporation. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include <linux/slab.h>
26 #include <drm/drm_scdc_helper.h>
31 * Status and Control Data Channel (SCDC) is a mechanism introduced by the
32 * HDMI 2.0 specification. It is a point-to-point protocol that allows the
33 * HDMI source and HDMI sink to exchange data. The same I2C interface that
34 * is used to access EDID serves as the transport mechanism for SCDC.
37 #define SCDC_I2C_SLAVE_ADDRESS 0x54
40 * drm_scdc_read - read a block of data from SCDC
41 * @adapter: I2C controller
42 * @offset: start offset of block to read
43 * @buffer: return location for the block to read
44 * @size: size of the block to read
46 * Reads a block of data from SCDC, starting at a given offset.
49 * The number of bytes read from SCDC or a negative error code on failure.
51 ssize_t drm_scdc_read(struct i2c_adapter *adapter, u8 offset, void *buffer,
54 struct i2c_msg msgs[2] = {
56 .addr = SCDC_I2C_SLAVE_ADDRESS,
61 .addr = SCDC_I2C_SLAVE_ADDRESS,
68 return i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
70 EXPORT_SYMBOL(drm_scdc_read);
73 * drm_scdc_write - write a block of data to SCDC
74 * @adapter: I2C controller
75 * @offset: start offset of block to write
76 * @buffer: block of data to write
77 * @size: size of the block to write
79 * Writes a block of data to SCDC, starting at a given offset.
82 * The number of bytes written to SCDC or a negative error code on failure.
84 ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset,
85 const void *buffer, size_t size)
87 struct i2c_msg msg = {
88 .addr = SCDC_I2C_SLAVE_ADDRESS,
96 data = kmalloc(1 + size, GFP_KERNEL);
102 memcpy(data, &offset, sizeof(offset));
103 memcpy(data + 1, buffer, size);
105 err = i2c_transfer(adapter, &msg, 1);
111 EXPORT_SYMBOL(drm_scdc_write);