blackfin: add spi and i2c specific get clock functions
Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
This commit is contained in:
		
							parent
							
								
									bb0fad0ea0
								
							
						
					
					
						commit
						d6a320d5bb
					
				|  | @ -42,13 +42,6 @@ | ||||||
| 
 | 
 | ||||||
| # include <linux/types.h> | # include <linux/types.h> | ||||||
| 
 | 
 | ||||||
| extern u_long get_vco(void); |  | ||||||
| extern u_long get_cclk(void); |  | ||||||
| extern u_long get_sclk(void); |  | ||||||
| extern u_long get_sclk0(void); |  | ||||||
| extern u_long get_sclk1(void); |  | ||||||
| extern u_long get_dclk(void); |  | ||||||
| 
 |  | ||||||
| # define bfin_revid() (bfin_read_CHIPID() >> 28) | # define bfin_revid() (bfin_read_CHIPID() >> 28) | ||||||
| 
 | 
 | ||||||
| extern int bfin_os_log_check(void); | extern int bfin_os_log_check(void); | ||||||
|  |  | ||||||
|  | @ -68,10 +68,21 @@ static inline uint32_t early_get_uart_clk(void) | ||||||
| 	return uclk; | 	return uclk; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | extern u_long get_vco(void); | ||||||
|  | extern u_long get_cclk(void); | ||||||
|  | extern u_long get_sclk(void); | ||||||
|  | 
 | ||||||
| #ifdef CGU_DIV | #ifdef CGU_DIV | ||||||
|  | extern u_long get_sclk0(void); | ||||||
|  | extern u_long get_sclk1(void); | ||||||
|  | extern u_long get_dclk(void); | ||||||
| # define get_uart_clk get_sclk0 | # define get_uart_clk get_sclk0 | ||||||
|  | # define get_i2c_clk get_sclk0 | ||||||
|  | # define get_spi_clk get_sclk0 | ||||||
| #else | #else | ||||||
| # define get_uart_clk get_sclk | # define get_uart_clk get_sclk | ||||||
|  | # define get_i2c_clk get_sclk | ||||||
|  | # define get_spi_clk get_sclk | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ | ||||||
| #include <i2c.h> | #include <i2c.h> | ||||||
| 
 | 
 | ||||||
| #include <asm/blackfin.h> | #include <asm/blackfin.h> | ||||||
|  | #include <asm/clock.h> | ||||||
| #include <asm/mach-common/bits/twi.h> | #include <asm/mach-common/bits/twi.h> | ||||||
| 
 | 
 | ||||||
| /* Every register is 32bit aligned, but only 16bits in size */ | /* Every register is 32bit aligned, but only 16bits in size */ | ||||||
|  | @ -274,7 +275,7 @@ unsigned int i2c_get_bus_speed(void) | ||||||
|  */ |  */ | ||||||
| void i2c_init(int speed, int slaveaddr) | void i2c_init(int speed, int slaveaddr) | ||||||
| { | { | ||||||
| 	uint8_t prescale = ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F; | 	uint8_t prescale = ((get_i2c_clk() / 1000 / 1000 + 5) / 10) & 0x7F; | ||||||
| 
 | 
 | ||||||
| 	/* Set TWI internal clock as 10MHz */ | 	/* Set TWI internal clock as 10MHz */ | ||||||
| 	twi->control = prescale; | 	twi->control = prescale; | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ | ||||||
| #include <spi.h> | #include <spi.h> | ||||||
| 
 | 
 | ||||||
| #include <asm/blackfin.h> | #include <asm/blackfin.h> | ||||||
|  | #include <asm/clock.h> | ||||||
| #include <asm/gpio.h> | #include <asm/gpio.h> | ||||||
| #include <asm/portmux.h> | #include <asm/portmux.h> | ||||||
| #include <asm/mach-common/bits/spi.h> | #include <asm/mach-common/bits/spi.h> | ||||||
|  | @ -140,12 +141,12 @@ static const unsigned short cs_pins[][7] = { | ||||||
| void spi_set_speed(struct spi_slave *slave, uint hz) | void spi_set_speed(struct spi_slave *slave, uint hz) | ||||||
| { | { | ||||||
| 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave); | 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave); | ||||||
| 	ulong sclk; | 	ulong clk; | ||||||
| 	u32 baud; | 	u32 baud; | ||||||
| 
 | 
 | ||||||
| 	sclk = get_sclk(); | 	clk = get_spi_clk(); | ||||||
| 	/* baud should be rounded up */ | 	/* baud should be rounded up */ | ||||||
| 	baud = DIV_ROUND_UP(sclk, 2 * hz); | 	baud = DIV_ROUND_UP(clk, 2 * hz); | ||||||
| 	if (baud < 2) | 	if (baud < 2) | ||||||
| 		baud = 2; | 		baud = 2; | ||||||
| 	else if (baud > (u16)-1) | 	else if (baud > (u16)-1) | ||||||
|  |  | ||||||
|  | @ -22,6 +22,7 @@ | ||||||
| #include <spi.h> | #include <spi.h> | ||||||
| 
 | 
 | ||||||
| #include <asm/blackfin.h> | #include <asm/blackfin.h> | ||||||
|  | #include <asm/clock.h> | ||||||
| #include <asm/gpio.h> | #include <asm/gpio.h> | ||||||
| #include <asm/portmux.h> | #include <asm/portmux.h> | ||||||
| #include <asm/mach-common/bits/spi6xx.h> | #include <asm/mach-common/bits/spi6xx.h> | ||||||
|  | @ -135,11 +136,11 @@ static const unsigned short cs_pins[][7] = { | ||||||
| void spi_set_speed(struct spi_slave *slave, uint hz) | void spi_set_speed(struct spi_slave *slave, uint hz) | ||||||
| { | { | ||||||
| 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave); | 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave); | ||||||
| 	ulong sclk; | 	ulong clk; | ||||||
| 	u32 clock; | 	u32 clock; | ||||||
| 
 | 
 | ||||||
| 	sclk = get_sclk1(); | 	clk = get_spi_clk(); | ||||||
| 	clock = sclk / hz; | 	clock = clk / hz; | ||||||
| 	if (clock) | 	if (clock) | ||||||
| 		clock--; | 		clock--; | ||||||
| 	bss->clock = clock; | 	bss->clock = clock; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue