H A D | i2c-bcm-iproc.c | 106 struct bcm_iproc_i2c_dev *iproc_i2c = data; bcm_iproc_i2c_isr() local 107 u32 status = readl(iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_isr() 114 writel(status, iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_isr() 115 iproc_i2c->xfer_is_done = 1; bcm_iproc_i2c_isr() 116 complete_all(&iproc_i2c->done); bcm_iproc_i2c_isr() 121 static int bcm_iproc_i2c_check_status(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_check_status() argument 126 val = readl(iproc_i2c->base + M_CMD_OFFSET); bcm_iproc_i2c_check_status() 134 dev_dbg(iproc_i2c->device, "lost bus arbitration\n"); bcm_iproc_i2c_check_status() 138 dev_dbg(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); bcm_iproc_i2c_check_status() 142 dev_dbg(iproc_i2c->device, "NAK data\n"); bcm_iproc_i2c_check_status() 146 dev_dbg(iproc_i2c->device, "bus timeout\n"); bcm_iproc_i2c_check_status() 150 dev_dbg(iproc_i2c->device, "unknown error code=%d\n", val); bcm_iproc_i2c_check_status() 155 static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_xfer_single_msg() argument 164 if (!!(readl(iproc_i2c->base + M_CMD_OFFSET) & bcm_iproc_i2c_xfer_single_msg() 166 dev_warn(iproc_i2c->device, "bus is busy\n"); bcm_iproc_i2c_xfer_single_msg() 172 writel(addr, iproc_i2c->base + M_TX_OFFSET); bcm_iproc_i2c_xfer_single_msg() 183 writel(val, iproc_i2c->base + M_TX_OFFSET); bcm_iproc_i2c_xfer_single_msg() 188 reinit_completion(&iproc_i2c->done); bcm_iproc_i2c_xfer_single_msg() 189 iproc_i2c->xfer_is_done = 0; bcm_iproc_i2c_xfer_single_msg() 196 writel(1 << IE_M_START_BUSY_SHIFT, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 209 writel(val, iproc_i2c->base + M_CMD_OFFSET); bcm_iproc_i2c_xfer_single_msg() 211 time_left = wait_for_completion_timeout(&iproc_i2c->done, time_left); bcm_iproc_i2c_xfer_single_msg() 214 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 216 readl(iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_xfer_single_msg() 219 synchronize_irq(iproc_i2c->irq); bcm_iproc_i2c_xfer_single_msg() 221 if (!time_left && !iproc_i2c->xfer_is_done) { bcm_iproc_i2c_xfer_single_msg() 222 dev_err(iproc_i2c->device, "transaction timed out\n"); bcm_iproc_i2c_xfer_single_msg() 227 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_xfer_single_msg() 231 ret = bcm_iproc_i2c_check_status(iproc_i2c, msg); bcm_iproc_i2c_xfer_single_msg() 236 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_xfer_single_msg() 246 msg->buf[i] = (readl(iproc_i2c->base + M_RX_OFFSET) >> bcm_iproc_i2c_xfer_single_msg() 257 struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(adapter); bcm_iproc_i2c_xfer() local 262 ret = bcm_iproc_i2c_xfer_single_msg(iproc_i2c, &msgs[i]); bcm_iproc_i2c_xfer() 264 dev_dbg(iproc_i2c->device, "xfer failed\n"); bcm_iproc_i2c_xfer() 288 static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c) bcm_iproc_i2c_cfg_speed() argument 292 int ret = of_property_read_u32(iproc_i2c->device->of_node, bcm_iproc_i2c_cfg_speed() 295 dev_info(iproc_i2c->device, bcm_iproc_i2c_cfg_speed() 301 dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", bcm_iproc_i2c_cfg_speed() 303 dev_err(iproc_i2c->device, bcm_iproc_i2c_cfg_speed() 312 val = readl(iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_cfg_speed() 315 writel(val, iproc_i2c->base + TIM_CFG_OFFSET); bcm_iproc_i2c_cfg_speed() 317 dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed); bcm_iproc_i2c_cfg_speed() 322 static int bcm_iproc_i2c_init(struct bcm_iproc_i2c_dev *iproc_i2c) bcm_iproc_i2c_init() argument 327 val = readl(iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 330 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 337 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_init() 341 writel(val, iproc_i2c->base + M_FIFO_CTRL_OFFSET); bcm_iproc_i2c_init() 344 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_init() 347 writel(0xffffffff, iproc_i2c->base + IS_OFFSET); bcm_iproc_i2c_init() 352 static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, bcm_iproc_i2c_enable_disable() argument 357 val = readl(iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_enable_disable() 362 writel(val, iproc_i2c->base + CFG_OFFSET); bcm_iproc_i2c_enable_disable() 368 struct bcm_iproc_i2c_dev *iproc_i2c; bcm_iproc_i2c_probe() local 372 iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), bcm_iproc_i2c_probe() 374 if (!iproc_i2c) bcm_iproc_i2c_probe() 377 platform_set_drvdata(pdev, iproc_i2c); bcm_iproc_i2c_probe() 378 iproc_i2c->device = &pdev->dev; bcm_iproc_i2c_probe() 379 init_completion(&iproc_i2c->done); bcm_iproc_i2c_probe() 382 iproc_i2c->base = devm_ioremap_resource(iproc_i2c->device, res); bcm_iproc_i2c_probe() 383 if (IS_ERR(iproc_i2c->base)) bcm_iproc_i2c_probe() 384 return PTR_ERR(iproc_i2c->base); bcm_iproc_i2c_probe() 386 ret = bcm_iproc_i2c_init(iproc_i2c); bcm_iproc_i2c_probe() 390 ret = bcm_iproc_i2c_cfg_speed(iproc_i2c); bcm_iproc_i2c_probe() 396 dev_err(iproc_i2c->device, "no irq resource\n"); bcm_iproc_i2c_probe() 399 iproc_i2c->irq = irq; bcm_iproc_i2c_probe() 401 ret = devm_request_irq(iproc_i2c->device, irq, bcm_iproc_i2c_isr, 0, bcm_iproc_i2c_probe() 402 pdev->name, iproc_i2c); bcm_iproc_i2c_probe() 404 dev_err(iproc_i2c->device, "unable to request irq %i\n", irq); bcm_iproc_i2c_probe() 408 bcm_iproc_i2c_enable_disable(iproc_i2c, true); bcm_iproc_i2c_probe() 410 adap = &iproc_i2c->adapter; bcm_iproc_i2c_probe() 411 i2c_set_adapdata(adap, iproc_i2c); bcm_iproc_i2c_probe() 420 dev_err(iproc_i2c->device, "failed to add adapter\n"); bcm_iproc_i2c_probe() 429 struct bcm_iproc_i2c_dev *iproc_i2c = platform_get_drvdata(pdev); bcm_iproc_i2c_remove() local 432 writel(0, iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_remove() 433 readl(iproc_i2c->base + IE_OFFSET); bcm_iproc_i2c_remove() 434 synchronize_irq(iproc_i2c->irq); bcm_iproc_i2c_remove() 436 i2c_del_adapter(&iproc_i2c->adapter); bcm_iproc_i2c_remove() 437 bcm_iproc_i2c_enable_disable(iproc_i2c, false); bcm_iproc_i2c_remove()
|