Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 1 | /* |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in |
| 11 | * the documentation and/or other materials provided with the |
| 12 | * distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 17 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 18 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 20 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 21 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 24 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 25 | * SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include <sys/types.h> |
| 29 | #include <platform/timer.h> |
| 30 | #include <dev/gpio.h> |
| 31 | |
| 32 | void spi_bit_bang_write(uint8_t spi_sclk, uint8_t spi_mosi, uint8_t dc, uint8_t data) |
| 33 | { |
| 34 | uint8_t bit; |
| 35 | uint8_t bnum; |
| 36 | |
| 37 | gpio_set(spi_sclk, 0); /* clk low */ |
| 38 | /* dc: 0 for command, 1 for parameter */ |
| 39 | gpio_set(spi_mosi, dc); |
| 40 | udelay(1); /* at least 20 ns */ |
| 41 | gpio_set(spi_sclk, 1); /* clk high */ |
| 42 | udelay(1); /* at least 20 ns */ |
| 43 | bnum = 8; /* 8 data bits */ |
| 44 | bit = 0x80; |
| 45 | while(bnum){ |
| 46 | gpio_set(spi_sclk, 0); /* clk low */ |
| 47 | if (data & bit) |
| 48 | gpio_set(spi_mosi, 1); |
| 49 | else |
| 50 | gpio_set(spi_mosi, 0); |
| 51 | udelay(1); |
| 52 | gpio_set(spi_sclk, 1); /* clk high */ |
| 53 | udelay(1); |
| 54 | bit >>= 1; |
| 55 | bnum--; |
| 56 | } |
| 57 | } |