a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is free software; you can redistribute it and/or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * modify it under the terms of the GNU General Public License as
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * published by the Free Software Foundation; either version 2 of the
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * License, or any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is distributed in the hope that it will be useful, but
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * WITHOUT ANY WARRANTY; without even the implied warranty of
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * General Public License for more details.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * You should have received a copy of the GNU General Public License
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * along with this program; if not, write to the Free Software
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Three-wire serial devices
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Read data from three-wire device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v nvs NVS device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v address Address from which to read
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v data Data buffer
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v len Length of data buffer
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncint threewire_read ( struct nvs_device *nvs, unsigned int address,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p reading %zd bytes at %04x\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = bus->rw ( bus, device, THREEWIRE_READ, address,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Write data to three-wire device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v nvs NVS device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v address Address from which to read
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v data Data buffer
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v len Length of data buffer
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncint threewire_write ( struct nvs_device *nvs, unsigned int address,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p writing %zd bytes at %04x\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Enable device for writing */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p could not enable writing: %s\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Write data */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = bus->rw ( bus, device, THREEWIRE_WRITE, address,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Our model of an SPI bus doesn't provide a mechanism for
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * "assert CS, wait for MISO to become high, so just wait for
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * long enough to ensure that the write has completed.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Autodetect device address length
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v device SPI device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncint threewire_detect_address_len ( struct spi_device *device ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p autodetecting address length\n", device );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p could not autodetect address "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( device, "3wire %p autodetected address length %d\n",