Loading...
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Driver for SMSC USB3503 USB 2.0 hub controller driver
4 *
5 * Copyright (c) 2012-2013 Dongjin Kim (tobetter@gmail.com)
6 */
7
8#include <linux/clk.h>
9#include <linux/i2c.h>
10#include <linux/gpio/consumer.h>
11#include <linux/delay.h>
12#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/platform_data/usb3503.h>
16#include <linux/regmap.h>
17
18#define USB3503_VIDL 0x00
19#define USB3503_VIDM 0x01
20#define USB3503_PIDL 0x02
21#define USB3503_PIDM 0x03
22#define USB3503_DIDL 0x04
23#define USB3503_DIDM 0x05
24
25#define USB3503_CFG1 0x06
26#define USB3503_SELF_BUS_PWR (1 << 7)
27
28#define USB3503_CFG2 0x07
29#define USB3503_CFG3 0x08
30#define USB3503_NRD 0x09
31
32#define USB3503_PDS 0x0a
33
34#define USB3503_SP_ILOCK 0xe7
35#define USB3503_SPILOCK_CONNECT (1 << 1)
36#define USB3503_SPILOCK_CONFIG (1 << 0)
37
38#define USB3503_CFGP 0xee
39#define USB3503_CLKSUSP (1 << 7)
40
41#define USB3503_RESET 0xff
42
43struct usb3503 {
44 enum usb3503_mode mode;
45 struct regmap *regmap;
46 struct device *dev;
47 struct clk *clk;
48 u8 port_off_mask;
49 struct gpio_desc *bypass;
50 struct gpio_desc *intn;
51 struct gpio_desc *reset;
52 struct gpio_desc *connect;
53 bool secondary_ref_clk;
54};
55
56static int usb3503_connect(struct usb3503 *hub)
57{
58 struct device *dev = hub->dev;
59 int err;
60
61 if (hub->regmap) {
62 /* SP_ILOCK: set connect_n, config_n for config */
63 err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
64 (USB3503_SPILOCK_CONNECT
65 | USB3503_SPILOCK_CONFIG));
66 if (err < 0) {
67 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
68 return err;
69 }
70
71 /* PDS : Set the ports which are disabled in self-powered mode. */
72 if (hub->port_off_mask) {
73 err = regmap_update_bits(hub->regmap, USB3503_PDS,
74 hub->port_off_mask,
75 hub->port_off_mask);
76 if (err < 0) {
77 dev_err(dev, "PDS failed (%d)\n", err);
78 return err;
79 }
80 }
81
82 /* CFG1 : Set SELF_BUS_PWR, this enables self-powered operation. */
83 err = regmap_update_bits(hub->regmap, USB3503_CFG1,
84 USB3503_SELF_BUS_PWR,
85 USB3503_SELF_BUS_PWR);
86 if (err < 0) {
87 dev_err(dev, "CFG1 failed (%d)\n", err);
88 return err;
89 }
90
91 /* SP_LOCK: clear connect_n, config_n for hub connect */
92 err = regmap_update_bits(hub->regmap, USB3503_SP_ILOCK,
93 (USB3503_SPILOCK_CONNECT
94 | USB3503_SPILOCK_CONFIG), 0);
95 if (err < 0) {
96 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
97 return err;
98 }
99 }
100
101 if (hub->connect)
102 gpiod_set_value_cansleep(hub->connect, 1);
103
104 hub->mode = USB3503_MODE_HUB;
105 dev_info(dev, "switched to HUB mode\n");
106
107 return 0;
108}
109
110static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
111{
112 struct device *dev = hub->dev;
113 int rst, bypass, conn;
114
115 switch (mode) {
116 case USB3503_MODE_HUB:
117 conn = 1;
118 rst = 0;
119 bypass = 0;
120 break;
121 case USB3503_MODE_STANDBY:
122 conn = 0;
123 rst = 1;
124 bypass = 1;
125 dev_info(dev, "switched to STANDBY mode\n");
126 break;
127 case USB3503_MODE_BYPASS:
128 conn = 0;
129 rst = 0;
130 bypass = 1;
131 break;
132 default:
133 dev_err(dev, "unknown mode is requested\n");
134 return -EINVAL;
135 }
136
137 if (!conn && hub->connect)
138 gpiod_set_value_cansleep(hub->connect, 0);
139
140 if (hub->reset)
141 gpiod_set_value_cansleep(hub->reset, rst);
142
143 if (hub->bypass)
144 gpiod_set_value_cansleep(hub->bypass, bypass);
145
146 if (conn) {
147 /* Wait T_HUBINIT == 4ms for hub logic to stabilize */
148 usleep_range(4000, 10000);
149 return usb3503_connect(hub);
150 }
151
152 return 0;
153}
154
155static const struct regmap_config usb3503_regmap_config = {
156 .reg_bits = 8,
157 .val_bits = 8,
158
159 .max_register = USB3503_RESET,
160};
161
162static int usb3503_probe(struct usb3503 *hub)
163{
164 struct device *dev = hub->dev;
165 struct usb3503_platform_data *pdata = dev_get_platdata(dev);
166 struct device_node *np = dev->of_node;
167 int err;
168 bool is_clk_enabled = false;
169 u32 mode = USB3503_MODE_HUB;
170 const u32 *property;
171 enum gpiod_flags flags;
172 int len;
173
174 if (pdata) {
175 hub->port_off_mask = pdata->port_off_mask;
176 hub->mode = pdata->initial_mode;
177 } else if (np) {
178 u32 rate = 0;
179 hub->port_off_mask = 0;
180
181 if (!of_property_read_u32(np, "refclk-frequency", &rate)) {
182 switch (rate) {
183 case 38400000:
184 case 26000000:
185 case 19200000:
186 case 12000000:
187 hub->secondary_ref_clk = 0;
188 break;
189 case 24000000:
190 case 27000000:
191 case 25000000:
192 case 50000000:
193 hub->secondary_ref_clk = 1;
194 break;
195 default:
196 dev_err(dev,
197 "unsupported reference clock rate (%d)\n",
198 (int) rate);
199 return -EINVAL;
200 }
201 }
202
203 hub->clk = devm_clk_get_optional(dev, "refclk");
204 if (IS_ERR(hub->clk)) {
205 dev_err(dev, "unable to request refclk (%ld)\n",
206 PTR_ERR(hub->clk));
207 return PTR_ERR(hub->clk);
208 }
209
210 if (rate != 0) {
211 err = clk_set_rate(hub->clk, rate);
212 if (err) {
213 dev_err(dev,
214 "unable to set reference clock rate to %d\n",
215 (int)rate);
216 return err;
217 }
218 }
219
220 err = clk_prepare_enable(hub->clk);
221 if (err) {
222 dev_err(dev, "unable to enable reference clock\n");
223 return err;
224 }
225
226 is_clk_enabled = true;
227 property = of_get_property(np, "disabled-ports", &len);
228 if (property && (len / sizeof(u32)) > 0) {
229 int i;
230 for (i = 0; i < len / sizeof(u32); i++) {
231 u32 port = be32_to_cpu(property[i]);
232 if ((1 <= port) && (port <= 3))
233 hub->port_off_mask |= (1 << port);
234 }
235 }
236
237 of_property_read_u32(np, "initial-mode", &mode);
238 hub->mode = mode;
239 }
240
241 if (hub->secondary_ref_clk)
242 flags = GPIOD_OUT_LOW;
243 else
244 flags = GPIOD_OUT_HIGH;
245 hub->intn = devm_gpiod_get_optional(dev, "intn", flags);
246 if (IS_ERR(hub->intn)) {
247 err = PTR_ERR(hub->intn);
248 goto err_clk;
249 }
250 if (hub->intn)
251 gpiod_set_consumer_name(hub->intn, "usb3503 intn");
252
253 hub->connect = devm_gpiod_get_optional(dev, "connect", GPIOD_OUT_LOW);
254 if (IS_ERR(hub->connect)) {
255 err = PTR_ERR(hub->connect);
256 goto err_clk;
257 }
258 if (hub->connect)
259 gpiod_set_consumer_name(hub->connect, "usb3503 connect");
260
261 hub->bypass = devm_gpiod_get_optional(dev, "bypass", GPIOD_OUT_HIGH);
262 if (IS_ERR(hub->bypass)) {
263 err = PTR_ERR(hub->bypass);
264 goto err_clk;
265 }
266 if (hub->bypass)
267 gpiod_set_consumer_name(hub->bypass, "usb3503 bypass");
268
269 hub->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
270 if (IS_ERR(hub->reset)) {
271 err = PTR_ERR(hub->reset);
272 goto err_clk;
273 }
274 if (hub->reset) {
275 /* Datasheet defines a hardware reset to be at least 100us */
276 usleep_range(100, 10000);
277 gpiod_set_consumer_name(hub->reset, "usb3503 reset");
278 }
279
280 if (hub->port_off_mask && !hub->regmap)
281 dev_err(dev, "Ports disabled with no control interface\n");
282
283 usb3503_switch_mode(hub, hub->mode);
284
285 dev_info(dev, "%s: probed in %s mode\n", __func__,
286 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby");
287
288 return 0;
289
290err_clk:
291 if (is_clk_enabled)
292 clk_disable_unprepare(hub->clk);
293 return err;
294}
295
296static int usb3503_i2c_probe(struct i2c_client *i2c)
297{
298 struct usb3503 *hub;
299 int err;
300
301 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL);
302 if (!hub)
303 return -ENOMEM;
304
305 i2c_set_clientdata(i2c, hub);
306 hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config);
307 if (IS_ERR(hub->regmap)) {
308 err = PTR_ERR(hub->regmap);
309 dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err);
310 return err;
311 }
312 hub->dev = &i2c->dev;
313
314 return usb3503_probe(hub);
315}
316
317static void usb3503_i2c_remove(struct i2c_client *i2c)
318{
319 struct usb3503 *hub;
320
321 hub = i2c_get_clientdata(i2c);
322 clk_disable_unprepare(hub->clk);
323}
324
325static int usb3503_platform_probe(struct platform_device *pdev)
326{
327 struct usb3503 *hub;
328
329 hub = devm_kzalloc(&pdev->dev, sizeof(struct usb3503), GFP_KERNEL);
330 if (!hub)
331 return -ENOMEM;
332 hub->dev = &pdev->dev;
333 platform_set_drvdata(pdev, hub);
334
335 return usb3503_probe(hub);
336}
337
338static void usb3503_platform_remove(struct platform_device *pdev)
339{
340 struct usb3503 *hub;
341
342 hub = platform_get_drvdata(pdev);
343 clk_disable_unprepare(hub->clk);
344}
345
346static int __maybe_unused usb3503_suspend(struct usb3503 *hub)
347{
348 usb3503_switch_mode(hub, USB3503_MODE_STANDBY);
349 clk_disable_unprepare(hub->clk);
350
351 return 0;
352}
353
354static int __maybe_unused usb3503_resume(struct usb3503 *hub)
355{
356 clk_prepare_enable(hub->clk);
357 usb3503_switch_mode(hub, hub->mode);
358
359 return 0;
360}
361
362static int __maybe_unused usb3503_i2c_suspend(struct device *dev)
363{
364 struct i2c_client *client = to_i2c_client(dev);
365
366 return usb3503_suspend(i2c_get_clientdata(client));
367}
368
369static int __maybe_unused usb3503_i2c_resume(struct device *dev)
370{
371 struct i2c_client *client = to_i2c_client(dev);
372
373 return usb3503_resume(i2c_get_clientdata(client));
374}
375
376static int __maybe_unused usb3503_platform_suspend(struct device *dev)
377{
378 return usb3503_suspend(dev_get_drvdata(dev));
379}
380
381static int __maybe_unused usb3503_platform_resume(struct device *dev)
382{
383 return usb3503_resume(dev_get_drvdata(dev));
384}
385
386static SIMPLE_DEV_PM_OPS(usb3503_i2c_pm_ops, usb3503_i2c_suspend,
387 usb3503_i2c_resume);
388
389static SIMPLE_DEV_PM_OPS(usb3503_platform_pm_ops, usb3503_platform_suspend,
390 usb3503_platform_resume);
391
392static const struct i2c_device_id usb3503_id[] = {
393 { USB3503_I2C_NAME, 0 },
394 { }
395};
396MODULE_DEVICE_TABLE(i2c, usb3503_id);
397
398#ifdef CONFIG_OF
399static const struct of_device_id usb3503_of_match[] = {
400 { .compatible = "smsc,usb3503", },
401 { .compatible = "smsc,usb3503a", },
402 { .compatible = "smsc,usb3803", },
403 {},
404};
405MODULE_DEVICE_TABLE(of, usb3503_of_match);
406#endif
407
408static struct i2c_driver usb3503_i2c_driver = {
409 .driver = {
410 .name = USB3503_I2C_NAME,
411 .pm = pm_ptr(&usb3503_i2c_pm_ops),
412 .of_match_table = of_match_ptr(usb3503_of_match),
413 },
414 .probe = usb3503_i2c_probe,
415 .remove = usb3503_i2c_remove,
416 .id_table = usb3503_id,
417};
418
419static struct platform_driver usb3503_platform_driver = {
420 .driver = {
421 .name = USB3503_I2C_NAME,
422 .of_match_table = of_match_ptr(usb3503_of_match),
423 .pm = pm_ptr(&usb3503_platform_pm_ops),
424 },
425 .probe = usb3503_platform_probe,
426 .remove_new = usb3503_platform_remove,
427};
428
429static int __init usb3503_init(void)
430{
431 int err;
432
433 err = i2c_add_driver(&usb3503_i2c_driver);
434 if (err) {
435 pr_err("usb3503: Failed to register I2C driver: %d\n", err);
436 return err;
437 }
438
439 err = platform_driver_register(&usb3503_platform_driver);
440 if (err) {
441 pr_err("usb3503: Failed to register platform driver: %d\n",
442 err);
443 i2c_del_driver(&usb3503_i2c_driver);
444 return err;
445 }
446
447 return 0;
448}
449module_init(usb3503_init);
450
451static void __exit usb3503_exit(void)
452{
453 platform_driver_unregister(&usb3503_platform_driver);
454 i2c_del_driver(&usb3503_i2c_driver);
455}
456module_exit(usb3503_exit);
457
458MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
459MODULE_DESCRIPTION("USB3503 USB HUB driver");
460MODULE_LICENSE("GPL");
1/*
2 * Driver for SMSC USB3503 USB 2.0 hub controller driver
3 *
4 * Copyright (c) 2012-2013 Dongjin Kim (tobetter@gmail.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/i2c.h>
22#include <linux/gpio.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include <linux/of_gpio.h>
27#include <linux/platform_device.h>
28#include <linux/platform_data/usb3503.h>
29#include <linux/regmap.h>
30
31#define USB3503_VIDL 0x00
32#define USB3503_VIDM 0x01
33#define USB3503_PIDL 0x02
34#define USB3503_PIDM 0x03
35#define USB3503_DIDL 0x04
36#define USB3503_DIDM 0x05
37
38#define USB3503_CFG1 0x06
39#define USB3503_SELF_BUS_PWR (1 << 7)
40
41#define USB3503_CFG2 0x07
42#define USB3503_CFG3 0x08
43#define USB3503_NRD 0x09
44
45#define USB3503_PDS 0x0a
46
47#define USB3503_SP_ILOCK 0xe7
48#define USB3503_SPILOCK_CONNECT (1 << 1)
49#define USB3503_SPILOCK_CONFIG (1 << 0)
50
51#define USB3503_CFGP 0xee
52#define USB3503_CLKSUSP (1 << 7)
53
54#define USB3503_RESET 0xff
55
56struct usb3503 {
57 enum usb3503_mode mode;
58 struct regmap *regmap;
59 struct device *dev;
60 u8 port_off_mask;
61 int gpio_intn;
62 int gpio_reset;
63 int gpio_connect;
64};
65
66static int usb3503_reset(struct usb3503 *hub, int state)
67{
68 if (!state && gpio_is_valid(hub->gpio_connect))
69 gpio_set_value_cansleep(hub->gpio_connect, 0);
70
71 if (gpio_is_valid(hub->gpio_reset))
72 gpio_set_value_cansleep(hub->gpio_reset, state);
73
74 /* Wait T_HUBINIT == 4ms for hub logic to stabilize */
75 if (state)
76 usleep_range(4000, 10000);
77
78 return 0;
79}
80
81static int usb3503_connect(struct usb3503 *hub)
82{
83 struct device *dev = hub->dev;
84 int err;
85
86 usb3503_reset(hub, 1);
87
88 if (hub->regmap) {
89 /* SP_ILOCK: set connect_n, config_n for config */
90 err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
91 (USB3503_SPILOCK_CONNECT
92 | USB3503_SPILOCK_CONFIG));
93 if (err < 0) {
94 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
95 return err;
96 }
97
98 /* PDS : Disable For Self Powered Operation */
99 if (hub->port_off_mask) {
100 err = regmap_update_bits(hub->regmap, USB3503_PDS,
101 hub->port_off_mask,
102 hub->port_off_mask);
103 if (err < 0) {
104 dev_err(dev, "PDS failed (%d)\n", err);
105 return err;
106 }
107 }
108
109 /* CFG1 : SELF_BUS_PWR -> Self-Powerd operation */
110 err = regmap_update_bits(hub->regmap, USB3503_CFG1,
111 USB3503_SELF_BUS_PWR,
112 USB3503_SELF_BUS_PWR);
113 if (err < 0) {
114 dev_err(dev, "CFG1 failed (%d)\n", err);
115 return err;
116 }
117
118 /* SP_LOCK: clear connect_n, config_n for hub connect */
119 err = regmap_update_bits(hub->regmap, USB3503_SP_ILOCK,
120 (USB3503_SPILOCK_CONNECT
121 | USB3503_SPILOCK_CONFIG), 0);
122 if (err < 0) {
123 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
124 return err;
125 }
126 }
127
128 if (gpio_is_valid(hub->gpio_connect))
129 gpio_set_value_cansleep(hub->gpio_connect, 1);
130
131 hub->mode = USB3503_MODE_HUB;
132 dev_info(dev, "switched to HUB mode\n");
133
134 return 0;
135}
136
137static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
138{
139 struct device *dev = hub->dev;
140 int err = 0;
141
142 switch (mode) {
143 case USB3503_MODE_HUB:
144 err = usb3503_connect(hub);
145 break;
146
147 case USB3503_MODE_STANDBY:
148 usb3503_reset(hub, 0);
149
150 hub->mode = mode;
151 dev_info(dev, "switched to STANDBY mode\n");
152 break;
153
154 default:
155 dev_err(dev, "unknown mode is requested\n");
156 err = -EINVAL;
157 break;
158 }
159
160 return err;
161}
162
163static const struct regmap_config usb3503_regmap_config = {
164 .reg_bits = 8,
165 .val_bits = 8,
166
167 .max_register = USB3503_RESET,
168};
169
170static int usb3503_probe(struct usb3503 *hub)
171{
172 struct device *dev = hub->dev;
173 struct usb3503_platform_data *pdata = dev_get_platdata(dev);
174 struct device_node *np = dev->of_node;
175 int err;
176 u32 mode = USB3503_MODE_HUB;
177 const u32 *property;
178 int len;
179
180 if (pdata) {
181 hub->port_off_mask = pdata->port_off_mask;
182 hub->gpio_intn = pdata->gpio_intn;
183 hub->gpio_connect = pdata->gpio_connect;
184 hub->gpio_reset = pdata->gpio_reset;
185 hub->mode = pdata->initial_mode;
186 } else if (np) {
187 hub->port_off_mask = 0;
188
189 property = of_get_property(np, "disabled-ports", &len);
190 if (property && (len / sizeof(u32)) > 0) {
191 int i;
192 for (i = 0; i < len / sizeof(u32); i++) {
193 u32 port = be32_to_cpu(property[i]);
194 if ((1 <= port) && (port <= 3))
195 hub->port_off_mask |= (1 << port);
196 }
197 }
198
199 hub->gpio_intn = of_get_named_gpio(np, "intn-gpios", 0);
200 if (hub->gpio_intn == -EPROBE_DEFER)
201 return -EPROBE_DEFER;
202 hub->gpio_connect = of_get_named_gpio(np, "connect-gpios", 0);
203 if (hub->gpio_connect == -EPROBE_DEFER)
204 return -EPROBE_DEFER;
205 hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
206 if (hub->gpio_reset == -EPROBE_DEFER)
207 return -EPROBE_DEFER;
208 of_property_read_u32(np, "initial-mode", &mode);
209 hub->mode = mode;
210 }
211
212 if (hub->port_off_mask && !hub->regmap)
213 dev_err(dev, "Ports disabled with no control interface\n");
214
215 if (gpio_is_valid(hub->gpio_intn)) {
216 err = devm_gpio_request_one(dev, hub->gpio_intn,
217 GPIOF_OUT_INIT_HIGH, "usb3503 intn");
218 if (err) {
219 dev_err(dev,
220 "unable to request GPIO %d as connect pin (%d)\n",
221 hub->gpio_intn, err);
222 return err;
223 }
224 }
225
226 if (gpio_is_valid(hub->gpio_connect)) {
227 err = devm_gpio_request_one(dev, hub->gpio_connect,
228 GPIOF_OUT_INIT_LOW, "usb3503 connect");
229 if (err) {
230 dev_err(dev,
231 "unable to request GPIO %d as connect pin (%d)\n",
232 hub->gpio_connect, err);
233 return err;
234 }
235 }
236
237 if (gpio_is_valid(hub->gpio_reset)) {
238 err = devm_gpio_request_one(dev, hub->gpio_reset,
239 GPIOF_OUT_INIT_LOW, "usb3503 reset");
240 if (err) {
241 dev_err(dev,
242 "unable to request GPIO %d as reset pin (%d)\n",
243 hub->gpio_reset, err);
244 return err;
245 }
246 }
247
248 usb3503_switch_mode(hub, hub->mode);
249
250 dev_info(dev, "%s: probed in %s mode\n", __func__,
251 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby");
252
253 return 0;
254}
255
256static int usb3503_i2c_probe(struct i2c_client *i2c,
257 const struct i2c_device_id *id)
258{
259 struct usb3503 *hub;
260 int err;
261
262 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL);
263 if (!hub) {
264 dev_err(&i2c->dev, "private data alloc fail\n");
265 return -ENOMEM;
266 }
267
268 i2c_set_clientdata(i2c, hub);
269 hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config);
270 if (IS_ERR(hub->regmap)) {
271 err = PTR_ERR(hub->regmap);
272 dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err);
273 return err;
274 }
275 hub->dev = &i2c->dev;
276
277 return usb3503_probe(hub);
278}
279
280static int usb3503_platform_probe(struct platform_device *pdev)
281{
282 struct usb3503 *hub;
283
284 hub = devm_kzalloc(&pdev->dev, sizeof(struct usb3503), GFP_KERNEL);
285 if (!hub) {
286 dev_err(&pdev->dev, "private data alloc fail\n");
287 return -ENOMEM;
288 }
289 hub->dev = &pdev->dev;
290
291 return usb3503_probe(hub);
292}
293
294static const struct i2c_device_id usb3503_id[] = {
295 { USB3503_I2C_NAME, 0 },
296 { }
297};
298MODULE_DEVICE_TABLE(i2c, usb3503_id);
299
300#ifdef CONFIG_OF
301static const struct of_device_id usb3503_of_match[] = {
302 { .compatible = "smsc,usb3503", },
303 { .compatible = "smsc,usb3503a", },
304 {},
305};
306MODULE_DEVICE_TABLE(of, usb3503_of_match);
307#endif
308
309static struct i2c_driver usb3503_i2c_driver = {
310 .driver = {
311 .name = USB3503_I2C_NAME,
312 .of_match_table = of_match_ptr(usb3503_of_match),
313 },
314 .probe = usb3503_i2c_probe,
315 .id_table = usb3503_id,
316};
317
318static struct platform_driver usb3503_platform_driver = {
319 .driver = {
320 .name = USB3503_I2C_NAME,
321 .of_match_table = of_match_ptr(usb3503_of_match),
322 .owner = THIS_MODULE,
323 },
324 .probe = usb3503_platform_probe,
325};
326
327static int __init usb3503_init(void)
328{
329 int err;
330
331 err = i2c_register_driver(THIS_MODULE, &usb3503_i2c_driver);
332 if (err != 0)
333 pr_err("usb3503: Failed to register I2C driver: %d\n", err);
334
335 err = platform_driver_register(&usb3503_platform_driver);
336 if (err != 0)
337 pr_err("usb3503: Failed to register platform driver: %d\n",
338 err);
339
340 return 0;
341}
342module_init(usb3503_init);
343
344static void __exit usb3503_exit(void)
345{
346 platform_driver_unregister(&usb3503_platform_driver);
347 i2c_del_driver(&usb3503_i2c_driver);
348}
349module_exit(usb3503_exit);
350
351MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
352MODULE_DESCRIPTION("USB3503 USB HUB driver");
353MODULE_LICENSE("GPL");