📄 cmd_bc3450.c
字号:
/* * (C) Copyright 2005 * Stefan Strobl, GERSYS GmbH, stefan.strobl@gersys.de * * (C) Copyright 2005 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de. * * See file CREDITS for list of people who contributed to this * project. * * 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 */#include <common.h>#include <command.h>/* * BC3450 specific commands */#if (CONFIG_COMMANDS & CFG_CMD_BSP)#undef DEBUG#ifdef DEBUG# define dprintf(fmt,args...) printf(fmt, ##args)#else# define dprintf(fmt,args...)#endif/* * Definitions for DS1620 chip */#define THERM_START_CONVERT 0xee#define THERM_RESET 0xaf#define THERM_READ_CONFIG 0xac#define THERM_READ_TEMP 0xaa#define THERM_READ_TL 0xa2#define THERM_READ_TH 0xa1#define THERM_WRITE_CONFIG 0x0c#define THERM_WRITE_TL 0x02#define THERM_WRITE_TH 0x01#define CFG_CPU 2#define CFG_1SHOT 1#define CFG_STANDALONE 0struct therm { int hi; int lo;};/* * SM501 Register */#define SM501_GPIO_CTRL_LOW 0x00000008UL /* gpio pins 0..31 */#define SM501_GPIO_CTRL_HIGH 0x0000000CUL /* gpio pins 32..63 */#define SM501_POWER_MODE0_GATE 0x00000040UL#define SM501_POWER_MODE1_GATE 0x00000048UL#define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL#define SM501_GPIO_DATA_LOW 0x00010000UL#define SM501_GPIO_DATA_HIGH 0x00010004UL#define SM501_GPIO_DATA_DIR_LOW 0x00010008UL#define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL#define SM501_PANEL_DISPLAY_CONTROL 0x00080000UL#define SM501_CRT_DISPLAY_CONTROL 0x00080200UL/* SM501 CRT Display Control Bits */#define SM501_CDC_SEL (1 << 9)#define SM501_CDC_TE (1 << 8)#define SM501_CDC_E (1 << 2)/* SM501 Panel Display Control Bits */#define SM501_PDC_FPEN (1 << 27)#define SM501_PDC_BIAS (1 << 26)#define SM501_PDC_DATA (1 << 25)#define SM501_PDC_VDDEN (1 << 24)/* SM501 GPIO Data LOW Bits */#define SM501_GPIO24 0x01000000#define SM501_GPIO25 0x02000000#define SM501_GPIO26 0x04000000#define SM501_GPIO27 0x08000000#define SM501_GPIO28 0x10000000#define SM501_GPIO29 0x20000000#define SM501_GPIO30 0x40000000#define SM501_GPIO31 0x80000000/* SM501 GPIO Data HIGH Bits */#define SM501_GPIO46 0x00004000#define SM501_GPIO47 0x00008000#define SM501_GPIO48 0x00010000#define SM501_GPIO49 0x00020000#define SM501_GPIO50 0x00040000#define SM501_GPIO51 0x00080000/* BC3450 GPIOs @ SM501 Data LOW */#define DIP (SM501_GPIO24 | SM501_GPIO25 | SM501_GPIO26 | SM501_GPIO27)#define DS1620_DQ SM501_GPIO29 /* I/O */#define DS1620_CLK SM501_GPIO30 /* High active O/P */#define DS1620_RES SM501_GPIO31 /* Low active O/P *//* BC3450 GPIOs @ SM501 Data HIGH */#define BUZZER SM501_GPIO47 /* Low active O/P */#define DS1620_TLOW SM501_GPIO48 /* High active I/P */#define PWR_OFF SM501_GPIO49 /* Low active O/P */#define FP_DATA_TRI SM501_GPIO50 /* High active O/P *//* * Initialise GPIO on SM501 * * This function may be called from several other functions. * Yet, the initialisation sequence is executed only the first * time the function is called. */int sm501_gpio_init (void){ static int init_done = 0; if (init_done) {/* dprintf("sm501_gpio_init: nothing to be done.\n"); */ return 1; } /* enable SM501 GPIO control (in both power modes) */ *(vu_long *) (SM501_MMIO_BASE + SM501_POWER_MODE0_GATE) |= POWER_MODE_GATE_GPIO_PWM_I2C; *(vu_long *) (SM501_MMIO_BASE + SM501_POWER_MODE1_GATE) |= POWER_MODE_GATE_GPIO_PWM_I2C; /* set up default O/Ps */ *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) &= ~(DS1620_RES | DS1620_CLK); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) |= DS1620_DQ; *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_HIGH) &= ~(FP_DATA_TRI); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_HIGH) |= (BUZZER | PWR_OFF); /* configure directions for SM501 GPIO pins */ *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_CTRL_LOW) &= ~(0xFF << 24); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_CTRL_HIGH) &= ~(0x3F << 14); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_LOW) &= ~(DIP | DS1620_DQ); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_LOW) |= (DS1620_RES | DS1620_CLK); *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_HIGH) &= ~DS1620_TLOW; *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_HIGH) |= (PWR_OFF | BUZZER | FP_DATA_TRI); init_done = 1;/* dprintf("sm501_gpio_init: done.\n"); */ return 0;}/* * dip - read Config Inputs * * read and prints the dip switch * and/or external config inputs (4bits) 0...0x0F */int cmd_dip (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ vu_long rc = 0; sm501_gpio_init (); /* read dip switch */ rc = *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW); rc = ~rc; rc &= DIP; rc = (int) (rc >> 24); /* plausibility check */ if (rc > 0x0F) return -1; printf ("0x%x\n", rc); return 0;}U_BOOT_CMD (dip, 1, 1, cmd_dip, "dip - read dip switch and config inputs\n", "\n" " - prints the state of the dip switch and/or\n" " external configuration inputs as hex value.\n" " - \"Config 1\" is the LSB\n");/* * buz - turns Buzzer on/off */#ifdef CONFIG_BC3450_BUZZERstatic int cmd_buz (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ if (argc != 2) { printf ("Usage:\nspecify one argument: \"on\" or \"off\"\n"); return 1; } sm501_gpio_init (); if (strncmp (argv[1], "on", 2) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_HIGH) &= ~(BUZZER); return 0; } else if (strncmp (argv[1], "off", 3) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_HIGH) |= BUZZER; return 0; } printf ("Usage:\nspecify one argument: \"on\" or \"off\"\n"); return 1;}U_BOOT_CMD (buz, 2, 1, cmd_buz, "buz - turns buzzer on/off\n", "\n" "buz <on/off>\n" " - turns the buzzer on or off\n");#endif /* CONFIG_BC3450_BUZZER *//* * fp - front panel commands */static int cmd_fp (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ sm501_gpio_init (); if (strncmp (argv[1], "on", 2) == 0) { /* turn on VDD first */ *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_VDDEN; udelay (1000); /* then put data on */ *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_DATA; /* wait some time and enable backlight */ udelay (1000); *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_BIAS; udelay (1000); *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_FPEN; return 0; } else if (strncmp (argv[1], "off", 3) == 0) { /* turn off the backlight first */ *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_FPEN; udelay (1000); *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_BIAS; udelay (200000); /* wait some time, then remove data */ *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_DATA; udelay (1000); /* and remove VDD last */ *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_VDDEN; return 0; } else if (strncmp (argv[1], "bl", 2) == 0) { /* turn on/off backlight only */ if (strncmp (argv[2], "on", 2) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_BIAS; udelay (1000); *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) |= SM501_PDC_FPEN; return 0; } else if (strncmp (argv[2], "off", 3) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_FPEN; udelay (1000); *(vu_long *) (SM501_MMIO_BASE + SM501_PANEL_DISPLAY_CONTROL) &= ~SM501_PDC_BIAS; return 0; } }#ifdef CONFIG_BC3450_CRT else if (strncmp (argv[1], "crt", 3) == 0) { /* enables/disables the crt output (debug only) */ if (strncmp (argv[2], "on", 2) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_CRT_DISPLAY_CONTROL) |= (SM501_CDC_TE | SM501_CDC_E); *(vu_long *) (SM501_MMIO_BASE + SM501_CRT_DISPLAY_CONTROL) &= ~SM501_CDC_SEL; return 0; } else if (strncmp (argv[2], "off", 3) == 0) { *(vu_long *) (SM501_MMIO_BASE + SM501_CRT_DISPLAY_CONTROL) &= ~(SM501_CDC_TE | SM501_CDC_E); *(vu_long *) (SM501_MMIO_BASE + SM501_CRT_DISPLAY_CONTROL) |= SM501_CDC_SEL; return 0; } }#endif /* CONFIG_BC3450_CRT */ printf ("Usage:%s\n", cmdtp->help); return 1;}U_BOOT_CMD (fp, 3, 1, cmd_fp, "fp - front panes access functions\n", "\n" "fp bl <on/off>\n" " - turns the CCFL backlight of the display on/off\n" "fp <on/off>\n" " - turns the whole display on/off\n"#ifdef CONFIG_BC3450_CRT "fp crt <on/off>\n" " - enables/disables the crt output (debug only)\n"#endif /* CONFIG_BC3450_CRT */ );/* * temp - DS1620 thermometer *//* GERSYS BC3450 specific functions */static inline void bc_ds1620_set_clk (int clk){ if (clk) *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) |= DS1620_CLK; else *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) &= ~DS1620_CLK;}static inline void bc_ds1620_set_data (int dat){ if (dat) *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) |= DS1620_DQ; else *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) &= ~DS1620_DQ;}static inline int bc_ds1620_get_data (void){ vu_long rc; rc = *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW); rc &= DS1620_DQ; if (rc != 0) rc = 1; return (int) rc;}static inline void bc_ds1620_set_data_dir (int dir){ if (dir) /* in */ *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_LOW) &= ~DS1620_DQ; else /* out */ *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_DIR_LOW) |= DS1620_DQ;}static inline void bc_ds1620_set_reset (int res){ if (res) *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) |= DS1620_RES; else *(vu_long *) (SM501_MMIO_BASE + SM501_GPIO_DATA_LOW) &= ~DS1620_RES;}/* hardware independent functions */static void ds1620_send_bits (int nr, int value){ int i; for (i = 0; i < nr; i++) { bc_ds1620_set_data (value & 1); bc_ds1620_set_clk (0); udelay (1); bc_ds1620_set_clk (1); udelay (1); value >>= 1; }}static unsigned int ds1620_recv_bits (int nr){ unsigned int value = 0, mask = 1; int i; bc_ds1620_set_data (0); for (i = 0; i < nr; i++) { bc_ds1620_set_clk (0); udelay (1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -