Deleted Added
full compact
bcm2835_bsc.c (256959) bcm2835_bsc.c (261078)
1/*-
2 * Copyright (c) 2001 Tsubai Masanari.
3 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
4 * Copyright (c) 2013 Luiz Otavio O Souza <loos@freebsd.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Tsubai Masanari.
3 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
4 * Copyright (c) 2013 Luiz Otavio O Souza <loos@freebsd.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c 256959 2013-10-23 12:29:39Z loos $");
30__FBSDID("$FreeBSD: stable/10/sys/arm/broadcom/bcm2835/bcm2835_bsc.c 261078 2014-01-23 12:32:30Z loos $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/lock.h>
36#include <sys/module.h>
37#include <sys/mutex.h>
38#include <sys/bus.h>

--- 190 unchanged lines hidden (view full) ---

229
230 return (BUS_PROBE_DEFAULT);
231}
232
233static int
234bcm_bsc_attach(device_t dev)
235{
236 struct bcm_bsc_softc *sc;
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/lock.h>
36#include <sys/module.h>
37#include <sys/mutex.h>
38#include <sys/bus.h>

--- 190 unchanged lines hidden (view full) ---

229
230 return (BUS_PROBE_DEFAULT);
231}
232
233static int
234bcm_bsc_attach(device_t dev)
235{
236 struct bcm_bsc_softc *sc;
237 unsigned long start;
237 device_t gpio;
238 device_t gpio;
238 int rid;
239 int i, rid;
239
240
240 if (device_get_unit(dev) > 1) {
241 device_printf(dev, "only bsc0 and bsc1 are supported\n");
241 sc = device_get_softc(dev);
242 sc->sc_dev = dev;
243
244 rid = 0;
245 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
246 RF_ACTIVE);
247 if (!sc->sc_mem_res) {
248 device_printf(dev, "cannot allocate memory window\n");
242 return (ENXIO);
243 }
244
249 return (ENXIO);
250 }
251
245 sc = device_get_softc(dev);
246 sc->sc_dev = dev;
252 sc->sc_bst = rman_get_bustag(sc->sc_mem_res);
253 sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res);
247
254
255 /* Check the unit we are attaching by its base address. */
256 start = rman_get_start(sc->sc_mem_res);
257 for (i = 0; i < nitems(bcm_bsc_pins); i++) {
258 if (bcm_bsc_pins[i].start == start)
259 break;
260 }
261 if (i == nitems(bcm_bsc_pins)) {
262 device_printf(dev, "only bsc0 and bsc1 are supported\n");
263 return (ENXIO);
264 }
265
248 /*
249 * Configure the GPIO pins to ALT0 function to enable BSC control
250 * over the pins.
251 */
252 gpio = devclass_get_device(devclass_find("gpio"), 0);
253 if (!gpio) {
254 device_printf(dev, "cannot find gpio0\n");
255 return (ENXIO);
256 }
266 /*
267 * Configure the GPIO pins to ALT0 function to enable BSC control
268 * over the pins.
269 */
270 gpio = devclass_get_device(devclass_find("gpio"), 0);
271 if (!gpio) {
272 device_printf(dev, "cannot find gpio0\n");
273 return (ENXIO);
274 }
257 bcm_gpio_set_alternate(gpio, bcm_bsc_pins[device_get_unit(dev)].sda,
258 BCM_GPIO_ALT0);
259 bcm_gpio_set_alternate(gpio, bcm_bsc_pins[device_get_unit(dev)].scl,
260 BCM_GPIO_ALT0);
275 bcm_gpio_set_alternate(gpio, bcm_bsc_pins[i].sda, BCM_GPIO_ALT0);
276 bcm_gpio_set_alternate(gpio, bcm_bsc_pins[i].scl, BCM_GPIO_ALT0);
261
262 rid = 0;
277
278 rid = 0;
263 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
264 RF_ACTIVE);
265 if (!sc->sc_mem_res) {
266 device_printf(dev, "cannot allocate memory window\n");
267 return (ENXIO);
268 }
269
270 sc->sc_bst = rman_get_bustag(sc->sc_mem_res);
271 sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res);
272
273 rid = 0;
274 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
275 RF_ACTIVE | RF_SHAREABLE);
276 if (!sc->sc_irq_res) {
277 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
278 device_printf(dev, "cannot allocate interrupt\n");
279 return (ENXIO);
280 }
281

--- 112 unchanged lines hidden (view full) ---

394
395 /* Clear the FIFO and the pending interrupts. */
396 bcm_bsc_reset(sc);
397
398 err = 0;
399 for (i = 0; i < nmsgs; i++) {
400
401 /* Write the slave address. */
279 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
280 RF_ACTIVE | RF_SHAREABLE);
281 if (!sc->sc_irq_res) {
282 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
283 device_printf(dev, "cannot allocate interrupt\n");
284 return (ENXIO);
285 }
286

--- 112 unchanged lines hidden (view full) ---

399
400 /* Clear the FIFO and the pending interrupts. */
401 bcm_bsc_reset(sc);
402
403 err = 0;
404 for (i = 0; i < nmsgs; i++) {
405
406 /* Write the slave address. */
402 BCM_BSC_WRITE(sc, BCM_BSC_SLAVE, (msgs[i].slave >> 1) & 0x7f);
407 BCM_BSC_WRITE(sc, BCM_BSC_SLAVE, msgs[i].slave);
403
404 /* Write the data length. */
405 BCM_BSC_WRITE(sc, BCM_BSC_DLEN, msgs[i].len);
406
407 sc->sc_data = msgs[i].buf;
408 sc->sc_resid = msgs[i].len;
409 if ((msgs[i].flags & IIC_M_RD) == 0) {
410 /* Fill up the TX FIFO. */

--- 75 unchanged lines hidden ---
408
409 /* Write the data length. */
410 BCM_BSC_WRITE(sc, BCM_BSC_DLEN, msgs[i].len);
411
412 sc->sc_data = msgs[i].buf;
413 sc->sc_resid = msgs[i].len;
414 if ((msgs[i].flags & IIC_M_RD) == 0) {
415 /* Fill up the TX FIFO. */

--- 75 unchanged lines hidden ---