H A D | i2c-bcm-iproc.c | 107 struct bcm_iproc_i2c_dev *iproc_i2c = data; bcm_iproc_i2c_isr() local 108 u32 status = readl(iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_isr() 115 writel(status, iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_isr() 116 iproc_i2c->xfer_is_done = 1; bcm_iproc_i2c_isr() 117 complete_all(&iproc_i2c->done); bcm_iproc_i2c_isr() 122 static int bcm_iproc_i2c_check_status(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_check_status() argument 127 val = readl(iproc_i2c->base + M_CMD_OFFSET); bcm_iproc_i2c_check_status() 135 dev_dbg(iproc_i2c->device, "lost bus arbitration\n"); bcm_iproc_i2c_check_status() 139 dev_dbg(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); bcm_iproc_i2c_check_status() 143 dev_dbg(iproc_i2c->device, "NAK data\n"); bcm_iproc_i2c_check_status() 147 dev_dbg(iproc_i2c->device, "bus timeout\n"); bcm_iproc_i2c_check_status() 151 dev_dbg(iproc_i2c->device, "unknown error code=%d\n", val); bcm_iproc_i2c_check_status() 156 static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_xfer_single_msg() argument 165 if (!!(readl(iproc_i2c->base + M_CMD_OFFSET) & bcm_iproc_i2c_xfer_single_msg() 167 dev_warn(iproc_i2c->device, "bus is busy\n"); bcm_iproc_i2c_xfer_single_msg() 173 writel(addr, iproc_i2c->base + M_TX_OFFSET); bcm_iproc_i2c_xfer_single_msg() 184 writel(val, iproc_i2c->base + M_TX_OFFSET); bcm_iproc_i2c_xfer_single_msg() 189 reinit_completion(&iproc_i2c->done); bcm_iproc_i2c_xfer_single_msg() 190 iproc_i2c->xfer_is_done = 0; bcm_iproc_i2c_xfer_single_msg() 197 writel(1 << IE_M_START_BUSY_SHIFT, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 210 writel(val, iproc_i2c->base + M_CMD_OFFSET); bcm_iproc_i2c_xfer_single_msg() 212 time_left = wait_for_completion_timeout(&iproc_i2c->done, time_left); bcm_iproc_i2c_xfer_single_msg() 215 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 217 readl(iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 220 synchronize_irq(iproc_i2c->irq); bcm_iproc_i2c_xfer_single_msg() 222 if (!time_left && !iproc_i2c->xfer_is_done) { bcm_iproc_i2c_xfer_single_msg() 223 dev_err(iproc_i2c->device, "transaction timed out\n"); bcm_iproc_i2c_xfer_single_msg() 228 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_xfer_single_msg() 232 ret = bcm_iproc_i2c_check_status(iproc_i2c, msg); bcm_iproc_i2c_xfer_single_msg() 237 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_xfer_single_msg() 247 msg->buf[i] = (readl(iproc_i2c->base + M_RX_OFFSET) >> bcm_iproc_i2c_xfer_single_msg() 258 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(adapter); bcm_iproc_i2c_xfer() local 263 ret = bcm_iproc_i2c_xfer_single_msg(iproc_i2c, &msgs[i]); bcm_iproc_i2c_xfer() 265 dev_dbg(iproc_i2c->device, "xfer failed\n"); bcm_iproc_i2c_xfer() 289 static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c) bcm_iproc_i2c_cfg_speed() argument 293 int ret = of_property_read_u32(iproc_i2c->device->of_node, bcm_iproc_i2c_cfg_speed() 296 dev_info(iproc_i2c->device, bcm_iproc_i2c_cfg_speed() 302 dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", bcm_iproc_i2c_cfg_speed() 304 dev_err(iproc_i2c->device, bcm_iproc_i2c_cfg_speed() 313 iproc_i2c->bus_speed = bus_speed; bcm_iproc_i2c_cfg_speed() 314 val = readl(iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_cfg_speed() 317 writel(val, iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_cfg_speed() 319 dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed); bcm_iproc_i2c_cfg_speed() 324 static int bcm_iproc_i2c_init(struct bcm_iproc_i2c_dev *iproc_i2c) bcm_iproc_i2c_init() argument 329 val = readl(iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 332 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 339 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 343 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_init() 346 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_init() 349 writel(0xffffffff, iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_init() 354 static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_enable_disable() argument 359 val = readl(iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_enable_disable() 364 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_enable_disable() 370 struct bcm_iproc_i2c_dev *iproc_i2c; bcm_iproc_i2c_probe() local 374 iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), bcm_iproc_i2c_probe() 376 if (!iproc_i2c) bcm_iproc_i2c_probe() 379 platform_set_drvdata(pdev, iproc_i2c); bcm_iproc_i2c_probe() 380 iproc_i2c->device = &pdev->dev; bcm_iproc_i2c_probe() 381 init_completion(&iproc_i2c->done); bcm_iproc_i2c_probe() 384 iproc_i2c->base = devm_ioremap_resource(iproc_i2c->device, res); bcm_iproc_i2c_probe() 385 if (IS_ERR(iproc_i2c->base)) bcm_iproc_i2c_probe() 386 return PTR_ERR(iproc_i2c->base); bcm_iproc_i2c_probe() 388 ret = bcm_iproc_i2c_init(iproc_i2c); bcm_iproc_i2c_probe() 392 ret = bcm_iproc_i2c_cfg_speed(iproc_i2c); bcm_iproc_i2c_probe() 398 dev_err(iproc_i2c->device, "no irq resource\n"); bcm_iproc_i2c_probe() 401 iproc_i2c->irq = irq; bcm_iproc_i2c_probe() 403 ret = devm_request_irq(iproc_i2c->device, irq, bcm_iproc_i2c_isr, 0, bcm_iproc_i2c_probe() 404 pdev->name, iproc_i2c); bcm_iproc_i2c_probe() 406 dev_err(iproc_i2c->device, "unable to request irq %i\n", irq); bcm_iproc_i2c_probe() 410 bcm_iproc_i2c_enable_disable(iproc_i2c, true); bcm_iproc_i2c_probe() 412 adap = &iproc_i2c->adapter; bcm_iproc_i2c_probe() 413 i2c_set_adapdata(adap, iproc_i2c); bcm_iproc_i2c_probe() 422 dev_err(iproc_i2c->device, "failed to add adapter\n"); bcm_iproc_i2c_probe() 431 struct bcm_iproc_i2c_dev *iproc_i2c = platform_get_drvdata(pdev); bcm_iproc_i2c_remove() local 434 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_remove() 435 readl(iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_remove() 436 synchronize_irq(iproc_i2c->irq); bcm_iproc_i2c_remove() 438 i2c_del_adapter(&iproc_i2c->adapter); bcm_iproc_i2c_remove() 439 bcm_iproc_i2c_enable_disable(iproc_i2c, false); bcm_iproc_i2c_remove() 449 struct bcm_iproc_i2c_dev *iproc_i2c = platform_get_drvdata(pdev); bcm_iproc_i2c_suspend() local 452 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_suspend() 453 readl(iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_suspend() 454 synchronize_irq(iproc_i2c->irq); bcm_iproc_i2c_suspend() 457 bcm_iproc_i2c_enable_disable(iproc_i2c, false); bcm_iproc_i2c_suspend() 465 struct bcm_iproc_i2c_dev *iproc_i2c = platform_get_drvdata(pdev); bcm_iproc_i2c_resume() local 473 ret = bcm_iproc_i2c_init(iproc_i2c); bcm_iproc_i2c_resume() 478 val = readl(iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_resume() 480 val |= (iproc_i2c->bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT; bcm_iproc_i2c_resume() 481 writel(val, iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_resume() 483 bcm_iproc_i2c_enable_disable(iproc_i2c, true); bcm_iproc_i2c_resume()
|