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 *intn;
50 struct gpio_desc *reset;
51 struct gpio_desc *connect;
52 bool secondary_ref_clk;
53};
54
55static int usb3503_reset(struct usb3503 *hub, int state)
56{
57 if (!state && hub->connect)
58 gpiod_set_value_cansleep(hub->connect, 0);
59
60 if (hub->reset)
61 gpiod_set_value_cansleep(hub->reset, !state);
62
63 /* Wait T_HUBINIT == 4ms for hub logic to stabilize */
64 if (state)
65 usleep_range(4000, 10000);
66
67 return 0;
68}
69
70static int usb3503_connect(struct usb3503 *hub)
71{
72 struct device *dev = hub->dev;
73 int err;
74
75 usb3503_reset(hub, 1);
76
77 if (hub->regmap) {
78 /* SP_ILOCK: set connect_n, config_n for config */
79 err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
80 (USB3503_SPILOCK_CONNECT
81 | USB3503_SPILOCK_CONFIG));
82 if (err < 0) {
83 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
84 return err;
85 }
86
87 /* PDS : Set the ports which are disabled in self-powered mode. */
88 if (hub->port_off_mask) {
89 err = regmap_update_bits(hub->regmap, USB3503_PDS,
90 hub->port_off_mask,
91 hub->port_off_mask);
92 if (err < 0) {
93 dev_err(dev, "PDS failed (%d)\n", err);
94 return err;
95 }
96 }
97
98 /* CFG1 : Set SELF_BUS_PWR, this enables self-powered operation. */
99 err = regmap_update_bits(hub->regmap, USB3503_CFG1,
100 USB3503_SELF_BUS_PWR,
101 USB3503_SELF_BUS_PWR);
102 if (err < 0) {
103 dev_err(dev, "CFG1 failed (%d)\n", err);
104 return err;
105 }
106
107 /* SP_LOCK: clear connect_n, config_n for hub connect */
108 err = regmap_update_bits(hub->regmap, USB3503_SP_ILOCK,
109 (USB3503_SPILOCK_CONNECT
110 | USB3503_SPILOCK_CONFIG), 0);
111 if (err < 0) {
112 dev_err(dev, "SP_ILOCK failed (%d)\n", err);
113 return err;
114 }
115 }
116
117 if (hub->connect)
118 gpiod_set_value_cansleep(hub->connect, 1);
119
120 hub->mode = USB3503_MODE_HUB;
121 dev_info(dev, "switched to HUB mode\n");
122
123 return 0;
124}
125
126static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
127{
128 struct device *dev = hub->dev;
129 int err = 0;
130
131 switch (mode) {
132 case USB3503_MODE_HUB:
133 err = usb3503_connect(hub);
134 break;
135
136 case USB3503_MODE_STANDBY:
137 usb3503_reset(hub, 0);
138 dev_info(dev, "switched to STANDBY mode\n");
139 break;
140
141 default:
142 dev_err(dev, "unknown mode is requested\n");
143 err = -EINVAL;
144 break;
145 }
146
147 return err;
148}
149
150static const struct regmap_config usb3503_regmap_config = {
151 .reg_bits = 8,
152 .val_bits = 8,
153
154 .max_register = USB3503_RESET,
155};
156
157static int usb3503_probe(struct usb3503 *hub)
158{
159 struct device *dev = hub->dev;
160 struct usb3503_platform_data *pdata = dev_get_platdata(dev);
161 struct device_node *np = dev->of_node;
162 int err;
163 u32 mode = USB3503_MODE_HUB;
164 const u32 *property;
165 enum gpiod_flags flags;
166 int len;
167
168 if (pdata) {
169 hub->port_off_mask = pdata->port_off_mask;
170 hub->mode = pdata->initial_mode;
171 } else if (np) {
172 u32 rate = 0;
173 hub->port_off_mask = 0;
174
175 if (!of_property_read_u32(np, "refclk-frequency", &rate)) {
176 switch (rate) {
177 case 38400000:
178 case 26000000:
179 case 19200000:
180 case 12000000:
181 hub->secondary_ref_clk = 0;
182 break;
183 case 24000000:
184 case 27000000:
185 case 25000000:
186 case 50000000:
187 hub->secondary_ref_clk = 1;
188 break;
189 default:
190 dev_err(dev,
191 "unsupported reference clock rate (%d)\n",
192 (int) rate);
193 return -EINVAL;
194 }
195 }
196
197 hub->clk = devm_clk_get_optional(dev, "refclk");
198 if (IS_ERR(hub->clk)) {
199 dev_err(dev, "unable to request refclk (%ld)\n",
200 PTR_ERR(hub->clk));
201 return PTR_ERR(hub->clk);
202 }
203
204 if (rate != 0) {
205 err = clk_set_rate(hub->clk, rate);
206 if (err) {
207 dev_err(dev,
208 "unable to set reference clock rate to %d\n",
209 (int)rate);
210 return err;
211 }
212 }
213
214 err = clk_prepare_enable(hub->clk);
215 if (err) {
216 dev_err(dev, "unable to enable reference clock\n");
217 return err;
218 }
219
220 property = of_get_property(np, "disabled-ports", &len);
221 if (property && (len / sizeof(u32)) > 0) {
222 int i;
223 for (i = 0; i < len / sizeof(u32); i++) {
224 u32 port = be32_to_cpu(property[i]);
225 if ((1 <= port) && (port <= 3))
226 hub->port_off_mask |= (1 << port);
227 }
228 }
229
230 of_property_read_u32(np, "initial-mode", &mode);
231 hub->mode = mode;
232 }
233
234 if (hub->secondary_ref_clk)
235 flags = GPIOD_OUT_LOW;
236 else
237 flags = GPIOD_OUT_HIGH;
238 hub->intn = devm_gpiod_get_optional(dev, "intn", flags);
239 if (IS_ERR(hub->intn))
240 return PTR_ERR(hub->intn);
241 if (hub->intn)
242 gpiod_set_consumer_name(hub->intn, "usb3503 intn");
243
244 hub->connect = devm_gpiod_get_optional(dev, "connect", GPIOD_OUT_LOW);
245 if (IS_ERR(hub->connect))
246 return PTR_ERR(hub->connect);
247 if (hub->connect)
248 gpiod_set_consumer_name(hub->connect, "usb3503 connect");
249
250 hub->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
251 if (IS_ERR(hub->reset))
252 return PTR_ERR(hub->reset);
253 if (hub->reset) {
254 /* Datasheet defines a hardware reset to be at least 100us */
255 usleep_range(100, 10000);
256 gpiod_set_consumer_name(hub->reset, "usb3503 reset");
257 }
258
259 if (hub->port_off_mask && !hub->regmap)
260 dev_err(dev, "Ports disabled with no control interface\n");
261
262 usb3503_switch_mode(hub, hub->mode);
263
264 dev_info(dev, "%s: probed in %s mode\n", __func__,
265 (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby");
266
267 return 0;
268}
269
270static int usb3503_i2c_probe(struct i2c_client *i2c,
271 const struct i2c_device_id *id)
272{
273 struct usb3503 *hub;
274 int err;
275
276 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL);
277 if (!hub)
278 return -ENOMEM;
279
280 i2c_set_clientdata(i2c, hub);
281 hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config);
282 if (IS_ERR(hub->regmap)) {
283 err = PTR_ERR(hub->regmap);
284 dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err);
285 return err;
286 }
287 hub->dev = &i2c->dev;
288
289 return usb3503_probe(hub);
290}
291
292static int usb3503_i2c_remove(struct i2c_client *i2c)
293{
294 struct usb3503 *hub;
295
296 hub = i2c_get_clientdata(i2c);
297 clk_disable_unprepare(hub->clk);
298
299 return 0;
300}
301
302static int usb3503_platform_probe(struct platform_device *pdev)
303{
304 struct usb3503 *hub;
305
306 hub = devm_kzalloc(&pdev->dev, sizeof(struct usb3503), GFP_KERNEL);
307 if (!hub)
308 return -ENOMEM;
309 hub->dev = &pdev->dev;
310 platform_set_drvdata(pdev, hub);
311
312 return usb3503_probe(hub);
313}
314
315static int usb3503_platform_remove(struct platform_device *pdev)
316{
317 struct usb3503 *hub;
318
319 hub = platform_get_drvdata(pdev);
320 clk_disable_unprepare(hub->clk);
321
322 return 0;
323}
324
325#ifdef CONFIG_PM_SLEEP
326static int usb3503_suspend(struct usb3503 *hub)
327{
328 usb3503_switch_mode(hub, USB3503_MODE_STANDBY);
329 clk_disable_unprepare(hub->clk);
330
331 return 0;
332}
333
334static int usb3503_resume(struct usb3503 *hub)
335{
336 clk_prepare_enable(hub->clk);
337 usb3503_switch_mode(hub, hub->mode);
338
339 return 0;
340}
341
342static int usb3503_i2c_suspend(struct device *dev)
343{
344 struct i2c_client *client = to_i2c_client(dev);
345
346 return usb3503_suspend(i2c_get_clientdata(client));
347}
348
349static int usb3503_i2c_resume(struct device *dev)
350{
351 struct i2c_client *client = to_i2c_client(dev);
352
353 return usb3503_resume(i2c_get_clientdata(client));
354}
355
356static int usb3503_platform_suspend(struct device *dev)
357{
358 return usb3503_suspend(dev_get_drvdata(dev));
359}
360
361static int usb3503_platform_resume(struct device *dev)
362{
363 return usb3503_resume(dev_get_drvdata(dev));
364}
365#endif
366
367static SIMPLE_DEV_PM_OPS(usb3503_i2c_pm_ops, usb3503_i2c_suspend,
368 usb3503_i2c_resume);
369
370static SIMPLE_DEV_PM_OPS(usb3503_platform_pm_ops, usb3503_platform_suspend,
371 usb3503_platform_resume);
372
373static const struct i2c_device_id usb3503_id[] = {
374 { USB3503_I2C_NAME, 0 },
375 { }
376};
377MODULE_DEVICE_TABLE(i2c, usb3503_id);
378
379#ifdef CONFIG_OF
380static const struct of_device_id usb3503_of_match[] = {
381 { .compatible = "smsc,usb3503", },
382 { .compatible = "smsc,usb3503a", },
383 {},
384};
385MODULE_DEVICE_TABLE(of, usb3503_of_match);
386#endif
387
388static struct i2c_driver usb3503_i2c_driver = {
389 .driver = {
390 .name = USB3503_I2C_NAME,
391 .pm = &usb3503_i2c_pm_ops,
392 .of_match_table = of_match_ptr(usb3503_of_match),
393 },
394 .probe = usb3503_i2c_probe,
395 .remove = usb3503_i2c_remove,
396 .id_table = usb3503_id,
397};
398
399static struct platform_driver usb3503_platform_driver = {
400 .driver = {
401 .name = USB3503_I2C_NAME,
402 .of_match_table = of_match_ptr(usb3503_of_match),
403 .pm = &usb3503_platform_pm_ops,
404 },
405 .probe = usb3503_platform_probe,
406 .remove = usb3503_platform_remove,
407};
408
409static int __init usb3503_init(void)
410{
411 int err;
412
413 err = i2c_add_driver(&usb3503_i2c_driver);
414 if (err != 0)
415 pr_err("usb3503: Failed to register I2C driver: %d\n", err);
416
417 err = platform_driver_register(&usb3503_platform_driver);
418 if (err != 0)
419 pr_err("usb3503: Failed to register platform driver: %d\n",
420 err);
421
422 return 0;
423}
424module_init(usb3503_init);
425
426static void __exit usb3503_exit(void)
427{
428 platform_driver_unregister(&usb3503_platform_driver);
429 i2c_del_driver(&usb3503_i2c_driver);
430}
431module_exit(usb3503_exit);
432
433MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
434MODULE_DESCRIPTION("USB3503 USB HUB driver");
435MODULE_LICENSE("GPL");
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");