2 * ACPI support for Intel Lynxpoint LPSS.
4 * Copyright (C) 2013, Intel Corporation
5 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
6 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/acpi.h>
14 #include <linux/clk.h>
15 #include <linux/clkdev.h>
16 #include <linux/clk-provider.h>
17 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/platform_data/clk-lpss.h>
21 #include <linux/pm_runtime.h>
25 ACPI_MODULE_NAME("acpi_lpss");
27 #define LPSS_CLK_SIZE 0x04
28 #define LPSS_LTR_SIZE 0x18
30 /* Offsets relative to LPSS_PRIVATE_OFFSET */
31 #define LPSS_GENERAL 0x08
32 #define LPSS_GENERAL_LTR_MODE_SW BIT(2)
33 #define LPSS_SW_LTR 0x10
34 #define LPSS_AUTO_LTR 0x14
35 #define LPSS_TX_INT 0x20
36 #define LPSS_TX_INT_MASK BIT(1)
38 struct lpss_shared_clock {
44 struct lpss_private_data;
46 struct lpss_device_desc {
48 const char *clkdev_name;
50 unsigned int prv_offset;
51 size_t prv_size_override;
53 struct lpss_shared_clock *shared_clock;
54 void (*setup)(struct lpss_private_data *pdata);
57 static struct lpss_device_desc lpss_dma_desc = {
59 .clkdev_name = "hclk",
62 struct lpss_private_data {
63 void __iomem *mmio_base;
64 resource_size_t mmio_size;
66 const struct lpss_device_desc *dev_desc;
69 static void lpss_uart_setup(struct lpss_private_data *pdata)
71 unsigned int tx_int_offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
74 reg = readl(pdata->mmio_base + tx_int_offset);
75 writel(reg | LPSS_TX_INT_MASK, pdata->mmio_base + tx_int_offset);
78 static struct lpss_device_desc lpt_dev_desc = {
85 static struct lpss_device_desc lpt_uart_dev_desc = {
90 .setup = lpss_uart_setup,
93 static struct lpss_device_desc lpt_sdio_dev_desc = {
95 .prv_size_override = 0x1018,
99 static struct lpss_shared_clock uart_clock = {
104 static struct lpss_device_desc byt_uart_dev_desc = {
105 .clk_required = true,
108 .shared_clock = &uart_clock,
109 .setup = lpss_uart_setup,
112 static struct lpss_shared_clock spi_clock = {
117 static struct lpss_device_desc byt_spi_dev_desc = {
118 .clk_required = true,
121 .shared_clock = &spi_clock,
124 static struct lpss_device_desc byt_sdio_dev_desc = {
125 .clk_required = true,
128 static struct lpss_shared_clock i2c_clock = {
133 static struct lpss_device_desc byt_i2c_dev_desc = {
134 .clk_required = true,
136 .shared_clock = &i2c_clock,
139 static const struct acpi_device_id acpi_lpss_device_ids[] = {
140 /* Generic LPSS devices */
141 { "INTL9C60", (unsigned long)&lpss_dma_desc },
143 /* Lynxpoint LPSS devices */
144 { "INT33C0", (unsigned long)&lpt_dev_desc },
145 { "INT33C1", (unsigned long)&lpt_dev_desc },
146 { "INT33C2", (unsigned long)&lpt_dev_desc },
147 { "INT33C3", (unsigned long)&lpt_dev_desc },
148 { "INT33C4", (unsigned long)&lpt_uart_dev_desc },
149 { "INT33C5", (unsigned long)&lpt_uart_dev_desc },
150 { "INT33C6", (unsigned long)&lpt_sdio_dev_desc },
153 /* BayTrail LPSS devices */
154 { "80860F0A", (unsigned long)&byt_uart_dev_desc },
155 { "80860F0E", (unsigned long)&byt_spi_dev_desc },
156 { "80860F14", (unsigned long)&byt_sdio_dev_desc },
157 { "80860F41", (unsigned long)&byt_i2c_dev_desc },
163 static int is_memory(struct acpi_resource *res, void *not_used)
166 return !acpi_dev_resource_memory(res, &r);
169 /* LPSS main clock device. */
170 static struct platform_device *lpss_clk_dev;
172 static inline void lpt_register_clock_device(void)
174 lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
177 static int register_device_clock(struct acpi_device *adev,
178 struct lpss_private_data *pdata)
180 const struct lpss_device_desc *dev_desc = pdata->dev_desc;
181 struct lpss_shared_clock *shared_clock = dev_desc->shared_clock;
182 struct clk *clk = ERR_PTR(-ENODEV);
183 struct lpss_clk_data *clk_data;
187 lpt_register_clock_device();
189 clk_data = platform_get_drvdata(lpss_clk_dev);
193 if (dev_desc->clkdev_name) {
194 clk_register_clkdev(clk_data->clk, dev_desc->clkdev_name,
195 dev_name(&adev->dev));
199 if (!pdata->mmio_base
200 || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE)
203 parent = clk_data->name;
206 clk = shared_clock->clk;
208 clk = clk_register_fixed_rate(NULL, shared_clock->name,
211 shared_clock->clk = clk;
213 parent = shared_clock->name;
216 if (dev_desc->clk_gate) {
217 clk = clk_register_gate(NULL, dev_name(&adev->dev), parent, 0,
218 pdata->mmio_base + dev_desc->prv_offset,
226 clk_register_clkdev(clk, NULL, dev_name(&adev->dev));
230 static int acpi_lpss_create_device(struct acpi_device *adev,
231 const struct acpi_device_id *id)
233 struct lpss_device_desc *dev_desc;
234 struct lpss_private_data *pdata;
235 struct resource_list_entry *rentry;
236 struct list_head resource_list;
239 dev_desc = (struct lpss_device_desc *)id->driver_data;
241 return acpi_create_platform_device(adev, id);
243 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
247 INIT_LIST_HEAD(&resource_list);
248 ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
252 list_for_each_entry(rentry, &resource_list, node)
253 if (resource_type(&rentry->res) == IORESOURCE_MEM) {
254 if (dev_desc->prv_size_override)
255 pdata->mmio_size = dev_desc->prv_size_override;
257 pdata->mmio_size = resource_size(&rentry->res);
258 pdata->mmio_base = ioremap(rentry->res.start,
260 pdata->dev_desc = dev_desc;
264 acpi_dev_free_resource_list(&resource_list);
266 if (dev_desc->clk_required) {
267 ret = register_device_clock(adev, pdata);
270 * Skip the device, but don't terminate the namespace
279 dev_desc->setup(pdata);
281 adev->driver_data = pdata;
282 ret = acpi_create_platform_device(adev, id);
286 adev->driver_data = NULL;
293 static int lpss_reg_read(struct device *dev, unsigned int reg, u32 *val)
295 struct acpi_device *adev;
296 struct lpss_private_data *pdata;
300 ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev);
304 spin_lock_irqsave(&dev->power.lock, flags);
305 if (pm_runtime_suspended(dev)) {
309 pdata = acpi_driver_data(adev);
310 if (WARN_ON(!pdata || !pdata->mmio_base)) {
314 *val = readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
317 spin_unlock_irqrestore(&dev->power.lock, flags);
321 static ssize_t lpss_ltr_show(struct device *dev, struct device_attribute *attr,
328 reg = strcmp(attr->attr.name, "auto_ltr") ? LPSS_SW_LTR : LPSS_AUTO_LTR;
329 ret = lpss_reg_read(dev, reg, <r_value);
333 return snprintf(buf, PAGE_SIZE, "%08x\n", ltr_value);
336 static ssize_t lpss_ltr_mode_show(struct device *dev,
337 struct device_attribute *attr, char *buf)
343 ret = lpss_reg_read(dev, LPSS_GENERAL, <r_mode);
347 outstr = (ltr_mode & LPSS_GENERAL_LTR_MODE_SW) ? "sw" : "auto";
348 return sprintf(buf, "%s\n", outstr);
351 static DEVICE_ATTR(auto_ltr, S_IRUSR, lpss_ltr_show, NULL);
352 static DEVICE_ATTR(sw_ltr, S_IRUSR, lpss_ltr_show, NULL);
353 static DEVICE_ATTR(ltr_mode, S_IRUSR, lpss_ltr_mode_show, NULL);
355 static struct attribute *lpss_attrs[] = {
356 &dev_attr_auto_ltr.attr,
357 &dev_attr_sw_ltr.attr,
358 &dev_attr_ltr_mode.attr,
362 static struct attribute_group lpss_attr_group = {
367 static int acpi_lpss_platform_notify(struct notifier_block *nb,
368 unsigned long action, void *data)
370 struct platform_device *pdev = to_platform_device(data);
371 struct lpss_private_data *pdata;
372 struct acpi_device *adev;
373 const struct acpi_device_id *id;
376 id = acpi_match_device(acpi_lpss_device_ids, &pdev->dev);
377 if (!id || !id->driver_data)
380 if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
383 pdata = acpi_driver_data(adev);
384 if (!pdata || !pdata->mmio_base || !pdata->dev_desc->ltr_required)
387 if (pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) {
388 dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n");
392 if (action == BUS_NOTIFY_ADD_DEVICE)
393 ret = sysfs_create_group(&pdev->dev.kobj, &lpss_attr_group);
394 else if (action == BUS_NOTIFY_DEL_DEVICE)
395 sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
400 static struct notifier_block acpi_lpss_nb = {
401 .notifier_call = acpi_lpss_platform_notify,
404 static struct acpi_scan_handler lpss_handler = {
405 .ids = acpi_lpss_device_ids,
406 .attach = acpi_lpss_create_device,
409 void __init acpi_lpss_init(void)
411 if (!lpt_clk_init()) {
412 bus_register_notifier(&platform_bus_type, &acpi_lpss_nb);
413 acpi_scan_add_handler(&lpss_handler);