Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2018 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 #include "dce_i2c.h"
0026 #include "reg_helper.h"
0027 
0028 bool dce_i2c_oem_device_present(
0029     struct resource_pool *pool,
0030     struct ddc_service *ddc,
0031     size_t slave_address
0032 )
0033 {
0034     struct dc *dc = ddc->ctx->dc;
0035     struct dc_bios *dcb = dc->ctx->dc_bios;
0036     struct graphics_object_id id = {0};
0037     struct graphics_object_i2c_info i2c_info;
0038 
0039     if (!dc->ctx->dc_bios->fw_info.oem_i2c_present)
0040         return false;
0041 
0042     id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
0043     id.enum_id = 0;
0044     id.type = OBJECT_TYPE_GENERIC;
0045     if (dcb->funcs->get_i2c_info(dcb, id, &i2c_info) != BP_RESULT_OK)
0046         return false;
0047 
0048     if (i2c_info.i2c_slave_address != slave_address)
0049         return false;
0050 
0051     return true;
0052 }
0053 
0054 bool dce_i2c_submit_command(
0055     struct resource_pool *pool,
0056     struct ddc *ddc,
0057     struct i2c_command *cmd)
0058 {
0059     struct dce_i2c_hw *dce_i2c_hw;
0060     struct dce_i2c_sw dce_i2c_sw = {0};
0061 
0062     if (!ddc) {
0063         BREAK_TO_DEBUGGER();
0064         return false;
0065     }
0066 
0067     if (!cmd) {
0068         BREAK_TO_DEBUGGER();
0069         return false;
0070     }
0071 
0072     dce_i2c_hw = acquire_i2c_hw_engine(pool, ddc);
0073 
0074     if (dce_i2c_hw)
0075         return dce_i2c_submit_command_hw(pool, ddc, cmd, dce_i2c_hw);
0076 
0077     dce_i2c_sw.ctx = ddc->ctx;
0078     if (dce_i2c_engine_acquire_sw(&dce_i2c_sw, ddc)) {
0079         return dce_i2c_submit_command_sw(pool, ddc, cmd, &dce_i2c_sw);
0080     }
0081 
0082     return false;
0083 }