Skip to content

Commit 048eb90

Browse files
Akash Asthanaandersson
authored andcommitted
soc: qcom-geni-se: Add interconnect support to fix earlycon crash
QUP core clock is shared among all the SE drivers present on particular QUP wrapper, the system will reset(unclocked access) if earlycon used after QUP core clock is put to 0 from other SE drivers before real console comes up. As earlycon can't vote for it's QUP core need, to fix this add ICC support to common/QUP wrapper driver and put vote for QUP core from probe on behalf of earlycon and remove vote during earlycon exit call. Signed-off-by: Akash Asthana <[email protected]> Reported-by: Matthias Kaehlcke <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 58ffbba commit 048eb90

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

drivers/soc/qcom/qcom-geni-se.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/acpi.h>
55
#include <linux/clk.h>
6+
#include <linux/console.h>
67
#include <linux/slab.h>
78
#include <linux/dma-mapping.h>
89
#include <linux/io.h>
@@ -90,11 +91,14 @@ struct geni_wrapper {
9091
struct device *dev;
9192
void __iomem *base;
9293
struct clk_bulk_data ahb_clks[NUM_AHB_CLKS];
94+
struct geni_icc_path to_core;
9395
};
9496

9597
static const char * const icc_path_names[] = {"qup-core", "qup-config",
9698
"qup-memory"};
9799

100+
static struct geni_wrapper *earlycon_wrapper;
101+
98102
#define QUP_HW_VER_REG 0x4
99103

100104
/* Common SE registers */
@@ -802,11 +806,38 @@ int geni_icc_disable(struct geni_se *se)
802806
}
803807
EXPORT_SYMBOL(geni_icc_disable);
804808

809+
void geni_remove_earlycon_icc_vote(void)
810+
{
811+
struct geni_wrapper *wrapper;
812+
struct device_node *parent;
813+
struct device_node *child;
814+
815+
if (!earlycon_wrapper)
816+
return;
817+
818+
wrapper = earlycon_wrapper;
819+
parent = of_get_next_parent(wrapper->dev->of_node);
820+
for_each_child_of_node(parent, child) {
821+
if (!of_device_is_compatible(child, "qcom,geni-se-qup"))
822+
continue;
823+
wrapper = platform_get_drvdata(of_find_device_by_node(child));
824+
icc_put(wrapper->to_core.path);
825+
wrapper->to_core.path = NULL;
826+
827+
}
828+
of_node_put(parent);
829+
830+
earlycon_wrapper = NULL;
831+
}
832+
EXPORT_SYMBOL(geni_remove_earlycon_icc_vote);
833+
805834
static int geni_se_probe(struct platform_device *pdev)
806835
{
807836
struct device *dev = &pdev->dev;
808837
struct resource *res;
809838
struct geni_wrapper *wrapper;
839+
struct console __maybe_unused *bcon;
840+
bool __maybe_unused has_earlycon = false;
810841
int ret;
811842

812843
wrapper = devm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL);
@@ -829,6 +860,43 @@ static int geni_se_probe(struct platform_device *pdev)
829860
}
830861
}
831862

863+
#ifdef CONFIG_SERIAL_EARLYCON
864+
for_each_console(bcon) {
865+
if (!strcmp(bcon->name, "qcom_geni")) {
866+
has_earlycon = true;
867+
break;
868+
}
869+
}
870+
if (!has_earlycon)
871+
goto exit;
872+
873+
wrapper->to_core.path = devm_of_icc_get(dev, "qup-core");
874+
if (IS_ERR(wrapper->to_core.path))
875+
return PTR_ERR(wrapper->to_core.path);
876+
/*
877+
* Put minmal BW request on core clocks on behalf of early console.
878+
* The vote will be removed earlycon exit function.
879+
*
880+
* Note: We are putting vote on each QUP wrapper instead only to which
881+
* earlycon is connected because QUP core clock of different wrapper
882+
* share same voltage domain. If core1 is put to 0, then core2 will
883+
* also run at 0, if not voted. Default ICC vote will be removed ASA
884+
* we touch any of the core clock.
885+
* core1 = core2 = max(core1, core2)
886+
*/
887+
ret = icc_set_bw(wrapper->to_core.path, GENI_DEFAULT_BW,
888+
GENI_DEFAULT_BW);
889+
if (ret) {
890+
dev_err(&pdev->dev, "%s: ICC BW voting failed for core: %d\n",
891+
__func__, ret);
892+
return ret;
893+
}
894+
895+
if (of_get_compatible_child(pdev->dev.of_node, "qcom,geni-debug-uart"))
896+
earlycon_wrapper = wrapper;
897+
of_node_put(pdev->dev.of_node);
898+
#endif
899+
exit:
832900
dev_set_drvdata(dev, wrapper);
833901
dev_dbg(dev, "GENI SE Driver probed\n");
834902
return devm_of_platform_populate(dev);

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,12 @@ static inline void qcom_geni_serial_enable_early_read(struct geni_se *se,
11211121
struct console *con) { }
11221122
#endif
11231123

1124+
static int qcom_geni_serial_earlycon_exit(struct console *con)
1125+
{
1126+
geni_remove_earlycon_icc_vote();
1127+
return 0;
1128+
}
1129+
11241130
static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
11251131
const char *opt)
11261132
{
@@ -1166,6 +1172,7 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
11661172
writel(stop_bit_len, uport->membase + SE_UART_TX_STOP_BIT_LEN);
11671173

11681174
dev->con->write = qcom_geni_serial_earlycon_write;
1175+
dev->con->exit = qcom_geni_serial_earlycon_exit;
11691176
dev->con->setup = NULL;
11701177
qcom_geni_serial_enable_early_read(&se, dev->con);
11711178

include/linux/qcom-geni-se.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,5 +454,7 @@ int geni_icc_set_bw(struct geni_se *se);
454454
int geni_icc_enable(struct geni_se *se);
455455

456456
int geni_icc_disable(struct geni_se *se);
457+
458+
void geni_remove_earlycon_icc_vote(void);
457459
#endif
458460
#endif

0 commit comments

Comments
 (0)