Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MIPS] rbtx4938: Convert SPI codes to use generic SPI drivers

Use rtc-rs5c348 and at25 spi protocol driver and spi_txx9 spi
controller driver instead of platform dependent codes.

This patch also removes dependencies to old RTC interfaces such as
rtc_mips_get_time, etc.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Atsushi Nemoto and committed by
Ralf Baechle
f74cf6ff 3896b054

+226 -702
+51 -3
arch/mips/configs/rbhma4500_defconfig
··· 966 966 # 967 967 # SPI support 968 968 # 969 - # CONFIG_SPI is not set 970 - # CONFIG_SPI_MASTER is not set 969 + CONFIG_SPI=y 970 + CONFIG_SPI_MASTER=y 971 + 972 + # 973 + # SPI Master Controller Drivers 974 + # 975 + # CONFIG_SPI_BITBANG is not set 976 + CONFIG_SPI_TXX9=y 977 + 978 + # 979 + # SPI Protocol Masters 980 + # 981 + CONFIG_SPI_AT25=y 982 + # CONFIG_SPI_SPIDEV is not set 971 983 972 984 # 973 985 # Dallas's 1-wire bus ··· 1219 1207 # 1220 1208 # Real Time Clock 1221 1209 # 1222 - # CONFIG_RTC_CLASS is not set 1210 + CONFIG_RTC_LIB=y 1211 + CONFIG_RTC_CLASS=y 1212 + CONFIG_RTC_HCTOSYS=y 1213 + CONFIG_RTC_HCTOSYS_DEVICE="rtc0" 1214 + # CONFIG_RTC_DEBUG is not set 1215 + 1216 + # 1217 + # RTC interfaces 1218 + # 1219 + CONFIG_RTC_INTF_SYSFS=y 1220 + CONFIG_RTC_INTF_PROC=y 1221 + CONFIG_RTC_INTF_DEV=y 1222 + CONFIG_RTC_INTF_DEV_UIE_EMUL=y 1223 + # CONFIG_RTC_DRV_TEST is not set 1224 + 1225 + # 1226 + # I2C RTC drivers 1227 + # 1228 + 1229 + # 1230 + # SPI RTC drivers 1231 + # 1232 + CONFIG_RTC_DRV_RS5C348=y 1233 + # CONFIG_RTC_DRV_MAX6902 is not set 1234 + 1235 + # 1236 + # Platform RTC drivers 1237 + # 1238 + # CONFIG_RTC_DRV_CMOS is not set 1239 + # CONFIG_RTC_DRV_DS1553 is not set 1240 + # CONFIG_RTC_DRV_DS1742 is not set 1241 + # CONFIG_RTC_DRV_M48T86 is not set 1242 + # CONFIG_RTC_DRV_V3020 is not set 1243 + 1244 + # 1245 + # on-CPU RTC drivers 1246 + # 1223 1247 1224 1248 # 1225 1249 # DMA Engine support
+1 -1
arch/mips/tx4938/common/Makefile
··· 6 6 # unless it's something special (ie not a .c file). 7 7 # 8 8 9 - obj-y += prom.o setup.o irq.o rtc_rx5c348.o 9 + obj-y += prom.o setup.o irq.o 10 10 obj-$(CONFIG_KGDB) += dbgio.o 11 11
-192
arch/mips/tx4938/common/rtc_rx5c348.c
··· 1 - /* 2 - * RTC routines for RICOH Rx5C348 SPI chip. 3 - * Copyright (C) 2000-2001 Toshiba Corporation 4 - * 5 - * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the 6 - * terms of the GNU General Public License version 2. This program is 7 - * licensed "as is" without any warranty of any kind, whether express 8 - * or implied. 9 - * 10 - * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com) 11 - */ 12 - #include <linux/init.h> 13 - #include <linux/kernel.h> 14 - #include <linux/string.h> 15 - #include <linux/rtc.h> 16 - #include <linux/time.h> 17 - #include <linux/bcd.h> 18 - #include <asm/time.h> 19 - #include <asm/tx4938/spi.h> 20 - 21 - #define EPOCH 2000 22 - 23 - /* registers */ 24 - #define Rx5C348_REG_SECOND 0 25 - #define Rx5C348_REG_MINUTE 1 26 - #define Rx5C348_REG_HOUR 2 27 - #define Rx5C348_REG_WEEK 3 28 - #define Rx5C348_REG_DAY 4 29 - #define Rx5C348_REG_MONTH 5 30 - #define Rx5C348_REG_YEAR 6 31 - #define Rx5C348_REG_ADJUST 7 32 - #define Rx5C348_REG_ALARM_W_MIN 8 33 - #define Rx5C348_REG_ALARM_W_HOUR 9 34 - #define Rx5C348_REG_ALARM_W_WEEK 10 35 - #define Rx5C348_REG_ALARM_D_MIN 11 36 - #define Rx5C348_REG_ALARM_D_HOUR 12 37 - #define Rx5C348_REG_CTL1 14 38 - #define Rx5C348_REG_CTL2 15 39 - 40 - /* register bits */ 41 - #define Rx5C348_BIT_PM 0x20 /* REG_HOUR */ 42 - #define Rx5C348_BIT_Y2K 0x80 /* REG_MONTH */ 43 - #define Rx5C348_BIT_24H 0x20 /* REG_CTL1 */ 44 - #define Rx5C348_BIT_XSTP 0x10 /* REG_CTL2 */ 45 - 46 - /* commands */ 47 - #define Rx5C348_CMD_W(addr) (((addr) << 4) | 0x08) /* single write */ 48 - #define Rx5C348_CMD_R(addr) (((addr) << 4) | 0x0c) /* single read */ 49 - #define Rx5C348_CMD_MW(addr) (((addr) << 4) | 0x00) /* burst write */ 50 - #define Rx5C348_CMD_MR(addr) (((addr) << 4) | 0x04) /* burst read */ 51 - 52 - static struct spi_dev_desc srtc_dev_desc = { 53 - .baud = 1000000, /* 1.0Mbps @ Vdd 2.0V */ 54 - .tcss = 31, 55 - .tcsh = 1, 56 - .tcsr = 62, 57 - /* 31us for Tcss (62us for Tcsr) is required for carry operation) */ 58 - .byteorder = 1, /* MSB-First */ 59 - .polarity = 0, /* High-Active */ 60 - .phase = 1, /* Shift-Then-Sample */ 61 - 62 - }; 63 - static int srtc_chipid; 64 - static int srtc_24h; 65 - 66 - static inline int 67 - spi_rtc_io(unsigned char *inbuf, unsigned char *outbuf, unsigned int count) 68 - { 69 - unsigned char *inbufs[1], *outbufs[1]; 70 - unsigned int incounts[2], outcounts[2]; 71 - inbufs[0] = inbuf; 72 - incounts[0] = count; 73 - incounts[1] = 0; 74 - outbufs[0] = outbuf; 75 - outcounts[0] = count; 76 - outcounts[1] = 0; 77 - return txx9_spi_io(srtc_chipid, &srtc_dev_desc, 78 - inbufs, incounts, outbufs, outcounts, 0); 79 - } 80 - 81 - /* RTC-dependent code for time.c */ 82 - 83 - static int 84 - rtc_rx5c348_set_time(unsigned long t) 85 - { 86 - unsigned char inbuf[8]; 87 - struct rtc_time tm; 88 - u8 year, month, day, hour, minute, second, century; 89 - 90 - /* convert */ 91 - to_tm(t, &tm); 92 - 93 - year = tm.tm_year % 100; 94 - month = tm.tm_mon+1; /* tm_mon starts from 0 to 11 */ 95 - day = tm.tm_mday; 96 - hour = tm.tm_hour; 97 - minute = tm.tm_min; 98 - second = tm.tm_sec; 99 - century = tm.tm_year / 100; 100 - 101 - inbuf[0] = Rx5C348_CMD_MW(Rx5C348_REG_SECOND); 102 - BIN_TO_BCD(second); 103 - inbuf[1] = second; 104 - BIN_TO_BCD(minute); 105 - inbuf[2] = minute; 106 - 107 - if (srtc_24h) { 108 - BIN_TO_BCD(hour); 109 - inbuf[3] = hour; 110 - } else { 111 - /* hour 0 is AM12, noon is PM12 */ 112 - inbuf[3] = 0; 113 - if (hour >= 12) 114 - inbuf[3] = Rx5C348_BIT_PM; 115 - hour = (hour + 11) % 12 + 1; 116 - BIN_TO_BCD(hour); 117 - inbuf[3] |= hour; 118 - } 119 - inbuf[4] = 0; /* ignore week */ 120 - BIN_TO_BCD(day); 121 - inbuf[5] = day; 122 - BIN_TO_BCD(month); 123 - inbuf[6] = month; 124 - if (century >= 20) 125 - inbuf[6] |= Rx5C348_BIT_Y2K; 126 - BIN_TO_BCD(year); 127 - inbuf[7] = year; 128 - /* write in one transfer to avoid data inconsistency */ 129 - return spi_rtc_io(inbuf, NULL, 8); 130 - } 131 - 132 - static unsigned long 133 - rtc_rx5c348_get_time(void) 134 - { 135 - unsigned char inbuf[8], outbuf[8]; 136 - unsigned int year, month, day, hour, minute, second; 137 - 138 - inbuf[0] = Rx5C348_CMD_MR(Rx5C348_REG_SECOND); 139 - memset(inbuf + 1, 0, 7); 140 - /* read in one transfer to avoid data inconsistency */ 141 - if (spi_rtc_io(inbuf, outbuf, 8)) 142 - return 0; 143 - second = outbuf[1]; 144 - BCD_TO_BIN(second); 145 - minute = outbuf[2]; 146 - BCD_TO_BIN(minute); 147 - if (srtc_24h) { 148 - hour = outbuf[3]; 149 - BCD_TO_BIN(hour); 150 - } else { 151 - hour = outbuf[3] & ~Rx5C348_BIT_PM; 152 - BCD_TO_BIN(hour); 153 - hour %= 12; 154 - if (outbuf[3] & Rx5C348_BIT_PM) 155 - hour += 12; 156 - } 157 - day = outbuf[5]; 158 - BCD_TO_BIN(day); 159 - month = outbuf[6] & ~Rx5C348_BIT_Y2K; 160 - BCD_TO_BIN(month); 161 - year = outbuf[7]; 162 - BCD_TO_BIN(year); 163 - year += EPOCH; 164 - 165 - return mktime(year, month, day, hour, minute, second); 166 - } 167 - 168 - void __init 169 - rtc_rx5c348_init(int chipid) 170 - { 171 - unsigned char inbuf[2], outbuf[2]; 172 - srtc_chipid = chipid; 173 - /* turn on RTC if it is not on */ 174 - inbuf[0] = Rx5C348_CMD_R(Rx5C348_REG_CTL2); 175 - inbuf[1] = 0; 176 - spi_rtc_io(inbuf, outbuf, 2); 177 - if (outbuf[1] & Rx5C348_BIT_XSTP) { 178 - inbuf[0] = Rx5C348_CMD_W(Rx5C348_REG_CTL2); 179 - inbuf[1] = 0; 180 - spi_rtc_io(inbuf, NULL, 2); 181 - } 182 - 183 - inbuf[0] = Rx5C348_CMD_R(Rx5C348_REG_CTL1); 184 - inbuf[1] = 0; 185 - spi_rtc_io(inbuf, outbuf, 2); 186 - if (outbuf[1] & Rx5C348_BIT_24H) 187 - srtc_24h = 1; 188 - 189 - /* set the function pointers */ 190 - rtc_mips_get_time = rtc_rx5c348_get_time; 191 - rtc_mips_set_time = rtc_rx5c348_set_time; 192 - }
+1 -1
arch/mips/tx4938/toshiba_rbtx4938/Makefile
··· 6 6 # unless it's something special (ie not a .c file). 7 7 # 8 8 9 - obj-y += prom.o setup.o irq.o spi_eeprom.o spi_txx9.o 9 + obj-y += prom.o setup.o irq.o spi_eeprom.o
-6
arch/mips/tx4938/toshiba_rbtx4938/irq.c
··· 165 165 TX4938_RD08(TOSHIBA_RBTX4938_IOC_INTR_ENAB); 166 166 } 167 167 168 - extern void __init txx9_spi_irqinit(int irc_irq); 169 - 170 168 void __init arch_init_irq(void) 171 169 { 172 170 extern void tx4938_irq_init(void); ··· 182 184 toshiba_rbtx4938_irq_ioc_init(); 183 185 /* Onboard 10M Ether: High Active */ 184 186 TX4938_WR(TX4938_MKA(TX4938_IRC_IRDM0), 0x00000040); 185 - 186 - if (tx4938_ccfgptr->pcfg & TX4938_PCFG_SPI_SEL) { 187 - txx9_spi_irqinit(RBTX4938_IRQ_IRC_SPI); 188 - } 189 187 190 188 wbflush(); 191 189 }
+94 -77
arch/mips/tx4938/toshiba_rbtx4938/setup.c
··· 14 14 #include <linux/init.h> 15 15 #include <linux/types.h> 16 16 #include <linux/ioport.h> 17 - #include <linux/proc_fs.h> 18 17 #include <linux/delay.h> 19 18 #include <linux/interrupt.h> 20 19 #include <linux/console.h> 21 20 #include <linux/pci.h> 22 21 #include <linux/pm.h> 23 22 #include <linux/platform_device.h> 23 + #include <linux/clk.h> 24 24 25 25 #include <asm/wbflush.h> 26 26 #include <asm/reboot.h> ··· 29 29 #include <asm/uaccess.h> 30 30 #include <asm/io.h> 31 31 #include <asm/bootinfo.h> 32 - #include <asm/gpio.h> 33 32 #include <asm/tx4938/rbtx4938.h> 34 33 #ifdef CONFIG_SERIAL_TXX9 35 34 #include <linux/tty.h> 36 35 #include <linux/serial.h> 37 36 #include <linux/serial_core.h> 38 37 #endif 38 + #include <linux/spi/spi.h> 39 + #include <asm/tx4938/spi.h> 40 + #include <asm/gpio.h> 39 41 40 42 extern void rbtx4938_time_init(void) __init; 41 43 extern char * __init prom_getcmdline(void); ··· 577 575 #define SEEPROM3_CS 1 /* IOC */ 578 576 #define SRTC_CS 2 /* IOC */ 579 577 580 - static int rbtx4938_spi_cs_func(int chipid, int on) 578 + #ifdef CONFIG_PCI 579 + static unsigned char rbtx4938_ethaddr[17]; 580 + static int __init rbtx4938_ethaddr_init(void) 581 581 { 582 - unsigned char bit; 583 - switch (chipid) { 584 - case RBTX4938_SEEPROM1_CHIPID: 585 - if (on) 586 - tx4938_pioptr->dout &= ~(1 << SEEPROM1_CS); 587 - else 588 - tx4938_pioptr->dout |= (1 << SEEPROM1_CS); 589 - return 0; 590 - break; 591 - case RBTX4938_SEEPROM2_CHIPID: 592 - bit = (1 << SEEPROM2_CS); 593 - break; 594 - case RBTX4938_SEEPROM3_CHIPID: 595 - bit = (1 << SEEPROM3_CS); 596 - break; 597 - case RBTX4938_SRTC_CHIPID: 598 - bit = (1 << SRTC_CS); 599 - break; 600 - default: 601 - return -ENODEV; 582 + unsigned char sum; 583 + int i; 584 + 585 + /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */ 586 + if (spi_eeprom_read(SEEPROM1_CS, 0, 587 + rbtx4938_ethaddr, sizeof(rbtx4938_ethaddr))) 588 + printk(KERN_ERR "seeprom: read error.\n"); 589 + else { 590 + unsigned char *dat = rbtx4938_ethaddr; 591 + if (strcmp(dat, "MAC") != 0) 592 + printk(KERN_WARNING "seeprom: bad signature.\n"); 593 + for (i = 0, sum = 0; i < sizeof(dat); i++) 594 + sum += dat[i]; 595 + if (sum) 596 + printk(KERN_WARNING "seeprom: bad checksum.\n"); 602 597 } 603 - /* bit1,2,4 are low active, bit3 is high active */ 604 - *rbtx4938_spics_ptr = 605 - (*rbtx4938_spics_ptr & ~bit) | 606 - ((on ? (bit ^ 0x0b) : ~(bit ^ 0x0b)) & bit); 607 598 return 0; 608 599 } 609 - 610 - #ifdef CONFIG_PCI 611 - extern int spi_eeprom_read(int chipid, int address, unsigned char *buf, int len); 600 + device_initcall(rbtx4938_ethaddr_init); 612 601 613 602 int rbtx4938_get_tx4938_ethaddr(struct pci_dev *dev, unsigned char *addr) 614 603 { 615 604 struct pci_controller *channel = (struct pci_controller *)dev->bus->sysdata; 616 - static unsigned char dat[17]; 617 - static int read_dat = 0; 618 605 int ch = 0; 619 606 620 607 if (channel != &tx4938_pci_controller[1]) ··· 619 628 default: 620 629 return -ENODEV; 621 630 } 622 - if (!read_dat) { 623 - unsigned char sum; 624 - int i; 625 - read_dat = 1; 626 - /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */ 627 - if (spi_eeprom_read(RBTX4938_SEEPROM1_CHIPID, 628 - 0, dat, sizeof(dat))) { 629 - printk(KERN_ERR "seeprom: read error.\n"); 630 - } else { 631 - if (strcmp(dat, "MAC") != 0) 632 - printk(KERN_WARNING "seeprom: bad signature.\n"); 633 - for (i = 0, sum = 0; i < sizeof(dat); i++) 634 - sum += dat[i]; 635 - if (sum) 636 - printk(KERN_WARNING "seeprom: bad checksum.\n"); 637 - } 638 - } 639 - memcpy(addr, &dat[4 + 6 * ch], 6); 631 + memcpy(addr, &rbtx4938_ethaddr[4 + 6 * ch], 6); 640 632 return 0; 641 633 } 642 634 #endif /* CONFIG_PCI */ 643 635 644 - extern void __init txx9_spi_init(unsigned long base, int (*cs_func)(int chipid, int on)); 645 636 static void __init rbtx4938_spi_setup(void) 646 637 { 647 638 /* set SPI_SEL */ ··· 631 658 /* chip selects for SPI devices */ 632 659 tx4938_pioptr->dout |= (1 << SEEPROM1_CS); 633 660 tx4938_pioptr->dir |= (1 << SEEPROM1_CS); 634 - txx9_spi_init(TX4938_SPI_REG, rbtx4938_spi_cs_func); 635 661 } 636 662 637 663 static struct resource rbtx4938_fpga_resource; ··· 869 897 /* We use onchip r4k counter or TMR timer as our system wide timer 870 898 * interrupt running at 100HZ. */ 871 899 872 - extern void __init rtc_rx5c348_init(int chipid); 873 900 void __init rbtx4938_time_init(void) 874 901 { 875 - rtc_rx5c348_init(RBTX4938_SRTC_CHIPID); 876 902 mips_hpt_frequency = txx9_cpu_clock / 2; 877 903 } 878 904 ··· 986 1016 printk(" DIPSW:%02x,%02x\n", 987 1017 *rbtx4938_dipsw_ptr, *rbtx4938_bdipsw_ptr); 988 1018 } 989 - 990 - #ifdef CONFIG_PROC_FS 991 - extern void spi_eeprom_proc_create(struct proc_dir_entry *dir, int chipid); 992 - static int __init tx4938_spi_proc_setup(void) 993 - { 994 - struct proc_dir_entry *tx4938_spi_eeprom_dir; 995 - 996 - tx4938_spi_eeprom_dir = proc_mkdir("spi_eeprom", 0); 997 - 998 - if (!tx4938_spi_eeprom_dir) 999 - return -ENOMEM; 1000 - 1001 - /* don't allow user access to RBTX4938_SEEPROM1_CHIPID 1002 - * as it contains eth0 and eth1 MAC addresses 1003 - */ 1004 - spi_eeprom_proc_create(tx4938_spi_eeprom_dir, RBTX4938_SEEPROM2_CHIPID); 1005 - spi_eeprom_proc_create(tx4938_spi_eeprom_dir, RBTX4938_SEEPROM3_CHIPID); 1006 - 1007 - return 0; 1008 - } 1009 - 1010 - __initcall(tx4938_spi_proc_setup); 1011 - #endif 1012 1019 1013 1020 static int __init rbtx4938_ne_init(void) 1014 1021 { ··· 1108 1161 else 1109 1162 rbtx4938_spi_gpio_set(gpio, value); 1110 1163 } 1164 + 1165 + /* SPI support */ 1166 + 1167 + static void __init txx9_spi_init(unsigned long base, int irq) 1168 + { 1169 + struct resource res[] = { 1170 + { 1171 + .start = base, 1172 + .end = base + 0x20 - 1, 1173 + .flags = IORESOURCE_MEM, 1174 + .parent = &tx4938_reg_resource, 1175 + }, { 1176 + .start = irq, 1177 + .flags = IORESOURCE_IRQ, 1178 + }, 1179 + }; 1180 + platform_device_register_simple("txx9spi", 0, 1181 + res, ARRAY_SIZE(res)); 1182 + } 1183 + 1184 + static int __init rbtx4938_spi_init(void) 1185 + { 1186 + struct spi_board_info srtc_info = { 1187 + .modalias = "rs5c348", 1188 + .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */ 1189 + .bus_num = 0, 1190 + .chip_select = 16 + SRTC_CS, 1191 + /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */ 1192 + .mode = SPI_MODE_1 | SPI_CS_HIGH, 1193 + }; 1194 + spi_register_board_info(&srtc_info, 1); 1195 + spi_eeprom_register(SEEPROM1_CS); 1196 + spi_eeprom_register(16 + SEEPROM2_CS); 1197 + spi_eeprom_register(16 + SEEPROM3_CS); 1198 + txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI); 1199 + return 0; 1200 + } 1201 + arch_initcall(rbtx4938_spi_init); 1202 + 1203 + /* Minimum CLK support */ 1204 + 1205 + struct clk *clk_get(struct device *dev, const char *id) 1206 + { 1207 + if (!strcmp(id, "spi-baseclk")) 1208 + return (struct clk *)(txx9_gbus_clock / 2 / 4); 1209 + return ERR_PTR(-ENOENT); 1210 + } 1211 + EXPORT_SYMBOL(clk_get); 1212 + 1213 + int clk_enable(struct clk *clk) 1214 + { 1215 + return 0; 1216 + } 1217 + EXPORT_SYMBOL(clk_enable); 1218 + 1219 + void clk_disable(struct clk *clk) 1220 + { 1221 + } 1222 + EXPORT_SYMBOL(clk_disable); 1223 + 1224 + unsigned long clk_get_rate(struct clk *clk) 1225 + { 1226 + return (unsigned long)clk; 1227 + } 1228 + EXPORT_SYMBOL(clk_get_rate); 1229 + 1230 + void clk_put(struct clk *clk) 1231 + { 1232 + } 1233 + EXPORT_SYMBOL(clk_put);
+78 -197
arch/mips/tx4938/toshiba_rbtx4938/spi_eeprom.c
··· 10 10 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com) 11 11 */ 12 12 #include <linux/init.h> 13 - #include <linux/delay.h> 14 - #include <linux/proc_fs.h> 15 - #include <linux/spinlock.h> 13 + #include <linux/device.h> 14 + #include <linux/spi/spi.h> 15 + #include <linux/spi/eeprom.h> 16 16 #include <asm/tx4938/spi.h> 17 - #include <asm/tx4938/tx4938.h> 18 17 19 - /* ATMEL 250x0 instructions */ 20 - #define ATMEL_WREN 0x06 21 - #define ATMEL_WRDI 0x04 22 - #define ATMEL_RDSR 0x05 23 - #define ATMEL_WRSR 0x01 24 - #define ATMEL_READ 0x03 25 - #define ATMEL_WRITE 0x02 18 + #define AT250X0_PAGE_SIZE 8 26 19 27 - #define ATMEL_SR_BSY 0x01 28 - #define ATMEL_SR_WEN 0x02 29 - #define ATMEL_SR_BP0 0x04 30 - #define ATMEL_SR_BP1 0x08 20 + /* register board information for at25 driver */ 21 + int __init spi_eeprom_register(int chipid) 22 + { 23 + static struct spi_eeprom eeprom = { 24 + .name = "at250x0", 25 + .byte_len = 128, 26 + .page_size = AT250X0_PAGE_SIZE, 27 + .flags = EE_ADDR1, 28 + }; 29 + struct spi_board_info info = { 30 + .modalias = "at25", 31 + .max_speed_hz = 1500000, /* 1.5Mbps */ 32 + .bus_num = 0, 33 + .chip_select = chipid, 34 + .platform_data = &eeprom, 35 + /* Mode 0: High-Active, Sample-Then-Shift */ 36 + }; 31 37 32 - DEFINE_SPINLOCK(spi_eeprom_lock); 38 + return spi_register_board_info(&info, 1); 39 + } 33 40 34 - static struct spi_dev_desc seeprom_dev_desc = { 35 - .baud = 1500000, /* 1.5Mbps */ 36 - .tcss = 1, 37 - .tcsh = 1, 38 - .tcsr = 1, 39 - .byteorder = 1, /* MSB-First */ 40 - .polarity = 0, /* High-Active */ 41 - .phase = 0, /* Sample-Then-Shift */ 41 + /* simple temporary spi driver to provide early access to seeprom. */ 42 42 43 + static struct read_param { 44 + int chipid; 45 + int address; 46 + unsigned char *buf; 47 + int len; 48 + } *read_param; 49 + 50 + static int __init early_seeprom_probe(struct spi_device *spi) 51 + { 52 + int stat = 0; 53 + u8 cmd[2]; 54 + int len = read_param->len; 55 + char *buf = read_param->buf; 56 + int address = read_param->address; 57 + 58 + dev_info(&spi->dev, "spiclk %u KHz.\n", 59 + (spi->max_speed_hz + 500) / 1000); 60 + if (read_param->chipid != spi->chip_select) 61 + return -ENODEV; 62 + while (len > 0) { 63 + /* spi_write_then_read can only work with small chunk */ 64 + int c = len < AT250X0_PAGE_SIZE ? len : AT250X0_PAGE_SIZE; 65 + cmd[0] = 0x03; /* AT25_READ */ 66 + cmd[1] = address; 67 + stat = spi_write_then_read(spi, cmd, sizeof(cmd), buf, c); 68 + buf += c; 69 + len -= c; 70 + address += c; 71 + } 72 + return stat; 73 + } 74 + 75 + static struct spi_driver early_seeprom_driver __initdata = { 76 + .driver = { 77 + .name = "at25", 78 + .owner = THIS_MODULE, 79 + }, 80 + .probe = early_seeprom_probe, 43 81 }; 44 - static inline int 45 - spi_eeprom_io(int chipid, 46 - unsigned char **inbufs, unsigned int *incounts, 47 - unsigned char **outbufs, unsigned int *outcounts) 82 + 83 + int __init spi_eeprom_read(int chipid, int address, 84 + unsigned char *buf, int len) 48 85 { 49 - return txx9_spi_io(chipid, &seeprom_dev_desc, 50 - inbufs, incounts, outbufs, outcounts, 0); 86 + int ret; 87 + struct read_param param = { 88 + .chipid = chipid, 89 + .address = address, 90 + .buf = buf, 91 + .len = len 92 + }; 93 + 94 + read_param = &param; 95 + ret = spi_register_driver(&early_seeprom_driver); 96 + if (!ret) 97 + spi_unregister_driver(&early_seeprom_driver); 98 + return ret; 51 99 } 52 - 53 - int spi_eeprom_write_enable(int chipid, int enable) 54 - { 55 - unsigned char inbuf[1]; 56 - unsigned char *inbufs[1]; 57 - unsigned int incounts[2]; 58 - unsigned long flags; 59 - int stat; 60 - inbuf[0] = enable ? ATMEL_WREN : ATMEL_WRDI; 61 - inbufs[0] = inbuf; 62 - incounts[0] = sizeof(inbuf); 63 - incounts[1] = 0; 64 - spin_lock_irqsave(&spi_eeprom_lock, flags); 65 - stat = spi_eeprom_io(chipid, inbufs, incounts, NULL, NULL); 66 - spin_unlock_irqrestore(&spi_eeprom_lock, flags); 67 - return stat; 68 - } 69 - 70 - static int spi_eeprom_read_status_nolock(int chipid) 71 - { 72 - unsigned char inbuf[2], outbuf[2]; 73 - unsigned char *inbufs[1], *outbufs[1]; 74 - unsigned int incounts[2], outcounts[2]; 75 - int stat; 76 - inbuf[0] = ATMEL_RDSR; 77 - inbuf[1] = 0; 78 - inbufs[0] = inbuf; 79 - incounts[0] = sizeof(inbuf); 80 - incounts[1] = 0; 81 - outbufs[0] = outbuf; 82 - outcounts[0] = sizeof(outbuf); 83 - outcounts[1] = 0; 84 - stat = spi_eeprom_io(chipid, inbufs, incounts, outbufs, outcounts); 85 - if (stat < 0) 86 - return stat; 87 - return outbuf[1]; 88 - } 89 - 90 - int spi_eeprom_read_status(int chipid) 91 - { 92 - unsigned long flags; 93 - int stat; 94 - spin_lock_irqsave(&spi_eeprom_lock, flags); 95 - stat = spi_eeprom_read_status_nolock(chipid); 96 - spin_unlock_irqrestore(&spi_eeprom_lock, flags); 97 - return stat; 98 - } 99 - 100 - int spi_eeprom_read(int chipid, int address, unsigned char *buf, int len) 101 - { 102 - unsigned char inbuf[2]; 103 - unsigned char *inbufs[2], *outbufs[2]; 104 - unsigned int incounts[2], outcounts[3]; 105 - unsigned long flags; 106 - int stat; 107 - inbuf[0] = ATMEL_READ; 108 - inbuf[1] = address; 109 - inbufs[0] = inbuf; 110 - inbufs[1] = NULL; 111 - incounts[0] = sizeof(inbuf); 112 - incounts[1] = 0; 113 - outbufs[0] = NULL; 114 - outbufs[1] = buf; 115 - outcounts[0] = 2; 116 - outcounts[1] = len; 117 - outcounts[2] = 0; 118 - spin_lock_irqsave(&spi_eeprom_lock, flags); 119 - stat = spi_eeprom_io(chipid, inbufs, incounts, outbufs, outcounts); 120 - spin_unlock_irqrestore(&spi_eeprom_lock, flags); 121 - return stat; 122 - } 123 - 124 - int spi_eeprom_write(int chipid, int address, unsigned char *buf, int len) 125 - { 126 - unsigned char inbuf[2]; 127 - unsigned char *inbufs[2]; 128 - unsigned int incounts[3]; 129 - unsigned long flags; 130 - int i, stat; 131 - 132 - if (address / 8 != (address + len - 1) / 8) 133 - return -EINVAL; 134 - stat = spi_eeprom_write_enable(chipid, 1); 135 - if (stat < 0) 136 - return stat; 137 - stat = spi_eeprom_read_status(chipid); 138 - if (stat < 0) 139 - return stat; 140 - if (!(stat & ATMEL_SR_WEN)) 141 - return -EPERM; 142 - 143 - inbuf[0] = ATMEL_WRITE; 144 - inbuf[1] = address; 145 - inbufs[0] = inbuf; 146 - inbufs[1] = buf; 147 - incounts[0] = sizeof(inbuf); 148 - incounts[1] = len; 149 - incounts[2] = 0; 150 - spin_lock_irqsave(&spi_eeprom_lock, flags); 151 - stat = spi_eeprom_io(chipid, inbufs, incounts, NULL, NULL); 152 - if (stat < 0) 153 - goto unlock_return; 154 - 155 - /* write start. max 10ms */ 156 - for (i = 10; i > 0; i--) { 157 - int stat = spi_eeprom_read_status_nolock(chipid); 158 - if (stat < 0) 159 - goto unlock_return; 160 - if (!(stat & ATMEL_SR_BSY)) 161 - break; 162 - mdelay(1); 163 - } 164 - spin_unlock_irqrestore(&spi_eeprom_lock, flags); 165 - if (i == 0) 166 - return -EIO; 167 - return len; 168 - unlock_return: 169 - spin_unlock_irqrestore(&spi_eeprom_lock, flags); 170 - return stat; 171 - } 172 - 173 - #ifdef CONFIG_PROC_FS 174 - #define MAX_SIZE 0x80 /* for ATMEL 25010 */ 175 - static int spi_eeprom_read_proc(char *page, char **start, off_t off, 176 - int count, int *eof, void *data) 177 - { 178 - unsigned int size = MAX_SIZE; 179 - if (spi_eeprom_read((int)data, 0, (unsigned char *)page, size) < 0) 180 - size = 0; 181 - return size; 182 - } 183 - 184 - static int spi_eeprom_write_proc(struct file *file, const char *buffer, 185 - unsigned long count, void *data) 186 - { 187 - unsigned int size = MAX_SIZE; 188 - int i; 189 - if (file->f_pos >= size) 190 - return -EIO; 191 - if (file->f_pos + count > size) 192 - count = size - file->f_pos; 193 - for (i = 0; i < count; i += 8) { 194 - int len = count - i < 8 ? count - i : 8; 195 - if (spi_eeprom_write((int)data, file->f_pos, 196 - (unsigned char *)buffer, len) < 0) { 197 - count = -EIO; 198 - break; 199 - } 200 - buffer += len; 201 - file->f_pos += len; 202 - } 203 - return count; 204 - } 205 - 206 - __init void spi_eeprom_proc_create(struct proc_dir_entry *dir, int chipid) 207 - { 208 - struct proc_dir_entry *entry; 209 - char name[128]; 210 - sprintf(name, "seeprom-%d", chipid); 211 - entry = create_proc_entry(name, 0600, dir); 212 - if (entry) { 213 - entry->read_proc = spi_eeprom_read_proc; 214 - entry->write_proc = spi_eeprom_write_proc; 215 - entry->data = (void *)chipid; 216 - } 217 - } 218 - #endif /* CONFIG_PROC_FS */
-164
arch/mips/tx4938/toshiba_rbtx4938/spi_txx9.c
··· 1 - /* 2 - * linux/arch/mips/tx4938/toshiba_rbtx4938/spi_txx9.c 3 - * Copyright (C) 2000-2001 Toshiba Corporation 4 - * 5 - * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the 6 - * terms of the GNU General Public License version 2. This program is 7 - * licensed "as is" without any warranty of any kind, whether express 8 - * or implied. 9 - * 10 - * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com) 11 - */ 12 - #include <linux/init.h> 13 - #include <linux/delay.h> 14 - #include <linux/errno.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/module.h> 17 - #include <linux/sched.h> 18 - #include <linux/spinlock.h> 19 - #include <linux/wait.h> 20 - #include <asm/tx4938/spi.h> 21 - #include <asm/tx4938/tx4938.h> 22 - 23 - static int (*txx9_spi_cs_func)(int chipid, int on); 24 - static DEFINE_SPINLOCK(txx9_spi_lock); 25 - 26 - extern unsigned int txx9_gbus_clock; 27 - 28 - #define SPI_FIFO_SIZE 4 29 - 30 - void __init txx9_spi_init(unsigned long base, int (*cs_func)(int chipid, int on)) 31 - { 32 - txx9_spi_cs_func = cs_func; 33 - /* enter config mode */ 34 - tx4938_spiptr->mcr = TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR; 35 - } 36 - 37 - static DECLARE_WAIT_QUEUE_HEAD(txx9_spi_wait); 38 - 39 - static irqreturn_t txx9_spi_interrupt(int irq, void *dev_id) 40 - { 41 - /* disable rx intr */ 42 - tx4938_spiptr->cr0 &= ~TXx9_SPCR0_RBSIE; 43 - wake_up(&txx9_spi_wait); 44 - 45 - return IRQ_HANDLED; 46 - } 47 - 48 - static struct irqaction txx9_spi_action = { 49 - .handler = txx9_spi_interrupt, 50 - .name = "spi", 51 - }; 52 - 53 - void __init txx9_spi_irqinit(int irc_irq) 54 - { 55 - setup_irq(irc_irq, &txx9_spi_action); 56 - } 57 - 58 - int txx9_spi_io(int chipid, struct spi_dev_desc *desc, 59 - unsigned char **inbufs, unsigned int *incounts, 60 - unsigned char **outbufs, unsigned int *outcounts, 61 - int cansleep) 62 - { 63 - unsigned int incount, outcount; 64 - unsigned char *inp, *outp; 65 - int ret; 66 - unsigned long flags; 67 - 68 - spin_lock_irqsave(&txx9_spi_lock, flags); 69 - if ((tx4938_spiptr->mcr & TXx9_SPMCR_OPMODE) == TXx9_SPMCR_ACTIVE) { 70 - spin_unlock_irqrestore(&txx9_spi_lock, flags); 71 - return -EBUSY; 72 - } 73 - /* enter config mode */ 74 - tx4938_spiptr->mcr = TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR; 75 - tx4938_spiptr->cr0 = 76 - (desc->byteorder ? TXx9_SPCR0_SBOS : 0) | 77 - (desc->polarity ? TXx9_SPCR0_SPOL : 0) | 78 - (desc->phase ? TXx9_SPCR0_SPHA : 0) | 79 - 0x08; 80 - tx4938_spiptr->cr1 = 81 - (((TXX9_IMCLK + desc->baud) / (2 * desc->baud) - 1) << 8) | 82 - 0x08 /* 8 bit only */; 83 - /* enter active mode */ 84 - tx4938_spiptr->mcr = TXx9_SPMCR_ACTIVE; 85 - spin_unlock_irqrestore(&txx9_spi_lock, flags); 86 - 87 - /* CS ON */ 88 - if ((ret = txx9_spi_cs_func(chipid, 1)) < 0) { 89 - spin_unlock_irqrestore(&txx9_spi_lock, flags); 90 - return ret; 91 - } 92 - udelay(desc->tcss); 93 - 94 - /* do scatter IO */ 95 - inp = inbufs ? *inbufs : NULL; 96 - outp = outbufs ? *outbufs : NULL; 97 - incount = 0; 98 - outcount = 0; 99 - while (1) { 100 - unsigned char data; 101 - unsigned int count; 102 - int i; 103 - if (!incount) { 104 - incount = incounts ? *incounts++ : 0; 105 - inp = (incount && inbufs) ? *inbufs++ : NULL; 106 - } 107 - if (!outcount) { 108 - outcount = outcounts ? *outcounts++ : 0; 109 - outp = (outcount && outbufs) ? *outbufs++ : NULL; 110 - } 111 - if (!inp && !outp) 112 - break; 113 - count = SPI_FIFO_SIZE; 114 - if (incount) 115 - count = min(count, incount); 116 - if (outcount) 117 - count = min(count, outcount); 118 - 119 - /* now tx must be idle... */ 120 - while (!(tx4938_spiptr->sr & TXx9_SPSR_SIDLE)) 121 - ; 122 - 123 - tx4938_spiptr->cr0 = 124 - (tx4938_spiptr->cr0 & ~TXx9_SPCR0_RXIFL_MASK) | 125 - ((count - 1) << 12); 126 - if (cansleep) { 127 - /* enable rx intr */ 128 - tx4938_spiptr->cr0 |= TXx9_SPCR0_RBSIE; 129 - } 130 - /* send */ 131 - for (i = 0; i < count; i++) 132 - tx4938_spiptr->dr = inp ? *inp++ : 0; 133 - /* wait all rx data */ 134 - if (cansleep) { 135 - wait_event(txx9_spi_wait, 136 - tx4938_spiptr->sr & TXx9_SPSR_SRRDY); 137 - } else { 138 - while (!(tx4938_spiptr->sr & TXx9_SPSR_RBSI)) 139 - ; 140 - } 141 - /* receive */ 142 - for (i = 0; i < count; i++) { 143 - data = tx4938_spiptr->dr; 144 - if (outp) 145 - *outp++ = data; 146 - } 147 - if (incount) 148 - incount -= count; 149 - if (outcount) 150 - outcount -= count; 151 - } 152 - 153 - /* CS OFF */ 154 - udelay(desc->tcsh); 155 - txx9_spi_cs_func(chipid, 0); 156 - udelay(desc->tcsr); 157 - 158 - spin_lock_irqsave(&txx9_spi_lock, flags); 159 - /* enter config mode */ 160 - tx4938_spiptr->mcr = TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR; 161 - spin_unlock_irqrestore(&txx9_spi_lock, flags); 162 - 163 - return 0; 164 - }
-6
include/asm-mips/tx4938/rbtx4938.h
··· 105 105 #define rbtx4938_pcireset_ptr \ 106 106 ((volatile unsigned char *)RBTX4938_PCIRESET_ADDR) 107 107 108 - /* SPI */ 109 - #define RBTX4938_SEEPROM1_CHIPID 0 110 - #define RBTX4938_SEEPROM2_CHIPID 1 111 - #define RBTX4938_SEEPROM3_CHIPID 2 112 - #define RBTX4938_SRTC_CHIPID 3 113 - 114 108 /* 115 109 * IRQ mappings 116 110 */
+1 -55
include/asm-mips/tx4938/spi.h
··· 14 14 #ifndef __ASM_TX_BOARDS_TX4938_SPI_H 15 15 #define __ASM_TX_BOARDS_TX4938_SPI_H 16 16 17 - /* SPI */ 18 - struct spi_dev_desc { 19 - unsigned int baud; 20 - unsigned short tcss, tcsh, tcsr; /* CS setup/hold/recovery time */ 21 - unsigned int byteorder:1; /* 0:LSB-First, 1:MSB-First */ 22 - unsigned int polarity:1; /* 0:High-Active */ 23 - unsigned int phase:1; /* 0:Sample-Then-Shift */ 24 - }; 25 - 26 - extern void txx9_spi_init(unsigned long base, int (*cs_func)(int chipid, int on)) __init; 27 - extern void txx9_spi_irqinit(int irc_irq) __init; 28 - extern int txx9_spi_io(int chipid, struct spi_dev_desc *desc, 29 - unsigned char **inbufs, unsigned int *incounts, 30 - unsigned char **outbufs, unsigned int *outcounts, 31 - int cansleep); 32 - extern int spi_eeprom_write_enable(int chipid, int enable); 33 - extern int spi_eeprom_read_status(int chipid); 17 + extern int spi_eeprom_register(int chipid); 34 18 extern int spi_eeprom_read(int chipid, int address, unsigned char *buf, int len); 35 - extern int spi_eeprom_write(int chipid, int address, unsigned char *buf, int len); 36 - extern void spi_eeprom_proc_create(struct proc_dir_entry *dir, int chipid) __init; 37 - 38 - #define TXX9_IMCLK (txx9_gbus_clock / 2) 39 - 40 - /* 41 - * SPI 42 - */ 43 - 44 - /* SPMCR : SPI Master Control */ 45 - #define TXx9_SPMCR_OPMODE 0xc0 46 - #define TXx9_SPMCR_CONFIG 0x40 47 - #define TXx9_SPMCR_ACTIVE 0x80 48 - #define TXx9_SPMCR_SPSTP 0x02 49 - #define TXx9_SPMCR_BCLR 0x01 50 - 51 - /* SPCR0 : SPI Status */ 52 - #define TXx9_SPCR0_TXIFL_MASK 0xc000 53 - #define TXx9_SPCR0_RXIFL_MASK 0x3000 54 - #define TXx9_SPCR0_SIDIE 0x0800 55 - #define TXx9_SPCR0_SOEIE 0x0400 56 - #define TXx9_SPCR0_RBSIE 0x0200 57 - #define TXx9_SPCR0_TBSIE 0x0100 58 - #define TXx9_SPCR0_IFSPSE 0x0010 59 - #define TXx9_SPCR0_SBOS 0x0004 60 - #define TXx9_SPCR0_SPHA 0x0002 61 - #define TXx9_SPCR0_SPOL 0x0001 62 - 63 - /* SPSR : SPI Status */ 64 - #define TXx9_SPSR_TBSI 0x8000 65 - #define TXx9_SPSR_RBSI 0x4000 66 - #define TXx9_SPSR_TBS_MASK 0x3800 67 - #define TXx9_SPSR_RBS_MASK 0x0700 68 - #define TXx9_SPSR_SPOE 0x0080 69 - #define TXx9_SPSR_IFSD 0x0008 70 - #define TXx9_SPSR_SIDLE 0x0004 71 - #define TXx9_SPSR_STRDY 0x0002 72 - #define TXx9_SPSR_SRRDY 0x0001 73 19 74 20 #endif /* __ASM_TX_BOARDS_TX4938_SPI_H */