1 // SPDX-License-Identifier: GPL-2.0+
5 * Clock synthesizer apis
7 * Copyright (C) 2016, Texas Instruments, Incorporated - http://www.ti.com/
12 #include <asm/arch/clk_synthesizer.h>
16 * clk_synthesizer_reg_read - Read register from synthesizer.
17 * dev: i2c bus device (not used if CONFIG_DM_I2C is not set)
18 * @addr: addr within the i2c device
19 * buf: Buffer to which value is to be read.
21 * For reading the register from this clock synthesizer, a command needs to
22 * be send along with enabling byte read more, and then read can happen.
23 * Returns 0 on success
25 static int clk_synthesizer_reg_read(struct udevice *dev, int addr, u8 *buf)
30 addr = addr | CLK_SYNTHESIZER_BYTE_MODE;
33 /* Send the command byte */
34 rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
36 printf("Failed to send command to clock synthesizer\n");
39 return i2c_read(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
41 /* Send the command byte */
42 rc = dm_i2c_reg_write(dev, addr, *buf);
44 printf("Failed to send command to clock synthesizer\n");
47 rc = dm_i2c_reg_read(dev, addr);
58 * clk_synthesizer_reg_write - Write a value to register in synthesizer.
59 * dev: i2c bus device (not used if CONFIG_DM_I2C is not set)
60 * @addr: addr within the i2c device
61 * val: Value to be written in the addr.
63 * Enable the byte read mode in the address and start the i2c transfer.
64 * Returns 0 on success
66 static int clk_synthesizer_reg_write(struct udevice *dev, int addr, u8 val)
71 /* Enable byte write */
72 cmd[0] = addr | CLK_SYNTHESIZER_BYTE_MODE;
76 rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, cmd, 2);
78 rc = dm_i2c_write(dev, addr, cmd, 2);
81 printf("Clock synthesizer reg write failed at addr = 0x%x\n",
87 * setup_clock_syntherizer - Program the clock synthesizer to get the desired
89 * @data: Data containing the desired output
91 * This is a PLL-based high performance synthesizer which gives 3 outputs
92 * as per the PLL_DIV and load capacitor programmed.
94 int setup_clock_synthesizer(struct clk_synth *data)
98 struct udevice *dev = NULL;
100 rc = i2c_probe(CLK_SYNTHESIZER_I2C_ADDR);
102 printf("i2c probe failed at address 0x%x\n",
103 CLK_SYNTHESIZER_I2C_ADDR);
107 rc = i2c_get_chip_for_busnum(0, CLK_SYNTHESIZER_I2C_ADDR, 1, &dev);
109 printf("failed to get device for synthesizer at address 0x%x\n",
110 CLK_SYNTHESIZER_I2C_ADDR);
114 rc = clk_synthesizer_reg_read(dev, CLK_SYNTHESIZER_ID_REG, &val);
118 /* Crystal Load capacitor selection */
119 rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_XCSEL,
123 rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_MUX_REG,
127 rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV2_REG,
131 rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV3_REG,