2 * rl6347a.c - RL6347A class device shared support
4 * Copyright 2015 Realtek Semiconductor Corp.
6 * Author: Oder Chiou <oder_chiou@realtek.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/i2c.h>
15 #include <linux/regmap.h>
19 int rl6347a_hw_write(void *context
, unsigned int reg
, unsigned int value
)
21 struct i2c_client
*client
= context
;
22 struct rl6347a_priv
*rl6347a
= i2c_get_clientdata(client
);
26 /* handle index registers */
28 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
29 for (i
= 0; i
< rl6347a
->index_cache_size
; i
++) {
30 if (reg
== rl6347a
->index_cache
[i
].reg
) {
31 rl6347a
->index_cache
[i
].def
= value
;
36 reg
= RL6347A_PROC_COEF
;
39 data
[0] = (reg
>> 24) & 0xff;
40 data
[1] = (reg
>> 16) & 0xff;
42 * 4 bit VID: reg should be 0
43 * 12 bit VID: value should be 0
44 * So we use an OR operator to handle it rather than use if condition.
46 data
[2] = ((reg
>> 8) & 0xff) | ((value
>> 8) & 0xff);
47 data
[3] = value
& 0xff;
49 ret
= i2c_master_send(client
, data
, 4);
54 dev_err(&client
->dev
, "I2C error %d\n", ret
);
60 EXPORT_SYMBOL_GPL(rl6347a_hw_write
);
62 int rl6347a_hw_read(void *context
, unsigned int reg
, unsigned int *value
)
64 struct i2c_client
*client
= context
;
65 struct i2c_msg xfer
[2];
68 unsigned int index
, vid
, buf
= 0x0;
70 /* handle index registers */
72 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
73 reg
= RL6347A_PROC_COEF
;
77 vid
= (reg
>> 8) & 0xfff;
79 if (AC_VERB_GET_AMP_GAIN_MUTE
== (vid
& 0xf00)) {
80 index
= (reg
>> 8) & 0xf;
81 reg
= (reg
& ~0xf0f) | index
;
83 be_reg
= cpu_to_be32(reg
);
86 xfer
[0].addr
= client
->addr
;
89 xfer
[0].buf
= (u8
*)&be_reg
;
92 xfer
[1].addr
= client
->addr
;
93 xfer
[1].flags
= I2C_M_RD
;
95 xfer
[1].buf
= (u8
*)&buf
;
97 ret
= i2c_transfer(client
->adapter
, xfer
, 2);
103 *value
= be32_to_cpu(buf
);
107 EXPORT_SYMBOL_GPL(rl6347a_hw_read
);
109 MODULE_DESCRIPTION("RL6347A class device shared support");
110 MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
111 MODULE_LICENSE("GPL v2");