This source file includes following definitions.
- v4l2_i2c_subdev_unregister
- v4l2_i2c_subdev_set_name
- v4l2_i2c_subdev_init
- v4l2_i2c_new_subdev_board
- v4l2_i2c_new_subdev
- v4l2_i2c_subdev_addr
- v4l2_i2c_tuner_addrs
1
2
3
4
5
6 #include <linux/i2c.h>
7 #include <linux/module.h>
8 #include <media/v4l2-common.h>
9 #include <media/v4l2-device.h>
10
11 void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
12 {
13 struct i2c_client *client = v4l2_get_subdevdata(sd);
14
15
16
17
18
19
20
21
22
23
24
25
26
27 if (client && !client->dev.of_node && !client->dev.fwnode)
28 i2c_unregister_device(client);
29 }
30
31 void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd,
32 struct i2c_client *client,
33 const char *devname, const char *postfix)
34 {
35 if (!devname)
36 devname = client->dev.driver->name;
37 if (!postfix)
38 postfix = "";
39
40 snprintf(sd->name, sizeof(sd->name), "%s%s %d-%04x", devname, postfix,
41 i2c_adapter_id(client->adapter), client->addr);
42 }
43 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_set_name);
44
45 void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
46 const struct v4l2_subdev_ops *ops)
47 {
48 v4l2_subdev_init(sd, ops);
49 sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
50
51 sd->owner = client->dev.driver->owner;
52 sd->dev = &client->dev;
53
54 v4l2_set_subdevdata(sd, client);
55 i2c_set_clientdata(client, sd);
56 v4l2_i2c_subdev_set_name(sd, client, NULL, NULL);
57 }
58 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
59
60
61 struct v4l2_subdev
62 *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
63 struct i2c_adapter *adapter,
64 struct i2c_board_info *info,
65 const unsigned short *probe_addrs)
66 {
67 struct v4l2_subdev *sd = NULL;
68 struct i2c_client *client;
69
70 if (!v4l2_dev)
71 return NULL;
72
73 request_module(I2C_MODULE_PREFIX "%s", info->type);
74
75
76 if (info->addr == 0 && probe_addrs)
77 client = i2c_new_probed_device(adapter, info, probe_addrs,
78 NULL);
79 else
80 client = i2c_new_device(adapter, info);
81
82
83
84
85
86
87
88
89
90
91 if (!client || !client->dev.driver)
92 goto error;
93
94
95 if (!try_module_get(client->dev.driver->owner))
96 goto error;
97 sd = i2c_get_clientdata(client);
98
99
100
101
102
103 if (v4l2_device_register_subdev(v4l2_dev, sd))
104 sd = NULL;
105
106 module_put(client->dev.driver->owner);
107
108 error:
109
110
111
112
113 if (client && !sd)
114 i2c_unregister_device(client);
115 return sd;
116 }
117 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board);
118
119 struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
120 struct i2c_adapter *adapter,
121 const char *client_type,
122 u8 addr,
123 const unsigned short *probe_addrs)
124 {
125 struct i2c_board_info info;
126
127
128
129
130
131 memset(&info, 0, sizeof(info));
132 strscpy(info.type, client_type, sizeof(info.type));
133 info.addr = addr;
134
135 return v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info,
136 probe_addrs);
137 }
138 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
139
140
141 unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
142 {
143 struct i2c_client *client = v4l2_get_subdevdata(sd);
144
145 return client ? client->addr : I2C_CLIENT_END;
146 }
147 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr);
148
149
150
151
152
153 const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
154 {
155 static const unsigned short radio_addrs[] = {
156 #if IS_ENABLED(CONFIG_MEDIA_TUNER_TEA5761)
157 0x10,
158 #endif
159 0x60,
160 I2C_CLIENT_END
161 };
162 static const unsigned short demod_addrs[] = {
163 0x42, 0x43, 0x4a, 0x4b,
164 I2C_CLIENT_END
165 };
166 static const unsigned short tv_addrs[] = {
167 0x42, 0x43, 0x4a, 0x4b,
168 0x60, 0x61, 0x62, 0x63, 0x64,
169 I2C_CLIENT_END
170 };
171
172 switch (type) {
173 case ADDRS_RADIO:
174 return radio_addrs;
175 case ADDRS_DEMOD:
176 return demod_addrs;
177 case ADDRS_TV:
178 return tv_addrs;
179 case ADDRS_TV_WITH_DEMOD:
180 return tv_addrs + 4;
181 }
182 return NULL;
183 }
184 EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);