Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007-2012 |
| 4 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 5 | * Tom Cubie <tangliang@allwinnertech.com> |
| 6 | * |
| 7 | * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net> |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/clock.h> |
Hans de Goede | 7969677 | 2016-03-16 20:57:28 +0100 | [diff] [blame] | 12 | #include <asm/arch/prcm.h> |
Philipp Tomsich | 3015e04 | 2016-10-28 18:21:29 +0800 | [diff] [blame] | 13 | #include <asm/arch/gtbus.h> |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 14 | #include <asm/arch/sys_proto.h> |
| 15 | |
Chen-Yu Tsai | 6daddfe | 2016-01-06 15:13:07 +0800 | [diff] [blame] | 16 | __weak void clock_init_sec(void) |
| 17 | { |
| 18 | } |
| 19 | |
Philipp Tomsich | 3015e04 | 2016-10-28 18:21:29 +0800 | [diff] [blame] | 20 | __weak void gtbus_init(void) |
| 21 | { |
| 22 | } |
| 23 | |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 24 | int clock_init(void) |
| 25 | { |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 26 | clock_init_safe(); |
Philipp Tomsich | 3015e04 | 2016-10-28 18:21:29 +0800 | [diff] [blame] | 27 | gtbus_init(); |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 28 | clock_init_uart(); |
Chen-Yu Tsai | 6daddfe | 2016-01-06 15:13:07 +0800 | [diff] [blame] | 29 | clock_init_sec(); |
Ian Campbell | 49aeca3 | 2014-05-05 11:52:23 +0100 | [diff] [blame] | 30 | |
| 31 | return 0; |
| 32 | } |
Hans de Goede | 7969677 | 2016-03-16 20:57:28 +0100 | [diff] [blame] | 33 | |
| 34 | /* These functions are shared between various SoCs so put them here. */ |
Icenowy Zheng | 8f2d1c0 | 2022-01-29 10:23:07 -0500 | [diff] [blame] | 35 | #if defined CONFIG_SUNXI_GEN_SUN6I && !defined CONFIG_MACH_SUN9I && \ |
| 36 | !defined CONFIG_MACH_SUNIV |
Hans de Goede | 7969677 | 2016-03-16 20:57:28 +0100 | [diff] [blame] | 37 | int clock_twi_onoff(int port, int state) |
| 38 | { |
| 39 | struct sunxi_ccm_reg *const ccm = |
| 40 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 41 | |
| 42 | if (port == 5) { |
| 43 | if (state) |
| 44 | prcm_apb0_enable( |
| 45 | PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C); |
| 46 | else |
| 47 | prcm_apb0_disable( |
| 48 | PRCM_APB0_GATE_PIO | PRCM_APB0_GATE_I2C); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | /* set the apb clock gate and reset for twi */ |
| 53 | if (state) { |
| 54 | setbits_le32(&ccm->apb2_gate, |
| 55 | CLK_GATE_OPEN << (APB2_GATE_TWI_SHIFT + port)); |
| 56 | setbits_le32(&ccm->apb2_reset_cfg, |
| 57 | 1 << (APB2_RESET_TWI_SHIFT + port)); |
| 58 | } else { |
| 59 | clrbits_le32(&ccm->apb2_reset_cfg, |
| 60 | 1 << (APB2_RESET_TWI_SHIFT + port)); |
| 61 | clrbits_le32(&ccm->apb2_gate, |
| 62 | CLK_GATE_OPEN << (APB2_GATE_TWI_SHIFT + port)); |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | #endif |