Raghavendra Rao Ananta | caa60aa | 2017-10-20 11:27:12 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, 2017-2018, The Linux Foundation. All rights reserved. |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 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 | #ifndef __ESOC_MDM_H__ |
| 14 | #define __ESOC_MDM_H__ |
| 15 | |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/gpio.h> |
| 18 | #include <linux/jiffies.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/of_address.h> |
| 21 | #include <linux/of_gpio.h> |
| 22 | #include <linux/pinctrl/consumer.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include "esoc.h" |
| 26 | |
| 27 | #define MDM_PBLRDY_CNT 20 |
| 28 | #define INVALID_GPIO (-1) |
| 29 | #define MDM_GPIO(mdm, i) (mdm->gpios[i]) |
| 30 | #define MDM9x25_LABEL "MDM9x25" |
| 31 | #define MDM9x25_HSIC "HSIC" |
| 32 | #define MDM9x35_LABEL "MDM9x35" |
| 33 | #define MDM9x35_PCIE "PCIe" |
| 34 | #define MDM9x35_DUAL_LINK "HSIC+PCIe" |
| 35 | #define MDM9x35_HSIC "HSIC" |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 36 | #define MDM9x55_LABEL "MDM9x55" |
| 37 | #define MDM9x55_PCIE "PCIe" |
Raghavendra Rao Ananta | caa60aa | 2017-10-20 11:27:12 -0700 | [diff] [blame] | 38 | #define SDXPOORWILLS_LABEL "SDXPOORWILLS" |
| 39 | #define SDXPOORWILLS_PCIE "PCIe" |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 40 | #define MDM2AP_STATUS_TIMEOUT_MS 120000L |
| 41 | #define MDM_MODEM_TIMEOUT 3000 |
| 42 | #define DEF_RAMDUMP_TIMEOUT 120000 |
| 43 | #define DEF_RAMDUMP_DELAY 2000 |
| 44 | #define RD_BUF_SIZE 100 |
| 45 | #define SFR_MAX_RETRIES 10 |
| 46 | #define SFR_RETRY_INTERVAL 1000 |
| 47 | #define MDM_DBG_OFFSET 0x934 |
| 48 | #define MDM_DBG_MODE 0x53444247 |
| 49 | #define MDM_CTI_NAME "coresight-cti-rpm-cpu0" |
| 50 | #define MDM_CTI_TRIG 0 |
| 51 | #define MDM_CTI_CH 0 |
| 52 | |
| 53 | enum mdm_gpio { |
| 54 | AP2MDM_WAKEUP = 0, |
| 55 | AP2MDM_STATUS, |
| 56 | AP2MDM_SOFT_RESET, |
| 57 | AP2MDM_VDD_MIN, |
| 58 | AP2MDM_CHNLRDY, |
| 59 | AP2MDM_ERRFATAL, |
| 60 | AP2MDM_VDDMIN, |
| 61 | AP2MDM_PMIC_PWR_EN, |
| 62 | MDM2AP_WAKEUP, |
| 63 | MDM2AP_ERRFATAL, |
| 64 | MDM2AP_PBLRDY, |
| 65 | MDM2AP_STATUS, |
| 66 | MDM2AP_VDDMIN, |
| 67 | MDM_LINK_DETECT, |
| 68 | NUM_GPIOS, |
| 69 | }; |
| 70 | |
| 71 | struct mdm_pon_ops; |
| 72 | |
| 73 | struct mdm_ctrl { |
| 74 | unsigned int gpios[NUM_GPIOS]; |
| 75 | spinlock_t status_lock; |
| 76 | struct workqueue_struct *mdm_queue; |
| 77 | struct delayed_work mdm2ap_status_check_work; |
| 78 | struct work_struct mdm_status_work; |
| 79 | struct work_struct restart_reason_work; |
| 80 | struct completion debug_done; |
| 81 | struct device *dev; |
| 82 | struct pinctrl *pinctrl; |
| 83 | struct pinctrl_state *gpio_state_booting; |
| 84 | struct pinctrl_state *gpio_state_running; |
| 85 | struct pinctrl_state *gpio_state_active; |
| 86 | struct pinctrl_state *gpio_state_suspend; |
| 87 | int mdm2ap_status_valid_old_config; |
| 88 | int soft_reset_inverted; |
| 89 | int errfatal_irq; |
| 90 | int status_irq; |
| 91 | int pblrdy_irq; |
| 92 | int debug; |
| 93 | int init; |
| 94 | bool debug_fail; |
| 95 | unsigned int dump_timeout_ms; |
| 96 | unsigned int ramdump_delay_ms; |
| 97 | struct esoc_clink *esoc; |
| 98 | bool get_restart_reason; |
| 99 | unsigned long irq_mask; |
| 100 | bool ready; |
| 101 | bool dual_interface; |
| 102 | u32 status; |
| 103 | void __iomem *dbg_addr; |
| 104 | bool dbg_mode; |
| 105 | struct coresight_cti *cti; |
| 106 | int trig_cnt; |
| 107 | const struct mdm_pon_ops *pon_ops; |
| 108 | }; |
| 109 | |
| 110 | struct mdm_pon_ops { |
| 111 | int (*pon)(struct mdm_ctrl *mdm); |
| 112 | int (*soft_reset)(struct mdm_ctrl *mdm, bool atomic); |
| 113 | int (*poff_force)(struct mdm_ctrl *mdm); |
| 114 | int (*poff_cleanup)(struct mdm_ctrl *mdm); |
| 115 | void (*cold_reset)(struct mdm_ctrl *mdm); |
| 116 | int (*dt_init)(struct mdm_ctrl *mdm); |
| 117 | int (*setup)(struct mdm_ctrl *mdm); |
| 118 | }; |
| 119 | |
| 120 | struct mdm_ops { |
| 121 | struct esoc_clink_ops *clink_ops; |
| 122 | struct mdm_pon_ops *pon_ops; |
| 123 | int (*config_hw)(struct mdm_ctrl *mdm, const struct mdm_ops *ops, |
| 124 | struct platform_device *pdev); |
| 125 | }; |
| 126 | |
| 127 | static inline int mdm_toggle_soft_reset(struct mdm_ctrl *mdm, bool atomic) |
| 128 | { |
| 129 | return mdm->pon_ops->soft_reset(mdm, atomic); |
| 130 | } |
| 131 | static inline int mdm_do_first_power_on(struct mdm_ctrl *mdm) |
| 132 | { |
| 133 | return mdm->pon_ops->pon(mdm); |
| 134 | } |
| 135 | static inline int mdm_power_down(struct mdm_ctrl *mdm) |
| 136 | { |
| 137 | return mdm->pon_ops->poff_force(mdm); |
| 138 | } |
| 139 | static inline void mdm_cold_reset(struct mdm_ctrl *mdm) |
| 140 | { |
| 141 | mdm->pon_ops->cold_reset(mdm); |
| 142 | } |
| 143 | static inline int mdm_pon_dt_init(struct mdm_ctrl *mdm) |
| 144 | { |
| 145 | return mdm->pon_ops->dt_init(mdm); |
| 146 | } |
| 147 | static inline int mdm_pon_setup(struct mdm_ctrl *mdm) |
| 148 | { |
| 149 | return mdm->pon_ops->setup(mdm); |
| 150 | } |
| 151 | |
| 152 | extern struct mdm_pon_ops mdm9x25_pon_ops; |
| 153 | extern struct mdm_pon_ops mdm9x35_pon_ops; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 154 | extern struct mdm_pon_ops mdm9x55_pon_ops; |
Raghavendra Rao Ananta | caa60aa | 2017-10-20 11:27:12 -0700 | [diff] [blame] | 155 | extern struct mdm_pon_ops sdxpoorwills_pon_ops; |
Abhimanyu Kapur | c75b2e1 | 2016-02-22 18:15:13 -0800 | [diff] [blame] | 156 | #endif |