blob: afcd00bd514bb268c63c3479742be41a0ef4091c [file] [log] [blame]
Reinhard Meyer82a09792010-10-30 23:09:58 +00001/*
2 * Copyright (C) 2010
3 * Reinhard Meyer, EMK Elektronik, reinhard.meyer@emk-elektronik.de
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Reinhard Meyer82a09792010-10-30 23:09:58 +00006 */
7
8#include <common.h>
9#include <asm/arch/hardware.h>
10#include <asm/arch/at91_spi.h>
11#include <asm/arch/gpio.h>
12#include <spi.h>
13
14static const struct {
15 u32 port;
16 u32 bit;
17} cs_to_portbit[2][4] = {
18 {{AT91_PIO_PORTA, 3}, {AT91_PIO_PORTC, 11},
19 {AT91_PIO_PORTC, 16}, {AT91_PIO_PORTC, 17} },
20 {{AT91_PIO_PORTB, 3}, {AT91_PIO_PORTC, 5},
21 {AT91_PIO_PORTC, 4}, {AT91_PIO_PORTC, 3} }
22};
23
24int spi_cs_is_valid(unsigned int bus, unsigned int cs)
25{
26 debug("spi_cs_is_valid: bus=%u cs=%u\n", bus, cs);
27 if (bus < 2 && cs < 4)
28 return 1;
29 return 0;
30}
31
32void spi_cs_activate(struct spi_slave *slave)
33{
34 debug("spi_cs_activate: bus=%u cs=%u\n", slave->bus, slave->cs);
35 at91_set_pio_output(cs_to_portbit[slave->bus][slave->cs].port,
36 cs_to_portbit[slave->bus][slave->cs].bit, 0);
37}
38
39void spi_cs_deactivate(struct spi_slave *slave)
40{
41 debug("spi_cs_deactivate: bus=%u cs=%u\n", slave->bus, slave->cs);
42 at91_set_pio_output(cs_to_portbit[slave->bus][slave->cs].port,
43 cs_to_portbit[slave->bus][slave->cs].bit, 1);
44}