123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- /*****************************************************************************
- Copyright(c) 2013 FCI Inc. All Rights Reserved
- File name : fc8080_ppi.c
- Description : EBI2LCD interface header file
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- History :
- ----------------------------------------------------------------------
- *******************************************************************************/
- #include "linux/io.h"
- #include <linux/mutex.h>
- #include "fci_types.h"
- #include "fc8080_regs.h"
- #include "fc8080_ppi.h"
- #include "fci_oal.h"
- #include "tdmb.h"
- #define BBM_BASE_ADDR (0)
- #define PPI_BMODE 0x00
- #define PPI_WMODE 0x04
- #define PPI_LMODE 0x08
- #define PPI_RD_THRESH 0x30
- #define PPI_RD_REG 0x20
- #define PPI_READ 0x40
- #define PPI_WRITE 0x00
- #define PPI_AINC 0x80
- static DEFINE_MUTEX(lock);
- u32 base_address;
- #define FC8080_PPI_REG_OUT(x) writeb(x, (void __iomem *)base_address)
- #define FC8080_PPI_REG_IN readb((void __iomem *)base_address)
- s32 fc8080_ppi_init(HANDLE handle, u16 param1, u16 param2)
- {
- base_address = param2;
- base_address <<= 16;
- base_address |= param1;
- DPRINTK("%s : 0x%p\n", __func__, (void __iomem *)base_address);
- return BBM_OK;
- }
- s32 fc8080_ppi_byteread(HANDLE handle, u16 addr, u8 *data)
- {
- u16 length = 1;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- *data = FC8080_PPI_REG_IN << 4;
- *data |= (FC8080_PPI_REG_IN & 0x0f);
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_wordread(HANDLE handle, u16 addr, u16 *data)
- {
- u16 length = 2;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- *data = (FC8080_PPI_REG_IN & 0x0f) << 4;
- *data |= FC8080_PPI_REG_IN & 0x0f;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 12;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 8;
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_longread(HANDLE handle, u16 addr, u32 *data)
- {
- u16 length = 4;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- *data = (FC8080_PPI_REG_IN & 0x0f) << 4;
- *data |= FC8080_PPI_REG_IN & 0x0f;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 12;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 8;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 20;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 16;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 28;
- *data |= (FC8080_PPI_REG_IN & 0x0f) << 24;
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_bulkread(HANDLE handle, u16 addr, u8 *data, u16 length)
- {
- s32 i, j;
- u8 command;
- u16 x, y;
- x = length / 255;
- y = length % 255;
- mutex_lock(&lock);
- for (i = 0; i < x; i++, addr += 255) {
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT((255 >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(255 & 0x0f);
- for (j = 0; j < 255; j++) {
- data[i * 255 + j] =
- (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
- data[i * 255 + j] |=
- (u8) (FC8080_PPI_REG_IN & 0x0f);
- }
- }
- if (y) {
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT((y >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(y & 0x0f);
- for (j = 0; j < y; j++) {
- data[x * 255 + j] =
- (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
- data[x * 255 + j] |=
- (u8) (FC8080_PPI_REG_IN & 0x0f);
- }
- }
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_bytewrite(HANDLE handle, u16 addr, u8 data)
- {
- u16 length = 1;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_WRITE);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- FC8080_PPI_REG_OUT(data >> 4);
- FC8080_PPI_REG_OUT(data);
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_wordwrite(HANDLE handle, u16 addr, u16 data)
- {
- u16 length = 2;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_WRITE | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- FC8080_PPI_REG_OUT(data >> 4);
- FC8080_PPI_REG_OUT(data);
- FC8080_PPI_REG_OUT(data >> 12);
- FC8080_PPI_REG_OUT(data >> 8);
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_longwrite(HANDLE handle, u16 addr, u32 data)
- {
- u16 length = 4;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_WRITE | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(length >> 4);
- FC8080_PPI_REG_OUT(length);
- FC8080_PPI_REG_OUT(data >> 4);
- FC8080_PPI_REG_OUT(data);
- FC8080_PPI_REG_OUT(data >> 12);
- FC8080_PPI_REG_OUT(data >> 8);
- FC8080_PPI_REG_OUT(data >> 20);
- FC8080_PPI_REG_OUT(data >> 16);
- FC8080_PPI_REG_OUT(data >> 28);
- FC8080_PPI_REG_OUT(data >> 24);
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_bulkwrite(HANDLE handle, u16 addr, u8 *data, u16 length)
- {
- s32 i, j;
- u8 command;
- u16 x, y;
- x = length / 255;
- y = length % 255;
- mutex_lock(&lock);
- for (i = 0; i < x; i++, addr += 255) {
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_WRITE | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT((255 >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(255 & 0x0f);
- for (j = 0; j < 255; j++) {
- FC8080_PPI_REG_OUT((data[i * 255 + j] >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(data[i * 255 + j] & 0x0f);
- }
- }
- if (y) {
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_WRITE | PPI_AINC);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT((y >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(y & 0x0f);
- for (j = 0; j < y; j++) {
- FC8080_PPI_REG_OUT((data[x * 255 + j] >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(data[x * 255 + j] & 0x0f);
- }
- }
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_dataread(HANDLE handle, u16 addr, u8 *data, u32 length)
- {
- s32 i;
- u8 command;
- mutex_lock(&lock);
- FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
- FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
- FC8080_PPI_REG_OUT(addr & 0x0f);
- command = (u8) (PPI_READ | PPI_RD_THRESH);
- FC8080_PPI_REG_OUT(command >> 4);
- FC8080_PPI_REG_OUT(command);
- FC8080_PPI_REG_OUT(0);
- FC8080_PPI_REG_OUT(0);
- for (i = 0; i < length; i++) {
- data[i] = (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
- data[i] |= (u8) (FC8080_PPI_REG_IN & 0x0f);
- }
- mutex_unlock(&lock);
- return BBM_OK;
- }
- s32 fc8080_ppi_deinit(HANDLE handle)
- {
- base_address = 0;
- return BBM_OK;
- }
|