SM501: Check SM501 ID register on initialisation

When binding the driver, check the ID register for a valid identity, in case
the SM501 is not functioning correctly.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Ben Dooks and committed by Linus Torvalds 1e27dbe7 ffd65af0

+13 -4
+10 -4
drivers/mfd/sm501.c
··· 893 893 { 894 894 resource_size_t mem_avail; 895 895 unsigned long dramctrl; 896 + unsigned long devid; 896 897 int ret; 897 898 898 899 mutex_init(&sm->clock_lock); ··· 901 900 902 901 INIT_LIST_HEAD(&sm->devices); 903 902 904 - dramctrl = readl(sm->regs + SM501_DRAM_CONTROL); 903 + devid = readl(sm->regs + SM501_DEVICEID); 905 904 905 + if ((devid & SM501_DEVICEID_IDMASK) != SM501_DEVICEID_SM501) { 906 + dev_err(sm->dev, "incorrect device id %08lx\n", devid); 907 + return -EINVAL; 908 + } 909 + 910 + dramctrl = readl(sm->regs + SM501_DRAM_CONTROL); 906 911 mem_avail = sm501_mem_local[(dramctrl >> 13) & 0x7]; 907 912 908 - dev_info(sm->dev, "SM501 At %p: Version %08x, %ld Mb, IRQ %d\n", 909 - sm->regs, readl(sm->regs + SM501_DEVICEID), 910 - (unsigned long)mem_avail >> 20, sm->irq); 913 + dev_info(sm->dev, "SM501 At %p: Version %08lx, %ld Mb, IRQ %d\n", 914 + sm->regs, devid, (unsigned long)mem_avail >> 20, sm->irq); 911 915 912 916 sm501_dump_gate(sm); 913 917
+3
include/linux/sm501-regs.h
··· 109 109 #define SM501_DEVICEID (0x000060) 110 110 /* 0x050100A0 */ 111 111 112 + #define SM501_DEVICEID_SM501 (0x05010000) 113 + #define SM501_DEVICEID_IDMASK (0xffff0000) 114 + 112 115 #define SM501_PLLCLOCK_COUNT (0x000064) 113 116 #define SM501_MISC_TIMING (0x000068) 114 117 #define SM501_CURRENT_SDRAM_CLOCK (0x00006C)