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

Merge branch 'sa11x0-mcp' into sa11x0

Conflicts:
arch/arm/mach-sa1100/assabet.c
arch/arm/mach-sa1100/collie.c
arch/arm/mach-sa1100/generic.c
arch/arm/mach-sa1100/lart.c
arch/arm/mach-sa1100/shannon.c

+525 -364
+15
arch/arm/mach-sa1100/assabet.c
··· 15 15 #include <linux/errno.h> 16 16 #include <linux/ioport.h> 17 17 #include <linux/serial_core.h> 18 + #include <linux/mfd/ucb1x00.h> 18 19 #include <linux/mtd/mtd.h> 19 20 #include <linux/mtd/partitions.h> 20 21 #include <linux/delay.h> ··· 71 70 } 72 71 73 72 EXPORT_SYMBOL(ASSABET_BCR_frob); 73 + 74 + static void assabet_ucb1x00_reset(enum ucb1x00_reset state) 75 + { 76 + if (state == UCB_RST_PROBE) 77 + ASSABET_BCR_set(ASSABET_BCR_CODEC_RST); 78 + } 74 79 75 80 76 81 /* ··· 174 167 .set_speed = assabet_irda_set_speed, 175 168 }; 176 169 170 + static struct ucb1x00_plat_data assabet_ucb1x00_data = { 171 + .reset = assabet_ucb1x00_reset, 172 + .gpio_base = -1, 173 + }; 174 + 177 175 static struct mcp_plat_data assabet_mcp_data = { 178 176 .mccr0 = MCCR0_ADM, 179 177 .sclk_rate = 11981000, 178 + .codec_pdata = &assabet_ucb1x00_data, 180 179 }; 181 180 182 181 static void assabet_lcd_set_visual(u32 visual) ··· 321 308 PSDR = 0; 322 309 PPDR |= PPC_TXD3 | PPC_TXD1; 323 310 PPSR |= PPC_TXD3 | PPC_TXD1; 311 + 312 + sa11x0_ppc_configure_mcp(); 324 313 325 314 if (machine_has_neponset()) { 326 315 /*
+1
arch/arm/mach-sa1100/cerf.c
··· 121 121 122 122 static void __init cerf_init(void) 123 123 { 124 + sa11x0_ppc_configure_mcp(); 124 125 platform_add_devices(cerf_devices, ARRAY_SIZE(cerf_devices)); 125 126 sa11x0_register_mtd(&cerf_flash_data, &cerf_flash_resource, 1); 126 127 sa11x0_register_mcp(&cerf_mcp_data);
+10 -1
arch/arm/mach-sa1100/collie.c
··· 22 22 #include <linux/tty.h> 23 23 #include <linux/delay.h> 24 24 #include <linux/platform_device.h> 25 + #include <linux/mfd/ucb1x00.h> 25 26 #include <linux/mtd/mtd.h> 26 27 #include <linux/mtd/partitions.h> 27 28 #include <linux/timer.h> ··· 84 83 .num_devs = 1, 85 84 }; 86 85 86 + static struct ucb1x00_plat_data collie_ucb1x00_data = { 87 + .gpio_base = COLLIE_TC35143_GPIO_BASE, 88 + }; 89 + 87 90 static struct mcp_plat_data collie_mcp_data = { 88 91 .mccr0 = MCCR0_ADM | MCCR0_ExtClk, 89 92 .sclk_rate = 9216000, 90 - .gpio_base = COLLIE_TC35143_GPIO_BASE, 93 + .codec_pdata = &collie_ucb1x00_data, 91 94 }; 92 95 93 96 /* ··· 346 341 347 342 collie_power_resource[0].start = gpio_to_irq(COLLIE_GPIO_AC_IN); 348 343 collie_power_resource[0].end = gpio_to_irq(COLLIE_GPIO_AC_IN); 344 + 345 + sa11x0_ppc_configure_mcp(); 346 + 347 + 349 348 platform_scoop_config = &collie_pcmcia_config; 350 349 351 350 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
+12 -1
arch/arm/mach-sa1100/generic.c
··· 195 195 196 196 static struct resource sa11x0mcp_resources[] = { 197 197 [0] = DEFINE_RES_MEM(__PREG(Ser4MCCR0), SZ_64K), 198 - [1] = DEFINE_RES_IRQ(IRQ_Ser4MCP), 198 + [1] = DEFINE_RES_MEM(__PREG(Ser4MCCR1), 4), 199 + [2] = DEFINE_RES_IRQ(IRQ_Ser4MCP), 199 200 }; 200 201 201 202 static u64 sa11x0mcp_dma_mask = 0xffffffffUL; ··· 211 210 .num_resources = ARRAY_SIZE(sa11x0mcp_resources), 212 211 .resource = sa11x0mcp_resources, 213 212 }; 213 + 214 + void __init sa11x0_ppc_configure_mcp(void) 215 + { 216 + /* Setup the PPC unit for the MCP */ 217 + PPDR &= ~PPC_RXD4; 218 + PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM; 219 + PSDR |= PPC_RXD4; 220 + PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM); 221 + PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM); 222 + } 214 223 215 224 void sa11x0_register_mcp(struct mcp_plat_data *data) 216 225 {
+1
arch/arm/mach-sa1100/generic.h
··· 36 36 void sa11x0_register_irda(struct irda_platform_data *irda); 37 37 38 38 struct mcp_plat_data; 39 + void sa11x0_ppc_configure_mcp(void); 39 40 void sa11x0_register_mcp(struct mcp_plat_data *data); 40 41 41 42 struct sa1100fb_mach_info;
+1 -1
arch/arm/mach-sa1100/include/mach/mcp.h
··· 16 16 u32 mccr0; 17 17 u32 mccr1; 18 18 unsigned int sclk_rate; 19 - int gpio_base; 19 + void *codec_pdata; 20 20 }; 21 21 22 22 #endif
+1
arch/arm/mach-sa1100/lart.c
··· 107 107 if (inf) 108 108 sa11x0_register_lcd(inf); 109 109 110 + sa11x0_ppc_configure_mcp(); 110 111 sa11x0_register_mcp(&lart_mcp_data); 111 112 } 112 113
+1
arch/arm/mach-sa1100/shannon.c
··· 72 72 73 73 static void __init shannon_init(void) 74 74 { 75 + sa11x0_ppc_configure_mcp(); 75 76 sa11x0_register_lcd(&shannon_lcd_info); 76 77 sa11x0_register_mtd(&shannon_flash_data, &shannon_flash_resource, 1); 77 78 sa11x0_register_mcp(&shannon_mcp_data);
+7 -1
arch/arm/mach-sa1100/simpad.c
··· 10 10 #include <linux/string.h> 11 11 #include <linux/pm.h> 12 12 #include <linux/platform_device.h> 13 + #include <linux/mfd/ucb1x00.h> 13 14 #include <linux/mtd/mtd.h> 14 15 #include <linux/mtd/partitions.h> 15 16 #include <linux/io.h> ··· 181 180 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_16M), 182 181 }; 183 182 183 + static struct ucb1x00_plat_data simpad_ucb1x00_data = { 184 + .gpio_base = SIMPAD_UCB1X00_GPIO_BASE, 185 + }; 186 + 184 187 static struct mcp_plat_data simpad_mcp_data = { 185 188 .mccr0 = MCCR0_ADM, 186 189 .sclk_rate = 11981000, 187 - .gpio_base = SIMPAD_UCB1X00_GPIO_BASE, 190 + .codec_pdata = &simpad_ucb1x00_data, 188 191 }; 189 192 190 193 ··· 374 369 375 370 pm_power_off = simpad_power_off; 376 371 372 + sa11x0_ppc_configure_mcp(); 377 373 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources, 378 374 ARRAY_SIZE(simpad_flash_resources)); 379 375 sa11x0_register_mcp(&simpad_mcp_data);
+3 -2
drivers/mfd/Kconfig
··· 847 847 848 848 # Chip drivers 849 849 config MCP_UCB1200 850 - tristate "Support for UCB1200 / UCB1300" 851 - depends on MCP 850 + bool "Support for UCB1200 / UCB1300" 851 + depends on MCP_SA11X0 852 + select MCP 852 853 853 854 config MCP_UCB1200_TS 854 855 tristate "Touchscreen interface support"
+14 -35
drivers/mfd/mcp-core.c
··· 19 19 #include <linux/string.h> 20 20 #include <linux/mfd/mcp.h> 21 21 22 - #include <mach/dma.h> 23 22 #include <asm/system.h> 24 23 25 24 ··· 47 48 return 0; 48 49 } 49 50 50 - static int mcp_bus_suspend(struct device *dev, pm_message_t state) 51 - { 52 - struct mcp *mcp = to_mcp(dev); 53 - int ret = 0; 54 - 55 - if (dev->driver) { 56 - struct mcp_driver *drv = to_mcp_driver(dev->driver); 57 - 58 - ret = drv->suspend(mcp, state); 59 - } 60 - return ret; 61 - } 62 - 63 - static int mcp_bus_resume(struct device *dev) 64 - { 65 - struct mcp *mcp = to_mcp(dev); 66 - int ret = 0; 67 - 68 - if (dev->driver) { 69 - struct mcp_driver *drv = to_mcp_driver(dev->driver); 70 - 71 - ret = drv->resume(mcp); 72 - } 73 - return ret; 74 - } 75 - 76 51 static struct bus_type mcp_bus_type = { 77 52 .name = "mcp", 78 53 .match = mcp_bus_match, 79 54 .probe = mcp_bus_probe, 80 55 .remove = mcp_bus_remove, 81 - .suspend = mcp_bus_suspend, 82 - .resume = mcp_bus_resume, 83 56 }; 84 57 85 58 /** ··· 179 208 mcp = kzalloc(sizeof(struct mcp) + size, GFP_KERNEL); 180 209 if (mcp) { 181 210 spin_lock_init(&mcp->lock); 211 + device_initialize(&mcp->attached_device); 182 212 mcp->attached_device.parent = parent; 183 213 mcp->attached_device.bus = &mcp_bus_type; 184 214 mcp->attached_device.dma_mask = parent->dma_mask; ··· 189 217 } 190 218 EXPORT_SYMBOL(mcp_host_alloc); 191 219 192 - int mcp_host_register(struct mcp *mcp) 220 + int mcp_host_add(struct mcp *mcp, void *pdata) 193 221 { 222 + mcp->attached_device.platform_data = pdata; 194 223 dev_set_name(&mcp->attached_device, "mcp0"); 195 - return device_register(&mcp->attached_device); 224 + return device_add(&mcp->attached_device); 196 225 } 197 - EXPORT_SYMBOL(mcp_host_register); 226 + EXPORT_SYMBOL(mcp_host_add); 198 227 199 - void mcp_host_unregister(struct mcp *mcp) 228 + void mcp_host_del(struct mcp *mcp) 200 229 { 201 - device_unregister(&mcp->attached_device); 230 + device_del(&mcp->attached_device); 202 231 } 203 - EXPORT_SYMBOL(mcp_host_unregister); 232 + EXPORT_SYMBOL(mcp_host_del); 233 + 234 + void mcp_host_free(struct mcp *mcp) 235 + { 236 + put_device(&mcp->attached_device); 237 + } 238 + EXPORT_SYMBOL(mcp_host_free); 204 239 205 240 int mcp_driver_register(struct mcp_driver *mcpdrv) 206 241 {
+126 -70
drivers/mfd/mcp-sa11x0.c
··· 13 13 */ 14 14 #include <linux/module.h> 15 15 #include <linux/init.h> 16 + #include <linux/io.h> 16 17 #include <linux/errno.h> 17 18 #include <linux/kernel.h> 18 19 #include <linux/delay.h> 19 20 #include <linux/spinlock.h> 20 21 #include <linux/platform_device.h> 22 + #include <linux/pm.h> 21 23 #include <linux/mfd/mcp.h> 22 24 23 - #include <mach/dma.h> 24 25 #include <mach/hardware.h> 25 26 #include <asm/mach-types.h> 26 27 #include <asm/system.h> 27 28 #include <mach/mcp.h> 28 29 29 - #include <mach/assabet.h> 30 - 30 + #define DRIVER_NAME "sa11x0-mcp" 31 31 32 32 struct mcp_sa11x0 { 33 - u32 mccr0; 34 - u32 mccr1; 33 + void __iomem *base0; 34 + void __iomem *base1; 35 + u32 mccr0; 36 + u32 mccr1; 35 37 }; 38 + 39 + /* Register offsets */ 40 + #define MCCR0(m) ((m)->base0 + 0x00) 41 + #define MCDR0(m) ((m)->base0 + 0x08) 42 + #define MCDR1(m) ((m)->base0 + 0x0c) 43 + #define MCDR2(m) ((m)->base0 + 0x10) 44 + #define MCSR(m) ((m)->base0 + 0x18) 45 + #define MCCR1(m) ((m)->base1 + 0x00) 36 46 37 47 #define priv(mcp) ((struct mcp_sa11x0 *)mcp_priv(mcp)) 38 48 39 49 static void 40 50 mcp_sa11x0_set_telecom_divisor(struct mcp *mcp, unsigned int divisor) 41 51 { 42 - unsigned int mccr0; 52 + struct mcp_sa11x0 *m = priv(mcp); 43 53 44 54 divisor /= 32; 45 55 46 - mccr0 = Ser4MCCR0 & ~0x00007f00; 47 - mccr0 |= divisor << 8; 48 - Ser4MCCR0 = mccr0; 56 + m->mccr0 &= ~0x00007f00; 57 + m->mccr0 |= divisor << 8; 58 + writel_relaxed(m->mccr0, MCCR0(m)); 49 59 } 50 60 51 61 static void 52 62 mcp_sa11x0_set_audio_divisor(struct mcp *mcp, unsigned int divisor) 53 63 { 54 - unsigned int mccr0; 64 + struct mcp_sa11x0 *m = priv(mcp); 55 65 56 66 divisor /= 32; 57 67 58 - mccr0 = Ser4MCCR0 & ~0x0000007f; 59 - mccr0 |= divisor; 60 - Ser4MCCR0 = mccr0; 68 + m->mccr0 &= ~0x0000007f; 69 + m->mccr0 |= divisor; 70 + writel_relaxed(m->mccr0, MCCR0(m)); 61 71 } 62 72 63 73 /* ··· 79 69 static void 80 70 mcp_sa11x0_write(struct mcp *mcp, unsigned int reg, unsigned int val) 81 71 { 72 + struct mcp_sa11x0 *m = priv(mcp); 82 73 int ret = -ETIME; 83 74 int i; 84 75 85 - Ser4MCDR2 = reg << 17 | MCDR2_Wr | (val & 0xffff); 76 + writel_relaxed(reg << 17 | MCDR2_Wr | (val & 0xffff), MCDR2(m)); 86 77 87 78 for (i = 0; i < 2; i++) { 88 79 udelay(mcp->rw_timeout); 89 - if (Ser4MCSR & MCSR_CWC) { 80 + if (readl_relaxed(MCSR(m)) & MCSR_CWC) { 90 81 ret = 0; 91 82 break; 92 83 } ··· 106 95 static unsigned int 107 96 mcp_sa11x0_read(struct mcp *mcp, unsigned int reg) 108 97 { 98 + struct mcp_sa11x0 *m = priv(mcp); 109 99 int ret = -ETIME; 110 100 int i; 111 101 112 - Ser4MCDR2 = reg << 17 | MCDR2_Rd; 102 + writel_relaxed(reg << 17 | MCDR2_Rd, MCDR2(m)); 113 103 114 104 for (i = 0; i < 2; i++) { 115 105 udelay(mcp->rw_timeout); 116 - if (Ser4MCSR & MCSR_CRC) { 117 - ret = Ser4MCDR2 & 0xffff; 106 + if (readl_relaxed(MCSR(m)) & MCSR_CRC) { 107 + ret = readl_relaxed(MCDR2(m)) & 0xffff; 118 108 break; 119 109 } 120 110 } ··· 128 116 129 117 static void mcp_sa11x0_enable(struct mcp *mcp) 130 118 { 131 - Ser4MCSR = -1; 132 - Ser4MCCR0 |= MCCR0_MCE; 119 + struct mcp_sa11x0 *m = priv(mcp); 120 + 121 + writel(-1, MCSR(m)); 122 + m->mccr0 |= MCCR0_MCE; 123 + writel_relaxed(m->mccr0, MCCR0(m)); 133 124 } 134 125 135 126 static void mcp_sa11x0_disable(struct mcp *mcp) 136 127 { 137 - Ser4MCCR0 &= ~MCCR0_MCE; 128 + struct mcp_sa11x0 *m = priv(mcp); 129 + 130 + m->mccr0 &= ~MCCR0_MCE; 131 + writel_relaxed(m->mccr0, MCCR0(m)); 138 132 } 139 133 140 134 /* ··· 155 137 .disable = mcp_sa11x0_disable, 156 138 }; 157 139 158 - static int mcp_sa11x0_probe(struct platform_device *pdev) 140 + static int mcp_sa11x0_probe(struct platform_device *dev) 159 141 { 160 - struct mcp_plat_data *data = pdev->dev.platform_data; 142 + struct mcp_plat_data *data = dev->dev.platform_data; 143 + struct resource *mem0, *mem1; 144 + struct mcp_sa11x0 *m; 161 145 struct mcp *mcp; 162 146 int ret; 163 147 164 148 if (!data) 165 149 return -ENODEV; 166 150 167 - if (!request_mem_region(0x80060000, 0x60, "sa11x0-mcp")) 168 - return -EBUSY; 151 + mem0 = platform_get_resource(dev, IORESOURCE_MEM, 0); 152 + mem1 = platform_get_resource(dev, IORESOURCE_MEM, 1); 153 + if (!mem0 || !mem1) 154 + return -ENXIO; 169 155 170 - mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0)); 156 + if (!request_mem_region(mem0->start, resource_size(mem0), 157 + DRIVER_NAME)) { 158 + ret = -EBUSY; 159 + goto err_mem0; 160 + } 161 + 162 + if (!request_mem_region(mem1->start, resource_size(mem1), 163 + DRIVER_NAME)) { 164 + ret = -EBUSY; 165 + goto err_mem1; 166 + } 167 + 168 + mcp = mcp_host_alloc(&dev->dev, sizeof(struct mcp_sa11x0)); 171 169 if (!mcp) { 172 170 ret = -ENOMEM; 173 - goto release; 171 + goto err_alloc; 174 172 } 175 173 176 174 mcp->owner = THIS_MODULE; 177 175 mcp->ops = &mcp_sa11x0; 178 176 mcp->sclk_rate = data->sclk_rate; 179 - mcp->dma_audio_rd = DMA_Ser4MCP0Rd; 180 - mcp->dma_audio_wr = DMA_Ser4MCP0Wr; 181 - mcp->dma_telco_rd = DMA_Ser4MCP1Rd; 182 - mcp->dma_telco_wr = DMA_Ser4MCP1Wr; 183 - mcp->gpio_base = data->gpio_base; 184 177 185 - platform_set_drvdata(pdev, mcp); 178 + m = priv(mcp); 179 + m->mccr0 = data->mccr0 | 0x7f7f; 180 + m->mccr1 = data->mccr1; 186 181 187 - if (machine_is_assabet()) { 188 - ASSABET_BCR_set(ASSABET_BCR_CODEC_RST); 182 + m->base0 = ioremap(mem0->start, resource_size(mem0)); 183 + m->base1 = ioremap(mem1->start, resource_size(mem1)); 184 + if (!m->base0 || !m->base1) { 185 + ret = -ENOMEM; 186 + goto err_ioremap; 189 187 } 190 188 191 - /* 192 - * Setup the PPC unit correctly. 193 - */ 194 - PPDR &= ~PPC_RXD4; 195 - PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM; 196 - PSDR |= PPC_RXD4; 197 - PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM); 198 - PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM); 189 + platform_set_drvdata(dev, mcp); 199 190 200 191 /* 201 192 * Initialise device. Note that we initially 202 193 * set the sampling rate to minimum. 203 194 */ 204 - Ser4MCSR = -1; 205 - Ser4MCCR1 = data->mccr1; 206 - Ser4MCCR0 = data->mccr0 | 0x7f7f; 195 + writel_relaxed(-1, MCSR(m)); 196 + writel_relaxed(m->mccr1, MCCR1(m)); 197 + writel_relaxed(m->mccr0, MCCR0(m)); 207 198 208 199 /* 209 200 * Calculate the read/write timeout (us) from the bit clock ··· 222 195 mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) / 223 196 mcp->sclk_rate; 224 197 225 - ret = mcp_host_register(mcp); 198 + ret = mcp_host_add(mcp, data->codec_pdata); 226 199 if (ret == 0) 227 - goto out; 200 + return 0; 228 201 229 - release: 230 - release_mem_region(0x80060000, 0x60); 231 - platform_set_drvdata(pdev, NULL); 202 + platform_set_drvdata(dev, NULL); 232 203 233 - out: 204 + err_ioremap: 205 + iounmap(m->base1); 206 + iounmap(m->base0); 207 + mcp_host_free(mcp); 208 + err_alloc: 209 + release_mem_region(mem1->start, resource_size(mem1)); 210 + err_mem1: 211 + release_mem_region(mem0->start, resource_size(mem0)); 212 + err_mem0: 234 213 return ret; 235 214 } 236 215 237 216 static int mcp_sa11x0_remove(struct platform_device *dev) 238 217 { 239 218 struct mcp *mcp = platform_get_drvdata(dev); 219 + struct mcp_sa11x0 *m = priv(mcp); 220 + struct resource *mem0, *mem1; 221 + 222 + if (m->mccr0 & MCCR0_MCE) 223 + dev_warn(&dev->dev, 224 + "device left active (missing disable call?)\n"); 225 + 226 + mem0 = platform_get_resource(dev, IORESOURCE_MEM, 0); 227 + mem1 = platform_get_resource(dev, IORESOURCE_MEM, 1); 240 228 241 229 platform_set_drvdata(dev, NULL); 242 - mcp_host_unregister(mcp); 243 - release_mem_region(0x80060000, 0x60); 230 + mcp_host_del(mcp); 231 + iounmap(m->base1); 232 + iounmap(m->base0); 233 + mcp_host_free(mcp); 234 + release_mem_region(mem1->start, resource_size(mem1)); 235 + release_mem_region(mem0->start, resource_size(mem0)); 244 236 245 237 return 0; 246 238 } 247 239 248 - static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state) 240 + #ifdef CONFIG_PM_SLEEP 241 + static int mcp_sa11x0_suspend(struct device *dev) 249 242 { 250 - struct mcp *mcp = platform_get_drvdata(dev); 243 + struct mcp_sa11x0 *m = priv(dev_get_drvdata(dev)); 251 244 252 - priv(mcp)->mccr0 = Ser4MCCR0; 253 - priv(mcp)->mccr1 = Ser4MCCR1; 254 - Ser4MCCR0 &= ~MCCR0_MCE; 245 + if (m->mccr0 & MCCR0_MCE) 246 + dev_warn(dev, "device left active (missing disable call?)\n"); 247 + 248 + writel(m->mccr0 & ~MCCR0_MCE, MCCR0(m)); 255 249 256 250 return 0; 257 251 } 258 252 259 - static int mcp_sa11x0_resume(struct platform_device *dev) 253 + static int mcp_sa11x0_resume(struct device *dev) 260 254 { 261 - struct mcp *mcp = platform_get_drvdata(dev); 255 + struct mcp_sa11x0 *m = priv(dev_get_drvdata(dev)); 262 256 263 - Ser4MCCR1 = priv(mcp)->mccr1; 264 - Ser4MCCR0 = priv(mcp)->mccr0; 257 + writel_relaxed(m->mccr1, MCCR1(m)); 258 + writel_relaxed(m->mccr0, MCCR0(m)); 265 259 266 260 return 0; 267 261 } 262 + #endif 268 263 269 - /* 270 - * The driver for the SA11x0 MCP port. 271 - */ 272 - MODULE_ALIAS("platform:sa11x0-mcp"); 264 + static const struct dev_pm_ops mcp_sa11x0_pm_ops = { 265 + #ifdef CONFIG_PM_SLEEP 266 + .suspend = mcp_sa11x0_suspend, 267 + .freeze = mcp_sa11x0_suspend, 268 + .poweroff = mcp_sa11x0_suspend, 269 + .resume_noirq = mcp_sa11x0_resume, 270 + .thaw_noirq = mcp_sa11x0_resume, 271 + .restore_noirq = mcp_sa11x0_resume, 272 + #endif 273 + }; 273 274 274 275 static struct platform_driver mcp_sa11x0_driver = { 275 276 .probe = mcp_sa11x0_probe, 276 277 .remove = mcp_sa11x0_remove, 277 - .suspend = mcp_sa11x0_suspend, 278 - .resume = mcp_sa11x0_resume, 279 278 .driver = { 280 - .name = "sa11x0-mcp", 279 + .name = DRIVER_NAME, 280 + .owner = THIS_MODULE, 281 + .pm = &mcp_sa11x0_pm_ops, 281 282 }, 282 283 }; 283 284 ··· 314 259 */ 315 260 module_platform_driver(mcp_sa11x0_driver); 316 261 262 + MODULE_ALIAS("platform:" DRIVER_NAME); 317 263 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 318 264 MODULE_DESCRIPTION("SA11x0 multimedia communications port driver"); 319 265 MODULE_LICENSE("GPL");
+40 -8
drivers/mfd/ucb1x00-assabet.c
··· 11 11 */ 12 12 #include <linux/module.h> 13 13 #include <linux/init.h> 14 - #include <linux/fs.h> 15 - #include <linux/proc_fs.h> 16 14 #include <linux/device.h> 15 + #include <linux/err.h> 16 + #include <linux/fs.h> 17 + #include <linux/gpio_keys.h> 18 + #include <linux/input.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/proc_fs.h> 17 21 #include <linux/mfd/ucb1x00.h> 18 - 19 - #include <mach/dma.h> 20 - 21 22 22 23 #define UCB1X00_ATTR(name,input)\ 23 24 static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \ ··· 39 38 40 39 static int ucb1x00_assabet_add(struct ucb1x00_dev *dev) 41 40 { 42 - device_create_file(&dev->ucb->dev, &dev_attr_vbatt); 43 - device_create_file(&dev->ucb->dev, &dev_attr_vcharger); 44 - device_create_file(&dev->ucb->dev, &dev_attr_batt_temp); 41 + struct ucb1x00 *ucb = dev->ucb; 42 + struct platform_device *pdev; 43 + struct gpio_keys_platform_data keys; 44 + static struct gpio_keys_button buttons[6]; 45 + unsigned i; 46 + 47 + memset(buttons, 0, sizeof(buttons)); 48 + memset(&keys, 0, sizeof(keys)); 49 + 50 + for (i = 0; i < ARRAY_SIZE(buttons); i++) { 51 + buttons[i].code = BTN_0 + i; 52 + buttons[i].gpio = ucb->gpio.base + i; 53 + buttons[i].type = EV_KEY; 54 + buttons[i].can_disable = true; 55 + } 56 + 57 + keys.buttons = buttons; 58 + keys.nbuttons = ARRAY_SIZE(buttons); 59 + keys.poll_interval = 50; 60 + keys.name = "ucb1x00"; 61 + 62 + pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1, 63 + &keys, sizeof(keys)); 64 + 65 + device_create_file(&ucb->dev, &dev_attr_vbatt); 66 + device_create_file(&ucb->dev, &dev_attr_vcharger); 67 + device_create_file(&ucb->dev, &dev_attr_batt_temp); 68 + 69 + dev->priv = pdev; 45 70 return 0; 46 71 } 47 72 48 73 static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev) 49 74 { 75 + struct platform_device *pdev = dev->priv; 76 + 77 + if (!IS_ERR(pdev)) 78 + platform_device_unregister(pdev); 79 + 50 80 device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp); 51 81 device_remove_file(&dev->ucb->dev, &dev_attr_vcharger); 52 82 device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
+240 -207
drivers/mfd/ucb1x00-core.c
··· 23 23 #include <linux/init.h> 24 24 #include <linux/errno.h> 25 25 #include <linux/interrupt.h> 26 + #include <linux/irq.h> 26 27 #include <linux/device.h> 27 28 #include <linux/mutex.h> 28 29 #include <linux/mfd/ucb1x00.h> 30 + #include <linux/pm.h> 29 31 #include <linux/gpio.h> 30 - #include <linux/semaphore.h> 31 - 32 - #include <mach/dma.h> 33 - #include <mach/hardware.h> 34 32 35 33 static DEFINE_MUTEX(ucb1x00_mutex); 36 34 static LIST_HEAD(ucb1x00_drivers); ··· 100 102 * ucb1x00_enable must have been called to enable the comms 101 103 * before using this function. 102 104 * 103 - * This function does not take any semaphores or spinlocks. 105 + * This function does not take any mutexes or spinlocks. 104 106 */ 105 107 unsigned int ucb1x00_io_read(struct ucb1x00 *ucb) 106 108 { ··· 118 120 else 119 121 ucb->io_out &= ~(1 << offset); 120 122 123 + ucb1x00_enable(ucb); 121 124 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); 125 + ucb1x00_disable(ucb); 122 126 spin_unlock_irqrestore(&ucb->io_lock, flags); 123 127 } 124 128 125 129 static int ucb1x00_gpio_get(struct gpio_chip *chip, unsigned offset) 126 130 { 127 131 struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio); 128 - return ucb1x00_reg_read(ucb, UCB_IO_DATA) & (1 << offset); 132 + unsigned val; 133 + 134 + ucb1x00_enable(ucb); 135 + val = ucb1x00_reg_read(ucb, UCB_IO_DATA); 136 + ucb1x00_disable(ucb); 137 + 138 + return val & (1 << offset); 129 139 } 130 140 131 141 static int ucb1x00_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ··· 143 137 144 138 spin_lock_irqsave(&ucb->io_lock, flags); 145 139 ucb->io_dir &= ~(1 << offset); 140 + ucb1x00_enable(ucb); 146 141 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); 142 + ucb1x00_disable(ucb); 147 143 spin_unlock_irqrestore(&ucb->io_lock, flags); 148 144 149 145 return 0; ··· 165 157 else 166 158 ucb->io_out &= ~mask; 167 159 160 + ucb1x00_enable(ucb); 168 161 if (old != ucb->io_out) 169 162 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); 170 163 ··· 173 164 ucb->io_dir |= mask; 174 165 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); 175 166 } 167 + ucb1x00_disable(ucb); 176 168 spin_unlock_irqrestore(&ucb->io_lock, flags); 177 169 178 170 return 0; 171 + } 172 + 173 + static int ucb1x00_to_irq(struct gpio_chip *chip, unsigned offset) 174 + { 175 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio); 176 + 177 + return ucb->irq_base > 0 ? ucb->irq_base + offset : -ENXIO; 179 178 } 180 179 181 180 /* ··· 203 186 * Any code wishing to use the ADC converter must call this 204 187 * function prior to using it. 205 188 * 206 - * This function takes the ADC semaphore to prevent two or more 189 + * This function takes the ADC mutex to prevent two or more 207 190 * concurrent uses, and therefore may sleep. As a result, it 208 191 * can only be called from process context, not interrupt 209 192 * context. ··· 213 196 */ 214 197 void ucb1x00_adc_enable(struct ucb1x00 *ucb) 215 198 { 216 - down(&ucb->adc_sem); 199 + mutex_lock(&ucb->adc_mutex); 217 200 218 201 ucb->adc_cr |= UCB_ADC_ENA; 219 202 ··· 235 218 * complete (2 frames max without sync). 236 219 * 237 220 * If called for a synchronised ADC conversion, it may sleep 238 - * with the ADC semaphore held. 221 + * with the ADC mutex held. 239 222 */ 240 223 unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync) 241 224 { ··· 263 246 * ucb1x00_adc_disable - disable the ADC converter 264 247 * @ucb: UCB1x00 structure describing chip 265 248 * 266 - * Disable the ADC converter and release the ADC semaphore. 249 + * Disable the ADC converter and release the ADC mutex. 267 250 */ 268 251 void ucb1x00_adc_disable(struct ucb1x00 *ucb) 269 252 { ··· 271 254 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr); 272 255 ucb1x00_disable(ucb); 273 256 274 - up(&ucb->adc_sem); 257 + mutex_unlock(&ucb->adc_mutex); 275 258 } 276 259 277 260 /* ··· 282 265 * SIBCLK to talk to the chip. We leave the clock running until 283 266 * we have finished processing all interrupts from the chip. 284 267 */ 285 - static irqreturn_t ucb1x00_irq(int irqnr, void *devid) 268 + static void ucb1x00_irq(unsigned int irq, struct irq_desc *desc) 286 269 { 287 - struct ucb1x00 *ucb = devid; 288 - struct ucb1x00_irq *irq; 270 + struct ucb1x00 *ucb = irq_desc_get_handler_data(desc); 289 271 unsigned int isr, i; 290 272 291 273 ucb1x00_enable(ucb); ··· 292 276 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, isr); 293 277 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0); 294 278 295 - for (i = 0, irq = ucb->irq_handler; i < 16 && isr; i++, isr >>= 1, irq++) 296 - if (isr & 1 && irq->fn) 297 - irq->fn(i, irq->devid); 279 + for (i = 0; i < 16 && isr; i++, isr >>= 1, irq++) 280 + if (isr & 1) 281 + generic_handle_irq(ucb->irq_base + i); 298 282 ucb1x00_disable(ucb); 299 - 300 - return IRQ_HANDLED; 301 283 } 302 284 303 - /** 304 - * ucb1x00_hook_irq - hook a UCB1x00 interrupt 305 - * @ucb: UCB1x00 structure describing chip 306 - * @idx: interrupt index 307 - * @fn: function to call when interrupt is triggered 308 - * @devid: device id to pass to interrupt handler 309 - * 310 - * Hook the specified interrupt. You can only register one handler 311 - * for each interrupt source. The interrupt source is not enabled 312 - * by this function; use ucb1x00_enable_irq instead. 313 - * 314 - * Interrupt handlers will be called with other interrupts enabled. 315 - * 316 - * Returns zero on success, or one of the following errors: 317 - * -EINVAL if the interrupt index is invalid 318 - * -EBUSY if the interrupt has already been hooked 319 - */ 320 - int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid) 285 + static void ucb1x00_irq_update(struct ucb1x00 *ucb, unsigned mask) 321 286 { 322 - struct ucb1x00_irq *irq; 323 - int ret = -EINVAL; 324 - 325 - if (idx < 16) { 326 - irq = ucb->irq_handler + idx; 327 - ret = -EBUSY; 328 - 329 - spin_lock_irq(&ucb->lock); 330 - if (irq->fn == NULL) { 331 - irq->devid = devid; 332 - irq->fn = fn; 333 - ret = 0; 334 - } 335 - spin_unlock_irq(&ucb->lock); 336 - } 337 - return ret; 287 + ucb1x00_enable(ucb); 288 + if (ucb->irq_ris_enbl & mask) 289 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 290 + ucb->irq_mask); 291 + if (ucb->irq_fal_enbl & mask) 292 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 293 + ucb->irq_mask); 294 + ucb1x00_disable(ucb); 338 295 } 339 296 340 - /** 341 - * ucb1x00_enable_irq - enable an UCB1x00 interrupt source 342 - * @ucb: UCB1x00 structure describing chip 343 - * @idx: interrupt index 344 - * @edges: interrupt edges to enable 345 - * 346 - * Enable the specified interrupt to trigger on %UCB_RISING, 347 - * %UCB_FALLING or both edges. The interrupt should have been 348 - * hooked by ucb1x00_hook_irq. 349 - */ 350 - void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges) 297 + static void ucb1x00_irq_noop(struct irq_data *data) 351 298 { 352 - unsigned long flags; 353 - 354 - if (idx < 16) { 355 - spin_lock_irqsave(&ucb->lock, flags); 356 - 357 - ucb1x00_enable(ucb); 358 - if (edges & UCB_RISING) { 359 - ucb->irq_ris_enbl |= 1 << idx; 360 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 361 - } 362 - if (edges & UCB_FALLING) { 363 - ucb->irq_fal_enbl |= 1 << idx; 364 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 365 - } 366 - ucb1x00_disable(ucb); 367 - spin_unlock_irqrestore(&ucb->lock, flags); 368 - } 369 299 } 370 300 371 - /** 372 - * ucb1x00_disable_irq - disable an UCB1x00 interrupt source 373 - * @ucb: UCB1x00 structure describing chip 374 - * @edges: interrupt edges to disable 375 - * 376 - * Disable the specified interrupt triggering on the specified 377 - * (%UCB_RISING, %UCB_FALLING or both) edges. 378 - */ 379 - void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges) 301 + static void ucb1x00_irq_mask(struct irq_data *data) 380 302 { 381 - unsigned long flags; 303 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 304 + unsigned mask = 1 << (data->irq - ucb->irq_base); 382 305 383 - if (idx < 16) { 384 - spin_lock_irqsave(&ucb->lock, flags); 385 - 386 - ucb1x00_enable(ucb); 387 - if (edges & UCB_RISING) { 388 - ucb->irq_ris_enbl &= ~(1 << idx); 389 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 390 - } 391 - if (edges & UCB_FALLING) { 392 - ucb->irq_fal_enbl &= ~(1 << idx); 393 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 394 - } 395 - ucb1x00_disable(ucb); 396 - spin_unlock_irqrestore(&ucb->lock, flags); 397 - } 306 + raw_spin_lock(&ucb->irq_lock); 307 + ucb->irq_mask &= ~mask; 308 + ucb1x00_irq_update(ucb, mask); 309 + raw_spin_unlock(&ucb->irq_lock); 398 310 } 399 311 400 - /** 401 - * ucb1x00_free_irq - disable and free the specified UCB1x00 interrupt 402 - * @ucb: UCB1x00 structure describing chip 403 - * @idx: interrupt index 404 - * @devid: device id. 405 - * 406 - * Disable the interrupt source and remove the handler. devid must 407 - * match the devid passed when hooking the interrupt. 408 - * 409 - * Returns zero on success, or one of the following errors: 410 - * -EINVAL if the interrupt index is invalid 411 - * -ENOENT if devid does not match 412 - */ 413 - int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid) 312 + static void ucb1x00_irq_unmask(struct irq_data *data) 414 313 { 415 - struct ucb1x00_irq *irq; 416 - int ret; 314 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 315 + unsigned mask = 1 << (data->irq - ucb->irq_base); 417 316 418 - if (idx >= 16) 419 - goto bad; 420 - 421 - irq = ucb->irq_handler + idx; 422 - ret = -ENOENT; 423 - 424 - spin_lock_irq(&ucb->lock); 425 - if (irq->devid == devid) { 426 - ucb->irq_ris_enbl &= ~(1 << idx); 427 - ucb->irq_fal_enbl &= ~(1 << idx); 428 - 429 - ucb1x00_enable(ucb); 430 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 431 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 432 - ucb1x00_disable(ucb); 433 - 434 - irq->fn = NULL; 435 - irq->devid = NULL; 436 - ret = 0; 437 - } 438 - spin_unlock_irq(&ucb->lock); 439 - return ret; 440 - 441 - bad: 442 - printk(KERN_ERR "Freeing bad UCB1x00 irq %d\n", idx); 443 - return -EINVAL; 317 + raw_spin_lock(&ucb->irq_lock); 318 + ucb->irq_mask |= mask; 319 + ucb1x00_irq_update(ucb, mask); 320 + raw_spin_unlock(&ucb->irq_lock); 444 321 } 322 + 323 + static int ucb1x00_irq_set_type(struct irq_data *data, unsigned int type) 324 + { 325 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 326 + unsigned mask = 1 << (data->irq - ucb->irq_base); 327 + 328 + raw_spin_lock(&ucb->irq_lock); 329 + if (type & IRQ_TYPE_EDGE_RISING) 330 + ucb->irq_ris_enbl |= mask; 331 + else 332 + ucb->irq_ris_enbl &= ~mask; 333 + 334 + if (type & IRQ_TYPE_EDGE_FALLING) 335 + ucb->irq_fal_enbl |= mask; 336 + else 337 + ucb->irq_fal_enbl &= ~mask; 338 + if (ucb->irq_mask & mask) { 339 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 340 + ucb->irq_mask); 341 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 342 + ucb->irq_mask); 343 + } 344 + raw_spin_unlock(&ucb->irq_lock); 345 + 346 + return 0; 347 + } 348 + 349 + static int ucb1x00_irq_set_wake(struct irq_data *data, unsigned int on) 350 + { 351 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 352 + struct ucb1x00_plat_data *pdata = ucb->mcp->attached_device.platform_data; 353 + unsigned mask = 1 << (data->irq - ucb->irq_base); 354 + 355 + if (!pdata || !pdata->can_wakeup) 356 + return -EINVAL; 357 + 358 + raw_spin_lock(&ucb->irq_lock); 359 + if (on) 360 + ucb->irq_wake |= mask; 361 + else 362 + ucb->irq_wake &= ~mask; 363 + raw_spin_unlock(&ucb->irq_lock); 364 + 365 + return 0; 366 + } 367 + 368 + static struct irq_chip ucb1x00_irqchip = { 369 + .name = "ucb1x00", 370 + .irq_ack = ucb1x00_irq_noop, 371 + .irq_mask = ucb1x00_irq_mask, 372 + .irq_unmask = ucb1x00_irq_unmask, 373 + .irq_set_type = ucb1x00_irq_set_type, 374 + .irq_set_wake = ucb1x00_irq_set_wake, 375 + }; 445 376 446 377 static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) 447 378 { ··· 403 440 ret = drv->add(dev); 404 441 405 442 if (ret == 0) { 406 - list_add(&dev->dev_node, &ucb->devs); 407 - list_add(&dev->drv_node, &drv->devs); 443 + list_add_tail(&dev->dev_node, &ucb->devs); 444 + list_add_tail(&dev->drv_node, &drv->devs); 408 445 } else { 409 446 kfree(dev); 410 447 } ··· 496 533 497 534 static int ucb1x00_probe(struct mcp *mcp) 498 535 { 499 - struct ucb1x00 *ucb; 536 + struct ucb1x00_plat_data *pdata = mcp->attached_device.platform_data; 500 537 struct ucb1x00_driver *drv; 501 - unsigned int id; 538 + struct ucb1x00 *ucb; 539 + unsigned id, i, irq_base; 502 540 int ret = -ENODEV; 503 - int temp; 541 + 542 + /* Tell the platform to deassert the UCB1x00 reset */ 543 + if (pdata && pdata->reset) 544 + pdata->reset(UCB_RST_PROBE); 504 545 505 546 mcp_enable(mcp); 506 547 id = mcp_reg_read(mcp, UCB_ID); 548 + mcp_disable(mcp); 507 549 508 550 if (id != UCB_ID_1200 && id != UCB_ID_1300 && id != UCB_ID_TC35143) { 509 551 printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id); 510 - goto err_disable; 552 + goto out; 511 553 } 512 554 513 555 ucb = kzalloc(sizeof(struct ucb1x00), GFP_KERNEL); 514 556 ret = -ENOMEM; 515 557 if (!ucb) 516 - goto err_disable; 558 + goto out; 517 559 518 - 560 + device_initialize(&ucb->dev); 519 561 ucb->dev.class = &ucb1x00_class; 520 562 ucb->dev.parent = &mcp->attached_device; 521 563 dev_set_name(&ucb->dev, "ucb1x00"); 522 564 523 - spin_lock_init(&ucb->lock); 565 + raw_spin_lock_init(&ucb->irq_lock); 524 566 spin_lock_init(&ucb->io_lock); 525 - sema_init(&ucb->adc_sem, 1); 567 + mutex_init(&ucb->adc_mutex); 526 568 527 569 ucb->id = id; 528 570 ucb->mcp = mcp; 571 + 572 + ret = device_add(&ucb->dev); 573 + if (ret) 574 + goto err_dev_add; 575 + 576 + ucb1x00_enable(ucb); 529 577 ucb->irq = ucb1x00_detect_irq(ucb); 578 + ucb1x00_disable(ucb); 530 579 if (ucb->irq == NO_IRQ) { 531 - printk(KERN_ERR "UCB1x00: IRQ probe failed\n"); 580 + dev_err(&ucb->dev, "IRQ probe failed\n"); 532 581 ret = -ENODEV; 533 - goto err_free; 582 + goto err_no_irq; 534 583 } 535 584 536 585 ucb->gpio.base = -1; 537 - if (mcp->gpio_base != 0) { 586 + irq_base = pdata ? pdata->irq_base : 0; 587 + ucb->irq_base = irq_alloc_descs(-1, irq_base, 16, -1); 588 + if (ucb->irq_base < 0) { 589 + dev_err(&ucb->dev, "unable to allocate 16 irqs: %d\n", 590 + ucb->irq_base); 591 + goto err_irq_alloc; 592 + } 593 + 594 + for (i = 0; i < 16; i++) { 595 + unsigned irq = ucb->irq_base + i; 596 + 597 + irq_set_chip_and_handler(irq, &ucb1x00_irqchip, handle_edge_irq); 598 + irq_set_chip_data(irq, ucb); 599 + set_irq_flags(irq, IRQF_VALID | IRQ_NOREQUEST); 600 + } 601 + 602 + irq_set_irq_type(ucb->irq, IRQ_TYPE_EDGE_RISING); 603 + irq_set_handler_data(ucb->irq, ucb); 604 + irq_set_chained_handler(ucb->irq, ucb1x00_irq); 605 + 606 + if (pdata && pdata->gpio_base) { 538 607 ucb->gpio.label = dev_name(&ucb->dev); 539 - ucb->gpio.base = mcp->gpio_base; 608 + ucb->gpio.dev = &ucb->dev; 609 + ucb->gpio.owner = THIS_MODULE; 610 + ucb->gpio.base = pdata->gpio_base; 540 611 ucb->gpio.ngpio = 10; 541 612 ucb->gpio.set = ucb1x00_gpio_set; 542 613 ucb->gpio.get = ucb1x00_gpio_get; 543 614 ucb->gpio.direction_input = ucb1x00_gpio_direction_input; 544 615 ucb->gpio.direction_output = ucb1x00_gpio_direction_output; 616 + ucb->gpio.to_irq = ucb1x00_to_irq; 545 617 ret = gpiochip_add(&ucb->gpio); 546 618 if (ret) 547 - goto err_free; 619 + goto err_gpio_add; 548 620 } else 549 621 dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); 550 622 551 - ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING, 552 - "UCB1x00", ucb); 553 - if (ret) { 554 - printk(KERN_ERR "ucb1x00: unable to grab irq%d: %d\n", 555 - ucb->irq, ret); 556 - goto err_gpio; 557 - } 558 - 559 623 mcp_set_drvdata(mcp, ucb); 560 624 561 - ret = device_register(&ucb->dev); 562 - if (ret) 563 - goto err_irq; 564 - 625 + if (pdata) 626 + device_set_wakeup_capable(&ucb->dev, pdata->can_wakeup); 565 627 566 628 INIT_LIST_HEAD(&ucb->devs); 567 629 mutex_lock(&ucb1x00_mutex); 568 - list_add(&ucb->node, &ucb1x00_devices); 630 + list_add_tail(&ucb->node, &ucb1x00_devices); 569 631 list_for_each_entry(drv, &ucb1x00_drivers, node) { 570 632 ucb1x00_add_dev(ucb, drv); 571 633 } 572 634 mutex_unlock(&ucb1x00_mutex); 573 635 574 - goto out; 636 + return ret; 575 637 576 - err_irq: 577 - free_irq(ucb->irq, ucb); 578 - err_gpio: 579 - if (ucb->gpio.base != -1) 580 - temp = gpiochip_remove(&ucb->gpio); 581 - err_free: 582 - kfree(ucb); 583 - err_disable: 584 - mcp_disable(mcp); 638 + err_gpio_add: 639 + irq_set_chained_handler(ucb->irq, NULL); 640 + err_irq_alloc: 641 + if (ucb->irq_base > 0) 642 + irq_free_descs(ucb->irq_base, 16); 643 + err_no_irq: 644 + device_del(&ucb->dev); 645 + err_dev_add: 646 + put_device(&ucb->dev); 585 647 out: 648 + if (pdata && pdata->reset) 649 + pdata->reset(UCB_RST_PROBE_FAIL); 586 650 return ret; 587 651 } 588 652 589 653 static void ucb1x00_remove(struct mcp *mcp) 590 654 { 655 + struct ucb1x00_plat_data *pdata = mcp->attached_device.platform_data; 591 656 struct ucb1x00 *ucb = mcp_get_drvdata(mcp); 592 657 struct list_head *l, *n; 593 658 int ret; ··· 634 643 dev_err(&ucb->dev, "Can't remove gpio chip: %d\n", ret); 635 644 } 636 645 637 - free_irq(ucb->irq, ucb); 646 + irq_set_chained_handler(ucb->irq, NULL); 647 + irq_free_descs(ucb->irq_base, 16); 638 648 device_unregister(&ucb->dev); 649 + 650 + if (pdata && pdata->reset) 651 + pdata->reset(UCB_RST_REMOVE); 639 652 } 640 653 641 654 int ucb1x00_register_driver(struct ucb1x00_driver *drv) ··· 648 653 649 654 INIT_LIST_HEAD(&drv->devs); 650 655 mutex_lock(&ucb1x00_mutex); 651 - list_add(&drv->node, &ucb1x00_drivers); 656 + list_add_tail(&drv->node, &ucb1x00_drivers); 652 657 list_for_each_entry(ucb, &ucb1x00_devices, node) { 653 658 ucb1x00_add_dev(ucb, drv); 654 659 } ··· 669 674 mutex_unlock(&ucb1x00_mutex); 670 675 } 671 676 672 - static int ucb1x00_suspend(struct mcp *mcp, pm_message_t state) 677 + static int ucb1x00_suspend(struct device *dev) 673 678 { 674 - struct ucb1x00 *ucb = mcp_get_drvdata(mcp); 675 - struct ucb1x00_dev *dev; 679 + struct ucb1x00_plat_data *pdata = dev->platform_data; 680 + struct ucb1x00 *ucb = dev_get_drvdata(dev); 681 + struct ucb1x00_dev *udev; 676 682 677 683 mutex_lock(&ucb1x00_mutex); 678 - list_for_each_entry(dev, &ucb->devs, dev_node) { 679 - if (dev->drv->suspend) 680 - dev->drv->suspend(dev, state); 684 + list_for_each_entry(udev, &ucb->devs, dev_node) { 685 + if (udev->drv->suspend) 686 + udev->drv->suspend(udev); 681 687 } 682 688 mutex_unlock(&ucb1x00_mutex); 689 + 690 + if (ucb->irq_wake) { 691 + unsigned long flags; 692 + 693 + raw_spin_lock_irqsave(&ucb->irq_lock, flags); 694 + ucb1x00_enable(ucb); 695 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 696 + ucb->irq_wake); 697 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 698 + ucb->irq_wake); 699 + ucb1x00_disable(ucb); 700 + raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); 701 + 702 + enable_irq_wake(ucb->irq); 703 + } else if (pdata && pdata->reset) 704 + pdata->reset(UCB_RST_SUSPEND); 705 + 683 706 return 0; 684 707 } 685 708 686 - static int ucb1x00_resume(struct mcp *mcp) 709 + static int ucb1x00_resume(struct device *dev) 687 710 { 688 - struct ucb1x00 *ucb = mcp_get_drvdata(mcp); 689 - struct ucb1x00_dev *dev; 711 + struct ucb1x00_plat_data *pdata = dev->platform_data; 712 + struct ucb1x00 *ucb = dev_get_drvdata(dev); 713 + struct ucb1x00_dev *udev; 690 714 715 + if (!ucb->irq_wake && pdata && pdata->reset) 716 + pdata->reset(UCB_RST_RESUME); 717 + 718 + ucb1x00_enable(ucb); 691 719 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); 692 720 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); 721 + 722 + if (ucb->irq_wake) { 723 + unsigned long flags; 724 + 725 + raw_spin_lock_irqsave(&ucb->irq_lock, flags); 726 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 727 + ucb->irq_mask); 728 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 729 + ucb->irq_mask); 730 + raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); 731 + 732 + disable_irq_wake(ucb->irq); 733 + } 734 + ucb1x00_disable(ucb); 735 + 693 736 mutex_lock(&ucb1x00_mutex); 694 - list_for_each_entry(dev, &ucb->devs, dev_node) { 695 - if (dev->drv->resume) 696 - dev->drv->resume(dev); 737 + list_for_each_entry(udev, &ucb->devs, dev_node) { 738 + if (udev->drv->resume) 739 + udev->drv->resume(udev); 697 740 } 698 741 mutex_unlock(&ucb1x00_mutex); 699 742 return 0; 700 743 } 744 + 745 + static const struct dev_pm_ops ucb1x00_pm_ops = { 746 + SET_SYSTEM_SLEEP_PM_OPS(ucb1x00_suspend, ucb1x00_resume) 747 + }; 701 748 702 749 static struct mcp_driver ucb1x00_driver = { 703 750 .drv = { 704 751 .name = "ucb1x00", 752 + .owner = THIS_MODULE, 753 + .pm = &ucb1x00_pm_ops, 705 754 }, 706 755 .probe = ucb1x00_probe, 707 756 .remove = ucb1x00_remove, 708 - .suspend = ucb1x00_suspend, 709 - .resume = ucb1x00_resume, 710 757 }; 711 758 712 759 static int __init ucb1x00_init(void) ··· 779 742 EXPORT_SYMBOL(ucb1x00_adc_read); 780 743 EXPORT_SYMBOL(ucb1x00_adc_disable); 781 744 782 - EXPORT_SYMBOL(ucb1x00_hook_irq); 783 - EXPORT_SYMBOL(ucb1x00_free_irq); 784 - EXPORT_SYMBOL(ucb1x00_enable_irq); 785 - EXPORT_SYMBOL(ucb1x00_disable_irq); 786 - 787 745 EXPORT_SYMBOL(ucb1x00_register_driver); 788 746 EXPORT_SYMBOL(ucb1x00_unregister_driver); 789 747 748 + MODULE_ALIAS("mcp:ucb1x00"); 790 749 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 791 750 MODULE_DESCRIPTION("UCB1x00 core driver"); 792 751 MODULE_LICENSE("GPL");
+31 -8
drivers/mfd/ucb1x00-ts.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/moduleparam.h> 22 22 #include <linux/init.h> 23 - #include <linux/smp.h> 23 + #include <linux/interrupt.h> 24 24 #include <linux/sched.h> 25 + #include <linux/spinlock.h> 25 26 #include <linux/completion.h> 26 27 #include <linux/delay.h> 27 28 #include <linux/string.h> ··· 33 32 #include <linux/kthread.h> 34 33 #include <linux/mfd/ucb1x00.h> 35 34 36 - #include <mach/dma.h> 37 35 #include <mach/collie.h> 38 36 #include <asm/mach-types.h> 39 37 ··· 42 42 struct input_dev *idev; 43 43 struct ucb1x00 *ucb; 44 44 45 + spinlock_t irq_lock; 46 + unsigned irq_disabled; 45 47 wait_queue_head_t irq_wait; 46 48 struct task_struct *rtask; 47 49 u16 x_res; ··· 240 238 if (ucb1x00_ts_pen_down(ts)) { 241 239 set_current_state(TASK_INTERRUPTIBLE); 242 240 243 - ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, machine_is_collie() ? UCB_RISING : UCB_FALLING); 241 + spin_lock_irq(&ts->irq_lock); 242 + if (ts->irq_disabled) { 243 + ts->irq_disabled = 0; 244 + enable_irq(ts->ucb->irq_base + UCB_IRQ_TSPX); 245 + } 246 + spin_unlock_irq(&ts->irq_lock); 244 247 ucb1x00_disable(ts->ucb); 245 248 246 249 /* ··· 288 281 * We only detect touch screen _touches_ with this interrupt 289 282 * handler, and even then we just schedule our task. 290 283 */ 291 - static void ucb1x00_ts_irq(int idx, void *id) 284 + static irqreturn_t ucb1x00_ts_irq(int irq, void *id) 292 285 { 293 286 struct ucb1x00_ts *ts = id; 294 287 295 - ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING); 288 + spin_lock(&ts->irq_lock); 289 + ts->irq_disabled = 1; 290 + disable_irq_nosync(ts->ucb->irq_base + UCB_IRQ_TSPX); 291 + spin_unlock(&ts->irq_lock); 296 292 wake_up(&ts->irq_wait); 293 + 294 + return IRQ_HANDLED; 297 295 } 298 296 299 297 static int ucb1x00_ts_open(struct input_dev *idev) 300 298 { 301 299 struct ucb1x00_ts *ts = input_get_drvdata(idev); 300 + unsigned long flags = 0; 302 301 int ret = 0; 303 302 304 303 BUG_ON(ts->rtask); 305 304 305 + if (machine_is_collie()) 306 + flags = IRQF_TRIGGER_RISING; 307 + else 308 + flags = IRQF_TRIGGER_FALLING; 309 + 310 + ts->irq_disabled = 0; 311 + 306 312 init_waitqueue_head(&ts->irq_wait); 307 - ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_TSPX, ucb1x00_ts_irq, ts); 313 + ret = request_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ucb1x00_ts_irq, 314 + flags, "ucb1x00-ts", ts); 308 315 if (ret < 0) 309 316 goto out; 310 317 ··· 335 314 if (!IS_ERR(ts->rtask)) { 336 315 ret = 0; 337 316 } else { 338 - ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts); 317 + free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); 339 318 ts->rtask = NULL; 340 319 ret = -EFAULT; 341 320 } ··· 355 334 kthread_stop(ts->rtask); 356 335 357 336 ucb1x00_enable(ts->ucb); 358 - ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts); 337 + free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); 359 338 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 0); 360 339 ucb1x00_disable(ts->ucb); 361 340 } ··· 380 359 ts->ucb = dev->ucb; 381 360 ts->idev = idev; 382 361 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; 362 + spin_lock_init(&ts->irq_lock); 383 363 384 364 idev->name = "Touchscreen panel"; 385 365 idev->id.product = ts->ucb->id; 386 366 idev->open = ucb1x00_ts_open; 387 367 idev->close = ucb1x00_ts_close; 368 + idev->dev.parent = &ts->ucb->dev; 388 369 389 370 idev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); 390 371 idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+3 -11
include/linux/mfd/mcp.h
··· 10 10 #ifndef MCP_H 11 11 #define MCP_H 12 12 13 - #include <mach/dma.h> 14 - 15 13 struct mcp_ops; 16 14 17 15 struct mcp { ··· 19 21 int use_count; 20 22 unsigned int sclk_rate; 21 23 unsigned int rw_timeout; 22 - dma_device_t dma_audio_rd; 23 - dma_device_t dma_audio_wr; 24 - dma_device_t dma_telco_rd; 25 - dma_device_t dma_telco_wr; 26 24 struct device attached_device; 27 - int gpio_base; 28 25 }; 29 26 30 27 struct mcp_ops { ··· 40 47 #define mcp_get_sclk_rate(mcp) ((mcp)->sclk_rate) 41 48 42 49 struct mcp *mcp_host_alloc(struct device *, size_t); 43 - int mcp_host_register(struct mcp *); 44 - void mcp_host_unregister(struct mcp *); 50 + int mcp_host_add(struct mcp *, void *); 51 + void mcp_host_del(struct mcp *); 52 + void mcp_host_free(struct mcp *); 45 53 46 54 struct mcp_driver { 47 55 struct device_driver drv; 48 56 int (*probe)(struct mcp *); 49 57 void (*remove)(struct mcp *); 50 - int (*suspend)(struct mcp *, pm_message_t); 51 - int (*resume)(struct mcp *); 52 58 }; 53 59 54 60 int mcp_driver_register(struct mcp_driver *);
+19 -19
include/linux/mfd/ucb1x00.h
··· 12 12 13 13 #include <linux/mfd/mcp.h> 14 14 #include <linux/gpio.h> 15 - #include <linux/semaphore.h> 15 + #include <linux/mutex.h> 16 16 17 17 #define UCB_IO_DATA 0x00 18 18 #define UCB_IO_DIR 0x01 ··· 104 104 #define UCB_MODE_DYN_VFLAG_ENA (1 << 12) 105 105 #define UCB_MODE_AUD_OFF_CAN (1 << 13) 106 106 107 + enum ucb1x00_reset { 108 + UCB_RST_PROBE, 109 + UCB_RST_RESUME, 110 + UCB_RST_SUSPEND, 111 + UCB_RST_REMOVE, 112 + UCB_RST_PROBE_FAIL, 113 + }; 107 114 108 - struct ucb1x00_irq { 109 - void *devid; 110 - void (*fn)(int, void *); 115 + struct ucb1x00_plat_data { 116 + void (*reset)(enum ucb1x00_reset); 117 + unsigned irq_base; 118 + int gpio_base; 119 + unsigned can_wakeup; 111 120 }; 112 121 113 122 struct ucb1x00 { 114 - spinlock_t lock; 123 + raw_spinlock_t irq_lock; 115 124 struct mcp *mcp; 116 125 unsigned int irq; 117 - struct semaphore adc_sem; 126 + int irq_base; 127 + struct mutex adc_mutex; 118 128 spinlock_t io_lock; 119 129 u16 id; 120 130 u16 io_dir; ··· 132 122 u16 adc_cr; 133 123 u16 irq_fal_enbl; 134 124 u16 irq_ris_enbl; 135 - struct ucb1x00_irq irq_handler[16]; 125 + u16 irq_mask; 126 + u16 irq_wake; 136 127 struct device dev; 137 128 struct list_head node; 138 129 struct list_head devs; ··· 155 144 struct list_head devs; 156 145 int (*add)(struct ucb1x00_dev *dev); 157 146 void (*remove)(struct ucb1x00_dev *dev); 158 - int (*suspend)(struct ucb1x00_dev *dev, pm_message_t state); 147 + int (*suspend)(struct ucb1x00_dev *dev); 159 148 int (*resume)(struct ucb1x00_dev *dev); 160 149 }; 161 150 ··· 255 244 unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync); 256 245 void ucb1x00_adc_enable(struct ucb1x00 *ucb); 257 246 void ucb1x00_adc_disable(struct ucb1x00 *ucb); 258 - 259 - /* 260 - * Which edges of the IRQ do you want to control today? 261 - */ 262 - #define UCB_RISING (1 << 0) 263 - #define UCB_FALLING (1 << 1) 264 - 265 - int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid); 266 - void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges); 267 - void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges); 268 - int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid); 269 247 270 248 #endif