netwalker_spi.c revision 1.1.10.2 1 1.1.10.2 tls /* $NetBSD: netwalker_spi.c,v 1.1.10.2 2014/08/20 00:02:55 tls Exp $ */
2 1.1.10.2 tls
3 1.1.10.2 tls /*-
4 1.1.10.2 tls * Copyright (c) 2009 Genetec Corporation. All rights reserved.
5 1.1.10.2 tls * Written by Hashimoto Kenichi for Genetec Corporation.
6 1.1.10.2 tls *
7 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
8 1.1.10.2 tls * modification, are permitted provided that the following conditions
9 1.1.10.2 tls * are met:
10 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
11 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
12 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
14 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
15 1.1.10.2 tls *
16 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 1.1.10.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1.10.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1.10.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 1.1.10.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.10.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.10.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.10.2 tls * SUCH DAMAGE.
27 1.1.10.2 tls */
28 1.1.10.2 tls
29 1.1.10.2 tls #include <sys/cdefs.h>
30 1.1.10.2 tls __KERNEL_RCSID(0, "$NetBSD: netwalker_spi.c,v 1.1.10.2 2014/08/20 00:02:55 tls Exp $");
31 1.1.10.2 tls
32 1.1.10.2 tls #include "opt_imxspi.h"
33 1.1.10.2 tls
34 1.1.10.2 tls #include <sys/param.h>
35 1.1.10.2 tls #include <sys/bus.h>
36 1.1.10.2 tls #include <sys/device.h>
37 1.1.10.2 tls
38 1.1.10.2 tls #include <arm/imx/imx51reg.h>
39 1.1.10.2 tls #include <arm/imx/imx51var.h>
40 1.1.10.2 tls #include <arm/imx/imx51_ccmvar.h>
41 1.1.10.2 tls #include <arm/imx/imx51_ccmreg.h>
42 1.1.10.2 tls #include <arm/imx/imx51_iomuxreg.h>
43 1.1.10.2 tls #include <arm/imx/imxgpiovar.h>
44 1.1.10.2 tls #include <arm/imx/imxspivar.h>
45 1.1.10.2 tls
46 1.1.10.2 tls struct imx51spi_softc {
47 1.1.10.2 tls struct imxspi_softc sc_spi;
48 1.1.10.2 tls struct spi_chipset_tag sc_tag;
49 1.1.10.2 tls };
50 1.1.10.2 tls
51 1.1.10.2 tls CFATTACH_DECL_NEW(spi_netwalker, sizeof(struct imx51spi_softc),
52 1.1.10.2 tls imxspi_match, imxspi_attach, NULL, NULL);
53 1.1.10.2 tls
54 1.1.10.2 tls static int
55 1.1.10.2 tls imxspi_cs_enable(void *arg, int slave)
56 1.1.10.2 tls {
57 1.1.10.2 tls switch (slave) {
58 1.1.10.2 tls case 0:
59 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 24), 0);
60 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 24), GPIO_DIR_OUT);
61 1.1.10.2 tls break;
62 1.1.10.2 tls case 1:
63 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 25), 0);
64 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 25), GPIO_DIR_OUT);
65 1.1.10.2 tls break;
66 1.1.10.2 tls case 2:
67 1.1.10.2 tls gpio_data_write(GPIO_NO(3, 0), 0);
68 1.1.10.2 tls gpio_set_direction(GPIO_NO(3, 0), GPIO_DIR_OUT);
69 1.1.10.2 tls break;
70 1.1.10.2 tls }
71 1.1.10.2 tls
72 1.1.10.2 tls return 0;
73 1.1.10.2 tls }
74 1.1.10.2 tls
75 1.1.10.2 tls static int
76 1.1.10.2 tls imxspi_cs_disable(void *arg, int slave)
77 1.1.10.2 tls {
78 1.1.10.2 tls switch (slave) {
79 1.1.10.2 tls case 0:
80 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 24), 1);
81 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 24), GPIO_DIR_IN);
82 1.1.10.2 tls break;
83 1.1.10.2 tls case 1:
84 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 25), 1);
85 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 25), GPIO_DIR_IN);
86 1.1.10.2 tls break;
87 1.1.10.2 tls case 2:
88 1.1.10.2 tls gpio_data_write(GPIO_NO(3, 0), 1);
89 1.1.10.2 tls gpio_set_direction(GPIO_NO(3, 0), GPIO_DIR_IN);
90 1.1.10.2 tls break;
91 1.1.10.2 tls }
92 1.1.10.2 tls
93 1.1.10.2 tls return 0;
94 1.1.10.2 tls }
95 1.1.10.2 tls
96 1.1.10.2 tls int
97 1.1.10.2 tls imxspi_match(device_t parent, cfdata_t cf, void *aux)
98 1.1.10.2 tls {
99 1.1.10.2 tls if (strcmp(cf->cf_name, "imxspi") == 0)
100 1.1.10.2 tls return 1;
101 1.1.10.2 tls if (cf->cf_unit != 0)
102 1.1.10.2 tls return 1;
103 1.1.10.2 tls
104 1.1.10.2 tls return 0;
105 1.1.10.2 tls }
106 1.1.10.2 tls
107 1.1.10.2 tls void
108 1.1.10.2 tls imxspi_attach(device_t parent, device_t self, void *aux)
109 1.1.10.2 tls {
110 1.1.10.2 tls struct imx51spi_softc *sc = device_private(self);
111 1.1.10.2 tls struct axi_attach_args *aa = aux;
112 1.1.10.2 tls struct imxspi_attach_args saa;
113 1.1.10.2 tls int cf_flags = device_cfdata(self)->cf_flags;
114 1.1.10.2 tls
115 1.1.10.2 tls sc->sc_tag.cookie = sc;
116 1.1.10.2 tls
117 1.1.10.2 tls if (device_cfdata(self)->cf_unit == 0) {
118 1.1.10.2 tls /* CS 0 GPIO setting */
119 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 24), 1);
120 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 24), GPIO_DIR_IN);
121 1.1.10.2 tls
122 1.1.10.2 tls /* CS 1 GPIO setting */
123 1.1.10.2 tls gpio_data_write(GPIO_NO(4, 25), 1);
124 1.1.10.2 tls gpio_set_direction(GPIO_NO(4, 25), GPIO_DIR_IN);
125 1.1.10.2 tls
126 1.1.10.2 tls /* CS 2 */
127 1.1.10.2 tls /* OJ6SH-T25 Shutdown */
128 1.1.10.2 tls gpio_data_write(GPIO_NO(3, 14), 0);
129 1.1.10.2 tls gpio_set_direction(GPIO_NO(3, 14), GPIO_DIR_OUT);
130 1.1.10.2 tls
131 1.1.10.2 tls /* CS 2 GPIO setting */
132 1.1.10.2 tls gpio_data_write(GPIO_NO(3, 0), 1);
133 1.1.10.2 tls gpio_set_direction(GPIO_NO(3, 0), GPIO_DIR_IN);
134 1.1.10.2 tls
135 1.1.10.2 tls sc->sc_tag.spi_cs_enable = imxspi_cs_enable;
136 1.1.10.2 tls sc->sc_tag.spi_cs_disable = imxspi_cs_disable;
137 1.1.10.2 tls }
138 1.1.10.2 tls
139 1.1.10.2 tls saa.saa_iot = aa->aa_iot;
140 1.1.10.2 tls saa.saa_addr = aa->aa_addr;
141 1.1.10.2 tls saa.saa_size = aa->aa_size;
142 1.1.10.2 tls saa.saa_irq = aa->aa_irq;
143 1.1.10.2 tls saa.saa_enhanced = cf_flags;
144 1.1.10.2 tls
145 1.1.10.2 tls saa.saa_nslaves = IMXSPINSLAVES;
146 1.1.10.2 tls saa.saa_freq = imx51_get_clock(IMX51CLK_CSPI_CLK_ROOT);
147 1.1.10.2 tls saa.saa_tag = &sc->sc_tag;
148 1.1.10.2 tls
149 1.1.10.2 tls sc->sc_spi.sc_dev = self;
150 1.1.10.2 tls
151 1.1.10.2 tls imxspi_attach_common(parent, &sc->sc_spi, &saa);
152 1.1.10.2 tls }
153