1 // SPDX-License-Identifier: GPL-2.0-only
3 * rl6347a.c - RL6347A class device shared support
5 * Copyright 2015 Realtek Semiconductor Corp.
7 * Author: Oder Chiou <oder_chiou@realtek.com>
10 #include <linux/module.h>
11 #include <linux/i2c.h>
12 #include <linux/regmap.h>
16 int rl6347a_hw_write(void *context
, unsigned int reg
, unsigned int value
)
18 struct i2c_client
*client
= context
;
19 struct rl6347a_priv
*rl6347a
= i2c_get_clientdata(client
);
23 /* handle index registers */
25 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
26 for (i
= 0; i
< rl6347a
->index_cache_size
; i
++) {
27 if (reg
== rl6347a
->index_cache
[i
].reg
) {
28 rl6347a
->index_cache
[i
].def
= value
;
33 reg
= RL6347A_PROC_COEF
;
36 data
[0] = (reg
>> 24) & 0xff;
37 data
[1] = (reg
>> 16) & 0xff;
39 * 4 bit VID: reg should be 0
40 * 12 bit VID: value should be 0
41 * So we use an OR operator to handle it rather than use if condition.
43 data
[2] = ((reg
>> 8) & 0xff) | ((value
>> 8) & 0xff);
44 data
[3] = value
& 0xff;
46 ret
= i2c_master_send(client
, data
, 4);
51 dev_err(&client
->dev
, "I2C error %d\n", ret
);
57 EXPORT_SYMBOL_GPL(rl6347a_hw_write
);
59 int rl6347a_hw_read(void *context
, unsigned int reg
, unsigned int *value
)
61 struct i2c_client
*client
= context
;
62 struct i2c_msg xfer
[2];
64 __be32 be_reg
, buf
= 0x0;
65 unsigned int index
, vid
;
67 /* handle index registers */
69 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
70 reg
= RL6347A_PROC_COEF
;
74 vid
= (reg
>> 8) & 0xfff;
76 if (AC_VERB_GET_AMP_GAIN_MUTE
== (vid
& 0xf00)) {
77 index
= (reg
>> 8) & 0xf;
78 reg
= (reg
& ~0xf0f) | index
;
80 be_reg
= cpu_to_be32(reg
);
83 xfer
[0].addr
= client
->addr
;
86 xfer
[0].buf
= (u8
*)&be_reg
;
89 xfer
[1].addr
= client
->addr
;
90 xfer
[1].flags
= I2C_M_RD
;
92 xfer
[1].buf
= (u8
*)&buf
;
94 ret
= i2c_transfer(client
->adapter
, xfer
, 2);
100 *value
= be32_to_cpu(buf
);
104 EXPORT_SYMBOL_GPL(rl6347a_hw_read
);
106 MODULE_DESCRIPTION("RL6347A class device shared support");
107 MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
108 MODULE_LICENSE("GPL v2");