blob: a21b5f24a3406eef0438cdd6b3cb337784ebcbc0 [file] [log] [blame]
Hans de Goedeba4bdc92014-03-01 18:09:26 +01001/*
2 * Allwinner sun4i USB phy driver
3 *
Hans de Goeded2332302015-06-13 14:37:45 +02004 * Copyright (C) 2014-2015 Hans de Goede <hdegoede@redhat.com>
Hans de Goedeba4bdc92014-03-01 18:09:26 +01005 *
6 * Based on code from
7 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
8 *
9 * Modelled after: Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver
10 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
11 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24#include <linux/clk.h>
Hans de Goede1aedf3a2015-06-13 14:37:50 +020025#include <linux/delay.h>
Sachin Kamat2d84aff2014-05-29 12:00:49 +053026#include <linux/err.h>
Hans de Goede1a52abe2015-06-13 14:37:46 +020027#include <linux/extcon.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010028#include <linux/io.h>
Hans de Goeded2332302015-06-13 14:37:45 +020029#include <linux/interrupt.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/mutex.h>
33#include <linux/of.h>
34#include <linux/of_address.h>
Hans de Goede68dbc2c2015-12-11 16:32:17 +010035#include <linux/of_device.h>
Hans de Goeded2332302015-06-13 14:37:45 +020036#include <linux/of_gpio.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010037#include <linux/phy/phy.h>
Hans de Goede24fe86a2015-03-29 12:50:46 +020038#include <linux/phy/phy-sun4i-usb.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010039#include <linux/platform_device.h>
Hans de Goede8665c182015-06-13 14:37:51 +020040#include <linux/power_supply.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010041#include <linux/regulator/consumer.h>
42#include <linux/reset.h>
Chen-Yu Tsai919ab252016-09-09 11:58:18 +080043#include <linux/spinlock.h>
Hans de Goedeb33ecca2016-08-08 21:55:39 +020044#include <linux/usb/of.h>
Hans de Goeded2332302015-06-13 14:37:45 +020045#include <linux/workqueue.h>
Hans de Goedeba4bdc92014-03-01 18:09:26 +010046
47#define REG_ISCR 0x00
Hans de Goedefc1f45e2015-06-13 14:37:49 +020048#define REG_PHYCTL_A10 0x04
Hans de Goedeba4bdc92014-03-01 18:09:26 +010049#define REG_PHYBIST 0x08
50#define REG_PHYTUNE 0x0c
Hans de Goedefc1f45e2015-06-13 14:37:49 +020051#define REG_PHYCTL_A33 0x10
Reinder de Haan626a6302015-12-11 16:32:18 +010052#define REG_PHY_UNK_H3 0x20
53
Icenowy Zhengb3e0d142016-08-12 11:06:21 +080054#define REG_PMU_UNK1 0x10
Hans de Goedeba4bdc92014-03-01 18:09:26 +010055
56#define PHYCTL_DATA BIT(7)
57
58#define SUNXI_AHB_ICHR8_EN BIT(10)
59#define SUNXI_AHB_INCR4_BURST_EN BIT(9)
60#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
61#define SUNXI_ULPI_BYPASS_EN BIT(0)
62
Hans de Goeded2332302015-06-13 14:37:45 +020063/* ISCR, Interface Status and Control bits */
64#define ISCR_ID_PULLUP_EN (1 << 17)
65#define ISCR_DPDM_PULLUP_EN (1 << 16)
66/* sunxi has the phy id/vbus pins not connected, so we use the force bits */
67#define ISCR_FORCE_ID_MASK (3 << 14)
68#define ISCR_FORCE_ID_LOW (2 << 14)
69#define ISCR_FORCE_ID_HIGH (3 << 14)
70#define ISCR_FORCE_VBUS_MASK (3 << 12)
71#define ISCR_FORCE_VBUS_LOW (2 << 12)
72#define ISCR_FORCE_VBUS_HIGH (3 << 12)
73
Hans de Goedeba4bdc92014-03-01 18:09:26 +010074/* Common Control Bits for Both PHYs */
75#define PHY_PLL_BW 0x03
76#define PHY_RES45_CAL_EN 0x0c
77
78/* Private Control Bits for Each PHY */
79#define PHY_TX_AMPLITUDE_TUNE 0x20
80#define PHY_TX_SLEWRATE_TUNE 0x22
81#define PHY_VBUSVALID_TH_SEL 0x25
82#define PHY_PULLUP_RES_SEL 0x27
83#define PHY_OTG_FUNC_EN 0x28
84#define PHY_VBUS_DET_EN 0x29
85#define PHY_DISCON_TH_SEL 0x2a
Hans de Goede24fe86a2015-03-29 12:50:46 +020086#define PHY_SQUELCH_DETECT 0x3c
Hans de Goedeba4bdc92014-03-01 18:09:26 +010087
Reinder de Haan626a6302015-12-11 16:32:18 +010088#define MAX_PHYS 4
Hans de Goedeba4bdc92014-03-01 18:09:26 +010089
Hans de Goeded2332302015-06-13 14:37:45 +020090/*
91 * Note do not raise the debounce time, we must report Vusb high within 100ms
92 * otherwise we get Vbus errors
93 */
94#define DEBOUNCE_TIME msecs_to_jiffies(50)
95#define POLL_TIME msecs_to_jiffies(250)
96
Hans de Goede68dbc2c2015-12-11 16:32:17 +010097enum sun4i_usb_phy_type {
98 sun4i_a10_phy,
Hans de Goede91d96f02016-06-29 20:14:10 +020099 sun6i_a31_phy,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100100 sun8i_a33_phy,
Reinder de Haan626a6302015-12-11 16:32:18 +0100101 sun8i_h3_phy,
Icenowy Zheng16c40362017-01-03 23:25:31 +0800102 sun8i_v3s_phy,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800103 sun50i_a64_phy,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100104};
105
106struct sun4i_usb_phy_cfg {
107 int num_phys;
108 enum sun4i_usb_phy_type type;
109 u32 disc_thresh;
110 u8 phyctl_offset;
111 bool dedicated_clocks;
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800112 bool enable_pmu_unk1;
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100113};
114
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100115struct sun4i_usb_phy_data {
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100116 void __iomem *base;
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100117 const struct sun4i_usb_phy_cfg *cfg;
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200118 enum usb_dr_mode dr_mode;
Chen-Yu Tsai919ab252016-09-09 11:58:18 +0800119 spinlock_t reg_lock; /* guard access to phyctl reg */
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100120 struct sun4i_usb_phy {
121 struct phy *phy;
122 void __iomem *pmu;
123 struct regulator *vbus;
124 struct reset_control *reset;
Maxime Ripardeadd4312014-05-13 17:44:18 +0200125 struct clk *clk;
Hans de Goeded2332302015-06-13 14:37:45 +0200126 bool regulator_on;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100127 int index;
128 } phys[MAX_PHYS];
Hans de Goeded2332302015-06-13 14:37:45 +0200129 /* phy0 / otg related variables */
Hans de Goede1a52abe2015-06-13 14:37:46 +0200130 struct extcon_dev *extcon;
Hans de Goeded2332302015-06-13 14:37:45 +0200131 bool phy0_init;
Hans de Goeded2332302015-06-13 14:37:45 +0200132 struct gpio_desc *id_det_gpio;
133 struct gpio_desc *vbus_det_gpio;
Hans de Goede8665c182015-06-13 14:37:51 +0200134 struct power_supply *vbus_power_supply;
135 struct notifier_block vbus_power_nb;
136 bool vbus_power_nb_registered;
Hans de Goede36f91592016-09-07 22:20:38 +0200137 bool force_session_end;
Hans de Goeded2332302015-06-13 14:37:45 +0200138 int id_det_irq;
139 int vbus_det_irq;
140 int id_det;
141 int vbus_det;
142 struct delayed_work detect;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100143};
144
145#define to_sun4i_usb_phy_data(phy) \
146 container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
147
Hans de Goeded2332302015-06-13 14:37:45 +0200148static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set)
149{
150 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
151 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
152 u32 iscr;
153
154 iscr = readl(data->base + REG_ISCR);
155 iscr &= ~clr;
156 iscr |= set;
157 writel(iscr, data->base + REG_ISCR);
158}
159
160static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val)
161{
162 if (val)
163 val = ISCR_FORCE_ID_HIGH;
164 else
165 val = ISCR_FORCE_ID_LOW;
166
167 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val);
168}
169
170static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val)
171{
172 if (val)
173 val = ISCR_FORCE_VBUS_HIGH;
174 else
175 val = ISCR_FORCE_VBUS_LOW;
176
177 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val);
178}
179
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100180static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
181 int len)
182{
183 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
184 u32 temp, usbc_bit = BIT(phy->index * 2);
Ben Dooksd99cb372016-06-07 18:14:56 +0100185 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
Chen-Yu Tsai919ab252016-09-09 11:58:18 +0800186 unsigned long flags;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100187 int i;
188
Chen-Yu Tsai919ab252016-09-09 11:58:18 +0800189 spin_lock_irqsave(&phy_data->reg_lock, flags);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100190
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800191 if (phy_data->cfg->type == sun8i_a33_phy ||
Icenowy Zheng16c40362017-01-03 23:25:31 +0800192 phy_data->cfg->type == sun50i_a64_phy ||
193 phy_data->cfg->type == sun8i_v3s_phy) {
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800194 /* A33 or A64 needs us to set phyctl to 0 explicitly */
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200195 writel(0, phyctl);
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200196 }
197
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100198 for (i = 0; i < len; i++) {
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200199 temp = readl(phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100200
201 /* clear the address portion */
202 temp &= ~(0xff << 8);
203
204 /* set the address */
205 temp |= ((addr + i) << 8);
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200206 writel(temp, phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100207
208 /* set the data bit and clear usbc bit*/
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200209 temp = readb(phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100210 if (data & 0x1)
211 temp |= PHYCTL_DATA;
212 else
213 temp &= ~PHYCTL_DATA;
214 temp &= ~usbc_bit;
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200215 writeb(temp, phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100216
217 /* pulse usbc_bit */
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200218 temp = readb(phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100219 temp |= usbc_bit;
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200220 writeb(temp, phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100221
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200222 temp = readb(phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100223 temp &= ~usbc_bit;
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200224 writeb(temp, phyctl);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100225
226 data >>= 1;
227 }
Chen-Yu Tsai919ab252016-09-09 11:58:18 +0800228
229 spin_unlock_irqrestore(&phy_data->reg_lock, flags);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100230}
231
232static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
233{
234 u32 bits, reg_value;
235
236 if (!phy->pmu)
237 return;
238
239 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
240 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
241
242 reg_value = readl(phy->pmu);
243
244 if (enable)
245 reg_value |= bits;
246 else
247 reg_value &= ~bits;
248
249 writel(reg_value, phy->pmu);
250}
251
252static int sun4i_usb_phy_init(struct phy *_phy)
253{
254 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
255 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
256 int ret;
Reinder de Haan626a6302015-12-11 16:32:18 +0100257 u32 val;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100258
Maxime Ripardeadd4312014-05-13 17:44:18 +0200259 ret = clk_prepare_enable(phy->clk);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100260 if (ret)
261 return ret;
262
263 ret = reset_control_deassert(phy->reset);
264 if (ret) {
Maxime Ripardeadd4312014-05-13 17:44:18 +0200265 clk_disable_unprepare(phy->clk);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100266 return ret;
267 }
268
Icenowy Zheng4320f9d2016-10-29 00:27:01 +0800269 if (phy->pmu && data->cfg->enable_pmu_unk1) {
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800270 val = readl(phy->pmu + REG_PMU_UNK1);
271 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
272 }
273
Reinder de Haan626a6302015-12-11 16:32:18 +0100274 if (data->cfg->type == sun8i_h3_phy) {
275 if (phy->index == 0) {
276 val = readl(data->base + REG_PHY_UNK_H3);
277 writel(val & ~1, data->base + REG_PHY_UNK_H3);
278 }
Reinder de Haan626a6302015-12-11 16:32:18 +0100279 } else {
280 /* Enable USB 45 Ohm resistor calibration */
281 if (phy->index == 0)
282 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100283
Reinder de Haan626a6302015-12-11 16:32:18 +0100284 /* Adjust PHY's magnitude and rate */
285 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
286
287 /* Disconnect threshold adjustment */
288 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
289 data->cfg->disc_thresh, 2);
290 }
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100291
292 sun4i_usb_phy_passby(phy, 1);
293
Hans de Goeded2332302015-06-13 14:37:45 +0200294 if (phy->index == 0) {
295 data->phy0_init = true;
296
297 /* Enable pull-ups */
298 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN);
299 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN);
300
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200301 /* Force ISCR and cable state updates */
302 data->id_det = -1;
303 data->vbus_det = -1;
304 queue_delayed_work(system_wq, &data->detect, 0);
Hans de Goeded2332302015-06-13 14:37:45 +0200305 }
306
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100307 return 0;
308}
309
310static int sun4i_usb_phy_exit(struct phy *_phy)
311{
312 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
Hans de Goeded2332302015-06-13 14:37:45 +0200313 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
314
315 if (phy->index == 0) {
316 /* Disable pull-ups */
317 sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
318 sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
319 data->phy0_init = false;
320 }
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100321
322 sun4i_usb_phy_passby(phy, 0);
323 reset_control_assert(phy->reset);
Maxime Ripardeadd4312014-05-13 17:44:18 +0200324 clk_disable_unprepare(phy->clk);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100325
326 return 0;
327}
328
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200329static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
330{
331 switch (data->dr_mode) {
332 case USB_DR_MODE_OTG:
Hans de Goede5f90d312016-09-07 22:20:39 +0200333 if (data->id_det_gpio)
334 return gpiod_get_value_cansleep(data->id_det_gpio);
335 else
336 return 1; /* Fallback to peripheral mode */
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200337 case USB_DR_MODE_HOST:
338 return 0;
339 case USB_DR_MODE_PERIPHERAL:
340 default:
341 return 1;
342 }
343}
344
Hans de Goede3d772c42015-07-31 10:01:41 +0200345static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data *data)
346{
347 if (data->vbus_det_gpio)
348 return gpiod_get_value_cansleep(data->vbus_det_gpio);
349
350 if (data->vbus_power_supply) {
351 union power_supply_propval val;
352 int r;
353
354 r = power_supply_get_property(data->vbus_power_supply,
355 POWER_SUPPLY_PROP_PRESENT, &val);
356 if (r == 0)
357 return val.intval;
358 }
359
360 /* Fallback: report vbus as high */
361 return 1;
362}
363
364static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
365{
366 return data->vbus_det_gpio || data->vbus_power_supply;
367}
368
Hans de Goede91d96f02016-06-29 20:14:10 +0200369static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
370{
371 if ((data->id_det_gpio && data->id_det_irq <= 0) ||
372 (data->vbus_det_gpio && data->vbus_det_irq <= 0))
373 return true;
374
375 /*
376 * The A31 companion pmic (axp221) does not generate vbus change
377 * interrupts when the board is driving vbus, so we must poll
378 * when using the pmic for vbus-det _and_ we're driving vbus.
379 */
380 if (data->cfg->type == sun6i_a31_phy &&
381 data->vbus_power_supply && data->phys[0].regulator_on)
382 return true;
383
384 return false;
385}
386
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100387static int sun4i_usb_phy_power_on(struct phy *_phy)
388{
389 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
Hans de Goeded2332302015-06-13 14:37:45 +0200390 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
391 int ret;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100392
Hans de Goeded2332302015-06-13 14:37:45 +0200393 if (!phy->vbus || phy->regulator_on)
394 return 0;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100395
Hans de Goeded2332302015-06-13 14:37:45 +0200396 /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
Hans de Goede80835262015-07-31 10:01:42 +0200397 if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) &&
Hans de Goede91d6e3b2016-09-07 22:20:41 +0200398 data->vbus_det) {
399 dev_warn(&_phy->dev, "External vbus detected, not enabling our own vbus\n");
Hans de Goeded2332302015-06-13 14:37:45 +0200400 return 0;
Hans de Goede91d6e3b2016-09-07 22:20:41 +0200401 }
Hans de Goeded2332302015-06-13 14:37:45 +0200402
403 ret = regulator_enable(phy->vbus);
404 if (ret)
405 return ret;
406
407 phy->regulator_on = true;
408
409 /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
Hans de Goede91d96f02016-06-29 20:14:10 +0200410 if (phy->index == 0 && sun4i_usb_phy0_poll(data))
Hans de Goeded2332302015-06-13 14:37:45 +0200411 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
412
413 return 0;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100414}
415
416static int sun4i_usb_phy_power_off(struct phy *_phy)
417{
418 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
Hans de Goeded2332302015-06-13 14:37:45 +0200419 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100420
Hans de Goeded2332302015-06-13 14:37:45 +0200421 if (!phy->vbus || !phy->regulator_on)
422 return 0;
423
424 regulator_disable(phy->vbus);
425 phy->regulator_on = false;
426
427 /*
428 * phy0 vbus typically slowly discharges, sometimes this causes the
429 * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
430 */
Hans de Goede91d96f02016-06-29 20:14:10 +0200431 if (phy->index == 0 && !sun4i_usb_phy0_poll(data))
Hans de Goeded2332302015-06-13 14:37:45 +0200432 mod_delayed_work(system_wq, &data->detect, POLL_TIME);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100433
434 return 0;
435}
436
Hans de Goede6ba43c22016-09-07 22:20:40 +0200437static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
438{
439 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
440 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
Hans de Goede5d04c882016-09-23 16:40:56 +0300441 int new_mode;
Hans de Goede6ba43c22016-09-07 22:20:40 +0200442
443 if (phy->index != 0)
444 return -EINVAL;
445
446 switch (mode) {
447 case PHY_MODE_USB_HOST:
Hans de Goede5d04c882016-09-23 16:40:56 +0300448 new_mode = USB_DR_MODE_HOST;
Hans de Goede6ba43c22016-09-07 22:20:40 +0200449 break;
450 case PHY_MODE_USB_DEVICE:
Hans de Goede5d04c882016-09-23 16:40:56 +0300451 new_mode = USB_DR_MODE_PERIPHERAL;
Hans de Goede6ba43c22016-09-07 22:20:40 +0200452 break;
453 case PHY_MODE_USB_OTG:
Hans de Goede5d04c882016-09-23 16:40:56 +0300454 new_mode = USB_DR_MODE_OTG;
Hans de Goede6ba43c22016-09-07 22:20:40 +0200455 break;
456 default:
457 return -EINVAL;
458 }
459
Hans de Goede5d04c882016-09-23 16:40:56 +0300460 if (new_mode != data->dr_mode) {
461 dev_info(&_phy->dev, "Changing dr_mode to %d\n", new_mode);
462 data->dr_mode = new_mode;
463 }
464
465 data->id_det = -1; /* Force reprocessing of id */
Hans de Goede6ba43c22016-09-07 22:20:40 +0200466 data->force_session_end = true;
467 queue_delayed_work(system_wq, &data->detect, 0);
468
469 return 0;
470}
471
Hans de Goede24fe86a2015-03-29 12:50:46 +0200472void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
473{
474 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
475
476 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
477}
Hans de Goede7167bf82015-07-31 10:01:40 +0200478EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
Hans de Goede24fe86a2015-03-29 12:50:46 +0200479
Axel Lin4a9e5ca2015-07-15 15:33:51 +0800480static const struct phy_ops sun4i_usb_phy_ops = {
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100481 .init = sun4i_usb_phy_init,
482 .exit = sun4i_usb_phy_exit,
483 .power_on = sun4i_usb_phy_power_on,
484 .power_off = sun4i_usb_phy_power_off,
Hans de Goede6ba43c22016-09-07 22:20:40 +0200485 .set_mode = sun4i_usb_phy_set_mode,
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100486 .owner = THIS_MODULE,
487};
488
Hans de Goeded2332302015-06-13 14:37:45 +0200489static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
490{
491 struct sun4i_usb_phy_data *data =
492 container_of(work, struct sun4i_usb_phy_data, detect.work);
493 struct phy *phy0 = data->phys[0].phy;
Hans de Goede36f91592016-09-07 22:20:38 +0200494 bool force_session_end, id_notify = false, vbus_notify = false;
Hans de Goede9745cee2016-09-07 22:20:37 +0200495 int id_det, vbus_det;
Hans de Goeded2332302015-06-13 14:37:45 +0200496
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200497 if (phy0 == NULL)
498 return;
499
500 id_det = sun4i_usb_phy0_get_id_det(data);
Hans de Goede8665c182015-06-13 14:37:51 +0200501 vbus_det = sun4i_usb_phy0_get_vbus_det(data);
Hans de Goeded2332302015-06-13 14:37:45 +0200502
503 mutex_lock(&phy0->mutex);
504
505 if (!data->phy0_init) {
506 mutex_unlock(&phy0->mutex);
507 return;
508 }
509
Hans de Goede36f91592016-09-07 22:20:38 +0200510 force_session_end = data->force_session_end;
511 data->force_session_end = false;
512
Hans de Goeded2332302015-06-13 14:37:45 +0200513 if (id_det != data->id_det) {
Hans de Goede36f91592016-09-07 22:20:38 +0200514 /* id-change, force session end if we've no vbus detection */
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200515 if (data->dr_mode == USB_DR_MODE_OTG &&
Hans de Goede36f91592016-09-07 22:20:38 +0200516 !sun4i_usb_phy0_have_vbus_det(data))
517 force_session_end = true;
518
519 /* When entering host mode (id = 0) force end the session now */
520 if (force_session_end && id_det == 0) {
Hans de Goede1aedf3a2015-06-13 14:37:50 +0200521 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
522 msleep(200);
523 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
524 }
Hans de Goeded2332302015-06-13 14:37:45 +0200525 sun4i_usb_phy0_set_id_detect(phy0, id_det);
526 data->id_det = id_det;
Hans de Goede9745cee2016-09-07 22:20:37 +0200527 id_notify = true;
Hans de Goeded2332302015-06-13 14:37:45 +0200528 }
529
530 if (vbus_det != data->vbus_det) {
531 sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
532 data->vbus_det = vbus_det;
Hans de Goede9745cee2016-09-07 22:20:37 +0200533 vbus_notify = true;
Hans de Goeded2332302015-06-13 14:37:45 +0200534 }
535
536 mutex_unlock(&phy0->mutex);
537
Hans de Goede1aedf3a2015-06-13 14:37:50 +0200538 if (id_notify) {
Chanwoo Choi66adb882016-12-30 13:11:29 +0900539 extcon_set_state_sync(data->extcon, EXTCON_USB_HOST,
Hans de Goede1a52abe2015-06-13 14:37:46 +0200540 !id_det);
Hans de Goede36f91592016-09-07 22:20:38 +0200541 /* When leaving host mode force end the session here */
542 if (force_session_end && id_det == 1) {
Hans de Goede1aedf3a2015-06-13 14:37:50 +0200543 mutex_lock(&phy0->mutex);
544 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
545 msleep(1000);
546 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
547 mutex_unlock(&phy0->mutex);
548 }
549 }
Hans de Goede1a52abe2015-06-13 14:37:46 +0200550
551 if (vbus_notify)
Chanwoo Choi66adb882016-12-30 13:11:29 +0900552 extcon_set_state_sync(data->extcon, EXTCON_USB, vbus_det);
Hans de Goede1a52abe2015-06-13 14:37:46 +0200553
Hans de Goede91d96f02016-06-29 20:14:10 +0200554 if (sun4i_usb_phy0_poll(data))
Hans de Goeded2332302015-06-13 14:37:45 +0200555 queue_delayed_work(system_wq, &data->detect, POLL_TIME);
556}
557
558static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id)
559{
560 struct sun4i_usb_phy_data *data = dev_id;
561
562 /* vbus or id changed, let the pins settle and then scan them */
563 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
564
565 return IRQ_HANDLED;
566}
567
Hans de Goede8665c182015-06-13 14:37:51 +0200568static int sun4i_usb_phy0_vbus_notify(struct notifier_block *nb,
569 unsigned long val, void *v)
570{
571 struct sun4i_usb_phy_data *data =
572 container_of(nb, struct sun4i_usb_phy_data, vbus_power_nb);
573 struct power_supply *psy = v;
574
575 /* Properties on the vbus_power_supply changed, scan vbus_det */
576 if (val == PSY_EVENT_PROP_CHANGED && psy == data->vbus_power_supply)
577 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
578
579 return NOTIFY_OK;
580}
581
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100582static struct phy *sun4i_usb_phy_xlate(struct device *dev,
583 struct of_phandle_args *args)
584{
585 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
586
Hans de Goede5f90d312016-09-07 22:20:39 +0200587 if (args->args[0] >= data->cfg->num_phys)
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100588 return ERR_PTR(-ENODEV);
589
590 return data->phys[args->args[0]].phy;
591}
592
Hans de Goeded2332302015-06-13 14:37:45 +0200593static int sun4i_usb_phy_remove(struct platform_device *pdev)
594{
595 struct device *dev = &pdev->dev;
596 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
597
Hans de Goede8665c182015-06-13 14:37:51 +0200598 if (data->vbus_power_nb_registered)
599 power_supply_unreg_notifier(&data->vbus_power_nb);
Hans de Goede04e59a02016-06-18 11:31:33 +0200600 if (data->id_det_irq > 0)
Hans de Goeded2332302015-06-13 14:37:45 +0200601 devm_free_irq(dev, data->id_det_irq, data);
Hans de Goede04e59a02016-06-18 11:31:33 +0200602 if (data->vbus_det_irq > 0)
Hans de Goeded2332302015-06-13 14:37:45 +0200603 devm_free_irq(dev, data->vbus_det_irq, data);
604
605 cancel_delayed_work_sync(&data->detect);
606
607 return 0;
608}
609
Hans de Goede1a52abe2015-06-13 14:37:46 +0200610static const unsigned int sun4i_usb_phy0_cable[] = {
611 EXTCON_USB,
612 EXTCON_USB_HOST,
613 EXTCON_NONE,
614};
615
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100616static int sun4i_usb_phy_probe(struct platform_device *pdev)
617{
618 struct sun4i_usb_phy_data *data;
619 struct device *dev = &pdev->dev;
620 struct device_node *np = dev->of_node;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100621 struct phy_provider *phy_provider;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100622 struct resource *res;
Hans de Goeded2332302015-06-13 14:37:45 +0200623 int i, ret;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100624
625 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
626 if (!data)
627 return -ENOMEM;
628
Chen-Yu Tsai919ab252016-09-09 11:58:18 +0800629 spin_lock_init(&data->reg_lock);
Hans de Goeded2332302015-06-13 14:37:45 +0200630 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
631 dev_set_drvdata(dev, data);
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100632 data->cfg = of_device_get_match_data(dev);
633 if (!data->cfg)
634 return -EINVAL;
Hans de Goedefc1f45e2015-06-13 14:37:49 +0200635
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100636 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
637 data->base = devm_ioremap_resource(dev, res);
638 if (IS_ERR(data->base))
639 return PTR_ERR(data->base);
640
Axel Linb2dfc342015-09-25 08:47:29 +0800641 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
642 GPIOD_IN);
643 if (IS_ERR(data->id_det_gpio))
644 return PTR_ERR(data->id_det_gpio);
Hans de Goeded2332302015-06-13 14:37:45 +0200645
Axel Linb2dfc342015-09-25 08:47:29 +0800646 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det",
647 GPIOD_IN);
648 if (IS_ERR(data->vbus_det_gpio))
649 return PTR_ERR(data->vbus_det_gpio);
Hans de Goeded2332302015-06-13 14:37:45 +0200650
Hans de Goede8665c182015-06-13 14:37:51 +0200651 if (of_find_property(np, "usb0_vbus_power-supply", NULL)) {
652 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev,
653 "usb0_vbus_power-supply");
654 if (IS_ERR(data->vbus_power_supply))
655 return PTR_ERR(data->vbus_power_supply);
656
657 if (!data->vbus_power_supply)
658 return -EPROBE_DEFER;
659 }
660
Hans de Goedeb33ecca2016-08-08 21:55:39 +0200661 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
Hans de Goede1a52abe2015-06-13 14:37:46 +0200662
Hans de Goede5f90d312016-09-07 22:20:39 +0200663 data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
664 if (IS_ERR(data->extcon))
665 return PTR_ERR(data->extcon);
666
667 ret = devm_extcon_dev_register(dev, data->extcon);
668 if (ret) {
669 dev_err(dev, "failed to register extcon: %d\n", ret);
670 return ret;
Hans de Goede1a52abe2015-06-13 14:37:46 +0200671 }
672
Hans de Goede5f90d312016-09-07 22:20:39 +0200673 for (i = 0; i < data->cfg->num_phys; i++) {
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200674 struct sun4i_usb_phy *phy = data->phys + i;
675 char name[16];
676
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100677 snprintf(name, sizeof(name), "usb%d_vbus", i);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200678 phy->vbus = devm_regulator_get_optional(dev, name);
679 if (IS_ERR(phy->vbus)) {
680 if (PTR_ERR(phy->vbus) == -EPROBE_DEFER)
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100681 return -EPROBE_DEFER;
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200682 phy->vbus = NULL;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100683 }
684
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100685 if (data->cfg->dedicated_clocks)
Maxime Ripardeadd4312014-05-13 17:44:18 +0200686 snprintf(name, sizeof(name), "usb%d_phy", i);
687 else
688 strlcpy(name, "usb_phy", sizeof(name));
689
690 phy->clk = devm_clk_get(dev, name);
691 if (IS_ERR(phy->clk)) {
692 dev_err(dev, "failed to get clock %s\n", name);
693 return PTR_ERR(phy->clk);
694 }
695
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100696 snprintf(name, sizeof(name), "usb%d_reset", i);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200697 phy->reset = devm_reset_control_get(dev, name);
698 if (IS_ERR(phy->reset)) {
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100699 dev_err(dev, "failed to get reset %s\n", name);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200700 return PTR_ERR(phy->reset);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100701 }
702
703 if (i) { /* No pmu for usbc0 */
704 snprintf(name, sizeof(name), "pmu%d", i);
705 res = platform_get_resource_byname(pdev,
706 IORESOURCE_MEM, name);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200707 phy->pmu = devm_ioremap_resource(dev, res);
708 if (IS_ERR(phy->pmu))
709 return PTR_ERR(phy->pmu);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100710 }
711
Heikki Krogerusdbc98632014-11-19 17:28:21 +0200712 phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200713 if (IS_ERR(phy->phy)) {
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100714 dev_err(dev, "failed to create PHY %d\n", i);
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200715 return PTR_ERR(phy->phy);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100716 }
717
Maxime Ripard2a7f9982014-05-13 17:44:17 +0200718 phy->index = i;
719 phy_set_drvdata(phy->phy, &data->phys[i]);
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100720 }
721
Hans de Goeded2332302015-06-13 14:37:45 +0200722 data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
Quentin Schulz5cf700a2016-06-13 13:45:48 +0200723 if (data->id_det_irq > 0) {
Hans de Goeded2332302015-06-13 14:37:45 +0200724 ret = devm_request_irq(dev, data->id_det_irq,
725 sun4i_usb_phy0_id_vbus_det_irq,
726 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
727 "usb0-id-det", data);
728 if (ret) {
729 dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
730 return ret;
731 }
732 }
733
Hans de Goede91d96f02016-06-29 20:14:10 +0200734 data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
Quentin Schulz5cf700a2016-06-13 13:45:48 +0200735 if (data->vbus_det_irq > 0) {
Hans de Goeded2332302015-06-13 14:37:45 +0200736 ret = devm_request_irq(dev, data->vbus_det_irq,
737 sun4i_usb_phy0_id_vbus_det_irq,
738 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
739 "usb0-vbus-det", data);
740 if (ret) {
741 dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
742 data->vbus_det_irq = -1;
743 sun4i_usb_phy_remove(pdev); /* Stop detect work */
744 return ret;
745 }
746 }
747
Hans de Goede8665c182015-06-13 14:37:51 +0200748 if (data->vbus_power_supply) {
749 data->vbus_power_nb.notifier_call = sun4i_usb_phy0_vbus_notify;
750 data->vbus_power_nb.priority = 0;
751 ret = power_supply_reg_notifier(&data->vbus_power_nb);
752 if (ret) {
753 sun4i_usb_phy_remove(pdev); /* Stop detect work */
754 return ret;
755 }
756 data->vbus_power_nb_registered = true;
757 }
758
Hans de Goeded2332302015-06-13 14:37:45 +0200759 phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
760 if (IS_ERR(phy_provider)) {
761 sun4i_usb_phy_remove(pdev); /* Stop detect work */
762 return PTR_ERR(phy_provider);
763 }
764
765 return 0;
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100766}
767
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100768static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
769 .num_phys = 3,
770 .type = sun4i_a10_phy,
771 .disc_thresh = 3,
772 .phyctl_offset = REG_PHYCTL_A10,
773 .dedicated_clocks = false,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800774 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100775};
776
777static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
778 .num_phys = 2,
779 .type = sun4i_a10_phy,
780 .disc_thresh = 2,
781 .phyctl_offset = REG_PHYCTL_A10,
782 .dedicated_clocks = false,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800783 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100784};
785
786static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
787 .num_phys = 3,
Hans de Goede91d96f02016-06-29 20:14:10 +0200788 .type = sun6i_a31_phy,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100789 .disc_thresh = 3,
790 .phyctl_offset = REG_PHYCTL_A10,
791 .dedicated_clocks = true,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800792 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100793};
794
795static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
796 .num_phys = 3,
797 .type = sun4i_a10_phy,
798 .disc_thresh = 2,
799 .phyctl_offset = REG_PHYCTL_A10,
800 .dedicated_clocks = false,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800801 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100802};
803
804static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
805 .num_phys = 2,
806 .type = sun4i_a10_phy,
807 .disc_thresh = 3,
808 .phyctl_offset = REG_PHYCTL_A10,
809 .dedicated_clocks = true,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800810 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100811};
812
813static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
814 .num_phys = 2,
815 .type = sun8i_a33_phy,
816 .disc_thresh = 3,
817 .phyctl_offset = REG_PHYCTL_A33,
818 .dedicated_clocks = true,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800819 .enable_pmu_unk1 = false,
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100820};
821
Reinder de Haan626a6302015-12-11 16:32:18 +0100822static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
823 .num_phys = 4,
824 .type = sun8i_h3_phy,
825 .disc_thresh = 3,
826 .dedicated_clocks = true,
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800827 .enable_pmu_unk1 = true,
828};
829
Icenowy Zheng16c40362017-01-03 23:25:31 +0800830static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
831 .num_phys = 1,
832 .type = sun8i_v3s_phy,
833 .disc_thresh = 3,
834 .phyctl_offset = REG_PHYCTL_A33,
835 .dedicated_clocks = true,
836 .enable_pmu_unk1 = true,
837};
838
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800839static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
840 .num_phys = 2,
841 .type = sun50i_a64_phy,
842 .disc_thresh = 3,
843 .phyctl_offset = REG_PHYCTL_A33,
844 .dedicated_clocks = true,
845 .enable_pmu_unk1 = true,
Reinder de Haan626a6302015-12-11 16:32:18 +0100846};
847
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100848static const struct of_device_id sun4i_usb_phy_of_match[] = {
Hans de Goede68dbc2c2015-12-11 16:32:17 +0100849 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
850 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
851 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = &sun6i_a31_cfg },
852 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
853 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
854 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
Reinder de Haan626a6302015-12-11 16:32:18 +0100855 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
Icenowy Zheng16c40362017-01-03 23:25:31 +0800856 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg },
Icenowy Zhengb3e0d142016-08-12 11:06:21 +0800857 { .compatible = "allwinner,sun50i-a64-usb-phy",
858 .data = &sun50i_a64_cfg},
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100859 { },
860};
861MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
862
863static struct platform_driver sun4i_usb_phy_driver = {
864 .probe = sun4i_usb_phy_probe,
Hans de Goeded2332302015-06-13 14:37:45 +0200865 .remove = sun4i_usb_phy_remove,
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100866 .driver = {
867 .of_match_table = sun4i_usb_phy_of_match,
868 .name = "sun4i-usb-phy",
Hans de Goedeba4bdc92014-03-01 18:09:26 +0100869 }
870};
871module_platform_driver(sun4i_usb_phy_driver);
872
873MODULE_DESCRIPTION("Allwinner sun4i USB phy driver");
874MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
875MODULE_LICENSE("GPL v2");