1 /* SPDX-License-Identifier: MIT */
3 * Copied from Linux drivers/gpu/drm/ast/ast_mode.c
6 #include <device/i2c_simple.h>
10 static struct ast_private
*ast
;
12 #define _GET_INDEX_REG(x) ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, (x))
15 static int get_clock(unsigned int bus
)
17 uint32_t val
, val2
, count
, pass
;
21 val
= (_GET_INDEX_REG(0x10) >> 4) & 0x01;
23 val2
= (_GET_INDEX_REG(0x10) >> 4) & 0x01;
28 val
= (_GET_INDEX_REG(0x10) >> 4) & 0x01;
30 } while ((pass
< 5) && (count
++ < 0x10000));
32 return val
& 1 ? 1 : 0;
35 static int get_data(unsigned int bus
)
37 uint32_t val
, val2
, count
, pass
;
41 val
= (_GET_INDEX_REG(0x20) >> 5) & 0x01;
43 val2
= (_GET_INDEX_REG(0x20) >> 5) & 0x01;
48 val
= (_GET_INDEX_REG(0x20) >> 5) & 0x01;
50 } while ((pass
< 5) && (count
++ < 0x10000));
52 return val
& 1 ? 1 : 0;
55 static void set_clock(unsigned int bus
, int clock
)
60 for (i
= 0; i
< 0x10000; i
++) {
61 ujcrb7
= ((clock
& 0x01) ? 0 : 1);
62 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb7, 0xf4, ujcrb7
);
63 jtemp
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb7, 0x01);
69 static void set_data(unsigned int bus
, int data
)
74 for (i
= 0; i
< 0x10000; i
++) {
75 ujcrb7
= ((data
& 0x01) ? 0 : 1) << 2;
76 ast_set_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb7, 0xf1, ujcrb7
);
77 jtemp
= ast_get_index_reg_mask(ast
, AST_IO_CRTC_PORT
, 0xb7, 0x04);
83 static struct software_i2c_ops ast_ops
= {
90 int ast_software_i2c_read(struct ast_private
*ast_priv
, uint8_t edid
[128])
92 struct software_i2c_ops
*backup
;
95 backup
= software_i2c
[ASPEED_BUS
];
97 software_i2c
[ASPEED_BUS
] = &ast_ops
;
101 /* Ast POST pulled SDA and SCL low, recover the bus to a known state */
102 set_clock(ASPEED_BUS
, 1);
103 set_data(ASPEED_BUS
, 1);
107 /* Need to reset internal EEPROM counter to 0 */
108 ret
= i2c_read_bytes(ASPEED_BUS
, 0x50, 0, edid
, 128);
110 software_i2c
[ASPEED_BUS
] = backup
;