Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/regmap.h> |
| 17 | #include <linux/regulator/consumer.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/irq.h> |
| 23 | #include <linux/of_irq.h> |
| 24 | #include <linux/debugfs.h> |
| 25 | #include <linux/seq_file.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/wait.h> |
| 28 | #include "usbpd.h" |
| 29 | |
| 30 | #define USB_PDPHY_MAX_DATA_OBJ_LEN 28 |
| 31 | #define USB_PDPHY_MSG_HDR_LEN 2 |
| 32 | |
| 33 | /* PD PHY register offsets and bit fields */ |
| 34 | #define USB_PDPHY_MSG_CONFIG 0x40 |
| 35 | #define MSG_CONFIG_PORT_DATA_ROLE BIT(3) |
| 36 | #define MSG_CONFIG_PORT_POWER_ROLE BIT(2) |
| 37 | #define MSG_CONFIG_SPEC_REV_MASK (BIT(1) | BIT(0)) |
| 38 | |
| 39 | #define USB_PDPHY_EN_CONTROL 0x46 |
| 40 | #define CONTROL_ENABLE BIT(0) |
| 41 | |
| 42 | #define USB_PDPHY_RX_STATUS 0x4A |
| 43 | #define RX_FRAME_TYPE (BIT(0) | BIT(1) | BIT(2)) |
| 44 | |
| 45 | #define USB_PDPHY_FRAME_FILTER 0x4C |
| 46 | #define FRAME_FILTER_EN_HARD_RESET BIT(5) |
| 47 | #define FRAME_FILTER_EN_SOP BIT(0) |
| 48 | |
| 49 | #define USB_PDPHY_TX_SIZE 0x42 |
| 50 | #define TX_SIZE_MASK 0xF |
| 51 | |
| 52 | #define USB_PDPHY_TX_CONTROL 0x44 |
Jack Pham | c671252 | 2018-06-07 10:29:15 -0700 | [diff] [blame] | 53 | #define TX_CONTROL_RETRY_COUNT(n) (((n) & 0x3) << 5) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 54 | #define TX_CONTROL_FRAME_TYPE (BIT(4) | BIT(3) | BIT(2)) |
| 55 | #define TX_CONTROL_FRAME_TYPE_CABLE_RESET (0x1 << 2) |
| 56 | #define TX_CONTROL_SEND_SIGNAL BIT(1) |
| 57 | #define TX_CONTROL_SEND_MSG BIT(0) |
| 58 | |
| 59 | #define USB_PDPHY_RX_SIZE 0x48 |
| 60 | |
| 61 | #define USB_PDPHY_RX_ACKNOWLEDGE 0x4B |
| 62 | #define RX_BUFFER_TOKEN BIT(0) |
| 63 | |
| 64 | #define USB_PDPHY_BIST_MODE 0x4E |
| 65 | #define BIST_MODE_MASK 0xF |
| 66 | #define BIST_ENABLE BIT(7) |
| 67 | #define PD_MSG_BIST 0x3 |
| 68 | #define PD_BIST_TEST_DATA_MODE 0x8 |
| 69 | |
| 70 | #define USB_PDPHY_TX_BUFFER_HDR 0x60 |
| 71 | #define USB_PDPHY_TX_BUFFER_DATA 0x62 |
| 72 | |
| 73 | #define USB_PDPHY_RX_BUFFER 0x80 |
| 74 | |
| 75 | #define USB_PDPHY_SEC_ACCESS 0xD0 |
| 76 | #define USB_PDPHY_TRIM_3 0xF3 |
| 77 | |
| 78 | /* VDD regulator */ |
| 79 | #define VDD_PDPHY_VOL_MIN 3088000 /* uV */ |
| 80 | #define VDD_PDPHY_VOL_MAX 3088000 /* uV */ |
| 81 | #define VDD_PDPHY_HPM_LOAD 3000 /* uA */ |
| 82 | |
Jack Pham | c671252 | 2018-06-07 10:29:15 -0700 | [diff] [blame] | 83 | /* Message Spec Rev field */ |
| 84 | #define PD_MSG_HDR_REV(hdr) (((hdr) >> 6) & 3) |
| 85 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 86 | /* timers */ |
| 87 | #define RECEIVER_RESPONSE_TIME 15 /* tReceiverResponse */ |
| 88 | #define HARD_RESET_COMPLETE_TIME 5 /* tHardResetComplete */ |
| 89 | |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 90 | struct usb_pdphy { |
| 91 | struct device *dev; |
| 92 | struct regmap *regmap; |
| 93 | |
| 94 | u16 base; |
| 95 | struct regulator *vdd_pdphy; |
| 96 | |
| 97 | /* irqs */ |
| 98 | int sig_tx_irq; |
| 99 | int sig_rx_irq; |
| 100 | int msg_tx_irq; |
| 101 | int msg_rx_irq; |
| 102 | int msg_tx_failed_irq; |
| 103 | int msg_tx_discarded_irq; |
| 104 | int msg_rx_discarded_irq; |
| 105 | |
Jack Pham | e95cfc7 | 2017-08-01 17:36:50 -0700 | [diff] [blame] | 106 | void (*signal_cb)(struct usbpd *pd, enum pd_sig_type sig); |
| 107 | void (*msg_rx_cb)(struct usbpd *pd, enum pd_sop_type sop, |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 108 | u8 *buf, size_t len); |
| 109 | void (*shutdown_cb)(struct usbpd *pd); |
| 110 | |
| 111 | /* write waitq */ |
| 112 | wait_queue_head_t tx_waitq; |
| 113 | |
| 114 | bool is_opened; |
| 115 | int tx_status; |
| 116 | u8 frame_filter_val; |
| 117 | bool in_test_data_mode; |
| 118 | |
| 119 | enum data_role data_role; |
| 120 | enum power_role power_role; |
| 121 | |
| 122 | struct usbpd *usbpd; |
| 123 | |
| 124 | /* debug */ |
| 125 | struct dentry *debug_root; |
| 126 | unsigned int tx_bytes; /* hdr + data */ |
| 127 | unsigned int rx_bytes; /* hdr + data */ |
| 128 | unsigned int sig_tx_cnt; |
| 129 | unsigned int sig_rx_cnt; |
| 130 | unsigned int msg_tx_cnt; |
| 131 | unsigned int msg_rx_cnt; |
| 132 | unsigned int msg_tx_failed_cnt; |
| 133 | unsigned int msg_tx_discarded_cnt; |
| 134 | unsigned int msg_rx_discarded_cnt; |
| 135 | }; |
| 136 | |
| 137 | static struct usb_pdphy *__pdphy; |
| 138 | |
| 139 | static int pdphy_dbg_status(struct seq_file *s, void *p) |
| 140 | { |
| 141 | struct usb_pdphy *pdphy = s->private; |
| 142 | |
| 143 | seq_printf(s, |
| 144 | "PD Phy driver status\n" |
| 145 | "==================================================\n"); |
| 146 | seq_printf(s, "opened: %10d\n", pdphy->is_opened); |
| 147 | seq_printf(s, "tx status: %10d\n", pdphy->tx_status); |
| 148 | seq_printf(s, "tx bytes: %10u\n", pdphy->tx_bytes); |
| 149 | seq_printf(s, "rx bytes: %10u\n", pdphy->rx_bytes); |
| 150 | seq_printf(s, "data role: %10u\n", pdphy->data_role); |
| 151 | seq_printf(s, "power role: %10u\n", pdphy->power_role); |
| 152 | seq_printf(s, "frame filter: %10u\n", pdphy->frame_filter_val); |
| 153 | seq_printf(s, "sig tx cnt: %10u\n", pdphy->sig_tx_cnt); |
| 154 | seq_printf(s, "sig rx cnt: %10u\n", pdphy->sig_rx_cnt); |
| 155 | seq_printf(s, "msg tx cnt: %10u\n", pdphy->msg_tx_cnt); |
| 156 | seq_printf(s, "msg rx cnt: %10u\n", pdphy->msg_rx_cnt); |
| 157 | seq_printf(s, "msg tx failed cnt: %10u\n", |
| 158 | pdphy->msg_tx_failed_cnt); |
| 159 | seq_printf(s, "msg tx discarded cnt: %10u\n", |
| 160 | pdphy->msg_tx_discarded_cnt); |
| 161 | seq_printf(s, "msg rx discarded cnt: %10u\n", |
| 162 | pdphy->msg_rx_discarded_cnt); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int pdphy_dbg_status_open(struct inode *inode, struct file *file) |
| 168 | { |
| 169 | return single_open(file, pdphy_dbg_status, inode->i_private); |
| 170 | } |
| 171 | |
| 172 | static const struct file_operations status_ops = { |
| 173 | .owner = THIS_MODULE, |
| 174 | .open = pdphy_dbg_status_open, |
| 175 | .llseek = seq_lseek, |
| 176 | .read = seq_read, |
| 177 | .release = single_release, |
| 178 | }; |
| 179 | |
| 180 | static void pdphy_create_debugfs_entries(struct usb_pdphy *pdphy) |
| 181 | { |
| 182 | struct dentry *ent; |
| 183 | |
| 184 | pdphy->debug_root = debugfs_create_dir("usb-pdphy", NULL); |
| 185 | if (!pdphy->debug_root) { |
| 186 | dev_warn(pdphy->dev, "Couldn't create debug dir\n"); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | ent = debugfs_create_file("status", 0400, pdphy->debug_root, pdphy, |
| 191 | &status_ops); |
| 192 | if (!ent) { |
| 193 | dev_warn(pdphy->dev, "Couldn't create status file\n"); |
| 194 | debugfs_remove(pdphy->debug_root); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static int pdphy_enable_power(struct usb_pdphy *pdphy, bool on) |
| 199 | { |
| 200 | int ret = 0; |
| 201 | |
| 202 | dev_dbg(pdphy->dev, "%s turn %s regulator.\n", __func__, |
| 203 | on ? "on" : "off"); |
| 204 | |
| 205 | if (!on) |
| 206 | goto disable_pdphy_vdd; |
| 207 | |
| 208 | ret = regulator_set_load(pdphy->vdd_pdphy, VDD_PDPHY_HPM_LOAD); |
| 209 | if (ret < 0) { |
| 210 | dev_err(pdphy->dev, "Unable to set HPM of vdd_pdphy:%d\n", ret); |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | ret = regulator_set_voltage(pdphy->vdd_pdphy, VDD_PDPHY_VOL_MIN, |
| 215 | VDD_PDPHY_VOL_MAX); |
| 216 | if (ret) { |
| 217 | dev_err(pdphy->dev, |
| 218 | "set voltage failed for vdd_pdphy:%d\n", ret); |
| 219 | goto put_pdphy_vdd_lpm; |
| 220 | } |
| 221 | |
| 222 | ret = regulator_enable(pdphy->vdd_pdphy); |
| 223 | if (ret) { |
| 224 | dev_err(pdphy->dev, "Unable to enable vdd_pdphy:%d\n", ret); |
| 225 | goto unset_pdphy_vdd; |
| 226 | } |
| 227 | |
| 228 | dev_dbg(pdphy->dev, "%s: PD PHY regulator turned ON.\n", __func__); |
| 229 | return ret; |
| 230 | |
| 231 | disable_pdphy_vdd: |
| 232 | ret = regulator_disable(pdphy->vdd_pdphy); |
| 233 | if (ret) |
| 234 | dev_err(pdphy->dev, "Unable to disable vdd_pdphy:%d\n", ret); |
| 235 | |
| 236 | unset_pdphy_vdd: |
| 237 | ret = regulator_set_voltage(pdphy->vdd_pdphy, 0, VDD_PDPHY_VOL_MAX); |
| 238 | if (ret) |
| 239 | dev_err(pdphy->dev, |
| 240 | "Unable to set (0) voltage for vdd_pdphy:%d\n", ret); |
| 241 | |
| 242 | put_pdphy_vdd_lpm: |
| 243 | ret = regulator_set_load(pdphy->vdd_pdphy, 0); |
| 244 | if (ret < 0) |
| 245 | dev_err(pdphy->dev, "Unable to set (0) HPM of vdd_pdphy\n"); |
| 246 | |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | void pdphy_enable_irq(struct usb_pdphy *pdphy, bool enable) |
| 251 | { |
| 252 | if (enable) { |
| 253 | enable_irq(pdphy->sig_tx_irq); |
| 254 | enable_irq(pdphy->sig_rx_irq); |
| 255 | enable_irq_wake(pdphy->sig_rx_irq); |
| 256 | enable_irq(pdphy->msg_tx_irq); |
| 257 | if (!pdphy->in_test_data_mode) { |
| 258 | enable_irq(pdphy->msg_rx_irq); |
| 259 | enable_irq_wake(pdphy->msg_rx_irq); |
| 260 | } |
| 261 | enable_irq(pdphy->msg_tx_failed_irq); |
| 262 | enable_irq(pdphy->msg_tx_discarded_irq); |
| 263 | enable_irq(pdphy->msg_rx_discarded_irq); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | disable_irq(pdphy->sig_tx_irq); |
| 268 | disable_irq(pdphy->sig_rx_irq); |
| 269 | disable_irq_wake(pdphy->sig_rx_irq); |
| 270 | disable_irq(pdphy->msg_tx_irq); |
| 271 | if (!pdphy->in_test_data_mode) { |
| 272 | disable_irq(pdphy->msg_rx_irq); |
| 273 | disable_irq_wake(pdphy->msg_rx_irq); |
| 274 | } |
| 275 | disable_irq(pdphy->msg_tx_failed_irq); |
| 276 | disable_irq(pdphy->msg_tx_discarded_irq); |
| 277 | disable_irq(pdphy->msg_rx_discarded_irq); |
| 278 | } |
| 279 | |
| 280 | static int pdphy_reg_read(struct usb_pdphy *pdphy, u8 *val, u16 addr, int count) |
| 281 | { |
| 282 | int ret; |
| 283 | |
| 284 | ret = regmap_bulk_read(pdphy->regmap, pdphy->base + addr, val, count); |
| 285 | if (ret) { |
| 286 | dev_err(pdphy->dev, "read failed: addr=0x%04x, ret=%d\n", |
| 287 | pdphy->base + addr, ret); |
| 288 | return ret; |
| 289 | } |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | /* Write multiple registers to device with block of data */ |
| 295 | static int pdphy_bulk_reg_write(struct usb_pdphy *pdphy, u16 addr, |
| 296 | const void *val, u8 val_cnt) |
| 297 | { |
| 298 | int ret; |
| 299 | |
| 300 | ret = regmap_bulk_write(pdphy->regmap, pdphy->base + addr, |
| 301 | val, val_cnt); |
| 302 | if (ret) { |
| 303 | dev_err(pdphy->dev, "bulk write failed: addr=0x%04x, ret=%d\n", |
| 304 | pdphy->base + addr, ret); |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | /* Writes a single byte to the specified register */ |
| 312 | static inline int pdphy_reg_write(struct usb_pdphy *pdphy, u16 addr, u8 val) |
| 313 | { |
| 314 | return pdphy_bulk_reg_write(pdphy, addr, &val, 1); |
| 315 | } |
| 316 | |
| 317 | /* Writes to the specified register limited by the bit mask */ |
| 318 | static int pdphy_masked_write(struct usb_pdphy *pdphy, u16 addr, |
| 319 | u8 mask, u8 val) |
| 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | ret = regmap_update_bits(pdphy->regmap, pdphy->base + addr, mask, val); |
| 324 | if (ret) { |
| 325 | dev_err(pdphy->dev, "write failed: addr=0x%04x, ret=%d\n", |
| 326 | pdphy->base + addr, ret); |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | int pd_phy_update_roles(enum data_role dr, enum power_role pr) |
| 334 | { |
| 335 | struct usb_pdphy *pdphy = __pdphy; |
| 336 | |
| 337 | return pdphy_masked_write(pdphy, USB_PDPHY_MSG_CONFIG, |
| 338 | (MSG_CONFIG_PORT_DATA_ROLE | MSG_CONFIG_PORT_POWER_ROLE), |
| 339 | ((dr == DR_DFP ? MSG_CONFIG_PORT_DATA_ROLE : 0) | |
| 340 | (pr == PR_SRC ? MSG_CONFIG_PORT_POWER_ROLE : 0))); |
| 341 | } |
| 342 | EXPORT_SYMBOL(pd_phy_update_roles); |
| 343 | |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 344 | int pd_phy_open(struct pd_phy_params *params) |
| 345 | { |
| 346 | int ret; |
| 347 | struct usb_pdphy *pdphy = __pdphy; |
| 348 | |
| 349 | if (!pdphy) { |
| 350 | pr_err("%s: pdphy not found\n", __func__); |
| 351 | return -ENODEV; |
| 352 | } |
| 353 | |
| 354 | if (pdphy->is_opened) { |
| 355 | dev_err(pdphy->dev, "%s: already opened\n", __func__); |
| 356 | return -EBUSY; |
| 357 | } |
| 358 | |
| 359 | pdphy->signal_cb = params->signal_cb; |
| 360 | pdphy->msg_rx_cb = params->msg_rx_cb; |
| 361 | pdphy->shutdown_cb = params->shutdown_cb; |
| 362 | pdphy->data_role = params->data_role; |
| 363 | pdphy->power_role = params->power_role; |
| 364 | pdphy->frame_filter_val = params->frame_filter_val; |
| 365 | |
| 366 | dev_dbg(pdphy->dev, "%s: DR %x PR %x frame filter val %x\n", __func__, |
| 367 | pdphy->data_role, pdphy->power_role, pdphy->frame_filter_val); |
| 368 | |
| 369 | ret = pdphy_enable_power(pdphy, true); |
| 370 | if (ret) |
| 371 | return ret; |
| 372 | |
| 373 | /* update data and power role to be used in GoodCRC generation */ |
| 374 | ret = pd_phy_update_roles(pdphy->data_role, pdphy->power_role); |
| 375 | if (ret) |
| 376 | return ret; |
| 377 | |
Hemant Kumar | 796534e | 2017-05-30 15:54:55 -0700 | [diff] [blame] | 378 | /* PD 2.0 phy */ |
| 379 | ret = pdphy_masked_write(pdphy, USB_PDPHY_MSG_CONFIG, |
| 380 | MSG_CONFIG_SPEC_REV_MASK, USBPD_REV_20); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 381 | if (ret) |
| 382 | return ret; |
| 383 | |
| 384 | ret = pdphy_reg_write(pdphy, USB_PDPHY_EN_CONTROL, 0); |
| 385 | if (ret) |
| 386 | return ret; |
| 387 | |
| 388 | ret = pdphy_reg_write(pdphy, USB_PDPHY_EN_CONTROL, CONTROL_ENABLE); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | |
| 392 | /* update frame filter */ |
| 393 | ret = pdphy_reg_write(pdphy, USB_PDPHY_FRAME_FILTER, |
| 394 | pdphy->frame_filter_val); |
| 395 | if (ret) |
| 396 | return ret; |
| 397 | |
| 398 | /* initialize Rx buffer ownership to PDPHY HW */ |
| 399 | ret = pdphy_reg_write(pdphy, USB_PDPHY_RX_ACKNOWLEDGE, 0); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | |
| 403 | pdphy->is_opened = true; |
| 404 | pdphy_enable_irq(pdphy, true); |
| 405 | |
| 406 | return ret; |
| 407 | } |
| 408 | EXPORT_SYMBOL(pd_phy_open); |
| 409 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 410 | int pd_phy_signal(enum pd_sig_type sig) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 411 | { |
| 412 | u8 val; |
| 413 | int ret; |
| 414 | struct usb_pdphy *pdphy = __pdphy; |
| 415 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 416 | dev_dbg(pdphy->dev, "%s: type %d\n", __func__, sig); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 417 | |
| 418 | if (!pdphy) { |
| 419 | pr_err("%s: pdphy not found\n", __func__); |
| 420 | return -ENODEV; |
| 421 | } |
| 422 | |
| 423 | if (!pdphy->is_opened) { |
| 424 | dev_dbg(pdphy->dev, "%s: pdphy disabled\n", __func__); |
| 425 | return -ENODEV; |
| 426 | } |
| 427 | |
| 428 | pdphy->tx_status = -EINPROGRESS; |
| 429 | |
| 430 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, 0); |
| 431 | if (ret) |
| 432 | return ret; |
| 433 | |
| 434 | usleep_range(2, 3); |
| 435 | |
Jack Pham | e95cfc7 | 2017-08-01 17:36:50 -0700 | [diff] [blame] | 436 | val = (sig == CABLE_RESET_SIG ? TX_CONTROL_FRAME_TYPE_CABLE_RESET : 0) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 437 | | TX_CONTROL_SEND_SIGNAL; |
| 438 | |
| 439 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, val); |
| 440 | if (ret) |
| 441 | return ret; |
| 442 | |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 443 | ret = wait_event_interruptible_hrtimeout(pdphy->tx_waitq, |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 444 | pdphy->tx_status != -EINPROGRESS, |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 445 | ms_to_ktime(HARD_RESET_COMPLETE_TIME)); |
| 446 | if (ret) { |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 447 | dev_err(pdphy->dev, "%s: failed ret %d", __func__, ret); |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 448 | return ret; |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, 0); |
| 452 | |
| 453 | if (pdphy->tx_status) |
| 454 | return pdphy->tx_status; |
| 455 | |
Jack Pham | e95cfc7 | 2017-08-01 17:36:50 -0700 | [diff] [blame] | 456 | if (sig == HARD_RESET_SIG) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 457 | /* Frame filter is reconfigured in pd_phy_open() */ |
| 458 | return pdphy_reg_write(pdphy, USB_PDPHY_FRAME_FILTER, 0); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | EXPORT_SYMBOL(pd_phy_signal); |
| 463 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 464 | int pd_phy_write(u16 hdr, const u8 *data, size_t data_len, enum pd_sop_type sop) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 465 | { |
| 466 | u8 val; |
| 467 | int ret; |
| 468 | size_t total_len = data_len + USB_PDPHY_MSG_HDR_LEN; |
| 469 | struct usb_pdphy *pdphy = __pdphy; |
| 470 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 471 | dev_dbg(pdphy->dev, "%s: hdr %x frame sop_type %d\n", |
| 472 | __func__, hdr, sop); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 473 | |
| 474 | if (data && data_len) |
| 475 | print_hex_dump_debug("tx data obj:", DUMP_PREFIX_NONE, 32, 4, |
| 476 | data, data_len, false); |
| 477 | |
| 478 | if (!pdphy) { |
| 479 | pr_err("%s: pdphy not found\n", __func__); |
| 480 | return -ENODEV; |
| 481 | } |
| 482 | |
| 483 | if (!pdphy->is_opened) { |
| 484 | dev_dbg(pdphy->dev, "%s: pdphy disabled\n", __func__); |
| 485 | return -ENODEV; |
| 486 | } |
| 487 | |
| 488 | if (data_len > USB_PDPHY_MAX_DATA_OBJ_LEN) { |
| 489 | dev_err(pdphy->dev, "%s: invalid data object len %zu\n", |
| 490 | __func__, data_len); |
| 491 | return -EINVAL; |
| 492 | } |
| 493 | |
Jack Pham | e24693c | 2017-06-06 22:30:47 -0700 | [diff] [blame] | 494 | ret = pdphy_reg_read(pdphy, &val, USB_PDPHY_RX_ACKNOWLEDGE, 1); |
Jack Pham | f0c2339 | 2017-10-12 09:41:51 -0700 | [diff] [blame] | 495 | if (ret || val) { |
Jack Pham | e24693c | 2017-06-06 22:30:47 -0700 | [diff] [blame] | 496 | dev_err(pdphy->dev, "%s: RX message pending\n", __func__); |
| 497 | return -EBUSY; |
| 498 | } |
| 499 | |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 500 | pdphy->tx_status = -EINPROGRESS; |
| 501 | |
| 502 | /* write 2 byte SOP message header */ |
| 503 | ret = pdphy_bulk_reg_write(pdphy, USB_PDPHY_TX_BUFFER_HDR, (u8 *)&hdr, |
| 504 | USB_PDPHY_MSG_HDR_LEN); |
| 505 | if (ret) |
| 506 | return ret; |
| 507 | |
| 508 | if (data && data_len) { |
| 509 | /* write data objects of SOP message */ |
| 510 | ret = pdphy_bulk_reg_write(pdphy, USB_PDPHY_TX_BUFFER_DATA, |
| 511 | data, data_len); |
| 512 | if (ret) |
| 513 | return ret; |
| 514 | } |
| 515 | |
| 516 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_SIZE, total_len - 1); |
| 517 | if (ret) |
| 518 | return ret; |
| 519 | |
| 520 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, 0); |
| 521 | if (ret) |
| 522 | return ret; |
| 523 | |
| 524 | usleep_range(2, 3); |
| 525 | |
Jack Pham | c671252 | 2018-06-07 10:29:15 -0700 | [diff] [blame] | 526 | val = (sop << 2) | TX_CONTROL_SEND_MSG; |
| 527 | |
| 528 | /* nRetryCount == 2 for PD 3.0, 3 for PD 2.0 */ |
| 529 | if (PD_MSG_HDR_REV(hdr) == USBPD_REV_30) |
| 530 | val |= TX_CONTROL_RETRY_COUNT(2); |
| 531 | else |
| 532 | val |= TX_CONTROL_RETRY_COUNT(3); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 533 | |
| 534 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, val); |
| 535 | if (ret) |
| 536 | return ret; |
| 537 | |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 538 | ret = wait_event_interruptible_hrtimeout(pdphy->tx_waitq, |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 539 | pdphy->tx_status != -EINPROGRESS, |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 540 | ms_to_ktime(RECEIVER_RESPONSE_TIME)); |
| 541 | if (ret) { |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 542 | dev_err(pdphy->dev, "%s: failed ret %d", __func__, ret); |
Jack Pham | b904b66 | 2018-06-08 10:10:12 -0700 | [diff] [blame] | 543 | return ret; |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (hdr && !pdphy->tx_status) |
| 547 | pdphy->tx_bytes += data_len + USB_PDPHY_MSG_HDR_LEN; |
| 548 | |
Jack Pham | 7dfd761 | 2017-08-01 18:04:13 -0700 | [diff] [blame] | 549 | return pdphy->tx_status ? pdphy->tx_status : 0; |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 550 | } |
| 551 | EXPORT_SYMBOL(pd_phy_write); |
| 552 | |
| 553 | void pd_phy_close(void) |
| 554 | { |
| 555 | int ret; |
| 556 | struct usb_pdphy *pdphy = __pdphy; |
| 557 | |
| 558 | if (!pdphy) { |
| 559 | pr_err("%s: pdphy not found\n", __func__); |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | if (!pdphy->is_opened) { |
| 564 | dev_err(pdphy->dev, "%s: not opened\n", __func__); |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | pdphy->is_opened = false; |
| 569 | pdphy_enable_irq(pdphy, false); |
| 570 | |
| 571 | pdphy->tx_status = -ESHUTDOWN; |
| 572 | |
| 573 | wake_up_all(&pdphy->tx_waitq); |
| 574 | |
| 575 | pdphy_reg_write(pdphy, USB_PDPHY_BIST_MODE, 0); |
| 576 | pdphy->in_test_data_mode = false; |
| 577 | |
| 578 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TX_CONTROL, 0); |
| 579 | if (ret) |
| 580 | return; |
| 581 | |
| 582 | ret = pdphy_reg_write(pdphy, USB_PDPHY_EN_CONTROL, 0); |
| 583 | if (ret) |
| 584 | return; |
| 585 | |
| 586 | pdphy_enable_power(pdphy, false); |
| 587 | } |
| 588 | EXPORT_SYMBOL(pd_phy_close); |
| 589 | |
| 590 | static irqreturn_t pdphy_msg_tx_irq(int irq, void *data) |
| 591 | { |
| 592 | struct usb_pdphy *pdphy = data; |
| 593 | |
Jack Pham | 4b32328 | 2017-11-03 12:24:59 -0700 | [diff] [blame] | 594 | /* TX already aborted by received signal */ |
| 595 | if (pdphy->tx_status != -EINPROGRESS) |
| 596 | return IRQ_HANDLED; |
| 597 | |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 598 | if (irq == pdphy->msg_tx_irq) { |
| 599 | pdphy->msg_tx_cnt++; |
| 600 | pdphy->tx_status = 0; |
| 601 | } else if (irq == pdphy->msg_tx_discarded_irq) { |
| 602 | pdphy->msg_tx_discarded_cnt++; |
| 603 | pdphy->tx_status = -EBUSY; |
| 604 | } else if (irq == pdphy->msg_tx_failed_irq) { |
| 605 | pdphy->msg_tx_failed_cnt++; |
| 606 | pdphy->tx_status = -EFAULT; |
| 607 | } else { |
| 608 | dev_err(pdphy->dev, "spurious irq #%d received\n", irq); |
| 609 | return IRQ_NONE; |
| 610 | } |
| 611 | |
| 612 | wake_up(&pdphy->tx_waitq); |
| 613 | |
| 614 | return IRQ_HANDLED; |
| 615 | } |
| 616 | |
| 617 | static irqreturn_t pdphy_msg_rx_discarded_irq(int irq, void *data) |
| 618 | { |
| 619 | struct usb_pdphy *pdphy = data; |
| 620 | |
| 621 | pdphy->msg_rx_discarded_cnt++; |
| 622 | |
| 623 | return IRQ_HANDLED; |
| 624 | } |
| 625 | |
| 626 | static irqreturn_t pdphy_sig_rx_irq_thread(int irq, void *data) |
| 627 | { |
| 628 | u8 rx_status, frame_type; |
| 629 | int ret; |
| 630 | struct usb_pdphy *pdphy = data; |
| 631 | |
| 632 | pdphy->sig_rx_cnt++; |
| 633 | |
| 634 | ret = pdphy_reg_read(pdphy, &rx_status, USB_PDPHY_RX_STATUS, 1); |
| 635 | if (ret) |
| 636 | goto done; |
| 637 | |
| 638 | frame_type = rx_status & RX_FRAME_TYPE; |
| 639 | if (frame_type != HARD_RESET_SIG) { |
| 640 | dev_err(pdphy->dev, "%s:unsupported frame type %d\n", |
| 641 | __func__, frame_type); |
| 642 | goto done; |
| 643 | } |
| 644 | |
| 645 | /* Frame filter is reconfigured in pd_phy_open() */ |
| 646 | ret = pdphy_reg_write(pdphy, USB_PDPHY_FRAME_FILTER, 0); |
| 647 | |
| 648 | if (pdphy->signal_cb) |
| 649 | pdphy->signal_cb(pdphy->usbpd, frame_type); |
| 650 | |
Jack Pham | 4b32328 | 2017-11-03 12:24:59 -0700 | [diff] [blame] | 651 | if (pdphy->tx_status == -EINPROGRESS) { |
| 652 | pdphy->tx_status = -EBUSY; |
| 653 | wake_up(&pdphy->tx_waitq); |
| 654 | } |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 655 | done: |
| 656 | return IRQ_HANDLED; |
| 657 | } |
| 658 | |
| 659 | static irqreturn_t pdphy_sig_tx_irq_thread(int irq, void *data) |
| 660 | { |
| 661 | struct usb_pdphy *pdphy = data; |
| 662 | |
| 663 | /* in case of exit from BIST Carrier Mode 2, clear BIST_MODE */ |
| 664 | pdphy_reg_write(pdphy, USB_PDPHY_BIST_MODE, 0); |
| 665 | |
| 666 | pdphy->sig_tx_cnt++; |
| 667 | pdphy->tx_status = 0; |
| 668 | wake_up(&pdphy->tx_waitq); |
| 669 | |
| 670 | return IRQ_HANDLED; |
| 671 | } |
| 672 | |
| 673 | static int pd_phy_bist_mode(u8 bist_mode) |
| 674 | { |
| 675 | struct usb_pdphy *pdphy = __pdphy; |
| 676 | |
| 677 | dev_dbg(pdphy->dev, "%s: enter BIST mode %d\n", __func__, bist_mode); |
| 678 | |
| 679 | pdphy_reg_write(pdphy, USB_PDPHY_BIST_MODE, 0); |
| 680 | |
| 681 | udelay(5); |
| 682 | |
| 683 | return pdphy_masked_write(pdphy, USB_PDPHY_BIST_MODE, |
| 684 | BIST_MODE_MASK | BIST_ENABLE, bist_mode | BIST_ENABLE); |
| 685 | } |
| 686 | |
Jack Pham | a27be8f | 2017-11-02 10:51:48 -0700 | [diff] [blame] | 687 | static irqreturn_t pdphy_msg_rx_irq(int irq, void *data) |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 688 | { |
| 689 | u8 size, rx_status, frame_type; |
| 690 | u8 buf[32]; |
| 691 | int ret; |
| 692 | struct usb_pdphy *pdphy = data; |
| 693 | |
| 694 | pdphy->msg_rx_cnt++; |
| 695 | |
| 696 | ret = pdphy_reg_read(pdphy, &size, USB_PDPHY_RX_SIZE, 1); |
| 697 | if (ret) |
| 698 | goto done; |
| 699 | |
| 700 | if (!size || size > 31) { |
| 701 | dev_err(pdphy->dev, "%s: invalid size %d\n", __func__, size); |
| 702 | goto done; |
| 703 | } |
| 704 | |
| 705 | ret = pdphy_reg_read(pdphy, &rx_status, USB_PDPHY_RX_STATUS, 1); |
| 706 | if (ret) |
| 707 | goto done; |
| 708 | |
| 709 | frame_type = rx_status & RX_FRAME_TYPE; |
| 710 | if (frame_type != SOP_MSG) { |
| 711 | dev_err(pdphy->dev, "%s:unsupported frame type %d\n", |
| 712 | __func__, frame_type); |
| 713 | goto done; |
| 714 | } |
| 715 | |
| 716 | ret = pdphy_reg_read(pdphy, buf, USB_PDPHY_RX_BUFFER, size + 1); |
| 717 | if (ret) |
| 718 | goto done; |
| 719 | |
| 720 | /* ack to change ownership of rx buffer back to PDPHY RX HW */ |
| 721 | pdphy_reg_write(pdphy, USB_PDPHY_RX_ACKNOWLEDGE, 0); |
| 722 | |
| 723 | if (((buf[0] & 0xf) == PD_MSG_BIST) && size >= 5) { /* BIST */ |
| 724 | u8 mode = buf[5] >> 4; /* [31:28] of 1st data object */ |
| 725 | |
| 726 | pd_phy_bist_mode(mode); |
| 727 | pdphy_reg_write(pdphy, USB_PDPHY_RX_ACKNOWLEDGE, 0); |
| 728 | |
| 729 | if (mode == PD_BIST_TEST_DATA_MODE) { |
| 730 | pdphy->in_test_data_mode = true; |
| 731 | disable_irq_nosync(irq); |
| 732 | } |
| 733 | goto done; |
| 734 | } |
| 735 | |
| 736 | if (pdphy->msg_rx_cb) |
| 737 | pdphy->msg_rx_cb(pdphy->usbpd, frame_type, buf, size + 1); |
| 738 | |
| 739 | print_hex_dump_debug("rx msg:", DUMP_PREFIX_NONE, 32, 4, buf, size + 1, |
| 740 | false); |
| 741 | pdphy->rx_bytes += size + 1; |
| 742 | done: |
| 743 | return IRQ_HANDLED; |
| 744 | } |
| 745 | |
| 746 | static int pdphy_request_irq(struct usb_pdphy *pdphy, |
| 747 | struct device_node *node, |
| 748 | int *irq_num, const char *irq_name, |
| 749 | irqreturn_t (irq_handler)(int irq, void *data), |
| 750 | irqreturn_t (thread_fn)(int irq, void *data), |
| 751 | int flags) |
| 752 | { |
| 753 | int ret; |
| 754 | |
| 755 | *irq_num = of_irq_get_byname(node, irq_name); |
| 756 | if (*irq_num < 0) { |
| 757 | dev_err(pdphy->dev, "Unable to get %s irqn", irq_name); |
| 758 | ret = -ENXIO; |
| 759 | } |
| 760 | |
| 761 | irq_set_status_flags(*irq_num, IRQ_NOAUTOEN); |
| 762 | ret = devm_request_threaded_irq(pdphy->dev, *irq_num, irq_handler, |
| 763 | thread_fn, flags, irq_name, pdphy); |
| 764 | if (ret < 0) { |
| 765 | dev_err(pdphy->dev, "Unable to request %s irq: %dn", |
| 766 | irq_name, ret); |
| 767 | ret = -ENXIO; |
| 768 | } |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int pdphy_probe(struct platform_device *pdev) |
| 774 | { |
| 775 | int ret; |
| 776 | unsigned int base; |
| 777 | struct usb_pdphy *pdphy; |
| 778 | |
| 779 | pdphy = devm_kzalloc(&pdev->dev, sizeof(*pdphy), GFP_KERNEL); |
| 780 | if (!pdphy) |
| 781 | return -ENOMEM; |
| 782 | |
| 783 | pdphy->regmap = dev_get_regmap(pdev->dev.parent, NULL); |
| 784 | if (!pdphy->regmap) { |
| 785 | dev_err(&pdev->dev, "Couldn't get parent's regmap\n"); |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
| 789 | dev_set_drvdata(&pdev->dev, pdphy); |
| 790 | |
| 791 | ret = of_property_read_u32(pdev->dev.of_node, "reg", &base); |
| 792 | if (ret < 0) { |
| 793 | dev_err(&pdev->dev, "failed to get reg base address ret = %d\n", |
| 794 | ret); |
| 795 | return ret; |
| 796 | } |
| 797 | |
| 798 | pdphy->base = base; |
| 799 | pdphy->dev = &pdev->dev; |
| 800 | |
| 801 | init_waitqueue_head(&pdphy->tx_waitq); |
| 802 | |
| 803 | pdphy->vdd_pdphy = devm_regulator_get(&pdev->dev, "vdd-pdphy"); |
| 804 | if (IS_ERR(pdphy->vdd_pdphy)) { |
| 805 | dev_err(&pdev->dev, "unable to get vdd-pdphy\n"); |
| 806 | return PTR_ERR(pdphy->vdd_pdphy); |
| 807 | } |
| 808 | |
| 809 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 810 | &pdphy->sig_tx_irq, "sig-tx", NULL, |
| 811 | pdphy_sig_tx_irq_thread, (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 812 | if (ret < 0) |
| 813 | return ret; |
| 814 | |
| 815 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 816 | &pdphy->sig_rx_irq, "sig-rx", NULL, |
| 817 | pdphy_sig_rx_irq_thread, (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 818 | if (ret < 0) |
| 819 | return ret; |
| 820 | |
| 821 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 822 | &pdphy->msg_tx_irq, "msg-tx", pdphy_msg_tx_irq, |
| 823 | NULL, (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 824 | if (ret < 0) |
| 825 | return ret; |
| 826 | |
| 827 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
Jack Pham | a27be8f | 2017-11-02 10:51:48 -0700 | [diff] [blame] | 828 | &pdphy->msg_rx_irq, "msg-rx", pdphy_msg_rx_irq, |
| 829 | NULL, (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
Jack Pham | f4baeb1 | 2017-02-03 19:01:48 -0800 | [diff] [blame] | 830 | if (ret < 0) |
| 831 | return ret; |
| 832 | |
| 833 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 834 | &pdphy->msg_tx_failed_irq, "msg-tx-failed", pdphy_msg_tx_irq, |
| 835 | NULL, (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 836 | if (ret < 0) |
| 837 | return ret; |
| 838 | |
| 839 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 840 | &pdphy->msg_tx_discarded_irq, "msg-tx-discarded", |
| 841 | pdphy_msg_tx_irq, NULL, |
| 842 | (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 843 | if (ret < 0) |
| 844 | return ret; |
| 845 | |
| 846 | ret = pdphy_request_irq(pdphy, pdev->dev.of_node, |
| 847 | &pdphy->msg_rx_discarded_irq, "msg-rx-discarded", |
| 848 | pdphy_msg_rx_discarded_irq, NULL, |
| 849 | (IRQF_TRIGGER_RISING | IRQF_ONESHOT)); |
| 850 | if (ret < 0) |
| 851 | return ret; |
| 852 | |
| 853 | ret = pdphy_reg_write(pdphy, USB_PDPHY_SEC_ACCESS, 0xA5); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | |
| 857 | ret = pdphy_reg_write(pdphy, USB_PDPHY_TRIM_3, 0x2); |
| 858 | if (ret) |
| 859 | return ret; |
| 860 | |
| 861 | /* usbpd_create() could call back to us, so have __pdphy ready */ |
| 862 | __pdphy = pdphy; |
| 863 | |
| 864 | pdphy->usbpd = usbpd_create(&pdev->dev); |
| 865 | if (IS_ERR(pdphy->usbpd)) { |
| 866 | dev_err(&pdev->dev, "usbpd_create failed: %ld\n", |
| 867 | PTR_ERR(pdphy->usbpd)); |
| 868 | __pdphy = NULL; |
| 869 | return PTR_ERR(pdphy->usbpd); |
| 870 | } |
| 871 | |
| 872 | pdphy_create_debugfs_entries(pdphy); |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | static int pdphy_remove(struct platform_device *pdev) |
| 878 | { |
| 879 | struct usb_pdphy *pdphy = platform_get_drvdata(pdev); |
| 880 | |
| 881 | debugfs_remove_recursive(pdphy->debug_root); |
| 882 | usbpd_destroy(pdphy->usbpd); |
| 883 | |
| 884 | if (pdphy->is_opened) |
| 885 | pd_phy_close(); |
| 886 | |
| 887 | __pdphy = NULL; |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static void pdphy_shutdown(struct platform_device *pdev) |
| 893 | { |
| 894 | struct usb_pdphy *pdphy = platform_get_drvdata(pdev); |
| 895 | |
| 896 | /* let protocol engine shutdown the pdphy synchronously */ |
| 897 | if (pdphy->shutdown_cb) |
| 898 | pdphy->shutdown_cb(pdphy->usbpd); |
| 899 | } |
| 900 | |
| 901 | static const struct of_device_id pdphy_match_table[] = { |
| 902 | { |
| 903 | .compatible = "qcom,qpnp-pdphy", |
| 904 | }, |
| 905 | { }, |
| 906 | }; |
| 907 | MODULE_DEVICE_TABLE(of, pdphy_match_table); |
| 908 | |
| 909 | static struct platform_driver pdphy_driver = { |
| 910 | .driver = { |
| 911 | .name = "qpnp-pdphy", |
| 912 | .of_match_table = pdphy_match_table, |
| 913 | }, |
| 914 | .probe = pdphy_probe, |
| 915 | .remove = pdphy_remove, |
| 916 | .shutdown = pdphy_shutdown, |
| 917 | }; |
| 918 | |
| 919 | module_platform_driver(pdphy_driver); |
| 920 | |
| 921 | MODULE_DESCRIPTION("QPNP PD PHY Driver"); |
| 922 | MODULE_LICENSE("GPL v2"); |
| 923 | MODULE_ALIAS("platform:qpnp-pdphy"); |