Path: blob/master/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
10818 views
/*1* Private header for the MPC52xx processor BestComm driver2*3* By private, we mean that driver should not use it directly. It's meant4* to be used by the BestComm engine driver itself and by the intermediate5* layer between the core and the drivers.6*7* Copyright (C) 2006 Sylvain Munaut <[email protected]>8* Copyright (C) 2005 Varma Electronics Oy,9* ( by Andrey Volkov <[email protected]> )10* Copyright (C) 2003-2004 MontaVista, Software, Inc.11* ( by Dale Farnsworth <[email protected]> )12*13* This file is licensed under the terms of the GNU General Public License14* version 2. This program is licensed "as is" without any warranty of any15* kind, whether express or implied.16*/1718#ifndef __BESTCOMM_PRIV_H__19#define __BESTCOMM_PRIV_H__2021#include <linux/spinlock.h>22#include <linux/of.h>23#include <asm/io.h>24#include <asm/mpc52xx.h>2526#include "sram.h"272829/* ======================================================================== */30/* Engine related stuff */31/* ======================================================================== */3233/* Zones sizes and needed alignments */34#define BCOM_MAX_TASKS 1635#define BCOM_MAX_VAR 2436#define BCOM_MAX_INC 837#define BCOM_MAX_FDT 6438#define BCOM_MAX_CTX 2039#define BCOM_CTX_SIZE (BCOM_MAX_CTX * sizeof(u32))40#define BCOM_CTX_ALIGN 0x10041#define BCOM_VAR_SIZE (BCOM_MAX_VAR * sizeof(u32))42#define BCOM_INC_SIZE (BCOM_MAX_INC * sizeof(u32))43#define BCOM_VAR_ALIGN 0x8044#define BCOM_FDT_SIZE (BCOM_MAX_FDT * sizeof(u32))45#define BCOM_FDT_ALIGN 0x1004647/**48* struct bcom_tdt - Task Descriptor Table Entry49*50*/51struct bcom_tdt {52u32 start;53u32 stop;54u32 var;55u32 fdt;56u32 exec_status; /* used internally by BestComm engine */57u32 mvtp; /* used internally by BestComm engine */58u32 context;59u32 litbase;60};6162/**63* struct bcom_engine64*65* This holds all info needed globaly to handle the engine66*/67struct bcom_engine {68struct device_node *ofnode;69struct mpc52xx_sdma __iomem *regs;70phys_addr_t regs_base;7172struct bcom_tdt *tdt;73u32 *ctx;74u32 *var;75u32 *fdt;7677spinlock_t lock;78};7980extern struct bcom_engine *bcom_eng;818283/* ======================================================================== */84/* Tasks related stuff */85/* ======================================================================== */8687/* Tasks image header */88#define BCOM_TASK_MAGIC 0x4243544B /* 'BCTK' */8990struct bcom_task_header {91u32 magic;92u8 desc_size; /* the size fields */93u8 var_size; /* are given in number */94u8 inc_size; /* of 32-bits words */95u8 first_var;96u8 reserved[8];97};9899/* Descriptors structure & co */100#define BCOM_DESC_NOP 0x000001f8101#define BCOM_LCD_MASK 0x80000000102#define BCOM_DRD_EXTENDED 0x40000000103#define BCOM_DRD_INITIATOR_SHIFT 21104105/* Tasks pragma */106#define BCOM_PRAGMA_BIT_RSV 7 /* reserved pragma bit */107#define BCOM_PRAGMA_BIT_PRECISE_INC 6 /* increment 0=when possible, */108/* 1=iter end */109#define BCOM_PRAGMA_BIT_RST_ERROR_NO 5 /* don't reset errors on */110/* task enable */111#define BCOM_PRAGMA_BIT_PACK 4 /* pack data enable */112#define BCOM_PRAGMA_BIT_INTEGER 3 /* data alignment */113/* 0=frac(msb), 1=int(lsb) */114#define BCOM_PRAGMA_BIT_SPECREAD 2 /* XLB speculative read */115#define BCOM_PRAGMA_BIT_CW 1 /* write line buffer enable */116#define BCOM_PRAGMA_BIT_RL 0 /* read line buffer enable */117118/* Looks like XLB speculative read generates XLB errors when a buffer119* is at the end of the physical memory. i.e. when accessing the120* lasts words, the engine tries to prefetch the next but there is no121* next ...122*/123#define BCOM_STD_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \124(0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \125(0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \126(0 << BCOM_PRAGMA_BIT_PACK) | \127(0 << BCOM_PRAGMA_BIT_INTEGER) | \128(0 << BCOM_PRAGMA_BIT_SPECREAD) | \129(1 << BCOM_PRAGMA_BIT_CW) | \130(1 << BCOM_PRAGMA_BIT_RL))131132#define BCOM_PCI_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \133(0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \134(0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \135(0 << BCOM_PRAGMA_BIT_PACK) | \136(1 << BCOM_PRAGMA_BIT_INTEGER) | \137(0 << BCOM_PRAGMA_BIT_SPECREAD) | \138(1 << BCOM_PRAGMA_BIT_CW) | \139(1 << BCOM_PRAGMA_BIT_RL))140141#define BCOM_ATA_PRAGMA BCOM_STD_PRAGMA142#define BCOM_CRC16_DP_0_PRAGMA BCOM_STD_PRAGMA143#define BCOM_CRC16_DP_1_PRAGMA BCOM_STD_PRAGMA144#define BCOM_FEC_RX_BD_PRAGMA BCOM_STD_PRAGMA145#define BCOM_FEC_TX_BD_PRAGMA BCOM_STD_PRAGMA146#define BCOM_GEN_DP_0_PRAGMA BCOM_STD_PRAGMA147#define BCOM_GEN_DP_1_PRAGMA BCOM_STD_PRAGMA148#define BCOM_GEN_DP_2_PRAGMA BCOM_STD_PRAGMA149#define BCOM_GEN_DP_3_PRAGMA BCOM_STD_PRAGMA150#define BCOM_GEN_DP_BD_0_PRAGMA BCOM_STD_PRAGMA151#define BCOM_GEN_DP_BD_1_PRAGMA BCOM_STD_PRAGMA152#define BCOM_GEN_RX_BD_PRAGMA BCOM_STD_PRAGMA153#define BCOM_GEN_TX_BD_PRAGMA BCOM_STD_PRAGMA154#define BCOM_GEN_LPC_PRAGMA BCOM_STD_PRAGMA155#define BCOM_PCI_RX_PRAGMA BCOM_PCI_PRAGMA156#define BCOM_PCI_TX_PRAGMA BCOM_PCI_PRAGMA157158/* Initiators number */159#define BCOM_INITIATOR_ALWAYS 0160#define BCOM_INITIATOR_SCTMR_0 1161#define BCOM_INITIATOR_SCTMR_1 2162#define BCOM_INITIATOR_FEC_RX 3163#define BCOM_INITIATOR_FEC_TX 4164#define BCOM_INITIATOR_ATA_RX 5165#define BCOM_INITIATOR_ATA_TX 6166#define BCOM_INITIATOR_SCPCI_RX 7167#define BCOM_INITIATOR_SCPCI_TX 8168#define BCOM_INITIATOR_PSC3_RX 9169#define BCOM_INITIATOR_PSC3_TX 10170#define BCOM_INITIATOR_PSC2_RX 11171#define BCOM_INITIATOR_PSC2_TX 12172#define BCOM_INITIATOR_PSC1_RX 13173#define BCOM_INITIATOR_PSC1_TX 14174#define BCOM_INITIATOR_SCTMR_2 15175#define BCOM_INITIATOR_SCLPC 16176#define BCOM_INITIATOR_PSC5_RX 17177#define BCOM_INITIATOR_PSC5_TX 18178#define BCOM_INITIATOR_PSC4_RX 19179#define BCOM_INITIATOR_PSC4_TX 20180#define BCOM_INITIATOR_I2C2_RX 21181#define BCOM_INITIATOR_I2C2_TX 22182#define BCOM_INITIATOR_I2C1_RX 23183#define BCOM_INITIATOR_I2C1_TX 24184#define BCOM_INITIATOR_PSC6_RX 25185#define BCOM_INITIATOR_PSC6_TX 26186#define BCOM_INITIATOR_IRDA_RX 25187#define BCOM_INITIATOR_IRDA_TX 26188#define BCOM_INITIATOR_SCTMR_3 27189#define BCOM_INITIATOR_SCTMR_4 28190#define BCOM_INITIATOR_SCTMR_5 29191#define BCOM_INITIATOR_SCTMR_6 30192#define BCOM_INITIATOR_SCTMR_7 31193194/* Initiators priorities */195#define BCOM_IPR_ALWAYS 7196#define BCOM_IPR_SCTMR_0 2197#define BCOM_IPR_SCTMR_1 2198#define BCOM_IPR_FEC_RX 6199#define BCOM_IPR_FEC_TX 5200#define BCOM_IPR_ATA_RX 7201#define BCOM_IPR_ATA_TX 7202#define BCOM_IPR_SCPCI_RX 2203#define BCOM_IPR_SCPCI_TX 2204#define BCOM_IPR_PSC3_RX 2205#define BCOM_IPR_PSC3_TX 2206#define BCOM_IPR_PSC2_RX 2207#define BCOM_IPR_PSC2_TX 2208#define BCOM_IPR_PSC1_RX 2209#define BCOM_IPR_PSC1_TX 2210#define BCOM_IPR_SCTMR_2 2211#define BCOM_IPR_SCLPC 2212#define BCOM_IPR_PSC5_RX 2213#define BCOM_IPR_PSC5_TX 2214#define BCOM_IPR_PSC4_RX 2215#define BCOM_IPR_PSC4_TX 2216#define BCOM_IPR_I2C2_RX 2217#define BCOM_IPR_I2C2_TX 2218#define BCOM_IPR_I2C1_RX 2219#define BCOM_IPR_I2C1_TX 2220#define BCOM_IPR_PSC6_RX 2221#define BCOM_IPR_PSC6_TX 2222#define BCOM_IPR_IRDA_RX 2223#define BCOM_IPR_IRDA_TX 2224#define BCOM_IPR_SCTMR_3 2225#define BCOM_IPR_SCTMR_4 2226#define BCOM_IPR_SCTMR_5 2227#define BCOM_IPR_SCTMR_6 2228#define BCOM_IPR_SCTMR_7 2229230231/* ======================================================================== */232/* API */233/* ======================================================================== */234235extern struct bcom_task *bcom_task_alloc(int bd_count, int bd_size, int priv_size);236extern void bcom_task_free(struct bcom_task *tsk);237extern int bcom_load_image(int task, u32 *task_image);238extern void bcom_set_initiator(int task, int initiator);239240241#define TASK_ENABLE 0x8000242243/**244* bcom_disable_prefetch - Hook to disable bus prefetching245*246* ATA DMA and the original MPC5200 need this due to silicon bugs. At the247* moment disabling prefetch is a one-way street. There is no mechanism248* in place to turn prefetch back on after it has been disabled. There is249* no reason it couldn't be done, it would just be more complex to implement.250*/251static inline void bcom_disable_prefetch(void)252{253u16 regval;254255regval = in_be16(&bcom_eng->regs->PtdCntrl);256out_be16(&bcom_eng->regs->PtdCntrl, regval | 1);257};258259static inline void260bcom_enable_task(int task)261{262u16 reg;263reg = in_be16(&bcom_eng->regs->tcr[task]);264out_be16(&bcom_eng->regs->tcr[task], reg | TASK_ENABLE);265}266267static inline void268bcom_disable_task(int task)269{270u16 reg = in_be16(&bcom_eng->regs->tcr[task]);271out_be16(&bcom_eng->regs->tcr[task], reg & ~TASK_ENABLE);272}273274275static inline u32 *276bcom_task_desc(int task)277{278return bcom_sram_pa2va(bcom_eng->tdt[task].start);279}280281static inline int282bcom_task_num_descs(int task)283{284return (bcom_eng->tdt[task].stop - bcom_eng->tdt[task].start)/sizeof(u32) + 1;285}286287static inline u32 *288bcom_task_var(int task)289{290return bcom_sram_pa2va(bcom_eng->tdt[task].var);291}292293static inline u32 *294bcom_task_inc(int task)295{296return &bcom_task_var(task)[BCOM_MAX_VAR];297}298299300static inline int301bcom_drd_is_extended(u32 desc)302{303return (desc) & BCOM_DRD_EXTENDED;304}305306static inline int307bcom_desc_is_drd(u32 desc)308{309return !(desc & BCOM_LCD_MASK) && desc != BCOM_DESC_NOP;310}311312static inline int313bcom_desc_initiator(u32 desc)314{315return (desc >> BCOM_DRD_INITIATOR_SHIFT) & 0x1f;316}317318static inline void319bcom_set_desc_initiator(u32 *desc, int initiator)320{321*desc = (*desc & ~(0x1f << BCOM_DRD_INITIATOR_SHIFT)) |322((initiator & 0x1f) << BCOM_DRD_INITIATOR_SHIFT);323}324325326static inline void327bcom_set_task_pragma(int task, int pragma)328{329u32 *fdt = &bcom_eng->tdt[task].fdt;330*fdt = (*fdt & ~0xff) | pragma;331}332333static inline void334bcom_set_task_auto_start(int task, int next_task)335{336u16 __iomem *tcr = &bcom_eng->regs->tcr[task];337out_be16(tcr, (in_be16(tcr) & ~0xff) | 0x00c0 | next_task);338}339340static inline void341bcom_set_tcr_initiator(int task, int initiator)342{343u16 __iomem *tcr = &bcom_eng->regs->tcr[task];344out_be16(tcr, (in_be16(tcr) & ~0x1f00) | ((initiator & 0x1f) << 8));345}346347348#endif /* __BESTCOMM_PRIV_H__ */349350351352