1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* Copyright (c) 2014 Samsung Electronics Co. Ltd.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#define DEBUG
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/jack.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <linux/i2c.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/completion.h>
#include "cod3033x-regctl.h"
static int cod3033_read_reg(struct i2c_client *client, u8 reg, u8 *dest)
{
struct cod3033x_power_priv *cod3033 = i2c_get_clientdata(client);
int ret = 0;
mutex_lock(&cod3033->io_lock);
ret = i2c_smbus_read_byte_data(client, reg);
mutex_unlock(&cod3033->io_lock);
if (ret < 0) {
pr_err("%s: can't read reg(0x%x), ret(%d)\n", __func__, reg, ret);
return ret;
}
reg &= 0xFF;
*dest = ret;
return 0;
}
static int cod3033_write_reg(struct i2c_client *client, u8 reg, u8 data)
{
struct cod3033x_power_priv *cod3033 = i2c_get_clientdata(client);
int ret = 0;
mutex_lock(&cod3033->io_lock);
ret = i2c_smbus_write_byte_data(client, reg, data);
mutex_unlock(&cod3033->io_lock);
if (ret < 0)
pr_err("%s: can't write reg(0x%x), ret(%d)\n", __func__, reg, ret);
return ret;
}
static inline void cod3033x_usleep(unsigned int u_sec)
{
usleep_range(u_sec, u_sec + 10);
}
static void cod3033_power_init(struct cod3033x_power_priv *cod3033)
{
u8 value = 0;
cod3033_write_reg(cod3033->i2c , 0x30, 0xe3);
cod3033_write_reg(cod3033->i2c , 0x38, 0xd2);
cod3033_write_reg(cod3033->i2c , 0x39, 0xd4);
cod3033_write_reg(cod3033->i2c , 0x10, 0x0f);
cod3033_read_reg(cod3033->i2c, 0x30, &value);
}
static int cod3033x_regctl_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct cod3033x_power_priv *cod3033x;
int ret=0;
dev_err(&i2c->dev, "%s register control driver probe\n", __func__);
cod3033x = kzalloc(sizeof(struct cod3033x_power_priv), GFP_KERNEL);
if (cod3033x == NULL)
return -ENOMEM;
cod3033x->dev = &i2c->dev;
cod3033x->i2c_addr = i2c->addr;
cod3033x->i2c = i2c;
mutex_init(&cod3033x->io_lock);
i2c_set_clientdata(i2c, cod3033x);
cod3033_power_init(cod3033x);
return ret;
}
static int cod3033x_regctl_i2c_remove(struct i2c_client *i2c)
{
snd_soc_unregister_codec(&i2c->dev);
return 0;
}
static const struct i2c_device_id cod3033x_regctl_i2c_id[] = {
{ "cod3033x-regctl", 3036 },
{ }
};
MODULE_DEVICE_TABLE(i2c, cod3033x_regctl_i2c_id);
const struct of_device_id cod3033x_regctl_of_match[] = {
{ .compatible = "codec,cod3033x-regctl",},
{},
};
static struct i2c_driver cod3033x_regctl_i2c_driver = {
.driver = {
.name = "cod3033x-regctl",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(cod3033x_regctl_of_match),
},
.probe = cod3033x_regctl_i2c_probe,
.remove = cod3033x_regctl_i2c_remove,
.id_table = cod3033x_regctl_i2c_id,
};
module_i2c_driver(cod3033x_regctl_i2c_driver);
MODULE_DESCRIPTION("ASoC COD3033X driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:COD3033X-codec");
MODULE_FIRMWARE(COD3033X_FIRMWARE_NAME);
|