Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Allwinner sun4i USB phy driver |
| 3 | * |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 4 | * Copyright (C) 2014-2015 Hans de Goede <hdegoede@redhat.com> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 5 | * |
| 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 Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 25 | #include <linux/delay.h> |
Sachin Kamat | 2d84aff | 2014-05-29 12:00:49 +0530 | [diff] [blame] | 26 | #include <linux/err.h> |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 27 | #include <linux/extcon.h> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 30 | #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 Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 35 | #include <linux/of_gpio.h> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 36 | #include <linux/phy/phy.h> |
Hans de Goede | 24fe86a | 2015-03-29 12:50:46 +0200 | [diff] [blame] | 37 | #include <linux/phy/phy-sun4i-usb.h> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 38 | #include <linux/platform_device.h> |
| 39 | #include <linux/regulator/consumer.h> |
| 40 | #include <linux/reset.h> |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 41 | #include <linux/workqueue.h> |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 42 | |
| 43 | #define REG_ISCR 0x00 |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 44 | #define REG_PHYCTL_A10 0x04 |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 45 | #define REG_PHYBIST 0x08 |
| 46 | #define REG_PHYTUNE 0x0c |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 47 | #define REG_PHYCTL_A33 0x10 |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 48 | |
| 49 | #define PHYCTL_DATA BIT(7) |
| 50 | |
| 51 | #define SUNXI_AHB_ICHR8_EN BIT(10) |
| 52 | #define SUNXI_AHB_INCR4_BURST_EN BIT(9) |
| 53 | #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8) |
| 54 | #define SUNXI_ULPI_BYPASS_EN BIT(0) |
| 55 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 56 | /* ISCR, Interface Status and Control bits */ |
| 57 | #define ISCR_ID_PULLUP_EN (1 << 17) |
| 58 | #define ISCR_DPDM_PULLUP_EN (1 << 16) |
| 59 | /* sunxi has the phy id/vbus pins not connected, so we use the force bits */ |
| 60 | #define ISCR_FORCE_ID_MASK (3 << 14) |
| 61 | #define ISCR_FORCE_ID_LOW (2 << 14) |
| 62 | #define ISCR_FORCE_ID_HIGH (3 << 14) |
| 63 | #define ISCR_FORCE_VBUS_MASK (3 << 12) |
| 64 | #define ISCR_FORCE_VBUS_LOW (2 << 12) |
| 65 | #define ISCR_FORCE_VBUS_HIGH (3 << 12) |
| 66 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 67 | /* Common Control Bits for Both PHYs */ |
| 68 | #define PHY_PLL_BW 0x03 |
| 69 | #define PHY_RES45_CAL_EN 0x0c |
| 70 | |
| 71 | /* Private Control Bits for Each PHY */ |
| 72 | #define PHY_TX_AMPLITUDE_TUNE 0x20 |
| 73 | #define PHY_TX_SLEWRATE_TUNE 0x22 |
| 74 | #define PHY_VBUSVALID_TH_SEL 0x25 |
| 75 | #define PHY_PULLUP_RES_SEL 0x27 |
| 76 | #define PHY_OTG_FUNC_EN 0x28 |
| 77 | #define PHY_VBUS_DET_EN 0x29 |
| 78 | #define PHY_DISCON_TH_SEL 0x2a |
Hans de Goede | 24fe86a | 2015-03-29 12:50:46 +0200 | [diff] [blame] | 79 | #define PHY_SQUELCH_DETECT 0x3c |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 80 | |
| 81 | #define MAX_PHYS 3 |
| 82 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 83 | /* |
| 84 | * Note do not raise the debounce time, we must report Vusb high within 100ms |
| 85 | * otherwise we get Vbus errors |
| 86 | */ |
| 87 | #define DEBOUNCE_TIME msecs_to_jiffies(50) |
| 88 | #define POLL_TIME msecs_to_jiffies(250) |
| 89 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 90 | struct sun4i_usb_phy_data { |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 91 | void __iomem *base; |
| 92 | struct mutex mutex; |
| 93 | int num_phys; |
| 94 | u32 disc_thresh; |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 95 | bool has_a33_phyctl; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 96 | struct sun4i_usb_phy { |
| 97 | struct phy *phy; |
| 98 | void __iomem *pmu; |
| 99 | struct regulator *vbus; |
| 100 | struct reset_control *reset; |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 101 | struct clk *clk; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 102 | bool regulator_on; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 103 | int index; |
| 104 | } phys[MAX_PHYS]; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 105 | /* phy0 / otg related variables */ |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 106 | struct extcon_dev *extcon; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 107 | bool phy0_init; |
| 108 | bool phy0_poll; |
| 109 | struct gpio_desc *id_det_gpio; |
| 110 | struct gpio_desc *vbus_det_gpio; |
| 111 | int id_det_irq; |
| 112 | int vbus_det_irq; |
| 113 | int id_det; |
| 114 | int vbus_det; |
| 115 | struct delayed_work detect; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #define to_sun4i_usb_phy_data(phy) \ |
| 119 | container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index]) |
| 120 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 121 | static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set) |
| 122 | { |
| 123 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
| 124 | struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); |
| 125 | u32 iscr; |
| 126 | |
| 127 | iscr = readl(data->base + REG_ISCR); |
| 128 | iscr &= ~clr; |
| 129 | iscr |= set; |
| 130 | writel(iscr, data->base + REG_ISCR); |
| 131 | } |
| 132 | |
| 133 | static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val) |
| 134 | { |
| 135 | if (val) |
| 136 | val = ISCR_FORCE_ID_HIGH; |
| 137 | else |
| 138 | val = ISCR_FORCE_ID_LOW; |
| 139 | |
| 140 | sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val); |
| 141 | } |
| 142 | |
| 143 | static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val) |
| 144 | { |
| 145 | if (val) |
| 146 | val = ISCR_FORCE_VBUS_HIGH; |
| 147 | else |
| 148 | val = ISCR_FORCE_VBUS_LOW; |
| 149 | |
| 150 | sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val); |
| 151 | } |
| 152 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 153 | static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data, |
| 154 | int len) |
| 155 | { |
| 156 | struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy); |
| 157 | u32 temp, usbc_bit = BIT(phy->index * 2); |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 158 | void *phyctl; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 159 | int i; |
| 160 | |
| 161 | mutex_lock(&phy_data->mutex); |
| 162 | |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 163 | if (phy_data->has_a33_phyctl) { |
| 164 | phyctl = phy_data->base + REG_PHYCTL_A33; |
| 165 | /* A33 needs us to set phyctl to 0 explicitly */ |
| 166 | writel(0, phyctl); |
| 167 | } else { |
| 168 | phyctl = phy_data->base + REG_PHYCTL_A10; |
| 169 | } |
| 170 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 171 | for (i = 0; i < len; i++) { |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 172 | temp = readl(phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 173 | |
| 174 | /* clear the address portion */ |
| 175 | temp &= ~(0xff << 8); |
| 176 | |
| 177 | /* set the address */ |
| 178 | temp |= ((addr + i) << 8); |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 179 | writel(temp, phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 180 | |
| 181 | /* set the data bit and clear usbc bit*/ |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 182 | temp = readb(phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 183 | if (data & 0x1) |
| 184 | temp |= PHYCTL_DATA; |
| 185 | else |
| 186 | temp &= ~PHYCTL_DATA; |
| 187 | temp &= ~usbc_bit; |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 188 | writeb(temp, phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 189 | |
| 190 | /* pulse usbc_bit */ |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 191 | temp = readb(phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 192 | temp |= usbc_bit; |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 193 | writeb(temp, phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 194 | |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 195 | temp = readb(phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 196 | temp &= ~usbc_bit; |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 197 | writeb(temp, phyctl); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 198 | |
| 199 | data >>= 1; |
| 200 | } |
| 201 | mutex_unlock(&phy_data->mutex); |
| 202 | } |
| 203 | |
| 204 | static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable) |
| 205 | { |
| 206 | u32 bits, reg_value; |
| 207 | |
| 208 | if (!phy->pmu) |
| 209 | return; |
| 210 | |
| 211 | bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN | |
| 212 | SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN; |
| 213 | |
| 214 | reg_value = readl(phy->pmu); |
| 215 | |
| 216 | if (enable) |
| 217 | reg_value |= bits; |
| 218 | else |
| 219 | reg_value &= ~bits; |
| 220 | |
| 221 | writel(reg_value, phy->pmu); |
| 222 | } |
| 223 | |
| 224 | static int sun4i_usb_phy_init(struct phy *_phy) |
| 225 | { |
| 226 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
| 227 | struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); |
| 228 | int ret; |
| 229 | |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 230 | ret = clk_prepare_enable(phy->clk); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 231 | if (ret) |
| 232 | return ret; |
| 233 | |
| 234 | ret = reset_control_deassert(phy->reset); |
| 235 | if (ret) { |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 236 | clk_disable_unprepare(phy->clk); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 237 | return ret; |
| 238 | } |
| 239 | |
Roman Byshko | 6827a46f | 2014-11-10 19:55:06 +0100 | [diff] [blame] | 240 | /* Enable USB 45 Ohm resistor calibration */ |
| 241 | if (phy->index == 0) |
| 242 | sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1); |
| 243 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 244 | /* Adjust PHY's magnitude and rate */ |
| 245 | sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5); |
| 246 | |
| 247 | /* Disconnect threshold adjustment */ |
| 248 | sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2); |
| 249 | |
| 250 | sun4i_usb_phy_passby(phy, 1); |
| 251 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 252 | if (phy->index == 0) { |
| 253 | data->phy0_init = true; |
| 254 | |
| 255 | /* Enable pull-ups */ |
| 256 | sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN); |
| 257 | sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN); |
| 258 | |
| 259 | if (data->id_det_gpio) { |
| 260 | /* OTG mode, force ISCR and cable state updates */ |
| 261 | data->id_det = -1; |
| 262 | data->vbus_det = -1; |
| 263 | queue_delayed_work(system_wq, &data->detect, 0); |
| 264 | } else { |
| 265 | /* Host only mode */ |
| 266 | sun4i_usb_phy0_set_id_detect(_phy, 0); |
| 267 | sun4i_usb_phy0_set_vbus_detect(_phy, 1); |
| 268 | } |
| 269 | } |
| 270 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static int sun4i_usb_phy_exit(struct phy *_phy) |
| 275 | { |
| 276 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 277 | struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); |
| 278 | |
| 279 | if (phy->index == 0) { |
| 280 | /* Disable pull-ups */ |
| 281 | sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0); |
| 282 | sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0); |
| 283 | data->phy0_init = false; |
| 284 | } |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 285 | |
| 286 | sun4i_usb_phy_passby(phy, 0); |
| 287 | reset_control_assert(phy->reset); |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 288 | clk_disable_unprepare(phy->clk); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int sun4i_usb_phy_power_on(struct phy *_phy) |
| 294 | { |
| 295 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 296 | struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); |
| 297 | int ret; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 298 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 299 | if (!phy->vbus || phy->regulator_on) |
| 300 | return 0; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 301 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 302 | /* For phy0 only turn on Vbus if we don't have an ext. Vbus */ |
| 303 | if (phy->index == 0 && data->vbus_det) |
| 304 | return 0; |
| 305 | |
| 306 | ret = regulator_enable(phy->vbus); |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | |
| 310 | phy->regulator_on = true; |
| 311 | |
| 312 | /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */ |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 313 | if (phy->index == 0 && data->vbus_det_gpio && data->phy0_poll) |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 314 | mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME); |
| 315 | |
| 316 | return 0; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static int sun4i_usb_phy_power_off(struct phy *_phy) |
| 320 | { |
| 321 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 322 | struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 323 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 324 | if (!phy->vbus || !phy->regulator_on) |
| 325 | return 0; |
| 326 | |
| 327 | regulator_disable(phy->vbus); |
| 328 | phy->regulator_on = false; |
| 329 | |
| 330 | /* |
| 331 | * phy0 vbus typically slowly discharges, sometimes this causes the |
| 332 | * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan. |
| 333 | */ |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 334 | if (phy->index == 0 && data->vbus_det_gpio && !data->phy0_poll) |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 335 | mod_delayed_work(system_wq, &data->detect, POLL_TIME); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Hans de Goede | 24fe86a | 2015-03-29 12:50:46 +0200 | [diff] [blame] | 340 | void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled) |
| 341 | { |
| 342 | struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); |
| 343 | |
| 344 | sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2); |
| 345 | } |
| 346 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 347 | static struct phy_ops sun4i_usb_phy_ops = { |
| 348 | .init = sun4i_usb_phy_init, |
| 349 | .exit = sun4i_usb_phy_exit, |
| 350 | .power_on = sun4i_usb_phy_power_on, |
| 351 | .power_off = sun4i_usb_phy_power_off, |
| 352 | .owner = THIS_MODULE, |
| 353 | }; |
| 354 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 355 | static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work) |
| 356 | { |
| 357 | struct sun4i_usb_phy_data *data = |
| 358 | container_of(work, struct sun4i_usb_phy_data, detect.work); |
| 359 | struct phy *phy0 = data->phys[0].phy; |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 360 | int id_det, vbus_det, id_notify = 0, vbus_notify = 0; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 361 | |
| 362 | id_det = gpiod_get_value_cansleep(data->id_det_gpio); |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 363 | if (data->vbus_det_gpio) |
| 364 | vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio); |
| 365 | else |
| 366 | vbus_det = 1; /* Report vbus as high */ |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 367 | |
| 368 | mutex_lock(&phy0->mutex); |
| 369 | |
| 370 | if (!data->phy0_init) { |
| 371 | mutex_unlock(&phy0->mutex); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | if (id_det != data->id_det) { |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 376 | /* |
| 377 | * When a host cable (id == 0) gets plugged in on systems |
| 378 | * without vbus detection report vbus low for long enough for |
| 379 | * the musb-ip to end the current device session. |
| 380 | */ |
| 381 | if (!data->vbus_det_gpio && id_det == 0) { |
| 382 | sun4i_usb_phy0_set_vbus_detect(phy0, 0); |
| 383 | msleep(200); |
| 384 | sun4i_usb_phy0_set_vbus_detect(phy0, 1); |
| 385 | } |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 386 | sun4i_usb_phy0_set_id_detect(phy0, id_det); |
| 387 | data->id_det = id_det; |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 388 | id_notify = 1; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | if (vbus_det != data->vbus_det) { |
| 392 | sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det); |
| 393 | data->vbus_det = vbus_det; |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 394 | vbus_notify = 1; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | mutex_unlock(&phy0->mutex); |
| 398 | |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 399 | if (id_notify) { |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 400 | extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST, |
| 401 | !id_det); |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 402 | /* |
| 403 | * When a host cable gets unplugged (id == 1) on systems |
| 404 | * without vbus detection report vbus low for long enough to |
| 405 | * the musb-ip to end the current host session. |
| 406 | */ |
| 407 | if (!data->vbus_det_gpio && id_det == 1) { |
| 408 | mutex_lock(&phy0->mutex); |
| 409 | sun4i_usb_phy0_set_vbus_detect(phy0, 0); |
| 410 | msleep(1000); |
| 411 | sun4i_usb_phy0_set_vbus_detect(phy0, 1); |
| 412 | mutex_unlock(&phy0->mutex); |
| 413 | } |
| 414 | } |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 415 | |
| 416 | if (vbus_notify) |
| 417 | extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det); |
| 418 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 419 | if (data->phy0_poll) |
| 420 | queue_delayed_work(system_wq, &data->detect, POLL_TIME); |
| 421 | } |
| 422 | |
| 423 | static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id) |
| 424 | { |
| 425 | struct sun4i_usb_phy_data *data = dev_id; |
| 426 | |
| 427 | /* vbus or id changed, let the pins settle and then scan them */ |
| 428 | mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME); |
| 429 | |
| 430 | return IRQ_HANDLED; |
| 431 | } |
| 432 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 433 | static struct phy *sun4i_usb_phy_xlate(struct device *dev, |
| 434 | struct of_phandle_args *args) |
| 435 | { |
| 436 | struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); |
| 437 | |
Roman Byshko | 6827a46f | 2014-11-10 19:55:06 +0100 | [diff] [blame] | 438 | if (args->args[0] >= data->num_phys) |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 439 | return ERR_PTR(-ENODEV); |
| 440 | |
| 441 | return data->phys[args->args[0]].phy; |
| 442 | } |
| 443 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 444 | static int sun4i_usb_phy_remove(struct platform_device *pdev) |
| 445 | { |
| 446 | struct device *dev = &pdev->dev; |
| 447 | struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); |
| 448 | |
| 449 | if (data->id_det_irq >= 0) |
| 450 | devm_free_irq(dev, data->id_det_irq, data); |
| 451 | if (data->vbus_det_irq >= 0) |
| 452 | devm_free_irq(dev, data->vbus_det_irq, data); |
| 453 | |
| 454 | cancel_delayed_work_sync(&data->detect); |
| 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 459 | static const unsigned int sun4i_usb_phy0_cable[] = { |
| 460 | EXTCON_USB, |
| 461 | EXTCON_USB_HOST, |
| 462 | EXTCON_NONE, |
| 463 | }; |
| 464 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 465 | static int sun4i_usb_phy_probe(struct platform_device *pdev) |
| 466 | { |
| 467 | struct sun4i_usb_phy_data *data; |
| 468 | struct device *dev = &pdev->dev; |
| 469 | struct device_node *np = dev->of_node; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 470 | struct phy_provider *phy_provider; |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 471 | bool dedicated_clocks; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 472 | struct resource *res; |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 473 | int i, ret; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 474 | |
| 475 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
| 476 | if (!data) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | mutex_init(&data->mutex); |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 480 | INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan); |
| 481 | dev_set_drvdata(dev, data); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 482 | |
Hans de Goede | 123dfdb | 2015-06-13 14:37:48 +0200 | [diff] [blame] | 483 | if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") || |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 484 | of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") || |
| 485 | of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 486 | data->num_phys = 2; |
| 487 | else |
| 488 | data->num_phys = 3; |
| 489 | |
Hans de Goede | 2846469 | 2015-06-13 14:37:47 +0200 | [diff] [blame] | 490 | if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") || |
| 491 | of_device_is_compatible(np, "allwinner,sun7i-a20-usb-phy")) |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 492 | data->disc_thresh = 2; |
Hans de Goede | 2846469 | 2015-06-13 14:37:47 +0200 | [diff] [blame] | 493 | else |
| 494 | data->disc_thresh = 3; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 495 | |
Hans de Goede | 123dfdb | 2015-06-13 14:37:48 +0200 | [diff] [blame] | 496 | if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") || |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 497 | of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") || |
| 498 | of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 499 | dedicated_clocks = true; |
| 500 | else |
| 501 | dedicated_clocks = false; |
| 502 | |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 503 | if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) |
| 504 | data->has_a33_phyctl = true; |
| 505 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 506 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl"); |
| 507 | data->base = devm_ioremap_resource(dev, res); |
| 508 | if (IS_ERR(data->base)) |
| 509 | return PTR_ERR(data->base); |
| 510 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 511 | data->id_det_gpio = devm_gpiod_get(dev, "usb0_id_det", GPIOD_IN); |
| 512 | if (IS_ERR(data->id_det_gpio)) { |
| 513 | if (PTR_ERR(data->id_det_gpio) == -EPROBE_DEFER) |
| 514 | return -EPROBE_DEFER; |
| 515 | data->id_det_gpio = NULL; |
| 516 | } |
| 517 | |
| 518 | data->vbus_det_gpio = devm_gpiod_get(dev, "usb0_vbus_det", GPIOD_IN); |
| 519 | if (IS_ERR(data->vbus_det_gpio)) { |
| 520 | if (PTR_ERR(data->vbus_det_gpio) == -EPROBE_DEFER) |
| 521 | return -EPROBE_DEFER; |
| 522 | data->vbus_det_gpio = NULL; |
| 523 | } |
| 524 | |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 525 | /* vbus_det without id_det makes no sense, and is not supported */ |
| 526 | if (data->vbus_det_gpio && !data->id_det_gpio) { |
| 527 | dev_err(dev, "usb0_id_det missing or invalid\n"); |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 528 | return -ENODEV; |
| 529 | } |
| 530 | |
Hans de Goede | 1a52abe | 2015-06-13 14:37:46 +0200 | [diff] [blame] | 531 | if (data->id_det_gpio) { |
| 532 | data->extcon = devm_extcon_dev_allocate(dev, |
| 533 | sun4i_usb_phy0_cable); |
| 534 | if (IS_ERR(data->extcon)) |
| 535 | return PTR_ERR(data->extcon); |
| 536 | |
| 537 | ret = devm_extcon_dev_register(dev, data->extcon); |
| 538 | if (ret) { |
| 539 | dev_err(dev, "failed to register extcon: %d\n", ret); |
| 540 | return ret; |
| 541 | } |
| 542 | } |
| 543 | |
Roman Byshko | 6827a46f | 2014-11-10 19:55:06 +0100 | [diff] [blame] | 544 | for (i = 0; i < data->num_phys; i++) { |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 545 | struct sun4i_usb_phy *phy = data->phys + i; |
| 546 | char name[16]; |
| 547 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 548 | snprintf(name, sizeof(name), "usb%d_vbus", i); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 549 | phy->vbus = devm_regulator_get_optional(dev, name); |
| 550 | if (IS_ERR(phy->vbus)) { |
| 551 | if (PTR_ERR(phy->vbus) == -EPROBE_DEFER) |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 552 | return -EPROBE_DEFER; |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 553 | phy->vbus = NULL; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 556 | if (dedicated_clocks) |
| 557 | snprintf(name, sizeof(name), "usb%d_phy", i); |
| 558 | else |
| 559 | strlcpy(name, "usb_phy", sizeof(name)); |
| 560 | |
| 561 | phy->clk = devm_clk_get(dev, name); |
| 562 | if (IS_ERR(phy->clk)) { |
| 563 | dev_err(dev, "failed to get clock %s\n", name); |
| 564 | return PTR_ERR(phy->clk); |
| 565 | } |
| 566 | |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 567 | snprintf(name, sizeof(name), "usb%d_reset", i); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 568 | phy->reset = devm_reset_control_get(dev, name); |
| 569 | if (IS_ERR(phy->reset)) { |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 570 | dev_err(dev, "failed to get reset %s\n", name); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 571 | return PTR_ERR(phy->reset); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | if (i) { /* No pmu for usbc0 */ |
| 575 | snprintf(name, sizeof(name), "pmu%d", i); |
| 576 | res = platform_get_resource_byname(pdev, |
| 577 | IORESOURCE_MEM, name); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 578 | phy->pmu = devm_ioremap_resource(dev, res); |
| 579 | if (IS_ERR(phy->pmu)) |
| 580 | return PTR_ERR(phy->pmu); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 581 | } |
| 582 | |
Heikki Krogerus | dbc9863 | 2014-11-19 17:28:21 +0200 | [diff] [blame] | 583 | phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 584 | if (IS_ERR(phy->phy)) { |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 585 | dev_err(dev, "failed to create PHY %d\n", i); |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 586 | return PTR_ERR(phy->phy); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Maxime Ripard | 2a7f998 | 2014-05-13 17:44:17 +0200 | [diff] [blame] | 589 | phy->index = i; |
| 590 | phy_set_drvdata(phy->phy, &data->phys[i]); |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 593 | data->id_det_irq = gpiod_to_irq(data->id_det_gpio); |
| 594 | data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio); |
Hans de Goede | 1aedf3a | 2015-06-13 14:37:50 +0200 | [diff] [blame^] | 595 | if ((data->id_det_gpio && data->id_det_irq < 0) || |
| 596 | (data->vbus_det_gpio && data->vbus_det_irq < 0)) |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 597 | data->phy0_poll = true; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 598 | |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 599 | if (data->id_det_irq >= 0) { |
| 600 | ret = devm_request_irq(dev, data->id_det_irq, |
| 601 | sun4i_usb_phy0_id_vbus_det_irq, |
| 602 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 603 | "usb0-id-det", data); |
| 604 | if (ret) { |
| 605 | dev_err(dev, "Err requesting id-det-irq: %d\n", ret); |
| 606 | return ret; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (data->vbus_det_irq >= 0) { |
| 611 | ret = devm_request_irq(dev, data->vbus_det_irq, |
| 612 | sun4i_usb_phy0_id_vbus_det_irq, |
| 613 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 614 | "usb0-vbus-det", data); |
| 615 | if (ret) { |
| 616 | dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret); |
| 617 | data->vbus_det_irq = -1; |
| 618 | sun4i_usb_phy_remove(pdev); /* Stop detect work */ |
| 619 | return ret; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate); |
| 624 | if (IS_ERR(phy_provider)) { |
| 625 | sun4i_usb_phy_remove(pdev); /* Stop detect work */ |
| 626 | return PTR_ERR(phy_provider); |
| 627 | } |
| 628 | |
| 629 | return 0; |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static const struct of_device_id sun4i_usb_phy_of_match[] = { |
| 633 | { .compatible = "allwinner,sun4i-a10-usb-phy" }, |
| 634 | { .compatible = "allwinner,sun5i-a13-usb-phy" }, |
Maxime Ripard | eadd431 | 2014-05-13 17:44:18 +0200 | [diff] [blame] | 635 | { .compatible = "allwinner,sun6i-a31-usb-phy" }, |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 636 | { .compatible = "allwinner,sun7i-a20-usb-phy" }, |
Hans de Goede | 123dfdb | 2015-06-13 14:37:48 +0200 | [diff] [blame] | 637 | { .compatible = "allwinner,sun8i-a23-usb-phy" }, |
Hans de Goede | fc1f45e | 2015-06-13 14:37:49 +0200 | [diff] [blame] | 638 | { .compatible = "allwinner,sun8i-a33-usb-phy" }, |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 639 | { }, |
| 640 | }; |
| 641 | MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match); |
| 642 | |
| 643 | static struct platform_driver sun4i_usb_phy_driver = { |
| 644 | .probe = sun4i_usb_phy_probe, |
Hans de Goede | d233230 | 2015-06-13 14:37:45 +0200 | [diff] [blame] | 645 | .remove = sun4i_usb_phy_remove, |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 646 | .driver = { |
| 647 | .of_match_table = sun4i_usb_phy_of_match, |
| 648 | .name = "sun4i-usb-phy", |
Hans de Goede | ba4bdc9 | 2014-03-01 18:09:26 +0100 | [diff] [blame] | 649 | } |
| 650 | }; |
| 651 | module_platform_driver(sun4i_usb_phy_driver); |
| 652 | |
| 653 | MODULE_DESCRIPTION("Allwinner sun4i USB phy driver"); |
| 654 | MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); |
| 655 | MODULE_LICENSE("GPL v2"); |