3 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * Each transfer is performed as:
29 * 1. chip-select active
30 * 2. send 8-bit start code
32 * 4. chip-select inactive
34 static int send_word(struct s6e63d6 *data, u8 rs, u16 word)
37 * The start byte looks like (binary):
39 * RS is 0 for index or 1 for data, and R/W is 0 for write.
41 u32 buf8 = 0x70 | data->id | (rs & 2);
42 u32 buf16 = cpu_to_le16(word);
46 err = spi_xfer(data->slave, 8, &buf8, &buf_in, SPI_XFER_BEGIN);
50 return spi_xfer(data->slave, 16, &buf16, &buf_in, SPI_XFER_END);
53 /* Index and param differ in Register Select bit */
54 int s6e63d6_index(struct s6e63d6 *data, u8 idx)
56 return send_word(data, 0, idx);
59 int s6e63d6_param(struct s6e63d6 *data, u16 param)
61 return send_word(data, 2, param);
64 int s6e63d6_init(struct s6e63d6 *data)
66 if (data->id != 0 && data->id != 4) {
67 printf("s6e63d6: invalid ID %u\n", data->id);
71 data->slave = spi_setup_slave(data->bus, data->cs, 100000, SPI_MODE_3);