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/moduleparam.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/platform_device.h>
20 #include <linux/spi/spi.h>
21 #include <linux/dmi.h>
22 #include <linux/acpi.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
28 #include <sound/initval.h>
29 #include <sound/tlv.h>
30 #include <sound/jack.h>
31 #include <linux/workqueue.h>
32 #include <sound/hda_verbs.h>
36 int rl6347a_hw_write(void *context
, unsigned int reg
, unsigned int value
)
38 struct i2c_client
*client
= context
;
39 struct rl6347a_priv
*rl6347a
= i2c_get_clientdata(client
);
43 /* handle index registers */
45 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
46 for (i
= 0; i
< rl6347a
->index_cache_size
; i
++) {
47 if (reg
== rl6347a
->index_cache
[i
].reg
) {
48 rl6347a
->index_cache
[i
].def
= value
;
53 reg
= RL6347A_PROC_COEF
;
56 data
[0] = (reg
>> 24) & 0xff;
57 data
[1] = (reg
>> 16) & 0xff;
59 * 4 bit VID: reg should be 0
60 * 12 bit VID: value should be 0
61 * So we use an OR operator to handle it rather than use if condition.
63 data
[2] = ((reg
>> 8) & 0xff) | ((value
>> 8) & 0xff);
64 data
[3] = value
& 0xff;
66 ret
= i2c_master_send(client
, data
, 4);
71 pr_err("ret=%d\n", ret
);
77 EXPORT_SYMBOL_GPL(rl6347a_hw_write
);
79 int rl6347a_hw_read(void *context
, unsigned int reg
, unsigned int *value
)
81 struct i2c_client
*client
= context
;
82 struct i2c_msg xfer
[2];
85 unsigned int index
, vid
, buf
= 0x0;
87 /* handle index registers */
89 rl6347a_hw_write(client
, RL6347A_COEF_INDEX
, reg
);
90 reg
= RL6347A_PROC_COEF
;
94 vid
= (reg
>> 8) & 0xfff;
96 if (AC_VERB_GET_AMP_GAIN_MUTE
== (vid
& 0xf00)) {
97 index
= (reg
>> 8) & 0xf;
98 reg
= (reg
& ~0xf0f) | index
;
100 be_reg
= cpu_to_be32(reg
);
103 xfer
[0].addr
= client
->addr
;
106 xfer
[0].buf
= (u8
*)&be_reg
;
109 xfer
[1].addr
= client
->addr
;
110 xfer
[1].flags
= I2C_M_RD
;
112 xfer
[1].buf
= (u8
*)&buf
;
114 ret
= i2c_transfer(client
->adapter
, xfer
, 2);
120 *value
= be32_to_cpu(buf
);
124 EXPORT_SYMBOL_GPL(rl6347a_hw_read
);
126 MODULE_DESCRIPTION("RL6347A class device shared support");
127 MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
128 MODULE_LICENSE("GPL v2");